-
-
Notifications
You must be signed in to change notification settings - Fork 586
Expand file tree
/
Copy pathmain.cpp
More file actions
103 lines (81 loc) · 2.46 KB
/
main.cpp
File metadata and controls
103 lines (81 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <enum_reflection_no_meta.h>
#include <iostream>
// Test if enum reflection works without the meta addon
enum Color {
Red, Green, Blue
};
int main(int argc, char *argv[]) {
flecs::world world(argc, argv);
flecs::entity c = world.component<Color>();
if (!world.is_alive(flecs::Constant)) {
std::cout << "Constant tag is not alive\n";
return -1;
}
{
flecs::entity constant = c.lookup("Red");
if (!constant) {
std::cout << "Constant not found\n";
return -1;
}
using U = std::underlying_type<Color>::type;
if (!constant.has(flecs::Constant, world.id<U>())) {
std::cout << "Constant pair not found on constant\n";
return -1;
}
const U *v = constant.get_second<U>(flecs::Constant);
if (*v != Red) {
std::cout << "Constant has wrong value\n";
return -1;
}
}
{
flecs::entity constant = c.lookup("Green");
if (!constant) {
std::cout << "Constant not found\n";
return -1;
}
using U = std::underlying_type<Color>::type;
if (!constant.has(flecs::Constant, world.id<U>())) {
std::cout << "Constant pair not found on constant\n";
return -1;
}
const U *v = constant.get_second<U>(flecs::Constant);
if (*v != Green) {
std::cout << "Constant has wrong value\n";
return -1;
}
}
{
flecs::entity constant = c.lookup("Blue");
if (!constant) {
std::cout << "Constant not found\n";
return -1;
}
using U = std::underlying_type<Color>::type;
if (!constant.has(flecs::Constant, world.id<U>())) {
std::cout << "Constant pair not found on constant\n";
return -1;
}
const U *v = constant.get_second<U>(flecs::Constant);
if (*v != Blue) {
std::cout << "Constant has wrong value\n";
return -1;
}
}
flecs::entity e = world.entity();
e.add(Color::Red);
if (!e.has(Color::Red)) {
std::cout << "Entity doesn't have Color::Red\n";
return -1;
}
e.add(Color::Green);
if (!e.has(Color::Green)) {
std::cout << "Entity doesn't have Color::Green\n";
return -1;
}
if (e.has(Color::Red)) {
std::cout << "Entity has Color::Red\n";
return -1;
}
return 0;
}