From e5c244baa4058dbfc0c5caee64e6c83523751924 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 15 Apr 2014 22:58:07 +0300 Subject: [PATCH] Keep routes until the train has completely left them --- source/libr2c2/trainrouter.cpp | 41 +++++++++++++++++----------------- source/libr2c2/trainrouter.h | 1 + 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index 959eba2..5b2c5ee 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -24,6 +24,7 @@ TrainRouter::TrainRouter(Train &t): { 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() @@ -338,27 +339,6 @@ void TrainRouter::train_advanced(Block &block) { 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(); @@ -381,6 +361,25 @@ void TrainRouter::train_advanced(Block &block) } } +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::iterator i=metrics.begin(); i!=metrics.end(); ++i) diff --git a/source/libr2c2/trainrouter.h b/source/libr2c2/trainrouter.h index 589c729..4f51b3e 100644 --- a/source/libr2c2/trainrouter.h +++ b/source/libr2c2/trainrouter.h @@ -100,6 +100,7 @@ public: private: void block_reserved(Block &, Train *); void train_advanced(Block &); + void train_rear_advanced(Block &); void create_metrics(); Route *create_lead_route(Route *, const Route *); -- 2.45.2