mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-31 13:50:48 +00:00
simplify lump filter setup and move the Doom special case for 'doom.doom' out of FResourceFile
This commit is contained in:
parent
4850ee3776
commit
21acb9d467
3 changed files with 20 additions and 43 deletions
|
@ -18,7 +18,6 @@ void strReplace(std::string& str, const char* from, const char* to);
|
|||
struct LumpFilterInfo
|
||||
{
|
||||
std::vector<std::string> gameTypeFilter; // this can contain multiple entries
|
||||
std::string dotFilter;
|
||||
|
||||
// The following are for checking if the root directory of a zip can be removed.
|
||||
std::vector<std::string> reservedFolders;
|
||||
|
@ -194,7 +193,6 @@ private:
|
|||
uint32_t FirstLump;
|
||||
|
||||
int FilterLumps(const std::string& filtername, void *lumps, size_t lumpsize, uint32_t max);
|
||||
int FilterLumpsByGameType(LumpFilterInfo *filter, void *lumps, size_t lumpsize, uint32_t max);
|
||||
bool FindPrefixRange(const char* 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 containeronly, LumpFilterInfo* filter, FileSystemMessageFunc Printf, StringPool* sp);
|
||||
|
|
|
@ -407,21 +407,22 @@ void FResourceFile::PostProcessArchive(void *lumps, size_t lumpsize, LumpFilterI
|
|||
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
|
||||
// in the ini file. 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(filter, lumps, lumpsize, max);
|
||||
|
||||
ptrdiff_t len;
|
||||
ptrdiff_t lastpos = -1;
|
||||
std::string file;
|
||||
std::string& LumpFilter = filter->dotFilter;
|
||||
while (size_t(len = LumpFilter.find_first_of('.', lastpos+1)) != LumpFilter.npos)
|
||||
for (auto& LumpFilter : filter->gameTypeFilter)
|
||||
{
|
||||
max -= FilterLumps(std::string(LumpFilter, 0, len), lumps, lumpsize, max);
|
||||
lastpos = len;
|
||||
ptrdiff_t len;
|
||||
ptrdiff_t lastpos = -1;
|
||||
std::string file;
|
||||
while (size_t(len = LumpFilter.find_first_of('.', lastpos + 1)) != LumpFilter.npos)
|
||||
{
|
||||
max -= FilterLumps(std::string(LumpFilter, 0, len), lumps, lumpsize, max);
|
||||
lastpos = len;
|
||||
}
|
||||
max -= FilterLumps(LumpFilter, lumps, lumpsize, max);
|
||||
}
|
||||
max -= FilterLumps(LumpFilter, lumps, lumpsize, max);
|
||||
|
||||
JunkLeftoverFilters(lumps, lumpsize, max);
|
||||
}
|
||||
|
@ -448,13 +449,6 @@ int FResourceFile::FilterLumps(const std::string& filtername, void *lumps, size_
|
|||
|
||||
bool found = FindPrefixRange(filter.c_str(), lumps, lumpsize, max, start, end);
|
||||
|
||||
// Workaround for old Doom filter names (todo: move out of here.)
|
||||
if (!found && filtername.find("doom.id.doom") == 0)
|
||||
{
|
||||
strReplace(filter, "doom.id.doom", "doom.doom");
|
||||
found = FindPrefixRange(filter.c_str(), lumps, lumpsize, max, start, end);
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
void *from = (uint8_t *)lumps + start * lumpsize;
|
||||
|
@ -491,29 +485,6 @@ int FResourceFile::FilterLumps(const std::string& filtername, void *lumps, size_
|
|||
return end - start;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FResourceFile :: FilterLumpsByGameType
|
||||
//
|
||||
// Matches any lumps that match "filter/game-<gametype>/*". Includes
|
||||
// inclusive gametypes like Raven.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FResourceFile::FilterLumpsByGameType(LumpFilterInfo *filter, void *lumps, size_t lumpsize, uint32_t max)
|
||||
{
|
||||
if (filter == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
for (auto &fstring : filter->gameTypeFilter)
|
||||
{
|
||||
count += FilterLumps(fstring, lumps, lumpsize, max);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FResourceFile :: JunkLeftoverFilters
|
||||
|
|
|
@ -3145,7 +3145,6 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector<std::string>& allw
|
|||
if (!batchrun) Printf ("W_Init: Init WADfiles.\n");
|
||||
|
||||
LumpFilterInfo lfi;
|
||||
lfi.dotFilter = LumpFilterIWAD.GetChars();
|
||||
|
||||
static const struct { int match; const char* name; } blanket[] =
|
||||
{
|
||||
|
@ -3161,6 +3160,15 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector<std::string>& allw
|
|||
}
|
||||
lfi.gameTypeFilter.push_back(FStringf("game-%s", GameTypeName()).GetChars());
|
||||
|
||||
lfi.gameTypeFilter.push_back(LumpFilterIWAD.GetChars());
|
||||
// Workaround for old Doom filter names.
|
||||
if (LumpFilterIWAD.Compare("doom.id.doom") == 0)
|
||||
{
|
||||
lfi.gameTypeFilter.push_back("doom.doom");
|
||||
}
|
||||
|
||||
|
||||
|
||||
GetReserved(lfi);
|
||||
|
||||
lfi.postprocessFunc = [&]()
|
||||
|
|
Loading…
Reference in a new issue