1#include <propagate.h>
2#include <stdio.h>
3
4
5
6
7
8
9
10
11
12
13
14
15typedef struct {
16 double x, y;
17} Position;
18
21
22
24
25
27
28
29 Position *p_self =
ecs_field(it, Position, 0);
30 Position *p_parent =
ecs_field(it, Position, 1);
31
32 for (
int i = 0; i < it->
count; i ++) {
34
35 printf(" - %s: %s: %s: self: {%f, %f}, parent: {%f, %f}\n",
39 p_self[i].x, p_self[i].y,
40 p_parent[i].x, p_parent[i].y);
41 }
42}
43
44int main(int argc, char *argv[]) {
46
48
49
51 .query = { .terms = {
52
53 { .id =
ecs_id(Position) },
54
56 }},
58 .callback = Observer
59 });
60
61
64
65
66
67 ecs_set(ecs, e, Position, {10, 20});
68
69
70
71 ecs_set(ecs, p, Position, {1, 2});
72
74
75
76
77}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
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_observer(world,...)
Shorthand for creating an observer with ecs_observer_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.
#define EcsUp
Match by traversing upwards.
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.
ecs_entity_t event
The event (if applicable).
ecs_id_t event_id
The (component) ID for the event.
int32_t count
Number of entities to iterate.
const ecs_entity_t * entities
Entity identifiers.