From: Mikko Rasa Date: Wed, 8 Apr 2015 20:11:40 +0000 (+0300) Subject: Proper ID management for Signals X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b36f3dc43853c76b4710cb1a7b932a758e1693a1;p=r2c2.git Proper ID management for Signals --- diff --git a/source/libr2c2/signal.cpp b/source/libr2c2/signal.cpp index 02a07d7..bece13d 100644 --- a/source/libr2c2/signal.cpp +++ b/source/libr2c2/signal.cpp @@ -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(); } } diff --git a/source/libr2c2/signal.h b/source/libr2c2/signal.h index 67aa77e..801a0b1 100644 --- a/source/libr2c2/signal.h +++ b/source/libr2c2/signal.h @@ -30,6 +30,7 @@ public: private: const SignalType &type; unsigned address; + unsigned id; BlockIter block; Train *train; sigc::connection train_conn;