Skip to content

Commit

Permalink
Polyobj: Added convenience accessors returning the linked Sector
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed May 22, 2013
1 parent 46f5fc1 commit d5dfb76
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 19 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/include/map/hedge.h
Expand Up @@ -208,7 +208,7 @@ class HEdge : public de::MapElement
*
* @see bspLeaf(), BspLeaf::sector()
*/
Sector &sector() const { return bspLeaf().sector(); }
inline Sector &sector() const { return bspLeaf().sector(); }

/**
* Convenience accessor which returns a pointer to the Sector of the BspLeaf
Expand All @@ -218,7 +218,7 @@ class HEdge : public de::MapElement
*
* @see hasBspLeaf(), BspLeaf::sectorPtr()
*/
Sector *sectorPtr() const { return hasBspLeaf()? bspLeaf().sectorPtr() : 0; }
inline Sector *sectorPtr() const { return hasBspLeaf()? bspLeaf().sectorPtr() : 0; }

/**
* Returns @c true iff a Line::Side is attributed to the half-edge.
Expand Down
35 changes: 34 additions & 1 deletion doomsday/client/include/map/polyobj.h
@@ -1,4 +1,4 @@
/** @file polyobj.h World Map Polyobj.
/** @file map/polyobj.h World Map Polyobj.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand Down Expand Up @@ -27,6 +27,8 @@

#include "dd_share.h"

#include "BspLeaf"

class Line;
class Vertex;

Expand Down Expand Up @@ -82,13 +84,44 @@ typedef struct polyobj_s
*/
void unlink();

/**
* Returns @c true iff a BspLeaf is linked to the polyobj.
*/
bool hasBspLeaf() const;

/**
* Returns the BSP leaf in which the polyobj is presently linked.
*
* @see isLinked();
*/
BspLeaf &bspLeaf() const;

/**
* Convenience accessor which determines whether a BspLeaf with an attributed
* sector is linked to the polyobj.
*
* @see hasBspLeaf(), BspLeaf::hasSector()
*/
inline bool hasSector() const { return hasBspLeaf() && bspLeaf().hasSector(); }

/**
* Convenience accessor which returns the Sector of the BspLeaf linked to the
* polyobj.
*
* @see bspLeaf(), BspLeaf::sector()
*/
inline Sector &sector() const { return bspLeaf().sector(); }

/**
* Convenience accessor which returns a pointer to the Sector of the BspLeaf
* linked to the polyobj.
*
* @return Sector attributed to the linked BspLeaf; otherwise @c 0.
*
* @see hasBspLeaf(), BspLeaf::sectorPtr()
*/
inline Sector *sectorPtr() const { return hasBspLeaf()? bspLeaf().sectorPtr() : 0; }

