Skip to content

Commit

Permalink
Refactor|Plane: Made private more Plane instance data
Browse files Browse the repository at this point in the history
Height tracking buffer/target height and visual height.
  • Loading branch information
danij-deng committed Apr 12, 2013
1 parent cd097ea commit 567ded6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
5 changes: 0 additions & 5 deletions doomsday/client/include/map/plane.h
Expand Up @@ -68,11 +68,6 @@ class Plane : public de::MapElement
Middle
};

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

public:
/**
* Construct a new plane.
Expand Down
45 changes: 27 additions & 18 deletions doomsday/client/src/map/plane.cpp
Expand Up @@ -45,6 +45,15 @@ DENG2_PIMPL(Plane)
/// 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 visHeight;

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

Expand All @@ -62,11 +71,15 @@ DENG2_PIMPL(Plane)
sector(&sector),
inSectorIndex(0),
height(height),
targetHeight(height),
visHeight(height),
visHeightDelta(0),
speed(0),
surface(dynamic_cast<MapElement &>(*i)),
type(Floor)
{}
{
oldHeight[0] = oldHeight[1] = height;
}

~Instance()
{
Expand Down Expand Up @@ -172,12 +185,8 @@ DENG2_PIMPL(Plane)
};

Plane::Plane(Sector &sector, Vector3f const &normal, coord_t height)
: MapElement(DMU_PLANE),
_targetHeight(height),
_visHeight(height),
d(new Instance(this, sector, height))
: MapElement(DMU_PLANE), d(new Instance(this, sector, height))
{
_oldHeight[0] = _oldHeight[1] = d->height;
setNormal(normal);
}

Expand Down Expand Up @@ -223,7 +232,7 @@ coord_t Plane::height() const

coord_t Plane::targetHeight() const
{
return _targetHeight;
return d->targetHeight;
}

coord_t Plane::speed() const
Expand All @@ -234,7 +243,7 @@ coord_t Plane::speed() const
coord_t Plane::visHeight() const
{
// $smoothplane
return _visHeight;
return d->visHeight;
}

coord_t Plane::visHeightDelta() const
Expand All @@ -246,10 +255,10 @@ coord_t Plane::visHeightDelta() const
void Plane::lerpVisHeight()
{
// $smoothplane
d->visHeightDelta = _oldHeight[0] * (1 - frameTimePos) + d->height * frameTimePos - d->height;
d->visHeightDelta = d->oldHeight[0] * (1 - frameTimePos) + d->height * frameTimePos - d->height;

// Visible plane height.
_visHeight = d->height + d->visHeightDelta;
d->visHeight = d->height + d->visHeightDelta;

#ifdef __CLIENT__
d->markDependantSurfacesForDecorationUpdate();
Expand All @@ -260,7 +269,7 @@ void Plane::resetVisHeight()
{
// $smoothplane
d->visHeightDelta = 0;
_visHeight = _oldHeight[0] = _oldHeight[1] = d->height;
d->visHeight = d->oldHeight[0] = d->oldHeight[1] = d->height;

#ifdef __CLIENT__
d->markDependantSurfacesForDecorationUpdate();
Expand All @@ -270,15 +279,15 @@ void Plane::resetVisHeight()
void Plane::updateHeightTracking()
{
// $smoothplane
_oldHeight[0] = _oldHeight[1];
_oldHeight[1] = d->height;
d->oldHeight[0] = d->oldHeight[1];
d->oldHeight[1] = d->height;

if(_oldHeight[0] != _oldHeight[1])
if(d->oldHeight[0] != d->oldHeight[1])
{
if(de::abs(_oldHeight[0] - _oldHeight[1]) >= MAX_SMOOTH_MOVE)
if(de::abs(d->oldHeight[0] - d->oldHeight[1]) >= MAX_SMOOTH_MOVE)
{
// Too fast: make an instantaneous jump.
_oldHeight[0] = _oldHeight[1];
d->oldHeight[0] = d->oldHeight[1];
}
}
}
Expand Down Expand Up @@ -306,7 +315,7 @@ int Plane::property(setargs_t &args) const
DMU_GetValue(DMT_PLANE_HEIGHT, &d->height, &args, 0);
break;
case DMU_TARGET_HEIGHT:
DMU_GetValue(DMT_PLANE_TARGET, &_targetHeight, &args, 0);
DMU_GetValue(DMT_PLANE_TARGET, &d->targetHeight, &args, 0);
break;
case DMU_SPEED:
DMU_GetValue(DMT_PLANE_SPEED, &d->speed, &args, 0);
Expand All @@ -329,7 +338,7 @@ int Plane::setProperty(setargs_t const &args)
d->applySharpHeightChange(newHeight);
break; }
case DMU_TARGET_HEIGHT:
DMU_SetValue(DMT_PLANE_TARGET, &_targetHeight, &args, 0);
DMU_SetValue(DMT_PLANE_TARGET, &d->targetHeight, &args, 0);
break;
case DMU_SPEED:
DMU_SetValue(DMT_PLANE_SPEED, &d->speed, &args, 0);
Expand Down

0 comments on commit 567ded6

Please sign in to comment.