From 997e14793d8e58d3cb14a495970b36b1e0cad39b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 4 Feb 2015 00:37:24 +0200 Subject: [PATCH] Eliminate the one step delay in adding tracks to routes 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 | 13 +++++-------- source/libr2c2/trainrouteplanner.h | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index b4f01ab..30d9f5e 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -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(); diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index 54ecadb..153eda0 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -34,7 +34,7 @@ private: float speed; TrainRouter *router; std::list routes; - Track *track_history[3]; + Track *track_history[2]; std::list sequence; TrainRoutingInfo(Train &); -- 2.45.2