aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2017-01-10 22:44:27 +0100
committerorwell96 <mono96.mml@gmail.com>2017-01-10 22:44:27 +0100
commitc2a92608fa896d805a8e7cf4c13846c06e987b4f (patch)
tree87fcadf63dc5e3f111df2b56aad6386ea6b64503 /advtrains
parent0d2ec6f49a781f4539f934217ec8eb157f6a7796 (diff)
downloadadvtrains-c2a92608fa896d805a8e7cf4c13846c06e987b4f.tar.gz
advtrains-c2a92608fa896d805a8e7cf4c13846c06e987b4f.tar.bz2
advtrains-c2a92608fa896d805a8e7cf4c13846c06e987b4f.zip
Fix restoring the detector.on_node table when paths get cleaned up
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/advtrains/tracks.lua31
1 files changed, 20 insertions, 11 deletions
diff --git a/advtrains/advtrains/tracks.lua b/advtrains/advtrains/tracks.lua
index 9fc3a56..671c861 100644
--- a/advtrains/advtrains/tracks.lua
+++ b/advtrains/advtrains/tracks.lua
@@ -398,17 +398,17 @@ advtrains.detector.clean_step_before = false
--The entry already being contained in advtrains.detector.on_node_restore will not trigger an on_train_enter event on the node. (when path is reset, this is saved).
function advtrains.detector.enter_node(pos, train_id)
local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
- --atprint("enterNode "..pts.." "..sid(train_id))
+ atprint("enterNode "..pts.." "..sid(train_id))
if advtrains.detector.on_node[pts] then
if advtrains.trains[advtrains.detector.on_node[pts]] then
- --atprint(""..pts.." already occupied")
+ atprint(""..pts.." already occupied")
return false
else
advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])
end
end
advtrains.detector.on_node[pts]=train_id
- if advtrains.detector.on_node_restore[pts] then
+ if advtrains.detector.on_node_restore[pts]==train_id then
advtrains.detector.on_node_restore[pts]=nil
else
advtrains.detector.call_enter_callback(advtrains.round_vector_floor_y(pos), train_id)
@@ -417,9 +417,9 @@ function advtrains.detector.enter_node(pos, train_id)
end
function advtrains.detector.leave_node(pos, train_id)
local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
- --atprint("leaveNode "..pts.." "..sid(train_id))
+ atprint("leaveNode "..pts.." "..sid(train_id))
if not advtrains.detector.on_node[pts] then
- --atprint(""..pts.." leave: nothing here")
+ atprint(""..pts.." leave: nothing here")
return false
end
if advtrains.detector.on_node[pts]==train_id then
@@ -427,7 +427,7 @@ function advtrains.detector.leave_node(pos, train_id)
advtrains.detector.on_node[pts]=nil
else
if advtrains.trains[advtrains.detector.on_node[pts]] then
- --atprint(""..pts.." occupied by another train")
+ atprint(""..pts.." occupied by another train")
return false
else
advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])
@@ -438,21 +438,30 @@ function advtrains.detector.leave_node(pos, train_id)
end
--called immediately before invalidating paths
function advtrains.detector.setup_restore()
- --atprint("setup_restore")
- advtrains.detector.on_node_restore = advtrains.detector.on_node
+ atprint("setup_restore")
+ -- don't execute if it already has been called. For some reason it gets called twice...
+ if advtrains.detector.clean_step_before then
+ return
+ end
+ advtrains.detector.on_node_restore={}
+ for k, v in pairs(advtrains.detector.on_node) do
+ advtrains.detector.on_node_restore[k]=v
+ end
advtrains.detector.on_node = {}
+ advtrains.detector.clean_step_before = true
end
--called one step after invalidating paths, when all trains have restored their path and called enter_node for their contents.
function advtrains.detector.finalize_restore()
- --atprint("finalize_restore")
+ atprint("finalize_restore")
for pts, train_id in pairs(advtrains.detector.on_node_restore) do
--atprint("called leave callback "..pts.." "..train_id)
advtrains.detector.call_leave_callback(minetest.string_to_pos(pts), train_id)
end
advtrains.detector.on_node_restore = {}
+ advtrains.detector.clean_step_before = false
end
function advtrains.detector.call_enter_callback(pos, train_id)
- --atprint("instructed to call enter calback")
+ atprint("instructed to call enter calback")
local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case
local mregnode=minetest.registered_nodes[node.name]
@@ -464,7 +473,7 @@ function advtrains.detector.call_enter_callback(pos, train_id)
advtrains.atc.trigger_controller_train_enter(pos, train_id)
end
function advtrains.detector.call_leave_callback(pos, train_id)
- --atprint("instructed to call leave calback")
+ atprint("instructed to call leave calback")
local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case
local mregnode=minetest.registered_nodes[node.name]