Navigation Menu

Skip to content

Commit

Permalink
Refactor|Resources: Base MaterialTextureLayer::AnimationStage on de::…
Browse files Browse the repository at this point in the history
…Record
  • Loading branch information
danij-deng committed Dec 20, 2014
1 parent a90e325 commit 37baf5c
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 381 deletions.
32 changes: 3 additions & 29 deletions doomsday/client/include/resource/materialdetaillayer.h
Expand Up @@ -23,7 +23,6 @@
#include <de/String>
#include <doomsday/defs/dedtypes.h>
#include "resource/materialtexturelayer.h"
#include "Texture"

/**
* Specialized MaterialTextureLayer for describing an animated detail texture layer.
Expand All @@ -39,7 +38,7 @@ class MaterialDetailLayer : public MaterialTextureLayer
class AnimationStage : public MaterialTextureLayer::AnimationStage
{
public:
AnimationStage(de::Texture *texture, int tics,
AnimationStage(de::Uri const &texture, int tics,
float variance = 0,
float scale = 1,
float strength = 1,
Expand All @@ -52,25 +51,7 @@ class MaterialDetailLayer : public MaterialTextureLayer
*/
static AnimationStage *fromDef(ded_detail_stage_t const &definition);

/**
* Returns the detail texture scale factor in effect for the animation stage.
*/
float scale() const;

/**
* Returns the detail texture blending factor in effect for the animation stage.
*/
float strength() const;

/**
* Returns the maximum world distance in effect for the animation stage.
*/
float maxDistance() const;

de::String description() const;

private:
DENG2_PRIVATE(d)
void resetToDefaults();
};

public:
Expand All @@ -90,14 +71,7 @@ class MaterialDetailLayer : public MaterialTextureLayer
*/
int addStage(AnimationStage const &stage);

/**
* Lookup an AnimationStage by it's unique @a index.
*
* @param index Index of the AnimationStage to lookup. Will be cycled into valid range.
*/
AnimationStage &stage(int index) const;

de::String describe() const;
};

#endif // CLIENT_RESOURCE_MATERIALDETAILTEXTURELAYER_H
#endif // CLIENT_RESOURCE_MATERIALDETAILLAYER_H
22 changes: 3 additions & 19 deletions doomsday/client/include/resource/materialshinelayer.h
Expand Up @@ -23,7 +23,6 @@
#include <de/String>
#include <doomsday/defs/dedtypes.h>
#include "resource/materialtexturelayer.h"
#include "Texture"

/**
* Specialized MaterialTextureLayer for describing an animated shine/reflection layer.
Expand All @@ -39,8 +38,8 @@ class MaterialShineLayer : public MaterialTextureLayer
class AnimationStage : public MaterialTextureLayer::AnimationStage
{
public:
AnimationStage(de::Texture *texture, int tics, float variance,
de::Texture *maskTexture = nullptr,
AnimationStage(de::Uri const &texture, int tics, float variance,
de::Uri const &maskTexture = de::Uri(),
blendmode_t blendMode = BM_ADD,
float opacity = 1,
de::Vector3f const &minColor = de::Vector3f(0, 0, 0),
Expand All @@ -53,15 +52,7 @@ class MaterialShineLayer : public MaterialTextureLayer
*/
static AnimationStage *fromDef(ded_shine_stage_t const &definition);

/**
* Returns the minimum surface color intensities in effect for the animation stage.
*/
de::Vector3f const &minColor() const;

de::String description() const;

private:
de::Vector3f _minColor;
void resetToDefaults();
};

public:
Expand All @@ -82,13 +73,6 @@ class MaterialShineLayer : public MaterialTextureLayer
*/
int addStage(AnimationStage const &stage);

/**
* Lookup an AnimationStage by it's unique @a index.
*
* @param index Index of the AnimationStage to lookup. Will be cycled into valid range.
*/
AnimationStage &stage(int index) const;

de::String describe() const;
};

Expand Down
56 changes: 6 additions & 50 deletions doomsday/client/include/resource/materialtexturelayer.h
Expand Up @@ -21,9 +21,9 @@
#define CLIENT_RESOURCE_MATERIALTEXTURELAYER_H

#include <de/String>
#include <de/Record>
#include <doomsday/defs/dedtypes.h>
#include "Material"
#include "Texture"

