-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
59 lines (49 loc) · 1.31 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
#include <iostream>
#include <entity_handlers/entity_manager.hpp>
#include <mpl/has_member.hpp>
struct foo {
int i = 10;
int id = 0;
void update() { i += 20; }
void draw(std::ostream& dc) const { dc<<"foo: "<<id<<"value: "<<i<<'\n'; }
bool is_alive() const {
if (i > 100) std::cout<<"foo: "<<id<<" died! at:"<<i<<'\n';
return i < 100;
}
};
struct bar {
std::string s = "I'M AN OBJECT!";
bar() = default;
bar(std::string str): s{std::move(str)} { }
void update() { }
void draw(std::ostream& dc) const { dc<<s<<'\n'; }
bool is_alive() const { return false; } // die instantly
};
struct foobar {
void update() { }
void draw(std::ostream& dc){ dc<<"foobar!\n"; }
bool is_alive() const { return true; }
template <typename T>
void draw(T&) const { }
};
int main() {
game_utils::entity_manager<foo, bar, foobar> mgr;
mgr.create<foo>();
mgr.create<foo>();
mgr.get_all<foo>().back().i = 50; // set the last one
mgr.get_all<foo>().back().id = 1; // set the last one
mgr.create<bar>();
mgr.create<bar>("something awesome");
mgr.create<foobar>();
mgr.for_each_in_group<foo>(
[](auto& e) {
std::cout<<std::boolalpha<<e.is_alive()<<'\n';
}
);
// emulate 20 frames
for (int i = 0;i != 20;++i) {
mgr.update();
mgr.draw(std::cout);
mgr.refresh();
}
}