Skip to content

Commit

Permalink
Refactor|BSP Builder: Began remodelling the space partitioning logic
Browse files Browse the repository at this point in the history
Returning to this code after the enhancements made for Doomsday 1.10
it is clear that the high level design of this module was somewhat
compromised in the process.

Before going further with the extraction of the geometry generation
from the map renderer, it makes sense to clarify the implementation
once more.
  • Loading branch information
danij-deng committed Apr 27, 2013
1 parent 1e962e2 commit 4809795
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 395 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/client.pro
Expand Up @@ -224,10 +224,10 @@ DENG_HEADERS += \
include/map/blockmap.h \
include/map/blockmapvisual.h \
include/map/bsp/bsptreenode.h \
include/map/bsp/hedgeinfo.h \
include/map/bsp/hedgeintercept.h \
include/map/bsp/hedgetip.h \
include/map/bsp/lineinfo.h \
include/map/bsp/linesegment.h \
include/map/bsp/partitioncost.h \
include/map/bsp/partitioner.h \
include/map/bsp/superblockmap.h \
Expand Down
36 changes: 34 additions & 2 deletions doomsday/client/include/map/bsp/hedgeintercept.h
Expand Up @@ -51,8 +51,9 @@ struct HEdgeIntercept
// True if this intersection was on a self-referencing line.
bool selfRef;

// Sector on each side of the vertex (along the partition),
// or NULL when that direction isn't OPEN.
/// Sector on each side of the vertex (along the partition), or @c 0 if that
/// direction is "closed" (i.e., the intercept point is along a map line that
/// has no Sector on the relevant side).
Sector *before;
Sector *after;

Expand All @@ -70,6 +71,37 @@ struct HEdgeIntercept
after(other.after)
{}

void merge(HEdgeIntercept const &other)
{
/*
LOG_TRACE("Merging intersections:");
debugPrint();
other.debugPrint();
*/

if(selfRef && !other.selfRef)
{
if(before && other.before)
before = other.before;

if(after && other.after)
after = other.after;

selfRef = false;
}

if(!before && other.before)
before = other.before;

if(!after && other.after)
after = other.after;

/*
LOG_TRACE("Result:");
debugPrint();
*/
}

#ifdef DENG_DEBUG
void debugPrint() const
{
Expand Down
4 changes: 0 additions & 4 deletions doomsday/client/include/map/bsp/lineinfo.h
Expand Up @@ -47,7 +47,6 @@ struct LineInfo
{
Twosided = 0x1, ///< Line is marked two-sided.
ZeroLength = 0x2, ///< Zero length (line should be totally ignored).
SelfRef = 0x4 ///< Sector is the same on both sides.
};
Q_DECLARE_FLAGS(Flags, Flag)

Expand Down Expand Up @@ -76,9 +75,6 @@ struct LineInfo
if(line->hasFrontSections() && line->hasBackSections())
{
flags |= Twosided;

if(line->isSelfReferencing())
flags |= SelfRef;
}
}
};
Expand Down
@@ -1,4 +1,4 @@
/** @file hedgeinfo.h BSP Builder half-edge info.
/** @file map/bsp/linesegment.h BSP Builder Line Segment.
*
* Originally based on glBSP 2.24 (in turn, based on BSP 2.3)
* @see http://sourceforge.net/projects/glbsp/
Expand All @@ -23,8 +23,8 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_WORLD_MAP_BSP_HEDGEINFO
#define DENG_WORLD_MAP_BSP_HEDGEINFO
#ifndef DENG_WORLD_MAP_BSP_LINESEGMENT
#define DENG_WORLD_MAP_BSP_LINESEGMENT

#include <de/mathutil.h>
#include <de/vector1.h>
Expand All @@ -38,12 +38,11 @@ namespace bsp {
class SuperBlock;

/**
* Plain old data (POD) structure storing additional information about a
* half-edge produced by BspBuilder.
* Models a finite line segment in the plane.
*
* @ingroup bsp
*/
struct HEdgeInfo
struct LineSegment
{
coord_t start[2];
coord_t end[2];
Expand All @@ -59,22 +58,23 @@ struct HEdgeInfo
HEdge *nextOnSide;
HEdge *prevOnSide;

// The superblock that contains this half-edge, or NULL if the half-edge
// is no longer in any superblock (e.g. now in a leaf).
/// The superblock that contains this segment, or @c 0 if the segment is no
/// longer in any superblock (e.g., now in or being turned into a leaf edge).
SuperBlock *bmapBlock;

/// Line side that this half-edge initially comes (otherwise @c 0 signifying a "mini-edge").
/// Line side that this line segment initially comes (otherwise @c 0 signifying
/// a "mini-segment").
Line::Side *lineSide;

// Line side that this half-edge initially comes from. For "real" half-edges,
// this is just the same as @var line field. For "mini-edges", this is the
// the partition line side.
/// Line side that this line segment initially comes from. For "real" segments,
/// this is just the same as @var lineSide. For "mini-segments", this is the
/// the partition line side.
Line::Side *sourceLineSide;

/// Map sector attributed to the half-edge. Can be @c 0 for "mini-edges".
/// Map sector attributed to the line segment. Can be @c 0 for "mini-segments".
Sector *sector;

HEdgeInfo()
LineSegment()
: pLength(0),
pAngle(0),
pPara(0),
Expand All @@ -92,7 +92,7 @@ struct HEdgeInfo
V2d_Set(direction, 0, 0);
}

HEdgeInfo(HEdgeInfo const &other)
LineSegment(LineSegment const &other)
: pLength(other.pLength),
pAngle(other.pAngle),
pPara(other.pPara),
Expand All @@ -110,6 +110,25 @@ struct HEdgeInfo
V2d_Copy(direction, other.direction);
}

LineSegment &operator = (LineSegment const &other)
{
V2d_Copy(start, other.start);
V2d_Copy(end, other.end);
V2d_Copy(direction, other.direction);
pLength = other.pLength;
pAngle = other.pAngle;
pPara = other.pPara;
pPerp = other.pPerp;
pSlopeType = other.pSlopeType;
nextOnSide = other.nextOnSide;
prevOnSide = other.prevOnSide;
bmapBlock = other.bmapBlock;
lineSide = other.lineSide;
sourceLineSide = other.sourceLineSide;
sector = other.sector;
return *this;
}

void initFromHEdge(HEdge const &hedge)
{
V2d_Set(start, hedge.fromOrigin().x, hedge.fromOrigin().y);
Expand All @@ -129,4 +148,4 @@ struct HEdgeInfo
} // namespace bsp
} // namespace de

#endif // DENG_WORLD_MAP_BSP_HEDGEINFO
#endif // DENG_WORLD_MAP_BSP_LINESEGMENT
4 changes: 2 additions & 2 deletions doomsday/client/include/map/bsp/partitioncost.h
Expand Up @@ -39,7 +39,7 @@ struct PartitionCost
{
enum Side
{
Right = 0,
Right,
Left
};

Expand Down Expand Up @@ -67,7 +67,7 @@ struct PartitionCost
inline PartitionCost &addHEdgeLeft(HEdge const &hedge)
{
if(hedge.hasLineSide()) realLeft += 1;
else miniLeft += 1;
else miniLeft += 1;
return *this;
}

Expand Down

0 comments on commit 4809795

Please sign in to comment.