]> git.tdb.fi Git - r2c2.git/commitdiff
Keep routes until the train has completely left them
authorMikko Rasa <tdb@tdb.fi>
Tue, 15 Apr 2014 19:58:07 +0000 (22:58 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 15 Apr 2014 19:58:07 +0000 (22:58 +0300)
source/libr2c2/trainrouter.cpp
source/libr2c2/trainrouter.h

index 959eba2393df2d3c5443670e239b91e0e449e159..5b2c5ee2f768e962cbbe669fb6f46425f6185d9e 100644 (file)
@@ -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<TrainRouteMetric *>::iterator i=metrics.begin(); i!=metrics.end(); ++i)
index 589c7297d648858472026be5ef8b42dc1459f948..4f51b3e107878b07e37cd86fa38d7509d8527208 100644 (file)
@@ -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 *);