EntityRegistry Class Template
Generic registry for creating and managing strongly-typed entity handles. More...
Declaration
Public Constructors Index
template < ... > | |
| EntityRegistry (const size_t capacity=TCapacity) | |
|
Constructs a registry with pre-allocated capacity. More... | |
Public Member Functions Index
template < ... > | |
| auto | create (StrongId< TDomainTag > strongId=StrongId< TDomainTag >{}) -> EntityHandle< TDomainTag > |
|
Creates a new entity and returns its handle. More... | |
template < ... > | |
| VersionId | version (const EntityId entityId) const |
|
Looks up the version for an EntityId. More... | |
template < ... > | |
| auto | strongId (const EntityId entityId) const -> StrongId< TDomainTag > |
|
Looks up the strong ID for an entity index. More... | |
template < ... > | |
| bool | isValid (const EntityHandle< TDomainTag > handle) const noexcept |
|
Checks whether the given handle refers to a currently alive entity. More... | |
template < ... > | |
| bool | destroy (const EntityHandle< TDomainTag > handle) |
|
Destroys the entity referenced by the given handle. More... | |
Private Member Attributes Index
template < ... > | |
| std::vector< EntityId > | freeList_ |
|
Free list of recycled entity indices available for reuse. More... | |
template < ... > | |
| std::vector< VersionId > | versions_ |
|
Version numbers for each entity slot. More... | |
template < ... > | |
| std::vector< StrongId_t > | strongIds_ |
|
Strong ID values for each entity slot. More... | |
template < ... > | |
| TLookupStrategy | lookupStrategy_ |
|
Lookup strategy instance for strong ID collision detection. More... | |
template < ... > | |
| size_t | strongIdCounter_ = 0 |
|
Auto-increment counter for generating strong IDs when none is provided. More... | |
Description
Generic registry for creating and managing strongly-typed entity handles.
EntityRegistry serves as the authoritative source for entity lifecycle management. It is responsible for:
- Handle Creation: Generates unique EntityHandle<TDomainTag> instances with versioned IDs and domain-specific strong IDs.
- Validation: Determines whether a given handle refers to a currently alive entity.
- Destruction: Marks entities as destroyed by incrementing their version and recycling the index for future use (when TAllowRemoval is true).
Definition at line 76 of file EntityRegistry.ixx.
Public Constructors
EntityRegistry()
| inline explicit |
Constructs a registry with pre-allocated capacity.
Reserving capacity upfront can improve performance when the approximate number of entities is known in advance.
- Parameters
-
capacity The initial capacity to reserve.
Definition at line 119 of file EntityRegistry.ixx.
Public Member Functions
create()
| inline |
Creates a new entity and returns its handle.
If recycled indices are available in the free list, one is reused. Otherwise, a new index is allocated at the end of the version vector. If the provided strongId is invalid, one is auto-assigned from the entity index.
- Parameters
-
strongId Optional domain-specific strong ID. Defaults to auto-assignment.
- Returns
A valid EntityHandle for the newly created entity.
Definition at line 139 of file EntityRegistry.ixx.
destroy()
| inline |
Destroys the entity referenced by the given handle.
If the handle is valid, the entity's version is incremented (invalidating all existing handles to it), the strong ID is unregistered, and the index is added to the free list for recycling.
If TAllowRemoval is false, triggers an assertion failure.
- Parameters
-
handle The handle of the entity to destroy.
- Returns
True if the entity was successfully destroyed, false if the handle was already invalid.
Definition at line 242 of file EntityRegistry.ixx.
References helios::ecs::types::EntityHandle< TDomainTag >::entityId, helios::ecs::EntityRegistry< TDomainTag, TLookupStrategy, TAllowRemoval, TCapacity >::isValid, helios::ecs::types::EntityHandle< TDomainTag >::strongId and helios::ecs::types::StrongId< Tag >::value.
isValid()
| inline noexcept |
Checks whether the given handle refers to a currently alive entity.
A handle is valid if its index is within bounds, its version matches the current version stored in the registry, and its strong ID matches the registered value.
- Parameters
-
handle The handle to validate.
- Returns
True if the handle is valid and the entity is alive.
Definition at line 215 of file EntityRegistry.ixx.
Referenced by helios::ecs::EntityRegistry< TDomainTag, TLookupStrategy, TAllowRemoval, TCapacity >::destroy.
strongId()
| inline |
Looks up the strong ID for an entity index.
- Parameters
-
entityId The entity index to retrieve the strong ID for.
- Returns
The strong ID for the entity, or a default-constructed (invalid) StrongId<TDomainTag> if out of bounds.
Definition at line 196 of file EntityRegistry.ixx.
version()
| inline |
Looks up the version for an EntityId.
- Parameters
-
entityId The entity to retrieve the version for.
- Returns
The version for the EntityId, or InvalidVersion if not found.
Definition at line 181 of file EntityRegistry.ixx.
Reference helios::ecs::types::InvalidVersion.
Private Member Attributes
freeList_
|
Free list of recycled entity indices available for reuse.
Definition at line 82 of file EntityRegistry.ixx.
lookupStrategy_
|
Lookup strategy instance for strong ID collision detection.
Definition at line 102 of file EntityRegistry.ixx.
strongIdCounter_
|
Auto-increment counter for generating strong IDs when none is provided.
Definition at line 107 of file EntityRegistry.ixx.
strongIds_
|
Strong ID values for each entity slot.
Definition at line 97 of file EntityRegistry.ixx.
versions_
|
Version numbers for each entity slot.
The version is incremented when an entity at that index is destroyed, allowing detection of stale handles.
Definition at line 91 of file EntityRegistry.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.