#ifndef MSP_GAME_BASICSYSTEM_
#define MSP_GAME_BASICSYSTEM_
-#include <msp/time/timedelta.h>
-#include "pool.h"
#include "stage.h"
#include "system.h"
namespace Msp::Game {
-template<typename T>
-concept HasPreTick = requires(T x) { x.pre_tick(); };
-
template<typename T>
concept HasTick = requires(T x) { x.tick(Time::TimeDelta()); };
template<typename T>
-concept HasPostTick = requires(T x) { x.post_tick(); };
-
-template<typename T>
+ requires std::is_base_of_v<Component, T> && HasTick<T>
class BasicSystem: public System
{
public:
BasicSystem(Stage &s): System(s) { }
- void pre_tick() override;
void tick(Time::TimeDelta) override;
- void post_tick() override;
};
-template<typename T>
-void BasicSystem<T>::pre_tick()
-{
- if constexpr(HasPreTick<T>)
- stage.iterate_objects<T>([](T &obj){ obj.pre_tick(); });
-}
-
template<typename T>
void BasicSystem<T>::tick(Time::TimeDelta dt)
{
- if constexpr(HasTick<T>)
- stage.iterate_objects<T>([dt](T &obj){ obj.tick(dt); });
-}
-
-template<typename T>
-void BasicSystem<T>::post_tick()
-{
- if constexpr(HasPostTick<T>)
- stage.iterate_objects<T>([](T &obj){ obj.post_tick(); });
+ stage.iterate_objects<T>([dt](T &obj){ obj.tick(dt); });
}
} // namespace Msp::Game
virtual ~Component() = default;
Handle<Entity> get_entity() const { return entity; }
-
- virtual void pre_tick() { }
- virtual void tick(Time::TimeDelta) { }
- virtual void post_tick() { }
};
} // namespace Msp::Game
void Stage::tick(Time::TimeDelta dt)
{
- for(const auto &s: systems)
- s->pre_tick();
for(const auto &s: systems)
s->tick(dt);
- for(const auto &s: systems)
- s->post_tick();
}
} // namespace Msp::Game
public:
virtual ~System() = default;
- virtual void pre_tick() = 0;
virtual void tick(Time::TimeDelta) = 0;
- virtual void post_tick() = 0;
};
} // namespace Msp::Game