qbsp: refactor model writing
This commit is contained in:
parent
c3d338616b
commit
561ffffb9b
|
|
@ -104,6 +104,7 @@ public:
|
|||
struct lumpdata lumps[BSPX_LUMPS];
|
||||
|
||||
int firstoutputfacenumber;
|
||||
int outputmodelnumber;
|
||||
|
||||
const mapbrush_t &mapbrush(int i) const;
|
||||
|
||||
|
|
@ -119,7 +120,8 @@ public:
|
|||
epairs(nullptr),
|
||||
brushes(nullptr),
|
||||
numbrushes(0),
|
||||
firstoutputfacenumber(-1) {
|
||||
firstoutputfacenumber(-1),
|
||||
outputmodelnumber(-1) {
|
||||
VectorSet(origin,0,0,0);
|
||||
VectorSet(mins,0,0,0);
|
||||
VectorSet(maxs,0,0,0);
|
||||
|
|
@ -167,6 +169,7 @@ typedef struct mapdata_s {
|
|||
std::vector<dvertex_t> exported_vertexes;
|
||||
std::vector<int> exported_surfedges;
|
||||
std::vector<bsp29_dface_t> exported_faces;
|
||||
std::vector<dmodelq1_t> exported_models;
|
||||
|
||||
// helpers
|
||||
std::string texinfoTextureName(int texinfo) const {
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ WriteBSPFile(void)
|
|||
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_EDGES, map.exported_edges.data(), map.exported_edges.size() * sizeof(map.exported_edges[0]));
|
||||
AddLump(f, LUMP_MODELS);
|
||||
AddLumpFromBuffer(f, LUMP_MODELS, map.exported_models.data(), map.exported_models.size() * sizeof(map.exported_models[0]));
|
||||
|
||||
AddLump(f, LUMP_LIGHTING);
|
||||
AddLump(f, LUMP_VISIBILITY);
|
||||
|
|
|
|||
11
qbsp/qbsp.cc
11
qbsp/qbsp.cc
|
|
@ -58,12 +58,18 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
|
|||
if (IsWorldBrushEntity(entity))
|
||||
return;
|
||||
|
||||
// Export a blank model struct, and reserve the index (only do this once, for all hulls)
|
||||
if (entity->outputmodelnumber == -1) {
|
||||
entity->outputmodelnumber = static_cast<int>(map.exported_models.size());
|
||||
map.exported_models.push_back({});
|
||||
}
|
||||
|
||||
if (entity != pWorldEnt()) {
|
||||
char mod[20];
|
||||
|
||||
if (entity == pWorldEnt() + 1)
|
||||
Message(msgProgress, "Internal Entities");
|
||||
q_snprintf(mod, sizeof(mod), "*%d", map.cTotal[LUMP_MODELS]);
|
||||
q_snprintf(mod, sizeof(mod), "*%d", entity->outputmodelnumber);
|
||||
if (options.fVerbose)
|
||||
PrintEntity(entity);
|
||||
|
||||
|
|
@ -242,8 +248,6 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
|
|||
}
|
||||
|
||||
FreeBrushes(entity);
|
||||
|
||||
map.cTotal[LUMP_MODELS]++;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -541,7 +545,6 @@ CreateSingleHull(const int hullnum)
|
|||
mapentity_t *entity;
|
||||
|
||||
Message(msgLiteral, "Processing hull %d...\n", hullnum);
|
||||
map.cTotal[LUMP_MODELS] = 0;
|
||||
|
||||
// for each entity in the map file that has geometry
|
||||
for (i = 0; i < map.numentities(); i++) {
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ accomodate new data interleaved with old.
|
|||
void
|
||||
ExportClipNodes(mapentity_t *entity, node_t *nodes, const int hullnum)
|
||||
{
|
||||
dmodel_t *model = (dmodel_t *)entity->lumps[LUMP_MODELS].data;
|
||||
auto *model = &map.exported_models.at(static_cast<size_t>(entity->outputmodelnumber));
|
||||
|
||||
model->headnode[hullnum] = ExportClipNodes_BSP29(entity, nodes);
|
||||
}
|
||||
|
|
@ -295,14 +295,10 @@ void
|
|||
ExportDrawNodes(mapentity_t *entity, node_t *headnode, int firstface)
|
||||
{
|
||||
int i;
|
||||
dmodel_t *dmodel;
|
||||
dmodelq1_t *dmodel;
|
||||
|
||||
// Allocate a model
|
||||
entity->lumps[LUMP_MODELS].data = AllocMem(BSP_MODEL, 1, true);
|
||||
entity->lumps[LUMP_MODELS].count = 1;
|
||||
|
||||
// emit a model
|
||||
dmodel = (dmodel_t *)entity->lumps[LUMP_MODELS].data;
|
||||
// populate model struct (which was emitted previously)
|
||||
dmodel = &map.exported_models.at(static_cast<size_t>(entity->outputmodelnumber));
|
||||
dmodel->headnode[0] = static_cast<int>(map.exported_nodes_bsp29.size());
|
||||
dmodel->firstface = firstface;
|
||||
dmodel->numfaces = static_cast<int>(map.exported_faces.size()) - firstface;
|
||||
|
|
|
|||
Loading…
Reference in New Issue