1#include <sync_point_delete.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position, Velocity;
7
10 const Velocity *v =
ecs_field(it,
const Velocity, 1);
11
12 for (
int i = 0; i < it->
count; i ++) {
13 p[i].x += v[i].x;
14 p[i].y += v[i].y;
15 }
16}
17
19 const Position *p =
ecs_field(it, Position, 0);
20
21 for (
int i = 0; i < it->
count; i ++) {
22 if (p[i].x >= 3) {
24 printf(
"Delete entity %s\n",
ecs_get_name(it->stage, e));
26 }
27 }
28}
29
31 const Position *p =
ecs_field(it,
const Position, 0);
32
33 for (
int i = 0; i < it->
count; i ++) {
35 p[i].x, p[i].y);
36 }
37}
38
39int main(int argc, char *argv[]) {
41
42
43
44
45
46
47
48
49
50
51
52
53
54
57
58
60
61
62
63
64
65
67
68
70
71
73 ecs_set(ecs, e1, Position, {0, 0});
74 ecs_set(ecs, e1, Velocity, {1, 2});
75
77 ecs_set(ecs, e2, Position, {1, 2});
78 ecs_set(ecs, e2, Velocity, {1, 2});
79
80
84 break;
85 }
86 }
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
136}
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.
void ecs_delete(ecs_world_t *world, ecs_entity_t entity)
Delete 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_set(world, entity, component,...)
Set a component value.
#define ecs_count(world, type)
Count entities with a component.
#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.