|
Aegis2D
Modular C++26 2D game engine for networked games
|
Enemy waves from a data file: which entities appear, where and when. More...
#include <aegis2d/ecs/waves.hpp>
Public Member Functions | |
| WaveSchedule ()=default | |
| Creates an empty schedule, finished from the start. | |
| void | update (const Tick &tick, std::vector< WaveSpawn > &due) |
| Moves time forward by one tick and lists the spawns that fall in it. | |
| void | restart () noexcept |
| Goes back to the start of the schedule. | |
| bool | finished () const noexcept |
| Tells whether every spawn has been listed. | |
| const std::vector< WaveSpawn > & | spawns () const noexcept |
| Every spawn of the schedule. | |
| std::size_t | waves () const noexcept |
| Number of waves in the file. | |
| bool | loops () const noexcept |
| Tells whether the schedule starts again after its last spawn. | |
| float | duration () const noexcept |
| Time of the last spawn. | |
| float | elapsed () const noexcept |
| Time spent in the schedule (in the current loop). | |
Static Public Member Functions | |
| static WaveSchedule | from_config (const core::Config &config, std::span< const std::string_view > types={}) |
| Reads a schedule from a loaded configuration. | |
| static WaveSchedule | from_string (std::string_view text, std::span< const std::string_view > types={}) |
| Reads a schedule from JSON text. | |
| static WaveSchedule | from_file (const std::filesystem::path &path, std::span< const std::string_view > types={}) |
Reads a schedule from a JSON file, e.g. core::asset_path("waves/stage1.json"). | |
Enemy waves from a data file: which entities appear, where and when.
The file describes waves that follow each other, so a level is changed without recompiling. Each wave starts delay seconds after the last spawn of the previous wave (after the start for the first wave) and lists groups of spawns:
A group needs a type and a position; at (seconds from the start of the wave), count (1), every (seconds between two members, 0) and step (offset between two members, [0, 0]) are optional. Comments are allowed. The engine knows no entity type: update() lists the spawns due and the game creates them by type; give the known types to the loader to reject a typo when the file is read rather than in the middle of a game. Spawns fall on the first tick at or after their time, so the schedule plays the same at any tick rate.
|
default |
Creates an empty schedule, finished from the start.
|
inlinenoexcept |
Time of the last spawn.
|
inlinenoexcept |
Time spent in the schedule (in the current loop).
|
inlinenoexcept |
Tells whether every spawn has been listed.
true once the last spawn is past; never for a looping schedule.
|
inlinestatic |
Reads a schedule from a loaded configuration.
| config | Document whose root has waves (and optionally loop). |
| types | Entity types the game can create; empty to accept any type. |
| core::ConfigError | If the document does not describe valid waves; the message starts with the path of the faulty value, e.g. waves.1.spawns.0.type: .... |
|
inlinestatic |
Reads a schedule from a JSON file, e.g. core::asset_path("waves/stage1.json").
| path | File to read. |
| types | Entity types the game can create; empty to accept any type. |
| core::ConfigError | If the file cannot be read or does not describe valid waves; the message starts with the file path. |
|
inlinestatic |
Reads a schedule from JSON text.
| text | JSON document. |
| types | Entity types the game can create; empty to accept any type. |
| core::ConfigError | If text is not valid JSON or not valid waves. |
|
inlinenoexcept |
Tells whether the schedule starts again after its last spawn.
loop value of the file.
|
inlinenoexcept |
Goes back to the start of the schedule.
|
inlinenoexcept |
Every spawn of the schedule.
|
inline |
Moves time forward by one tick and lists the spawns that fall in it.
Spawns come in time order. A looping schedule starts again after its last spawn, the first wave waiting its delay again.
| tick | Step of the simulation. |
| due | Cleared, then filled with the spawns due this tick. |
|
inlinenoexcept |
Number of waves in the file.