Skip to content

Commit

Permalink
World|Sector: Sector observes smoothed height changes of its floor/ce…
Browse files Browse the repository at this point in the history
…iling planes

Also trimmed some unnecessary fat from Plane on server side.
  • Loading branch information
danij-deng committed Sep 11, 2013
1 parent d1e9ded commit e41bdaf
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 85 deletions.
6 changes: 5 additions & 1 deletion doomsday/client/include/world/plane.h
Expand Up @@ -52,10 +52,14 @@ class Plane : public de::MapElement
*/
DENG2_DEFINE_AUDIENCE(HeightChange, void planeHeightChanged(Plane &plane, coord_t oldHeight))

#ifdef __CLIENT__

/*
* Notified whenever a @em smoothed height change occurs.
*/
DENG2_DEFINE_AUDIENCE(SmoothedHeightChange, void planeSmoothedHeightChanged(Plane &plane, coord_t oldHeight))
DENG2_DEFINE_AUDIENCE(HeightSmoothedChange, void planeHeightSmoothedChanged(Plane &plane, coord_t oldHeight))

#endif

// Constants:
static int const MAX_SMOOTH_MOVE = 64; ///< $smoothplane: Maximum speed for a smoothed plane.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/include/world/surface.h
Expand Up @@ -408,8 +408,8 @@ class Surface : public de::MapElement
#ifdef __CLIENT__

/**
* Returns the current smoothed (interpolated) material origin for the plane
* in the map coordinate space.
* Returns the current smoothed (interpolated) material origin for the
* surface in the map coordinate space.
*
* @see setMaterialOrigin()
*/
Expand Down
115 changes: 43 additions & 72 deletions doomsday/client/src/world/plane.cpp
Expand Up @@ -32,44 +32,34 @@ using namespace de;

DENG2_PIMPL(Plane)
{
/// Sound emitter.
SoundEmitter soundEmitter;

/// Index of the plane in the owning sector.
int indexInSector;

/// Current @em sharp height relative to @c 0 on the map up axis (positive is up).
coord_t height;

/// @em sharp height change tracking buffer (for smoothing).
coord_t oldHeight[2];

/// Target @em sharp height.
coord_t targetHeight;

/// Visual plane height (smoothed).
coord_t heightSmoothed;

/// Delta between the current @em sharp height and the visual height.
coord_t heightSmoothedDelta;

/// Movement speed (map space units per tic).
coord_t speed;

/// Plane surface.
int indexInSector; ///< Index in the owning sector.
coord_t height; ///< Current @em sharp height.
coord_t targetHeight; ///< Target @em sharp height.
coord_t speed; ///< Movement speed (map space units per tic).
Surface surface;

#ifdef __CLIENT__
coord_t oldHeight[2]; ///< @em sharp height change tracking buffer (for smoothing).
coord_t heightSmoothed; ///< @ref height (smoothed).
coord_t heightSmoothedDelta; ///< Delta between the current @em sharp height and the visual height.
#endif

Instance(Public *i, coord_t height)
: Base(i),
indexInSector(-1),
height(height),
targetHeight(height),
heightSmoothed(height),
heightSmoothedDelta(0),
speed(0),
surface(dynamic_cast<MapElement &>(*i))
#ifdef __CLIENT__
,heightSmoothed(height),
heightSmoothedDelta(0)
#endif
{
#ifdef __CLIENT__
oldHeight[0] = oldHeight[1] = height;
#endif
zap(soundEmitter);
}

Expand All @@ -91,6 +81,16 @@ DENG2_PIMPL(Plane)
}
}

#ifdef __CLIENT__
void notifySmoothedHeightChanged(coord_t oldHeight)
{
DENG2_FOR_PUBLIC_AUDIENCE(HeightSmoothedChange, i)
{
i->planeHeightSmoothedChanged(self, oldHeight);
}
}
#endif

void applySharpHeightChange(coord_t newHeight)
{
// No change?
Expand Down Expand Up @@ -122,46 +122,9 @@ DENG2_PIMPL(Plane)
{
// Add ourself to tracked plane list (for movement interpolation).
self.map().trackedPlanes().insert(&self);

markDependantSurfacesForDecorationUpdate();
}
#endif
}

#ifdef __CLIENT__
/**
* To be called when the height changes to update the plotted decoration
* origins for surfaces whose material offset is dependant upon this.
*
* @todo Sector should observe instead.
*/
void markDependantSurfacesForDecorationUpdate()
{
if(ddMapSetup) return;

// "Middle" planes have no dependent surfaces.
if(indexInSector > Sector::Ceiling) return;

// Mark the decor lights on the sides of this plane as requiring an update.
foreach(LineSide *side, self.sector().sides())
{
if(side->hasSections())
{
side->middle().markAsNeedingDecorationUpdate();
side->bottom().markAsNeedingDecorationUpdate();
side->top().markAsNeedingDecorationUpdate();
}

if(side->back().hasSections())
{
LineSide &back = side->back();
back.middle().markAsNeedingDecorationUpdate();
back.bottom().markAsNeedingDecorationUpdate();
back.top().markAsNeedingDecorationUpdate();
}
}
}
#endif // __CLIENT__
};

Plane::Plane(Sector &sector, Vector3f const &normal, coord_t height)
Expand Down Expand Up @@ -263,22 +226,30 @@ coord_t Plane::heightSmoothedDelta() const

