Skip to content

Commit

Permalink
BSP Builder|Cleanup: Use HEdge's lineDef link instead of BspHEdgeInfo
Browse files Browse the repository at this point in the history
Now that we are constructing the final BSP objects as there is no
need to store this info separately in BspHEdgeInfo.
  • Loading branch information
danij-deng committed Apr 12, 2012
1 parent 69d70ea commit d266455
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
3 changes: 0 additions & 3 deletions doomsday/engine/portable/include/map/bsp/bsphedgeinfo.h
Expand Up @@ -57,9 +57,6 @@ typedef struct bsphedgeinfo_s {
// is no longer in any superblock (e.g. now in a leaf).
void* block;

// Linedef that this half-edge goes along, or NULL if miniseg.
LineDef* lineDef;

// Linedef that this half-edge initially comes from.
// For "real" half-edges, this is just the same as the 'linedef' field
// above. For "miniedges", this is the linedef of the partition line.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/map/bsp/superblockmap.h
Expand Up @@ -204,7 +204,7 @@ class SuperBlock
{
HEdge* hedge = *it;
LOG_DEBUG("Build: %s %p sector: %d [%1.1f, %1.1f] -> [%1.1f, %1.1f]")
<< (hedge->bspBuildInfo->lineDef? "NORM" : "MINI")
<< (hedge->lineDef? "NORM" : "MINI")
<< hedge << hedge->sector->buildData.index
<< hedge->v[0]->buildData.pos[VX] << hedge->v[0]->buildData.pos[VY]
<< hedge->v[1]->buildData.pos[VX] << hedge->v[1]->buildData.pos[VY];
Expand Down
52 changes: 26 additions & 26 deletions doomsday/engine/portable/src/map/bsp/partitioner.cpp
Expand Up @@ -94,7 +94,7 @@ struct Partitioner::Instance
map(_map),
numEditableVertexes(_numEditableVertexes), editableVertexes(_editableVertexes),
numNodes(0), numLeafs(0), numVertexes(0),
rootNode(0), partition(0),
rootNode(0), partition(0), partitionLineDef(0),
unclosedSectors(), migrantHEdges(),
builtOK(false)
{
Expand Down Expand Up @@ -297,7 +297,7 @@ struct Partitioner::Instance
// Handle the 'One-Sided Window' trick.
if(line->buildData.windowEffect && front)
{
HEdge* other = newHEdge(front->bspBuildInfo->lineDef, line,
HEdge* other = newHEdge(front->lineDef, line,
line->v[1], line->v[0], line->buildData.windowEffect, true);

hedgeList.push(other);
Expand Down Expand Up @@ -360,7 +360,7 @@ struct Partitioner::Instance
const HPlaneIntercept* inter = partitionInterceptByVertex(vertex);
if(inter) return inter;

LineDef* line = hedge->bspBuildInfo->lineDef;
LineDef* line = hedge->lineDef;
HEdgeIntercept* intercept = newHEdgeIntercept(vertex, line && lineDefInfo(*line).flags.testFlag(LineDefInfo::SELFREF));

return partition->newIntercept(vertexDistanceFromPartition(vertex), intercept);
Expand Down Expand Up @@ -767,9 +767,9 @@ struct Partitioner::Instance

// Only test half-edges from the same linedef once per round of
// partition picking (they are collinear).
if(hedge->bspBuildInfo->lineDef)
if(hedge->lineDef)
{
LineDefInfo& lInfo = lineDefInfo(*hedge->bspBuildInfo->lineDef);
LineDefInfo& lInfo = lineDefInfo(*hedge->lineDef);
if(lInfo.validCount == validCount) continue;
lInfo.validCount = validCount;
}
Expand Down Expand Up @@ -1067,13 +1067,13 @@ struct Partitioner::Instance
{
if(!hedge) return false;

const LineDef* lineDef = hedge->bspBuildInfo->lineDef;
LineDef* lineDef = hedge->lineDef;
if(!lineDef) return false; // A "mini hedge" is not suitable.

// Clear the HEdge intercept data associated with points in the half-plane.
clearPartitionIntercepts();

setPartitionInfo(*hedge->bspBuildInfo);
setPartitionInfo(*hedge->bspBuildInfo, lineDef);

// We can now reconfire the half-plane itself.

Expand Down Expand Up @@ -1216,10 +1216,8 @@ struct Partitioner::Instance
hedge->bspLeaf = leaf;

/// @kludge This should not be done here!
if(hedge->bspBuildInfo->lineDef)
if(hedge->lineDef)
{
// Update LineDef link.
hedge->lineDef = hedge->bspBuildInfo->lineDef;
SideDef* side = HEDGE_SIDEDEF(hedge);
if(side)
{
Expand Down Expand Up @@ -1247,10 +1245,9 @@ struct Partitioner::Instance
hedge = leaf->hedge;
do
{
if(hedge->bspBuildInfo->lineDef &&
hedge->bspBuildInfo->lineDef->sideDefs[hedge->side])
if(hedge->lineDef && hedge->lineDef->sideDefs[hedge->side])
{
SideDef* side = hedge->bspBuildInfo->lineDef->sideDefs[hedge->side];
SideDef* side = hedge->lineDef->sideDefs[hedge->side];
leaf->sector = side->sector;
}
} while(!leaf->sector && (hedge = hedge->next) != leaf->hedge);
Expand Down Expand Up @@ -1334,8 +1331,8 @@ struct Partitioner::Instance
// Create the half-edge pair.
// Leave 'linedef' field as NULL as these are not linedef-linked.
// Leave 'side' as zero too.
(*right) = newHEdge(NULL, partitionInfo.lineDef, start->vertex, end->vertex, start->after, false);
( *left) = newHEdge(NULL, partitionInfo.lineDef, end->vertex, start->vertex, start->after, false);
(*right) = newHEdge(NULL, partitionLineDef, start->vertex, end->vertex, start->after, false);
( *left) = newHEdge(NULL, partitionLineDef, end->vertex, start->vertex, start->after, false);

// Twin the half-edges together.
(*right)->twin = *left;
Expand Down Expand Up @@ -1701,11 +1698,11 @@ struct Partitioner::Instance
hedge->sector = sec;
Q_ASSERT(sec == NULL || GameMap_SectorIndex(map, sec) >= 0);
hedge->side = (back? 1 : 0);
hedge->lineDef = lineDef;

BspHEdgeInfo* info = static_cast<BspHEdgeInfo*>(Z_Malloc(sizeof *info, PU_MAP, 0));
HEdge_AttachBspBuildInfo(hedge, info);

info->lineDef = lineDef;
info->sourceLineDef = sourceLineDef;
info->nextOnSide = info->prevOnSide = NULL;
info->block = NULL;
Expand Down Expand Up @@ -1867,14 +1864,16 @@ struct Partitioner::Instance
void initPartitionInfo()
{
memset(&partitionInfo, 0, sizeof(partitionInfo));
partitionLineDef = 0;
}

/**
* Update the extra info about the current partition plane.
*/
void setPartitionInfo(const BspHEdgeInfo& info)
void setPartitionInfo(const BspHEdgeInfo& info, LineDef* lineDef)
{
memcpy(&partitionInfo, &info, sizeof(partitionInfo));
partitionLineDef = lineDef;
}

/**
Expand Down Expand Up @@ -1936,10 +1935,10 @@ struct Partitioner::Instance

// In the absence of a better mechanism, simply log this right away.
/// @todo Implement something better!
if(migrant->bspBuildInfo->lineDef)
if(migrant->lineDef)
LOG_WARNING("Sector #%d has HEdge facing #%d (line #%d).")
<< sector->buildData.index << migrant->sector->buildData.index
<< migrant->bspBuildInfo->lineDef->buildData.index;
<< migrant->lineDef->buildData.index;
else
LOG_WARNING("Sector #%d has HEdge facing #%d.")
<< sector->buildData.index << migrant->sector->buildData.index;
Expand Down Expand Up @@ -2010,6 +2009,7 @@ struct Partitioner::Instance

/// Extra info about the partition plane.
BspHEdgeInfo partitionInfo;
LineDef* partitionLineDef;

/// Unclosed sectors are recorded here so we don't print too many warnings.
struct UnclosedSectorRecord
Expand Down Expand Up @@ -2228,7 +2228,7 @@ static boolean sanityCheckHasRealhedge(const BspLeaf* leaf)
HEdge* hedge = leaf->hedge;
do
{
if(hedge->bspBuildInfo->lineDef) return true;
if(hedge->lineDef) return true;
} while((hedge = hedge->next) != leaf->hedge);
return false;
}
Expand All @@ -2255,12 +2255,12 @@ static void evalPartitionCostForHEdge(const BspHEdgeInfo* partInfo,
int costFactorMultiplier, const HEdge* hedge, PartitionCost& cost)
{
#define ADD_LEFT() \
if (hedge->bspBuildInfo->lineDef) cost.realLeft += 1; \
else cost.miniLeft += 1; \
if (hedge->lineDef) cost.realLeft += 1; \
else cost.miniLeft += 1; \

#define ADD_RIGHT() \
if (hedge->bspBuildInfo->lineDef) cost.realRight += 1; \
else cost.miniRight += 1; \
if (hedge->lineDef) cost.realRight += 1; \
else cost.miniRight += 1; \

double qnty, a, b, fa, fb;
assert(hedge);
Expand Down Expand Up @@ -2466,8 +2466,7 @@ static bool evalPartition(const SuperBlock& block, int splitCostFactor,
if(!hedge) return false;

// "Mini-hedges" are never potential candidates.
BspHEdgeInfo* hedgeInfo = hedge->bspBuildInfo;
LineDef* lineDef = hedgeInfo->lineDef;
LineDef* lineDef = hedge->lineDef;
if(!lineDef) return false;

if(!evalPartitionCostForSuperBlock(block, splitCostFactor, best, bestCost, hedge, cost))
Expand All @@ -2492,6 +2491,7 @@ static bool evalPartition(const SuperBlock& block, int splitCostFactor,

// Another little twist, here we show a slight preference for partition
// lines that lie either purely horizontally or purely vertically.
BspHEdgeInfo* hedgeInfo = hedge->bspBuildInfo;
if(!FEQUAL(hedgeInfo->pDX, 0) && !FEQUAL(hedgeInfo->pDY, 0))
cost.total += 25;

Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/src/map/bsp/superblockmap.cpp
Expand Up @@ -68,15 +68,15 @@ struct SuperBlock::Instance
void incrementHEdgeCount(HEdge* hedge)
{
if(!hedge) return;
if(hedge->bspBuildInfo->lineDef) realNum++;
else miniNum++;
if(hedge->lineDef) realNum++;
else miniNum++;
}

void decrementHEdgeCount(HEdge* hedge)
{
if(!hedge) return;
if(hedge->bspBuildInfo->lineDef) realNum--;
else miniNum--;
if(hedge->lineDef) realNum--;
else miniNum--;
}
};

Expand Down

0 comments on commit d266455

Please sign in to comment.