Skip to content

Commit

Permalink
World|Surface: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 1, 2014
1 parent 9c4d825 commit 68a3bf3
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 150 deletions.
217 changes: 86 additions & 131 deletions doomsday/client/include/world/surface.h
Expand Up @@ -30,7 +30,9 @@
#include "MapElement"
#include "Material"

#ifdef __CLIENT__
class Decoration;
#endif

/**
* Models a "boundless" but otherwise geometric map surface. Boundless in the
Expand Down Expand Up @@ -80,62 +82,102 @@ class Surface : public de::MapElement
*/
de::Matrix3f const &tangentMatrix() const;

inline de::Vector3f tangent() const { return tangentMatrix().column(0); }
inline de::Vector3f bitangent() const { return tangentMatrix().column(1); }
inline de::Vector3f normal() const { return tangentMatrix().column(2); }

/**
* Returns a copy of the normalized tangent vector for the surface.
* Change the tangent space normal vector for the surface. If changed, the
* tangent vectors will be recalculated next time they are needed. The
* NormalChange audience is notified whenever the normal changes.
*
* @param newNormal New normal vector (will be normalized if needed).
*/
inline de::Vector3f tangent() const { return tangentMatrix().column(0); }
Surface &setNormal(de::Vector3f const &newNormal);

/**
* Returns a copy of the normalized bitangent vector for the surface.
* Returns the opacity of the surface. The OpacityChange audience is notified
* whenever the opacity changes.
*
* @see setOpacity()
*/
inline de::Vector3f bitangent() const { return tangentMatrix().column(1); }
float opacity() const;
Surface &setOpacity(float newOpacity);

/**
* Returns the tint color of the surface. The TintColorChange audience is
* notified whenever the tint color changes.
*
* @see setTintColor()
*/
de::Vector3f const &tintColor() const;
Surface &setTintColor(de::Vector3f const &newTintColor);

/**
* Returns a copy of the normalized normal vector for the surface.
* Returns the blendmode for the surface.
*/
inline de::Vector3f normal() const { return tangentMatrix().column(2); }
blendmode_t blendMode() const;
Surface &setBlendMode(blendmode_t newBlendMode);

#ifdef __CLIENT__
/**
* Change the tangent space normal vector for the surface. If changed,
* the tangent vectors will be recalculated next time they are needed.
* The NormalChange audience is notified whenever the normal changes.
* Determine the glow properties of the surface, which, are derived from the
* bound material (averaged color).
*
* @param newNormal New normal vector (will be normalized if needed).
* @param color Amplified glow color is written here.
*
* @return Glow strength/intensity or @c 0 if not presently glowing.
*/
Surface &setNormal(de::Vector3f const &newNormal);
float glow(de::Vector3f &color) const;

public: // Decorations ------------------------------------------------------------

/**
* Returns a copy of the current @ref surfaceFlags of the surface.
* Clear all surface decorations.
*/
int flags() const;
void clearDecorations();

/**
* Change the @ref surfaceFlags of the surface.
* Returns the total number of surface decorations.
*/
int decorationCount() const;

/**
* Add the specified decoration to the surface.
*
* @param flagsToChange Flags to change the value of.
* @param operation Logical operation to perform on the flags.
* @param decoration Decoration to add. Ownership is given to the surface.
*/
Surface &setFlags(int flagsToChange, de::FlagOp operation = de::SetFlags);
void addDecoration(Decoration *decoration);

/**
* Returns @c true iff the surface is flagged @a flagsToTest.
* Iterate through all the surface decorations.
*/
inline bool isFlagged(int flagsToTest) const {
return (flags() & flagsToTest) != 0;
}
de::LoopResult forAllDecorations(std::function<de::LoopResult (Decoration &)> func) const;

/**
* Mark the surface as needing a decoration update.
*/
void markForDecorationUpdate(bool yes = true);

/**
* Returns @c true if the surface is marked for decoration update.
*/
bool needsDecorationUpdate() const;
#endif // __CLIENT__

public: // Material ---------------------------------------------------------------

