Skip to content

Commit

Permalink
Refactor: Cleaned up map geometry construction somewhat
Browse files Browse the repository at this point in the history
Added precondition assertions and effected some rename refactorings
so that we can again see the wood for the trees...

This'll do for now.
  • Loading branch information
danij-deng committed Apr 14, 2013
1 parent 7fafdc9 commit 2dc1f7f
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 428 deletions.
8 changes: 4 additions & 4 deletions doomsday/client/include/map/line.h
Expand Up @@ -414,9 +414,9 @@ class Line : public de::MapElement
#endif // __CLIENT__

/**
* Returns the left-most half-edge for the side.
* Returns a pointer the left-most half-edge for the side; otherwise @c 0.
*/
HEdge &leftHEdge() const;
HEdge *leftHEdge() const;

/**
* Change the left-most half-edge for the side.
Expand All @@ -428,9 +428,9 @@ class Line : public de::MapElement
void setLeftHEdge(HEdge *newHEdge);

/**
* Returns the right-most half-edge for the side.
* Returns a pointer to the right-most half-edge for the side; otherwise @c 0.
*/
HEdge &rightHEdge() const;
HEdge *rightHEdge() const;

/**
* Change the right-most half-edge for the side.
Expand Down
10 changes: 7 additions & 3 deletions doomsday/client/include/map/polyobj.h
Expand Up @@ -21,12 +21,16 @@
#ifndef LIBDENG_MAP_POLYOBJ_H
#define LIBDENG_MAP_POLYOBJ_H

#include "dd_share.h"

#include <QList>
#include <QSet>

#include <de/vector1.h>

#include "dd_share.h"

#include "map/line.h"
#include "map/vertex.h"

/**
* @ingroup map
*/
Expand Down Expand Up @@ -63,7 +67,7 @@ typedef struct polyobj_s
{
foreach(Line *line, lines())
{
delete &line->front().leftHEdge();
delete line->front().leftHEdge();
}

delete static_cast<Lines *>(_lines);
Expand Down
18 changes: 10 additions & 8 deletions doomsday/client/src/map/bsp/partitioner.cpp
Expand Up @@ -1771,20 +1771,22 @@ DENG2_PIMPL(Partitioner)
/// @todo kludge: This should not be done here!
if(hedge->hasLine())
{
Line::Side &side = hedge->line().side(hedge->lineSideId());
Line::Side &side = hedge->lineSide();

// Already processed?
if(!side._leftHEdge)
if(!side.leftHEdge())
{
side._leftHEdge = hedge;
HEdge *leftHEdge = hedge;
// Find the left-most hedge.
while(hedgeInfo(*side._leftHEdge).prevOnSide)
side._leftHEdge = hedgeInfo(*side._leftHEdge).prevOnSide;
while(hedgeInfo(*leftHEdge).prevOnSide)
leftHEdge = hedgeInfo(*leftHEdge).prevOnSide;
side.setLeftHEdge(leftHEdge);

// Find the right-most hedge.
side._rightHEdge = hedge;
while(hedgeInfo(*side._rightHEdge).nextOnSide)
side._rightHEdge = hedgeInfo(*side._rightHEdge).nextOnSide;
HEdge *rightHEdge = hedge;
while(hedgeInfo(*rightHEdge).nextOnSide)
rightHEdge = hedgeInfo(*rightHEdge).nextOnSide;
side.setRightHEdge(rightHEdge);
}
}
/// kludge end
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/map/hedge.cpp
Expand Up @@ -221,8 +221,8 @@ static void addWallDivNodesForPlaneIntercepts(HEdge const *hedge, walldivs_t *wa
if(section == SS_MIDDLE && isTwoSided) return;

// Only edges at line ends can/should be split.
if(!((hedge == &hedge->lineSide().leftHEdge() && !doRight) ||
(hedge == &hedge->lineSide().rightHEdge() && doRight)))
if(!((hedge == hedge->lineSide().leftHEdge() && !doRight) ||
(hedge == hedge->lineSide().rightHEdge() && doRight)))
return;

if(bottomZ >= topZ) return; // Obviously no division.
Expand Down
10 changes: 4 additions & 6 deletions doomsday/client/src/map/line.cpp
Expand Up @@ -135,10 +135,9 @@ Line::Side::Section const &Line::Side::section(SideSection sectionId) const
return const_cast<Section const &>(const_cast<Side *>(this)->section(sectionId));
}

HEdge &Line::Side::leftHEdge() const
HEdge *Line::Side::leftHEdge() const
{
DENG_ASSERT(_leftHEdge != 0);
return *_leftHEdge;
return _leftHEdge;
}

void Line::Side::setLeftHEdge(HEdge *newLeftHEdge)
Expand All @@ -151,10 +150,9 @@ void Line::Side::setRightHEdge(HEdge *newRightHEdge)
_rightHEdge = newRightHEdge;
}

HEdge &Line::Side::rightHEdge() const
HEdge *Line::Side::rightHEdge() const
{
DENG_ASSERT(_rightHEdge != 0);
return *_rightHEdge;
return _rightHEdge;
}

void Line::Side::updateMiddleSoundEmitterOrigin()
Expand Down
10 changes: 6 additions & 4 deletions doomsday/client/src/map/polyobj.cpp
Expand Up @@ -36,10 +36,12 @@ static void notifyGeometryChanged(Polyobj &po)
// Shadow bias must be informed when surfaces move/deform.
foreach(Line *line, po.lines())
{
HEdge &hedge = line->front().leftHEdge();
HEdge *hedge = line->front().leftHEdge();
if(!hedge) continue;

for(int i = 0; i < 3; ++i)
{
SB_SurfaceMoved(&hedge.biasSurfaceForGeometryGroup(i));
SB_SurfaceMoved(&hedge->biasSurfaceForGeometryGroup(i));
}
}
#else // !__CLIENT__
Expand Down Expand Up @@ -276,7 +278,7 @@ bool Polyobj::rotate(angle_t delta)
line->updateSlopeType();

// HEdge angle must be kept in sync.
line->front().leftHEdge()._angle = BANG_TO_ANGLE(line->angle());
line->front().leftHEdge()->_angle = BANG_TO_ANGLE(line->angle());
}
updateAABox();
angle += delta;
Expand All @@ -303,7 +305,7 @@ bool Polyobj::rotate(angle_t delta)
line->updateSlopeType();

// HEdge angle must be kept in sync.
line->front().leftHEdge()._angle = BANG_TO_ANGLE(line->angle());
line->front().leftHEdge()->_angle = BANG_TO_ANGLE(line->angle());
}
updateAABox();
angle -= delta;
Expand Down
6 changes: 3 additions & 3 deletions doomsday/client/src/render/lumobj.cpp
Expand Up @@ -1173,14 +1173,14 @@ boolean LOIT_ClipLumObjBySight(void *data, void *context)
Polyobj *po = bspLeaf->firstPolyobj();
foreach(Line *line, po->lines())
{
HEdge &hedge = line->front().leftHEdge();
HEdge *hedge = line->front().leftHEdge();

// Ignore half-edges facing the wrong way.
if(hedge._frameFlags & HEDGEINF_FACINGFRONT)
if(hedge->_frameFlags & HEDGEINF_FACINGFRONT)
{
vec2d_t origin; V2d_Set(origin, lum->origin[VX], lum->origin[VY]);

if(V2d_Intercept2(origin, eye, hedge.v1Origin(), hedge.v2Origin(), 0, 0, 0))
if(V2d_Intercept2(origin, eye, hedge->v1Origin(), hedge->v2Origin(), 0, 0, 0))
{
luminousClipped[lumIdx] = 1;
break;
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/render/rend_bias.cpp
Expand Up @@ -252,7 +252,7 @@ void SB_Clear()

void SB_InitForMap(char const *uniqueID)
{
uint startTime = Timer_RealMilliseconds();
de::Time begunAt;

DENG_ASSERT(theMap);

Expand Down Expand Up @@ -345,7 +345,7 @@ void SB_InitForMap(char const *uniqueID)
foreach(Polyobj *polyobj, theMap->polyobjs())
foreach(Line *line, polyobj->lines())
{
HEdge &hedge = line->front().leftHEdge();
HEdge *hedge = line->front().leftHEdge();

for(int i = 0; i < 3; ++i)
{
Expand All @@ -355,11 +355,11 @@ void SB_InitForMap(char const *uniqueID)
bsuf->illum = illums;
illums += 4;

hedge._bsuf[i] = bsuf;
hedge->_bsuf[i] = bsuf;
}
}

VERBOSE2( Con_Message("SB_InitForMap: Done in %.2f seconds.", (Timer_RealMilliseconds() - startTime) / 1000.0f) )
LOG_INFO(String("SB_InitForMap: Done in %1 seconds.").arg(begunAt.since(), 0, 'g', 2));
}

void SB_SetColor(float *dest, float *src)
Expand Down

0 comments on commit 2dc1f7f

Please sign in to comment.