]> git.tdb.fi Git - r2c2.git/commitdiff
Fix a problem with estimated remaining distance in route planner
authorMikko Rasa <tdb@tdb.fi>
Mon, 23 Feb 2015 14:40:02 +0000 (16:40 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 23 Feb 2015 14:40:02 +0000 (16:40 +0200)
The front of the occupied tracks list contains the length of the chosen
path on the current track and needs to be updated when the path changes.

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

index d9eedd2d4daccd0d33224548325c594859c7777a..97f1cf6c8501af801a42b2123768503c929e7b14 100644 (file)
@@ -505,6 +505,16 @@ void TrainRoutePlanner::TrainRoutingState::advance_track(unsigned next_path)
        offset = 0;
 }
 
+void TrainRoutePlanner::TrainRoutingState::set_path(unsigned p)
+{
+       path = p;
+       OccupiedTrack *next_occ = occupied_tracks->next;
+       if(!--occupied_tracks->refcount)
+               delete occupied_tracks;
+       occupied_tracks = new OccupiedTrack(*track, path, next_occ);
+       update_estimate();
+}
+
 void TrainRoutePlanner::TrainRoutingState::update_estimate()
 {
        TrackIter iter = track.reverse(path);
@@ -604,8 +614,7 @@ void TrainRoutePlanner::RoutingStep::create_successor(RoutingStep &next, unsigne
 {
        TrainRoutingState &train = next.trains[train_index];
 
-       train.path = path;
-       train.update_estimate();
+       train.set_path(path);
        next.update_estimate();
        if(next.is_viable())
                new_steps.push_back(next);
index 32c9dadc3494671dcbe805c6fcf1ff4bee5b5247..47d00b8079d4f3062702ed3a040e086cb6157e77 100644 (file)
@@ -96,6 +96,7 @@ private:
                void advance(float);
                void advance(const Msp::Time::TimeDelta &);
                void advance_track(unsigned);
+               void set_path(unsigned);
                void update_estimate();
                bool is_viable() const;
        };