Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::ecs::RandomSpawner Class Reference

Decides when and where entities spawn, the same way for the same seed. More...

#include <aegis2d/ecs/spawner.hpp>

Public Member Functions

 RandomSpawner (const SpawnSettings &settings, std::uint64_t seed)
 Creates a spawner whose first spawn is one random interval away.
 
void update (const Tick &tick, std::vector< Vec2 > &spawns)
 Moves time forward by one tick and lists the spawns that fall in it.
 
core::Random & random () noexcept
 Random numbers of the spawner, to decide more about the spawned entities.
 
const SpawnSettings & settings () const noexcept
 Spawn line and intervals.
 
float until_next () const noexcept
 Time left before the next spawn.
 

Detailed Description

Decides when and where entities spawn, the same way for the same seed.

It owns a core::Random seeded once: the spawn times and points depend only on the seed and on the time spent, so a server started with a recorded seed replays the same game, and a test can check exact spawns. It creates no entity itself: update() lists the points due this tick and the game creates what it wants there, like trigger_weapons() does for shots. Use random() to draw anything else about the new entities (a phase, a type), so that it also follows the seed. Spawns fall on the first tick at or after their time, so the same seed gives the same points at any tick rate.

Constructor & Destructor Documentation

◆ RandomSpawner()

aegis2d::ecs::RandomSpawner::RandomSpawner ( const SpawnSettings &  settings,
std::uint64_t  seed 
)
inline

Creates a spawner whose first spawn is one random interval away.

Parameters
settingsSpawn line and intervals.
seedSeed of its random numbers.
Exceptions
std::invalid_argumentIf min_interval is not above 0 or max_interval is below it.

Member Function Documentation

◆ random()

core::Random & aegis2d::ecs::RandomSpawner::random ( )
inlinenoexcept

Random numbers of the spawner, to decide more about the spawned entities.

Returns
Its generator; numbers drawn from it are part of the seeded sequence.

◆ settings()

const SpawnSettings & aegis2d::ecs::RandomSpawner::settings ( ) const
inlinenoexcept

Spawn line and intervals.

Returns
The settings given to the constructor.

◆ until_next()

float aegis2d::ecs::RandomSpawner::until_next ( ) const
inlinenoexcept

Time left before the next spawn.

Returns
Seconds, above 0 between two updates.

◆ update()

void aegis2d::ecs::RandomSpawner::update ( const Tick &  tick,
std::vector< Vec2 > &  spawns 
)
inline

Moves time forward by one tick and lists the spawns that fall in it.

A tick longer than the shortest interval can hold several spawns, listed in order.

Parameters
tickStep of the simulation.
spawnsCleared, then filled with the point of each spawn due this tick.

The documentation for this class was generated from the following file: