From: Mikko Rasa Date: Tue, 8 Apr 2014 18:47:07 +0000 (+0300) Subject: Display blinking red markers on blocks where emergencies have occurred X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=dabab2f3bfb5c8548b9c36f3fe40065563653990;p=r2c2.git Display blinking red markers on blocks where emergencies have occurred --- diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index cc604d3..aa82dcb 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -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 &blocks = layout.get_all(); @@ -174,11 +179,20 @@ void Engineer::tick() for(list::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::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(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::iterator i=emergencies.begin(); i!=emergencies.end(); ++i) + delete *i; + emergencies.clear(); + } } void Engineer::locomotive_detected(const Driver::DetectedLocomotive &loco) diff --git a/source/engineer/engineer.h b/source/engineer/engineer.h index 7cf1cfc..0769473 100644 --- a/source/engineer/engineer.h +++ b/source/engineer/engineer.h @@ -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 train_views; Msp::Time::TimeStamp status_timeout; R2C2::Vector pointer; + std::list 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 &);