mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-31 13:50:48 +00:00
cleaned up some redundant file reads and fixed file opening in the movie player.
As a streaming action this cannot borrow the one from the archive.
This commit is contained in:
parent
3e7ec9118f
commit
df3e82d94c
10 changed files with 31 additions and 17 deletions
|
@ -515,7 +515,7 @@ public:
|
|||
}
|
||||
else if (soundtrack >= 0)
|
||||
{
|
||||
FileReader reader = fileSystem.OpenFileReader(soundtrack);
|
||||
FileReader reader = fileSystem.ReopenFileReader(soundtrack);
|
||||
if (reader.isOpen())
|
||||
{
|
||||
MusicStream = ZMusic_OpenSong(GetMusicReader(reader), MDEV_DEFAULT, nullptr);
|
||||
|
@ -838,10 +838,10 @@ MoviePlayer* OpenMovie(const char* filename, TArray<int>& ans, const int* framet
|
|||
{
|
||||
auto fn = StripExtension(filename);
|
||||
DefaultExtension(fn, ".ivf");
|
||||
fr = fileSystem.OpenFileReader(fn.GetChars());
|
||||
fr = fileSystem.ReopenFileReader(fn.GetChars());
|
||||
}
|
||||
|
||||
if (!fr.isOpen()) fr = fileSystem.OpenFileReader(filename);
|
||||
if (!fr.isOpen()) fr = fileSystem.ReopenFileReader(filename);
|
||||
if (!fr.isOpen())
|
||||
{
|
||||
size_t nLen = strlen(filename);
|
||||
|
@ -849,7 +849,7 @@ MoviePlayer* OpenMovie(const char* filename, TArray<int>& ans, const int* framet
|
|||
if (nLen >= 3 && isalpha(filename[0]) && filename[1] == ':' && filename[2] == '/')
|
||||
{
|
||||
filename += 3;
|
||||
fr = fileSystem.OpenFileReader(filename);
|
||||
fr = fileSystem.ReopenFileReader(filename);
|
||||
}
|
||||
if (!fr.isOpen())
|
||||
{
|
||||
|
|
|
@ -200,10 +200,10 @@ void FScanner :: OpenLumpNum (int lump)
|
|||
{
|
||||
Close ();
|
||||
{
|
||||
auto mem = fileSystem.OpenFileReader(lump);
|
||||
auto buff = ScriptBuffer.LockNewBuffer(mem.GetLength());
|
||||
mem.Read(buff, mem.GetLength());
|
||||
buff[mem.GetLength()] = 0;
|
||||
auto len = fileSystem.FileLength(lump);
|
||||
auto buff = ScriptBuffer.LockNewBuffer(len);
|
||||
fileSystem.ReadFile(lump, buff);
|
||||
buff[len] = 0;
|
||||
ScriptBuffer.UnlockBuffer();
|
||||
}
|
||||
ScriptName = fileSystem.GetFileFullPath(lump).c_str();
|
||||
|
|
|
@ -96,6 +96,7 @@ public:
|
|||
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.
|
||||
FileReader OpenFileReader(const char* name);
|
||||
FileReader ReopenFileReader(const char* name, bool alwayscache = false);
|
||||
|
||||
int FindLump (const char *name, int *lastlump, bool anyns=false); // [RH] Find lumps with duplication
|
||||
int FindLumpMulti (const char **names, int *lastlump, bool anyns = false, int *nameindex = NULL); // same with multiple possible names
|
||||
|
|
|
@ -1329,9 +1329,18 @@ FileReader FileSystem::ReopenFileReader(int lump, bool alwayscache)
|
|||
|
||||
FileReader FileSystem::OpenFileReader(const char* name)
|
||||
{
|
||||
FileReader fr;
|
||||
auto lump = CheckNumForFullName(name);
|
||||
if (lump < 0) return FileReader();
|
||||
else return OpenFileReader(lump);
|
||||
if (lump >= 0) fr = OpenFileReader(lump);
|
||||
return fr;
|
||||
}
|
||||
|
||||
FileReader FileSystem::ReopenFileReader(const char* name, bool alwayscache)
|
||||
{
|
||||
FileReader fr;
|
||||
auto lump = CheckNumForFullName(name);
|
||||
if (lump >= 0) fr = ReopenFileReader(lump, alwayscache);
|
||||
return fr;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -89,7 +89,6 @@ 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);
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
|
||||
Compile(type, lumpName, code, defines, maxGlslVersion);
|
||||
|
|
|
@ -383,11 +383,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
|
||||
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump.GetChars(), 0);
|
||||
if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump.GetChars());
|
||||
auto vp_data = fileSystem.ReadFile(vp_lump);
|
||||
|
||||
int fp_lump = fileSystem.CheckNumForFullName(frag_prog_lump.GetChars(), 0);
|
||||
if (fp_lump == -1) I_Error("Unable to load '%s'", frag_prog_lump.GetChars());
|
||||
auto fp_data = fileSystem.ReadFile(fp_lump);
|
||||
|
||||
|
||||
|
||||
|
@ -422,7 +420,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump_, const char *
|
|||
{
|
||||
int pp_lump = fileSystem.CheckNumForFullName(proc_prog_lump.GetChars());
|
||||
if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump.GetChars());
|
||||
auto ppf = fileSystem.ReadFile(pp_lump);
|
||||
FString pp_data = GetStringFromLump(pp_lump);
|
||||
|
||||
if (pp_data.IndexOf("ProcessMaterial") < 0 && pp_data.IndexOf("SetupMaterial") < 0)
|
||||
|
|
|
@ -89,7 +89,6 @@ 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);
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
Compile(type, lumpName, code, defines, maxGlslVersion);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,6 @@ FString VkPPShader::LoadShaderCode(const FString &lumpName, const FString &defin
|
|||
{
|
||||
int lump = fileSystem.CheckNumForFullName(lumpName.GetChars());
|
||||
if (lump == -1) I_FatalError("Unable to load '%s'", lumpName.GetChars());
|
||||
auto sp = fileSystem.ReadFile(lump);
|
||||
FString code = GetStringFromLump(lump);
|
||||
|
||||
FString patchedCode;
|
||||
|
|
|
@ -475,7 +475,6 @@ FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname)
|
|||
{
|
||||
int lump = fileSystem.CheckNumForFullName(lumpname, 0);
|
||||
if (lump == -1) I_Error("Unable to load '%s'", lumpname);
|
||||
auto data = fileSystem.ReadFile(lump);
|
||||
return GetStringFromLump(lump);
|
||||
}
|
||||
|
||||
|
|
|
@ -4009,3 +4009,14 @@ CCMD(fs_dir)
|
|||
Printf(PRINT_HIGH | PRINT_NONOTIFY, "%s%-64s %-15s (%5d) %10d %s %s\n", hidden ? TEXTCOLOR_RED : TEXTCOLOR_UNTRANSLATED, fn1, fns, fnid, length, container, hidden ? "(h)" : "");
|
||||
}
|
||||
}
|
||||
|
||||
CCMD(type)
|
||||
{
|
||||
if (argv.argc() < 2) return;
|
||||
int lump = fileSystem.CheckNumForFullName(argv[1]);
|
||||
if (lump >= 0)
|
||||
{
|
||||
auto data = fileSystem.ReadFile(lump);
|
||||
Printf("%.*s\n", data.size(), data.string());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue