- fixed compilation of file system code.

This commit is contained in:
Christoph Oelckers 2019-10-31 18:06:05 +01:00
parent 8ef40c5083
commit d7e183d46d
6 changed files with 48 additions and 38 deletions

View file

@ -60,6 +60,7 @@ struct RFFLump
uint8_t Flags; uint8_t Flags;
char Extension[3]; char Extension[3];
char Name[8]; char Name[8];
uint32_t ResourceId;
}; };
//========================================================================== //==========================================================================
@ -71,7 +72,7 @@ struct RFFLump
struct FRFFLump : public FUncompressedLump struct FRFFLump : public FUncompressedLump
{ {
virtual FileReader *GetReader(); virtual FileReader *GetReader();
int ValidataCache() override; int ValidateCache() override;
uint32_t IndexNum; uint32_t IndexNum;
}; };
@ -205,7 +206,7 @@ int FRFFLump::ValidateCache()
{ {
int res = FUncompressedLump::ValidateCache(); int res = FUncompressedLump::ValidateCache();
if (res && )(Flags & LUMPF_BLOODCRYPT)) if (res && (Flags & LUMPF_BLOODCRYPT))
{ {
int cryptlen = std::min<int> (LumpSize, 256); int cryptlen = std::min<int> (LumpSize, 256);
uint8_t *data = Cache.Data(); uint8_t *data = Cache.Data();

View file

@ -356,7 +356,7 @@ FileReader *FZipLump::GetReader()
// //
//========================================================================== //==========================================================================
int FZipLump::ValidataCache() int FZipLump::ValidateCache()
{ {
if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress(); if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress();

View file

@ -312,7 +312,7 @@ int FileSystem::FindResource (int resid, const char *type, int filenum) const no
FName lname(type, true); FName lname(type, true);
if (lname == NAME_None) return -1; 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* fli = FirstFileIndex[lookuptype];
uint32_t* nli = NextFileIndex[lookuptype]; uint32_t* nli = NextFileIndex[lookuptype];
@ -337,7 +337,7 @@ int FileSystem::GetResource (int resid, const char *type, int filenum) const
{ {
int i; int i;
i = FindResource (resid, type, lookupmode, filenum); i = FindResource (resid, type, filenum);
if (i == -1) if (i == -1)
{ {
@ -450,7 +450,7 @@ void FileSystem::AddLump(FResourceLump *lump)
hash = int(lump->ResourceId) % NumEntries; hash = int(lump->ResourceId) % NumEntries;
} }
NextFileIndex[l][hash] = FirstFileIndex[l][hash]; 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<FolderEntry> &r
TArray<uint8_t> FileSystem::GetFileData(int lump, int pad) TArray<uint8_t> FileSystem::GetFileData(int lump, int pad)
{ {
if ((size_t)lump >= FileInfo.Size()) if ((size_t)lump >= FileInfo.Size())
return TArray<<uint8_t>(); return TArray<uint8_t>();
auto lumpr = OpenFileReader(lump); auto lumpr = OpenFileReader(lump);
auto size = lumpr.GetLength(); auto size = lumpr.GetLength();
@ -656,22 +656,22 @@ TArray<uint8_t> FileSystem::GetFileData(int lump, int pad)
const void *FileSystem::Lock(int lump) const void *FileSystem::Lock(int lump)
{ {
if ((size_t)lump >= FileInfo.Size()) return nullptr; if ((size_t)lump >= FileInfo.Size()) return nullptr;
auto lump = FileInfo[lump].lump; auto lumpp = FileInfo[lump].lump;
return lump->Lock(); return lumpp->Lock();
} }
void FileSystem::Unlock(bool mayfree) void FileSystem::Unlock(int lump, bool mayfree)
{ {
if ((size_t)lump >= FileInfo.Size()) return; if ((size_t)lump >= FileInfo.Size()) return;
auto lump = FileInfo[lump].lump; auto lumpp = FileInfo[lump].lump;
lump->Unlock(maxfree); lumpp->Unlock(mayfree);
} }
const void *FileSystem::Get(int lump) const void *FileSystem::Get(int lump)
{ {
if ((size_t)lump >= FileInfo.Size()) return nullptr; if ((size_t)lump >= FileInfo.Size()) return nullptr;
auto lump = FileInfo[lump].lump; auto lumpp = FileInfo[lump].lump;
return lump->Get(); 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(); if (lump) return lump->Lock();
else return nullptr;
} }
void FileSystem::Unlock(FResourceLump *lump) void FileSystem::Unlock(FResourceLump *lump)
@ -690,9 +691,10 @@ void FileSystem::Unlock(FResourceLump *lump)
if (lump) return lump->Unlock(); if (lump) return lump->Unlock();
} }
void FileSystem::Load(FResourceLump *lump) const void *FileSystem::Load(FResourceLump *lump)
{ {
if (lump) return lump->Get(); 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); FStringf fname("%s.%s", name, type);
auto lump = FindFile(fname); auto lump = FindFile(fname);
if (lump >= 0) return FileInfo[lump].lump; if (lump >= 0) return FileInfo[lump].lump;
else return nullptr;
} }
FResourceLump *FileSystem::Lookup(unsigned int id, const char *type) FResourceLump *FileSystem::Lookup(unsigned int id, const char *type)
{ {
auto lump = FindResource(id, type); auto lump = FindResource(id, type);
auto lump = FindFile(fname);
if (lump >= 0) return FileInfo[lump].lump; if (lump >= 0) return FileInfo[lump].lump;
else return nullptr;
} }
//========================================================================== //==========================================================================

View file

@ -12,6 +12,10 @@
#include "tarray.h" #include "tarray.h"
#include "zstring.h" #include "zstring.h"
#ifdef FindResource
#undef FindResource
#endif
// We do not want to expose the resource file interface here. // We do not want to expose the resource file interface here.
class FResourceFile; class FResourceFile;
struct FResourceLump; struct FResourceLump;
@ -107,13 +111,13 @@ public:
FileData ReadFile (const char *name) { return ReadFile (GetFile (name)); } FileData ReadFile (const char *name) { return ReadFile (GetFile (name)); }
const void *Lock(int lump); const void *Lock(int lump);
void Unlock(bool mayfree = false); void Unlock(int lump, bool mayfree = false);
void *Get(int lump); const void *Get(int lump);
// These are designed to be stand-ins for Blood's resource class. // 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 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 *lump) { Load(lump); }
static void Read(FResourceLump *n, void *p); static void Read(FResourceLump *n, void *p);
FResourceLump *Lookup(const char *name, const char *type); 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. 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 InitHashChains (); // [RH] Set up the lumpinfo hashing
void AddLump(FResourceLump* lump);
private: private:
void DeleteAll(); void DeleteAll();

View file

@ -54,13 +54,13 @@ public:
FLumpReader(FResourceLump *src) FLumpReader(FResourceLump *src)
: MemoryReader(NULL, src->LumpSize), source(src) : MemoryReader(NULL, src->LumpSize), source(src)
{ {
src->CacheLump(); bufptr = (const char*)src->Lock();
bufptr = (const char*)src->Cache.Data(); src->Cache.Data();
} }
~FLumpReader() ~FLumpReader()
{ {
source->ReleaseCache(); source->Unlock(true);
} }
}; };
@ -154,7 +154,7 @@ void *FResourceLump::Lock()
} }
else if (LumpSize > 0) else if (LumpSize > 0)
{ {
ValidateCache() ValidateCache();
RefCount++; RefCount++;
} }
return Cache.Data(); return Cache.Data();
@ -170,7 +170,7 @@ void *FResourceLump::Get()
{ {
if (Cache.Size() == 0) if (Cache.Size() == 0)
{ {
ValidateCache() ValidateCache();
} }
return Cache.Data(); 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) if (LumpSize > 0 && RefCount > 0)
{ {
@ -190,7 +190,6 @@ int FResourceLump::Unlock(bool mayfree)
if (mayfree) Cache.Reset(); if (mayfree) Cache.Reset();
} }
} }
return RefCount;
} }
//========================================================================== //==========================================================================

