cubos::core::ecs::Entity struct

Identifies an entity.

When serializing/deserializing, if there's a data::old::SerializationMap<Entity, std::string, EntityHash> in the context, it will be used to (de)serialize strings representing the entities. Otherwise, the identifiers will be (de)serialized as objects with two fields: their index and their generation.

Public types

using Mask = std::bitset<CUBOS_CORE_ECS_MAX_COMPONENTS+1>
Type used to store which components an entity has.

Constructors, destructors, conversion operators

Entity()
Constructs a null entity.
Entity(uint32_t index, uint32_t generation)
Constructs an entity from an index and a generation.
Entity(const Entity& entity) defaulted
Copy constructs.

Public functions

auto operator=(const Entity& entity) -> Entity& defaulted
Copy assigns.
auto operator==(const Entity& entity) const -> bool defaulted
Checks if the entity is equal to another.
auto operator!=(const Entity& entity) const -> bool defaulted
Checks if the entity is not equal to another.
auto isNull() const -> bool
Checks if the entity is null, a special value returned on errors.

Public variables

uint32_t index
Identifies the entity among the living entities in a world.
uint32_t generation
Counts how many entities with the same index have previously been destroyed.

Function documentation

cubos::core::ecs::Entity::Entity(uint32_t index, uint32_t generation)

Constructs an entity from an index and a generation.

Parameters
index Entity index.
generation Entity generation.

cubos::core::ecs::Entity::Entity(const Entity& entity) defaulted

Copy constructs.

Parameters
entity Entity to copy.

Entity& cubos::core::ecs::Entity::operator=(const Entity& entity) defaulted

Copy assigns.

Parameters
entity Entity to copy.

bool cubos::core::ecs::Entity::operator==(const Entity& entity) const defaulted

Checks if the entity is equal to another.

Parameters
entity Entity to compare to.
Returns Whether the entities are equal.

bool cubos::core::ecs::Entity::operator!=(const Entity& entity) const defaulted

Checks if the entity is not equal to another.

Parameters
entity Entity to compare to.
Returns Whether the entities are not equal.

bool cubos::core::ecs::Entity::isNull() const

Checks if the entity is null, a special value returned on errors.

Returns Whether the entity is null.

Variable documentation

uint32_t cubos::core::ecs::Entity::index

Identifies the entity among the living entities in a world.

While this is unique at a given time, it may be reused after the entity is destroyed.

uint32_t cubos::core::ecs::Entity::generation

Counts how many entities with the same index have previously been destroyed.

Allows us to detect when an entity has been destroyed by comparing its generation with the current generation of the entity with the same index.