-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
86 lines (76 loc) · 2.68 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <UECS/World.h>
using namespace Ubpa;
using namespace Ubpa::UECS;
struct Translation { float value{ 0.f }; };
struct LocalToParent { float value{ 0.f }; };
struct LocalToWorld { float value{ 0.f }; };
struct Children { std::vector<Entity> value; };
struct Parent { Entity value; };
struct TranslationSystem {
static void SetTreeL2W(World* w, const Entity& entity, const LocalToWorld* l2w) {
if(!w->entityMngr.Have<LocalToParent>(entity) || !w->entityMngr.Have<LocalToWorld>(entity))
return;
auto* el2p = w->entityMngr.Get<LocalToParent>(entity);
auto* el2w = w->entityMngr.Get<LocalToWorld>(entity);
el2w->value = l2w->value + el2p->value;
if(w->entityMngr.Have<Children>(entity)) {
auto* children = w->entityMngr.Get<Children>(entity);
for (const auto& child : children->value)
SetTreeL2W(w, child, el2w);
}
}
static void OnUpdate(Schedule& schedule) {
{
ArchetypeFilter filter;
filter.all.insert(TypeID_of<Parent>);
schedule.RegisterEntityJob([](LocalToParent* l2p, const Translation* t) {
l2p->value = t->value;
}, "T2LocalToParent", true, filter);
}
{
ArchetypeFilter filter;
filter.none.insert(TypeID_of<Parent>);
schedule.RegisterEntityJob([](LocalToWorld* l2w, const Translation* t) {
l2w->value = t->value;
}, "T2LocalToWorld", true, filter);
}
{
ArchetypeFilter filter;
RandomAccessor randomAccessor;
randomAccessor.types = {
AccessTypeID_of<Write<LocalToWorld>>,
AccessTypeID_of<Latest<LocalToParent>>,
AccessTypeID_of<Latest<Children>>
};
filter.none.insert(TypeID_of<Parent>);
schedule.RegisterEntityJob([](World* w, Children* children, const LocalToWorld* l2w) {
for(const auto& child : children->value)
SetTreeL2W(w, child, l2w);
}, "LocalToWorld", true, filter, {}, {}, randomAccessor);
}
{
schedule.RegisterEntityJob([](const LocalToWorld* l2w) {
std::cout << l2w->value << std::endl;
}, "PrintL2W");
}
schedule.Order("T2LocalToWorld", "LocalToWorld");
}
};
int main() {
World w;
w.entityMngr.cmptTraits.Register<Translation, LocalToWorld, LocalToParent, Children, Parent>();
w.systemMngr.RegisterAndActivate<TranslationSystem>();
auto [e1, c, t1, l2w1] = w.entityMngr.Create<Children, Translation, LocalToWorld>();
auto [e2, p2, t2, l2p2, l2w2] = w.entityMngr.Create<Parent, Translation, LocalToParent, LocalToWorld>();
auto [e3, p3, t3, l2p3, l2w3] = w.entityMngr.Create<Parent, Translation, LocalToParent, LocalToWorld>();
c->value = { e2, e3 };
p2->value = e1;
p3->value = e1;
t1->value = 1.f;
t2->value = 2.f;
t3->value = 3.f;
w.Update();
std::cout << w.GenUpdateFrameGraph().Dump() << std::endl;
std::cout << w.DumpUpdateJobGraph() << std::endl;
return 0;
}