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

Entity-Component-System used by client and server. More...

Namespaces

namespace  detail
 

Classes

struct  Aabb
 Axis-aligned box given by its two corners, in logical pixels. More...
 
struct  Animation
 Frames of the entity's Sprite shown in turn, at a steady rate. More...
 
struct  Award
 Points given to a player for a kill. More...
 
struct  Cell
 Column and row of a grid cell, from the top-left one. More...
 
struct  Collider
 Axis-aligned box an entity collides with. More...
 
class  CollisionGrid
 Broad phase of collision detection: a uniform grid over the play area. More...
 
struct  CollisionPair
 Two entities that may collide, the one with the smaller handle first. More...
 
struct  Contact
 Two entities whose boxes overlap and whose layers interact. More...
 
struct  Damage
 How much damage an entity deals to what it hits. More...
 
struct  DamageReport
 What apply_damage() did during one tick, in the order of the contacts. More...
 
struct  DestroyAfterAnimation
 Entity destroyed once its Animation has played to the end: a visual effect that lasts as long as its clip, such as an explosion. More...
 
class  Entity
 Handle to an entity: 32 bits made of a 24-bit index and an 8-bit generation. More...
 
class  EntityAllocator
 Hands out entity handles and recycles the indices of destroyed entities. More...
 
struct  Explosion
 An entity whose health reached zero blows up: an enemy shot down, or a player that loses a life. More...
 
class  FunctionSystem
 System made of a function, for logic that keeps no state of its own. More...
 
struct  Health
 How much damage an entity can still take. More...
 
struct  Hit
 One hit that removed health points. More...
 
class  ISystem
 Game logic run on the registry once per tick (movement, collisions, spawns...). More...
 
struct  Kill
 An entity whose health reached zero, and the hit that did it. More...
 
struct  LifeLost
 A player who lost a life during the tick. More...
 
struct  Lives
 Lives of a player, and how it comes back after losing one. More...
 
class  NavGrid
 Grid of cells that can be walked or not, each with a cost, and the shortest path between two of them. More...
 
struct  NavPath
 Path between two cells, found again only when the grid has changed. More...
 
struct  NetworkId
 Identity of an entity shared by the server and the clients. More...
 
struct  OffscreenDespawn
 Entity destroyed once it has left the play area for good. More...
 
struct  Owner
 Entity that created this one, e.g. the player who fired a missile. More...
 
struct  PathEnded
 An entity that reached the last waypoint of its path. More...
 
struct  PathFollower
 An entity that walks along waypoints, such as an enemy of a tower defense on the path found by NavGrid::find_path(). More...
 
struct  PlayerInput
 Actions a player holds during the tick, as received from its client. More...
 
class  PluginContext
 What a plugin can add to the game, given to its start function. More...
 
class  Plugins
 The plugins a game loaded, kept loaded as long as it lives. More...
 
class  RandomSpawner
 Decides when and where entities spawn, the same way for the same seed. More...
 
class  Registry
 Entry point of the ECS: creates entities and stores their components. More...
 
class  Scheduler
 Ordered list of named systems, all updated once per tick. More...
 
struct  Score
 Points a player has earned. More...
 
struct  ScoreValue
 Points earned by the player who destroys this entity. More...
 
struct  SineMotion
 Sine wave added to an entity's movement, like an enemy weaving up and down. More...
 
class  SparseSet
 Pool of one component type, stored in a sparse set. More...
 
class  SparseSetBase
 Type-erased part of a sparse set: which entities are in the pool, and where. More...
 
struct  SpawnSettings
 Where and how often a RandomSpawner makes entities appear. More...
 
struct  Sprite
 What an entity looks like. More...
 
struct  Tick
 One simulation step, as the systems see it. More...
 
struct  Timer
 Fires every period seconds (a tower that shoots, a wave every 30 s), or once after a delay (a bomb, a message that goes away). More...
 
struct  Transform
 Where an entity is. More...
 
struct  Velocity
 How fast an entity moves. More...
 
class  View
 Visits every entity that owns all of Components, with those components. More...
 
class  WaveSchedule
 Enemy waves from a data file: which entities appear, where and when. More...
 
