|
Aegis2D
Modular C++26 2D game engine for networked games
|
Handle to an entity: 32 bits made of a 24-bit index and an 8-bit generation. More...
#include <aegis2d/ecs/entity.hpp>
Public Types | |
| using | Index = std::uint32_t |
| Position of the entity in the component pools. | |
| using | Generation = std::uint8_t |
| Reuse counter of an index. | |
| using | Id = std::uint32_t |
| Packed value: generation in the 8 high bits, index in the 24 low bits. | |
Public Member Functions | |
| constexpr | Entity () noexcept=default |
| Creates a null handle. | |
| constexpr | Entity (Index index, Generation generation) noexcept |
| Creates the handle of an index at a given generation. | |
| constexpr Index | index () const noexcept |
| Position of the entity in the component pools. | |
| constexpr Generation | generation () const noexcept |
| Generation of the index when this handle was created. | |
| constexpr Id | id () const noexcept |
| Packed value, unique per index and generation. | |
| constexpr bool | is_null () const noexcept |
| Tells whether the handle designates no entity. | |
Static Public Member Functions | |
| static constexpr Entity | from_id (Id id) noexcept |
| Rebuilds a handle from its packed value, e.g. received from the network. | |
| static constexpr Entity | null () noexcept |
| The null handle, equal to a default-constructed one. | |
Static Public Attributes | |
| static constexpr unsigned | index_bits = 24 |
| Number of bits of the index. | |
| static constexpr Index | max_index = (Index{1} << index_bits) - 2 |
| Highest valid index: 16 777 214 (the last value is reserved for null). | |
Friends | |
| constexpr bool | operator== (Entity, Entity) noexcept=default |
| Handles are equal when both index and generation are. | |
| constexpr std::strong_ordering | operator<=> (Entity, Entity) noexcept=default |
| Orders handles by packed value (generation, then index). | |
Handle to an entity: 32 bits made of a 24-bit index and an 8-bit generation.
The index locates the entity's components in the pools; it is recycled when the entity is destroyed. The generation changes at each reuse, so a handle kept by a system after its entity was destroyed no longer matches the new occupant of the index and is detected as stale instead of silently pointing to another entity.
The generation wraps after 256 reuses of the same index. A default-constructed handle is null: it designates no entity. Handles are plain values: compare, hash, copy and send them freely (id() gives the packed 32-bit value).
| using aegis2d::ecs::Entity::Generation = std::uint8_t |
Reuse counter of an index.
| using aegis2d::ecs::Entity::Id = std::uint32_t |
Packed value: generation in the 8 high bits, index in the 24 low bits.
| using aegis2d::ecs::Entity::Index = std::uint32_t |
Position of the entity in the component pools.
|
constexprdefaultnoexcept |
Creates a null handle.
|
inlineconstexprnoexcept |
Creates the handle of an index at a given generation.
| index | Position in the pools, at most max_index. |
| generation | Current generation of that index. |
Rebuilds a handle from its packed value, e.g. received from the network.
| id | Value returned by id(). |
|
inlineconstexprnoexcept |
Generation of the index when this handle was created.
|
inlineconstexprnoexcept |
Packed value, unique per index and generation.
|
inlineconstexprnoexcept |
Position of the entity in the component pools.
[0, max_index] for a non-null handle.
|
inlineconstexprnoexcept |
Tells whether the handle designates no entity.
true for a default-constructed or null() handle.
|
inlinestaticconstexprnoexcept |
The null handle, equal to a default-constructed one.
Orders handles by packed value (generation, then index).
Handles are equal when both index and generation are.
|
staticconstexpr |
Number of bits of the index.
|
staticconstexpr |
Highest valid index: 16 777 214 (the last value is reserved for null).