![]() |
Flecs v4.1
A fast entity component system (ECS) for C & C++
|
Functions for working with ecs_table_t.
More...
Functions | |
| const ecs_type_t * | ecs_table_get_type (const ecs_table_t *table) |
| Get the type for a table. | |
| int32_t | ecs_table_get_type_index (const ecs_world_t *world, const ecs_table_t *table, ecs_id_t component) |
| Get the type index for a component. | |
| int32_t | ecs_table_get_column_index (const ecs_world_t *world, const ecs_table_t *table, ecs_id_t component) |
| Get the column index for a component. | |
| int32_t | ecs_table_column_count (const ecs_table_t *table) |
| Return the number of columns in a table. | |
| int32_t | ecs_table_type_to_column_index (const ecs_table_t *table, int32_t index) |
| Convert a type index to a column index. | |
| int32_t | ecs_table_column_to_type_index (const ecs_table_t *table, int32_t index) |
| Convert a column index to a type index. | |
| void * | ecs_table_get_column (const ecs_table_t *table, int32_t index, int32_t offset) |
| Get a column from a table by column index. | |
| void * | ecs_table_get_id (const ecs_world_t *world, const ecs_table_t *table, ecs_id_t component, int32_t offset) |
| Get a column from a table by component. | |
| size_t | ecs_table_get_column_size (const ecs_table_t *table, int32_t index) |
| Get the column size from a table. | |
| int32_t | ecs_table_count (const ecs_table_t *table) |
| Return the number of entities in the table. | |
| int32_t | ecs_table_size (const ecs_table_t *table) |
| Return the allocated size of the table. | |
| const ecs_entity_t * | ecs_table_entities (const ecs_table_t *table) |
| Return the array with entity IDs for the table. | |
| bool | ecs_table_has_id (const ecs_world_t *world, const ecs_table_t *table, ecs_id_t component) |
| Test if a table has a component. | |
| ecs_entity_t | ecs_table_get_target (const ecs_world_t *world, const ecs_table_t *table, ecs_entity_t relationship, int32_t index) |
| Get the relationship target for a table. | |
| int32_t | ecs_table_get_depth (const ecs_world_t *world, const ecs_table_t *table, ecs_entity_t rel) |
| Return the depth for a table in the tree for the specified relationship. | |
| ecs_table_t * | ecs_table_add_id (ecs_world_t *world, ecs_table_t *table, ecs_id_t component) |
| Get the table that has all components of the current table plus the specified ID. | |
| ecs_table_t * | ecs_table_find (ecs_world_t *world, const ecs_id_t *ids, int32_t id_count) |
| Find a table from an ID array. | |
| ecs_table_t * | ecs_table_remove_id (ecs_world_t *world, ecs_table_t *table, ecs_id_t component) |
| Get the table that has all components of the current table minus the specified component. | |
| void | ecs_table_lock (ecs_world_t *world, ecs_table_t *table) |
| Lock a table. | |
| void | ecs_table_unlock (ecs_world_t *world, ecs_table_t *table) |
| Unlock a table. | |
| bool | ecs_table_has_flags (ecs_table_t *table, ecs_flags32_t flags) |
| Test a table for flags. | |
| bool | ecs_table_has_traversable (const ecs_table_t *table) |
| Check if a table has traversable entities. | |
| void | ecs_table_swap_rows (ecs_world_t *world, ecs_table_t *table, int32_t row_1, int32_t row_2) |
| Swap two elements inside the table. | |
| bool | ecs_commit (ecs_world_t *world, ecs_entity_t entity, ecs_record_t *record, ecs_table_t *table, const ecs_type_t *added, const ecs_type_t *removed) |
| Commit (move) an entity to a table. | |
| int32_t | ecs_search (const ecs_world_t *world, const ecs_table_t *table, ecs_id_t component, ecs_id_t *component_out) |
| Search for a component in a table type. | |
| int32_t | ecs_search_offset (const ecs_world_t *world, const ecs_table_t *table, int32_t offset, ecs_id_t component, ecs_id_t *component_out) |
| Search for a component in a table type starting from an offset. | |
| int32_t | ecs_search_relation (const ecs_world_t *world, const ecs_table_t *table, int32_t offset, ecs_id_t component, ecs_entity_t rel, ecs_flags64_t flags, ecs_entity_t *tgt_out, ecs_id_t *component_out, struct ecs_table_record_t **tr_out) |
| Search for a component or relationship ID in a table type starting from an offset. | |
| int32_t | ecs_search_relation_for_entity (const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id, ecs_entity_t rel, bool self, ecs_component_record_t *cr, ecs_entity_t *tgt_out, ecs_id_t *id_out, struct ecs_table_record_t **tr_out) |
| Search for a component ID by following a relationship, starting from an entity. | |
| void | ecs_table_clear_entities (ecs_world_t *world, ecs_table_t *table) |
| Remove all entities in a table. | |
Functions for working with ecs_table_t.
| bool ecs_commit | ( | ecs_world_t * | world, |
| ecs_entity_t | entity, | ||
| ecs_record_t * | record, | ||
| ecs_table_t * | table, | ||
| const ecs_type_t * | added, | ||
| const ecs_type_t * | removed ) |
Commit (move) an entity to a table.
This operation moves an entity from its current table to the specified table. This may cause the following actions:
OnAdd observers for non-overlapping components in the target table.OnRemove observers for non-overlapping components in the source table.This operation is faster than adding or removing components individually.
The application must explicitly provide the difference in components between tables as the added and removed parameters. This can usually be derived directly from the result of ecs_table_add_id() and ecs_table_remove_id(). These arrays are required to properly execute OnAdd and OnRemove observers.
| world | The world. |
| entity | The entity to commit. |
| record | The entity's record (optional, providing it saves a lookup). |
| table | The table to commit the entity to. |
| added | The components added to the entity. |
| removed | The components removed from the entity. |
| int32_t ecs_search | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| ecs_id_t | component, | ||
| ecs_id_t * | component_out ) |
Search for a component in a table type.
This operation returns the index of the first occurrence of the component in the table type. The component may be a pair or a wildcard.
When component_out is provided, the function will assign it with the found component. The found component may be different from the provided component if it is a wildcard.
This is a constant-time operation.
| world | The world. |
| table | The table. |
| component | The component to search for. |
| component_out | If provided, it will be set to the found component (optional). |
| int32_t ecs_search_offset | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| int32_t | offset, | ||
| ecs_id_t | component, | ||
| ecs_id_t * | component_out ) |
Search for a component in a table type starting from an offset.
This operation is the same as ecs_search(), but starts searching from an offset in the table type.
This operation is typically called in a loop where the resulting index is used in the next iteration as offset:
Depending on how the operation is used, it is either linear or constant time. When the ID has the form (id) or (rel, *) and the operation is invoked as in the above example, it is guaranteed to be constant time.
If the provided component has the form (*, tgt), the operation takes linear time. The reason for this is that IDs for a target are not packed together, as they are sorted relationship-first.
If the component at the offset does not match the provided ID, the operation will do a linear search to find a matching ID.
| world | The world. |
| table | The table. |
| offset | The offset from where to start searching. |
| component | The component to search for. |
| component_out | If provided, it will be set to the found component (optional). |
| int32_t ecs_search_relation | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| int32_t | offset, | ||
| ecs_id_t | component, | ||
| ecs_entity_t | rel, | ||
| ecs_flags64_t | flags, | ||
| ecs_entity_t * | tgt_out, | ||
| ecs_id_t * | component_out, | ||
| struct ecs_table_record_t ** | tr_out ) |
Search for a component or relationship ID in a table type starting from an offset.
This operation is the same as ecs_search_offset(), but has the additional capability of traversing relationships to find a component. For example, if an application wants to find a component for either the provided table or a prefab (using the IsA relationship) of that table, it could use the operation like this:
The operation searches depth-first. If a table type has 2 IsA relationships, the operation will first search the IsA tree of the first relationship.
When choosing between ecs_search(), ecs_search_offset(), and ecs_search_relation(), the simpler the function, the better its performance.
| world | The world. |
| table | The table. |
| offset | The offset from where to start searching. |
| component | The component to search for. |
| rel | The relationship to traverse (optional). |
| flags | Whether to search EcsSelf and/or EcsUp. |
| tgt_out | If provided, it will be set to the matched entity. |
| component_out | If provided, it will be set to the found component (optional). |
| tr_out | The internal datatype. |
| int32_t ecs_search_relation_for_entity | ( | const ecs_world_t * | world, |
| ecs_entity_t | entity, | ||
| ecs_id_t | id, | ||
| ecs_entity_t | rel, | ||
| bool | self, | ||
| ecs_component_record_t * | cr, | ||
| ecs_entity_t * | tgt_out, | ||
| ecs_id_t * | id_out, | ||
| struct ecs_table_record_t ** | tr_out ) |
Search for a component ID by following a relationship, starting from an entity.
This operation is the same as ecs_search_relation(), but starts the search from an entity rather than a table.
| world | The world. |
| entity | The entity from which to begin the search. |
| id | The component ID to search for. |
| rel | The relationship to follow. |
| self | If true, also search components on the entity itself. |
| cr | Optional component record for the component ID. |
| tgt_out | Out parameter for the target entity. |
| id_out | Out parameter for the found component ID. |
| tr_out | Out parameter for the table record. |
| ecs_table_t * ecs_table_add_id | ( | ecs_world_t * | world, |
| ecs_table_t * | table, | ||
| ecs_id_t | component ) |
Get the table that has all components of the current table plus the specified ID.
If the provided table already has the provided ID, the operation will return the provided table.
| world | The world. |
| table | The table. |
| component | The component to add. |
| void ecs_table_clear_entities | ( | ecs_world_t * | world, |
| ecs_table_t * | table ) |
Remove all entities in a table.
Does not deallocate table memory. Retaining table memory can be efficient when planning to refill the table with operations like ecs_bulk_init().
| world | The world. |
| table | The table to clear. |
| int32_t ecs_table_column_count | ( | const ecs_table_t * | table | ) |
Return the number of columns in a table.
Similar to ecs_table_get_type(table)->count, except that the column count only counts the number of components in a table.
| table | The table. |
| int32_t ecs_table_column_to_type_index | ( | const ecs_table_t * | table, |
| int32_t | index ) |
Convert a column index to a type index.
Same as ecs_table_type_to_column_index(), but converts from an index in the column array to an index in the table type.
| table | The table. |
| index | The column index. |
| int32_t ecs_table_count | ( | const ecs_table_t * | table | ) |
Return the number of entities in the table.
This operation returns the number of entities in the table.
| table | The table. |
| const ecs_entity_t * ecs_table_entities | ( | const ecs_table_t * | table | ) |
Return the array with entity IDs for the table.
The size of the returned array is the result of ecs_table_count().
| table | The table. |
| ecs_table_t * ecs_table_find | ( | ecs_world_t * | world, |
| const ecs_id_t * | ids, | ||
| int32_t | id_count ) |
Find a table from an ID array.
This operation finds or creates a table with the specified array of (component) IDs. The IDs in the array must be sorted, and it may not contain duplicate elements.
| world | The world. |
| ids | The ID array. |
| id_count | The number of elements in the ID array. |
| void * ecs_table_get_column | ( | const ecs_table_t * | table, |
| int32_t | index, | ||
| int32_t | offset ) |
Get a column from a table by column index.
This operation returns the component array for the provided index.
| table | The table. |
| index | The column index. |
| offset | The index of the first row to return (0 for entire column). |
| int32_t ecs_table_get_column_index | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| ecs_id_t | component ) |
Get the column index for a component.
This operation returns the column index for a component in the table's type. If the component doesn't have data (it is a tag), the function will return -1.
| world | The world. |
| table | The table. |
| component | The component. |
| size_t ecs_table_get_column_size | ( | const ecs_table_t * | table, |
| int32_t | index ) |
Get the column size from a table.
This operation returns the component size for the provided index.
| table | The table. |
| index | The column index. |
| int32_t ecs_table_get_depth | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| ecs_entity_t | rel ) |
Return the depth for a table in the tree for the specified relationship.
Depth is determined by counting the number of targets encountered while traversing up the relationship tree. Only acyclic relationships are supported.
| world | The world. |
| table | The table. |
| rel | The relationship. |
| void * ecs_table_get_id | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| ecs_id_t | component, | ||
| int32_t | offset ) |
Get a column from a table by component.
This operation returns the component array for the provided component.
| world | The world. |
| table | The table. |
| component | The component for the column. |
| offset | The index of the first row to return (0 for entire column). |
| ecs_entity_t ecs_table_get_target | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| ecs_entity_t | relationship, | ||
| int32_t | index ) |
Get the relationship target for a table.
| world | The world. |
| table | The table. |
| relationship | The relationship for which to obtain the target. |
| index | The index, in case the table has multiple instances of the relationship. |
| const ecs_type_t * ecs_table_get_type | ( | const ecs_table_t * | table | ) |
Get the type for a table.
The table type is a vector that contains all component, tag, and pair IDs.
| table | The table. |
| int32_t ecs_table_get_type_index | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| ecs_id_t | component ) |
Get the type index for a component.
This operation returns the index for a component in the table's type.
| world | The world. |
| table | The table. |
| component | The component. |
| bool ecs_table_has_flags | ( | ecs_table_t * | table, |
| ecs_flags32_t | flags ) |
Test a table for flags.
Test if a table has all of the provided flags. See include/flecs/private/api_flags.h for a list of table flags that can be used with this function.
| table | The table. |
| flags | The flags to test for. |
| bool ecs_table_has_id | ( | const ecs_world_t * | world, |
| const ecs_table_t * | table, | ||
| ecs_id_t | component ) |
Test if a table has a component.
Same as ecs_table_get_type_index(world, table, component) != -1.
| world | The world. |
| table | The table. |
| component | The component. |
| bool ecs_table_has_traversable | ( | const ecs_table_t * | table | ) |
Check if a table has traversable entities.
Traversable entities are entities that are used as a target in a pair with a relationship that has the Traversable trait.
| table | The table. |
| void ecs_table_lock | ( | ecs_world_t * | world, |
| ecs_table_t * | table ) |
Lock a table.
When a table is locked, modifications to it will throw an assert. When the table is locked recursively, it will take an equal amount of unlock operations to actually unlock the table.
Table locks can be used to build safe iterators where it is guaranteed that the contents of a table are not modified while it is being iterated.
The operation only works when called on the world, and has no side effects when called on a stage. The assumption is that when called on a stage, operations are deferred already.
| world | The world. |
| table | The table to lock. |
| ecs_table_t * ecs_table_remove_id | ( | ecs_world_t * | world, |
| ecs_table_t * | table, | ||
| ecs_id_t | component ) |
Get the table that has all components of the current table minus the specified component.
If the provided table doesn't have the provided component, the operation will return the provided table.
| world | The world. |
| table | The table. |
| component | The component to remove. |
| int32_t ecs_table_size | ( | const ecs_table_t * | table | ) |
Return the allocated size of the table.
This operation returns the number of elements allocated in the table per column.
| table | The table. |
| void ecs_table_swap_rows | ( | ecs_world_t * | world, |
| ecs_table_t * | table, | ||
| int32_t | row_1, | ||
| int32_t | row_2 ) |
Swap two elements inside the table.
This is useful for implementing custom table sorting algorithms.
| world | The world. |
| table | The table to swap elements in. |
| row_1 | The table element to swap with row_2. |
| row_2 | The table element to swap with row_1. |
| int32_t ecs_table_type_to_column_index | ( | const ecs_table_t * | table, |
| int32_t | index ) |
Convert a type index to a column index.
Tables have an array of columns for each component in the table. This array does not include elements for tags, which means that the index for a component in the table type is not necessarily the same as the index in the column array. This operation converts from an index in the table type to an index in the column array.
| table | The table. |
| index | The index in the table type. |
| void ecs_table_unlock | ( | ecs_world_t * | world, |
| ecs_table_t * | table ) |
Unlock a table.
Must be called after calling ecs_table_lock().
| world | The world. |
| table | The table to unlock. |