qbsp: misc naming and comment cleanups for CutNodePortals_r

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-02-22 21:06:23 +10:30
parent a86e38e5b1
commit 8134601ef3
1 changed files with 52 additions and 49 deletions

View File

@ -426,108 +426,111 @@ CutNodePortals_r
static void static void
CutNodePortals_r(node_t *node) CutNodePortals_r(node_t *node)
{ {
plane_t *plane, clipplane; const plane_t *plane;
node_t *f, *b, *other_node; plane_t clipplane;
portal_t *p, *new_portal, *next_portal; node_t *front, *back, *other_node;
winding_t *w, *frontwinding, *backwinding; portal_t *portal, *new_portal, *next_portal;
winding_t *winding, *frontwinding, *backwinding;
int side; int side;
#ifdef PARANOID #ifdef PARANOID
CheckLeafPortalConsistancy (node); CheckLeafPortalConsistancy(node);
#endif #endif
// separate the portals on node into it's children /* If a leaf, no more dividing */
if (node->contents) if (node->contents)
return; // at a leaf, no more dividing return;
plane = &map.planes[node->planenum]; plane = &map.planes[node->planenum];
front = node->children[0];
back = node->children[1];
f = node->children[0]; /*
b = node->children[1]; * create the new portal by taking the full plane winding for the cutting
* plane and clipping it by all of the planes from the other portals
// create the new portal by taking the full plane winding for the cutting plane */
// and clipping it by all of the planes from the other portals
new_portal = AllocMem(PORTAL, 1, true); new_portal = AllocMem(PORTAL, 1, true);
new_portal->planenum = node->planenum; new_portal->planenum = node->planenum;
w = BaseWindingForPlane(&map.planes[node->planenum]); winding = BaseWindingForPlane(plane);
side = 0; // shut up compiler warning for (portal = node->portals; portal; portal = portal->next[side]) {
for (p = node->portals; p; p = p->next[side]) { clipplane = map.planes[portal->planenum];
clipplane = map.planes[p->planenum]; if (portal->nodes[0] == node)
if (p->nodes[0] == node)
side = 0; side = 0;
else if (p->nodes[1] == node) { else if (portal->nodes[1] == node) {
clipplane.dist = -clipplane.dist; clipplane.dist = -clipplane.dist;
VectorSubtract(vec3_origin, clipplane.normal, clipplane.normal); VectorSubtract(vec3_origin, clipplane.normal, clipplane.normal);
side = 1; side = 1;
} else } else
Error(errMislinkedPortal); Error(errMislinkedPortal);
w = ClipWinding(w, &clipplane, true); winding = ClipWinding(winding, &clipplane, true);
if (!w) { if (!winding) {
Message(msgWarning, warnPortalClippedAway); Message(msgWarning, warnPortalClippedAway);
break; break;
} }
} }
if (w) { /* If the plane was not clipped on all sides, there was an error */
// if the plane was not clipped on all sides, there was an error if (winding) {
new_portal->winding = w; new_portal->winding = winding;
AddPortalToNodes(new_portal, f, b); AddPortalToNodes(new_portal, front, back);
} }
// partition the portals
for (p = node->portals; p; p = next_portal) { /* partition the portals */
if (p->nodes[0] == node) for (portal = node->portals; portal; portal = next_portal) {
if (portal->nodes[0] == node)
side = 0; side = 0;
else if (p->nodes[1] == node) else if (portal->nodes[1] == node)
side = 1; side = 1;
else else
Error(errMislinkedPortal); Error(errMislinkedPortal);
next_portal = p->next[side]; next_portal = portal->next[side];
other_node = p->nodes[!side]; other_node = portal->nodes[!side];
RemovePortalFromNode(p, p->nodes[0]); RemovePortalFromNode(portal, portal->nodes[0]);
RemovePortalFromNode(p, p->nodes[1]); RemovePortalFromNode(portal, portal->nodes[1]);
// cut the portal into two portals, one on each side of the cut plane /* cut the portal into two portals, one on each side of the cut plane */
DivideWinding(p->winding, plane, &frontwinding, &backwinding); DivideWinding(portal->winding, plane, &frontwinding, &backwinding);
if (!frontwinding) { if (!frontwinding) {
if (side == 0) if (side == 0)
AddPortalToNodes(p, b, other_node); AddPortalToNodes(portal, back, other_node);
else else
AddPortalToNodes(p, other_node, b); AddPortalToNodes(portal, other_node, back);
continue; continue;
} }
if (!backwinding) { if (!backwinding) {
if (side == 0) if (side == 0)
AddPortalToNodes(p, f, other_node); AddPortalToNodes(portal, front, other_node);
else else
AddPortalToNodes(p, other_node, f); AddPortalToNodes(portal, other_node, front);
continue; continue;
} }
// the winding is split
/* the winding is split */
new_portal = AllocMem(PORTAL, 1, true); new_portal = AllocMem(PORTAL, 1, true);
*new_portal = *p; *new_portal = *portal;
new_portal->winding = backwinding; new_portal->winding = backwinding;
FreeMem(p->winding, WINDING, 1); FreeMem(portal->winding, WINDING, 1);
p->winding = frontwinding; portal->winding = frontwinding;
if (side == 0) { if (side == 0) {
AddPortalToNodes(p, f, other_node); AddPortalToNodes(portal, front, other_node);
AddPortalToNodes(new_portal, b, other_node); AddPortalToNodes(new_portal, back, other_node);
} else { } else {
AddPortalToNodes(p, other_node, f); AddPortalToNodes(portal, other_node, front);
AddPortalToNodes(new_portal, other_node, b); AddPortalToNodes(new_portal, other_node, back);
} }
} }
// Display progress /* Display progress */
iNodesDone++; iNodesDone++;
Message(msgPercent, iNodesDone, splitnodes); Message(msgPercent, iNodesDone, splitnodes);
CutNodePortals_r(f); CutNodePortals_r(front);
CutNodePortals_r(b); CutNodePortals_r(back);
} }