mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-19 16:11:23 +00:00
- got rid of FileSystem::GetFileData.
Using FMemFile is better in all these places.
This commit is contained in:
parent
21d6eb99eb
commit
5398045f7d
14 changed files with 50 additions and 84 deletions
|
@ -179,11 +179,10 @@ static void SetupGenMidi()
|
|||
Printf("No GENMIDI lump found. OPL playback not available.\n");
|
||||
return;
|
||||
}
|
||||
auto data = fileSystem.OpenFileReader(lump);
|
||||
auto genmidi = fileSystem.ReadFile(lump);
|
||||
|
||||
auto genmidi = data.Read();
|
||||
if (genmidi.size() < 8 + 175 * 36 || memcmp(genmidi.data(), "#OPL_II#", 8)) return;
|
||||
ZMusic_SetGenMidi(genmidi.data()+8);
|
||||
if (genmidi.GetSize() < 8 + 175 * 36 || memcmp(genmidi.GetMem(), "#OPL_II#", 8)) return;
|
||||
ZMusic_SetGenMidi((uint8_t*)genmidi.GetString().GetChars() + 8);
|
||||
}
|
||||
|
||||
static void SetupWgOpn()
|
||||
|
|
|
@ -136,7 +136,7 @@ void FScanner::Open (const char *name)
|
|||
//
|
||||
// FScanner :: OpenFile
|
||||
//
|
||||
// Loads a script from a file. Uses new/delete for memory allocation.
|
||||
// Loads a script from a file.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
|
|
|
@ -60,10 +60,10 @@ void FStringTable::LoadStrings (const char *language)
|
|||
lastlump = 0;
|
||||
while ((lump = fileSystem.FindLump ("LANGUAGE", &lastlump)) != -1)
|
||||
{
|
||||
auto lumpdata = fileSystem.GetFileData(lump);
|
||||
auto lumpdata = fileSystem.ReadFile(lump);
|
||||
|
||||
if (!ParseLanguageCSV(lump, lumpdata))
|
||||
LoadLanguage (lump, lumpdata);
|
||||
if (!ParseLanguageCSV(lump, lumpdata.GetString(), lumpdata.GetSize()))
|
||||
LoadLanguage (lump, lumpdata.GetString(), lumpdata.GetSize());
|
||||
}
|
||||
UpdateLanguage(language);
|
||||
allMacros.Clear();
|
||||
|
@ -77,9 +77,9 @@ void FStringTable::LoadStrings (const char *language)
|
|||
//==========================================================================
|
||||
|
||||
|
||||
TArray<TArray<FString>> FStringTable::parseCSV(const TArray<uint8_t> &buffer)
|
||||
TArray<TArray<FString>> FStringTable::parseCSV(const char* buffer, size_t size)
|
||||
{
|
||||
const size_t bufLength = buffer.Size();
|
||||
const size_t bufLength = size;
|
||||
TArray<TArray<FString>> data;
|
||||
TArray<FString> row;
|
||||
TArray<char> cell;
|
||||
|
@ -158,8 +158,8 @@ TArray<TArray<FString>> FStringTable::parseCSV(const TArray<uint8_t> &buffer)
|
|||
|
||||
bool FStringTable::readMacros(int lumpnum)
|
||||
{
|
||||
auto lumpdata = fileSystem.GetFileData(lumpnum);
|
||||
auto data = parseCSV(lumpdata);
|
||||
auto lumpdata = fileSystem.ReadFile(lumpnum);
|
||||
auto data = parseCSV(lumpdata.GetString(), lumpdata.GetSize());
|
||||
|
||||
for (unsigned i = 1; i < data.Size(); i++)
|
||||
{
|
||||
|
@ -186,11 +186,11 @@ bool FStringTable::readMacros(int lumpnum)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
bool FStringTable::ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer)
|
||||
bool FStringTable::ParseLanguageCSV(int lumpnum, const char* buffer, size_t size)
|
||||
{
|
||||
if (buffer.Size() < 11) return false;
|
||||
if (strnicmp((const char*)buffer.Data(), "default,", 8) && strnicmp((const char*)buffer.Data(), "identifier,", 11 )) return false;
|
||||
auto data = parseCSV(buffer);
|
||||
if (size < 11) return false;
|
||||
if (strnicmp(buffer, "default,", 8) && strnicmp(buffer, "identifier,", 11 )) return false;
|
||||
auto data = parseCSV(buffer, size);
|
||||
|
||||
int labelcol = -1;
|
||||
int filtercol = -1;
|
||||
|
@ -282,14 +282,14 @@ bool FStringTable::ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FStringTable::LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer)
|
||||
void FStringTable::LoadLanguage (int lumpnum, const char* buffer, size_t size)
|
||||
{
|
||||
bool errordone = false;
|
||||
TArray<uint32_t> activeMaps;
|
||||
FScanner sc;
|
||||
bool hasDefaultEntry = false;
|
||||
|
||||
sc.OpenMem("LANGUAGE", buffer);
|
||||
sc.OpenMem("LANGUAGE", buffer, (int)size);
|
||||
sc.SetCMode (true);
|
||||
while (sc.GetString ())
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include "basics.h"
|
||||
#include "zstring.h"
|
||||
#include "tarray.h"
|
||||
|
@ -111,11 +112,10 @@ private:
|
|||
LangMap allStrings;
|
||||
TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet;
|
||||
|
||||
void LoadLanguage (int lumpnum, const TArray<uint8_t> &buffer);
|
||||
TArray<TArray<FString>> parseCSV(const TArray<uint8_t> &buffer);
|
||||
bool ParseLanguageCSV(int lumpnum, const TArray<uint8_t> &buffer);
|
||||
void LoadLanguage (int lumpnum, const char* buffer, size_t size);
|
||||
TArray<TArray<FString>> parseCSV(const char* buffer, size_t size);
|
||||
bool ParseLanguageCSV(int lumpnum, const char* buffer, size_t size);
|
||||
|
||||
bool LoadLanguageFromSpreadsheet(int lumpnum, const TArray<uint8_t> &buffer);
|
||||
bool readMacros(int lumpnum);
|
||||
void DeleteString(int langid, FName label);
|
||||
void DeleteForLabel(int lumpnum, FName label);
|
||||
|
|
|
@ -1294,32 +1294,6 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray<FolderEntry> &r
|
|||
return result.Size();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// GetFileData
|
||||
//
|
||||
// Loads the lump into a TArray and returns it.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
TArray<uint8_t> FileSystem::GetFileData(int lump, int pad)
|
||||
{
|
||||
if ((size_t)lump >= FileInfo.Size())
|
||||
return TArray<uint8_t>();
|
||||
|
||||
auto lumpr = OpenFileReader(lump);
|
||||
auto size = lumpr.GetLength();
|
||||
TArray<uint8_t> data(size + pad, true);
|
||||
auto numread = lumpr.Read(data.Data(), size);
|
||||
|
||||
if (numread != size)
|
||||
{
|
||||
throw FileSystemException("GetFileData: only read %ld of %ld on lump %i\n",
|
||||
numread, size, lump);
|
||||
}
|
||||
if (pad > 0) memset(&data[size], 0, pad);
|
||||
return data;
|
||||
}
|
||||
//==========================================================================
|
||||
//
|
||||
// W_ReadFile
|
||||
|
@ -1352,7 +1326,7 @@ void FileSystem::ReadFile (int lump, void *dest)
|
|||
|
||||
FileData FileSystem::ReadFile (int lump)
|
||||
{
|
||||
return FileData(FString(ELumpNum(lump)));
|
||||
return FileData(FString(*this, ELumpNum(lump)));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -1578,7 +1552,7 @@ FileData::~FileData ()
|
|||
{
|
||||
}
|
||||
|
||||
FString::FString (ELumpNum lumpnum)
|
||||
FString::FString (FileSystem& fileSystem, ELumpNum lumpnum)
|
||||
{
|
||||
auto lumpr = fileSystem.OpenFileReader ((int)lumpnum);
|
||||
auto size = lumpr.GetLength ();
|
||||
|
|
|
@ -125,16 +125,10 @@ public:
|
|||
inline int GetNumForFullName (const FString &name) { return GetNumForFullName(name.GetChars()); }
|
||||
|
||||
void ReadFile (int lump, void *dest);
|
||||
TArray<uint8_t> GetFileData(int lump, int pad = 0); // reads lump into a writable buffer and optionally adds some padding at the end. (FileData isn't writable!)
|
||||
// These should only be used if the file data really needs padding.
|
||||
FileData ReadFile (int lump);
|
||||
FileData ReadFile (const char *name) { return ReadFile (GetNumForName (name)); }
|
||||
|
||||
inline TArray<uint8_t> LoadFile(const char* name, int padding = 0)
|
||||
{
|
||||
auto lump = FindFile(name);
|
||||
if (lump < 0) return TArray<uint8_t>();
|
||||
return GetFileData(lump, padding);
|
||||
}
|
||||
FileData ReadFileFullName(const char* name) { return ReadFile(GetNumForFullName(name)); }
|
||||
|
||||
FileReader OpenFileReader(int lump); // opens a reader that redirects to the containing file's one.
|
||||
FileReader ReopenFileReader(int lump, bool alwayscache = false); // opens an independent reader.
|
||||
|
|
|
@ -140,15 +140,15 @@ int FQOITexture::CopyPixels(FBitmap *bmp, int conversion)
|
|||
|
||||
constexpr auto QOI_COLOR_HASH = [](PalEntry C) { return (C.r * 3 + C.g * 5 + C.b * 7 + C.a * 11); };
|
||||
|
||||
auto lump = fileSystem.OpenFileReader(SourceLump);
|
||||
auto bytes = lump.Read();
|
||||
if (bytes.size() < 22) return 0; // error
|
||||
auto lump = fileSystem.ReadFile(SourceLump);
|
||||
if (lump.GetSize() < 22) return 0; // error
|
||||
PalEntry index[64] = {};
|
||||
PalEntry pe = 0xff000000;
|
||||
|
||||
size_t p = 14, run = 0;
|
||||
|
||||
size_t chunks_len = bytes.size() - 8;
|
||||
size_t chunks_len = lump.GetSize() - 8;
|
||||
auto bytes = (const uint8_t*)lump.GetMem();
|
||||
|
||||
for (int h = 0; h < Height; h++)
|
||||
{
|
||||
|
|
|
@ -117,6 +117,8 @@ enum ELumpNum
|
|||
{
|
||||
};
|
||||
|
||||
class FileSystem;
|
||||
|
||||
class FString
|
||||
{
|
||||
public:
|
||||
|
@ -146,7 +148,7 @@ public:
|
|||
FString (char head, const FString &tail);
|
||||
|
||||
// Other constructors
|
||||
FString (ELumpNum); // Create from a lump
|
||||
FString (FileSystem&, ELumpNum); // Create from a lump
|
||||
|
||||
~FString ();
|
||||
|
||||
|
|
|
@ -314,8 +314,8 @@ FIWadManager::FIWadManager(const char *firstfn, const char *optfn)
|
|||
int num = check.CheckNumForName("IWADINFO");
|
||||
if (num >= 0)
|
||||
{
|
||||
auto data = check.GetFileData(num);
|
||||
ParseIWadInfo("IWADINFO", (const char*)data.Data(), data.Size());
|
||||
auto data = check.ReadFile(num);
|
||||
ParseIWadInfo("IWADINFO", data.GetString(), (int)data.GetSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -399,8 +399,8 @@ int FIWadManager::CheckIWADInfo(const char* fn)
|
|||
{
|
||||
|
||||
FIWADInfo result;
|
||||
auto data = check.GetFileData(num);
|
||||
ParseIWadInfo(fn, (const char*)data.Data(), data.Size(), &result);
|
||||
auto data = check.ReadFile(num);
|
||||
ParseIWadInfo(fn, data.GetString(), (int)data.GetSize(), &result);
|
||||
|
||||
for (unsigned i = 0, count = mIWadInfos.Size(); i < count; ++i)
|
||||
{
|
||||
|
|
|
@ -1934,9 +1934,9 @@ static FString CheckGameInfo(TArray<FString> & pwads)
|
|||
if (num >= 0)
|
||||
{
|
||||
// Found one!
|
||||
auto data = check.GetFileData(num);
|
||||
auto data = check.ReadFile(num);
|
||||
auto wadname = check.GetResourceFileName(check.GetFileContainer(num));
|
||||
return ParseGameInfo(pwads, wadname, (const char*)data.Data(), data.Size());
|
||||
return ParseGameInfo(pwads, wadname, data.GetString(), (int)data.GetSize());
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
|
|
@ -78,7 +78,7 @@ bool FParseContext::FindSym (char *sym, FParseSymbol **val)
|
|||
//
|
||||
//
|
||||
//==========================================================================
|
||||
int FParseContext::GetToken (char *&sourcep, FParseToken *yylval)
|
||||
int FParseContext::GetToken (const char *&sourcep, FParseToken *yylval)
|
||||
{
|
||||
char token[80];
|
||||
int toksize;
|
||||
|
@ -103,7 +103,7 @@ loop:
|
|||
c = *sourcep++;
|
||||
if (c == 'x' || c == 'X')
|
||||
{
|
||||
yylval->val = (int)strtoll(sourcep, &sourcep, 16);
|
||||
yylval->val = (int)strtoll(sourcep, (char**)&sourcep, 16);
|
||||
return TokenTrans[NUM];
|
||||
}
|
||||
else
|
||||
|
@ -118,7 +118,7 @@ loop:
|
|||
if (*endp == '.')
|
||||
{
|
||||
// It's a float
|
||||
yylval->fval = strtod(sourcep, &sourcep);
|
||||
yylval->fval = strtod(sourcep, (char**)& sourcep);
|
||||
return TokenTrans[FLOATVAL];
|
||||
}
|
||||
else
|
||||
|
@ -323,12 +323,12 @@ void FParseContext::ParseLump(const char *lumpname)
|
|||
}
|
||||
|
||||
// Read the lump into a buffer and add a 0-terminator
|
||||
auto lumpdata = fileSystem.GetFileData(lumpno, 1);
|
||||
auto lumpdata = fileSystem.ReadFile(lumpno);
|
||||
|
||||
SourceLine = 0;
|
||||
SourceFile = lumpname;
|
||||
|
||||
char *sourcep = (char*)lumpdata.Data();
|
||||
const char *sourcep = lumpdata.GetString();
|
||||
while ( (tokentype = GetToken(sourcep, &token)) )
|
||||
{
|
||||
// It is much easier to handle include statements outside the main parser.
|
||||
|
|
|
@ -146,7 +146,7 @@ struct FParseContext
|
|||
void AddSym (char *sym, int val);
|
||||
bool FindSym (char *sym, FParseSymbol **val);
|
||||
virtual bool FindToken (char *tok, int *type) = 0;
|
||||
int GetToken (char *&sourcep, FParseToken *yylval);
|
||||
int GetToken (const char *&sourcep, FParseToken *yylval);
|
||||
int PrintError (const char *s);
|
||||
void ParseLump(const char *lumpname);
|
||||
};
|
||||
|
|
|
@ -410,7 +410,6 @@ void DFsScript::Preprocess(FLevelLocals *Level)
|
|||
void DFsScript::ParseInclude(FLevelLocals *Level, char *lumpname)
|
||||
{
|
||||
int lumpnum;
|
||||
char *lump;
|
||||
|
||||
if((lumpnum = fileSystem.CheckNumForName(lumpname)) == -1)
|
||||
{
|
||||
|
@ -419,21 +418,18 @@ void DFsScript::ParseInclude(FLevelLocals *Level, char *lumpname)
|
|||
}
|
||||
|
||||
int lumplen=fileSystem.FileLength(lumpnum);
|
||||
lump=new char[lumplen+10];
|
||||
fileSystem.ReadFile(lumpnum,lump);
|
||||
TArray<char> lump(lumplen + 10);
|
||||
fileSystem.ReadFile(lumpnum,lump.Data());
|
||||
|
||||
lump[lumplen]=0;
|
||||
|
||||
// preprocess the include
|
||||
// we assume that it does not include sections or labels or
|
||||
// other nasty things
|
||||
ProcessFindChar(lump, 0);
|
||||
ProcessFindChar(lump.Data(), 0);
|
||||
|
||||
// now parse the lump
|
||||
FParser parse(Level, this);
|
||||
parse.Run(lump, lump, lump+lumplen);
|
||||
|
||||
// free the lump
|
||||
delete[] lump;
|
||||
parse.Run(lump.Data(), lump.Data(), lump.Data() + lumplen);
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,8 @@ void S_Init()
|
|||
TArray<uint8_t> curve;
|
||||
if (curvelump >= 0)
|
||||
{
|
||||
curve = fileSystem.GetFileData(curvelump);
|
||||
curve.Resize(fileSystem.FileLength(curvelump));
|
||||
fileSystem.ReadFile(curvelump, curve.Data());
|
||||
}
|
||||
soundEngine->Init(curve);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue