]> git.tdb.fi Git - r2c2.git/commitdiff
Move Endpoint inside TrackType
authorMikko Rasa <tdb@tdb.fi>
Mon, 25 Oct 2010 16:08:57 +0000 (16:08 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 25 Oct 2010 16:08:57 +0000 (16:08 +0000)
source/3d/track.cpp
source/libmarklin/block.cpp
source/libmarklin/endpoint.h [deleted file]
source/libmarklin/route.cpp
source/libmarklin/track.cpp
source/libmarklin/trackiter.cpp
source/libmarklin/trackpart.h
source/libmarklin/tracktype.cpp
source/libmarklin/tracktype.h
source/libmarklin/train.cpp

index baf35195ff3dd454ebd693cfb53a8b1eb6ae4ed6..49ef02e4ff06ae079968d5698c565b71e19f6f86 100644 (file)
@@ -29,7 +29,7 @@ Track3D::Track3D(Layout3D &l, Track &t):
        layout.add_track(*this);
        layout.get_scene().add(*this);
 
-       const vector<Endpoint> &type_eps = track.get_type().get_endpoints();
+       const vector<TrackType::Endpoint> &type_eps = track.get_type().get_endpoints();
        for(unsigned i=0; i<type_eps.size(); ++i)
                endpoints.push_back(new Endpoint3D(*this, i));
 }
