-
Notifications
You must be signed in to change notification settings - Fork 54
/
main.cpp
55 lines (45 loc) · 1.12 KB
/
main.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
#include <UECS/UECS.hpp>
#include <iostream>
using namespace Ubpa::UECS;
using namespace std;
struct Data { std::size_t value; };
struct MySystem {
static void OnUpdate(Schedule& schedule) {
auto buffer = std::make_shared<std::vector<std::size_t>>();
auto f = schedule.RegisterEntityJob(
[buffer](std::size_t idxInQuery, const Data* data) {
buffer->at(idxInQuery) = data->value;
},
"use"
);
schedule.RegisterJob([buffer]() {
std::size_t sum = 0;
for (std::size_t i : *buffer)
sum += i;
cout << sum << endl;
},
"print"
);
schedule.RegisterJob(
[buffer, f](World* w) {
std::size_t num = w->entityMngr.EntityNum(f->entityQuery);
buffer->resize(num);
},
"allocate"
);
schedule.Order("allocate", "use");
schedule.Order("use", "print");
}
};
int main() {
World w;
w.entityMngr.cmptTraits.Register<Data>();
w.systemMngr.RegisterAndActivate<MySystem>();
for (std::size_t i = 1; i <= 100; i++) {
auto e = w.entityMngr.Create(Ubpa::TypeIDs_of<Data>);
w.entityMngr.WriteComponent<Data>(e)->value = i;
}
w.Update();
cout << w.DumpUpdateJobGraph() << endl;
return 0;
}