]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/engineer.cpp
Code reformatting: add spaces around assignment operators
[r2c2.git] / source / engineer / engineer.cpp
index 83827c142f61f023a04fb7a005a3012d0c37ad40..08e1466893f209a445c6d69e49c2fe03136209ee 100644 (file)
@@ -46,9 +46,9 @@ Engineer::Engineer(int argc, char **argv):
        simulate(false)
 {
        string res;
-       bool debug=false;
-       string device="/dev/ttyS0";
-       unsigned quality=4;
+       bool debug = false;
+       string device = "/dev/ttyS0";
+       unsigned quality = 4;
 
        GetOpt getopt;
        getopt.add_option('r', "resolution",  res,         GetOpt::REQUIRED_ARG);
@@ -64,8 +64,8 @@ Engineer::Engineer(int argc, char **argv):
        {
                if(RegMatch m=Regex("([1-9][0-9]*)x([1-9][0-9]*)").match(res))
                {
-                       screen_w=lexical_cast<unsigned>(m[1].str);
-                       screen_h=lexical_cast<unsigned>(m[2].str);
+                       screen_w = lexical_cast<unsigned>(m[1].str);
+                       screen_h = lexical_cast<unsigned>(m[2].str);
                }
                else
                        throw UsageError("Invalid resolution");
@@ -81,17 +81,17 @@ Engineer::Engineer(int argc, char **argv):
        DataFile::load(catalogue, "tracks.dat");
        DataFile::load(catalogue, "locos.dat");
 
-       const vector<string> &args=getopt.get_args();
+       const vector<string> &args = getopt.get_args();
        if(args.empty())
                throw UsageError("No layout given");
        DataFile::load(layout, args.front());
 
-       trfc_mgr=new TrafficManager(control, layout);
+       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<unsigned, Sensor *> &sensors=control.get_sensors();
+       const map<unsigned, Sensor *> &sensors = control.get_sensors();
        for(map<unsigned, Sensor *>::const_iterator i=sensors.begin(); i!=sensors.end(); ++i)
                i->second->signal_state_changed.connect(sigc::bind(sigc::mem_fun(this, &Engineer::sensor_event), i->second));
 
@@ -107,24 +107,24 @@ Engineer::~Engineer()
 
 void Engineer::add_train()
 {
-       train_prop=new TrainProperties(*this, ui_res, 0);
+       train_prop = new TrainProperties(*this, ui_res, 0);
        root->add(*train_prop);
        train_prop->signal_ok.connect(sigc::mem_fun(this, &Engineer::dismiss_train_prop));
-       train_prop_stale=false;
+       train_prop_stale = false;
        train_prop->set_visible(true);
 }
 
 Train *Engineer::add_train(const LocoType &type, unsigned addr)
 {
-       Locomotive *loco=new Locomotive(type, control, addr);
-       Train *train=new Train(*trfc_mgr, *loco);
+       Locomotive *loco = new Locomotive(type, control, addr);
+       Train *train = new Train(*trfc_mgr, *loco);
        train->set_name(format("Train %d", trfc_mgr->get_trains().size()));
 
-       TrainPanel *tpanel=new TrainPanel(*this, ui_res, *train);
+       TrainPanel *tpanel = new TrainPanel(*this, ui_res, *train);
        root->add(*tpanel);
-       int y=main_panel->get_geometry().y;
+       int y = main_panel->get_geometry().y;
        for(list<TrainPanel *>::iterator i=train_panels.begin(); i!=train_panels.end(); ++i)
-               y-=(*i)->get_geometry().h;
+               y -= (*i)->get_geometry().h;
        tpanel->set_position(0, y-tpanel->get_geometry().h);
        train_panels.push_back(tpanel);
        tpanel->set_visible(true);
@@ -136,24 +136,24 @@ Train *Engineer::add_train(const LocoType &type, unsigned addr)
 
 void Engineer::place_train(Train &train)
 {
-       placing_train=&train;
-       placing_block=0;
+       placing_train = &train;
+       placing_block = 0;
        main_panel->set_status_text("Select location");
 }
 
 int Engineer::main()
 {
-       dpy=new Graphics::Display;
+       dpy = new Graphics::Display;
 
        Graphics::WindowOptions wopt;
-       wopt.width=screen_w;
-       wopt.height=screen_h;
-       wopt.fullscreen=fullscreen;
-       wnd=new Graphics::Window(*dpy, wopt);
+       wopt.width = screen_w;
+       wopt.height = screen_h;
+       wopt.fullscreen = fullscreen;
+       wnd = new Graphics::Window(*dpy, wopt);
 
        Graphics::GLOptions glopt;
-       //glopt.multisample=4;
-       glc=new Graphics::GLContext(*wnd, glopt);
+       //glopt.multisample = 4;
+       glc = new Graphics::GLContext(*wnd, glopt);
 
        wnd->signal_close.connect(sigc::bind(sigc::mem_fun(this, &Engineer::exit), 0));
        wnd->signal_button_press.connect(sigc::mem_fun(this, &Engineer::button_press));
@@ -168,31 +168,31 @@ int Engineer::main()
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
        DataFile::load(ui_res, "marklin.res");
-       root=new GLtk::Root(ui_res, *wnd);
+       root = new GLtk::Root(ui_res, *wnd);
        root->set_visible(true);
 
-       list<GL::Texture *> texs=ui_res.get_list<GL::Texture>();
+       list<GL::Texture *> texs = ui_res.get_list<GL::Texture>();
        for(list<GL::Texture *>::iterator i=texs.begin(); i!=texs.end(); ++i)
        {
                (*i)->set_min_filter(GL::NEAREST);
                (*i)->set_mag_filter(GL::NEAREST);
        }
 
-       main_panel=new MainPanel(*this, ui_res);
+       main_panel = new MainPanel(*this, ui_res);
        root->add(*main_panel);
        main_panel->set_position(0, screen_h-main_panel->get_geometry().h);
        main_panel->set_visible(true);
 
-       const list<Train *> &trains=trfc_mgr->get_trains();
-       int y=main_panel->get_geometry().y;
+       const list<Train *> &trains = trfc_mgr->get_trains();
+       int y = main_panel->get_geometry().y;
        for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
-               TrainPanel *tpanel=new TrainPanel(*this, ui_res, **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;
+               y -= tpanel->get_geometry().h;
        }
 
        wnd->show();
@@ -225,10 +225,10 @@ void Engineer::tick()
                glEnable(GL_LIGHTING);
                glEnable(GL_LIGHT0);
                float params[4];
-               params[0]=0;
-               params[1]=-0.2;
-               params[2]=1;
-               params[3]=0;
+               params[0] = 0;
+               params[1] = -0.2;
+               params[2] = 1;
+               params[3] = 0;
                glLightfv(GL_LIGHT0, GL_POSITION, params);
        }
 
@@ -239,13 +239,13 @@ void Engineer::tick()
 
        glDisable(GL_LIGHTING);
        glColor4f(1, 1, 1, 1);
-       const list<Track3D *> &ltracks=layout_3d.get_tracks();
+       const list<Track3D *> &ltracks = layout_3d.get_tracks();
        for(list<Track3D *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
        {
-               Track &track=(*i)->get_track();
+               Track &track = (*i)->get_track();
                if(track.get_turnout_id())
                {
-                       Turnout &trnt=control.get_turnout(track.get_turnout_id());
+                       Turnout &trnt = control.get_turnout(track.get_turnout_id());
                        (*i)->render_route(trnt.get_route());
                }
                else
@@ -256,9 +256,9 @@ void Engineer::tick()
        {
                GL::push_matrix();
 
-               const Marklin::Block::Endpoint &bep=placing_block->get_endpoints()[placing_entry];
-               float rot=bep.track->get_endpoint_direction(bep.track_ep);
-               Point pos=bep.track->get_endpoint_position(bep.track_ep);
+               const Marklin::Block::Endpoint &bep = placing_block->get_endpoints()[placing_entry];
+               float rot = bep.track->get_endpoint_direction(bep.track_ep);
+               Point pos = bep.track->get_endpoint_position(bep.track_ep);
 
                GL::translate(pos.x, pos.y, pos.z+0.03);
                GL::rotate(rot*180/M_PI+180, 0, 0, 1);
@@ -279,12 +279,12 @@ void Engineer::tick()
                GL::pop_matrix();
        }
 
-       const list<Train *> &trains=trfc_mgr->get_trains();
+       const list<Train *> &trains = trfc_mgr->get_trains();
        for(list<Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
                GL::PushMatrix _push;
 
-               const Point &tp=(*i)->get_position();
+               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);
@@ -316,7 +316,7 @@ void Engineer::tick()
        if(train_prop_stale)
        {
                delete train_prop;
-               train_prop=0;
+               train_prop = 0;
        }
 
        glc->swap_buffers();
@@ -337,23 +337,23 @@ 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=0;
+                       placing_train = 0;
                        main_panel->set_status_text(string());
                }
                else if(btn==3)
                {
-                       const vector<Block::Endpoint> &endpoints=placing_block->get_endpoints();
-                       placing_entry=(placing_entry+1)%endpoints.size();
+                       const vector<Block::Endpoint> &endpoints = placing_block->get_endpoints();
+                       placing_entry = (placing_entry+1)%endpoints.size();
                }
        }
        else
        {
-               Track3D *track=pick_track(x, screen_h-y-1);
+               Track3D *track = pick_track(x, screen_h-y-1);
                if(track)
                {
                        if(unsigned tid=track->get_track().get_turnout_id())
                        {
-                               Turnout &turnout=control.get_turnout(tid);
+                               Turnout &turnout = control.get_turnout(tid);
                                try
                                {
                                        turnout.set_route((turnout.get_route()+1)%track->get_track().get_type().get_n_routes());
@@ -368,7 +368,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned)
                        {
                                if(unsigned sid=track->get_track().get_sensor_id())
                                {
-                                       Sensor &sensor=control.get_sensor(sid);
+                                       Sensor &sensor = control.get_sensor(sid);
                                        control.signal_sensor_event.emit(sid, !sensor.get_state());
                                }
                        }
@@ -384,16 +384,16 @@ void Engineer::pointer_motion(int x, int y)
 {
        if(placing_train)
        {
-               Track3D *track=pick_track(x, screen_h-y-1);
+               Track3D *track = pick_track(x, screen_h-y-1);
                if(track && placing_train)
                {
-                       Block &block=trfc_mgr->get_block_by_track(track->get_track());
+                       Block &block = trfc_mgr->get_block_by_track(track->get_track());
                        if(&block!=placing_block)
                        {
                                if(placing_block)
                                        reset_block_color(*placing_block);
-                               placing_block=&block;
-                               placing_entry=0;
+                               placing_block = &block;
+                               placing_entry = 0;
                                set_block_color(*placing_block, GL::Color(0.5, 1, 0.7));
                        }
                }
@@ -406,51 +406,51 @@ void Engineer::pointer_motion(int x, int y)
 
 void Engineer::view_all()
 {
-       const list<Track3D *> &tracks=layout_3d.get_tracks();
+       const list<Track3D *> &tracks = layout_3d.get_tracks();
 
-       cam_rot=0;
-       float best_height=-1;
-       float mid_x=0;
-       float mid_y=0;
+       cam_rot = 0;
+       float best_height = -1;
+       float mid_x = 0;
+       float mid_y = 0;
        for(float angle=0; angle<M_PI; angle+=0.01)
        {
-               float min_x=0;
-               float max_x=0;
-               float min_y=0;
-               float max_y=0;
+               float min_x = 0;
+               float max_x = 0;
+               float min_y = 0;
+               float max_y = 0;
                for(list<Track3D *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                {
                        Point minp, maxp;
                        (*i)->get_bounds(angle, minp, maxp);
-                       min_x=min(min_x, minp.x);
-                       max_x=max(max_x, maxp.x);
-                       min_y=min(min_y, minp.y);
-                       max_y=max(max_y, maxp.y);
+                       min_x = min(min_x, minp.x);
+                       max_x = max(max_x, maxp.x);
+                       min_y = min(min_y, minp.y);
+                       max_y = max(max_y, maxp.y);
                }
 
-               float width=max_x-min_x;
-               float height=max_y-min_y;
-               height=max(height, width);
+               float width = max_x-min_x;
+               float height = max_y-min_y;
+               height = max(height, width);
 
                if(height<best_height || best_height<0)
                {
-                       cam_rot=angle;
-                       best_height=height;
-                       mid_x=(min_x+max_x)/2;
-                       mid_y=(min_y+max_y)/2;
+                       cam_rot = angle;
+                       best_height = height;
+                       mid_x = (min_x+max_x)/2;
+                       mid_y = (min_y+max_y)/2;
                }
        }
 
-       float c=cos(cam_rot);
-       float s=sin(cam_rot);
-       cam_pos.x=c*mid_x-s*mid_y;
-       cam_pos.y=s*mid_x+c*mid_y;
-       cam_pos.z=max(best_height*1.05/0.82843, 0.15);
+       float c = cos(cam_rot);
+       float s = sin(cam_rot);
+       cam_pos.x = c*mid_x-s*mid_y;
+       cam_pos.y = s*mid_x+c*mid_y;
+       cam_pos.z = max(best_height*1.05/0.82843, 0.15);
 }
 
 void Engineer::set_block_color(const Block &block, const GL::Color &color)
 {
-       const set<Track *> &tracks=block.get_tracks();
+       const set<Track *> &tracks = block.get_tracks();
        for(set<Track *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                layout_3d.get_track(**i).set_color(color);
 }
@@ -459,7 +459,7 @@ void Engineer::reset_block_color(const Block &block)
 {
        if(unsigned sid=block.get_sensor_id())
        {
-               Sensor &sensor=control.get_sensor(sid);
+               Sensor &sensor = control.get_sensor(sid);
                if(sensor.get_state())
                {
                        set_block_color(block, GL::Color(1, 0.5, 0.3));
@@ -475,7 +475,7 @@ void Engineer::reset_block_color(const Block &block)
 
 void Engineer::sensor_event(bool, Sensor *sensor)
 {
-       const list<Block *> &blocks=trfc_mgr->get_blocks();
+       const list<Block *> &blocks = trfc_mgr->get_blocks();
        for(list<Block *>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
                if((*i)->get_sensor_id()==sensor->get_address())
                        reset_block_color(**i);
@@ -490,16 +490,16 @@ void Engineer::project_3d()
 {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
-       float offset=200.0/screen_w*0.055228;
+       float offset = 200.0/screen_w*0.055228;
        glFrustum(-0.055228-offset, 0.055228-offset, -0.041421, 0.041421, 0.1, 10);
        glMatrixMode(GL_MODELVIEW);
 }
 
 Track3D *Engineer::pick_track(int x, int y)
 {
-       float xx=(static_cast<float>(x-static_cast<int>(screen_w)/2-100)/screen_h)*0.82843;
-       float yy=(static_cast<float>(y)/screen_h-0.5)*0.82843;
-       float size=4.0/screen_h*0.82843;
+       float xx = (static_cast<float>(x-static_cast<int>(screen_w)/2-100)/screen_h)*0.82843;
+       float yy = (static_cast<float>(y)/screen_h-0.5)*0.82843;
+       float size = 4.0/screen_h*0.82843;
 
        project_3d();
        glLoadIdentity();
@@ -511,7 +511,7 @@ Track3D *Engineer::pick_track(int x, int y)
 
 void Engineer::dismiss_train_prop()
 {
-       train_prop_stale=true;
+       train_prop_stale = true;
 }
 
 Application::RegApp<Engineer> Engineer::reg;