diff --git a/doomsday/client/include/map/bsp/partitioner.h b/doomsday/client/include/map/bsp/partitioner.h index e4b28a4444..9d88ac5596 100644 --- a/doomsday/client/include/map/bsp/partitioner.h +++ b/doomsday/client/include/map/bsp/partitioner.h @@ -1,9 +1,4 @@ -/** - * @file partitioner.h - * BSP space partitioner. @ingroup bsp - * - * Based on glBSP 2.24 (in turn, based on BSP 2.3), which is hosted on - * SourceForge: http://sourceforge.net/projects/glbsp/ +/** @file partitioner.h BSP space partitioner. * * @authors Copyright © 2007-2013 Daniel Swanson * @authors Copyright © 2000-2007 Andrew Apted @@ -43,19 +38,27 @@ static const coord_t DIST_EPSILON = (1.0 / 128.0); /// Smallest difference between two angles before being considered equal (in degrees). static const coord_t ANG_EPSILON = (1.0 / 1024.0); +/** + * BSP space partitioner. + * + * Originally based on glBSP 2.24 (in turn, based on BSP 2.3). + * @see http://sourceforge.net/projects/glbsp/ + * + * @ingroup bsp + */ class Partitioner { public: - Partitioner(GameMap& _map, uint numEditableVertexes, - Vertex const **editableVertexes, int _splitCostFactor=7); + Partitioner(GameMap &map, uint numEditableVertexes, + Vertex const **editableVertexes, int splitCostFactor = 7); ~Partitioner(); /** * Set the cost factor associated with splitting an existing half-edge. - * @param factor New factor value. - * @return Reference to this Partitioner. + * + * @param newFactor New split cost factor. */ - Partitioner& setSplitCostFactor(int factor); + void setSplitCostFactor(int newFactor); /** * Build the BSP for the given map. @@ -73,16 +76,6 @@ class Partitioner */ bool build(); - /** - * Retrieve the number of BspNodes owned by this Partitioner. When the - * build completes this number will be the total number of BspNodes that - * were produced during that process. Note that as BspNode ownership is - * claimed this number will decrease respectively. - * - * @return Current number of BspNodes owned by this Partitioner. - */ - uint numNodes(); - /** * Retrieve a pointer to the root BinaryTree node for the constructed BSP. * Even if construction fails this will return a valid node. @@ -90,7 +83,17 @@ class Partitioner * The only time upon which @c NULL is returned is if called prior to calling * BspBuilder::build() */ - BspTreeNode* root() const; + BspTreeNode *root() const; + + /** + * Retrieve the number of HEdges owned by this Partitioner. When the build + * completes this number will be the total number of half-edges that were + * produced during that process. Note that as BspLeaf ownership is claimed + * this number will decrease respectively. + * + * @return Current number of HEdges owned by this Partitioner. + */ + uint numHEdges(); /** * Retrieve the number of BspLeafs owned by this Partitioner. When the @@ -103,14 +106,14 @@ class Partitioner uint numLeafs(); /** - * Retrieve the number of HEdges owned by this Partitioner. When the build - * completes this number will be the total number of half-edges that were - * produced during that process. Note that as BspLeaf ownership is claimed - * this number will decrease respectively. + * Retrieve the number of BspNodes owned by this Partitioner. When the + * build completes this number will be the total number of BspNodes that + * were produced during that process. Note that as BspNode ownership is + * claimed this number will decrease respectively. * - * @return Current number of HEdges owned by this Partitioner. + * @return Current number of BspNodes owned by this Partitioner. */ - uint numHEdges(); + uint numNodes(); /** * Retrieve the total number of Vertexes produced during the build process. @@ -122,15 +125,14 @@ class Partitioner * this will result in fatal error. The caller should ensure the index is * within valid range using Partitioner::numVertexes() */ - Vertex& vertex(uint index); + Vertex &vertex(uint index); /** - * Release ownership of the specified object. + * Relinquish ownership of the specified map data element to the caller. * - * @param ob Map data object to release ownership of. - * @return Reference to this Partitioner. + * @param mapElement Map data element to relinquish ownership of. */ - Partitioner& release(de::MapElement* ob); + void release(MapElement *mapElement); private: struct Instance; diff --git a/doomsday/client/include/map/bspbuilder.h b/doomsday/client/include/map/bspbuilder.h index 21a9cf6b65..e218826361 100644 --- a/doomsday/client/include/map/bspbuilder.h +++ b/doomsday/client/include/map/bspbuilder.h @@ -1,9 +1,4 @@ -/** - * @file bspbuilder.h - * BSP Builder (public interface). @ingroup map - * - * Based on glBSP 2.24 (in turn, based on BSP 2.3), which is hosted on - * SourceForge: http://sourceforge.net/projects/glbsp/ +/** @file bspbuilder.h BSP Builder. * * @authors Copyright © 2007-2013 Daniel Swanson * @authors Copyright © 2000-2007 Andrew Apted @@ -33,10 +28,8 @@ namespace de { -namespace bsp { class Partitioner; } - /** - * BSP node builder. + * Map geometry partitioner and BSP tree builder. * * BspBuilder constructs a BSP object object tree for the specified map. * @@ -48,37 +41,27 @@ class BspBuilder /// Default cost factor attributed to splitting an existing half-edge. static const int DEFAULT_PARTITION_COST_HEDGESPLIT = 7; +public: /** * Create a new BspBuilder initialized for construction using the specified map. * @param map GameMap for which to construct a BSP object tree. * @param splitCostFactor Cost factor attributed to splitting an existing half-edge. */ - BspBuilder(GameMap& map, uint numEditableVertexes, Vertex const **editableVertexes, + BspBuilder(GameMap &map, uint numEditableVertexes, Vertex const **editableVertexes, int splitCostFactor = DEFAULT_PARTITION_COST_HEDGESPLIT); - ~BspBuilder(); /** * Set the cost factor associated with splitting an existing half-edge. - * @param factor New factor value. - * @return Reference to this BspBuilder. + * + * @param newFactor New split cost factor. */ - BspBuilder& setSplitCostFactor(int factor); + void setSplitCostFactor(int newFactor); /** * Build the BSP for the given map. * @return @c true= iff completed successfully. */ - bool build(); - - /** - * Retrieve the number of BspNodes owned by this Partitioner. When the - * build completes this number will be the total number of BspNodes that - * were produced during that process. Note that as BspNode ownership is - * claimed this number will decrease respectively. - * - * @return Current number of BspNodes owned by this Partitioner. - */ - uint numNodes(); + bool buildBsp(); /** * Retrieve a pointer to the root BinaryTree node for the constructed BSP. @@ -87,7 +70,17 @@ class BspBuilder * The only time upon which @c NULL is returned is if called prior to calling * BspBuilder::build() */ - BspTreeNode* root() const; + BspTreeNode *root() const; + + /** + * Retrieve the number of HEdges owned by this Partitioner. When the build + * completes this number will be the total number of half-edges that were + * produced during that process. Note that as BspLeaf ownership is claimed + * this number will decrease respectively. + * + * @return Current number of HEdges owned by this Partitioner. + */ + uint numHEdges(); /** * Retrieve the number of BspLeafs owned by this Partitioner. When the @@ -100,14 +93,14 @@ class BspBuilder uint numLeafs(); /** - * Retrieve the number of HEdges owned by this Partitioner. When the build - * completes this number will be the total number of half-edges that were - * produced during that process. Note that as BspLeaf ownership is claimed - * this number will decrease respectively. + * Retrieve the number of BspNodes owned by this Partitioner. When the + * build completes this number will be the total number of BspNodes that + * were produced during that process. Note that as BspNode ownership is + * claimed this number will decrease respectively. * - * @return Current number of HEdges owned by this Partitioner. + * @return Current number of BspNodes owned by this Partitioner. */ - uint numHEdges(); + uint numNodes(); /** * Retrieve the total number of Vertexes produced during the build process. @@ -119,18 +112,17 @@ class BspBuilder * this will result in fatal error. The caller should ensure the index is * within valid range using Partitioner::numVertexes() */ - Vertex& vertex(uint idx); + Vertex &vertex(uint idx); /** * Release ownership of the specified object. * - * @param ob Map data object to release ownership of. - * @return Reference to this Partitioner. + * @param mapElement Map data object to relinquish ownership of. */ - BspBuilder& take(de::MapElement* ob); + void take(MapElement *mapElement); private: - bsp::Partitioner* partitioner; + DENG2_PRIVATE(d) }; } // namespace de diff --git a/doomsday/client/src/map/bsp/partitioner.cpp b/doomsday/client/src/map/bsp/partitioner.cpp index 2aaddac5ec..133e155504 100644 --- a/doomsday/client/src/map/bsp/partitioner.cpp +++ b/doomsday/client/src/map/bsp/partitioner.cpp @@ -1,8 +1,4 @@ /** @file partitioner.cpp BSP Partitioner. Recursive node creation and sorting. - * @ingroup map - * - * Originally based on glBSP 2.24 (in turn, based on BSP 2.3), which is hosted - * on SourceForge: http://sourceforge.net/projects/glbsp/ * * @authors Copyright © 2006-2013 Daniel Swanson * @authors Copyright © 2006-2007 Jamie Jones @@ -57,6 +53,7 @@ #include "render/r_main.h" // validCount #include "m_misc.h" // M_BoxOnLineSide2 +using namespace de; using namespace de::bsp; // Misc utility routines (most don't belong here...): @@ -1450,10 +1447,10 @@ struct Partitioner::Instance return node; } - BspTreeNode* newTreeNode(de::MapElement* bspOb, - BspTreeNode* rightChild = 0, BspTreeNode* leftChild = 0) + BspTreeNode *newTreeNode(de::MapElement *bspOb, + BspTreeNode *rightChild = 0, BspTreeNode *leftChild = 0) { - BspTreeNode* subtree = new BspTreeNode(bspOb); + BspTreeNode *subtree = new BspTreeNode(bspOb); if(rightChild) { subtree->setRight(rightChild); @@ -1465,7 +1462,7 @@ struct Partitioner::Instance leftChild->setParent(subtree); } - treeNodeMap.insert(std::pair(bspOb, subtree)); + treeNodeMap.insert(std::pair(bspOb, subtree)); return subtree; } @@ -1487,15 +1484,15 @@ struct Partitioner::Instance * @param partList The list of half-edges to be carved into convex subregions. * @return Newly created subtree else @c NULL if degenerate. */ - BspTreeNode* buildNodes(SuperBlock& partList) + BspTreeNode *buildNodes(SuperBlock &partList) { LOG_AS("Partitioner::buildNodes"); - de::MapElement* bspObject = 0; ///< Built BSP object at this node. - BspTreeNode* rightTree = 0, *leftTree = 0; + de::MapElement *bspObject = 0; ///< Built BSP object at this node. + BspTreeNode *rightTree = 0, *leftTree = 0; // Pick a half-edge to use as the next partition plane. - HEdge* partHEdge = chooseNextPartition(partList); + HEdge *partHEdge = chooseNextPartition(partList); if(partHEdge) { //LOG_TRACE("Partition %p [%1.0f, %1.0f] -> [%1.0f, %1.0f].") << de::dintptr(hedge) @@ -1540,7 +1537,7 @@ struct Partitioner::Instance else { // No partition required/possible - already convex (or degenerate). - BspLeaf* leaf = buildBspLeaf(collectHEdges(partList)); + BspLeaf *leaf = buildBspLeaf(collectHEdges(partList)); partList.clear(); // Not a leaf? (collapse upward). @@ -2400,10 +2397,10 @@ struct Partitioner::Instance } }; -Partitioner::Partitioner(GameMap& map, uint numEditableVertexes, +Partitioner::Partitioner(GameMap &map, uint numEditableVertexes, Vertex const **editableVertexes, int splitCostFactor) + : d(new Instance(&map, numEditableVertexes, editableVertexes, splitCostFactor)) { - d = new Instance(&map, numEditableVertexes, editableVertexes, splitCostFactor); d->initForMap(); } @@ -2412,10 +2409,12 @@ Partitioner::~Partitioner() delete d; } -Partitioner& Partitioner::setSplitCostFactor(int factor) +void Partitioner::setSplitCostFactor(int newFactor) { - d->splitCostFactor = factor; - return *this; + if(d->splitCostFactor != newFactor) + { + d->splitCostFactor = newFactor; + } } bool Partitioner::build() @@ -2423,7 +2422,7 @@ bool Partitioner::build() return d->buildBsp(SuperBlockmap(blockmapBounds(d->mapBounds))); } -BspTreeNode* Partitioner::root() const +BspTreeNode *Partitioner::root() const { return d->rootNode; } @@ -2448,22 +2447,21 @@ uint Partitioner::numVertexes() return d->numVertexes; } -Vertex& Partitioner::vertex(uint idx) +Vertex &Partitioner::vertex(uint idx) { DENG2_ASSERT(idx < d->vertexes.size()); DENG2_ASSERT(d->vertexes[idx]); return *d->vertexes[idx]; } -Partitioner& Partitioner::release(de::MapElement* ob) +void Partitioner::release(MapElement *mapElement) { - LOG_AS("Partitioner::release"); - - if(!d->release(ob)) + if(!d->release(mapElement)) { - LOG_DEBUG("Attempted to release an unknown/unowned object %p.") << de::dintptr(ob); + LOG_AS("Partitioner::release"); + LOG_DEBUG("Attempted to release an unknown/unowned object %p.") + << de::dintptr(mapElement); } - return *this; } static LineRelationship lineRelationship(coord_t a, coord_t b, coord_t distEpsilon)