-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameObjectFactory.cpp
More file actions
43 lines (37 loc) · 927 Bytes
/
Copy pathGameObjectFactory.cpp
File metadata and controls
43 lines (37 loc) · 927 Bytes
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
#include "GameObjectFactory.h"
GameObjectFactory* GameObjectFactory::s_instance = 0;
GameObjectFactory* GameObjectFactory::Instance()
{
if (s_instance == 0)
{
s_instance = new GameObjectFactory();
}
return s_instance;
}
GameObjectFactory::GameObjectFactory()
{
}
bool GameObjectFactory::RegisterType(std::string typeID, BaseCreator* pCreator)
{
std::map<std::string, BaseCreator*>::iterator it = m_creators.find(typeID);
// if the type is already registered, do nothing
if (it != m_creators.end())
{
delete pCreator;
return false;
}
m_creators[typeID] = pCreator;
return true;
}
GameObject* GameObjectFactory::Create(std::string typeID)
{
std::map<std::string, BaseCreator*>::iterator it =
m_creators.find(typeID);
if (it == m_creators.end())
{
std::cout << "could not find type: " << typeID << "\n";
return NULL;
}
BaseCreator* pCreator = (*it).second;
return pCreator->CreateGameObject();
}