Skip to content

Commit

Permalink
Map: Cleaned up interface to the binary space partitioner
Browse files Browse the repository at this point in the history
As the BSP data elements are now produced using data and mechanisms
provided by the map it is no longer logical to "black box" the whole
build process by encapsulating behind a high-level BspBuilder class.

The BspBuilder wrapper was dumped and Reporter relocated to World.

Also reworked the interface to support building a BSP using only a
subset of the map's lines in preparation for future work which will
begin post 1.11 for Doomsday 1.12

Todo: Reconnect the Reporter to the map conversion process so that
any issues or problems encountered are logged.
  • Loading branch information
danij-deng committed Jun 18, 2013
1 parent 6fc8bb5 commit e85bda1
Show file tree
Hide file tree
Showing 11 changed files with 468 additions and 624 deletions.
3 changes: 0 additions & 3 deletions doomsday/client/client.pro
Expand Up @@ -109,7 +109,6 @@ DENG_API_HEADERS = \

# Convenience headers.
DENG_HEADERS += \
include/BspBuilder \
include/BspLeaf \
include/BspNode \
include/EntityDatabase \
Expand Down Expand Up @@ -364,7 +363,6 @@ DENG_HEADERS += \
include/world/bsp/partitioncost.h \
include/world/bsp/partitioner.h \
include/world/bsp/superblockmap.h \
include/world/bspbuilder.h \
include/world/bspleaf.h \
include/world/bspnode.h \
include/world/dmuargs.h \
Expand Down Expand Up @@ -659,7 +657,6 @@ SOURCES += \
src/world/bsp/linesegment.cpp \
src/world/bsp/partitioner.cpp \
src/world/bsp/superblockmap.cpp \
src/world/bspbuilder.cpp \
src/world/bspleaf.cpp \
src/world/bspnode.cpp \
src/world/dmuargs.cpp \
Expand Down
2 changes: 0 additions & 2 deletions doomsday/client/include/BspBuilder

This file was deleted.

45 changes: 23 additions & 22 deletions doomsday/client/include/world/bsp/partitioner.h
Expand Up @@ -29,14 +29,11 @@

#include "world/bsp/bsptreenode.h" /// @todo remove me

class BspLeaf;
class Line;
class Sector;
class Segment;

namespace de {

class Map;
class Mesh;

namespace bsp {
Expand All @@ -51,7 +48,7 @@ static coord_t const DIST_EPSILON = 1.0 / 128.0;
static coord_t const ANG_EPSILON = 1.0 / 1024.0;

/**
* BSP space partitioner.
* World map binary space partitioner (BSP).
*
* Originally based on glBSP 2.24 (in turn, based on BSP 2.3).
* @see http://sourceforge.net/projects/glbsp/
Expand All @@ -62,19 +59,20 @@ class Partitioner
{
public:
/*
* Observers to be notified when an unclosed sector is first found.
* Observers to be notified when an unclosed sector is found.
*/
DENG2_DEFINE_AUDIENCE(UnclosedSectorFound,
void unclosedSectorFound(Sector &sector, Vector2d const &nearPoint))

/*
* Observers to be notified when a one-way window construct is first found.
*/
DENG2_DEFINE_AUDIENCE(OneWayWindowFound,
void oneWayWindowFound(Line &line, Sector &backFacingSector))
typedef QSet<Line *> LineSet;

public:
Partitioner(Map const &map, Mesh &mesh, int splitCostFactor = 7);
/**
* Construct a new binary space partitioner.
*
* @param splitCostFactor Cost factor attributed to splitting a half-edge.
*/
Partitioner(int splitCostFactor = 7);

/**
* Set the cost factor associated with splitting an existing half-edge.
Expand All @@ -84,18 +82,21 @@ class Partitioner
void setSplitCostFactor(int newFactor);

/**
* Build the BSP for the given map.
* Build a new BSP for the given geometry.
*
* @param lines Set of lines to construct a BSP for. A copy of the set is
* made however the caller must ensure that line data remains
* accessible until the build process has completed (ownership
* is unaffected).
*
* @param mesh Mesh from which to assign new geometries. The caller must
* ensure that the mesh remains accessible until the build
* process has completed (ownership is unaffected).
*
* High-level description (courtesy of Raphael Quinet):
* 1. Create one Seg for each Side: pick each Line in turn. If it
* has a "first" Side, then create a normal Seg. If it has a
* "second" Side, then create a flipped Seg.
* 2. Call CreateNodes with the current list of Segs. The list of Segs is
* the only argument to CreateNodes.
* 3. Save the Nodes, Segs and BspLeafs to disk. Start with the leaves of
* the Nodes tree and continue up to the root (last Node).
* @return Root tree node of the resultant BSP otherwise @c 0 if no usable
* tree data was produced.
*/
void build();
BspTreeNode *buildBsp(LineSet const &lines, Mesh &mesh);

/**
* Retrieve a pointer to the root BinaryTree node for the constructed BSP.
Expand Down Expand Up @@ -146,7 +147,7 @@ class Partitioner
*
* @param mapElement Map data element to relinquish ownership of.
*/
void release(MapElement *mapElement);
void take(MapElement *mapElement);

private:
DENG2_PRIVATE(d)
Expand Down
129 changes: 0 additions & 129 deletions doomsday/client/include/world/bspbuilder.h

This file was deleted.

5 changes: 5 additions & 0 deletions doomsday/client/include/world/line.h
Expand Up @@ -611,6 +611,11 @@ class Line : public de::MapElement
*/
coord_t length() const;

/**
* Returns @c true iff the line has a length equivalent to zero.
*/
inline bool hasZeroLength() const { return de::abs(length()) < 1.0 / 128.0; }

/**
* Returns the axis-aligned bounding box which encompases both vertex
* origin points, in map coordinate space units.
Expand Down
14 changes: 14 additions & 0 deletions doomsday/client/include/world/map.h
Expand Up @@ -24,6 +24,8 @@
#include <QList>
#include <QSet>

#include <de/Observers>

#include "Mesh"
#include "p_particle.h"
#include "Polyobj"
Expand Down Expand Up @@ -105,6 +107,18 @@ class Map
DENG2_ERROR(MissingLightGridError);
#endif

/*
* Observers to be notified when a one-way window construct is first found.
*/
DENG2_DEFINE_AUDIENCE(OneWayWindowFound,
void oneWayWindowFound(Line &line, Sector &backFacingSector))

/*
* Observers to be notified when an unclosed sector is first found.
*/
DENG2_DEFINE_AUDIENCE(UnclosedSectorFound,
void unclosedSectorFound(Sector &sector, Vector2d const &nearPoint))

/*
* Linked-element lists/sets:
*/
Expand Down

0 comments on commit e85bda1

Please sign in to comment.