diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index 78b81612..e68fe3a6 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -62,6 +62,12 @@ struct bspstats_t std::atomic c_midsplit; // total number of leafs std::atomic c_leafs; + // number of bogus brushes (beyond world extents) + std::atomic c_bogus; + // number of brushes entirely removed from a split + std::atomic c_brushesremoved; + // number of brushes half-removed from a split + std::atomic c_brushesonesided; }; /* @@ -455,7 +461,7 @@ input. https://github.com/id-Software/Quake-2-Tools/blob/master/bsp/qbsp3/brushbsp.c#L935 ================ */ -static twosided> SplitBrush(std::unique_ptr brush, const qplane3d &split) +static twosided> SplitBrush(std::unique_ptr brush, const qplane3d &split, bspstats_t &stats) { twosided> result; @@ -554,7 +560,7 @@ static twosided> SplitBrush(std::unique_ptrbounds.mins()[j] < -qbsp_options.worldextent.value() || result[i]->bounds.maxs()[j] > qbsp_options.worldextent.value()) { - logging::print("bogus brush after clip\n"); + stats.c_bogus++; bogus = true; break; } @@ -565,18 +571,17 @@ static twosided> SplitBrush(std::unique_ptrvolume->copy_unique(), plane); + auto [front, back] = SplitBrush(node->volume->copy_unique(), plane, stats); bool good = (front && back); @@ -711,7 +716,7 @@ ChooseMidPlaneFromList The clipping hull BSP doesn't worry about avoiding splits ================== */ -static std::optional ChooseMidPlaneFromList(const std::vector> &brushes, const node_t *node) +static std::optional ChooseMidPlaneFromList(const std::vector> &brushes, const node_t *node, bspstats_t &stats) { vec_t bestaxialmetric = VECT_MAX; std::optional bestaxialplane; @@ -730,7 +735,7 @@ static std::optional ChooseMidPlaneFromList(const std::vector SelectSplitPlane(const std::vector SelectSplitPlane(const std::vector>, 2> SplitBrushList( - std::vector> brushes, const qbsp_plane_t &plane) + std::vector> brushes, const qbsp_plane_t &plane, bspstats_t &stats) { std::array>, 2> result; @@ -985,7 +990,7 @@ static std::array>, 2> SplitBrushList( if (sides == PSIDE_BOTH) { // split into two brushes - auto [front, back] = SplitBrush(brush->copy_unique(), plane); + auto [front, back] = SplitBrush(brush->copy_unique(), plane, stats); if (front) { result[0].push_back(std::move(front)); @@ -1052,7 +1057,7 @@ static void BuildTree_r(node_t *node, std::vector> b auto &plane = map.get_plane(bestplane.value()); node->plane.set_plane(plane); - auto children = SplitBrushList(std::move(brushes), node->plane); + auto children = SplitBrushList(std::move(brushes), node->plane, stats); // allocate children before recursing for (int i = 0; i < 2; i++) { @@ -1069,7 +1074,7 @@ static void BuildTree_r(node_t *node, std::vector> b } } - auto children_volumes = SplitBrush(node->volume->copy_unique(), node->plane); + auto children_volumes = SplitBrush(node->volume->copy_unique(), node->plane, stats); node->children[0]->volume = std::move(children_volumes[0]); node->children[1]->volume = std::move(children_volumes[1]); @@ -1169,6 +1174,9 @@ static std::unique_ptr BrushBSP(mapentity_t *entity, std::vectorprint_content_stats(*stats.leafstats, "leafs"); return tree; diff --git a/qbsp/portals.cc b/qbsp/portals.cc index 25ffd280..f3da675d 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -838,13 +838,12 @@ static void FindPortalSide(portal_t *p) break; } // see how close the match is - // fixme-brushbsp: verify that this actually works, restore it - // const auto &p2 = side.plane; - // double dot = qv::dot(p1.normal, p2.normal); - // if (dot > bestdot) { - // bestdot = dot; - // bestside[j] = &side; - // } + const auto &p2 = side.get_positive_plane(); + double dot = qv::dot(p1.get_normal(), p2.get_normal()); + if (dot > bestdot) { + bestdot = dot; + bestside[j] = &side; + } } } }