1#include <hierarchy.h>
2#include <iostream>
3
4
5struct Transform {
6 double x, y;
7};
8
9
10struct WorldTransform : Transform { };
11struct LocalTransform : Transform { };
12
13int main(int, char *[]) {
15
16
18 .add(flecs::With, ecs.
component<WorldTransform>());
19
20
22 .set(LocalTransform{1, 1});
23
25 .set(LocalTransform{1, 1});
26
28 .set(LocalTransform{2, 2});
29
31 .set(LocalTransform{3, 3});
32
34 .set(LocalTransform{0.1, 0.1});
35
36
37
38
39
40
42 ecs.
query_builder<
const LocalTransform,
const WorldTransform*, WorldTransform>()
43
44
45
46 .term_at(1).parent().cascade()
47
48 .build();
49
50
52 const LocalTransform& t_local,
53 const WorldTransform *t_parent,
54 WorldTransform& t_world)
55 {
56 t_world.x = t_local.x;
57 t_world.y = t_local.y;
58 if (t_parent) {
59 t_world.x += t_parent->x;
60 t_world.y += t_parent->y;
61 }
62 });
63
64
66 std::cout << e.
name() <<
": {" << p.x <<
", " << p.y <<
"}\n";
67 });
68
69
70
71
72
73
74
75}
flecs::component< T > component(Args &&... args) const
Find or register a component.
flecs::query_builder< Comps... > query_builder(Args &&... args) const
Create a query builder.
void each(Func &&func) const
Iterate over all entities with components in the argument list of the function.
flecs::entity entity(Args &&... args) const
Create an entity.
flecs::string_view name() const
Return the entity name.
void each(Func &&func) const
Each iterator.