Skip to content

Commit

Permalink
Refactor|World: Relocated R_OpenRange(); world/maputil now client-only
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 29, 2013
1 parent 631a788 commit eb4ca59
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 95 deletions.
37 changes: 2 additions & 35 deletions doomsday/client/include/world/maputil.h
Expand Up @@ -20,22 +20,20 @@
#ifndef DENG_WORLD_MAPUTIL_H
#define DENG_WORLD_MAPUTIL_H

#ifdef __CLIENT__

#include <de/binangle.h>

#include <de/Vector>

#include "Line" // LineSide

class Sector;
#ifdef __CLIENT__
class LineOwner;
#endif

void R_SetRelativeHeights(Sector const *front, Sector const *back, int planeIndex,
coord_t *fz = 0, coord_t *bz = 0, coord_t *bhz = 0);

#ifdef __CLIENT__

/**
* Determine the map space Z coordinates of a wall section.
*
Expand All @@ -51,37 +49,6 @@ void R_SetRelativeHeights(Sector const *front, Sector const *back, int planeInde
void R_SideSectionCoords(LineSide const &side, int section, bool skyClip = true,
coord_t *bottom = 0, coord_t *top = 0, de::Vector2f *materialOrigin = 0);

#endif // __CLIENT__

/**
* Find the "sharp" Z coordinate range of the opening between sectors @a frontSec
* and @a backSec. The open range is defined as the gap between foor and ceiling on
* the front side clipped by the floor and ceiling planes on the back side (if present).
*
* @param side Line side to find the open range for.
* @param frontSec Sector on the front side.
* @param backSec Sector on the back side. Can be @c 0.
*
* Return values:
* @param bottom Bottom Z height is written here. Can be @c 0.
* @param top Top Z height is written here. Can be @c 0.
*
* @return Height of the open range.
*/
coord_t R_OpenRange(LineSide const &side, Sector const *frontSec, Sector const *backSec,
coord_t *bottom = 0, coord_t *top = 0);

/**
* Same as @ref R_OpenRange() except that the sector arguments are taken from the
* specified line @a side.
*/
inline coord_t R_OpenRange(LineSide const &side, coord_t *bottom = 0, coord_t *top = 0)
{
return R_OpenRange(side, side.sectorPtr(), side.back().sectorPtr(), bottom, top);
}

#ifdef __CLIENT__

/**
* @param side LineSide instance.
* @param ignoreOpacity @c true= do not consider Material opacity.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/render/skyfixedge.cpp
Expand Up @@ -123,15 +123,15 @@ DENG2_PIMPL(SkyFixEdge)
if(!hedge->mapElement()) return false;

LineSide const &lineSide = hedge->mapElement()->as<LineSideSegment>().lineSide();
BspLeaf const *frontLeaf = &hedge->face().mapElement()->as<BspLeaf>();
BspLeaf const *leaf = &hedge->face().mapElement()->as<BspLeaf>();
BspLeaf const *backLeaf = hedge->twin().hasFace()? &hedge->twin().face().mapElement()->as<BspLeaf>() : 0;

if(!(!backLeaf || backLeaf->sectorPtr() != frontLeaf->sectorPtr()))
if(!(!backLeaf || backLeaf->sectorPtr() != leaf->sectorPtr()))
return false;

// Select the relative planes for the fix type.
int relPlane = lower? Sector::Floor : Sector::Ceiling;
Plane const *front = &frontLeaf->visPlane(relPlane);
Plane const *front = &leaf->visPlane(relPlane);
Plane const *back = backLeaf? &backLeaf->visPlane(relPlane) : 0;

if(!front->surface().hasSkyMaskedMaterial())
Expand Down
47 changes: 46 additions & 1 deletion doomsday/client/src/world/map.cpp
Expand Up @@ -1485,6 +1485,51 @@ TraceOpening const &Map::traceOpening() const
return d->traceOpening;
}

/**
* Find the "sharp" Z coordinate range of the opening between sectors @a frontSec
* and @a backSec. The open range is defined as the gap between foor and ceiling on
* the front side clipped by the floor and ceiling planes on the back side (if present).
*
* @param side Line side to find the open range for.
*
* Return values:
* @param bottom Bottom Z height is written here. Can be @c 0.
* @param top Top Z height is written here. Can be @c 0.
*
* @return Height of the open range.
*/
static coord_t openRange(LineSide const &side, coord_t *retBottom, coord_t *retTop)
{
Sector const *frontSec = side.sectorPtr();
Sector const *backSec = side.back().sectorPtr();
DENG_ASSERT(frontSec != 0);

coord_t top;
if(backSec && backSec->ceiling().height() < frontSec->ceiling().height())
{
top = backSec->ceiling().height();
}
else
{
top = frontSec->ceiling().height();
}

coord_t bottom;
if(backSec && backSec->floor().height() > frontSec->floor().height())
{
bottom = backSec->floor().height();
}
else
{
bottom = frontSec->floor().height();
}

if(retBottom) *retBottom = bottom;
if(retTop) *retTop = top;

return top - bottom;
}

