From ead1ecd407cab2acad23bec9af5540a2d84fcf56 Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 4 Dec 2013 13:37:47 +0000 Subject: [PATCH] ResourceSystem: Improved material and texture search APIs --- .../include/resource/materialmanifest.h | 13 ++++++ .../client/include/resource/resourcesystem.h | 46 ++++++++++++++----- .../client/include/resource/texturemanifest.h | 13 ++++++ .../client/src/resource/resourcesystem.cpp | 6 +-- 4 files changed, 64 insertions(+), 14 deletions(-) diff --git a/doomsday/client/include/resource/materialmanifest.h b/doomsday/client/include/resource/materialmanifest.h index defa25d266..e7e0525875 100644 --- a/doomsday/client/include/resource/materialmanifest.h +++ b/doomsday/client/include/resource/materialmanifest.h @@ -136,14 +136,27 @@ class MaterialManifest : public PathTree::Node /** * Returns @c true if a Material is presently associated with the manifest. + * + * @see material(), materialPtr() */ bool hasMaterial() const; /** * Returns the logical Material associated with the manifest. + * + * @see hasMaterial() */ Material &material() const; + /** + * Returns a pointer to the associated Material resource; otherwise @c 0. + * + * @see hasMaterial() + */ + inline Material *materialPtr() const { + return hasMaterial()? &material() : 0; + } + /** * Change the material associated with the manifest. * diff --git a/doomsday/client/include/resource/resourcesystem.h b/doomsday/client/include/resource/resourcesystem.h index 7317786351..d975a62c5c 100644 --- a/doomsday/client/include/resource/resourcesystem.h +++ b/doomsday/client/include/resource/resourcesystem.h @@ -175,10 +175,15 @@ class ResourceSystem : public de::System patchid_t declarePatch(de::String encodedName); /** - * Determines if a manifest exists for a material on @a path. - * @return @c true if a manifest exists; otherwise @a false. + * Determines if a material exists for a @a path. + * @return @c true if a material exists; otherwise @a false. + * + * @see hasMaterialManifest(), MaterialManifest::hasMaterial() */ - bool hasMaterial(de::Uri const &path) const; + inline bool hasMaterial(de::Uri const &path) const { + if(hasMaterialManifest(path)) return materialManifest(path).hasMaterial(); + return false; + } /** * Lookup a material resource for the specified @a path. @@ -194,12 +199,19 @@ class ResourceSystem : public de::System /** * Returns a pointer to the identified Material. * - * @see hasMaterial() + * @see hasMaterialManifest(), MaterialManifest::materialPtr() */ inline Material *materialPtr(de::Uri const &path) { - return hasMaterial(path)? &material(path) : 0; + if(hasMaterialManifest(path)) return materialManifest(path).materialPtr(); + return 0; } + /** + * Determines if a manifest exists for a material on @a path. + * @return @c true if a manifest exists; otherwise @a false. + */ + bool hasMaterialManifest(de::Uri const &path) const; + /** * Lookup a material manifest by it's unique resource @a path. * @@ -309,17 +321,22 @@ class ResourceSystem : public de::System AllMaterials const &allMaterials() const; /** - * Determines if a texture manifest exists for a declared texture on @a path. - * @return @c true, if a manifest exists; otherwise @a false. + * Determines if a texture exists for @a path. + * @return @c true, if a texture exists; otherwise @a false. + * + * @see hasTextureManifest(), TextureManifest::hasTexture() */ - bool hasTexture(de::Uri const &path) const; + inline bool hasTexture(de::Uri const &path) const { + if(hasTextureManifest(path)) return textureManifest(path).hasTexture(); + return false; + } /** * Lookup a texture resource for the specified @a path. * * @return The found texture. * - * @see TextureManifest::material() + * @see textureManifest(), TextureManifest::texture() */ inline de::Texture &texture(de::Uri const &path) const { return textureManifest(path).texture(); @@ -328,10 +345,11 @@ class ResourceSystem : public de::System /** * Returns a pointer to the identified Texture. * - * @see hasTexture() + * @see hasTextureManifest(), TextureManifest::texturePtr() */ inline de::Texture *texturePtr(de::Uri const &path) { - return hasTexture(path)? &texture(path) : 0; + if(hasTextureManifest(path)) return textureManifest(path).texturePtr(); + return false; } /** @@ -345,6 +363,12 @@ class ResourceSystem : public de::System */ de::Texture *texture(de::String schemeName, de::Uri const *resourceUri); + /** + * Determines if a texture manifest exists for a declared texture on @a path. + * @return @c true, if a manifest exists; otherwise @a false. + */ + bool hasTextureManifest(de::Uri const &path) const; + /** * Find the manifest for a declared texture. * diff --git a/doomsday/client/include/resource/texturemanifest.h b/doomsday/client/include/resource/texturemanifest.h index e6d87a2c43..15fb0e640d 100644 --- a/doomsday/client/include/resource/texturemanifest.h +++ b/doomsday/client/include/resource/texturemanifest.h @@ -188,14 +188,27 @@ class TextureManifest : public PathTree::Node /** * Returns @c true if a Texture is presently associated with the manifest. + * + * @see texture(), texturePtr() */ bool hasTexture() const; /** * Returns the logical Texture associated with the manifest. + * + * @see hasTexture() */ Texture &texture() const; + /** + * Returns a pointer to the associated Texture resource; otherwise @c 0. + * + * @see hasTexture() + */ + inline Texture *texturePtr() const { + return hasTexture()? &texture() : 0; + } + /** * Change the logical Texture associated with the manifest. * diff --git a/doomsday/client/src/resource/resourcesystem.cpp b/doomsday/client/src/resource/resourcesystem.cpp index 18688c0999..d61ef96d12 100644 --- a/doomsday/client/src/resource/resourcesystem.cpp +++ b/doomsday/client/src/resource/resourcesystem.cpp @@ -1957,7 +1957,7 @@ void ResourceSystem::initFlatTextures() !percentEncodedName.compareWithoutCase("FF_END")) continue; de::Uri uri("Flats", Path(percentEncodedName)); - if(hasTexture(uri)) continue; + if(hasTextureManifest(uri)) continue; Texture::Flags flags; if(file.container().hasCustom()) flags |= Texture::Custom; @@ -2291,7 +2291,7 @@ MaterialManifest &ResourceSystem::toMaterialManifest(materialid_t id) const throw UnknownMaterialIdError("ResourceSystem::toMaterialManifest", "Invalid material ID " + String::number(id) + ", valid range " + Rangeui(1, d->materialManifestCount + 1).asText()); } -bool ResourceSystem::hasMaterial(de::Uri const &path) const +bool ResourceSystem::hasMaterialManifest(de::Uri const &path) const { try { @@ -2395,7 +2395,7 @@ ResourceSystem::TextureSchemes const& ResourceSystem::allTextureSchemes() const return d->textureSchemes; } -bool ResourceSystem::hasTexture(de::Uri const &path) const +bool ResourceSystem::hasTextureManifest(de::Uri const &path) const { try {