Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimisation pass #1365

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lua/autorun/pac_core_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ if SERVER then
local function add_files(dir)
local files, folders = file.Find(dir .. "*", "LUA")

for key, file_name in pairs(files) do
AddCSLuaFile(dir .. file_name)
for i = 1, #files do
AddCSLuaFile(dir .. files[i])
end

for key, folder_name in pairs(folders) do
add_files(dir .. folder_name .. "/")
for i = 1, #folders do
add_files(dir .. folders[i] .. "/")
end
end

Expand All @@ -27,5 +27,4 @@ if CLIENT then
end

include("pac3/core/client/init.lua")
end

end
8 changes: 4 additions & 4 deletions lua/autorun/pac_editor_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ if SERVER then
local function add_files(dir)
local files, folders = file.Find(dir .. "*", "LUA")

for key, file_name in pairs(files) do
AddCSLuaFile(dir .. file_name)
for i = 1, #files do
AddCSLuaFile(dir .. files[i])
end

for key, folder_name in pairs(folders) do
add_files(dir .. folder_name .. "/")
for i = 1, #folders do
add_files(dir .. folders[i] .. "/")
end
end

Expand Down
8 changes: 4 additions & 4 deletions lua/autorun/pac_extra_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ if SERVER then
local function add_files(dir)
local files, folders = file.Find(dir .. "*", "LUA")

for key, file_name in pairs(files) do
AddCSLuaFile(dir .. file_name)
for i = 1, #files do
AddCSLuaFile(dir .. files[i])
end

for key, folder_name in pairs(folders) do
add_files(dir .. folder_name .. "/")
for i = 1, #folders do
add_files(dir .. folders[i] .. "/")
end
end

Expand Down
69 changes: 48 additions & 21 deletions lua/autorun/pac_restart.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
AddCSLuaFile()

if SERVER then
return
end
if SERVER then return end

local file_Find = file.Find
local file_Exists = file.Exists
local file_Read = file.Read

local sv_allowcslua = GetConVar("sv_allowcslua")
local prefer_local_version = CreateClientConVar("pac_restart_prefer_local_version", "0")

function _G.pac_ReloadParts()
local pacLocal = _G.pac

local _, dirs = file.Find("addons/*", "MOD")
for _, dir in ipairs(dirs) do
if file.Exists("addons/" .. dir .. "/lua/autorun/pac_editor_init.lua", "MOD") then
local _, dirs = file_Find("addons/*", "MOD")

for i = 1, #dirs do
local dir = dirs[i]

if file_Exists("addons/" .. dir .. "/lua/autorun/pac_editor_init.lua", "MOD") then
pacLocal.Message("found PAC3 in garrysmod/addons/" .. dir)

local old_include = _G.include

local function include(path, ...)
local new_path = path
if not file.Exists("addons/" .. dir .. "/lua/" .. path, "MOD") then

if not file_Exists("addons/" .. dir .. "/lua/" .. path, "MOD") then
local src = debug.getinfo(2).source
local lua_dir = src:sub(2):match("(.+/)")

if lua_dir:StartWith("addons/" .. dir) then
lua_dir = lua_dir:match("addons/.-/lua/(.+)")
end

new_path = lua_dir .. path
end

if file.Exists("addons/" .. dir .. "/lua/" .. new_path, "MOD") then
local str = file.Read("addons/" .. dir .. "/lua/" .. new_path, "MOD")
if file_Exists("addons/" .. dir .. "/lua/" .. new_path, "MOD") then
local str = file_Read("addons/" .. dir .. "/lua/" .. new_path, "MOD")
if str then
local func = CompileString(str, "addons/" .. dir .. "/lua/" .. new_path)
if isfunction(func) then
Expand All @@ -53,6 +62,7 @@ function _G.pac_ReloadParts()
pac.LoadParts()
end)
_G.include = old_include

break
end
end
Expand Down Expand Up @@ -100,7 +110,7 @@ function _G.pac_Restart()
pace.Panic()
end

for _, ent in pairs(ents.GetAll()) do
for _, ent in ents.Iterator() do
for k in pairs(ent:GetTable()) do
if k:sub(0, 4) == "pac_" then
ent[k] = nil
Expand Down Expand Up @@ -133,12 +143,15 @@ function _G.pac_Restart()
if not prefer_local_version:GetBool() then
pacLocal.Message("pac_restart: not reloading from local version")

for _, path in ipairs((file.Find("autorun/pac*", "LUA"))) do
local files = file_Find("autorun/pac*", "LUA")

