summary refs log tree commit diff stats
path: root/src/entity_manager.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:55:37 -0400
committerGitHub <noreply@github.com>2018-05-17 15:55:37 -0400
commit90aadf3844386824140a20d7fbb847bc16009a94 (patch)
tree6f83fce90e71abb22b1a8f3e09c79963b2a34d5d /src/entity_manager.cpp
parentbc63fa57ced1c7329f7fdcfd168eaf7e290158bc (diff)
parent86f0106d0523825549f1e74b835688c78a10cf6c (diff)
downloadtherapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.gz
therapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.bz2
therapy-90aadf3844386824140a20d7fbb847bc16009a94.zip
Merge pull request #7 from hatkirby/es-rewrite
The ECS rewrite exceeds the original branch in functionality, so it is time to merge it in.
Diffstat (limited to 'src/entity_manager.cpp')
-rw-r--r--src/entity_manager.cpp39
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..0aaaf8e --- /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
6template <>
7std::set<EntityManager::id_type> EntityManager::getEntitiesWithComponents<>(
8 std::set<std::type_index>& componentTypes) const
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 const 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 */