struct  WaveSpawn
 One entity a WaveSchedule makes appear. More...
 

Enumerations

enum class  Action : std::uint8_t {
  Up = 1U << 0U , Down = 1U << 1U , Left = 1U << 2U , Right = 1U << 3U ,
  Fire = 1U << 4U
}
 Actions a player can hold, one bit each in PlayerInput. More...
 
enum class  Painted : std::uint8_t { Walkable , Blocked }
 What the painted cells of a tile layer are, for NavGrid::mark_tiles(). More...
 
enum class  TargetOrder : std::uint8_t { Nearest , MostAdvanced }
 Which targets come first in find_targets(). More...
 

Functions

std::uint32_t advance (Animation &animation, float seconds) noexcept
 Moves an animation forward and tells which frame it shows.
 
void animate_sprites (Registry &registry, const Tick &tick)
 Advances every animation by one tick and shows its frame.
 
void destroy_finished_animations (Registry &registry, std::vector< Entity > &destroyed)
 Destroys the effects whose animation has played to the end.
 
constexpr bool hits (const Collider &attacker, const Collider &target) noexcept
 Tells whether a collider can hit another one, according to their layers.
 
void find_contacts (const Registry &registry, std::span< const CollisionPair > candidates, std::vector< Contact > &out)
 Narrow phase: keeps the candidate pairs whose layers interact and boxes overlap.
 
std::vector< Contact > find_contacts (const Registry &registry, const CollisionGrid &grid)
 Broad and narrow phases on a grid built for this tick.
 
void apply_damage (Registry &registry, std::span< const Contact > contacts, DamageReport &report)
 Applies the damage of a tick's contacts to the entities' health.
 
std::size_t remove_casualties (Registry &registry, const DamageReport &report)
 Destroys the entities that died or were consumed during the tick.
 
bool left_for_good (Vec2 position, Vec2 half, Vec2 velocity, const Aabb &area) noexcept
 Tells whether a moving box has left an area and will not come back.
 
void despawn_outside (Registry &registry, const Aabb &area, std::vector< Entity > &despawned)
 Destroys the entities that have left the play area for good.
 
std::string to_string (Entity entity)
 Text form of a handle, for logs: Entity(3, 1) (index, generation) or Entity(null).
 
void publish_explosions (core::EventBus &events, const Registry &registry, const DamageReport &report)
 Publishes an Explosion for each kill of the tick, in the order of the kills.
 
void publish_deaths (core::EventBus &events, std::span< const LifeLost > lost)
 Publishes each player's death of the tick.
 
void handle_player_deaths (Registry &registry, const DamageReport &report, std::vector< LifeLost > &lost)
 Takes a life from each killed player and respawns those who have some left.
 
std::size_t players_left (const Registry &registry)
 Number of players still in the game.
 
bool game_over (const Registry &registry)
 Tells whether every player is out.
 
std::string_view name () noexcept
 Name of the module, used to check that it is linked.
 
Vec2 direction_of (const PlayerInput &input) noexcept
 Direction a player's input points to.
 
void apply_velocity (Registry &registry, const Tick &tick)
 Moves every entity by its velocity for one tick.
 
Vec2 sine_offset (const SineMotion &motion, float time) noexcept
 Offset of a sine motion from its path at a time.
 
void apply_sine_motion (Registry &registry, const Tick &tick)
 Moves every entity with a sine motion along its wave for one tick.
 
Vec2 half_extent_of (const Registry &registry, Entity entity)
 Half size of what must stay visible of an entity.
 
Vec2 clamp_into (Vec2 position, Vec2 half, const Aabb &area) noexcept
 Keeps a position inside an area, with a margin on each side.
 
float path_length (std::span< const Vec2 > waypoints) noexcept
 Length of a path.
 
Vec2 point_along (std::span< const Vec2 > waypoints, float distance) noexcept
 Point at a distance along a path.
 
float remaining (const PathFollower &follower) noexcept
 Distance a follower still has to walk.
 
void follow_paths (Registry &registry, const Tick &tick, std::vector< Entity > &arrived)
 Moves every PathFollower along its path for one tick and lists those that arrived.
 
