]> git.tdb.fi Git - r2c2.git/commitdiff
Proper ID management for Signals
authorMikko Rasa <tdb@tdb.fi>
Wed, 8 Apr 2015 20:11:40 +0000 (23:11 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 8 Apr 2015 20:11:40 +0000 (23:11 +0300)
source/libr2c2/signal.cpp
source/libr2c2/signal.h

index 02a07d76bc9585861b4c7df0a0954f3060772d7c..bece13d7c6078cd3dac8e300cc0ec5417b33fe89 100644 (file)
@@ -17,6 +17,7 @@ Signal::Signal(Layout &l, const SignalType &t):
        TrackAttachment(l),
        type(t),
        address(0),
+       id(0),
        train(0),
        check_allocated_blocks(false),
        passing(false)
@@ -28,8 +29,8 @@ Signal::Signal(Layout &l, const SignalType &t):
 
 Signal::~Signal()
 {
-       if(layout.has_driver() && address)
-               layout.get_driver().remove_sensor(address);
+       if(layout.has_driver() && id)
+               layout.get_driver().remove_signal(id);
        layout.remove(*this);
 }
 
@@ -45,11 +46,13 @@ void Signal::set_address(unsigned a)
 {
        Driver *driver = (layout.has_driver() ? &layout.get_driver() : 0);
 
-       if(driver && address)
-               driver->remove_signal(address);
+       if(driver && id)
+               driver->remove_signal(id);
        address = a;
        if(driver && address)
-               driver->add_signal(address, type);
+               id = driver->add_signal(address, type);
+       else
+               id = 0;
 }
 
 void Signal::set_position(const Vector &p)
@@ -129,7 +132,7 @@ void Signal::tick(const Time::TimeDelta &)
                                break;
                        }
 
-               layout.get_driver().set_signal(address, aspect);
+               layout.get_driver().set_signal(id, aspect);
        }
 }
 
@@ -152,7 +155,7 @@ void Signal::block_reserved(const Block &b, Train *t)
                }
                else
                {
-                       layout.get_driver().set_signal(address, type.get_indications().back().aspect);
+                       layout.get_driver().set_signal(id, type.get_indications().back().aspect);
                        reset();
                }
        }
@@ -166,7 +169,7 @@ void Signal::train_advanced(Block &b)
                passing = true;
        else if(passing && b.get_sensor_address())
        {
-               layout.get_driver().set_signal(address, type.get_indications().back().aspect);
+               layout.get_driver().set_signal(id, type.get_indications().back().aspect);
                reset();
        }
 }
index 67aa77ee73a0bfa758c26edf7d6a144ffde0d590..801a0b1d6fce596732ddf26309422f7aaab64e34 100644 (file)
@@ -30,6 +30,7 @@ public:
 private:
        const SignalType &type;
        unsigned address;
+       unsigned id;
        BlockIter block;
        Train *train;
        sigc::connection train_conn;