X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fengineer.cpp;h=6a35a06a3317992dae0075dece5eecfe72e43ddd;hb=446fa7ad737b431621be53a23360ea3bbe417fe5;hp=7bd0f77d50c7721ca411745595e92fbe247a540b;hpb=03aa7d090507e40f6362cd242d711de4bbba8f18;p=r2c2.git diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 7bd0f77..6a35a06 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -7,6 +7,7 @@ Distributed under the GPL #include #include +#include #include #include #include @@ -17,6 +18,7 @@ Distributed under the GPL #include #include #include +#include #include #include #include @@ -105,10 +107,24 @@ Engineer::Engineer(int argc, char **argv): i->second->signal_state_changed.connect(sigc::bind(sigc::mem_fun(this, &Engineer::sensor_event), i->second)); view_all(); + + catch_signal(SIGINT); + catch_signal(SIGTERM); + catch_signal(SIGSEGV); + catch_signal(SIGILL); + catch_signal(SIGFPE); + catch_signal(SIGABRT); } Engineer::~Engineer() { + const list &trains = trfc_mgr->get_trains(); + for(list::const_iterator i=trains.begin(); i!=trains.end(); ++i) + (*i)->set_speed(0); + + while(control.get_queue_length()) + control.tick(); + if(!simulate) trfc_mgr->save("engineer.state"); delete trfc_mgr; @@ -176,6 +192,10 @@ int Engineer::main() y -= tpanel->get_geometry().h; } + const list &blocks = trfc_mgr->get_blocks(); + for(list::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) + reset_block_color(**i); + wnd->show(); Application::main(); @@ -265,6 +285,9 @@ void Engineer::tick() const list &trains = trfc_mgr->get_trains(); for(list::const_iterator i=trains.begin(); i!=trains.end(); ++i) { + if(!(*i)->is_placed()) + continue; + GL::PushMatrix _push; const Point &tp = (*i)->get_position(); @@ -494,4 +517,20 @@ void Engineer::train_added(Train &train) place_train(train); } +void Engineer::sighandler(int sig) +{ + if(sig==SIGSEGV || sig==SIGILL || sig==SIGFPE || sig==SIGABRT) + { + signal(sig, SIG_DFL); + IO::print(IO::cerr, "Fatal signal received, terminating\n"); + const map &locos = control.get_locomotives(); + for(map::const_iterator i=locos.begin(); i!=locos.end(); ++i) + i->second->set_speed(0); + control.flush(); + raise(sig); + } + else if(sig==SIGTERM || sig==SIGINT) + exit(0); +} + Application::RegApp Engineer::reg;