-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameObjectManager.cpp
50 lines (38 loc) · 1.33 KB
/
GameObjectManager.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
#include "GameObjectManager.h"
GameObjectManager::GameObjectManager() {
}
GameObjectManager::~GameObjectManager() {
std::for_each(m_container.begin(), m_container.end(), deallocator());
}
void GameObjectManager::add(std::string name, VisibleGameObject* object) {
m_container.insert(std::pair<std::string, VisibleGameObject*>(name, object));
}
void GameObjectManager::remove(std::string name) {
std::map<std::string, VisibleGameObject*>::iterator result = m_container.find(name);
if (result != m_container.end()) {
delete result->second;
m_container.erase(result);
}
}
VisibleGameObject* GameObjectManager::get_object(std::string name) {
std::map<std::string, VisibleGameObject*>::const_iterator result = m_container.find(name);
if (result == m_container.end()) {
return NULL;
} else {
return result->second;
}
}
void GameObjectManager::update_all() {
std::map<std::string, VisibleGameObject*>::const_iterator itr = m_container.begin();
while (itr != m_container.end()) {
itr->second->update();
itr++;
}
}
void GameObjectManager::draw_all(sf::RenderWindow& window) {
std::map<std::string, VisibleGameObject*>::const_iterator itr = m_container.begin();
while (itr != m_container.end()) {
itr->second->draw(window);
itr++;
}
}