From 189f70ca306ef7bd945a1db6caa703b00a26a738 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 8 Aug 2022 22:43:10 -0400 Subject: [PATCH] add in-place versions of union and expand to help with inlining --- include/common/aabb.hh | 30 ++++++++++++++++++++++++++---- qbsp/brush.cc | 2 +- qbsp/brushbsp.cc | 7 ++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/include/common/aabb.hh b/include/common/aabb.hh index c5f2b5dd..99076b6a 100644 --- a/include/common/aabb.hh +++ b/include/common/aabb.hh @@ -149,12 +149,34 @@ public: constexpr aabb operator+(const aabb &other) const { return unionWith(other); } - constexpr aabb &operator+=(const value_type &pt) { return (*this = expand(pt)); } - - constexpr aabb &operator+=(const aabb &other) { return (*this = unionWith(other)); } - constexpr aabb unionWith(const aabb &other) const { return expand(other.mins()).expand(other.maxs()); } + // in-place expansions + + constexpr aabb &expand_in_place(const value_type &pt) + { + for (size_t i = 0; i < N; i++) { + m_corners[0][i] = min(m_corners[0][i], pt[i]); + m_corners[1][i] = max(m_corners[1][i], pt[i]); + } + + return *this; + } + + constexpr aabb &operator+=(const value_type &pt) { return expand_in_place(pt); } + + constexpr aabb &operator+=(const aabb &other) { return unionWith_in_place(other); } + + constexpr aabb &unionWith_in_place(const aabb &other) + { + for (size_t i = 0; i < N; i++) { + m_corners[0][i] = min({ m_corners[0][i], other.mins()[i], other.maxs()[i] }); + m_corners[1][i] = max({ m_corners[1][i], other.mins()[i], other.maxs()[i] }); + } + + return *this; + } + constexpr intersection_t intersectWith(const aabb &other) const { auto corners = m_corners; diff --git a/qbsp/brush.cc b/qbsp/brush.cc index ce7d2858..3bc46f70 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -584,7 +584,7 @@ bool bspbrush_t::update_bounds(bool warn_on_failures) for (const auto &face : sides) { if (face.w) { - this->bounds = this->bounds.unionWith(face.w.bounds()); + this->bounds.unionWith_in_place(face.w.bounds()); } } diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index 3785f2d2..5bfd856f 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -68,6 +68,8 @@ struct bspstats_t std::atomic c_brushesremoved; // number of brushes half-removed from a split std::atomic c_brushesonesided; + // tiny volumes after clipping + std::atomic c_tinyvolumes; }; /* @@ -591,7 +593,7 @@ static twosided> SplitBrush(std::unique_ptr BrushBSP_internal(mapentity_t *entity, std::vecto if (stats.c_brushesonesided) { logging::print(logging::flag::STAT, " {:8} brushes split only on one side\n", stats.c_brushesonesided); } + if (stats.c_tinyvolumes) { + logging::print(logging::flag::STAT, " {:8} tiny volumes removed after splits\n", stats.c_tinyvolumes); + } logging::header("CountLeafs"); qbsp_options.target_game->print_content_stats(*stats.leafstats, "leafs");