1#include <query_to_custom_json.h>
2#include <stdio.h>
3
4
5
6typedef struct {
7 float x, y;
8} Position, Velocity;
9
10typedef struct {
11 float value;
12} Mass;
13
14int main(int argc, char *argv[]) {
16
17
21
22
24 .entity =
ecs_id(Position),
25 .members = {
28 }
29 });
30
32 .entity =
ecs_id(Velocity),
33 .members = {
36 }
37 });
38
41 .members = {
43 }
44 });
45
50
51 ecs_set(ecs, a, Position, {10, 20});
52 ecs_set(ecs, b, Position, {20, 30});
53 ecs_set(ecs, c, Position, {30, 40});
54 ecs_set(ecs, d, Position, {40, 50});
55
56 ecs_set(ecs, a, Velocity, {1, 2});
57 ecs_set(ecs, b, Velocity, {2, 3});
58 ecs_set(ecs, c, Velocity, {3, 4});
59 ecs_set(ecs, d, Velocity, {4, 5});
60
63
64
66 .terms = {
68 }
69 });
70
72
73
74
76 .serialize_values = true
77 };
79 printf("%s\n", json);
80 ecs_os_free(json);
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
158}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
FLECS_API char * ecs_iter_to_json(ecs_iter_t *iter, const ecs_iter_to_json_desc_t *desc)
Serialize iterator into JSON string.
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.
ecs_entity_t ecs_set_name(ecs_world_t *world, ecs_entity_t entity, const char *name)
Set the name of an entity.
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.
Used with ecs_iter_to_json().
Queries are lists of constraints (terms) that match entities.