]> git.tdb.fi Git - r2c2.git/commitdiff
Allow an undetermined turnout at the beginning of a route
authorMikko Rasa <tdb@tdb.fi>
Thu, 5 Feb 2015 14:01:13 +0000 (16:01 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 5 Feb 2015 14:01:13 +0000 (16:01 +0200)
If route plans are regenerated when the train's last vehicle is on the
sensor following a turnout in a points-facing movement, the first track
of the lead route is a turnout with undetermined path.  Route_changed
would then try to figure out which route the next allocation will occur
on and fail at the very beginning because advance_to_track refused to
use the undetermined turnout.

source/libr2c2/trainrouter.cpp
source/libr2c2/trainrouter.h

index 13b2970883535f99a9869939f83e32ab81ace7e0..a1582fd65c64920346c1566f3a161d46b4df6dc8 100644 (file)
@@ -79,7 +79,7 @@ void TrainRouter::route_changed()
                TrackIter track = train.get_block_allocator().first().track_iter();
                for(; track; track=track.next())
                {
-                       if(!advance_to_track(reserving_route, *track))
+                       if(!advance_to_track(reserving_route, track))
                        {
                                already_at_end = true;
                                break;
@@ -307,7 +307,7 @@ void TrainRouter::block_reserved(Block &block, Train *t)
                track = t->get_block_allocator().first().track_iter();
                for(; track; track=track.next())
                {
-                       if(!advance_to_track(reserving_route, *track))
+                       if(!advance_to_track(reserving_route, track))
                                throw logic_error("internal error (reservation outside of route)");
                        else if(&track->get_block()==&block)
                                break;
@@ -318,7 +318,7 @@ void TrainRouter::block_reserved(Block &block, Train *t)
        expected to be allocated next. */
        for(; track; track=track.next((*reserving_route)->get_path(*track)))
        {
-               if(!advance_to_track(reserving_route, *track))
+               if(!advance_to_track(reserving_route, track))
                {
                        // We've reached the end of the route.  Stop here.
                        arrival = RESERVED_TO_END;
@@ -444,16 +444,16 @@ bool TrainRouter::create_lead_route()
        return true;
 }
 
-bool TrainRouter::is_valid_for_track(const Route &route, Track &track) const
+bool TrainRouter::is_valid_for_track(const Route &route, const TrackIter &track) const
 {
-       if(!route.has_track(track))
+       if(!route.has_track(*track))
                return false;
-       if(track.get_type().is_turnout() && route.get_turnout(track.get_turnout_address())<0)
+       if(track->get_type().is_turnout() && route.get_turnout(track->get_turnout_address())<0 && route.has_track(*track.flip()))
                return false;
        return true;
 }
 
-bool TrainRouter::advance_to_track(RouteList::iterator &route, Track &track)
+bool TrainRouter::advance_to_track(RouteList::iterator &route, const TrackIter &track)
 {
        if(!is_valid_for_track(**route, track))
        {
index 7a560a11904d7475b961198d191b6103585ec311..3d8b72246f2d02ce492b7c6672ba9a4ee5c1711a 100644 (file)
@@ -106,8 +106,8 @@ private:
 
        void create_metrics();
        bool create_lead_route();
-       bool is_valid_for_track(const Route &, Track &) const;
-       bool advance_to_track(RouteList::iterator &, Track &);
+       bool is_valid_for_track(const Route &, const TrackIter &) const;
+       bool advance_to_track(RouteList::iterator &, const TrackIter &);
 
        static void start_planning(Layout &);
 };