1#include <sorting.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position;
7
8
9int compare_position(
11 const void *ptr1,
13 const void *ptr2)
14{
15 const Position *p1 = ptr1;
16 const Position *p2 = ptr2;
17 (void)e1;
18 (void)e2;
19 return (p1->x > p2->x) - (p1->x < p2->x);
20}
21
24 for (
int i = 0; i < it->
count; i ++) {
25 printf("{%.1f, %.1f}\n", p[i].x, p[i].y);
26 }
27}
28
29
33 print_position(&it);
34 }
35}
36
37int main(int argc, char *argv[]) {
39
41
47
48
50 .query = {
51 .terms = {{ .id =
ecs_id(Position) }},
52 .order_by_callback = compare_position,
53 .order_by =
ecs_id(Position)
54 },
55 .callback = print_position
56 });
57
58
60 .terms = {{ .id =
ecs_id(Position) }},
61 .order_by_callback = compare_position,
62 .order_by =
ecs_id(Position)
63 });
64
65
66 printf("-- First iteration\n");
67 print_query(ecs, q);
68
69
70 ecs_set(ecs, e, Position, {7, 0});
71
72
73 printf("\n-- Second iteration\n");
74 print_query(ecs, q);
75
76
78
79 printf("\n-- System iteration\n");
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
106}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
#define ecs_system(world,...)
Shorthand for creating a system with ecs_system_init().
FLECS_API ecs_entity_t ecs_run(ecs_world_t *world, ecs_entity_t system, ecs_ftime_t delta_time, void *param)
Run a specific system manually.
ecs_id_t ecs_entity_t
An entity identifier.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
#define ECS_COMPONENT(world, id)
Declare and define a component.
#define ecs_query(world,...)
Shorthand for creating a query with ecs_query_init().
#define ecs_set(world, entity, component,...)
Set a component value.
#define ecs_insert(world,...)
Insert a new entity with a list of component values.
#define ecs_field(it, T, index)
Get field data for a component.
#define ecs_value(T,...)
Convenience macro for creating a compound literal value literal.
bool ecs_query_next(ecs_iter_t *it)
Progress a query iterator.
ecs_iter_t ecs_query_iter(const ecs_world_t *world, const ecs_query_t *query)
Create a query iterator.
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
int32_t count
Number of entities to iterate.
Queries are lists of constraints (terms) that match entities.