]> git.tdb.fi Git - libs/game.git/blobdiff - source/game/system.cpp
Enforce correct access to buffered components
[libs/game.git] / source / game / system.cpp
index 87ba3b691eb20f5aa7311440b82d85cfe41d39e7..4c1f4fbba01fa46ecc8b39c9a9dcb80172925c6b 100644 (file)
@@ -1,7 +1,44 @@
 #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)
+       {
+#ifdef DEBUG
+               if(d.unblock)
+                       d.unblock(d.flags);
+#endif
+               if(d.prepare)
+                       d.prepare(stage);
+       }
+}
+
+void System::end_tick()
+{
+       for(const Dependency &d: dependencies)
+       {
+               if(d.commit)
+                       d.commit(stage);
+#ifdef DEBUG
+               if(d.block)
+                       d.block(d.flags);
+#endif
+       }
+
+       if(active==this)
+               active = nullptr;
+}
+
 void System::deferred_tick()
 {
        for(const auto &f: deferred_queue)