Skip to content

Commit

Permalink
Surface: Added audience for MaterialOriginChange notification
Browse files Browse the repository at this point in the history
Plus minor interface improvements.
  • Loading branch information
danij-deng committed Apr 11, 2013
1 parent 1f2dbbd commit f2cefb6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 77 deletions.
52 changes: 43 additions & 9 deletions doomsday/client/include/map/surface.h
Expand Up @@ -49,13 +49,27 @@ class Surface : public de::MapElement
/// The referenced property is not writeable. @ingroup errors
DENG2_ERROR(WritePropertyError);

/**
* Observers to be notified when the normal vector changes.
*/
DENG2_DEFINE_AUDIENCE(NormalChange,
void normalChanged(Surface &surface, de::Vector3f oldNormal,
int changedAxes /*bit-field (0x1=X, 0x2=Y, 0x4=Z)*/))

/**
* Observers to be notified when the @em sharp material origin changes.
*/
DENG2_DEFINE_AUDIENCE(MaterialOriginChange,
void materialOriginChanged(Surface &surface, de::Vector2f oldMaterialOrigin,
int changedAxes /*bit-field (0x1=X, 0x2=Y)*/))
/**
* Observers to be notified when the opacity changes.
*/
DENG2_DEFINE_AUDIENCE(OpacityChange,
void opacityChanged(Surface &surface, float oldOpacity))

/**
* Observers to be notified when the tint color changes.
*/
DENG2_DEFINE_AUDIENCE(TintColorChange,
void tintColorChanged(Surface &sector, de::Vector3f const &oldTintColor,
int changedComponents /*bit-field (0x1=Red, 0x2=Green, 0x4=Blue)*/))
Expand Down Expand Up @@ -189,31 +203,51 @@ class Surface : public de::MapElement
*
* @param newOrigin New origin offset in map coordinate space units.
*/
bool setMaterialOrigin(de::Vector2f const &newOrigin);
void setMaterialOrigin(de::Vector2f const &newOrigin);

