diff options
Diffstat (limited to 'advtrains/advtrains_luaautomation')
-rw-r--r-- | advtrains/advtrains_luaautomation/init.lua | 50 | ||||
-rw-r--r-- | advtrains/advtrains_luaautomation/interrupt.lua | 37 |
2 files changed, 39 insertions, 48 deletions
diff --git a/advtrains/advtrains_luaautomation/init.lua b/advtrains/advtrains_luaautomation/init.lua index 71808e7..0257aef 100644 --- a/advtrains/advtrains_luaautomation/init.lua +++ b/advtrains/advtrains_luaautomation/init.lua @@ -40,29 +40,32 @@ dofile(mp.."/chatcmds.lua") local filename=minetest.get_worldpath().."/advtrains_luaautomation" -local file, err = io.open(filename, "r") -if not file then - minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error")) -else - atprint("luaautomation reading file:",filename) - local tbl = minetest.deserialize(file:read("*a")) - if type(tbl) == "table" then - if tbl.version==1 then - for envname, data in pairs(tbl.envs) do - atlatc.envs[envname]=atlatc.env_load(envname, data) + +function atlatc.load() + local file, err = io.open(filename, "r") + if not file then + minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error")) + else + atprint("luaautomation reading file:",filename) + local tbl = minetest.deserialize(file:read("*a")) + if type(tbl) == "table" then + if tbl.version==1 then + for envname, data in pairs(tbl.envs) do + atlatc.envs[envname]=atlatc.env_load(envname, data) + end + atlatc.active.load(tbl.active) + atlatc.interrupt.load(tbl.interrupt) + atlatc.pcnaming.load(tbl.pcnaming) end - atlatc.active.load(tbl.active) - atlatc.interrupt.load(tbl.interrupt) - atlatc.pcnaming.load(tbl.pcnaming) + else + minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": Not a table!") end - else - minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": Not a table!") + file:close() end - file:close() + -- run init code of all environments + atlatc.run_initcode() end --- run init code of all environments -atlatc.run_initcode() atlatc.save = function() --versions: @@ -94,21 +97,14 @@ atlatc.save = function() file:close() end -minetest.register_on_shutdown(atlatc.save) -- globalstep for step code local timer, step_int=0, 2 -local stimer, sstep_int=0, 10 -minetest.register_globalstep(function(dtime) +function atlatc.mainloop_stepcode(dtime) timer=timer+dtime if timer>step_int then timer=0 atlatc.run_stepcode() end - stimer=stimer+dtime - if stimer>sstep_int then - stimer=0 - atlatc.save() - end -end) +end diff --git a/advtrains/advtrains_luaautomation/interrupt.lua b/advtrains/advtrains_luaautomation/interrupt.lua index b8fc879..718b8c7 100644 --- a/advtrains/advtrains_luaautomation/interrupt.lua +++ b/advtrains/advtrains_luaautomation/interrupt.lua @@ -21,30 +21,25 @@ function iq.add(t, pos, evtdata) run=true end -minetest.register_globalstep(function(dtime) -return advtrains.pcall(function() - - if run then - timer=timer + math.min(dtime, 0.2) - for i=1,#queue do - local qe=queue[i] - if not qe then - table.remove(queue, i) - i=i-1 - elseif timer>qe.t then - local pos, evtdata=queue[i].p, queue[i].e - local node=advtrains.ndb.get_node(pos) - local ndef=minetest.registered_nodes[node.name] - if ndef and ndef.luaautomation and ndef.luaautomation.fire_event then - ndef.luaautomation.fire_event(pos, evtdata) - end - table.remove(queue, i) - i=i-1 +function iq.mainloop(dtime) + timer=timer + math.min(dtime, 0.2) + for i=1,#queue do + local qe=queue[i] + if not qe then + table.remove(queue, i) + i=i-1 + elseif timer>qe.t then + local pos, evtdata=queue[i].p, queue[i].e + local node=advtrains.ndb.get_node(pos) + local ndef=minetest.registered_nodes[node.name] + if ndef and ndef.luaautomation and ndef.luaautomation.fire_event then + ndef.luaautomation.fire_event(pos, evtdata) end + table.remove(queue, i) + i=i-1 end end -end) -end) +end |