- renamed the remaining file system access wrappers in cache1d.h

This commit is contained in:
Christoph Oelckers 2019-12-07 10:31:27 +01:00
parent 749eda32c5
commit 30cbcb54b1
21 changed files with 65 additions and 90 deletions

View file

@ -1685,7 +1685,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
break;
}
if (fileName == NULL || check_file_exist(fileName))
if (fileName == NULL || fileSystem.FileExists(fileName))
break;
if (S_DefineMusic(musicID, fileName) == -1)
@ -1937,7 +1937,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
break;
}
if (fileName == NULL || check_file_exist(fileName))
if (fileName == NULL || fileSystem.FileExists(fileName))
break;
// maybe I should have just packed this into a sound_t and passed a reference...

View file

@ -69,7 +69,7 @@ CGameMenuItemQAV::CGameMenuItemQAV(int a3, int a4, const char* name, bool widesc
if (name)
{
// NBlood read this directly from the file system cache, but let's better store the data locally for robustness.
raw = kloadfile(name, 0);
raw = fileSystem.LoadFile(name, 0);
if (raw.Size() != 0)
{
auto data = (QAV*)raw.Data();

View file

@ -70,7 +70,7 @@ IniFile *BloodINI;
void levelInitINI(const char *pzIni)
{
if (!testkopen(pzIni, 0))
if (!fileSystem.FileExists(pzIni))
ThrowError("Initialization: %s does not exist", pzIni);
BloodINI = new IniFile(pzIni);
Bstrncpy(BloodIniFile, pzIni, BMAX_PATH);

View file

@ -27,31 +27,5 @@ inline FileReader fopenFileReader(const char* name, int where)
return fr;
}
inline bool testkopen(const char* name, int where)
{
// todo: if backed by a single file, we must actually open it to make sure.
return fileSystem.FindFile(name) >= 0;
}
inline TArray<uint8_t> kloadfile(const char* name, int where)
{
auto lump = fileSystem.FindFile(name);
if (lump < 0) return TArray<uint8_t>();
return fileSystem.GetFileData(lump);
}
inline int32_t kfilesize(const char* name, int where)
{
auto lump = fileSystem.FindFile(name);
if (lump < 0) return -1;
return fileSystem.FileLength(lump);
}
// checks from path and in ZIPs, returns 1 if NOT found
inline int32_t check_file_exist(const char* fn)
{
return fileSystem.FindFile(fn) >= 0;
}
#endif // cache1d_h_

View file

@ -355,7 +355,7 @@ static int32_t defsparser(scriptfile *script)
if (scriptfile_getnumber(script,&fnoo)) break; //y-size
if (scriptfile_getstring(script,&fn)) break;
if (check_file_exist(fn))
if (fileSystem.FileExists(fn))
break;
tileSetHightileReplacement(tile,pal,fn,-1.0,1.0,1.0,1.0,1.0,0);
@ -373,7 +373,7 @@ static int32_t defsparser(scriptfile *script)
{
if (scriptfile_getstring(script,&fn[i])) break; //grab the 6 faces
if (check_file_exist(fn[i]))
if (fileSystem.FileExists(fn[i]))
happy = 0;
}
if (i < 6 || !happy) break;
@ -1098,7 +1098,7 @@ static int32_t defsparser(scriptfile *script)
if (seenframe) { modelskin = ++lastmodelskin; }
seenframe = 0;
if (check_file_exist(skinfn))
if (fileSystem.FileExists(skinfn))
break;
#ifdef USE_OPENGL
@ -1473,7 +1473,7 @@ static int32_t defsparser(scriptfile *script)
break;
}
if (check_file_exist(skinfn))
if (fileSystem.FileExists(skinfn))
break;
#ifdef USE_OPENGL
@ -1791,7 +1791,7 @@ static int32_t defsparser(scriptfile *script)
{
if (EDUKE32_PREDICT_FALSE(!fn[i])) initprintf("Error: skybox: missing '%s filename' near line %s:%d\n", skyfaces[i], script->filename, scriptfile_getlinum(script,skyboxtokptr)), happy = 0;
// FIXME?
if (check_file_exist(fn[i]))
if (fileSystem.FileExists(fn[i]))
happy = 0;
}
if (!happy) break;
@ -1846,7 +1846,7 @@ static int32_t defsparser(scriptfile *script)
break;
}
if (check_file_exist(fn))
if (fileSystem.FileExists(fn))
break;
}
@ -2101,7 +2101,7 @@ static int32_t defsparser(scriptfile *script)
break;
}
if (EDUKE32_PREDICT_FALSE(check_file_exist(fn)))
if (EDUKE32_PREDICT_FALSE(fileSystem.FileExists(fn)))
break;
if (xsiz > 0 && ysiz > 0)
@ -2164,7 +2164,7 @@ static int32_t defsparser(scriptfile *script)
break;
}
if (EDUKE32_PREDICT_FALSE(check_file_exist(fn)))
if (EDUKE32_PREDICT_FALSE(fileSystem.FileExists(fn)))
break;
switch (token)

