Skip to content

Commit

Permalink
BSP Builder: Cleanup continues...
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 3, 2012
1 parent 1e1f239 commit 2609c5f
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 99 deletions.
18 changes: 17 additions & 1 deletion doomsday/engine/portable/include/bspbuilder/bspbuilder.hh
Expand Up @@ -165,9 +165,25 @@ private:
* half-edge (and/or backseg), so that future processing is not messed up
* by incorrect counts.
*/
HEdge* splitHEdge(HEdge* oldHEdge, double x, double y);
HEdge* splitHEdge(HEdge* oldHEdge, const_pvec2d_t point);

public:
/**
* Determine the distance (euclidean) from @a hedge to the current partition plane.
*
* @param hedge Half-edge to test.
* @param end @c true= use the point defined by the end (else start) vertex.
*/
inline double hedgeDistanceFromPartition(const HEdge* hedge, bool end) const;

/**
* Calculate the intersection point between a half-edge and the current partition
* plane. Takes advantage of some common situations like horizontal and vertical
* lines to choose a 'nicer' intersection point.
*/
void hedgePartitionIntersection(const HEdge* hedge, double perpC, double perpD,
pvec2d_t point) const;

/**
* Partition the given edge and perform any further necessary action (moving it
* into either the left list, right list, or splitting it).
Expand Down
23 changes: 19 additions & 4 deletions doomsday/engine/portable/include/bspbuilder/superblockmap.h
Expand Up @@ -33,8 +33,8 @@
#include "dd_types.h"
#include "bspbuilder/bsphedgeinfo.h"

#include <de/Log>
#include <list>
#include <assert.h>

#ifdef RIGHT
# undef RIGHT
Expand Down Expand Up @@ -72,7 +72,7 @@ class SuperBlock
/// Assert that the specified value is a valid @a childId.
static void inline assertValidChildId(ChildId DENG_DEBUG_ONLY(childId))
{
assert(childId == RIGHT || childId == LEFT);
Q_ASSERT(childId == RIGHT || childId == LEFT);
}

/**
Expand Down Expand Up @@ -179,19 +179,34 @@ class SuperBlock
*
* @param hedge HEdge instance to add.
*/
SuperBlock* hedgePush(HEdge* hedge);
SuperBlock* push(HEdge* hedge);

/**
* Pop (unlink) the next HEdge from the FIFO list of half-edges linked
* to this superblock.
*
* @return Previous top-most HEdge instance or @c NULL if empty.
*/
HEdge* hedgePop();
HEdge* pop();

HEdges::const_iterator hedgesBegin() const;
HEdges::const_iterator hedgesEnd() const;

DENG_DEBUG_ONLY(
void DebugPrint() const
{
for(SuperBlock::HEdges::const_iterator it = hedgesBegin();
it != hedgesEnd(); ++it)
{
HEdge* hedge = *it;
LOG_DEBUG("Build: %s %p sector: %d [%1.1f, %1.1f] -> [%1.1f, %1.1f]")
<< (hedge->bspBuildInfo->lineDef? "NORM" : "MINI")
<< hedge << hedge->sector->buildData.index
<< hedge->v[0]->buildData.pos[VX] << hedge->v[0]->buildData.pos[VY]
<< hedge->v[1]->buildData.pos[VX] << hedge->v[1]->buildData.pos[VY];
}
})

