]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/stage.h
Decorate things which constitute the public API of the library
[libs/game.git] / source / game / stage.h
index a046947f57ad7d0f49e43621f003ac739a4d5713..03a8adebc2531e605e5e7e3a58f8ca1dfb573c36 100644 (file)
@@ -8,6 +8,9 @@
 #include "events.h"
 #include "eventsource.h"
 #include "handle.h"
+#include "mspgame_api.h"
+#include "reflection.h"
+#include "systemscheduler.h"
 
 namespace Msp::Game {
 
@@ -15,13 +18,14 @@ class Camera;
 class Root;
 class System;
 
-class Stage
+class MSPGAME_API Stage
 {
 public:
        using EventSource = Game::EventSource<Events::EntityCreated, Events::EntityDestroyed,
                Events::ComponentCreated, Events::ComponentDestroyed, Events::CameraChanged>;
 
 private:
+       Reflection::Reflector &reflector;
        DataFile::Collection &resources;
        PoolPool pools;
        EventBus event_bus;
@@ -31,12 +35,15 @@ private:
        to put it in a pool. */
        std::unique_ptr<Root> root;
        std::vector<std::unique_ptr<System>> systems;
+       SystemScheduler scheduler;
        Handle<Camera> 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; }
@@ -75,8 +82,13 @@ inline void Stage::iterate_objects(const F &func)
 template<typename T, typename... Args>
 inline T &Stage::add_system(Args &&... args)
 {
-       systems.emplace_back(std::make_unique<T>(*this, std::forward<Args>(args)...));
-       return static_cast<T &>(*systems.back());
+       // Ensure that a reflected class exists for scheduling
+       reflector.get_or_create_class<T>();
+
+       auto &sys = systems.emplace_back(std::make_unique<T>(*this, std::forward<Args>(args)...));
+       scheduler.add_system(*sys);
+       pending_reschedule = true;
+       return static_cast<T &>(*sys);
 }
 
 template<typename T>