From: Mikko Rasa Date: Mon, 23 Feb 2015 14:40:02 +0000 (+0200) Subject: Fix a problem with estimated remaining distance in route planner X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=44e13f6732f206aa72ff7b001d77fe59bf2830ee;p=r2c2.git Fix a problem with estimated remaining distance in route planner 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. --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index d9eedd2..97f1cf6 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -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); diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index 32c9dad..47d00b8 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -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; };