Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
ParticleBursts.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "../core/Types.hpp"
4
5#include <algorithm>
6#include <cmath>
7#include <vector>
8
9namespace esengine::particle {
10
13 f32 time = 0.0f;
15};
16
23inline u32 burstsDue(const std::vector<ScheduledBurst>& schedule, f32 prev, f32 cur, f32 duration, bool looping) {
24 u32 total = 0;
25 const bool cycles = looping && duration > 0.0f;
26 const int first = cycles ? static_cast<int>(std::floor(std::max(prev, 0.0f) / duration)) : 0;
27 const int last = cycles ? static_cast<int>(std::floor(cur / duration)) : 0;
28 for (const ScheduledBurst& b : schedule) {
29 for (int k = first; k <= last; ++k) {
30 const f32 at = b.time + static_cast<f32>(k) * duration;
31 if (prev < at && at <= cur) total += b.count;
32 }
33 }
34 return total;
35}
36
37} // namespace esengine::particle
Core type definitions and utilities for ESEngine.
u32 burstsDue(const std::vector< ScheduledBurst > &schedule, f32 prev, f32 cur, f32 duration, bool looping)
How many particles the schedule releases while the emitter's clock goes from prev to cur.
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
float f32
32-bit floating point
Definition Types.hpp:59
One burst of a schedule: count particles at time seconds after the emitter starts emitting.