/**
* Returns @c true iff a material is bound to the surface.
*/
bool hasMaterial() const;

/**
* Returns @c true iff a @em fix material is bound to the surface, which
* was chosen automatically where one was missing. Clients should not be
* notified when a fix material is bound to the surface (as they should
* perform their fixing, locally). However, if the fix material is later
* replaced with a "normally-bound" material, clients should be notified
* as per usual.
* Returns @c true iff a @em fix material is bound to the surface, which was
* chosen automatically where one was missing. Clients should not be notified
* when a fix material is bound to the surface (as they should perform their
* fixing, locally). However, if the fix material is later replaced with a
* "normally-bound" material, clients should be notified as per usual.
*/
bool hasFixMaterial() const;

Expand Down Expand Up @@ -167,93 +209,49 @@ class Surface : public de::MapElement
* @see hasMaterial(), hasFixMaterial()
*/
Material &material() const;
Material *materialPtr() const;

/**
* Returns a pointer to the attributed material of the surface; otherwise @c nullptr.
*
* @see hasMaterial(), hasFixMaterial()
*/
inline Material *materialPtr() const { return hasMaterial()? &material() : nullptr; }

/**
* Change the attributed material of the surface. On client side, any existing
* Change the material attributed to the surface. On client side, any existing
* decorations are cleared whenever the material changes and the surface is
* marked for redecoration.
*
* @param newMaterial New material to apply. Use @c 0 to clear.
* @param newMaterial New material to apply. Use @c nullptr to clear.
* @param isMissingFix @c true= this is a fix for a "missing" material.
*/
Surface &setMaterial(Material *newMaterial, bool isMissingFix = false);

/**
* Returns the material origin offset of the surface.
* Returns @c true if the surface material is mirrored on the X axis.
*/
de::Vector2f const &materialOrigin() const;
bool materialMirrorX() const;

/**
* Change the material origin offset of the surface.
*
* @param newOrigin New origin offset in map coordinate space units.
* Returns @c true if the surface material is mirrored on the Y axis.
*/
Surface &setMaterialOrigin(de::Vector2f const &newOrigin);
bool materialMirrorY() const;

/**
* Compose a URI for the surface's material. If no material is bound then a
* default (i.e., empty) URI is returned.
*
* @see hasMaterial(), MaterialManifest::composeUri()
* Returns the material origin offset for the surface.
*/
de::Uri composeMaterialUri() const;

/**
* Returns the opacity of the surface. The OpacityChange audience is notified
* whenever the opacity changes.
*
* @see setOpacity()
*/
float opacity() const;

/**
* Change the opacity of the surface. The OpacityChange audience is notified
* whenever the opacity changes.
*
* @param newOpacity New opacity strength.
*
* @see opacity()
*/
Surface &setOpacity(float newOpacity);

/**
* Returns the tint color of the surface. The TintColorChange audience is notified
* whenever the tint color changes.
*
* @see setTintColor()
*/
de::Vector3f const &tintColor() const;

/**
* Change the tint color for the surface. The TintColorChange audience is notified
* whenever the tint color changes.
*
* @param newTintColor New tint color.
*
* @see tintColor()
*/
Surface &setTintColor(de::Vector3f const &newTintColor);
de::Vector2f const &materialOrigin() const;
Surface &setMaterialOrigin(de::Vector2f const &newOrigin);

/**
* Returns the blendmode for the surface.
* Returns the material scale factors for the surface.
*/
blendmode_t blendMode() const;
de::Vector2f materialScale() const;

/**
* Change blendmode.
* Compose a URI for the surface's material. If no material is bound then a
* default (i.e., empty) URI is returned.
*
* @param newBlendMode New blendmode.
* @see hasMaterial(), MaterialManifest::composeUri()
*/
Surface &setBlendMode(blendmode_t newBlendMode);
de::Uri composeMaterialUri() const;

#ifdef __CLIENT__
public: // Material origin animation/smoothing ------------------------------------

