Skip to content

Commit

Permalink
BSP Builder|Cleanup: Relocated various functions to their new homes
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Mar 24, 2012
1 parent 357bd93 commit e2681cc
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 174 deletions.
174 changes: 160 additions & 14 deletions doomsday/engine/portable/src/bspbuilder/bspbuilder.cpp
Expand Up @@ -446,6 +446,166 @@ void BspBuilder::addHEdgesBetweenIntercepts(HPlane* hplane,
*/
}

void Bsp_MergeHEdgeIntercepts(HEdgeIntercept* final, const HEdgeIntercept* other)
{
if(!final || !other)
Con_Error("Bsp_MergeIntersections2: Invalid arguments");

/* DEBUG_Message((" Merging intersections:\n"));
#if _DEBUG
Bsp_PrintHEdgeIntercept(final);
Bsp_PrintHEdgeIntercept(other);
#endif*/

if(final->selfRef && !other->selfRef)
{
if(final->before && other->before)
final->before = other->before;

if(final->after && other->after)
final->after = other->after;

final->selfRef = false;
}

if(!final->before && other->before)
final->before = other->before;

if(!final->after && other->after)
final->after = other->after;

/* DEBUG_Message((" Result:\n"));
#if _DEBUG
Bsp_PrintHEdgeIntercept(final);
#endif*/
}

void BspBuilder::mergeIntersections(HPlane* hplane)
{
if(!hplane) return;

HPlane::Intercepts::const_iterator node = hplane->begin();
while(node != hplane->end())
{
HPlane::Intercepts::const_iterator np = node; np++;
if(np == hplane->end()) break;

double len = *np - *node;
if(len < -0.1)
{
Con_Error("BspBuilder_MergeIntersections: Invalid intercept order - %1.3f > %1.3f\n",
node->distance, np->distance);
}
else if(len > 0.2)
{
node++;
continue;
}

HEdgeIntercept* cur = (HEdgeIntercept*)node->userData;
HEdgeIntercept* next = (HEdgeIntercept*)np->userData;

/*if(len > DIST_EPSILON)
{
DEBUG_Message((" Skipping very short half-edge (len=%1.3f) near (%1.1f,%1.1f)\n",
len, cur->vertex->V_pos[VX], cur->vertex->V_pos[VY]));
}*/

// Merge info for the two intersections into one.
Bsp_MergeHEdgeIntercepts(cur, next);

// Destroy the orphaned info.
deleteHEdgeIntercept(next);

// Unlink this intercept.
hplane->deleteIntercept(np);
}
}

void BspBuilder::buildHEdgesAtIntersectionGaps(HPlane* hplane, SuperBlock* rightList,
SuperBlock* leftList)
{
HPlane::Intercepts::const_iterator node;

if(!hplane) return;

node = hplane->begin();
while(node != hplane->end())
{
HPlane::Intercepts::const_iterator np = node; np++;
if(np == hplane->end()) break;

HEdgeIntercept* cur = (HEdgeIntercept*)((*node).userData);
HEdgeIntercept* next = (HEdgeIntercept*)((*np).userData);

if(!(!cur->after && !next->before))
{
// Check for some nasty open/closed or close/open cases.
if(cur->after && !next->before)
{
if(!cur->selfRef)
{
double pos[2];

pos[VX] = cur->vertex->buildData.pos[VX] + next->vertex->buildData.pos[VX];
pos[VY] = cur->vertex->buildData.pos[VY] + next->vertex->buildData.pos[VY];

pos[VX] /= 2;
pos[VY] /= 2;

MPE_RegisterUnclosedSectorNear(cur->after, pos[VX], pos[VY]);
}
}
else if(!cur->after && next->before)
{
if(!next->selfRef)
{
double pos[2];

pos[VX] = cur->vertex->buildData.pos[VX] + next->vertex->buildData.pos[VX];
pos[VY] = cur->vertex->buildData.pos[VY] + next->vertex->buildData.pos[VY];
pos[VX] /= 2;
pos[VY] /= 2;

MPE_RegisterUnclosedSectorNear(next->before, pos[VX], pos[VY]);
}
}
else
{
// This is definitetly open space.
bsp_hedge_t* right, *left;

// Do a sanity check on the sectors (just for good measure).
if(cur->after != next->before)
{
if(!cur->selfRef && !next->selfRef)
{
VERBOSE(
Con_Message("Sector mismatch: #%d (%1.1f,%1.1f) != #%d (%1.1f,%1.1f)\n",
cur->after->buildData.index, cur->vertex->buildData.pos[VX],
cur->vertex->buildData.pos[VY], next->before->buildData.index,
next->vertex->buildData.pos[VX], next->vertex->buildData.pos[VY]));
}

// Choose the non-self-referencing sector when we can.
if(cur->selfRef && !next->selfRef)
{
cur->after = next->before;
}
}

addHEdgesBetweenIntercepts(hplane, cur, next, &right, &left);

// Add the new half-edges to the appropriate lists.
rightList->hedgePush(right);
leftList->hedgePush(left);
}
}

node++;
}
}

void BspBuilder::addMiniHEdges(HPlane* hplane, SuperBlock* rightList,
SuperBlock* leftList)
{
Expand Down Expand Up @@ -527,17 +687,3 @@ void BspBuilder::addEdgeTip(Vertex* vert, double dx, double dy, bsp_hedge_t* bac
vert->buildData.tipSet = tip;
}
}

#if _DEBUG
void Bsp_PrintHEdgeIntercept(HEdgeIntercept* inter)
{
assert(inter);
Con_Message("Vertex #%i [x:%f, y:%f] beforeSector: #%d afterSector: #%d %s\n",
inter->vertex->buildData.index,
inter->vertex->buildData.pos[VX],
inter->vertex->buildData.pos[VY],
(inter->before? inter->before->buildData.index : -1),
(inter->after? inter->after->buildData.index : -1),
(inter->selfRef? "SELFREF" : ""));
}
#endif
14 changes: 14 additions & 0 deletions doomsday/engine/portable/src/bspbuilder/hedges.cpp
Expand Up @@ -44,6 +44,20 @@

using namespace de;

#if _DEBUG
void Bsp_PrintHEdgeIntercept(HEdgeIntercept* inter)
{
assert(inter);
Con_Message("Vertex #%i [x:%f, y:%f] beforeSector: #%d afterSector: #%d %s\n",
inter->vertex->buildData.index,
inter->vertex->buildData.pos[VX],
inter->vertex->buildData.pos[VY],
(inter->before? inter->before->buildData.index : -1),
(inter->after? inter->after->buildData.index : -1),
(inter->selfRef? "SELFREF" : ""));
}
#endif

static void initBspHEdgeInfo(const bsp_hedge_t* hedge, BspHEdgeInfo* info)
{
assert(hedge);
Expand Down
160 changes: 0 additions & 160 deletions doomsday/engine/portable/src/bspbuilder/intersection.cpp
Expand Up @@ -119,166 +119,6 @@ HPlane* HPlane::setDY(double newDY)
return this;
}

void Bsp_MergeHEdgeIntercepts(HEdgeIntercept* final, const HEdgeIntercept* other)
{
if(!final || !other)
Con_Error("Bsp_MergeIntersections2: Invalid arguments");

/* DEBUG_Message((" Merging intersections:\n"));
#if _DEBUG
Bsp_PrintHEdgeIntercept(final);
Bsp_PrintHEdgeIntercept(other);
#endif*/

if(final->selfRef && !other->selfRef)
{
if(final->before && other->before)
final->before = other->before;

if(final->after && other->after)
final->after = other->after;

final->selfRef = false;
}

if(!final->before && other->before)
final->before = other->before;

if(!final->after && other->after)
final->after = other->after;

/* DEBUG_Message((" Result:\n"));
#if _DEBUG
Bsp_PrintHEdgeIntercept(final);
#endif*/
}

