]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/system.h
Add a way for systems to do things at the end of a tick
[libs/game.git] / source / game / system.h
index 88ba291fb50bcb05e9881014f5e6096f34939daa..3b379178c1b6e27972cd60f9bfa31441bafbebe2 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GAME_SYSTEM_H_
 #define MSP_GAME_SYSTEM_H_
 
+#include <functional>
 #include <msp/time/timedelta.h>
 
 namespace Msp::Game {
@@ -11,14 +12,20 @@ class System
 {
 protected:
        Stage &stage;
+       std::vector<std::function<void()>> deferred_queue;
 
        System(Stage &s): stage(s) { }
 public:
        virtual ~System() = default;
 
-       virtual void pre_tick() = 0;
+       Stage &get_stage() const { return stage; }
+
        virtual void tick(Time::TimeDelta) = 0;
-       virtual void post_tick() = 0;
+       virtual void deferred_tick();
+
+protected:
+       template<typename F>
+       void defer(F &&f) { deferred_queue.emplace_back(std::forward<F>(f)); }
 };
 
 } // namespace Msp::Game