From 0db1e0fc0127d849b6a46d59e3b8b387acb31652 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 11 Aug 2022 00:27:28 -0400 Subject: [PATCH] add chop control to settings only chop if desired or if hull is -1 or > 0 since those can be chopped without affecting visuals farewell, shared_lock fix brush contents issue --- include/qbsp/qbsp.hh | 1 + qbsp/brushbsp.cc | 12 ++++++------ qbsp/map.cc | 5 ++--- qbsp/qbsp.cc | 9 ++++++++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 3a176209..f7336dff 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -266,6 +266,7 @@ public: setting_bool noclip{this, "noclip", false, &common_format_group, "don't write clip nodes (Q1-like BSP formats)"}; setting_bool noskip{this, "noskip", false, &debugging_group, "don't remove faces with the 'skip' texture"}; setting_bool nodetail{this, "nodetail", false, &debugging_group, "treat all detail brushes to structural"}; + setting_invertible_bool chop{this, "chop", false, &debugging_group, "adjust brushes to remove intersections if possible"}; setting_bool onlyents{this, "onlyents", false, &map_development_group, "only updates .MAP entities"}; setting_bool splitsky{this, "splitsky", false, &debugging_group, "doesn't combine sky faces into one large face"}; setting_bool splitturb{ diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index 18c19e03..4d767dd3 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -801,9 +801,9 @@ static std::optional SelectSplitPlane(const bspbrush_t::container &brush constexpr int numpasses = 4; for (int pass = 0; pass < numpasses; pass++) { for (auto &brush : brushes) { - if ((pass & 1) && !brush->mapbrush->contents.is_any_detail(qbsp_options.target_game)) + if ((pass & 1) && !brush->contents.is_any_detail(qbsp_options.target_game)) continue; - if (!(pass & 1) && brush->mapbrush->contents.is_any_detail(qbsp_options.target_game)) + if (!(pass & 1) && brush->contents.is_any_detail(qbsp_options.target_game)) continue; for (auto &side : brush->sides) { if (side.bevel) @@ -1165,11 +1165,11 @@ Returns true if b1 is allowed to bite b2 inline bool BrushGE(const bspbrush_t &b1, const bspbrush_t &b2) { // detail brushes never bite structural brushes - if ((b1.mapbrush->contents.is_any_detail(qbsp_options.target_game)) - && !(b2.mapbrush->contents.is_any_detail(qbsp_options.target_game))) { + if ((b1.contents.is_any_detail(qbsp_options.target_game)) + && !(b2.contents.is_any_detail(qbsp_options.target_game))) { return false; } - if (b1.mapbrush->contents.is_solid(qbsp_options.target_game)) { + if (b1.contents.is_any_solid(qbsp_options.target_game)) { return true; } return false; @@ -1370,5 +1370,5 @@ newlist: brushes.insert(brushes.begin(), std::make_move_iterator(list.begin()), std::make_move_iterator(list.end())); logging::print(logging::flag::STAT, "chopped {} brushes into {}\n", original_count, brushes.size()); - //WriteBspBrushMap("test.map", brushes); + //WriteBspBrushMap("chopped.map", brushes); } \ No newline at end of file diff --git a/qbsp/map.cc b/qbsp/map.cc index 4f881695..19d9c2e5 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -42,7 +42,6 @@ #include mapdata_t map; -std::shared_mutex map_planes_lock; const std::optional &mapdata_t::load_image_meta(const std::string_view &name) { @@ -2805,8 +2804,6 @@ from q3map */ void WriteBspBrushMap(const fs::path &name, const bspbrush_t::container &list) { - std::shared_lock lock(map_planes_lock); - logging::print("writing {}\n", name); std::ofstream f(name); @@ -2839,6 +2836,8 @@ void WriteBspBrushMap(const fs::path &name, const bspbrush_t::container &list) } fmt::print(f, "}}\n"); + + f.close(); } /* diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index e5e867d1..1ee471fa 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -272,6 +272,10 @@ void qbsp_settings::postinitialize(int argc, const char **argv) if (!software.value() && !subdivide.isChanged()) { subdivide.setValue(496, settings::source::GAME_TARGET); } + + if (!qbsp_options.chop.isChanged()) { + qbsp_options.chop.setValue(true, settings::source::GAME_TARGET); + } } // load texture defs @@ -456,7 +460,10 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) logging::print(logging::flag::STAT, "INFO: calculating BSP for {} brushes with {} sides\n", brushes.size(), num_sides); - ChopBrushes(brushes); + // always chop the other hulls + if (qbsp_options.chop.value() || hullnum != 0) { + ChopBrushes(brushes); + } // we're discarding the brush if (discarded_trigger) {