- second backend update from GZDoom.

This commit is contained in:
Christoph Oelckers 2023-08-19 19:32:17 +02:00
parent 32ede813e9
commit 6355671480
13 changed files with 57 additions and 92 deletions

View file

@ -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()+8);
}
static void SetupWgOpn()

View file

@ -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.
//
//==========================================================================

View 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 std::vector<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 std::vector<uint8_t> &buffe
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 std::vector<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 std::vector<uint8_t> &buf
//
//==========================================================================
void FStringTable::LoadLanguage (int lumpnum, const std::vector<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 ())
{

View file

@ -112,11 +112,10 @@ private:
LangMap allStrings;
TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet;
void LoadLanguage (int lumpnum, const std::vector<uint8_t> &buffer);
TArray<TArray<FString>> parseCSV(const std::vector<uint8_t> &buffer);
bool ParseLanguageCSV(int lumpnum, const std::vector<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 std::vector<uint8_t> &buffer);
bool readMacros(int lumpnum);
void DeleteString(int langid, FName label);
void DeleteForLabel(int lumpnum, FName label);

View file

@ -1294,34 +1294,6 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray<FolderEntry> &r
return result.Size();
}
//==========================================================================
//
// GetFileData
//
// Loads the lump into a TArray and returns it.
//
//==========================================================================
std::vector<uint8_t> FileSystem::GetFileData(int lump, int pad)
{
std::vector<uint8_t> data;
if ((size_t)lump >= FileInfo.Size())
return data;
auto lumpr = OpenFileReader(lump);
auto size = lumpr.GetLength();
data.resize(size + pad);
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

View file

@ -35,9 +35,9 @@ public:
FileData (const FileData &copy);
FileData &operator= (const FileData &copy);
~FileData ();
void *GetMem () { return Block.Len() == 0 ? NULL : (void *)Block.GetChars(); }
const void *GetMem () { return Block.Len() == 0 ? NULL : (void *)Block.GetChars(); }
size_t GetSize () { return Block.Len(); }
const FString &GetString () const { return Block; }
const char* GetString () const { return Block.GetChars(); }
private:
FileData (const FString &source);
@ -125,15 +125,10 @@ public:
inline int GetNumForFullName (const FString &name) { return GetNumForFullName(name.GetChars()); }
void ReadFile (int lump, void *dest);
std::vector<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!)
std::vector<uint8_t> GetFileData(const char* name, int pad = 0) { return GetFileData(GetNumForName(name), pad); }
// These should only be used if the file data really needs padding.
FileData ReadFile (int lump);
inline std::vector<uint8_t> LoadFile(const char* name, int padding = 0)
{
auto lump = GetNumForFullName(name);
return GetFileData(lump, padding);
}
FileData ReadFile (const char *name) { return ReadFile (GetNumForName (name)); }
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.

View file

@ -423,27 +423,27 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump, 0); // if it's a core shader, ignore overrides by user mods.
if (pp_lump == -1) pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump);
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump);
FileData pp_data = fileSystem.ReadFile(pp_lump);
FString pp_data = fileSystem.ReadFile(pp_lump).GetString();
if (pp_data.GetString().IndexOf("ProcessMaterial") < 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0)
if (pp_data.IndexOf("ProcessMaterial") < 0 && pp_data.IndexOf("SetupMaterial") < 0)
{
// this looks like an old custom hardware shader.
if (pp_data.GetString().IndexOf("GetTexCoord") >= 0)
if (pp_data.IndexOf("GetTexCoord") >= 0)
{
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat2.fp", 0);
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat2.fp");
FileData pl_data = fileSystem.ReadFile(pl_lump);
fp_comb << "\n" << pl_data.GetString().GetChars();
fp_comb << "\n" << pl_data.GetString();
}
else
{
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat.fp", 0);
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat.fp");
FileData pl_data = fileSystem.ReadFile(pl_lump);
fp_comb << "\n" << pl_data.GetString().GetChars();
fp_comb << "\n" << pl_data.GetString();
if (pp_data.GetString().IndexOf("ProcessTexel") < 0)
if (pp_data.IndexOf("ProcessTexel") < 0)
{
// this looks like an even older custom hardware shader.
// We need to replace the ProcessTexel call to make it work.
@ -452,7 +452,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
}
}
if (pp_data.GetString().IndexOf("ProcessLight") >= 0)
if (pp_data.IndexOf("ProcessLight") >= 0)
{
// The ProcessLight signatured changed. Forward to the old one.
fp_comb << "\nvec4 ProcessLight(vec4 color);\n";
@ -460,19 +460,19 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
}
}
fp_comb << RemoveLegacyUserUniforms(pp_data.GetString()).GetChars();
fp_comb << RemoveLegacyUserUniforms(pp_data).GetChars();
fp_comb.Substitute("gl_TexCoord[0]", "vTexCoord"); // fix old custom shaders.
if (pp_data.GetString().IndexOf("ProcessLight") < 0)
if (pp_data.IndexOf("ProcessLight") < 0)
{
int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultlight.fp", 0);
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultlight.fp");
FileData pl_data = fileSystem.ReadFile(pl_lump);
fp_comb << "\n" << pl_data.GetString().GetChars();
fp_comb << "\n" << pl_data.GetString();
}
// ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about.
if (pp_data.GetString().IndexOf("ProcessMaterial") >= 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0)
if (pp_data.IndexOf("ProcessMaterial") >= 0 && pp_data.IndexOf("SetupMaterial") < 0)
{
// This reactivates the old logic and disables all features that cannot be supported with that method.
placeholder << "#define LEGACY_USER_SHADER\n";
@ -491,7 +491,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0);
if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog);
FileData pp_data = fileSystem.ReadFile(pp_lump);
fp_comb << pp_data.GetString().GetChars() << "\n";
fp_comb << pp_data.GetString() << "\n";
}
if (gl.flags & RFL_NO_CLIP_PLANES)