/**
* Specialized MaterialLayer for describing an animated texture layer.
Expand All @@ -36,73 +36,29 @@ class MaterialTextureLayer : public MaterialLayer
/**
* Stages describe texture change animations.
*/
class AnimationStage : public Stage
class AnimationStage : public de::Record, public Stage
{
public:
AnimationStage(de::Texture *texture, int tics,
AnimationStage(de::Uri const &texture, int tics,
float variance = 0,
float glowStrength = 0,
float glowStrengthVariance = 0,
de::Vector2f const origin = de::Vector2f(),
de::Texture *maskTexture = nullptr,
de::Uri const &maskTexture = de::Uri(),
de::Vector2f const &maskDimensions = de::Vector2f(1, 1),
blendmode_t blendMode = BM_NORMAL,
float opacity = 1);
AnimationStage(AnimationStage const &other);
virtual ~AnimationStage();

virtual void resetToDefaults();

/**
* Construct a new AnimationStage from the given @a definition.
*/
static AnimationStage *fromDef(ded_material_layer_stage_t const &definition);

/**
* Returns the Texture in effect for the animation stage.
*/
de::Texture *texture() const;

/**
* Returns the material space, texture origin in effect for the animation stage.
*/
de::Vector2f const &origin() const;

/**
* Returns the mask Texture in effect for the animation stage.
*/
de::Texture *maskTexture() const;

/**
* Returns the mask dimensions in effect for the animation stage.
*/
de::Vector2f const &maskDimensions() const;

/**
* Returns the opacity factor in effect for the animation stage.
*/
float opacity() const;

/**
* Returns the texture blending mode in effect for the animation stage.
*/
blendmode_t blendMode() const;

/**
* Returns the glow strength factor in effect for the animation stage.
*/
float glowStrength() const;

/**
* Returns the glow strength variance factor in effect for the animation stage.
*/
float glowStrengthVariance() const;

de::String description() const;

/// @todo refactor away:
void setTexture(de::Texture *newTexture);

private:
DENG2_PRIVATE(d)
};

public:
Expand Down
53 changes: 20 additions & 33 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -939,14 +939,14 @@ static void configureMaterial(Material &mat, ded_material_t const &def)
MaterialTextureLayer &layer0 = mat.layer(0).as<MaterialTextureLayer>();
MaterialTextureLayer::AnimationStage &stage0 = layer0.stage(0);

if(stage0.texture())
if(!stage0.gets("texture").isEmpty())
{
// We may need to interpret the layer animation from the now
// deprecated Group definitions.

if(def.autoGenerated && layer0.stageCount() == 1)
{
de::Uri textureUri(stage0.texture()->manifest().composeUri());
de::Uri const textureUri(stage0.gets("texture"), RC_NULL);

// Possibly; see if there is a compatible definition with
// a member named similarly to the texture for layer #0.
Expand All @@ -970,20 +970,13 @@ static void configureMaterial(Material &mat, ded_material_t const &def)
startFrame++;
for(int i = 0; i < grp->members.size() - 1; ++i)
{
int frame = de::wrap(startFrame + i, 0, grp->members.size());
int const frame = de::wrap(startFrame + i, 0, grp->members.size());
ded_group_member_t const &gm = grp->members[frame];

if(!gm.material) continue;

try
if(gm.material)
{
Texture &texture = resSys().texture(*gm.material);
layer0.addStage(MaterialTextureLayer::AnimationStage(&texture, gm.tics, gm.randomTics / float( gm.tics )));
layer0.addStage(MaterialTextureLayer::AnimationStage(*gm.material, gm.tics, gm.randomTics / float( gm.tics )));
}
catch(TextureManifest::MissingTextureError const &)
{} // Ignore this error.
catch(ResourceSystem::MissingManifestError const &)
{} // Ignore this error.
}
}
}
Expand All @@ -994,7 +987,7 @@ static void configureMaterial(Material &mat, ded_material_t const &def)
{
MaterialTextureLayer::AnimationStage &stage = layer0.stage(i);
ded_detailtexture_t const *detailDef =
tryFindDetailTexture(stage.texture()->manifest().composeUri(),
tryFindDetailTexture(stage.gets("texture"),
/*UNKNOWN VALUE,*/ mat.manifest().isCustom());

if(!detailDef || !detailDef->stage.texture)
Expand All @@ -1010,23 +1003,21 @@ static void configureMaterial(Material &mat, ded_material_t const &def)
// Add a new stage.
try
{
Texture &texture = resSys().textureScheme("Details").findByResourceUri(*detailDef->stage.texture).texture();
dlayer->addStage(MaterialDetailLayer::AnimationStage(&texture, stage.tics, stage.variance,
detailDef->stage.scale, detailDef->stage.strength,
detailDef->stage.maxDistance));
TextureManifest &texture = resSys().textureScheme("Details").findByResourceUri(*detailDef->stage.texture);
dlayer->addStage(MaterialDetailLayer::AnimationStage(texture.composeUri(), stage.tics, stage.variance,
detailDef->stage.scale, detailDef->stage.strength,
detailDef->stage.maxDistance));

if(dlayer->stageCount() == 2)
{
// Update the first stage with timing info.
MaterialTextureLayer::AnimationStage const &stage0 = layer0.stage(0);
MaterialDetailLayer::AnimationStage &dstage0 = dlayer->stage(0);
MaterialTextureLayer::AnimationStage const &stage0 = layer0.stage(0);
MaterialTextureLayer::AnimationStage &dstage0 = dlayer->stage(0);

dstage0.tics = stage0.tics;
dstage0.variance = stage0.variance;
}
}
catch(TextureManifest::MissingTextureError const &)
{} // Ignore this error.
catch(ResourceSystem::MissingManifestError const &)
{} // Ignore this error.
}
Expand All @@ -1038,7 +1029,7 @@ static void configureMaterial(Material &mat, ded_material_t const &def)
{
MaterialTextureLayer::AnimationStage &stage = layer0.stage(i);
ded_reflection_t const *shineDef =
tryFindReflection(stage.texture()->manifest().composeUri(),
tryFindReflection(stage.gets("texture"),
/*UNKNOWN VALUE,*/ mat.manifest().isCustom());

if(!shineDef || !shineDef->stage.texture)
Expand All @@ -1054,25 +1045,23 @@ static void configureMaterial(Material &mat, ded_material_t const &def)
// Add a new stage.
try
{
Texture &texture = resSys().textureScheme("Reflections")
.findByResourceUri(*shineDef->stage.texture).texture();
TextureManifest &texture = resSys().textureScheme("Reflections")
.findByResourceUri(*shineDef->stage.texture);

Texture *maskTexture = nullptr;
TextureManifest *maskTexture = nullptr;
if(shineDef->stage.maskTexture)
{
try
{
maskTexture = &resSys().textureScheme("Masks")
.findByResourceUri(*shineDef->stage.maskTexture).texture();
.findByResourceUri(*shineDef->stage.maskTexture);
}
catch(TextureManifest::MissingTextureError const &)
{} // Ignore this error.
catch(ResourceSystem::MissingManifestError const &)
{} // Ignore this error.
}

slayer->addStage(MaterialShineLayer::AnimationStage(&texture, stage.tics, stage.variance,
maskTexture, shineDef->stage.blendMode,
slayer->addStage(MaterialShineLayer::AnimationStage(texture.composeUri(), stage.tics, stage.variance,
maskTexture->composeUri(), shineDef->stage.blendMode,
shineDef->stage.shininess,
Vector3f(shineDef->stage.minColor),
Vector2f(shineDef->stage.maskWidth, shineDef->stage.maskHeight)));
Expand All @@ -1081,14 +1070,12 @@ static void configureMaterial(Material &mat, ded_material_t const &def)
{
// Update the first stage with timing info.
MaterialTextureLayer::AnimationStage const &stage0 = layer0.stage(0);
MaterialShineLayer::AnimationStage &sstage0 = slayer->stage(0);
MaterialTextureLayer::AnimationStage &sstage0 = slayer->stage(0);

sstage0.tics = stage0.tics;
sstage0.variance = stage0.variance;
}
}
catch(TextureManifest::MissingTextureError const &)
{} // Ignore this error.
catch(ResourceSystem::MissingManifestError const &)
{} // Ignore this error.
}
Expand Down
15 changes: 11 additions & 4 deletions doomsday/client/src/resource/material.cpp
Expand Up @@ -214,7 +214,7 @@ DENG2_PIMPL(Material)
for(Layer *layer : layers)
{
if(layer->is<MaterialDetailLayer>()) continue;
if(layer->is<MaterialShineLayer>()) continue;
if(layer->is<MaterialShineLayer>()) continue;

if(auto *texLayer = layer->maybeAs<MaterialTextureLayer>())
{
Expand All @@ -234,7 +234,14 @@ DENG2_PIMPL(Material)
{
if(texLayer->stageCount() >= 1)
{
return texLayer->stage(0).texture();
try
{
return &App_ResourceSystem().texture(de::Uri(texLayer->stage(0).gets("texture"), RC_NULL));
}
catch(TextureManifest::MissingTextureError &)
{}
catch(ResourceSystem::MissingManifestError &)
{}
}
}
return nullptr;
Expand Down Expand Up @@ -273,8 +280,8 @@ DENG2_PIMPL(Material)
DENG2_ASSERT(!haveValidDimensions()); // Sanity check.
DENG2_ASSERT(inheritDimensionsTexture() == &texture); // Sanity check.

// Clear the association so we don't try to cancel notifications later.
firstTextureLayer()->stage(0).setTexture(nullptr);
/// @todo kludge: Clear the association so we don't try to cancel notifications later.
firstTextureLayer()->stage(0).set("texture", "");

#if !defined(DENG2_DEBUG)
DENG2_UNUSED(texture);
Expand Down

0 comments on commit 37baf5c

Please sign in to comment.