Skip to content

Commit

Permalink
BSP Builder|Cleanup: Reorganised sources to remove some redundancy in…
Browse files Browse the repository at this point in the history
… the class hierarchy
  • Loading branch information
danij-deng committed Apr 6, 2012
1 parent dd2e229 commit 6ff47a5
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 141 deletions.
26 changes: 12 additions & 14 deletions doomsday/engine/engine.pro
Expand Up @@ -129,14 +129,6 @@ DENG_HEADERS += \
portable/include/BspBuilder \

# Private headers.
DENG_HEADERS += \
portable/src/map/bspbuilder/bspbuilder_instance.h \
portable/include/map/bspbuilder/bsphedgeinfo.h \
portable/include/map/bspbuilder/hedgeintercept.h \
portable/include/map/bspbuilder/hplane.h \
portable/include/map/bspbuilder/linedefinfo.h \
portable/include/map/bspbuilder/superblockmap.h \

DENG_HEADERS += \
portable/include/abstractfile.h \
portable/include/abstractresource.h \
Expand All @@ -146,7 +138,13 @@ DENG_HEADERS += \
portable/include/blockmap.h \
portable/include/blockmapvisual.h \
portable/include/blockset.h \
portable/include/map/bspbuilder/bspbuilder.h \
portable/include/map/bspbuilder.h \
portable/include/map/bsp/bsphedgeinfo.h \
portable/include/map/bsp/hedgeintercept.h \
portable/include/map/bsp/hplane.h \
portable/include/map/bsp/linedefinfo.h \
portable/include/map/bsp/partitioner.h \
portable/include/map/bsp/superblockmap.h \
portable/include/bspleaf.h \
portable/include/bspnode.h \
portable/include/b_command.h \
Expand Down Expand Up @@ -440,11 +438,11 @@ SOURCES += \
portable/src/blockset.c \
portable/src/blockmap.c \
portable/src/blockmapvisual.c \
portable/src/map/bspbuilder/bspbuilder.cpp \
portable/src/map/bspbuilder/hedges.cpp \
portable/src/map/bspbuilder/hplane.cpp \
portable/src/map/bspbuilder/nodes.cpp \
portable/src/map/bspbuilder/superblockmap.cpp \
portable/src/map/bspbuilder.cpp \
portable/src/map/bsp/hedges.cpp \
portable/src/map/bsp/hplane.cpp \
portable/src/map/bsp/nodes.cpp \
portable/src/map/bsp/superblockmap.cpp \
portable/src/bspleaf.c \
portable/src/bspnode.c \
portable/src/busytask.cpp \
Expand Down
5 changes: 3 additions & 2 deletions doomsday/engine/portable/include/BspBuilder
@@ -1,2 +1,3 @@
#include "map/bspbuilder/bspbuilder.h"
#include "map/bspbuilder/bsphedgeinfo.h"
#include "map/bspbuilder.h"
#include "map/bsp/bsphedgeinfo.h"
#include "map/bsp/bsptreenode.h"
31 changes: 31 additions & 0 deletions doomsday/engine/portable/include/map/bsp/bsptreenode.h
@@ -0,0 +1,31 @@
/**
* @file bsptreenode.h
* BSP Builder BspTreeNode. @ingroup bsp
*
* @authors Copyright © 2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_BSPBUILDER_BSPTREENODE
#define LIBDENG_BSPBUILDER_BSPTREENODE

#include "p_mapdata.h"
#include "binarytree.h"

/// Nodes in BspBuilder's internal tree are modelled with this type.
typedef de::BinaryTree<runtime_mapdata_header_t*> BspTreeNode;

#endif /// LIBDENG_BSPBUILDER_BSPTREENODE
Expand Up @@ -34,7 +34,7 @@
#include <de/Log>

namespace de {
namespace bspbuilder {
namespace bsp {

/**
* Plain-old-data structure containing additional information for a half-edge
Expand Down Expand Up @@ -69,7 +69,7 @@ struct HEdgeIntercept
})
};

} // namespace bspbuilder
} // namespace bsp
} // namespace de

#endif /// LIBDENG_BSPBUILDER_HEDGEINTERCEPT
Expand Up @@ -33,7 +33,7 @@
#include <list>

namespace de {
namespace bspbuilder {
namespace bsp {

struct HPlanePartition {
double origin[2];
Expand Down Expand Up @@ -158,7 +158,7 @@ class HPlane {
Intercepts intercepts;
};

} // namespace bspbuilder
} // namespace bsp
} // namespace de

#endif /// LIBDENG_BSPBUILDER_HPLANE
Expand Up @@ -33,7 +33,7 @@
#include <QGlobalStatic>

namespace de {
namespace bspbuilder {
namespace bsp {

/**
* Plain old data (POD) structure used to record additional information and
Expand Down Expand Up @@ -62,7 +62,7 @@ struct LineDefInfo

Q_DECLARE_OPERATORS_FOR_FLAGS(LineDefInfo::Flags)

} // namespace bspbuilder
} // namespace bsp
} // namespace de

#endif /// LIBDENG_BSPBUILDER_LINEDEFINFO
Expand Up @@ -33,18 +33,19 @@
#include "binarytree.h"
#include "m_misc.h"

#include "map/bspbuilder/bsphedgeinfo.h"
#include "map/bspbuilder/hedgeintercept.h"
#include "map/bspbuilder/hplane.h"
#include "map/bspbuilder/linedefinfo.h"
#include "map/bspbuilder/superblockmap.h"
#include "map/bsp/bsphedgeinfo.h"
#include "map/bsp/bsptreenode.h"
#include "map/bsp/hedgeintercept.h"
#include "map/bsp/hplane.h"
#include "map/bsp/linedefinfo.h"
#include "map/bsp/superblockmap.h"

#include <BspBuilder>
#include <vector>
#include <list>

namespace de {
namespace bspbuilder {
namespace bsp {

const double IFFY_LEN = 4.0;

Expand Down Expand Up @@ -92,9 +93,10 @@ struct UnclosedSectorRecord
* When there is no more Seg in CreateNodes' list, then they are all in the
* global list and ready to be saved to disk.
*/
struct BspBuilderImp
class Partitioner
{
BspBuilderImp(GameMap* _map, int _splitCostFactor=7) :
public:
Partitioner(GameMap* _map, int _splitCostFactor=7) :
splitCostFactor(_splitCostFactor),
map(_map),
rootNode(0), partition(0),
Expand All @@ -104,7 +106,7 @@ struct BspBuilderImp
initPartitionInfo();
}

