Layout::Layout(Catalogue &c, Driver *d):
catalogue(c),
driver(d)
-{ }
+{
+ if(driver)
+ driver->signal_sensor.connect(sigc::mem_fun(this, &Layout::sensor_event));
+}
Layout::~Layout()
{
i->second->tick(t, dt);
}
+void Layout::emergency(const string &msg)
+{
+ if(driver)
+ driver->halt(true);
+ signal_emergency.emit(msg);
+}
+
void Layout::save(const string &fn)
{
IO::BufferedFile out(fn, IO::M_WRITE);
for(map<string, Route *>::iterator i=routes.begin(); i!=routes.end(); ++i)
{
+ if(i->second->is_temporary())
+ continue;
+
DataFile::Statement st("route");
st.append(i->first);
i->second->save(st.sub);
{
for(map<string, Route *>::iterator i=routes.begin(); i!=routes.end(); ++i)
{
+ if(i->second->is_temporary())
+ continue;
+
/* We must copy the turnout map, since adding tracks to the route will
(temporarily) mess it up */
const map<unsigned, int> turnouts = i->second->get_turnouts();
while(1)
{
// Traverse the track and get the next one
+ if(track->get_type().get_endpoints().size()<2)
+ break;
unsigned out_ep = track->traverse(ep, trk_path);
Track *next = track->get_links()[out_ep];
if(!next || next == start)
}
}
+void Layout::sensor_event(unsigned addr, bool state)
+{
+ if(state)
+ {
+ for(set<Block *>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
+ if((*i)->get_sensor_id()==addr)
+ {
+ if(!(*i)->get_train())
+ emergency("Unreserved sensor triggered");
+ break;
+ }
+ }
+}
+
Layout::Loader::Loader(Layout &l):
DataFile::BasicLoader<Layout>(l),