Skip to content

Commit

Permalink
Cleanup|Refactor|World|Client: Added a (stub) ClSkyPlane class
Browse files Browse the repository at this point in the history
Cleaning up the world::Map API a little more.
  • Loading branch information
danij-deng committed Aug 10, 2016
1 parent 30d519e commit cd87d77
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 156 deletions.
70 changes: 70 additions & 0 deletions doomsday/apps/client/include/client/clskyplane.h
@@ -0,0 +1,70 @@
/** @file clskyplane.h Client-side world map sky plane.
* @ingroup world
*
* @authors Copyright © 2016 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef DENG_CLIENT_WORLD_CLSKYPLANE_H
#define DENG_CLIENT_WORLD_CLSKYPLANE_H

#include <de/Observers>

namespace world {

/**
*
*/
class ClSkyPlane
{
public:
/// Notified whenever a @em height change occurs.
DENG2_DEFINE_AUDIENCE2(HeightChange, void clSkyPlaneHeightChanged(ClSkyPlane &skyPlane))

ClSkyPlane(bool isCeiling = false, de::ddouble defaultHeight = 0);

/**
* Returns @c true if this sky plane is configured as the "ceiling".
*
* @see isFloor()
*/
bool isCeiling() const;

/**
* Returns @c true if this sky plane is configured as the "ceiling".
*
* @see isCeiling()
*/
bool isFloor() const;

/**
* Returns the current height of the sky plane.
*/
de::ddouble height() const;

/**
* Change the height of the sky plane to @a newHeight. The HeightChange audience will
* be notified if a change occurs.
*/
void setHeight(de::ddouble newHeight);

private:
DENG2_PRIVATE(d)
};

} // namespace world

#endif // DENG_CLIENT_WORLD_CLSKYPLANE_H
21 changes: 11 additions & 10 deletions doomsday/apps/client/include/world/map.h
Expand Up @@ -71,6 +71,9 @@ class LineBlockmap;
class Subsector;
class Sky;
class Thinkers;
#ifdef __CLIENT__
class ClSkyPlane;
#endif

/**
* World map.
Expand Down Expand Up @@ -554,19 +557,17 @@ class Map : public world::BaseMap

SkyDrawable::Animator &skyAnimator() const;

de::ddouble skyFix(bool ceiling) const;
ClSkyPlane &skyFloor();
ClSkyPlane const &skyFloor() const;

inline de::ddouble skyFixFloor () const { return skyFix(false /*the floor*/); }
inline de::ddouble skyFixCeiling() const { return skyFix(true /*the ceiling*/); }
ClSkyPlane &skyCeiling();
ClSkyPlane const &skyCeiling() const;

void setSkyFix(bool ceiling, de::ddouble newHeight);

