mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-22 01:01:45 +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
|
||||
#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
|
||||
#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)
|
||||
#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2"
|
||||
|
@ -2804,6 +2831,20 @@ static const char *searchWad(const char *searchDir)
|
|||
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
|
||||
|
||||
\return path to srb2.pk3 if any
|
||||
|
@ -2812,6 +2853,7 @@ static const char *locateWad(void)
|
|||
{
|
||||
const char *envstr;
|
||||
const char *WadPath;
|
||||
int i;
|
||||
|
||||
I_OutputMsg("SRB2WADDIR");
|
||||
// does SRB2WADDIR exist?
|
||||
|
@ -2819,108 +2861,44 @@ static const char *locateWad(void)
|
|||
return envstr;
|
||||
|
||||
#ifndef NOCWD
|
||||
I_OutputMsg(",.");
|
||||
// examine current dir
|
||||
strcpy(returnWadPath, ".");
|
||||
if (isWadPathOk(returnWadPath))
|
||||
return NULL;
|
||||
CHECKWADPATH(NULL);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CMAKECONFIG
|
||||
#ifndef NDEBUG
|
||||
I_OutputMsg(","CMAKE_ASSETS_DIR);
|
||||
strcpy(returnWadPath, CMAKE_ASSETS_DIR);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
{
|
||||
return returnWadPath;
|
||||
}
|
||||
CHECKWADPATH(returnWadPath);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
OSX_GetResourcesPath(returnWadPath);
|
||||
I_OutputMsg(",%s", returnWadPath);
|
||||
if (isWadPathOk(returnWadPath))
|
||||
{
|
||||
return returnWadPath;
|
||||
}
|
||||
CHECKWADPATH(returnWadPath);
|
||||
#endif
|
||||
|
||||
// examine default dirs
|
||||
#ifdef DEFAULTWADLOCATION1
|
||||
I_OutputMsg(","DEFAULTWADLOCATION1);
|
||||
strcpy(returnWadPath, DEFAULTWADLOCATION1);
|
||||
if (isWadPathOk(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
|
||||
for (i = 0; wadDefaultPaths[i]; i++)
|
||||
{
|
||||
strcpy(returnWadPath, wadDefaultPaths[i]);
|
||||
CHECKWADPATH(returnWadPath);
|
||||
}
|
||||
|
||||
#ifndef NOHOME
|
||||
// find in $HOME
|
||||
I_OutputMsg(",HOME");
|
||||
if ((envstr = I_GetEnv("HOME")) != NULL)
|
||||
SEARCHWAD(envstr);
|
||||
#endif
|
||||
|
||||
// search paths
|
||||
for (i = 0; wadSearchPaths[i]; i++)
|
||||
{
|
||||
WadPath = searchWad(envstr);
|
||||
if (WadPath)
|
||||
return WadPath;
|
||||
I_OutputMsg(", in:%s", wadSearchPaths[i]);
|
||||
SEARCHWAD(wadSearchPaths[i]);
|
||||
}
|
||||
#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
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue