]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/track.cpp
Turnout handling fixes
[r2c2.git] / source / libr2c2 / track.cpp
index 5da34f692b370c9f5711536e2d0838da78e9f8cb..23f1b9e2b6da280d7179276de2d8e1d1afa1a112 100644 (file)
@@ -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<DataFile::Statement> &st) const
 
 void Track::turnout_event(unsigned addr, unsigned state)
 {
-       if(!turnout_id)
-               return;
-
        if(addr==turnout_id)
        {
                active_path = state;