1 #ifndef MSP_GAME_STAGE_H_
2 #define MSP_GAME_STAGE_H_
5 #include <msp/time/timedelta.h>
8 #include "eventsource.h"
19 using EventSource = Game::EventSource<Events::EntityCreated, Events::EntityDestroyed,
20 Events::ComponentCreated, Events::ComponentDestroyed>;
25 EventSource event_source;
26 /* Use unique_ptr because there's only one root per stage so it's pointless
27 to put it in a pool. */
28 std::unique_ptr<Root> root;
29 std::vector<std::unique_ptr<System>> systems;
35 PoolPool &get_pools() { return pools; }
36 EventBus &get_event_bus() { return event_bus; }
37 EventSource &get_event_source() { return event_source; }
38 Handle<Root> get_root() { return Handle<Root>::from_object(root.get()); }
40 template<typename T, typename F>
41 void iterate_objects(const F &);
43 template<typename T, typename... Args>
44 T &add_system(Args &&...);
46 const std::vector<std::unique_ptr<System>> &get_systems() const { return systems; }
48 void tick(Time::TimeDelta);
51 template<typename T, typename F>
52 void Stage::iterate_objects(const F &func)
54 pools.get_pool<T>().iterate_objects(func);
57 template<typename T, typename... Args>
58 T &Stage::add_system(Args &&... args)
60 systems.emplace_back(std::make_unique<T>(*this, std::forward<Args>(args)...));
61 return static_cast<T &>(*systems.back());
64 } // namespace Msp::Game