]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/tracktype.h
Add utility functions to make endpoint path mask operations clearer
[r2c2.git] / source / libr2c2 / tracktype.h
index d38f1b21b86d4f4fdac0f4e6f84d21804189c807..dd2a7c4ddf29f83c67d8bed648382d449412db46 100644 (file)
@@ -1,14 +1,7 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #ifndef LIBR2C2_TRACKTYPE_H_
 #define LIBR2C2_TRACKTYPE_H_
 
-#include <msp/datafile/loader.h>
+#include <msp/datafile/objectloader.h>
 #include "articlenumber.h"
 #include "geometry.h"
 #include "trackpart.h"
@@ -20,21 +13,28 @@ class TrackType
 public:
        struct Endpoint
        {
-               Point pos;
+               Vector pos;
                float dir;  // Direction outwards from the endpoint
                unsigned paths;
 
                Endpoint(float, float, float, unsigned);
+
+               bool has_path(unsigned p) const { return paths&(1<<p); }
+               bool has_common_paths(const Endpoint &e) const { return paths&e.paths; }
        };
 
-       class Loader: public Msp::DataFile::BasicLoader<TrackType>
+       class Loader: public Msp::DataFile::ObjectLoader<TrackType>
        {
+       private:
+               bool state_bits_set;
+
        public:
                Loader(TrackType &);
        private:
                virtual void finish();
                void part();
                void position(float, float, float);
+               void state_bits(unsigned);
        };
 
 private:
@@ -42,8 +42,9 @@ private:
        std::string description;
        std::vector<TrackPart> parts;
        std::vector<Endpoint> endpoints;
-       bool double_address;
+       unsigned state_bits;
        unsigned autofit_preference;
+       std::string object;
 
 public:
        TrackType(const ArticleNumber &);
@@ -54,14 +55,17 @@ public:
        float get_path_length(int) const;
        unsigned get_paths() const;
        unsigned get_n_paths() const;
+       unsigned get_state_bits() const { return state_bits; }
        bool is_turnout() const;
        bool is_dead_end() const;
-       bool is_double_address() const { return double_address; }
        unsigned get_autofit_preference() const { return autofit_preference; }
+       const std::string &get_object() const { return object; }
        const std::vector<TrackPart> &get_parts() const { return parts; }
        const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
        const Endpoint &get_endpoint(unsigned) const;
        TrackPoint get_point(unsigned, unsigned, float) const;
+       TrackPoint get_nearest_point(const Vector &) const;
+       bool collide_ray(const Vector &, const Vector &, float) const;
 
 private:
        void collect_endpoints();