Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches

Unique identifier for entities with generation counter to handle recycling. More...

#include <entity.hpp>

Public Types

using IndexType = uint32_t
using GenerationType = uint32_t

Public Member Functions

constexpr Entity () noexcept=default
 Constructs an invalid entity.
constexpr Entity (IndexType index, GenerationType generation) noexcept
 Constructs entity with specific index and generation.
constexpr Entity (const Entity &) noexcept=default
constexpr Entity (Entity &&) noexcept=default
constexpr ~Entity () noexcept=default
constexpr Entityoperator= (const Entity &) noexcept=default
constexpr Entityoperator= (Entity &&) noexcept=default
constexpr bool operator== (const Entity &) const noexcept=default
constexpr bool operator!= (const Entity &) const noexcept=default
constexpr bool operator< (const Entity &other) const noexcept
constexpr bool Valid () const noexcept
 Checks if the entity is valid.
constexpr size_t Hash () const noexcept
 Generates a hash value for this entity.
constexpr IndexType Index () const noexcept
 Gets the index component of the entity.
constexpr GenerationType Generation () const noexcept
 Gets the generation component of the entity.

Static Public Attributes

static constexpr IndexType kInvalidIndex
static constexpr GenerationType kInvalidGeneration

Detailed Description

Unique identifier for entities with generation counter to handle recycling.

Entity uses a combination of index and generation to provide stable references even when entities are destroyed and their indices are recycled. The generation counter ensures that old entity references become invalid when the index is reused.

Memory layout: 32-bit index + 32-bit generation = 64-bit total

Note
This class is thread-safe for all operations.

Definition at line 22 of file entity.hpp.

Member Typedef Documentation

◆ GenerationType

Definition at line 25 of file entity.hpp.

◆ IndexType

Definition at line 24 of file entity.hpp.

Constructor & Destructor Documentation

◆ Entity() [1/4]

helios::ecs::Entity::Entity ( )
constexprdefaultnoexcept

Constructs an invalid entity.

Creates an entity with invalid index and generation values.

◆ Entity() [2/4]

helios::ecs::Entity::Entity ( IndexType index,
GenerationType generation )
inlineconstexprnoexcept

Constructs entity with specific index and generation.

Private constructor used by entity manager to create valid entities.

Parameters
indexThe entity index
generationThe entity generation

Definition at line 45 of file entity.hpp.

◆ Entity() [3/4]

helios::ecs::Entity::Entity ( const Entity & )
constexprdefaultnoexcept

◆ Entity() [4/4]

helios::ecs::Entity::Entity ( Entity && )
constexprdefaultnoexcept

◆ ~Entity()

helios::ecs::Entity::~Entity ( )
constexprdefaultnoexcept

Member Function Documentation

◆ Generation()

GenerationType helios::ecs::Entity::Generation ( ) const
inlinenodiscardconstexprnoexcept

Gets the generation component of the entity.

The generation counter prevents use of stale entity references after recycling.

Returns
Entity generation, or kInvalidGeneration if entity is invalid

Definition at line 90 of file entity.hpp.

◆ Hash()

size_t helios::ecs::Entity::Hash ( ) const
nodiscardconstexprnoexcept

Generates a hash value for this entity.

Combines index and generation into a 64-bit hash value. Invalid entities always return hash value of 0.

Returns
Hash combining generation (high bits) and index (low bits)

Definition at line 107 of file entity.hpp.

◆ Index()

IndexType helios::ecs::Entity::Index ( ) const
inlinenodiscardconstexprnoexcept

Gets the index component of the entity.

The index identifies the entity's storage location in sparse arrays.

Returns
Entity index, or kInvalidIndex if entity is invalid

Definition at line 82 of file entity.hpp.

◆ operator!=()

bool helios::ecs::Entity::operator!= ( const Entity & ) const
constexprdefaultnoexcept

◆ operator<()

bool helios::ecs::Entity::operator< ( const Entity & other) const
constexprnoexcept

Definition at line 100 of file entity.hpp.

◆ operator=() [1/2]

Entity & helios::ecs::Entity::operator= ( const Entity & )
constexprdefaultnoexcept

◆ operator=() [2/2]

Entity & helios::ecs::Entity::operator= ( Entity && )
constexprdefaultnoexcept

◆ operator==()

bool helios::ecs::Entity::operator== ( const Entity & ) const
constexprdefaultnoexcept

◆ Valid()

bool helios::ecs::Entity::Valid ( ) const
inlinenodiscardconstexprnoexcept

Checks if the entity is valid.

An entity is valid if both its index and generation are not the reserved invalid values.

Returns
True if entity has valid index and generation, false otherwise

Definition at line 64 of file entity.hpp.

Member Data Documentation

◆ kInvalidGeneration

GenerationType helios::ecs::Entity::kInvalidGeneration
staticconstexpr
Initial value:
=
std::numeric_limits<GenerationType>::max()

Definition at line 29 of file entity.hpp.

◆ kInvalidIndex

IndexType helios::ecs::Entity::kInvalidIndex
staticconstexpr
Initial value:
=
std::numeric_limits<IndexType>::max()

Definition at line 27 of file entity.hpp.