Skip to content

Commit

Permalink
BSP Builder|Cleanup: Standardizing naming conventions and adding comm…
Browse files Browse the repository at this point in the history
…ents where useful
  • Loading branch information
danij-deng committed Apr 3, 2012
1 parent fdcfd03 commit 422e5be
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 48 deletions.
43 changes: 20 additions & 23 deletions doomsday/engine/portable/include/bspbuilder/bspbuilder.hh
Expand Up @@ -134,7 +134,7 @@ private:
*/
BspLeaf* createBSPLeaf(SuperBlock& hedgeList);

const HPlaneIntercept* makeHPlaneIntersection(HEdge* hedge, int leftSide);
const HPlaneIntercept* makePartitionIntersection(HEdge* hedge, int leftSide);

/**
* Initially create all half-edges, one for each side of a linedef.
Expand Down Expand Up @@ -184,35 +184,34 @@ public:
void divideHEdge(HEdge* hedge, SuperBlock& rightList, SuperBlock& leftList);

private:
void clearHPlaneIntercepts();
void clearPartitionIntercepts();

boolean configureHPlane(const HEdge* hedge);
boolean configurePartition(const HEdge* hedge);

/**
* Find the best half-edge in the list to use as a partition.
* Find the best half-edge in the list to use as the next partition.
*
* @param hedgeList List of half-edges to choose from.
* @param partition Ptr to partition to be updated with the results.
*
* @return @c true= A suitable partition was found.
*/
boolean choosePartition(SuperBlock& hedgeList);
boolean chooseNextPartition(SuperBlock& hedgeList);

/**
* Takes the half-edge list and determines if it is convex, possibly converting it
* into a BSP leaf. Otherwise, the list is divided into two halves and recursion will
* continue on the new sub list.
* Takes the half-edge list and determines if it is convex, possibly converting
* it into a BSP leaf. Otherwise, the list is divided into two halves and recursion
* will continue on the new sub list.
*
* This is done by scanning all of the half-edges and finding the one that does the
* least splitting and has the least difference in numbers of half-edges on either side.
* This is done by scanning all of the half-edges and finding the one that does
* the least splitting and has the least difference in numbers of half-edges on
* either side.
*
* If the ones on the left side make a BspLeaf, then create another BspLeaf
* else put the half-edges into the left list.
*
* If the ones on the right side make a BspLeaf, then create another BspLeaf
* else put the half-edges into the right list.
*
* @param superblock Ptr to the list of half edges at the current node.
* @param superblock The list of half edges at the current node.
* @param parent Ptr to write back the address of any newly created subtree.
* @return @c true iff successfull.
*/
Expand All @@ -222,15 +221,15 @@ private:
* Traverse the BSP tree and put all the half-edges in each BSP leaf into clockwise
* order, and renumber their indices.
*
* @important This cannot be done during BspBuilder::buildNodes() since splitting a half-edge with
* a twin may insert another half-edge into that twin's list, usually in the wrong
* place order-wise.
* @important This cannot be done during BspBuilder::buildNodes() since splitting
* a half-edge with a twin may insert another half-edge into that twin's list,
* usually in the wrong place order-wise.
*/
void windLeafs(struct binarytree_s* rootNode);

/**
* Remove all the half-edges from the list, partitioning them into the left or right
* lists based on the given partition line. Adds any intersections onto the
* Remove all the half-edges from the list, partitioning them into the left or
* right lists based on the given partition line. Adds any intersections onto the
* intersection list as it goes.
*/
void partitionHEdges(SuperBlock& hedgeList, SuperBlock& rightList, SuperBlock& leftList);
Expand All @@ -239,10 +238,8 @@ private:
HEdge** right, HEdge** left);

/**
* Analyze the intersection list, and add any needed minihedges to the given half-edge lists
* (one minihedge on each side).
*
* @note All the intersections in the hplane will be free'd back into the quick-alloc list.
* Analyze the intersection list, and add any needed minihedges to the given
* half-edge lists (one minihedge on each side).
*/
void addMiniHEdges(SuperBlock& rightList, SuperBlock& leftList);

