]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/terrain.h
Store routing information in TrainRoutePlanner to avoid threading problems
[r2c2.git] / source / libr2c2 / terrain.h
1 #ifndef LIBR2C2_TERRAIN_H_
2 #define LIBR2C2_TERRAIN_H_
3
4 #include "object.h"
5 #include "terraintype.h"
6
7 namespace R2C2 {
8
9 class Terrain: public Object
10 {
11 public:
12         class Loader: public Msp::DataFile::ObjectLoader<Terrain>
13         {
14         private:
15                 unsigned next_tile;
16
17         public:
18                 Loader(Terrain &);
19
20         private:
21                 void position(float, float, float);
22                 void rotation(float);
23                 void size(unsigned, unsigned);
24                 void tile();
25                 void tile_coords(unsigned, unsigned);
26         };
27
28         struct Node
29         {
30                 class Loader: public Msp::DataFile::ObjectLoader<Node>
31                 {
32                 private:
33                         Terrain &terrain;
34
35                 public:
36                         Loader(Terrain &, Node &);
37
38                 private:
39                         void ground(unsigned);
40                 };
41
42                 float elevation;
43                 unsigned ground;
44                 unsigned wall;
45
46                 Node();
47
48                 void save(std::list<Msp::DataFile::Statement> &) const;
49         };
50
51         struct Tile
52         {
53                 class Loader: public Msp::DataFile::ObjectLoader<Tile>
54                 {
55                 private:
56                         Terrain &terrain;
57
58                 public:
59                         Loader(Terrain &, Tile &);
60
61                 private:
62                         void ground(unsigned);
63                         void elevation(float);
64                         void node(unsigned);
65                 };
66
67                 Node nodes[4];
68                 bool secondary_axis;
69
70                 Tile();
71
72                 void set_node_elevation(unsigned, float);
73                 void update_axis();
74                 void save(std::list<Msp::DataFile::Statement> &) const;
75                 template<typename T>
76                 T find_mode(T Node::*) const;
77         };
78
79         struct NodeCoordinates
80         {
81                 unsigned x, y;
82                 unsigned i;
83
84                 NodeCoordinates();
85                 NodeCoordinates(unsigned, unsigned, unsigned);
86         };
87
88         sigc::signal<void, unsigned, unsigned> signal_size_changed;
89         sigc::signal<void, unsigned, unsigned> signal_tile_changed;
90
91 private:
92         const TerrainType &type;
93         unsigned width;
94         unsigned height;
95         std::vector<Tile> tiles;
96
97 public:
98         Terrain(Layout &, const TerrainType &);
99         virtual ~Terrain();
100
101         virtual Terrain *clone(Layout *) const;
102
103         virtual const TerrainType &get_type() const { return type; }
104         virtual void set_position(const Vector &);
105         virtual void set_rotation(const Angle &);
106         virtual void set_tilt(const Angle &) { }
107
108         void set_size(unsigned, unsigned);
109         unsigned get_width() const { return width; }
110         unsigned get_height() const { return height; }
111         const Tile &get_tile(unsigned, unsigned) const;
112         void set_node_elevation(const NodeCoordinates &, float, bool = false);
113         float get_node_elevation(const NodeCoordinates &) const;
114         Vector get_node_position(const NodeCoordinates &) const;
115         NodeCoordinates get_closest_node(const Ray &) const;
116
117         void save(std::list<Msp::DataFile::Statement> &) const;
118 };
119
120 } // namespace R2C2
121
122 #endif