From 135f15992763e009cef63a704f5fd30bef061f5b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 13:21:18 +0200 Subject: [PATCH] - pass lump filters as parameter when initializing the file system to reduce dependencies on high level state in the low level code. --- src/d_main.cpp | 20 ++++- src/gamedata/resourcefiles/file_7z.cpp | 10 +-- src/gamedata/resourcefiles/file_directory.cpp | 16 ++-- src/gamedata/resourcefiles/file_grp.cpp | 8 +- src/gamedata/resourcefiles/file_lump.cpp | 8 +- src/gamedata/resourcefiles/file_pak.cpp | 9 ++- src/gamedata/resourcefiles/file_rff.cpp | 8 +- src/gamedata/resourcefiles/file_wad.cpp | 8 +- src/gamedata/resourcefiles/file_whres.cpp | 8 +- src/gamedata/resourcefiles/file_zip.cpp | 8 +- src/gamedata/resourcefiles/file_zip.h | 2 +- src/gamedata/resourcefiles/resourcefile.cpp | 80 +++++++------------ src/gamedata/resourcefiles/resourcefile.h | 23 +++--- src/gamedata/w_wad.cpp | 12 +-- src/gamedata/w_wad.h | 4 +- 15 files changed, 115 insertions(+), 109 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 07bc0b8f8..a48da088e 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2480,7 +2480,25 @@ static int D_DoomMain_Internal (void) } if (!batchrun) Printf ("W_Init: Init WADfiles.\n"); - Wads.InitMultipleFiles (allwads, iwad_info->DeleteLumps); + + LumpFilterInfo lfi; + lfi.dotFilter = LumpFilterIWAD; + + static const struct { int match; const char* name; } blanket[] = + { + { GAME_Raven, "game-Raven" }, + { GAME_DoomStrifeChex, "game-DoomStrifeChex" }, + { GAME_DoomChex, "game-DoomChex" }, + { GAME_Any, NULL } + }; + + for (auto& inf : blanket) + { + if (gameinfo.gametype & inf.match) lfi.gameTypeFilter.Push(inf.name); + } + lfi.gameTypeFilter.Push(FStringf("game-%s", GameTypeName())); + + Wads.InitMultipleFiles (allwads, iwad_info->DeleteLumps, false, &lfi); allwads.Clear(); allwads.ShrinkToFit(); SetMapxxFlag(); diff --git a/src/gamedata/resourcefiles/file_7z.cpp b/src/gamedata/resourcefiles/file_7z.cpp index a7d1aec9c..f26b04133 100644 --- a/src/gamedata/resourcefiles/file_7z.cpp +++ b/src/gamedata/resourcefiles/file_7z.cpp @@ -190,7 +190,7 @@ class F7ZFile : public FResourceFile public: F7ZFile(const char * filename, FileReader &filer); - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); virtual ~F7ZFile(); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } }; @@ -217,7 +217,7 @@ F7ZFile::F7ZFile(const char * filename, FileReader &filer) // //========================================================================== -bool F7ZFile::Open(bool quiet) +bool F7ZFile::Open(bool quiet, LumpFilterInfo *filter) { Archive = new C7zArchive(Reader); int skipped = 0; @@ -317,7 +317,7 @@ bool F7ZFile::Open(bool quiet) if (!quiet && !batchrun) Printf(", %d lumps\n", NumLumps); GenerateHash(); - PostProcessArchive(&Lumps[0], sizeof(F7ZLump)); + PostProcessArchive(&Lumps[0], sizeof(F7ZLump), filter); return true; } @@ -359,7 +359,7 @@ int F7ZLump::FillCache() // //========================================================================== -FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet) +FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter) { char head[k7zSignatureSize]; @@ -371,7 +371,7 @@ FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet) if (!memcmp(head, k7zSignature, k7zSignatureSize)) { FResourceFile *rf = new F7ZFile(filename, file); - if (rf->Open(quiet)) return rf; + if (rf->Open(quiet, filter)) return rf; file = std::move(rf->Reader); // to avoid destruction of reader delete rf; diff --git a/src/gamedata/resourcefiles/file_directory.cpp b/src/gamedata/resourcefiles/file_directory.cpp index d4e848c05..013d9bf1c 100644 --- a/src/gamedata/resourcefiles/file_directory.cpp +++ b/src/gamedata/resourcefiles/file_directory.cpp @@ -51,8 +51,8 @@ struct FDirectoryLump : public FResourceLump { - virtual FileReader NewReader(); - virtual int FillCache(); + FileReader NewReader() override; + int FillCache() override; FString mFullPath; }; @@ -74,7 +74,7 @@ class FDirectory : public FResourceFile public: FDirectory(const char * dirname, bool nosubdirflag = false); - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } }; @@ -180,11 +180,11 @@ int FDirectory::AddDirectory(const char *dirpath) // //========================================================================== -bool FDirectory::Open(bool quiet) +bool FDirectory::Open(bool quiet, LumpFilterInfo* filter) { NumLumps = AddDirectory(FileName); if (!quiet) Printf(", %d lumps\n", NumLumps); - PostProcessArchive(&Lumps[0], sizeof(FDirectoryLump)); + PostProcessArchive(&Lumps[0], sizeof(FDirectoryLump), filter); return true; } @@ -253,10 +253,10 @@ int FDirectoryLump::FillCache() // //========================================================================== -FResourceFile *CheckDir(const char *filename, bool quiet) +FResourceFile *CheckDir(const char *filename, bool quiet, bool nosubdirflag, LumpFilterInfo* filter) { - FResourceFile *rf = new FDirectory(filename); - if (rf->Open(quiet)) return rf; + FResourceFile *rf = new FDirectory(filename, nosubdirflag); + if (rf->Open(quiet, filter)) return rf; delete rf; return NULL; } diff --git a/src/gamedata/resourcefiles/file_grp.cpp b/src/gamedata/resourcefiles/file_grp.cpp index 937feef90..a8e050061 100644 --- a/src/gamedata/resourcefiles/file_grp.cpp +++ b/src/gamedata/resourcefiles/file_grp.cpp @@ -73,7 +73,7 @@ class FGrpFile : public FUncompressedFile { public: FGrpFile(const char * filename, FileReader &file); - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); }; @@ -94,7 +94,7 @@ FGrpFile::FGrpFile(const char *filename, FileReader &file) // //========================================================================== -bool FGrpFile::Open(bool quiet) +bool FGrpFile::Open(bool quiet, LumpFilterInfo*) { GrpInfo header; @@ -131,7 +131,7 @@ bool FGrpFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckGRP(const char *filename, FileReader &file, bool quiet) +FResourceFile *CheckGRP(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter) { char head[12]; @@ -143,7 +143,7 @@ FResourceFile *CheckGRP(const char *filename, FileReader &file, bool quiet) if (!memcmp(head, "KenSilverman", 12)) { FResourceFile *rf = new FGrpFile(filename, file); - if (rf->Open(quiet)) return rf; + if (rf->Open(quiet, filter)) return rf; file = std::move(rf->Reader); // to avoid destruction of reader delete rf; diff --git a/src/gamedata/resourcefiles/file_lump.cpp b/src/gamedata/resourcefiles/file_lump.cpp index d4add8271..c7d87284e 100644 --- a/src/gamedata/resourcefiles/file_lump.cpp +++ b/src/gamedata/resourcefiles/file_lump.cpp @@ -47,7 +47,7 @@ class FLumpFile : public FUncompressedFile { public: FLumpFile(const char * filename, FileReader &file); - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); }; @@ -68,7 +68,7 @@ FLumpFile::FLumpFile(const char *filename, FileReader &file) // //========================================================================== -bool FLumpFile::Open(bool quiet) +bool FLumpFile::Open(bool quiet, LumpFilterInfo*) { FString name(ExtractFileBase(FileName, true)); @@ -92,11 +92,11 @@ bool FLumpFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckLump(const char *filename, FileReader &file, bool quiet) +FResourceFile *CheckLump(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter) { // always succeeds FResourceFile *rf = new FLumpFile(filename, file); - if (rf->Open(quiet)) return rf; + if (rf->Open(quiet, filter)) return rf; file = std::move(rf->Reader); // to avoid destruction of reader delete rf; return NULL; diff --git a/src/gamedata/resourcefiles/file_pak.cpp b/src/gamedata/resourcefiles/file_pak.cpp index e61ab2f6b..f58ba1cc5 100644 --- a/src/gamedata/resourcefiles/file_pak.cpp +++ b/src/gamedata/resourcefiles/file_pak.cpp @@ -66,7 +66,7 @@ class FPakFile : public FUncompressedFile { public: FPakFile(const char * filename, FileReader &file); - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); }; @@ -89,7 +89,7 @@ FPakFile::FPakFile(const char *filename, FileReader &file) // //========================================================================== -bool FPakFile::Open(bool quiet) +bool FPakFile::Open(bool quiet, LumpFilterInfo* filter) { dpackheader_t header; @@ -115,6 +115,7 @@ bool FPakFile::Open(bool quiet) Lumps[i].CheckEmbedded(); } GenerateHash(); + PostProcessArchive(&Lumps[0], sizeof(Lumps[0]), filter); return true; } @@ -125,7 +126,7 @@ bool FPakFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet) +FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter) { char head[4]; @@ -137,7 +138,7 @@ FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet) if (!memcmp(head, "PACK", 4)) { FResourceFile *rf = new FPakFile(filename, file); - if (rf->Open(quiet)) return rf; + if (rf->Open(quiet, filter)) return rf; file = std::move(rf->Reader); // to avoid destruction of reader delete rf; diff --git a/src/gamedata/resourcefiles/file_rff.cpp b/src/gamedata/resourcefiles/file_rff.cpp index 63f1c47d0..05f7ed542 100644 --- a/src/gamedata/resourcefiles/file_rff.cpp +++ b/src/gamedata/resourcefiles/file_rff.cpp @@ -112,7 +112,7 @@ class FRFFFile : public FResourceFile public: FRFFFile(const char * filename, FileReader &file); virtual ~FRFFFile(); - virtual bool Open(bool quiet); + virtual bool Open(bool quiet, LumpFilterInfo* filter); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } }; @@ -135,7 +135,7 @@ FRFFFile::FRFFFile(const char *filename, FileReader &file) // //========================================================================== -bool FRFFFile::Open(bool quiet) +bool FRFFFile::Open(bool quiet, LumpFilterInfo*) { RFFLump *lumps; RFFInfo header; @@ -239,7 +239,7 @@ int FRFFLump::FillCache() // //========================================================================== -FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet) +FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter) { char head[4]; @@ -251,7 +251,7 @@ FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet) if (!memcmp(head, "RFF\x1a", 4)) { FResourceFile *rf = new FRFFFile(filename, file); - if (rf->Open(quiet)) return rf; + if (rf->Open(quiet, filter)) return rf; file = std::move(rf->Reader); // to avoid destruction of reader delete rf; diff --git a/src/gamedata/resourcefiles/file_wad.cpp b/src/gamedata/resourcefiles/file_wad.cpp index b96d18db4..36b2a1195 100644 --- a/src/gamedata/resourcefiles/file_wad.cpp +++ b/src/gamedata/resourcefiles/file_wad.cpp @@ -116,7 +116,7 @@ class FWadFile : public FResourceFile public: FWadFile(const char * filename, FileReader &file); FResourceLump *GetLump(int lump) { return &Lumps[lump]; } - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); }; @@ -139,7 +139,7 @@ FWadFile::FWadFile(const char *filename, FileReader &file) // //========================================================================== -bool FWadFile::Open(bool quiet) +bool FWadFile::Open(bool quiet, LumpFilterInfo*) { wadinfo_t header; uint32_t InfoTableOfs; @@ -442,7 +442,7 @@ void FWadFile::SkinHack () // //========================================================================== -FResourceFile *CheckWad(const char *filename, FileReader &file, bool quiet) +FResourceFile *CheckWad(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter) { char head[4]; @@ -454,7 +454,7 @@ FResourceFile *CheckWad(const char *filename, FileReader &file, bool quiet) if (!memcmp(head, "IWAD", 4) || !memcmp(head, "PWAD", 4)) { FResourceFile *rf = new FWadFile(filename, file); - if (rf->Open(quiet)) return rf; + if (rf->Open(quiet, filter)) return rf; file = std::move(rf->Reader); // to avoid destruction of reader delete rf; diff --git a/src/gamedata/resourcefiles/file_whres.cpp b/src/gamedata/resourcefiles/file_whres.cpp index 873f358e2..c328adf46 100644 --- a/src/gamedata/resourcefiles/file_whres.cpp +++ b/src/gamedata/resourcefiles/file_whres.cpp @@ -68,7 +68,7 @@ class FWHResFile : public FUncompressedFile FString basename; public: FWHResFile(const char * filename, FileReader &file); - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); }; @@ -92,7 +92,7 @@ FWHResFile::FWHResFile(const char *filename, FileReader &file) // //========================================================================== -bool FWHResFile::Open(bool quiet) +bool FWHResFile::Open(bool quiet, LumpFilterInfo*) { int directory[1024]; @@ -130,7 +130,7 @@ bool FWHResFile::Open(bool quiet) // //========================================================================== -FResourceFile *CheckWHRes(const char *filename, FileReader &file, bool quiet) +FResourceFile *CheckWHRes(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter) { if (file.GetLength() >= 8192) // needs to be at least 8192 to contain one file and the directory. { @@ -150,7 +150,7 @@ FResourceFile *CheckWHRes(const char *filename, FileReader &file, bool quiet) checkpos += (length+4095) / 4096; } FResourceFile *rf = new FWHResFile(filename, file); - if (rf->Open(quiet)) return rf; + if (rf->Open(quiet, filter)) return rf; file = std::move(rf->Reader); // to avoid destruction of reader delete rf; } diff --git a/src/gamedata/resourcefiles/file_zip.cpp b/src/gamedata/resourcefiles/file_zip.cpp index 6fd8b8bcb..881b52763 100644 --- a/src/gamedata/resourcefiles/file_zip.cpp +++ b/src/gamedata/resourcefiles/file_zip.cpp @@ -171,7 +171,7 @@ FZipFile::FZipFile(const char * filename, FileReader &file) Lumps = NULL; } -bool FZipFile::Open(bool quiet) +bool FZipFile::Open(bool quiet, LumpFilterInfo* filter) { uint32_t centraldir = Zip_FindCentralDir(Reader); FZipEndOfCentralDirectory info; @@ -359,7 +359,7 @@ bool FZipFile::Open(bool quiet) if (!quiet && !batchrun) Printf(TEXTCOLOR_NORMAL ", %d lumps\n", NumLumps); GenerateHash(); - PostProcessArchive(&Lumps[0], sizeof(FZipLump)); + PostProcessArchive(&Lumps[0], sizeof(FZipLump), filter); return true; } @@ -474,7 +474,7 @@ int FZipLump::GetFileOffset() // //========================================================================== -FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet) +FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter) { char head[4]; @@ -486,7 +486,7 @@ FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet) if (!memcmp(head, "PK\x3\x4", 4)) { FResourceFile *rf = new FZipFile(filename, file); - if (rf->Open(quiet)) return rf; + if (rf->Open(quiet, filter)) return rf; file = std::move(rf->Reader); // to avoid destruction of reader delete rf; diff --git a/src/gamedata/resourcefiles/file_zip.h b/src/gamedata/resourcefiles/file_zip.h index 1036e1ec6..330e7289d 100644 --- a/src/gamedata/resourcefiles/file_zip.h +++ b/src/gamedata/resourcefiles/file_zip.h @@ -41,7 +41,7 @@ class FZipFile : public FResourceFile public: FZipFile(const char * filename, FileReader &file); virtual ~FZipFile(); - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; } }; diff --git a/src/gamedata/resourcefiles/resourcefile.cpp b/src/gamedata/resourcefiles/resourcefile.cpp index 347c25388..e6ee26920 100644 --- a/src/gamedata/resourcefiles/resourcefile.cpp +++ b/src/gamedata/resourcefiles/resourcefile.cpp @@ -236,52 +236,45 @@ int FResourceLump::Unlock() // //========================================================================== -typedef FResourceFile * (*CheckFunc)(const char *filename, FileReader &file, bool quiet); +typedef FResourceFile * (*CheckFunc)(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter); -FResourceFile *CheckWad(const char *filename, FileReader &file, bool quiet); -FResourceFile *CheckGRP(const char *filename, FileReader &file, bool quiet); -FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet); -FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet); -FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet); -FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet); -FResourceFile *CheckLump(const char *filename,FileReader &file, bool quiet); -FResourceFile *CheckDir(const char *filename, bool quiet); +FResourceFile *CheckWad(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter); +FResourceFile *CheckGRP(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter); +FResourceFile *CheckRFF(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter); +FResourceFile *CheckPak(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter); +FResourceFile *CheckZip(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter); +FResourceFile *Check7Z(const char *filename, FileReader &file, bool quiet, LumpFilterInfo* filter); +FResourceFile *CheckLump(const char *filename,FileReader &file, bool quiet, LumpFilterInfo* filter); +FResourceFile *CheckDir(const char *filename, bool quiet, bool nosub, LumpFilterInfo* filter); static CheckFunc funcs[] = { CheckWad, CheckZip, Check7Z, CheckPak, CheckGRP, CheckRFF, CheckLump }; -FResourceFile *FResourceFile::DoOpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly) +FResourceFile *FResourceFile::DoOpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly, LumpFilterInfo* filter) { for(size_t i = 0; i < countof(funcs) - containeronly; i++) { - FResourceFile *resfile = funcs[i](filename, file, quiet); + FResourceFile *resfile = funcs[i](filename, file, quiet, filter); if (resfile != NULL) return resfile; } return NULL; } -FResourceFile *FResourceFile::OpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly) +FResourceFile *FResourceFile::OpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly, LumpFilterInfo* filter) { - return DoOpenResourceFile(filename, file, quiet, containeronly); + return DoOpenResourceFile(filename, file, quiet, containeronly, filter); } -FResourceFile *FResourceFile::OpenResourceFile(const char *filename, bool quiet, bool containeronly) +FResourceFile *FResourceFile::OpenResourceFile(const char *filename, bool quiet, bool containeronly, LumpFilterInfo* filter) { FileReader file; if (!file.OpenFile(filename)) return nullptr; - return DoOpenResourceFile(filename, file, quiet, containeronly); + return DoOpenResourceFile(filename, file, quiet, containeronly, filter); } -FResourceFile *FResourceFile::OpenResourceFileFromLump(int lumpnum, bool quiet, bool containeronly) +FResourceFile *FResourceFile::OpenDirectory(const char *filename, bool quiet, LumpFilterInfo* filter) { - FileReader file = Wads.ReopenLumpReader(lumpnum); - return DoOpenResourceFile("internal", file, quiet, containeronly); -} - - -FResourceFile *FResourceFile::OpenDirectory(const char *filename, bool quiet) -{ - return CheckDir(filename, quiet); + return CheckDir(filename, quiet, false, filter); } //========================================================================== @@ -355,28 +348,29 @@ void FResourceFile::GenerateHash() // //========================================================================== -void FResourceFile::PostProcessArchive(void *lumps, size_t lumpsize) +void FResourceFile::PostProcessArchive(void *lumps, size_t lumpsize, LumpFilterInfo *filter) { // Entries in archives are sorted alphabetically qsort(lumps, NumLumps, lumpsize, lumpcmp); - + if (!filter) return; // Filter out lumps using the same names as the Autoload.* sections // in the ini file use. We reduce the maximum lump concidered after // each one so that we don't risk refiltering already filtered lumps. uint32_t max = NumLumps; - max -= FilterLumpsByGameType(gameinfo.gametype, lumps, lumpsize, max); + max -= FilterLumpsByGameType(filter, lumps, lumpsize, max); long len; int lastpos = -1; FString file; - if (LumpFilterIWAD.IndexOf('.') < 0) + FString LumpFilter = filter->dotFilter; + if (LumpFilter.IndexOf('.') < 0) { - max -= FilterLumps(LumpFilterIWAD, lumps, lumpsize, max); + max -= FilterLumps(LumpFilter, lumps, lumpsize, max); } - else while ((len = LumpFilterIWAD.IndexOf('.', lastpos+1)) > 0) + else while ((len = LumpFilter.IndexOf('.', lastpos+1)) > 0) { - max -= FilterLumps(LumpFilterIWAD.Left(len), lumps, lumpsize, max); + max -= FilterLumps(LumpFilter.Left(len), lumps, lumpsize, max); lastpos = len; } JunkLeftoverFilters(lumps, lumpsize, max); @@ -457,30 +451,18 @@ int FResourceFile::FilterLumps(FString filtername, void *lumps, size_t lumpsize, // //========================================================================== -int FResourceFile::FilterLumpsByGameType(int type, void *lumps, size_t lumpsize, uint32_t max) +int FResourceFile::FilterLumpsByGameType(LumpFilterInfo *filter, void *lumps, size_t lumpsize, uint32_t max) { - static const struct { int match; const char *name; } blanket[] = - { - { GAME_Raven, "game-Raven" }, - { GAME_DoomStrifeChex, "game-DoomStrifeChex" }, - { GAME_DoomChex, "game-DoomChex" }, - { GAME_Any, NULL } - }; - if (type == 0) + if (filter == nullptr) { return 0; } int count = 0; - for (int i = 0; blanket[i].name != NULL; ++i) + for (auto &fstring : filter->gameTypeFilter) { - if (type & blanket[i].match) - { - count += FilterLumps(blanket[i].name, lumps, lumpsize, max); - } + count += FilterLumps(fstring, lumps, lumpsize, max); } - FString filter = "game-"; - filter += GameNames[type]; - return count + FilterLumps(filter, lumps, lumpsize, max); + return count; } //========================================================================== @@ -707,7 +689,7 @@ int FExternalLump::FillCache() } -bool FMemoryFile::Open(bool quiet) +bool FMemoryFile::Open(bool quiet, LumpFilterInfo*) { FString name(ExtractFileBase(FileName)); FString fname(ExtractFileBase(FileName, true)); diff --git a/src/gamedata/resourcefiles/resourcefile.h b/src/gamedata/resourcefiles/resourcefile.h index fcf244040..6bd7fc51f 100644 --- a/src/gamedata/resourcefiles/resourcefile.h +++ b/src/gamedata/resourcefiles/resourcefile.h @@ -5,6 +5,12 @@ #include "files.h" +struct LumpFilterInfo +{ + TArray gameTypeFilter; // this can contain multiple entries + FString dotFilter; +}; + class FResourceFile; class FTexture; @@ -128,22 +134,21 @@ protected: // for archives that can contain directories void GenerateHash(); - void PostProcessArchive(void *lumps, size_t lumpsize); + void PostProcessArchive(void *lumps, size_t lumpsize, LumpFilterInfo *filter); private: uint32_t FirstLump; int FilterLumps(FString filtername, void *lumps, size_t lumpsize, uint32_t max); - int FilterLumpsByGameType(int gametype, void *lumps, size_t lumpsize, uint32_t max); + int FilterLumpsByGameType(LumpFilterInfo *filter, void *lumps, size_t lumpsize, uint32_t max); bool FindPrefixRange(FString filter, void *lumps, size_t lumpsize, uint32_t max, uint32_t &start, uint32_t &end); void JunkLeftoverFilters(void *lumps, size_t lumpsize, uint32_t max); - static FResourceFile *DoOpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly); + static FResourceFile *DoOpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly, LumpFilterInfo* filter); public: - static FResourceFile *OpenResourceFile(const char *filename, FileReader &file, bool quiet = false, bool containeronly = false); - static FResourceFile *OpenResourceFile(const char *filename, bool quiet = false, bool containeronly = false); - static FResourceFile *OpenResourceFileFromLump(int lumpnum, bool quiet = false, bool containeronly = false); - static FResourceFile *OpenDirectory(const char *filename, bool quiet = false); + static FResourceFile *OpenResourceFile(const char *filename, FileReader &file, bool quiet = false, bool containeronly = false, LumpFilterInfo* filter = nullptr); + static FResourceFile *OpenResourceFile(const char *filename, bool quiet = false, bool containeronly = false, LumpFilterInfo* filter = nullptr); + static FResourceFile *OpenDirectory(const char *filename, bool quiet = false, LumpFilterInfo* filter = nullptr); virtual ~FResourceFile(); // If this FResourceFile represents a directory, the Reader object is not usable so don't return it. FileReader *GetReader() { return Reader.isOpen()? &Reader : nullptr; } @@ -153,7 +158,7 @@ public: const FString &GetHash() const { return Hash; } - virtual bool Open(bool quiet) = 0; + virtual bool Open(bool quiet, LumpFilterInfo* filter) = 0; virtual FResourceLump *GetLump(int no) = 0; FResourceLump *FindLump(const char *name); }; @@ -198,7 +203,7 @@ struct FMemoryFile : public FUncompressedFile Reader.OpenMemoryArray(sdata, length); } - bool Open(bool quiet); + bool Open(bool quiet, LumpFilterInfo* filter); }; diff --git a/src/gamedata/w_wad.cpp b/src/gamedata/w_wad.cpp index 1e40dc57c..171fea6d3 100644 --- a/src/gamedata/w_wad.cpp +++ b/src/gamedata/w_wad.cpp @@ -263,7 +263,7 @@ void FWadCollection::InitSingleFile(const char* filename, bool quiet) InitMultipleFiles(filenames, deletes, true); } -void FWadCollection::InitMultipleFiles (TArray &filenames, const TArray &deletelumps, bool quiet) +void FWadCollection::InitMultipleFiles (TArray &filenames, const TArray &deletelumps, bool quiet, LumpFilterInfo* filter) { int numfiles; @@ -274,7 +274,7 @@ void FWadCollection::InitMultipleFiles (TArray &filenames, const TArray for(unsigned i=0;iGetHash().GetChars()); @@ -331,7 +331,7 @@ int FWadCollection::AddExternalFile(const char *filename) // [RH] Removed reload hack //========================================================================== -void FWadCollection::AddFile (const char *filename, FileReader *wadr, bool quiet) +void FWadCollection::AddFile (const char *filename, FileReader *wadr, bool quiet, LumpFilterInfo* filter) { int startlump; bool isdir = false; @@ -371,9 +371,9 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadr, bool quiet FResourceFile *resfile; if (!isdir) - resfile = FResourceFile::OpenResourceFile(filename, wadreader, quiet); + resfile = FResourceFile::OpenResourceFile(filename, wadreader, quiet, false, filter); else - resfile = FResourceFile::OpenDirectory(filename, quiet); + resfile = FResourceFile::OpenDirectory(filename, quiet, filter); if (resfile != NULL) { @@ -397,7 +397,7 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadr, bool quiet FString path; path.Format("%s:%s", filename, lump->getName()); auto embedded = lump->NewReader(); - AddFile(path, &embedded); + AddFile(path, &embedded, quiet, filter); } } diff --git a/src/gamedata/w_wad.h b/src/gamedata/w_wad.h index ece994141..9ab28631b 100644 --- a/src/gamedata/w_wad.h +++ b/src/gamedata/w_wad.h @@ -82,8 +82,8 @@ public: void SetMaxIwadNum(int x) { MaxIwadIndex = x; } void InitSingleFile(const char *filename, bool quiet = false); - void InitMultipleFiles (TArray &filenames, const TArray &deletelumps, bool quiet = false); - void AddFile (const char *filename, FileReader *wadinfo = NULL, bool quiet = false); + void InitMultipleFiles (TArray &filenames, const TArray &deletelumps, bool quiet = false, LumpFilterInfo* filter = nullptr); + void AddFile (const char *filename, FileReader *wadinfo, bool quiet, LumpFilterInfo* filter); int CheckIfWadLoaded (const char *name); const char *GetWadName (int wadnum) const;