45 : settings_{
settings}, random_{seed} {
47 throw std::invalid_argument{
"aegis2d: spawn intervals must be positive and ordered"};
49 until_next_ = draw_interval();
57 void update(
const Tick& tick, std::vector<Vec2>& spawns) {
59 until_next_ -= tick.
delta();
60 while (until_next_ <= 0.0F) {
61 spawns.push_back(draw_point());
62 until_next_ += draw_interval();
76 [[nodiscard]]
float until_next() const noexcept {
return until_next_; }
79 Vec2 draw_point() noexcept {
83 float draw_interval() noexcept {
87 SpawnSettings settings_;
89 float until_next_ = 0.0F;
Seeded pseudo-random generator (PCG32), for gameplay the server must replay.
Definition random.hpp:16
constexpr float uniform() noexcept
Real number between 0 and 1.
Definition random.hpp:75
Decides when and where entities spawn, the same way for the same seed.
Definition spawner.hpp:37
const SpawnSettings & settings() const noexcept
Spawn line and intervals.
Definition spawner.hpp:72
RandomSpawner(const SpawnSettings &settings, std::uint64_t seed)
Creates a spawner whose first spawn is one random interval away.
Definition spawner.hpp:44
float until_next() const noexcept
Time left before the next spawn.
Definition spawner.hpp:76
void update(const Tick &tick, std::vector< Vec2 > &spawns)
Moves time forward by one tick and lists the spawns that fall in it.
Definition spawner.hpp:57
core::Random & random() noexcept
Random numbers of the spawner, to decide more about the spawned entities.
Definition spawner.hpp:68
Vector and matrix types of the engine (GLM behind engine names).
Entity-Component-System used by client and server.
Definition animation.hpp:13
glm::vec2 Vec2
2D vector of floats: positions, velocities, sizes (glm::vec2).
Definition math.hpp:19
Seeded random numbers that are the same on every platform.
Where and how often a RandomSpawner makes entities appear.
Definition spawner.hpp:18
float min_interval
Shortest time between two spawns, in seconds; must be above 0.
Definition spawner.hpp:24
Vec2 from
One end of the spawn line, in logical pixels.
Definition spawner.hpp:20
float max_interval
Longest time between two spawns, in seconds; at least min_interval.
Definition spawner.hpp:26
Vec2 to
Other end of the spawn line; equal to from for a single spawn point.
Definition spawner.hpp:22
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
Systems and the scheduler that updates them in order, once per tick.