X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fstage.h;h=6af3b60a62596b97d61f833baa0c937c395b063a;hb=41fa4483d8f017175800992d8fdacd7ee312d0c3;hp=dbffc9960bedb4fd89c55a232dd6dd91f0fb68c5;hpb=6a93721ab67315e916f6c649b1f7bc5447d611a4;p=libs%2Fgame.git diff --git a/source/game/stage.h b/source/game/stage.h index dbffc99..6af3b60 100644 --- a/source/game/stage.h +++ b/source/game/stage.h @@ -2,8 +2,11 @@ #define MSP_GAME_STAGE_H_ #include +#include #include #include "eventbus.h" +#include "events.h" +#include "eventsource.h" #include "handle.h" namespace Msp::Game { @@ -13,20 +16,28 @@ class System; class Stage { +public: + using EventSource = Game::EventSource; + private: + DataFile::Collection &resources; 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; std::vector> systems; public: - Stage(); + Stage(DataFile::Collection &); ~Stage(); + DataFile::Collection &get_resources() const { return resources; } 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 +48,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