Flecs: ecs_iter_t Struct Reference
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.1 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
ecs_iter_t Struct Reference
C API » Core » API types | C API » Core » Queries

Iterator. More...

`#include <flecs.h>`

## Public Attributes
ecs_world_t * | world
| The world.
ecs_world_t * | real_world
| Actual world.
int32_t | offset
| Offset relative to the current table.
int32_t | count
| Number of entities to iterate.
const ecs_entity_t * | entities
| Entity identifiers.
void ** | ptrs
| Component pointers.
const ecs_table_record_t ** | trs
| Info on where to find the field in the table.
const int16_t * | columns
const ecs_size_t * | sizes
| Component sizes.
ecs_table_t * | table
| Current table.
ecs_table_t * | other_table
| Previous or next table when adding or removing.
ecs_id_t * | ids
| (Component) IDs.
ecs_entity_t * | sources
| Entity on which the ID was matched (0 if same as entities).
ecs_flags64_t | constrained_vars
| Bitset that marks constrained variables.
ecs_flags32_t | set_fields
| Fields that are set.
ecs_flags32_t | ref_fields
| Bitset with fields that aren't component arrays.
ecs_flags32_t | row_fields
| Fields that must be obtained with field_at.
ecs_flags32_t | up_fields
| Bitset with fields matched through up traversal.
ecs_entity_t | system
| The system (if applicable).
ecs_entity_t | event
| The event (if applicable).
ecs_id_t | event_id
| The (component) ID for the event.
int32_t | event_cur
| Unique event ID.
int8_t | field_count
| Number of fields in the iterator.
int8_t | term_index
| Index of the term that emitted an event.
const ecs_query_t * | query
| Query being evaluated.
void * | param
| Param passed to ecs_run().
void * | ctx
| System context.
void * | binding_ctx
| System binding context.
void * | callback_ctx
| Callback language binding context.
void * | run_ctx
| Run language binding context.
float | delta_time
| Time elapsed since last frame.
float | delta_system_time
| Time elapsed since last system invocation.
int32_t | frame_offset
| Offset relative to the start of iteration.
ecs_flags32_t | flags
| Iterator flags.
ecs_entity_t | interrupted_by
| When set, system execution is interrupted.
ecs_iter_private_t | priv_
| Private data.
ecs_iter_next_action_t | next
| Function to progress iterator.
ecs_iter_action_t | callback
| Callback of system or observer.
ecs_iter_fini_action_t | fini
| Function to clean up iterator resources.
ecs_iter_t * | chain_it
| Optional, allows for creating iterator chains.

## Detailed Description

Iterator.

Used for iterating queries. The ecs_iter_t type contains all the information that is provided by a query, and contains all the state required for the iterator code.

Functions that create iterators accept as first argument the world, and as second argument the object they iterate. For example:

ecs_iter_t it = ecs_query_iter(world, q);
ecs_query_iter
ecs_iter_t ecs_query_iter(const ecs_world_t *world, const ecs_query_t *query)
Create a query iterator.
ecs_iter_t
Iterator.
Definition flecs.h:1170
ecs_iter_t::world
ecs_world_t * world
The world.
Definition flecs.h:1172

When this code is called from a system, it is important to use the world provided by its iterator object to ensure thread safety. For example:

void Collide(ecs_iter_t *it) {
ecs_iter_t qit = ecs_query_iter(it->world, Colliders);
}

An iterator contains resources that need to be released. By default, this is handled by the last call to next() that returns false. When iteration is ended before iteration has completed, an application has to manually call ecs_iter_fini() to release the iterator resources:

ecs_iter_t it = ecs_query_iter(world, q);
while (ecs_query_next(&it)) {
if (cond) {
ecs_iter_fini(&it);
break;
}
}
ecs_iter_fini
void ecs_iter_fini(ecs_iter_t *it)
Clean up iterator resources.
ecs_query_next
bool ecs_query_next(ecs_iter_t *it)
Progress a query iterator.

Definition at line 1170 of file flecs.h.

## Member Data Documentation

## ◆ binding_ctx

void* ecs_iter_t::binding_ctx

System binding context.

Definition at line 1209 of file flecs.h.

## ◆ callback

ecs_iter_action_t ecs_iter_t::callback

Callback of system or observer.

Definition at line 1227 of file flecs.h.

## ◆ callback_ctx

void* ecs_iter_t::callback_ctx

Callback language binding context.

Definition at line 1210 of file flecs.h.

## ◆ chain_it

ecs_iter_t* ecs_iter_t::chain_it

Optional, allows for creating iterator chains.

Definition at line 1229 of file flecs.h.

## ◆ columns

const int16_t* ecs_iter_t::columns

Definition at line 1181 of file flecs.h.

## ◆ constrained_vars

ecs_flags64_t ecs_iter_t::constrained_vars

Bitset that marks constrained variables.

Definition at line 1187 of file flecs.h.

## ◆ count

int32_t ecs_iter_t::count

Number of entities to iterate.

Definition at line 1177 of file flecs.h.

