1#include <query_to_json.h>
2#include <stdio.h>
3
4typedef struct {
5 float x, y;
6} Position, Velocity;
7
8typedef struct {
9 float value;
10} Mass;
11
12int main(int argc, char *argv[]) {
14
15
19
20
22 .entity =
ecs_id(Position),
23 .members = {
26 }
27 });
28
30 .entity =
ecs_id(Velocity),
31 .members = {
34 }
35 });
36
39 .members = {
41 }
42 });
43
48
49 ecs_set(ecs, a, Position, {10, 20});
50 ecs_set(ecs, b, Position, {20, 30});
51 ecs_set(ecs, c, Position, {30, 40});
52 ecs_set(ecs, d, Position, {40, 50});
53
54 ecs_set(ecs, a, Velocity, {1, 2});
55 ecs_set(ecs, b, Velocity, {2, 3});
56 ecs_set(ecs, c, Velocity, {3, 4});
57 ecs_set(ecs, d, Velocity, {4, 5});
58
61
62
64 .terms = {
66 }
67 });
68
69
72 printf("%s\n", json);
73 ecs_os_free(json);
74
75
76
77
78
79
80
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
125}
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.
Queries are lists of constraints (terms) that match entities.