FECS
Loading...
Searching...
No Matches
FECS::Manager::EntityManager Class Reference

Manages entity lifecycle, including creation, destruction, and version tracking. More...

#include <entity_manager.h>

Public Member Functions

 EntityManager ()
 Constructs an empty EntityManager.
 
void Reserve (std::uint32_t amount)
 Pre-allocates memory for a number of entities.
 
Entity Create ()
 Creates a new Entity.
 
void Destroy (Entity e)
 Destroys and entity and recycles its index.
 
bool IsAlive (Entity e) const
 Checks whether an entity is still valid (alive).
 

Detailed Description

Manages entity lifecycle, including creation, destruction, and version tracking.

This class handles entity ID allocation using a freelist-based approach. It also maintains versioning for safe validation of entity references.

Member Function Documentation

◆ Create()

Entity FECS::Manager::EntityManager::Create ( )
inline

Creates a new Entity.

If there are free slots available from destroyed entities, they are reused. Otherwise, a new index is assigned.

Returns
A new valid Entity ID with embedded version.

< First version is always 0

◆ Destroy()

void FECS::Manager::EntityManager::Destroy ( Entity e)
inline

Destroys and entity and recycles its index.

The version at the entity's index is incremented to invalidate old references.

Parameters
eThe entity to destroy.

◆ IsAlive()

bool FECS::Manager::EntityManager::IsAlive ( Entity e) const
inline

Checks whether an entity is still valid (alive).

An entity is considered alive if its version matches the stored version.

Parameters
eThe entity to check.
Returns
Returns true if the entity is alive, false otherwise

◆ Reserve()

void FECS::Manager::EntityManager::Reserve ( std::uint32_t amount)
inline

Pre-allocates memory for a number of entities.

Parameters
amountNumber of entities to reserve space for.

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