add in-place versions of union and expand to help with inlining

This commit is contained in:
Jonathan 2022-08-08 22:43:10 -04:00
parent 1c6b2e5a95
commit 189f70ca30
3 changed files with 33 additions and 6 deletions

View File

@ -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;

View File

@ -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());
}
}

View File

@ -68,6 +68,8 @@ struct bspstats_t
std::atomic<int> c_brushesremoved;
// number of brushes half-removed from a split
std::atomic<int> c_brushesonesided;
// tiny volumes after clipping
std::atomic<int> c_tinyvolumes;
};
/*
@ -591,7 +593,7 @@ static twosided<std::unique_ptr<bspbrush_t>> SplitBrush(std::unique_ptr<bspbrush
v1 = BrushVolume(*result[i]);
if (v1 < 1.0) {
result[i] = nullptr;
// qprintf ("tiny volume after clip\n");
stats.c_tinyvolumes++;
}
}
}
@ -1135,6 +1137,9 @@ static std::unique_ptr<tree_t> 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");