From 97d7fb425da906947cc45e11fadb35f708da50d6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 7 Feb 2018 14:13:32 -0500 Subject: Changed EntityManager to dense vector This should improve speed, because entity lookup will be O(1) instead of O(log n). Deletion is also O(1). Insert stays at potentially O(n), but still should be overall faster than the previous method. Also replaced some asserts with exceptions. Also made Component polymorphic so that deletion actually works properly. --- src/entity_manager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/entity_manager.cpp') diff --git a/src/entity_manager.cpp b/src/entity_manager.cpp index 9ad758b..f792e17 100644 --- a/src/entity_manager.cpp +++ b/src/entity_manager.cpp @@ -4,17 +4,18 @@ #include "entity_manager.h" template <> -std::set EntityManager::getEntitiesWithComponents<>(std::set& componentTypes) +std::set EntityManager::getEntitiesWithComponents<>( + std::set& componentTypes) { if (cachedComponents.count(componentTypes) == 1) { return cachedComponents[componentTypes]; } - std::set& cache = cachedComponents[componentTypes]; - for (auto& entity : entities) + std::set& cache = cachedComponents[componentTypes]; + for (id_type entity = 0; entity < entities.size(); entity++) { - EntityData& data = entity.second; + EntityData& data = entities[entity]; bool cacheEntity = true; for (auto& componentType : componentTypes) @@ -28,7 +29,7 @@ std::set EntityManager::getEntitiesWithComponents<>(std::set