-
Notifications
You must be signed in to change notification settings - Fork 54
/
main.cpp
39 lines (31 loc) · 975 Bytes
/
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
#include <UECS/UECS.hpp>
#include <iostream>
using namespace Ubpa::UECS;
struct Timer {
float dt{ 0.f };
};
struct Position { float val{ 1.f }; };
struct Velocity { float val{ 1.f }; };
struct MoverSystem {
static void OnUpdate(Schedule& schedule) {
schedule.RegisterJob([](Singleton<Timer> timer) {
timer->dt = 0.03f;
}, "Timer");
schedule.RegisterEntityJob([](const Velocity* v, Position* p, Latest<Singleton<Timer>> timer) {
p->val += timer->dt * v->val;
}, "Mover");
schedule.RegisterEntityJob([](const Position* p) {
std::cout << p->val << std::endl;
}, "Print");
}
};
int main() {
World w;
w.entityMngr.cmptTraits.Register<Timer, Position, Velocity>();
w.systemMngr.RegisterAndActivate<MoverSystem>();
w.entityMngr.Create(Ubpa::TypeIDs_of<Position, Velocity>);
w.entityMngr.Create(Ubpa::TypeIDs_of<Timer>);
w.Update();
std::cout << w.DumpUpdateJobGraph() << std::endl;
std::cout << w.GenUpdateFrameGraph().Dump() << std::endl;
}