-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsymbols.cpp
152 lines (132 loc) · 4.08 KB
/
symbols.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "symbols.h"
#include "fxhelper.h"
// application icon
#include "csicon.data"
// small multipurpose symbols
#include "symbols/symbols.data"
// 16x16 symbols for toolbar
#include "symbols/toolbar.data"
// 64x64 terrain symbols for map
#include "terrain.data"
// 16x16 symbols for terrain and factions in regionlist
#include "symbols.data"
#include "bullets/bullets.data"
// other data
#include "infodlg.data"
#include "infodlg.e3.data"
#include "terrain.h"
#include <string>
#include <climits>
namespace data
{
const unsigned int infodlg_data_size = sizeof(infodlg_data);
const unsigned int infodlg_data_e3_size = sizeof(infodlg_data_e3);
struct {
const char* filename;
const unsigned char* image;
} terrains[data::TERRAIN_LAST] = {
{ "undefined.gif", undefined },
{ "ocean.gif", ocean },
{ "swamp.gif", swamp },
{ "plains.gif", plains },
{ "desert.gif", desert },
{ "forest.gif", forest },
{ "highland.gif", highland },
{ "mountain.gif", mountain },
{ "glacier.gif", glacier },
{ "volcano.gif", volcano },
{ "activevolcano.gif", activevolcano },
{ "packice.gif", packice },
{ "iceberg.gif", iceberg },
{ "icefloe.gif", icefloe },
{ "corridor.gif", corridor },
{ "wall.gif", wall },
{ "hall.gif", undefined },
{ "fog.gif", undefined },
{ "thickfog.gif", undefined },
{ "firewall.gif", firewall },
{ "mahlstrom.gif", mahlstrom },
};
const unsigned char* terrainSymbols[data::TERRAIN_LAST] =
{
sym_undefined,
sym_ocean,
sym_swamp,
sym_plains,
sym_desert,
sym_forest,
sym_highland,
sym_mountain,
sym_glacier,
sym_volcano,
sym_volcano,
sym_iceberg,
sym_iceberg,
sym_iceberg,
sym_corridor,
sym_wall,
sym_hall,
sym_fog,
sym_thickfog,
sym_firewall,
sym_mahlstrom
};
class Textures {
private:
struct TextureData {
std::string str;
const unsigned char* bitmap;
} data;
static Textures* instance;
TextureData m_terrains[data::TERRAIN_LAST];
TextureData m_icons[data::TERRAIN_LAST];
public:
static Textures* get() {
if (!instance) {
instance = new Textures();
}
return instance;
}
static std::string loadTexture(const char* folder, const char* name)
{
std::string filename(folder);
filename += '/';
filename += name;
return loadResourceFile(filename.c_str());
}
const unsigned char* getTerrainIcon(int i) {
if (m_icons[i].bitmap == nullptr) {
m_icons[i].str = Textures::loadTexture("terrain/icons", terrains[i].filename);
if (m_icons[i].str.empty())
{
m_icons[i].bitmap = terrainSymbols[i];
}
else {
m_icons[i].bitmap = (const unsigned char*)m_icons[i].str.c_str();
}
}
return m_icons[i].bitmap;
}
const unsigned char *getTerrainData(int i) {
if (m_terrains[i].bitmap == nullptr) {
m_terrains[i].str = Textures::loadTexture("terrain", terrains[i].filename);
if (m_terrains[i].str.empty())
{
// give up, don't try loading again. hack: cast, but never free this!
m_terrains[i].bitmap = terrains[i].image;
}
else {
m_terrains[i].bitmap = (const unsigned char*)m_terrains[i].str.c_str();
}
}
return m_terrains[i].bitmap;
}
};
Textures* Textures::instance;
const unsigned char* terrain_data(int i) {
return Textures::get()->getTerrainData(i);
}
const unsigned char* terrain_icon(int i) {
return Textures::get()->getTerrainIcon(i);
}
}