qbsp: drop MemSize stuff

This commit is contained in:
Eric Wasylishen 2021-08-24 22:51:44 -06:00
parent 1123205d47
commit 899b2b8384
5 changed files with 7 additions and 266 deletions

View File

@ -141,42 +141,10 @@
// volume. is this still needed?
#define SIDESPACE 24
/*
* If this enum is changed, make sure to also update MemSize and PrintMem
*/
// AllocMem types
enum {
BSP_ENT,
BSP_PLANE,
BSP_TEX,
BSP_VERTEX,
BSP_VIS,
BSP_NODE,
BSP_TEXINFO,
BSP_FACE,
BSP_LIGHT,
BSP_CLIPNODE,
BSP_LEAF,
BSP_MARKSURF,
BSP_EDGE,
BSP_SURFEDGE,
BSP_MODEL,
MAPFACE,
MAPBRUSH,
MAPENTITY,
WINDING,
FACE,
PLANE,
PORTAL,
SURFACE,
NODE,
BRUSH,
MIPTEX,
WVERT,
WEDGE,
HASHVERT,
OTHER,
GLOBAL
OTHER
};
#include <common/cmdlib.hh>

View File

@ -31,15 +31,8 @@
#define msgPercent 7
extern const char *rgszWarnings[cWarnings];
extern const int *MemSize;
extern const int MemSize_BSP29[GLOBAL + 1];
extern const int MemSize_BSP2rmq[GLOBAL + 1];
extern const int MemSize_BSP2[GLOBAL + 1];
void *AllocMem(int Type, int cSize, bool fZero);
void FreeMem(void *pMem, int Type, int cSize);
void FreeAllMem(void);
void PrintMem(void);
void Message(int MsgType, ...);
void Error(const char *error, ...)

View File

@ -22,92 +22,6 @@
#include <qbsp/qbsp.hh>
/*
* MemSize is used by the memory manager to allocate and track data
* allocations. Default to BSP29 allocations.
*/
const int *MemSize = MemSize_BSP29;
/*
* Use a macro to avoid repeating the shared data
*/
#define COMMON_MEMSIZES \
sizeof(mapface_t), \
sizeof(mapbrush_t), \
sizeof(mapentity_t), \
1, /* Winding */ \
sizeof(face_t), \
sizeof(qbsp_plane_t), \
sizeof(portal_t), \
sizeof(surface_t), \
sizeof(node_t), \
sizeof(brush_t), \
sizeof(texname_t), \
sizeof(wvert_t), \
sizeof(wedge_t), \
sizeof(hashvert_t), \
1, /* Other (uint8_t) */ \
1, /* Global (totals) */
const int MemSize_BSP29[] = {
sizeof(char), /* Entity text */
sizeof(dplane_t),
sizeof(uint8_t), /* Texture data */
sizeof(dvertex_t),
sizeof(uint8_t), /* Visibility data */
sizeof(bsp29_dnode_t),
sizeof(texinfo_t),
sizeof(bsp29_dface_t),
sizeof(uint8_t), /* Light data */
sizeof(bsp29_dclipnode_t),
sizeof(bsp29_dleaf_t),
sizeof(uint16_t), /* Marksurfaces */
sizeof(bsp29_dedge_t),
sizeof(int32_t), /* Surfedges */
sizeof(dmodel_t),
COMMON_MEMSIZES
};
const int MemSize_BSP2[] = {
sizeof(char), /* Entity text */
sizeof(dplane_t),
sizeof(uint8_t), /* Texture data */
sizeof(dvertex_t),
sizeof(uint8_t), /* Visibility data */
sizeof(bsp2_dnode_t),
sizeof(texinfo_t),
sizeof(bsp2_dface_t),
sizeof(uint8_t), /* Light data */
sizeof(bsp2_dclipnode_t),
sizeof(bsp2_dleaf_t),
sizeof(uint32_t), /* Marksurfaces */
sizeof(bsp2_dedge_t),
sizeof(int32_t), /* Surfedges */
sizeof(dmodel_t),
COMMON_MEMSIZES
};
const int MemSize_BSP2rmq[] = {
sizeof(char), /* Entity text */
sizeof(dplane_t),
sizeof(uint8_t), /* Texture data */
sizeof(dvertex_t),
sizeof(uint8_t), /* Visibility data */
sizeof(bsp2rmq_dnode_t),
sizeof(texinfo_t),
sizeof(bsp2_dface_t),
sizeof(uint8_t), /* Light data */
sizeof(bsp2_dclipnode_t),
sizeof(bsp2rmq_dleaf_t),
sizeof(uint32_t), /* Marksurfaces */
sizeof(bsp2_dedge_t),
sizeof(int32_t), /* Surfedges */
sizeof(dmodel_t),
COMMON_MEMSIZES
};
#undef COMMON_MEMSIZES
/* ------------------------------------------------------------------------ */
mapdata_t map;

View File

@ -842,13 +842,10 @@ ParseOptions(char *szOptions)
}
else if (!Q_strcasecmp(szTok, "hlbsp")) {
options.BSPVersion = BSPHLVERSION;
MemSize = MemSize_BSP29;
} else if (!Q_strcasecmp(szTok, "bsp2")) {
options.BSPVersion = BSP2VERSION;
MemSize = MemSize_BSP2;
} else if (!Q_strcasecmp(szTok, "2psb")) {
options.BSPVersion = BSP2RMQVERSION;
MemSize = MemSize_BSP2rmq;
} else if (!Q_strcasecmp(szTok, "leakdist")) {
szTok2 = GetTok(szTok + strlen(szTok) + 1, szEnd);
if (!szTok2)
@ -1080,7 +1077,7 @@ int qbsp_main(int argc, const char **argv)
end = I_FloatTime();
Message(msgLiteral, "\n%5.3f seconds elapsed\n", end - start);
PrintMem();
// FreeAllMem();
// PrintMem();

View File

@ -29,14 +29,6 @@
#include <qbsp/qbsp.hh>
static int rgMemTotal[GLOBAL + 1];
static int rgMemActive[GLOBAL + 1];
static int rgMemPeak[GLOBAL + 1];
static int rgMemActiveBytes[GLOBAL + 1];
static int rgMemPeakBytes[GLOBAL + 1];
std::mutex memoryStatsLock;
/*
==========
AllocMem
@ -48,7 +40,7 @@ AllocMem(int Type, int cElements, bool fZero)
void *pTemp;
int cSize;
if (Type < 0 || Type > OTHER)
if (!(Type == WINDING || Type == OTHER))
Error("Internal error: invalid memory type %d (%s)", Type, __func__);
// For windings, cElements == number of points on winding
@ -63,9 +55,9 @@ AllocMem(int Type, int cElements, bool fZero)
// Set cElements to 1 so bookkeeping works OK
cElements = 1;
} else
cSize = cElements * MemSize[Type];
} else {
cSize = cElements;
}
pTemp = malloc(cSize);
if (!pTemp)
Error("allocation of %d bytes failed (%s)", cSize, __func__);
@ -73,132 +65,9 @@ AllocMem(int Type, int cElements, bool fZero)
if (fZero)
memset(pTemp, 0, cSize);
std::unique_lock<std::mutex> lck { memoryStatsLock };
rgMemTotal[Type] += cElements;
rgMemActive[Type] += cElements;
rgMemActiveBytes[Type] += cSize;
if (rgMemActive[Type] > rgMemPeak[Type])
rgMemPeak[Type] = rgMemActive[Type];
if (rgMemActiveBytes[Type] > rgMemPeakBytes[Type])
rgMemPeakBytes[Type] = rgMemActiveBytes[Type];
// Also keep global statistics
rgMemTotal[GLOBAL] += cSize;
rgMemActive[GLOBAL] += cSize;
if (rgMemActive[GLOBAL] > rgMemPeak[GLOBAL])
rgMemPeak[GLOBAL] = rgMemActive[GLOBAL];
return pTemp;
}
/*
==========
FreeMem
==========
*/
void
FreeMem(void *pMem, int Type, int cElements)
{
free(pMem);
std::unique_lock<std::mutex> lck { memoryStatsLock };
rgMemActive[Type] -= cElements;
rgMemActiveBytes[Type] -= cElements * MemSize[Type];
rgMemActive[GLOBAL] -= cElements * MemSize[Type];
}
static const char *
MemString(int bytes)
{
static char buf[20];
if (bytes > 1024 * 1024 * 1024 / 2)
q_snprintf(buf, 20, "%0.1fG", (float)bytes / (1024 * 1024 * 1024));
else if (bytes > 1024 * 1024 / 2)
q_snprintf(buf, 20, "%0.1fM", (float)bytes / (1024 * 1024));
else if (bytes > 1024 / 2)
q_snprintf(buf, 20, "%0.1fk", (float)bytes / 1024);
else
buf[0] = 0;
return buf;
}
/*
==========
PrintMem
==========
*/
void
PrintMem(void)
{
const char *MemTypes[] = {
"BSPEntity", "BSPPlane", "BSPTex", "BSPVertex", "BSPVis", "BSPNode",
"BSPTexinfo", "BSPFace", "BSPLight", "BSPClipnode", "BSPLeaf",
"BSPMarksurface", "BSPEdge", "BSPSurfedge", "BSPModel",
"Mapface", "Mapbrush", "Mapentity", "Winding", "Face", "Plane",
"Portal", "Surface", "Node", "Brush", "Miptex", "World verts",
"World edges", "Hash verts", "Other", "Total"
};
int i;
if (options.fVerbose) {
Message(msgLiteral,
"\nData type CurrentNum PeakNum PeakMem\n");
for (i = 0; i <= OTHER; i++)
Message(msgLiteral, "%-16s %9d %9d %12d %8s\n",
MemTypes[i], rgMemActive[i], rgMemPeak[i],
rgMemPeakBytes[i], MemString(rgMemPeakBytes[i]));
Message(msgLiteral, "%-16s %12d %8s\n",
MemTypes[GLOBAL], rgMemPeak[GLOBAL],
MemString(rgMemPeak[GLOBAL]));
} else
Message(msgLiteral, "Peak memory usage: %d (%s)\n", rgMemPeak[GLOBAL],
MemString(rgMemPeak[GLOBAL]));
}
#if 0
/*
============
FreeAllMem
============
*/
void
FreeAllMem(void)
{
int i, j;
epair_t *ep, *next;
struct lumpdata *lump;
mapentity_t *entity;
for (i = 0, entity = map.entities; i < map.numentities; i++, entity++) {
for (ep = entity->epairs; ep; ep = next) {
next = ep->next;
if (ep->key)
FreeMem(ep->key, OTHER, strlen(ep->key) + 1);
if (ep->value)
FreeMem(ep->value, OTHER, strlen(ep->value) + 1);
FreeMem(ep, OTHER, sizeof(epair_t));
}
lump = entity->lumps;
for (j = 0; j < BSP_LUMPS; j++)
if (lump[j].data)
FreeMem(lump[j].data, j, lump[j].count);
}
FreeMem(map.planes, PLANE, map.maxplanes);
FreeMem(map.faces, MAPFACE, map.maxfaces);
FreeMem(map.brushes, MAPBRUSH, map.maxbrushes);
FreeMem(map.entities, MAPENTITY, map.maxentities);
}
#endif
/* Keep track of output state */
static bool fInPercent = false;