From: Mikko Rasa Date: Wed, 30 Oct 2013 22:19:40 +0000 (+0200) Subject: Turnout handling fixes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=695f7651bf45b3991ddbab5efe4c2213dbd76f07;p=r2c2.git 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. --- 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;