From 28affa22541b9ef251707793f6b1c1a26d663592 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 3 Nov 2018 18:23:45 -0400 Subject: Started on new npc system Started work on the new npc system --- gamemode/nrequire.lua | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'gamemode/nrequire.lua') diff --git a/gamemode/nrequire.lua b/gamemode/nrequire.lua index 1b6be2f..4313ce0 100644 --- a/gamemode/nrequire.lua +++ b/gamemode/nrequire.lua @@ -6,6 +6,7 @@ ]] if nrequire ~= nil then return end +--The files we want clients to load local clienttoload = {} local searchpaths = { @@ -131,6 +132,7 @@ local ntbl = {} local reqtbl = {} --Holds already nrequire()'d things local lastcall = {} --Holds when things were loaded +local location = {} --Holds the location of files ("DATA","GAME","LUA",...) local deptbl = {} --Holds the dependencies between files local pathstack = {} function nrequire(req,...) @@ -153,6 +155,7 @@ function nrequire(req,...) local trace = debug.getinfo(2,"flnSu") local source = trace.source + print("Adding to deptbl, src:",source,"tpath:",tpath) deptbl[source] = tpath --If we've already run it (and its up to date), just return it @@ -187,7 +190,8 @@ function nrequire(req,...) local m = filefunc(varargs) hook.Run("artery_file_included",tpath,m) reqtbl[tpath[1]] = m - lastcall[tpath[1]] = CurTime() + lastcall[tpath[1]] = file.Time(tpath[1],tpath[2]) + location[tpath[1]] = tpath[2] end,function(err) MsgC(Color(209,96,196),debug.traceback(),"\n") MsgC(Color(209,96,196),"nrequire Error:",err,"\n") @@ -201,6 +205,25 @@ function nrequire(req,...) end +local update_file_co = coroutine.create(function() + while true do + for k,v in pairs(reqtbl) do + local loc = location[k] + if file.Time(k,loc) > lastcall[k] then + print(string.format("Found updated file:%s calling nrequire",k)) + nrequire(k) + end + coroutine.yield() + end + end +end) + +hook.Add("Tick","nrequire_update_tick",function() + if coroutine.status(update_file_co) == "suspended" then + coroutine.resume(update_file_co) + end +end) + if SERVER then net.Receive("artery_requestcsfile",function(ln,ply) local which = net.ReadString() -- cgit v1.2.3-70-g09d2