Skip to content

Commit

Permalink
Refactor|Partitioner: Use a map Line::Side as the partition line
Browse files Browse the repository at this point in the history
Enabling the partitioning logic to be defined side-relatively.
  • Loading branch information
danij-deng committed Apr 26, 2013
1 parent 32be1a3 commit 1e962e2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
24 changes: 13 additions & 11 deletions doomsday/client/include/map/bsp/hedgeinfo.h
Expand Up @@ -28,7 +28,9 @@

#include <de/mathutil.h>
#include <de/vector1.h>
#include "map/p_maptypes.h"

#include "Line"
#include "Vertex"

namespace de {
namespace bsp {
Expand Down Expand Up @@ -61,13 +63,13 @@ struct HEdgeInfo
// is no longer in any superblock (e.g. now in a leaf).
SuperBlock *bmapBlock;

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

// Line that this half-edge initially comes from.
// For "real" half-edges, this is just the same as the 'line' field
// above. For "miniedges", this is the line of the partition.
Line *sourceLine;
// 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 *sourceLineSide;

/// Map sector attributed to the half-edge. Can be @c 0 for "mini-edges".
Sector *sector;
Expand All @@ -81,8 +83,8 @@ struct HEdgeInfo
nextOnSide(0),
prevOnSide(0),
bmapBlock(0),
line(0),
sourceLine(0),
lineSide(0),
sourceLineSide(0),
sector(0)
{
V2d_Set(start, 0, 0);
Expand All @@ -99,8 +101,8 @@ struct HEdgeInfo
nextOnSide(other.nextOnSide),
prevOnSide(other.prevOnSide),
bmapBlock(other.bmapBlock),
line(other.line),
sourceLine(other.sourceLine),
lineSide(other.lineSide),
sourceLineSide(other.sourceLineSide),
sector(other.sector)
{
V2d_Copy(start, other.start);
Expand Down
64 changes: 31 additions & 33 deletions doomsday/client/src/map/bsp/partitioner.cpp
Expand Up @@ -170,8 +170,8 @@ DENG2_PIMPL(Partitioner)
/// Extra info about the partition plane.
HEdgeInfo partitionInfo;

/// Map line for the partition.
Line *partitionLine;
/// Map line side for the partition.
Line::Side *partitionLineSide;

/// @c true = a BSP for the current map has been built successfully.
bool builtOk;
Expand All @@ -181,7 +181,7 @@ DENG2_PIMPL(Partitioner)
splitCostFactor(_splitCostFactor),
map(&_map),
numNodes(0), numLeafs(0), numHEdges(0), numVertexes(0),
rootNode(0), partitionLine(0),
rootNode(0), partitionLineSide(0),
builtOk(false)
{}

Expand Down Expand Up @@ -411,12 +411,12 @@ DENG2_PIMPL(Partitioner)
*/
HEdge *buildHEdgesBetweenVertexes(Vertex &start, Vertex &end,
Sector *frontSec, Sector *backSec, Line::Side *frontSide,
Line *partitionLine)
Line::Side *partitionLineSide)
{
HEdge *right = newHEdge(start, end, *frontSec, frontSide, partitionLine);
HEdge *right = newHEdge(start, end, *frontSec, frontSide, partitionLineSide);
if(!backSec) return right;

HEdge *left = newHEdge(end, start, *backSec, frontSide? &frontSide->back() : 0, partitionLine);
HEdge *left = newHEdge(end, start, *backSec, frontSide? &frontSide->back() : 0, partitionLineSide);

// Twin the half-edges together.
right->_twin = left;
Expand Down Expand Up @@ -464,7 +464,7 @@ DENG2_PIMPL(Partitioner)
}

front = buildHEdgesBetweenVertexes(line->from(), line->to(),
frontSec, backSec, &line->front(), line);
frontSec, backSec, &line->front(), &line->front());

linkHEdgeInSuperBlockmap(hedgeList, *front);
if(front->hasTwin())
Expand Down Expand Up @@ -509,7 +509,7 @@ DENG2_PIMPL(Partitioner)
if(partitionHasInterceptForVertex(vertex)) return;

HEdgeInfo &hInfo = hedgeInfo(hedge);
bool isSelfRefLine = (hInfo.line && lineInfos[hInfo.line->indexInMap()].flags.testFlag(LineInfo::SelfRef));
bool isSelfRefLine = (hInfo.lineSide && lineInfos[hInfo.lineSide->line().indexInMap()].flags.testFlag(LineInfo::SelfRef));

coord_t distance = vertexDistanceFromPartition(vertex);

Expand Down Expand Up @@ -652,7 +652,7 @@ DENG2_PIMPL(Partitioner)
}

HEdge *right = buildHEdgesBetweenVertexes(*cur.vertex, *next.vertex, sector, sector,
0 /*no line*/, partitionLine);
0 /*no line*/, partitionLineSide);

