qbsp: refactor face writing
This commit is contained in:
parent
a0bdbf89d1
commit
f59bc08db8
|
|
@ -103,6 +103,8 @@ public:
|
||||||
int numbrushes;
|
int numbrushes;
|
||||||
struct lumpdata lumps[BSPX_LUMPS];
|
struct lumpdata lumps[BSPX_LUMPS];
|
||||||
|
|
||||||
|
int firstoutputfacenumber;
|
||||||
|
|
||||||
const mapbrush_t &mapbrush(int i) const;
|
const mapbrush_t &mapbrush(int i) const;
|
||||||
|
|
||||||
mapentity_t() :
|
mapentity_t() :
|
||||||
|
|
@ -116,7 +118,8 @@ public:
|
||||||
liquid(nullptr),
|
liquid(nullptr),
|
||||||
epairs(nullptr),
|
epairs(nullptr),
|
||||||
brushes(nullptr),
|
brushes(nullptr),
|
||||||
numbrushes(0) {
|
numbrushes(0),
|
||||||
|
firstoutputfacenumber(-1) {
|
||||||
VectorSet(origin,0,0,0);
|
VectorSet(origin,0,0,0);
|
||||||
VectorSet(mins,0,0,0);
|
VectorSet(mins,0,0,0);
|
||||||
VectorSet(maxs,0,0,0);
|
VectorSet(maxs,0,0,0);
|
||||||
|
|
@ -163,6 +166,7 @@ typedef struct mapdata_s {
|
||||||
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;
|
std::vector<int> exported_surfedges;
|
||||||
|
std::vector<bsp29_dface_t> exported_faces;
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
std::string texinfoTextureName(int texinfo) const {
|
std::string texinfoTextureName(int texinfo) const {
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,7 @@ WriteBSPFile(void)
|
||||||
AddLumpFromBuffer(f, LUMP_VERTEXES, map.exported_vertexes.data(), map.exported_vertexes.size() * sizeof(map.exported_vertexes[0]));
|
AddLumpFromBuffer(f, LUMP_VERTEXES, map.exported_vertexes.data(), map.exported_vertexes.size() * sizeof(map.exported_vertexes[0]));
|
||||||
AddLumpFromBuffer(f, LUMP_NODES, map.exported_nodes_bsp29.data(), map.exported_nodes_bsp29.size() * sizeof(map.exported_nodes_bsp29[0]));
|
AddLumpFromBuffer(f, LUMP_NODES, map.exported_nodes_bsp29.data(), map.exported_nodes_bsp29.size() * sizeof(map.exported_nodes_bsp29[0]));
|
||||||
AddLumpFromBuffer(f, LUMP_TEXINFO, map.exported_texinfos.data(), map.exported_texinfos.size() * sizeof(map.exported_texinfos[0]));
|
AddLumpFromBuffer(f, LUMP_TEXINFO, map.exported_texinfos.data(), map.exported_texinfos.size() * sizeof(map.exported_texinfos[0]));
|
||||||
AddLump(f, LUMP_FACES);
|
AddLumpFromBuffer(f, LUMP_FACES, map.exported_faces.data(), map.exported_faces.size() * sizeof(map.exported_faces[0]));
|
||||||
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]));
|
||||||
AddLumpFromBuffer(f, LUMP_SURFEDGES, map.exported_surfedges.data(), map.exported_surfedges.size() * sizeof(map.exported_surfedges[0]));
|
AddLumpFromBuffer(f, LUMP_SURFEDGES, map.exported_surfedges.data(), map.exported_surfedges.size() * sizeof(map.exported_surfedges[0]));
|
||||||
|
|
@ -385,7 +385,7 @@ PrintBSPFileSizes(void)
|
||||||
Message(msgStat, "%8d vertexes %10d", static_cast<int>(map.exported_vertexes.size()), static_cast<int>(map.exported_vertexes.size()) * MemSize[BSP_VERTEX]);
|
Message(msgStat, "%8d vertexes %10d", static_cast<int>(map.exported_vertexes.size()), static_cast<int>(map.exported_vertexes.size()) * MemSize[BSP_VERTEX]);
|
||||||
Message(msgStat, "%8d nodes %10d", static_cast<int>(map.exported_nodes_bsp29.size()), static_cast<int>(map.exported_nodes_bsp29.size()) * MemSize[BSP_NODE]);
|
Message(msgStat, "%8d nodes %10d", static_cast<int>(map.exported_nodes_bsp29.size()), static_cast<int>(map.exported_nodes_bsp29.size()) * MemSize[BSP_NODE]);
|
||||||
Message(msgStat, "%8d texinfo %10d", static_cast<int>(map.exported_texinfos.size()), static_cast<int>(map.exported_texinfos.size()) * MemSize[BSP_TEXINFO]);
|
Message(msgStat, "%8d texinfo %10d", static_cast<int>(map.exported_texinfos.size()), static_cast<int>(map.exported_texinfos.size()) * MemSize[BSP_TEXINFO]);
|
||||||
Message(msgStat, "%8d faces %10d", map.cTotal[LUMP_FACES], map.cTotal[LUMP_FACES] * MemSize[BSP_FACE]);
|
Message(msgStat, "%8d faces %10d", static_cast<int>(map.exported_faces.size()), static_cast<int>(map.exported_faces.size()) * MemSize[BSP_FACE]);
|
||||||
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]);
|
||||||
|
|
|
||||||
|
|
@ -388,13 +388,11 @@ MakeFaceEdges_r(mapentity_t *entity, node_t *node, int progress)
|
||||||
EmitFace
|
EmitFace
|
||||||
==============
|
==============
|
||||||
*/
|
*/
|
||||||
template <class DFACE>
|
|
||||||
static void
|
static void
|
||||||
EmitFace_Internal(mapentity_t *entity, face_t *face)
|
EmitFace(mapentity_t *entity, face_t *face)
|
||||||
{
|
{
|
||||||
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
|
|
||||||
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
|
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
|
||||||
DFACE *out;
|
bsp29_dface_t *out;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (map.mtexinfos.at(face->texinfo).flags & (TEX_SKIP | TEX_HINT))
|
if (map.mtexinfos.at(face->texinfo).flags & (TEX_SKIP | TEX_HINT))
|
||||||
|
|
@ -402,10 +400,15 @@ EmitFace_Internal(mapentity_t *entity, face_t *face)
|
||||||
|
|
||||||
// emit a region
|
// emit a region
|
||||||
Q_assert(face->outputnumber == -1);
|
Q_assert(face->outputnumber == -1);
|
||||||
face->outputnumber = map.cTotal[LUMP_FACES];
|
face->outputnumber = static_cast<int>(map.exported_faces.size());
|
||||||
if (lmshifts->data)
|
map.exported_faces.push_back({});
|
||||||
((unsigned char*)lmshifts->data)[faces->index] = face->lmshift[1];
|
|
||||||
out = (DFACE *)faces->data + faces->index;
|
if (lmshifts->data) {
|
||||||
|
const int localfacenumber = face->outputnumber - entity->firstoutputfacenumber;
|
||||||
|
((unsigned char*)lmshifts->data)[localfacenumber] = face->lmshift[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
out = &map.exported_faces.at(face->outputnumber);
|
||||||
out->planenum = ExportMapPlane(face->planenum);
|
out->planenum = ExportMapPlane(face->planenum);
|
||||||
out->side = face->planeside;
|
out->side = face->planeside;
|
||||||
out->texinfo = ExportMapTexinfo(face->texinfo);
|
out->texinfo = ExportMapTexinfo(face->texinfo);
|
||||||
|
|
@ -421,18 +424,6 @@ EmitFace_Internal(mapentity_t *entity, face_t *face)
|
||||||
FreeMem(face->edges, OTHER, face->w.numpoints * sizeof(int));
|
FreeMem(face->edges, OTHER, face->w.numpoints * sizeof(int));
|
||||||
|
|
||||||
out->numedges = static_cast<int>(map.exported_surfedges.size()) - out->firstedge;
|
out->numedges = static_cast<int>(map.exported_surfedges.size()) - out->firstedge;
|
||||||
|
|
||||||
map.cTotal[LUMP_FACES]++;
|
|
||||||
faces->index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
EmitFace(mapentity_t *entity, face_t *face)
|
|
||||||
{
|
|
||||||
if (options.BSPVersion == BSPVERSION || options.BSPVersion == BSPHLVERSION)
|
|
||||||
EmitFace_Internal<bsp29_dface_t>(entity, face);
|
|
||||||
else
|
|
||||||
EmitFace_Internal<bsp2_dface_t>(entity, face);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -446,7 +437,7 @@ GrowNodeRegion(mapentity_t *entity, node_t *node)
|
||||||
if (node->planenum == PLANENUM_LEAF)
|
if (node->planenum == PLANENUM_LEAF)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
node->firstface = map.cTotal[LUMP_FACES];
|
node->firstface = static_cast<int>(map.exported_faces.size());
|
||||||
|
|
||||||
for (face_t *face = node->faces; face; face = face->next) {
|
for (face_t *face = node->faces; face; face = face->next) {
|
||||||
Q_assert(face->planenum == node->planenum);
|
Q_assert(face->planenum == node->planenum);
|
||||||
|
|
@ -455,21 +446,22 @@ GrowNodeRegion(mapentity_t *entity, node_t *node)
|
||||||
EmitFace(entity, face);
|
EmitFace(entity, face);
|
||||||
}
|
}
|
||||||
|
|
||||||
node->numfaces = map.cTotal[LUMP_FACES] - node->firstface;
|
node->numfaces = static_cast<int>(map.exported_faces.size()) - node->firstface;
|
||||||
|
|
||||||
GrowNodeRegion(entity, node->children[0]);
|
GrowNodeRegion(entity, node->children[0]);
|
||||||
GrowNodeRegion(entity, node->children[1]);
|
GrowNodeRegion(entity, node->children[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
CountFace(mapentity_t *entity, face_t *f, int* vertexesCount)
|
CountFace(mapentity_t *entity, face_t *f, int *facesCount, int *vertexesCount)
|
||||||
{
|
{
|
||||||
if (map.mtexinfos.at(f->texinfo).flags & (TEX_SKIP | TEX_HINT))
|
if (map.mtexinfos.at(f->texinfo).flags & (TEX_SKIP | TEX_HINT))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (f->lmshift[1] != 4)
|
if (f->lmshift[1] != 4)
|
||||||
needlmshifts = true;
|
needlmshifts = true;
|
||||||
entity->lumps[LUMP_FACES].count++;
|
|
||||||
|
(*facesCount)++;
|
||||||
(*vertexesCount) += f->w.numpoints;
|
(*vertexesCount) += f->w.numpoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -479,7 +471,7 @@ CountData_r
|
||||||
==============
|
==============
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
CountData_r(mapentity_t *entity, node_t *node, int* vertexesCount)
|
CountData_r(mapentity_t *entity, node_t *node, int *facesCount, int *vertexesCount)
|
||||||
{
|
{
|
||||||
face_t *f;
|
face_t *f;
|
||||||
|
|
||||||
|
|
@ -487,11 +479,11 @@ CountData_r(mapentity_t *entity, node_t *node, int* vertexesCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (f = node->faces; f; f = f->next) {
|
for (f = node->faces; f; f = f->next) {
|
||||||
CountFace(entity, f, vertexesCount);
|
CountFace(entity, f, facesCount, vertexesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
CountData_r(entity, node->children[0], vertexesCount);
|
CountData_r(entity, node->children[0], facesCount, vertexesCount);
|
||||||
CountData_r(entity, node->children[1], vertexesCount);
|
CountData_r(entity, node->children[1], facesCount, vertexesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -503,28 +495,29 @@ int
|
||||||
MakeFaceEdges(mapentity_t *entity, node_t *headnode)
|
MakeFaceEdges(mapentity_t *entity, node_t *headnode)
|
||||||
{
|
{
|
||||||
int i, firstface;
|
int i, firstface;
|
||||||
struct lumpdata *faces = &entity->lumps[LUMP_FACES];
|
|
||||||
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
|
struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT];
|
||||||
|
|
||||||
Message(msgProgress, "MakeFaceEdges");
|
Message(msgProgress, "MakeFaceEdges");
|
||||||
|
|
||||||
needlmshifts = false;
|
needlmshifts = false;
|
||||||
|
|
||||||
|
Q_assert(entity->firstoutputfacenumber == -1);
|
||||||
|
entity->firstoutputfacenumber = static_cast<int>(map.exported_faces.size());
|
||||||
|
|
||||||
|
int facesCount = 0;
|
||||||
int vertexesCount = 0;
|
int vertexesCount = 0;
|
||||||
CountData_r(entity, headnode, &vertexesCount);
|
CountData_r(entity, headnode, &facesCount, &vertexesCount);
|
||||||
|
|
||||||
// Accessory data
|
// Accessory data
|
||||||
InitHash();
|
InitHash();
|
||||||
|
|
||||||
firstface = map.cTotal[LUMP_FACES];
|
firstface = static_cast<int>(map.exported_faces.size());
|
||||||
MakeFaceEdges_r(entity, headnode, 0);
|
MakeFaceEdges_r(entity, headnode, 0);
|
||||||
|
|
||||||
pEdgeFaces0.clear();
|
pEdgeFaces0.clear();
|
||||||
pEdgeFaces1.clear();
|
pEdgeFaces1.clear();
|
||||||
|
|
||||||
faces->data = AllocMem(BSP_FACE, faces->count, true);
|
lmshifts->count = needlmshifts?facesCount:0;
|
||||||
|
|
||||||
lmshifts->count = needlmshifts?faces->count:0;
|
|
||||||
lmshifts->data = needlmshifts?AllocMem(OTHER, sizeof(uint8_t) * lmshifts->count, true):NULL;
|
lmshifts->data = needlmshifts?AllocMem(OTHER, sizeof(uint8_t) * lmshifts->count, true):NULL;
|
||||||
|
|
||||||
Message(msgProgress, "GrowRegions");
|
Message(msgProgress, "GrowRegions");
|
||||||
|
|
|
||||||
|
|
@ -342,7 +342,7 @@ ExportDrawNodes(mapentity_t *entity, node_t *headnode, int firstface)
|
||||||
dmodel = (dmodel_t *)entity->lumps[LUMP_MODELS].data;
|
dmodel = (dmodel_t *)entity->lumps[LUMP_MODELS].data;
|
||||||
dmodel->headnode[0] = static_cast<int>(map.exported_nodes_bsp29.size());
|
dmodel->headnode[0] = static_cast<int>(map.exported_nodes_bsp29.size());
|
||||||
dmodel->firstface = firstface;
|
dmodel->firstface = firstface;
|
||||||
dmodel->numfaces = map.cTotal[LUMP_FACES] - firstface;
|
dmodel->numfaces = static_cast<int>(map.exported_faces.size()) - firstface;
|
||||||
|
|
||||||
const size_t mapleafsAtStart = map.exported_leafs_bsp29.size();
|
const size_t mapleafsAtStart = map.exported_leafs_bsp29.size();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue