-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBitmapStore.cpp
64 lines (54 loc) · 1.59 KB
/
BitmapStore.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
64
#include "BitmapStore.h"
#include <assert.h>
using namespace sf;
using namespace std;
BitmapStore* BitmapStore::m_s_Instance = nullptr;
BitmapStore::BitmapStore()
{
assert(m_s_Instance == nullptr);
m_s_Instance = this;
}
void BitmapStore::addBitmap(std::string const& filename)
{
// Get a reference to m_Textures using m_S_Instance
auto& bitmapsMap = m_s_Instance->m_BitmapsMap;
// auto is the equivalent of map<string, Texture>
// Create an iterator to hold a key-value-pair (kvp)
// and search for the required kvp
// using the passed in file name
auto keyValuePair = bitmapsMap.find(filename);
// auto is equivalent of map<string, Texture>::iterator
// No match found so save the texture in the map
if (keyValuePair == bitmapsMap.end())
{
// Create a new key value pair using the filename
auto& texture = bitmapsMap[filename];
// Load the texture from file in the usual way
texture.loadFromFile(filename);
}
}
sf::Texture& BitmapStore::getBitmap(std::string const& filename)
{
// Get a reference to m_Textures using m_S_Instance
auto& m = m_s_Instance->m_BitmapsMap;
// auto is the equivalent of map<string, Texture>
// Create an iterator to hold a key-value-pair (kvp)
// and search for the required kvp
// using the passed in file name
auto keyValuePair = m.find(filename);
// auto is equivalent of map<string, Texture>::iterator
// Did we find a match?
if (keyValuePair != m.end())
{
return keyValuePair->second;
}
else
{
#ifdef debuggingOnConsole
cout <<
"BitmapStore::getBitmap()Texture not found Crrrashh!"
<< endl;
#endif
return keyValuePair->second;
}
}