From 4a3d442601a800e28a274026392461bd1a7cb127 Mon Sep 17 00:00:00 2001 From: "Y. Wang" Date: Sun, 3 Jul 2022 15:34:42 +0200 Subject: Reduce number of set_aspect calls --- advtrains_interlocking/distant.lua | 6 ++++-- advtrains_interlocking/routesetting.lua | 13 +++++++------ advtrains_interlocking/signal_api.lua | 4 ++-- advtrains_interlocking/signal_aspect_accessors.lua | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) (limited to 'advtrains_interlocking') diff --git a/advtrains_interlocking/distant.lua b/advtrains_interlocking/distant.lua index ffa9e08..f62ca36 100644 --- a/advtrains_interlocking/distant.lua +++ b/advtrains_interlocking/distant.lua @@ -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) diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua index 4ce6fd3..857a681 100644 --- a/advtrains_interlocking/routesetting.lua +++ b/advtrains_interlocking/routesetting.lua @@ -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 diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua index eec70f9..1c6ed27 100644 --- a/advtrains_interlocking/signal_api.lua +++ b/advtrains_interlocking/signal_api.lua @@ -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 diff --git a/advtrains_interlocking/signal_aspect_accessors.lua b/advtrains_interlocking/signal_aspect_accessors.lua index bdbb803..e23aa13 100644 --- a/advtrains_interlocking/signal_aspect_accessors.lua +++ b/advtrains_interlocking/signal_aspect_accessors.lua @@ -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 -- cgit v1.2.3