for i = 1, #files do
local path = files[i]

if path:EndsWith("_init.lua") and path ~= "pac_init.lua" then
include("autorun/" .. path)
end
end

elseif sv_allowcslua:GetBool() or LocalPlayer():IsSuperAdmin() then
local loadingHit = false

Expand All @@ -150,25 +163,32 @@ function _G.pac_Restart()
pacLocal.Message("pac_restart: LocalPlayer() is superadmin, looking for PAC3 addon..")
end

local _, dirs = file.Find("addons/*", "MOD")
for _, dir in ipairs(dirs) do
if file.Exists("addons/" .. dir .. "/lua/autorun/pac_editor_init.lua", "MOD") then
local _, dirs = file_Find("addons/*", "MOD")

for i = 1, #dirs do
local dir = dirs[i]

if file_Exists("addons/" .. dir .. "/lua/autorun/pac_editor_init.lua", "MOD") then
pacLocal.Message("found PAC3 in garrysmod/addons/" .. dir)

local old_include = _G.include

local function include(path, ...)
local new_path = path
if not file.Exists("addons/" .. dir .. "/lua/" .. path, "MOD") then

if not file_Exists("addons/" .. dir .. "/lua/" .. path, "MOD") then
local src = debug.getinfo(2).source
local lua_dir = src:sub(2):match("(.+/)")

if lua_dir:StartWith("addons/" .. dir) then
lua_dir = lua_dir:match("addons/.-/lua/(.+)")
end

new_path = lua_dir .. path
end

if file.Exists("addons/" .. dir .. "/lua/" .. new_path, "MOD") then
local str = file.Read("addons/" .. dir .. "/lua/" .. new_path, "MOD")
if file_Exists("addons/" .. dir .. "/lua/" .. new_path, "MOD") then
local str = file_Read("addons/" .. dir .. "/lua/" .. new_path, "MOD")
if str then
local func = CompileString(str, "addons/" .. dir .. "/lua/" .. new_path)
if isfunction(func) then
Expand All @@ -192,7 +212,11 @@ function _G.pac_Restart()

_G.include = include

for _, path in ipairs((file.Find("autorun/pac_*", "LUA"))) do
local init_files = file_Find("autorun/pac_*", "LUA")

for i = 1, #init_files do
local path = init_files[i]

if path:EndsWith("_init.lua") and path ~= "pac_init.lua" then
pacLocal.Message("pac_restart: including autorun/" .. path .. "...")

Expand All @@ -213,11 +237,14 @@ function _G.pac_Restart()
end
end


if not loadingHit then
pacLocal.Message("sv_allowcslua is not enabled or unable to find PAC3 in addons/, loading PAC3 again from server lua")

for _, path in ipairs((file.Find("autorun/pac*", "LUA"))) do
local init_files = file_Find("autorun/pac_*", "LUA")

for i = 1, #init_files do
local path = init_files[i]

if path:EndsWith("_init.lua") and path ~= "pac_init.lua" then
include("autorun/" .. path)
end
Expand Down
19 changes: 12 additions & 7 deletions lua/autorun/pac_version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ if SERVER then
local function pacVersion()
local addonFound = false

for k,v in pairs(select(2, file.Find( "addons/*", "GAME" ))) do
if file.Exists("addons/"..v.."/lua/autorun/pac_init.lua", "GAME") then
local _, dirs = file.Find("addons/*", "GAME")

for i = 1, #dirs do
local v = dirs[i]

if file.Exists("addons/" .. v .. "/lua/autorun/pac_init.lua", "GAME") then
addonFound = true
local dir = "addons/"..v.."/.git/"
local head = file.Read(dir.."HEAD", "GAME") -- Where head points to

local dir = "addons/" .. v .. "/.git/"
local head = file.Read(dir .. "HEAD", "GAME") -- Where head points to
if not head then break end

head = string.match(head, "ref:%s+(%S+)")
if not head then break end

local lastCommit = string.match(file.Read( dir..head, "GAME") or "", "%S+")
local lastCommit = string.match(file.Read(dir..head, "GAME") or "", "%S+")
if not lastCommit then break end

return "Git: " .. string.GetFileFromFilename(head) .. " (" .. lastCommit .. ")"
Expand All @@ -37,15 +42,15 @@ end

