Skip to content

Commit

Permalink
Refactor: Return a reference from App_FileSystem()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Feb 24, 2013
1 parent 35266a8 commit cb28593
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 153 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/include/filesys/fs_main.h
Expand Up @@ -568,7 +568,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(FS1::Scheme::Flags)

} // namespace de

de::FS1 *App_FileSystem();
de::FS1 &App_FileSystem();

/**
* Returns the application's data base path in the format expected by FS1.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/audio/s_cache.cpp
Expand Up @@ -553,8 +553,8 @@ static sfxsample_t *cacheSample(int id, sfxinfo_t const *info)
{
try
{
String foundPath = App_FileSystem()->findPath(de::Uri(info->lumpName, RC_SOUND),
RLF_DEFAULT, DD_ResourceClassById(RC_SOUND));
String foundPath = App_FileSystem().findPath(de::Uri(info->lumpName, RC_SOUND),
RLF_DEFAULT, DD_ResourceClassById(RC_SOUND));
foundPath = App_BasePath() / foundPath; // Ensure the path is absolute.

data = WAV_Load(foundPath.toUtf8().constData(), &bytesPer, &rate, &numSamples);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/audio/s_mus.cpp
Expand Up @@ -252,8 +252,8 @@ int Mus_GetExt(ded_music_t *def, ddstring_t *retPath)
{
try
{
String foundPath = App_FileSystem()->findPath(de::Uri(def->lumpName, RC_MUSIC), RLF_DEFAULT,
DD_ResourceClassById(RC_MUSIC));
String foundPath = App_FileSystem().findPath(de::Uri(def->lumpName, RC_MUSIC), RLF_DEFAULT,
DD_ResourceClassById(RC_MUSIC));
foundPath = App_BasePath() / foundPath; // Ensure the path is absolute.

// Does the caller want to know the matched path?
Expand Down
66 changes: 33 additions & 33 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -404,7 +404,7 @@ FileTypes const& DD_FileTypes()

static void createPackagesScheme()
{
FS1::Scheme& scheme = App_FileSystem()->createScheme("Packages");
FS1::Scheme& scheme = App_FileSystem().createScheme("Packages");

/*
* Add default search paths.
Expand Down Expand Up @@ -507,7 +507,7 @@ void DD_CreateFileSystemSchemes()
struct schemedef_s const* def = defs;
for(int i = 0; defs[i].name; ++i, ++def)
{
FS1::Scheme& scheme = App_FileSystem()->createScheme(def->name, def->flags);
FS1::Scheme& scheme = App_FileSystem().createScheme(def->name, def->flags);

int searchPathCount = 0;
while(def->searchPaths[searchPathCount] && ++searchPathCount < schemedef_max_searchpaths)
Expand Down Expand Up @@ -761,7 +761,7 @@ static int findAllGameDataPaths(FS1::PathList &found)
for(uint extIdx = 0; !extensions[extIdx].isEmpty(); ++extIdx)
{
Path pattern = Path("$(App.DataPath)/$(GamePlugin.Name)/auto/*." + extensions[extIdx]);
App_FileSystem()->findAllPaths(de::Uri(pattern).resolved(), 0, found);
App_FileSystem().findAllPaths(de::Uri(pattern).resolved(), 0, found);
}
return found.count() - numFoundSoFar;
}
Expand Down Expand Up @@ -889,9 +889,9 @@ static int DD_LoadGameStartupResourcesWorker(void* parameters)
DENG_ASSERT(p);

// Reset file Ids so previously seen files can be processed again.
App_FileSystem()->resetFileIds();
App_FileSystem().resetFileIds();
initPathMappings();
App_FileSystem()->resetAllSchemes();
App_FileSystem().resetAllSchemes();

if(p->initiatedBusyMode)
Con_SetProgress(50);
Expand All @@ -901,10 +901,10 @@ static int DD_LoadGameStartupResourcesWorker(void* parameters)
// Create default Auto mappings in the runtime directory.

// Data class resources.
App_FileSystem()->addPathMapping("auto/", de::Uri("$(App.DataPath)/$(GamePlugin.Name)/auto/", RC_NULL).resolved());
App_FileSystem().addPathMapping("auto/", de::Uri("$(App.DataPath)/$(GamePlugin.Name)/auto/", RC_NULL).resolved());

// Definition class resources.
App_FileSystem()->addPathMapping("auto/", de::Uri("$(App.DefsPath)/$(GamePlugin.Name)/auto/", RC_NULL).resolved());
App_FileSystem().addPathMapping("auto/", de::Uri("$(App.DefsPath)/$(GamePlugin.Name)/auto/", RC_NULL).resolved());
}

/**
Expand Down Expand Up @@ -958,7 +958,7 @@ static int addListFiles(ddstring_t*** list, size_t* listSize, FileType const& ft
*/
static void initPathMappings()
{
App_FileSystem()->clearPathMappings();
App_FileSystem().clearPathMappings();

if(DD_IsShuttingDown()) return;

Expand All @@ -972,7 +972,7 @@ static void initPathMappings()
{
String source = NativePath(CommandLine_PathAt(i + 1)).expand().withSeparators('/');
String destination = NativePath(CommandLine_PathAt(i + 2)).expand().withSeparators('/');
App_FileSystem()->addPathMapping(source, destination);
App_FileSystem().addPathMapping(source, destination);
i += 2;
}
}
Expand Down Expand Up @@ -1048,7 +1048,7 @@ static bool parsePathLumpMappings(char const* buffer)
else
{
String destination = NativePath(Str_Text(&path)).expand().withSeparators('/');
App_FileSystem()->addPathLumpMapping(lumpName, destination);
App_FileSystem().addPathLumpMapping(lumpName, destination);
}
} while(*ch);

