From: Mikko Rasa Date: Wed, 11 Feb 2015 18:14:30 +0000 (+0200) Subject: Avoid arriving too early if there's an unexpected stop on the last route X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=195ba0e08c597190481ac205afa05243c68fb39b;p=r2c2.git Avoid arriving too early if there's an unexpected stop on the last route If the final block of the route is allocated while the train is stopped, arrival could be triggered prematurely. I'm not entirely certain if this can happen in absence of certain quirks of the dummy driver, but better safe than sorry. --- diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index e38e29c..d95bdff 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -92,13 +92,14 @@ void TrainRouter::route_changed() /* Find the route that should be used for the next allocated block. We can't rely on the resync code in block_reserved since we may need to clear the stop marker to continue allocation. */ - TrackIter track = train.get_block_allocator().first().track_iter(); + const BlockAllocator &allocator = train.get_block_allocator(); + TrackIter track = allocator.first().track_iter(); list::iterator seq_begin = sequence_points.begin(); for(; track; track=track.next()) { if(!advance_to_track(reserving_route, track)) { - arrival = RESERVED_TO_END; + arrival = (allocator.is_block_current(track->get_block()) ? ADVANCED_TO_END : RESERVED_TO_END); break; } if(&track->get_block()==fncb.block()) @@ -252,7 +253,7 @@ void TrainRouter::tick(const Time::TimeDelta &dt) sequence_check_pending = false; } - if(arrival==RESERVED_TO_END && !train.get_speed()) + if(arrival==ADVANCED_TO_END && !train.get_speed()) { signal_arrived.emit(waypoints.back()); signal_event.emit(Message("arrived", waypoints.back())); @@ -363,7 +364,7 @@ void TrainRouter::train_advanced(Block &block) { BlockIter b_iter = train.get_block_allocator().iter_for(block); - if(waypoints.size()>1) + if(!waypoints.empty()) { // A waypoint is considered reached when the train has advanced through it. const TrackChain &wp = *waypoints.front(); @@ -374,10 +375,18 @@ void TrainRouter::train_advanced(Block &block) { if(!wp.has_track(*t_iter)) { - waypoints.erase(waypoints.begin()); - metrics_stale = true; - signal_waypoint_reached.emit(&wp); - signal_event.emit(Message("waypoint-reached", &wp)); + if(waypoints.size()==1) + { + if(arrival==RESERVED_TO_END) + arrival = ADVANCED_TO_END; + } + else + { + waypoints.erase(waypoints.begin()); + metrics_stale = true; + signal_waypoint_reached.emit(&wp); + signal_event.emit(Message("waypoint-reached", &wp)); + } break; } else if(!block.has_track(*t_iter)) diff --git a/source/libr2c2/trainrouter.h b/source/libr2c2/trainrouter.h index 542d1ff..b56e932 100644 --- a/source/libr2c2/trainrouter.h +++ b/source/libr2c2/trainrouter.h @@ -45,6 +45,7 @@ private: ON_THE_WAY, WAITING_FOR_SEQUENCE, RESERVED_TO_END, + ADVANCED_TO_END, ARRIVED };