From dfd31d7441d7f7174d590b36fb05e423fe035f44 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 25 Jan 2022 00:13:12 -0500 Subject: [PATCH] make markfaces a vector to simplify usage --- include/qbsp/qbsp.hh | 2 +- qbsp/exportobj.cc | 4 +--- qbsp/outside.cc | 12 ++++++------ qbsp/solidbsp.cc | 16 ++++------------ qbsp/surfaces.cc | 4 ---- qbsp/writebsp.cc | 4 +--- 6 files changed, 13 insertions(+), 29 deletions(-) diff --git a/include/qbsp/qbsp.hh b/include/qbsp/qbsp.hh index 6bfacb3b..2234fd5b 100644 --- a/include/qbsp/qbsp.hh +++ b/include/qbsp/qbsp.hh @@ -287,7 +287,7 @@ struct node_t // information for leafs contentflags_t contents; // leaf nodes (0 for decision nodes) - face_t **markfaces; // leaf nodes only, point to node faces + std::vector markfaces; // leaf nodes only, point to node faces portal_t *portals; int visleafnum; // -1 = solid int viscluster; // detail cluster for faster vis diff --git a/qbsp/exportobj.cc b/qbsp/exportobj.cc index 2f402ac3..9a4f9342 100644 --- a/qbsp/exportobj.cc +++ b/qbsp/exportobj.cc @@ -170,9 +170,7 @@ static void ExportObj_Marksurfaces_r(const node_t *node, std::unordered_setmarkfaces; *markface; markface++) { - face_t *face = *markface; - + for (auto &face : node->markfaces) { if (map.mtexinfos.at(face->texinfo).flags.is_skip) continue; diff --git a/qbsp/outside.cc b/qbsp/outside.cc index b17d6670..9c35bbf1 100644 --- a/qbsp/outside.cc +++ b/qbsp/outside.cc @@ -351,8 +351,8 @@ static void MarkFacesTouchingOccupiedLeafs(node_t *node) if (node->outside_distance == -1) { // This is an occupied leaf, so we need to keep all of the faces touching it. - for (face_t **markface = node->markfaces; *markface; markface++) { - (*markface)->touchesOccupiedLeaf = true; + for (auto &markface : node->markfaces) { + markface->touchesOccupiedLeaf = true; } } } @@ -377,9 +377,9 @@ static void ClearOutFaces(node_t *node) return; } - for (face_t **markface = node->markfaces; *markface; markface++) { + for (auto &markface : node->markfaces) { // NOTE: This is how faces are deleted here, kind of ugly - (*markface)->w.clear(); + markface->w.clear(); } // FIXME: Shouldn't be needed here @@ -405,8 +405,8 @@ static void OutLeafsToSolid_r(node_t *node, int *outleafs_count) // Now check all faces touching the leaf. If any of them are partially going into the occupied part of the map, // don't fill the leaf (see comment in FillOutside). bool skipFill = false; - for (face_t **markface = node->markfaces; *markface; markface++) { - if ((*markface)->touchesOccupiedLeaf) { + for (auto &markface : node->markfaces) { + if (markface->touchesOccupiedLeaf) { skipFill = true; break; } diff --git a/qbsp/solidbsp.cc b/qbsp/solidbsp.cc index 9a73a465..7527984d 100644 --- a/qbsp/solidbsp.cc +++ b/qbsp/solidbsp.cc @@ -56,9 +56,8 @@ void ConvertNodeToLeaf(node_t *node, const contentflags_t &contents) node->planenum = PLANENUM_LEAF; node->contents = contents; - node->markfaces = new face_t *[1] {}; - Q_assert(node->markfaces[0] == nullptr); + Q_assert(node->markfaces.empty()); } void DetailToSolid(node_t *node) @@ -338,7 +337,7 @@ static std::list::iterator ChooseMidPlaneFromList(std::list::iterator ChoosePlaneFromList(std::list &surfaces, const aabb3d &bounds) @@ -673,21 +672,16 @@ static void LinkConvexFaces(std::list &planelist, node_t *leafnode) // write the list of the original faces to the leaf's markfaces // free surf and the surf->faces list. leaffaces += count; - leafnode->markfaces = new face_t *[count + 1] {}; - - int i = 0; + leafnode->markfaces.reserve(count); for (auto &surf : planelist) { for (face_t *f = surf.faces; f; ) { face_t *next = f->next; - leafnode->markfaces[i] = f->original; - i++; + leafnode->markfaces.push_back(f->original); delete f; f = next; } } - - leafnode->markfaces[i] = NULL; // sentinal } /* @@ -811,11 +805,9 @@ node_t *SolidBSP(const mapentity_t *entity, std::list &surfhead, bool headnode->children[0] = new node_t{}; headnode->children[0]->planenum = PLANENUM_LEAF; headnode->children[0]->contents = options.target_game->create_empty_contents(); - headnode->children[0]->markfaces = new face_t *[1] {}; headnode->children[1] = new node_t{}; headnode->children[1]->planenum = PLANENUM_LEAF; headnode->children[1]->contents = options.target_game->create_empty_contents(); - headnode->children[1]->markfaces = new face_t *[1] {}; return headnode; } diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index 53ba2479..772797b9 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -131,10 +131,6 @@ static void FreeNode(node_t* node) } node->faces = nullptr; } - if (node->markfaces) { - delete[] node->markfaces; - node->markfaces = nullptr; - } delete node; } diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index 450ee221..7232f309 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -184,9 +184,7 @@ static void ExportLeaf(mapentity_t *entity, node_t *node) // write the marksurfaces dleaf.firstmarksurface = static_cast(map.bsp.dleaffaces.size()); - for (face_t **markfaces = node->markfaces; *markfaces; markfaces++) { - face_t *face = *markfaces; - + for (auto &face : node->markfaces) { if (!options.includeSkip && map.mtexinfos.at(face->texinfo).flags.is_skip) continue; // FIXME: this can happen when compiling some Q2 maps