diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index 5509248547..269a491332 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -1536,6 +1536,7 @@ int SoundEngine::AddSoundLump(const char* logicalname, int lump, int CurrentPitc newsfx.PitchMask = CurrentPitchMask; newsfx.NearLimit = nearlimit; newsfx.ResourceId = resid; + newsfx.bTentative = false; if (resid >= 0) ResIdMap[resid] = S_sfx.Size() - 1; return (int)S_sfx.Size()-1; diff --git a/src/common/engine/serializer.h b/src/common/engine/serializer.h index 6110ca4b4b..22f32f73c6 100644 --- a/src/common/engine/serializer.h +++ b/src/common/engine/serializer.h @@ -125,6 +125,12 @@ public: return Serialize(*this, key, obj, save_full? nullptr : &def); } + template + FSerializer& operator()(const char* key, T& obj, T* def) + { + return Serialize(*this, key, obj, !def || save_full ? nullptr : def); + } + template FSerializer &Array(const char *key, T *obj, int count, bool fullcompare = false) { @@ -172,6 +178,29 @@ public: return *this; } + template + FSerializer &SparseArray(const char *key, T *obj, int count, const Map &map, bool fullcompare = false) + { + if (BeginArray(key)) + { + int max = count; + if (isReading()) + { + max = ArraySize(); + } + for (int i = 0; i < count; i++) + { + if (map[i]) + { + Serialize(*this, nullptr, obj[i], (T*)nullptr); + if (--max < 0) break; + } + } + EndArray(); + } + return *this; + } + template FSerializer &Enum(const char *key, T &obj) { diff --git a/src/common/filesystem/filesystem.cpp b/src/common/filesystem/filesystem.cpp index c57b061130..7fd559502c 100644 --- a/src/common/filesystem/filesystem.cpp +++ b/src/common/filesystem/filesystem.cpp @@ -1446,7 +1446,7 @@ const char *FileSystem::GetResourceFileName (int rfnum) const noexcept name = Files[rfnum]->FileName; slash = strrchr (name, '/'); - return slash != NULL ? slash+1 : name; + return (slash != NULL && slash[1] != 0) ? slash+1 : name; } //========================================================================== diff --git a/src/common/textures/imagetexture.cpp b/src/common/textures/imagetexture.cpp index d222733a7e..5ec15c7b59 100644 --- a/src/common/textures/imagetexture.cpp +++ b/src/common/textures/imagetexture.cpp @@ -57,6 +57,11 @@ FImageTexture::FImageTexture(FImageSource *img) noexcept } } +FImageTexture::~FImageTexture() +{ + delete mImage; +} + void FImageTexture::SetFromImage() { auto img = mImage; diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index f8fd763cff..c5a85fd6b2 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -357,6 +357,7 @@ protected: void SetFromImage(); public: FImageTexture(FImageSource* image) noexcept; + ~FImageTexture(); TArray Get8BitPixels(bool alphatex) override; void SetImage(FImageSource* img) diff --git a/src/common/thirdparty/m_crc32.h b/src/common/thirdparty/m_crc32.h index 079bffec4b..2930b8cbdf 100644 --- a/src/common/thirdparty/m_crc32.h +++ b/src/common/thirdparty/m_crc32.h @@ -31,7 +31,7 @@ **--------------------------------------------------------------------------- ** */ - +#pragma once #include #include diff --git a/src/common/utility/findfile.cpp b/src/common/utility/findfile.cpp index 332f0db881..ac0ca8fdfb 100644 --- a/src/common/utility/findfile.cpp +++ b/src/common/utility/findfile.cpp @@ -42,6 +42,7 @@ #include #include +#include #include "cmdlib.h" @@ -203,6 +204,52 @@ bool D_AddFile(TArray& wadfiles, const char* file, bool check, int posi { return false; } +#ifdef __unix__ + // Confirm file exists in filesystem. + struct stat info; + bool found = stat(file, &info) == 0; + if (!found) + { + // File not found, so split file into path and filename so we can enumerate the path for the file. + FString fullpath = file; + auto lastindex = fullpath.LastIndexOf("/"); + FString basepath = fullpath.Left(lastindex); + FString filename = fullpath.Right(fullpath.Len() - lastindex - 1); + + // Proceed only if locating a file (i.e. `file` isn't a path to just a directory.) + if (filename.IsNotEmpty()) + { + DIR *d; + struct dirent *dir; + d = opendir(basepath.GetChars()); + if (d) + { + while ((dir = readdir(d)) != NULL) + { + if (filename.CompareNoCase(dir->d_name) == 0) + { + found = true; + filename = dir->d_name; + fullpath = basepath << "/" << filename; + file = fullpath.GetChars(); + break; + } + } + closedir(d); + if (!found) + { + Printf("Can't find file '%s' in '%s'\n", filename.GetChars(), basepath.GetChars()); + return false; + } + } + else + { + Printf("Can't open directory '%s'\n", basepath.GetChars()); + return false; + } + } + } +#endif if (check && !DirEntryExists(file)) { diff --git a/src/common/utility/templates.h b/src/common/utility/templates.h index 48d306cf8b..3f3e596f0c 100644 --- a/src/common/utility/templates.h +++ b/src/common/utility/templates.h @@ -136,11 +136,11 @@ const T MAX (const T a, const T b) // Clamps in to the range [min,max]. //========================================================================== -template -inline -T clamp (const T in, const T min, const T max) +template +inline constexpr +T clamp (const T in, const X min, const Y max) { - return in <= min ? min : in >= max ? max : in; + return in <= (T) min ? (T) min : in >= (T) max ? (T) max : in; } #endif //__TEMPLATES_H__