qbsp: refactor clipnode writing (changes .bsp output)
- drop reshuffling feature from ExportClipNodes As far as I can tell, the only purpose of this was to keep clipnodes for a given model contiguous within the lump (i.e. keep the different hulls contiguous). Vanilla qbsp didn't appear to have done this, and the code was unmaintainable/complex, so I'm dropping the feature.
This commit is contained in:
parent
bc5e743817
commit
671bacf30c
|
|
@ -159,6 +159,7 @@ typedef struct mapdata_s {
|
|||
std::vector<bsp29_dleaf_t> exported_leafs_bsp29; // FIXME: change to generic leaf
|
||||
std::vector<bsp29_dnode_t> exported_nodes_bsp29; // FIXME: change to generic node
|
||||
std::vector<uint16_t> exported_marksurfaces; // FIXME: change type to generic
|
||||
std::vector<bsp29_dclipnode_t> exported_clipnodes;
|
||||
|
||||
// helpers
|
||||
std::string texinfoTextureName(int texinfo) const {
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ WriteBSPFile(void)
|
|||
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]));
|
||||
AddLump(f, LUMP_FACES);
|
||||
AddLump(f, LUMP_CLIPNODES);
|
||||
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);
|
||||
AddLump(f, LUMP_EDGES);
|
||||
|
|
@ -386,7 +386,7 @@ PrintBSPFileSizes(void)
|
|||
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 faces %10d", map.cTotal[LUMP_FACES], map.cTotal[LUMP_FACES] * MemSize[BSP_FACE]);
|
||||
Message(msgStat, "%8d clipnodes %10d", map.cTotal[LUMP_CLIPNODES], map.cTotal[LUMP_CLIPNODES] * 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 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]);
|
||||
|
|
|
|||
|
|
@ -114,24 +114,6 @@ ExportMapTexinfo(int texinfonum)
|
|||
|
||||
//===========================================================================
|
||||
|
||||
|
||||
/*
|
||||
==================
|
||||
CountClipNodes_r
|
||||
==================
|
||||
*/
|
||||
static void
|
||||
CountClipNodes_r(mapentity_t *entity, node_t *node)
|
||||
{
|
||||
if (node->planenum == -1)
|
||||
return;
|
||||
|
||||
entity->lumps[LUMP_CLIPNODES].count++;
|
||||
|
||||
CountClipNodes_r(entity, node->children[0]);
|
||||
CountClipNodes_r(entity, node->children[1]);
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
ExportClipNodes
|
||||
|
|
@ -140,10 +122,8 @@ ExportClipNodes
|
|||
static int
|
||||
ExportClipNodes_BSP29(mapentity_t *entity, node_t *node)
|
||||
{
|
||||
int nodenum;
|
||||
bsp29_dclipnode_t *clipnode;
|
||||
face_t *face, *next;
|
||||
struct lumpdata *clipnodes = &entity->lumps[LUMP_CLIPNODES];
|
||||
|
||||
// FIXME: free more stuff?
|
||||
if (node->planenum == -1) {
|
||||
|
|
@ -153,14 +133,17 @@ ExportClipNodes_BSP29(mapentity_t *entity, node_t *node)
|
|||
}
|
||||
|
||||
/* emit a clipnode */
|
||||
clipnode = (bsp29_dclipnode_t *)clipnodes->data + clipnodes->index;
|
||||
clipnodes->index++;
|
||||
nodenum = map.cTotal[LUMP_CLIPNODES];
|
||||
map.cTotal[LUMP_CLIPNODES]++;
|
||||
const int nodenum = static_cast<int>(map.exported_clipnodes.size());
|
||||
map.exported_clipnodes.push_back({});
|
||||
|
||||
const int child0 = ExportClipNodes_BSP29(entity, node->children[0]);
|
||||
const int child1 = ExportClipNodes_BSP29(entity, node->children[1]);
|
||||
|
||||
// Careful not to modify the vector while using this clipnode pointer
|
||||
clipnode = &map.exported_clipnodes.at(nodenum);
|
||||
clipnode->planenum = ExportMapPlane(node->planenum);
|
||||
clipnode->children[0] = ExportClipNodes_BSP29(entity, node->children[0]);
|
||||
clipnode->children[1] = ExportClipNodes_BSP29(entity, node->children[1]);
|
||||
clipnode->children[0] = child0;
|
||||
clipnode->children[1] = child1;
|
||||
|
||||
for (face = node->faces; face; face = next) {
|
||||
next = face->next;
|
||||
|
|
@ -172,6 +155,7 @@ ExportClipNodes_BSP29(mapentity_t *entity, node_t *node)
|
|||
return nodenum;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int
|
||||
ExportClipNodes_BSP2(mapentity_t *entity, node_t *node)
|
||||
{
|
||||
|
|
@ -206,6 +190,7 @@ ExportClipNodes_BSP2(mapentity_t *entity, node_t *node)
|
|||
|
||||
return nodenum;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
==================
|
||||
|
|
@ -222,61 +207,9 @@ accomodate new data interleaved with old.
|
|||
void
|
||||
ExportClipNodes(mapentity_t *entity, node_t *nodes, const int hullnum)
|
||||
{
|
||||
int oldcount, i, diff;
|
||||
int clipcount = 0;
|
||||
void *olddata;
|
||||
struct lumpdata *clipnodes = &entity->lumps[LUMP_CLIPNODES];
|
||||
dmodel_t *model = (dmodel_t *)entity->lumps[LUMP_MODELS].data;
|
||||
|
||||
oldcount = clipnodes->count;
|
||||
|
||||
/* Count nodes before this one */
|
||||
const int entnum = entity - &map.entities.at(0);
|
||||
for (i = 0; i < entnum; i++)
|
||||
clipcount += map.entities.at(i).lumps[LUMP_CLIPNODES].count;
|
||||
model->headnode[hullnum] = clipcount + oldcount;
|
||||
|
||||
CountClipNodes_r(entity, nodes);
|
||||
if (clipnodes->count > MAX_BSP_CLIPNODES && (options.BSPVersion == BSPVERSION || options.BSPVersion == BSPHLVERSION))
|
||||
Error("Clipnode count exceeds bsp 29 max (%d > %d)",
|
||||
clipnodes->count, MAX_BSP_CLIPNODES);
|
||||
|
||||
olddata = clipnodes->data;
|
||||
clipnodes->data = AllocMem(BSP_CLIPNODE, clipnodes->count, true);
|
||||
if (olddata) {
|
||||
memcpy(clipnodes->data, olddata, oldcount * MemSize[BSP_CLIPNODE]);
|
||||
FreeMem(olddata, BSP_CLIPNODE, oldcount);
|
||||
|
||||
/* Worth special-casing for entity 0 (no modification needed) */
|
||||
diff = clipcount - model->headnode[1];
|
||||
if (diff != 0) {
|
||||
for (i = 1; i < hullnum; i++)
|
||||
model->headnode[i] += diff;
|
||||
if (options.BSPVersion == BSPVERSION || options.BSPVersion == BSPHLVERSION) {
|
||||
bsp29_dclipnode_t *clipnode = (bsp29_dclipnode_t *)clipnodes->data;
|
||||
for (i = 0; i < oldcount; i++, clipnode++) {
|
||||
if (clipnode->children[0] < MAX_BSP_CLIPNODES)
|
||||
clipnode->children[0] += diff;
|
||||
if (clipnode->children[1] < MAX_BSP_CLIPNODES)
|
||||
clipnode->children[1] += diff;
|
||||
}
|
||||
} else {
|
||||
bsp2_dclipnode_t *clipnode = (bsp2_dclipnode_t *)clipnodes->data;
|
||||
for (i = 0; i < oldcount; i++, clipnode++) {
|
||||
if (clipnode->children[0] >= 0)
|
||||
clipnode->children[0] += diff;
|
||||
if (clipnode->children[1] >= 0)
|
||||
clipnode->children[1] += diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map.cTotal[LUMP_CLIPNODES] = clipcount + oldcount;
|
||||
if (options.BSPVersion == BSPVERSION || options.BSPVersion == BSPHLVERSION)
|
||||
ExportClipNodes_BSP29(entity, nodes);
|
||||
else
|
||||
ExportClipNodes_BSP2(entity, nodes);
|
||||
model->headnode[hullnum] = ExportClipNodes_BSP29(entity, nodes);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
|
|
|||
Loading…
Reference in New Issue