ImagoEngine
A C++ 2D game engine built on a sparse-set ECS, with scenes, scheduled systems, events, and action-based input
Loading...
Searching...
No Matches
Entity.hpp File Reference

Defines the Entity alias and the free functions used to pack and unpack it. More...

#include <cstdint>
#include <cassert>
Include dependency graph for Entity.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

using Imago::ECS::Entity = uint32_t
 A packed identifier: 20 bits of index, 12 bits of generation.

Functions

constexpr uint32_t Imago::ECS::get_entity_index (Entity entity)
 Extracts the index bits from a packed Entity.
constexpr uint32_t Imago::ECS::get_entity_generation (Entity entity)
 Extracts the generation bits from a packed Entity.
constexpr Entity Imago::ECS::make_entity (uint32_t index, uint32_t generation)
 Packs an index and generation into a single Entity.

Variables

constexpr uint32_t Imago::ECS::ENTITY_INDEX_BITS = 20
 Number of bits allocated to an Entity's index.
constexpr uint32_t Imago::ECS::ENTITY_GENERATION_BITS = 12
 Number of bits allocated to an Entity's generation.
constexpr uint32_t Imago::ECS::ENTITY_INDEX_MASK = (1u << ENTITY_INDEX_BITS) - 1
 Mask isolating the low 20 index bits of a packed Entity.
constexpr uint32_t Imago::ECS::ENTITY_GENERATION_MASK = (1u << ENTITY_GENERATION_BITS) -1
 Mask isolating the low 12 bits of a right shifted generation value.
constexpr Entity Imago::ECS::NULL_ENTITY = 0xFFFFFFFFu
 Sentinel value representing "no entity".

Detailed Description

Defines the Entity alias and the free functions used to pack and unpack it.

Author
Shane David

An Entity is a lightweight identifier, a single packed uint32_t containing both an index (which slot this entity occupies), and a generation (how many times that slot has been destroyed and recreated). Entities carry no data and no behavior; they are pure IDs used to look up components in component pools.

Function Documentation

◆ get_entity_generation()

uint32_t Imago::ECS::get_entity_generation ( Entity entity)
constexpr

Extracts the generation bits from a packed Entity.

Parameters
entityThe packed Entity to decode.
Returns
The entity's generation.

◆ get_entity_index()

uint32_t Imago::ECS::get_entity_index ( Entity entity)
constexpr

Extracts the index bits from a packed Entity.

Parameters
entityThe packed Entity to decode.
Returns
The entity's index.

◆ make_entity()

Entity Imago::ECS::make_entity ( uint32_t index,
uint32_t generation )
constexpr

Packs an index and generation into a single Entity.

Parameters
indexIndex value.
generationGeneration value.
Precondition
index <= ENTITY_INDEX_MASK
generation <= ENTITY_GENERATION_MASK
Returns
The packed Entity.
Note
Debug builds assert on out-of-range input; release builds silently mask it.

Variable Documentation

◆ NULL_ENTITY

Entity Imago::ECS::NULL_ENTITY = 0xFFFFFFFFu
constexpr

Sentinel value representing "no entity".

Decodes to index == ENTITY_INDEX_MASK and generation == ENTITY_GENERATION_MASK, a bit pattern EntityManager never hands out as a real, live Entity.