]> git.tdb.fi Git - r2c2.git/commitdiff
Further fix delay handling
authorMikko Rasa <tdb@tdb.fi>
Thu, 10 Apr 2014 22:54:47 +0000 (01:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 10 Apr 2014 23:00:04 +0000 (02:00 +0300)
source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouteplanner.h

index fc62faaa48ab25d6478e42dc55205cc3f5c92f46..b4d4afd64c23bd0b43ee0361d410d86ef9245f1f 100644 (file)
@@ -273,6 +273,25 @@ void TrainRoutePlanner::TrainRoutingState::advance(float distance)
        remaining_estimate -= distance;
 }
 
+void TrainRoutePlanner::TrainRoutingState::advance(const Time::TimeDelta &dt)
+{
+       if(delay>=dt)
+       {
+               delay -= dt;
+               return;
+       }
+
+       float secs = dt/Time::sec;
+       if(delay)
+       {
+               secs -= delay/Time::sec;
+               delay = Time::zero;
+       }
+
+       if(state==MOVING)
+               advance(info->speed*secs);
+}
+
 void TrainRoutePlanner::TrainRoutingState::advance_track(unsigned next_path)
 {
        float distance = occupied_tracks->path_length-offset;
@@ -439,17 +458,7 @@ void TrainRoutePlanner::RoutingStep::advance(const Time::TimeDelta &dt)
 {
        time += dt;
        for(vector<TrainRoutingState>::iterator i=trains.begin(); i!=trains.end(); ++i)
-       {
-               if(i->delay)
-               {
-                       i->delay -= dt;
-                       if(i->delay>Time::zero)
-                               continue;
-                       i->delay = Time::zero;
-               }
-               else if(i->state==MOVING)
-                       i->advance(i->info->speed*(dt/Time::sec));
-       }
+               i->advance(dt);
 }
 
 void TrainRoutePlanner::RoutingStep::update_estimate()
index a191cb6b117417fb288b8035ddd2bf03415fe017..33e6ef5f1b4c5c7f22e23432eb3ed87932191e0c 100644 (file)
@@ -74,6 +74,7 @@ private:
                bool is_occupying(Track &) const;
                bool check_arrival();
                void advance(float);
+               void advance(const Msp::Time::TimeDelta &);
                void advance_track(unsigned);
                void update_estimate();
        };