Skip to content

Commit

Permalink
BSP Builder|SuperBlockmap: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 3, 2013
1 parent 550a02d commit df5d94a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 125 deletions.
62 changes: 12 additions & 50 deletions doomsday/client/include/map/bsp/superblockmap.h
Expand Up @@ -82,14 +82,6 @@ class SuperBlockmap
DENG2_PRIVATE(d)
};

#ifdef RIGHT
# undef RIGHT
#endif

#ifdef LEFT
# undef LEFT
#endif

/**
* Subblocks:
* RIGHT - has the lower coordinates.
Expand All @@ -104,17 +96,7 @@ class SuperBlock

/// A SuperBlock may be subdivided with two child subblocks which are
/// uniquely identifiable by these associated ids.
enum ChildId
{
RIGHT,
LEFT
};

/// Assert that the specified value is a valid @a childId.
static void inline assertValidChildId(ChildId DENG_DEBUG_ONLY(childId))
{
DENG_ASSERT(childId == RIGHT || childId == LEFT);
}
enum ChildId { Right, Left };

private:
/**
Expand All @@ -134,8 +116,8 @@ class SuperBlock
*/
SuperBlock *addChild(ChildId childId, bool splitVertical);

inline SuperBlock *addRight(bool splitVertical) { return addChild(RIGHT, splitVertical); }
inline SuperBlock *addLeft(bool splitVertical) { return addChild(LEFT, splitVertical); }
inline SuperBlock *addRight(bool splitVertical) { return addChild(Right, splitVertical); }
inline SuperBlock *addLeft(bool splitVertical) { return addChild(Left, splitVertical); }

public:

Expand Down Expand Up @@ -168,32 +150,12 @@ class SuperBlock
return (dimensions.x <= 256 && dimensions.y <= 256);
}

/**
* Returns @c true iff the block has a parent.
*/
bool hasParent() const;

/**
* Returns a pointer to the parent block; otherwise @c 0.
*
* @see hasParent()
*/
SuperBlock *parentPtr() const;

/**
* Returns @c true iff the block has the specified @a child subblock.
*/
bool hasChild(ChildId child) const;

/**
* Returns @c true iff the block has a right child subblock.
*/
inline bool hasRight() const { return hasChild(RIGHT); }

/**
* Returns @c true iff the block has a left child subblock.
*/
inline bool hasLeft() const { return hasChild(LEFT); }
SuperBlock *parent() const;

/**
* Retrieve a child of this subblock. Callers must first determine if a
Expand All @@ -203,19 +165,19 @@ class SuperBlock
* @param childId Subblock identifier.
* @return Selected subblock.
*/
SuperBlock *childPtr(ChildId childId) const;
SuperBlock *child(ChildId childId) const;

/**
* Returns the right subblock.
* @see SuperBlock::childPtr()
* @see SuperBlock::child()
*/
inline SuperBlock *rightPtr() const { return childPtr(RIGHT); }
inline SuperBlock *right() const { return child(Right); }

/**
* Returns the left subblock.
* @see SuperBlock::childPtr()
*/
inline SuperBlock *leftPtr() const { return childPtr(LEFT); }
inline SuperBlock *left() const { return child(Left); }

/**
* Perform a depth-first traversal over all child superblocks and then
Expand Down Expand Up @@ -247,12 +209,12 @@ class SuperBlock
*
* @return Determined line segment total.
*/
uint segmentCount(bool addMap, bool addPart) const;
int segmentCount(bool addMap, bool addPart) const;

/// Convenience functions for retrieving line segment totals:
inline uint partSegmentCount() const { return segmentCount(false, true); }
inline uint mapSegmentCount() const { return segmentCount(true, false); }
inline uint totalSegmentCount() const { return segmentCount(true, true); }
inline int partSegmentCount() const { return segmentCount(false, true); }
inline int mapSegmentCount() const { return segmentCount(true, false); }
inline int totalSegmentCount() const { return segmentCount(true, true); }

/**
* Push (link) the given line segment onto the FIFO list of segments linked
Expand Down
40 changes: 20 additions & 20 deletions doomsday/client/src/map/bsp/partitioner.cpp
Expand Up @@ -576,16 +576,16 @@ DENG2_PIMPL(Partitioner)
}

// Handle sub-blocks recursively.
if(block.hasRight())
if(block.right())
{
bool unsuitable = !evalPartitionCostForSuperBlock(*block.rightPtr(), best, bestCost,
bool unsuitable = !evalPartitionCostForSuperBlock(*block.right(), best, bestCost,
seg, cost);
if(unsuitable) return false;
}

if(block.hasLeft())
if(block.left())
{
bool unsuitable = !evalPartitionCostForSuperBlock(*block.leftPtr(), best, bestCost,
bool unsuitable = !evalPartitionCostForSuperBlock(*block.left(), best, bestCost,
seg, cost);
if(unsuitable) return false;
}
Expand Down Expand Up @@ -719,31 +719,31 @@ DENG2_PIMPL(Partitioner)
{
chooseNextPartitionFromSuperBlock(*cur, candidates, &best, bestCost);

if(prev == cur->parentPtr())
if(prev == cur->parent())
{
// Descending - right first, then left.
prev = cur;
if(cur->hasRight()) cur = cur->rightPtr();
else cur = cur->leftPtr();
if(cur->right()) cur = cur->right();
else cur = cur->left();
}
else if(prev == cur->rightPtr())
else if(prev == cur->right())
{
// Last moved up the right branch - descend the left.
prev = cur;
cur = cur->leftPtr();
cur = cur->left();
}
else if(prev == cur->leftPtr())
else if(prev == cur->left())
{
// Last moved up the left branch - continue upward.
prev = cur;
cur = cur->parentPtr();
cur = cur->parent();
}
}

if(prev)
{
// No left child - back up.
cur = prev->parentPtr();
cur = prev->parent();
}
}

Expand Down Expand Up @@ -1028,31 +1028,31 @@ DENG2_PIMPL(Partitioner)
partitionOneSegment(*seg, rights, lefts);
}

if(prev == cur->parentPtr())
if(prev == cur->parent())
{
// Descending - right first, then left.
prev = cur;
if(cur->hasRight()) cur = cur->rightPtr();
else cur = cur->leftPtr();
if(cur->right()) cur = cur->right();
else cur = cur->left();
}
else if(prev == cur->rightPtr())
else if(prev == cur->right())
{
// Last moved up the right branch - descend the left.
prev = cur;
cur = cur->leftPtr();
cur = cur->left();
}
else if(prev == cur->leftPtr())
else if(prev == cur->left())
{
// Last moved up the left branch - continue upward.
prev = cur;
cur = cur->parentPtr();
cur = cur->parent();
}
}

if(prev)
{
// No left child - back up.
cur = prev->parentPtr();
cur = prev->parent();
}
}

Expand Down

0 comments on commit df5d94a

Please sign in to comment.