From 781a772d8a63db11ea0a202327cd356e363dc232 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 14 Aug 2022 07:33:41 -0400 Subject: [PATCH] move immediately instead of splicing after construction (probably compiles to the same code but whatever) don't add all of the `result_portals_onnode` one at a time; just directly copy-elision the result. --- include/qbsp/map.hh | 1 + qbsp/brush.cc | 32 +++++++++++--------------------- qbsp/map.cc | 11 +++++++++++ qbsp/portals.cc | 10 +++------- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index f3a22917..48d6c0b9 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -91,6 +91,7 @@ public: contentflags_t contents {}; int16_t lmshift = 0; /* lightmap scaling (qu/lightmap pixel), passed to the light util */ mapentity_t *func_areaportal = nullptr; + bool is_hint = false; // whether we are a hint brush or not (at least one side is "hint" or SURF_HINT) }; struct lumpdata diff --git a/qbsp/brush.cc b/qbsp/brush.cc index ee5c4f1a..79a1bb01 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -231,26 +231,6 @@ qvec3d FixRotateOrigin(mapentity_t *entity) return offset; } -static bool MapBrush_IsHint(const mapbrush_t &brush) -{ - for (auto &f : brush.faces) { - if (f.flags.is_hint) - return true; - } - - return false; -} - -#if 0 - if (hullnum <= 0 && Brush_IsHint(*hullbrush)) { - /* Don't generate hintskip faces */ - const maptexinfo_t &texinfo = map.mtexinfos.at(mapface.texinfo); - - if (qbsp_options.target_game->texinfo_is_hintskip(texinfo.flags, map.miptexTextureName(texinfo.miptex))) - continue; - } -#endif - //============================================================================ /* @@ -315,6 +295,16 @@ std::optional LoadBrush(const mapentity_t *src, mapbrush_t *mapbrush for (size_t i = 0; i < mapbrush->faces.size(); i++) { auto &src = mapbrush->faces[i]; + if (hullnum <= 0 && mapbrush->is_hint) { + /* Don't generate hintskip faces */ + const maptexinfo_t &texinfo = map.mtexinfos.at(src.texinfo); + + // any face that isn't a hint is assumed to be hintskip + if (!texinfo.flags.is_hint) { + continue; + } + } + // don't add bevels for the point hull if (hullnum <= 0 && src.bevel) { continue; @@ -511,7 +501,7 @@ static void Brush_LoadEntity(mapentity_t *dst, mapentity_t *src, const int hulln } /* "hint" brushes don't affect the collision hulls */ - if (MapBrush_IsHint(mapbrush)) { + if (mapbrush.is_hint) { if (hullnum > 0) continue; contents = qbsp_options.target_game->create_empty_contents(); diff --git a/qbsp/map.cc b/qbsp/map.cc index 5a5fc84b..78104f41 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -2251,6 +2251,16 @@ inline void CalculateBrushBounds(mapbrush_t &ob) } } +inline bool MapBrush_IsHint(const mapbrush_t &brush) +{ + for (auto &f : brush.faces) { + if (f.flags.is_hint) + return true; + } + + return false; +} + void ProcessMapBrushes() { logging::funcheader(); @@ -2295,6 +2305,7 @@ void ProcessMapBrushes() // set properties calculated above brush.lmshift = lmshift; brush.func_areaportal = areaportal; + brush.is_hint = MapBrush_IsHint(brush); // calculate brush bounds CalculateBrushBounds(brush); diff --git a/qbsp/portals.cc b/qbsp/portals.cc index b0f585d2..a3720dc8 100644 --- a/qbsp/portals.cc +++ b/qbsp/portals.cc @@ -448,8 +448,7 @@ static std::list ClipNodePortalsToTree_r(node_t *node, portaltype auto front_fragments = ClipNodePortalsToTree_r(node->children[0], type, std::move(boundary_portals_split.front), stats); auto back_fragments = ClipNodePortalsToTree_r(node->children[1], type, std::move(boundary_portals_split.back), stats); - std::list merged_result; - merged_result.splice(merged_result.end(), front_fragments); + std::list merged_result = std::move(front_fragments); merged_result.splice(merged_result.end(), back_fragments); return merged_result; } @@ -496,14 +495,11 @@ std::list MakeTreePortals_r(tree_t *tree, node_t *node, portaltyp std::list half_clipped = ClipNodePortalsToTree_r(node->children[0], type, make_list(std::move(*nodeportal)), stats); - for (auto &clipped_p : ClipNodePortalsToTree_r(node->children[1], type, std::move(half_clipped), stats)) { - result_portals_onnode.push_back(std::move(clipped_p)); - } + result_portals_onnode = ClipNodePortalsToTree_r(node->children[1], type, std::move(half_clipped), stats); } // all done, merge together the lists and return - std::list merged_result; - merged_result.splice(merged_result.end(), result_portals_front); + std::list merged_result = std::move(result_portals_front); merged_result.splice(merged_result.end(), result_portals_back); merged_result.splice(merged_result.end(), result_portals_onnode); return merged_result;