Skip to content

Commit

Permalink
BSP Builder|Refactor: Relocated in-tree linking of BSP data objects t…
Browse files Browse the repository at this point in the history
…o BspBuilder

The BSP object tree produced by BspBuilder is now final. All the user
must do is to take ownership of the object tree (see MPE_SaveBSP).
  • Loading branch information
danij-deng committed Apr 2, 2012
1 parent 91d2982 commit b80d9a3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
27 changes: 26 additions & 1 deletion doomsday/engine/portable/src/bspbuilder/bspbuilder.cpp
Expand Up @@ -250,6 +250,28 @@ void BspBuilder::initForMap()
}
}

static int C_DECL linkTreeNode(BinaryTree* tree, void* /*parameters*/)
{
// We are only interested in BspNodes at this level.
if(BinaryTree_IsLeaf(tree)) return false; // Continue iteration.

BspNode* node = static_cast<BspNode*>(BinaryTree_UserData(tree));

if(BinaryTree* right = BinaryTree_Right(tree))
{
runtime_mapdata_header_t* child = reinterpret_cast<runtime_mapdata_header_t*>(BinaryTree_UserData(right));
BspNode_SetRight(node, child);
}

if(BinaryTree* left = BinaryTree_Left(tree))
{
runtime_mapdata_header_t* child = reinterpret_cast<runtime_mapdata_header_t*>(BinaryTree_UserData(left));
BspNode_SetLeft(node, child);
}

return false; // Continue iteration.
}

void BspBuilder::initHEdgesAndBuildBsp(SuperBlockmap& blockmap, HPlane& hplane)
{
Q_ASSERT(map);
Expand All @@ -260,10 +282,13 @@ void BspBuilder::initHEdgesAndBuildBsp(SuperBlockmap& blockmap, HPlane& hplane)
rootNode = NULL;
builtOK = buildNodes(blockmap.root(), &rootNode, hplane);

// Wind the tree.
if(builtOK)
{
// Wind leafs.
windLeafs(rootNode);

// Link up the BSP object tree.
BinaryTree_PostOrder(rootNode, linkTreeNode, NULL/*no parameters*/);
}
}

Expand Down
33 changes: 9 additions & 24 deletions doomsday/engine/portable/src/edit_bsp.cpp
Expand Up @@ -209,53 +209,38 @@ typedef struct {
GameMap* dest;
uint leafCurIndex;
uint nodeCurIndex;
} hardenbspparams_t;
} populatebspobjectluts_params_t;

/**
* @todo The tree linking functionality should be moved into BspBuilder.
*/
static int C_DECL hardenNode(BinaryTree* tree, void* parameters)
static int C_DECL populateBspObjectLuts(BinaryTree* tree, void* parameters)
{
// We are only interested in nodes at this level.
// We are only interested in BspNodes at this level.
if(BinaryTree_IsLeaf(tree)) return false; // Continue iteration.

BspNode* node = static_cast<BspNode*>(BinaryTree_UserData(tree));
hardenbspparams_t* p = static_cast<hardenbspparams_t*>(parameters);
populatebspobjectluts_params_t* p = static_cast<populatebspobjectluts_params_t*>(parameters);
Q_ASSERT(p);

// Add this to the BspNode LUT.
// Add this BspNode to the LUT.
p->dest->bspNodes[p->nodeCurIndex++] = node;

if(BinaryTree* right = BinaryTree_Right(tree))
{
if(BinaryTree_IsLeaf(right))
{
BspLeaf* leaf = static_cast<BspLeaf*>(BinaryTree_UserData(right));

BspNode_SetRight(node, reinterpret_cast<runtime_mapdata_header_t*>(leaf));
// Add this BspLeaf to the LUT.
p->dest->bspLeafs[p->leafCurIndex++] = leaf;
}
else
{
BspNode* data = static_cast<BspNode*>(BinaryTree_UserData(right));
BspNode_SetRight(node, reinterpret_cast<runtime_mapdata_header_t*>(data));
}
}

if(BinaryTree* left = BinaryTree_Left(tree))
{
if(BinaryTree_IsLeaf(left))
{
BspLeaf* leaf = static_cast<BspLeaf*>(BinaryTree_UserData(left));

BspNode_SetLeft(node, reinterpret_cast<runtime_mapdata_header_t*>(leaf));
// Add this BspLeaf to the LUT.
p->dest->bspLeafs[p->leafCurIndex++] = leaf;
}
else
{
BspNode* data = static_cast<BspNode*>(BinaryTree_UserData(left));
BspNode_SetLeft(node, reinterpret_cast<runtime_mapdata_header_t*>(data));
}
}

return false; // Continue iteration.
Expand Down Expand Up @@ -297,11 +282,11 @@ static void hardenBSP(GameMap* dest, BinaryTree* rootNode)

dest->bsp = static_cast<runtime_mapdata_header_t*>(BinaryTree_UserData(rootNode));

hardenbspparams_t p;
populatebspobjectluts_params_t p;
p.dest = dest;
p.leafCurIndex = 0;
p.nodeCurIndex = 0;
BinaryTree_PostOrder(rootNode, hardenNode, &p);
BinaryTree_PostOrder(rootNode, populateBspObjectLuts, &p);
}

static void hardenVertexes(GameMap* dest, Vertex*** vertexes, uint* numVertexes)
Expand Down

0 comments on commit b80d9a3

Please sign in to comment.