-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextureManager.cpp
63 lines (56 loc) · 1.55 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
62
63
#include "TextureManager.hpp"
#include <iostream>
#include <SFML/Graphics/Texture.hpp>
TextureManager::TextureManager() : m_textureList()
{
}
TextureManager::~TextureManager()
{
for(std::map<std::string, sf::Texture*>::iterator it(m_textureList.begin()); it!=m_textureList.end(); it++)
{
delete it->second;
}
m_textureList.clear();
}
inline bool TextureManager::SearchTexture(const std::string& link)
{
std::map<std::string, sf::Texture*>::iterator it;
it=m_textureList.find(link);
if(it==m_textureList.end())
return false;
else
return true;
}
sf::Texture& TextureManager::getTexture(const std::string& link)
{
if(!SearchTexture(link))
{
std::cout<<"load image"<<std::endl;
m_textureList.insert(std::make_pair(link, new sf::Texture));
std::map<std::string, sf::Texture*>::iterator it(m_textureList.find(link));
if(!it->second->loadFromFile(link))
{
std::cerr<<"Failed to load : "<<link<<std::endl;
}
}
return *m_textureList.find(link)->second;
}
bool TextureManager::deleteTexture(const std::string& link)
{
if(SearchTexture(link))
{
std::map<std::string, sf::Texture*>::iterator it(m_textureList.find(link));
delete it->second;
m_textureList.erase(it);
return true;
}
return false;
}
void TextureManager::deleteAll()
{
for(std::map<std::string, sf::Texture*>::iterator it(m_textureList.begin()); it!=m_textureList.end(); it++)
{
delete it->second;
}
m_textureList.clear();
}