]> git.tdb.fi Git - r2c2.git/commitdiff
Diverge from a route early only if it's a loop
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Apr 2014 19:31:18 +0000 (22:31 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Apr 2014 19:36:48 +0000 (22:36 +0300)
This does not entirely fix handling of chained routes, but it's a step in
the right direction.

source/libr2c2/trainrouter.cpp

index 5691ac9a30ccdbdcc15e506d3581f2be26cddc31..a6a47c0b5b13a291e30096795c87d2f8c1908628 100644 (file)
@@ -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));
                }
        }