]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/engineer.cpp
Rendering improvements
[r2c2.git] / source / engineer / engineer.cpp
index c8092872c4dc0e0b3314115329fabd8562d6b017..5cf22ba0f2f9c8390f557a26fb000bd1f5a6c23d 100644 (file)
@@ -5,6 +5,7 @@ Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
+#include <algorithm>
 #include <cmath>
 #include <cstdlib>
 #include <limits>
@@ -33,6 +34,7 @@ Distributed under the GPL
 #include "mainpanel.h"
 #include "trainpanel.h"
 #include "trainproperties.h"
+#include "trainview.h"
 
 using namespace std;
 using namespace Marklin;
@@ -95,14 +97,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();
 
@@ -137,6 +145,26 @@ void Engineer::set_status(const string &text)
        status_timeout = Time::now()+10*Time::sec;
 }
 
+void Engineer::rearrange_panels()
+{
+       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;
+               (*i)->set_position(0, y);
+       }
+}
+
+void Engineer::add_train_view(TrainView &tv)
+{
+       train_views.push_back(&tv);
+}
+
+void Engineer::remove_train_view(TrainView &tv)
+{
+       train_views.erase(remove(train_views.begin(), train_views.end(), &tv), train_views.end());
+}
+
 void Engineer::pick(bool with_ep)
 {
        picking = true;
@@ -158,19 +186,18 @@ void Engineer::tick()
        layout.tick();
        event_disp.tick(Time::zero);
 
+       for(list<TrainView *>::iterator i=train_views.begin(); i!=train_views.end(); ++i)
+               (*i)->prepare();
+
        if(status_timeout && Time::now()>status_timeout)
        {
                main_panel->set_status_text(string());
                status_timeout = Time::TimeStamp();
        }
 
-       GL::clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
+       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);
@@ -270,12 +297,14 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned)
                                                        ++i;
                                        }
                                        track.set_active_path(i);
+                                       set_status(format("Turnout %d", track.get_turnout_id()));
                                }
                        }
-                       else if(options.simulate)
+                       if(unsigned sid = track.get_sensor_id())
                        {
-                               if(unsigned sid=track.get_sensor_id())
+                               if(options.simulate)
                                        layout.get_driver().set_sensor(sid, !layout.get_driver().get_sensor(sid));
+                               set_status(format("Sensor %d", sid));
                        }
                }
        }
@@ -401,12 +430,8 @@ void Engineer::train_added(Train &train)
 {
        TrainPanel *tpanel = new TrainPanel(*this, ui_res, train);
        root->add(*tpanel);
-       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;
-       tpanel->set_position(0, y-tpanel->get_geometry().h);
        train_panels.push_back(tpanel);
-       tpanel->set_visible(true);
+       rearrange_panels();
 
        Vehicle3D &loco3d = layout_3d.get_vehicle(train.get_vehicle(0));
        overlay->set_label(loco3d, train.get_name());