View file

@ -95,12 +95,25 @@ public:
int FindFile (const char *name, ELookupMode lookupmode = ELookupMode::FullName, int filenum = -1) const noexcept;
int GetFile (const char *name, ELookupMode lookupmode = ELookupMode::FullName, int filenum = -1) const; // Like FindFile, but throws an exception when it cannot find what it looks for.
bool FileExists(const char* name)
{
return FindFile(name) >= 0;
}
int FindFile (const FString &name, ELookupMode lookupmode = ELookupMode::FullName, int filenum = -1) const noexcept { return FindFile(name.GetChars(), lookupmode, filenum); }
int GetFile (const FString &name, ELookupMode lookupmode = ELookupMode::FullName, int filenum = -1) const { return GetFile(name.GetChars(), lookupmode, filenum); }
bool FileExists(const FString & name)
{
return FindFile(name) >= 0;
}
int FindFile (const std::string &name, ELookupMode lookupmode = ELookupMode::FullName, int filenum = -1) const noexcept { return FindFile(name.c_str(), lookupmode, filenum); }
int GetFile (const std::string &name, ELookupMode lookupmode = ELookupMode::FullName, int filenum = -1) const { return GetFile(name.c_str(), lookupmode, filenum); }
bool FileExists(const std::string& name)
{
return FindFile(name) >= 0;
}
int FindResource (int resid, const char *type, int filenum = -1) const noexcept;
int GetResource (int resid, const char *type, int filenum = -1) const; // Like FindFile, but throws an exception when it cannot find what it looks for.
@ -112,6 +125,15 @@ public:
TArray<uint8_t> GetFileData(int file, int pad = 0); // reads file into a writable buffer and optionally adds some padding at the end. (FileData isn't writable!)
FileData ReadFile (int file);
FileData ReadFile (const char *name) { return ReadFile (GetFile (name)); }
inline TArray<uint8_t> LoadFile(const char* name, int padding)
{
auto lump = FindFile(name);
if (lump < 0) return TArray<uint8_t>();
return GetFileData(lump, padding);
}
const void *Lock(int lump);
void Unlock(int lump, bool mayfree = false);

View file

@ -125,7 +125,7 @@ FSingleLumpFont::FSingleLumpFont (const char *name, const char * lump)
FontName = name;
rawData = kloadfile(lump, 0);
rawData = fileSystem.LoadFile(lump, 0);
auto& data = rawData;
if (data[0] == 0xE1 && data[1] == 0xE6 && data[2] == 0xD5 && data[3] == 0x1A)

View file

