]> git.tdb.fi Git - libs/game.git/blob - source/game/stage.h
060759696914264ce5c177c0d1674a154b253e52
[libs/game.git] / source / game / stage.h
1 #ifndef MSP_GAME_STAGE_H_
2 #define MSP_GAME_STAGE_H_
3
4 #include <memory>
5 #include <msp/time/timedelta.h>
6 #include "handle.h"
7 #include "root.h"
8
9 namespace Msp::Game {
10
11 class System;
12
13 class Stage
14 {
15 private:
16         PoolPool pools;
17         Root root;
18         std::vector<std::unique_ptr<System>> systems;
19
20 public:
21         Stage();
22         ~Stage();
23
24         PoolPool &get_pools() { return pools; }
25         Handle<Root> get_root() { return Handle<Root>::from_object(&root); }
26
27         template<typename T, typename F>
28         void iterate_objects(const F &);
29
30         template<typename T, typename... Args>
31         T &add_system(Args &&...);
32
33         const std::vector<std::unique_ptr<System>> &get_systems() const { return systems; }
34
35         void tick(Time::TimeDelta);
36 };
37
38 template<typename T, typename F>
39 void Stage::iterate_objects(const F &func)
40 {
41         pools.get_pool<T>().iterate_objects(func);
42 }
43
44 template<typename T, typename... Args>
45 T &Stage::add_system(Args &&... args)
46 {
47         systems.emplace_back(std::make_unique<T>(*this, std::forward<Args>(args)...));
48         return static_cast<T &>(*systems.back());
49 }
50
51 } // namespace Msp::Game
52
53 #endif