]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/system.cpp
Implement base support for buffered components
[libs/game.git] / source / game / system.cpp
index 87ba3b691eb20f5aa7311440b82d85cfe41d39e7..33157c3946990c6c64b25b1b8b6f0ee8782f35da 100644 (file)
@@ -1,7 +1,32 @@
 #include "system.h"
 
+using namespace std;
+
 namespace Msp::Game {
 
+thread_local System *System::active = nullptr;
+
+void System::begin_tick()
+{
+       if(active)
+               throw logic_error("System::active != nullptr");
+       active = this;
+
+       for(const Dependency &d: dependencies)
+               if(d.prepare)
+                       d.prepare(stage);
+}
+
+void System::end_tick()
+{
+       for(const Dependency &d: dependencies)
+               if(d.commit)
+                       d.commit(stage);
+
+       if(active==this)
+               active = nullptr;
+}
+
 void System::deferred_tick()
 {
        for(const auto &f: deferred_queue)