1#include <run_callback.h>
2#include <stdio.h>
3
4
5
6
7
8
9
10
11typedef struct {
12 double x, y;
13} Position, Velocity;
14
16 printf("Move begin\n");
17
18
19
21
23 const Velocity *v =
ecs_field(it, Velocity, 1);
24
25 for (
int i = 0; i < it->
count; i ++) {
26 p[i].x += v[i].x;
27 p[i].y += v[i].y;
29 p[i].x, p[i].y);
30 }
31 }
32
33 printf("Move end\n");
34}
35
36int main(int argc, char *argv[]) {
38
41
42
44 .query.terms = {
45 { .id =
ecs_id(Position) },
47 },
48 .run = Move
49 });
50
51
53 ecs_set(ecs, e1, Position, {10, 20});
54 ecs_set(ecs, e1, Velocity, {1, 2});
55
57 ecs_set(ecs, e2, Position, {10, 20});
58 ecs_set(ecs, e2, Velocity, {3, 4});
59
60
62 ecs_set(ecs, e3, Position, {10, 20});
63
64
66
68
69
70
71
72
73
74}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
#define ecs_system(world,...)
Shorthand for creating a system with ecs_system_init().
FLECS_API ecs_entity_t ecs_run(ecs_world_t *world, ecs_entity_t system, ecs_ftime_t delta_time, void *param)
Run a specific system manually.
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(world, id)
Declare and define 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.
bool ecs_query_next(ecs_iter_t *it)
Progress a query iterator.
@ EcsIn
Term is only read.
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.