diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index c6c2030c..915adc98 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -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); + } } } diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index d4457d35..51190a3f 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -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]); } /*