Expand All @@ -254,7 +251,7 @@ private:
*
* @return Ptr to the found intercept, else @c NULL;
*/
const HPlaneIntercept* hplaneInterceptByVertex(Vertex* vertex);
const HPlaneIntercept* partitionInterceptByVertex(Vertex* vertex);

/**
* Create a new intersection.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/bspbuilder/bspbuilder.cpp
Expand Up @@ -368,7 +368,7 @@ BinaryTree* BspBuilder::root() const
return rootNode;
}

const HPlaneIntercept* BspBuilder::hplaneInterceptByVertex(Vertex* vertex)
const HPlaneIntercept* BspBuilder::partitionInterceptByVertex(Vertex* vertex)
{
if(!vertex) return NULL; // Hmm...

Expand All @@ -383,7 +383,7 @@ const HPlaneIntercept* BspBuilder::hplaneInterceptByVertex(Vertex* vertex)

HEdgeIntercept* BspBuilder::hedgeInterceptByVertex(Vertex* vertex)
{
const HPlaneIntercept* hpi = hplaneInterceptByVertex(vertex);
const HPlaneIntercept* hpi = partitionInterceptByVertex(vertex);
if(!hpi) return NULL; // Not found.
return (HEdgeIntercept*) hpi->userData();
}
Expand Down
52 changes: 29 additions & 23 deletions doomsday/engine/portable/src/bspbuilder/node.cpp
Expand Up @@ -699,7 +699,7 @@ static int chooseHEdgeFromSuperBlock(SuperBlock* partList, void* parameters)
return false; // Continue iteration.
}

void BspBuilder::clearHPlaneIntercepts()
void BspBuilder::clearPartitionIntercepts()
{
for(HPlane::Intercepts::iterator it = partition().begin(); it != partition().end(); ++it)
{
Expand All @@ -709,15 +709,15 @@ void BspBuilder::clearHPlaneIntercepts()
partition().clear();
}

boolean BspBuilder::configureHPlane(const HEdge* hedge)
boolean BspBuilder::configurePartition(const HEdge* hedge)
{
if(!hedge) return false;

const LineDef* lineDef = hedge->bspBuildInfo->lineDef;
if(!lineDef) return false; // A "mini hedge" is not suitable.

// Clear the HEdge intercept data associated with points in the half-plane.
clearHPlaneIntercepts();
clearPartitionIntercepts();

setPartitionInfo(*hedge->bspBuildInfo);

Expand All @@ -737,7 +737,7 @@ boolean BspBuilder::configureHPlane(const HEdge* hedge)
return true;
}

boolean BspBuilder::choosePartition(SuperBlock& hedgeList)
boolean BspBuilder::chooseNextPartition(SuperBlock& hedgeList)
{
choosehedgefromsuperblockparams_t parm;
parm.hedgeList = &hedgeList;
Expand All @@ -759,10 +759,10 @@ boolean BspBuilder::choosePartition(SuperBlock& hedgeList)
}*/

// Reconfigure the half plane for the next round of hedge sorting.
return configureHPlane(parm.best);
return configurePartition(parm.best);
}

