Skip to content

Commit

Permalink
BSP Builder|Refactor: Switched various internal tree traversals to it…
Browse files Browse the repository at this point in the history
…erative algorithms
  • Loading branch information
danij-deng committed Apr 7, 2012
1 parent e45a35e commit aa3296c
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 136 deletions.
37 changes: 31 additions & 6 deletions doomsday/engine/portable/include/map/bsp/partitioner.h
Expand Up @@ -110,6 +110,9 @@ class SuperBlockmap;
*/
class Partitioner
{
// Used when sorting BSP leaf half-edges by angle around midpoint.
typedef std::vector<HEdge*>HEdgeSortBuffer;

public:
Partitioner(GameMap* _map, uint* numEditableVertexes, Vertex*** editableVertexes, int _splitCostFactor=7);
~Partitioner();
Expand Down Expand Up @@ -288,6 +291,27 @@ class Partitioner
*/
bool buildNodes(SuperBlock& superblock, BspTreeNode** subtree);

/**
* Sort half-edges by angle (from the middle point to the start vertex).
* The desired order (clockwise) means descending angles.
*/
static void sortHEdgesByAngleAroundPoint(HEdgeSortBuffer::iterator begin,
HEdgeSortBuffer::iterator end, pvec2d_t point);

/**
* Sort the given list of half-edges into clockwise order based on their
* position/orientation compared to the specified point.
*
* @param headPtr Ptr to the address of the headPtr to the list
* of hedges to be sorted.
* @param num Number of half edges in the list.
* @param point The point to order around.
*/
static void clockwiseOrder(HEdgeSortBuffer& sortBuffer, HEdge** headPtr,
uint num, pvec2d_t point);

void clockwiseLeaf(BspTreeNode& tree, HEdgeSortBuffer& sortBuffer);

/**
* Traverse the BSP tree and put all the half-edges in each BSP leaf into clockwise
* order, and renumber their indices.
Expand Down Expand Up @@ -329,18 +353,20 @@ class Partitioner
*/
HEdgeIntercept* newHEdgeIntercept(Vertex* vertex, bool lineDefIsSelfReferencing);

/**
* Create a new half-edge.
*/
HEdge* newHEdge(LineDef* line, LineDef* sourceLine, Vertex* start, Vertex* end,
Sector* sec, bool back);
void clearAllHEdgeInfo();

HEdgeTip* newHEdgeTip();

void deleteHEdgeTip(HEdgeTip* tip);

void deleteHEdgeTips(Vertex* vtx);

/**
* Create a new half-edge.
*/
HEdge* newHEdge(LineDef* line, LineDef* sourceLine, Vertex* start, Vertex* end,
Sector* sec, bool back);

/**
* Create a clone of an existing half-edge.
*/
Expand Down Expand Up @@ -384,7 +410,6 @@ class Partitioner

bool registerMigrantHEdge(Sector* sector, HEdge* migrant);

public:
void registerMigrantHEdges(const BspLeaf* leaf);

private:
Expand Down

0 comments on commit aa3296c

Please sign in to comment.