Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Sector: Observe Plane HeightChange notification
  • Loading branch information
danij-deng committed Apr 12, 2013
1 parent caad4ae commit bfa8a2c
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 294 deletions.
8 changes: 4 additions & 4 deletions doomsday/client/include/map/plane.h
Expand Up @@ -56,7 +56,7 @@ class Plane : public de::MapElement
/**
* Observers to be notified whenever a @em sharp height change occurs.
*/
DENG2_DEFINE_AUDIENCE(HeightChange, void planeHeightChanged(Plane const &plane, coord_t oldHeight))
DENG2_DEFINE_AUDIENCE(HeightChange, void planeHeightChanged(Plane &plane, coord_t oldHeight))

static int const MAX_SMOOTH_MOVE; ///< 64, $smoothplane: Maximum speed for a smoothed plane.

Expand All @@ -69,9 +69,9 @@ class Plane : public de::MapElement
};

public: /// @todo Make private:
coord_t _oldHeight[2];
coord_t _targetHeight; ///< Target height.
coord_t _visHeight; ///< Visual plane height (smoothed).
coord_t _oldHeight[2];
coord_t _targetHeight; ///< Target height.
coord_t _visHeight; ///< Visual plane height (smoothed).

public:
/**
Expand Down
5 changes: 3 additions & 2 deletions doomsday/client/include/map/r_world.h
Expand Up @@ -67,6 +67,8 @@ boolean R_SectorContainsSkySurfaces(Sector const *sec);

void R_ClearSectorFlags();

void R_UpdateMissingMaterialsForLinesOfSector(Sector const &sec);

/**
* Returns pointers to the line's vertices in such a fashion that @c verts[0]
* is the leftmost vertex and @c verts[1] is the rightmost vertex, when the
Expand Down Expand Up @@ -172,8 +174,7 @@ boolean R_MiddleMaterialCoversOpening(int lineFlags, Sector const *frontSec,
boolean R_MiddleMaterialCoversLineOpening(LineDef const *line, int side, boolean ignoreOpacity);
#endif // __CLIENT__

bool R_UpdateSector(Sector &sector, bool forceUpdate = false);
bool R_UpdatePlane(Plane &plane, bool forceUpdate = false);
void R_UpdateSector(Sector &sector, bool forceUpdate = false);

/// @return Current glow strength for the plane.
float R_GlowStrength(Plane const *pln);
Expand Down
9 changes: 7 additions & 2 deletions doomsday/client/include/map/sector.h
Expand Up @@ -49,11 +49,12 @@ class LineDef;
///@}

/**
* Map sector.
* World map sector.
*
* @ingroup map
*/
class Sector : public de::MapElement
class Sector : public de::MapElement,
DENG2_OBSERVES(Plane, HeightChange)
{
public:
/// Required/referenced plane is missing. @ingroup errors
Expand Down Expand Up @@ -480,6 +481,10 @@ class Sector : public de::MapElement
*/
int setProperty(setargs_t const &args);

protected:
// Observes Plane HeightChange.
void planeHeightChanged(Plane &plane, coord_t oldHeight);

private:
DENG2_PRIVATE(d)
};
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -1251,6 +1251,8 @@ uint MPE_PlaneCreate(uint sectorIdx, coord_t height, ddstring_t const *materialU
sector->_planes.append(plane);
plane->setInSectorIndex(sector->planeCount() - 1);

plane->audienceForHeightChange += sector;

return plane->inSectorIndex() + 1; // 1-based index.
}

Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/map/p_dmu.cpp
Expand Up @@ -1036,8 +1036,7 @@ static int setProperty(void *ptr, void *context)

if(updatePlane)
{
if(R_UpdatePlane(*updatePlane))
updateSector1 = &updatePlane->sector();
updateSector1 = &updatePlane->sector();
}

if(updateSector1)
Expand Down
21 changes: 17 additions & 4 deletions doomsday/client/src/map/plane.cpp
@@ -1,4 +1,4 @@
/** @file plane.h Map Plane.
/** @file plane.h World Map Plane.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand All @@ -18,13 +18,13 @@
* 02110-1301 USA</small>
*/

#include <de/Log>

#include "de_base.h"
#include "de_console.h"
#include "de_play.h"

#include "audio/s_environ.h"
#include "map/linedef.h"
#include "map/gamemap.h"

#include "render/r_main.h" // frameTimePos

#include "map/plane.h"
Expand Down Expand Up @@ -108,6 +108,17 @@ DENG2_PIMPL(Plane)
coord_t oldHeight = height;
height = newHeight;

if(!ddMapSetup)
{
#ifdef __CLIENT__
// Update the sound emitter origin for the plane.
surface.updateSoundEmitterOrigin();
#endif

// We need the decorations updated.
surface.markAsNeedingDecorationUpdate();
}

// Notify interested parties of the change.
notifyHeightChanged(oldHeight);

Expand All @@ -129,6 +140,8 @@ DENG2_PIMPL(Plane)
/**
* 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()
{
Expand Down

0 comments on commit bfa8a2c

Please sign in to comment.