#include <include/flecs.h> FLECS_API void ecs_query_order_by(ecs_world_t *world, ecs_query_t *query, ecs_entity_t component, ecs_compare_action_t compare)
Sort the output of a query. This enables sorting of entities across matched tables. As a result of this operation, the order of entities in the matched tables may be changed. Resorting happens when a query iterator is obtained, and only if the table data has changed.
If multiple queries that match the same (sub)set of tables specify different sorting functions, resorting is likely to happen every time an iterator is obtained, which can significantly slow down iterations.
The sorting function will be applied to the specified component. Resorting only happens if that component has changed, or when the entity order in the table has changed. If no component is provided, resorting only happens when the entity order changes.
world- The world.
query- The query.
component- The component used to sort.
compare- The compare function used to sort the components.