Skip to content

Commit

Permalink
Refactor: Further resource locator cleanup refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 13, 2012
1 parent 2e12663 commit 52ad72b
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 156 deletions.
17 changes: 6 additions & 11 deletions doomsday/engine/portable/include/sys_reslocator.h
Expand Up @@ -181,21 +181,15 @@ resourcenamespaceid_t F_DefaultResourceNamespaceForClass(resourceclass_t rclass)
*/
resourcenamespaceid_t F_SafeResourceNamespaceForName(char const* name);

/**
* Same as F_SafeResourceNamespaceForName except will throw a fatal error if not
* found and won't return.
*/
resourcenamespaceid_t F_ResourceNamespaceForName(char const* name);

#ifdef __cplusplus
/**
* Attempts to determine which "type" should be attributed to a resource, solely
* by examining the name (e.g., a file name/path).
*
* @return Type determined for this resource else @c RT_NONE.
* @return Type determined for this resource else @c RT_NONE if not recognizable.
*/
resourcetype_t F_GuessResourceTypeByName(char const* name);
resourcetype_t F_GuessResourceTypeByName(de::String name);

#ifdef __cplusplus
/**
* Apply mapping for this namespace to the specified path (if enabled).
*
Expand All @@ -209,12 +203,13 @@ resourcetype_t F_GuessResourceTypeByName(char const* name);
* @return @c true iff mapping was applied to the path.
*/
bool F_MapGameResourcePath(resourcenamespaceid_t rnamespaceId, de::String& path);
#endif

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

#endif

#ifdef __cplusplus
} // extern "C"
Expand Down
33 changes: 13 additions & 20 deletions doomsday/engine/portable/src/dd_main.cpp
Expand Up @@ -377,31 +377,24 @@ boolean DD_ExchangeGamePluginEntryPoints(pluginid_t pluginId)

static void loadResource(ResourceRecord& record)
{
switch(record.resourceClass())
DENG_ASSERT(record.resourceClass() == RC_PACKAGE);

QString const& path = record.resolvedPath(false/*do not locate resource*/);
if(!path.isEmpty())
{
case RC_PACKAGE: {
QString const& path = record.resolvedPath(false/*do not locate resource*/);
if(!path.isEmpty())
QByteArray pathUtf8 = path.toUtf8();
de::File1* file;
if(tryLoadFile(pathUtf8.constData(), 0/*base offset*/, &file))
{
QByteArray pathUtf8 = path.toUtf8();
de::File1* file;
if(tryLoadFile(pathUtf8.constData(), 0/*base offset*/, &file))
{
// Mark this as an original game resource.
file->setCustom(false);

// Print the 'CRC' number of IWADs, so they can be identified.
if(Wad* wad = dynamic_cast<Wad*>(file))
{
Con_Message(" IWAD identification: %08x\n", wad->calculateCRC());
}
// Mark this as an original game resource.
file->setCustom(false);

// Print the 'CRC' number of IWADs, so they can be identified.
if(Wad* wad = dynamic_cast<Wad*>(file))
{
Con_Message(" IWAD identification: %08x\n", wad->calculateCRC());
}
}
break; }

default: Con_Error("loadGameResource: No resource loader found for %s.",
F_ResourceClassStr(record.resourceClass()));
}
}

Expand Down
3 changes: 1 addition & 2 deletions doomsday/engine/portable/src/fs_main.cpp
Expand Up @@ -1027,8 +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.
QByteArray pathUtf8 = path.toUtf8();
resourcetype_t resTypeGuess = F_GuessResourceTypeByName(pathUtf8.constData());
resourcetype_t resTypeGuess = F_GuessResourceTypeByName(path);
if(resTypeGuess != RT_NONE)
{
for(FileInterpreter* intper = interpreters; intper->interpret; ++intper)
Expand Down

0 comments on commit 52ad72b

Please sign in to comment.