-
Notifications
You must be signed in to change notification settings - Fork 54
/
main.cpp
70 lines (56 loc) · 1.58 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <UECS/World.h>
#include <iostream>
using namespace Ubpa::UECS;
using namespace Ubpa;
using namespace std;
struct S { float value; };
struct A { float value; };
struct B { float value; };
constexpr float dt = 0.003f;
class SAB_System : public System {
public:
using System::System;
virtual void OnUpdate(Schedule& schedule) override {
ArchetypeFilter filter;
filter.all = { CmptType::Of<Write<S>> };
filter.any = { CmptType::Of<Latest<A>>,CmptType::Of<Latest<B>> };
schedule.RegisterChunkJob([](ChunkView chunk) {
auto arrayS = chunk.GetCmptArray<S>();
auto arrayA = chunk.GetCmptArray<A>();
auto arrayB = chunk.GetCmptArray<B>();
bool containsA = arrayA != nullptr;
bool containsB = arrayB != nullptr;
bool containsAB = containsA && containsB;
if (containsAB) {
cout << "[AB]" << endl;
for (size_t i = 0; i < chunk.EntityNum(); i++) {
arrayS[i].value += arrayA[i].value * arrayB[i].value;
}
}
else if (containsA) {
cout << "[A]" << endl;
for (size_t i = 0; i < chunk.EntityNum(); i++) {
arrayS[i].value += arrayA[i].value;
}
}
else { // containsB
cout << "[B]" << endl;
for (size_t i = 0; i < chunk.EntityNum(); i++) {
arrayS[i].value += arrayB[i].value;
}
}
}, "SAB_System", filter);
}
};
int main() {
World w;
w.systemMngr.Register<SAB_System>();
w.entityMngr.cmptTraits.Register<S, A, B>();
w.entityMngr.Create<S>();
w.entityMngr.Create<S, A>();
w.entityMngr.Create<S, B>();
w.entityMngr.Create<S, A, B>();
w.Update();
cout << w.GenUpdateFrameGraph().Dump() << endl;
return 0;
}