## ◆ ctx

void* ecs_iter_t::ctx

System context.

Definition at line 1208 of file flecs.h.

## ◆ delta_system_time

float ecs_iter_t::delta_system_time

Time elapsed since last system invocation.

Definition at line 1215 of file flecs.h.

## ◆ delta_time

float ecs_iter_t::delta_time

Time elapsed since last frame.

Definition at line 1214 of file flecs.h.

## ◆ entities

const ecs_entity_t* ecs_iter_t::entities

Entity identifiers.

Definition at line 1178 of file flecs.h.

## ◆ event

ecs_entity_t ecs_iter_t::event

The event (if applicable).

Definition at line 1195 of file flecs.h.

## ◆ event_cur

int32_t ecs_iter_t::event_cur

Unique event ID.

Used to dedup observer calls.

Definition at line 1197 of file flecs.h.

## ◆ event_id

ecs_id_t ecs_iter_t::event_id

The (component) ID for the event.

Definition at line 1196 of file flecs.h.

## ◆ field_count

int8_t ecs_iter_t::field_count

Number of fields in the iterator.

Definition at line 1200 of file flecs.h.

## ◆ fini

ecs_iter_fini_action_t ecs_iter_t::fini

Function to clean up iterator resources.

Definition at line 1228 of file flecs.h.

## ◆ flags

ecs_flags32_t ecs_iter_t::flags

Iterator flags.

Definition at line 1221 of file flecs.h.

## ◆ frame_offset

int32_t ecs_iter_t::frame_offset

Offset relative to the start of iteration.

Definition at line 1218 of file flecs.h.

## ◆ ids

ecs_id_t* ecs_iter_t::ids

(Component) IDs.

Definition at line 1185 of file flecs.h.

## ◆ interrupted_by

ecs_entity_t ecs_iter_t::interrupted_by

When set, system execution is interrupted.

Definition at line 1222 of file flecs.h.

## ◆ next

ecs_iter_next_action_t ecs_iter_t::next

Function to progress iterator.

Definition at line 1226 of file flecs.h.

## ◆ offset

int32_t ecs_iter_t::offset

Offset relative to the current table.

Definition at line 1176 of file flecs.h.

## ◆ other_table

ecs_table_t* ecs_iter_t::other_table

Previous or next table when adding or removing.

Definition at line 1184 of file flecs.h.

## ◆ param

void* ecs_iter_t::param

Param passed to ecs_run().

Definition at line 1207 of file flecs.h.

## ◆ priv_

ecs_iter_private_t ecs_iter_t::priv_

Private data.

Definition at line 1223 of file flecs.h.

## ◆ ptrs

void** ecs_iter_t::ptrs

Component pointers.

If not set or if it is NULL for a field, use it->trs.

Definition at line 1179 of file flecs.h.

## ◆ query

const ecs_query_t* ecs_iter_t::query

Query being evaluated.

Definition at line 1204 of file flecs.h.

## ◆ real_world

ecs_world_t* ecs_iter_t::real_world

Actual world.

Never points to a stage.

Definition at line 1173 of file flecs.h.

## ◆ ref_fields

ecs_flags32_t ecs_iter_t::ref_fields

Bitset with fields that aren't component arrays.

Definition at line 1189 of file flecs.h.

## ◆ row_fields

ecs_flags32_t ecs_iter_t::row_fields

Fields that must be obtained with field_at.

Definition at line 1190 of file flecs.h.

## ◆ run_ctx

void* ecs_iter_t::run_ctx

Run language binding context.

Definition at line 1211 of file flecs.h.

## ◆ set_fields

ecs_flags32_t ecs_iter_t::set_fields

Fields that are set.

Definition at line 1188 of file flecs.h.

## ◆ sizes

const ecs_size_t* ecs_iter_t::sizes

Component sizes.

Definition at line 1182 of file flecs.h.

## ◆ sources

ecs_entity_t* ecs_iter_t::sources

Entity on which the ID was matched (0 if same as entities).

Definition at line 1186 of file flecs.h.

## ◆ system

ecs_entity_t ecs_iter_t::system

The system (if applicable).

Definition at line 1194 of file flecs.h.

## ◆ table

ecs_table_t* ecs_iter_t::table

Current table.

Definition at line 1183 of file flecs.h.

## ◆ term_index

int8_t ecs_iter_t::term_index

Index of the term that emitted an event.

This field will be set to the 'index' field of an observer term.

Definition at line 1201 of file flecs.h.

## ◆ trs

const ecs_table_record_t** ecs_iter_t::trs

Info on where to find the field in the table.

Definition at line 1180 of file flecs.h.

## ◆ up_fields

ecs_flags32_t ecs_iter_t::up_fields

Bitset with fields matched through up traversal.

Definition at line 1191 of file flecs.h.

## ◆ world

ecs_world_t* ecs_iter_t::world

The world.

Can point to a stage when in deferred or readonly mode.

Definition at line 1172 of file flecs.h.

The documentation for this struct was generated from the following file:

- include/flecs.h