void Map::setTraceOpening(Line &line)
{
if(!line.hasBackSector())
Expand All @@ -1494,7 +1539,7 @@ void Map::setTraceOpening(Line &line)
}

coord_t bottom, top;
d->traceOpening.range = float( R_OpenRange(line.front(), &bottom, &top) );
d->traceOpening.range = float( openRange(line.front(), &bottom, &top) );
d->traceOpening.bottom = float( bottom );
d->traceOpening.top = float( top );

Expand Down
61 changes: 5 additions & 56 deletions doomsday/client/src/world/maputil.cpp
Expand Up @@ -18,6 +18,8 @@
* 02110-1301 USA</small>
*/

#ifdef __CLIENT__

#include "Face"

#include "BspLeaf"
Expand All @@ -26,49 +28,15 @@
#include "world/lineowner.h"
#include "world/p_players.h"

#ifdef __CLIENT__
# include "MaterialSnapshot"
# include "MaterialVariantSpec"
#include "MaterialSnapshot"
#include "MaterialVariantSpec"

# include "render/rend_main.h"
#endif
#include "render/rend_main.h"

#include "world/maputil.h"

using namespace de;

coord_t R_OpenRange(LineSide const &side, Sector const *frontSec,
Sector const *backSec, coord_t *retBottom, coord_t *retTop)
{
DENG_UNUSED(side); // Don't remove (present for API symmetry) -ds
DENG_ASSERT(frontSec != 0);

coord_t top;
if(backSec && backSec->ceiling().height() < frontSec->ceiling().height())
{
top = backSec->ceiling().height();
}
else
{
top = frontSec->ceiling().height();
}

coord_t bottom;
if(backSec && backSec->floor().height() > frontSec->floor().height())
{
bottom = backSec->floor().height();
}
else
{
bottom = frontSec->floor().height();
}

if(retBottom) *retBottom = bottom;
if(retTop) *retTop = top;

return top - bottom;
}

/// @todo fixme: Should work at BspLeaf level and use the visual plane heights
/// of sector clusters.
void R_SetRelativeHeights(Sector const *front, Sector const *back, int planeIndex,
Expand All @@ -78,11 +46,7 @@ void R_SetRelativeHeights(Sector const *front, Sector const *back, int planeInde
{
if(front)
{
#ifdef __CLIENT__
*fz = front->plane(planeIndex).visHeight();
#else
*fz = front->plane(planeIndex).height();
#endif
if(planeIndex != Sector::Floor)
*fz = -(*fz);
}
Expand All @@ -95,11 +59,7 @@ void R_SetRelativeHeights(Sector const *front, Sector const *back, int planeInde
{
if(back)
{
#ifdef __CLIENT__
*bz = back->plane(planeIndex).visHeight();
#else
*bz = back->plane(planeIndex).height();
#endif
if(planeIndex != Sector::Floor)
*bz = -(*bz);
}
Expand All @@ -113,11 +73,7 @@ void R_SetRelativeHeights(Sector const *front, Sector const *back, int planeInde
if(back)
{
int otherPlaneIndex = planeIndex == Sector::Floor? Sector::Ceiling : Sector::Floor;
#ifdef __CLIENT__
*bhz = back->plane(otherPlaneIndex).visHeight();
#else
*bhz = back->plane(otherPlaneIndex).height();
#endif
if(planeIndex != Sector::Floor)
*bhz = -(*bhz);
}
Expand All @@ -128,8 +84,6 @@ void R_SetRelativeHeights(Sector const *front, Sector const *back, int planeInde
}
}

#ifdef __CLIENT__

/// @todo fixme: Should use the visual plane heights of sector clusters.
void R_SideSectionCoords(LineSide const &side, int section, bool skyClip,
coord_t *retBottom, coord_t *retTop, Vector2f *retMaterialOrigin)
Expand Down Expand Up @@ -272,13 +226,8 @@ void R_SideSectionCoords(LineSide const &side, int section, bool skyClip,
// Perform clipping.
if(surface->hasMaterial() && !stretchMiddle)
{
#ifdef __CLIENT__
bool const clipBottom = !(!(devRendSkyMode || P_IsInVoid(viewPlayer)) && ffloor->surface().hasSkyMaskedMaterial() && bfloor->surface().hasSkyMaskedMaterial());
bool const clipTop = !(!(devRendSkyMode || P_IsInVoid(viewPlayer)) && fceil->surface().hasSkyMaskedMaterial() && bceil->surface().hasSkyMaskedMaterial());
#else
bool const clipBottom = !(ffloor->surface().hasSkyMaskedMaterial() && bfloor->surface().hasSkyMaskedMaterial());
bool const clipTop = !(fceil->surface().hasSkyMaskedMaterial() && bceil->surface().hasSkyMaskedMaterial());
#endif

coord_t openBottom, openTop;
if(!side.line().isSelfReferencing())
Expand Down

0 comments on commit eb4ca59

Please sign in to comment.