1#include <parent_hierarchy.h>
2#include <stdio.h>
3
4
5
6
7
8
9
10
11
12
13typedef struct {
14 double x, y;
15} Position;
16
17
19
21
24 printf("%s [%s]\n", path_str, type_str);
25 ecs_os_free(type_str);
26 ecs_os_free(path_str);
27
28
29 const Position *ptr =
ecs_get(world, e, Position);
30
31
32 Position p_actual = {ptr->x + p_parent.x, ptr->y + p_parent.y};
33 printf("{%f, %f}\n\n", p_actual.x, p_actual.y);
34
35
38 for (
int i = 0; i < it.
count; i ++) {
39 iterate_tree(world, it.
entities[i], p_actual);
40 }
41 }
42}
43
44int main(int argc, char *argv[]) {
46
51
52
53
54
55
56
57
58
61 ecs_set(world, sun, Position, {1, 1});
62
64 ecs_add(world, mercury, Planet);
65 ecs_set(world, mercury, Position, {1, 1});
66
69 ecs_set(world, venus, Position, {2, 2});
70
73 ecs_set(world, earth, Position, {3, 3});
74
77 ecs_set(world, moon, Position, {0.1, 0.1});
78
79
81
82
85 printf("Moon found: %s\n\n", path);
86 ecs_os_free(path);
87
88
89 iterate_tree(world, sun, (Position){0, 0});
90
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112}
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.
ecs_entity_t ecs_new_w_parent(ecs_world_t *world, ecs_entity_t parent, const char *name)
Create child with Parent component.
#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.