From f305e582aef0dceafd3b7b00bf9374bb69bdf8b0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 11 Apr 2014 01:50:43 +0300 Subject: [PATCH] Track trains' remaining estimate by distance, not time This makes it easier to keep correct since delay is not included. --- source/libr2c2/trainrouteplanner.cpp | 18 +++++++----------- source/libr2c2/trainrouteplanner.h | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index cd79a61..fc62faa 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -270,9 +270,7 @@ void TrainRoutePlanner::TrainRoutingState::advance(float distance) --occupied_tracks->n_tracks; } - remaining_estimate -= (distance/info->speed)*Time::sec; - if(remaining_estimaterouter->get_metric(waypoint).get_distance_from(*iter.track(), iter.entry()); distance += track->get_type().get_path_length(path)-offset; - remaining_estimate = (distance/info->speed)*Time::sec+delay; + remaining_estimate = distance; } @@ -458,13 +456,7 @@ void TrainRoutePlanner::RoutingStep::update_estimate() { for(vector::const_iterator i=trains.begin(); i!=trains.end(); ++i) { - if(i->remaining_estimateremaining_estimate; - return; - } - - Time::TimeDelta t = time+i->remaining_estimate; + Time::TimeDelta t = time+(i->remaining_estimate/i->info->speed)*Time::sec+i->delay; if(i==trains.begin() || t>total_estimate) total_estimate = t; } @@ -475,6 +467,10 @@ bool TrainRoutePlanner::RoutingStep::is_viable() const if(total_estimate::const_iterator i=trains.begin(); i!=trains.end(); ++i) + if(i->remaining_estimate<0) + return false; + for(vector::const_iterator i=trains.begin(); i!=trains.end(); ++i) if(i->state==MOVING) return true; diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index f799420..a191cb6 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -63,7 +63,7 @@ private: TrainState state; Msp::Time::TimeDelta delay; int waypoint; - Msp::Time::TimeDelta remaining_estimate; + float remaining_estimate; int blocked_by; TrainRoutingState(TrainRoutingInfo &); -- 2.45.2