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