30 using Id = std::uint32_t;
38 constexpr Entity() noexcept = default;
61 [[nodiscard]]
constexpr Index index() const noexcept {
return id_ & index_mask; }
71 [[nodiscard]]
constexpr Id id() const noexcept {
return id_; }
75 [[nodiscard]]
constexpr bool is_null() const noexcept {
return index() == null_index; }
84 static constexpr Index null_index = index_mask;
97 return "Entity(null)";
99 return std::format(
"Entity({}, {})", entity.
index(), entity.
generation());
107struct std::hash<
aegis2d::ecs::Entity> {
109 return std::hash<aegis2d::ecs::Entity::Id>{}(entity.id());
Handle to an entity: 32 bits made of a 24-bit index and an 8-bit generation.
Definition entity.hpp:23
constexpr Generation generation() const noexcept
Generation of the index when this handle was created.
Definition entity.hpp:65
constexpr Index index() const noexcept
Position of the entity in the component pools.
Definition entity.hpp:61
constexpr bool is_null() const noexcept
Tells whether the handle designates no entity.
Definition entity.hpp:75
constexpr Entity() noexcept=default
Creates a null handle.
static constexpr Entity from_id(Id id) noexcept
Rebuilds a handle from its packed value, e.g. received from the network.
Definition entity.hpp:49
static constexpr Index max_index
Highest valid index: 16 777 214 (the last value is reserved for null).
Definition entity.hpp:35
std::uint32_t Id
Packed value: generation in the 8 high bits, index in the 24 low bits.
Definition entity.hpp:30
std::uint32_t Index
Position of the entity in the component pools.
Definition entity.hpp:26
friend constexpr std::strong_ordering operator<=>(Entity, Entity) noexcept=default
Orders handles by packed value (generation, then index).
friend constexpr bool operator==(Entity, Entity) noexcept=default
Handles are equal when both index and generation are.
std::uint8_t Generation
Reuse counter of an index.
Definition entity.hpp:28
static constexpr unsigned index_bits
Number of bits of the index.
Definition entity.hpp:33
static constexpr Entity null() noexcept
The null handle, equal to a default-constructed one.
Definition entity.hpp:57
constexpr Id id() const noexcept
Packed value, unique per index and generation.
Definition entity.hpp:71
Entity-Component-System used by client and server.
Definition animation.hpp:13
std::string to_string(Entity entity)
Text form of a handle, for logs: Entity(3, 1) (index, generation) or Entity(null).
Definition entity.hpp:95
Root namespace of the engine.
Definition audio.hpp:17