-
Notifications
You must be signed in to change notification settings - Fork 1
/
entityfactory.cpp
44 lines (34 loc) · 1002 Bytes
/
entityfactory.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
/*
* entityfactory.cpp
*
* Created on: 2013-07-29
* Author: Liam
*/
#include "entityfactory.h"
#include "entitylist.h"
Entity *EntityFactory::createEntity(const int &id) {
CreatorMap::iterator it = m_creatorMap.find(id);
if (it == m_creatorMap.end())
return NULL;
EntityCreator *pCreator = it->second;
Entity *pEntity = pCreator->create();
g_Entities.add(pEntity);
return pEntity;
}
Entity *EntityFactory::createEntity(const int &id, const vec2d &pos, const vec2d &size, const int &properties) {
CreatorMap::iterator it = m_creatorMap.find(id);
if (it == m_creatorMap.end())
return NULL;
EntityCreator *pCreator = it->second;
Entity *pEntity = pCreator->create(pos, size, properties);
g_Entities.add(pEntity);
return pEntity;
}
bool EntityFactory::registerCreator(int id, EntityCreator *creator) {
CreatorMap::iterator it = m_creatorMap.find(id);
if (it != m_creatorMap.end())
return false;
m_creatorMap[id] = creator;
return true;
}
EntityFactory g_Factory;