From 4567f9b4b915dd1bf0365acf4f17dcfcbf1c5b74 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 11 Sep 2022 23:56:29 -0600 Subject: [PATCH] qbsp: add -debugleak for saving more info about leaks --- include/qbsp/map.hh | 2 +- include/qbsp/qbsp.hh | 2 ++ qbsp/brushbsp.cc | 8 ++++++-- qbsp/map.cc | 5 ++++- qbsp/outside.cc | 26 ++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 834ecac3..8e3a1076 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -337,6 +337,6 @@ void ExportObj_Brushes(const std::string &filesuffix, const std::vector original_brushes; + bspbrush_t::container bsp_brushes; }; void InitQBSP(int argc, const char **argv); diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index bd595208..44f05337 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -354,7 +354,11 @@ static void LeafNode(node_t *leafnode, bspbrush_t::container brushes, bspstats_t qbsp_options.target_game->count_contents_in_stats(leafnode->contents, *stats.leafstats); - leafnode->volume.reset(); + if (qbsp_options.debugleak.value()) { + leafnode->bsp_brushes = brushes; + } else { + leafnode->volume.reset(); + } } //============================================================ @@ -1486,6 +1490,6 @@ newlist: logging::print(logging::flag::STAT, "chopped {} brushes into {}\n", original_count, brushes.size()); if (qbsp_options.debugchop.value()) { - WriteBspBrushMap("chopped.map", brushes); + WriteBspBrushMap("chopped", brushes); } } \ No newline at end of file diff --git a/qbsp/map.cc b/qbsp/map.cc index 0cb5c8b4..1ad2cb20 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -3334,8 +3334,11 @@ WriteBspBrushMap from q3map ================== */ -void WriteBspBrushMap(const fs::path &name, const bspbrush_t::container &list) +void WriteBspBrushMap(std::string_view filename_suffix, const bspbrush_t::container &list) { + fs::path name = qbsp_options.bsp_path; + name.replace_extension(std::string(filename_suffix) + ".map"); + logging::print("writing {}\n", name); std::ofstream f(name); diff --git a/qbsp/outside.cc b/qbsp/outside.cc index db180fb8..8d1dcdf8 100644 --- a/qbsp/outside.cc +++ b/qbsp/outside.cc @@ -284,6 +284,27 @@ static void WriteLeakLine(const mapentity_t &leakentity, const std::vector &leakline, std::string_view filename_suffix) +{ + std::set used_leafs; + std::vector volumes_to_write; + + for (portal_t *portal : leakline) { + for (node_t *node : portal->nodes) { + // make sure we only visit each leaf once + if (used_leafs.find(node) != used_leafs.end()) + continue; + + used_leafs.insert(node); + + // now output the leaf's volume as a brush + volumes_to_write.push_back(node->volume); + } + } + + WriteBspBrushMap(filename_suffix, volumes_to_write); +} + /* ================== FindOccupiedLeafs @@ -671,6 +692,11 @@ bool FillOutside(tree_t &tree, hull_index_t hullnum, bspbrush_t::container &brus // also write the leak portals to `.leak.prt` WriteDebugPortals(leakline, "leak"); + // also write the leafs used in the leak line to .leak-leaf-volumes.map` + if (qbsp_options.debugleak.value()) { + WriteLeafVolumes(leakline, "leak-leaf-volumes"); + } + /* Get rid of the .prt file since the map has a leak */ if (!qbsp_options.keepprt.value()) { fs::path name = qbsp_options.bsp_path;