View file

@ -6,6 +6,7 @@
#include <stdint.h> #include <stdint.h>
#include "files.h" #include "files.h"
#include "zstring.h" #include "zstring.h"
#include "name.h"
class FResourceFile; class FResourceFile;
class FTexture; class FTexture;
@ -56,6 +57,7 @@ struct FResourceLump
}; };
friend class FResourceFile; friend class FResourceFile;
friend struct FClonedLump;
unsigned LumpSize = 0; unsigned LumpSize = 0;
int RefCount = 0; int RefCount = 0;
@ -81,9 +83,9 @@ struct FResourceLump
// Wrappers for emulating Blood's resource system // Wrappers for emulating Blood's resource system
unsigned Size() const{ return LumpSize; } unsigned Size() const{ return LumpSize; }
int LockCount() const { return RefCount; } 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 *ResType() { return LumpName[ExtensionType]; }
const char *FullName() const { return LumpName[FullNameType]; } needed const char *FullName() const { return LumpName[FullNameType]; }
protected: protected:
virtual int ValidateCache() { return -1; } virtual int ValidateCache() { return -1; }
@ -167,7 +169,7 @@ struct FExternalLump : public FResourceLump
struct FMemoryLump : public FResourceLump struct FMemoryLump : public FResourceLump
{ {
FMemoryLump(const void *data, int length) FMemoryLump(const void* data, int length)
{ {
Cache.Resize(length); Cache.Resize(length);
memcpy(Cache.Data(), data, 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. 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; return 1;
} }
} };
struct FClonedLump : public FResourceLump struct FClonedLump : public FResourceLump
{ {
FResourceLump *parent; FResourceLump* parent;
FClonedLump(FResourceLump *lump) FClonedLump(FResourceLump* lump)
{ {
parent = lump; parent = lump;
} }
void *Lock() { return parent->Lock(); } void* Lock() { return parent->Lock(); }
void Unlock(bool mayfree) override { parent->Unlock(mayfree); } void Unlock(bool mayfree) override { parent->Unlock(mayfree); }
void *Get() { return parent->Get(); } void* Get() { return parent->Get(); }
void ValidateCache() override { parent->ValidateCache(); } int ValidateCache() override { return parent->ValidateCache(); }
} };