Skip to content

Commit

Permalink
Refactor: Materials now observes MaterialManifest derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 3, 2013
1 parent 8cbe33a commit c514544
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions doomsday/client/include/resource/materialmanifest.h
Expand Up @@ -24,6 +24,7 @@
#include "MaterialScheme"
#include "uri.hh"
#include <de/Error>
#include <de/Observers>
#include <de/PathTree>

namespace de {
Expand All @@ -45,6 +46,8 @@ class MaterialManifest : public PathTree::Node
/// Required material instance is missing. @ingroup errors
DENG2_ERROR(MissingMaterialError);

DENG2_DEFINE_AUDIENCE(MaterialDerived, void manifestMaterialDerived(MaterialManifest &manifest, Material &material))

enum Flag
{
/// The manifest was automatically produced for a game/add-on resource.
Expand Down
7 changes: 4 additions & 3 deletions doomsday/client/include/resource/materials.h
Expand Up @@ -29,6 +29,7 @@
#endif
#include "uri.hh"
#include <de/Error>
#include <de/Observers>
#include <QList>
#include <QMap>
#include <QSet>
Expand All @@ -52,7 +53,7 @@ class MaterialManifest;
*
* @ingroup resource
*/
class Materials
class Materials : DENG2_OBSERVES(MaterialManifest, MaterialDerived)
{
/// Internal typedefs for brevity/cleanliness.
typedef class MaterialScheme Scheme;
Expand Down Expand Up @@ -293,8 +294,8 @@ class Materials

#endif // __CLIENT__

/// @todo Refactor away:
void addMaterial(Material &material);
// Observes Manifest MaterialDerived.
void manifestMaterialDerived(MaterialManifest &manifest, Material &material);

private:
DENG2_PRIVATE(d)
Expand Down
7 changes: 5 additions & 2 deletions doomsday/client/include/resource/textures.h
Expand Up @@ -164,12 +164,15 @@ class Textures

/**
* Clear all textures in all schemes.
*
* @see Scheme::clear().
*/
inline void clearAllSchemes()
{
Schemes schemes = allSchemes();
DENG2_FOR_EACH(Schemes, i, schemes){ (*i)->clear(); }
foreach(Scheme *scheme, allSchemes())
{
scheme->clear();
}
}

/**
Expand Down
5 changes: 2 additions & 3 deletions doomsday/client/src/resource/materialmanifest.cpp
Expand Up @@ -62,9 +62,8 @@ Material *MaterialManifest::derive()
// Instantiate and associate the new material with this.
setMaterial(new Material(*this));

// Include the material in the app's scheme-agnostic list of instances.
/// @todo de::Materials should observe instead.
materials().addMaterial(*d->material);
// Notify interested parties that a new material was derived from the manifest.
DENG2_FOR_AUDIENCE(MaterialDerived, i) i->manifestMaterialDerived(*this, material());
}
return &material();
}
Expand Down
7 changes: 6 additions & 1 deletion doomsday/client/src/resource/materials.cpp
Expand Up @@ -351,6 +351,9 @@ MaterialManifest &Materials::declare(Uri const &uri)

Manifest *manifest = &scheme(uri.scheme()).insertManifest(uri.path(), id);

// We want notification when the manifest is derived to produce a material.
manifest->audienceForMaterialDerived += this;

// Add the new manifest to the id index/map.
if(d->manifestCount > d->manifestIdMapSize)
{
Expand All @@ -363,8 +366,10 @@ MaterialManifest &Materials::declare(Uri const &uri)
return *manifest;
}

void Materials::addMaterial(Material &material)
void Materials::manifestMaterialDerived(MaterialManifest &manifest, Material &material)
{
DENG2_UNUSED(manifest);
// Include this new material in the scheme-agnostic list of instances.
d->materials.push_back(&material);
}

Expand Down

0 comments on commit c514544

Please sign in to comment.