1#include <cpp_traits.h>
2#include <iostream>
3
4
5
6
7struct Position {
8 static constexpr bool dont_fragment = true;
9 double x, y;
10};
11
12
13
14
15
16struct Velocity {
17 static constexpr bool sparse = true;
18 double x, y;
19};
20
21
22
23
24struct Mass {
25 static constexpr auto on_instantiate = flecs::on_instantiate::inherit;
26 double value;
27};
28
29int main(int, char *[]) {
31
32
34 std::cout << "Position has DontFragment: "
35 << pos.has(flecs::DontFragment) << "\n";
36
38 std::cout << "Velocity has Sparse: "
39 << vel.has(flecs::Sparse) << "\n";
40
41
44 std::cout << "MySpaceship owns Mass: " << inst.owns<Mass>() << "\n";
45 std::cout << "MySpaceship mass: " << inst.get<Mass>().value << "\n";
46
47 inst.set<Position>({10, 20});
48
49
50
51
52 inst.set<Velocity>({1, 2});
53 std::cout << "MySpaceship velocity: {"
54 << inst.get<Velocity>().x << ", " << inst.get<Velocity>().y << "}\n";
55
56
57
58
60
62 std::cout << e.
name() <<
": {" << p.x <<
", " << p.y <<
"}" <<
"\n";
63 });
64
65
66
67
69 std::cout << e.
name() <<
": {" << p.x <<
", " << p.y <<
"}" <<
"\n";
70 });
71
72
73
74
75
76
77
78
79
80}
flecs::component< T > component(Args &&... args) const
Find or register a component.
conditional_t< sizeof...(Args)==0 &&_::is_sparse_query< Comps... >::value, flecs::sparse_query< Comps... >, flecs::query< Comps... > > query(Args &&... args) const
Create a query.
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::entity prefab(const char *name=nullptr) const
Create a prefab that's associated with a type.
const Self & is_a(entity_t second) const
Shortcut for add(IsA, entity).
flecs::string_view name() const
Return the entity name.
Query that iterates sparse component storages directly.
void each(Func &&func) const
Iterate the query.
on_instantiate
OnInstantiate policies that can be assigned to a component at compile time with the flecs::on_instant...