diff options
Diffstat (limited to 'src/components/mappable.h')
-rw-r--r-- | src/components/mappable.h | 208 |
1 files changed, 110 insertions, 98 deletions
diff --git a/src/components/mappable.h b/src/components/mappable.h index 633cdf4..6f3d38e 100644 --- a/src/components/mappable.h +++ b/src/components/mappable.h | |||
@@ -2,14 +2,47 @@ | |||
2 | #define MAPPABLE_H_0B0316FB | 2 | #define MAPPABLE_H_0B0316FB |
3 | 3 | ||
4 | #include <map> | 4 | #include <map> |
5 | #include <string> | ||
6 | #include <vector> | ||
7 | #include <list> | ||
5 | #include "component.h" | 8 | #include "component.h" |
6 | #include "renderer/texture.h" | 9 | #include "renderer/texture.h" |
7 | #include "collision.h" | 10 | #include "collision.h" |
8 | #include "map.h" | 11 | #include "entity_manager.h" |
9 | 12 | ||
10 | class MappableComponent : public Component { | 13 | class MappableComponent : public Component { |
11 | public: | 14 | public: |
12 | 15 | ||
16 | using id_type = EntityManager::id_type; | ||
17 | |||
18 | /** | ||
19 | * Helper type that stores information about map adjacency. | ||
20 | */ | ||
21 | class Adjacent { | ||
22 | public: | ||
23 | |||
24 | enum class Type { | ||
25 | wall, | ||
26 | wrap, | ||
27 | warp, | ||
28 | reverse | ||
29 | }; | ||
30 | |||
31 | Adjacent( | ||
32 | Type type = Type::wall, | ||
33 | size_t mapId = 0) : | ||
34 | type(type), | ||
35 | mapId(mapId) | ||
36 | { | ||
37 | } | ||
38 | |||
39 | Type type; | ||
40 | size_t mapId; | ||
41 | }; | ||
42 | |||
43 | /** | ||
44 | * Helper type that stores information about collision boundaries. | ||
45 | */ | ||
13 | class Boundary { | 46 | class Boundary { |
14 | public: | 47 | public: |
15 | 48 | ||
@@ -20,121 +53,100 @@ public: | |||
20 | double lower, | 53 | double lower, |
21 | double upper, | 54 | double upper, |
22 | Type type) : | 55 | Type type) : |
23 | axis_(axis), | 56 | axis(axis), |
24 | lower_(lower), | 57 | lower(lower), |
25 | upper_(upper), | 58 | upper(upper), |
26 | type_(type) | 59 | type(type) |
27 | { | ||
28 | } | ||
29 | |||
30 | inline double getAxis() const | ||
31 | { | ||
32 | return axis_; | ||
33 | } | ||
34 | |||
35 | inline double getLower() const | ||
36 | { | ||
37 | return lower_; | ||
38 | } | ||
39 | |||
40 | inline double getUpper() const | ||
41 | { | ||
42 | return upper_; | ||
43 | } | ||
44 | |||
45 | inline Type getType() const | ||
46 | { | 60 | { |
47 | return type_; | ||
48 | } | 61 | } |
49 | 62 | ||
50 | private: | 63 | double axis; |
51 | 64 | double lower; | |
52 | double axis_; | 65 | double upper; |
53 | double lower_; | 66 | Type type; |
54 | double upper_; | ||
55 | Type type_; | ||
56 | }; | 67 | }; |
57 | 68 | ||
58 | MappableComponent( | 69 | /** |
59 | Texture tileset, | 70 | * Helper types for efficient storage and lookup of collision boundaries. |
60 | Texture font) : | 71 | */ |
61 | tileset_(std::move(tileset)), | ||
62 | font_(std::move(font)) | ||
63 | { | ||
64 | } | ||
65 | |||
66 | using asc_boundaries_type = | 72 | using asc_boundaries_type = |
67 | std::multimap< | 73 | std::multimap< |
68 | double, | 74 | double, |
69 | Boundary, | 75 | const Boundary, |
70 | std::less<double>>; | 76 | std::less<double>>; |
71 | 77 | ||
72 | using desc_boundaries_type = | 78 | using desc_boundaries_type = |
73 | std::multimap< | 79 | std::multimap< |
74 | double, | 80 | double, |
75 | Boundary, | 81 | const Boundary, |
76 | std::greater<double>>; | 82 | std::greater<double>>; |
77 | 83 | ||
78 | inline size_t getMapId() const | 84 | /** |
79 | { | 85 | * Constructor for initializing the tileset and font attributes, as they are |
80 | return mapId_; | 86 | * not default constructible. |
81 | } | 87 | */ |
82 | 88 | MappableComponent( | |
83 | inline void setMapId(size_t v) | 89 | Texture tileset, |
84 | { | 90 | Texture font) : |
85 | mapId_ = v; | 91 | tileset(std::move(tileset)), |
86 | } | 92 | font(std::move(font)) |
87 | |||
88 | inline desc_boundaries_type& getLeftBoundaries() | ||
89 | { | ||
90 | return leftBoundaries_; | ||
91 | } | ||
92 | |||
93 | inline asc_boundaries_type& getRightBoundaries() | ||
94 | { | ||
95 | return rightBoundaries_; | ||
96 | } | ||
97 | |||
98 | inline desc_boundaries_type& getUpBoundaries() | ||
99 | { | ||
100 | return upBoundaries_; | ||
101 | } | ||
102 | |||
103 | inline asc_boundaries_type& getDownBoundaries() | ||
104 | { | ||
105 | return downBoundaries_; | ||
106 | } | ||
107 | |||
108 | inline const Texture& getTileset() const | ||
109 | { | ||
110 | return tileset_; | ||
111 | } | ||
112 | |||
113 | inline void setTileset(Texture v) | ||
114 | { | ||
115 | tileset_ = std::move(v); | ||
116 | } | ||
117 | |||
118 | inline const Texture& getFont() const | ||
119 | { | ||
120 | return font_; | ||
121 | } | ||
122 | |||
123 | inline void setFont(Texture v) | ||
124 | { | 93 | { |
125 | font_ = std::move(v); | ||
126 | } | 94 | } |
127 | 95 | ||
128 | private: | 96 | /** |
129 | 97 | * The ID of the map in the world definition that this entity represents. | |
130 | size_t mapId_ = -1; | 98 | * |
131 | 99 | * @managed_by RealizingSystem | |
132 | desc_boundaries_type leftBoundaries_; | 100 | */ |
133 | asc_boundaries_type rightBoundaries_; | 101 | size_t mapId; |
134 | desc_boundaries_type upBoundaries_; | 102 | |
135 | asc_boundaries_type downBoundaries_; | 103 | /** |
136 | Texture tileset_; | 104 | * The title of the map, which is displayed at the bottom of the screen. |
137 | Texture font_; | 105 | */ |
106 | std::string title; | ||
107 | |||
108 | /** | ||
109 | * The map data. | ||
110 | * | ||
111 | * @managed_by RealizingSystem | ||
112 | */ | ||
113 | std::vector<int> tiles; | ||
114 | |||
115 | /** | ||
116 | * These objects describe the behavior of the four edges of the map. | ||
117 | * | ||
118 | * @managed_by RealizingSystem | ||
119 | */ | ||
120 | Adjacent leftAdjacent; | ||
121 | Adjacent rightAdjacent; | ||
122 | Adjacent upAdjacent; | ||
123 | Adjacent downAdjacent; | ||
124 | |||
125 | /** | ||
126 | * Collision boundaries, for detecting when a ponderable entity is colliding | ||
127 | * with the environment. | ||
128 | * | ||
129 | * @managed_by MappingSystem | ||
130 | */ | ||
131 | desc_boundaries_type leftBoundaries; | ||
132 | asc_boundaries_type rightBoundaries; | ||
133 | desc_boundaries_type upBoundaries; | ||
134 | asc_boundaries_type downBoundaries; | ||
135 | |||
136 | /** | ||
137 | * The list of entities representing the objects owned by the map. | ||
138 | * | ||
139 | * @managed_by RealizingSystem | ||
140 | */ | ||
141 | std::list<id_type> objects; | ||
142 | |||
143 | /** | ||
144 | * The tilesets for the map and the map name. | ||
145 | * | ||
146 | * TODO: These probably do not belong here. | ||
147 | */ | ||
148 | Texture tileset; | ||
149 | Texture font; | ||
138 | }; | 150 | }; |
139 | 151 | ||
140 | #endif /* end of include guard: MAPPABLE_H_0B0316FB */ | 152 | #endif /* end of include guard: MAPPABLE_H_0B0316FB */ |