]> git.tdb.fi Git - r2c2.git/commitdiff
Be more permissive when checking route continuity
authorMikko Rasa <tdb@tdb.fi>
Thu, 12 Feb 2015 16:11:06 +0000 (18:11 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 12 Feb 2015 16:11:06 +0000 (18:11 +0200)
In some cases more than one consecutive route may end on the same track,
or a route might only go one track past the previous one, with that track
being a turnout with undetermined path.  Allow skipping routes to deal
with these situations, as long as we don't go completely off route.

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

index 3d8b9d4b7b42a3c7ee3c69c84a81407232107107..9befe4788c4b03114cfe4939f6ea7c02eee0fe06 100644 (file)
@@ -486,27 +486,25 @@ bool TrainRouter::create_lead_route()
        return true;
 }
 
-bool TrainRouter::is_valid_for_track(const Route &route, const TrackIter &track) const
-{
-       if(!route.has_track(*track))
-               return false;
-       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, const TrackIter &track)
 {
-       if(!is_valid_for_track(**route, track))
+       Track &prev_track = *track.flip();
+       unsigned taddr = (track->get_type().is_turnout() ? track->get_turnout_address() : 0);
+       for(unsigned i=0; route!=routes.end(); ++i)
        {
-               ++route;
-               if(route==routes.end())
-                       return false;
-               if(!is_valid_for_track(**route, track))
+               bool in_route = (*route)->has_track(*track);
+               bool prev_in_route = (*route)->has_track(prev_track);
+               bool known_path = (!taddr || (*route)->get_turnout(taddr)>=0);
+
+               if(in_route && (known_path || !prev_in_route))
+                       return true;
+               else if(i==0 || prev_in_route)
+                       ++route;
+               else
                        throw logic_error("internal error (routes are not continuous)");
        }
 
-       return true;
+       return false;
 }
 
 void TrainRouter::get_routers(Layout &layout, vector<TrainRouter *> &routers)
index b56e93281f7ade4c183edc4b3be223e4c5fe2a60..9fab2892efe15803da1f413277f7a6bd25678122 100644 (file)
@@ -108,7 +108,6 @@ private:
 
        void create_metrics();
        bool create_lead_route();
-       bool is_valid_for_track(const Route &, const TrackIter &) const;
        bool advance_to_track(RouteList::iterator &, const TrackIter &);
 
        static void get_routers(Layout &, std::vector<TrainRouter *> &);