diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-18 12:35:45 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-18 12:35:45 -0500 |
commit | e16fb5be90c889c371cbb0ca2444735c2e12073c (patch) | |
tree | cbaa20e14a34c460b6c9886f266c4b4b6f62ae87 /src/entity_manager.h | |
parent | ed08b673c50b076042d8f0c49501372168142764 (diff) | |
download | therapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.tar.gz therapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.tar.bz2 therapy-e16fb5be90c889c371cbb0ca2444735c2e12073c.zip |
Implemented map adjacency
This brings along with it the ability to move to different maps, for which the PlayingSystem and PlayableComponent were introduced. The PlayingSystem is a general overseer system that handles big picture stuff like initializing the player and changing maps. The PlayableComponent represents the player. While the ControllableComponent is also likely to always only be on the player entity, the two are distinct by separation of concerns. This also required a refactoring of how collisions are processed, because of a bug where the player can move to a new map when horizontal collisions are checked, and vertical collisions are skipped, causing the player to clip through the ground because the normal force was never handled.
Diffstat (limited to 'src/entity_manager.h')
-rw-r--r-- | src/entity_manager.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/entity_manager.h b/src/entity_manager.h index 65fa6ca..1e8d31c 100644 --- a/src/entity_manager.h +++ b/src/entity_manager.h | |||
@@ -26,6 +26,7 @@ private: | |||
26 | 26 | ||
27 | database_type entities; | 27 | database_type entities; |
28 | std::vector<bool> slotAvailable; | 28 | std::vector<bool> slotAvailable; |
29 | std::set<id_type> allEntities; | ||
29 | std::map<std::set<std::type_index>, std::set<id_type>> cachedComponents; | 30 | std::map<std::set<std::type_index>, std::set<id_type>> cachedComponents; |
30 | 31 | ||
31 | id_type nextEntityID = 0; | 32 | id_type nextEntityID = 0; |
@@ -59,12 +60,14 @@ public: | |||
59 | // If the database is saturated, add a new element for the new entity. | 60 | // If the database is saturated, add a new element for the new entity. |
60 | entities.emplace_back(); | 61 | entities.emplace_back(); |
61 | slotAvailable.push_back(false); | 62 | slotAvailable.push_back(false); |
63 | allEntities.insert(nextEntityID); | ||
62 | 64 | ||
63 | return nextEntityID++; | 65 | return nextEntityID++; |
64 | } else { | 66 | } else { |
65 | // If there is an available slot in the database, use it. | 67 | // If there is an available slot in the database, use it. |
66 | id_type id = nextEntityID++; | 68 | id_type id = nextEntityID++; |
67 | slotAvailable[id] = false; | 69 | slotAvailable[id] = false; |
70 | allEntities.insert(id); | ||
68 | 71 | ||
69 | // Fast forward the next available slot pointer to an available slot. | 72 | // Fast forward the next available slot pointer to an available slot. |
70 | while ((nextEntityID < entities.size()) && !slotAvailable[nextEntityID]) | 73 | while ((nextEntityID < entities.size()) && !slotAvailable[nextEntityID]) |
@@ -89,6 +92,8 @@ public: | |||
89 | cache.second.erase(entity); | 92 | cache.second.erase(entity); |
90 | } | 93 | } |
91 | 94 | ||
95 | allEntities.erase(entity); | ||
96 | |||
92 | // Destroy the data | 97 | // Destroy the data |
93 | entities[entity].components.clear(); | 98 | entities[entity].components.clear(); |
94 | 99 | ||
@@ -202,6 +207,11 @@ public: | |||
202 | 207 | ||
203 | return getEntitiesWithComponentsHelper<R...>(componentTypes); | 208 | return getEntitiesWithComponentsHelper<R...>(componentTypes); |
204 | } | 209 | } |
210 | |||
211 | const std::set<id_type>& getEntities() const | ||
212 | { | ||
213 | return allEntities; | ||
214 | } | ||
205 | }; | 215 | }; |
206 | 216 | ||
207 | template <> | 217 | template <> |