]> git.tdb.fi Git - libs/game.git/blob - source/game/basicsystem.h
Implement base support for buffered components
[libs/game.git] / source / game / basicsystem.h
1 #ifndef MSP_GAME_BASICSYSTEM_
2 #define MSP_GAME_BASICSYSTEM_
3
4 #include "stage.h"
5 #include "system.h"
6
7 namespace Msp::Game {
8
9 template<typename T>
10 concept HasTick = requires(T x) { x.tick(Time::TimeDelta()); };
11
12 template<typename T>
13         requires std::is_base_of_v<Component, T> && HasTick<T>
14 class BasicSystem: public System
15 {
16 public:
17         BasicSystem(Stage &);
18
19         void tick(Time::TimeDelta) override;
20 };
21
22
23 template<typename T>
24 BasicSystem::BasicSystem(Stage &s):
25         System(s)
26 {
27         declare_dependency<T>(UPDATE);
28 }
29
30 template<typename T>
31 void BasicSystem<T>::tick(Time::TimeDelta dt)
32 {
33         stage.iterate_objects<T>([dt](T &obj){ obj.tick(dt); });
34 }
35
36 } // namespace Msp::Game
37
38 #endif