From e41bdaf15a87a664cf305e2d8f8138e4d4beaff4 Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 11 Sep 2013 17:10:15 +0100 Subject: [PATCH] World|Sector: Sector observes smoothed height changes of its floor/ceiling planes Also trimmed some unnecessary fat from Plane on server side. --- doomsday/client/include/world/plane.h | 6 +- doomsday/client/include/world/surface.h | 4 +- doomsday/client/src/world/plane.cpp | 115 +++++++++--------------- doomsday/client/src/world/sector.cpp | 61 +++++++++++-- doomsday/client/src/world/surface.cpp | 2 +- 5 files changed, 103 insertions(+), 85 deletions(-) diff --git a/doomsday/client/include/world/plane.h b/doomsday/client/include/world/plane.h index c88c99cbef..f41cf28d0d 100644 --- a/doomsday/client/include/world/plane.h +++ b/doomsday/client/include/world/plane.h @@ -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. diff --git a/doomsday/client/include/world/surface.h b/doomsday/client/include/world/surface.h index ed0a8b5447..6f0e959a3b 100644 --- a/doomsday/client/include/world/surface.h +++ b/doomsday/client/include/world/surface.h @@ -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() */ diff --git a/doomsday/client/src/world/plane.cpp b/doomsday/client/src/world/plane.cpp index 68010d7f1e..99899fe147 100644 --- a/doomsday/client/src/world/plane.cpp +++ b/doomsday/client/src/world/plane.cpp @@ -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(*i)) +#ifdef __CLIENT__ + ,heightSmoothed(height), + heightSmoothedDelta(0) +#endif { +#ifdef __CLIENT__ oldHeight[0] = oldHeight[1] = height; +#endif zap(soundEmitter); } @@ -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? @@ -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 §or, Vector3f const &normal, coord_t height) @@ -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() diff --git a/doomsday/client/src/world/sector.cpp b/doomsday/client/src/world/sector.cpp index de354caaba..4303cfb7cb 100644 --- a/doomsday/client/src/world/sector.cpp +++ b/doomsday/client/src/world/sector.cpp @@ -272,6 +272,9 @@ typedef QSet 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; @@ -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; @@ -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) @@ -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. diff --git a/doomsday/client/src/world/surface.cpp b/doomsday/client/src/world/surface.cpp index 80fe0b097f..be8178c24f 100644 --- a/doomsday/client/src/world/surface.cpp +++ b/doomsday/client/src/world/surface.cpp @@ -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.