]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/route.cpp
Add a generic link interface as well
[r2c2.git] / source / libr2c2 / route.cpp
index be2eefc258ea8cfc7e135932e9ab325c1611ee96..e3dfe36961c66a5a9e37d518373cc927d18df4c2 100644 (file)
@@ -83,9 +83,9 @@ list<Track *> dijkstra(const TrackIter &from, const Pred &goal)
                        break;
                }
 
-               unsigned paths = lowest.track.endpoint().paths;
-               for(unsigned i=0; paths>>i; ++i)
-                       if(paths&(1<<i))
+               const TrackType::Endpoint &ep = lowest.track.endpoint();
+               for(unsigned i=0; ep.paths>>i; ++i)
+                       if(ep.has_path(i))
                        {
                                TrackIter next = lowest.track.next(i);
                                if(!next)
@@ -196,9 +196,9 @@ void Route::update_turnouts()
 
                                if(unsigned tid2 = links[j]->get_turnout_id())
                                {
-                                       const TrackType::Endpoint &ep = links[j]->get_type().get_endpoint(links[j]->get_endpoint_by_link(**i));
+                                       const TrackType::Endpoint &ep = links[j]->get_type().get_endpoint(links[j]->get_link_slot(**i));
                                        int p = get_turnout(tid2);
-                                       if(p>=0 && !(ep.paths&(1<<p)))
+                                       if(p>=0 && !ep.has_path(p))
                                        {
                                                // The linked track is a turnout and has a path which is incompatible with this endpoint
                                                mask &= ~endpoints[j].paths;
@@ -345,12 +345,12 @@ RouteValidityMask Route::check_validity(Track &trk) const
 
                if(unsigned tid = (*i)->get_turnout_id())
                {
-                       const TrackType::Endpoint &ep = (*i)->get_type().get_endpoint((*i)->get_endpoint_by_link(trk));
+                       const TrackType::Endpoint &ep = (*i)->get_type().get_endpoint((*i)->get_link_slot(trk));
                        int path = get_turnout(tid);
                        if(path>=0)
                        {
                                // Linking to a turnout with path set is only good if we're continuing that path
-                               if(ep.paths&(1<<path))
+                               if(ep.has_path(path))
                                        result |= ROUTE_LINEAR;
                        }
                        else
@@ -364,17 +364,17 @@ RouteValidityMask Route::check_validity(Track &trk) const
                                                unsigned tid2 = tlinks[j]->get_turnout_id();
                                                if(tid2)
                                                {
-                                                       const TrackType::Endpoint &ep2 = tlinks[j]->get_type().get_endpoint(tlinks[j]->get_endpoint_by_link(**i));
+                                                       const TrackType::Endpoint &ep2 = tlinks[j]->get_type().get_endpoint(tlinks[j]->get_link_slot(**i));
                                                        path = get_turnout(tid2);
                                                        // Ignore a linked turnout with some other path set
-                                                       if(path>=0 && !(ep2.paths&(1<<path)))
+                                                       if(path>=0 && !ep2.has_path(path))
                                                                continue;
                                                }
 
                                                ++count;
 
                                                const TrackType::Endpoint &ep2 = (*i)->get_type().get_endpoint(j);
-                                               if(!(ep.paths&ep2.paths))
+                                               if(!ep.has_common_paths(ep2))
                                                        // Impossible path through the turnout - not good
                                                        result &= ~ROUTE_SMOOTH;
                                        }
@@ -438,14 +438,13 @@ void Route::Loader::finish()
                if(j==turnouts.end())
                        continue;
 
-               unsigned path_mask = 1<<j->second;
                const vector<TrackType::Endpoint> &eps = (*i)->get_type().get_endpoints();
                for(unsigned k=0; k<eps.size(); ++k)
-                       if(eps[k].paths&path_mask)
+                       if(eps[k].has_path(j->second))
                        {
                                Track *link = (*i)->get_link(k);
                                if(!obj.tracks.count(link))
-                                       obj.add_track_chain(*link, link->get_endpoint_by_link(**i), turnouts);
+                                       obj.add_track_chain(*link, link->get_link_slot(**i), turnouts);
                                if(!obj.tracks.count(*i))
                                        obj.add_track_chain(**i, k, turnouts);
                                break;