-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.cpp
57 lines (44 loc) · 1.21 KB
/
example.cpp
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
#define LAMECS_INFO_ENABLED
#include "lamecs.hpp"
struct pos
{
int x, y, z;
};
struct vel
{
int dx, dy, dz;
};
int main()
{
lamecs::registry registry;
auto e1 = registry.create_entity();
auto e2 = registry.create_entity();
auto e3 = registry.create_entity();
// you dont have to do this since components are registered during .emplace()
registry.register_component<pos>();
registry.emplace<pos>(e1, {0, 0, 0});
registry.emplace<pos>(e2, {0, 0, 1});
registry.emplace<vel>(e1, {1, 0, 0});
registry.emplace<vel>(e2, {0, 1, 1});
registry.emplace<vel>(e3, {0, 1, 3});
// remove component from entity
registry.remove<vel>(e2);
registry.remove_entity(e3);
// access and modify specific components of an entity
auto [p, v] = registry.get_entity<pos, vel>(e1);
// callback style iterating
registry.each<vel>([®istry](lamecs::entity_id id, vel& v)
{
//...
});
registry.each<vel, pos>([®istry](vel& v, pos& p)
{
//...
});
// you can also create "views" to access entities with specific components
for(auto& [id, pos, vel] : registry.view<pos, vel>())
{
//...
}
return 0;
}