#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)