Flecs v3.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Entity Information.

Get information from entity. More...

Functions

const ecs_type_tecs_get_type (const ecs_world_t *world, ecs_entity_t entity)
 Get the type of an entity. More...
 
ecs_table_tecs_get_table (const ecs_world_t *world, ecs_entity_t entity)
 Get the table of an entity. More...
 
char * ecs_type_str (const ecs_world_t *world, const ecs_type_t *type)
 Convert type to string. More...
 
char * ecs_table_str (const ecs_world_t *world, const ecs_table_t *table)
 Convert table to string. More...
 
char * ecs_entity_str (const ecs_world_t *world, ecs_entity_t entity)
 Convert entity to string. More...
 
bool ecs_has_id (const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
 Test if an entity has an entity. More...
 
ecs_entity_t ecs_get_target (const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel, int32_t index)
 Get the target of a relationship. More...
 
ecs_entity_t ecs_get_target_for_id (const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel, ecs_id_t id)
 Get the target of a relationship for a given id. More...
 
int32_t ecs_get_depth (const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel)
 Return depth for entity in tree for relationship rel. More...
 
int32_t ecs_count_id (const ecs_world_t *world, ecs_id_t entity)
 Count entities that have the specified id. More...
 

Detailed Description

Get information from entity.

Function Documentation

◆ ecs_count_id()

int32_t ecs_count_id ( const ecs_world_t world,
ecs_id_t  entity 
)

Count entities that have the specified id.

Returns the number of entities that have the specified id.

Parameters
worldThe world.
entityThe id to search for.
Returns
The number of entities that have the id.

◆ ecs_entity_str()

char * ecs_entity_str ( const ecs_world_t world,
ecs_entity_t  entity 
)

Convert entity to string.

Same as combining:

  • ecs_get_fullpath(world, entity)
  • ecs_type_str(world, ecs_get_type(world, entity))

The result of this operation must be freed with ecs_os_free.

Parameters
worldThe world.
entityThe entity.
Returns
The entity path with stringified type.

◆ ecs_get_depth()

int32_t ecs_get_depth ( const ecs_world_t world,
ecs_entity_t  entity,
ecs_entity_t  rel 
)

Return depth for entity in tree for relationship rel.

Depth is determined by counting the number of targets encountered while traversing up the relationship tree for rel. Only acyclic relationships are supported.

Parameters
worldThe world.
entityThe entity.
relThe relationship.
Returns
The depth of the entity in the tree.

◆ ecs_get_table()

ecs_table_t * ecs_get_table ( const ecs_world_t world,
ecs_entity_t  entity 
)

Get the table of an entity.

Parameters
worldThe world.
entityThe entity.
Returns
The table of the entity, NULL if the entity has no components/tags.

◆ ecs_get_target()

ecs_entity_t ecs_get_target ( const ecs_world_t world,
ecs_entity_t  entity,
ecs_entity_t  rel,
int32_t  index 
)

Get the target of a relationship.

This will return a target (second element of a pair) of the entity for the specified relationship. The index allows for iterating through the targets, if a single entity has multiple targets for the same relationship.

If the index is larger than the total number of instances the entity has for the relationship, the operation will return 0.

Parameters
worldThe world.
entityThe entity.
relThe relationship between the entity and the target.
indexThe index of the relationship instance.
Returns
The target for the relationship at the specified index.

◆ ecs_get_target_for_id()

ecs_entity_t ecs_get_target_for_id ( const ecs_world_t world,
ecs_entity_t  entity,
ecs_entity_t  rel,
ecs_id_t  id 
)

Get the target of a relationship for a given id.

This operation returns the first entity that has the provided id by following the specified relationship. If the entity itself has the id then entity will be returned. If the id cannot be found on the entity or by following the relationship, the operation will return 0.

This operation can be used to lookup, for example, which prefab is providing a component by specifying the IsA relationship:

// Is Position provided by the entity or one of its base entities? ecs_get_target_for_id(world, entity, EcsIsA, ecs_id(Position))

Parameters
worldThe world.
entityThe entity.
relThe relationship to follow.
idThe id to lookup.
Returns
The entity for which the target has been found.

◆ ecs_get_type()

const ecs_type_t * ecs_get_type ( const ecs_world_t world,
ecs_entity_t  entity 
)

Get the type of an entity.

Parameters
worldThe world.
entityThe entity.
Returns
The type of the entity, NULL if the entity has no components.

◆ ecs_has_id()

bool ecs_has_id ( const ecs_world_t world,
ecs_entity_t  entity,
ecs_id_t  id 
)

Test if an entity has an entity.

This operation returns true if the entity has the provided entity in its type.

Parameters
worldThe world.
entityThe entity.
idThe id to test for.
Returns
True if the entity has the entity, false if not.

◆ ecs_table_str()

char * ecs_table_str ( const ecs_world_t world,
const ecs_table_t table 
)

Convert table to string.

Same as ecs_type_str(world, ecs_table_get_type(table)). The result of this operation must be freed with ecs_os_free.

Parameters
worldThe world.
tableThe table.
Returns
The stringified table type.

◆ ecs_type_str()

char * ecs_type_str ( const ecs_world_t world,
const ecs_type_t type 
)

Convert type to string.

The result of this operation must be freed with ecs_os_free.

Parameters
worldThe world.
typeThe type.
Returns
The stringified type.