From 6355671480eb328eafc4a9f6634057026e14f318 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 19 Aug 2023 19:32:17 +0200 Subject: [PATCH] - second backend update from GZDoom. --- source/common/audio/music/i_music.cpp | 7 ++--- source/common/engine/sc_man.cpp | 2 +- source/common/engine/stringtable.cpp | 26 ++++++++--------- source/common/engine/stringtable.h | 7 ++--- source/common/filesystem/filesystem.cpp | 28 ------------------- source/common/filesystem/filesystem.h | 15 ++++------ source/common/rendering/gl/gl_shader.cpp | 24 ++++++++-------- .../common/rendering/gl/gl_shaderprogram.cpp | 2 +- source/common/rendering/gles/gles_shader.cpp | 24 ++++++++-------- .../rendering/gles/gles_shaderprogram.cpp | 2 +- .../rendering/vulkan/shaders/vk_ppshader.cpp | 2 +- .../common/scripting/interface/vmnatives.cpp | 2 +- source/common/textures/formats/qoitexture.cpp | 8 +++--- 13 files changed, 57 insertions(+), 92 deletions(-) diff --git a/source/common/audio/music/i_music.cpp b/source/common/audio/music/i_music.cpp index fd9395970..68f28f79d 100644 --- a/source/common/audio/music/i_music.cpp +++ b/source/common/audio/music/i_music.cpp @@ -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() diff --git a/source/common/engine/sc_man.cpp b/source/common/engine/sc_man.cpp index 98de9f0b1..bc50c7925 100644 --- a/source/common/engine/sc_man.cpp +++ b/source/common/engine/sc_man.cpp @@ -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. // //========================================================================== diff --git a/source/common/engine/stringtable.cpp b/source/common/engine/stringtable.cpp index 97ba64d27..68cec6db8 100644 --- a/source/common/engine/stringtable.cpp +++ b/source/common/engine/stringtable.cpp @@ -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> FStringTable::parseCSV(const std::vector &buffer) +TArray> FStringTable::parseCSV(const char* buffer, size_t size) { - const size_t bufLength = buffer.size(); + const size_t bufLength = size; TArray> data; TArray row; TArray cell; @@ -158,8 +158,8 @@ TArray> FStringTable::parseCSV(const std::vector &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 &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 &buf // //========================================================================== -void FStringTable::LoadLanguage (int lumpnum, const std::vector &buffer) +void FStringTable::LoadLanguage (int lumpnum, const char* buffer, size_t size) { bool errordone = false; TArray activeMaps; FScanner sc; bool hasDefaultEntry = false; - sc.OpenMem("LANGUAGE", buffer); + sc.OpenMem("LANGUAGE", buffer, (int)size); sc.SetCMode (true); while (sc.GetString ()) { diff --git a/source/common/engine/stringtable.h b/source/common/engine/stringtable.h index 6b083ce5c..df1508ae8 100644 --- a/source/common/engine/stringtable.h +++ b/source/common/engine/stringtable.h @@ -112,11 +112,10 @@ private: LangMap allStrings; TArray> currentLanguageSet; - void LoadLanguage (int lumpnum, const std::vector &buffer); - TArray> parseCSV(const std::vector &buffer); - bool ParseLanguageCSV(int lumpnum, const std::vector &buffer); + void LoadLanguage (int lumpnum, const char* buffer, size_t size); + TArray> parseCSV(const char* buffer, size_t size); + bool ParseLanguageCSV(int lumpnum, const char* buffer, size_t size); - bool LoadLanguageFromSpreadsheet(int lumpnum, const std::vector &buffer); bool readMacros(int lumpnum); void DeleteString(int langid, FName label); void DeleteForLabel(int lumpnum, FName label); diff --git a/source/common/filesystem/filesystem.cpp b/source/common/filesystem/filesystem.cpp index c86d5b145..156b05262 100644 --- a/source/common/filesystem/filesystem.cpp +++ b/source/common/filesystem/filesystem.cpp @@ -1294,34 +1294,6 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray &r return result.Size(); } -//========================================================================== -// -// GetFileData -// -// Loads the lump into a TArray and returns it. -// -//========================================================================== - -std::vector FileSystem::GetFileData(int lump, int pad) -{ - std::vector 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 diff --git a/source/common/filesystem/filesystem.h b/source/common/filesystem/filesystem.h index adc3706d3..febb76911 100644 --- a/source/common/filesystem/filesystem.h +++ b/source/common/filesystem/filesystem.h @@ -35,9 +35,9 @@ public: FileData (const FileData ©); FileData &operator= (const FileData ©); ~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 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 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 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. diff --git a/source/common/rendering/gl/gl_shader.cpp b/source/common/rendering/gl/gl_shader.cpp index d1b6aee54..85ba5c1eb 100644 --- a/source/common/rendering/gl/gl_shader.cpp +++ b/source/common/rendering/gl/gl_shader.cpp @@ -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) diff --git a/source/common/rendering/gl/gl_shaderprogram.cpp b/source/common/rendering/gl/gl_shaderprogram.cpp index 2b6df3254..69729a8c7 100644 --- a/source/common/rendering/gl/gl_shaderprogram.cpp +++ b/source/common/rendering/gl/gl_shaderprogram.cpp @@ -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); } diff --git a/source/common/rendering/gles/gles_shader.cpp b/source/common/rendering/gles/gles_shader.cpp index 61c1a720e..16ff0eb65 100644 --- a/source/common/rendering/gles/gles_shader.cpp +++ b/source/common/rendering/gles/gles_shader.cpp @@ -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) diff --git a/source/common/rendering/gles/gles_shaderprogram.cpp b/source/common/rendering/gles/gles_shaderprogram.cpp index 16bd1ebe9..8677257f3 100644 --- a/source/common/rendering/gles/gles_shaderprogram.cpp +++ b/source/common/rendering/gles/gles_shaderprogram.cpp @@ -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); } diff --git a/source/common/rendering/vulkan/shaders/vk_ppshader.cpp b/source/common/rendering/vulkan/shaders/vk_ppshader.cpp index 287762f77..f83b01c93 100644 --- a/source/common/rendering/vulkan/shaders/vk_ppshader.cpp +++ b/source/common/rendering/vulkan/shaders/vk_ppshader.cpp @@ -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); diff --git a/source/common/scripting/interface/vmnatives.cpp b/source/common/scripting/interface/vmnatives.cpp index f04e39d45..4dcd568e4 100644 --- a/source/common/scripting/interface/vmnatives.cpp +++ b/source/common/scripting/interface/vmnatives.cpp @@ -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() : ""); } //========================================================================== diff --git a/source/common/textures/formats/qoitexture.cpp b/source/common/textures/formats/qoitexture.cpp index 223a0b70e..abe628223 100644 --- a/source/common/textures/formats/qoitexture.cpp +++ b/source/common/textures/formats/qoitexture.cpp @@ -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++) {