From 37baf5c8e937fd78cd4bfbb5a33a44b10e231f4e Mon Sep 17 00:00:00 2001 From: danij Date: Sat, 20 Dec 2014 01:22:09 +0000 Subject: [PATCH] Refactor|Resources: Base MaterialTextureLayer::AnimationStage on de::Record --- .../include/resource/materialdetaillayer.h | 32 +--- .../include/resource/materialshinelayer.h | 22 +-- .../include/resource/materialtexturelayer.h | 56 +------ doomsday/client/src/def_main.cpp | 53 +++---- doomsday/client/src/resource/material.cpp | 15 +- .../client/src/resource/materialanimator.cpp | 136 ++++++++++------- .../src/resource/materialdetaillayer.cpp | 73 +++------ .../src/resource/materialshinelayer.cpp | 51 +++---- .../src/resource/materialtexturelayer.cpp | 138 +++++------------- 9 files changed, 195 insertions(+), 381 deletions(-) diff --git a/doomsday/client/include/resource/materialdetaillayer.h b/doomsday/client/include/resource/materialdetaillayer.h index 3e933bb302..ddd34874d9 100644 --- a/doomsday/client/include/resource/materialdetaillayer.h +++ b/doomsday/client/include/resource/materialdetaillayer.h @@ -23,7 +23,6 @@ #include #include #include "resource/materialtexturelayer.h" -#include "Texture" /** * Specialized MaterialTextureLayer for describing an animated detail texture layer. @@ -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, @@ -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: @@ -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 diff --git a/doomsday/client/include/resource/materialshinelayer.h b/doomsday/client/include/resource/materialshinelayer.h index 407b5fd948..9df52e5059 100644 --- a/doomsday/client/include/resource/materialshinelayer.h +++ b/doomsday/client/include/resource/materialshinelayer.h @@ -23,7 +23,6 @@ #include #include #include "resource/materialtexturelayer.h" -#include "Texture" /** * Specialized MaterialTextureLayer for describing an animated shine/reflection layer. @@ -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), @@ -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: @@ -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; }; diff --git a/doomsday/client/include/resource/materialtexturelayer.h b/doomsday/client/include/resource/materialtexturelayer.h index f07f87fe7e..5f358cb11b 100644 --- a/doomsday/client/include/resource/materialtexturelayer.h +++ b/doomsday/client/include/resource/materialtexturelayer.h @@ -21,9 +21,9 @@ #define CLIENT_RESOURCE_MATERIALTEXTURELAYER_H #include +#include #include #include "Material" -#include "Texture" /** * Specialized MaterialLayer for describing an animated texture layer. @@ -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: diff --git a/doomsday/client/src/def_main.cpp b/doomsday/client/src/def_main.cpp index c03e464107..9796d5c2a6 100644 --- a/doomsday/client/src/def_main.cpp +++ b/doomsday/client/src/def_main.cpp @@ -939,14 +939,14 @@ static void configureMaterial(Material &mat, ded_material_t const &def) MaterialTextureLayer &layer0 = mat.layer(0).as(); 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. @@ -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. } } } @@ -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) @@ -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. } @@ -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) @@ -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))); @@ -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. } diff --git a/doomsday/client/src/resource/material.cpp b/doomsday/client/src/resource/material.cpp index f70a22e451..4e1ddd005e 100644 --- a/doomsday/client/src/resource/material.cpp +++ b/doomsday/client/src/resource/material.cpp @@ -214,7 +214,7 @@ DENG2_PIMPL(Material) for(Layer *layer : layers) { if(layer->is()) continue; - if(layer->is()) continue; + if(layer->is()) continue; if(auto *texLayer = layer->maybeAs()) { @@ -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; @@ -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); diff --git a/doomsday/client/src/resource/materialanimator.cpp b/doomsday/client/src/resource/materialanimator.cpp index 56705c3feb..05a3707a4d 100644 --- a/doomsday/client/src/resource/materialanimator.cpp +++ b/doomsday/client/src/resource/materialanimator.cpp @@ -232,6 +232,25 @@ void MaterialAnimator::Decoration::reset() // ------------------------------------------------------------------------------------ +/** + * Returns the Texture in effect for the given animation stage, if any. + * + * @todo optimize: Perform this lookup once (when assets are cached). + */ +static Texture *findTextureForAnimationStage(MaterialTextureLayer::AnimationStage const &stage, + String const &propertyName = "texture") +{ + try + { + return &resSys().texture(de::Uri(stage.gets(propertyName, ""), RC_NULL)); + } + catch(TextureManifest::MissingTextureError &) + {} + catch(ResourceSystem::MissingManifestError &) + {} + return nullptr; +} + DENG2_PIMPL(MaterialAnimator) { Material *material = nullptr; ///< Material to animate (not owned). @@ -368,35 +387,35 @@ DENG2_PIMPL(MaterialAnimator) if(auto const *detailLayer = layer.maybeAs()) { - MaterialDetailLayer::AnimationStage const &stage = detailLayer->stage(ls.stage); - MaterialDetailLayer::AnimationStage const &next = detailLayer->stage(ls.stage + 1); + MaterialTextureLayer::AnimationStage const &stage = detailLayer->stage(ls.stage); + MaterialTextureLayer::AnimationStage const &next = detailLayer->stage(ls.stage + 1); - if(Texture *tex = stage.texture()) + if(Texture *tex = findTextureForAnimationStage(stage)) { - float const contrast = de::clamp(0.f, stage.strength(), 1.f) * ::detailFactor /*Global strength multiplier*/; + float const contrast = de::clamp(0.f, stage.getf("strength"), 1.f) * ::detailFactor /*Global strength multiplier*/; snapshot->textures[TU_DETAIL] = tex->prepareVariant(resSys().detailTextureSpec(contrast)); } // Smooth Texture Animation? if(::smoothTexAnim && &stage != &next) { - if(Texture *tex = next.texture()) + if(Texture *tex = findTextureForAnimationStage(next)) { - float const contrast = de::clamp(0.f, next.strength(), 1.f) * ::detailFactor /*Global strength multiplier*/; + float const contrast = de::clamp(0.f, next.getf("strength"), 1.f) * ::detailFactor /*Global strength multiplier*/; snapshot->textures[TU_DETAIL_INTER] = tex->prepareVariant(resSys().detailTextureSpec(contrast)); } } } - else if(auto const *shineLayer = layer.maybeAs()) + else if(layer.is()) { - MaterialShineLayer::AnimationStage const &stage = shineLayer->stage(ls.stage); - //MaterialShineLayer::AnimationStage const &next = shineLayer->stage(l.stage + 1); + MaterialTextureLayer::AnimationStage const &stage = layer.as().stage(ls.stage); + //MaterialTextureLayer::AnimationStage const &next = layer.stage(l.stage + 1); - if(Texture *tex = stage.texture()) + if(Texture *tex = findTextureForAnimationStage(stage)) { snapshot->textures[TU_SHINE] = tex->prepareVariant(Rend_MapSurfaceShinyTextureSpec()); // We are only interested in a mask if we have a shiny texture. - if(Texture *maskTex = stage.maskTexture()) + if(Texture *maskTex = findTextureForAnimationStage(stage, "maskTexture")) { snapshot->textures[TU_SHINE_MASK] = maskTex->prepareVariant(Rend_MapSurfaceShinyMaskTextureSpec()); } @@ -407,14 +426,14 @@ DENG2_PIMPL(MaterialAnimator) MaterialTextureLayer::AnimationStage const &stage = texLayer->stage(ls.stage); MaterialTextureLayer::AnimationStage const &next = texLayer->stage(ls.stage + 1); - if(Texture *tex = stage.texture()) + if(Texture *tex = findTextureForAnimationStage(stage)) { snapshot->textures[TU_LAYER0 + texLayerIndex] = tex->prepareVariant(*spec->primarySpec); } // Smooth Texture Animation? if(::smoothTexAnim && &stage != &next) { - if(Texture *tex = next.texture()) + if(Texture *tex = findTextureForAnimationStage(next)) { snapshot->textures[TU_LAYER0_INTER + texLayerIndex] = tex->prepareVariant(*spec->primarySpec); } @@ -442,10 +461,10 @@ DENG2_PIMPL(MaterialAnimator) { if(TextureVariant *tex = snapshot->textures[TU_DETAIL]) { - MaterialDetailLayer::AnimationStage const &stage = detailLayer->stage(ls.stage); - MaterialDetailLayer::AnimationStage const &next = detailLayer->stage(ls.stage + 1); + MaterialTextureLayer::AnimationStage const &stage = detailLayer->stage(ls.stage); + MaterialTextureLayer::AnimationStage const &next = detailLayer->stage(ls.stage + 1); - float scale = de::lerp(stage.scale(), next.scale(), ls.inter); + float scale = de::lerp(stage.getf("scale"), next.getf("scale"), ls.inter); if(::detailScale > .0001f) scale *= ::detailScale; // Global scale factor. snapshot->units[TU_DETAIL] = @@ -468,22 +487,31 @@ DENG2_PIMPL(MaterialAnimator) } } } - else if(auto const *shineLayer = layer.maybeAs()) + else if(layer.is()) { if(TextureVariant *tex = snapshot->textures[TU_SHINE]) { - MaterialShineLayer::AnimationStage const &stage = shineLayer->stage(ls.stage); - MaterialShineLayer::AnimationStage const &next = shineLayer->stage(ls.stage + 1); + MaterialTextureLayer::AnimationStage const &stage = layer.as().stage(ls.stage); + MaterialTextureLayer::AnimationStage const &next = layer.as().stage(ls.stage + 1); - Vector2f const scale = Vector2f(1, 1); - Vector2f const origin = de::lerp(stage.origin(), next.origin(), ls.inter); - float const opacity = de::lerp(stage.opacity(), next.opacity(), ls.inter); - Vector3f const minColor = de::lerp(stage.minColor(), next.minColor(), ls.inter); + Vector2f origin; + for(int k = 0; k < 2; ++k) + { + origin[k] = de::lerp(stage.geta("origin")[k].asNumber(), next.geta("origin")[k].asNumber(), ls.inter); + } + + Vector3f minColor; + for(int k = 0; k < 3; ++k) + { + minColor[k] = de::lerp(stage.geta("minColor")[k].asNumber(), next.geta("minColor")[k].asNumber(), ls.inter); + } + + float const opacity = de::lerp(stage.getf("opacity"), next.getf("opacity"), ls.inter); - snapshot->shineBlendMode = stage.blendMode(); + snapshot->shineBlendMode = blendmode_t( stage.geti("blendMode") ); snapshot->shineMinColor = minColor.min(Vector3f(1, 1, 1)).max(Vector3f(0, 0, 0)); - snapshot->units[TU_SHINE] = GLTextureUnit(*tex, scale, origin, de::clamp(0.0f, opacity, 1.0f)); + snapshot->units[TU_SHINE] = GLTextureUnit(*tex, Vector2f(1, 1), origin, de::clamp(0.0f, opacity, 1.0f)); // Setup the shine mask texture unit. if(TextureVariant *maskTex = snapshot->textures[TU_SHINE_MASK]) @@ -501,16 +529,20 @@ DENG2_PIMPL(MaterialAnimator) MaterialTextureLayer::AnimationStage const &stage = texLayer->stage(ls.stage); MaterialTextureLayer::AnimationStage const &next = texLayer->stage(ls.stage + 1); - Vector2f const scale = Vector2f(1, 1) / snapshot->dimensions; - Vector2f const origin = de::lerp(stage.origin(), next.origin(), ls.inter); - float const opacity = de::lerp(stage.opacity(), next.opacity(), ls.inter); + Vector2f const scale = Vector2f(1, 1) / snapshot->dimensions; + Vector2f origin; + for(int k = 0; k < 2; ++k) + { + origin[k] = de::lerp(stage.geta("origin")[k].asNumber(), next.geta("origin")[k].asNumber(), ls.inter); + } + float const opacity = de::lerp(stage.getf("opacity"), next.getf("opacity"), ls.inter); snapshot->units[TU_LAYER0 + texLayerIndex] = GLTextureUnit(*tex, scale, origin, de::clamp(0.0f, opacity, 1.0f)); // Glow strength is taken from texture layer #0. if(texLayerIndex == 0) { - snapshot->glowStrength = de::lerp(stage.glowStrength(), next.glowStrength(), ls.inter); + snapshot->glowStrength = de::lerp(stage.getf("glowStrength"), next.getf("glowStrength"), ls.inter); } // Setup the inter texture unit. @@ -677,37 +709,31 @@ void MaterialAnimator::cacheAssets() for(int i = 0; i < material().layerCount(); ++i) { - MaterialLayer &layer = material().layer(i); - - for(int k = 0; k < layer.stageCount(); ++k) + if(MaterialTextureLayer *layer = material().layer(i).maybeAs()) { - if(auto *detailLayer = layer.maybeAs()) - { - MaterialDetailLayer::AnimationStage &stage = detailLayer->stage(k); - if(Texture *tex = stage.texture()) - { - float const contrast = de::clamp(0.f, stage.strength(), 1.f) * detailFactor /*Global strength multiplier*/; - tex->prepareVariant(resSys().detailTextureSpec(contrast)); - } - } - else if(auto *shineLayer = layer.maybeAs()) + for(int k = 0; k < layer->stageCount(); ++k) { - MaterialShineLayer::AnimationStage &stage = shineLayer->stage(k); - if(Texture *tex = stage.texture()) + MaterialTextureLayer::AnimationStage &stage = layer->stage(k); + + if(Texture *tex = findTextureForAnimationStage(stage)) { - tex->prepareVariant(Rend_MapSurfaceShinyTextureSpec()); - if(Texture *maskTex = stage.maskTexture()) + if(layer->is()) { - maskTex->prepareVariant(Rend_MapSurfaceShinyMaskTextureSpec()); + float const contrast = de::clamp(0.f, stage.getf("strength"), 1.f) * detailFactor /*Global strength multiplier*/; + tex->prepareVariant(resSys().detailTextureSpec(contrast)); + } + else if(layer->is()) + { + tex->prepareVariant(Rend_MapSurfaceShinyTextureSpec()); + if(Texture *maskTex = findTextureForAnimationStage(stage, "maskTexture")) + { + maskTex->prepareVariant(Rend_MapSurfaceShinyMaskTextureSpec()); + } + } + else + { + tex->prepareVariant(*variantSpec().primarySpec); } - } - } - else if(auto *texLayer = layer.maybeAs()) - { - MaterialTextureLayer::AnimationStage &stage = texLayer->stage(k); - if(Texture *tex = stage.texture()) - { - tex->prepareVariant(*variantSpec().primarySpec); } } } diff --git a/doomsday/client/src/resource/materialdetaillayer.cpp b/doomsday/client/src/resource/materialdetaillayer.cpp index 5324d60c92..a6c29f66b5 100644 --- a/doomsday/client/src/resource/materialdetaillayer.cpp +++ b/doomsday/client/src/resource/materialdetaillayer.cpp @@ -23,86 +23,54 @@ using namespace de; -static Texture *findTextureForDetailLayerStage(ded_detail_stage_t const &def) +static de::Uri findTextureForDetailStage(ded_detail_stage_t const &def) { try { if(def.texture) { - return &App_ResourceSystem().textureScheme("Details") - .findByResourceUri(*def.texture).texture(); + return App_ResourceSystem().textureScheme("Details") + .findByResourceUri(*def.texture) + .composeUri(); } } - catch(TextureManifest::MissingTextureError const &) - {} // Ignore this error. catch(TextureScheme::NotFoundError const &) {} // Ignore this error. - return nullptr; + return de::Uri(); } -DENG2_PIMPL_NOREF(MaterialDetailLayer::AnimationStage) -{ - float scale = 1; - float strength = 1; - float maxDistance = 0; - - Instance() {} - Instance(Instance const &other) - : scale (other.scale) - , strength (other.strength) - , maxDistance(other.maxDistance) - {} -}; - -MaterialDetailLayer::AnimationStage::AnimationStage(Texture *texture, int tics, +MaterialDetailLayer::AnimationStage::AnimationStage(de::Uri const &texture, int tics, float variance, float scale, float strength, float maxDistance) : MaterialTextureLayer::AnimationStage(texture, tics, variance) - , d(new Instance) { - d->scale = scale; - d->strength = strength; - d->maxDistance = maxDistance; + set("scale", scale); + set("strength", strength); + set("maxDistance", maxDistance); } MaterialDetailLayer::AnimationStage::AnimationStage(AnimationStage const &other) : MaterialTextureLayer::AnimationStage(other) - , d(new Instance(*other.d)) {} MaterialDetailLayer::AnimationStage::~AnimationStage() {} +void MaterialDetailLayer::AnimationStage::resetToDefaults() +{ + MaterialTextureLayer::AnimationStage::resetToDefaults(); + addNumber("scale", 1); + addNumber("strength", 1); + addNumber("maxDistance", 0); +} + MaterialDetailLayer::AnimationStage * MaterialDetailLayer::AnimationStage::fromDef(ded_detail_stage_t const &def) { - Texture *texture = findTextureForDetailLayerStage(def); + de::Uri const texture = findTextureForDetailStage(def); return new AnimationStage(texture, def.tics, def.variance, def.scale, def.strength, def.maxDistance); } -float MaterialDetailLayer::AnimationStage::scale() const -{ - return d->scale; -} - -float MaterialDetailLayer::AnimationStage::strength() const -{ - return d->strength; -} - -float MaterialDetailLayer::AnimationStage::maxDistance() const -{ - return d->maxDistance; -} - -String MaterialDetailLayer::AnimationStage::description() const -{ - return MaterialTextureLayer::AnimationStage::description() - + _E(l) + "\nScale: " + _E(.) + String::number(d->scale, 'f', 2) - + _E(l) + " Strength: " + _E(.) + String::number(d->strength, 'f', 2) - + _E(l) + " MaxDistance: " + _E(.) + String::number(d->maxDistance, 'f', 2); -} - // ------------------------------------------------------------------------------------ MaterialDetailLayer *MaterialDetailLayer::fromDef(ded_detailtexture_t const &layerDef) @@ -119,11 +87,6 @@ int MaterialDetailLayer::addStage(MaterialDetailLayer::AnimationStage const &sta return _stages.count() - 1; } -MaterialDetailLayer::AnimationStage &MaterialDetailLayer::stage(int index) const -{ - return static_cast(Layer::stage(index)); -} - String MaterialDetailLayer::describe() const { return "Detail layer"; diff --git a/doomsday/client/src/resource/materialshinelayer.cpp b/doomsday/client/src/resource/materialshinelayer.cpp index 523b3ec94f..fd312939f6 100644 --- a/doomsday/client/src/resource/materialshinelayer.cpp +++ b/doomsday/client/src/resource/materialshinelayer.cpp @@ -23,62 +23,56 @@ using namespace de; -static Texture *findTextureForShineLayerStage(ded_shine_stage_t const &def, bool findMask) +static de::Uri findTextureForShineStage(ded_shine_stage_t const &def, bool findMask) { if(de::Uri *resourceUri = (findMask? def.maskTexture : def.texture)) { try { - return &App_ResourceSystem() - .textureScheme(findMask? "Masks" : "Reflections") - .findByResourceUri(*resourceUri).texture(); + return App_ResourceSystem() + .textureScheme(findMask? "Masks" : "Reflections") + .findByResourceUri(*resourceUri) + .composeUri(); } - catch(TextureManifest::MissingTextureError const &) - {} // Ignore this error. catch(TextureScheme::NotFoundError const &) {} // Ignore this error. } - return nullptr; + return de::Uri(); } -MaterialShineLayer::AnimationStage::AnimationStage(Texture *texture, int tics, float variance, - Texture *maskTexture, blendmode_t blendMode, float opacity, Vector3f const &minColor, - Vector2f const &maskDimensions) +MaterialShineLayer::AnimationStage::AnimationStage(de::Uri const &texture, int tics, + float variance, de::Uri const &maskTexture, blendmode_t blendMode, float opacity, + Vector3f const &minColor, Vector2f const &maskDimensions) : MaterialTextureLayer::AnimationStage(texture, tics, variance, 0, 0, Vector2f(0, 0), maskTexture, maskDimensions, blendMode, opacity) - , _minColor(minColor) -{} +{ + set("minColor", new ArrayValue(minColor)); +} MaterialShineLayer::AnimationStage::AnimationStage(AnimationStage const &other) : MaterialTextureLayer::AnimationStage(other) - , _minColor(other._minColor) {} MaterialShineLayer::AnimationStage::~AnimationStage() {} +void MaterialShineLayer::AnimationStage::resetToDefaults() +{ + MaterialTextureLayer::AnimationStage::resetToDefaults(); + addArray("minColor", new ArrayValue(Vector3f(0, 0, 0))); +} + MaterialShineLayer::AnimationStage * MaterialShineLayer::AnimationStage::fromDef(ded_shine_stage_t const &def) { - Texture *texture = findTextureForShineLayerStage(def, false/*not mask*/); - Texture *maskTexture = findTextureForShineLayerStage(def, true/*mask*/); + de::Uri const texture = findTextureForShineStage(def, false/*not mask*/); + de::Uri const maskTexture = findTextureForShineStage(def, true/*mask*/); return new AnimationStage(texture, def.tics, def.variance, maskTexture, def.blendMode, def.shininess, Vector3f(def.minColor), Vector2f(def.maskWidth, def.maskHeight)); } -Vector3f const &MaterialShineLayer::AnimationStage::minColor() const -{ - return _minColor; -} - -String MaterialShineLayer::AnimationStage::description() const -{ - return MaterialTextureLayer::AnimationStage::description() - + _E(l) + " MinColor: " + _E(.) + _minColor.asText(); -} - // ------------------------------------------------------------------------------------ MaterialShineLayer::MaterialShineLayer() @@ -102,11 +96,6 @@ int MaterialShineLayer::addStage(MaterialShineLayer::AnimationStage const &stage return _stages.count() - 1; } -MaterialShineLayer::AnimationStage &MaterialShineLayer::stage(int index) const -{ - return static_cast(Layer::stage(index)); -} - String MaterialShineLayer::describe() const { return "Shine layer"; diff --git a/doomsday/client/src/resource/materialtexturelayer.cpp b/doomsday/client/src/resource/materialtexturelayer.cpp index e52cd99938..327e8a885f 100644 --- a/doomsday/client/src/resource/materialtexturelayer.cpp +++ b/doomsday/client/src/resource/materialtexturelayer.cpp @@ -23,129 +23,57 @@ using namespace de; -DENG2_PIMPL_NOREF(MaterialTextureLayer::AnimationStage) -{ - Vector2f origin; - Texture *texture = nullptr; ///< Not owned. - Texture *maskTexture = nullptr; ///< Not owned. - Vector2f maskDimensions; - blendmode_t blendMode = BM_NORMAL; - float opacity = 1; - - float glowStrength = 0; - float glowStrengthVariance = 0; - - Instance() {} - Instance(Instance const &other) - : IPrivate() - , origin (other.origin) - , texture (other.texture) - , maskTexture (other.maskTexture) - , maskDimensions (other.maskDimensions) - , blendMode (other.blendMode) - , opacity (other.opacity) - , glowStrength (other.glowStrength) - , glowStrengthVariance(other.glowStrengthVariance) - {} -}; - -MaterialTextureLayer::AnimationStage::AnimationStage(Texture *texture, int tics, +MaterialTextureLayer::AnimationStage::AnimationStage(de::Uri const &texture, int tics, float variance, float glowStrength, float glowStrengthVariance, Vector2f const origin, - Texture *maskTexture, Vector2f const &maskDimensions, blendmode_t blendMode, float opacity) - : Stage(tics, variance) - , d(new Instance) + de::Uri const &maskTexture, Vector2f const &maskDimensions, blendmode_t blendMode, float opacity) + : Record() + , Stage(tics, variance) { - d->origin = origin; - d->texture = texture; - d->maskTexture = maskTexture; - d->maskDimensions = maskDimensions; - d->blendMode = blendMode; - d->opacity = opacity; - - d->glowStrength = glowStrength; - d->glowStrengthVariance = glowStrengthVariance; + resetToDefaults(); + + set("origin", new ArrayValue(origin)); + set("texture", texture.asText()); + set("maskTexture", maskTexture.asText()); + set("maskDimensions", new ArrayValue(maskDimensions)); + set("blendMode", blendMode); + set("opacity", opacity); + + set("glowStrength", glowStrength); + set("glowStrengthVariance", glowStrengthVariance); } MaterialTextureLayer::AnimationStage::AnimationStage(AnimationStage const &other) - : Stage(other) - , d(new Instance(*other.d)) + : Record(other) + , Stage(other) {} MaterialTextureLayer::AnimationStage::~AnimationStage() {} +void MaterialTextureLayer::AnimationStage::resetToDefaults() +{ + addArray ("origin", new ArrayValue(Vector2f(0, 0))); + addText ("texture", ""); + addText ("maskTexture", ""); + addArray ("maskDimensions", new ArrayValue(Vector2f(0, 0))); + addNumber("blendMode", BM_NORMAL); + addNumber("opacity", 1); + addNumber("glowStrength", 0); + addNumber("glowStrengthVariance", 0); +} + MaterialTextureLayer::AnimationStage * MaterialTextureLayer::AnimationStage::fromDef(ded_material_layer_stage_t const &def) { - Texture *texture = (def.texture? App_ResourceSystem().texturePtr(*def.texture) : nullptr); + de::Uri const texture = (def.texture? *def.texture : de::Uri()); return new AnimationStage(texture, def.tics, def.variance, def.glowStrength, def.glowStrengthVariance, Vector2f(def.texOrigin)); } -Texture *MaterialTextureLayer::AnimationStage::texture() const -{ - return d->texture; -} - -Vector2f const &MaterialTextureLayer::AnimationStage::origin() const -{ - return d->origin; -} - -Texture *MaterialTextureLayer::AnimationStage::maskTexture() const -{ - return d->maskTexture; -} - -Vector2f const &MaterialTextureLayer::AnimationStage::maskDimensions() const -{ - return d->maskDimensions; -} - -blendmode_t MaterialTextureLayer::AnimationStage::blendMode() const -{ - return d->blendMode; -} - -float MaterialTextureLayer::AnimationStage::opacity() const -{ - return d->opacity; -} - -float MaterialTextureLayer::AnimationStage::glowStrength() const -{ - return d->glowStrength; -} - -float MaterialTextureLayer::AnimationStage::glowStrengthVariance() const -{ - return d->glowStrengthVariance; -} - String MaterialTextureLayer::AnimationStage::description() const { - String const path = (d->texture? d->texture->manifest().composeUri().asText() : "(prev)"); - - String str = String(_E(l) "Tics: ") + _E(.) + (tics > 0? String("%1 (~%2)").arg(tics).arg(variance, 0, 'f', 2) : "-1") - + _E(l) + " Origin: " + _E(.) + d->origin.asText() - + _E(l) + " Texture: \"" + _E(.) + path + "\""; - - if(d->maskTexture) - { - str += String(_E(l) "\nMaskTexture: \"") + _E(.) + d->maskTexture->manifest().composeUri().asText() + "\"" - + _E(l) + " MaskDimensions: " + _E(.) + d->maskDimensions.asText(); - } - - str += String(_E(l) "\nBlendMode: ") + _E(.) + R_NameForBlendMode(d->blendMode) - + _E(l) + " Opacity: " + _E(.) + String::number(d->opacity, 'f', 2) - + _E(l) + " Glow: " + _E(.) + String("%1 (~%2)").arg(d->glowStrength, 0, 'f', 2).arg(d->glowStrengthVariance, 0, 'f', 2); - - return str; -} - -void MaterialTextureLayer::AnimationStage::setTexture(Texture *newTexture) -{ - d->texture = newTexture; + /// @todo Record::asText() formatting is not intended for end users. + return asText(); } // ------------------------------------------------------------------------------------ @@ -175,7 +103,7 @@ bool MaterialTextureLayer::hasGlow() const { for(int i = 0; i < stageCount(); ++i) { - if(stage(i).glowStrength() > .0001f) + if(stage(i).getf("glowStrength") > .0001f) return true; } return false;