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");
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>();
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);
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)
#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"
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);
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 &);