-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainer.cpp
More file actions
131 lines (101 loc) · 2.39 KB
/
Container.cpp
File metadata and controls
131 lines (101 loc) · 2.39 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "Container.h"
#include "InputComponent.h"
#include "PhysicsComponent.h"
#include "GraphicsComponent.h"
#include "Messages_defs.h"
Container::Container() :
Container(nullptr) {
}
Container::Container(SDLGame* game) :
GameObject(game), ic_(), pc_(), gc_() {
}
Container::~Container() {
}
void Container::handleInput(Uint32 time) {
for (auto ic : ic_) {
if (ic.active && isActive())
ic.data->handleInput(this, time);
}
}
void Container::update(Uint32 time) {
for (auto pc : pc_) {
if (pc.active && isActive())
pc.data->update(this, time);
}
}
void Container::render(Uint32 time) {
for (auto gc : gc_) {
if (gc.active && isActive())
gc.data->render(this, time);
}
}
void Container::addC(InputComponent* ic) {
addC(ic_, ic);
}
void Container::addC(PhysicsComponent* pc) {
addC(pc_, pc);
}
void Container::addC(GraphicsComponent* gc) {
addC(gc_, gc);
}
void Container::addOC(Component* oc) {
addC(oc_, oc);
}
bool Container::hasC(InputComponent* ic) {
return hasC(ic_, ic);
}
bool Container::hasOC(Component* oc) {
return hasC(oc_, oc);
}
bool Container::hasC(PhysicsComponent* pc) {
return hasC(pc_, pc);
}
bool Container::hasC(GraphicsComponent* gc) {
return hasC(gc_, gc);
}
void Container::removeC(InputComponent* ic) {
removeC(ic_, ic);
}
void Container::removeC(PhysicsComponent* pc) {
removeC(pc_, pc);
}
void Container::removeC(GraphicsComponent* gc) {
removeC(gc_, gc);
}
void Container::removeOC(Component* oc) {
removeC(oc_, oc);
}
void Container::receive(const void* senderObj, const msg::Message& msg) {
broadcastToLocalComponents(senderObj, msg);
}
void Container::broadcastToLocalComponents(
const void* senderObj, const msg::Message& msg) {
for (auto ic : ic_) {
if (ic.data != senderObj && ic.active)
ic.data->receive(this, msg);
}
for (auto pc : pc_) {
if (pc.data != senderObj && pc.active)
pc.data->receive(this, msg);
}
for (auto gc : gc_) {
if (gc.data != senderObj && gc.active)
gc.data->receive(this, msg);
}
for (auto oc : oc_) {
if (oc.data != senderObj && oc.active)
oc.data->receive(this, msg);
}
}
void Container::localSend(const void* senderObj, const msg::Message& msg) {
broadcastToLocalComponents(senderObj, msg);
}
void Container::globalSend(const void* senderObj, const msg::Message& msg) {
getGame()->send(senderObj,msg);
}
void Container::reset() {
ic_.clear();
pc_.clear();
gc_.clear();
oc_.clear();
}