-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
51 lines (37 loc) · 1.39 KB
/
test.cpp
File metadata and controls
51 lines (37 loc) · 1.39 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
#include "klecs.h"
#include <iostream>
using namespace klecs;
struct vec3 {
int elements[3];
vec3 operator+(const vec3 &rhs) {
return vec3{.elements = {
elements[0] + rhs.elements[0],
elements[1] + rhs.elements[1],
elements[2] + rhs.elements[2],
}};
}
vec3 &operator+=(const vec3 &rhs) { return *this = *this + rhs; }
};
struct Transform {
vec3 position;
};
struct Rigidbody {
vec3 linear_velocity;
};
int main() {
World world{};
EntityId right =
world.spawn(Transform{.position = {0, 0, 0}}, Rigidbody{.linear_velocity = {1, 0, 0}});
EntityId left =
world.spawn(Transform{.position = {0, 0, 0}}, Rigidbody{.linear_velocity = {-1, 0, 0}});
world.query<Transform &, Rigidbody &>(
[](const EntityId &id, Transform &transform, const Rigidbody &rigidbody) {
transform.position += rigidbody.linear_velocity;
});
const Transform &right_transform = std::get<0>(*world.get<const Transform &>(right));
const Transform &left_transform = std::get<0>(*world.get<const Transform &>(left));
klecs_assert(right_transform.position.elements[0] == 1, "should move one unit right");
klecs_assert(left_transform.position.elements[0] == -1, "should move one unit left");
std::cout << "Tests passed" << std::endl;
return 0;
}