Skip to content

Commit 616ee90

Browse files
Merge branch 'DFHack:master' into squid-keybinds-update
2 parents a47e642 + 5838a5e commit 616ee90

32 files changed

+895
-1343
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ allegro_deps-msvc2015-x64-1.2.0.zip
1111
allegro_deps
1212
allegro_deps-msvc2015-x86-1.2.0.zip
1313
allegro-msvc2015-x86-5.1.12.zip
14+
win64/allegro-msvc-x64-5.2.10.7z
15+
win64/allegro_deps-msvc-x64-1.15.0.7z

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
args: ['--fix=lf']
2020
- id: trailing-whitespace
2121
- repo: https://github.com/python-jsonschema/check-jsonschema
22-
rev: 0.30.0
22+
rev: 0.31.0
2323
hooks:
2424
- id: check-github-workflows
2525
- repo: https://github.com/Lucas-C/pre-commit-hooks

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ SET(PROJECT_SRCS
3636
WorldSegment.cpp
3737
VegetationConfiguration.cpp
3838
Keybinds.cpp
39-
EnumToString.cpp
4039
MaterialMatcher.cpp
4140
main.cpp
4241
)
@@ -55,7 +54,6 @@ SET(PROJECT_HDRS
5554
CreatureConfiguration.h
5655
Creatures.h
5756
DumpInfo.h
58-
EnumToString.h
5957
FluidConfiguration.h
6058
GameBuildings.h
6159
GroundMaterialConfiguration.h
@@ -148,7 +146,7 @@ IF(UNIX)
148146
set(ALLEGRO_DOWNLOAD_FILE "linux64-allegro5210.tbz2")
149147
download_file("https://github.com/DFHack/dfhack-bin/releases/download/50.15/linux64-allegro5210.tbz2"
150148
"${ALLEGRO_DOWNLOAD_DIR}/${ALLEGRO_DOWNLOAD_FILE}"
151-
"17d5f7dd89eb624b005b7b9202b94aff")
149+
"14c4237fbe6f2abf26edc0ba4d6c4424")
152150
else()
153151
MESSAGE(FATAL_ERROR "32 bit build not supported for stonesense")
154152
endif()

Config.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <iostream>
22
#include <fstream>
33
#include <string>
4+
#include <filesystem>
45
#include "common.h"
56
#include "commonTypes.h"
67
#include "Config.h"
@@ -299,7 +300,7 @@ namespace {
299300
}
300301
if (line.find("[FONT") != string::npos) {
301302
string result = parseStrFromLine("FONT", line);
302-
ssConfig.font = al_create_path(result.c_str());
303+
ssConfig.font = std::filesystem::path{ result }.make_preferred();
303304
}
304305
if (line.find("[USE_DF_COLORS") != string::npos) {
305306
string result = parseStrFromLine("USE_DF_COLORS", line);
@@ -806,12 +807,10 @@ namespace {
806807
bool loadConfigFile()
807808
{
808809
string line;
809-
ALLEGRO_PATH * p =al_create_path("dfhack-config/stonesense/init.txt");
810-
const char * path = al_path_cstr(p,ALLEGRO_NATIVE_PATH_SEP);
810+
auto path = std::filesystem::path{} / "dfhack-config" / "stonesense" / "init.txt";
811811
std::ifstream myfile(path);
812812
if (myfile.is_open() == false) {
813813
LogError( "cannot find init file\n" );
814-
al_destroy_path(p);
815814
return false;
816815
}
817816

@@ -823,6 +822,5 @@ bool loadConfigFile()
823822
ssConfig.colors.update();
824823
//close file, etc.
825824
myfile.close();
826-
al_destroy_path(p);
827825
return true;
828826
}

Constructions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void changeConstructionMaterials(WorldSegment* segment, vector<df::construction>
3333
* Reads an unbuilt construction's tle type to the given block and converts the
3434
* material to "CONSTRUCTION".
3535
*/
36-
bool readConstructionsToTile( Tile* b, const Buildings::t_building* building )
36+
bool readConstructionsToTile( Tile* b, const Stonesense_Building* building )
3737
{
3838
if(building->type == df::building_type::Construction) {
3939
df::tiletype constructedTiletype = df::tiletype::Void;

Constructions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#include "df/construction.h"
44

55
void changeConstructionMaterials(WorldSegment* segment, std::vector<df::construction>* allConstructions);
6-
bool readConstructionsToTile( Tile* b, const DFHack::Buildings::t_building* building );
6+
bool readConstructionsToTile( Tile* b, const Stonesense_Building* building );

ContentBuildingReader.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,15 @@ bool includeFile(SpriteNode* node, TiXmlElement* includeNode, SpriteTile* &oldSi
208208
std::filesystem::path documentRef = getDocument(includeNode);
209209

210210
std::filesystem::path configfilepath = getLocalFilename(includeNode->Attribute("file"), documentRef);
211-
ALLEGRO_PATH * incpath = al_create_path(configfilepath.string().c_str());
212-
al_append_path_component(incpath, "include");
213-
TiXmlDocument doc( al_path_cstr(incpath, ALLEGRO_NATIVE_PATH_SEP) );
214-
al_destroy_path(incpath);
211+
std::filesystem::path incpath = configfilepath.remove_filename() / "include" / configfilepath.filename();
212+
TiXmlDocument doc( incpath.string().c_str() );
215213
bool loadOkay = doc.LoadFile();
216214
TiXmlHandle hDoc(&doc);
217215
TiXmlElement* elemParent;
218216
if(!loadOkay) {
219217
contentError("Include failed",includeNode);
220-
LogError("File load failed: %s\n", configfilepath.string().c_str());
221-
LogError("Line %d: %s\n",doc.ErrorRow(),doc.ErrorDesc());
218+
LogError("File load failed: %s\n", incpath.string().c_str());
219+
LogError("Line %d: %s\n",doc.ErrorRow(),doc.ErrorDesc() ? doc.ErrorDesc() : "(null)");
222220
return false;
223221
}
224222
elemParent = hDoc.FirstChildElement("include").Element();

ContentLoader.cpp

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "df/world.h"
3131
#include "df/world_raws.h"
3232

33-
#include "EnumToString.h"
34-
3533
using namespace DFHack;
3634
using namespace df::enums;
3735

@@ -210,9 +208,8 @@ bool ContentLoader::Load()
210208
contentLoader->obsidian = lookupMaterialIndex(INORGANIC, "OBSIDIAN");
211209

212210
loadGraphicsFromDisk(); //these get destroyed when flushImgFiles is called.
213-
ALLEGRO_PATH * p = al_create_path("stonesense/index.txt");
214-
bool overallResult = parseContentIndexFile( al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP) );
215-
al_destroy_path(p);
211+
std::filesystem::path p{ "stonesense" };
212+
bool overallResult = parseContentIndexFile( p / "index.txt");
216213
translationComplete = false;
217214

218215
return overallResult;
@@ -235,33 +232,15 @@ bool ContentLoader::reload_configs()
235232
flushImgFiles();
236233

237234
loadGraphicsFromDisk(); //these get destroyed when flushImgFiles is called.
238-
ALLEGRO_PATH * p = al_create_path("stonesense/index.txt");
239-
bool overallResult = parseContentIndexFile( al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP) );
240-
al_destroy_path(p);
235+
std::filesystem::path p = std::filesystem::path{} / "stonesense" / "index.txt";
236+
bool overallResult = parseContentIndexFile( p );
241237

242238
return overallResult;
243239
}
244240

245-
// takes a filename and the file referring to it, and makes a combined filename in
246-
// HTML style: (ie "/something" is relative to the stonesense root, everything
247-
// else is relative to the referrer)
248-
// buffer must be FILENAME_BUFFERSIZE chars
249-
// returns true if it all works
250-
251-
std::filesystem::path getLocalFilename(const char* filename, std::filesystem::path relativeto)
241+
std::filesystem::path getLocalFilename(std::filesystem::path filename, std::filesystem::path relativeto)
252242
{
253-
// TODO verify that this does not leak
254-
ALLEGRO_PATH* temppath;
255-
if (filename[0] == '/' || filename[0] == '\\') {
256-
temppath = al_create_path(filename);
257-
al_make_path_canonical(temppath);
258-
}
259-
else {
260-
temppath = al_create_path(relativeto.string().c_str());
261-
al_join_paths(temppath, al_create_path(filename));
262-
al_make_path_canonical(temppath);
263-
}
264-
return std::string{ al_path_cstr(temppath, ALLEGRO_NATIVE_PATH_SEP) };
243+
return relativeto.remove_filename() / filename;
265244
}
266245

267246
bool ContentLoader::parseContentIndexFile( std::filesystem::path filepath )
@@ -313,16 +292,14 @@ bool ContentLoader::parseContentIndexFile( std::filesystem::path filepath )
313292
continue;
314293
}
315294

316-
std::filesystem::path configfilepath = getLocalFilename(line.c_str(), filepath);
317-
ALLEGRO_PATH * temppath = al_create_path(configfilepath.string().c_str());
318-
const char* extension;
319-
extension = al_get_path_extension(temppath);
320-
if (strcmp(extension,".xml") == 0) {
295+
std::filesystem::path configfilepath = filepath.remove_filename() / std::filesystem::path{ line }.make_preferred();
296+
auto extension = configfilepath.extension();
297+
if (extension == ".xml") {
321298
LogVerbose("Reading xml %s...\n", configfilepath.string().c_str());
322299
if (!parseContentXMLFile(configfilepath)) {
323300
LogError("Failure in reading %s\n",configfilepath.string().c_str());
324301
}
325-
} else if (strcmp(extension,".txt") == 0) {
302+
} else if (extension == ".txt") {
326303
LogVerbose("Reading index %s...\n", configfilepath.string().c_str());
327304
if (!parseContentIndexFile(configfilepath)) {
328305
LogError("Failure in reading %s\n",configfilepath.string().c_str());
@@ -468,13 +445,19 @@ const char* getDocument(TiXmlNode* element)
468445
return parent->Value();
469446
}
470447

471-
void contentError(const char* message, TiXmlNode* element)
448+
void contentError(const string& message, TiXmlNode* element)
472449
{
473-
LogError("%s: %s: %s (Line %d)\n",getDocument(element),message,element->Value(),element->Row());
450+
auto safeStr = [](const char* s)->const char* {return s ? s : "(unknown)"; };
451+
452+
LogError("%s: %s: %s (Line %d)\n",
453+
safeStr(getDocument(element)),
454+
message.c_str(),
455+
element ? safeStr(element->Value()) : "(no element)",
456+
element ? element->Row() : -1);
474457
}
475-
void contentWarning(const char* message, TiXmlNode* element)
458+
void contentWarning(const string& message, TiXmlNode* element)
476459
{
477-
LogVerbose("%s: %s: %s (Line %d)\n",getDocument(element),message,element->Value(),element->Row());
460+
LogVerbose("%s: %s: %s (Line %d)\n",getDocument(element),message.c_str(),element->Value(),element->Row());
478461
}
479462
// converts list of characters 0-5 into bits, ignoring garbage
480463
// eg "035" or "0 3 5" or "0xx3x5" are all good
@@ -697,11 +680,11 @@ uint8_t lookupMaterialBright(int matType,int matIndex)
697680
return 0;
698681
}
699682

700-
int loadConfigImgFile(const char* filename, TiXmlElement* referrer)
683+
int loadConfigImgFile(std::filesystem::path filename, TiXmlElement* referrer)
701684
{
702685
std::filesystem::path documentRef = getDocument(referrer);
703686
std::filesystem::path configfilepath = getLocalFilename(filename, documentRef);
704-
return loadImgFile(configfilepath.string().c_str());
687+
return loadImgFile(configfilepath);
705688
}
706689

707690
void ContentLoader::flushCreatureConfig()

ContentLoader.h

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,41 +86,31 @@ class ContentLoader
8686
extern ContentLoader * contentLoader;
8787

8888
extern const char* getDocument(TiXmlNode* element);
89-
std::filesystem::path getLocalFilename(const char* filename, std::filesystem::path relativeto);
90-
extern void contentError(const char* message, TiXmlNode* element);
91-
extern void contentWarning(const char* message, TiXmlNode* element);
89+
std::filesystem::path getLocalFilename(std::filesystem::path filename, std::filesystem::path relativeto);
90+
extern void contentError(const std::string& message, TiXmlNode* element);
91+
extern void contentWarning(const std::string& message, TiXmlNode* element);
9292
extern char getAnimFrames(const char* framestring);
93-
extern int loadConfigImgFile(const char* filename, TiXmlElement* referrer);
93+
extern int loadConfigImgFile(std::filesystem::path filename, TiXmlElement* referrer);
9494
MAT_BASICS lookupMaterialType(const char* strValue);
9595
int lookupMaterialIndex(int matType, const char* strValue);
96-
template <typename T>
97-
int lookupIndexedType(const char* indexName, std::vector<T>& typeVector)
96+
97+
template <typename T, typename Index = decltype(T::id)>
98+
int lookupIndexedType(const Index& indexName, const std::vector<T>& typeVector)
9899
{
99-
if (indexName == NULL || indexName[0] == 0) {
100-
return INVALID_INDEX;
101-
}
102-
uint32_t vsize = (uint32_t)typeVector.size();
103-
for(uint32_t i=0; i < vsize; i++) {
104-
if (typeVector[i].id == indexName) {
105-
return i;
106-
}
107-
}
108-
return INVALID_INDEX;
100+
auto get_id = [](auto tv) {
101+
if constexpr (std::is_pointer_v<T>) return tv->id;
102+
else return tv.id;
103+
};
104+
auto it = std::find_if(typeVector.begin(), typeVector.end(),
105+
[&](auto tv) -> bool { return get_id(tv) == indexName; });
106+
return it != typeVector.end() ? it - typeVector.begin() : INVALID_INDEX;
109107
}
110-
template <typename T>
111-
int lookupIndexedPonterType(const char* indexName, std::vector<T*>& typeVector)
108+
template <typename T, typename Index = decltype(T::id)>
109+
int lookupIndexedPointerType(const Index& indexName, const std::vector<T*>& typeVector)
112110
{
113-
if (indexName == NULL || indexName[0] == 0) {
114-
return INVALID_INDEX;
115-
}
116-
uint32_t vsize = (uint32_t)typeVector.size();
117-
for(uint32_t i=0; i < vsize; i++) {
118-
if (typeVector[i]->id == indexName) {
119-
return i;
120-
}
121-
}
122-
return INVALID_INDEX;
111+
return lookupIndexedType<T*, Index>(indexName, typeVector);
123112
}
113+
124114
const char *lookupMaterialTypeName(int matType);
125115
const char *lookupMaterialName(int matType,int matIndex);
126116
const char *lookupBuildingSubtype(int main_type, int i);

EnumToString.cpp

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)