qbsp: refactor surfedges writing
This commit is contained in:
parent
d7c7fb6b2d
commit
a0bdbf89d1
|
|
@ -162,6 +162,7 @@ typedef struct mapdata_s {
|
||||||
std::vector<bsp29_dclipnode_t> exported_clipnodes;
|
std::vector<bsp29_dclipnode_t> exported_clipnodes;
|
||||||
std::vector<bsp29_dedge_t> exported_edges;
|
std::vector<bsp29_dedge_t> exported_edges;
|
||||||
std::vector<dvertex_t> exported_vertexes;
|
std::vector<dvertex_t> exported_vertexes;
|
||||||
|
std::vector<int> exported_surfedges;
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
std::string texinfoTextureName(int texinfo) const {
|
std::string texinfoTextureName(int texinfo) const {
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ WriteBSPFile(void)
|
||||||
AddLump(f, LUMP_FACES);
|
AddLump(f, LUMP_FACES);
|
||||||
AddLumpFromBuffer(f, LUMP_CLIPNODES, map.exported_clipnodes.data(), map.exported_clipnodes.size() * sizeof(map.exported_clipnodes[0]));
|
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]));
|
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]));
|
AddLumpFromBuffer(f, LUMP_EDGES, map.exported_edges.data(), map.exported_edges.size() * sizeof(map.exported_edges[0]));
|
||||||
AddLump(f, LUMP_MODELS);
|
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 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 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 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]);
|
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];
|
lump = &pWorldEnt()->lumps[LUMP_TEXTURES];
|
||||||
|
|
|
||||||
|
|
@ -392,7 +392,6 @@ template <class DFACE>
|
||||||
static void
|
static void
|
||||||
EmitFace_Internal(mapentity_t *entity, face_t *face)
|
EmitFace_Internal(mapentity_t *entity, face_t *face)
|
||||||
{
|
{
|
||||||
struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES];
|
|
||||||
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
|
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
|
||||||
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
|
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
|
||||||
DFACE *out;
|
DFACE *out;
|
||||||
|
|
@ -414,15 +413,14 @@ EmitFace_Internal(mapentity_t *entity, face_t *face)
|
||||||
out->styles[i] = 255;
|
out->styles[i] = 255;
|
||||||
out->lightofs = -1;
|
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++) {
|
for (i = 0; i < face->w.numpoints; i++) {
|
||||||
((int *)surfedges->data)[surfedges->index] = face->edges[i];
|
map.exported_surfedges.push_back(face->edges[i]);
|
||||||
surfedges->index++;
|
|
||||||
map.cTotal[LUMP_SURFEDGES]++;
|
|
||||||
}
|
}
|
||||||
FreeMem(face->edges, OTHER, face->w.numpoints * sizeof(int));
|
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]++;
|
map.cTotal[LUMP_FACES]++;
|
||||||
faces->index++;
|
faces->index++;
|
||||||
|
|
@ -505,7 +503,6 @@ int
|
||||||
MakeFaceEdges(mapentity_t *entity, node_t *headnode)
|
MakeFaceEdges(mapentity_t *entity, node_t *headnode)
|
||||||
{
|
{
|
||||||
int i, firstface;
|
int i, firstface;
|
||||||
struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES];
|
|
||||||
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
|
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
|
||||||
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
|
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
|
||||||
|
|
||||||
|
|
@ -516,14 +513,6 @@ MakeFaceEdges(mapentity_t *entity, node_t *headnode)
|
||||||
int vertexesCount = 0;
|
int vertexesCount = 0;
|
||||||
CountData_r(entity, headnode, &vertexesCount);
|
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
|
// Accessory data
|
||||||
InitHash();
|
InitHash();
|
||||||
|
|
||||||
|
|
@ -533,7 +522,6 @@ MakeFaceEdges(mapentity_t *entity, node_t *headnode)
|
||||||
pEdgeFaces0.clear();
|
pEdgeFaces0.clear();
|
||||||
pEdgeFaces1.clear();
|
pEdgeFaces1.clear();
|
||||||
|
|
||||||
surfedges->data = AllocMem(BSP_SURFEDGE, surfedges->count, true);
|
|
||||||
faces->data = AllocMem(BSP_FACE, faces->count, true);
|
faces->data = AllocMem(BSP_FACE, faces->count, true);
|
||||||
|
|
||||||
lmshifts->count = needlmshifts?faces->count:0;
|
lmshifts->count = needlmshifts?faces->count:0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue