diff --git a/doomsday/engine/portable/include/file.h b/doomsday/engine/portable/include/file.h index 90ce792fef..93c6b35ce0 100644 --- a/doomsday/engine/portable/include/file.h +++ b/doomsday/engine/portable/include/file.h @@ -26,6 +26,7 @@ #ifdef __cplusplus +#include "dd_share.h" #include #include #include "filehandle.h" diff --git a/doomsday/engine/portable/include/resourcenamespace.h b/doomsday/engine/portable/include/resourcenamespace.h index 2579c7cce3..324fe85e31 100644 --- a/doomsday/engine/portable/include/resourcenamespace.h +++ b/doomsday/engine/portable/include/resourcenamespace.h @@ -30,10 +30,10 @@ /** * @defgroup searchPathFlags Search Path Flags - * @{ */ +///@{ #define SPF_NO_DESCEND 0x1 ///< Do not decend into branches when populating paths. -/**@}*/ +///@} namespace de { @@ -111,11 +111,11 @@ namespace de typedef QList ResourceList; public: - explicit ResourceNamespace(char const* symbolicName = ""); + explicit ResourceNamespace(String symbolicName); ~ResourceNamespace(); /// @return Symbolic name of this namespace (e.g., "Models"). - ddstring_t const* name() const; + String const& name() const; /** * Rebuild this namespace by re-scanning for resources on all search @@ -151,7 +151,7 @@ namespace de * * @return Number of found resources. */ - int findAll(ddstring_t const* searchPath, ResourceList& found); + int findAll(String searchPath, ResourceList& found); /** * Add a new search path to this namespace. Newer paths have priority @@ -178,39 +178,7 @@ namespace de void clearSearchPaths(); /** - * Append to @a pathList all resolved search paths in @a group, in - * descending (i.e., most recent) order. - * - * @param group Group of paths to append. - * @param pathList String to receive the search path list. - * @param delimiter Discreet paths will be delimited by this character. - * - * @return Same as @a pathList for caller convenience. - */ - ddstring_t* listSearchPaths(PathGroup group, ddstring_t* pathList, - char delimiter = ';') const; - - /** - * Append to @a pathList all resolved search paths from all groups, - * firstly in priority group order (from Override to Fallback) and - * secondly in descending (i.e., most recent) order. - * - * @param pathList String to receive the search paths. - * @param delimiter Discreet paths will be delimited by this character. - * - * @return Same as @a pathList for caller convenience. - */ - ddstring_t* listSearchPaths(ddstring_t* pathList, char delimiter = ';') const - { - listSearchPaths(OverridePaths, pathList, delimiter); - listSearchPaths(ExtraPaths, pathList, delimiter); - listSearchPaths(DefaultPaths, pathList, delimiter); - listSearchPaths(FallbackPaths, pathList, delimiter); - return pathList; - } - - /** - * Provides access to the search paths for efficent traversals. + * Provides access to the search paths for efficient traversals. */ SearchPaths const& searchPaths() const; diff --git a/doomsday/engine/portable/include/sys_reslocator.h b/doomsday/engine/portable/include/sys_reslocator.h index 584f54e361..de0c59c78f 100644 --- a/doomsday/engine/portable/include/sys_reslocator.h +++ b/doomsday/engine/portable/include/sys_reslocator.h @@ -122,8 +122,6 @@ void F_ResetResourceNamespace(resourcenamespaceid_t rni); void F_CreateNamespacesForFileResourcePaths(void); -ddstring_t const* F_ResourceNamespaceName(resourcenamespaceid_t rni); - /// @return Number of resource namespaces. uint F_NumResourceNamespaces(void); diff --git a/doomsday/engine/portable/src/resourcenamespace.cpp b/doomsday/engine/portable/src/resourcenamespace.cpp index e833b40b47..1eef68502d 100644 --- a/doomsday/engine/portable/src/resourcenamespace.cpp +++ b/doomsday/engine/portable/src/resourcenamespace.cpp @@ -177,6 +177,8 @@ struct ResourceNamespace::Instance { ResourceNamespace& self; + /// Symbolic name of this namespace. + String name; /// Associated path directory for this namespace. /// @todo It should not be necessary for a unique directory per namespace. PathTree directory; @@ -194,20 +196,9 @@ struct ResourceNamespace::Instance /// Each set is in order of greatest-importance, right to left. ResourceNamespace::SearchPaths searchPaths; - /// Symbolic name of this namespace. - ddstring_t name; - - Instance(ResourceNamespace& d, char const* _name) - : self(d), directory(), rootNode(0), nameHash(), nameHashIsDirty(true) - { - Str_InitStd(&name); - if(_name) Str_Set(&name, _name); - } - - ~Instance() - { - Str_Free(&name); - } + Instance(ResourceNamespace& d, String _name) + : self(d), name(_name), directory(), rootNode(0), nameHash(), nameHashIsDirty(true) + {} NameHash::Node* findResourceInNameHash(NameHash::key_type key, PathTree::Node const& ptNode) @@ -361,7 +352,7 @@ struct ResourceNamespace::Instance } }; -ResourceNamespace::ResourceNamespace(char const* symbolicName) +ResourceNamespace::ResourceNamespace(String symbolicName) { d = new Instance(*this, symbolicName); } @@ -371,9 +362,9 @@ ResourceNamespace::~ResourceNamespace() delete d; } -ddstring_t const* ResourceNamespace::name() const +String const& ResourceNamespace::name() const { - return &d->name; + return d->name; } void ResourceNamespace::clear() @@ -393,7 +384,6 @@ void ResourceNamespace::rebuild() uint startTime; VERBOSE( Con_Message("Rebuilding ResourceNamespace '%s'...\n", Str_Text(d->name)) ) VERBOSE2( startTime = Sys_GetRealTime() ) - VERBOSE2( Con_PrintPathList(Str_Text(listSearchPaths(AutoStr_NewStd()))) ) #endif*/ // (Re)populate the directory and add found resources. @@ -492,21 +482,6 @@ void ResourceNamespace::clearSearchPaths() d->searchPaths.clear(); } -ddstring_t* ResourceNamespace::listSearchPaths(PathGroup group, ddstring_t* pathList, - char delimiter) const -{ - if(pathList) - { - for(ResourceNamespace::SearchPaths::const_iterator i = d->searchPaths.find(group); - i != d->searchPaths.end() && i.key() == group; ++i) - { - AutoStr* path = i.value().uri().compose(); - Str_Appendf(pathList, "%s%c", Str_Text(path), delimiter); - } - } - return pathList; -} - ResourceNamespace::SearchPaths const& ResourceNamespace::searchPaths() const { return d->searchPaths; @@ -537,14 +512,15 @@ void ResourceNamespace::debugPrint() const } #endif -int ResourceNamespace::findAll(ddstring_t const* searchPath, ResourceList& found) +int ResourceNamespace::findAll(String searchPath, ResourceList& found) { int numFoundSoFar = found.count(); AutoStr* name = 0; - if(searchPath && !Str_IsEmpty(searchPath)) + if(!searchPath.isEmpty()) { - name = composeResourceName(Str_Text(searchPath)); + QByteArray searchPathUtf8 = searchPath.toUtf8(); + name = composeResourceName(searchPathUtf8.constData()); } NameHash::key_type from, to; diff --git a/doomsday/engine/portable/src/sys_reslocator.cpp b/doomsday/engine/portable/src/sys_reslocator.cpp index 689ba2a5b1..e540bc36f1 100644 --- a/doomsday/engine/portable/src/sys_reslocator.cpp +++ b/doomsday/engine/portable/src/sys_reslocator.cpp @@ -150,14 +150,14 @@ static inline ResourceNamespaceInfo* getNamespaceInfoForId(resourcenamespaceid_t return &namespaces[((uint)rni)-1]; } -static resourcenamespaceid_t findNamespaceForName(char const* name) +static resourcenamespaceid_t findNamespaceForName(String name) { - if(name && name[0]) + if(!name.isEmpty()) { for(uint i = 0; i < numNamespaces; ++i) { ResourceNamespaceInfo* info = &namespaces[i]; - if(!stricmp(Str_Text(info->rnamespace->name()), name)) + if(!info->rnamespace->name().compareWithoutCase(name)) return (resourcenamespaceid_t)(i+1); } } @@ -195,9 +195,9 @@ static void resetAllNamespaces(void) * @return The found PathTree node which represents the resource else @c NULL. */ static PathTree::Node* findResourceInNamespace(ResourceNamespace& rnamespace, - ddstring_t const* searchPath, char delimiter) + String searchPath, QChar delimiter = '/') { - if(!searchPath || Str_IsEmpty(searchPath)) return 0; + if(searchPath.isEmpty()) return 0; // Ensure the namespace is up to date. rnamespace.rebuild(); @@ -208,7 +208,8 @@ static PathTree::Node* findResourceInNamespace(ResourceNamespace& rnamespace, if(rnamespace.findAll(searchPath, foundResources)) { // There is at least one name-matched (perhaps partially) resource. - PathMap searchPattern = PathMap(PathTree::hashPathFragment, Str_Text(searchPath), delimiter); + QByteArray searchPathUtf8 = searchPath.toUtf8(); + PathMap searchPattern = PathMap(PathTree::hashPathFragment, searchPathUtf8.constData(), delimiter.toLatin1()); DENG2_FOR_EACH_CONST(ResourceNamespace::ResourceList, i, foundResources) { @@ -235,7 +236,7 @@ static bool tryFindResource2(resourceclass_t rclass, ddstring_t const* rawSearch if(rnInfo) { ResourceNamespace& rnamespace = *rnInfo->rnamespace; - if(PathTree::Node* found = findResourceInNamespace(rnamespace, searchPath, '/')) + if(PathTree::Node* found = findResourceInNamespace(rnamespace, Str_Text(searchPath), '/')) { // Does the caller want to know the matched path? if(foundPath) @@ -320,9 +321,8 @@ static bool findResource2(resourceclass_t rclass, ddstring_t const* searchPath, { DENG_ASSERT(inited && searchPath && !Str_IsEmpty(searchPath)); -#if _DEBUG - VERBOSE2( Con_Message("Using rnamespace '%s'...\n", rnamespaceInfo? Str_Text(rnamespaceInfo->rnamespace->name()) : "None") ) -#endif + LOG_AS("findResource2"); + LOG_TRACE("Using namespace '%s'...") << (rnamespaceInfo? rnamespaceInfo->rnamespace->name() : "None"); bool found = false; @@ -694,16 +694,14 @@ ResourceNamespace* F_CreateResourceNamespace(char const* name, byte flags) DENG_ASSERT(name); errorIfNotInited("F_CreateResourceNamespace"); - if(strlen(name) < RESOURCENAMESPACE_MINNAMELENGTH) + if(qstrlen(name) < RESOURCENAMESPACE_MINNAMELENGTH) Con_Error("F_CreateResourceNamespace: Invalid name '%s' (min length:%i)", name, (int)RESOURCENAMESPACE_MINNAMELENGTH); - ResourceNamespace* rn = new ResourceNamespace(name); + ResourceNamespace* rn = new ResourceNamespace(String(name)); // Add this new namespace to the global list. namespaces = (ResourceNamespaceInfo*) M_Realloc(namespaces, sizeof *namespaces * ++numNamespaces); - if(!namespaces) - Con_Error("F_CreateResourceNamespace: Failed on (re)allocation of %lu bytes for new resource namespace\n", - (unsigned long) sizeof *namespaces * numNamespaces); + if(!namespaces) Con_Error("F_CreateResourceNamespace: Failed on (re)allocation of %lu bytes for new resource namespace\n", (unsigned long) sizeof *namespaces * numNamespaces); ResourceNamespaceInfo* info = &namespaces[numNamespaces-1]; info->rnamespace = rn; @@ -723,11 +721,6 @@ boolean F_AddExtraSearchPathToResourceNamespace(resourcenamespaceid_t rni, int f return rnamespace.addSearchPath(ResourceNamespace::ExtraPaths, reinterpret_cast(*searchPath), flags); } -ddstring_t const* F_ResourceNamespaceName(resourcenamespaceid_t rni) -{ - return (getNamespaceInfoForId(rni))->rnamespace->name(); -} - uri_s** F_CreateUriList2(resourceclass_t rclass, char const* searchPaths, int* count) { if(!searchPaths || !searchPaths[0]) @@ -1035,11 +1028,12 @@ boolean F_MapGameResourcePath(resourcenamespaceid_t rni, ddstring_t* path) ResourceNamespace& rnamespace = *info->rnamespace; if(info->flags & RNF_USE_VMAP) { - int const nameLen = Str_Length(rnamespace.name()); + QByteArray rnamespaceName = rnamespace.name().toUtf8(); + int const nameLen = rnamespaceName.length(); int const pathLen = Str_Length(path); if(nameLen <= pathLen && Str_At(path, nameLen) == '/' && - !strnicmp(Str_Text(rnamespace.name()), Str_Text(path), nameLen)) + !qstrnicmp(rnamespaceName.constData(), Str_Text(path), nameLen)) { Str_Prepend(path, "$(App.DataPath)/$(GamePlugin.Name)/"); return true; diff --git a/doomsday/engine/portable/src/uri.cpp b/doomsday/engine/portable/src/uri.cpp index d1ea21613c..bbead1c9dc 100644 --- a/doomsday/engine/portable/src/uri.cpp +++ b/doomsday/engine/portable/src/uri.cpp @@ -26,6 +26,7 @@ #include "de_base.h" #include "fs_util.h" #include "game.h" +#include "resourcenamespace.h" #include "sys_reslocator.h" #include @@ -34,6 +35,8 @@ #include "uri.h" +extern de::ResourceNamespace* F_ToResourceNamespace(resourcenamespaceid_t rni); + namespace de { struct Uri::Instance @@ -99,8 +102,10 @@ struct Uri::Instance if(VALID_RESOURCE_CLASS(defaultResourceClass)) { - ddstring_t const* name = F_ResourceNamespaceName(F_DefaultResourceNamespaceForClass(defaultResourceClass)); - Str_Copy(&scheme, name); + ResourceNamespace* rnamespace = F_ToResourceNamespace(F_DefaultResourceNamespaceForClass(defaultResourceClass)); + DENG_ASSERT(rnamespace); + QByteArray rnamespaceName = rnamespace->name().toUtf8(); + Str_Set(&scheme, rnamespaceName.constData()); } }