make markfaces a vector to simplify usage

This commit is contained in:
Jonathan 2022-01-25 00:13:12 -05:00
parent 6dadb1d8f6
commit dfd31d7441
6 changed files with 13 additions and 29 deletions

View File

@ -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<face_t *> markfaces; // leaf nodes only, point to node faces
portal_t *portals;
int visleafnum; // -1 = solid
int viscluster; // detail cluster for faster vis

View File

@ -170,9 +170,7 @@ static void ExportObj_Marksurfaces_r(const node_t *node, std::unordered_set<cons
return;
}
for (face_t **markface = node->markfaces; *markface; markface++) {
face_t *face = *markface;
for (auto &face : node->markfaces) {
if (map.mtexinfos.at(face->texinfo).flags.is_skip)
continue;

View File

@ -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;
}

View File

@ -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<surface_t>::iterator ChooseMidPlaneFromList(std::list<surface_t
==================
ChoosePlaneFromList
The real BSP hueristic
The real BSP heuristic
==================
*/
static std::list<surface_t>::iterator ChoosePlaneFromList(std::list<surface_t> &surfaces, const aabb3d &bounds)
@ -673,21 +672,16 @@ static void LinkConvexFaces(std::list<surface_t> &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<surface_t> &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;
}

View File

@ -131,10 +131,6 @@ static void FreeNode(node_t* node)
}
node->faces = nullptr;
}
if (node->markfaces) {
delete[] node->markfaces;
node->markfaces = nullptr;
}
delete node;
}

View File

@ -184,9 +184,7 @@ static void ExportLeaf(mapentity_t *entity, node_t *node)
// write the marksurfaces
dleaf.firstmarksurface = static_cast<int>(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