X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fstage.h;h=03a8adebc2531e605e5e7e3a58f8ca1dfb573c36;hb=12c863fc1bc5456a4b3aceacc88904d76bd1d8bb;hp=6af3b60a62596b97d61f833baa0c937c395b063a;hpb=41fa4483d8f017175800992d8fdacd7ee312d0c3;p=libs%2Fgame.git diff --git a/source/game/stage.h b/source/game/stage.h index 6af3b60..03a8ade 100644 --- a/source/game/stage.h +++ b/source/game/stage.h @@ -8,32 +8,42 @@ #include "events.h" #include "eventsource.h" #include "handle.h" +#include "mspgame_api.h" +#include "reflection.h" +#include "systemscheduler.h" namespace Msp::Game { +class Camera; class Root; class System; -class Stage +class MSPGAME_API Stage { public: using EventSource = Game::EventSource; + Events::ComponentCreated, Events::ComponentDestroyed, Events::CameraChanged>; private: + Reflection::Reflector &reflector; DataFile::Collection &resources; PoolPool pools; EventBus event_bus; EventSource event_source; + EventObserver event_observer; /* 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; + SystemScheduler scheduler; + Handle active_camera; + bool pending_reschedule = false; public: - Stage(DataFile::Collection &); + Stage(Reflection::Reflector &, DataFile::Collection &); ~Stage(); + Reflection::Reflector &get_reflector() const { return reflector; } DataFile::Collection &get_resources() const { return resources; } PoolPool &get_pools() { return pools; } EventBus &get_event_bus() { return event_bus; } @@ -46,11 +56,20 @@ public: template T &add_system(Args &&...); + void remove_system(System &); const std::vector> &get_systems() const { return systems; } template T *get_system() const; + void set_active_camera(Handle); + Handle get_active_camera() const { return active_camera; } + + void synthesize_initial_events(EventObserver &); +private: + void synthesize_initial_events(Handle, EventObserver &); + +public: void tick(Time::TimeDelta); }; @@ -63,8 +82,13 @@ inline void Stage::iterate_objects(const F &func) template inline T &Stage::add_system(Args &&... args) { - systems.emplace_back(std::make_unique(*this, std::forward(args)...)); - return static_cast(*systems.back()); + // Ensure that a reflected class exists for scheduling + reflector.get_or_create_class(); + + auto &sys = systems.emplace_back(std::make_unique(*this, std::forward(args)...)); + scheduler.add_system(*sys); + pending_reschedule = true; + return static_cast(*sys); } template