-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameEntityManager.cpp
70 lines (56 loc) · 1.65 KB
/
gameEntityManager.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
/*
* gameEntityManager.cpp
*
* Created on: Dec 29, 2015
* Author: alexander
*/
#include "gameEntityManager.hpp"
std::map<std::string, gameEntity*> gameEntityManager::_gameObjects;
gameEntityManager::gameEntityManager(){
}
gameEntityManager::~gameEntityManager(){
std::for_each(_gameObjects.begin(),_gameObjects.end(),gameEntityDeallocator());
}
void gameEntityManager::addEntity(std::string name, gameEntity* entity){
_gameObjects.insert(std::pair<std::string,gameEntity*>(name, entity));
}
void gameEntityManager::removeEntity(std::string name){
std::map<std::string, gameEntity*>::iterator results = _gameObjects.find(name);
if(results != _gameObjects.end() ){
delete results->second;
_gameObjects.erase(results);
}
}
int gameEntityManager::getEntityCount(){
return _gameObjects.size();
}
gameEntity* gameEntityManager::getEntity(std::string name){
std::map<std::string, gameEntity*>::const_iterator results = _gameObjects.find(name);
}
void gameEntityManager::onRender(sf::RenderWindow& mainWindow){
if(!_gameObjects.empty()){
std::map<std::string,gameEntity*>::const_iterator itr = _gameObjects.begin();
while(itr != _gameObjects.end()){
itr->second->onRender(mainWindow);
itr++;
}
}
}
void gameEntityManager::onLoop(){
if(!_gameObjects.empty()){
std::map<std::string,gameEntity*>::const_iterator itr = _gameObjects.begin();
while(itr != _gameObjects.end()){
itr->second->onLoop();
itr++;
}
}
}
void gameEntityManager::onCleanup(){
if(!_gameObjects.empty()){
std::map<std::string,gameEntity*>::const_iterator itr = _gameObjects.begin();
while(itr != _gameObjects.end()){
itr->second->onCleanup();
itr++;
}
}
}