X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fengineer.cpp;h=6a35a06a3317992dae0075dece5eecfe72e43ddd;hb=446fa7ad737b431621be53a23360ea3bbe417fe5;hp=2c4e7263b4da113e3b304ab529e8229e5b47cebd;hpb=e375f8bf215058398795be1010ffec89d0150114;p=r2c2.git diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 2c4e726..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,13 +107,28 @@ 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; + delete server; } void Engineer::place_train(Train &train) @@ -175,10 +192,15 @@ 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(); + delete root; delete glc; delete wnd; delete dpy; @@ -227,10 +249,10 @@ void Engineer::tick() if(track.get_turnout_id()) { Turnout &trnt = control.get_turnout(track.get_turnout_id()); - (*i)->render_route(trnt.get_route()); + (*i)->render_path(trnt.get_path()); } else - (*i)->render_route(-1); + (*i)->render_path(-1); } if(placing_train && placing_block) @@ -263,10 +285,13 @@ 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(); - GL::translate(tp.x, tp.y, 0.02); + GL::translate(tp.x, tp.y, tp.z+0.02); GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2)); imm.color(0.8f, 0.8f, 1.0f); imm.begin(GL::TRIANGLE_FAN); @@ -305,7 +330,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) { set_block_color(*placing_block, GL::Color(1, 1, 1)); - placing_train->place(placing_block, placing_entry); + placing_train->place(*placing_block, placing_entry); placing_train = 0; main_panel->set_status_text(string()); } @@ -325,7 +350,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) Turnout &turnout = control.get_turnout(tid); try { - turnout.set_route((turnout.get_route()+1)%track->get_track().get_type().get_n_routes()); + turnout.set_path((turnout.get_path()+1)%track->get_track().get_type().get_n_paths()); main_panel->set_status_text(format("Turnout %d switched", turnout.get_address())); } catch(const TurnoutBusy &e) @@ -492,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;