]> 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 9e6ec2a6e923e7ca6befd3f66ae0c67aa0119099..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,6 +12,7 @@ class System
 {
 protected:
        Stage &stage;
+       std::vector<std::function<void()>> deferred_queue;
 
        System(Stage &s): stage(s) { }
 public:
@@ -19,6 +21,11 @@ public:
        Stage &get_stage() const { return stage; }
 
        virtual void tick(Time::TimeDelta) = 0;
+       virtual void deferred_tick();
+
+protected:
+       template<typename F>
+       void defer(F &&f) { deferred_queue.emplace_back(std::forward<F>(f)); }
 };
 
 } // namespace Msp::Game