Skip to content

Commit

Permalink
Refactor: Minor cleanup refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 14, 2012
1 parent dc1743a commit 8793fed
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 41 deletions.
6 changes: 3 additions & 3 deletions doomsday/engine/include/sys_reslocator.h
Expand Up @@ -101,7 +101,7 @@ void F_ShutdownResourceLocator(void);

void F_ResetAllResourceNamespaces(void);

void F_CreateNamespacesForFileResourcePaths(void);
void F_CreateResourceNamespaces(void);

/**
* Attempt to locate a named resource.
Expand Down Expand Up @@ -171,12 +171,12 @@ de::ResourceNamespace* F_ResourceNamespaceByName(de::String name);
*
* @return Type determined for this resource else @c RT_NONE if not recognizable.
*/
resourcetype_t F_GuessResourceTypeByName(de::String name);
resourcetype_t F_GuessResourceTypeFromFileName(de::String name);

/**
* Convert a resourceclass_t constant into a string for error/debug messages.
*/
de::String const& F_ResourceClassStr(resourceclass_t rclass);
de::String const& F_ResourceClassName(resourceclass_t rclass);

#endif // __cplusplus

Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/src/dd_main.cpp
Expand Up @@ -486,7 +486,7 @@ static int addListFiles(ddstring_t*** list, size_t* listSize, resourcetype_t res
if(!list || !listSize) return 0;
for(i = 0; i < *listSize; ++i)
{
if(resType != F_GuessResourceTypeByName(Str_Text((*list)[i]))) continue;
if(resType != F_GuessResourceTypeFromFileName(Str_Text((*list)[i]))) continue;
if(tryLoadFile(Str_Text((*list)[i])))
{
count += 1;
Expand Down Expand Up @@ -1568,7 +1568,7 @@ static void DD_InitResourceSystem(void)
Con_Message("Initializing Resource subsystem...\n");

F_InitResourceLocator();
F_CreateNamespacesForFileResourcePaths();
F_CreateResourceNamespaces();

initPathMappings();

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/fs_main.cpp
Expand Up @@ -1027,7 +1027,7 @@ de::File1& FS1::interpret(de::FileHandle& hndl, String path, FileInfo const& inf
de::File1* interpretedFile = 0;

// Firstly try interpreter(s) for guessed resource types.
resourcetype_t resTypeGuess = F_GuessResourceTypeByName(path);
resourcetype_t resTypeGuess = F_GuessResourceTypeFromFileName(path);
if(resTypeGuess != RT_NONE)
{
for(FileInterpreter* intper = interpreters; intper->interpret; ++intper)
Expand Down
63 changes: 30 additions & 33 deletions doomsday/engine/src/sys_reslocator.cpp
Expand Up @@ -47,6 +47,8 @@ struct ResourceTypeInfo

/// Default class attributed to resources of this type.
resourceclass_t defaultClass;

/// List of known extensions for this resource type.
String const knownFileNameExtensions[max_extensions];
};

Expand Down Expand Up @@ -272,7 +274,7 @@ static bool findResource(resourceclass_t rclass, de::Uri const& searchPath,
return false;
}

static void createPackagesResourceNamespace(void)
static void createPackagesNamespace(void)
{
ResourceNamespace& rnamespace = createResourceNamespace("Packages");

Expand Down Expand Up @@ -335,7 +337,7 @@ static void createPackagesResourceNamespace(void)
rnamespace.addSearchPath(ResourceNamespace::DefaultPaths, de::Uri("$(App.DataPath)/$(GamePlugin.Name)/", RC_NULL), SPF_NO_DESCEND);
}

void F_CreateNamespacesForFileResourcePaths(void)
void F_CreateResourceNamespaces(void)
{
#define NAMESPACEDEF_MAX_SEARCHPATHS 5

Expand Down Expand Up @@ -381,8 +383,7 @@ void F_CreateNamespacesForFileResourcePaths(void)
{ 0, 0, 0, ResourceNamespace::Flag(0), 0, { 0 } }
};

// Setup of the Packages namespace is somewhat more involved...
createPackagesResourceNamespace();
createPackagesNamespace();

// Setup the rest...
for(size_t i = 0; defs[i].name; ++i)
Expand All @@ -403,20 +404,16 @@ void F_CreateNamespacesForFileResourcePaths(void)

if(def->optOverridePath && CommandLine_CheckWith(def->optOverridePath, 1))
{
String path = NativePath(CommandLine_NextAsPath()).expand().withSeparators('/');

de::Uri uri2 = de::Uri(path / "$(Game.IdentityKey)/", RC_NULL);
rnamespace.addSearchPath(ResourceNamespace::OverridePaths, uri2, def->searchPathFlags);

de::Uri uri = de::Uri(path, RC_NULL);
rnamespace.addSearchPath(ResourceNamespace::OverridePaths, uri, def->searchPathFlags);
NativePath path = NativePath(CommandLine_NextAsPath());
rnamespace.addSearchPath(ResourceNamespace::OverridePaths, de::Uri::fromNativeDirPath(path), def->searchPathFlags);
path = path / "$(Game.IdentityKey)";
rnamespace.addSearchPath(ResourceNamespace::OverridePaths, de::Uri::fromNativeDirPath(path), def->searchPathFlags);
}

if(def->optFallbackPath && CommandLine_CheckWith(def->optFallbackPath, 1))
{
String path = NativePath(CommandLine_NextAsPath()).expand().withSeparators('/');
de::Uri uri = de::Uri(path, RC_NULL);
rnamespace.addSearchPath(ResourceNamespace::FallbackPaths, uri, def->searchPathFlags);
NativePath path = NativePath(CommandLine_NextAsPath());
rnamespace.addSearchPath(ResourceNamespace::FallbackPaths, de::Uri::fromNativeDirPath(path), def->searchPathFlags);
}
}

Expand Down Expand Up @@ -499,12 +496,6 @@ uint F_FindResourceFromList(resourceclass_t rclass, char const* searchPaths,
return 0; // Not found.
}

resourceclass_t F_DefaultResourceClassForType(resourcetype_t type)
{
if(type == RT_NONE) return RC_UNKNOWN;
return resourceTypeInfo(type).defaultClass;
}

ResourceNamespace* F_DefaultResourceNamespaceForClass(resourceclass_t rclass)
{
DENG_ASSERT(VALID_RESOURCE_CLASS(rclass));
Expand All @@ -520,7 +511,22 @@ ResourceNamespace* F_DefaultResourceNamespaceForClass(resourceclass_t rclass)
return namespaceByName(defaultNamespaces[rclass]);
}

resourcetype_t F_GuessResourceTypeByName(String path)
String const& F_ResourceClassName(resourceclass_t rclass)
{
DENG_ASSERT(VALID_RESOURCE_CLASS(rclass));
static String const resourceClassNames[RESOURCECLASS_COUNT] = {
"RC_PACKAGE",
"RC_DEFINITION",
"RC_GRAPHIC",
"RC_MODEL",
"RC_SOUND",
"RC_MUSIC",
"RC_FONT"
};
return resourceClassNames[uint(rclass)];
}

resourcetype_t F_GuessResourceTypeFromFileName(String path)
{
if(path.isEmpty()) return RT_NONE;

Expand All @@ -543,17 +549,8 @@ resourcetype_t F_GuessResourceTypeByName(String path)
return RT_NONE;
}

String const& F_ResourceClassStr(resourceclass_t rclass)
resourceclass_t F_DefaultResourceClassForType(resourcetype_t type)
{
DENG_ASSERT(VALID_RESOURCE_CLASS(rclass));
static String const resourceClassNames[RESOURCECLASS_COUNT] = {
"RC_PACKAGE",
"RC_DEFINITION",
"RC_GRAPHIC",
"RC_MODEL",
"RC_SOUND",
"RC_MUSIC",
"RC_FONT"
};
return resourceClassNames[uint(rclass)];
if(type == RT_NONE) return RC_UNKNOWN;
return resourceTypeInfo(type).defaultClass;
}
2 changes: 1 addition & 1 deletion doomsday/engine/src/uri.cpp
Expand Up @@ -288,7 +288,7 @@ struct Uri::Instance

// Attempt to guess the scheme by interpreting the path?
if(defaultResourceClass == RC_UNKNOWN)
defaultResourceClass = F_DefaultResourceClassForType(F_GuessResourceTypeByName(Str_Text(&path)));
defaultResourceClass = F_DefaultResourceClassForType(F_GuessResourceTypeFromFileName(Str_Text(&path)));

if(VALID_RESOURCE_CLASS(defaultResourceClass))
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/src/zip.cpp
Expand Up @@ -973,7 +973,7 @@ static bool applyGamePathMappings(String& path)
if(!path.contains('/'))
{
// No directory separators; i.e., a root file.
resourcetype_t type = F_GuessResourceTypeByName(path.fileName());
resourcetype_t type = F_GuessResourceTypeFromFileName(path.fileName());
resourceclass_t rclass;

// Certain resource files require special handling.
Expand Down

0 comments on commit 8793fed

Please sign in to comment.