aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell <orwell@bleipb.de>2023-12-17 12:20:22 +0100
committerorwell <orwell@bleipb.de>2023-12-17 12:20:22 +0100
commitf8c2ec60d6fe1927b444aae51c3bce075ed05208 (patch)
treeb115901d04496a0a067fd6691f75eff4b41de0af
parentc890d77d639cb032872c7ddd641927980b2967ac (diff)
downloadadvtrains-f8c2ec60d6fe1927b444aae51c3bce075ed05208.tar.gz
advtrains-f8c2ec60d6fe1927b444aae51c3bce075ed05208.tar.bz2
advtrains-f8c2ec60d6fe1927b444aae51c3bce075ed05208.zip
Signals can have nil name, documentation on route def
-rw-r--r--advtrains_interlocking/database.lua29
-rw-r--r--advtrains_interlocking/route_prog.lua20
-rw-r--r--advtrains_interlocking/route_ui.lua2
-rw-r--r--advtrains_interlocking/routesetting.lua2
-rwxr-xr-xadvtrains_interlocking/tcb_ts_ui.lua12
5 files changed, 50 insertions, 15 deletions
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua
index 492326c..5d42309 100644
--- a/advtrains_interlocking/database.lua
+++ b/advtrains_interlocking/database.lua
@@ -178,6 +178,12 @@ TCB data structure
signal_name = <string> -- The human-readable name of the signal, only for documenting purposes
routes = { <route definition> } -- a collection of routes from this signal
route_auto = <boolean> -- When set, we will automatically re-set the route (designated by routeset)
+
+ auto_block_signal_mode = <boolean> -- Simplified mode for simple block signals:
+ -- Signal has only one route which is constantly re-set (route_auto is implied)
+ -- Supposed to be used when only a single track section is ahead and it directly ends at the next signal
+ -- UI only offers to enable or disable the signal
+ -- ARS is implicitly disabled on the signal
},
-- This is the "B" side of the TCB
[2] = { -- Variant: end of track-circuited area (initial state of TC)
@@ -185,6 +191,29 @@ TCB data structure
}
}
+Route definition
+routes = {
+ [i] = {
+ -- one table for each track section on the route
+ -- Note that the section ID is implicitly inferred from the TCB
+ 1 = {
+ locks = { -- component locks for this section of the route. Not used when use_rscache is true.
+ (-16,9,0) = st
+ }
+ next = S[(-23,9,0)/2] -- the start TCB of the next route segment (pointing forward)
+ }
+ 2 = {
+ locks = {}
+ -- if next is omitted, then there is no final TCB (e.g. a buffer)
+ }
+ name = "<the route name>"
+ ars = { <ARS rule definition table> }
+ use_rscache = false -- if true, instead of "locks", the track section's rs_cache will be used to set locks
+ -- Fields used by the autorouter:
+ ar_end_sigd = <sigd> -- the sigd describing the end of the route. Used for merging route options on recalculation
+ }
+}
+
Track section
[id] = {
name = "Some human-readable name"
diff --git a/advtrains_interlocking/route_prog.lua b/advtrains_interlocking/route_prog.lua
index 6abe431..5fd9363 100644
--- a/advtrains_interlocking/route_prog.lua
+++ b/advtrains_interlocking/route_prog.lua
@@ -19,6 +19,11 @@ C. punch a turnout (or some other passive component) to fix its state (toggle)
The route visualization will also be used to visualize routes after they have been programmed.
]]--
+-- TODO duplicate
+local lntrans = { "A", "B" }
+local function sigd_to_string(sigd)
+ return minetest.pos_to_string(sigd.p).." / "..lntrans[sigd.s]
+end
-- table with objectRefs
local markerent = {}
@@ -237,10 +242,10 @@ local function get_last_route_item(origin, route)
return route[#route].next
end
-local function do_advance_route(pname, rp, sigd, tsname)
+local function do_advance_route(pname, rp, sigd, tsref)
table.insert(rp.route, {next = sigd, locks = rp.tmp_lcks})
rp.tmp_lcks = {}
- chat(pname, "Added track section '"..tsname.."' to the route.")
+ chat(pname, "Added track section '"..(tsref and (tsref.name or "") or "--EOI--").."' to the route.")
end
local function finishrpform(pname)
@@ -253,8 +258,9 @@ local function finishrpform(pname)
local term_tcbs = advtrains.interlocking.db.get_tcbs(terminal)
if term_tcbs.signal then
+ local signalname = (term_tcbs.signal_name or "") .. sigd_to_string(terminal)
form = form .. "label[0.5,1.5;Route ends at signal:]"
- form = form .. "label[0.5,2 ;"..term_tcbs.signal_name.."]"
+ form = form .. "label[0.5,2 ;"..signalname.."]"
else
form = form .. "label[0.5,1.5;WARNING: Route does not end at a signal.]"
form = form .. "label[0.5,2 ;Routes should in most cases end at signals.]"
@@ -423,20 +429,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.advance then
-- advance route
if not is_endpoint then
- do_advance_route(pname, rp, this_sigd, this_ts.name)
+ do_advance_route(pname, rp, this_sigd, this_ts)
end
end
if fields.endhere then
if not is_endpoint then
- do_advance_route(pname, rp, this_sigd, this_ts.name)
+ do_advance_route(pname, rp, this_sigd, this_ts)
end
finishrpform(pname)
end
if can_over and fields.endover then
if not is_endpoint then
- do_advance_route(pname, rp, this_sigd, this_ts.name)
+ do_advance_route(pname, rp, this_sigd, this_ts)
end
- do_advance_route(pname, rp, over_sigd, over_ts and over_ts.name or "--EOI--")
+ do_advance_route(pname, rp, over_sigd, over_ts)
finishrpform(pname)
end
end
diff --git a/advtrains_interlocking/route_ui.lua b/advtrains_interlocking/route_ui.lua
index 1999941..a1a331d 100644
--- a/advtrains_interlocking/route_ui.lua
+++ b/advtrains_interlocking/route_ui.lua
@@ -33,7 +33,7 @@ function atil.show_route_edit_form(pname, sigd, routeid)
local function itab(t)
tab[#tab+1] = minetest.formspec_escape(string.gsub(t, ",", " "))
end
- itab("TCB "..sigd_to_string(sigd).." ("..tcbs.signal_name..") Route #"..routeid)
+ itab("TCB "..sigd_to_string(sigd).." ("..(tcbs.signal_name or "")..") Route #"..routeid)
-- this code is partially copy-pasted from routesetting.lua
-- we start at the tc designated by signal
diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua
index 67efaea..ede3d49 100644
--- a/advtrains_interlocking/routesetting.lua
+++ b/advtrains_interlocking/routesetting.lua
@@ -43,7 +43,7 @@ function ilrs.set_route(signal, route, try)
local first = true
local i = 1
local rtename = route.name
- local signalname = ildb.get_tcbs(signal).signal_name
+ local signalname = (ildb.get_tcbs(signal).signal_name or "") .. sigd_to_string(signal)
local c_tcbs, c_ts_id, c_ts, c_rseg, c_lckp
while c_sigd and i<=#route do
c_tcbs = ildb.get_tcbs(c_sigd)
diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua
index 08d1c32..e365f4f 100755
--- a/advtrains_interlocking/tcb_ts_ui.lua
+++ b/advtrains_interlocking/tcb_ts_ui.lua
@@ -188,9 +188,6 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
local tcbs = ildb.get_tcbs(sigd)
if tcbs then
tcbs.signal = pos
- if not tcbs.signal_name then
- tcbs.signal_name = "Signal at "..minetest.pos_to_string(sigd.p)
- end
if not tcbs.routes then
tcbs.routes = {}
end
@@ -580,11 +577,10 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, calle
local tcbs = ildb.get_tcbs(sigd)
if not tcbs.signal then return end
- if not tcbs.signal_name then tcbs.signal_name = "Signal at "..minetest.pos_to_string(sigd.p) end
if not tcbs.routes then tcbs.routes = {} end
local form = "size[7,10]label[0.5,0.5;Signal at "..minetest.pos_to_string(sigd.p).."]"
- form = form.."field[0.8,1.5;5.2,1;name;Signal name;"..minetest.formspec_escape(tcbs.signal_name).."]"
+ form = form.."field[0.8,1.5;5.2,1;name;Signal name;"..minetest.formspec_escape(tcbs.signal_name or "").."]"
form = form.."button[5.5,1.2;1,1;setname;Set]"
if tcbs.routeset then
@@ -717,7 +713,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
sel_rte = tpsi
end
if fields.setname and fields.name and hasprivs then
- tcbs.signal_name = fields.name
+ if fields.name == "" then
+ tcbs.signal_name = nil -- do not save a signal name if it isnt used (equivalent to track sections)
+ else
+ tcbs.signal_name = fields.name
+ end
end
if tcbs.routeset and fields.cancelroute then
if tcbs.routes[tcbs.routeset] and tcbs.routes[tcbs.routeset].ars then