Skip to content

Commit

Permalink
Refactor|libdoomsday|DED: Reimplemented Decoration definitions using …
Browse files Browse the repository at this point in the history
…DED 2.0 components
  • Loading branch information
danij-deng committed Feb 8, 2015
1 parent 0227ce2 commit 77cd24e
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 552 deletions.
6 changes: 3 additions & 3 deletions doomsday/client/include/def_main.h
Expand Up @@ -3,7 +3,7 @@
* @ingroup defs
*
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -231,9 +231,9 @@ StringArray *Def_ListMobjTypeIDs(void);
StringArray *Def_ListStateIDs(void);

/**
* Returns @c true iff @a def is compatible with the specified context.
* Returns @c true iff @a decorDef is compatible with the specified context.
*/
bool Def_IsAllowedDecoration(ded_decoration_t const *def, /*bool hasExternal,*/ bool isCustom);
bool Def_IsAllowedDecoration(de::Record const &decorDef, /*bool hasExternal,*/ bool isCustom);

/**
* Returns @c true iff @a def is compatible with the specified context.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/include/r_util.h
@@ -1,7 +1,7 @@
/** @file r_util.h Refresh Utility Routines.
/** @file r_util.h Refresh Utility Routines.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -42,7 +42,7 @@ struct LightRange

LightRange(float _min = 0, float _max = 0) : min(_min), max(_max) {}
LightRange(float const minMax[2]) : min(minMax[0]), max(minMax[1]) {}
LightRange(de::Vector2f const minMax) : min(minMax.x), max(minMax.y) {}
LightRange(de::Vector2f const &minMax) : min(minMax.x), max(minMax.y) {}
LightRange(LightRange const &other) : min(other.min), max(other.max) {}

/// Returns a textual representation of the lightlevels.
Expand Down
1 change: 0 additions & 1 deletion doomsday/client/include/resource/materiallightdecoration.h
Expand Up @@ -69,7 +69,6 @@ class MaterialLightDecoration : public Material::Decoration
* Construct a new AnimationStage from the given @a stageDef.
*/
static AnimationStage *fromDef(de::Record const &stageDef);
static AnimationStage *fromDef(ded_decorlight_stage_t const &stageDef);

de::String description() const;
};
Expand Down
69 changes: 32 additions & 37 deletions doomsday/client/src/def_main.cpp
Expand Up @@ -29,6 +29,8 @@
#include <de/findfile.h>
#include <de/App>
#include <de/NativePath>
#include <de/RecordValue>
#include <doomsday/defs/decoration.h>
#include <doomsday/defs/dedfile.h>
#include <doomsday/defs/dedparser.h>
#include <doomsday/defs/material.h>
Expand Down Expand Up @@ -829,22 +831,27 @@ static void generateMaterialDefs()
#ifdef __CLIENT__

/// @todo $revise-texture-animation
static ded_decoration_t *tryFindDecoration(de::Uri const &uri, /*bool hasExternal,*/ bool isCustom)
static Record const *tryFindDecoration(de::Uri const &uri, /*bool hasExternal,*/ bool isCustom)
{
for(int i = defs.decorations.size() - 1; i >= 0; i--)
if(!uri.isEmpty())
{
ded_decoration_t *def = &defs.decorations[i];
if(def->material && *def->material == uri)
DictionaryValue::Elements const &decorationsByMaterial = defs.decorations.lookup("material").elements();
for(auto const &pair : decorationsByMaterial)
{
// Is this suitable?
if(Def_IsAllowedDecoration(def, /*hasExternal,*/ isCustom))
return def;
Record const &decorDef = *pair.second->as<RecordValue>().record();
de::Uri const materialUri(decorDef.gets("material"), RC_NULL);
if(materialUri == uri)
{
// Is this suitable?
if(Def_IsAllowedDecoration(decorDef, /*hasExternal,*/ isCustom))
return &decorDef;
}
}
}
return nullptr; // None found.
return nullptr; // Not found.
}