concommand.Add("pac_version", function()
print(PAC_VERSION())

if CLIENT and PAC_VERSION() == "workshop" then
print("Fetching workshop info...")
steamworks.FileInfo( "104691717", function(result)
steamworks.FileInfo("104691717", function(result)
print("Updated: " .. os.date("%x %X", result.updated))
end)
end
end)


--accessed in the editor under pac-help-version
function pac.OpenMOTD(mode)
local pnl = vgui.Create("DFrame")
Expand Down
41 changes: 24 additions & 17 deletions lua/pac3/core/client/base_drawable.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local pac = pac

local table_insert = table.insert
local table_remove = table.remove
local render_OverrideAlphaWriteEnable = render.OverrideAlphaWriteEnable
local render_OverrideColorWriteEnable = render.OverrideColorWriteEnable
local render_OverrideBlendFunc = render.OverrideBlendFunc
local ProtectedCall = ProtectedCall
local cam_IgnoreZ = cam.IgnoreZ
local pac = pac
local ipairs = ipairs
local table = table
local TEXFILTER_POINT = TEXFILTER.POINT
local render_PopFilterMag = render.PopFilterMag
local render_PopFilterMin = render.PopFilterMin
Expand Down Expand Up @@ -111,13 +112,13 @@ do -- modifiers

function PART:AddModifier(part)
self:RemoveModifier(part)
table.insert(self.modifiers, part)
table_insert(self.modifiers, part)
end

function PART:RemoveModifier(part)
for i, v in ipairs(self.modifiers) do
if v == part then
table.remove(self.modifiers, i)
for i = 1, #self.modifiers do
if self.modifiers[i] == part then
table_remove(self.modifiers, i)
break
end
end
Expand All @@ -126,9 +127,10 @@ do -- modifiers
function PART:ModifiersPreEvent(event)
if not self.modifiers[1] then return end

for _, part in ipairs(self.modifiers) do
if not part:IsHidden() then
for i = 1, #self.modifiers do
local part = self.modifiers[i]

if not part:IsHidden() then
if not part.pre_draw_events then part.pre_draw_events = {} end
if not part.pre_draw_events[event] then part.pre_draw_events[event] = "Pre" .. event end

Expand All @@ -142,9 +144,10 @@ do -- modifiers
function PART:ModifiersPostEvent(event)
if not self.modifiers[1] then return end

for _, part in ipairs(self.modifiers) do
if not part:IsHidden() then
for i = 1, #self.modifiers do
local part = self.modifiers[i]

if not part:IsHidden() then
if not part.post_draw_events then part.post_draw_events = {} end
if not part.post_draw_events[event] then part.post_draw_events[event] = "Post" .. event end

Expand All @@ -167,15 +170,19 @@ local function call_draw()
_self:OnDraw()
end

local type_opaque = "opaque"
local type_translucent = "translucent"
local type_viewmodel = "viewmodel"
local type_hands = "hands"

function PART:Draw(draw_type)
if not self.OnDraw or not self.Enabled or self:IsHiddenCached() then return end

if
draw_type == "viewmodel" or draw_type == "hands" or
((self.Translucent == true or self.force_translucent == true) and draw_type == "translucent") or
((self.Translucent == false or self.force_translucent == false) and draw_type == "opaque")
if ((self.Translucent == false or self.force_translucent == false) and draw_type == type_opaque)
or ((self.Translucent == true or self.force_translucent == true) and draw_type == type_translucent)
or draw_type == type_viewmodel or draw_type == type_hands
then
if not self.HandleModifiersManually then self:ModifiersPreEvent('OnDraw', draw_type) end
if not self.HandleModifiersManually then self:ModifiersPreEvent("OnDraw", draw_type) end

if self.IgnoreZ then cam_IgnoreZ(true) end

Expand All @@ -199,7 +206,7 @@ function PART:Draw(draw_type)

if self.IgnoreZ then cam_IgnoreZ(false) end

if not self.HandleModifiersManually then self:ModifiersPostEvent('OnDraw', draw_type) end
if not self.HandleModifiersManually then self:ModifiersPostEvent("OnDraw", draw_type) end
end
end

Expand Down
5 changes: 4 additions & 1 deletion lua/pac3/core/client/base_movable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ function PART:CalcAngles(ang, wpos)
local nearest_dist = math.huge
local owner_ent = part:GetRootPart():GetOwner()

for _,ent in pairs(ents.FindInSphere(wpos, 5000)) do
local ents_in_sphere = ents.FindInSphere(wpos, 5000)

for i = 1, #ents_in_sphere do
local ent = ents_in_sphere[i]
if (ent:IsNPC() or ent:IsPlayer()) and ent ~= owner_ent then
local dist = (wpos - ent:GetPos()):LengthSqr()
if dist < nearest_dist then
Expand Down
Loading
Loading