From c796e17cef61ad2e3f476b6037892d7bc6c52680 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 11 Apr 2014 22:31:18 +0300 Subject: [PATCH] Diverge from a route early only if it's a loop This does not entirely fix handling of chained routes, but it's a step in the right direction. --- source/libr2c2/trainrouter.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index 5691ac9..a6a47c0 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -266,14 +266,21 @@ void TrainRouter::train_advanced(Block &block) // Check if we've reached the next route if(routes.size()>1) { - const Route &route = **++routes.begin(); - if(route.has_track(*b_iter.endpoint().track)) + 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(); - const Route *r = get_route(); + route = get_route(); // XXX Exceptions? - signal_route_changed.emit(r); - signal_event.emit(Message("route-changed", r)); + signal_route_changed.emit(route); + signal_event.emit(Message("route-changed", route)); } } -- 2.45.2