diff --git a/doomsday/engine/portable/include/resourcenamespace.h b/doomsday/engine/portable/include/resourcenamespace.h index b169723db6..92aaa3f23c 100644 --- a/doomsday/engine/portable/include/resourcenamespace.h +++ b/doomsday/engine/portable/include/resourcenamespace.h @@ -78,7 +78,7 @@ typedef struct resourcenamespace_s { uint _extraSearchPathsCount; /// Path hash table. - filedirectory_t* _fileDirectory; + filedirectory_t* _directory; ddstring_t* (*_composeHashName) (const ddstring_t* path); resourcenamespace_namehash_key_t (*_hashName) (const ddstring_t* name); resourcenamespace_namehash_t _pathHash; @@ -88,22 +88,22 @@ typedef struct resourcenamespace_s { } resourcenamespace_t; resourcenamespace_t* ResourceNamespace_Construct(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name)); resourcenamespace_t* ResourceNamespace_Construct2(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, uint searchPathsCount); resourcenamespace_t* ResourceNamespace_Construct3(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, uint searchPathsCount, byte flags); resourcenamespace_t* ResourceNamespace_Construct4(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, uint searchPathsCount, byte flags, const char* overrideName); resourcenamespace_t* ResourceNamespace_Construct5(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, uint searchPathsCount, byte flags, const char* overrideName, const char* overrideName2); @@ -162,4 +162,7 @@ boolean ResourceNamespace_MapPath(resourcenamespace_t* rnamespace, ddstring_t* p /// @return Ptr to a string containing the symbolic name. const ddstring_t* ResourceNamespace_Name(const resourcenamespace_t* rnamespace); +/// @return Ptr to the path directory used with this namespace. +filedirectory_t* ResourceNamespace_Directory(const resourcenamespace_t* rnamespace); + #endif /* LIBDENG_SYSTEM_RESOURCENAMESPACE_H */ diff --git a/doomsday/engine/portable/include/sys_reslocator.h b/doomsday/engine/portable/include/sys_reslocator.h index bd35c83bed..3edd942a2d 100644 --- a/doomsday/engine/portable/include/sys_reslocator.h +++ b/doomsday/engine/portable/include/sys_reslocator.h @@ -116,7 +116,7 @@ resourcenamespace_namehash_key_t F_HashKeyForAlphaNumericNameIgnoreCase(const dd #define F_HashKeyForFilePathHashName F_HashKeyForAlphaNumericNameIgnoreCase resourcenamespace_t* F_CreateResourceNamespace(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, int numSearchPaths, byte flags, const char* overrideName, const char* overrideName2); diff --git a/doomsday/engine/portable/src/resourcenamespace.c b/doomsday/engine/portable/src/resourcenamespace.c index 7b8a1a1247..56c40198be 100644 --- a/doomsday/engine/portable/src/resourcenamespace.c +++ b/doomsday/engine/portable/src/resourcenamespace.c @@ -189,10 +189,7 @@ static void rebuild(resourcenamespace_t* rn) if(rn->_flags & RNF_IS_DIRTY) { clearPathHash(rn); - if(NULL != rn->_fileDirectory) - { - FileDirectory_Clear(rn->_fileDirectory); - } + FileDirectory_Clear(rn->_directory); { ddstring_t tmp; Str_Init(&tmp); formSearchPathList(&tmp, rn); @@ -205,7 +202,7 @@ static void rebuild(resourcenamespace_t* rn) //startTime = verbose >= 2? Sys_GetRealTime(): 0; #endif - FileDirectory_AddPathList3(rn->_fileDirectory, Str_Text(&tmp), addFilePathWorker, rn); + FileDirectory_AddPathList3(rn->_directory, Str_Text(&tmp), addFilePathWorker, rn); /*#if _DEBUG printPathHash(rn); @@ -220,12 +217,12 @@ static void rebuild(resourcenamespace_t* rn) } resourcenamespace_t* ResourceNamespace_Construct5(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, uint searchPathsCount, byte flags, const char* overrideName, const char* overrideName2) { - assert(name && composeHashNameFunc && hashNameFunc); + assert(name && directory && composeHashNameFunc && hashNameFunc); { resourcenamespace_t* rn; @@ -240,7 +237,7 @@ resourcenamespace_t* ResourceNamespace_Construct5(const char* name, rn->_flags = flags; Str_Init(&rn->_name); Str_Set(&rn->_name, name); - rn->_fileDirectory = FileDirectory_ConstructDefault(); + rn->_directory = directory; rn->_composeHashName = composeHashNameFunc; rn->_hashName = hashNameFunc; memset(rn->_pathHash, 0, sizeof(rn->_pathHash)); @@ -286,38 +283,38 @@ resourcenamespace_t* ResourceNamespace_Construct5(const char* name, } resourcenamespace_t* ResourceNamespace_Construct4(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, uint searchPathsCount, byte flags, const char* overrideName) { - return ResourceNamespace_Construct5(name, composeHashNameFunc, hashNameFunc, + return ResourceNamespace_Construct5(name, directory, composeHashNameFunc, hashNameFunc, searchPaths, searchPathsCount, flags, overrideName, 0); } resourcenamespace_t* ResourceNamespace_Construct3(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, uint searchPathsCount, byte flags) { - return ResourceNamespace_Construct4(name, composeHashNameFunc, hashNameFunc, + return ResourceNamespace_Construct4(name, directory, composeHashNameFunc, hashNameFunc, searchPaths, searchPathsCount, flags, 0); } resourcenamespace_t* ResourceNamespace_Construct2(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, uint searchPathsCount) { - return ResourceNamespace_Construct3(name, composeHashNameFunc, hashNameFunc, + return ResourceNamespace_Construct3(name, directory, composeHashNameFunc, hashNameFunc, searchPaths, searchPathsCount, 0); } resourcenamespace_t* ResourceNamespace_Construct(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name)) { - return ResourceNamespace_Construct2(name, composeHashNameFunc, hashNameFunc, 0, 0); + return ResourceNamespace_Construct2(name, directory, composeHashNameFunc, hashNameFunc, 0, 0); } void ResourceNamespace_Destruct(resourcenamespace_t* rn) @@ -326,11 +323,6 @@ void ResourceNamespace_Destruct(resourcenamespace_t* rn) ResourceNamespace_ClearSearchPaths(rn); ResourceNamespace_ClearExtraSearchPaths(rn); clearPathHash(rn); - if(NULL != rn->_fileDirectory) - { - FileDirectory_Destruct(rn->_fileDirectory); - rn->_fileDirectory = NULL; - } Str_Free(&rn->_name); if(rn->_overrideName) Str_Delete(rn->_overrideName); @@ -344,10 +336,7 @@ void ResourceNamespace_Reset(resourcenamespace_t* rn) assert(rn); ResourceNamespace_ClearExtraSearchPaths(rn); clearPathHash(rn); - if(NULL != rn->_fileDirectory) - { - FileDirectory_Clear(rn->_fileDirectory); - } + FileDirectory_Clear(rn->_directory); rn->_flags |= RNF_IS_DIRTY; } @@ -471,3 +460,9 @@ const ddstring_t* ResourceNamespace_Name(const resourcenamespace_t* rn) assert(rn); return &rn->_name; } + +filedirectory_t* ResourceNamespace_Directory(const resourcenamespace_t* rn) +{ + assert(rn); + return rn->_directory; +} diff --git a/doomsday/engine/portable/src/sys_reslocator.c b/doomsday/engine/portable/src/sys_reslocator.c index 7bc0822e8a..254ac46b5a 100644 --- a/doomsday/engine/portable/src/sys_reslocator.c +++ b/doomsday/engine/portable/src/sys_reslocator.c @@ -155,8 +155,14 @@ static void destroyAllNamespaces(void) return; { uint i; for(i = 0; i < numNamespaces; ++i) - ResourceNamespace_Destruct(namespaces[i]); - } + { + resourcenamespace_t* rnamespace = namespaces[i]; + if(NULL != ResourceNamespace_Directory(rnamespace)) + { + FileDirectory_Destruct(ResourceNamespace_Directory(rnamespace)); + } + ResourceNamespace_Destruct(rnamespace); + }} free(namespaces); namespaces = 0; } @@ -384,6 +390,7 @@ static void createPackagesResourceNamespace(void) { ddstring_t** doomWadPaths = 0, *doomWadDir = 0; uint doomWadPathsCount = 0, searchPathsCount, idx; + filedirectory_t* directory; dduri_t** searchPaths; // Is the DOOMWADPATH environment variable in use? @@ -488,7 +495,8 @@ static void createPackagesResourceNamespace(void) Str_Delete(doomWadDir); } - F_CreateResourceNamespace(PACKAGES_RESOURCE_NAMESPACE_NAME, F_ComposeHashNameForFilePath, + directory = FileDirectory_ConstructDefault(); + F_CreateResourceNamespace(PACKAGES_RESOURCE_NAMESPACE_NAME, directory, F_ComposeHashNameForFilePath, F_HashKeyForFilePathHashName, (const dduri_t**)searchPaths, searchPathsCount, 0, 0, 0); for(idx = 0; idx < searchPathsCount; ++idx) @@ -530,6 +538,7 @@ void F_CreateNamespacesForFileResourcePaths(void) struct namespacedef_s* def = &defs[i]; dduri_t** searchPaths = 0; uint j, searchPathsCount = 0; + filedirectory_t* directory; for(searchPathsCount = 0; searchPathsCount < NAMESPACEDEF_MAX_SEARCHPATHS; ++searchPathsCount) if(!def->searchPaths[searchPathsCount]) @@ -542,7 +551,8 @@ void F_CreateNamespacesForFileResourcePaths(void) for(j = 0; j < searchPathsCount; ++j) searchPaths[j] = Uri_Construct2(def->searchPaths[j], RC_NULL); - F_CreateResourceNamespace(def->name, F_ComposeHashNameForFilePath, F_HashKeyForFilePathHashName, + directory = FileDirectory_ConstructDefault(); + F_CreateResourceNamespace(def->name, directory, F_ComposeHashNameForFilePath, F_HashKeyForFilePathHashName, (const dduri_t**)searchPaths, searchPathsCount, def->flags, def->overrideName, def->overrideName2); for(j = 0; j < searchPathsCount; ++j) @@ -610,14 +620,14 @@ boolean F_IsValidResourceNamespaceId(int val) } resourcenamespace_t* F_CreateResourceNamespace(const char* name, - ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), + filedirectory_t* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path), resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), const dduri_t* const* searchPaths, int numSearchPaths, byte flags, const char* overrideName, const char* overrideName2) { assert(inited && name); { - resourcenamespace_t* rn = ResourceNamespace_Construct5(name, composeHashNameFunc, + resourcenamespace_t* rn = ResourceNamespace_Construct5(name, directory, composeHashNameFunc, hashNameFunc, searchPaths, numSearchPaths, flags, overrideName, overrideName2); namespaces = (resourcenamespace_t**) realloc(namespaces, sizeof(*namespaces) * ++numNamespaces); if(namespaces == NULL)