From: Mikko Rasa Date: Fri, 11 Apr 2014 19:31:18 +0000 (+0300) Subject: Diverge from a route early only if it's a loop X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c796e17cef61ad2e3f476b6037892d7bc6c52680;p=r2c2.git 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. --- 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)); } }