forked from Themaister/Granite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecs_test.cpp
56 lines (48 loc) · 1.05 KB
/
ecs_test.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
#include "ecs.hpp"
#include "logging.hpp"
using namespace Granite;
using namespace std;
struct AComponent : ComponentBase
{
GRANITE_COMPONENT_TYPE_DECL(AComponent)
AComponent(int v_)
: v(v_)
{
}
int v;
};
struct BComponent : ComponentBase
{
GRANITE_COMPONENT_TYPE_DECL(BComponent)
BComponent(int v_)
: v(v_)
{
}
int v;
};
struct CComponent : ComponentBase
{
GRANITE_COMPONENT_TYPE_DECL(CComponent)
CComponent(int v_)
: v(v_)
{
}
int v;
};
int main()
{
EntityPool pool;
auto a = pool.create_entity();
a->allocate_component<AComponent>(10);
a->allocate_component<BComponent>(20);
auto &group_ab = pool.get_component_group<AComponent, BComponent>();
auto &group_ba = pool.get_component_group<BComponent, AComponent>();
auto &group_bc = pool.get_component_group<BComponent, CComponent>();
a->allocate_component<AComponent>(40);
for (auto &e : group_ab)
LOGI("AB: %d, %d\n", get<0>(e)->v, get<1>(e)->v);
for (auto &e : group_ba)
LOGI("BA: %d, %d\n", get<0>(e)->v, get<1>(e)->v);
for (auto &e : group_bc)
LOGI("BC: %d\n", get<0>(e)->v);
}