/**
* Returns the sound emitter for the polyobj.
*/
Expand Down
7 changes: 6 additions & 1 deletion doomsday/client/src/map/polyobj.cpp
@@ -1,4 +1,4 @@
/** @file polyobj.cpp World Map Polyobj.
/** @file map/polyobj.cpp World Map Polyobj.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
Expand Down Expand Up @@ -163,6 +163,11 @@ void Polyobj::link()
}
}

bool Polyobj::hasBspLeaf() const
{
return _bspLeaf != 0;
}

BspLeaf &Polyobj::bspLeaf() const
{
if(_bspLeaf)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/map/r_world.cpp
Expand Up @@ -114,7 +114,7 @@ void R_SetRelativeHeights(Sector const *front, Sector const *back, int planeInde
void R_SideSectionCoords(Line::Side const &side, int section,
coord_t *retBottom, coord_t *retTop, Vector2f *retMaterialOrigin)
{
Sector const *frontSec = side.line().definesPolyobj()? side.line().polyobj().bspLeaf().sectorPtr() : side.sectorPtr();
Sector const *frontSec = side.line().definesPolyobj()? side.line().polyobj().sectorPtr() : side.sectorPtr();
Sector const *backSec = (side.line().definesPolyobj() || (side.leftHEdge()->twin().hasBspLeaf() && !side.leftHEdge()->twin().bspLeaf().isDegenerate()))? side.back().sectorPtr() : 0;

Line const &line = side.line();
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -3074,7 +3074,7 @@ static void Rend_DrawBoundingBoxes()
{
foreach(Polyobj const *polyobj, theMap->polyobjs())
{
Sector const &sec = polyobj->bspLeaf().sector();
Sector const &sec = polyobj->sector();
coord_t width = (polyobj->aaBox.maxX - polyobj->aaBox.minX)/2;
coord_t length = (polyobj->aaBox.maxY - polyobj->aaBox.minY)/2;
coord_t height = (sec.ceiling().height() - sec.floor().height())/2;
Expand Down Expand Up @@ -3235,7 +3235,7 @@ static void Rend_DrawSurfaceVectors()

foreach(Polyobj *polyobj, theMap->polyobjs())
{
Sector const &sector = polyobj->bspLeaf().sector();
Sector const &sector = polyobj->sector();
float zPos = sector.floor().height() + (sector.ceiling().height() - sector.floor().height())/2;

foreach(Line *line, polyobj->lines())
Expand Down Expand Up @@ -3441,8 +3441,8 @@ static int drawVertex1(Line *li, void *context)

if(alpha > 0)
{
coord_t bottom = po->bspLeaf().sector().floor().visHeight();
coord_t top = po->bspLeaf().sector().ceiling().visHeight();
coord_t bottom = po->sector().floor().visHeight();
coord_t top = po->sector().ceiling().visHeight();

if(devVertexBars)
drawVertexBar(vtx, bottom, top, MIN_OF(alpha, .15f));
Expand All @@ -3461,7 +3461,7 @@ static int drawVertex1(Line *li, void *context)

pos[VX] = vtx->origin().x;
pos[VY] = vtx->origin().y;
pos[VZ] = po->bspLeaf().sector().floor().visHeight();
pos[VZ] = po->sector().floor().visHeight();

dist3D = V3d_Distance(pos, eye);

Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/render/shadowedge.cpp
Expand Up @@ -127,14 +127,14 @@ void ShadowEdge::prepare(int planeIndex)

if(d->leftMostHEdge->twin().hasBspLeaf() &&
!d->leftMostHEdge->twin().bspLeaf().isDegenerate() &&
d->leftMostHEdge->twin().bspLeaf().sectorPtr() != 0)
d->leftMostHEdge->twin().sectorPtr() != 0)
{
Surface const &wallEdgeSurface =
side.back().hasSector()? side.surface(planeIndex == Plane::Ceiling? Line::Side::Top : Line::Side::Bottom)
: side.middle();

Sector const *frontSec = d->leftMostHEdge->bspLeaf().sectorPtr();
Sector const *backSec = d->leftMostHEdge->twin().bspLeaf().sectorPtr();
Sector const *frontSec = d->leftMostHEdge->sectorPtr();
Sector const *backSec = d->leftMostHEdge->twin().sectorPtr();

coord_t fz = 0, bz = 0, bhz = 0;
R_SetRelativeHeights(frontSec, backSec, planeIndex, &fz, &bz, &bhz);
Expand Down Expand Up @@ -198,11 +198,11 @@ void ShadowEdge::prepare(int planeIndex)
{
// Its a normal neighbor.
Sector const *backSec = otherSide->back().sectorPtr();
if(backSec != d->leftMostHEdge->bspLeaf().sectorPtr() &&
if(backSec != d->leftMostHEdge->sectorPtr() &&
!((plane.type() == Plane::Floor && backSec->ceiling().visHeight() <= plane.visHeight()) ||
(plane.type() == Plane::Ceiling && backSec->floor().height() >= plane.visHeight())))
{
Sector const *frontSec = d->leftMostHEdge->bspLeaf().sectorPtr();
Sector const *frontSec = d->leftMostHEdge->sectorPtr();

coord_t fz = 0, bz = 0, bhz = 0;
R_SetRelativeHeights(frontSec, backSec, planeIndex, &fz, &bz, &bhz);
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/skyfixedge.cpp
Expand Up @@ -115,8 +115,8 @@ DENG2_PIMPL(SkyFixEdge)
// Partition line segments have no map line sides.
if(!hedge->hasLineSide()) return false;

Sector const *frontSec = hedge->bspLeaf().sectorPtr();
Sector const *backSec = hedge->twin().hasBspLeaf() && !hedge->twin().bspLeaf().isDegenerate()? hedge->twin().bspLeaf().sectorPtr() : 0;
Sector const *frontSec = hedge->sectorPtr();
Sector const *backSec = hedge->twin().hasBspLeaf() && !hedge->twin().bspLeaf().isDegenerate()? hedge->twin().sectorPtr() : 0;

if(!(!backSec || backSec != frontSec)) return false;

Expand Down Expand Up @@ -170,8 +170,8 @@ void SkyFixEdge::prepare()
return;
}

Sector const *frontSec = d->hedge->bspLeaf().sectorPtr();
Sector const *backSec = d->hedge->twin().hasBspLeaf() && !d->hedge->twin().bspLeaf().isDegenerate()? d->hedge->twin().bspLeaf().sectorPtr() : 0;
Sector const *frontSec = d->hedge->sectorPtr();
Sector const *backSec = d->hedge->twin().hasBspLeaf() && !d->hedge->twin().bspLeaf().isDegenerate()? d->hedge->twin().sectorPtr() : 0;
Plane const *ffloor = &frontSec->floor();
Plane const *fceil = &frontSec->ceiling();
Plane const *bceil = backSec? &backSec->ceiling() : 0;
Expand Down

0 comments on commit d5dfb76

Please sign in to comment.