aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation/active_common.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2019-08-26 23:08:02 +0200
committerorwell96 <orwell@bleipb.de>2019-08-26 23:08:02 +0200
commit7b488f40d95c2d68db898d7cb228e17e001cea73 (patch)
tree686712ef9e75631feebdbac4218a26fa73a72975 /advtrains_luaautomation/active_common.lua
parentd867cd723f373b0fc52bd2cdd19176a29598f8be (diff)
downloadadvtrains-7b488f40d95c2d68db898d7cb228e17e001cea73.tar.gz
advtrains-7b488f40d95c2d68db898d7cb228e17e001cea73.tar.bz2
advtrains-7b488f40d95c2d68db898d7cb228e17e001cea73.zip
Add lines scheduler for reliable railway-time scheduling(which is also safer than the atlatc scheduler) and document new atlatc functions
Diffstat (limited to 'advtrains_luaautomation/active_common.lua')
-rw-r--r--advtrains_luaautomation/active_common.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/advtrains_luaautomation/active_common.lua b/advtrains_luaautomation/active_common.lua
index 5d8cc48..8d0975f 100644
--- a/advtrains_luaautomation/active_common.lua
+++ b/advtrains_luaautomation/active_common.lua
@@ -123,6 +123,15 @@ function ac.run_in_env(pos, evtdata, customfct_p)
digiline:receptor_send(pos, digiline.rules.default, channel, msg)
end
end
+ -- add lines scheduler if enabled
+ if advtrains.lines and advtrains.lines.sched then
+ customfct.schedule = function(rwtime, msg)
+ advtrains.lines.sched.enqueue(rwtime, "atlatc_env", {pos=pos, msg=msg}, advtrains.encode_pos(pos), 1)
+ end
+ customfct.schedule_in = function(rwtime, msg)
+ advtrains.lines.sched.enqueue_in(rwtime, "atlatc_env", {pos=pos, msg=msg}, advtrains.encode_pos(pos), 1)
+ end
+ end
local datain=nodetbl.data or {}
local succ, dataout = atlatc.envs[nodetbl.env]:execute_code(datain, nodetbl.code, evtdata, customfct)
@@ -144,4 +153,11 @@ function ac.on_digiline_receive(pos, node, channel, msg)
atlatc.interrupt.add(0, pos, {type="digiline", digiline=true, channel = channel, msg = msg})
end
+if advtrains.lines and advtrains.lines.sched then
+ advtrains.lines.sched.register_callback("atlatc_env", function(data)
+ -- This adds another interrupt to the atlatc queue... there might be a better way
+ atlatc.interrupt.add(0, data.pos, {type="schedule",schedule=true, msg=data.msg})
+ end)
+end
+
atlatc.active=ac