qbsp: move node_t markfaces list to a std::vector
This commit is contained in:
parent
0cba9c5138
commit
31df408333
|
|
@ -267,7 +267,8 @@ typedef struct surface_s {
|
|||
|
||||
// there is a node_t structure for every node and leaf in the bsp tree
|
||||
|
||||
typedef struct node_s {
|
||||
class node_t {
|
||||
public:
|
||||
vec3_t mins, maxs; // bounding volume, not just points inside
|
||||
|
||||
// information for decision nodes
|
||||
|
|
@ -275,19 +276,19 @@ typedef struct node_s {
|
|||
//outputplanenum moved to qbsp_plane_t
|
||||
int firstface; // decision node only
|
||||
int numfaces; // decision node only
|
||||
struct node_s *children[2]; // children[0] = front side, children[1] = back side of plane. only valid for decision nodes
|
||||
node_t *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)
|
||||
face_t **markfaces; // leaf nodes only, point to node faces
|
||||
std::vector<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.
|
||||
} node_t;
|
||||
bool detail_separator; // for vis portal generation. true if ALL faces on node, and on all descendant nodes/leafs, are detail.
|
||||
};
|
||||
|
||||
#include <qbsp/brush.hh>
|
||||
#include <qbsp/csg4.hh>
|
||||
|
|
|
|||
|
|
@ -229,11 +229,8 @@ static bool
|
|||
LineIntersect_Leafnode(const node_t *node,
|
||||
const vec3_t point1, const vec3_t point2)
|
||||
{
|
||||
face_t *const *markfaces;
|
||||
const face_t *face;
|
||||
|
||||
for (markfaces = node->markfaces; *markfaces; markfaces++) {
|
||||
for (face = *markfaces; face; face = face->original) {
|
||||
for (const face_t *markface : node->markfaces) {
|
||||
for (const face_t *face = markface; 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;
|
||||
|
|
@ -427,8 +424,6 @@ ClearOutFaces
|
|||
static void
|
||||
ClearOutFaces(node_t *node)
|
||||
{
|
||||
face_t **markfaces;
|
||||
|
||||
if (node->planenum != -1) {
|
||||
ClearOutFaces(node->children[0]);
|
||||
ClearOutFaces(node->children[1]);
|
||||
|
|
@ -437,9 +432,9 @@ ClearOutFaces(node_t *node)
|
|||
if (node->contents != CONTENTS_SOLID)
|
||||
return;
|
||||
|
||||
for (markfaces = node->markfaces; *markfaces; markfaces++) {
|
||||
for (face_t *markface : node->markfaces) {
|
||||
// mark all the original faces that are removed
|
||||
(*markfaces)->w.numpoints = 0;
|
||||
markface->w.numpoints = 0;
|
||||
}
|
||||
node->faces = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,9 +49,8 @@ ConvertNodeToLeaf(node_t *node, int contents)
|
|||
|
||||
node->planenum = PLANENUM_LEAF;
|
||||
node->contents = contents;
|
||||
node->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
|
||||
|
||||
Q_assert(node->markfaces[0] == nullptr);
|
||||
node->markfaces.clear();
|
||||
Q_assert(node->markfaces.empty());
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -790,7 +789,7 @@ LinkConvexFaces(surface_t *planelist, node_t *leafnode)
|
|||
{
|
||||
face_t *f, *next;
|
||||
surface_t *surf, *pnext;
|
||||
int i, count;
|
||||
int count;
|
||||
|
||||
leafnode->faces = NULL;
|
||||
leafnode->contents = 0;
|
||||
|
|
@ -852,20 +851,18 @@ LinkConvexFaces(surface_t *planelist, node_t *leafnode)
|
|||
|
||||
// write the list of faces, and free the originals
|
||||
leaffaces += count;
|
||||
leafnode->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *) * (count + 1), true);
|
||||
|
||||
Q_assert(leafnode->markfaces.empty());
|
||||
|
||||
i = 0;
|
||||
for (surf = planelist; surf; surf = pnext) {
|
||||
pnext = surf->next;
|
||||
for (f = surf->faces; f; f = next) {
|
||||
next = f->next;
|
||||
leafnode->markfaces[i] = f->original;
|
||||
i++;
|
||||
leafnode->markfaces.push_back(f->original);
|
||||
FreeMem(f, FACE, 1);
|
||||
}
|
||||
FreeMem(surf, SURFACE, 1);
|
||||
}
|
||||
leafnode->markfaces[i] = NULL; // sentinal
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -933,8 +930,8 @@ PartitionSurfaces(surface_t *surfaces, node_t *node)
|
|||
Message(msgPercent, splitnodes, csgmergefaces);
|
||||
|
||||
node->faces = LinkNodeFaces(split);
|
||||
node->children[0] = (node_t *)AllocMem(NODE, 1, true);
|
||||
node->children[1] = (node_t *)AllocMem(NODE, 1, true);
|
||||
node->children[0] = new node_t();
|
||||
node->children[1] = new node_t();
|
||||
node->planenum = split->planenum;
|
||||
node->detail_separator = split->detail_separator;
|
||||
|
||||
|
|
@ -993,26 +990,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 = (node_t *)AllocMem(NODE, 1, true);
|
||||
headnode = new node_t();
|
||||
for (i = 0; i < 3; i++) {
|
||||
headnode->mins[i] = entity->mins[i] - SIDESPACE;
|
||||
headnode->maxs[i] = entity->maxs[i] + SIDESPACE;
|
||||
}
|
||||
headnode->children[0] = (node_t *)AllocMem(NODE, 1, true);
|
||||
headnode->children[0] = new node_t();
|
||||
headnode->children[0]->planenum = PLANENUM_LEAF;
|
||||
headnode->children[0]->contents = CONTENTS_EMPTY;
|
||||
headnode->children[0]->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
|
||||
headnode->children[1] = (node_t *)AllocMem(NODE, 1, true);
|
||||
Q_assert(headnode->children[0]->markfaces.empty());
|
||||
headnode->children[1] = new node_t();
|
||||
headnode->children[1]->planenum = PLANENUM_LEAF;
|
||||
headnode->children[1]->contents = CONTENTS_EMPTY;
|
||||
headnode->children[1]->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
|
||||
Q_assert(headnode->children[1]->markfaces.empty());
|
||||
|
||||
return headnode;
|
||||
}
|
||||
|
||||
Message(msgProgress, "SolidBSP");
|
||||
|
||||
headnode = (node_t *)AllocMem(NODE, 1, true);
|
||||
headnode = new node_t();
|
||||
usemidsplit = midsplit;
|
||||
|
||||
// calculate a bounding box for the entire model
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
FreeMem(node, NODE, 1);
|
||||
delete node;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ ExportClipNodes_BSP29(mapentity_t *entity, node_t *node)
|
|||
// FIXME: free more stuff?
|
||||
if (node->planenum == -1) {
|
||||
int contents = node->contents;
|
||||
FreeMem(node, NODE, 1);
|
||||
delete node;
|
||||
return contents;
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ ExportClipNodes_BSP29(mapentity_t *entity, node_t *node)
|
|||
memset(face, 0, sizeof(face_t));
|
||||
FreeMem(face, FACE, 1);
|
||||
}
|
||||
FreeMem(node, NODE, 1);
|
||||
delete node;
|
||||
|
||||
return nodenum;
|
||||
}
|
||||
|
|
@ -180,7 +180,7 @@ ExportClipNodes_BSP2(mapentity_t *entity, node_t *node)
|
|||
// FIXME: free more stuff?
|
||||
if (node->planenum == -1) {
|
||||
int contents = node->contents;
|
||||
FreeMem(node, NODE, 1);
|
||||
delete node;
|
||||
return contents;
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ ExportClipNodes_BSP2(mapentity_t *entity, node_t *node)
|
|||
memset(face, 0, sizeof(face_t));
|
||||
FreeMem(face, FACE, 1);
|
||||
}
|
||||
FreeMem(node, NODE, 1);
|
||||
delete node;
|
||||
|
||||
return nodenum;
|
||||
}
|
||||
|
|
@ -287,13 +287,11 @@ CountLeaves
|
|||
static void
|
||||
CountLeaves(mapentity_t *entity, node_t *node)
|
||||
{
|
||||
face_t **markfaces, *face;
|
||||
|
||||
entity->lumps[LUMP_LEAFS].count++;
|
||||
for (markfaces = node->markfaces; *markfaces; markfaces++) {
|
||||
if (map.mtexinfos.at((*markfaces)->texinfo).flags & TEX_SKIP)
|
||||
for (face_t *markface : node->markfaces) {
|
||||
if (map.mtexinfos.at(markface->texinfo).flags & TEX_SKIP)
|
||||
continue;
|
||||
for (face = *markfaces; face; face = face->original)
|
||||
for (face_t *face = markface; face; face = face->original)
|
||||
entity->lumps[LUMP_MARKSURFACES].count++;
|
||||
}
|
||||
}
|
||||
|
|
@ -344,7 +342,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 **markfaces, *face;
|
||||
face_t *face;
|
||||
bsp29_dleaf_t *dleaf;
|
||||
|
||||
// ptr arithmetic to get correct leaf in memory
|
||||
|
|
@ -371,8 +369,8 @@ ExportLeaf_BSP29(mapentity_t *entity, node_t *node)
|
|||
// write the marksurfaces
|
||||
dleaf->firstmarksurface = map.cTotal[LUMP_MARKSURFACES];
|
||||
|
||||
for (markfaces = node->markfaces; *markfaces; markfaces++) {
|
||||
face = *markfaces;
|
||||
for (face_t *markface : node->markfaces) {
|
||||
face = markface;
|
||||
if (map.mtexinfos.at(face->texinfo).flags & TEX_SKIP)
|
||||
continue;
|
||||
|
||||
|
|
@ -394,7 +392,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 **markfaces, *face;
|
||||
face_t *face;
|
||||
bsp2_dleaf_t *dleaf;
|
||||
|
||||
// ptr arithmetic to get correct leaf in memory
|
||||
|
|
@ -421,8 +419,8 @@ ExportLeaf_BSP2(mapentity_t *entity, node_t *node)
|
|||
// write the marksurfaces
|
||||
dleaf->firstmarksurface = map.cTotal[LUMP_MARKSURFACES];
|
||||
|
||||
for (markfaces = node->markfaces; *markfaces; markfaces++) {
|
||||
face = *markfaces;
|
||||
for (face_t *markface : node->markfaces) {
|
||||
face = markface;
|
||||
if (map.mtexinfos.at(face->texinfo).flags & TEX_SKIP)
|
||||
continue;
|
||||
|
||||
|
|
@ -444,7 +442,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 **markfaces, *face;
|
||||
face_t *face;
|
||||
bsp2rmq_dleaf_t *dleaf;
|
||||
|
||||
// ptr arithmetic to get correct leaf in memory
|
||||
|
|
@ -471,8 +469,8 @@ ExportLeaf_BSP2rmq(mapentity_t *entity, node_t *node)
|
|||
// write the marksurfaces
|
||||
dleaf->firstmarksurface = map.cTotal[LUMP_MARKSURFACES];
|
||||
|
||||
for (markfaces = node->markfaces; *markfaces; markfaces++) {
|
||||
face = *markfaces;
|
||||
for (face_t *markface : node->markfaces) {
|
||||
face = markface;
|
||||
if (map.mtexinfos.at(face->texinfo).flags & TEX_SKIP)
|
||||
continue;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue