]> git.tdb.fi Git - r2c2.git/commitdiff
Only create track circuits for blocks that need one
authorMikko Rasa <tdb@tdb.fi>
Sun, 7 Jul 2013 20:28:12 +0000 (23:28 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 7 Jul 2013 20:28:12 +0000 (23:28 +0300)
source/engineer/engineer.cpp
source/libr2c2/block.cpp
source/libr2c2/block.h

index 1fb4adf75653a852905aae77bafaff338d15d18e..8c1738eb0603d4e152a20afe7344d5f4e1ba814d 100644 (file)
@@ -74,7 +74,8 @@ Engineer::Engineer(int argc, char **argv):
        layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::set_status));
        const set<Block *> &blocks = layout.get_all<Block>();
        for(set<Block *>::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())
        {
index 2df313e27c1f8c53104c4314908be2391eec7b52..f02762c85a958e668b5b4e200c86bcbb877f0767 100644 (file)
@@ -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);
 }
index 4309290da3f3145a553a405009dc35a4c60b8ad9..558d425016ffe050a937ef47726536229b2b9eee 100644 (file)
@@ -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<Endpoint> &get_endpoints() const { return endpoints; }
        const Endpoint &get_endpoint(unsigned) const;
        int get_endpoint_by_link(Block &) const;