- use std::vector in GetFilesInFolder

This commit is contained in:
Christoph Oelckers 2023-08-20 00:56:56 +02:00
parent 2a6fb6da84
commit 535eb9a853
6 changed files with 21 additions and 20 deletions

View file

@ -1241,13 +1241,13 @@ static int folderentrycmp(const void *a, const void *b)
//
//==========================================================================
unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray<FolderEntry> &result, bool atomic) const
unsigned FileSystem::GetFilesInFolder(const char *inpath, std::vector<FolderEntry> &result, bool atomic) const
{
std::string path = inpath;
FixPathSeparator(&path.front());
for (auto& c : path) c = tolower(c);
if (path.back() != '/') path += '/';
result.Clear();
result.clear();
for (size_t i = 0; i < FileInfo.size(); i++)
{
if (FileInfo[i].longName.find(path) == 0)
@ -1256,11 +1256,11 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray<FolderEntry> &r
if ((unsigned)fileSystem.CheckNumForFullName(FileInfo[i].longName.c_str()) == i)
{
FolderEntry fe{ FileInfo[i].longName.c_str(), (uint32_t)i };
result.Push(fe);
result.push_back(fe);
}
}
}
if (result.Size())
if (result.size())
{
int maxfile = -1;
if (atomic)
@ -1272,14 +1272,14 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray<FolderEntry> &r
if (thisfile > maxfile) maxfile = thisfile;
}
// Delete everything from older files.
for (int i = result.Size() - 1; i >= 0; i--)
for (int i = (int)result.size() - 1; i >= 0; i--)
{
if (fileSystem.GetFileContainer(result[i].lumpnum) != maxfile) result.Delete(i);
if (fileSystem.GetFileContainer(result[i].lumpnum) != maxfile) result.erase(result.begin() + i);
}
}
qsort(result.Data(), result.Size(), sizeof(FolderEntry), folderentrycmp);
qsort(result.data(), result.size(), sizeof(FolderEntry), folderentrycmp);
}
return result.Size();
return (unsigned)result.size();
}
//==========================================================================

View file

@ -144,7 +144,7 @@ public:
int GetResourceId(int lump) const; // Returns the RFF index number for this lump
const char* GetResourceType(int lump) const;
bool CheckFileName (int lump, const char *name) const; // [RH] Returns true if the names match
unsigned GetFilesInFolder(const char *path, TArray<FolderEntry> &result, bool atomic) const;
unsigned GetFilesInFolder(const char *path, std::vector<FolderEntry> &result, bool atomic) const;
int GetNumEntries() const
{

View file

@ -91,7 +91,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
// Read the font's configuration.
// This will not be done for the default fonts, because they are not atomic and the default content does not need it.
TArray<FolderEntry> folderdata;
std::vector<FolderEntry> folderdata;
if (filetemplate != nullptr)
{
FStringf path("fonts/%s/", filetemplate);
@ -103,12 +103,13 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
{
FStringf infpath("fonts/%s/font.inf", filetemplate);
unsigned index = folderdata.FindEx([=](const FolderEntry &entry)
size_t index;
for(index = 0; index < folderdata.size(); index++)
{
return infpath.CompareNoCase(entry.name) == 0;
});
if (infpath.CompareNoCase(folderdata[i].name) == 0) break;
}
if (index < folderdata.Size())
if (index < folderdata.size())
{
FScanner sc;
sc.OpenLumpNum(folderdata[index].lumpnum);
@ -288,7 +289,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
}
}
}
if (folderdata.Size() > 0)
if (folderdata.size() > 0)
{
// all valid lumps must be named with a hex number that represents its Unicode character index.
for (auto &entry : folderdata)
@ -397,7 +398,7 @@ public:
}
};
void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
void FFont::ReadSheetFont(std::vector<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
{
TMap<int, FGameTexture*> charMap;
int minchar = INT_MAX;

View file

@ -109,7 +109,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
int lump = -1;
int folderfile = -1;
TArray<FolderEntry> folderdata;
std::vector<FolderEntry> folderdata;
FStringf path("fonts/%s/", name);
// Use a folder-based font only if it comes from a later file than the single lump version.
@ -149,7 +149,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
return font;
}
}
if (folderdata.Size() > 0)
if (folderdata.size() > 0)
{
font = new FFont(name, nullptr, name, 0, 0, 1, -1);
if (translationsLoaded) font->LoadTranslations();

View file

@ -175,7 +175,7 @@ protected:
void FixXMoves();
void ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);
void ReadSheetFont(std::vector<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);
EFontType Type = EFontType::Unknown;
FName AltFontName = NAME_None;

View file

@ -1108,7 +1108,7 @@ void FTextureManager::SortTexturesByType(int start, int end)
void FTextureManager::AddLocalizedVariants()
{
TArray<FolderEntry> content;
std::vector<FolderEntry> content;
fileSystem.GetFilesInFolder("localized/textures/", content, false);
for (auto &entry : content)
{