// Add the new half-edges to the appropriate lists.
linkHEdgeInSuperBlockmap(rightList, *right);
Expand Down Expand Up @@ -756,7 +756,7 @@ DENG2_PIMPL(Partitioner)
/// necessary due to precision inaccuracies when a line is split into
/// multiple segments.
HEdgeInfo const &hInfo = hedgeInfo(hedge);
if(hInfo.sourceLine == pInfo.sourceLine)
if(&hInfo.sourceLineSide->line() == &pInfo.sourceLineSide->line())
{
a = b = 0;
}
Expand Down Expand Up @@ -1230,10 +1230,10 @@ DENG2_PIMPL(Partitioner)
// Optimization: Only the first half-edge produced from a given
// line is tested per round of partition costing (they are all
// collinear).
if(hInfo.line)
if(hInfo.lineSide)
{
// Can we skip this half-edge?
LineInfo &lInfo = lineInfos[hInfo.line->indexInMap()];
LineInfo &lInfo = lineInfos[hInfo.lineSide->line().indexInMap()];
if(lInfo.validCount == validCount) continue; // Yes.

lInfo.validCount = validCount;
Expand Down Expand Up @@ -1511,7 +1511,7 @@ DENG2_PIMPL(Partitioner)
// << Vector2d(hedge->toOrigin()).asText();

// Reconfigure the half-plane for the next round of partitioning.
configurePartition(partHEdge);
configurePartition(*partHEdge);

// Take a copy of the partition - we'll need this later.
Partition oldPartition(partition);
Expand Down Expand Up @@ -1627,28 +1627,25 @@ DENG2_PIMPL(Partitioner)
partitionIntercepts.clear();
}

bool configurePartition(HEdge const *hedge)
bool configurePartition(HEdge const &hedge)
{
LOG_AS("Partitioner::configurePartition");

if(!hedge) return false;
// A "mini hedge" is never suitable.
if(!hedge->hasLineSide()) return false;
DENG_ASSERT(hedge.hasLineSide());

// Clear the HEdge intercept data associated with points in the half-plane.
LOG_AS("Partitioner::configurePartition");

// Clear the list of half-plane intersections.
clearPartitionIntercepts();

// We can now reconfire the half-plane itself.
Line &line = hedge->line();
setPartitionInfo(hedgeInfo(*hedge), &line);
// We can now reconfigure the half-plane.
Line::Side &side = hedge.lineSide();
setPartitionInfo(hedgeInfo(hedge), &side);

Vertex const &from = line.vertex(hedge->lineSideId());
Vertex const &to = line.vertex(hedge->lineSideId()^1);
partition.origin = from.origin();
partition.direction = to.origin() - from.origin();
partition.origin = side.from().origin();
partition.direction = side.to().origin() - side.from().origin();

//LOG_DEBUG("hedge %p %s %s.")
// << de::dintptr(best) << partition.origin.asText() << partition.direction.asText();
// << de::dintptr(&hedge) << partition.origin.asText() << partition.direction.asText();

return true;
}
Expand Down Expand Up @@ -2077,7 +2074,7 @@ DENG2_PIMPL(Partitioner)
* Create a new half-edge.
*/
HEdge *newHEdge(Vertex &from, Vertex &to, Sector &sec, Line::Side *side = 0,
Line *sourceLine = 0)
Line::Side *sourceSide = 0)
{
HEdge *hedge = new HEdge(from, side);
hedge->_to = &to;
Expand All @@ -2087,9 +2084,10 @@ DENG2_PIMPL(Partitioner)
hedgeInfos.insert(hedge, HEdgeInfo());

HEdgeInfo &info = hedgeInfo(*hedge);
info.line = side? &side->line() : 0;
info.sourceLine = sourceLine;
info.sector = &sec;

info.lineSide = side;
info.sourceLineSide = sourceSide;
info.sector = &sec;
info.initFromHEdge(*hedge);

return hedge;
Expand Down Expand Up @@ -2211,10 +2209,10 @@ DENG2_PIMPL(Partitioner)
/**
* Update the extra info about the current partition plane.
*/
void setPartitionInfo(HEdgeInfo const &info, Line *line)
void setPartitionInfo(HEdgeInfo const &info, Line::Side *side)
{
std::memcpy(&partitionInfo, &info, sizeof(partitionInfo));
partitionLine = line;
partitionLineSide = side;
}

bool release(MapElement *elm)
Expand Down

0 comments on commit 1e962e2

Please sign in to comment.