]> git.tdb.fi Git - r2c2.git/commitdiff
Eliminate the one step delay in adding tracks to routes
authorMikko Rasa <tdb@tdb.fi>
Tue, 3 Feb 2015 22:37:24 +0000 (00:37 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 4 Feb 2015 09:13:17 +0000 (11:13 +0200)
It is no longer necessary now that we inspect linked tracks to detect
loops.  Removing it makes the logic easier to understand.

source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouteplanner.h

index b4f01ab6a860084901add49d3ab21de3405d49d0..30d9f5e482ee054aa4a5dee7df770abbddd743a7 100644 (file)
@@ -133,7 +133,7 @@ void TrainRoutePlanner::finalize_plan()
        {
                i->routes.clear();
                i->sequence.clear();
-               for(unsigned j=0; j<3; ++j)
+               for(unsigned j=0; j<2; ++j)
                        i->track_history[j] = 0;
        }
 
@@ -168,16 +168,13 @@ void TrainRoutePlanner::finalize_plan()
                                route = new Route(j->info->train->get_layout());
                                route->set_name("Router");
                                route->set_temporary(true);
-                               for(unsigned k=2; k>0; --k)
-                                       if(history[k])
-                                               route->add_track(*history[k]);
+                               for(unsigned k=0; (k<2 && history[k]); ++k)
+                                       route->add_track(*history[k]);
                                j->info->routes.push_front(route);
                        }
 
-                       if(history[0])
-                               route->add_track(*history[0]);
-                       for(unsigned k=2; k>0; --k)
-                               history[k] = history[k-1];
+                       route->add_track(*j->track.track());
+                       history[1] = history[0];
                        history[0] = j->track.track();
 
                        bool waitable = j->track.endpoint().paths!=j->track->get_type().get_paths();
index 54ecadb8e905cd19138ef5070f11cd88b16da75e..153eda0532dfc369d48f34aabc77fff068a3ec51 100644 (file)
@@ -34,7 +34,7 @@ private:
                float speed;
                TrainRouter *router;
                std::list<Route *> routes;
-               Track *track_history[3];
+               Track *track_history[2];
                std::list<TrainRouter::SequencePoint> sequence;
 
                TrainRoutingInfo(Train &);