-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextureManager.cpp
61 lines (48 loc) · 1.27 KB
/
TextureManager.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
#include "inc.h"
TextureManager* TextureManager::tmInstance = nullptr;
std::map<std::string, Texture*> TextureManager::Textures;
TextureManager::TextureManager() {
}
TextureManager::~TextureManager() {
Close("all");
}
void TextureManager::Initialize(const char * path) {
std::string temp = path;
std::string fileName = temp.substr(temp.find_last_of("/") + 1, temp.size());
Textures[fileName] = new Texture(path);
}
TextureManager* TextureManager::Instance() {
if (tmInstance == nullptr) {
tmInstance = new TextureManager();
tmInstance->loadTextures();
}
return tmInstance;
}
void TextureManager::Close(std::string fileName) {
for (auto t : Textures) {
if (t.first == fileName) {
delete t.second;
Textures.erase(fileName);
}
if (fileName == "all") {
delete t.second;
}
}
if (fileName == "all") {
Textures.clear();
}
}
Texture * TextureManager::getTexture(const char * fileName) {
if (Textures.find(fileName) == Textures.end()) {
return nullptr;
} else {
return Textures[fileName];
}
}
void TextureManager::loadTextures() {
Initialize("Data/bullet.png");
Initialize("Data/avatar.jpg");
Initialize("Data/en1.png");
Initialize("Data/Scope1.png");
Initialize("Data/Floor.png");
}