summary refs log tree commit diff stats
path: root/src/entity_manager.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2015-06-18 12:14:05 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2015-06-18 12:14:05 -0400
commit55c8a14a7e2b2dadf0def3e09f970818164366f5 (patch)
treee05795e83aa61dc5b951a70328b8499d3c583ea6 /src/entity_manager.cpp
parent879c2c04d9c3879f871cfe79f9b25fd23c5184b4 (diff)
downloadtherapy-55c8a14a7e2b2dadf0def3e09f970818164366f5.tar.gz
therapy-55c8a14a7e2b2dadf0def3e09f970818164366f5.tar.bz2
therapy-55c8a14a7e2b2dadf0def3e09f970818164366f5.zip
Now displaying player character
Diffstat (limited to 'src/entity_manager.cpp')
-rw-r--r--src/entity_manager.cpp38
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
6template <>
7std::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 */