-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameObjectFactory.h
50 lines (37 loc) · 1.54 KB
/
GameObjectFactory.h
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
#ifndef GAMEOBJECTFACTORY_H
#define GAMEOBJECTFACTORY_H
#include <string>
#include <map>
#include <iostream>
#include "GameObject.h"
using namespace std;
class BaseCreator
{
public:
virtual GameObject* createGameObject() const = 0;
virtual ~BaseCreator() {}
};
class GameObjectFactory
{
public:
//Constructors //////////////////////
static GameObjectFactory* Instance() //////////////////////
{ //////////////////////
if(s_pInstance == 0) //////// SINGLETON ////
{ //////////////////////
s_pInstance = new GameObjectFactory(); //////////////////////
} //////////////////////
//////////////////////
return s_pInstance; //////////////////////
}
bool registerType(string typeID, BaseCreator* pCreator); //add types to the map
GameObject* create(string typeID); //creates a GameObject.
protected:
private:
map<string, BaseCreator*> m_creators; //saves all kind of basecreators
GameObjectFactory(){}; //now is a SINGLETON
~GameObjectFactory();
static GameObjectFactory* s_pInstance; // Now in GOD-MODE SINGLETON
};
typedef GameObjectFactory TheGameObjectFactory;//Owned SINGLETON
#endif // GAMEOBJECTFACTORY_H