Skip to content

Commit

Permalink
World|bsp::Partitioner: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 22, 2014
1 parent f61537b commit 3d31e7a
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 181 deletions.
26 changes: 13 additions & 13 deletions doomsday/client/include/world/bsp/linesegment.h
@@ -1,9 +1,9 @@
/** @file world/bsp/linesegment.h World BSP Line Segment.
/** @file linesegment.h World BSP Line Segment.
*
* Originally based on glBSP 2.24 (in turn, based on BSP 2.3)
* @see http://sourceforge.net/projects/glbsp/
*
* @authors Copyright © 2007-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2007-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2000-2007 Andrew Apted <ajapted@gmail.com>
* @authors Copyright © 1998-2000 Colin Reed <cph@moria.org.uk>
* @authors Copyright © 1998-2000 Lee Killough <killough@rsn.hp.com>
Expand Down Expand Up @@ -40,7 +40,6 @@ namespace de {
namespace bsp {

class ConvexSubspaceProxy;
//class SuperBlock;

/**
* LineRelationship delineates the possible logical relationships between two
Expand Down Expand Up @@ -175,9 +174,9 @@ class LineSegment

/**
* Returns a pointer to the map LineSide attributed to this side of the
* line segment; otherwise @c 0
* line segment; otherwise @c nullptr
*/
inline LineSide *mapSidePtr() const { return hasMapSide()? &mapSide() : 0; }
inline LineSide *mapSidePtr() const { return hasMapSide()? &mapSide() : nullptr; }

/**
* Change the map LineSide attributed to the "this" side of the line
Expand Down Expand Up @@ -287,7 +286,7 @@ class LineSegment
* Change the line segment block tree node to which "this" side of the
* line segment is associated.
*
* @param newBMapBlock New blockmap block. Can be @c 0.
* @param newBMapBlock New blockmap block. Use @c nullptr to clear.
*/
void setBlockTreeNode(/*LineSegmentBlockTreeNode*/ void *newNode);

Expand All @@ -306,17 +305,17 @@ class LineSegment

/**
* Returns a pointer to the Sector attributed to "this" side of the line
* segment; otherwise @c 0.
* segment; otherwise @c nullptr.
*
* @see hasSector()
*/
inline Sector *sectorPtr() const { return hasSector()? &sector() : 0; }
inline Sector *sectorPtr() const { return hasSector()? &sector() : nullptr; }

/**
* Change the sector attributed to "this" side of the line segment.
*
* @param newSector New sector to attribute. Ownership is unaffected.
* Can be @c 0.
* Use @c nullptr to clear.
*/
void setSector(Sector *newSector);

Expand Down Expand Up @@ -375,7 +374,8 @@ class LineSegment
* @param toDist Perpendicular distance from the "to" vertex.
* Can be @c 0.
*/
void distance(Side const &other, coord_t *fromDist = 0, coord_t *toDist = 0) const;
void distance(Side const &other, coord_t *fromDist = nullptr,
coord_t *toDist = nullptr) const;

/**
* Determine the logical relationship between "this" line segment side
Expand Down Expand Up @@ -428,7 +428,7 @@ class LineSegment
*
* @see hasHEdge()
*/
inline HEdge *hedgePtr() const { return hasHEdge()? &hedge() : 0; }
inline HEdge *hedgePtr() const { return hasHEdge()? &hedge() : nullptr; }

/**
* Change the built half-edge linked to "this" side of the line segment.
Expand All @@ -449,8 +449,8 @@ class LineSegment
* Change the convex subspace to which "this" side of the line segment
* is attributed.
*
* @param newConvexSubspace ConvexSubspace to attribute. Can be @c 0
* (to clear the attribution).
* @param newConvexSubspace ConvexSubspace to attribute. Use @c nullptr to
* clear the attribution.
*/
void setConvexSubspace(ConvexSubspaceProxy *newConvexSubspace);

Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/include/world/bspleaf.h
Expand Up @@ -51,7 +51,7 @@ class BspLeaf : public BspElement
* Construct a new BSP leaf and optionally attribute it to @a sector.
* Ownership is unaffected.
*/
BspLeaf(Sector *sector = 0);
explicit BspLeaf(Sector *sector = nullptr);

