aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell <orwell@bleipb.de>2024-05-24 00:00:12 +0200
committerorwell <orwell@bleipb.de>2024-05-24 00:00:12 +0200
commitf52653209aecb2310c1fb9598391c86113296f27 (patch)
tree2fba34771edf587e21a666ec0c59fce3d03ca937
parenteb029711534006f73624a64c30f7a8597209ceec (diff)
downloadadvtrains-f52653209aecb2310c1fb9598391c86113296f27.tar.gz
advtrains-f52653209aecb2310c1fb9598391c86113296f27.tar.bz2
advtrains-f52653209aecb2310c1fb9598391c86113296f27.zip
Fix working of the legacy signals under new system
-rw-r--r--advtrains/passive.lua6
-rw-r--r--advtrains/signals.lua111
-rw-r--r--advtrains_interlocking/database.lua2
-rw-r--r--advtrains_interlocking/demosignals.lua97
-rw-r--r--advtrains_interlocking/init.lua1
-rw-r--r--advtrains_interlocking/signal_api.lua15
6 files changed, 55 insertions, 177 deletions
diff --git a/advtrains/passive.lua b/advtrains/passive.lua
index 37b79e4..aad309e 100644
--- a/advtrains/passive.lua
+++ b/advtrains/passive.lua
@@ -70,6 +70,12 @@ function advtrains.setstate(parpos, newstate, pnode)
end
-- invalidate paths (only relevant if this is a track)
advtrains.invalidate_all_paths(pos)
+ -- hack for old signals. Compatibility only, DO NOT USE for new signals!
+ if advtrains.interlocking and ndef.advtrains._is_passivenode_signal then
+ -- forcefully clears any set aspect, so that aspect system doesnt override it again
+ -- implicitly does an signal.notify_trains(pos)
+ advtrains.interlocking.signal.clear_aspect(pos)
+ end
return true
end
diff --git a/advtrains/signals.lua b/advtrains/signals.lua
index 58d28a5..0b874bf 100644
--- a/advtrains/signals.lua
+++ b/advtrains/signals.lua
@@ -5,13 +5,13 @@ local mrules_wallsignal = advtrains.meseconrules
local function can_dig_func(pos)
if advtrains.interlocking then
- return advtrains.interlocking.signal_can_dig(pos)
+ return advtrains.interlocking.signal.can_dig(pos)
end
return true
end
local function after_dig_func(pos)
if advtrains.interlocking then
- return advtrains.interlocking.signal_after_dig(pos)
+ return advtrains.interlocking.signal.after_dig(pos)
end
return true
end
@@ -26,18 +26,20 @@ return {
}
end
-local suppasp = {
- main = {0, -1},
- dst = {false},
- shunt = nil,
- proceed_as_main = true,
- info = {
- call_on = false,
- dead_end = false,
- w_speed = nil,
- }
+local main_aspects = {
+ { name = "free", description = "Free" }
}
+local function simple_apply_aspect(offname, onname)
+ return function(pos, node, main_aspect, rem_aspect, rem_aspinfo)
+ if main_aspect.halt then
+ advtrains.ndb.swap_node(pos, {name = offname, param2 = node.param2})
+ else
+ advtrains.ndb.swap_node(pos, {name = onname, param2 = node.param2})
+ end
+ end
+end
+
for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do
for rotid, rotation in ipairs({"", "_30", "_45", "_60"}) do
@@ -71,7 +73,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
["action_"..f.as] = function (pos, node)
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true)
if advtrains.interlocking then
- advtrains.interlocking.signal_on_aspect_changed(pos)
+ -- forcefully clears any set aspect, so that aspect system doesnt override it again
+ -- implicitly does an signal.notify_trains(pos)
+ advtrains.interlocking.signal.clear_aspect(pos)
end
end
}},
@@ -85,23 +89,17 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true)
if advtrains.interlocking then
- advtrains.interlocking.signal_on_aspect_changed(pos)
+ -- forcefully clears any set aspect, so that aspect system doesnt override it again
+ -- implicitly does an signal.notify_trains(pos)
+ advtrains.interlocking.signal.clear_aspect(pos)
end
end
end,
- -- new signal API
+ -- very new signal API
advtrains = {
- set_aspect = function(pos, node, asp)
- if asp.main ~= 0 then
- advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_on"..rotation, param2 = node.param2}, true)
- else
- advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_off"..rotation, param2 = node.param2}, true)
- end
- end,
- get_aspect = function(pos, node)
- return aspect(r=="on")
- end,
- supported_aspects = suppasp,
+ main_aspects = main_aspects,
+ apply_aspect = simple_apply_aspect("advtrains:retrosignal_off"..rotation, "advtrains:retrosignal_on"..rotation),
+ get_aspect_info = function() return aspect(r=="on") end,
},
can_dig = can_dig_func,
after_dig_node = after_dig_func,
@@ -136,7 +134,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
["action_"..f.as] = function (pos, node)
advtrains.setstate(pos, f.als, node)
if advtrains.interlocking then
- advtrains.interlocking.signal_on_aspect_changed(pos)
+ advtrains.interlocking.signal.notify_on_aspect_changed(pos)
end
end
}},
@@ -149,30 +147,16 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
advtrains.interlocking.show_ip_form(pos, pname)
elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
advtrains.setstate(pos, f.als, node)
- if advtrains.interlocking then
- advtrains.interlocking.signal_on_aspect_changed(pos)
- end
end
end,
- -- new signal API
+ -- very new signal API
advtrains = {
- set_aspect = function(pos, node, asp)
- if asp.main ~= 0 then
- advtrains.ndb.swap_node(pos, {name = "advtrains:signal_on"..rotation, param2 = node.param2}, true)
- else
- advtrains.ndb.swap_node(pos, {name = "advtrains:signal_off"..rotation, param2 = node.param2}, true)
- end
- end,
- get_aspect = function(pos, node)
- return aspect(r=="on")
- end,
- supported_aspects = suppasp,
- getstate = f.ls,
- setstate = function(pos, node, newstate)
- if newstate == f.als then
- advtrains.ndb.swap_node(pos, {name = "advtrains:signal_"..f.as..rotation, param2 = node.param2}, true)
- end
- end,
+ main_aspects = main_aspects,
+ apply_aspect = simple_apply_aspect("advtrains:signal_off"..rotation, "advtrains:signal_on"..rotation),
+ get_aspect_info = function() return aspect(r=="on") end,
+ node_state = f.ls,
+ node_state_map = { red = "advtrains:signal_off"..rotation, green = "advtrains:signal_on"..rotation},
+ _is_passivenode_signal = true
},
can_dig = can_dig_func,
after_dig_node = after_dig_func,
@@ -211,9 +195,6 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
rules = mrules_wallsignal,
["action_"..f.as] = function (pos, node)
advtrains.setstate(pos, f.als, node)
- if advtrains.interlocking then
- advtrains.interlocking.signal_on_aspect_changed(pos)
- end
end
}},
on_rightclick=function(pos, node, player)
@@ -225,30 +206,16 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
advtrains.interlocking.show_ip_form(pos, pname)
elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
advtrains.setstate(pos, f.als, node)
- if advtrains.interlocking then
- advtrains.interlocking.signal_on_aspect_changed(pos)
- end
end
end,
- -- new signal API
+ -- very new signal API
advtrains = {
- set_aspect = function(pos, node, asp)
- if asp.main ~= 0 then
- advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_on", param2 = node.param2}, true)
- else
- advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_off", param2 = node.param2}, true)
- end
- end,
- get_aspect = function(pos, node)
- return aspect(r=="on")
- end,
- supported_aspects = suppasp,
- getstate = f.ls,
- setstate = function(pos, node, newstate)
- if newstate == f.als then
- advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_"..f.as, param2 = node.param2}, true)
- end
- end,
+ main_aspects = main_aspects,
+ apply_aspect = simple_apply_aspect("advtrains:signal_wall_"..loc.."_off", "advtrains:signal_wall_"..loc.."_on"),
+ get_aspect_info = function() return aspect(r=="on") end,
+ node_state = f.ls,
+ node_state_map = { red = "advtrains:signal_wall_"..loc.."_off", green = "advtrains:signal_wall_"..loc.."_on" },
+ _is_passivenode_signal = true
},
can_dig = can_dig_func,
after_dig_node = after_dig_func,
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua
index e2df547..49ca13d 100644
--- a/advtrains_interlocking/database.lua
+++ b/advtrains_interlocking/database.lua
@@ -1006,7 +1006,7 @@ end
function ildb.get_ip_signal_asp(pts, connid)
local p = ildb.get_ip_signal(pts, connid)
if p then
- local asp = advtrains.interlocking.signal.get_aspect(p)
+ local asp = advtrains.interlocking.signal.get_aspect_info(p)
if not asp then
atlog("Clearing orphaned signal influence point", pts, "/", connid)
ildb.clear_ip_signal(pts, connid)
diff --git a/advtrains_interlocking/demosignals.lua b/advtrains_interlocking/demosignals.lua
deleted file mode 100644
index de6926a..0000000
--- a/advtrains_interlocking/demosignals.lua
+++ /dev/null
@@ -1,97 +0,0 @@
--- Demonstration signals
--- Those can display the 3 main aspects of Ks signals
-
--- Note that the group value of advtrains_signal is 2, which means "step 2 of signal capabilities"
--- advtrains_signal=1 is meant for signals that do not implement set_aspect.
-
-
-local setaspect = function(pos, node, asp)
- if asp.main == 0 then
- advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_danger"})
- else
- if asp.dst ~= 0 and asp.main == -1 then
- advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"})
- else
- advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_slow"})
- end
- end
- local meta = minetest.get_meta(pos)
- if meta then
- meta:set_string("infotext", minetest.serialize(asp))
- end
-end
-
-local suppasp = {
- main = {0, 6, -1},
- dst = {0, false},
- shunt = false,
- proceed_as_main = true,
- info = {
- call_on = false,
- dead_end = false,
- w_speed = nil,
- }
-}
-
-minetest.register_node("advtrains_interlocking:ds_danger", {
- description = "Demo signal at Danger",
- tiles = {"at_il_signal_asp_danger.png"},
- groups = {
- cracky = 3,
- advtrains_signal = 2,
- save_in_at_nodedb = 1,
- },
- advtrains = {
- set_aspect = setaspect,
- supported_aspects = suppasp,
- get_aspect = function(pos, node)
- return advtrains.interlocking.DANGER
- end,
- },
- on_rightclick = advtrains.interlocking.signal_rc_handler,
- can_dig = advtrains.interlocking.signal_can_dig,
- after_destruct = advtrains.interlocking.signal_after_dig,
-})
-minetest.register_node("advtrains_interlocking:ds_free", {
- description = "Demo signal at Free",
- tiles = {"at_il_signal_asp_free.png"},
- groups = {
- cracky = 3,
- advtrains_signal = 2,
- save_in_at_nodedb = 1,
- },
- advtrains = {
- set_aspect = setaspect,
- supported_aspects = suppasp,
- get_aspect = function(pos, node)
- return {
- main = -1,
- }
- end,
- },
- on_rightclick = advtrains.interlocking.signal_rc_handler,
- can_dig = advtrains.interlocking.signal_can_dig,
- after_destruct = advtrains.interlocking.signal_after_dig,
-})
-minetest.register_node("advtrains_interlocking:ds_slow", {
- description = "Demo signal at Slow",
- tiles = {"at_il_signal_asp_slow.png"},
- groups = {
- cracky = 3,
- advtrains_signal = 2,
- save_in_at_nodedb = 1,
- },
- advtrains = {
- set_aspect = setaspect,
- supported_aspects = suppasp,
- get_aspect = function(pos, node)
- return {
- main = 6,
- }
- end,
- },
- on_rightclick = advtrains.interlocking.signal_rc_handler,
- can_dig = advtrains.interlocking.signal_can_dig,
- after_destruct = advtrains.interlocking.signal_after_dig,
-})
-
diff --git a/advtrains_interlocking/init.lua b/advtrains_interlocking/init.lua
index c397aa6..a4ddbad 100644
--- a/advtrains_interlocking/init.lua
+++ b/advtrains_interlocking/init.lua
@@ -17,7 +17,6 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) .. DIR_DELI
dofile(modpath.."database.lua")
dofile(modpath.."signal_api.lua")
dofile(modpath.."signal_aspect_ui.lua")
-dofile(modpath.."demosignals.lua")
dofile(modpath.."train_sections.lua")
dofile(modpath.."route_prog.lua")
dofile(modpath.."routesetting.lua")
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index 7826d30..6f52816 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -272,14 +272,14 @@ local function cache_mainaspects(ndefat)
end
function signal.get_aspect_internal(pos, aspt)
- if not aspt then
- -- oh, no main aspect, nevermind
- return signal.MASP_HALT, nil, nil
- end
atdebug("get_aspect_internal",pos,aspt)
-- look aspect in nodedef
local node = advtrains.ndb.get_node_or_nil(pos)
local ndef = node and minetest.registered_nodes[node.name]
+ if not aspt then
+ -- oh, no main aspect, nevermind
+ return signal.MASP_HALT, nil, node, ndef
+ end
local ndefat = ndef and ndef.advtrains
if ndefat and ndefat.apply_aspect then
-- only if signal defines main aspect and its set in aspt
@@ -318,7 +318,9 @@ function signal.get_aspect_info(pos)
local masp, remote, node, ndef = signal.get_aspect_internal(pos, aspt)
-- call into ndef
if ndef.advtrains and ndef.advtrains.get_aspect_info then
- return ndef.advtrains.get_aspect_info(pos, masp)
+ local ai = ndef.advtrains.get_aspect_info(pos, masp)
+ atdebug(pos,"aspectinfo",ai)
+ return ai
end
end
@@ -333,11 +335,12 @@ function signal.reapply_aspect(pts)
-- get aspt
local aspt = signal.aspects[pts]
atdebug("reapply_aspect",advtrains.decode_pos(pts),"aspt",aspt)
+ local pos = advtrains.decode_pos(pts)
if not aspt then
+ signal.notify_trains(pos)
return -- oop, nothing to do
end
-- resolve mainaspect table by name
- local pos = advtrains.decode_pos(pts)
local masp, remote, node, ndef = signal.get_aspect_internal(pos, aspt)
-- if we have remote, resolve remote
local rem_masp, rem_aspi