qbsp: merge original brush lists when merging leafs in PruneNodes

This commit is contained in:
Eric Wasylishen 2022-05-21 16:05:22 -06:00
parent 70706b4923
commit 25b390aafe
3 changed files with 53 additions and 1 deletions

View File

@ -30,7 +30,8 @@ add_library(common STATIC
${CMAKE_SOURCE_DIR}/include/common/threads.hh
${CMAKE_SOURCE_DIR}/include/common/fs.hh
${CMAKE_SOURCE_DIR}/include/common/imglib.hh
${CMAKE_SOURCE_DIR}/include/common/settings.hh)
${CMAKE_SOURCE_DIR}/include/common/settings.hh
${CMAKE_SOURCE_DIR}/include/common/vectorutils.hh)
target_link_libraries(common ${CMAKE_THREAD_LIBS_INIT} TBB::tbb fmt::fmt nlohmann_json::nlohmann_json)

View File

@ -0,0 +1,44 @@
/* Copyright (C) 2022 Eric Wasylishen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
See file, 'COPYING', for details.
*/
#pragma once
#include <algorithm>
#include <iterator>
#include <vector>
template <class T>
void sort_and_remove_duplicates(T& v)
{
std::sort(v.begin(), v.end());
auto last = std::unique(v.begin(), v.end());
v.erase(last, v.end());
}
template <class E>
std::vector<E> concat(const std::vector<E> &a, const std::vector<E> &b)
{
std::vector<E> result;
result.reserve(a.size() + b.size());
std::copy(a.begin(), a.end(), std::back_inserter(result));
std::copy(b.begin(), b.end(), std::back_inserter(result));
return result;
}

View File

@ -21,6 +21,7 @@
#include <climits>
#include <common/vectorutils.hh>
#include <qbsp/brush.hh>
#include <qbsp/csg4.hh>
#include <qbsp/map.hh>
@ -48,6 +49,12 @@ static int mapbrushes;
void ConvertNodeToLeaf(node_t *node, const contentflags_t &contents)
{
// merge the children's brush lists
node->original_brushes = concat(
node->children[0]->original_brushes,
node->children[1]->original_brushes);
sort_and_remove_duplicates(node->original_brushes);
node->planenum = PLANENUM_LEAF;
for (int i = 0; i < 2; ++i) {