]> git.tdb.fi Git - libs/game.git/blob - source/game/basicsystem.h
aa5d9426ea1053d2e4532a91b6b407d5c166c10b
[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 &s): System(s) { }
18
19         void tick(Time::TimeDelta) override;
20 };
21
22 template<typename T>
23 void BasicSystem<T>::tick(Time::TimeDelta dt)
24 {
25         stage.iterate_objects<T>([dt](T &obj){ obj.tick(dt); });
26 }
27
28 } // namespace Msp::Game
29
30 #endif