- let FileData.GetString only return a const char pointer.

Not exposing the implementation will allow a lot more optimization in the backend and we also want to get rid of FString here.
This commit is contained in:
Christoph Oelckers 2023-08-19 18:46:21 +02:00
parent 5398045f7d
commit eccbafc1bc
8 changed files with 31 additions and 31 deletions

View File

@ -182,7 +182,7 @@ static void SetupGenMidi()
auto genmidi = fileSystem.ReadFile(lump);
if (genmidi.GetSize() < 8 + 175 * 36 || memcmp(genmidi.GetMem(), "#OPL_II#", 8)) return;
ZMusic_SetGenMidi((uint8_t*)genmidi.GetString().GetChars() + 8);
ZMusic_SetGenMidi((uint8_t*)genmidi.GetString() + 8);
}
static void SetupWgOpn()

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);

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() : "");
}
//==========================================================================