]> git.tdb.fi Git - r2c2.git/commitdiff
Track trains' remaining estimate by distance, not time
authorMikko Rasa <tdb@tdb.fi>
Thu, 10 Apr 2014 22:50:43 +0000 (01:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 10 Apr 2014 22:59:37 +0000 (01:59 +0300)
This makes it easier to keep correct since delay is not included.

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

index cd79a61c8f947ff64a4533396fc716ca6ff24387..fc62faaa48ab25d6478e42dc55205cc3f5c92f46 100644 (file)
@@ -270,9 +270,7 @@ void TrainRoutePlanner::TrainRoutingState::advance(float distance)
                --occupied_tracks->n_tracks;
        }
 
-       remaining_estimate -= (distance/info->speed)*Time::sec;
-       if(remaining_estimate<Time::zero)
-               remaining_estimate = Time::zero;
+       remaining_estimate -= distance;
 }
 
 void TrainRoutePlanner::TrainRoutingState::advance_track(unsigned next_path)
@@ -290,7 +288,7 @@ void TrainRoutePlanner::TrainRoutingState::update_estimate()
        TrackIter iter = track.reverse(path);
        float distance = info->router->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<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
-               if(i->remaining_estimate<Time::zero)
-               {
-                       total_estimate = i->remaining_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<Time::zero)
                return false;
 
+       for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
+               if(i->remaining_estimate<0)
+                       return false;
+
        for(vector<TrainRoutingState>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
                if(i->state==MOVING)
                        return true;
index f7994200a33d6d3ff39f4029aeb25e263a8fcea9..a191cb6b117417fb288b8035ddd2bf03415fe017 100644 (file)
@@ -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 &);