index 952fe50d56adc538ad6f4e8cab526cb815485a33..02b6da5c7203dffaf346e4ad3690a0c77b1d2bee 100644 (file)
@@ -171,7 +171,7 @@ void Block::find_paths(Track &track, unsigned track_ep, unsigned path, set<Track
 {
        visited.insert(&track);
 
-       const vector<Marklin::Endpoint> &eps = track.get_type().get_endpoints();
+       const vector<TrackType::Endpoint> &eps = track.get_type().get_endpoints();
        for(unsigned i=0; i<eps.size(); ++i)
        {
                if(i==track_ep) continue;
diff --git a/source/libmarklin/endpoint.h b/source/libmarklin/endpoint.h
deleted file mode 100644 (file)
index 7382404..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
-#ifndef MARKLIN_ENDPOINT_H_
-#define MARKLIN_ENDPOINT_H_
-
-#include "geometry.h"
-
-namespace Marklin {
-
-struct Endpoint
-{
-       Point pos;
-       float dir;  // Direction outwards from the endpoint
-       unsigned paths;
-
-       Endpoint(): dir(0), paths(0) { }
-       Endpoint(float x, float y, float d, unsigned p): pos(x, y), dir(d), paths(p) { }
-};
-
-} // namespace Marklin
-
-#endif
index 6dc7ae51e13350efe01269c06c199fde829675f8..970c2d79dec63574691656f177af205208a3f751 100644 (file)
@@ -89,7 +89,7 @@ list<Track *> dijkstra(Track &from, unsigned ep, const Pred &goal)
                }
 
                const TrackType &type = lowest.track->get_type();
-               const vector<Endpoint> &eps = type.get_endpoints();
+               const vector<TrackType::Endpoint> &eps = type.get_endpoints();
                const vector<Track *> &links = lowest.track->get_links();
                for(unsigned i=0; i<eps.size(); ++i)
                {
@@ -184,7 +184,7 @@ void Route::update_turnouts()
                {
                        found.insert(tid);
 
-                       const vector<Endpoint> &endpoints = (*i)->get_type().get_endpoints();
+                       const vector<TrackType::Endpoint> &endpoints = (*i)->get_type().get_endpoints();
                        const vector<Track *> &links = (*i)->get_links();
 
                        // Build a combined path mask from linked endpoints
@@ -196,7 +196,7 @@ void Route::update_turnouts()
 
                                if(unsigned tid2 = links[j]->get_turnout_id())
                                {
-                                       const Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)];
+                                       const TrackType::Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)];
                                        int p = get_turnout(tid2);
                                        if(p>=0 && !(ep.paths&(1<<p)))
                                        {
@@ -333,7 +333,7 @@ unsigned Route::check_validity(Track &trk) const
                {
                        // Linked to an existing track - good
                        result |= 1;
-                       const vector<Endpoint> &endpoints = (*i)->get_type().get_endpoints();
+                       const vector<TrackType::Endpoint> &endpoints = (*i)->get_type().get_endpoints();
                        if(unsigned tid=(*i)->get_turnout_id())
                        {
                                int r = get_turnout(tid);
@@ -417,7 +417,7 @@ void Route::Loader::finish()
                        continue;
 
                unsigned path_mask = 1<<j->second;
-               const vector<Endpoint> &eps = (*i)->get_type().get_endpoints();
+               const vector<TrackType::Endpoint> &eps = (*i)->get_type().get_endpoints();
                for(unsigned k=0; k<eps.size(); ++k)
                        if(eps[k].paths&path_mask)
                        {
index 6ec3c3bf7cefc78041f3ddb357acdfb1b3fa203a..0a9f1ac83f8977f02935fd6f5838d93265a62278 100644 (file)
@@ -168,11 +168,11 @@ int Track::get_endpoint_by_link(Track &other) const
 
 Point Track::get_endpoint_position(unsigned epi) const
 {
-       const vector<Endpoint> &eps = type.get_endpoints();
+       const vector<TrackType::Endpoint> &eps = type.get_endpoints();
        if(epi>=eps.size())
-               throw InvalidParameterValue("Endpoint index out of range");
+               throw InvalidParameterValue("TrackType::Endpoint index out of range");
 
-       const Endpoint &ep = eps[epi];
+       const TrackType::Endpoint &ep = eps[epi];
 
        float c = cos(rot);
        float s = sin(rot);
@@ -185,11 +185,11 @@ Point Track::get_endpoint_position(unsigned epi) const
 
 float Track::get_endpoint_direction(unsigned epi) const
 {
-       const vector<Endpoint> &eps = type.get_endpoints();
+       const vector<TrackType::Endpoint> &eps = type.get_endpoints();
        if(epi>=eps.size())
-               throw InvalidParameterValue("Endpoint index out of range");
+               throw InvalidParameterValue("TrackType::Endpoint index out of range");
 
-       const Endpoint &ep = eps[epi];
+       const TrackType::Endpoint &ep = eps[epi];
 
        return rot+ep.dir;
 }
@@ -197,8 +197,8 @@ float Track::get_endpoint_direction(unsigned epi) const
 bool Track::snap_to(Track &other, bool link)
 {
        float limit = (link && !flex && !other.get_flex()) ? 1e-6 : 1e-4;
-       const vector<Endpoint> &eps = type.get_endpoints();
-       const vector<Endpoint> &other_eps = other.get_type().get_endpoints();
+       const vector<TrackType::Endpoint> &eps = type.get_endpoints();
+       const vector<TrackType::Endpoint> &other_eps = other.get_type().get_endpoints();
 
        for(unsigned i=0; i<eps.size(); ++i)
        {
@@ -244,7 +244,7 @@ bool Track::snap_to(Track &other, bool link)
 
 bool Track::snap(Point &pt, float &d) const
 {
-       const vector<Endpoint> &eps = type.get_endpoints();
+       const vector<TrackType::Endpoint> &eps = type.get_endpoints();
 
        for(unsigned i=0; i<eps.size(); ++i)
        {
index e8b327b0a245fd20ef1565960228d5c45de36f0e..6ee7231f924ebc9ab953f22c6ca922db81d010e4 100644 (file)
@@ -30,7 +30,7 @@ TrackIter::TrackIter(Track *t, unsigned e):
 
 int TrackIter::get_exit(unsigned path) const
 {
-       const vector<Endpoint> &eps = _track->get_type().get_endpoints();
+       const vector<TrackType::Endpoint> &eps = _track->get_type().get_endpoints();
        
        // Find an endpoint that's connected to the entry and has the requested path
        for(unsigned i=0; i<eps.size(); ++i)
index aebe7ef7f2418cb7c9511663a928b694ce3cb1e6..13e0f38528c86e94046e7dc2b03d8f71857e5931 100644 (file)
@@ -9,7 +9,6 @@ Distributed under the GPL
 #define MARKLIN_TRACKPART_H_
 
 #include <msp/datafile/loader.h>
-#include "endpoint.h"
 #include "geometry.h"
 
 namespace Marklin {
index 1a39877a94bbb649d86b193e133c4030aa61a1a1..8c1505b87033ca821526a7831f9a33d58d5b00cc 100644 (file)
@@ -154,6 +154,12 @@ void TrackType::collect_endpoints()
        }
 }
 
+TrackType::Endpoint::Endpoint(float x, float y, float d, unsigned p):
+       pos(x, y),
+       dir(d),
+       paths(p)
+{ }
+
 
 TrackType::Loader::Loader(TrackType &t):
        Msp::DataFile::BasicLoader<TrackType>(t)
index 99989be664ae15e7ba3f14dd64be865b8da186e5..902a2f6ddd561df38ecb1c84dbdfbb0fb3d2c79b 100644 (file)
@@ -9,7 +9,7 @@ Distributed under the GPL
 #define LIBMARKLIN_TRACKTYPE_H_
 
 #include <msp/datafile/loader.h>
-#include "endpoint.h"
+#include "geometry.h"
 #include "trackpart.h"
 
 namespace Marklin {
@@ -17,6 +17,15 @@ namespace Marklin {
 class TrackType
 {
 public:
+       struct Endpoint
+       {
+               Point pos;
+               float dir;  // Direction outwards from the endpoint
+               unsigned paths;
+
+               Endpoint(float, float, float, unsigned);
+       };
+
        class Loader: public Msp::DataFile::BasicLoader<TrackType>
        {
        public:
index cdb8e67d169297925a627c4b7556338316c0d9b6..11ec776497e436c64eea49d3a8bcaecdf1e27e11 100644 (file)
@@ -990,7 +990,7 @@ unsigned Train::reserve_more()
 
                if(block->get_turnout_id())
                {
-                       const Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
+                       const TrackType::Endpoint &track_ep = track->get_type().get_endpoints()[track.entry()];
                        bool multiple_paths = (track_ep.paths&(track_ep.paths-1));
 
                        if(multiple_paths || !last->get_turnout_id())