From f36e0c6b5718f641502f5b532072ebc1b9c5a136 Mon Sep 17 00:00:00 2001 From: danij Date: Thu, 10 Jan 2013 13:53:25 +0000 Subject: [PATCH] Refactor|Materials: Minor material system cleanup refactorings --- doomsday/engine/include/resource/materials.h | 6 -- doomsday/engine/src/map/p_particle.cpp | 2 +- doomsday/engine/src/map/r_world.cpp | 6 +- doomsday/engine/src/map/surface.cpp | 2 +- doomsday/engine/src/render/lumobj.cpp | 4 +- doomsday/engine/src/render/rend_decor.cpp | 55 ++++++++----------- doomsday/engine/src/resource/material.cpp | 4 +- .../engine/src/resource/materialmanifest.cpp | 27 +++++++-- doomsday/engine/src/resource/materials.cpp | 20 ------- 9 files changed, 56 insertions(+), 70 deletions(-) diff --git a/doomsday/engine/include/resource/materials.h b/doomsday/engine/include/resource/materials.h index 39f1db5e9e..1f8954633d 100644 --- a/doomsday/engine/include/resource/materials.h +++ b/doomsday/engine/include/resource/materials.h @@ -274,12 +274,6 @@ class Materials void updateTextureLinks(MaterialManifest &manifest); - /// @return (Particle) Generator definition associated with @a material else @c NULL. - ded_ptcgen_t const *ptcGenDef(material_t &material); - - /// @return Decoration defintion associated with @a material else @c NULL. - ded_decor_t const *decorationDef(material_t &material); - /** * Create a new Material unless an existing Material is found at the path * (and within the same scheme) as that specified in @a def, in which case diff --git a/doomsday/engine/src/map/p_particle.cpp b/doomsday/engine/src/map/p_particle.cpp index a2d9751305..9d99c4f82b 100644 --- a/doomsday/engine/src/map/p_particle.cpp +++ b/doomsday/engine/src/map/p_particle.cpp @@ -190,7 +190,7 @@ void P_MapSpawnPlaneParticleGens() Plane *plane = sector->SP_plane(j); if(!plane->PS_material) continue; - ded_ptcgen_t const *def = App_Materials()->ptcGenDef(*plane->PS_material); + ded_ptcgen_t const *def = Material_Manifest(plane->PS_material).ptcGenDef(); P_SpawnPlaneParticleGen(def, plane); } } diff --git a/doomsday/engine/src/map/r_world.cpp b/doomsday/engine/src/map/r_world.cpp index d901e1e2f3..32b80003ba 100644 --- a/doomsday/engine/src/map/r_world.cpp +++ b/doomsday/engine/src/map/r_world.cpp @@ -1055,7 +1055,7 @@ boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector *frontSec, Sector *b // Ensure we have up to date info about the material. MaterialSnapshot const &ms = - App_Materials()->prepare(*material, Rend_MapSurfaceMaterialSpec(), true); + App_Materials()->prepare(*material, Rend_MapSurfaceMaterialSpec()); if(ignoreOpacity || (ms.isOpaque() && !frontDef->SW_middleblendmode && frontDef->SW_middlergba[3] >= 1)) { @@ -1464,7 +1464,7 @@ boolean R_IsGlowingPlane(Plane const *pln) if(mat) { MaterialSnapshot const &ms = - App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec(), true); + App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec()); if(!Material_IsDrawable(mat) || ms.glowStrength() > 0) return true; } @@ -1485,7 +1485,7 @@ float R_GlowStrength(Plane const *pln) { /// @todo We should not need to prepare to determine this. MaterialSnapshot const &ms = - App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec(), true); + App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec()); return ms.glowStrength(); } diff --git a/doomsday/engine/src/map/surface.cpp b/doomsday/engine/src/map/surface.cpp index 6cedd4dd17..ff8628ba5d 100644 --- a/doomsday/engine/src/map/surface.cpp +++ b/doomsday/engine/src/map/surface.cpp @@ -89,7 +89,7 @@ boolean Surface_SetMaterial(Surface *suf, material_t *mat) if(DMU_GetType(suf->owner) == DMU_PLANE) { - ded_ptcgen_t const *def = App_Materials()->ptcGenDef(*mat); + ded_ptcgen_t const *def = Material_Manifest(mat).ptcGenDef(); P_SpawnPlaneParticleGen(def, (Plane *)suf->owner); } } diff --git a/doomsday/engine/src/render/lumobj.cpp b/doomsday/engine/src/render/lumobj.cpp index 082e5628e8..dc8699c033 100644 --- a/doomsday/engine/src/render/lumobj.cpp +++ b/doomsday/engine/src/render/lumobj.cpp @@ -749,7 +749,7 @@ static void addLuminous(mobj_t *mo) // Ensure we have up-to-date information about the material. MaterialSnapshot const &ms = - App_Materials()->prepare(*mat, Rend_SpriteMaterialSpec(), true); + App_Materials()->prepare(*mat, Rend_SpriteMaterialSpec()); if(!ms.hasTexture(MTU_PRIMARY)) return; // An invalid sprite texture. pl = (pointlight_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_SPRITE_AUTOLIGHT); @@ -964,7 +964,7 @@ static boolean createGlowLightForSurface(Surface *suf, void * /*parameters*/) // Are we glowing at this moment in time? MaterialSnapshot const &ms = - App_Materials()->prepare(*suf->material, Rend_MapSurfaceMaterialSpec(), true); + App_Materials()->prepare(*suf->material, Rend_MapSurfaceMaterialSpec()); if(!(ms.glowStrength() > .001f)) return true; // Continue iteration. averagecolor_analysis_t const *avgColorAmplified = (averagecolor_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_COLOR_AMPLIFIED); diff --git a/doomsday/engine/src/render/rend_decor.cpp b/doomsday/engine/src/render/rend_decor.cpp index ee82314a8c..b076a2a74d 100644 --- a/doomsday/engine/src/render/rend_decor.cpp +++ b/doomsday/engine/src/render/rend_decor.cpp @@ -462,44 +462,37 @@ static uint generateDecorLights(ded_decorlight_t const *def, Surface *suf, static void updateSurfaceDecorations2(Surface *suf, float offsetS, float offsetT, vec3d_t v1, vec3d_t v2, Sector *sec, boolean visible) { - vec3d_t delta; + if(!visible) return; + + ded_decor_t const *def = Material_Manifest(suf->material).decorationDef(); + if(!def) return; + vec3d_t delta; V3d_Subtract(delta, v2, v1); - if(visible && - (delta[VX] * delta[VY] != 0 || - delta[VX] * delta[VZ] != 0 || - delta[VY] * delta[VZ] != 0)) + if(delta[VX] * delta[VY] != 0 || delta[VX] * delta[VZ] != 0 || delta[VY] * delta[VZ] != 0) { - // Ensure we've prepared a variant of this material. - App_Materials()->prepare(*suf->material, Rend_MapSurfaceMaterialSpec(), - true /*smooth*/, true /*do-create*/); - - ded_decor_t const *def = App_Materials()->decorationDef(*suf->material); - if(def) + int const axis = V3f_MajorAxis(suf->normal); + coord_t width, height; + if(axis == VX || axis == VY) { - int const axis = V3f_MajorAxis(suf->normal); - coord_t width, height; - if(axis == VX || axis == VY) - { - width = sqrt(delta[VX] * delta[VX] + delta[VY] * delta[VY]); - height = delta[VZ]; - } - else - { - width = sqrt(delta[VX] * delta[VX]); - height = delta[VY]; - } + width = sqrt(delta[VX] * delta[VX] + delta[VY] * delta[VY]); + height = delta[VZ]; + } + else + { + width = sqrt(delta[VX] * delta[VX]); + height = delta[VY]; + } - if(width < 0) width = -width; - if(height < 0) height = -height; + if(width < 0) width = -width; + if(height < 0) height = -height; - // Generate a number of lights. - for(uint i = 0; i < DED_DECOR_NUM_LIGHTS; ++i) - { - generateDecorLights(&def->lights[i], suf, suf->material, v1, v2, width, height, - delta, axis, offsetS, offsetT, sec); - } + // Generate a number of lights. + for(uint i = 0; i < DED_DECOR_NUM_LIGHTS; ++i) + { + generateDecorLights(&def->lights[i], suf, suf->material, v1, v2, width, height, + delta, axis, offsetS, offsetT, sec); } } } diff --git a/doomsday/engine/src/resource/material.cpp b/doomsday/engine/src/resource/material.cpp index 5f558e2d66..6f6286f9bc 100644 --- a/doomsday/engine/src/resource/material.cpp +++ b/doomsday/engine/src/resource/material.cpp @@ -452,7 +452,7 @@ boolean Material_HasGlow(material_t *mat) /// @todo We should not need to prepare to determine this. MaterialSnapshot const &ms = - App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec(), true); + App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec()); return (ms.glowStrength() > .0001f); } @@ -704,7 +704,7 @@ boolean Material_HasDecorations(material_t *mat) /// @todo We should not need to prepare to determine this. if(!mat->prepared) { - App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec(), false); + App_Materials()->prepare(*mat, Rend_MapSurfaceMaterialSpec()); } MaterialManifest &manifest = Material_Manifest(mat); if(manifest.decorationDef()) return true; diff --git a/doomsday/engine/src/resource/materialmanifest.cpp b/doomsday/engine/src/resource/materialmanifest.cpp index bde001d463..4ab12dd691 100644 --- a/doomsday/engine/src/resource/materialmanifest.cpp +++ b/doomsday/engine/src/resource/materialmanifest.cpp @@ -21,8 +21,10 @@ #include "de_defs.h" #include -#include "uri.hh" +#include "render/rend_main.h" #include "resource/materials.h" +#include "uri.hh" + #include "resource/materialmanifest.h" namespace de { @@ -164,6 +166,11 @@ ded_detailtexture_t *MaterialManifest::detailTextureDef() const throw MissingMaterialError("MaterialManifest::detailTextureDef", "Missing required material"); } + if(isDedicated) return 0; + + // We must prepare a variant before we can determine which definition is in effect. + materials().prepare(*d->material, Rend_MapSurfaceMaterialSpec()); + // We must prepare to determine which definition is in effect. byte prepared = Material_Prepared(d->material); if(prepared) return d->defs.detailtextures[prepared - 1]; @@ -178,7 +185,11 @@ ded_decor_t *MaterialManifest::decorationDef() const throw MissingMaterialError("MaterialManifest::decorationTextureDef", "Missing required material"); } - // We must prepare to determine which definition is in effect. + if(isDedicated) return 0; + + // We must prepare a variant before we can determine which definition is in effect. + materials().prepare(*d->material, Rend_MapSurfaceMaterialSpec()); + byte prepared = Material_Prepared(d->material); if(prepared) return d->defs.decors[prepared - 1]; return 0; @@ -192,7 +203,11 @@ ded_ptcgen_t *MaterialManifest::ptcGenDef() const throw MissingMaterialError("MaterialManifest::ptcGenDef", "Missing required material"); } - // We must prepare to determine which definition is in effect. + if(isDedicated) return 0; + + // We must prepare a variant before we can determine which definition is in effect. + materials().prepare(*d->material, Rend_MapSurfaceMaterialSpec()); + byte prepared = Material_Prepared(d->material); if(prepared) return d->defs.ptcgens[prepared - 1]; return 0; @@ -206,7 +221,11 @@ ded_reflection_t *MaterialManifest::reflectionDef() const throw MissingMaterialError("MaterialManifest::reflectionDef", "Missing required material"); } - // We must prepare to determine which definition is in effect. + if(isDedicated) return 0; + + // We must prepare a variant before we can determine which definition is in effect. + materials().prepare(*d->material, Rend_MapSurfaceMaterialSpec()); + byte prepared = Material_Prepared(d->material); if(prepared) return d->defs.reflections[prepared - 1]; return 0; diff --git a/doomsday/engine/src/resource/materials.cpp b/doomsday/engine/src/resource/materials.cpp index 75d6e82bd8..da369f8530 100644 --- a/doomsday/engine/src/resource/materials.cpp +++ b/doomsday/engine/src/resource/materials.cpp @@ -750,25 +750,6 @@ MaterialSnapshot const &Materials::prepare(MaterialVariant &variant, return *snapshot; } -ded_decor_t const *Materials::decorationDef(material_t &mat) -{ - if(!Material_Prepared(&mat)) - { - prepare(mat, Rend_MapSurfaceMaterialSpec(), false); - } - return Material_Manifest(&mat).decorationDef(); -} - -ded_ptcgen_t const *Materials::ptcGenDef(material_t &mat) -{ - if(isDedicated) return 0; - if(!Material_Prepared(&mat)) - { - prepare(mat, Rend_MapSurfaceMaterialSpec(), false); - } - return Material_Manifest(&mat).ptcGenDef(); -} - uint Materials::size() const { return d->materials.size(); @@ -884,7 +865,6 @@ static void printVariantInfo(MaterialVariant &variant, int variantIdx) MaterialVariant *next = variant.translationNext(); float inter = variant.translationPoint(); - /// @todo kludge: Should not use App_Materials() here. QByteArray curPath = Material_Manifest(&cur->generalCase()).composeUri().asText().toUtf8(); QByteArray nextPath = Material_Manifest(&next->generalCase()).composeUri().asText().toUtf8();