From: Mikko Rasa Date: Sun, 7 Jul 2013 20:28:12 +0000 (+0300) Subject: Only create track circuits for blocks that need one X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=91385545a7d76784a17af421b0def49775be0d4c;p=r2c2.git Only create track circuits for blocks that need one --- diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 1fb4adf..8c1738e 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -74,7 +74,8 @@ Engineer::Engineer(int argc, char **argv): layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::set_status)); const set &blocks = layout.get_all(); for(set::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) - (*i)->get_sensor().signal_state_changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &Engineer::reset_block_color), sigc::ref(**i)))); + if(Sensor *sensor = (*i)->get_sensor()) + sensor->signal_state_changed.connect(sigc::hide(sigc::bind(sigc::mem_fun(this, &Engineer::reset_block_color), sigc::ref(**i)))); if(FS::exists(options.state_fn)) DataFile::load(layout, options.state_fn); @@ -358,7 +359,9 @@ void Engineer::set_block_color(const Block &block, const GL::Color &color) void Engineer::reset_block_color(const Block &block) { - bool active = block.get_sensor().get_state()>Sensor::INACTIVE; + bool active = false; + if(Sensor *sensor = block.get_sensor()) + active = sensor->get_state()>Sensor::INACTIVE; if(block.get_train()) { diff --git a/source/libr2c2/block.cpp b/source/libr2c2/block.cpp index 2df313e..f02762c 100644 --- a/source/libr2c2/block.cpp +++ b/source/libr2c2/block.cpp @@ -18,6 +18,7 @@ Block::Block(Layout &l, Track &start): id(0), sensor_id(start.get_sensor_id()), turnout_id(start.get_turnout_id()), + sensor(0), train(0) { add_track(start); @@ -43,7 +44,8 @@ Block::Block(Layout &l, Track &start): determine_id(); - sensor = new TrackCircuit(layout, *this); + if(sensor_id) + sensor = new TrackCircuit(layout, *this); layout.add(*this); } diff --git a/source/libr2c2/block.h b/source/libr2c2/block.h index 4309290..558d425 100644 --- a/source/libr2c2/block.h +++ b/source/libr2c2/block.h @@ -50,7 +50,7 @@ public: unsigned get_id() const { return id; } unsigned get_sensor_id() const { return sensor_id; } unsigned get_turnout_id() const { return turnout_id; } - TrackCircuit &get_sensor() const { return *sensor; } + TrackCircuit *get_sensor() const { return sensor; } const std::vector &get_endpoints() const { return endpoints; } const Endpoint &get_endpoint(unsigned) const; int get_endpoint_by_link(Block &) const;