~BspBuilderImp();
~Partitioner();

void setSplitCostFactor(int factor)
{
Expand All @@ -113,8 +115,9 @@ struct BspBuilderImp

bool build();

BspBuilder::TreeNode* root() const;
BspTreeNode* root() const;

private:
void initForMap();

Vertex* newVertex(const_pvec2d_t point);
Expand Down Expand Up @@ -191,7 +194,7 @@ struct BspBuilderImp
*
* @param vertex Vertex to test.
*/
inline double BspBuilderImp::vertexDistanceFromPartition(const Vertex* vertex) const
inline double Partitioner::vertexDistanceFromPartition(const Vertex* vertex) const
{
Q_ASSERT(vertex);
const BspHEdgeInfo& info = partitionInfo;
Expand Down Expand Up @@ -235,8 +238,10 @@ struct BspBuilderImp
* also reworked, heavily). I think it is important that both these routines
* follow the exact same logic.
*/
public:
void divideHEdge(HEdge* hedge, SuperBlock& rightList, SuperBlock& leftList);

private:
void clearPartitionIntercepts();

bool configurePartition(const HEdge* hedge);
Expand Down Expand Up @@ -268,7 +273,7 @@ struct BspBuilderImp
* @param parent Ptr to write back the address of any newly created subtree.
* @return @c true iff successfull.
*/
bool buildNodes(SuperBlock& superblock, BspBuilder::TreeNode** parent);
bool buildNodes(SuperBlock& superblock, BspTreeNode** parent);

/**
* Traverse the BSP tree and put all the half-edges in each BSP leaf into clockwise
Expand All @@ -280,6 +285,8 @@ struct BspBuilderImp
*/
void windLeafs();

static int C_DECL partitionHEdgeWorker(SuperBlock* superblock, void* parameters);

/**
* Remove all the half-edges from the list, partitioning them into the left or
* right lists based on the given partition line. Adds any intersections onto the
Expand Down Expand Up @@ -358,7 +365,7 @@ struct BspBuilderImp
*/
bool registerUnclosedSector(Sector* sector, double x, double y);

/// The Active HEdge split cost factor. @see BSPBUILDER_PARTITION_COST_HEDGESPLIT
/// HEdge split cost factor.
int splitCostFactor;

/// Current map which we are building BSP data for.
Expand All @@ -370,7 +377,7 @@ struct BspBuilderImp

/// Root node of our internal binary tree around which the final BSP data
/// objects are constructed.
BspBuilder::TreeNode* rootNode;
BspTreeNode* rootNode;

/// HPlane used to model the current BSP partition and the list of intercepts.
HPlane* partition;
Expand All @@ -386,7 +393,7 @@ struct BspBuilderImp
bool builtOK;
};

} // namespace bspbuilder
} // namespace bsp
} // namespace de

#endif /// LIBDENG_BSPBUILDER_IMPLEMENTATION
Expand Up @@ -36,7 +36,7 @@
#include <list>

namespace de {
namespace bspbuilder {
namespace bsp {

class SuperBlockmap;

Expand Down Expand Up @@ -273,7 +273,7 @@ class SuperBlockmap {
Instance* d;
};

} // namespace bspbuilder
} // namespace bsp
} // namespace de

#endif /// LIBDENG_BSPBUILDER_SUPERBLOCKMAP
Expand Up @@ -29,11 +29,11 @@
#define LIBDENG_BSPBUILDER

#include "de_play.h"
#include "binarytree.h"
#include "map/bsp/bsptreenode.h"

namespace de {

namespace bspbuilder { struct BspBuilderImp; }
namespace bsp { class Partitioner; }

/**
* BSP node builder.
Expand All @@ -48,9 +48,6 @@ class BspBuilder
/// Default cost factor attributed to splitting an existing half-edge.
static const int DEFAULT_PARTITION_COST_HEDGESPLIT = 7;

/// Nodes in the internal tree are modelled with this type.
typedef BinaryTree<runtime_mapdata_header_t*> TreeNode;

/**
* Create a new BspBuilder initialized for construction using the specified map.
* @param map GameMap for which to construct a BSP object tree.
Expand Down Expand Up @@ -79,10 +76,10 @@ class BspBuilder
* The only time upon which @c NULL is returned is if called prior to calling
* BspBuilder::build()
*/
TreeNode* root() const;
BspTreeNode* root() const;

private:
bspbuilder::BspBuilderImp* d;
bsp::Partitioner* partitioner;
};

} // namespace de
Expand Down

0 comments on commit 6ff47a5

Please sign in to comment.