Fix working of the legacy signals under new system

This commit is contained in:
orwell 2024-05-24 00:00:12 +02:00
parent eb02971153
commit f52653209a
6 changed files with 55 additions and 177 deletions

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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,
})

View File

@ -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")

View File

@ -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