aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-10-10 22:41:59 +0200
committerorwell96 <orwell@bleipb.de>2018-10-10 22:41:59 +0200
commit842a85606e4495dd631c2916d09a760d74a0ce13 (patch)
treef28bb815ecd01681f98166578c659aef48082b2a /advtrains_interlocking
parent33c839b40d48e154f5b03619a9bdce1bed1fc602 (diff)
downloadadvtrains-842a85606e4495dd631c2916d09a760d74a0ce13.tar.gz
advtrains-842a85606e4495dd631c2916d09a760d74a0ce13.tar.bz2
advtrains-842a85606e4495dd631c2916d09a760d74a0ce13.zip
Properly implement invalidate_all_paths, recheck lzb on aspect change
Diffstat (limited to 'advtrains_interlocking')
-rw-r--r--advtrains_interlocking/database.lua5
-rw-r--r--advtrains_interlocking/lzb.lua12
-rw-r--r--advtrains_interlocking/signal_api.lua31
3 files changed, 45 insertions, 3 deletions
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua
index af90880..a2df111 100644
--- a/advtrains_interlocking/database.lua
+++ b/advtrains_interlocking/database.lua
@@ -105,6 +105,7 @@ local signal_assignments = {}
-- track+direction -> signal position
local influence_points = {}
+
function ildb.load(data)
if not data then return end
if data.tcbs then
@@ -119,6 +120,9 @@ function ildb.load(data)
if data.rs_locks then
advtrains.interlocking.route.rte_locks = data.rs_locks
end
+ if data.rs_callbacks then
+ advtrains.interlocking.route.rte_callbacks = data.rs_callbacks
+ end
if data.influence_points then
influence_points = data.influence_points
end
@@ -130,6 +134,7 @@ function ildb.save()
ts=track_sections,
signalass = signal_assignments,
rs_locks = advtrains.interlocking.route.rte_locks,
+ rs_callbacks = advtrains.interlocking.route.rte_callbacks,
influence_points = influence_points,
}
end
diff --git a/advtrains_interlocking/lzb.lua b/advtrains_interlocking/lzb.lua
index c9e40ab..8781d40 100644
--- a/advtrains_interlocking/lzb.lua
+++ b/advtrains_interlocking/lzb.lua
@@ -177,14 +177,22 @@ local function apply_control(id, train)
train.ctrl.lzb = nil
end
-
-advtrains.te_register_on_new_path(function(id, train)
+local function invalidate(train)
train.lzb = {
trav = atfloor(train.index),
travsht = train.is_shunt,
oncoming = {}
}
train.ctrl.lzb = nil
+end
+
+function advtrains.interlocking.lzb_invalidate(train)
+ invalidate(train)
+end
+
+
+advtrains.te_register_on_new_path(function(id, train)
+ invalidate(train)
look_ahead(id, train)
end)
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index 90fe1fc..3a042c0 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -66,9 +66,10 @@ advtrains = {
-- The aspect passed in here can always be queried using the
-- advtrains.interlocking.signal_get_supposed_aspect(pos) function.
+ -- It is always DANGER when the signal is not used as route signal.
-- For static signals, this function should be completely omitted
- -- If this function is ommitted, it won't be possible to use
+ -- If this function is omitted, it won't be possible to use
-- route setting on this signal.
end
function get_aspect(pos, node)
@@ -89,6 +90,18 @@ after_dig_node = advtrains.interlocking.signal_after_dig
(If you need to specify custom can_dig or after_dig_node callbacks,
please call those functions anyway!)
+
+Important note: If your signal should support external ways to set its
+aspect (e.g. via mesecons), there are some things that need to be considered:
+- advtrains.interlocking.signal_get_supposed_aspect(pos) won't respect this
+- Whenever you change the signal aspect, and that aspect change
+did not happen through a call to
+advtrains.interlocking.signal_set_aspect(pos, asp), you are
+*required* to call this function:
+advtrains.interlocking.signal_on_aspect_changed(pos)
+in order to notify trains about the aspect change.
+This function will query get_aspect to retrieve the new aspect.
+
]]--
local DANGER = {
@@ -128,6 +141,22 @@ function advtrains.interlocking.signal_set_aspect(pos, asp)
local ndef=minetest.registered_nodes[node.name]
if ndef and ndef.advtrains and ndef.advtrains.set_aspect then
ndef.advtrains.set_aspect(pos, node, asp)
+ advtrains.interlocking.signal_on_aspect_changed(pos)
+ end
+end
+
+-- should be called when aspect has changed on this signal.
+function advtrains.interlocking.signal_on_aspect_changed(pos)
+ local ipts, iconn = advtrains.interlocking.db.get_ip_by_signalpos(pos)
+ if not ipts then return end
+ local ipos = minetest.string_to_pos(ipts)
+
+ local tns = advtrains.occ.get_trains_over(ipos)
+ for id, sidx in pairs(tns) do
+ local train = advtrains.trains[id]
+ if train.index <= sidx then
+ advtrains.interlocking.lzb_invalidate(train)
+ end
end
end