inline void setSkyFixFloor(de::ddouble newHeight) {
setSkyFix(false /*the floor*/, newHeight);
inline ClSkyPlane &skyPlane(bool ceiling) {
return ceiling ? skyCeiling() : skyFloor();
}

inline void setSkyFixCeiling(de::ddouble newHeight) {
setSkyFix(true /*the ceiling*/, newHeight);
inline ClSkyPlane const &skyPlane(bool ceiling) const {
return ceiling ? skyCeiling() : skyFloor();
}

#endif
Expand Down
1 change: 0 additions & 1 deletion doomsday/apps/client/include/world/sky.h
Expand Up @@ -23,7 +23,6 @@
#define DENG_WORLD_SKY_H

#include <functional>
#include <QList>
#include <de/libcore.h>
#include <de/Error>
#include <de/Observers>
Expand Down
9 changes: 5 additions & 4 deletions doomsday/apps/client/src/client/clientsubsector.cpp
Expand Up @@ -26,6 +26,7 @@
#include "world/p_object.h"
#include "world/p_players.h"
#include "world/surface.h"
#include "client/clskyplane.h"

#include "render/rend_main.h" // Rend_SkyLightColor(), useBias
#include "BiasIllum"
Expand Down Expand Up @@ -1522,8 +1523,8 @@ bool ClientSubsector::isHeightInVoid(ddouble height) const
// Check the mapped planes.
if (visCeiling().surface().hasSkyMaskedMaterial())
{
ddouble const skyCeil = sector().map().skyFixCeiling();
if (skyCeil < DDMAXFLOAT && height > skyCeil)
ClSkyPlane const &skyCeil = sector().map().skyCeiling();
if (skyCeil.height() < DDMAXFLOAT && height > skyCeil.height())
return true;
}
else if (height > visCeiling().heightSmoothed())
Expand All @@ -1533,8 +1534,8 @@ bool ClientSubsector::isHeightInVoid(ddouble height) const

if (visFloor().surface().hasSkyMaskedMaterial())
{
ddouble const skyFloor = sector().map().skyFixFloor();
if (skyFloor > DDMINFLOAT && height < skyFloor)
ClSkyPlane const &skyFloor = sector().map().skyFloor();
if (skyFloor.height() > DDMINFLOAT && height < skyFloor.height())
return true;
}
else if (height < visFloor().heightSmoothed())
Expand Down
68 changes: 68 additions & 0 deletions doomsday/apps/client/src/client/clskyplane.cpp
@@ -0,0 +1,68 @@
/** @file clskyplane.cpp Client-side world map sky plane.
*
* @authors Copyright © 2016 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#include "client/clskyplane.h"

using namespace de;

namespace world {

DENG2_PIMPL_NOREF(ClSkyPlane)
{
bool isCeiling = false; ///< @c true if this is the ceiling; otherwise the floor.
ddouble height = 0;

Impl(bool ceiling, ddouble defaultHeight)
: isCeiling(ceiling), height(defaultHeight)
{}

DENG2_PIMPL_AUDIENCE(HeightChange)
};

DENG2_AUDIENCE_METHOD(ClSkyPlane, HeightChange)

ClSkyPlane::ClSkyPlane(bool isCeiling, ddouble defaultHeight)
: d(new Impl(isCeiling, defaultHeight))
{}

bool ClSkyPlane::isCeiling() const
{
return d->isCeiling;
}

bool ClSkyPlane::isFloor() const
{
return !d->isCeiling;
}

ddouble ClSkyPlane::height() const
{
return d->height;
}

void ClSkyPlane::setHeight(ddouble newHeight)
{
if (d->height != newHeight)
{
d->height = newHeight;
DENG2_FOR_AUDIENCE2(HeightChange, i) i->clSkyPlaneHeightChanged(*this);
}
}

} // namespace world
21 changes: 11 additions & 10 deletions doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -39,6 +39,7 @@
#include "ConvexSubspace"
#include "Hand"
#include "client/clientsubsector.h"
#include "client/clskyplane.h"
#include "BiasIllum"
#include "HueCircleVisual"
#include "LightDecoration"
Expand Down Expand Up @@ -3066,13 +3067,13 @@ static void writeSubspaceSkyMaskStrips(SkyFixEdge::FixType fixType)

static ddouble skyPlaneZ(dint skyCap)
{
auto const &subsec = curSubspace->subsector().as<world::ClientSubsector>();
dint const relPlane = (skyCap & SKYCAP_UPPER) ? Sector::Ceiling : Sector::Floor;
auto const &subsec = curSubspace->subsector().as<world::ClientSubsector>();
dint const planeIndex = (skyCap & SKYCAP_UPPER) ? Sector::Ceiling : Sector::Floor;
if (!P_IsInVoid(viewPlayer))
{
return subsec.sector().map().skyFix(relPlane == Sector::Ceiling);
return subsec.sector().map().skyPlane(planeIndex == Sector::Ceiling).height();
}
return subsec.visPlane(relPlane).heightSmoothed();
return subsec.visPlane(planeIndex).heightSmoothed();
}

static DrawList::Indices makeFlatSkyMaskGeometry(Store &verts, gl::Primitive &primitive,
Expand Down Expand Up @@ -3563,11 +3564,12 @@ static void projectSubspaceSprites()
&& mob.origin[2] <= subsec.visCeiling().heightSmoothed()
&& mob.origin[2] >= subsec.visFloor ().heightSmoothed())
{
coord_t visibleTop = mob.origin[2] + material->height();
if(visibleTop > subsec.sector().map().skyFixCeiling())
world::ClSkyPlane &skyCeiling = subsec.sector().map().skyCeiling();
ddouble visibleTop = mob.origin[2] + material->height();
if(visibleTop > skyCeiling.height())
{
// Raise the skyfix ceiling.
subsec.sector().map().setSkyFixCeiling(visibleTop + 16/*leeway*/);
// Raise the ceiling!
skyCeiling.setHeight(visibleTop + 16/*leeway*/);
}
}
}
Expand Down Expand Up @@ -5464,11 +5466,10 @@ static void drawSurfaceTangentVectors(Subsector &subsec)
{
Plane const &plane = subsec.as<world::ClientSubsector>().visPlane(i);
ddouble height = 0;

if (plane.surface().hasSkyMaskedMaterial()
&& (plane.isSectorFloor() || plane.isSectorCeiling()))
{
height = plane.map().skyFix(plane.isSectorCeiling());
height = plane.map().skyPlane(plane.isSectorCeiling()).height();
}
else
{
Expand Down
24 changes: 12 additions & 12 deletions doomsday/apps/client/src/render/skyfixedge.cpp
Expand Up @@ -32,48 +32,48 @@
#include "render/rend_main.h"

#include "client/clientsubsector.h"
#include "client/clskyplane.h"

using namespace world;

namespace de {

static coord_t skyFixFloorZ(Plane const *frontFloor, Plane const *backFloor)
static ddouble skyFixFloorZ(Plane const *frontFloor, Plane const *backFloor)
{
DENG_UNUSED(backFloor);
if(devRendSkyMode || P_IsInVoid(viewPlayer))
return frontFloor->heightSmoothed();
return frontFloor->map().skyFixFloor();
return frontFloor->map().skyFloor().height();
}

static coord_t skyFixCeilZ(Plane const *frontCeil, Plane const *backCeil)
static ddouble skyFixCeilZ(Plane const *frontCeil, Plane const *backCeil)
{
DENG_UNUSED(backCeil);
if(devRendSkyMode || P_IsInVoid(viewPlayer))
return frontCeil->heightSmoothed();
return frontCeil->map().skyFixCeiling();
return frontCeil->map().skyCeiling().height();
}

DENG2_PIMPL_NOREF(SkyFixEdge::Event)
{
SkyFixEdge &owner;
double distance;

Impl(SkyFixEdge &owner, double distance)
ddouble distance;
Impl(SkyFixEdge &owner, ddouble distance)
: owner(owner), distance(distance)
{}
};

SkyFixEdge::Event::Event(SkyFixEdge &owner, double distance)
: WorldEdge::Event(),
d(new Impl(owner, distance))
SkyFixEdge::Event::Event(SkyFixEdge &owner, ddouble distance)
: WorldEdge::Event()
, d(new Impl(owner, distance))
{}

bool SkyFixEdge::Event::operator < (Event const &other) const
{
return d->distance < other.distance();
}

double SkyFixEdge::Event::distance() const
ddouble SkyFixEdge::Event::distance() const
{
return d->distance;
}
Expand All @@ -87,7 +87,7 @@ DENG2_PIMPL(SkyFixEdge)
{
HEdge *hedge;
FixType fixType;
int edge;
dint edge;

Vector3d pOrigin;
Vector3d pDirection;
Expand Down

0 comments on commit cd87d77

Please sign in to comment.