Expand All @@ -1068,15 +1068,15 @@ static bool parsePathLumpMappings(char const* buffer)
static void initPathLumpMappings()
{
// Free old paths, if any.
App_FileSystem()->clearPathLumpMappings();
App_FileSystem().clearPathLumpMappings();

if(DD_IsShuttingDown()) return;

size_t bufSize = 0;
uint8_t* buf = NULL;

// Add the contents of all DD_DIREC lumps.
DENG2_FOR_EACH_CONST(LumpIndex::Lumps, i, App_FileSystem()->nameIndex().lumps())
DENG2_FOR_EACH_CONST(LumpIndex::Lumps, i, App_FileSystem().nameIndex().lumps())
{
de::File1& lump = **i;
FileInfo const& lumpInfo = lump.info();
Expand Down Expand Up @@ -1139,7 +1139,7 @@ static int DD_LoadAddonResourcesWorker(void* parameters)

// Re-initialize the resource locator as there are now new resources to be found
// on existing search paths (probably that is).
App_FileSystem()->resetAllSchemes();
App_FileSystem().resetAllSchemes();

if(p->initiatedBusyMode)
{
Expand Down Expand Up @@ -1508,19 +1508,19 @@ bool DD_ChangeGame(de::Game& game, bool allowReload = false)
R_InitViewWindow();
#endif

App_FileSystem()->unloadAllNonStartupFiles();
App_FileSystem().unloadAllNonStartupFiles();

// Reset file IDs so previously seen files can be processed again.
/// @todo this releases the IDs of startup files too but given the
/// only startup file is doomsday.pk3 which we never attempt to load
/// again post engine startup, this isn't an immediate problem.
App_FileSystem()->resetFileIds();
App_FileSystem().resetFileIds();

// Update the dir/WAD translations.
initPathLumpMappings();
initPathMappings();

App_FileSystem()->resetAllSchemes();
App_FileSystem().resetAllSchemes();
}

FI_Shutdown();
Expand Down Expand Up @@ -1847,7 +1847,7 @@ boolean DD_Init(void)
DD_DummyWorker, 0, "Buffering...");

// Add resource paths specified using -iwad on the command line.
FS1::Scheme& scheme = App_FileSystem()->scheme(DD_ResourceClassByName("RC_PACKAGE").defaultScheme());
FS1::Scheme& scheme = App_FileSystem().scheme(DD_ResourceClassByName("RC_PACKAGE").defaultScheme());
for(int p = 0; p < CommandLine_Count(); ++p)
{
if(!CommandLine_IsMatchingAlias("-iwad", CommandLine_At(p)))
Expand Down Expand Up @@ -1932,13 +1932,13 @@ boolean DD_Init(void)

// Re-initialize the filesystem subspace schemess as there are now new
// resources to be found on existing search paths (probably that is).
App_FileSystem()->resetAllSchemes();
App_FileSystem().resetAllSchemes();

// One-time execution of various command line features available during startup.
if(CommandLine_CheckWith("-dumplump", 1))
{
String name = CommandLine_Next();
lumpnum_t lumpNum = App_FileSystem()->lumpNumForName(name);
lumpnum_t lumpNum = App_FileSystem().lumpNumForName(name);
if(lumpNum >= 0)
{
F_DumpLump(lumpNum);
Expand Down Expand Up @@ -2021,10 +2021,10 @@ boolean DD_Init(void)
// No game loaded.
// Lets get most of everything else initialized.
// Reset file IDs so previously seen files can be processed again.
App_FileSystem()->resetFileIds();
App_FileSystem().resetFileIds();
initPathLumpMappings();
initPathMappings();
App_FileSystem()->resetAllSchemes();
App_FileSystem().resetAllSchemes();

R_InitCompositeTextures();
R_InitFlatTextures();
Expand Down Expand Up @@ -2058,7 +2058,7 @@ static void DD_InitResourceSystem(void)

initPathMappings();

App_FileSystem()->resetAllSchemes();
App_FileSystem().resetAllSchemes();

// Initialize the definition databases.
Def_Init();
Expand Down Expand Up @@ -2108,8 +2108,8 @@ static int DD_StartupWorker(void* /*parm*/)
/*
* Add required engine resource files.
*/
String foundPath = App_FileSystem()->findPath(de::Uri("doomsday.pk3", RC_PACKAGE),
RLF_DEFAULT, DD_ResourceClassById(RC_PACKAGE));
String foundPath = App_FileSystem().findPath(de::Uri("doomsday.pk3", RC_PACKAGE),
RLF_DEFAULT, DD_ResourceClassById(RC_PACKAGE));
foundPath = App_BasePath() / foundPath; // Ensure the path is absolute.
de::File1 *loadedFile = tryLoadFile(de::Uri(foundPath, RC_NULL));
DENG2_ASSERT(loadedFile);
Expand Down Expand Up @@ -2260,14 +2260,14 @@ void DD_UpdateEngineState(void)
Demo_StopPlayback();
#endif

//App_FileSystem()->resetFileIds();
//App_FileSystem().resetFileIds();

// Update the dir/WAD translations.
initPathLumpMappings();
initPathMappings();

// Re-build the filesystem subspace schemes as there may be new resources to be found.
App_FileSystem()->resetAllSchemes();
App_FileSystem().resetAllSchemes();

R_InitCompositeTextures();
R_InitFlatTextures();
Expand Down Expand Up @@ -2810,7 +2810,7 @@ D_CMD(Load)
{
try
{
String foundPath = App_FileSystem()->findPath(de::Uri::fromNativePath(argv[arg], RC_PACKAGE),
String foundPath = App_FileSystem().findPath(de::Uri::fromNativePath(argv[arg], RC_PACKAGE),
RLF_MATCH_EXTENSION, DD_ResourceClassById(RC_PACKAGE));
foundPath = App_BasePath() / foundPath; // Ensure the path is absolute.

Expand All @@ -2835,18 +2835,18 @@ static de::File1* tryLoadFile(de::Uri const& search, size_t baseOffset)
{
try
{
de::FileHandle& hndl = App_FileSystem()->openFile(search.path(), "rb", baseOffset, false /* no duplicates */);
de::FileHandle& hndl = App_FileSystem().openFile(search.path(), "rb", baseOffset, false /* no duplicates */);

de::Uri foundFileUri = hndl.file().composeUri();
VERBOSE( Con_Message("Loading \"%s\"...\n", NativePath(foundFileUri.asText()).pretty().toUtf8().constData()) )

App_FileSystem()->index(hndl.file());
App_FileSystem().index(hndl.file());

return &hndl.file();
}
catch(FS1::NotFoundError const&)
{
if(App_FileSystem()->accessFile(search))
if(App_FileSystem().accessFile(search))
{
// Must already be loaded.
LOG_VERBOSE("\"%s\" already loaded.") << NativePath(search.asText()).pretty();
Expand All @@ -2859,7 +2859,7 @@ static bool tryUnloadFile(de::Uri const& search)
{
try
{
de::File1& file = App_FileSystem()->find(search);
de::File1& file = App_FileSystem().find(search);
de::Uri foundFileUri = file.composeUri();
QByteArray pathUtf8 = NativePath(foundFileUri.asText()).pretty().toUtf8();

Expand All @@ -2874,7 +2874,7 @@ static bool tryUnloadFile(de::Uri const& search)

VERBOSE2( Con_Message("Unloading \"%s\"...\n", pathUtf8.constData()) )

App_FileSystem()->deindex(file);
App_FileSystem().deindex(file);
delete &file;

VERBOSE2( Con_Message("Done unloading \"%s\".\n", pathUtf8.constData()) )
Expand Down Expand Up @@ -2938,7 +2938,7 @@ D_CMD(Unload)
{
try
{
String foundPath = App_FileSystem()->findPath(de::Uri::fromNativePath(argv[1], RC_PACKAGE),
String foundPath = App_FileSystem().findPath(de::Uri::fromNativePath(argv[1], RC_PACKAGE),
RLF_MATCH_EXTENSION, DD_ResourceClassById(RC_PACKAGE));
foundPath = App_BasePath() / foundPath; // Ensure the path is absolute.

Expand Down
20 changes: 10 additions & 10 deletions doomsday/client/src/dd_wad.cpp
Expand Up @@ -45,7 +45,7 @@ size_t W_LumpLength(lumpnum_t lumpNum)
{
try
{
return App_FileSystem()->nameIndex().lump(lumpNum).info().size;
return App_FileSystem().nameIndex().lump(lumpNum).info().size;
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -58,7 +58,7 @@ AutoStr* W_LumpName(lumpnum_t lumpNum)
{
try
{
String const& name = App_FileSystem()->nameIndex().lump(lumpNum).name();
String const& name = App_FileSystem().nameIndex().lump(lumpNum).name();
QByteArray nameUtf8 = name.toUtf8();
return AutoStr_FromTextStd(nameUtf8.constData());
}
Expand All @@ -73,7 +73,7 @@ uint W_LumpLastModified(lumpnum_t lumpNum)
{
try
{
return App_FileSystem()->nameIndex().lump(lumpNum).info().lastModified;
return App_FileSystem().nameIndex().lump(lumpNum).info().lastModified;
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -86,7 +86,7 @@ AutoStr* W_LumpSourceFile(lumpnum_t lumpNum)
{
try
{
de::File1 const& lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::File1 const& lump = App_FileSystem().nameIndex().lump(lumpNum);
QByteArray path = lump.container().composePath().toUtf8();
return AutoStr_FromText(path.constData());
}
Expand All @@ -101,7 +101,7 @@ boolean W_LumpIsCustom(lumpnum_t lumpNum)
{
try
{
de::File1 const& lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::File1 const& lump = App_FileSystem().nameIndex().lump(lumpNum);
return lump.container().hasCustom();
}
catch(LumpIndex::NotFoundError const&)
Expand All @@ -120,7 +120,7 @@ lumpnum_t W_CheckLumpNumForName2(char const* name, boolean silent)
VERBOSE2( Con_Message("Warning: W_CheckLumpNumForName: Empty name, returning invalid lumpnum.\n") )
return -1;
}
lumpNum = App_FileSystem()->lumpNumForName(name);
lumpNum = App_FileSystem().lumpNumForName(name);
if(!silent && lumpNum < 0)
VERBOSE2( Con_Message("Warning: W_CheckLumpNumForName: Lump \"%s\" not found.\n", name) )
return lumpNum;
Expand All @@ -145,7 +145,7 @@ size_t W_ReadLump(lumpnum_t lumpNum, uint8_t* buffer)
{
try
{
de::File1& lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::File1& lump = App_FileSystem().nameIndex().lump(lumpNum);
return lump.read(buffer, 0, lump.size());
}
catch(LumpIndex::NotFoundError const&)
Expand All @@ -159,7 +159,7 @@ size_t W_ReadLumpSection(lumpnum_t lumpNum, uint8_t* buffer, size_t startOffset,
{
try
{
de::File1& lump = App_FileSystem()->nameIndex().lump(lumpNum);
de::File1& lump = App_FileSystem().nameIndex().lump(lumpNum);
return lump.read(buffer, startOffset, length);
}
catch(LumpIndex::NotFoundError const&)
Expand All @@ -173,7 +173,7 @@ uint8_t const* W_CacheLump(lumpnum_t lumpNum)
{
try
{
return App_FileSystem()->nameIndex().lump(lumpNum).cache();
return App_FileSystem().nameIndex().lump(lumpNum).cache();
}
catch(LumpIndex::NotFoundError const&)
{
Expand All @@ -186,7 +186,7 @@ void W_UnlockLump(lumpnum_t lumpNum)
{
try
{
App_FileSystem()->nameIndex().lump(lumpNum).unlock();
App_FileSystem().nameIndex().lump(lumpNum).unlock();
}
catch(LumpIndex::NotFoundError const&)
{
Expand Down

0 comments on commit cb28593

Please sign in to comment.