summary refs log tree commit diff stats
path: root/src/components/mappable.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/mappable.h')
-rw-r--r--src/components/mappable.h152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/components/mappable.h b/src/components/mappable.h new file mode 100644 index 0000000..e92074e --- /dev/null +++ b/src/components/mappable.h
@@ -0,0 +1,152 @@
1#ifndef MAPPABLE_H_0B0316FB
2#define MAPPABLE_H_0B0316FB
3
4#include <map>
5#include <string>
6#include <vector>
7#include <list>
8#include "component.h"
9#include "renderer/texture.h"
10#include "components/ponderable.h"
11#include "entity_manager.h"
12
13class MappableComponent : public Component {
14public:
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 */
46 class Boundary {
47 public:
48
49 using Type = PonderableComponent::Collision;
50
51 Boundary(
52 double axis,
53 double lower,
54 double upper,
55 Type type) :
56 axis(axis),
57 lower(lower),
58 upper(upper),
59 type(type)
60 {
61 }
62
63 double axis;
64 double lower;
65 double upper;
66 Type type;
67 };
68
69 /**
70 * Helper types for efficient storage and lookup of collision boundaries.
71 */
72 using asc_boundaries_type =
73 std::multimap<
74 double,
75 const Boundary,
76 std::less<double>>;
77
78 using desc_boundaries_type =
79 std::multimap<
80 double,
81 const Boundary,
82 std::greater<double>>;
83
84 /**
85 * Constructor for initializing the tileset and font attributes, as they are
86 * not default constructible.
87 */
88 MappableComponent(
89 Texture tileset,
90 Texture font) :
91 tileset(std::move(tileset)),
92 font(std::move(font))
93 {
94 }
95
96 /**
97 * The ID of the map in the world definition that this entity represents.
98 *
99 * @managed_by RealizingSystem
100 */
101 size_t mapId;
102
103 /**
104 * The title of the map, which is displayed at the bottom of the screen.
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;
150};
151
152#endif /* end of include guard: MAPPABLE_H_0B0316FB */