@ -114,14 +114,14 @@ const char *G_DefaultRtsFile(void)
return defaultrtsfilename[GAME_WW2GI];
else if (NAPALM)
{
if (!testkopen(defaultrtsfilename[GAME_NAPALM],0) && testkopen(defaultrtsfilename[GAME_NAM],0))
if (!fileSystem.FileExists(defaultrtsfilename[GAME_NAPALM]) && fileSystem.FileExists(defaultrtsfilename[GAME_NAM]))
return defaultrtsfilename[GAME_NAM]; // NAM/NAPALM Sharing
else
return defaultrtsfilename[GAME_NAPALM];
}
else if (NAM)
{
if (!testkopen(defaultrtsfilename[GAME_NAM],0) && testkopen(defaultrtsfilename[GAME_NAPALM],0))
if (!fileSystem.FileExists(defaultrtsfilename[GAME_NAM]) && fileSystem.FileExists(defaultrtsfilename[GAME_NAPALM]))
return defaultrtsfilename[GAME_NAPALM]; // NAM/NAPALM Sharing
else
return defaultrtsfilename[GAME_NAM];
@ -5065,7 +5065,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
break;
}
if (fileName == NULL || check_file_exist(fileName))
if (fileName == NULL || fileSystem.FileExists(fileName))
break;
if (S_DefineMusic(musicID, fileName) == -1)
@ -5213,7 +5213,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
break;
}
if (fileName == NULL || check_file_exist(fileName))
if (fileName == NULL || fileSystem.FileExists(fileName))
break;
// maybe I should have just packed this into a sound_t and passed a reference...
@ -5682,7 +5682,7 @@ static void G_Startup(void)
Bcorrectfilename(boardfilename,0);
if (testkopen(boardfilename, 0))
if (fileSystem.FileExists(boardfilename))
{
initprintf("Using level: \"%s\".\n",boardfilename);
}
@ -5875,7 +5875,7 @@ int GameInterface::app_main()
g_Shareware = 1;
else
{
if (testkopen("DUKESW.BIN", 1)) // JBF 20030810
if (fileSystem.FileExists("DUKESW.BIN")) // JBF 20030810
{
g_Shareware = 1;
}

View file

@ -1986,7 +1986,7 @@ static void Net_ReceiveUserMapName(uint8_t *pbuf, int32_t packbufleng)
Bcorrectfilename(boardfilename, 0);
if (boardfilename[0] != 0)
{
if (testkopen(boardfilename, 0))
if (fileSystem.FileExists(boardfilename))
{
Bmemset(boardfilename, 0, sizeof(boardfilename));
Net_SendUserMapName();

View file

@ -124,7 +124,7 @@ static int osdcmd_map(osdcmdptr_t parm)
maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map");
if (!testkopen(filename,0))
if (!fileSystem.FileExists(filename))
{
OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", filename);
return OSDCMD_OK;

View file

@ -1721,7 +1721,7 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName)
{
Bmemcpy(p+1, ext, Bstrlen(ext) + 1);
if (testkopen(nameBuf, 0))
if (fileSystem.FileExists(nameBuf))
{
realloc_copy(&g_mapInfo[USERMAPMUSICFAKESLOT].musicfn, nameBuf);
return;

View file

@ -1303,7 +1303,7 @@ void gameDisplay3DRScreen()
{
Net_GetPackets();
if (testkopen("3dr.ivf", 0) || testkopen("3dr.anm", 0))
if (fileSystem.FileExists("3dr.ivf") || fileSystem.FileExists("3dr.anm"))
{
Anim_Play("3dr.anm");
G_FadePalette(0, 0, 0, 252);

View file

@ -104,8 +104,8 @@ void GLInstance::Init(int ydim)
ImGui_ImplOpenGL3_Init();
if (!ttf.Size())
{
//ttf = kloadfile("demolition/Capsmall_clean.ttf", 0);
ttf = kloadfile("demolition/Roboto-Regular.ttf", 0);
//ttf = fileSystem.LoadFile("demolition/Capsmall_clean.ttf", 0);
ttf = fileSystem.LoadFile("demolition/Roboto-Regular.ttf", 0);
}
if (ttf.Size()) io.Fonts->AddFontFromMemoryTTF(ttf.Data(), ttf.Size(), std::clamp(ydim / 40, 10, 30));
}

View file

@ -109,14 +109,14 @@ const char *G_DefaultRtsFile(void)
return defaultrtsfilename[GAME_DUKE];
else if (NAPALM)
{
if (!testkopen(defaultrtsfilename[GAME_NAPALM],0) && testkopen(defaultrtsfilename[GAME_NAM],0))
if (!fileSystem.FileExists(defaultrtsfilename[GAME_NAPALM]) && fileSystem.FileExists(defaultrtsfilename[GAME_NAM]))
return defaultrtsfilename[GAME_NAM]; // NAM/NAPALM Sharing
else
return defaultrtsfilename[GAME_NAPALM];
}
else if (NAM)
{
if (!testkopen(defaultrtsfilename[GAME_NAM],0) && testkopen(defaultrtsfilename[GAME_NAPALM],0))
if (!fileSystem.FileExists(defaultrtsfilename[GAME_NAM]) && fileSystem.FileExists(defaultrtsfilename[GAME_NAPALM]))
return defaultrtsfilename[GAME_NAPALM]; // NAM/NAPALM Sharing
else
return defaultrtsfilename[GAME_NAM];
@ -6598,7 +6598,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
break;
}
if (fileName == NULL || check_file_exist(fileName))
if (fileName == NULL || fileSystem.FileExists(fileName))
break;
if (S_DefineMusic(musicID, fileName) == -1)
@ -6746,7 +6746,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
break;
}
if (fileName == NULL || check_file_exist(fileName))
if (fileName == NULL || fileSystem.FileExists(fileName))
break;
// maybe I should have just packed this into a sound_t and passed a reference...
@ -7119,7 +7119,7 @@ static void G_Startup(void)
Bcorrectfilename(boardfilename,0);
if (testkopen(boardfilename, 0))
if (fileSystem.FileExists(boardfilename))
{
initprintf("Using level: \"%s\".\n",boardfilename);
}
@ -7326,7 +7326,7 @@ int GameInterface::app_main()
g_Shareware = 1;
else
{
if (testkopen("DUKESW.BIN",1)) // JBF 20030810
if (fileSystem.FileExists("DUKESW.BIN")) // JBF 20030810
{
g_Shareware = 1;
}

View file

@ -2594,7 +2594,7 @@ void Net_ParsePacket(uint8_t *packbuf, int packbufleng)
Bcorrectfilename(boardfilename,0);
if (boardfilename[0] != 0)
{
if (testkopen(boardfilename,0))
if (fileSystem.FileExists(boardfilename,0))
{
Bmemset(boardfilename,0,sizeof(boardfilename));
Net_SendUserMapName();
@ -3519,7 +3519,7 @@ void Net_ReceiveUserMapName(uint8_t *pbuf, int32_t packbufleng)
Bcorrectfilename(boardfilename,0);
if (boardfilename[0] != 0)
{
if (testkopen(boardfilename,0))
if (fileSystem.FileExists(boardfilename))
{
Bmemset(boardfilename,0,sizeof(boardfilename));
Net_SendUserMapName();

View file

@ -157,7 +157,7 @@ static int osdcmd_map(osdcmdptr_t parm)
maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map");
if (!testkopen(filename,0))
if (!fileSystem.FileExists(filename))
{
OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", filename);
return OSDCMD_OK;

View file

@ -2280,7 +2280,7 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum
{
Bmemcpy(p+1, ext, Bstrlen(ext) + 1);
if (testkopen(nameBuf, 0))
if (fileSystem.FileExists(nameBuf))
{
realloc_copy(&g_mapInfo[levelNum].musicfn, nameBuf);
return;

View file

@ -1393,7 +1393,7 @@ void G_DisplayLogo(void)
{
Net_GetPackets();
if (testkopen("3dr.ivf", 0) || testkopen("3dr.anm", 0))
if (fileSystem.FileExists("3dr.ivf") || fileSystem.FileExists("3dr.anm"))
{
Anim_Play("3dr.anm");
G_FadePalette(0, 0, 0, 252);

View file

@ -226,7 +226,7 @@ void AnimZilla(int frame, int numframes)
}
}
unsigned char *LoadAnm(short anim_num)
unsigned char *LoadAnm(short anim_num, int *lengthp)
{
int length;
unsigned char *animbuf, *palptr;
@ -246,7 +246,7 @@ unsigned char *LoadAnm(short anim_num)
auto handle = fileSystem.OpenFileReader(ANIMname[ANIMnum], 0);
if (!handle.isOpen())
return NULL;
length = handle.GetLength();
*lengthp = length = handle.GetLength();
buffer.Resize(length + sizeof(anim_t));
anm_ptr[anim_num] = (anim_t*)buffer.Data();
@ -280,14 +280,10 @@ playanm(short anim_num)
DSPRINTF(ds,"PlayAnm");
MONO_PRINT(ds);
animbuf = LoadAnm(anim_num);
animbuf = LoadAnm(anim_num, &length);
if (!animbuf)
return;
// [JM] Temporary, needed to get the file's length for ANIM_LoadAnim. !CHECKME!
length = kfilesize(ANIMname[ANIMnum], 0);
if (length == -1) return;
DSPRINTF(ds,"PlayAnm - Palette Stuff");
MONO_PRINT(ds);

View file

@ -30,6 +30,6 @@ BEGIN_SW_NS
#define ANIM_SUMO 2
#define ANIM_ZILLA 3
unsigned char *LoadAnm(short anim_num);
unsigned char *LoadAnm(short anim_num, int *);
void playanm(short anim_num);
END_SW_NS

View file

@ -1615,9 +1615,9 @@ void LogoLevel(void)
MONO_PRINT(ds);
// PreCache Anim
LoadAnm(0);
LoadAnm(0, &fin);
auto pal = kloadfile("3drealms.pal", 0);
auto pal = fileSystem.LoadFile("3drealms.pal", 0);
if (pal.Size() >= 768)
{
@ -2991,24 +2991,7 @@ char isShareware = FALSE;
int DetectShareware(void)
{
#define DOS_SCREEN_NAME_SW "SHADSW.BIN"
#define DOS_SCREEN_NAME_REG "SWREG.BIN"
int h;
if (testkopen(DOS_SCREEN_NAME_SW, 1))
{
isShareware = TRUE;
return 0;
}
if (testkopen(DOS_SCREEN_NAME_REG, 1))
{
isShareware = FALSE;
return 0;
}
return 1; // heavens knows what this is...
return (isShareware = !!(g_gameType & GAMEFLAG_SHAREWARE));
}