void BspBuilder::mergeIntersections(HPlane* hplane)
{
if(!hplane) return;

HPlane::Intercepts::const_iterator node = hplane->begin();
while(node != hplane->end())
{
HPlane::Intercepts::const_iterator np = node; np++;
if(np == hplane->end()) break;

double len = *np - *node;
if(len < -0.1)
{
Con_Error("BspBuilder_MergeIntersections: Invalid intercept order - %1.3f > %1.3f\n",
node->distance, np->distance);
}
else if(len > 0.2)
{
node++;
continue;
}

HEdgeIntercept* cur = (HEdgeIntercept*)node->userData;
HEdgeIntercept* next = (HEdgeIntercept*)np->userData;

/*if(len > DIST_EPSILON)
{
DEBUG_Message((" Skipping very short half-edge (len=%1.3f) near (%1.1f,%1.1f)\n",
len, cur->vertex->V_pos[VX], cur->vertex->V_pos[VY]));
}*/

// Merge info for the two intersections into one.
Bsp_MergeHEdgeIntercepts(cur, next);

// Destroy the orphaned info.
deleteHEdgeIntercept(next);

// Unlink this intercept.
hplane->deleteIntercept(np);
}
}

void BspBuilder::buildHEdgesAtIntersectionGaps(HPlane* hplane, SuperBlock* rightList,
SuperBlock* leftList)
{
HPlane::Intercepts::const_iterator node;

if(!hplane) return;

node = hplane->begin();
while(node != hplane->end())
{
HPlane::Intercepts::const_iterator np = node; np++;
if(np == hplane->end()) break;

HEdgeIntercept* cur = (HEdgeIntercept*)((*node).userData);
HEdgeIntercept* next = (HEdgeIntercept*)((*np).userData);

if(!(!cur->after && !next->before))
{
// Check for some nasty open/closed or close/open cases.
if(cur->after && !next->before)
{
if(!cur->selfRef)
{
double pos[2];

pos[VX] = cur->vertex->buildData.pos[VX] + next->vertex->buildData.pos[VX];
pos[VY] = cur->vertex->buildData.pos[VY] + next->vertex->buildData.pos[VY];

pos[VX] /= 2;
pos[VY] /= 2;

MPE_RegisterUnclosedSectorNear(cur->after, pos[VX], pos[VY]);
}
}
else if(!cur->after && next->before)
{
if(!next->selfRef)
{
double pos[2];

pos[VX] = cur->vertex->buildData.pos[VX] + next->vertex->buildData.pos[VX];
pos[VY] = cur->vertex->buildData.pos[VY] + next->vertex->buildData.pos[VY];
pos[VX] /= 2;
pos[VY] /= 2;

MPE_RegisterUnclosedSectorNear(next->before, pos[VX], pos[VY]);
}
}
else
{
// This is definitetly open space.
bsp_hedge_t* right, *left;

// Do a sanity check on the sectors (just for good measure).
if(cur->after != next->before)
{
if(!cur->selfRef && !next->selfRef)
{
VERBOSE(
Con_Message("Sector mismatch: #%d (%1.1f,%1.1f) != #%d (%1.1f,%1.1f)\n",
cur->after->buildData.index, cur->vertex->buildData.pos[VX],
cur->vertex->buildData.pos[VY], next->before->buildData.index,
next->vertex->buildData.pos[VX], next->vertex->buildData.pos[VY]));
}

// Choose the non-self-referencing sector when we can.
if(cur->selfRef && !next->selfRef)
{
cur->after = next->before;
}
}

addHEdgesBetweenIntercepts(hplane, cur, next, &right, &left);

// Add the new half-edges to the appropriate lists.
rightList->hedgePush(right);
leftList->hedgePush(left);
}
}

node++;
}
}

HPlaneIntercept* HPlane::newIntercept(double distance, void* userData)
{
Intercepts::const_reverse_iterator after;
Expand Down

0 comments on commit e2681cc

Please sign in to comment.