diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 6a88f733..8662de4c 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -162,6 +162,7 @@ typedef struct mapdata_s { std::vector exported_clipnodes; std::vector exported_edges; std::vector exported_vertexes; + std::vector exported_surfedges; // helpers std::string texinfoTextureName(int texinfo) const { diff --git a/qbsp/bspfile.cc b/qbsp/bspfile.cc index d5f9b579..1e38e2c2 100644 --- a/qbsp/bspfile.cc +++ b/qbsp/bspfile.cc @@ -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(map.exported_clipnodes.size()), static_cast(map.exported_clipnodes.size()) * MemSize[BSP_CLIPNODE]); Message(msgStat, "%8d leafs %10d", static_cast(map.exported_leafs_bsp29.size()), static_cast(map.exported_leafs_bsp29.size()) * MemSize[BSP_LEAF]); Message(msgStat, "%8d marksurfaces %10d", static_cast(map.exported_marksurfaces.size()), static_cast(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(map.exported_surfedges.size()), static_cast(map.exported_surfedges.size()) * MemSize[BSP_SURFEDGE]); Message(msgStat, "%8d edges %10d", static_cast(map.exported_edges.size()), static_cast(map.exported_edges.size()) * MemSize[BSP_EDGE]); lump = &pWorldEnt()->lumps[LUMP_TEXTURES]; diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index 6911d839..711adeaf 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -392,7 +392,6 @@ template 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(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(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;