From aebf710da0099cfc85a3b4c2687f0c1ddf4d72e7 Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 27 Feb 2013 16:21:28 +0000 Subject: [PATCH] TextureManifest: Revised resource URI property access --- .../client/include/resource/texturemanifest.h | 12 +- doomsday/client/src/gl/gl_texmanager.cpp | 129 ++++++++++-------- .../client/src/resource/texturemanifest.cpp | 16 ++- doomsday/client/src/resource/textures.cpp | 2 +- .../client/src/resource/texturescheme.cpp | 7 +- 5 files changed, 101 insertions(+), 65 deletions(-) diff --git a/doomsday/client/include/resource/texturemanifest.h b/doomsday/client/include/resource/texturemanifest.h index c8efa76b3a..4eb2353c1a 100644 --- a/doomsday/client/include/resource/texturemanifest.h +++ b/doomsday/client/include/resource/texturemanifest.h @@ -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(); @@ -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. diff --git a/doomsday/client/src/gl/gl_texmanager.cpp b/doomsday/client/src/gl/gl_texmanager.cpp index a4157d44c3..6d20cbdfb7 100644 --- a/doomsday/client/src/gl/gl_texmanager.cpp +++ b/doomsday/client/src/gl/gl_texmanager.cpp @@ -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. } } } @@ -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. } } } @@ -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; @@ -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; } @@ -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; @@ -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; diff --git a/doomsday/client/src/resource/texturemanifest.cpp b/doomsday/client/src/resource/texturemanifest.cpp index effa023b7c..4eb002bc2e 100644 --- a/doomsday/client/src/resource/texturemanifest.cpp +++ b/doomsday/client/src/resource/texturemanifest.cpp @@ -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) diff --git a/doomsday/client/src/resource/textures.cpp b/doomsday/client/src/resource/textures.cpp index 8da886d401..2d00698175 100644 --- a/doomsday/client/src/resource/textures.cpp +++ b/doomsday/client/src/resource/textures.cpp @@ -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()); diff --git a/doomsday/client/src/resource/texturescheme.cpp b/doomsday/client/src/resource/texturescheme.cpp index 8b9046a974..0d391db2ec 100644 --- a/doomsday/client/src/resource/texturescheme.cpp +++ b/doomsday/client/src/resource/texturescheme.cpp @@ -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; + } } } }