/**
* Returns the current smoothed (interpolated) material origin for the
Expand Down Expand Up @@ -290,49 +288,6 @@ class Surface : public de::MapElement
*/
void updateMaterialOriginTracking();

/**
* Determine the glow properties of the surface, which, are derived from the
* bound material (averaged color).
*
* Return values:
* @param color Amplified glow color is written here.
*
* @return Glow strength/intensity or @c 0 if not presently glowing.
*/
float glow(de::Vector3f &color) const;

/**
* Clear all surface decorations.
*/
void clearDecorations();

/**
* Returns the total number of surface decorations.
*/
int decorationCount() const;

/**
* Add the specified decoration to the surface.
*
* @param decoration Decoration to add. Ownership is given to the surface.
*/
void addDecoration(Decoration *decoration);

/**
* Iterate through all the surface decorations.
*/
de::LoopResult forAllDecorations(std::function<de::LoopResult (Decoration &)> func) const;

/**
* Mark the surface as needing a decoration update.
*/
void markForDecorationUpdate(bool yes = true);

/**
* Returns @c true if the surface is marked for decoration update.
*/
bool needsDecorationUpdate() const;

#endif // __CLIENT__

protected:
Expand Down
6 changes: 2 additions & 4 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -1898,8 +1898,7 @@ static void writeWallSection(HEdge &hedge, int section,

MaterialSnapshot const &ms = material->prepare(Rend_MapSurfaceMaterialSpec());

Vector2f const materialScale((surface.flags() & DDSUF_MATERIAL_FLIPH)? -1 : 1,
(surface.flags() & DDSUF_MATERIAL_FLIPV)? -1 : 1);
Vector2f const materialScale = surface.materialScale();

rendworldpoly_params_t parm; zap(parm);

Expand Down Expand Up @@ -2120,8 +2119,7 @@ static void writeSubspacePlane(Plane &plane)
}
materialOrigin.y = -materialOrigin.y;

Vector2f const materialScale((surface.flags() & DDSUF_MATERIAL_FLIPH)? -1 : 1,
(surface.flags() & DDSUF_MATERIAL_FLIPV)? -1 : 1);
Vector2f const materialScale = surface.materialScale();

// Set the texture origin, Y is flipped for the ceiling.
Vector3d topLeft(poly.aaBox().minX,
Expand Down
36 changes: 21 additions & 15 deletions doomsday/client/src/world/surface.cpp
Expand Up @@ -193,17 +193,6 @@ Surface &Surface::setNormal(Vector3f const &newNormal)
return *this;
}

int Surface::flags() const
{
return d->flags;
}

Surface &Surface::setFlags(int flagsToChange, FlagOp operation)
{
applyFlagOperation(d->flags, flagsToChange, operation);
return *this;
}

bool Surface::hasMaterial() const
{
return d->material != nullptr;
Expand All @@ -216,14 +205,16 @@ bool Surface::hasFixMaterial() const

Material &Surface::material() const
{
if(d->material)
{
return *d->material;
}
if(d->material) return *d->material;
/// @throw MissingMaterialError Attempted with no material bound.
throw MissingMaterialError("Surface::material", "No material is bound");
}

Material *Surface::materialPtr() const
{
return hasMaterial()? &material() : nullptr;
}

Surface &Surface::setMaterial(Material *newMaterial, bool isMissingFix)
{
if(d->material == newMaterial)
Expand Down Expand Up @@ -300,6 +291,21 @@ Surface &Surface::setMaterialOrigin(Vector2f const &newOrigin)
return *this;
}

bool Surface::materialMirrorX() const
{
return (d->flags & DDSUF_MATERIAL_FLIPH) != 0;
}

bool Surface::materialMirrorY() const
{
return (d->flags & DDSUF_MATERIAL_FLIPV) != 0;
}

Vector2f Surface::materialScale() const
{
return Vector2f(materialMirrorX()? -1 : 1, materialMirrorY()? -1 : 1);
}

de::Uri Surface::composeMaterialUri() const
{
if(!hasMaterial()) return de::Uri();
Expand Down

0 comments on commit 68a3bf3

Please sign in to comment.