private:
/**
* SuperBlock objects must be constructed within the context of an
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/src/bspbuilder/bspbuilder.cpp
Expand Up @@ -176,7 +176,7 @@ void BspBuilder::createInitialHEdges(SuperBlock& hedgeList)
LOG_INFO("Bad SideDef on LineDef #%d.") << line->buildData.index;

front = newHEdge(line, line, line->v[0], line->v[1], side->sector, false);
hedgeList.hedgePush(front);
hedgeList.push(front);
}
else
{
Expand All @@ -191,7 +191,7 @@ void BspBuilder::createInitialHEdges(SuperBlock& hedgeList)
LOG_INFO("Bad SideDef on LineDef #%d.") << line->buildData.index;

back = newHEdge(line, line, line->v[1], line->v[0], side->sector, true);
hedgeList.hedgePush(back);
hedgeList.push(back);

if(front)
{
Expand All @@ -215,7 +215,7 @@ void BspBuilder::createInitialHEdges(SuperBlock& hedgeList)
HEdge* other = newHEdge(front->bspBuildInfo->lineDef, line,
line->v[1], line->v[0], line->buildData.windowEffect, true);

hedgeList.hedgePush(other);
hedgeList.push(other);

// Setup the twin-ing (it's very strange to have a mini
// and a normal partnered together).
Expand Down Expand Up @@ -559,8 +559,8 @@ void BspBuilder::buildHEdgesAtIntersectionGaps(SuperBlock& rightList, SuperBlock
addHEdgesBetweenIntercepts(cur, next, &right, &left);

// Add the new half-edges to the appropriate lists.
rightList.hedgePush(right);
leftList.hedgePush(left);
rightList.push(right);
leftList.push(left);
}
}

Expand Down
20 changes: 9 additions & 11 deletions doomsday/engine/portable/src/bspbuilder/hedges.cpp
Expand Up @@ -96,10 +96,9 @@ HEdge* BspBuilder::cloneHEdge(const HEdge& other)
return hedge;
}

HEdge* BspBuilder::splitHEdge(HEdge* oldHEdge, double x, double y)
HEdge* BspBuilder::splitHEdge(HEdge* oldHEdge, const_pvec2d_t point)
{
HEdge* newHEdge;
Vertex* newVert;
Q_ASSERT(oldHEdge && point);

/*#if _DEBUG
if(oldHEdge->lineDef)
Expand All @@ -112,16 +111,15 @@ HEdge* BspBuilder::splitHEdge(HEdge* oldHEdge, double x, double y)
* Create a new vertex (with correct wall_tip info) for the split that
* happens along the given half-edge at the given location.
*/
newVert = createVertex();
newVert->buildData.pos[VX] = x;
newVert->buildData.pos[VY] = y;
Vertex* newVert = createVertex();
V2d_Copy(newVert->buildData.pos, point);

// Compute wall_tip info.
addEdgeTip(newVert, -oldHEdge->bspBuildInfo->pDX, -oldHEdge->bspBuildInfo->pDY, oldHEdge, oldHEdge->twin);
addEdgeTip(newVert, oldHEdge->bspBuildInfo->pDX, oldHEdge->bspBuildInfo->pDY, oldHEdge->twin, oldHEdge);

// Copy the old half-edge info.
newHEdge = cloneHEdge(*oldHEdge);
HEdge* newHEdge = cloneHEdge(*oldHEdge);

newHEdge->bspBuildInfo->prevOnSide = oldHEdge;
oldHEdge->bspBuildInfo->nextOnSide = newHEdge;
Expand All @@ -132,13 +130,13 @@ HEdge* BspBuilder::splitHEdge(HEdge* oldHEdge, double x, double y)
newHEdge->v[0] = newVert;
updateHEdgeInfo(newHEdge, newHEdge->bspBuildInfo);

//DEBUG_Message(("Splitting Vertex is %04X at (%1.1f,%1.1f)\n",
// newVert->index, newVert->V_pos[VX], newVert->V_pos[VY]));
//LOG_DEBUG("Splitting Vertex is %04X at [%1.1f, %1.1f].")
// << newVert->index << newVert->V_pos[VX] << newVert->V_pos[VY];

// Handle the twin.
if(oldHEdge->twin)
{
//DEBUG_Message(("Splitting hedge->twin %p\n", oldHEdge->twin));
//LOG_DEBUG("Splitting hedge twin %p.") << oldHEdge->twin;

// Copy the old hedge info.
newHEdge->twin = cloneHEdge(*oldHEdge->twin);
Expand All @@ -159,7 +157,7 @@ HEdge* BspBuilder::splitHEdge(HEdge* oldHEdge, double x, double y)
if(oldHEdge->twin->bspBuildInfo->block)
{
SuperBlock* block = reinterpret_cast<SuperBlock*>(oldHEdge->twin->bspBuildInfo->block);
block->hedgePush(newHEdge->twin);
block->push(newHEdge->twin);
}
else
{
Expand Down

0 comments on commit 2609c5f

Please sign in to comment.