Skip to content

Commit

Permalink
TextureManifest: Revised resource URI property access
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Feb 27, 2013
1 parent ad107f6 commit aebf710
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 65 deletions.
12 changes: 10 additions & 2 deletions doomsday/client/include/resource/texturemanifest.h
Expand Up @@ -46,6 +46,9 @@ class TextureManifest : public PathTree::Node
/// Required texture instance is missing. @ingroup errors
DENG2_ERROR(MissingTextureError);

/// Required resource URI is not defined. @ingroup errors
DENG2_ERROR(MissingResourceUriError);

public:
TextureManifest(PathTree::NodeArgs const &args);
virtual ~TextureManifest();
Expand Down Expand Up @@ -97,9 +100,14 @@ class TextureManifest : public PathTree::Node
}

/**
* Returns the URI to the associated resource. May be empty.
* Returns @c true if a URI to an associated resource is defined.
*/
bool hasResourceUri() const;

/**
* Returns the URI to the associated resource.
*/
Uri const &resourceUri() const;
Uri resourceUri() const;

/**
* Change the resource URI associated with the manifest.
Expand Down
129 changes: 72 additions & 57 deletions doomsday/client/src/gl/gl_texmanager.cpp
Expand Up @@ -661,22 +661,25 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t

if(source == TEXS_NONE)
{
de::Uri const &resourceUri = tex.manifest().resourceUri();
if(!resourceUri.scheme().compareWithoutCase("LumpIndex"))
if(tex.manifest().hasResourceUri())
{
try
de::Uri resourceUri = tex.manifest().resourceUri();
if(!resourceUri.scheme().compareWithoutCase("LumpIndex"))
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadFlat(image, hndl);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadFlat(image, hndl);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
}
}
Expand All @@ -699,22 +702,25 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t

if(source == TEXS_NONE)
{
de::Uri const &resourceUri = tex.manifest().resourceUri();
if(!resourceUri.scheme().compareWithoutCase("LumpIndex"))
if(tex.manifest().hasResourceUri())
{
try
de::Uri resourceUri = tex.manifest().resourceUri();
if(!resourceUri.scheme().compareWithoutCase("LumpIndex"))
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadPatch(image, hndl, tclass, tmap, spec.border);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadPatch(image, hndl, tclass, tmap, spec.border);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
}
}
Expand Down Expand Up @@ -751,16 +757,46 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t

if(source == TEXS_NONE)
{
de::Uri const &resourceUri = tex.manifest().resourceUri();
if(!resourceUri.scheme().compareWithoutCase("LumpIndex"))
if(tex.manifest().hasResourceUri())
{
de::Uri resourceUri = tex.manifest().resourceUri();
if(!resourceUri.scheme().compareWithoutCase("LumpIndex"))
{
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadPatch(image, hndl, tclass, tmap, spec.border);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
}
}
}
else if(!tex.manifest().schemeName().compareWithoutCase("Details"))
{
if(tex.manifest().hasResourceUri())
{
de::Uri resourceUri = tex.manifest().resourceUri();
if(resourceUri.scheme().compareWithoutCase("Lumps"))
{
source = loadExternalTexture(image, resourceUri.compose());
}
else
{
lumpnum_t lumpNum = App_FileSystem().lumpNumForName(resourceUri.path());
try
{
lumpnum_t lumpNum = resourceUri.path().toString().toInt();
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadPatch(image, hndl, tclass, tmap, spec.border);
source = loadDetail(image, hndl);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
Expand All @@ -770,34 +806,13 @@ static TexSource loadSourceImage(de::Texture &tex, texturevariantspecification_t
}
}
}
else if(!tex.manifest().schemeName().compareWithoutCase("Details"))
else
{
de::Uri const &resourceUri = tex.manifest().resourceUri();
if(resourceUri.scheme().compareWithoutCase("Lumps"))
if(tex.manifest().hasResourceUri())
{
de::Uri resourceUri = tex.manifest().resourceUri();
source = loadExternalTexture(image, resourceUri.compose());
}
else
{
lumpnum_t lumpNum = App_FileSystem().lumpNumForName(resourceUri.path());
try
{
de::File1 &lump = App_FileSystem().nameIndex().lump(lumpNum);
de::FileHandle &hndl = App_FileSystem().openLump(lump);

source = loadDetail(image, hndl);

App_FileSystem().releaseFile(hndl.file());
delete &hndl;
}
catch(LumpIndex::NotFoundError const&)
{} // Ignore this error.
}
}
else
{
de::Uri const &resourceUri = tex.manifest().resourceUri();
source = loadExternalTexture(image, resourceUri.compose());
}
return source;
}
Expand Down Expand Up @@ -2012,13 +2027,13 @@ void GL_UploadTextureContent(texturecontent_t const &content)
}
}

static TexSource loadExternalTexture(image_t &image, String searchPath,
static TexSource loadExternalTexture(image_t &image, String encodedSearchPath,
String optionalSuffix)
{
// First look for a version with an optional suffix.
try
{
String foundPath = App_FileSystem().findPath(de::Uri(searchPath + optionalSuffix, RC_GRAPHIC),
String foundPath = App_FileSystem().findPath(de::Uri(encodedSearchPath + optionalSuffix, RC_GRAPHIC),
RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC));
// Ensure the found path is absolute.
foundPath = App_BasePath() / foundPath;
Expand All @@ -2033,7 +2048,7 @@ static TexSource loadExternalTexture(image_t &image, String searchPath,
{
try
{
String foundPath = App_FileSystem().findPath(de::Uri(searchPath, RC_GRAPHIC),
String foundPath = App_FileSystem().findPath(de::Uri(encodedSearchPath, RC_GRAPHIC),
RLF_DEFAULT, DD_ResourceClassById(RC_GRAPHIC));
// Ensure the found path is absolute.
foundPath = App_BasePath() / foundPath;
Expand Down
16 changes: 13 additions & 3 deletions doomsday/client/src/resource/texturemanifest.cpp
Expand Up @@ -103,12 +103,22 @@ Textures::Scheme &TextureManifest::scheme() const
if(&scheme->index() == &tree()) return *scheme;
}
/// @throw Error Failed to determine the scheme of the manifest (should never happen...).
throw Error("TextureManifest::scheme", String("Failed to determine scheme for manifest [%1].").arg(de::dintptr(this)));
throw Error("TextureManifest::scheme", String("Failed to determine scheme for manifest [%1]").arg(de::dintptr(this)));
}

de::Uri const &TextureManifest::resourceUri() const
bool TextureManifest::hasResourceUri() const
{
return d->resourceUri;
return !d->resourceUri.isEmpty();
}

de::Uri TextureManifest::resourceUri() const
{
if(hasResourceUri())
{
return d->resourceUri;
}
/// @throw MissingResourceUriError There is no resource URI defined.
throw MissingResourceUriError("TextureManifest::scheme", "No resource URI is defined");
}

bool TextureManifest::setResourceUri(de::Uri const &newUri)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/textures.cpp
Expand Up @@ -450,7 +450,7 @@ static void printManifestInfo(TextureManifest &manifest,
#ifdef __CLIENT__
info += String("x%1").arg(!manifest.hasTexture()? 0 : manifest.texture().variantCount());
#endif
info += " " + (manifest.resourceUri().isEmpty()? "N/A" : manifest.resourceUri().asText());
info += " " + (!manifest.hasResourceUri()? "N/A" : manifest.resourceUri().asText());

info += "\n";
Con_FPrintf(!manifest.hasTexture()? CPF_LIGHT : CPF_WHITE, info.toUtf8().constData());
Expand Down
7 changes: 5 additions & 2 deletions doomsday/client/src/resource/texturescheme.cpp
Expand Up @@ -215,9 +215,12 @@ TextureManifest const &TextureScheme::findByResourceUri(de::Uri const &uri) cons
while(iter.hasNext())
{
TextureManifest &manifest = iter.next();
if(manifest.resourceUri() == uri)
if(manifest.hasResourceUri())
{
return manifest;
if(manifest.resourceUri() == uri)
{
return manifest;
}
}
}
}
Expand Down

0 comments on commit aebf710

Please sign in to comment.