void publish_path_ends (core::EventBus &events, const Registry &registry, std::span< const Entity > arrived)
 Publishes a PathEnded for each entity that arrived this tick.
 
std::optional< Entity > shooter_of (const Registry &registry, Entity killer)
 Player credited for a kill made by an entity.
 
void credit_kills (Registry &registry, const DamageReport &report, std::vector< Award > &awards)
 Adds the value of each killed entity to the score of the player who killed it.
 
template<typename Component >
void find_targets (const Registry &registry, const CollisionGrid &grid, Vec2 center, float radius, TargetOrder order, std::vector< Entity > &out)
 Lists the entities with a component whose center is within a radius of a point, in the order asked.
 
std::uint32_t advance (Timer &timer, float seconds) noexcept
 Moves a timer forward and tells how many times it fires.
 
void fire_timers (Registry &registry, const Tick &tick, std::vector< Entity > &fired)
 Advances every Timer by one tick and lists the entities whose timer fired.
 

Variables

constexpr std::string_view plugin_start = "aegis2d_plugin_start"
 Name of the C function a plugin exports, called once when it is loaded.
 

Detailed Description

Entity-Component-System used by client and server.

Enumeration Type Documentation

◆ Action

enum class aegis2d::ecs::Action : std::uint8_t
strong

Actions a player can hold, one bit each in PlayerInput.

Enumerator
Up 

Move up (towards y = 0).

Down 

Move down.

Left 

Move left.

Right 

Move right.

Fire 

Fire.

◆ Painted

enum class aegis2d::ecs::Painted : std::uint8_t
strong

What the painted cells of a tile layer are, for NavGrid::mark_tiles().

Enumerator
Walkable 

Painted cells can be walked, empty ones cannot (a layer that draws the path).

Blocked 

Painted cells are blocked, empty ones can be walked (a layer of walls).

◆ TargetOrder

enum class aegis2d::ecs::TargetOrder : std::uint8_t
strong

Which targets come first in find_targets().

Enumerator
Nearest 

The closest to the point first.

MostAdvanced 

The furthest along its path first: the least PathFollower remaining(), then the closest; entities that follow no path come last.

Function Documentation

◆ advance() [1/2]

std::uint32_t aegis2d::ecs::advance ( Animation &  animation,
float  seconds 
)
inlinenoexcept

Moves an animation forward and tells which frame it shows.

A looping clip wraps elapsed into [0, duration()), so the time never grows without bound; a clip that does not loop stops at its end.

Parameters
animationAnimation to advance.
secondsTime spent, such as tick.delta(); negative values count as 0.
Returns
The frame to show, Animation::frame().

◆ advance() [2/2]

std::uint32_t aegis2d::ecs::advance ( Timer &  timer,
float  seconds 
)
inlinenoexcept

Moves a timer forward and tells how many times it fires.

A repeating timer fires once per period elapsed, so a long tick (a stall, a slow machine) does not lose fires; a period of 0 or less fires once per call. A paused or done timer does not move.

Parameters
timerTimer to advance.
secondsTime spent, such as tick.delta(); negative values count as 0.
Returns
The number of fires during this time: 0 or 1 for a one-shot timer.

◆ animate_sprites()

void aegis2d::ecs::animate_sprites ( Registry &  registry,
const Tick &  tick 
)
inline

Advances every animation by one tick and shows its frame.

For each entity with Animation and Sprite, advance() moves the clip forward by tick.delta() and Sprite::frame becomes its frame. Run it once per tick, e.g. systems.add("animation", ecs::animate_sprites);; the frames then follow the time spent, not the tick or frame rate. Defined in the header because it reads components (see CollisionGrid::build()).

Parameters
registryWorld holding the sprites.
tickStep of the simulation.

◆ apply_damage()

void aegis2d::ecs::apply_damage ( Registry &  registry,
std::span< const Contact >  contacts,
DamageReport &  report 
)
inline

Applies the damage of a tick's contacts to the entities' health.