const HPlaneIntercept* BspBuilder::makeHPlaneIntersection(HEdge* hedge, int leftSide)
const HPlaneIntercept* BspBuilder::makePartitionIntersection(HEdge* hedge, int leftSide)
{
HEdgeIntercept* hedgeIntercept;
const HPlaneIntercept* inter;
Expand All @@ -772,7 +772,7 @@ const HPlaneIntercept* BspBuilder::makeHPlaneIntersection(HEdge* hedge, int left

// Already present on this edge?
vertex = hedge->v[leftSide?1:0];
inter = hplaneInterceptByVertex(vertex);
inter = partitionInterceptByVertex(vertex);
if(inter) return inter;

const BspHEdgeInfo& info = partitionInfo();
Expand Down Expand Up @@ -831,22 +831,26 @@ void BspBuilder::divideHEdge(HEdge* hedge, SuperBlock& rightList, SuperBlock& le
LEFT
};

// Get state of lines' relation to each other.
// Determine the relationship between this half-edge and the partition plane.
const BspHEdgeInfo& info = partitionInfo();
double a = M_PerpDist(info.pDX, info.pDY, info.pPerp, info.pLength, hedge->bspBuildInfo->pSX, hedge->bspBuildInfo->pSY);
double b = M_PerpDist(info.pDX, info.pDY, info.pPerp, info.pLength, hedge->bspBuildInfo->pEX, hedge->bspBuildInfo->pEY);

/// @kludge Half-edges produced from the same source linedef must always
/// be treated as collinear.
/// @todo Why is this override necessary?
if(hedge->bspBuildInfo->sourceLineDef == info.sourceLineDef)
a = b = 0;
// kludge end

// Check for being on the same line.
// Collinear with the partition plane?
if(fabs(a) <= DIST_EPSILON && fabs(b) <= DIST_EPSILON)
{
makeHPlaneIntersection(hedge, RIGHT);
makeHPlaneIntersection(hedge, LEFT);
makePartitionIntersection(hedge, RIGHT);
makePartitionIntersection(hedge, LEFT);

// This hedge runs along the same line as the partition. Check whether it goes in
// the same direction or the opposite.
// Direction (vs that of the partition plane) determines in which subset
// this half-edge belongs.
if(hedge->bspBuildInfo->pDX * info.pDX + hedge->bspBuildInfo->pDY * info.pDY < 0)
{
leftList.hedgePush(hedge);
Expand All @@ -858,25 +862,27 @@ void BspBuilder::divideHEdge(HEdge* hedge, SuperBlock& rightList, SuperBlock& le
return;
}

// Check for right side.
// Right of the partition plane?.
if(a > -DIST_EPSILON && b > -DIST_EPSILON)
{
// Close enough to intersect?
if(a < DIST_EPSILON)
makeHPlaneIntersection(hedge, RIGHT);
makePartitionIntersection(hedge, RIGHT);
else if(b < DIST_EPSILON)
makeHPlaneIntersection(hedge, LEFT);
makePartitionIntersection(hedge, LEFT);

rightList.hedgePush(hedge);
return;
}

// Check for left side.
// Left of the partition plane?
if(a < DIST_EPSILON && b < DIST_EPSILON)
{
// Close enough to intersect?
if(a > -DIST_EPSILON)
makeHPlaneIntersection(hedge, RIGHT);
makePartitionIntersection(hedge, RIGHT);
else if(b > -DIST_EPSILON)
makeHPlaneIntersection(hedge, LEFT);
makePartitionIntersection(hedge, LEFT);

leftList.hedgePush(hedge);
return;
Expand All @@ -887,7 +893,7 @@ void BspBuilder::divideHEdge(HEdge* hedge, SuperBlock& rightList, SuperBlock& le
double x, y;
calcIntersection(hedge->bspBuildInfo, &info, a, b, &x, &y);
HEdge* newhedge = splitHEdge(hedge, x, y);
makeHPlaneIntersection(hedge, LEFT);
makePartitionIntersection(hedge, LEFT);

if(a < 0)
{
Expand Down Expand Up @@ -970,8 +976,8 @@ boolean BspBuilder::buildNodes(SuperBlock& hedgeList, BinaryTree** parent)
BSP_PrintSuperBlockhedges(superblock);
#endif*/

// Pick the next partition to use.
if(!choosePartition(hedgeList))
// Pick a half-edge to use as the next partition plane.
if(!chooseNextPartition(hedgeList))
{
// No partition required, already convex.
//LOG_TRACE("BspBuilder::buildNodes: Convex.");
Expand All @@ -997,7 +1003,7 @@ boolean BspBuilder::buildNodes(SuperBlock& hedgeList, BinaryTree** parent)

addMiniHEdges(rightHEdges->root(), leftHEdges->root());

clearHPlaneIntercepts();
clearPartitionIntercepts();

AABoxf rightHEdgesBounds, leftHEdgesBounds;
rightHEdges->findHEdgeBounds(rightHEdgesBounds);
Expand Down

0 comments on commit 422e5be

Please sign in to comment.