FileSystem: Make path caching optional via config
Because Windows has case insensitive paths, this should be turned on (which it is by default) for maximum compatibility. Can be turned off as an optimization (this will speed up startup a little depending on the number of game assets).
This commit is contained in:
parent
f163c51eed
commit
ce7bf97dd4
|
@ -80,6 +80,7 @@ mkxp reads configuration data from the file "mkxp.conf" contained in the current
|
|||
| solidFonts | bool | false | Don't use alpha blending for fonts |
|
||||
| gameFolder | string | "." | mkxp will look for all game related files here |
|
||||
| allowSymlinks | bool | false | Allow symlinks to be followed in the game folder. |
|
||||
| pathCache | bool | true | Scan and cache asset paths at startup. Allows for case insensitive paths. |
|
||||
| customScript | string | "" | Execute a raw ruby script file instead of an RPG Maker game. |
|
||||
| RTP | string | "" | Path to a Run Time Package to be used. Can be specified multiple times. |
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ Config::Config()
|
|||
frameSkip(true),
|
||||
solidFonts(false),
|
||||
gameFolder("."),
|
||||
allowSymlinks(false)
|
||||
allowSymlinks(false),
|
||||
pathCache(true)
|
||||
{}
|
||||
|
||||
void Config::read()
|
||||
|
@ -64,7 +65,8 @@ void Config::read()
|
|||
PO_DESC(solidFonts, bool) \
|
||||
PO_DESC(gameFolder, std::string) \
|
||||
PO_DESC(allowSymlinks, bool) \
|
||||
PO_DESC(customScript, std::string)
|
||||
PO_DESC(customScript, std::string) \
|
||||
PO_DESC(pathCache, bool)
|
||||
|
||||
#define PO_DESC(key, type) (#key, po::value< type >()->default_value(key))
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ struct Config
|
|||
|
||||
std::string gameFolder;
|
||||
bool allowSymlinks;
|
||||
bool pathCache;
|
||||
|
||||
std::string customScript;
|
||||
std::vector<std::string> rtps;
|
||||
|
|
|
@ -498,7 +498,11 @@ struct FileSystemPrivate
|
|||
/* All keys are lower case */
|
||||
BoostHash<std::string, std::string> pathCache;
|
||||
|
||||
std::vector<std::string> extensions[FileSystem::Undefined];
|
||||
std::vector<std::string> extensions[FileSystem::Undefined+1];
|
||||
|
||||
// FIXME Need to find a better way to do this..
|
||||
char pathBuffer[512];
|
||||
bool havePathCache;
|
||||
|
||||
/* Attempt to locate an extension string in a filename.
|
||||
* Either a pointer into the input string pointing at the
|
||||
|
@ -523,6 +527,39 @@ struct FileSystemPrivate
|
|||
FileSystem::FileType type,
|
||||
const char **foundExt)
|
||||
{
|
||||
if (!havePathCache)
|
||||
{
|
||||
if (PHYSFS_exists(filename))
|
||||
{
|
||||
if (foundExt)
|
||||
*foundExt = findExt(filename);
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
const std::vector<std::string> &extList = extensions[type];
|
||||
for (size_t i = 0; i < extList.size(); ++i)
|
||||
{
|
||||
const char *ext = extList[i].c_str();
|
||||
|
||||
snprintf(pathBuffer, sizeof(pathBuffer), "%s.%s", filename, ext);
|
||||
|
||||
if (PHYSFS_exists(pathBuffer))
|
||||
{
|
||||
if (foundExt)
|
||||
*foundExt = ext;
|
||||
|
||||
return pathBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
// Is this even necessary?
|
||||
if (foundExt)
|
||||
*foundExt = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char buff[512];
|
||||
size_t i;
|
||||
|
||||
|
@ -533,6 +570,8 @@ struct FileSystemPrivate
|
|||
|
||||
std::string key(buff);
|
||||
|
||||
/* If the path was already complete,
|
||||
* we are done at this point */
|
||||
if (pathCache.contains(key))
|
||||
{
|
||||
/* The extension might already be included here,
|
||||
|
@ -545,6 +584,8 @@ struct FileSystemPrivate
|
|||
|
||||
char buff2[512];
|
||||
|
||||
/* Try supplementing extensions
|
||||
* to find an existing path */
|
||||
if (type != FileSystem::Undefined)
|
||||
{
|
||||
std::vector<std::string> &extList = extensions[type];
|
||||
|
@ -594,6 +635,8 @@ FileSystem::FileSystem(const char *argv0,
|
|||
{
|
||||
p = new FileSystemPrivate;
|
||||
|
||||
p->havePathCache = false;
|
||||
|
||||
/* Image extensions */
|
||||
p->extensions[Image].push_back("jpg");
|
||||
p->extensions[Image].push_back("png");
|
||||
|
@ -671,6 +714,8 @@ static void cacheEnumCB(void *d, const char *origdir,
|
|||
void FileSystem::createPathCache()
|
||||
{
|
||||
PHYSFS_enumerateFilesCallback(".", cacheEnumCB, p);
|
||||
|
||||
p->havePathCache = true;
|
||||
}
|
||||
|
||||
static inline PHYSFS_File *sdlPHYS(SDL_RWops *ops)
|
||||
|
|
|
@ -118,6 +118,7 @@ struct SharedStatePrivate
|
|||
for (size_t i = 0; i < config.rtps.size(); ++i)
|
||||
fileSystem.addPath(config.rtps[i].c_str());
|
||||
|
||||
if (config.pathCache)
|
||||
fileSystem.createPathCache();
|
||||
|
||||
globalTexW = 128;
|
||||
|
|
Loading…
Reference in New Issue