qbsp: removing fancy AllocMem uses

This commit is contained in:
Eric Wasylishen 2021-08-24 22:40:35 -06:00
parent 208a9610ad
commit 1f7ac25f0c
6 changed files with 23 additions and 26 deletions

View File

@ -409,7 +409,8 @@ CreateBrushFaces(const mapentity_t *src, hullbrush_t *hullbrush,
continue; // overconstrained plane continue; // overconstrained plane
// this face is a keeper // this face is a keeper
f = (face_t *)AllocMem(FACE, 1, true); f = (face_t *)AllocMem(OTHER, sizeof(face_t), true);
f->planenum = -1;
f->w.numpoints = w->numpoints; f->w.numpoints = w->numpoints;
if (f->w.numpoints > MAXEDGES) if (f->w.numpoints > MAXEDGES)
Error("face->numpoints > MAXEDGES (%d), source face on line %d", Error("face->numpoints > MAXEDGES (%d), source face on line %d",
@ -990,7 +991,7 @@ brush_t *LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, int conte
} }
// create the brush // create the brush
brush = (brush_t *)AllocMem(BRUSH, 1, true); brush = (brush_t *)AllocMem(OTHER, sizeof(brush_t), true);
brush->contents = contents; brush->contents = contents;
brush->faces = facelist; brush->faces = facelist;
@ -1435,7 +1436,7 @@ int BrushMostlyOnSide (const brush_t *brush, const vec3_t planenormal, vec_t pla
face_t *CopyFace(const face_t *face) face_t *CopyFace(const face_t *face)
{ {
face_t *newface = (face_t *)AllocMem(FACE, 1, true); face_t *newface = (face_t *)AllocMem(OTHER, sizeof(face_t), true);
memcpy(newface, face, sizeof(face_t)); memcpy(newface, face, sizeof(face_t));
@ -1459,7 +1460,7 @@ Duplicates the brush, the sides, and the windings
*/ */
brush_t *CopyBrush (const brush_t *brush) brush_t *CopyBrush (const brush_t *brush)
{ {
brush_t *newbrush = (brush_t *)AllocMem(BRUSH, 1, true); brush_t *newbrush = (brush_t *)AllocMem(OTHER, sizeof(brush_t), true);
memcpy(newbrush, brush, sizeof(brush_t)); memcpy(newbrush, brush, sizeof(brush_t));
@ -1637,7 +1638,7 @@ void SplitBrush (const brush_t *brush,
for (int i=0 ; i<2 ; i++) for (int i=0 ; i<2 ; i++)
{ {
b[i] = (brush_t *) AllocMem (BRUSH, 1, true); b[i] = (brush_t *) AllocMem (OTHER, sizeof(brush_t), true);
//memcpy( b[i], brush, sizeof( brush_t ) ); //memcpy( b[i], brush, sizeof( brush_t ) );
// NOTE: brush copying // NOTE: brush copying

View File

@ -78,7 +78,7 @@ NewFaceFromFace(face_t *in)
{ {
face_t *newf; face_t *newf;
newf = (face_t *)AllocMem(FACE, 1, true); newf = (face_t *)AllocMem(OTHER, sizeof(face_t), true);
newf->planenum = in->planenum; newf->planenum = in->planenum;
newf->texinfo = in->texinfo; newf->texinfo = in->texinfo;
@ -514,7 +514,7 @@ BuildSurfaces(const std::map<int, face_t *> &planefaces)
continue; continue;
/* create a new surface to hold the faces on this plane */ /* create a new surface to hold the faces on this plane */
surface_t *surf = (surface_t *)AllocMem(SURFACE, 1, true); surface_t *surf = (surface_t *)AllocMem(OTHER, sizeof(surface_t), true);
surf->planenum = entry->first; surf->planenum = entry->first;
surf->next = surfaces; surf->next = surfaces;
surfaces = surf; surfaces = surf;
@ -544,7 +544,7 @@ CopyBrushFaces(const brush_t *brush)
facelist = NULL; facelist = NULL;
for (face = brush->faces; face; face = face->next) { for (face = brush->faces; face; face = face->next) {
brushfaces++; brushfaces++;
newface = (face_t *)AllocMem(FACE, 1, true); newface = (face_t *)AllocMem(OTHER, sizeof(face_t), true);
*newface = *face; *newface = *face;
newface->contents[0] = CONTENTS_EMPTY; newface->contents[0] = CONTENTS_EMPTY;
newface->contents[1] = brush->contents; newface->contents[1] = brush->contents;

View File

@ -410,7 +410,7 @@ MakeHeadnodePortals(const mapentity_t *entity, node_t *node)
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
n = j * 3 + i; n = j * 3 + i;
p = (portal_t *)AllocMem(PORTAL, 1, true); p = (portal_t *)AllocMem(OTHER, sizeof(portal_t), true);
portals[n] = p; portals[n] = p;
pl = &bplanes[n]; pl = &bplanes[n];
@ -580,7 +580,7 @@ CutNodePortals_r(node_t *node, portal_state_t *state)
* create the new portal by taking the full plane winding for the cutting * create the new portal by taking the full plane winding for the cutting
* plane and clipping it by all of the planes from the other portals * plane and clipping it by all of the planes from the other portals
*/ */
new_portal = (portal_t *)AllocMem(PORTAL, 1, true); new_portal = (portal_t *)AllocMem(OTHER, sizeof(portal_t), true);
new_portal->planenum = node->planenum; new_portal->planenum = node->planenum;
winding = BaseWindingForPlane(plane); winding = BaseWindingForPlane(plane);
@ -650,7 +650,7 @@ CutNodePortals_r(node_t *node, portal_state_t *state)
} }
/* the winding is split */ /* the winding is split */
new_portal = (portal_t *)AllocMem(PORTAL, 1, true); new_portal = (portal_t *)AllocMem(OTHER, sizeof(portal_t), true);
*new_portal = *portal; *new_portal = *portal;
new_portal->winding = backwinding; new_portal->winding = backwinding;
FreeMem(portal->winding, WINDING, 1); FreeMem(portal->winding, WINDING, 1);

View File

@ -609,7 +609,7 @@ DividePlane(surface_t *in, const qbsp_plane_t *split, surface_t **front,
in->onnode = true; in->onnode = true;
// divide the facets to the front and back sides // divide the facets to the front and back sides
surface_t *newsurf = (surface_t *)AllocMem(SURFACE, 1, true); surface_t *newsurf = (surface_t *)AllocMem(OTHER, sizeof(surface_t), true);
*newsurf = *in; *newsurf = *in;
// Prepend each face in facet list to either in or newsurf lists // Prepend each face in facet list to either in or newsurf lists
@ -685,7 +685,7 @@ DividePlane(surface_t *in, const qbsp_plane_t *split, surface_t **front,
} }
// stuff got split, so allocate one new plane and reuse in // stuff got split, so allocate one new plane and reuse in
surface_t *newsurf = (surface_t *)AllocMem(SURFACE, 1, true); surface_t *newsurf = (surface_t *)AllocMem(OTHER, sizeof(surface_t), true);
*newsurf = *in; *newsurf = *in;
newsurf->faces = backlist; newsurf->faces = backlist;
*back = newsurf; *back = newsurf;
@ -907,7 +907,7 @@ LinkNodeFaces(surface_t *surface)
// copy // copy
for (face_t *f = surface->faces; f; f = f->next) { for (face_t *f = surface->faces; f; f = f->next) {
nodefaces++; nodefaces++;
face_t *newf = (face_t *)AllocMem(FACE, 1, true); face_t *newf = (face_t *)AllocMem(OTHER, sizeof(face_t), true);
*newf = *f; *newf = *f;
f->original = newf; f->original = newf;
newf->next = list; newf->next = list;
@ -942,8 +942,8 @@ PartitionSurfaces(surface_t *surfaces, node_t *node)
Message(msgPercent, splitnodes.load(), csgmergefaces); Message(msgPercent, splitnodes.load(), csgmergefaces);
node->faces = LinkNodeFaces(split); node->faces = LinkNodeFaces(split);
node->children[0] = (node_t *)AllocMem(NODE, 1, true); node->children[0] = (node_t *)AllocMem(OTHER, sizeof(node_t), true);
node->children[1] = (node_t *)AllocMem(NODE, 1, true); node->children[1] = (node_t *)AllocMem(OTHER, sizeof(node_t), true);
node->planenum = split->planenum; node->planenum = split->planenum;
node->detail_separator = split->detail_separator; node->detail_separator = split->detail_separator;
@ -1004,16 +1004,16 @@ SolidBSP(const mapentity_t *entity, surface_t *surfhead, bool midsplit)
* collision hull for the engine. Probably could be done a little * collision hull for the engine. Probably could be done a little
* smarter, but this works. * smarter, but this works.
*/ */
node_t *headnode = (node_t *)AllocMem(NODE, 1, true); node_t *headnode = (node_t *)AllocMem(OTHER, sizeof(node_t), true);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
headnode->mins[i] = entity->mins[i] - SIDESPACE; headnode->mins[i] = entity->mins[i] - SIDESPACE;
headnode->maxs[i] = entity->maxs[i] + SIDESPACE; headnode->maxs[i] = entity->maxs[i] + SIDESPACE;
} }
headnode->children[0] = (node_t *)AllocMem(NODE, 1, true); headnode->children[0] = (node_t *)AllocMem(OTHER, sizeof(node_t), true);
headnode->children[0]->planenum = PLANENUM_LEAF; headnode->children[0]->planenum = PLANENUM_LEAF;
headnode->children[0]->contents = CONTENTS_EMPTY; headnode->children[0]->contents = CONTENTS_EMPTY;
headnode->children[0]->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true); headnode->children[0]->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
headnode->children[1] = (node_t *)AllocMem(NODE, 1, true); headnode->children[1] = (node_t *)AllocMem(OTHER, sizeof(node_t), true);
headnode->children[1]->planenum = PLANENUM_LEAF; headnode->children[1]->planenum = PLANENUM_LEAF;
headnode->children[1]->contents = CONTENTS_EMPTY; headnode->children[1]->contents = CONTENTS_EMPTY;
headnode->children[1]->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true); headnode->children[1]->markfaces = (face_t **)AllocMem(OTHER, sizeof(face_t *), true);
@ -1023,7 +1023,7 @@ SolidBSP(const mapentity_t *entity, surface_t *surfhead, bool midsplit)
Message(msgProgress, "SolidBSP"); Message(msgProgress, "SolidBSP");
node_t *headnode = (node_t *)AllocMem(NODE, 1, true); node_t *headnode = (node_t *)AllocMem(OTHER, sizeof(node_t), true);
usemidsplit = midsplit; usemidsplit = midsplit;
// calculate a bounding box for the entire model // calculate a bounding box for the entire model

View File

@ -478,8 +478,8 @@ TJunc(const mapentity_t *entity, node_t *headnode)
cWEdges = cWVerts; cWEdges = cWVerts;
cWVerts *= 2; cWVerts *= 2;
pWVerts = (wvert_t *)AllocMem(WVERT, cWVerts, true); pWVerts = (wvert_t *)AllocMem(OTHER, cWVerts * sizeof(wvert_t), true);
pWEdges = (wedge_t *)AllocMem(WEDGE, cWEdges, true); pWEdges = (wedge_t *)AllocMem(OTHER, cWEdges * sizeof(wedge_t), true);
/* /*
* identify all points on common edges * identify all points on common edges

View File

@ -73,10 +73,6 @@ AllocMem(int Type, int cElements, bool fZero)
if (fZero) if (fZero)
memset(pTemp, 0, cSize); memset(pTemp, 0, cSize);
// Special stuff for face_t
if (Type == FACE && cElements == 1)
((face_t *)pTemp)->planenum = -1;
std::unique_lock<std::mutex> lck { memoryStatsLock }; std::unique_lock<std::mutex> lck { memoryStatsLock };
rgMemTotal[Type] += cElements; rgMemTotal[Type] += cElements;