Skip to content

Commit

Permalink
Mesh: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 3, 2013
1 parent 930d005 commit 5513217
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 59 deletions.
10 changes: 10 additions & 0 deletions doomsday/client/include/mesh.h
Expand Up @@ -87,6 +87,16 @@ class Mesh
/// @copydoc mapElement()
MapElement const &mapElement() const;

template <class MapElementType>
MapElementType &mapElementAs() {
return mapElement().as<MapElementType>();
}

template <class MapElementType>
MapElementType const &mapElementAs() const {
return mapElement().as<MapElementType>();
}

/**
* Change the map element to which the mesh element is attributed.
*
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/r_main.cpp
Expand Up @@ -1470,7 +1470,7 @@ void R_ViewerClipLumobjBySight(Lumobj *lum, BspLeaf *bspLeaf)
continue;

// Ignore half-edges facing the wrong way.
if(hedge->mapElement().as<LineSideSegment>().isFrontFacing())
if(hedge->mapElementAs<LineSideSegment>().isFrontFacing())
{
coord_t eyeV1[2] = { eye.x, eye.y };
coord_t lumOriginV1[2] = { lum->origin().x, lum->origin().y };
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/render/rend_fakeradio.cpp
Expand Up @@ -1091,12 +1091,12 @@ void Rend_RadioWallSection(WallEdge const &leftEdge, WallEdge const &rightEdge,

LineSide &side = leftEdge.mapLineSide();
HEdge const *hedge = side.leftHEdge();
SectorCluster const *cluster = &hedge->face().mapElement().as<BspLeaf>().cluster();
SectorCluster const *cluster = &hedge->face().mapElementAs<BspLeaf>().cluster();
SectorCluster const *backCluster = 0;

if(leftEdge.spec().section != LineSide::Middle && hedge->twin().hasFace())
{
backCluster = hedge->twin().face().mapElement().as<BspLeaf>().clusterPtr();
backCluster = hedge->twin().face().mapElementAs<BspLeaf>().clusterPtr();
}

bool const haveBottomShadower = Rend_RadioPlaneCastsShadow(cluster->visFloor());
Expand Down Expand Up @@ -1269,7 +1269,7 @@ static void writeShadowSection(int planeIndex, LineSide &side, float shadowDark)
/// @todo Encapsulate this logic in ShadowEdge -ds
if(!leftHEdge->hasFace()) return;

BspLeaf &frontLeaf = leftHEdge->face().mapElement().as<BspLeaf>();
BspLeaf &frontLeaf = leftHEdge->face().mapElementAs<BspLeaf>();
if(!frontLeaf.hasCluster() || !frontLeaf.cluster().hasWorldVolume())
return;

Expand Down
32 changes: 16 additions & 16 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -1485,7 +1485,7 @@ static void writeWallSection(HEdge &hedge, int section,
{
BspLeaf *leaf = currentBspLeaf;

LineSideSegment &segment = hedge.mapElement().as<LineSideSegment>();
LineSideSegment &segment = hedge.mapElementAs<LineSideSegment>();
DENG_ASSERT(segment.isFrontFacing() && segment.lineSide().hasSections());

if(retWroteOpaque) *retWroteOpaque = false;
Expand Down Expand Up @@ -1920,14 +1920,14 @@ static void writeLeafSkyMaskStrips(SkyFixEdge::FixType fixType)
Material *skyMaterial = 0;
if(splitOnMaterialChange)
{
skyMaterial = hedge->face().mapElement().as<BspLeaf>()
skyMaterial = hedge->face().mapElementAs<BspLeaf>()
.cluster().visPlane(relPlane).surface().materialPtr();
}

// Add a first (left) edge to the current strip?
if(startNode == 0 && hedge->hasMapElement())
{
startMaterialOffset = hedge->mapElement().as<LineSideSegment>().lineSideOffset();
startMaterialOffset = hedge->mapElementAs<LineSideSegment>().lineSideOffset();

// Prepare the edge geometry
SkyFixEdge skyEdge(*hedge, fixType, (direction == Anticlockwise)? Line::To : Line::From,
Expand Down Expand Up @@ -1956,7 +1956,7 @@ static void writeLeafSkyMaskStrips(SkyFixEdge::FixType fixType)
bool endStrip = false;
if(hedge->hasMapElement())
{
startMaterialOffset += hedge->mapElement().as<LineSideSegment>().length()
startMaterialOffset += hedge->mapElementAs<LineSideSegment>().length()
* (direction == Anticlockwise? -1 : 1);

// Prepare the edge geometry
Expand Down Expand Up @@ -2102,7 +2102,7 @@ static void writeLeafSkyMask(int skyCap = SKYCAP_LOWER|SKYCAP_UPPER)
static bool coveredOpenRange(HEdge &hedge, coord_t middleBottomZ, coord_t middleTopZ,
bool wroteOpaqueMiddle)
{
LineSide const &front = hedge.mapElement().as<LineSideSegment>().lineSide();
LineSide const &front = hedge.mapElementAs<LineSideSegment>().lineSide();

if(front.considerOneSided())
{
Expand All @@ -2117,8 +2117,8 @@ static bool coveredOpenRange(HEdge &hedge, coord_t middleBottomZ, coord_t middle
return wroteOpaqueMiddle;
}

SectorCluster const &cluster = hedge.face().mapElement().as<BspLeaf>().cluster();
SectorCluster const &backCluster = hedge.twin().face().mapElement().as<BspLeaf>().cluster();
SectorCluster const &cluster = hedge.face().mapElementAs<BspLeaf>().cluster();
SectorCluster const &backCluster = hedge.twin().face().mapElementAs<BspLeaf>().cluster();

coord_t const ffloor = cluster.visFloor().heightSmoothed();
coord_t const fceil = cluster.visCeiling().heightSmoothed();
Expand Down Expand Up @@ -2189,7 +2189,7 @@ static void writeAllWallSections(HEdge *hedge)
return;

// We are only interested in front facing segments with sections.
LineSideSegment &seg = hedge->mapElement().as<LineSideSegment>();
LineSideSegment &seg = hedge->mapElementAs<LineSideSegment>();
if(!seg.isFrontFacing() || !seg.lineSide().hasSections())
return;

Expand Down Expand Up @@ -2259,7 +2259,7 @@ static void writeLeafPlanes()
static void markFrontFacingWalls(HEdge *hedge)
{
if(!hedge || !hedge->hasMapElement()) return;
LineSideSegment &seg = hedge->mapElement().as<LineSideSegment>();
LineSideSegment &seg = hedge->mapElementAs<LineSideSegment>();
// Which way is the line segment facing?
seg.setFrontFacing(viewFacingDot(hedge->origin(), hedge->twin().origin()) >= 0);
}
Expand Down Expand Up @@ -2315,7 +2315,7 @@ static void occludeLeaf(bool frontFacing)
if(!hedge->hasMapElement())
continue;

LineSideSegment &seg = hedge->mapElement().as<LineSideSegment>();
LineSideSegment &seg = hedge->mapElementAs<LineSideSegment>();

// Edges without line segment surface sections can never occlude.
if(!seg.lineSide().hasSections())
Expand All @@ -2329,7 +2329,7 @@ static void occludeLeaf(bool frontFacing)
if(!hedge->hasTwin() || !hedge->twin().hasFace())
continue;

BspLeaf &backLeaf = hedge->twin().face().mapElement().as<BspLeaf>();
BspLeaf &backLeaf = hedge->twin().face().mapElementAs<BspLeaf>();
if(!backLeaf.hasCluster())
continue;
SectorCluster &backCluster = backLeaf.cluster();
Expand Down Expand Up @@ -2408,7 +2408,7 @@ static void clipFrontFacingWalls(HEdge *hedge)
if(!hedge || !hedge->hasMapElement())
return;

LineSideSegment &seg = hedge->mapElement().as<LineSideSegment>();
LineSideSegment &seg = hedge->mapElementAs<LineSideSegment>();
if(seg.isFrontFacing())
{
if(!C_CheckRangeFromViewRelPoints(hedge->origin(), hedge->twin().origin()))
Expand Down Expand Up @@ -3313,7 +3313,7 @@ static void drawTangentVectorsForWallSections(HEdge const *hedge)
if(!hedge || !hedge->hasMapElement())
return;

LineSideSegment const &seg = hedge->mapElement().as<LineSideSegment>();
LineSideSegment const &seg = hedge->mapElementAs<LineSideSegment>();
LineSide const &lineSide = seg.lineSide();
Line const &line = lineSide.line();
Vector2d const center = (hedge->twin().origin() + hedge->origin()) / 2;
Expand All @@ -3322,7 +3322,7 @@ static void drawTangentVectorsForWallSections(HEdge const *hedge)
{
SectorCluster &cluster =
(line.definesPolyobj()? line.polyobj().bspLeaf()
: hedge->face().mapElement().as<BspLeaf>()).cluster();
: hedge->face().mapElementAs<BspLeaf>()).cluster();

coord_t const bottom = cluster. visFloor().heightSmoothed();
coord_t const top = cluster.visCeiling().heightSmoothed();
Expand All @@ -3334,10 +3334,10 @@ static void drawTangentVectorsForWallSections(HEdge const *hedge)
{
SectorCluster &cluster =
(line.definesPolyobj()? line.polyobj().bspLeaf()
: hedge->face().mapElement().as<BspLeaf>()).cluster();
: hedge->face().mapElementAs<BspLeaf>()).cluster();
SectorCluster &backCluster =
(line.definesPolyobj()? line.polyobj().bspLeaf()
: hedge->twin().face().mapElement().as<BspLeaf>()).cluster();
: hedge->twin().face().mapElementAs<BspLeaf>()).cluster();

if(lineSide.middle().hasMaterial())
{
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/shadowedge.cpp
Expand Up @@ -146,10 +146,10 @@ void ShadowEdge::prepare(int planeIndex)
{
int const otherPlaneIndex = planeIndex == Sector::Floor? Sector::Ceiling : Sector::Floor;
HEdge const &hedge = *d->leftMostHEdge;
SectorCluster const &cluster = hedge.face().mapElement().as<BspLeaf>().cluster();
SectorCluster const &cluster = hedge.face().mapElementAs<BspLeaf>().cluster();
Plane const &plane = cluster.visPlane(planeIndex);

LineSide const &lineSide = hedge.mapElement().as<LineSideSegment>().lineSide();
LineSide const &lineSide = hedge.mapElementAs<LineSideSegment>().lineSide();

d->sectorOpenness = 0; // Default is fully closed.
d->openness = 0; // Default is fully closed.
Expand All @@ -159,9 +159,9 @@ void ShadowEdge::prepare(int planeIndex)
// in the polygon corner vertices (placement, opacity).

if(hedge.twin().hasFace() &&
hedge.twin().face().mapElement().as<BspLeaf>().hasCluster())
hedge.twin().face().mapElementAs<BspLeaf>().hasCluster())
{
SectorCluster const &backCluster = hedge.twin().face().mapElement().as<BspLeaf>().cluster();
SectorCluster const &backCluster = hedge.twin().face().mapElementAs<BspLeaf>().cluster();
Plane const &backPlane = backCluster.visPlane(planeIndex);
Surface const &wallEdgeSurface =
lineSide.back().hasSector()? lineSide.surface(planeIndex == Sector::Ceiling? LineSide::Top : LineSide::Bottom)
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/src/render/skyfixedge.cpp
Expand Up @@ -123,8 +123,8 @@ DENG2_PIMPL(SkyFixEdge)
// Only edges with line segments need fixes.
if(!hedge->hasMapElement()) return false;

SectorCluster const *cluster = hedge->face().mapElement().as<BspLeaf>().clusterPtr();
SectorCluster const *backCluster = hedge->twin().hasFace()? hedge->twin().face().mapElement().as<BspLeaf>() .clusterPtr() : 0;
SectorCluster const *cluster = hedge->face().mapElementAs<BspLeaf>().clusterPtr();
SectorCluster const *backCluster = hedge->twin().hasFace()? hedge->twin().face().mapElementAs<BspLeaf>() .clusterPtr() : 0;

if(backCluster && &backCluster->sector() == &cluster->sector())
return false;
Expand All @@ -137,7 +137,7 @@ DENG2_PIMPL(SkyFixEdge)
if(!front->surface().hasSkyMaskedMaterial())
return false;

LineSide const &lineSide = hedge->mapElement().as<LineSideSegment>().lineSide();
LineSide const &lineSide = hedge->mapElementAs<LineSideSegment>().lineSide();
bool const hasClosedBack = R_SideBackClosed(lineSide);

if(!devRendSkyMode)
Expand Down Expand Up @@ -185,9 +185,9 @@ DENG2_PIMPL(SkyFixEdge)
return;
}

SectorCluster const *cluster = hedge->face().mapElement().as<BspLeaf>().clusterPtr();
SectorCluster const *cluster = hedge->face().mapElementAs<BspLeaf>().clusterPtr();
SectorCluster const *backCluster =
hedge->twin().hasFace()? hedge->twin().face().mapElement().as<BspLeaf>().clusterPtr() : 0;
hedge->twin().hasFace()? hedge->twin().face().mapElementAs<BspLeaf>().clusterPtr() : 0;

Plane const *ffloor = &cluster->visFloor();
Plane const *fceil = &cluster->visCeiling();
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/walledge.cpp
Expand Up @@ -140,7 +140,7 @@ DENG2_PIMPL(WallEdge), public IHPlane

SectorCluster const *cluster =
(line.definesPolyobj()? &line.polyobj().bspLeaf()
: &wallHEdge->face().mapElement().as<BspLeaf>())->clusterPtr();
: &wallHEdge->face().mapElementAs<BspLeaf>())->clusterPtr();

if(seg.lineSide().considerOneSided() ||
// Mapping errors may result in a line segment missing a back face.
Expand All @@ -167,7 +167,7 @@ DENG2_PIMPL(WallEdge), public IHPlane
// Two sided.
SectorCluster const *backCluster =
line.definesPolyobj()? cluster
: wallHEdge->twin().face().mapElement().as<BspLeaf>().clusterPtr();
: wallHEdge->twin().face().mapElementAs<BspLeaf>().clusterPtr();

Plane const *ffloor = &cluster->visFloor();
Plane const *fceil = &cluster->visCeiling();
Expand Down Expand Up @@ -347,7 +347,7 @@ DENG2_PIMPL(WallEdge), public IHPlane

inline LineSideSegment &lineSideSegment()
{
return wallHEdge->mapElement().as<LineSideSegment>();
return wallHEdge->mapElementAs<LineSideSegment>();
}

void verifyValid() const
Expand Down Expand Up @@ -503,7 +503,7 @@ DENG2_PIMPL(WallEdge), public IHPlane
while((hedge = &SectorClusterCirculator::findBackNeighbor(*hedge, direction)) != wallHEdge)
{
// Stop if there is no back cluster.
BspLeaf *backLeaf = hedge->hasFace()? &hedge->face().mapElement().as<BspLeaf>() : 0;
BspLeaf *backLeaf = hedge->hasFace()? &hedge->face().mapElementAs<BspLeaf>() : 0;
if(!backLeaf || !backLeaf->hasCluster())
break;

Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/world/bspleaf.cpp
Expand Up @@ -445,7 +445,7 @@ static void updateBiasForWallSectionsAfterGeometryMove(HEdge *hedge)
if(!hedge || !hedge->hasMapElement())
return;

LineSideSegment &seg = hedge->mapElement().as<LineSideSegment>();
LineSideSegment &seg = hedge->mapElementAs<LineSideSegment>();
seg.updateBiasAfterGeometryMove(LineSide::Middle);
seg.updateBiasAfterGeometryMove(LineSide::Bottom);
seg.updateBiasAfterGeometryMove(LineSide::Top);
Expand Down Expand Up @@ -478,7 +478,7 @@ static void applyBiasDigestToWallSections(HEdge *hedge, BiasDigest &changes)
{
if(!hedge || !hedge->hasMapElement())
return;
hedge->mapElement().as<LineSideSegment>().applyBiasDigest(changes);
hedge->mapElementAs<LineSideSegment>().applyBiasDigest(changes);
}

void BspLeaf::applyBiasDigest(BiasDigest &changes)
Expand Down Expand Up @@ -545,7 +545,7 @@ static void accumReverbForWallSections(HEdge const *hedge,
if(!hedge || !hedge->hasMapElement())
return;

LineSideSegment const &seg = hedge->mapElement().as<LineSideSegment>();
LineSideSegment const &seg = hedge->mapElementAs<LineSideSegment>();
if(!seg.lineSide().hasSections() || !seg.lineSide().middle().hasMaterial())
return;

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/line.cpp
Expand Up @@ -405,7 +405,7 @@ bool Line::Side::considerOneSided() const
if(!hedge || !hedge->twin().hasFace())
return true;

if(!hedge->twin().face().mapElement().as<BspLeaf>().hasCluster())
if(!hedge->twin().face().mapElementAs<BspLeaf>().hasCluster())
return true;
}

Expand Down Expand Up @@ -801,7 +801,7 @@ static void addMissingMaterial(LineSide &side, int section)
{
if(hedge->hasFace())
{
BspLeaf &bspLeaf = hedge->face().mapElement().as<BspLeaf>();
BspLeaf &bspLeaf = hedge->face().mapElementAs<BspLeaf>();
if(bspLeaf.hasCluster())
{
bspLeaf.cluster().markReverbDirty();
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/world/linesighttest.cpp
Expand Up @@ -260,7 +260,7 @@ DENG2_PIMPL(LineSightTest)
{
if(hedge->hasMapElement())
{
if(!crossLine(hedge->mapElement().as<LineSideSegment>().lineSide()))
if(!crossLine(hedge->mapElementAs<LineSideSegment>().lineSide()))
return false;
}
} while((hedge = &hedge->next()) != base);
Expand All @@ -272,7 +272,7 @@ DENG2_PIMPL(LineSightTest)
if(!hedge->hasMapElement())
continue;

if(!crossLine(hedge->mapElement().as<LineSideSegment>().lineSide()))
if(!crossLine(hedge->mapElementAs<LineSideSegment>().lineSide()))
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/world/p_objlink.cpp
Expand Up @@ -358,14 +358,14 @@ static void maybeSpreadOverEdge(HEdge *hedge, contactfinderparams_t *parms)
{
DENG_ASSERT(hedge != 0 && parms != 0);

BspLeaf &leaf = hedge->face().mapElement().as<BspLeaf>();
BspLeaf &leaf = hedge->face().mapElementAs<BspLeaf>();
SectorCluster &cluster = leaf.cluster();

// There must be a back BSP leaf to spread to.
if(!hedge->hasTwin() || !hedge->twin().hasFace())
return;

BspLeaf &backLeaf = hedge->twin().face().mapElement().as<BspLeaf>();
BspLeaf &backLeaf = hedge->twin().face().mapElementAs<BspLeaf>();
if(!backLeaf.hasCluster())
return;
SectorCluster &backCluster = backLeaf.cluster();
Expand Down Expand Up @@ -402,7 +402,7 @@ static void maybeSpreadOverEdge(HEdge *hedge, contactfinderparams_t *parms)
// Are there line side surfaces which should prevent spreading?
if(hedge->hasMapElement())
{
LineSideSegment const &seg = hedge->mapElement().as<LineSideSegment>();
LineSideSegment const &seg = hedge->mapElementAs<LineSideSegment>();

// On which side of the line are we? (distance is from segment to origin).
LineSide const &facingLineSide = seg.line().side(seg.lineSide().sideId() ^ (distance < 0));
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/polyobj.cpp
Expand Up @@ -57,7 +57,7 @@ static void notifyGeometryChanged(Polyobj &po)
if(!hedge->hasMapElement())
continue;

hedge->mapElement().as<LineSideSegment>().
hedge->mapElementAs<LineSideSegment>().
updateBiasAfterGeometryMove(LineSide::Middle);
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/world/sector.cpp
Expand Up @@ -455,7 +455,7 @@ void Sector::buildClusters()
{
if(hedge->twin().hasFace())
{
BspLeaf &otherLeaf = hedge->twin().face().mapElement().as<BspLeaf>();
BspLeaf &otherLeaf = hedge->twin().face().mapElementAs<BspLeaf>();
if(&otherLeaf.parent() == this &&
bspLeafSets[k].contains(&otherLeaf))
{
Expand Down

0 comments on commit 5513217

Please sign in to comment.