{
train.get_layout().signal_block_reserved.connect(sigc::mem_fun(this, &TrainRouter::block_reserved));
train.signal_advanced.connect(sigc::mem_fun(this, &TrainRouter::train_advanced));
+ train.signal_rear_advanced.connect(sigc::mem_fun(this, &TrainRouter::train_rear_advanced));
}
TrainRouter::~TrainRouter()
{
BlockIter b_iter = train.get_block_allocator().iter_for(block);
- // Check if we've reached the next route
- if(routes.size()>1)
- {
- Track &track = *b_iter.endpoint().track;
- const Route *route = get_route();
- bool change_route = false;
- if(route->is_loop())
- change_route = (*++routes.begin())->has_track(track);
- else
- change_route = !route->has_track(track);
-
- if(change_route)
- {
- routes.pop_front();
- route = get_route();
- // XXX Exceptions?
- signal_route_changed.emit(route);
- signal_event.emit(Message("route-changed", route));
- }
- }
-
if(!waypoints.empty())
{
const TrackChain &wp = *waypoints.front();
}
}
+void TrainRouter::train_rear_advanced(Block &block)
+{
+ Track &track = *train.get_block_allocator().iter_for(block).endpoint().track;
+
+ // Have we left some routes completely behind?
+ for(RouteList::iterator i=routes.begin(); i!=routes.end(); ++i)
+ if((*i)->has_track(track))
+ {
+ if(i!=routes.begin())
+ {
+ routes.erase(routes.begin(), i);
+ const Route *route = get_route();
+ signal_route_changed.emit(route);
+ signal_event.emit(Message("route-changed", route));
+ }
+ break;
+ }
+}
+
void TrainRouter::create_metrics()
{
for(vector<TrainRouteMetric *>::iterator i=metrics.begin(); i!=metrics.end(); ++i)