From e16fb5be90c889c371cbb0ca2444735c2e12073c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 18 Feb 2018 12:35:45 -0500 Subject: 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. --- src/entity_manager.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/entity_manager.h') 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: database_type entities; std::vector slotAvailable; + std::set allEntities; std::map, std::set> cachedComponents; id_type nextEntityID = 0; @@ -59,12 +60,14 @@ public: // If the database is saturated, add a new element for the new entity. entities.emplace_back(); slotAvailable.push_back(false); + allEntities.insert(nextEntityID); return nextEntityID++; } else { // If there is an available slot in the database, use it. id_type id = nextEntityID++; slotAvailable[id] = false; + allEntities.insert(id); // Fast forward the next available slot pointer to an available slot. while ((nextEntityID < entities.size()) && !slotAvailable[nextEntityID]) @@ -89,6 +92,8 @@ public: cache.second.erase(entity); } + allEntities.erase(entity); + // Destroy the data entities[entity].components.clear(); @@ -202,6 +207,11 @@ public: return getEntitiesWithComponentsHelper(componentTypes); } + + const std::set& getEntities() const + { + return allEntities; + } }; template <> -- cgit 1.4.1