Skip to content

Commit

Permalink
ResourceSystem: Improved material and texture search APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 4, 2013
1 parent f78ac1e commit ead1ecd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
13 changes: 13 additions & 0 deletions doomsday/client/include/resource/materialmanifest.h
Expand Up @@ -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.
*
Expand Down
46 changes: 35 additions & 11 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

/**
Expand All @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions doomsday/client/include/resource/texturemanifest.h
Expand Up @@ -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.
*
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit ead1ecd

Please sign in to comment.