-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcTextureMgr.cpp
More file actions
107 lines (100 loc) · 2.27 KB
/
cTextureMgr.cpp
File metadata and controls
107 lines (100 loc) · 2.27 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
=================
cTextureMgr.cpp
- CPP file for class definition - IMPLEMENTATION
- CPP file for the TextureMgr class
=================
*/
#include "cTextureMgr.h"
cTextureMgr* cTextureMgr::pInstance = NULL;
/*
=================================================================================
Singleton Design Pattern
=================================================================================
*/
cTextureMgr* cTextureMgr::getInstance()
{
if (pInstance == NULL)
{
pInstance = new cTextureMgr();
}
return cTextureMgr::pInstance;
}
/*
=================
- Data constructor initializes the TextureMgr object
- Is always called, thus ensures all TextureMgr objects are in a consistent state.
=================
*/
cTextureMgr::cTextureMgr()
{
}
cTextureMgr::cTextureMgr(SDL_Renderer* theRenderer)
{
theSDLRenderer = theRenderer;
}
/*
=================
- Destructor.
=================
*/
cTextureMgr::~cTextureMgr()
{
deleteTextures();
}
void cTextureMgr::addTexture(LPCSTR txtName, LPCSTR theFilename)
{
if (!getTexture(txtName))
{
cTexture * newTxt = new cTexture();
newTxt->loadTexture(theFilename, theSDLRenderer);
textureList.insert(make_pair(txtName, newTxt));
}
}
void cTextureMgr::addTexture(LPCSTR txtName, SDL_Texture* theTexture)
{
if (!getTexture(txtName))
{
cTexture * newTxt = new cTexture();
newTxt->loadTexture(theTexture);
textureList.insert(make_pair(txtName, newTxt));
}
}
void cTextureMgr::deleteTextures()
{
for (map<LPCSTR, cTexture*>::iterator txt = textureList.begin(); txt != textureList.end(); ++txt)
{
delete txt->second;
}
}
void cTextureMgr::deleteTexture(LPCSTR txtName)
{
map<LPCSTR, cTexture*>::iterator txt = textureList.find(txtName);
this->textureList.erase(txt);
}
/*
=================
- return the texture.
=================
*/
cTexture* cTextureMgr::getTexture(LPCSTR textureName) // return the texture.
{
map<LPCSTR, cTexture*>::iterator txt = textureList.find(textureName);
if (txt != textureList.end())
{
return txt->second;
}
else
{
return NULL;
}
}
/*
=================
- Set the renderer.
=================
*/
void cTextureMgr::setRenderer(SDL_Renderer* ptheRenderer)
{
this->theSDLRenderer = ptheRenderer;
}