diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 53562edd..3f618436 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -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) diff --git a/include/common/vectorutils.hh b/include/common/vectorutils.hh new file mode 100644 index 00000000..88d97de2 --- /dev/null +++ b/include/common/vectorutils.hh @@ -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 +#include +#include + +template +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 +std::vector concat(const std::vector &a, const std::vector &b) +{ + std::vector 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; +} diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index eb88e75e..6f3fb55d 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -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) {