mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-22 09:11:21 +00:00
Use lookup tables, macros, and for loops to shorten up the wad search code.
The old inline mess needed to go badly.
This commit is contained in:
parent
6504557393
commit
20987eba92
1 changed files with 59 additions and 81 deletions
|
@ -143,6 +143,33 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
|
||||||
#define UNIXBACKTRACE
|
#define UNIXBACKTRACE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Locations to directly check for srb2.pk3 in
|
||||||
|
const char *wadDefaultPaths[] = {
|
||||||
|
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
||||||
|
"/usr/local/share/games/SRB2",
|
||||||
|
"/usr/local/games/SRB2",
|
||||||
|
"/usr/share/games/SRB2",
|
||||||
|
"/usr/games/SRB2",
|
||||||
|
#elif defined (_WIN32)
|
||||||
|
"c:\\games\\srb2",
|
||||||
|
"\\games\\srb2",
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
// Folders to recurse through looking for srb2.pk3
|
||||||
|
const char *wadSearchPaths[] = {
|
||||||
|
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
||||||
|
"/usr/local/games",
|
||||||
|
"/usr/games",
|
||||||
|
"/usr/local",
|
||||||
|
#elif defined (_WIN32)
|
||||||
|
"c:\\games",
|
||||||
|
"\\games",
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
// Locations for searching the srb2.pk3
|
// Locations for searching the srb2.pk3
|
||||||
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
||||||
#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2"
|
#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2"
|
||||||
|
@ -2804,6 +2831,20 @@ static const char *searchWad(const char *searchDir)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHECKWADPATH(ret) \
|
||||||
|
do { \
|
||||||
|
I_OutputMsg(",%s", returnWadPath); \
|
||||||
|
if (isWadPathOk(returnWadPath)) \
|
||||||
|
return ret; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define SEARCHWAD(str) \
|
||||||
|
do { \
|
||||||
|
WadPath = searchWad(str); \
|
||||||
|
if (WadPath) \
|
||||||
|
return WadPath; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/** \brief go through all possible paths and look for srb2.pk3
|
/** \brief go through all possible paths and look for srb2.pk3
|
||||||
|
|
||||||
\return path to srb2.pk3 if any
|
\return path to srb2.pk3 if any
|
||||||
|
@ -2812,6 +2853,7 @@ static const char *locateWad(void)
|
||||||
{
|
{
|
||||||
const char *envstr;
|
const char *envstr;
|
||||||
const char *WadPath;
|
const char *WadPath;
|
||||||
|
int i;
|
||||||
|
|
||||||
I_OutputMsg("SRB2WADDIR");
|
I_OutputMsg("SRB2WADDIR");
|
||||||
// does SRB2WADDIR exist?
|
// does SRB2WADDIR exist?
|
||||||
|
@ -2819,108 +2861,44 @@ static const char *locateWad(void)
|
||||||
return envstr;
|
return envstr;
|
||||||
|
|
||||||
#ifndef NOCWD
|
#ifndef NOCWD
|
||||||
I_OutputMsg(",.");
|
|
||||||
// examine current dir
|
// examine current dir
|
||||||
strcpy(returnWadPath, ".");
|
strcpy(returnWadPath, ".");
|
||||||
if (isWadPathOk(returnWadPath))
|
CHECKWADPATH(NULL);
|
||||||
return NULL;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef CMAKECONFIG
|
#ifdef CMAKECONFIG
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
I_OutputMsg(","CMAKE_ASSETS_DIR);
|
|
||||||
strcpy(returnWadPath, CMAKE_ASSETS_DIR);
|
strcpy(returnWadPath, CMAKE_ASSETS_DIR);
|
||||||
if (isWadPathOk(returnWadPath))
|
CHECKWADPATH(returnWadPath);
|
||||||
{
|
|
||||||
return returnWadPath;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
OSX_GetResourcesPath(returnWadPath);
|
OSX_GetResourcesPath(returnWadPath);
|
||||||
I_OutputMsg(",%s", returnWadPath);
|
CHECKWADPATH(returnWadPath);
|
||||||
if (isWadPathOk(returnWadPath))
|
|
||||||
{
|
|
||||||
return returnWadPath;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// examine default dirs
|
// examine default dirs
|
||||||
#ifdef DEFAULTWADLOCATION1
|
for (i = 0; wadDefaultPaths[i]; i++)
|
||||||
I_OutputMsg(","DEFAULTWADLOCATION1);
|
{
|
||||||
strcpy(returnWadPath, DEFAULTWADLOCATION1);
|
strcpy(returnWadPath, wadDefaultPaths[i]);
|
||||||
if (isWadPathOk(returnWadPath))
|
CHECKWADPATH(returnWadPath);
|
||||||
return returnWadPath;
|
}
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTWADLOCATION2
|
|
||||||
I_OutputMsg(","DEFAULTWADLOCATION2);
|
|
||||||
strcpy(returnWadPath, DEFAULTWADLOCATION2);
|
|
||||||
if (isWadPathOk(returnWadPath))
|
|
||||||
return returnWadPath;
|
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTWADLOCATION3
|
|
||||||
I_OutputMsg(","DEFAULTWADLOCATION3);
|
|
||||||
strcpy(returnWadPath, DEFAULTWADLOCATION3);
|
|
||||||
if (isWadPathOk(returnWadPath))
|
|
||||||
return returnWadPath;
|
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTWADLOCATION4
|
|
||||||
I_OutputMsg(","DEFAULTWADLOCATION4);
|
|
||||||
strcpy(returnWadPath, DEFAULTWADLOCATION4);
|
|
||||||
if (isWadPathOk(returnWadPath))
|
|
||||||
return returnWadPath;
|
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTWADLOCATION5
|
|
||||||
I_OutputMsg(","DEFAULTWADLOCATION5);
|
|
||||||
strcpy(returnWadPath, DEFAULTWADLOCATION5);
|
|
||||||
if (isWadPathOk(returnWadPath))
|
|
||||||
return returnWadPath;
|
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTWADLOCATION6
|
|
||||||
I_OutputMsg(","DEFAULTWADLOCATION6);
|
|
||||||
strcpy(returnWadPath, DEFAULTWADLOCATION6);
|
|
||||||
if (isWadPathOk(returnWadPath))
|
|
||||||
return returnWadPath;
|
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTWADLOCATION7
|
|
||||||
I_OutputMsg(","DEFAULTWADLOCATION7);
|
|
||||||
strcpy(returnWadPath, DEFAULTWADLOCATION7);
|
|
||||||
if (isWadPathOk(returnWadPath))
|
|
||||||
return returnWadPath;
|
|
||||||
#endif
|
|
||||||
#ifndef NOHOME
|
#ifndef NOHOME
|
||||||
// find in $HOME
|
// find in $HOME
|
||||||
I_OutputMsg(",HOME");
|
I_OutputMsg(",HOME");
|
||||||
if ((envstr = I_GetEnv("HOME")) != NULL)
|
if ((envstr = I_GetEnv("HOME")) != NULL)
|
||||||
|
SEARCHWAD(envstr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// search paths
|
||||||
|
for (i = 0; wadSearchPaths[i]; i++)
|
||||||
{
|
{
|
||||||
WadPath = searchWad(envstr);
|
I_OutputMsg(", in:%s", wadSearchPaths[i]);
|
||||||
if (WadPath)
|
SEARCHWAD(wadSearchPaths[i]);
|
||||||
return WadPath;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTSEARCHPATH1
|
|
||||||
// find in /usr/local
|
|
||||||
I_OutputMsg(", in:"DEFAULTSEARCHPATH1);
|
|
||||||
WadPath = searchWad(DEFAULTSEARCHPATH1);
|
|
||||||
if (WadPath)
|
|
||||||
return WadPath;
|
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTSEARCHPATH2
|
|
||||||
// find in /usr/games
|
|
||||||
I_OutputMsg(", in:"DEFAULTSEARCHPATH2);
|
|
||||||
WadPath = searchWad(DEFAULTSEARCHPATH2);
|
|
||||||
if (WadPath)
|
|
||||||
return WadPath;
|
|
||||||
#endif
|
|
||||||
#ifdef DEFAULTSEARCHPATH3
|
|
||||||
// find in ???
|
|
||||||
I_OutputMsg(", in:"DEFAULTSEARCHPATH3);
|
|
||||||
WadPath = searchWad(DEFAULTSEARCHPATH3);
|
|
||||||
if (WadPath)
|
|
||||||
return WadPath;
|
|
||||||
#endif
|
|
||||||
// if nothing was found
|
// if nothing was found
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue