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 1 commit
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
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