Flecs v4.0
A fast entity component system (ECS) for C & C++
|
Functions for working with ecs_iter_t
.
More...
Functions | |
bool | ecs_iter_next (ecs_iter_t *it) |
Progress any iterator. | |
void | ecs_iter_fini (ecs_iter_t *it) |
Cleanup iterator resources. | |
int32_t | ecs_iter_count (ecs_iter_t *it) |
Count number of matched entities in query. | |
bool | ecs_iter_is_true (ecs_iter_t *it) |
Test if iterator is true. | |
ecs_entity_t | ecs_iter_first (ecs_iter_t *it) |
Get first matching entity from iterator. | |
void | ecs_iter_set_var (ecs_iter_t *it, int32_t var_id, ecs_entity_t entity) |
Set value for iterator variable. | |
void | ecs_iter_set_var_as_table (ecs_iter_t *it, int32_t var_id, const ecs_table_t *table) |
Same as ecs_iter_set_var(), but for a table. | |
void | ecs_iter_set_var_as_range (ecs_iter_t *it, int32_t var_id, const ecs_table_range_t *range) |
Same as ecs_iter_set_var(), but for a range of entities This constrains the variable to a range of entities in a table. | |
ecs_entity_t | ecs_iter_get_var (ecs_iter_t *it, int32_t var_id) |
Get value of iterator variable as entity. | |
ecs_table_t * | ecs_iter_get_var_as_table (ecs_iter_t *it, int32_t var_id) |
Get value of iterator variable as table. | |
ecs_table_range_t | ecs_iter_get_var_as_range (ecs_iter_t *it, int32_t var_id) |
Get value of iterator variable as table range. | |
bool | ecs_iter_var_is_constrained (ecs_iter_t *it, int32_t var_id) |
Returns whether variable is constrained. | |
bool | ecs_iter_changed (ecs_iter_t *it) |
Returns whether current iterator result has changed. | |
char * | ecs_iter_str (const ecs_iter_t *it) |
Convert iterator to string. | |
ecs_iter_t | ecs_page_iter (const ecs_iter_t *it, int32_t offset, int32_t limit) |
Create a paged iterator. | |
bool | ecs_page_next (ecs_iter_t *it) |
Progress a paged iterator. | |
ecs_iter_t | ecs_worker_iter (const ecs_iter_t *it, int32_t index, int32_t count) |
Create a worker iterator. | |
bool | ecs_worker_next (ecs_iter_t *it) |
Progress a worker iterator. | |
void * | ecs_field_w_size (const ecs_iter_t *it, size_t size, int8_t index) |
Get data for field. | |
void * | ecs_field_at_w_size (const ecs_iter_t *it, size_t size, int8_t index, int32_t row) |
Get data for field at specified row. | |
bool | ecs_field_is_readonly (const ecs_iter_t *it, int8_t index) |
Test whether the field is readonly. | |
bool | ecs_field_is_writeonly (const ecs_iter_t *it, int8_t index) |
Test whether the field is writeonly. | |
bool | ecs_field_is_set (const ecs_iter_t *it, int8_t index) |
Test whether field is set. | |
ecs_id_t | ecs_field_id (const ecs_iter_t *it, int8_t index) |
Return id matched for field. | |
int32_t | ecs_field_column (const ecs_iter_t *it, int8_t index) |
Return index of matched table column. | |
ecs_entity_t | ecs_field_src (const ecs_iter_t *it, int8_t index) |
Return field source. | |
size_t | ecs_field_size (const ecs_iter_t *it, int8_t index) |
Return field type size. | |
bool | ecs_field_is_self (const ecs_iter_t *it, int8_t index) |
Test whether the field is matched on self. | |
Functions for working with ecs_iter_t
.
void * ecs_field_at_w_size | ( | const ecs_iter_t * | it, |
size_t | size, | ||
int8_t | index, | ||
int32_t | row ) |
Get data for field at specified row.
This operation should be used instead of ecs_field_w_size for sparse component fields. This operation should be called for each returned row in a result. In the following example the Velocity component is sparse:
it | the iterator. |
size | The size of the field type. |
index | The index of the field. |
int32_t ecs_field_column | ( | const ecs_iter_t * | it, |
int8_t | index ) |
Return index of matched table column.
This function only returns column indices for fields that have been matched on the $this variable. Fields matched on other tables will return -1.
it | The iterator. |
index | The index of the field in the iterator. |
ecs_id_t ecs_field_id | ( | const ecs_iter_t * | it, |
int8_t | index ) |
Return id matched for field.
it | The iterator. |
index | The index of the field in the iterator. |
bool ecs_field_is_readonly | ( | const ecs_iter_t * | it, |
int8_t | index ) |
Test whether the field is readonly.
This operation returns whether the field is readonly. Readonly fields are annotated with [in], or are added as a const type in the C++ API.
it | The iterator. |
index | The index of the field in the iterator. |
bool ecs_field_is_self | ( | const ecs_iter_t * | it, |
int8_t | index ) |
Test whether the field is matched on self.
This operation returns whether the field is matched on the currently iterated entity. This function will return false when the field is owned by another entity, such as a parent or a prefab.
When this operation returns false, the field must be accessed as a single value instead of an array. Fields for which this operation returns true return arrays with it->count values.
it | The iterator. |
index | The index of the field in the iterator. |
bool ecs_field_is_set | ( | const ecs_iter_t * | it, |
int8_t | index ) |
Test whether field is set.
it | The iterator. |
index | The index of the field in the iterator. |
bool ecs_field_is_writeonly | ( | const ecs_iter_t * | it, |
int8_t | index ) |
Test whether the field is writeonly.
This operation returns whether this is a writeonly field. Writeonly terms are annotated with [out].
Serializers are not required to serialize the values of a writeonly field.
it | The iterator. |
index | The index of the field in the iterator. |
size_t ecs_field_size | ( | const ecs_iter_t * | it, |
int8_t | index ) |
Return field type size.
Return type size of the field. Returns 0 if the field has no data.
it | The iterator. |
index | The index of the field in the iterator. |
ecs_entity_t ecs_field_src | ( | const ecs_iter_t * | it, |
int8_t | index ) |
Return field source.
The field source is the entity on which the field was matched.
it | The iterator. |
index | The index of the field in the iterator. |
void * ecs_field_w_size | ( | const ecs_iter_t * | it, |
size_t | size, | ||
int8_t | index ) |
Get data for field.
This operation retrieves a pointer to an array of data that belongs to the term in the query. The index refers to the location of the term in the query, and starts counting from zero.
For example, the query "Position, Velocity"
will return the Position
array for index 0, and the Velocity
array for index 1.
When the specified field is not owned by the entity this function returns a pointer instead of an array. This happens when the source of a field is not the entity being iterated, such as a shared component (from a prefab), a component from a parent, or another entity. The ecs_field_is_self() operation can be used to test dynamically if a field is owned.
When a field contains a sparse component, use the ecs_field_at function. When a field is guaranteed to be set and owned, the ecs_field_self() function can be used. ecs_field_self() has slightly better performance, and provides stricter validity checking.
The provided size must be either 0 or must match the size of the type of the returned array. If the size does not match, the operation may assert. The size can be dynamically obtained with ecs_field_size().
An example:
it | The iterator. |
size | The size of the field type. |
index | The index of the field. |
bool ecs_iter_changed | ( | ecs_iter_t * | it | ) |
Returns whether current iterator result has changed.
This operation must be used in combination with a query that supports change detection (e.g. is cached). The operation returns whether the currently iterated result has changed since the last time it was iterated by the query.
Change detection works on a per-table basis. Changes to individual entities cannot be detected this way.
it | The iterator. |
int32_t ecs_iter_count | ( | ecs_iter_t * | it | ) |
Count number of matched entities in query.
This operation returns the number of matched entities. If a query contains no matched entities but still yields results (e.g. it has no terms with This sources) the operation will return 0.
To determine the number of matched entities, the operation iterates the iterator until it yields no more results.
it | The iterator. |
void ecs_iter_fini | ( | ecs_iter_t * | it | ) |
Cleanup iterator resources.
This operation cleans up any resources associated with the iterator.
This operation should only be used when an iterator is not iterated until completion (next has not yet returned false). When an iterator is iterated until completion, resources are automatically freed.
it | The iterator. |
ecs_entity_t ecs_iter_first | ( | ecs_iter_t * | it | ) |
Get first matching entity from iterator.
After this operation the application should treat the iterator as if it has been iterated until completion.
it | The iterator. |
ecs_entity_t ecs_iter_get_var | ( | ecs_iter_t * | it, |
int32_t | var_id ) |
Get value of iterator variable as entity.
A variable can be interpreted as entity if it is set to an entity, or if it is set to a table range with count 1.
This operation can only be invoked on valid iterators. The variable index must be smaller than the total number of variables provided by the iterator (as set in ecs_iter_t::variable_count).
it | The iterator. |
var_id | The variable index. |
ecs_table_range_t ecs_iter_get_var_as_range | ( | ecs_iter_t * | it, |
int32_t | var_id ) |
Get value of iterator variable as table range.
A value can be interpreted as table range if it is set as table range, or if it is set to an entity with a non-empty type (the entity must have at least one component, tag or relationship in its type).
This operation can only be invoked on valid iterators. The variable index must be smaller than the total number of variables provided by the iterator (as set in ecs_iter_t::variable_count).
it | The iterator. |
var_id | The variable index. |
ecs_table_t * ecs_iter_get_var_as_table | ( | ecs_iter_t * | it, |
int32_t | var_id ) |
Get value of iterator variable as table.
A variable can be interpreted as table if it is set as table range with both offset and count set to 0, or if offset is 0 and count matches the number of elements in the table.
This operation can only be invoked on valid iterators. The variable index must be smaller than the total number of variables provided by the iterator (as set in ecs_iter_t::variable_count).
it | The iterator. |
var_id | The variable index. |
bool ecs_iter_is_true | ( | ecs_iter_t * | it | ) |
Test if iterator is true.
This operation will return true if the iterator returns at least one result. This is especially useful in combination with fact-checking queries (see the queries addon).
The operation requires a valid iterator. After the operation is invoked, the application should no longer invoke next on the iterator and should treat it as if the iterator is iterated until completion.
it | The iterator. |
bool ecs_iter_next | ( | ecs_iter_t * | it | ) |
Progress any iterator.
This operation is useful in combination with iterators for which it is not known what created them. Example use cases are functions that should accept any kind of iterator (such as serializers) or iterators created from poly objects.
This operation is slightly slower than using a type-specific iterator (e.g. ecs_query_next, ecs_query_next) as it has to call a function pointer which introduces a level of indirection.
it | The iterator. |
void ecs_iter_set_var | ( | ecs_iter_t * | it, |
int32_t | var_id, | ||
ecs_entity_t | entity ) |
Set value for iterator variable.
This constrains the iterator to return only results for which the variable equals the specified value. The default value for all variables is EcsWildcard, which means the variable can assume any value.
Example:
The variable must be initialized after creating the iterator and before the first call to next.
it | The iterator. |
var_id | The variable index. |
entity | The entity variable value. |
void ecs_iter_set_var_as_range | ( | ecs_iter_t * | it, |
int32_t | var_id, | ||
const ecs_table_range_t * | range ) |
Same as ecs_iter_set_var(), but for a range of entities This constrains the variable to a range of entities in a table.
it | The iterator. |
var_id | The variable index. |
range | The range variable value. |
void ecs_iter_set_var_as_table | ( | ecs_iter_t * | it, |
int32_t | var_id, | ||
const ecs_table_t * | table ) |
Same as ecs_iter_set_var(), but for a table.
This constrains the variable to all entities in a table.
it | The iterator. |
var_id | The variable index. |
table | The table variable value. |
char * ecs_iter_str | ( | const ecs_iter_t * | it | ) |
Convert iterator to string.
Prints the contents of an iterator to a string. Useful for debugging and/or testing the output of an iterator.
The function only converts the currently iterated data to a string. To convert all data, the application has to manually call the next function and call ecs_iter_str() on each result.
it | The iterator. |
bool ecs_iter_var_is_constrained | ( | ecs_iter_t * | it, |
int32_t | var_id ) |
Returns whether variable is constrained.
This operation returns true for variables set by one of the ecs_iter_set_var* operations.
A constrained variable is guaranteed not to change values while results are being iterated.
it | The iterator. |
var_id | The variable index. |
ecs_iter_t ecs_page_iter | ( | const ecs_iter_t * | it, |
int32_t | offset, | ||
int32_t | limit ) |
Create a paged iterator.
Paged iterators limit the results to those starting from 'offset', and will return at most 'limit' results.
The iterator must be iterated with ecs_page_next().
A paged iterator acts as a passthrough for data exposed by the parent iterator, so that any data provided by the parent will also be provided by the paged iterator.
it | The source iterator. |
offset | The number of entities to skip. |
limit | The maximum number of entities to iterate. |
bool ecs_page_next | ( | ecs_iter_t * | it | ) |
Progress a paged iterator.
Progresses an iterator created by ecs_page_iter().
it | The iterator. |
ecs_iter_t ecs_worker_iter | ( | const ecs_iter_t * | it, |
int32_t | index, | ||
int32_t | count ) |
Create a worker iterator.
Worker iterators can be used to equally divide the number of matched entities across N resources (usually threads). Each resource will process the total number of matched entities divided by 'count'.
Entities are distributed across resources such that the distribution is stable between queries. Two queries that match the same table are guaranteed to match the same entities in that table.
The iterator must be iterated with ecs_worker_next().
A worker iterator acts as a passthrough for data exposed by the parent iterator, so that any data provided by the parent will also be provided by the worker iterator.
it | The source iterator. |
index | The index of the current resource. |
count | The total number of resources to divide entities between. |
bool ecs_worker_next | ( | ecs_iter_t * | it | ) |
Progress a worker iterator.
Progresses an iterator created by ecs_worker_iter().
it | The iterator. |