1#include <change_tracking.h>
2#include <stdio.h>
3
4
5
6
7
8
9
10
11typedef struct {
12 bool value;
13} Dirty;
14
15typedef struct {
16 double x, y;
17} Position;
18
19int main(int argc, char *argv[]) {
21
24
25
27
28
29
30
31
33 .terms = {{ .id =
ecs_id(Position), .inout =
EcsIn }},
35 });
36
37
39 .terms = {
40
41 {
46 },
48 }
49 });
50
51
52
55 ecs_set(world, p1, Dirty, {
false});
56
59 ecs_set(world, p2, Dirty, {
true});
60
61
62
65 ecs_set(world, e1, Position, {10, 20});
66
69 ecs_set(world, e2, Position, {30, 40});
70
73 ecs_set(world, e3, Position, {50, 60});
74
77 ecs_set(world, e4, Position, {70, 80});
78
79
80
81
82
84
85
88
89
90
91
93 printf("it.changed for table [%s]: %d\n", table_str,
95 ecs_os_free(table_str);
96 }
97
98
100
101
102
106
108 printf("iterate table [%s]\n", table_str);
109 ecs_os_free(table_str);
110
111
112
113 if (!dirty->value) {
116 printf("it.skip for table [%s]\n", table_str);
117 ecs_os_free(table_str);
118 continue;
119 }
120
121 Position *p =
ecs_field(&it, Position, 1);
122
123
124 for (
int i = 0; i < it.
count; i ++) {
125 p[i].x ++;
126 p[i].y ++;
127 }
128 }
129
130
132
133
137 printf("it.changed for table [%s]: %d\n", table_str,
139 ecs_os_free(table_str);
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
157}
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
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.
char * ecs_table_str(const ecs_world_t *world, const ecs_table_t *table)
Convert a table to a string.
#define ecs_add_pair(world, subject, first, second)
Add a pair to an entity.
#define ecs_entity(world,...)
Shorthand for creating an entity with ecs_entity_init().
#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_field(it, T, index)
Get field data for a component.
bool ecs_iter_changed(ecs_iter_t *it)
Return whether the current iterator result has changed.
void ecs_iter_skip(ecs_iter_t *it)
Skip a table while iterating.
bool ecs_query_next(ecs_iter_t *it)
Progress a query iterator.
#define EcsQueryDetectChanges
Enable change detection for a query.
ecs_iter_t ecs_query_iter(const ecs_world_t *world, const ecs_query_t *query)
Create a query iterator.
bool ecs_query_changed(ecs_query_t *query)
Return whether the query data changed since the last iteration.
#define EcsUp
Match by traversing upwards.
@ EcsIn
Term is only read.
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.
ecs_table_t * table
Current table.
int32_t count
Number of entities to iterate.
Queries are lists of constraints (terms) that match entities.