]> git.tdb.fi Git - libs/game.git/blob - source/game/system.cpp
Enforce correct access to 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         {
17 #ifdef DEBUG
18                 if(d.unblock)
19                         d.unblock(d.flags);
20 #endif
21                 if(d.prepare)
22                         d.prepare(stage);
23         }
24 }
25
26 void System::end_tick()
27 {
28         for(const Dependency &d: dependencies)
29         {
30                 if(d.commit)
31                         d.commit(stage);
32 #ifdef DEBUG
33                 if(d.block)
34                         d.block(d.flags);
35 #endif
36         }
37
38         if(active==this)
39                 active = nullptr;
40 }
41
42 void System::deferred_tick()
43 {
44         for(const auto &f: deferred_queue)
45                 f();
46         deferred_queue.clear();
47 }
48
49 } // namespace Msp::Game