qbsp: refactor surfedges writing

This commit is contained in:
Eric Wasylishen 2021-08-23 19:52:46 -06:00
parent d7c7fb6b2d
commit a0bdbf89d1
3 changed files with 7 additions and 18 deletions

View File

@ -162,6 +162,7 @@ typedef struct mapdata_s {
std::vector<bsp29_dclipnode_t> exported_clipnodes;
std::vector<bsp29_dedge_t> exported_edges;
std::vector<dvertex_t> exported_vertexes;
std::vector<int> exported_surfedges;
// helpers
std::string texinfoTextureName(int texinfo) const {

View File

@ -301,7 +301,7 @@ WriteBSPFile(void)
AddLump(f, LUMP_FACES);
AddLumpFromBuffer(f, LUMP_CLIPNODES, map.exported_clipnodes.data(), map.exported_clipnodes.size() * sizeof(map.exported_clipnodes[0]));
AddLumpFromBuffer(f, LUMP_MARKSURFACES, map.exported_marksurfaces.data(), map.exported_marksurfaces.size() * sizeof(map.exported_marksurfaces[0]));
AddLump(f, LUMP_SURFEDGES);
AddLumpFromBuffer(f, LUMP_SURFEDGES, map.exported_surfedges.data(), map.exported_surfedges.size() * sizeof(map.exported_surfedges[0]));
AddLumpFromBuffer(f, LUMP_EDGES, map.exported_edges.data(), map.exported_edges.size() * sizeof(map.exported_edges[0]));
AddLump(f, LUMP_MODELS);
@ -389,7 +389,7 @@ PrintBSPFileSizes(void)
Message(msgStat, "%8d clipnodes %10d", static_cast<int>(map.exported_clipnodes.size()), static_cast<int>(map.exported_clipnodes.size()) * MemSize[BSP_CLIPNODE]);
Message(msgStat, "%8d leafs %10d", static_cast<int>(map.exported_leafs_bsp29.size()), static_cast<int>(map.exported_leafs_bsp29.size()) * MemSize[BSP_LEAF]);
Message(msgStat, "%8d marksurfaces %10d", static_cast<int>(map.exported_marksurfaces.size()), static_cast<int>(map.exported_marksurfaces.size()) * MemSize[BSP_MARKSURF]);
Message(msgStat, "%8d surfedges %10d", map.cTotal[LUMP_SURFEDGES], map.cTotal[LUMP_SURFEDGES] * MemSize[BSP_SURFEDGE]);
Message(msgStat, "%8d surfedges %10d", static_cast<int>(map.exported_surfedges.size()), static_cast<int>(map.exported_surfedges.size()) * MemSize[BSP_SURFEDGE]);
Message(msgStat, "%8d edges %10d", static_cast<int>(map.exported_edges.size()), static_cast<int>(map.exported_edges.size()) * MemSize[BSP_EDGE]);
lump = &pWorldEnt()->lumps[LUMP_TEXTURES];

View File

@ -392,7 +392,6 @@ template <class DFACE>
static void
EmitFace_Internal(mapentity_t *entity, face_t *face)
{
struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES];
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
DFACE *out;
@ -414,15 +413,14 @@ EmitFace_Internal(mapentity_t *entity, face_t *face)
out->styles[i] = 255;
out->lightofs = -1;
out->firstedge = map.cTotal[LUMP_SURFEDGES];
// emit surfedges
out->firstedge = static_cast<int>(map.exported_surfedges.size());
for (i = 0; i < face->w.numpoints; i++) {
((int *)surfedges->data)[surfedges->index] = face->edges[i];
surfedges->index++;
map.cTotal[LUMP_SURFEDGES]++;
map.exported_surfedges.push_back(face->edges[i]);
}
FreeMem(face->edges, OTHER, face->w.numpoints * sizeof(int));
out->numedges = map.cTotal[LUMP_SURFEDGES] - out->firstedge;
out->numedges = static_cast<int>(map.exported_surfedges.size()) - out->firstedge;
map.cTotal[LUMP_FACES]++;
faces->index++;
@ -505,7 +503,6 @@ int
MakeFaceEdges(mapentity_t *entity, node_t *headnode)
{
int i, firstface;
struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES];
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
@ -516,14 +513,6 @@ MakeFaceEdges(mapentity_t *entity, node_t *headnode)
int vertexesCount = 0;
CountData_r(entity, headnode, &vertexesCount);
/*
* Remember edges are +1 in BeginBSPFile. Often less than half
* the vertices actually are unique, although heavy use of skip
* faces will break that assumption. 2/3 should be safe most of
* the time without wasting too much memory...
*/
surfedges->count = vertexesCount;
// Accessory data
InitHash();
@ -533,7 +522,6 @@ MakeFaceEdges(mapentity_t *entity, node_t *headnode)
pEdgeFaces0.clear();
pEdgeFaces1.clear();
surfedges->data = AllocMem(BSP_SURFEDGE, surfedges->count, true);
faces->data = AllocMem(BSP_FACE, faces->count, true);
lmshifts->count = needlmshifts?faces->count:0;