-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceManager.cpp
More file actions
40 lines (33 loc) · 1.05 KB
/
ResourceManager.cpp
File metadata and controls
40 lines (33 loc) · 1.05 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
#include "ResourceManager.hpp"
sf::Texture& ResourceManager::getTexture(const std::string& filename)
{
// Check if already defined
auto it = textures.find(filename);
if (it != textures.end()) {
return *(it->second);
}
// load new texture
std::unique_ptr<sf::Texture> texture = std::make_unique<sf::Texture>();
if (!texture->loadFromFile(filename)) {
throw std::runtime_error("Failed to load texture: " + filename);
}
sf::Texture& texRef = *texture;
textures[filename] = std::move(texture);
return texRef;
}
sf::Font& ResourceManager::getFont(const std::string& filename)
{
// Check if already defined
auto it = fonts.find(filename);
if (it != fonts.end()) {
return *(it->second);
}
// load new font
std::unique_ptr<sf::Font> font = std::make_unique<sf::Font>();
if (!font->openFromFile(filename)) {
throw std::runtime_error("Failed to load font: " + filename);
}
sf::Font& fontRef = *font;
fonts[filename] = std::move(font);
return fontRef;
}