- Backend update.

This commit is contained in:
Christoph Oelckers 2020-10-16 23:25:18 +02:00
parent ef7a7cc39d
commit 65c52b9825
8 changed files with 89 additions and 6 deletions

View file

@ -1536,6 +1536,7 @@ int SoundEngine::AddSoundLump(const char* logicalname, int lump, int CurrentPitc
newsfx.PitchMask = CurrentPitchMask; newsfx.PitchMask = CurrentPitchMask;
newsfx.NearLimit = nearlimit; newsfx.NearLimit = nearlimit;
newsfx.ResourceId = resid; newsfx.ResourceId = resid;
newsfx.bTentative = false;
if (resid >= 0) ResIdMap[resid] = S_sfx.Size() - 1; if (resid >= 0) ResIdMap[resid] = S_sfx.Size() - 1;
return (int)S_sfx.Size()-1; return (int)S_sfx.Size()-1;

View file

@ -125,6 +125,12 @@ public:
return Serialize(*this, key, obj, save_full? nullptr : &def); return Serialize(*this, key, obj, save_full? nullptr : &def);
} }
template<class T>
FSerializer& operator()(const char* key, T& obj, T* def)
{
return Serialize(*this, key, obj, !def || save_full ? nullptr : def);
}
template<class T> template<class T>
FSerializer &Array(const char *key, T *obj, int count, bool fullcompare = false) FSerializer &Array(const char *key, T *obj, int count, bool fullcompare = false)
{ {
@ -172,6 +178,29 @@ public:
return *this; return *this;
} }
template<class T, class Map>
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<class T> template<class T>
FSerializer &Enum(const char *key, T &obj) FSerializer &Enum(const char *key, T &obj)
{ {

View file

@ -1446,7 +1446,7 @@ const char *FileSystem::GetResourceFileName (int rfnum) const noexcept
name = Files[rfnum]->FileName; name = Files[rfnum]->FileName;
slash = strrchr (name, '/'); slash = strrchr (name, '/');
return slash != NULL ? slash+1 : name; return (slash != NULL && slash[1] != 0) ? slash+1 : name;
} }
//========================================================================== //==========================================================================

View file

@ -57,6 +57,11 @@ FImageTexture::FImageTexture(FImageSource *img) noexcept
} }
} }
FImageTexture::~FImageTexture()
{
delete mImage;
}
void FImageTexture::SetFromImage() void FImageTexture::SetFromImage()
{ {
auto img = mImage; auto img = mImage;

View file

@ -357,6 +357,7 @@ protected:
void SetFromImage(); void SetFromImage();
public: public:
FImageTexture(FImageSource* image) noexcept; FImageTexture(FImageSource* image) noexcept;
~FImageTexture();
TArray<uint8_t> Get8BitPixels(bool alphatex) override; TArray<uint8_t> Get8BitPixels(bool alphatex) override;
void SetImage(FImageSource* img) void SetImage(FImageSource* img)

View file

@ -31,7 +31,7 @@
**--------------------------------------------------------------------------- **---------------------------------------------------------------------------
** **
*/ */
#pragma once
#include <zlib.h> #include <zlib.h>
#include <stdint.h> #include <stdint.h>

View file

@ -42,6 +42,7 @@
#include <unistd.h> #include <unistd.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <sys/stat.h>
#include "cmdlib.h" #include "cmdlib.h"
@ -203,6 +204,52 @@ bool D_AddFile(TArray<FString>& wadfiles, const char* file, bool check, int posi
{ {
return false; 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)) if (check && !DirEntryExists(file))
{ {

View file

@ -136,11 +136,11 @@ const T MAX (const T a, const T b)
// Clamps in to the range [min,max]. // Clamps in to the range [min,max].
//========================================================================== //==========================================================================
template<class T> template<typename T, typename X, typename Y>
inline inline constexpr
T clamp (const T in, const T min, const T max) 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__ #endif //__TEMPLATES_H__