From da3df061699203eccc9a0c98becaee3ce8050a4f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 5 Feb 2018 11:51:24 -0500 Subject: Whitespace changes --- src/entity_manager.h | 64 ++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'src/entity_manager.h') diff --git a/src/entity_manager.h b/src/entity_manager.h index 5f0f2d4..a36d720 100644 --- a/src/entity_manager.h +++ b/src/entity_manager.h @@ -13,30 +13,30 @@ class EntityManager { struct EntityData { std::map> components; }; - + std::map entities; std::map, std::set> cachedComponents; - + int nextEntityID = 0; - + template std::set getEntitiesWithComponentsHelper(std::set& componentTypes) { componentTypes.insert(typeid(T)); - + return getEntitiesWithComponents(componentTypes); } - + template std::set getEntitiesWithComponents(std::set& componentTypes) { return getEntitiesWithComponentsHelper(componentTypes); } - + public: EntityManager() = default; EntityManager(const EntityManager& copy) = delete; - + int emplaceEntity() { // Find a suitable entity ID @@ -44,76 +44,76 @@ class EntityManager { { nextEntityID++; } - + if (nextEntityID < 0) { nextEntityID = 0; - + while ((entities.count(nextEntityID) == 1) && (nextEntityID >= 0)) { nextEntityID++; } - + assert(nextEntityID >= 0); } - + // Initialize the data int id = nextEntityID++; entities[id]; - + return id; } - + void deleteEntity(int entity) { assert(entities.count(entity) == 1); - + // Uncache components for (auto& cache : cachedComponents) { cache.second.erase(entity); } - + // Destroy the data entities.erase(entity); } - + template T& emplaceComponent(int entity, Args&&... args) { assert(entities.count(entity) == 1); - + EntityData& data = entities[entity]; std::type_index componentType = typeid(T); - + assert(data.components.count(componentType) == 0); - + // Initialize the component std::unique_ptr ptr = std::unique_ptr(new T(std::forward(args)...)); T& component = *ptr; data.components[componentType] = std::move(ptr); - + // Invalidate related caches erase_if(cachedComponents, [&componentType] (std::pair, std::set>& cache) { return cache.first.count(componentType) == 1; }); - + return component; } - + template void removeComponent(int entity) { assert(entities.count(entity) == 1); - + EntityData& data = entities[entity]; std::type_index componentType = typeid(T); - + assert(data.components.count(componentType) == 1); - + // Destroy the component data.components.erase(componentType); - + // Uncache the component for (auto& cache : cachedComponents) { @@ -123,25 +123,25 @@ class EntityManager { } } } - + template T& getComponent(int entity) { assert(entities.count(entity) == 1); - + EntityData& data = entities[entity]; std::type_index componentType = typeid(T); - + assert(data.components.count(componentType) == 1); - + return *((T*)data.components[componentType].get()); } - + template std::set getEntitiesWithComponents() { std::set componentTypes; - + return getEntitiesWithComponentsHelper(componentTypes); } }; -- cgit 1.4.1