X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fgame%2Fstage.h;h=d7793e22f60ec21fd52acab1b8af9aafbe2f4d94;hb=c3ac50ad3e79b26d1d99bd222a7e43adb86c2c1e;hp=dbffc9960bedb4fd89c55a232dd6dd91f0fb68c5;hpb=6a93721ab67315e916f6c649b1f7bc5447d611a4;p=libs%2Fgame.git diff --git a/source/game/stage.h b/source/game/stage.h index dbffc99..d7793e2 100644 --- a/source/game/stage.h +++ b/source/game/stage.h @@ -4,6 +4,8 @@ #include #include #include "eventbus.h" +#include "events.h" +#include "eventsource.h" #include "handle.h" namespace Msp::Game { @@ -13,9 +15,14 @@ class System; class Stage { +public: + using EventSource = Game::EventSource; + private: PoolPool pools; EventBus event_bus; + EventSource event_source; /* Use unique_ptr because there's only one root per stage so it's pointless to put it in a pool. */ std::unique_ptr root; @@ -27,6 +34,7 @@ public: PoolPool &get_pools() { return pools; } EventBus &get_event_bus() { return event_bus; } + EventSource &get_event_source() { return event_source; } Handle get_root() { return Handle::from_object(root.get()); } template @@ -37,22 +45,34 @@ public: const std::vector> &get_systems() const { return systems; } + template + T *get_system() const; + void tick(Time::TimeDelta); }; template -void Stage::iterate_objects(const F &func) +inline void Stage::iterate_objects(const F &func) { pools.get_pool().iterate_objects(func); } template -T &Stage::add_system(Args &&... args) +inline T &Stage::add_system(Args &&... args) { systems.emplace_back(std::make_unique(*this, std::forward(args)...)); return static_cast(*systems.back()); } +template +inline T *Stage::get_system() const +{ + for(const auto &s: systems) + if(T *ts = dynamic_cast(s.get())) + return ts; + return nullptr; +} + } // namespace Msp::Game #endif