Reduce number of set_aspect calls

This commit is contained in:
Y. Wang 2022-07-03 15:34:42 +02:00
parent 875968f078
commit 4a3d442601
No known key found for this signature in database
GPG Key ID: 54A05DDF18D7A0EB
4 changed files with 15 additions and 12 deletions

View File

@ -62,7 +62,7 @@ local function unassign_all(pos, force)
unassign_dst(pos, force)
end
local function assign(main, dst, by)
local function assign(main, dst, by, skip_update)
local pts_main = pts(main)
local pts_dst = pts(dst)
local t = db_distant[pts_main]
@ -76,7 +76,9 @@ local function assign(main, dst, by)
unassign_dst(dst, true)
t[pts_dst] = by
db_distant_of[pts_dst] = {pts_main, by}
update_dst(dst)
if not skip_update then
update_dst(dst)
end
end
local function pre_occupy(dst, by)

View File

@ -115,8 +115,7 @@ function ilrs.set_route(signal, route, try)
c_tcbs.route_committed = true
c_tcbs.aspect = route.aspect or advtrains.interlocking.FULL_FREE
c_tcbs.route_origin = signal
advtrains.interlocking.update_signal_aspect(c_tcbs)
signals[#signals+1] = c_tcbs.signal
signals[#signals+1] = c_tcbs
end
end
-- advance
@ -136,11 +135,13 @@ function ilrs.set_route(signal, route, try)
end
for i = #signals, 1, -1 do
if lastsig then
local pos = signals[i]
local tcbs = signals[i]
local pos = tcbs.signal
local _, assigned_by = advtrains.distant.get_main(pos)
if not assigned_by or assigned_by == "routesetting" then
advtrains.distant.assign(lastsig, signals[i], "routesetting")
advtrains.distant.assign(lastsig, pos, "routesetting", true)
end
advtrains.interlocking.update_signal_aspect(tcbs, i ~= 1)
end
end
@ -250,14 +251,14 @@ function ilrs.cancel_route_from(sigd)
c_tcbs.route_auto = nil
c_tcbs.route_origin = nil
advtrains.interlocking.update_signal_aspect(c_tcbs)
if c_tcbs.signal then
local pos = c_tcbs.signal
local _, assigned_by = advtrains.distant.get_main(pos)
if assigned_by == "routesetting" then
advtrains.distant.unassign_dst(pos)
advtrains.distant.unassign_dst(pos, true)
end
end
advtrains.interlocking.update_signal_aspect(c_tcbs)
c_ts_id = c_tcbs.ts_id
if not c_tcbs then

View File

@ -204,10 +204,10 @@ local function convert_aspect_if_necessary(asp)
end
advtrains.interlocking.signal_convert_aspect_if_necessary = convert_aspect_if_necessary
function advtrains.interlocking.update_signal_aspect(tcbs)
function advtrains.interlocking.update_signal_aspect(tcbs, skipdst)
if tcbs.signal then
local asp = tcbs.aspect or DANGER
advtrains.interlocking.signal_set_aspect(tcbs.signal, asp)
advtrains.interlocking.signal_set_aspect(tcbs.signal, asp, skipdst)
end
end

View File

@ -95,7 +95,7 @@ get_aspect = function(pos)
return asp
end
local function set_aspect(pos, asp)
local function set_aspect(pos, asp, skipdst)
local node = N.get_node(pos)
local ndef = minetest.registered_nodes[node.name]
if ndef and ndef.advtrains and ndef.advtrains.set_aspect then
@ -105,7 +105,7 @@ local function set_aspect(pos, asp)
ndef.advtrains.set_aspect(pos, node, aspval)
I.signal_on_aspect_changed(pos)
local aspect_changed = A.not_equalp(oldasp, newasp)
if aspect_changed then
if (not skipdst) and aspect_changed then
D.update_main(pos)
end
end