X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fengineer.cpp;h=40011ce9ce1e58768281f7c01a8e57203c51aba1;hb=b14059de03324aecde3efc649293d98ce5b7aaf2;hp=90cb8eb7007fbb9ab08e62924888e42f546d6680;hpb=f4417d49014ec6bcbb4b5dfcbe85c8395bae662f;p=r2c2.git diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index 90cb8eb..40011ce 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of R²C² -Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2011 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -73,7 +73,7 @@ Engineer::Engineer(int argc, char **argv): main_panel->set_position(0, window.get_height()-main_panel->get_geometry().h); main_panel->set_visible(true); - overlay = new Overlay3D(window, camera, ui_res.get_default_font()); + overlay = new Overlay3D(ui_res.get_default_font()); // Setup railroad control DataFile::load(catalogue, "tracks.dat"); @@ -82,9 +82,10 @@ Engineer::Engineer(int argc, char **argv): DataFile::load(layout, options.layout_fn); layout.signal_train_added.connect(sigc::mem_fun(this, &Engineer::train_added)); - layout.signal_block_reserved.connect(sigc::mem_fun(this, &Engineer::block_reserved)); + layout.signal_block_reserved.connect(sigc::hide<1>(sigc::mem_fun(this, &Engineer::reset_block_color))); + layout.signal_block_state_changed.connect(sigc::hide<1>(sigc::mem_fun(this, &Engineer::reset_block_color))); 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(options.state_fn)) DataFile::load(layout, options.state_fn); @@ -100,6 +101,7 @@ Engineer::Engineer(int argc, char **argv): pipeline.set_camera(&camera); pipeline.add_renderable_for_pass(layout_3d.get_scene(), 0); pipeline.add_renderable_for_pass(layout_3d.get_path_scene(), "unlit"); + pipeline.add_renderable_for_pass(*overlay, "overlay"); light.set_position(GL::Vector4(0, -0.259, 0.966, 0)); light.set_diffuse(GL::Color(0.9)); @@ -113,6 +115,9 @@ Engineer::Engineer(int argc, char **argv): pass = &pipeline.add_pass("unlit"); pass->depth_test = &GL::DepthTest::lequal(); + pass = &pipeline.add_pass("overlay"); + pass->blend = &GL::Blend::alpha(); + view_all(); // Catch various signals so we can stop the trains in case we get terminated @@ -202,10 +207,6 @@ void Engineer::tick() GL::Framebuffer::system().clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT); pipeline.render_all(); - { - GL::Bind blend(GL::Blend::alpha()); - overlay->render(0); - } if(pointer_moved) { @@ -213,15 +214,15 @@ void Engineer::tick() if(picking) { - Track3D *track = pick_track(pointer_x, window.get_height()-pointer_y-1); - if(track && &track->get_track()!=picking_track) + Track *track = pick_track(pointer_x, window.get_height()-pointer_y-1); + if(track && track!=picking_track) { - picking_track = &track->get_track(); + picking_track = track; if(picking_entry>=0) picking_entry = 0; delete picking_path; - picking_path = new Path3D(*track); + picking_path = new Path3D(layout_3d.get_track(*track)); if(picking_entry>=0) picking_path->set_mask(picking_track->get_type().get_endpoint(picking_entry).paths); else @@ -237,7 +238,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); @@ -280,19 +281,18 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) } else { - Track3D *t3d = pick_track(x, window.get_height()-y-1); - if(t3d) + Track *track = pick_track(x, window.get_height()-y-1); + if(track) { - Track &track = t3d->get_track(); - if(track.get_turnout_id()) + if(track->get_turnout_id()) { - Block &block = track.get_block(); + Block &block = track->get_block(); if(block.get_train() && !block.get_train()->free_block(block)) set_status("Turnout is busy"); else { - unsigned paths = track.get_type().get_paths(); - unsigned i = track.get_active_path()+1; + unsigned paths = track->get_type().get_paths(); + unsigned i = track->get_active_path()+1; while(!(paths&(1<>i)) @@ -300,11 +300,11 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) else ++i; } - track.set_active_path(i); - set_status(format("Turnout %d", track.get_turnout_id())); + track->set_active_path(i); + set_status(format("Turnout %d", track->get_turnout_id())); } } - 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)); @@ -338,7 +338,7 @@ void Engineer::view_all() float max_y = 0; for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { - Point 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); @@ -383,9 +383,7 @@ void Engineer::set_block_color(const Block &block, const GL::Color &color) void Engineer::reset_block_color(const Block &block) { - bool active = false; - if(unsigned sid=block.get_sensor_id()) - active = layout.get_driver().get_sensor(sid); + bool active = block.get_state()>Block::INACTIVE; if(block.get_train()) { @@ -405,29 +403,14 @@ void Engineer::reset_block_color(const Block &block) set_block_color(block, GL::Color(1)); } -void Engineer::sensor_event(unsigned addr, bool) +Track *Engineer::pick_track(int x, int y) { - const set &blocks = layout.get_blocks(); - for(set::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) - if((*i)->get_sensor_id()==addr) - reset_block_color(**i); -} - -void Engineer::block_reserved(const Block &block, const Train *) -{ - reset_block_color(block); -} - -Track3D *Engineer::pick_track(int x, int y) -{ - float view_height = tan(camera.get_field_of_view()/2)*2; - float xx = ((float(x)-window.get_width()/2)/window.get_height())*view_height; - float yy = (float(y)/window.get_height()-0.5)*view_height; - float size = 4.0/window.get_height()*view_height; - - camera.apply(); + const GL::Vector3 &start = camera.get_position(); + float xx = x*2.0/window.get_width()-1.0; + float yy = y*2.0/window.get_height()-1.0; + GL::Vector4 ray = camera.unproject(GL::Vector4(xx, yy, 0, 0)); - return layout_3d.pick_track(xx, yy, size); + return layout.pick_track(Vector(start.x, start.y, start.z), Vector(ray.x, ray.y, ray.z)); } void Engineer::train_added(Train &train)