qbsp: ExportDrawNodes: add assertion from DP that node children are different

DetailToSolid: collapse redundant nodes where both children are
solid (-1) to just be the leaf -1. Any faces on-node should be
impossible to see so they can be safely discarded.
This commit is contained in:
Eric Wasylishen 2017-06-09 11:50:34 -06:00
parent d01b740b5b
commit 7198884392
2 changed files with 44 additions and 0 deletions

View File

@ -32,6 +32,28 @@ static bool usemidsplit;
//============================================================================
void
ConvertNodeToLeaf(node_t *node, int contents)
{
// backup the mins/maxs
vec3_t mins, maxs;
VectorCopy(node->mins, mins);
VectorCopy(node->maxs, maxs);
// zero it
memset(node, 0, sizeof(*node));
// restore relevant fields
VectorCopy(mins, node->mins);
VectorCopy(maxs, node->maxs);
node->planenum = PLANENUM_LEAF;
node->contents = contents;
node->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
Q_assert(node->markfaces[0] == nullptr);
}
void
DetailToSolid(node_t *node)
{
@ -46,6 +68,15 @@ DetailToSolid(node_t *node)
} else {
DetailToSolid(node->children[0]);
DetailToSolid(node->children[1]);
// If both children are solid, we can merge the two leafs into one.
// DarkPlaces has an assertion that fails if both children are
// solid.
if (node->children[0]->contents == CONTENTS_SOLID
&& node->children[1]->contents == CONTENTS_SOLID) {
// This discards any faces on-node. Should be safe (?)
ConvertNodeToLeaf(node, CONTENTS_SOLID);
}
}
}

View File

@ -540,6 +540,13 @@ ExportDrawNodes_BSP29(mapentity_t *entity, node_t *node)
ExportDrawNodes_BSP29(entity, node->children[i]);
}
}
// DarkPlaces asserts that the leaf numbers are different
// if mod_bsp_portalize is 1 (default)
// The most likely way it could fail is if both sides are the
// shared CONTENTS_SOLID leaf (-1)
Q_assert(!(dnode->children[0] == -1 && dnode->children[1] == -1));
Q_assert(dnode->children[0] != dnode->children[1]);
}
static void
@ -579,6 +586,9 @@ ExportDrawNodes_BSP2(mapentity_t *entity, node_t *node)
ExportDrawNodes_BSP2(entity, node->children[i]);
}
}
Q_assert(!(dnode->children[0] == -1 && dnode->children[1] == -1));
Q_assert(dnode->children[0] != dnode->children[1]);
}
static void
@ -618,6 +628,9 @@ ExportDrawNodes_BSP2rmq(mapentity_t *entity, node_t *node)
ExportDrawNodes_BSP2rmq(entity, node->children[i]);
}
}
Q_assert(!(dnode->children[0] == -1 && dnode->children[1] == -1));
Q_assert(dnode->children[0] != dnode->children[1]);
}
/*