X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fsystem.cpp;h=33157c3946990c6c64b25b1b8b6f0ee8782f35da;hb=a99b57a74252fd3de649d544d070b747f91fcf4d;hp=87ba3b691eb20f5aa7311440b82d85cfe41d39e7;hpb=e3b8bcdcb5abfdc4cfaf0af0f9633ac15d1f3b69;p=libs%2Fgame.git diff --git a/source/game/system.cpp b/source/game/system.cpp index 87ba3b6..33157c3 100644 --- a/source/game/system.cpp +++ b/source/game/system.cpp @@ -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)