-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAGE_AboutDialog.h
78 lines (66 loc) · 2.14 KB
/
AGE_AboutDialog.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include "Common.h"
class AGE_AboutDialog: public wxDialog
{
public:
AGE_AboutDialog(wxWindow *parent, const wxFont &font);
static const wxString AGE_VER;
};
namespace GG
{
void LoadPalettes(vector<vector<genie::Color>> &palettes, const string &path);
string LoadSound(wxArrayString &folders, const string &filename, int resnum);
std::shared_ptr<unsigned char[]> LoadSound(vector<genie::DrsFile*> &datafiles, int resnum);
genie::SlpFilePtr LoadSLP(genie::DrsFile &pack, int resnum);
genie::SlpFilePtr LoadSLP(const string &filename);
genie::SmpFilePtr LoadSMP(const string &filename);
extern size_t cache_depth;
template <typename key_t, typename value_t>
class LRU_SLP
{
public:
typedef pair<key_t, value_t> pair_t;
typedef typename list<pair_t>::iterator lit_t;
// Handle least recently used cache here.
void put(const key_t &key, const value_t &slp)
{
// Put key as first item.
auto it = slp_cache_map.find(key);
slp_cache_list.push_front(pair_t(key, slp));
if(it != slp_cache_map.end())
{
slp_cache_list.erase(it->second);
//slp_cache_map.erase(it); // Why is this needed?
}
slp_cache_map[key] = slp_cache_list.begin();
// Unload from end excess items.
if(slp_cache_map.size() > cache_depth)
{
auto last = --(slp_cache_list.end());
// Remember to unload before popping.
last->second->unload();
slp_cache_map.erase(last->first);
slp_cache_list.pop_back();
}
}
value_t use(const key_t &key)
{
auto it = slp_cache_map.find(key);
if(it == slp_cache_map.end())
{
return {};
}
else
{
slp_cache_list.splice(slp_cache_list.begin(), slp_cache_list, it->second);
return it->second->second;
}
}
private:
list<pair_t> slp_cache_list;
unordered_map<key_t, lit_t> slp_cache_map;
};
extern LRU_SLP<int, genie::SlpFilePtr> slp_cache_resnum;
extern LRU_SLP<string, genie::SlpFilePtr> slp_cache_resname;
extern LRU_SLP<string, genie::SmpFilePtr> smp_cache_resname;
}