diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-06-26 19:59:28 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-06-26 19:59:28 -0400 |
commit | 428c401f9c1053f7e13ffe641758dfb72791d8dc (patch) | |
tree | 3b7c74e0346db3d08319e309c37e975e19395d74 /src/system_manager.h | |
parent | 55c8a14a7e2b2dadf0def3e09f970818164366f5 (diff) | |
download | therapy-428c401f9c1053f7e13ffe641758dfb72791d8dc.tar.gz therapy-428c401f9c1053f7e13ffe641758dfb72791d8dc.tar.bz2 therapy-428c401f9c1053f7e13ffe641758dfb72791d8dc.zip |
Player now moves
Diffstat (limited to 'src/system_manager.h')
-rw-r--r-- | src/system_manager.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/system_manager.h b/src/system_manager.h new file mode 100644 index 0000000..8f76db2 --- /dev/null +++ b/src/system_manager.h | |||
@@ -0,0 +1,37 @@ | |||
1 | #ifndef SYSTEM_MANAGER_H_544E6056 | ||
2 | #define SYSTEM_MANAGER_H_544E6056 | ||
3 | |||
4 | #include <list> | ||
5 | #include <memory> | ||
6 | #include <map> | ||
7 | #include <typeindex> | ||
8 | #include "system.h" | ||
9 | |||
10 | class SystemManager { | ||
11 | private: | ||
12 | std::list<std::unique_ptr<System>> loop; | ||
13 | std::map<std::type_index, System*> systems; | ||
14 | |||
15 | public: | ||
16 | template <class T, class... Args> | ||
17 | void emplaceSystem(Game& game, Args&&... args) | ||
18 | { | ||
19 | std::unique_ptr<T> ptr = std::unique_ptr<T>(new T(game, std::forward<Args>(args)...)); | ||
20 | std::type_index systemType = typeid(T); | ||
21 | |||
22 | systems[systemType] = ptr.get(); | ||
23 | loop.push_back(std::move(ptr)); | ||
24 | } | ||
25 | |||
26 | template <class T> | ||
27 | T& getSystem() | ||
28 | { | ||
29 | std::type_index systemType = typeid(T); | ||
30 | |||
31 | assert(systems.count(systemType) == 1); | ||
32 | |||
33 | return *((T*)systems[systemType]); | ||
34 | } | ||
35 | }; | ||
36 | |||
37 | #endif /* end of include guard: SYSTEM_MANAGER_H_544E6056 */ | ||