#include "driver.h"
#include "layout.h"
#include "route.h"
+#include "trackcircuit.h"
#include "trackiter.h"
#include "tracktype.h"
id(0),
sensor_id(start.get_sensor_id()),
turnout_id(start.get_turnout_id()),
- state(INACTIVE),
train(0)
{
tracks.insert(&start);
{
unsigned path = 1<<i;
endpoints[i].paths |= path;
- find_paths(TrackIter(endpoints[i].track, endpoints[i].track_ep), path);
+ find_paths(endpoints[i].track_iter(), path);
}
- if(sensor_id && layout.has_driver())
- layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Block::sensor_event));
+ sensor = new TrackCircuit(layout, *this);
layout.add_block(*this);
}
}
layout.remove_block(*this);
+
+ delete sensor;
}
bool Block::has_track(Track &t) const
if(entry>=endpoints.size())
throw out_of_range("Block::get_path_length");
- TrackIter t_iter(endpoints[entry].track, endpoints[entry].track_ep);
+ TrackIter t_iter = endpoints[entry].track_iter();
float result = 0;
while(t_iter && has_track(*t_iter))
return false;
}
-void Block::tick(const Time::TimeDelta &dt)
-{
- if(state_confirm_timeout)
- {
- state_confirm_timeout -= dt;
- if(state_confirm_timeout<=Time::zero)
- {
- if(state==MAYBE_INACTIVE)
- state = INACTIVE;
- else if(state==MAYBE_ACTIVE)
- state = ACTIVE;
- state_confirm_timeout = Time::zero;
- signal_state_changed.emit(state);
- }
- }
-}
-
-void Block::find_paths(TrackIter track, unsigned path)
+void Block::find_paths(const TrackIter &track, unsigned path)
{
unsigned mask = track.endpoint().paths;
for(unsigned i=0; mask>>i; ++i)
}
}
-void Block::sensor_event(unsigned addr, bool s)
-{
- if(addr==sensor_id)
- {
- if(s && state<MAYBE_ACTIVE)
- {
- state = MAYBE_ACTIVE;
- state_confirm_timeout = 300*Time::msec;
- signal_state_changed.emit(state);
- }
- else if(!s && state>MAYBE_INACTIVE)
- {
- state = MAYBE_INACTIVE;
- state_confirm_timeout = 700*Time::msec;
- signal_state_changed.emit(state);
- }
- }
-}
-
Block::Endpoint::Endpoint(Track *t, unsigned e):
track(t),
paths(0)
{ }
+TrackIter Block::Endpoint::track_iter() const
+{
+ return TrackIter(track, track_ep);
+}
+
} // namespace R2C2