aboutsummaryrefslogtreecommitdiff
path: root/gamemode/nrequire.lua
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2018-11-03 18:23:45 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2018-11-03 18:23:45 -0400
commit28affa22541b9ef251707793f6b1c1a26d663592 (patch)
tree622754894d75c74dc5e8516ccf184ad4bf328fef /gamemode/nrequire.lua
parentc639e7c7c6ab1595fdce39f56312e3d6a886bbe8 (diff)
downloadartery-28affa22541b9ef251707793f6b1c1a26d663592.tar.gz
artery-28affa22541b9ef251707793f6b1c1a26d663592.tar.bz2
artery-28affa22541b9ef251707793f6b1c1a26d663592.zip
Started on new npc system
Started work on the new npc system
Diffstat (limited to 'gamemode/nrequire.lua')
-rw-r--r--gamemode/nrequire.lua25
1 files changed, 24 insertions, 1 deletions
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()