]> git.tdb.fi Git - libs/game.git/blob - source/game/system.cpp
Implement base support for buffered components
[libs/game.git] / source / game / system.cpp
1 #include "system.h"
2
3 using namespace std;
4
5 namespace Msp::Game {
6
7 thread_local System *System::active = nullptr;
8
9 void System::begin_tick()
10 {
11         if(active)
12                 throw logic_error("System::active != nullptr");
13         active = this;
14
15         for(const Dependency &d: dependencies)
16                 if(d.prepare)
17                         d.prepare(stage);
18 }
19
20 void System::end_tick()
21 {
22         for(const Dependency &d: dependencies)
23                 if(d.commit)
24                         d.commit(stage);
25
26         if(active==this)
27                 active = nullptr;
28 }
29
30 void System::deferred_tick()
31 {
32         for(const auto &f: deferred_queue)
33                 f();
34         deferred_queue.clear();
35 }
36
37 } // namespace Msp::Game