*/
#include <cmath>
+#include <cstdlib>
#include <limits>
#include <signal.h>
#include <msp/core/except.h>
using namespace Marklin;
using namespace Msp;
+Application::RegApp<Engineer> Engineer::reg;
+
Engineer::Engineer(int argc, char **argv):
options(argc, argv),
window(options.screen_w, options.screen_h, options.fullscreen),
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());
+
// Setup railroad control
DataFile::load(catalogue, "tracks.dat");
DataFile::load(catalogue, "locos.dat");
// Setup 3D view
DataFile::load(arrow_mesh, "arrow.mesh");
- overlay = new Overlay3D(window, camera, ui_res.get_default_font());
-
pipeline.set_camera(&camera);
pipeline.add_renderable(layout_3d.get_scene());
layout.tick();
event_disp.tick(Time::zero);
- for(list<Train *>::iterator i=new_trains.begin(); i!=new_trains.end(); ++i)
- overlay->set_label(layout_3d.get_train(**i), (*i)->get_name());
- new_trains.clear();
-
GL::clear(GL::COLOR_BUFFER_BIT|GL::DEPTH_BUFFER_BIT);
pipeline.render_all();
reset_block_color(*placing_block);
placing_block = █
placing_entry = 0;
- set_block_color(*placing_block, GL::Color(0.5, 1, 0.7));
+ if(!placing_block->get_train())
+ set_block_color(*placing_block, GL::Color(0));
}
}
}
void Engineer::reset_block_color(const Block &block)
{
+ bool active = false;
if(unsigned sid=block.get_sensor_id())
- {
- if(layout.get_driver().get_sensor(sid))
- {
- set_block_color(block, GL::Color(1, 0.5, 0.3));
- return;
- }
- }
+ active = layout.get_driver().get_sensor(sid);
if(block.get_train())
- set_block_color(block, GL::Color(1, 1, 0.3));
+ {
+ GL::Color color;
+ map<Train *, GL::Color>::iterator i = train_colors.find(block.get_train());
+ if(i!=train_colors.end())
+ color = i->second;
+
+ if(active)
+ set_block_color(block, color*0.6);
+ else
+ set_block_color(block, color*0.5+0.5);
+ }
+ else if(active)
+ set_block_color(block, GL::Color(0.6));
else
- set_block_color(block, GL::Color(1, 1, 1));
+ set_block_color(block, GL::Color(1));
}
void Engineer::sensor_event(unsigned addr, bool)
train_panels.push_back(tpanel);
tpanel->set_visible(true);
- new_trains.push_back(&train);
+ Train3D &t3d = layout_3d.get_train(train);
+ overlay->set_label(t3d, train.get_name());
+ train.signal_name_changed.connect(sigc::bind<0>(sigc::mem_fun(overlay, &Overlay3D::set_label), sigc::ref(t3d)));
+
+ GL::Color best_color;
+ float best_d_sq = 0;
+ for(unsigned i=0; i<10; ++i)
+ {
+ GL::Color color;
+ color.r = rand()*1.0/RAND_MAX;
+ color.g = rand()*1.0/RAND_MAX;
+ color.b = rand()*1.0/RAND_MAX;
+ color = color*(1/max(max(color.r, color.g), color.b));
+ float min_d_sq = 3;
+ for(map<Train *, GL::Color>::const_iterator j=train_colors.begin(); j!=train_colors.end(); ++j)
+ {
+ float dr = color.r-j->second.r;
+ float dg = color.g-j->second.g;
+ float db = color.b-j->second.b;
+ float d_sq = dr*dr+dg*dg+db*db;
+ if(d_sq<min_d_sq)
+ min_d_sq = d_sq;
+ }
+ if(min_d_sq>best_d_sq)
+ {
+ best_color = color;
+ best_d_sq = min_d_sq;
+ }
+ }
+ train_colors[&train] = best_color;
}
void Engineer::sighandler(int sig)
else if(sig==SIGTERM || sig==SIGINT)
exit(0);
}
-
-Application::RegApp<Engineer> Engineer::reg;