Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Each iterator
Collaboration diagram for Each iterator:

Functions

ecs_iter_t ecs_each_id (const ecs_world_t *world, ecs_id_t id)
 Iterate all entities with specified (component id).
 
bool ecs_each_next (ecs_iter_t *it)
 Progress an iterator created with ecs_each_id().
 
ecs_iter_t ecs_children (const ecs_world_t *world, ecs_entity_t parent)
 Iterate children of parent.
 
bool ecs_children_next (ecs_iter_t *it)
 Progress an iterator created with ecs_children().
 

Detailed Description

Find all entities that have a single (component) id.

Function Documentation

◆ ecs_children()

ecs_iter_t ecs_children ( const ecs_world_t * world,
ecs_entity_t parent )

Iterate children of parent.

Equivalent to:

ecs_iter_t it = ecs_each_id(world, ecs_pair(EcsChildOf, parent));
const ecs_entity_t EcsChildOf
Used to express parent-child relationships.
ecs_iter_t ecs_each_id(const ecs_world_t *world, ecs_id_t id)
Iterate all entities with specified (component id).
Iterator.
Definition flecs.h:1062
Parameters
worldThe world.
parentThe parent.
Returns
An iterator that iterates all children of the parent.
See also
ecs_each_id()

◆ ecs_children_next()

bool ecs_children_next ( ecs_iter_t * it)

Progress an iterator created with ecs_children().

Parameters
itThe iterator.
Returns
True if the iterator has more results, false if not.

◆ ecs_each_id()

ecs_iter_t ecs_each_id ( const ecs_world_t * world,
ecs_id_t id )

Iterate all entities with specified (component id).

This returns an iterator that yields all entities with a single specified component. This is a much lighter weight operation than creating and iterating a query.

Usage:

ecs_iter_t it = ecs_each(world, Player);
while (ecs_each_next(&it)) {
for (int i = 0; i < it.count; i ++) {
// Iterate as usual.
}
}
bool ecs_each_next(ecs_iter_t *it)
Progress an iterator created with ecs_each_id().
int32_t count
Number of entities to iterate.
Definition flecs.h:1112

If the specified id is a component, it is possible to access the component pointer with ecs_field just like with regular queries:

ecs_iter_t it = ecs_each(world, Position);
while (ecs_each_next(&it)) {
Position *p = ecs_field(&it, Position, 0);
for (int i = 0; i < it.count; i ++) {
// Iterate as usual.
}
}
Parameters
worldThe world.
idThe (component) id to iterate.
Returns
An iterator that iterates all entities with the (component) id.

◆ ecs_each_next()

bool ecs_each_next ( ecs_iter_t * it)

Progress an iterator created with ecs_each_id().

Parameters
itThe iterator.
Returns
True if the iterator has more results, false if not.