void Plane::lerpSmoothedHeight()
{
// $smoothplane
d->heightSmoothedDelta = d->oldHeight[0] * (1 - frameTimePos) + d->height * frameTimePos - d->height;
coord_t newSmoothedHeight = d->height + d->heightSmoothedDelta;
if(!de::fequal(d->heightSmoothed, newSmoothedHeight))
{
coord_t oldHeightSmoothed = d->heightSmoothed;

// Visible plane height.
d->heightSmoothed = d->height + d->heightSmoothedDelta;
d->heightSmoothed = newSmoothedHeight;
d->heightSmoothedDelta = d->oldHeight[0] * (1 - frameTimePos) + d->height * frameTimePos - d->height;

d->markDependantSurfacesForDecorationUpdate();
d->notifySmoothedHeightChanged(oldHeightSmoothed);
}
}

void Plane::resetSmoothedHeight()
{
// $smoothplane
d->heightSmoothedDelta = 0;
d->heightSmoothed = d->oldHeight[0] = d->oldHeight[1] = d->height;
coord_t newSmoothedHeight = d->oldHeight[0] = d->oldHeight[1] = d->height;
if(!de::fequal(d->heightSmoothed, newSmoothedHeight))
{
coord_t oldHeightSmoothed = d->heightSmoothed;

d->markDependantSurfacesForDecorationUpdate();
d->heightSmoothed = newSmoothedHeight;
d->heightSmoothedDelta = 0;

d->notifySmoothedHeightChanged(oldHeightSmoothed);
}
}

void Plane::updateHeightTracking()
Expand Down
61 changes: 52 additions & 9 deletions doomsday/client/src/world/sector.cpp
Expand Up @@ -272,6 +272,9 @@ typedef QSet<BspLeaf *> ReverbBspLeafs;

DENG2_PIMPL(Sector),
DENG2_OBSERVES(Plane, HeightChange)
#ifdef __CLIENT__
, DENG2_OBSERVES(Plane, HeightSmoothedChange)
#endif
{
/// Bounding box for the whole sector (all clusters).
AABoxd aaBox;
Expand Down Expand Up @@ -505,17 +508,41 @@ DENG2_OBSERVES(Plane, HeightChange)
if(reverb[SRD_VOLUME] > 1)
reverb[SRD_VOLUME] = 1;
}
#endif

/**
* To be called when the height changes to update the plotted decoration
* origins for surfaces whose material offset is dependant upon this.
*/
void markDependantSurfacesForDecorationUpdate()
{
if(ddMapSetup) return;

foreach(LineSide *side, self.sides())
{
if(side->hasSections())
{
side->middle().markAsNeedingDecorationUpdate();
side->bottom().markAsNeedingDecorationUpdate();
side->top().markAsNeedingDecorationUpdate();
}

if(side->back().hasSections())
{
LineSide &back = side->back();
back.middle().markAsNeedingDecorationUpdate();
back.bottom().markAsNeedingDecorationUpdate();
back.top().markAsNeedingDecorationUpdate();
}
}
}

#endif // __CLIENT__

// Observes Plane HeightChange.
void planeHeightChanged(Plane &plane, coord_t oldHeight)
{
DENG2_UNUSED(oldHeight);

// We are presently only interested in floor and/or ceiling height changes.
if(!(&plane == &self.floor() || &plane == &self.ceiling()))
return;

// Update the z-height origin of our sound emitter right away.
emitter.origin[VZ] = (self.floor().height() + self.ceiling().height()) / 2;

Expand Down Expand Up @@ -562,8 +589,18 @@ DENG2_OBSERVES(Plane, HeightChange)
}
}

markDependantSurfacesForDecorationUpdate();
#endif // __CLIENT__
}

#ifdef __CLIENT__
/// Observes Plane HeightSmoothedChange
void planeHeightSmoothedChanged(Plane &plane, coord_t oldHeight)
{
DENG2_UNUSED(oldHeight);
markDependantSurfacesForDecorationUpdate();
}
#endif
};

Sector::Sector(float lightLevel, Vector3f const &lightColor)
Expand Down Expand Up @@ -713,13 +750,19 @@ Plane *Sector::addPlane(Vector3f const &normal, coord_t height)
{
Plane *plane = new Plane(*this, normal, height);

// We want notification of height changes so that we can relay and/or update
// other components (e.g., BSP leafs) accordingly.
plane->audienceForHeightChange += d;
plane->setIndexInSector(d->planes.count());

d->planes.append(plane);

if(plane->isSectorFloor() || plane->isSectorCeiling())
{
// We want notification of height changes so that we can relay and/or
// update other components (e.g., BSP leafs) accordingly.
plane->audienceForHeightChange += d;
#ifdef __CLIENT__
plane->audienceForHeightSmoothedChange += d;
#endif
}

// Once both floor and ceiling are known we can determine the z-height origin
// of our sound emitter.
/// @todo fixme: Assume planes are defined in order.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/surface.cpp
Expand Up @@ -50,7 +50,7 @@ DENG2_PIMPL(Surface)
Vector2f materialOrigin; ///< @em sharp surface space material origin.

#ifdef __CLIENT__
Vector2f oldMaterialOrigin[2]; ///< Old @em sharp surface space material origins, for smoothing.
Vector2f oldMaterialOrigin[2]; ///< Old @em sharp surface space material origins, for smoothing.
Vector2f materialOriginSmoothed; ///< @em smoothed surface space material origin.
Vector2f materialOriginSmoothedDelta; ///< Delta between @em sharp and @em smoothed.

Expand Down

0 comments on commit e41bdaf

Please sign in to comment.