X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fengineer.cpp;h=581a301d8f194df79574671c15e95d165e4714c0;hb=3df8cb5c78fbb0b919bcb79677c6c788b8028482;hp=dc7c49c1ffed44f287b508ce54b0971e7f314e0f;hpb=3e9c210ddc036cd015228504cc0803c909e27f84;p=r2c2.git diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index dc7c49c..581a301 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of the MSP Märklin suite -Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -10,6 +10,7 @@ Distributed under the GPL #include #include #include +#include #include #include #include @@ -19,6 +20,7 @@ Distributed under the GPL #include #include #include +#include "libmarklin/tracktype.h" #include "engineer.h" #include "mainpanel.h" #include "trainpanel.h" @@ -28,8 +30,6 @@ using namespace std; using namespace Marklin; using namespace Msp; -#include - Engineer::Engineer(int argc, char **argv): screen_w(1280), screen_h(960), @@ -83,10 +83,12 @@ Engineer::Engineer(int argc, char **argv): const vector &args=getopt.get_args(); if(args.empty()) throw UsageError("No layout given"); - layout.load(args.front()); + DataFile::load(layout, args.front()); trfc_mgr=new TrafficManager(control, layout); trfc_mgr->signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved)); + if(FS::exists("engineer.state")) + DataFile::load(*trfc_mgr, "engineer.state"); const map &sensors=control.get_sensors(); for(map::const_iterator i=sensors.begin(); i!=sensors.end(); ++i) @@ -97,6 +99,7 @@ Engineer::Engineer(int argc, char **argv): Engineer::~Engineer() { + trfc_mgr->save("engineer.state"); delete trfc_mgr; } @@ -162,7 +165,7 @@ int Engineer::main() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - DataFile::load(ui_res, "engineer.res"); + DataFile::load(ui_res, "marklin.res"); root=new GLtk::Root(ui_res, *wnd); root->set_visible(true); @@ -178,6 +181,18 @@ int Engineer::main() main_panel->set_position(0, screen_h-main_panel->get_geometry().h); main_panel->set_visible(true); + const list &trains=trfc_mgr->get_trains(); + int y=main_panel->get_geometry().y; + for(list::const_iterator i=trains.begin(); i!=trains.end(); ++i) + { + TrainPanel *tpanel=new TrainPanel(*this, ui_res, **i); + root->add(*tpanel); + tpanel->set_position(0, y-tpanel->get_geometry().h); + train_panels.push_back(tpanel); + tpanel->set_visible(true); + y-=tpanel->get_geometry().h; + } + wnd->show(); Application::main(); @@ -262,6 +277,28 @@ void Engineer::tick() GL::pop_matrix(); } + const list &trains=trfc_mgr->get_trains(); + for(list::const_iterator i=trains.begin(); i!=trains.end(); ++i) + { + GL::PushMatrix _push; + + const Point &tp=(*i)->get_position(); + GL::translate(tp.x, tp.y, 0.02); + GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2)); + imm.color(0.8f, 0.8f, 1.0f); + imm.begin(GL::TRIANGLE_FAN); + imm.vertex(0, 0); + for(unsigned j=0; j<=12; ++j) + imm.vertex(0.02*cos(j*M_PI/6), 0.02*sin(j*M_PI/6)); + imm.end(); + + GL::rotate(cam_rot*180/M_PI, 0, 0, 1); + GL::translate(0.03, -0.02, 0); + GL::scale_uniform(0.04); + ui_res.get_default_font().draw_string((*i)->get_name()); + GL::Texture::unbind(); + } + GL::matrix_mode(GL::PROJECTION); GL::load_identity(); GL::ortho_bottomleft(screen_w, screen_h); @@ -315,7 +352,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) if(unsigned tid=track->get_track().get_turnout_id()) { Turnout &turnout=control.get_turnout(tid); - turnout.set_route(1-turnout.get_route()); + turnout.set_route((turnout.get_route()+1)%track->get_track().get_type().get_n_routes()); } else if(simulate) {