From d7e183d46d3d7c14cb4a84d8aff36113902010ea Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 31 Oct 2019 18:06:05 +0100 Subject: [PATCH] - fixed compilation of file system code. --- source/common/filesystem/file_rff.cpp | 5 ++-- source/common/filesystem/file_zip.cpp | 2 +- source/common/filesystem/filesystem.cpp | 31 +++++++++++++---------- source/common/filesystem/filesystem.h | 13 +++++++--- source/common/filesystem/resourcefile.cpp | 13 +++++----- source/common/filesystem/resourcefile.h | 22 ++++++++-------- 6 files changed, 48 insertions(+), 38 deletions(-) diff --git a/source/common/filesystem/file_rff.cpp b/source/common/filesystem/file_rff.cpp index 8c5cbf1d0..b6bc7aef4 100644 --- a/source/common/filesystem/file_rff.cpp +++ b/source/common/filesystem/file_rff.cpp @@ -60,6 +60,7 @@ struct RFFLump uint8_t Flags; char Extension[3]; char Name[8]; + uint32_t ResourceId; }; //========================================================================== @@ -71,7 +72,7 @@ struct RFFLump struct FRFFLump : public FUncompressedLump { virtual FileReader *GetReader(); - int ValidataCache() override; + int ValidateCache() override; uint32_t IndexNum; }; @@ -205,7 +206,7 @@ int FRFFLump::ValidateCache() { int res = FUncompressedLump::ValidateCache(); - if (res && )(Flags & LUMPF_BLOODCRYPT)) + if (res && (Flags & LUMPF_BLOODCRYPT)) { int cryptlen = std::min (LumpSize, 256); uint8_t *data = Cache.Data(); diff --git a/source/common/filesystem/file_zip.cpp b/source/common/filesystem/file_zip.cpp index 19b7569ab..ac807ff09 100644 --- a/source/common/filesystem/file_zip.cpp +++ b/source/common/filesystem/file_zip.cpp @@ -356,7 +356,7 @@ FileReader *FZipLump::GetReader() // //========================================================================== -int FZipLump::ValidataCache() +int FZipLump::ValidateCache() { if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress(); diff --git a/source/common/filesystem/filesystem.cpp b/source/common/filesystem/filesystem.cpp index 9fc559e60..ec24c32d5 100644 --- a/source/common/filesystem/filesystem.cpp +++ b/source/common/filesystem/filesystem.cpp @@ -312,7 +312,7 @@ int FileSystem::FindResource (int resid, const char *type, int filenum) const no FName lname(type, true); if (lname == NAME_None) return -1; - const int lookuptype = (int)ELookupMode::IdWithType + const int lookuptype = (int)ELookupMode::IdWithType; uint32_t* fli = FirstFileIndex[lookuptype]; uint32_t* nli = NextFileIndex[lookuptype]; @@ -337,7 +337,7 @@ int FileSystem::GetResource (int resid, const char *type, int filenum) const { int i; - i = FindResource (resid, type, lookupmode, filenum); + i = FindResource (resid, type, filenum); if (i == -1) { @@ -450,7 +450,7 @@ void FileSystem::AddLump(FResourceLump *lump) hash = int(lump->ResourceId) % NumEntries; } NextFileIndex[l][hash] = FirstFileIndex[l][hash]; - FirstFileIndex[l][hash] = i; + FirstFileIndex[l][hash] = FileInfo.Size() - 1; } } @@ -631,7 +631,7 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray &r TArray FileSystem::GetFileData(int lump, int pad) { if ((size_t)lump >= FileInfo.Size()) - return TArray<(); + return TArray(); auto lumpr = OpenFileReader(lump); auto size = lumpr.GetLength(); @@ -656,22 +656,22 @@ TArray FileSystem::GetFileData(int lump, int pad) const void *FileSystem::Lock(int lump) { if ((size_t)lump >= FileInfo.Size()) return nullptr; - auto lump = FileInfo[lump].lump; - return lump->Lock(); + auto lumpp = FileInfo[lump].lump; + return lumpp->Lock(); } -void FileSystem::Unlock(bool mayfree) +void FileSystem::Unlock(int lump, bool mayfree) { if ((size_t)lump >= FileInfo.Size()) return; - auto lump = FileInfo[lump].lump; - lump->Unlock(maxfree); + auto lumpp = FileInfo[lump].lump; + lumpp->Unlock(mayfree); } const void *FileSystem::Get(int lump) { if ((size_t)lump >= FileInfo.Size()) return nullptr; - auto lump = FileInfo[lump].lump; - return lump->Get(); + auto lumpp = FileInfo[lump].lump; + return lumpp->Get(); } //========================================================================== @@ -680,9 +680,10 @@ const void *FileSystem::Get(int lump) // //========================================================================== -void *FileSystem::Lock(FResourceLump *lump) +const void *FileSystem::Lock(FResourceLump *lump) { if (lump) return lump->Lock(); + else return nullptr; } void FileSystem::Unlock(FResourceLump *lump) @@ -690,9 +691,10 @@ void FileSystem::Unlock(FResourceLump *lump) if (lump) return lump->Unlock(); } -void FileSystem::Load(FResourceLump *lump) +const void *FileSystem::Load(FResourceLump *lump) { if (lump) return lump->Get(); + else return nullptr; } //========================================================================== @@ -890,13 +892,14 @@ FResourceLump *FileSystem::Lookup(const char *name, const char *type) FStringf fname("%s.%s", name, type); auto lump = FindFile(fname); if (lump >= 0) return FileInfo[lump].lump; + else return nullptr; } FResourceLump *FileSystem::Lookup(unsigned int id, const char *type) { auto lump = FindResource(id, type); - auto lump = FindFile(fname); if (lump >= 0) return FileInfo[lump].lump; + else return nullptr; } //========================================================================== diff --git a/source/common/filesystem/filesystem.h b/source/common/filesystem/filesystem.h index f4de4df29..c1cff5dc2 100644 --- a/source/common/filesystem/filesystem.h +++ b/source/common/filesystem/filesystem.h @@ -12,6 +12,10 @@ #include "tarray.h" #include "zstring.h" +#ifdef FindResource +#undef FindResource +#endif + // We do not want to expose the resource file interface here. class FResourceFile; struct FResourceLump; @@ -107,13 +111,13 @@ public: FileData ReadFile (const char *name) { return ReadFile (GetFile (name)); } const void *Lock(int lump); - void Unlock(bool mayfree = false); - void *Get(int lump); + void Unlock(int lump, bool mayfree = false); + const void *Get(int lump); // These are designed to be stand-ins for Blood's resource class. - static void *Lock(FResourceLump *lump); + static const void *Lock(FResourceLump *lump); static void Unlock(FResourceLump *lump); - static void *Load(FResourceLump *lump); + static const void *Load(FResourceLump *lump); static void Read(FResourceLump *lump) { Load(lump); } static void Read(FResourceLump *n, void *p); FResourceLump *Lookup(const char *name, const char *type); @@ -158,6 +162,7 @@ protected: uint32_t NumEntries; // Hash modulus. Can be smaller than NumFiles if things get added at run time. void InitHashChains (); // [RH] Set up the lumpinfo hashing + void AddLump(FResourceLump* lump); private: void DeleteAll(); diff --git a/source/common/filesystem/resourcefile.cpp b/source/common/filesystem/resourcefile.cpp index 984c16384..0c9978f33 100644 --- a/source/common/filesystem/resourcefile.cpp +++ b/source/common/filesystem/resourcefile.cpp @@ -54,13 +54,13 @@ public: FLumpReader(FResourceLump *src) : MemoryReader(NULL, src->LumpSize), source(src) { - src->CacheLump(); - bufptr = (const char*)src->Cache.Data(); + bufptr = (const char*)src->Lock(); + src->Cache.Data(); } ~FLumpReader() { - source->ReleaseCache(); + source->Unlock(true); } }; @@ -154,7 +154,7 @@ void *FResourceLump::Lock() } else if (LumpSize > 0) { - ValidateCache() + ValidateCache(); RefCount++; } return Cache.Data(); @@ -170,7 +170,7 @@ void *FResourceLump::Get() { if (Cache.Size() == 0) { - ValidateCache() + ValidateCache(); } return Cache.Data(); } @@ -181,7 +181,7 @@ void *FResourceLump::Get() // //========================================================================== -int FResourceLump::Unlock(bool mayfree) +void FResourceLump::Unlock(bool mayfree) { if (LumpSize > 0 && RefCount > 0) { @@ -190,7 +190,6 @@ int FResourceLump::Unlock(bool mayfree) if (mayfree) Cache.Reset(); } } - return RefCount; } //========================================================================== diff --git a/source/common/filesystem/resourcefile.h b/source/common/filesystem/resourcefile.h index b76c86cf4..2ca9f6ad2 100644 --- a/source/common/filesystem/resourcefile.h +++ b/source/common/filesystem/resourcefile.h @@ -6,6 +6,7 @@ #include #include "files.h" #include "zstring.h" +#include "name.h" class FResourceFile; class FTexture; @@ -56,6 +57,7 @@ struct FResourceLump }; friend class FResourceFile; + friend struct FClonedLump; unsigned LumpSize = 0; int RefCount = 0; @@ -81,9 +83,9 @@ struct FResourceLump // Wrappers for emulating Blood's resource system unsigned Size() const{ return LumpSize; } int LockCount() const { return RefCount; } - const char *ResName() const { return LumpName[BaseNameNoExtType]; } needed + const char *ResName() const { return LumpName[BaseNameNoExtType]; } const char *ResType() { return LumpName[ExtensionType]; } - const char *FullName() const { return LumpName[FullNameType]; } needed + const char *FullName() const { return LumpName[FullNameType]; } protected: virtual int ValidateCache() { return -1; } @@ -167,7 +169,7 @@ struct FExternalLump : public FResourceLump struct FMemoryLump : public FResourceLump { - FMemoryLump(const void *data, int length) + FMemoryLump(const void* data, int length) { Cache.Resize(length); memcpy(Cache.Data(), data, length); @@ -177,20 +179,20 @@ struct FMemoryLump : public FResourceLump RefCount = INT_MAX / 2; // Make sure it never counts down to 0 by resetting it to something high each time it is used. return 1; } -} +}; struct FClonedLump : public FResourceLump { - FResourceLump *parent; - FClonedLump(FResourceLump *lump) + FResourceLump* parent; + FClonedLump(FResourceLump* lump) { parent = lump; } - void *Lock() { return parent->Lock(); } + void* Lock() { return parent->Lock(); } void Unlock(bool mayfree) override { parent->Unlock(mayfree); } - void *Get() { return parent->Get(); } - void ValidateCache() override { parent->ValidateCache(); } -} + void* Get() { return parent->Get(); } + int ValidateCache() override { return parent->ValidateCache(); } +};