/**
* Determines whether a subspace geometry is attributed to the BSP leaf half-space.
Expand All @@ -73,7 +73,9 @@ class BspLeaf : public BspElement
*
* @see subspace(), hasSubspace()
*/
inline ConvexSubspace *subspacePtr() const { return hasSubspace()? &subspace() : 0; }
inline ConvexSubspace *subspacePtr() const {
return hasSubspace()? &subspace() : nullptr;
}

/**
* Change the subspace geometry attributed to the BSP leaf.
Expand Down
102 changes: 41 additions & 61 deletions doomsday/client/src/world/bsp/convexsubspaceproxy.cpp
Expand Up @@ -47,42 +47,29 @@ namespace bsp {
typedef QList<LineSegmentSide *> SegmentList;

/**
* Represents a clockwise ordering of a subset of the line segments and
* implements logic for partitioning that subset into @em contiguous ranges
* for geometry construction.
* Represents a clockwise ordering of a subset of the line segments and implements logic
* for partitioning the subset into @em contiguous ranges, for geometry construction.
*/
struct Continuity
{
typedef QList<OrderedSegment *> OrderedSegmentList;

/// Front sector uniformly referenced by all line segments.
Sector *sector;
Sector *sector = nullptr; ///< Front sector uniformly referenced by all line segments.
double coverage = 0; ///< Coverage metric.
int discordSegments = 0; ///< Number of discordant (i.e., non-contiguous) line segments.

/// Coverage metric.
double coverage;
/// Number of referencing line segments of each type:
int norm = 0;
int part = 0;
int self = 0;

/// Number of discordant (i.e., non-contiguous) line segments.
int discordSegments;
OrderedSegmentList orderedSegs; ///< Ordered line segments (not owned).
OrderedSegmentList discordSegs; ///< The discordant line segment subset (not owned).

/// Number of referencing line segments of each type:
int norm;
int part;
int self;

/// The ordered line segments.
OrderedSegmentList orderedSegs;

/// The discordant line segments.
OrderedSegmentList discordSegs;

Continuity(Sector *sector)
: sector(sector),
coverage(0),
discordSegments(0),
norm(0),
part(0),
self(0)
{}
Continuity(Sector *frontSector)
{
sector = frontSector;
}

/**
* Perform heuristic comparison between two continuities to determine a
Expand All @@ -108,11 +95,11 @@ struct Continuity
*/
void addOneSegment(OrderedSegment const &oseg)
{
DENG_ASSERT(oseg.segment->sectorPtr() == sector);
DENG2_ASSERT(oseg.segment->sectorPtr() == sector);

// Separate the discordant duplicates.
OrderedSegmentList *list = &orderedSegs;
foreach(OrderedSegment const *other, orderedSegs)
for(OrderedSegment const *other : orderedSegs)
{
if(oseg == *other)
{
Expand Down Expand Up @@ -167,7 +154,7 @@ struct Continuity
}
}

#ifdef DENG_DEBUG
#ifdef DENG2_DEBUG
void debugPrint() const
{
LOGDEV_MAP_MSG("Continuity %p (sector:%i, coverage:%f, discord:%i)")
Expand All @@ -176,11 +163,11 @@ struct Continuity
<< coverage
<< discordSegments;

foreach(OrderedSegment const *oseg, orderedSegs)
for(OrderedSegment const *oseg : orderedSegs)
{
oseg->debugPrint();
}
foreach(OrderedSegment const *oseg, discordSegs)
for(OrderedSegment const *oseg : discordSegs)
{
oseg->debugPrint();
}
Expand All @@ -192,21 +179,14 @@ DENG2_PIMPL_NOREF(ConvexSubspaceProxy)
{
typedef QSet<LineSegmentSide *> Segments;

/// The set of line segments.
Segments segments;

/// The same line segments in a clockwise order with angle info.
OrderedSegments orderedSegments;

/// Set to @c true when the ordered segment list needs to be rebuilt.
bool needRebuildOrderedSegments;

/// BSP leaf attributed to the subspace (if any).
BspLeaf *bspLeaf;
Segments segments; ///< All line segments.
OrderedSegments orderedSegments; ///< All line segments in clockwise order, with angle info.
bool needRebuildOrderedSegments; ///< @c true= the ordered segment list needs to be rebuilt.
BspLeaf *bspLeaf; ///< BSP leaf attributed to the subspace (if any).

Instance()
: needRebuildOrderedSegments(false),
bspLeaf(0)
: needRebuildOrderedSegments(false)
, bspLeaf (nullptr)
{}

Instance(Instance const &other)
Expand All @@ -221,21 +201,21 @@ DENG2_PIMPL_NOREF(ConvexSubspaceProxy)
* Returns @c true iff at least one line segment in the set is derived
* from a map line.
*/
bool haveMapLineSegment()
bool haveMapLineSegment() const
{
foreach(LineSegmentSide *seg, segments)
for(LineSegmentSide const *seg : segments)
{
if(seg->hasMapSide())
return true;
}
return false;
}

Vector2d findCenter()
Vector2d findCenter() const
{
Vector2d center;
int numPoints = 0;
foreach(LineSegmentSide *seg, segments)
for(LineSegmentSide const *seg : segments)
{
center += seg->from().origin();
center += seg->to().origin();
Expand All @@ -261,7 +241,7 @@ DENG2_PIMPL_NOREF(ConvexSubspaceProxy)

orderedSegments.clear();

foreach(LineSegmentSide *seg, segments)
for(LineSegmentSide *seg : segments)
{
Vector2d fromDist = seg->from().origin() - point;
Vector2d toDist = seg->to().origin() - point;
Expand Down Expand Up @@ -321,11 +301,11 @@ DENG2_PIMPL_NOREF(ConvexSubspaceProxy)
};

ConvexSubspaceProxy::ConvexSubspaceProxy()
: d(new Instance())
: d(new Instance)
{}

ConvexSubspaceProxy::ConvexSubspaceProxy(QList<LineSegmentSide *> const &segments)
: d(new Instance())
: d(new Instance)
{
addSegments(segments);
}
Expand All @@ -352,7 +332,7 @@ void ConvexSubspaceProxy::addSegments(QList<LineSegmentSide *> const &newSegment
d->needRebuildOrderedSegments = true;
}

#ifdef DENG_DEBUG
#ifdef DENG2_DEBUG
int numSegmentsAdded = d->segments.size() - sizeBefore;
if(numSegmentsAdded < newSegments.size())
{
Expand Down Expand Up @@ -401,7 +381,7 @@ void ConvexSubspaceProxy::buildGeometry(BspLeaf &leaf, Mesh &mesh) const
typedef QHash<Sector *, Continuity *> SectorContinuityMap;
SectorContinuityMap scMap;

foreach(OrderedSegment const &oseg, d->orderedSegments)
for(OrderedSegment const &oseg : d->orderedSegments)
{
Sector *frontSector = oseg.segment->sectorPtr();

Expand All @@ -427,13 +407,13 @@ void ConvexSubspaceProxy::buildGeometry(BspLeaf &leaf, Mesh &mesh) const

if(!conty.discordSegs.isEmpty())
{
Mesh *extraMesh = 0;
Face *face = 0;
Mesh *extraMesh = nullptr;
Face *face = nullptr;

foreach(OrderedSegment const *oseg, conty.discordSegs)
for(OrderedSegment const *oseg : conty.discordSegs)
{
LineSegmentSide *lineSeg = oseg->segment;
LineSide *mapSide = lineSeg->mapSidePtr();
LineSide *mapSide = lineSeg->mapSidePtr();
if(!mapSide) continue;

if(!extraMesh)
Expand All @@ -453,7 +433,7 @@ void ConvexSubspaceProxy::buildGeometry(BspLeaf &leaf, Mesh &mesh) const
seg->setLineSideOffset(Vector2d(mapSide->from().origin() - lineSeg->from().origin()).length());
seg->setLength(Vector2d(lineSeg->to().origin() - lineSeg->from().origin()).length());
#else
DENG_UNUSED(seg);
DENG2_UNUSED(seg);
#endif

// Link the new half-edge for this line segment to the head of
Expand Down Expand Up @@ -519,7 +499,7 @@ void ConvexSubspaceProxy::buildGeometry(BspLeaf &leaf, Mesh &mesh) const
<< (leaf.sectorPtr()? leaf.sectorPtr()->indexInArchive() : -1)
<< continuities.count();
foreach(Continuity const &conty, continuities)
for(Continuity const &conty : continuities)
{
conty.debugPrint();
}
Expand Down

0 comments on commit 3d31e7a

Please sign in to comment.