-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentFile.cpp
More file actions
62 lines (47 loc) · 1.96 KB
/
ContentFile.cpp
File metadata and controls
62 lines (47 loc) · 1.96 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "ContentFile.h"
#include "RTEError.h"
namespace RTE {
const std::string ContentFile::m_ClassName = "ContentFile";
std::unordered_map<std::string, BITMAP *> ContentFile::m_LoadedBitmaps;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int ContentFile::Create(const char *filePath) {
m_DataPath = filePath;
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int ContentFile::Create(const ContentFile &reference) {
m_DataPath = reference.m_DataPath;
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ContentFile::FreeAllLoaded() {
for (const std::pair<std::string, BITMAP *> &loadedBitmap : m_LoadedBitmaps) {
destroy_bitmap(loadedBitmap.second);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BITMAP * ContentFile::GetAsBitmap(int conversionMode) {
if (m_DataPath.empty()) {
return nullptr;
}
BITMAP *returnBitmap = nullptr;
std::unordered_map<std::string, BITMAP *>::iterator foundBitmap = m_LoadedBitmaps.find(m_DataPath);
if (foundBitmap != m_LoadedBitmaps.end()) {
returnBitmap = (*foundBitmap).second;
} else {
returnBitmap = LoadAndReleaseBitmap(conversionMode);
m_LoadedBitmaps.insert({ m_DataPath, returnBitmap });
}
return returnBitmap;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BITMAP * ContentFile::LoadAndReleaseBitmap(int conversionMode) {
if (m_DataPath.empty()) {
return nullptr;
}
set_color_conversion(conversionMode == 0 ? COLORCONV_MOST : conversionMode);
PALETTE currentPalette;
get_palette(currentPalette);
return load_bmp(m_DataPath.c_str(), currentPalette);
}
}