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