1#include <sorting.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position;
7
8
9int compare_position(
11 const Position *p1,
13 const Position *p2)
14{
15 (void)e1;
16 (void)e2;
17 return (p1->x > p2->x) - (p1->x < p2->x);
18}
19
22 for (
int i = 0; i < it->
count; i ++) {
23 printf("{%.1f, %.1f}\n", p[i].x, p[i].y);
24 }
25}
26
27
31 print_position(&it);
32 }
33}
34
35int main(int argc, char *argv[]) {
37
39
45
46
48 .query = {
49 .terms = {{ .id =
ecs_id(Position) }},
51 .order_by =
ecs_id(Position)
52 },
53 .callback = print_position
54 });
55
56
58 .terms = {{ .id =
ecs_id(Position) }},
60 .order_by =
ecs_id(Position)
61 });
62
63
64 printf("-- First iteration\n");
65 print_query(ecs, q);
66
67
68 ecs_set(ecs, e, Position, {7, 0});
69
70
71 printf("\n-- Second iteration\n");
72 print_query(ecs, q);
73
74
76
77 printf("\n-- System iteration\n");
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
104}
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.
int(*) ecs_order_by_action_t(ecs_entity_t e1, const void *ptr1, ecs_entity_t e2, const void *ptr2)
Callback used for comparing components.
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.