Start using path_invalidate_ahead()
This commit is contained in:
parent
d3b2f614be
commit
61329c11a2
@ -190,15 +190,16 @@ function advtrains.lzb_invalidate_ahead(train, start_idx)
|
|||||||
local idx = atfloor(start_idx)
|
local idx = atfloor(start_idx)
|
||||||
local i = 1
|
local i = 1
|
||||||
while train.lzb.checkpoints[i] do
|
while train.lzb.checkpoints[i] do
|
||||||
if train.lzb.checkpoints[i].idx >= idx then
|
if train.lzb.checkpoints[i].index >= idx then
|
||||||
table.remove(train.lzb.checkpoints, i)
|
table.remove(train.lzb.checkpoints, i)
|
||||||
else
|
else
|
||||||
i=i+1
|
i=i+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
train.lzb.trav_index = idx
|
||||||
-- re-apply all checkpoints to path_speed
|
-- re-apply all checkpoints to path_speed
|
||||||
train.path_speed = {}
|
train.path_speed = {}
|
||||||
for _,ckp in train.lzb.checkpoints do
|
for _,ckp in ipairs(train.lzb.checkpoints) do
|
||||||
apply_checkpoint_to_path(train, ckp)
|
apply_checkpoint_to_path(train, ckp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -236,8 +237,9 @@ advtrains.te_register_on_new_path(function(id, train)
|
|||||||
look_ahead(id, train)
|
look_ahead(id, train)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
advtrains.te_register_on_invalidate_ahead(function(id, train)
|
advtrains.te_register_on_invalidate_ahead(function(id, train, start_idx)
|
||||||
advtrains.lzb_invalidate_ahead(train, start_idx)
|
advtrains.lzb_invalidate_ahead(train, start_idx)
|
||||||
|
look_ahead(id, train)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
advtrains.te_register_on_update(function(id, train)
|
advtrains.te_register_on_update(function(id, train)
|
||||||
|
@ -246,7 +246,7 @@ function ndb.update(pos, pnode)
|
|||||||
local resid = (nid * 4) + (l2b(node.param2 or 0))
|
local resid = (nid * 4) + (l2b(node.param2 or 0))
|
||||||
ndbset(pos.x, pos.y, pos.z, resid )
|
ndbset(pos.x, pos.y, pos.z, resid )
|
||||||
--atdebug("nodedb: updating node", pos, "stored nid",nid,"assigned",ndb_nodeids[nid],"resulting cid",resid)
|
--atdebug("nodedb: updating node", pos, "stored nid",nid,"assigned",ndb_nodeids[nid],"resulting cid",resid)
|
||||||
minetest.after(0, advtrains.invalidate_all_paths, pos)
|
advtrains.invalidate_all_paths_ahead(pos)
|
||||||
else
|
else
|
||||||
--at this position there is no longer a node that needs to be tracked.
|
--at this position there is no longer a node that needs to be tracked.
|
||||||
--atdebug("nodedb: updating node", pos, "cleared")
|
--atdebug("nodedb: updating node", pos, "cleared")
|
||||||
|
@ -141,22 +141,30 @@ end
|
|||||||
|
|
||||||
-- Keeps the path intact, but invalidates all path nodes from the specified index (inclusive)
|
-- Keeps the path intact, but invalidates all path nodes from the specified index (inclusive)
|
||||||
-- onwards. This has the advantage that we don't need to recalculate the whole path, and we can do it synchronously.
|
-- onwards. This has the advantage that we don't need to recalculate the whole path, and we can do it synchronously.
|
||||||
function advtrains.path_invalidate_ahead(train, start_idx)
|
function advtrains.path_invalidate_ahead(train, start_idx, ignore_when_passed)
|
||||||
|
|
||||||
local idx = atfloor(start_idx)
|
local idx = atfloor(start_idx)
|
||||||
|
--atdebug("Invalidate_ahead:",train.id,"start_index",start_idx,"cur_idx",train.index)
|
||||||
|
|
||||||
if(idx <= train.index) then
|
if(idx <= train.index - 0.5) then
|
||||||
|
if ignore_when_passed then
|
||||||
|
--atdebug("ignored passed")
|
||||||
|
return
|
||||||
|
end
|
||||||
advtrains.path_print(train, atwarn)
|
advtrains.path_print(train, atwarn)
|
||||||
error("Train "+train.id+": Cannot path_invalidate_ahead start_idx="+idx+" as train has already passed!")
|
error("Train "+train.id+": Cannot path_invalidate_ahead start_idx="+idx+" as train has already passed!")
|
||||||
end
|
end
|
||||||
|
|
||||||
local i = idx
|
-- leave current node in path, it won't change. What might change is the path onward from here (e.g. switch)
|
||||||
|
local i = idx + 1
|
||||||
while train.path[i] do
|
while train.path[i] do
|
||||||
advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(train.path[i]))
|
advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(train.path[i]))
|
||||||
|
i = i+1
|
||||||
end
|
end
|
||||||
train.path_ext_f=idx - 1
|
train.path_ext_f=idx
|
||||||
train.path_trk_f=idx - 1
|
train.path_trk_f=math.min(idx, train.path_trk_f)
|
||||||
|
|
||||||
|
-- callbacks called anyway for current node, because of LZB
|
||||||
advtrains.run_callbacks_invahead(train.id, train, idx)
|
advtrains.run_callbacks_invahead(train.id, train, idx)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,6 +20,18 @@ return {
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local suppasp = {
|
||||||
|
main = {0, false},
|
||||||
|
dst = {false},
|
||||||
|
shunt = nil,
|
||||||
|
proceed_as_main = true,
|
||||||
|
info = {
|
||||||
|
call_on = false,
|
||||||
|
dead_end = false,
|
||||||
|
w_speed = nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do
|
for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do
|
||||||
|
|
||||||
advtrains.trackplacer.register_tracktype("advtrains:retrosignal", "")
|
advtrains.trackplacer.register_tracktype("advtrains:retrosignal", "")
|
||||||
@ -81,7 +93,8 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
|
|||||||
end,
|
end,
|
||||||
get_aspect = function(pos, node)
|
get_aspect = function(pos, node)
|
||||||
return aspect(r=="on")
|
return aspect(r=="on")
|
||||||
end
|
end,
|
||||||
|
supported_aspects = suppasp,
|
||||||
},
|
},
|
||||||
can_dig = can_dig_func,
|
can_dig = can_dig_func,
|
||||||
})
|
})
|
||||||
@ -141,6 +154,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
|
|||||||
get_aspect = function(pos, node)
|
get_aspect = function(pos, node)
|
||||||
return aspect(r=="on")
|
return aspect(r=="on")
|
||||||
end,
|
end,
|
||||||
|
supported_aspects = suppasp,
|
||||||
getstate = f.ls,
|
getstate = f.ls,
|
||||||
setstate = function(pos, node, newstate)
|
setstate = function(pos, node, newstate)
|
||||||
if newstate == f.als then
|
if newstate == f.als then
|
||||||
@ -209,6 +223,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
|
|||||||
get_aspect = function(pos, node)
|
get_aspect = function(pos, node)
|
||||||
return aspect(r=="on")
|
return aspect(r=="on")
|
||||||
end,
|
end,
|
||||||
|
supported_aspects = suppasp,
|
||||||
getstate = f.ls,
|
getstate = f.ls,
|
||||||
setstate = function(pos, node, newstate)
|
setstate = function(pos, node, newstate)
|
||||||
if newstate == f.als then
|
if newstate == f.als then
|
||||||
|
@ -1277,6 +1277,18 @@ function advtrains.invalidate_all_paths(pos)
|
|||||||
advtrains.invalidate_path(id)
|
advtrains.invalidate_path(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Calls invalidate_path_ahead on all trains occupying (having paths over) this node
|
||||||
|
-- Can be called during train step.
|
||||||
|
function advtrains.invalidate_all_paths_ahead(pos)
|
||||||
|
local tab = advtrains.occ.get_trains_over(pos)
|
||||||
|
|
||||||
|
for id,index in pairs(tab) do
|
||||||
|
local train = advtrains.trains[id]
|
||||||
|
advtrains.path_invalidate_ahead(train, index, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function advtrains.invalidate_path(id)
|
function advtrains.invalidate_path(id)
|
||||||
--atdebug("Path invalidate:",id)
|
--atdebug("Path invalidate:",id)
|
||||||
local v=advtrains.trains[id]
|
local v=advtrains.trains[id]
|
||||||
|
@ -224,17 +224,17 @@ function advtrains.interlocking.signal_on_aspect_changed(pos)
|
|||||||
if not ipts then return end
|
if not ipts then return end
|
||||||
local ipos = minetest.string_to_pos(ipts)
|
local ipos = minetest.string_to_pos(ipts)
|
||||||
|
|
||||||
local tns = advtrains.occ.get_trains_over(ipos)
|
advtrains.invalidate_all_paths_ahead(ipos)
|
||||||
for id, sidx in pairs(tns) do
|
|
||||||
-- local train = advtrains.trains[id]
|
|
||||||
--if train.index <= sidx then
|
|
||||||
minetest.after(0, advtrains.invalidate_path, id)
|
|
||||||
--end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack, pointed_thing)
|
function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack, pointed_thing)
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
|
local control = player:get_player_control()
|
||||||
|
if control.aux1 then
|
||||||
|
advtrains.interlocking.show_ip_form(pos, pname)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
|
local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
|
||||||
if sigd then
|
if sigd then
|
||||||
advtrains.interlocking.show_signalling_form(sigd, pname)
|
advtrains.interlocking.show_signalling_form(sigd, pname)
|
||||||
@ -243,7 +243,7 @@ function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack,
|
|||||||
if ndef.advtrains and ndef.advtrains.set_aspect then
|
if ndef.advtrains and ndef.advtrains.set_aspect then
|
||||||
-- permit to set aspect manually
|
-- permit to set aspect manually
|
||||||
local function callback(pname, aspect)
|
local function callback(pname, aspect)
|
||||||
ndef.advtrains.set_aspect(pos, node, aspect)
|
advtrains.interlocking.signal_set_aspect(pos, aspect)
|
||||||
end
|
end
|
||||||
local isasp = ndef.advtrains.get_aspect(pos, node)
|
local isasp = ndef.advtrains.get_aspect(pos, node)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user