For each contact, in order, and each direction in which one entity hits the other (Contact::first_hits_second, Contact::second_hits_first), an attacker with a Damage component removes Damage::amount points from a target with a Health component. Then:

  • a target that reaches zero points or less is a Kill, credited to that attacker;
  • an attacker with Damage::consumed_on_hit is consumed, even by a target without Health (an indestructible wall);
  • an entity already consumed or killed during the tick takes no part in the next contacts: a missile overlapping two enemies hits only the first, and a second missile is not wasted on an enemy that is already dead;
  • both directions of one contact happen at once: a player that rams an enemy hurts it and is hurt by it, even if one of them dies.

Nothing is destroyed here: the game reads the report first (score, explosions, lives), then calls remove_casualties(). Contacts whose entities were destroyed are skipped. Defined in the header, like the collision functions, because it reads components.

Parameters
registryWorld holding the Damage and Health components.
contactsContacts of the tick, usually from find_contacts().
reportCleared, then filled with what happened.

◆ apply_sine_motion()

void aegis2d::ecs::apply_sine_motion ( Registry &  registry,
const Tick &  tick 
)
inline

Moves every entity with a sine motion along its wave for one tick.

For each entity with SineMotion and Transform, advances elapsed by tick.delta() and adds the change of sine_offset() to the position. Only the change is added, so the wave stacks with apply_velocity() and with anything else that moves the entity, and the offset reached depends only on the time spent, not on the tick rate: starting from elapsed = 0, the entity is sine_offset(elapsed) away from where it would be without the wave. Run it next to apply_velocity(), e.g. systems.add("sine_motion", ecs::apply_sine_motion);. Defined in the header because it reads components (see CollisionGrid::build()).

Parameters
registryWorld holding the entities.
tickStep of the simulation.

◆ apply_velocity()

void aegis2d::ecs::apply_velocity ( Registry &  registry,
const Tick &  tick 
)
inline

Moves every entity by its velocity for one tick.

Adds velocity * tick.delta() to the position of each entity with Transform and Velocity (players, missiles, enemies), so speeds are per second whatever the tick rate. Defined in the header because it reads components.

Parameters
registryWorld holding the entities.
tickStep of the simulation.

◆ clamp_into()

Vec2 aegis2d::ecs::clamp_into ( Vec2  position,
Vec2  half,
const Aabb &  area 
)
inlinenoexcept

Keeps a position inside an area, with a margin on each side.

An area narrower than twice the margin keeps the position at its center on that axis.

Parameters
positionCenter of the entity.
halfMargin: half the entity's size.
areaAllowed area.
Returns
The nearest position whose box fits in the area.

◆ credit_kills()

void aegis2d::ecs::credit_kills ( Registry &  registry,
const DamageReport &  report,
std::vector< Award > &  awards 
)
inline

Adds the value of each killed entity to the score of the player who killed it.

For each Kill of the report whose victim has a ScoreValue, the player found by shooter_of() gets the points; kills without a value (a player, a wall) or without a player to credit give nothing. Call it after apply_damage() and before remove_casualties(), while the victims still exist. Scores stop at the largest std::uint32_t instead of wrapping. Defined in the header because it reads components (see CollisionGrid::build()).

Parameters
registryWorld holding the scores.
reportReport of apply_damage() for this tick.
awardsCleared, then filled with one Award per credited kill, in the order of the kills, for the HUD or the network.

◆ despawn_outside()

void aegis2d::ecs::despawn_outside ( Registry &  registry,
const Aabb &  area,
std::vector< Entity > &  despawned 
)
inline

Destroys the entities that have left the play area for good.

Each entity with OffscreenDespawn and Transform is destroyed when left_for_good() holds for its box (see half_extent_of(): its Sprite, else its Collider, else its center), its Velocity (none counts as not moving) and area grown by its margin. Run it once per tick after the movement, e.g. last: systems.add("despawn", [area, &gone](ecs::Registry& r, const ecs::Tick&) { ecs::despawn_outside(r, area, gone); });. Defined in the header because it reads components (see CollisionGrid::build()).

Parameters
registryWorld holding the entities.
areaPlay area, usually {0, 0} to the logical resolution.
despawnedCleared, then filled with the destroyed entities, so the server can tell the clients.

◆ destroy_finished_animations()

