From b80d9a34290aeeadd8fef6e955bcdc4e99e04210 Mon Sep 17 00:00:00 2001 From: danij Date: Mon, 2 Apr 2012 04:02:00 +0100 Subject: [PATCH] BSP Builder|Refactor: Relocated in-tree linking of BSP data objects to 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). --- .../portable/src/bspbuilder/bspbuilder.cpp | 27 ++++++++++++++- doomsday/engine/portable/src/edit_bsp.cpp | 33 +++++-------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/doomsday/engine/portable/src/bspbuilder/bspbuilder.cpp b/doomsday/engine/portable/src/bspbuilder/bspbuilder.cpp index e95e954c89..440ca4939b 100644 --- a/doomsday/engine/portable/src/bspbuilder/bspbuilder.cpp +++ b/doomsday/engine/portable/src/bspbuilder/bspbuilder.cpp @@ -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(BinaryTree_UserData(tree)); + + if(BinaryTree* right = BinaryTree_Right(tree)) + { + runtime_mapdata_header_t* child = reinterpret_cast(BinaryTree_UserData(right)); + BspNode_SetRight(node, child); + } + + if(BinaryTree* left = BinaryTree_Left(tree)) + { + runtime_mapdata_header_t* child = reinterpret_cast(BinaryTree_UserData(left)); + BspNode_SetLeft(node, child); + } + + return false; // Continue iteration. +} + void BspBuilder::initHEdgesAndBuildBsp(SuperBlockmap& blockmap, HPlane& hplane) { Q_ASSERT(map); @@ -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*/); } } diff --git a/doomsday/engine/portable/src/edit_bsp.cpp b/doomsday/engine/portable/src/edit_bsp.cpp index de0a5c5572..e18d377dd0 100644 --- a/doomsday/engine/portable/src/edit_bsp.cpp +++ b/doomsday/engine/portable/src/edit_bsp.cpp @@ -209,21 +209,18 @@ 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(BinaryTree_UserData(tree)); - hardenbspparams_t* p = static_cast(parameters); + populatebspobjectluts_params_t* p = static_cast(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)) @@ -231,15 +228,9 @@ static int C_DECL hardenNode(BinaryTree* tree, void* parameters) if(BinaryTree_IsLeaf(right)) { BspLeaf* leaf = static_cast(BinaryTree_UserData(right)); - - BspNode_SetRight(node, reinterpret_cast(leaf)); + // Add this BspLeaf to the LUT. p->dest->bspLeafs[p->leafCurIndex++] = leaf; } - else - { - BspNode* data = static_cast(BinaryTree_UserData(right)); - BspNode_SetRight(node, reinterpret_cast(data)); - } } if(BinaryTree* left = BinaryTree_Left(tree)) @@ -247,15 +238,9 @@ static int C_DECL hardenNode(BinaryTree* tree, void* parameters) if(BinaryTree_IsLeaf(left)) { BspLeaf* leaf = static_cast(BinaryTree_UserData(left)); - - BspNode_SetLeft(node, reinterpret_cast(leaf)); + // Add this BspLeaf to the LUT. p->dest->bspLeafs[p->leafCurIndex++] = leaf; } - else - { - BspNode* data = static_cast(BinaryTree_UserData(left)); - BspNode_SetLeft(node, reinterpret_cast(data)); - } } return false; // Continue iteration. @@ -297,11 +282,11 @@ static void hardenBSP(GameMap* dest, BinaryTree* rootNode) dest->bsp = static_cast(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)