-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResourceManager.h
45 lines (37 loc) · 1.08 KB
/
ResourceManager.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
/*
* ResourceManager.h
*
* Created on: 23 janv. 2012
* Author: greg
*/
#ifndef RESOURCEMANAGER_H_
#define RESOURCEMANAGER_H_
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include <map>
#include <memory>
namespace game {
typedef std::map<std::string, std::unique_ptr<sf::Texture>> TextureMap;
class ResourceManager {
public:
static sf::Texture *getTexture(const std::string filename) {
static TextureMap textures;
std::cout << "getTexture called " << filename << std::endl;
TextureMap::iterator it = textures.find(filename);
if (it == textures.end()) {
std::unique_ptr<sf::Texture> temp(new sf::Texture);
if (temp->loadFromFile(filename)) {
textures.emplace(filename, std::move(temp));
return textures[filename].get();
} else {
std::cout << "could not load texture" << std::endl;
}
} else {
return it->second.get();
}
return nullptr;
}
};
} /* namespace game */
#endif /* RESOURCEMANAGER_H_ */