37 [[nodiscard]]
static constexpr Timer every(
float seconds)
noexcept {
38 return Timer{.
period = seconds, .left = seconds, .repeat =
true};
44 [[nodiscard]]
static constexpr Timer after(
float seconds)
noexcept {
45 return Timer{.
period = seconds, .left = seconds, .repeat =
false};
56inline std::uint32_t
advance(
Timer& timer,
float seconds)
noexcept {
57 if (!timer.running || timer.done) {
60 timer.left -= std::max(seconds, 0.0F);
61 if (timer.left > 0.0F) {
69 if (timer.period <= 0.0F) {
73 std::uint32_t fires = 0;
74 while (timer.left <= 0.0F) {
75 timer.left += timer.period;
93 const float delta = tick.
delta();
95 for (std::uint32_t fires =
advance(timer, delta); fires > 0; --fires) {
96 fired.push_back(entity);
Handle to an entity: 32 bits made of a 24-bit index and an 8-bit generation.
Definition entity.hpp:23
Entry point of the ECS: creates entities and stores their components.
Definition registry.hpp:34
View< Components... > view()
View on the entities that own all the listed components.
Definition registry.hpp:222
Generational entity handle: an index into the component pools plus a generation.
Entity-Component-System used by client and server.
Definition animation.hpp:13
void fire_timers(Registry ®istry, const Tick &tick, std::vector< Entity > &fired)
Advances every Timer by one tick and lists the entities whose timer fired.
Definition timers.hpp:91
std::uint32_t advance(Animation &animation, float seconds) noexcept
Moves an animation forward and tells which frame it shows.
Definition animation.hpp:21
Registry: owns the entities and one component pool per component type.
One simulation step, as the systems see it.
Definition system.hpp:23
constexpr float delta() const noexcept
Duration of the step in seconds, to scale values given per second.
Definition system.hpp:32
Fires every period seconds (a tower that shoots, a wave every 30 s), or once after a delay (a bomb,...
Definition timers.hpp:22
bool running
false while paused: the time does not run.
Definition timers.hpp:30
static constexpr Timer after(float seconds) noexcept
A timer that fires once, seconds from now.
Definition timers.hpp:44
bool done
true once a one-shot timer has fired; it never fires again.
Definition timers.hpp:32
float left
Seconds before the next fire.
Definition timers.hpp:26
float period
Seconds between two fires of a repeating timer; not used by a one-shot one.
Definition timers.hpp:24
bool repeat
true to fire every period, false to fire once.
Definition timers.hpp:28
static constexpr Timer every(float seconds) noexcept
A timer that fires every seconds, the first time seconds from now.
Definition timers.hpp:37
Systems and the scheduler that updates them in order, once per tick.