From 695f7651bf45b3991ddbab5efe4c2213dbd76f07 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 31 Oct 2013 00:19:40 +0200 Subject: [PATCH] Turnout handling fixes 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. --- source/libr2c2/track.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index 5da34f6..23f1b9e 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -40,12 +40,19 @@ Track::Track(Layout &l, const TrackType &t): 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) ; } @@ -400,9 +407,6 @@ void Track::save(list &st) const void Track::turnout_event(unsigned addr, unsigned state) { - if(!turnout_id) - return; - if(addr==turnout_id) { active_path = state; -- 2.45.2