Add the turnout to driver when acquiring automatic id to avoid a key_error
later when removing it. Don't bother connecting to turnout_event signal
if the track is not actually a turnout.
path_changing(false)
{
if(type.is_turnout())
+ {
turnout_id = layout.allocate_turnout_id();
+ if(layout.has_driver())
+ {
+ Driver &driver = layout.get_driver();
+ driver.add_turnout(turnout_id, type);
+ driver.signal_turnout.connect(sigc::mem_fun(this, &Track::turnout_event));
+ }
+ }
+
layout.add(*this);
- if(layout.has_driver())
- layout.get_driver().signal_turnout.connect(sigc::mem_fun(this, &Track::turnout_event));
for(unsigned paths = type.get_paths(); !(paths&1); ++active_path, paths>>=1) ;
}
void Track::turnout_event(unsigned addr, unsigned state)
{
- if(!turnout_id)
- return;
-
if(addr==turnout_id)
{
active_path = state;