]> git.tdb.fi Git - r2c2.git/commitdiff
Display blinking red markers on blocks where emergencies have occurred
authorMikko Rasa <tdb@tdb.fi>
Tue, 8 Apr 2014 18:47:07 +0000 (21:47 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 8 Apr 2014 18:47:07 +0000 (21:47 +0300)
source/engineer/engineer.cpp
source/engineer/engineer.h

index cc604d3254bf747a150035b5b2c6dd52255d579e..aa82dcb66b0b50475dfa16b87dbf3c23ee34969f 100644 (file)
@@ -45,7 +45,8 @@ Engineer::Engineer(int argc, char **argv):
        layout(catalogue, (options.driver.empty() ? 0 : Driver::create(options.driver))),
        layout_3d(layout),
        server(0),
-       main_view(layout_3d, window.get_width(), window.get_height())
+       main_view(layout_3d, window.get_width(), window.get_height()),
+       emergency_blink_state(0)
 {
        // Setup GUI
        window.set_title("Railroad Engineer");
@@ -75,7 +76,11 @@ Engineer::Engineer(int argc, char **argv):
        DataFile::load(layout, options.layout_fn);
 
        if(layout.has_driver())
-               layout.get_driver().signal_locomotive_detected.connect(sigc::mem_fun(this, &Engineer::locomotive_detected));
+       {
+               Driver &driver = layout.get_driver();
+               driver.signal_locomotive_detected.connect(sigc::mem_fun(this, &Engineer::locomotive_detected));
+               driver.signal_halt.connect(sigc::mem_fun(this, &Engineer::halt_event));
+       }
        layout.signal_train_added.connect(sigc::mem_fun(this, &Engineer::train_added));
        layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::emergency));
        const set<Block *> &blocks = layout.get_all<Block>();
@@ -174,11 +179,20 @@ void Engineer::tick()
        for(list<TrainView *>::iterator i=train_views.begin(); i!=train_views.end(); ++i)
                (*i)->prepare();
 
-       if(status_timeout && Time::now()>status_timeout)
+       Time::TimeStamp t = Time::now();
+       if(status_timeout && t>status_timeout)
        {
                main_wnd->set_status_text(string());
                status_timeout = Time::TimeStamp();
        }
+       if(!emergencies.empty() && t>emergency_blink_timeout)
+       {
+               emergency_blink_state = (emergency_blink_state+1)%2;
+               GL::Color color(1.0f/(1+emergency_blink_state), 0.0f, 0.0f);
+               for(list<TrackChain3D *>::iterator i=emergencies.begin(); i!=emergencies.end(); ++i)
+                       (*i)->set_color(color);
+               emergency_blink_timeout = t+0.5*Time::sec;
+       }
 
        GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
 
@@ -299,9 +313,22 @@ Object *Engineer::pick_object(const Vector &p)
        return layout.pick<Track>(Ray(start, Vector(ray)));
 }
 
-void Engineer::emergency(Block *, const string &msg)
+void Engineer::emergency(Block *block, const string &msg)
 {
        set_status(msg);
+       TrackChain3D *tch3d = new TrackChain3D(layout_3d, *block);
+       tch3d->set_color(GL::Color(1.0f, 0.0f, 0.0f));
+       emergencies.push_back(tch3d);
+}
+
+void Engineer::halt_event(bool h)
+{
+       if(!h)
+       {
+               for(list<TrackChain3D *>::iterator i=emergencies.begin(); i!=emergencies.end(); ++i)
+                       delete *i;
+               emergencies.clear();
+       }
 }
 
 void Engineer::locomotive_detected(const Driver::DetectedLocomotive &loco)
index 7cf1cfcf475377bafc3a886e6cddee368997681f..0769473a786e45e639c544c0b7478bf7d9205c94 100644 (file)
@@ -15,6 +15,7 @@
 #include "3d/layout.h"
 #include "3d/overlay.h"
 #include "3d/path.h"
+#include "3d/trackchain.h"
 #include "3d/view.h"
 #include "network/server.h"
 #include "options.h"
@@ -50,6 +51,9 @@ private:
        std::list<TrainView *> train_views;
        Msp::Time::TimeStamp status_timeout;
        R2C2::Vector pointer;
+       std::list<R2C2::TrackChain3D *> emergencies;
+       Msp::Time::TimeStamp emergency_blink_timeout;
+       unsigned emergency_blink_state;
 
 public:
        Engineer(int argc, char **argv);
@@ -73,6 +77,7 @@ private:
        void view_all();
        R2C2::Object *pick_object(const R2C2::Vector &);
        void emergency(R2C2::Block *, const std::string &);
+       void halt_event(bool);
        void locomotive_detected(const R2C2::Driver::DetectedLocomotive &);
        void import_finished(int);
        void train_added(R2C2::Train &);