static inline ded_decoration_t *tryFindDecorationForMaterial(Material const &mat)
static inline Record const *tryFindDecorationForMaterial(Material const &mat)
{
return tryFindDecoration(mat.manifest().composeUri(), mat.manifest().isCustom());
}
Expand All @@ -867,9 +874,6 @@ static void redecorateMaterial(Material &material, Record const &def)
{
defn::MaterialDecoration decorDef(matDef.decoration(i));

// Is this valid? (A zero number of stages signifies the last).
//if(!decorDef.stageCount()) break;

for(int k = 0; k < decorDef.stageCount(); ++k)
{
Record const &st = decorDef.stage(k);
Expand All @@ -888,21 +892,12 @@ static void redecorateMaterial(Material &material, Record const &def)

// Perhaps old style linked decoration definitions?
/// @todo fixme: Need to factor in the decoration definitions for all animation frames.
if(ded_decoration_t *decorDef = tryFindDecorationForMaterial(material))
if(Record const *definition = tryFindDecorationForMaterial(material))
{
for(int i = 0; i < DED_DECOR_NUM_LIGHTS; ++i)
defn::Decoration decorDef(*definition);
for(int i = 0; i < decorDef.lightCount(); ++i)
{
ded_decorlight_t const &lightDef = decorDef->lights[i];

// Is this valid? (A zero-strength color signifies the last).
if(Vector3f(lightDef.stage.color) == Vector3f(0, 0, 0))
break;

// Translate the old style definition.
std::unique_ptr<MaterialLightDecoration> decor(new MaterialLightDecoration(lightDef.patternSkip, lightDef.patternOffset));
std::unique_ptr<MaterialLightDecoration::AnimationStage> tempStage(MaterialLightDecoration::AnimationStage::fromDef(lightDef.stage));
decor->addStage(*tempStage); // makes a copy.
material.addDecoration(decor.release()); // takes ownership.
material.addDecoration(MaterialLightDecoration::fromDef(decorDef.light(i)));
}
}
}
Expand Down Expand Up @@ -1285,16 +1280,16 @@ void Def_Read()
// Decorations. (Define textures).
for(int i = 0; i < defs.decorations.size(); ++i)
{
ded_decoration_t *dec = &defs.decorations[i];
for(int k = 0; k < DED_DECOR_NUM_LIGHTS; ++k)
defn::Decoration decorDef(defs.decorations[i]);
for(int k = 0; k < decorDef.lightCount(); ++k)
{
ded_decorlight_t *dl = &dec->lights[k];
if(Vector3f(dl->stage.color) != Vector3f(0, 0, 0))
Record const &st = defn::MaterialDecoration(decorDef.light(k)).stage(0);
if(Vector3f(st.geta("color")) != Vector3f(0, 0, 0))
{
if(dl->stage.up) defineLightmap(*dl->stage.up);
if(dl->stage.down) defineLightmap(*dl->stage.down);
if(dl->stage.sides) defineLightmap(*dl->stage.sides);
if(dl->stage.flare) defineFlaremap(*dl->stage.flare);
defineLightmap(de::Uri(st["lightmapUp"], RC_NULL));
defineLightmap(de::Uri(st["lightmapDown"], RC_NULL));
defineLightmap(de::Uri(st["lightmapSide"], RC_NULL));
defineFlaremap(de::Uri(st["haloTexture"], RC_NULL));
}
}
}
Expand Down Expand Up @@ -2042,11 +2037,11 @@ StringArray *Def_ListStateIDs()
return array;
}

bool Def_IsAllowedDecoration(ded_decoration_t const *def, /*bool hasExternal,*/ bool isCustom)
bool Def_IsAllowedDecoration(Record const &decorDef, /*bool hasExternal,*/ bool isCustom)
{
//if(hasExternal) return (def->flags & DCRF_EXTERNAL) != 0;
if(!isCustom) return (def->flags & DCRF_NO_IWAD) == 0;
return (def->flags & DCRF_PWAD) != 0;
//if(hasExternal) return (decorDef.geti("flags") & DCRF_EXTERNAL) != 0;
if(!isCustom) return (decorDef.geti("flags") & DCRF_NO_IWAD) == 0;
return (decorDef.geti("flags") & DCRF_PWAD) != 0;
}

