1#include <world_ser_deser.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position, Velocity;
7
10
13 const Velocity *v =
ecs_field(it, Velocity, 1);
14
15 for (
int i = 0; i < it->
count; i ++) {
16 p[i].x += v[i].x;
17 p[i].y += v[i].y;
19 p[i].x, p[i].y);
20 }
21}
22
23
24
27
30
32 .entity =
ecs_id(Position),
33 .members = {
36 }
37 });
38
40 .entity =
ecs_id(Velocity),
41 .members = {
44 }
45 });
46
48}
49
50int main(int argc, char *argv[]) {
53 }
54
57 ecs_set(world_a, ent_1, Position, {10, 20});
58 ecs_set(world_a, ent_2, Position, {30, 40});
59 ecs_set(world_a, ent_1, Velocity, {1, -1});
60 ecs_set(world_a, ent_2, Velocity, {-1, 1});
61
62
64 printf("%s\n\n", json);
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
97 }
98
99
101
102
104 printf("\n");
106
107
108
109
110
111
112
113
116
117 ecs_os_free(json);
118
119 return 0;
120}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
FLECS_API const char * ecs_world_from_json(ecs_world_t *world, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON object with multiple entities into the world.
FLECS_API char * ecs_world_to_json(ecs_world_t *world, const ecs_world_to_json_desc_t *desc)
Serialize world into JSON string.
#define ECS_MODULE(world, id)
Create a module.
#define ECS_IMPORT(world, id)
Wrapper around ecs_import().
FLECS_API bool ecs_progress(ecs_world_t *world, ecs_ftime_t delta_time)
Progress a world.
#define ECS_SYSTEM(world, id, phase,...)
Declare and define a system.
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_entity(world,...)
Shorthand for creating an entity with ecs_entity_init().
#define ECS_COMPONENT_DEFINE(world, id_)
Define a forward-declared component.
#define ECS_COMPONENT_DECLARE(id)
Forward declare a component.
#define ecs_set(world, entity, component,...)
Set a component value.
#define ecs_field(it, T, index)
Get field data for a component.
const char * ecs_get_name(const ecs_world_t *world, ecs_entity_t entity)
Get the name of an entity.
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_world_t * ecs_init(void)
Create a new 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.
const ecs_entity_t * entities
Entity identifiers.