-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathContentLoader.h
195 lines (172 loc) · 6.7 KB
/
ContentLoader.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#pragma once
#define NOMINMAX
#include <filesystem>
#include <algorithm>
#include <optional>
#include "tinyxml.h"
#include "BuildingConfiguration.h"
#include "CreatureConfiguration.h"
#include "VegetationConfiguration.h"
#include "GroundMaterialConfiguration.h"
#include "ColorConfiguration.h"
#include "commonTypes.h"
#include "FluidConfiguration.h"
#include "ItemConfiguration.h"
#include "common.h"
namespace df {
struct world_raws;
}
class ContentLoader
{
private:
bool parseContentIndexFile(std::filesystem::path filepath );
bool parseContentXMLFile( std::filesystem::path filepath );
bool parseBuildingContent( TiXmlElement* elemRoot );
bool parseCreatureContent( TiXmlElement* elemRoot );
bool parseTerrainContent ( TiXmlElement* elemRoot );
bool parseGrowthContent(TiXmlElement* elemRoot);
bool parseTreeContent( TiXmlElement* elemRoot );
bool parseShrubContent( TiXmlElement* elemRoot );
bool parseColorContent( TiXmlElement* elemRoot );
bool parseFluidContent( TiXmlElement* elemRoot );
bool parseGrassContent( TiXmlElement* elemRoot );
bool parseItemContent( TiXmlElement* elemRoot );
void flushCreatureConfig();
bool translationComplete = false;
void gatherStyleIndices(df::world_raws * raws);
public:
ContentLoader(void);
~ContentLoader(void);
bool Load();
bool reload_configs();
std::vector<std::unique_ptr<BuildingConfiguration>> buildingConfigs;
std::vector<std::unique_ptr<std::vector<CreatureConfiguration>>> creatureConfigs;
std::vector<std::unique_ptr<VegetationConfiguration>> treeConfigs;
std::vector<std::unique_ptr<VegetationConfiguration>> shrubConfigs;
std::vector<std::unique_ptr<VegetationConfiguration>> grassConfigs;
std::vector<std::unique_ptr<TerrainConfiguration>> terrainFloorConfigs;
std::vector<std::unique_ptr<TerrainConfiguration>> terrainWallConfigs;
std::vector<ColorConfiguration> colorConfigs;
MaterialMatcher<ALLEGRO_COLOR> materialColorConfigs;
MaterialMatcher<c_sprite> growthTopConfigs;
MaterialMatcher<c_sprite> growthBottomConfigs;
std::vector<std::unique_ptr<ItemConfiguration>> itemConfigs;
FluidConfiguration lava[8];
FluidConfiguration water[8];
class StyleIndices {
struct Key
{
int32_t race;
int32_t caste;
int32_t style_type;
bool operator==(const Key&) const = default;
};
struct Hash
{
std::size_t operator()(const Key& k) const noexcept
{
return size_t(k.race) ^ (size_t(k.caste) << 15) ^ (size_t(k.style_type) << 30);
}
};
SparseArray<Key, int32_t, Hash> map;
public:
void clear() {
map.clear();
}
void add(int32_t race, int32_t caste, int32_t type, int32_t id)
{
map.add({ race,caste,type }, id);
}
int32_t lookup(int32_t race, int32_t caste, int32_t style_type)
{
auto res = map.lookup({ race,caste,style_type });
return res ? *res : -1;
}
};
class PositionIndices
{
struct Key
{
int32_t entity_id;
int32_t pos_id;
bool operator==(const Key&) const = default;
};
struct Hash
{
std::size_t operator()(const Key& k) const noexcept
{
return size_t(k.entity_id) ^ (size_t(k.pos_id) << 31);
}
};
SparseArray<Key, int32_t, Hash> map;
public:
void clear() {
map.clear();
}
void add(int32_t entity_id, int32_t pos_id, int32_t id)
{
map.add({ entity_id, pos_id }, id);
}
int32_t lookup(int32_t entity_id, int32_t pos_id)
{
auto res = map.lookup({ entity_id, pos_id });
return res ? *res : -1;
}
};
StyleIndices style_indices;
PositionIndices position_Indices;
std::vector<std::string> professionStrings;
std::map <uint32_t, std::string> custom_workshop_types;
DFHack::Materials* Mats = nullptr;
std::vector<DFHack::t_matgloss> organic;
std::vector<DFHack::t_matglossInorganic> inorganic;
uint32_t currentTick = 0;
uint32_t currentYear = 0;
uint8_t currentMonth = 0;
uint8_t currentDay = 0;
uint8_t currentHour = 0;
uint8_t currentTickRel = 0;
DFHack::t_gamemodes gameMode{
df::game_mode::NONE,
df::game_type::NONE
};
int obsidian = 0;
};
extern const char* getDocument(TiXmlNode* element);
std::filesystem::path getLocalFilename(std::filesystem::path filename, std::filesystem::path relativeto);
extern void contentError(const std::string& message, TiXmlNode* element);
extern void contentWarning(const std::string& message, TiXmlNode* element);
extern char getAnimFrames(const char* framestring);
extern int loadConfigImgFile(std::filesystem::path filename, TiXmlElement* referrer);
extern int loadImgFromXML(TiXmlElement* elemRoot);
MAT_BASICS lookupMaterialType(const char* strValue);
int lookupMaterialIndex(int matType, const char* strValue);
template <typename T, typename Index = decltype(T::id)>
int lookupIndexedType(const Index& indexName, const std::vector<T>& typeVector)
{
auto get_id = [](auto tv) {
if constexpr (std::is_pointer_v<T>) return tv->id;
else return tv.id;
};
auto it = std::find_if(typeVector.begin(), typeVector.end(),
[&](auto tv) -> bool { return get_id(tv) == indexName; });
return it != typeVector.end() ? it - typeVector.begin() : INVALID_INDEX;
}
template <typename T, typename Index = decltype(T::id)>
int lookupIndexedPointerType(const Index& indexName, const std::vector<T*>& typeVector)
{
return lookupIndexedType<T*, Index>(indexName, typeVector);
}
const char *lookupMaterialTypeName(int matType);
const char *lookupMaterialName(int matType,int matIndex);
const char *lookupBuildingSubtype(int main_type, int i);
uint8_t lookupMaterialFore(int matType,int matIndex);
uint8_t lookupMaterialBack(int matType,int matIndex);
uint8_t lookupMaterialBright(int matType,int matIndex);
const char *lookupTreeName(int matIndex);
ALLEGRO_COLOR lookupMaterialColor(DFHack::t_matglossPair matt, DFHack::t_matglossPair dyematt, ALLEGRO_COLOR defaultColor=al_map_rgb(255,255,255));
ALLEGRO_COLOR lookupMaterialColor(DFHack::t_matglossPair matt, ALLEGRO_COLOR defaultColor=al_map_rgb(255,255,255));
ALLEGRO_COLOR lookupMaterialColor(int matType, int matIndex, int dyeType, int dyeIndex, ALLEGRO_COLOR defaultColor=al_map_rgb(255,255,255));
ALLEGRO_COLOR lookupMaterialColor(int matType, int matIndex, ALLEGRO_COLOR defaultColor=al_map_rgb(255,255,255));
const char * lookupFormName(int formType);
ShadeBy getShadeType(const char* Input);