View file

@ -88,7 +88,7 @@ void FShaderProgram::Compile(ShaderType type, const char *lumpName, const char *
{
int lump = fileSystem.CheckNumForFullName(lumpName);
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName);
FString code = fileSystem.ReadFile(lump).GetString().GetChars();
FString code = fileSystem.ReadFile(lump).GetString();
Compile(type, lumpName, code, defines, maxGlslVersion);
}

View file

@ -422,27 +422,27 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
{
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump);
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump.GetChars());
FileData pp_data = fileSystem.ReadFile(pp_lump);
FString pp_data = fileSystem.ReadFile(pp_lump).GetString();
if (pp_data.GetString().IndexOf("ProcessMaterial") < 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0)
if (pp_data.IndexOf("ProcessMaterial") < 0 && pp_data.IndexOf("SetupMaterial") < 0)
{
// this looks like an old custom hardware shader.
if (pp_data.GetString().IndexOf("GetTexCoord") >= 0)
if (pp_data.IndexOf("GetTexCoord") >= 0)
{
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultmat2.fp", 0);
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultmat2.fp");
FileData pl_data = fileSystem.ReadFile(pl_lump);
fp_comb << "\n" << pl_data.GetString().GetChars();
fp_comb << "\n" << pl_data.GetString();
}
else
{
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultmat.fp", 0);
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultmat.fp");
FileData pl_data = fileSystem.ReadFile(pl_lump);
fp_comb << "\n" << pl_data.GetString().GetChars();
fp_comb << "\n" << pl_data.GetString();
if (pp_data.GetString().IndexOf("ProcessTexel") < 0)
if (pp_data.IndexOf("ProcessTexel") < 0)
{
// this looks like an even older custom hardware shader.
// We need to replace the ProcessTexel call to make it work.
@ -451,7 +451,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
}
}
if (pp_data.GetString().IndexOf("ProcessLight") >= 0)
if (pp_data.IndexOf("ProcessLight") >= 0)
{
// The ProcessLight signatured changed. Forward to the old one.
fp_comb << "\nvec4 ProcessLight(vec4 color);\n";
@ -459,19 +459,19 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
}
}
fp_comb << RemoveLegacyUserUniforms(pp_data.GetString()).GetChars();
fp_comb << RemoveLegacyUserUniforms(pp_data).GetChars();
fp_comb.Substitute("gl_TexCoord[0]", "vTexCoord"); // fix old custom shaders.
if (pp_data.GetString().IndexOf("ProcessLight") < 0)
if (pp_data.IndexOf("ProcessLight") < 0)
{
int pl_lump = fileSystem.CheckNumForFullName("shaders_gles/glsl/func_defaultlight.fp", 0);
if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders_gles/glsl/func_defaultlight.fp");
FileData pl_data = fileSystem.ReadFile(pl_lump);
fp_comb << "\n" << pl_data.GetString().GetChars();
fp_comb << "\n" << pl_data.GetString();
}
// ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about.
if (pp_data.GetString().IndexOf("ProcessMaterial") >= 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0)
if (pp_data.IndexOf("ProcessMaterial") >= 0 && pp_data.IndexOf("SetupMaterial") < 0)
{
// This reactivates the old logic and disables all features that cannot be supported with that method.
placeholder << "#define LEGACY_USER_SHADER\n";
@ -490,7 +490,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
int pp_lump = fileSystem.CheckNumForFullName(light_fragprog, 0);
if (pp_lump == -1) I_Error("Unable to load '%s'", light_fragprog.GetChars());
FileData pp_data = fileSystem.ReadFile(pp_lump);
fp_comb << pp_data.GetString().GetChars() << "\n";
fp_comb << pp_data.GetString() << "\n";
}
if (gles.flags & RFL_NO_CLIP_PLANES)

View file

@ -88,7 +88,7 @@ void FShaderProgram::Compile(ShaderType type, const char *lumpName, const char *
{
int lump = fileSystem.CheckNumForFullName(lumpName);
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName);
FString code = fileSystem.ReadFile(lump).GetString().GetChars();
FString code = fileSystem.ReadFile(lump).GetString();
Compile(type, lumpName, code, defines, maxGlslVersion);
}

View file

@ -66,7 +66,7 @@ FString VkPPShader::LoadShaderCode(const FString &lumpName, const FString &defin
{
int lump = fileSystem.CheckNumForFullName(lumpName);
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName.GetChars());
FString code = fileSystem.ReadFile(lump).GetString().GetChars();
FString code = fileSystem.ReadFile(lump).GetString();
FString patchedCode;
patchedCode.AppendFormat("#version %d\n", 450);

View file

@ -843,7 +843,7 @@ DEFINE_ACTION_FUNCTION(_Wads, ReadLump)
PARAM_PROLOGUE;
PARAM_INT(lump);
const bool isLumpValid = lump >= 0 && lump < fileSystem.GetNumEntries();
ACTION_RETURN_STRING(isLumpValid ? fileSystem.ReadFile(lump).GetString() : FString());
ACTION_RETURN_STRING(isLumpValid ? fileSystem.ReadFile(lump).GetString() : "");
}
//==========================================================================

View file

@ -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++)
{