qbsp: refactor texdata writing
This commit is contained in:
parent
6a7e59026c
commit
a7fd04af12
|
|
@ -171,6 +171,7 @@ typedef struct mapdata_s {
|
|||
std::vector<bsp29_dface_t> exported_faces;
|
||||
std::vector<dmodelq1_t> exported_models;
|
||||
std::string exported_entities;
|
||||
std::string exported_texdata;
|
||||
|
||||
// helpers
|
||||
std::string texinfoTextureName(int texinfo) const {
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ WriteBSPFile(void)
|
|||
AddLumpFromBuffer(f, LUMP_LIGHTING, nullptr, 0);
|
||||
AddLumpFromBuffer(f, LUMP_VISIBILITY, nullptr, 0);
|
||||
AddLumpFromBuffer(f, LUMP_ENTITIES, map.exported_entities.data(), map.exported_entities.size() + 1); // +1 to write the terminating null (safe in C++11)
|
||||
AddLump(f, LUMP_TEXTURES);
|
||||
AddLumpFromBuffer(f, LUMP_TEXTURES, map.exported_texdata.data(), map.exported_texdata.size());
|
||||
|
||||
GenLump("LMSHIFT", BSPX_LMSHIFT, 1);
|
||||
|
||||
|
|
@ -392,10 +392,9 @@ PrintBSPFileSizes(void)
|
|||
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]);
|
||||
|
||||
lump = &pWorldEnt()->lumps[LUMP_TEXTURES];
|
||||
if (lump->data)
|
||||
if (!map.exported_texdata.empty())
|
||||
Message(msgStat, "%8d textures %10d",
|
||||
((dmiptexlump_t *)lump->data)->nummiptex, lump->count);
|
||||
((dmiptexlump_t *)map.exported_texdata.data())->nummiptex, map.exported_texdata.size());
|
||||
else
|
||||
Message(msgStat, " 0 textures 0");
|
||||
|
||||
|
|
|
|||
14
qbsp/wad.cc
14
qbsp/wad.cc
|
|
@ -199,24 +199,23 @@ WADList_Process(const wad_t *wadlist)
|
|||
int i;
|
||||
lumpinfo_t *texture;
|
||||
dmiptexlump_t *miptexlump;
|
||||
struct lumpdata *texdata = &pWorldEnt()->lumps[LUMP_TEXTURES];
|
||||
|
||||
|
||||
WADList_AddAnimationFrames(wadlist);
|
||||
|
||||
/* Count space for miptex header/offsets */
|
||||
texdata->count = offsetof(dmiptexlump_t, dataofs[0]) + (map.nummiptex() * sizeof(uint32_t));
|
||||
size_t texdatasize = offsetof(dmiptexlump_t, dataofs[0]) + (map.nummiptex() * sizeof(uint32_t));
|
||||
|
||||
/* Count texture size. Slower, but saves memory. */
|
||||
for (i = 0; i < map.nummiptex(); i++) {
|
||||
texture = WADList_FindTexture(wadlist, map.miptex.at(i).c_str());
|
||||
if (texture) {
|
||||
texdata->count += texture->size;
|
||||
texdatasize += texture->size;
|
||||
}
|
||||
}
|
||||
|
||||
/* Default texture data to store in worldmodel */
|
||||
texdata->data = AllocMem(BSP_TEX, texdata->count, true);
|
||||
miptexlump = (dmiptexlump_t *)texdata->data;
|
||||
map.exported_texdata = std::string(texdatasize, '\0');
|
||||
miptexlump = (dmiptexlump_t *)map.exported_texdata.data();
|
||||
miptexlump->nummiptex = map.nummiptex();
|
||||
|
||||
WADList_LoadTextures(wadlist, miptexlump);
|
||||
|
|
@ -236,7 +235,6 @@ WADList_LoadTextures(const wad_t *wadlist, dmiptexlump_t *lump)
|
|||
int i, size;
|
||||
uint8_t *data;
|
||||
const wad_t *wad;
|
||||
struct lumpdata *texdata = &pWorldEnt()->lumps[LUMP_TEXTURES];
|
||||
|
||||
data = (uint8_t *)&lump->dataofs[map.nummiptex()];
|
||||
|
||||
|
|
@ -251,7 +249,7 @@ WADList_LoadTextures(const wad_t *wadlist, dmiptexlump_t *lump)
|
|||
}
|
||||
if (!size)
|
||||
continue;
|
||||
if (data + size - (uint8_t *)texdata->data > texdata->count)
|
||||
if (data + size - (uint8_t *)map.exported_texdata.data() > map.exported_texdata.size())
|
||||
Error("Internal error: not enough texture memory allocated");
|
||||
lump->dataofs[i] = data - (uint8_t *)lump;
|
||||
data += size;
|
||||
|
|
|
|||
Loading…
Reference in New Issue