From af74cb5987d38c8efc820aa8d41a516ade40bcf2 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 14 Jan 2018 15:40:04 -0500 Subject: Massive updates updates to nrequire, only re-includes things out of date changes to cl_inventory, and config --- gamemode/cl_init.lua | 5 +- gamemode/client/cl_inventory.lua | 1 + gamemode/core/config/sv_config.lua | 25 +++++++ gamemode/core/inventory/inventory.lua | 1 + gamemode/nrequire.lua | 134 +++++++++++++++++++++++++++++++--- 5 files changed, 152 insertions(+), 14 deletions(-) create mode 100644 gamemode/core/config/sv_config.lua diff --git a/gamemode/cl_init.lua b/gamemode/cl_init.lua index 2f80ddd..07cd341 100644 --- a/gamemode/cl_init.lua +++ b/gamemode/cl_init.lua @@ -1,10 +1,11 @@ --Find out where all our prints are comming from! +--[[ local oldprint = print print = function(...) oldprint(unpack({...})) oldprint(debug.traceback()) end - +]] include( "shared.lua" ) -print = oldprint +--print = oldprint diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua index 002ea73..1887559 100644 --- a/gamemode/client/cl_inventory.lua +++ b/gamemode/client/cl_inventory.lua @@ -40,6 +40,7 @@ local clt = nrequire("cl_invtracker.lua") local function CreateSheetTree(tabs,dpropertysheet) for k,v in pairs(tabs) do + print("Making seet,(" .. type(k) .. ")", k) if type(k) == "string" then local tsheet = vgui.Create( "DPropertySheet", dpropertysheet ) dpropertysheet:AddSheet(k,tsheet,"icon16/user.png") diff --git a/gamemode/core/config/sv_config.lua b/gamemode/core/config/sv_config.lua new file mode 100644 index 0000000..6eb5394 --- /dev/null +++ b/gamemode/core/config/sv_config.lua @@ -0,0 +1,25 @@ +--[[ + Allows addons to add config settings for easy manipulation +]] + +local config = {} + +--Master list of addons, and the config for each +local addons = {} + +local function config_number(panel) + +end +local config_types = { + ["number"] = config_number, + "text", + "textbox" +} +function config.RegisterConfig(name,t,func) + assert(config_types[t],string.format("Attempted to register unknown config type %q, allowed types are %s"),t,table.concat(table.GetKeys(config_types))) + local tb = debug.getinfo(-1,"flnSu") + print("Debug info was:") + PrintTable(tb) +end + +return config diff --git a/gamemode/core/inventory/inventory.lua b/gamemode/core/inventory/inventory.lua index 1fb3dba..d97f5be 100644 --- a/gamemode/core/inventory/inventory.lua +++ b/gamemode/core/inventory/inventory.lua @@ -184,6 +184,7 @@ end) ---To Be Depriciated. function inv.DeriveInventory(name) + error("inv.DeriveInventory called") while inventories[name] == nil do coroutine.yield() end diff --git a/gamemode/nrequire.lua b/gamemode/nrequire.lua index 24f0266..3fbe9d7 100644 --- a/gamemode/nrequire.lua +++ b/gamemode/nrequire.lua @@ -119,24 +119,23 @@ local lastcall = {} --Holds when things were loaded local deptbl = {} --Holds the dependencies between files local pathstack = {} function nrequire(req,...) - - + local tpath = scan(ntbl,req) -- Find the full path for the nrequired() module - - local trace = debug.getinfo(1,"flnSu") + + local trace = debug.getinfo(2,"flnSu") local source = trace.source deptbl[source] = tpath - - --If we've already run it, just return it - if reqtbl[tpath[1]] then + + --If we've already run it (and its up to date), just return it + if reqtbl[tpath[1]] and lastcall[tpath[1]] >= file.Time(tpath[1],tpath[2]) then return reqtbl[tpath[1]] end - + --Otherwise, make sure we don't have a circular depedency for k,v in pairs(pathstack) do assert(v ~= tpath[1],string.format("Circular dependancy detected:\n\t%s\n\t\t|\n\t\tV\n\t%s",table.concat(pathstack,"\n\t\t|\n\t\tV\n\t"),v)) end - + --Actually run the file pathstack[#pathstack + 1] = tpath[1] local filetxt = file.Read(tpath[1],tpath[2]) @@ -160,6 +159,74 @@ function nrequire(req,...) end +if SERVER then + --[[Server tells the client to load a file]] + util.AddNetworkString("artery_loadfile") + --[[Client tells server we don't have that file]] + util.AddNetworkString("artery_requestcsfile") + --[[Server gives client the contents of a file]] + util.AddNetworkString("artery_respondfile") + net.Receive("artery_requestcsfile",function(ln,ply) + local which = net.ReadString() + local path = net.ReadString() + local found = false + for k,v in pairs(clienttoload) do + if v.name == which and v.directory == path then + net.Start("artery_respondfile") + net.WriteString(which) + net.WriteString(path) + net.WriteString(file.Read(which,path)) + net.Send(ply) + return + end + end + end) +else + local function run_csfile(txt,name) + assert(#txt > 0, "File was size 0 on: " .. name) + local ptr = CompileString(txt,name,false) + if type(ptr) == "function" then + ptr() + else + log.error(ptr) + end + end + net.Receive("artery_loadfile",function() + local filename = net.ReadString() + local hash = net.ReadUInt(32) + local path = net.ReadString() + local cache = file.Read("artery/client/files/" .. path .. "/" .. filename,"DATA") + if cache == nil then --We don't have this file downloaded! + net.Start("artery_requestcsfile") + net.WriteString(filename) + net.WriteString(path) + net.SendToServer() + return + end + local thash = tonumber(util.CRC(cache)) + if hash != thash then + print("I need to load a file",filename," but my hash was old, redownloading!") + net.Start("artery_requestcsfile") + net.WriteString(filename) + net.WriteString(path) + net.SendToServer() + else + run_csfile(cache,filename) + end + end) + net.Receive("artery_respondfile",function() + local filename = net.ReadString() + local filetext = net.ReadString() + local dirname = string.GetPathFromFilename(filename) + file.CreateDir("artery/client/files/" .. dirname) + assert(#filetext > 0, "Retreived a size 0 file: " .. filename) + file.Write("artery/client/files/" .. filename,filetext) + run_csfile(filetext,filename) + end) +end + +local clienttoload = {} + --[[ Automatically include all the files in the gamemode directory based on the file name. If the file starts with cl_ it will only be included on the client, if it starts with sv_ it will only be included on the server. If it starts with anything else, it will be shared. Will detect and error on circuar dependancy. @@ -187,11 +254,19 @@ local function doincludes() if CLIENT then nrequire(filename) else - AddCSLuaFile(filename) + clienttoload[#clienttoload+1] = { + name = filename, + hash = util.CRC(file.Read(filename,v[2])), + directory = v[2] + } end else if SERVER then - AddCSLuaFile(filename) + clienttoload[#clienttoload + 1] = { + name = filename, + hash = util.CRC(file.Read(filename,v[2])), + directory = v[2] + } end nrequire(filename) end @@ -200,6 +275,23 @@ local function doincludes() end doincludes() +hook.Call("artery_core_loaded") +local function loadclient(who) + local routine = coroutine.create(function() + for k,v in pairs(clienttoload) do + print("Asking client to load",k) + net.Start("artery_loadfile") + net.WriteString(v.name) + net.WriteUInt(v.hash,32) + net.WriteString(v.directory) + net.Send(who) + coroutine.yield() + end + end) + timer.Create("artery_load_client_timer",1,#clienttoload,function() + coroutine.resume(routine) + end) +end concommand.Add("PrintDepTbl",function(ply,cmd,args) PrintTable(deptbl) @@ -207,9 +299,27 @@ end) concommand.Add("PrintReqTbl",function(ply,cmd,args) PrintTable(reqtbl) end) +concommand.Add("PrintClientToLoad",function(ply,cmd,args) + PrintTable(clienttoload) +end) +concommand.Add("Loadclient",function(ply,cmd,args) + loadclient(ply) +end) if SERVER then util.AddNetworkString("art_refresh") + concommand.Add("art_refresh",function(ply,cmd,args) + print("Doing soft refresh") + doincludes() + net.Start("art_refresh") + net.Broadcast() + end) +else + net.Receive("art_manualrefresh",doincludes) +end + +if SERVER then + util.AddNetworkString("art_manualrefresh") concommand.Add("art_manualrefresh",function(ply,cmd,args) if not ply:IsAdmin() then return end reqtbl = {} @@ -218,7 +328,7 @@ if SERVER then net.Broadcast() end) end -if CLIENT then net.Receive("art_refresh",doincludes) end +if CLIENT then net.Receive("art_manualrefresh",doincludes) end concommand.Add("artery_manualrefresh",function(ply,cmd,args) doincludes() -- cgit v1.2.3-70-g09d2