Revert "qbsp: move node_t markfaces list to a std::vector"

This reverts commit 31df408333.
This commit is contained in:
Eric Wasylishen 2017-07-05 18:10:56 -07:00
parent 89c035a95a
commit a4e3a3a887
5 changed files with 50 additions and 41 deletions

View File

@ -268,8 +268,7 @@ typedef struct surface_s {
// there is a node_t structure for every node and leaf in the bsp tree
class node_t {
public:
typedef struct node_s {
vec3_t mins, maxs; // bounding volume, not just points inside
// information for decision nodes
@ -277,19 +276,19 @@ public:
//outputplanenum moved to qbsp_plane_t
int firstface; // decision node only
int numfaces; // decision node only
node_t *children[2]; // children[0] = front side, children[1] = back side of plane. only valid for decision nodes
struct node_s *children[2]; // children[0] = front side, children[1] = back side of plane. only valid for decision nodes
face_t *faces; // decision nodes only, list for both sides
// information for leafs
int contents; // leaf nodes (0 for decision nodes)
std::vector<face_t *> markfaces; // leaf nodes only, point to node faces
face_t **markfaces; // leaf nodes only, point to node faces
struct portal_s *portals;
int visleafnum; // -1 = solid
int viscluster; // detail cluster for faster vis
int fillmark; // for flood filling
int occupied; // entity number in leaf for outside filling
bool detail_separator; // for vis portal generation. true if ALL faces on node, and on all descendant nodes/leafs, are detail.
};
bool detail_separator; // for vis portal generation. true if ALL faces on node, and on all descendant nodes/leafs, are detail.
} node_t;
#include <qbsp/brush.hh>
#include <qbsp/csg4.hh>

View File

@ -229,8 +229,11 @@ static bool
LineIntersect_Leafnode(const node_t *node,
const vec3_t point1, const vec3_t point2)
{
for (const face_t *markface : node->markfaces) {
for (const face_t *face = markface; face; face = face->original) {
face_t *const *markfaces;
const face_t *face;
for (markfaces = node->markfaces; *markfaces; markfaces++) {
for (face = *markfaces; face; face = face->original) {
const qbsp_plane_t *const plane = &map.planes[face->planenum];
const vec_t dist1 = DotProduct(point1, plane->normal) - plane->dist;
const vec_t dist2 = DotProduct(point2, plane->normal) - plane->dist;
@ -424,6 +427,8 @@ ClearOutFaces
static void
ClearOutFaces(node_t *node)
{
face_t **markfaces;
if (node->planenum != -1) {
ClearOutFaces(node->children[0]);
ClearOutFaces(node->children[1]);
@ -432,9 +437,9 @@ ClearOutFaces(node_t *node)
if (node->contents != CONTENTS_SOLID)
return;
for (face_t *markface : node->markfaces) {
for (markfaces = node->markfaces; *markfaces; markfaces++) {
// mark all the original faces that are removed
markface->w.numpoints = 0;
(*markfaces)->w.numpoints = 0;
}
node->faces = NULL;
}

View File

@ -49,8 +49,9 @@ ConvertNodeToLeaf(node_t *node, int contents)
node->planenum = PLANENUM_LEAF;
node->contents = contents;
node->markfaces.clear();
Q_assert(node->markfaces.empty());
node->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
Q_assert(node->markfaces[0] == nullptr);
}
void
@ -789,7 +790,7 @@ LinkConvexFaces(surface_t *planelist, node_t *leafnode)
{
face_t *f, *next;
surface_t *surf, *pnext;
int count;
int i, count;
leafnode->faces = NULL;
leafnode->contents = 0;
@ -852,18 +853,20 @@ LinkConvexFaces(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;
Q_assert(leafnode->markfaces.empty());
leafnode->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *) * (count + 1), true);
i = 0;
for (surf = planelist; surf; surf = pnext) {
pnext = surf->next;
for (f = surf->faces; f; f = next) {
next = f->next;
leafnode->markfaces.push_back(f->original);
leafnode->markfaces[i] = f->original;
i++;
FreeMem(f, FACE, 1);
}
FreeMem(surf, SURFACE, 1);
}
leafnode->markfaces[i] = NULL; // sentinal
}
@ -934,8 +937,8 @@ PartitionSurfaces(surface_t *surfaces, node_t *node)
Message(msgPercent, splitnodes, csgmergefaces);
node->faces = LinkNodeFaces(split);
node->children[0] = new node_t();
node->children[1] = new node_t();
node->children[0] = (node_t *)AllocMem(NODE, 1, true);
node->children[1] = (node_t *)AllocMem(NODE, 1, true);
node->planenum = split->planenum;
node->detail_separator = split->detail_separator;
@ -994,26 +997,26 @@ SolidBSP(const mapentity_t *entity, surface_t *surfhead, bool midsplit)
* collision hull for the engine. Probably could be done a little
* smarter, but this works.
*/
headnode = new node_t();
headnode = (node_t *)AllocMem(NODE, 1, true);
for (i = 0; i < 3; i++) {
headnode->mins[i] = entity->mins[i] - SIDESPACE;
headnode->maxs[i] = entity->maxs[i] + SIDESPACE;
}
headnode->children[0] = new node_t();
headnode->children[0] = (node_t *)AllocMem(NODE, 1, true);
headnode->children[0]->planenum = PLANENUM_LEAF;
headnode->children[0]->contents = CONTENTS_EMPTY;
Q_assert(headnode->children[0]->markfaces.empty());
headnode->children[1] = new node_t();
headnode->children[0]->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
headnode->children[1] = (node_t *)AllocMem(NODE, 1, true);
headnode->children[1]->planenum = PLANENUM_LEAF;
headnode->children[1]->contents = CONTENTS_EMPTY;
Q_assert(headnode->children[1]->markfaces.empty());
headnode->children[1]->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
return headnode;
}
Message(msgProgress, "SolidBSP");
headnode = new node_t();
headnode = (node_t *)AllocMem(NODE, 1, true);
usemidsplit = midsplit;
// calculate a bounding box for the entire model

View File

@ -145,7 +145,7 @@ GatherNodeFaces_r(node_t *node, std::map<int, face_t *> &planefaces)
GatherNodeFaces_r(node->children[0], planefaces);
GatherNodeFaces_r(node->children[1], planefaces);
}
delete node;
FreeMem(node, NODE, 1);
}
/*

View File

@ -205,7 +205,7 @@ ExportClipNodes_BSP29(mapentity_t *entity, node_t *node)
// FIXME: free more stuff?
if (node->planenum == -1) {
int contents = node->contents;
delete node;
FreeMem(node, NODE, 1);
return contents;
}
@ -224,7 +224,7 @@ ExportClipNodes_BSP29(mapentity_t *entity, node_t *node)
memset(face, 0, sizeof(face_t));
FreeMem(face, FACE, 1);
}
delete node;
FreeMem(node, NODE, 1);
return nodenum;
}
@ -240,7 +240,7 @@ ExportClipNodes_BSP2(mapentity_t *entity, node_t *node)
// FIXME: free more stuff?
if (node->planenum == -1) {
int contents = node->contents;
delete node;
FreeMem(node, NODE, 1);
return contents;
}
@ -259,7 +259,7 @@ ExportClipNodes_BSP2(mapentity_t *entity, node_t *node)
memset(face, 0, sizeof(face_t));
FreeMem(face, FACE, 1);
}
delete node;
FreeMem(node, NODE, 1);
return nodenum;
}
@ -347,11 +347,13 @@ CountLeaves
static void
CountLeaves(mapentity_t *entity, node_t *node)
{
face_t **markfaces, *face;
entity->lumps[LUMP_LEAFS].count++;
for (face_t *markface : node->markfaces) {
if (map.mtexinfos.at(markface->texinfo).flags & TEX_SKIP)
for (markfaces = node->markfaces; *markfaces; markfaces++) {
if (map.mtexinfos.at((*markfaces)->texinfo).flags & TEX_SKIP)
continue;
for (face_t *face = markface; face; face = face->original)
for (face = *markfaces; face; face = face->original)
entity->lumps[LUMP_MARKSURFACES].count++;
}
}
@ -402,7 +404,7 @@ ExportLeaf_BSP29(mapentity_t *entity, node_t *node)
struct lumpdata *leaves = &entity->lumps[LUMP_LEAFS];
struct lumpdata *marksurfs = &entity->lumps[LUMP_MARKSURFACES];
uint16_t *marksurfnums = (uint16_t *)marksurfs->data;
face_t *face;
face_t **markfaces, *face;
bsp29_dleaf_t *dleaf;
// ptr arithmetic to get correct leaf in memory
@ -429,8 +431,8 @@ ExportLeaf_BSP29(mapentity_t *entity, node_t *node)
// write the marksurfaces
dleaf->firstmarksurface = map.cTotal[LUMP_MARKSURFACES];
for (face_t *markface : node->markfaces) {
face = markface;
for (markfaces = node->markfaces; *markfaces; markfaces++) {
face = *markfaces;
if (map.mtexinfos.at(face->texinfo).flags & TEX_SKIP)
continue;
@ -452,7 +454,7 @@ ExportLeaf_BSP2(mapentity_t *entity, node_t *node)
struct lumpdata *leaves = &entity->lumps[LUMP_LEAFS];
struct lumpdata *marksurfs = &entity->lumps[LUMP_MARKSURFACES];
uint32_t *marksurfnums = (uint32_t *)marksurfs->data;
face_t *face;
face_t **markfaces, *face;
bsp2_dleaf_t *dleaf;
// ptr arithmetic to get correct leaf in memory
@ -479,8 +481,8 @@ ExportLeaf_BSP2(mapentity_t *entity, node_t *node)
// write the marksurfaces
dleaf->firstmarksurface = map.cTotal[LUMP_MARKSURFACES];
for (face_t *markface : node->markfaces) {
face = markface;
for (markfaces = node->markfaces; *markfaces; markfaces++) {
face = *markfaces;
if (map.mtexinfos.at(face->texinfo).flags & TEX_SKIP)
continue;
@ -502,7 +504,7 @@ ExportLeaf_BSP2rmq(mapentity_t *entity, node_t *node)
struct lumpdata *leaves = &entity->lumps[LUMP_LEAFS];
struct lumpdata *marksurfs = &entity->lumps[LUMP_MARKSURFACES];
uint32_t *marksurfnums = (uint32_t *)marksurfs->data;
face_t *face;
face_t **markfaces, *face;
bsp2rmq_dleaf_t *dleaf;
// ptr arithmetic to get correct leaf in memory
@ -529,8 +531,8 @@ ExportLeaf_BSP2rmq(mapentity_t *entity, node_t *node)
// write the marksurfaces
dleaf->firstmarksurface = map.cTotal[LUMP_MARKSURFACES];
for (face_t *markface : node->markfaces) {
face = markface;
for (markfaces = node->markfaces; *markfaces; markfaces++) {
face = *markfaces;
if (map.mtexinfos.at(face->texinfo).flags & TEX_SKIP)
continue;