bool Def_IsAllowedReflection(ded_reflection_t const *def, /*bool hasExternal,*/ bool isCustom)
Expand Down
37 changes: 1 addition & 36 deletions doomsday/client/src/resource/materiallightdecoration.cpp
@@ -1,6 +1,6 @@
/** @file materiallightdecoration.cpp Logical material, light decoration.
*
* @authors Copyright © 2011-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2011-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -95,41 +95,6 @@ MaterialLightDecoration::AnimationStage::fromDef(Record const &stageDef)
haloTexture, haloTextureIndex);
}

MaterialLightDecoration::AnimationStage *
MaterialLightDecoration::AnimationStage::fromDef(ded_decorlight_stage_t const &stageDef)
{
Texture *lightmapUp = stageDef.up? resSys().texture("Lightmaps", *stageDef.up) : nullptr;
Texture *lightmapDown = stageDef.down? resSys().texture("Lightmaps", *stageDef.down) : nullptr;
Texture *lightmapSide = stageDef.sides? resSys().texture("Lightmaps", *stageDef.sides) : nullptr;

int haloTextureIndex = stageDef.sysFlareIdx;
Texture *haloTexture = nullptr;
if(stageDef.flare && !stageDef.flare->isEmpty())
{
DENG2_ASSERT(stageDef.flare);
de::Uri const &haloTextureUri = *stageDef.flare;

// Select a system flare by numeric identifier?
if(haloTextureUri.path().length() == 1 &&
haloTextureUri.path().toStringRef().first().isDigit())
{
haloTextureIndex = haloTextureUri.path().toStringRef().first().digitValue();
}
else
{
haloTexture = resSys().texture("Flaremaps", haloTextureUri);
}
}

return new AnimationStage(stageDef.tics, stageDef.variance,
Vector2f(stageDef.pos), stageDef.elevation,
Vector3f(stageDef.color), stageDef.radius,
stageDef.haloRadius,
LightRange(stageDef.lightLevels),
lightmapUp, lightmapDown, lightmapSide,
haloTexture, haloTextureIndex);
}

String MaterialLightDecoration::AnimationStage::description() const
{
return String(_E(l) "Tics: ") + _E(.) + (tics > 0? String("%1 (~%2)").arg(tics).arg(variance, 0, 'g', 2) : "-1")
Expand Down
56 changes: 56 additions & 0 deletions doomsday/libdoomsday/include/doomsday/defs/decoration.h
@@ -0,0 +1,56 @@
/** @file decoration.h Decoration definition accessor.
*
* @authors Copyright © 2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDOOMSDAY_DEFN_DECORATION_H
#define LIBDOOMSDAY_DEFN_DECORATION_H

#include "definition.h"
#include <de/RecordAccessor>

// Flags for decoration definitions.
#define DCRF_NO_IWAD 0x1 ///< Don't use if from IWAD.
#define DCRF_PWAD 0x2 ///< Can use if from PWAD.
#define DCRF_EXTERNAL 0x4 ///< Can use if from external resource.

namespace defn {

/**
* Utility for handling oldschool decoration definitions.
*/
class LIBDOOMSDAY_PUBLIC Decoration : public Definition
{
public:
Decoration() : Definition() {}
Decoration(Decoration const &other) : Definition(other) {}
Decoration(de::Record &d) : Definition(d) {}
Decoration(de::Record const &d) : Definition(d) {}

void resetToDefaults();

int lightCount() const;
bool hasLight(int index) const;

de::Record &light(int index);
de::Record const &light(int index) const;

de::Record &addLight();
};

} // namespace defn

#endif // LIBDOOMSDAY_DEFN_DECORATION_H
7 changes: 3 additions & 4 deletions doomsday/libdoomsday/include/doomsday/defs/ded.h
@@ -1,7 +1,7 @@
/** @file defs/ded.h Definition namespace.
/** @file ded.h Definition namespace.
*
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -104,11 +104,10 @@ struct LIBDOOMSDAY_PUBLIC ded_s
DEDArray<ded_ptcgen_t> ptcGens;

// Finales.
//DEDArray<ded_finale_t> finales;
DEDRegister finales;

// Decorations.
DEDArray<ded_decoration_t> decorations;
DEDRegister decorations;

// Reflections.
DEDArray<ded_reflection_t> reflections;
Expand Down

0 comments on commit 77cd24e

Please sign in to comment.