diff options
Diffstat (limited to 'src/entity_manager.cpp')
| -rw-r--r-- | src/entity_manager.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
| diff --git a/src/entity_manager.cpp b/src/entity_manager.cpp new file mode 100644 index 0000000..4bdfe8a --- /dev/null +++ b/src/entity_manager.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #ifndef ENTITY_MANAGER_CPP_42D78C22 | ||
| 2 | #define ENTITY_MANAGER_CPP_42D78C22 | ||
| 3 | |||
| 4 | #include "entity_manager.h" | ||
| 5 | |||
| 6 | template <> | ||
| 7 | std::set<int> EntityManager::getEntitiesWithComponents<>(std::set<std::type_index>& componentTypes) | ||
| 8 | { | ||
| 9 | if (cachedComponents.count(componentTypes) == 1) | ||
| 10 | { | ||
| 11 | return cachedComponents[componentTypes]; | ||
| 12 | } | ||
| 13 | |||
| 14 | std::set<int>& cache = cachedComponents[componentTypes]; | ||
| 15 | for (auto& entity : entities) | ||
| 16 | { | ||
| 17 | EntityData& data = entity.second; | ||
| 18 | bool cacheEntity = true; | ||
| 19 | |||
| 20 | for (auto& componentType : componentTypes) | ||
| 21 | { | ||
| 22 | if (data.components.count(componentType) == 0) | ||
| 23 | { | ||
| 24 | cacheEntity = false; | ||
| 25 | break; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | if (cacheEntity) | ||
| 30 | { | ||
| 31 | cache.insert(entity.first); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | return cache; | ||
| 36 | } | ||
| 37 | |||
| 38 | #endif /* end of include guard: ENTITY_MANAGER_CPP_42D78C22 */ | ||