void aegis2d::ecs::destroy_finished_animations ( Registry &  registry,
std::vector< Entity > &  destroyed 
)
inline

Destroys the effects whose animation has played to the end.

Each entity with DestroyAfterAnimation and an Animation that does not loop is destroyed once Animation::finished(), so a one-shot effect such as an explosion goes away after its last frame; a looping animation is never finished, and the entity stays. Run it after animate_sprites(), e.g. systems.add("effects", [&gone](ecs::Registry& r, const ecs::Tick&) { ecs::destroy_finished_animations(r, gone); });. Defined in the header because it reads components (see CollisionGrid::build()).

Parameters
registryWorld holding the effects.
destroyedCleared, then filled with the destroyed entities.

◆ direction_of()

Vec2 aegis2d::ecs::direction_of ( const PlayerInput &  input)
inlinenoexcept

Direction a player's input points to.

Up and down, left and right cancel each other. A diagonal is normalized, so a player moves at the same speed in all eight directions.

Parameters
inputHeld actions.
Returns
A vector of length 1, or zero when no direction is held.

◆ find_contacts() [1/2]

std::vector< Contact > aegis2d::ecs::find_contacts ( const Registry &  registry,
const CollisionGrid &  grid 
)
inline

Broad and narrow phases on a grid built for this tick.

Parameters
registryWorld holding the entities' components.
gridGrid filled with CollisionGrid::build() (or insert()).
Returns
The contacts, in the order of CollisionGrid::pairs().

◆ find_contacts() [2/2]

void aegis2d::ecs::find_contacts ( const Registry &  registry,
std::span< const CollisionPair >  candidates,
std::vector< Contact > &  out 
)
inline

Narrow phase: keeps the candidate pairs whose layers interact and boxes overlap.

For each pair, the layers are checked first (no contact if neither entity can hit the other, so enemies ignore enemies), then the boxes built from each entity's Transform and Collider. Pairs where an entity was destroyed or lost one of these components since the grid was built are skipped. Defined in the header for the same reason as CollisionGrid::build().

Parameters
registryWorld holding the entities' components.
candidatesPairs from the broad phase, usually CollisionGrid::pairs().
outCleared, then filled with the contacts, in the order of candidates.

◆ find_targets()

template<typename Component >
void aegis2d::ecs::find_targets ( const Registry &  registry,
const CollisionGrid &  grid,
Vec2  center,
float  radius,
TargetOrder  order,
std::vector< Entity > &  out 
)

Lists the entities with a component whose center is within a radius of a point, in the order asked.

The candidates come from CollisionGrid::query() over the square around the circle, so only the entities near the point are tested, not every entity of the world; the grid must have been built this tick (grid.build(registry)), and only entities with a Collider are in it. An entity is in range when the distance from center to its Transform is at most radius. Equal entities come in handle order, so the choice is the same on every run. A tower fires at the first one:

