Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Table sorting

Convenience macros for sorting tables. More...

Collaboration diagram for Table sorting:

Macros

#define ecs_sort_table(id)   ecs_id(id##_sort_table)
 Declare a table sort function.
 
#define ecs_compare(id)   ecs_id(id##_compare_fn)
 Declare a comparison function.
 
#define ECS_SORT_TABLE_WITH_COMPARE(id, op_name, compare_fn, ...)
 Declare an efficient table sorting operation that uses the provided compare function.
 
#define ECS_SORT_TABLE(id, ...)    ECS_SORT_TABLE_WITH_COMPARE(id, ecs_sort_table(id), ecs_compare(id), __VA_ARGS__)
 Declare an efficient table sorting operation that uses the default component comparison operator.
 
#define ECS_COMPARE(id, ...)
 Declare component comparison operations.
 

Detailed Description

Convenience macros for sorting tables.

Macro Definition Documentation

◆ ecs_compare

#define ecs_compare ( id)    ecs_id(id##_compare_fn)

Declare a comparison function.

Definition at line 799 of file flecs_c.h.

◆ ECS_COMPARE

#define ECS_COMPARE ( id,
... )
Value:
int ecs_compare(id)(ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2) { \
__VA_ARGS__ \
}
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:381
#define ecs_compare(id)
Declare a comparison function.
Definition flecs_c.h:799

Declare component comparison operations.

Parameters: ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2 Example:

ECS_COMPARE(MyType, { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; });
#define ECS_COMPARE(id,...)
Declare component comparison operations.
Definition flecs_c.h:907

Definition at line 907 of file flecs_c.h.

◆ ecs_sort_table

#define ecs_sort_table ( id)    ecs_id(id##_sort_table)

Declare a table sort function.

Definition at line 796 of file flecs_c.h.

◆ ECS_SORT_TABLE

#define ECS_SORT_TABLE ( id,
... )    ECS_SORT_TABLE_WITH_COMPARE(id, ecs_sort_table(id), ecs_compare(id), __VA_ARGS__)

Declare an efficient table sorting operation that uses the default component comparison operator.

For best results, use LTO or make the comparison operator visible in the same compilation unit. Variadic arguments are prepended before generated functions; use them to declare static or exported functions. Example:

ECS_COMPARE(MyType, { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; });
#define ECS_SORT_TABLE(id,...)
Declare an efficient table sorting operation that uses the default component comparison operator.
Definition flecs_c.h:894

Definition at line 894 of file flecs_c.h.

◆ ECS_SORT_TABLE_WITH_COMPARE

#define ECS_SORT_TABLE_WITH_COMPARE ( id,
op_name,
compare_fn,
... )

Declare an efficient table sorting operation that uses the provided compare function.

For best results, use LTO or make the function body visible in the same compilation unit. Variadic arguments are prepended before generated functions; use them to declare static or exported functions. Parameters of the comparison function: ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2 Parameters of the sort functions: ecs_world_t *world ecs_table_t *table ecs_entity_t *entities void *ptr int32_t elem_size int32_t lo int32_t hi ecs_order_by_action_t order_by - Pointer to the original comparison function. You are not supposed to use it. Example:

int CompareMyType(ecs_entity_t e1, const void* ptr1, ecs_entity_t e2, const void* ptr2) { const MyType* p1 = ptr1; const MyType* p2 = ptr2; return p1->value - p2->value; }
ECS_SORT_TABLE_WITH_COMPARE(MyType, MyCustomCompare, CompareMyType)
#define ECS_SORT_TABLE_WITH_COMPARE(id, op_name, compare_fn,...)
Declare an efficient table sorting operation that uses the provided compare function.
Definition flecs_c.h:824

Definition at line 824 of file flecs_c.h.