X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fstage.h;h=d7793e22f60ec21fd52acab1b8af9aafbe2f4d94;hb=c3ac50ad3e79b26d1d99bd222a7e43adb86c2c1e;hp=47ca47d9a572b6c5742e5a5279877d5af983584c;hpb=c7d0e1aff305778f97974b329826628966380158;p=libs%2Fgame.git diff --git a/source/game/stage.h b/source/game/stage.h index 47ca47d..d7793e2 100644 --- a/source/game/stage.h +++ b/source/game/stage.h @@ -3,6 +3,9 @@ #include #include +#include "eventbus.h" +#include "events.h" +#include "eventsource.h" #include "handle.h" namespace Msp::Game { @@ -12,8 +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; @@ -24,6 +33,8 @@ public: ~Stage(); 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 @@ -34,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