Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
EntityManager Class Reference

Manages entity allocation, deallocation, component masks, and lifetime tracking. More...

#include <EntityManager.hpp>

Public Member Functions

 EntityManager ()
 Construct a new Entity Manager object and initializes the free identifier pool.
Entity create ()
 Creates a new Entity, populating it from the free ID pool.
void destroy (Entity e)
 Destroys an entity and recycles its identifier.
ComponentMask & getMask (Entity e)
 Retrieves the component mask of an entity.
const std::vector< Entity::IdType > & getAlive () const
 Retrieves list of currently active entity identifiers.

Static Public Attributes

static constexpr std::size_t MAX_ENTITIES = 10000
 Maximum allowed active entities.

Private Attributes

std::vector< Entity::IdType > alive
 Tracking vector of active entity IDs.
std::stack< Entity::IdType > freeIds
 Stack of available identifiers.
std::array< ComponentMask, MAX_ENTITIES > masks
 Array of component masks indexable by entity ID.

Detailed Description

Manages entity allocation, deallocation, component masks, and lifetime tracking.

Constructor & Destructor Documentation

◆ EntityManager()

EntityManager::EntityManager ( )
inline

Construct a new Entity Manager object and initializes the free identifier pool.

Member Function Documentation

◆ create()

Entity EntityManager::create ( )
inline

Creates a new Entity, populating it from the free ID pool.

Returns
The spawned Entity, or an invalid Entity if limit is reached.

◆ destroy()

void EntityManager::destroy ( Entity e)
inline

Destroys an entity and recycles its identifier.

Parameters
eEntity to destroy.

◆ getAlive()

const std::vector< Entity::IdType > & EntityManager::getAlive ( ) const
inline

Retrieves list of currently active entity identifiers.

Returns
List of active entity IDs.

◆ getMask()

ComponentMask & EntityManager::getMask ( Entity e)
inline

Retrieves the component mask of an entity.

Parameters
eEntity to check.
Returns
Reference to component mask.

Member Data Documentation

◆ alive

std::vector<Entity::IdType> EntityManager::alive
private

Tracking vector of active entity IDs.

◆ freeIds

std::stack<Entity::IdType> EntityManager::freeIds
private

Stack of available identifiers.

◆ masks

std::array<ComponentMask, MAX_ENTITIES> EntityManager::masks
private

Array of component masks indexable by entity ID.

◆ MAX_ENTITIES

std::size_t EntityManager::MAX_ENTITIES = 10000
staticconstexpr

Maximum allowed active entities.


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