From b7fbb4876344dcaafae8d79a473da44c788ea775 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 10 Apr 2022 00:00:28 -0600 Subject: [PATCH] qbsp: enable new outside filling --- include/qbsp/qbsp.hh | 2 +- qbsp/outside.cc | 32 ++++++-------------------------- qbsp/solidbsp.cc | 24 ++++++++++++++++++++++++ qbsp/surfaces.cc | 8 +++----- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 11513205..bd860af2 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -328,7 +328,7 @@ struct face_t : face_fragment_t // fixme-brushbsp: move to a brush_side_t struct bool onnode; // has this face been used as a BSP node plane yet? - bool visible; // can any part of this side be seen from non-void parts of the level? + bool visible = true; // can any part of this side be seen from non-void parts of the level? // non-visible means we can discard the brush side // (avoiding generating a BSP spit, so expanding it outwards) }; diff --git a/qbsp/outside.cc b/qbsp/outside.cc index fb3c4bbf..3b35f9e7 100644 --- a/qbsp/outside.cc +++ b/qbsp/outside.cc @@ -325,17 +325,11 @@ std::vector FindOccupiedClusters(node_t *headnode) //============================================================================= -static void AssertBrushSidesInvisible(node_t *node) +static void MarkBrushSidesInvisible(mapentity_t *entity) { - if (node->planenum != PLANENUM_LEAF) { - AssertBrushSidesInvisible(node->children[0]); - AssertBrushSidesInvisible(node->children[1]); - return; - } - - for (auto *brush : node->original_brushes) { - for (const auto &face : brush->faces) { - Q_assert(!face.visible); + for (auto &brush : entity->brushes) { + for (auto &face : brush.faces) { + face.visible = false; } } } @@ -507,25 +501,11 @@ bool FillOutside(mapentity_t *entity, node_t *node, const int hullnum) const int outleafs = OutLeafsToSolid(node); // See missing_face_simple.map for a test case with a brush that straddles between void and non-void - AssertBrushSidesInvisible(node); + + MarkBrushSidesInvisible(entity); MarkVisibleBrushSides(node); - // Count brush sides - int visible_brush_sides = 0; - int invisible_brush_sides = 0; - for (const auto &brush : entity->brushes) { - for (auto &side : brush.faces) { - if (side.visible) { - ++visible_brush_sides; - } else { - ++invisible_brush_sides; - } - } - } - logging::print(logging::flag::STAT, " {:8} outleafs\n", outleafs); - logging::print(logging::flag::STAT, " {:8} visible brush sides\n", visible_brush_sides); - logging::print(logging::flag::STAT, " {:8} invisible brush sides\n", invisible_brush_sides); return true; } diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index dd7f085c..dfff6a29 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -287,6 +287,10 @@ static face_t *ChooseMidPlaneFromList(std::vector &brushes, const aabb3 for (auto &face : brush.faces) { if (face.onnode) continue; + if (!face.visible) { + // never use as a bsp splitter, efffectively filling the brush outwards + continue; + } const qbsp_plane_t &plane = map.planes[face.planenum]; bool axial = false; @@ -350,6 +354,10 @@ static face_t *ChoosePlaneFromList(std::vector &brushes, const aabb3d & if (face.onnode) { continue; } + if (!face.visible) { + // never use as a bsp splitter, efffectively filling the brush outwards + continue; + } const bool hintsplit = map.mtexinfos.at(face.texinfo).flags.is_hint; @@ -915,6 +923,22 @@ node_t *SolidBSP(mapentity_t *entity, bool midsplit) logging::print(logging::flag::PROGRESS, "---- {} ----\n", __func__); + // Count visible/nonvisible brush sides (this is the side effect of FillOutside) + int visible_brush_sides = 0; + int invisible_brush_sides = 0; + for (const auto &brush : entity->brushes) { + for (auto &side : brush.faces) { + if (side.visible) { + ++visible_brush_sides; + } else { + ++invisible_brush_sides; + } + } + } + + logging::print(logging::flag::STAT, " {:8} visible brush sides\n", visible_brush_sides); + logging::print(logging::flag::STAT, " {:8} invisible brush sides\n", invisible_brush_sides); + node_t *headnode = new node_t{}; usemidsplit = midsplit; diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index 562a827f..b9bd0b52 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -526,11 +526,9 @@ void MakeMarkFaces(mapentity_t* entity, node_t* node) static void AddFaceToTree_r(mapentity_t* entity, face_t *face, brush_t *srcbrush, node_t* node) { if (node->planenum == PLANENUM_LEAF) { - if (!face->w.size()) { - // spurious - return; - } - FError("couldn't find node for face"); + //FError("couldn't find node for face"); + // after outside filling, this is completely expected + return; } if (face->planenum == node->planenum) {