From: Mikko Rasa Date: Thu, 12 Feb 2015 16:11:06 +0000 (+0200) Subject: Be more permissive when checking route continuity X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=83c6923396fcfa42e6adf949b9476663f322748b;p=r2c2.git Be more permissive when checking route continuity 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. --- diff --git a/source/libr2c2/trainrouter.cpp b/source/libr2c2/trainrouter.cpp index 3d8b9d4..9befe47 100644 --- a/source/libr2c2/trainrouter.cpp +++ b/source/libr2c2/trainrouter.cpp @@ -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 &routers) diff --git a/source/libr2c2/trainrouter.h b/source/libr2c2/trainrouter.h index b56e932..9fab289 100644 --- a/source/libr2c2/trainrouter.h +++ b/source/libr2c2/trainrouter.h @@ -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 &);