/**
* @copydoc setMaterialOrigin()
*
* @param x New X origin offset in map coordinate space units.
* @param y New Y origin offset in map coordinate space units.
*/
inline bool setMaterialOrigin(float x, float y) {
inline void setMaterialOrigin(float x, float y) {
return setMaterialOrigin(de::Vector2f(x, y));
}

/**
* Change Material origin X coordinate.
* Change the specified @a component of the material origin for the surface.
* The MaterialOriginChange audience is notified whenever the material origin
* changes.
*
* @param component Index of the component axis (0=X, 1=Y).
* @param newPosition New position for the origin component axis.
*
* @see setMaterialorigin(), setMaterialOriginX(), setMaterialOriginY()
*/
void setMaterialOriginComponent(int component, float newPosition);

/**
* Change the position of the X axis component of the material origin for the
* surface. The MaterialOriginChange audience is notified whenever the material
* origin changes.
*
* @param x New X origin in map space.
* @param newPosition New X axis position for the material origin.
*
* @see setMaterialOriginComponent(), setMaterialOriginY()
*/
bool setMaterialOriginX(float x);
inline void setMaterialOriginX(float newPosition) { setMaterialOriginComponent(0, newPosition); }

/**
* Change Material origin Y coordinate.
* Change the position of the Y axis component of the material origin for the
* surface. The MaterialOriginChange audience is notified whenever the material
* origin changes.
*
* @param newPosition New Y axis position for the material origin.
*
* @param y New Y origin in map space.
* @see setMaterialOriginComponent(), setMaterialOriginX()
*/
bool setMaterialOriginY(float y);
inline void setMaterialOriginY(float newPosition) { setMaterialOriginComponent(1, newPosition); }

/**
* Returns the current interpolated visual material origin of the surface
Expand Down
127 changes: 59 additions & 68 deletions doomsday/client/src/map/surface.cpp
Expand Up @@ -94,6 +94,54 @@ DENG2_PIMPL(Surface)
std::memset(&soundEmitter, 0, sizeof(soundEmitter));
}

void notifyNormalChanged(Vector3f const &oldNormal)
{
// Predetermine which axes have changed.
int changedAxes = 0;
for(int i = 0; i < 3; ++i)
{
if(!de::fequal(normal[i], oldNormal[i]))
changedAxes |= (1 << i);
}

DENG2_FOR_PUBLIC_AUDIENCE(NormalChange, i)
{
i->normalChanged(self, oldNormal, changedAxes);
}
}

void notifyMaterialOriginChanged(Vector2f const &oldMaterialOrigin,
int changedComponents)
{
DENG2_FOR_PUBLIC_AUDIENCE(MaterialOriginChange, i)
{
i->materialOriginChanged(self, oldMaterialOrigin, changedComponents);
}

if(!ddMapSetup && self.isAttachedToMap())
{
#ifdef __CLIENT__
/// @todo Replace with a de::Observer-based mechanism.
self._decorationData.needsUpdate = true;
#endif
/// @todo Do not assume surface is from the CURRENT map.
theMap->scrollingSurfaces().insert(&self);
}
}

void notifyMaterialOriginChanged(Vector2f const &oldMaterialOrigin)
{
// Predetermine which axes have changed.
int changedAxes = 0;
for(int i = 0; i < 3; ++i)
{
if(!de::fequal(materialOrigin[i], oldMaterialOrigin[i]))
changedAxes |= (1 << i);
}

notifyMaterialOriginChanged(oldMaterialOrigin, changedAxes);
}

void notifyOpacityChanged(float oldOpacity)
{
DENG2_FOR_PUBLIC_AUDIENCE(OpacityChange, i)
Expand Down Expand Up @@ -124,22 +172,6 @@ DENG2_PIMPL(Surface)
notifyTintColorChanged(oldTintColor, changedComponents);
}

void notifyNormalChanged(Vector3f const &oldNormal)
{
// Predetermine which axes have changed.
int changedAxes = 0;
for(int i = 0; i < 3; ++i)
{
if(!de::fequal(normal[i], oldNormal[i]))
changedAxes |= (1 << i);
}

DENG2_FOR_PUBLIC_AUDIENCE(NormalChange, i)
{
i->normalChanged(self, oldNormal, changedAxes);
}
}

void updateTangents()
{
vec3f_t v1Tangent, v1Bitangent;
Expand Down Expand Up @@ -329,71 +361,30 @@ Vector2f const &Surface::materialOrigin() const
return d->materialOrigin;
}

bool Surface::setMaterialOrigin(Vector2f const &newOrigin)
void Surface::setMaterialOrigin(Vector2f const &newOrigin)
{
if(d->materialOrigin != newOrigin)
{
d->materialOrigin = newOrigin;
Vector2f oldMaterialOrigin = d->materialOrigin;

if(isAttachedToMap())
{
#ifdef __CLIENT__
/// @todo Replace with a de::Observer-based mechanism.
_decorationData.needsUpdate = true;
#endif
d->materialOrigin = newOrigin;

if(!ddMapSetup)
{
/// @todo Do not assume surface is from the CURRENT map.
theMap->scrollingSurfaces().insert(this);
}
}
// Notify interested parties of the change.
d->notifyMaterialOriginChanged(oldMaterialOrigin);
}
return true;
}

bool Surface::setMaterialOriginX(float x)
void Surface::setMaterialOriginComponent(int component, float newPosition)
{
if(d->materialOrigin.x != x)
if(!de::fequal(d->materialOrigin[component], newPosition))
{
d->materialOrigin.x = x;
if(isAttachedToMap())
{
#ifdef __CLIENT__
/// @todo Replace with a de::Observer-based mechanism.
_decorationData.needsUpdate = true;
#endif
Vector2f oldMaterialOrigin = d->materialOrigin;

if(!ddMapSetup)
{
/// @todo Do not assume surface is from the CURRENT map.
theMap->scrollingSurfaces().insert(this);
}
}
}
return true;
}
d->materialOrigin[component] = newPosition;

bool Surface::setMaterialOriginY(float y)
{
if(d->materialOrigin.y != y)
{
d->materialOrigin.y = y;
if(isAttachedToMap())
{
#ifdef __CLIENT__
/// @todo Replace with a de::Observer-based mechanism.
_decorationData.needsUpdate = true;
#endif

if(!ddMapSetup)
{
/// @todo Do not assume surface is from the CURRENT map.
theMap->scrollingSurfaces().insert(this);
}
}
// Notify interested parties of the change.
d->notifyMaterialOriginChanged(oldMaterialOrigin, (1 << component));
}
return true;
}

Vector2f const &Surface::visMaterialOrigin() const
Expand Down

0 comments on commit f2cefb6

Please sign in to comment.