![]() |
Flecs v4.0
A fast entity component system (ECS) for C & C++
|
Functions for testing and modifying entity liveliness. More...
Functions | |
bool | ecs_is_valid (const ecs_world_t *world, ecs_entity_t e) |
Test whether an entity is valid. | |
bool | ecs_is_alive (const ecs_world_t *world, ecs_entity_t e) |
Test whether an entity is alive. | |
ecs_id_t | ecs_strip_generation (ecs_entity_t e) |
Remove generation from entity id. | |
ecs_entity_t | ecs_get_alive (const ecs_world_t *world, ecs_entity_t e) |
Get alive identifier. | |
void | ecs_make_alive (ecs_world_t *world, ecs_entity_t entity) |
Ensure id is alive. | |
void | ecs_make_alive_id (ecs_world_t *world, ecs_id_t component) |
Same as ecs_make_alive(), but for components. | |
bool | ecs_exists (const ecs_world_t *world, ecs_entity_t entity) |
Test whether an entity exists. | |
void | ecs_set_version (ecs_world_t *world, ecs_entity_t entity) |
Override the generation of an entity. | |
Functions for testing and modifying entity liveliness.
bool ecs_exists | ( | const ecs_world_t * | world, |
ecs_entity_t | entity ) |
Test whether an entity exists.
Similar as ecs_is_alive(), but ignores entity generation count.
world | The world. |
entity | The entity. |
ecs_entity_t ecs_get_alive | ( | const ecs_world_t * | world, |
ecs_entity_t | e ) |
Get alive identifier.
In some cases an application may need to work with identifiers from which the generation has been stripped. A typical scenario in which this happens is when iterating relationships in an entity type.
For example, when obtaining the parent id from a ChildOf
relationship, the parent (second element of the pair) will have been stored in a 32 bit value, which cannot store the entity generation. This function can retrieve the identifier with the current generation for that id.
If the provided identifier is not alive, the function will return 0.
world | The world. |
e | The for which to obtain the current alive entity id. |
bool ecs_is_alive | ( | const ecs_world_t * | world, |
ecs_entity_t | e ) |
Test whether an entity is alive.
Entities are alive after they are created, and become not alive when they are deleted. Operations that return alive ids are (amongst others) ecs_new(), ecs_new_low_id() and ecs_entity_init(). Ids can be made alive with the ecs_make_alive() * function.
After an id is deleted it can be recycled. Recycled ids are different from the original id in that they have a different generation count. This makes it possible for the API to distinguish between the two. An example:
Other than ecs_is_valid(), this operation will panic if the passed in entity id is 0 or has an invalid bit pattern.
world | The world. |
e | The entity. |
bool ecs_is_valid | ( | const ecs_world_t * | world, |
ecs_entity_t | e ) |
Test whether an entity is valid.
This operation tests whether the entity id:
If this operation returns true, it is safe to use the entity with other other operations.
This operation should only be used if an application cannot be sure that an entity is initialized with a valid value. In all other cases where an entity was initialized with a valid value, but the application wants to check if the entity is (still) alive, use ecs_is_alive.
world | The world. |
e | The entity. |
void ecs_make_alive | ( | ecs_world_t * | world, |
ecs_entity_t | entity ) |
Ensure id is alive.
This operation ensures that the provided id is alive. This is useful in scenarios where an application has an existing id that has not been created with ecs_new_w() (such as a global constant or an id from a remote application).
When this operation is successful it guarantees that the provided id exists, is valid and is alive.
Before this operation the id must either not be alive or have a generation that is equal to the passed in entity.
If the provided id has a non-zero generation count and the id does not exist in the world, the id will be created with the specified generation.
If the provided id is alive and has a generation count that does not match the provided id, the operation will fail.
world | The world. |
entity | The entity id to make alive. |
void ecs_make_alive_id | ( | ecs_world_t * | world, |
ecs_id_t | component ) |
Same as ecs_make_alive(), but for components.
An id can be an entity or pair, and can contain id flags. This operation ensures that the entity (or entities, for a pair) are alive.
When this operation is successful it guarantees that the provided id can be used in operations that accept an id.
Since entities in a pair do not encode their generation ids, this operation will not fail when an entity with non-zero generation count already exists in the world.
This is different from ecs_make_alive(), which will fail if attempted with an id that has generation 0 and an entity with a non-zero generation is currently alive.
world | The world. |
component | The component to make alive. |
void ecs_set_version | ( | ecs_world_t * | world, |
ecs_entity_t | entity ) |
Override the generation of an entity.
The generation count of an entity is increased each time an entity is deleted and is used to test whether an entity id is alive.
This operation overrides the current generation of an entity with the specified generation, which can be useful if an entity is externally managed, like for external pools, savefiles or netcode.
This operation is similar to ecs_make_alive(), except that it will also override the generation of an alive entity.
world | The world. |
entity | Entity for which to set the generation with the new generation. |
ecs_id_t ecs_strip_generation | ( | ecs_entity_t | e | ) |
Remove generation from entity id.
e | The entity id. |