ecs::find_targets<Enemy>(registry, grid, tower.position, range,
if (!targets.empty()) { /* fire at targets.front() */ }
@ MostAdvanced
The furthest along its path first: the least PathFollower remaining(), then the closest; entities tha...

Defined in the header because it reads components (see CollisionGrid::build()).

Template Parameters
ComponentComponent the targets have, such as the game's Enemy.
Parameters
registryWorld the grid was built from.
gridGrid built this tick.
centerPoint to measure from, such as a tower's position.
radiusRange, in logical pixels; a negative or NaN radius finds nothing.
orderWhich targets come first.
outCleared, then filled with the targets in range, the best one first.

◆ fire_timers()

void aegis2d::ecs::fire_timers ( Registry &  registry,
const Tick &  tick,
std::vector< Entity > &  fired 
)
inline

Advances every Timer by one tick and lists the entities whose timer fired.

An entity is listed once per fire, in the order of the timers, so a timer that fires twice during a long tick is listed twice. The game then does what each timer is for (fires a tower, sends a wave). Run it once per tick, e.g. systems.add("timers", [&fired](ecs::Registry& r, const ecs::Tick& t) { ecs::fire_timers(r, t, fired); });. Defined in the header because it reads components (see CollisionGrid::build()).

Parameters
registryWorld holding the timers.
tickStep of the simulation.
firedCleared, then filled with the entities whose timer fired this tick.

◆ follow_paths()

void aegis2d::ecs::follow_paths ( Registry &  registry,
const Tick &  tick,
std::vector< Entity > &  arrived 
)
inline

Moves every PathFollower along its path for one tick and lists those that arrived.

An entity is listed once, on the tick it reaches its last waypoint; a path of one waypoint is reached on the first tick, an empty one is ignored. To send an entity on a new path (found again from where it is), set the waypoints from its position, then progress = 0 and arrived = false. Defined in the header because it reads components (see CollisionGrid::build()).

Parameters
registryWorld holding the followers and their Transform.
tickStep of the simulation.
arrivedCleared, then filled with the entities that arrived this tick.

◆ game_over()

bool aegis2d::ecs::game_over ( const Registry &  registry)
inline

Tells whether every player is out.

True as soon as no entity has Lives: check it only once the players have joined, after remove_casualties(). The server then tells every client the game is over (#115) and stops the simulation.

Parameters
registryWorld holding the players.
Returns
true when players_left() is 0.

◆ half_extent_of()

Vec2 aegis2d::ecs::half_extent_of ( const Registry &  registry,
Entity  entity 
)
inline

Half size of what must stay visible of an entity.

The Sprite if the entity has one (the whole sprite stays on screen), otherwise its Collider, otherwise nothing (the center alone is kept in the area).

Parameters
registryWorld holding the entity.
entityEntity to measure.
Returns
Half its width and height, in logical pixels.

◆ handle_player_deaths()

void aegis2d::ecs::handle_player_deaths ( Registry &  registry,
const DamageReport &  report,
std::vector< LifeLost > &  lost 
)
inline

Takes a life from each killed player and respawns those who have some left.

For each Kill of the report whose victim has Lives, one life is taken. While lives remain, the player is revived: Health back to Lives::health, Transform moved to Lives::spawn and Velocity set to zero (when it has them), so remove_casualties() keeps it. A player with no life left keeps its depleted health and is destroyed by remove_casualties(), like any casualty. Kills of entities without Lives are ignored.

Order of a tick: apply_damage(), credit_kills(), handle_player_deaths(), then remove_casualties(). Defined in the header because it reads components (see CollisionGrid::build()).

Parameters
registryWorld holding the players.
reportReport of apply_damage() for this tick.
lostCleared, then filled with one event per player who lost a life, in the order of the kills.

◆ hits()

constexpr bool aegis2d::ecs::hits ( const Collider &  attacker,
const Collider &  target 
)
constexprnoexcept

Tells whether a collider can hit another one, according to their layers.

attacker hits target when its mask contains one of the target's layers. The test is one-way: a player missile (mask: enemies) hits an enemy even if the enemy's mask does not contain player missiles.

Parameters
attackerCollider whose mask is read.
targetCollider whose layers are read.
Returns
true if attacker.mask & target.layer is not 0.

◆ left_for_good()

bool aegis2d::ecs::left_for_good ( Vec2  position,
Vec2  half,
Vec2  velocity,
const Aabb &  area 
)
inlinenoexcept

Tells whether a moving box has left an area and will not come back.

The box is gone when, on one axis, it lies entirely beyond an edge of the area (touching the edge from outside counts as beyond) and its velocity on that axis does not point back towards the area: moving away or not moving. A box outside but heading in, like an enemy entering from the right, is not gone.

Parameters
positionCenter of the box.
halfHalf its width and height.
velocityVelocity of the entity, in logical pixels per second.
areaArea the entity lives in.
Returns
true if the box will never overlap area again at this velocity.

◆ name()

std::string_view aegis2d::ecs::name ( )
noexcept

Name of the module, used to check that it is linked.

Returns
"ecs", a view of a static string.

◆ path_length()

float aegis2d::ecs::path_length ( std::span< const Vec2 >  waypoints)
inlinenoexcept

Length of a path.

Parameters
waypointsPoints of the path, in order.
Returns
The sum of the distances between consecutive points; 0 for fewer than two.

◆ players_left()

std::size_t aegis2d::ecs::players_left ( const Registry &  registry)
inline

Number of players still in the game.

Counts the entities with Lives, so call it after remove_casualties(), once out players are destroyed.

Parameters
registryWorld holding the players.
Returns
Living entities that have Lives.

◆ point_along()

Vec2 aegis2d::ecs::point_along ( std::span< const Vec2 >  waypoints,
float  distance 
)
inlinenoexcept

Point at a distance along a path.

Parameters
waypointsPoints of the path, in order.
distanceDistance from the first point; clamped to the path.
Returns
The point, the origin for an empty path.

◆ publish_deaths()

void aegis2d::ecs::publish_deaths ( core::EventBus &  events,
std::span< const LifeLost >  lost 
)
inline

Publishes each player's death of the tick.

Call it after handle_player_deaths(), with the events it listed; LifeLost::out() tells the player has no life left.

Parameters
eventsBus to publish on.
lostPlayers who lost a life this tick.

◆ publish_explosions()

void aegis2d::ecs::publish_explosions ( core::EventBus &  events,
const Registry &  registry,
const DamageReport &  report 
)
inline

Publishes an Explosion for each kill of the tick, in the order of the kills.

Every entity whose health reached zero explodes, players included. Call it right after apply_damage(): handle_player_deaths() moves a revived player back to its spawn point, and remove_casualties() destroys the dead, so the explosion would no longer be where the entity was hit.

Parameters
eventsBus to publish on.
registryWorld holding the casualties, not yet removed.
reportReport of apply_damage() for this tick.

◆ publish_path_ends()

void aegis2d::ecs::publish_path_ends ( core::EventBus &  events,
const Registry &  registry,
std::span< const Entity >  arrived 
)
inline

Publishes a PathEnded for each entity that arrived this tick.

Call it after follow_paths(), with the entities it listed, so the game (a life lost when an enemy reaches the exit) and the sounds react to it.

Parameters
eventsBus to publish on.
registryWorld holding the followers.
arrivedEntities listed by follow_paths().

◆ remaining()

float aegis2d::ecs::remaining ( const PathFollower &  follower)
inlinenoexcept

Distance a follower still has to walk.

Parameters
followerFollower to measure.
Returns
The length of its path minus its progress, 0 once arrived.

◆ remove_casualties()

std::size_t aegis2d::ecs::remove_casualties ( Registry &  registry,
const DamageReport &  report 
)
inline

Destroys the entities that died or were consumed during the tick.

A killed entity whose health is above zero again is kept: the game revived it (a player who still has lives). Entities already destroyed are ignored.

Parameters
registryWorld to update.
reportReport of apply_damage() for this tick.
Returns
Number of entities destroyed.

◆ shooter_of()

std::optional< Entity > aegis2d::ecs::shooter_of ( const Registry &  registry,
Entity  killer 
)
inline

Player credited for a kill made by an entity.

The killer's Owner if it has one (a missile and its shooter), otherwise the killer itself (a player that rammed an enemy). The result must be alive and have a Score.

Parameters
registryWorld holding the Owner and Score components.
killerAttacker of the killing hit (Kill::killer).
Returns
The player to credit, or std::nullopt.

◆ sine_offset()

Vec2 aegis2d::ecs::sine_offset ( const SineMotion &  motion,
float  time 
)
inlinenoexcept

Offset of a sine motion from its path at a time.

Parameters
motionAmplitude and period of the wave.
timeSeconds into the wave.
Returns
amplitude * sin(2π * time / period), or zero when the period is zero or less.

◆ to_string()

std::string aegis2d::ecs::to_string ( Entity  entity)
inline

Text form of a handle, for logs: Entity(3, 1) (index, generation) or Entity(null).

A free function rather than a std::formatter: libc++ 18 rejects user formatters at compile time; log with log_info("spawned {}", to_string(entity)).

Parameters
entityHandle to write.
Returns
The text.

Variable Documentation

◆ plugin_start

constexpr std::string_view aegis2d::ecs::plugin_start = "aegis2d_plugin_start"
inlineconstexpr

Name of the C function a plugin exports, called once when it is loaded.