qbsp: refactor texinfo lump writing
This commit is contained in:
parent
eaa86c71c6
commit
460428d099
|
|
@ -153,6 +153,9 @@ typedef struct mapdata_s {
|
|||
/* Misc other global state for the compile process */
|
||||
bool leakfile; /* Flag once we've written a leak (.por/.pts) file */
|
||||
|
||||
// Final, exported data
|
||||
std::vector<texinfo_t> exported_texinfos; // FIXME: change to gtexinfo_t
|
||||
|
||||
// helpers
|
||||
std::string texinfoTextureName(int texinfo) const {
|
||||
int mt = mtexinfos.at(texinfo).miptex;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ int ExportMapPlane(int planenum);
|
|||
int ExportMapTexinfo(int texinfonum);
|
||||
|
||||
void AllocBSPPlanes();
|
||||
void AllocBSPTexinfo();
|
||||
|
||||
void BeginBSPFile(void);
|
||||
void FinishBSPFile(void);
|
||||
|
|
|
|||
|
|
@ -191,6 +191,34 @@ AddLump(FILE *f, int Type)
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: remove this once we switch to common
|
||||
static void
|
||||
AddLumpFromBuffer(FILE *f, int Type, void* src, size_t srcbytes)
|
||||
{
|
||||
lump_t *lump;
|
||||
size_t ret;
|
||||
const mapentity_t *entity;
|
||||
|
||||
lump = &header->lumps[Type];
|
||||
lump->fileofs = ftell(f);
|
||||
|
||||
if (srcbytes) {
|
||||
ret = fwrite(src, 1, srcbytes, f);
|
||||
if (ret != srcbytes)
|
||||
Error("Failure writing to file");
|
||||
}
|
||||
|
||||
lump->filelen = srcbytes;
|
||||
|
||||
// Pad to 4-byte boundary
|
||||
if (srcbytes % 4 != 0) {
|
||||
size_t pad = 4 - (srcbytes % 4);
|
||||
ret = fwrite(" ", 1, pad, f);
|
||||
if (ret != pad)
|
||||
Error("Failure writing to file");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
GenLump(const char *bspxlump, int Type, size_t sz)
|
||||
{
|
||||
|
|
@ -269,7 +297,7 @@ WriteBSPFile(void)
|
|||
AddLump(f, LUMP_LEAFS);
|
||||
AddLump(f, LUMP_VERTEXES);
|
||||
AddLump(f, LUMP_NODES);
|
||||
AddLump(f, LUMP_TEXINFO);
|
||||
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);
|
||||
AddLump(f, LUMP_MARKSURFACES);
|
||||
|
|
@ -356,7 +384,7 @@ PrintBSPFileSizes(void)
|
|||
Message(msgStat, "%8d planes %10d", map.cTotal[LUMP_PLANES], map.cTotal[LUMP_PLANES] * MemSize[BSP_PLANE]);
|
||||
Message(msgStat, "%8d vertexes %10d", map.cTotal[LUMP_VERTEXES], map.cTotal[LUMP_VERTEXES] * MemSize[BSP_VERTEX]);
|
||||
Message(msgStat, "%8d nodes %10d", map.cTotal[LUMP_NODES], map.cTotal[LUMP_NODES] * MemSize[BSP_NODE]);
|
||||
Message(msgStat, "%8d texinfo %10d", map.cTotal[LUMP_TEXINFO], map.cTotal[LUMP_TEXINFO] * 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 clipnodes %10d", map.cTotal[LUMP_CLIPNODES], map.cTotal[LUMP_CLIPNODES] * MemSize[BSP_CLIPNODE]);
|
||||
Message(msgStat, "%8d leafs %10d", map.cTotal[LUMP_LEAFS], map.cTotal[LUMP_LEAFS] * MemSize[BSP_LEAF]);
|
||||
|
|
|
|||
|
|
@ -179,7 +179,6 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
|
|||
}
|
||||
}
|
||||
AllocBSPPlanes();
|
||||
AllocBSPTexinfo();
|
||||
ExportClipNodes(entity, nodes, hullnum);
|
||||
} else {
|
||||
/*
|
||||
|
|
@ -235,7 +234,6 @@ ProcessEntity(mapentity_t *entity, const int hullnum)
|
|||
DetailToSolid(nodes);
|
||||
|
||||
AllocBSPPlanes();
|
||||
AllocBSPTexinfo();
|
||||
|
||||
if (options.fObjExport && entity == pWorldEnt()) {
|
||||
ExportObj_Nodes("pre_makefaceedges_plane_faces", nodes);
|
||||
|
|
|
|||
|
|
@ -102,14 +102,13 @@ ExportMapTexinfo(int texinfonum)
|
|||
if (src->outputnum != -1)
|
||||
return src->outputnum;
|
||||
|
||||
struct lumpdata *texinfo = &pWorldEnt()->lumps[LUMP_TEXINFO];
|
||||
// this will be the index of the exported texinfo in the BSP lump
|
||||
const int i = static_cast<int>(map.exported_texinfos.size());
|
||||
|
||||
if (texinfo->index >= texinfo->count)
|
||||
Error("Internal error: texinfo count mismatch (%s)", __func__);
|
||||
map.exported_texinfos.push_back({});
|
||||
texinfo_t* dest = &map.exported_texinfos.back();
|
||||
memset(dest, 0, sizeof(dest));
|
||||
|
||||
const int i = texinfo->index;
|
||||
|
||||
texinfo_t *dest = &(static_cast<texinfo_t *>(texinfo->data)[i]);
|
||||
dest->flags = static_cast<int32_t>(src->flags & TEX_SPECIAL);
|
||||
dest->miptex = src->miptex;
|
||||
for (int j=0; j<2; j++) {
|
||||
|
|
@ -118,11 +117,6 @@ ExportMapTexinfo(int texinfonum)
|
|||
}
|
||||
}
|
||||
|
||||
texinfo->index++;
|
||||
map.cTotal[LUMP_TEXINFO]++;
|
||||
|
||||
Q_assert(texinfo->index == map.cTotal[LUMP_TEXINFO]);
|
||||
|
||||
src->outputnum = i;
|
||||
return i;
|
||||
}
|
||||
|
|
@ -150,29 +144,6 @@ AllocBSPPlanes()
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
AllocBSPTexinfo
|
||||
==================
|
||||
*/
|
||||
void
|
||||
AllocBSPTexinfo()
|
||||
{
|
||||
struct lumpdata *texinfo = &pWorldEnt()->lumps[LUMP_TEXINFO];
|
||||
|
||||
// OK just need one plane array, stick it in worldmodel
|
||||
if (map.numtexinfo() > texinfo->count) {
|
||||
int newcount = map.numtexinfo();
|
||||
struct lumpdata *newtexinfo = (struct lumpdata *)AllocMem(BSP_TEXINFO, newcount, true);
|
||||
|
||||
memcpy(newtexinfo, texinfo->data, MemSize[BSP_TEXINFO] * texinfo->count);
|
||||
FreeMem(texinfo->data, BSP_TEXINFO, texinfo->count);
|
||||
|
||||
texinfo->count = newcount;
|
||||
texinfo->data = newtexinfo;
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
||||
|
||||
|
|
@ -835,7 +806,7 @@ WriteExtendedTexinfoFlags(void)
|
|||
fprintf(texinfofile, "%llu\n", static_cast<unsigned long long>(tx.flags));
|
||||
count++;
|
||||
}
|
||||
Q_assert(count == map.cTotal[LUMP_TEXINFO]);
|
||||
Q_assert(count == static_cast<int>(map.exported_texinfos.size()));
|
||||
|
||||
fclose(texinfofile);
|
||||
}
|
||||
|
|
@ -855,9 +826,6 @@ FinishBSPFile(void)
|
|||
struct lumpdata *planes = &pWorldEnt()->lumps[LUMP_PLANES];
|
||||
planes->count = map.cTotal[LUMP_PLANES];
|
||||
|
||||
struct lumpdata *texinfo = &pWorldEnt()->lumps[LUMP_TEXINFO];
|
||||
texinfo->count = map.cTotal[LUMP_TEXINFO];
|
||||
|
||||
WriteExtendedTexinfoFlags();
|
||||
WriteBSPFile();
|
||||
PrintBSPFileSizes();
|
||||
|
|
|
|||
Loading…
Reference in New Issue