]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/engineer.cpp
Rename Point to Vector
[r2c2.git] / source / engineer / engineer.cpp
index 59aaeeca9f9e3aef5677ccc5196c7a0d6b57a1a1..fad61693aef66161e1822dc18f7e8a209f7d33af 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$
 
-This file is part of the MSP Märklin suite
+This file is part of R²C²
 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
@@ -12,6 +12,7 @@ Distributed under the GPL
 #include <signal.h>
 #include <msp/core/except.h>
 #include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
 #include <msp/gbase/display.h>
 #include <msp/gbase/window.h>
 #include <msp/gl/blend.h>
@@ -25,8 +26,8 @@ Distributed under the GPL
 #include <msp/strings/formatter.h>
 #include <msp/time/units.h>
 #include <msp/time/utils.h>
-#include "libmarklin/driver.h"
-#include "libmarklin/tracktype.h"
+#include "libr2c2/driver.h"
+#include "libr2c2/tracktype.h"
 #include "3d/path.h"
 #include "3d/track.h"
 #include "3d/vehicle.h"
@@ -37,7 +38,7 @@ Distributed under the GPL
 #include "trainview.h"
 
 using namespace std;
-using namespace Marklin;
+using namespace R2C2;
 using namespace Msp;
 
 Application::RegApp<Engineer> Engineer::reg;
@@ -61,13 +62,13 @@ Engineer::Engineer(int argc, char **argv):
        window.set_title("Railroad Engineer");
        window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Engineer::exit), 0));
 
-       DataFile::load(ui_res, "marklin.res");
+       DataFile::load(ui_res, "r2c2.res");
        root = new GLtk::Root(ui_res, window);
        root->signal_button_press.connect(sigc::mem_fun(this, &Engineer::button_press));
        root->signal_pointer_motion.connect(sigc::mem_fun(this, &Engineer::pointer_motion));
        root->set_visible(true);
 
-       main_panel = new MainPanel(*this, ui_res);
+       main_panel = new MainPanel(*this);
        root->add(*main_panel);
        main_panel->set_position(0, window.get_height()-main_panel->get_geometry().h);
        main_panel->set_visible(true);
@@ -84,8 +85,8 @@ Engineer::Engineer(int argc, char **argv):
        layout.signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved));
        layout.signal_emergency.connect(sigc::mem_fun(this, &Engineer::set_status));
        layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Engineer::sensor_event));
-       if(FS::exists("engineer.state"))
-               DataFile::load(layout, "engineer.state");
+       if(FS::exists(options.state_fn))
+               DataFile::load(layout, options.state_fn);
 
        if(options.network)
        {
@@ -97,14 +98,20 @@ Engineer::Engineer(int argc, char **argv):
        DataFile::load(arrow_mesh, "arrow.mesh");
 
        pipeline.set_camera(&camera);
-       pipeline.add_renderable(layout_3d.get_scene());
+       pipeline.add_renderable_for_pass(layout_3d.get_scene(), 0);
+       pipeline.add_renderable_for_pass(layout_3d.get_path_scene(), "unlit");
 
-       light.set_position(0, -0.259, 0.966, 0);
+       light.set_position(GL::Vector4(0, -0.259, 0.966, 0));
+       light.set_diffuse(GL::Color(0.9));
+       lighting.set_ambient(GL::Color(0.4));
        lighting.attach(0, light);
 
-       GL::PipelinePass &pass = pipeline.add_pass(0);
-       pass.depth_test = &GL::DepthTest::lequal();
-       pass.lighting = &lighting;
+       GL::PipelinePass *pass = &pipeline.add_pass(0);
+       pass->depth_test = &GL::DepthTest::lequal();
+       pass->lighting = &lighting;
+
+       pass = &pipeline.add_pass("unlit");
+       pass->depth_test = &GL::DepthTest::lequal();
 
        view_all();
 
@@ -125,7 +132,10 @@ Engineer::~Engineer()
        layout.get_driver().flush();
 
        if(!options.simulate)
-               layout.save_trains("engineer.state");
+       {
+               layout.save_dynamic(options.state_fn+".tmp");
+               FS::rename(options.state_fn+".tmp", options.state_fn);
+       }
 
        delete overlay;
        delete root;
@@ -192,10 +202,6 @@ void Engineer::tick()
        GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
 
        pipeline.render_all();
-       {
-               GL::Bind depth(GL::DepthTest::lequal());
-               layout_3d.get_path_scene().render();
-       }
        {
                GL::Bind blend(GL::Blend::alpha());
                overlay->render(0);
@@ -217,7 +223,7 @@ void Engineer::tick()
                                delete picking_path;
                                picking_path = new Path3D(*track);
                                if(picking_entry>=0)
-                                       picking_path->set_mask(picking_track->get_type().get_endpoints()[picking_entry].paths);
+                                       picking_path->set_mask(picking_track->get_type().get_endpoint(picking_entry).paths);
                                else
                                        picking_path->set_mask(picking_track->get_type().get_paths());
                                picking_path->set_color(GL::Color(0));
@@ -231,7 +237,7 @@ void Engineer::tick()
                GL::PushMatrix push_mat;
 
                float rot = picking_track->get_endpoint_direction(picking_entry);
-               Point pos = picking_track->get_endpoint_position(picking_entry);
+               Vector pos = picking_track->get_endpoint_position(picking_entry);
 
                GL::translate(pos.x, pos.y, pos.z+0.03);
                GL::rotate(rot*180/M_PI+180, 0, 0, 1);
@@ -269,7 +275,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned)
                else if(btn==3 && picking_entry>=0)
                {
                        picking_entry = (picking_entry+1)%picking_track->get_type().get_endpoints().size();
-                       picking_path->set_mask(picking_track->get_type().get_endpoints()[picking_entry].paths);
+                       picking_path->set_mask(picking_track->get_type().get_endpoint(picking_entry).paths);
                }
        }
        else
@@ -280,7 +286,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned)
                        Track &track = t3d->get_track();
                        if(track.get_turnout_id())
                        {
-                               Block &block = layout.get_block_by_track(track);
+                               Block &block = track.get_block();
                                if(block.get_train() && !block.get_train()->free_block(block))
                                        set_status("Turnout is busy");
                                else
@@ -317,7 +323,7 @@ void Engineer::pointer_motion(int x, int y)
 
 void Engineer::view_all()
 {
-       const list<Track3D *> &tracks = layout_3d.get_tracks();
+       const Layout3D::TrackMap &tracks = layout_3d.get_tracks();
 
        float view_aspect = float(window.get_width()-200)/window.get_height();
        float view_height = tan(camera.get_field_of_view()/2)*2;
@@ -330,10 +336,10 @@ void Engineer::view_all()
                float max_x = 0;
                float min_y = 0;
                float max_y = 0;
-               for(list<Track3D *>::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
+               for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
                {
-                       Point minp, maxp;
-                       (*i)->get_bounds(angle, minp, maxp);
+                       Vector minp, maxp;
+                       i->second->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);
@@ -426,7 +432,7 @@ Track3D *Engineer::pick_track(int x, int y)
 
 void Engineer::train_added(Train &train)
 {
-       TrainPanel *tpanel = new TrainPanel(*this, ui_res, train);
+       TrainPanel *tpanel = new TrainPanel(*this, train);
        root->add(*tpanel);
        train_panels.push_back(tpanel);
        rearrange_panels();