1#include <hierarchy.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position;
7
8
10
12
15 printf("%s [%s]\n", path_str, type_str);
16 ecs_os_free(type_str);
17 ecs_os_free(path_str);
18
19
20 const Position *ptr =
ecs_get(ecs, e, Position);
21
22
23 Position p_actual = {ptr->x + p_parent.x, ptr->y + p_parent.y};
24 printf("{%f, %f}\n\n", p_actual.x, p_actual.y);
25
26
29 for (
int i = 0; i < it.
count; i ++) {
30 iterate_tree(ecs, it.
entities[i], p_actual);
31 }
32 }
33}
34
35int main(int argc, char *argv[]) {
37
42
43
44
45
46
49 ecs_set(ecs, sun, Position, {1, 1});
50
53 ecs_set(ecs, mercury, Position, {1, 1});
54
57 ecs_set(ecs, venus, Position, {2, 2});
58
61 ecs_set(ecs, earth, Position, {3, 3});
62
65 ecs_set(ecs, moon, Position, {0.1, 0.1});
66
67
69
70
73 printf("Moon found: %s\n\n", path);
74 ecs_os_free(path);
75
76
77 iterate_tree(ecs, sun, (Position){0, 0});
78
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100}
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.
bool ecs_children_next(ecs_iter_t *it)
Progress an iterator created with ecs_children().
ecs_iter_t ecs_children(const ecs_world_t *world, ecs_entity_t parent)
Iterate children of a parent.
const ecs_type_t * ecs_get_type(const ecs_world_t *world, ecs_entity_t entity)
Get the type of an entity.
char * ecs_type_str(const ecs_world_t *world, const ecs_type_t *type)
Convert a type to a string.
#define ecs_add(world, entity, T)
Add a component to an entity.
#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_TAG(world, id)
Declare and define a tag.
#define ECS_COMPONENT_DECLARE(id)
Forward declare a component.
#define ecs_get_path(world, child)
Get path from root.
#define ecs_set(world, entity, component,...)
Set a component value.
#define ecs_get(world, entity, T)
Get a component.
#define ecs_has_pair(world, entity, first, second)
Test if an entity has a pair.
ecs_entity_t ecs_lookup(const ecs_world_t *world, const char *path)
Look up an entity by its path.
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.