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; }
49 T *get_system() const;
51 void tick(Time::TimeDelta);
54 template<typename T, typename F>
55 inline void Stage::iterate_objects(const F &func)
57 pools.get_pool<T>().iterate_objects(func);
60 template<typename T, typename... Args>
61 inline T &Stage::add_system(Args &&... args)
63 systems.emplace_back(std::make_unique<T>(*this, std::forward<Args>(args)...));
64 return static_cast<T &>(*systems.back());
68 inline T *Stage::get_system() const
70 for(const auto &s: systems)
71 if(T *ts = dynamic_cast<T *>(s.get()))
76 } // namespace Msp::Game