From: Mikko Rasa Date: Thu, 10 Apr 2014 22:54:47 +0000 (+0300) Subject: Further fix delay handling X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7d6f95321585b41bb5a6f11ff148486612bbc19e;p=r2c2.git Further fix delay handling --- diff --git a/source/libr2c2/trainrouteplanner.cpp b/source/libr2c2/trainrouteplanner.cpp index fc62faa..b4d4afd 100644 --- a/source/libr2c2/trainrouteplanner.cpp +++ b/source/libr2c2/trainrouteplanner.cpp @@ -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::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() diff --git a/source/libr2c2/trainrouteplanner.h b/source/libr2c2/trainrouteplanner.h index a191cb6..33e6ef5 100644 --- a/source/libr2c2/trainrouteplanner.h +++ b/source/libr2c2/trainrouteplanner.h @@ -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(); };