Skip to content

Commit

Permalink
Refactor|Materials: Further material system cleanup refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jan 5, 2013
1 parent b4adfbf commit 9b35fe1
Show file tree
Hide file tree
Showing 24 changed files with 878 additions and 603 deletions.
2 changes: 2 additions & 0 deletions doomsday/engine/engine.pro
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ DENG_HEADERS += \
include/resource/material.h \
include/resource/materialbind.h \
include/resource/materials.h \
include/resource/materialscheme.h \
include/resource/materialsnapshot.h \
include/resource/materialvariant.h \
include/resource/models.h \
Expand Down Expand Up @@ -585,6 +586,7 @@ SOURCES += \
src/resource/materialarchive.c \
src/resource/materialbind.cpp \
src/resource/materials.cpp \
src/resource/materialscheme.cpp \
src/resource/materialsnapshot.cpp \
src/resource/materialvariant.cpp \
src/resource/models.cpp \
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/include/dd_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ de::ResourceClass& DD_ResourceClassById(resourceclassid_t classId);
de::ResourceClass& DD_ResourceClassByName(de::String name);

/// @return Symbolic name of the material scheme associated with @a textureSchemeName.
de::String const &DD_MaterialSchemeNameForTextureScheme(de::String textureSchemeName);
de::String DD_MaterialSchemeNameForTextureScheme(de::String textureSchemeName);

extern "C" {
#endif // __cplusplus
Expand Down
63 changes: 35 additions & 28 deletions doomsday/engine/include/resource/materialbind.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
#ifdef __cplusplus

#include "def_data.h"
#include "resource/materials.h"
#include "resource/materialscheme.h"

namespace de {

class Materials;

/**
* Contains extended info about a material binding (see MaterialBind).
* @note POD object.
Expand All @@ -42,34 +44,47 @@ namespace de {
class MaterialBind
{
public:
MaterialBind(MaterialScheme::Index::Node &_direcNode, materialid_t id)
: direcNode(&_direcNode), asocMaterial(0), guid(id), extInfo(0)
{}
MaterialBind(MaterialScheme::Index::Node &_direcNode, materialid_t id);

virtual ~MaterialBind();

~MaterialBind()
{
MaterialBindInfo *detachedInfo = detachInfo();
if(detachedInfo) M_Free(detachedInfo);
}
/**
* Returns the owning scheme of the material bind.
*/
MaterialScheme &scheme() const;

/// Convenience method for returning the name of the owning scheme.
String const &schemeName() const;

/**
* Compose a URI of the form "scheme:path" for the material bind.
*
* The scheme component of the URI will contain the symbolic name of
* the scheme for the material bind.
*
* The path component of the URI will contain the percent-encoded path
* of the material bind.
*/
Uri composeUri(QChar sep = '/') const;

/// @return Unique identifier associated with this.
materialid_t id() const { return guid; }
materialid_t id() const;

/// @return Index node associated with this.
MaterialScheme::Index::Node &directoryNode() const { return *direcNode; }
MaterialScheme::Index::Node &directoryNode() const;

/// @return Material associated with this else @c NULL.
material_t *material() const { return asocMaterial; }
material_t *material() const;

/// @return Extended info owned by this else @c NULL.
MaterialBindInfo *info() const { return extInfo; }
MaterialBindInfo *info() const;

/**
* Attach extended info data to this. If existing info is present it is replaced.
* MaterialBind is given ownership of the info.
* @param info Extended info data to attach.
*/
MaterialBind &attachInfo(MaterialBindInfo &info);
void attachInfo(MaterialBindInfo &info);

/**
* Detach any extended info owned by this and relinquish ownership to the caller.
Expand All @@ -86,9 +101,8 @@ namespace de {
* MaterialBindInfo presently owned by this will destroyed (its invalid).
*
* @param material New Material to associate with this.
* @return This instance.
*/
MaterialBind &setMaterial(material_t *material);
void setMaterial(material_t *material);

/// @return Detail texture definition associated with this else @c NULL
ded_detailtexture_t *detailTextureDef() const;
Expand All @@ -102,19 +116,12 @@ namespace de {
/// @return Reflection definition associated with this else @c NULL
ded_reflection_t *reflectionDef() const;

private:
/// This binding's node in the directory.
MaterialScheme::Index::Node *direcNode;
/// Returns a reference to the application's material system.
static Materials &materials();

/// Material associated with this.
material_t *asocMaterial;

/// Unique identifier.
materialid_t guid;

/// Extended info about this binding. Will be attached upon successfull preparation
/// of the first derived variant of the associated Material.
MaterialBindInfo *extInfo;
private:
struct Instance;
Instance *d;
};

} // namespace de
Expand Down
Loading

0 comments on commit 9b35fe1

Please sign in to comment.