1#include <prefab.h>
2#include <iostream>
3
4
5
6
7
8struct Attack { double value; };
9struct Defense { double value; };
10struct FreightCapacity { double value; };
11struct ImpulseSpeed { double value; };
12struct HasFTL { };
13
14struct Position { double x = 0; double y = 0; };
15
16int main(int, char *[]) {
18
19
21
22 .set<ImpulseSpeed>({50})
23 .set<Defense>({50})
24
25
26
27
28 .auto_override<Position>();
29
31
32
34 .add<HasFTL>()
35 .set<FreightCapacity>({100})
36 .set<Defense>({100});
37
40 .set<FreightCapacity>({500})
41 .set<Defense>({300});
42
45 .add<HasFTL>()
46 .set<Attack>({100})
47 .set<Defense>({75})
48 .set<ImpulseSpeed>({125});
49
50
51
52
54 .
is_a(mammoth_freighter);
55
56
57
58 std::cout <<
"Instance type: [" << inst.
type().
str() <<
"]\n";
59
60
61
62 const ImpulseSpeed& ptr = inst.get<ImpulseSpeed>();
63 std::cout << "Impulse speed: " << ptr.value << "\n";
64
65
67 p.x += is.value;
68 std::cout << e.
name() <<
": {" << p.x <<
", " << p.y <<
"}\n";
69 });
70}
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::type type() const
Get the entity's type.
flecs::string_view name() const
Return the entity name.
flecs::string str() const
Convert the type to a comma-separated string.