-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitmapStore.cpp
More file actions
43 lines (36 loc) · 1016 Bytes
/
Copy pathBitmapStore.cpp
File metadata and controls
43 lines (36 loc) · 1016 Bytes
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
#include "BitmapStore.h"
#include <map>
#include <stdexcept>
using namespace std;
using namespace sf;
namespace
{
std::map<std::string, sf::Texture>& textures()
{
static std::map<std::string, sf::Texture> loaded;
return loaded;
}
}
void BitmapStore::clear()
{
textures().clear();
}
const sf::Texture& BitmapStore::getBitmap(const std::string& filename)
{
auto& loaded = textures();
auto found = loaded.find(filename);
if (found != loaded.end())
{
return found->second;
}
auto& texture = loaded[filename];
if (!texture.loadFromFile(filename))
{
// Erase before throwing: leaving an empty texture in the map would let
// a later call succeed with a 0x0 image, and StandardGraphicsComponent
// divides the object size by the texture size to compute a scale.
loaded.erase(filename);
throw std::runtime_error("BitmapStore::getBitmap - could not load \"" + filename + "\"");
}
return texture;
}