1#include <sync_point.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position, Velocity;
7
8
11
13 for (
int i = 0; i < it->
count; i ++) {
15 }
16}
17
20 const Velocity *v =
ecs_field(it,
const Velocity, 1);
21
22 for (
int i = 0; i < it->
count; i ++) {
23 p[i].x += v[i].x;
24 p[i].y += v[i].y;
25 }
26}
27
29 const Position *p =
ecs_field(it,
const Position, 0);
30
31 for (
int i = 0; i < it->
count; i ++) {
33 p[i].x, p[i].y);
34 }
35}
36
37int main(int argc, char *argv[]) {
39
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
62
63
65
66
68
69
71 ecs_set(ecs, e1, Position, {10, 20});
72 ecs_set(ecs, e1, Velocity, {1, 2});
73
75 ecs_set(ecs, e2, Position, {10, 20});
76 ecs_set(ecs, e2, Velocity, {3, 4});
77
78
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
121}
FLECS_API int ecs_log_set_level(int level)
Enable or disable log.
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_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.