From d2e5955547e9bf193bd91d96f16553f83ca0bfc5 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 7 Apr 2024 00:16:43 +0300 Subject: [PATCH] renders: reuse CalcLumpHunkSize for Leaf and Nodes --- src/client/refresh/files/maps.c | 31 +++++++++++++++++++++++++++++- src/client/refresh/gl1/gl1_model.c | 28 +-------------------------- src/client/refresh/gl3/gl3_model.c | 28 +-------------------------- src/client/refresh/gl4/gl4_model.c | 28 +-------------------------- src/client/refresh/ref_shared.h | 3 ++- src/client/refresh/soft/sw_model.c | 28 +-------------------------- src/client/refresh/vk/vk_model.c | 28 +-------------------------- 7 files changed, 37 insertions(+), 137 deletions(-) diff --git a/src/client/refresh/files/maps.c b/src/client/refresh/files/maps.c index 3db86501..e0c5ffdb 100644 --- a/src/client/refresh/files/maps.c +++ b/src/client/refresh/files/maps.c @@ -1358,7 +1358,8 @@ calcTexinfoAndQFacesSize(const byte *mod_base, const lump_t *fl, const lump_t *t } int -calcTexinfoFacesLeafsSize(const byte *mod_base, const dheader_t *header) +calcTexinfoFacesLeafsSize(const byte *mod_base, const dheader_t *header, + maptype_t maptype) { int hunkSize = 0; @@ -1378,6 +1379,34 @@ calcTexinfoFacesLeafsSize(const byte *mod_base, const dheader_t *header) sizeof(int), sizeof(msurface_t *), 0); // yes, out is indeed a pointer! } + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], + 1, 1, 0); + if ((header->ident == IDBSPHEADER) || + (header->ident == RBSPHEADER)) + { + if ((maptype == map_daikatana) && + (header->lumps[LUMP_LEAFS].filelen % sizeof(ddkleaf_t) == 0)) + { + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], + sizeof(ddkleaf_t), sizeof(mleaf_t), 0); + } + else + { + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], + sizeof(dleaf_t), sizeof(mleaf_t), 0); + } + + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], + sizeof(dnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); + } + else + { + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], + sizeof(dqleaf_t), sizeof(mleaf_t), 0); + hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], + sizeof(dqnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); + } + hunkSize += 5000000; // and 5MB extra just in case return hunkSize; diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index b2cb31a4..4731ec71 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -510,34 +510,8 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen) 1, 1, 0); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), EXTRA_LUMP_PLANES); - hunkSize += calcTexinfoFacesLeafsSize(mod_base, header); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], - 1, 1, 0); - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if ((maptype == map_daikatana) && - (header->lumps[LUMP_LEAFS].filelen % sizeof(ddkleaf_t) == 0)) - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(ddkleaf_t), sizeof(mleaf_t), 0); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dleaf_t), sizeof(mleaf_t), 0); - } + hunkSize += calcTexinfoFacesLeafsSize(mod_base, header, maptype); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dqleaf_t), sizeof(mleaf_t), 0); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dqnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(model_t), 0); diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 6d9cb6bd..647bf78c 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -511,34 +511,8 @@ Mod_LoadBrushModel(gl3model_t *mod, const void *buffer, int modfilelen) 1, 1, 0); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), EXTRA_LUMP_PLANES); - hunkSize += calcTexinfoFacesLeafsSize(mod_base, header); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], - 1, 1, 0); - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if ((maptype == map_daikatana) && - (header->lumps[LUMP_LEAFS].filelen % sizeof(ddkleaf_t) == 0)) - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(ddkleaf_t), sizeof(mleaf_t), 0); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dleaf_t), sizeof(mleaf_t), 0); - } + hunkSize += calcTexinfoFacesLeafsSize(mod_base, header, maptype); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dqleaf_t), sizeof(mleaf_t), 0); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dqnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(gl3model_t), 0); diff --git a/src/client/refresh/gl4/gl4_model.c b/src/client/refresh/gl4/gl4_model.c index 809ed904..93296403 100644 --- a/src/client/refresh/gl4/gl4_model.c +++ b/src/client/refresh/gl4/gl4_model.c @@ -511,34 +511,8 @@ Mod_LoadBrushModel(gl4model_t *mod, const void *buffer, int modfilelen) 1, 1, 0); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), EXTRA_LUMP_PLANES); - hunkSize += calcTexinfoFacesLeafsSize(mod_base, header); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], - 1, 1, 0); - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if ((maptype == map_daikatana) && - (header->lumps[LUMP_LEAFS].filelen % sizeof(ddkleaf_t) == 0)) - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(ddkleaf_t), sizeof(mleaf_t), 0); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dleaf_t), sizeof(mleaf_t), 0); - } + hunkSize += calcTexinfoFacesLeafsSize(mod_base, header, maptype); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dqleaf_t), sizeof(mleaf_t), 0); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dqnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(gl4model_t), 0); diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index 5431b699..2daa7174 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -369,7 +369,8 @@ extern const bspx_header_t *Mod_LoadBSPX(int filesize, const byte *mod_base, maptype_t maptype); extern int Mod_LoadBSPXDecoupledLM(const dlminfo_t* lminfos, int surfnum, msurface_t *out); extern int Mod_LoadFile(const char *name, void **buffer); -extern int calcTexinfoFacesLeafsSize(const byte *mod_base, const dheader_t *header); +extern int calcTexinfoFacesLeafsSize(const byte *mod_base, const dheader_t *header, + maptype_t maptype); /* Surface logic */ #define DLIGHT_CUTOFF 64 diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index a8818460..0d6ebc54 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -497,34 +497,8 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen) 1, 1, 0); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), EXTRA_LUMP_PLANES); - hunkSize += calcTexinfoFacesLeafsSize(mod_base, header); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], - 1, 1, 0); - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if ((maptype == map_daikatana) && - (header->lumps[LUMP_LEAFS].filelen % sizeof(ddkleaf_t) == 0)) - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(ddkleaf_t), sizeof(mleaf_t), 0); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dleaf_t), sizeof(mleaf_t), 0); - } + hunkSize += calcTexinfoFacesLeafsSize(mod_base, header, maptype); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dqleaf_t), sizeof(mleaf_t), 0); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dqnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(model_t), 0); diff --git a/src/client/refresh/vk/vk_model.c b/src/client/refresh/vk/vk_model.c index 8bd2ab9e..210980af 100644 --- a/src/client/refresh/vk/vk_model.c +++ b/src/client/refresh/vk/vk_model.c @@ -485,34 +485,8 @@ Mod_LoadBrushModel(model_t *mod, const void *buffer, int modfilelen) 1, 1, 0); hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_PLANES], sizeof(dplane_t), sizeof(cplane_t), EXTRA_LUMP_PLANES); - hunkSize += calcTexinfoFacesLeafsSize(mod_base, header); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_VISIBILITY], - 1, 1, 0); - if ((header->ident == IDBSPHEADER) || - (header->ident == RBSPHEADER)) - { - if ((maptype == map_daikatana) && - (header->lumps[LUMP_LEAFS].filelen % sizeof(ddkleaf_t) == 0)) - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(ddkleaf_t), sizeof(mleaf_t), 0); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dleaf_t), sizeof(mleaf_t), 0); - } + hunkSize += calcTexinfoFacesLeafsSize(mod_base, header, maptype); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } - else - { - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_LEAFS], - sizeof(dqleaf_t), sizeof(mleaf_t), 0); - hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_NODES], - sizeof(dqnode_t), sizeof(mnode_t), EXTRA_LUMP_NODES); - } hunkSize += Mod_CalcLumpHunkSize(&header->lumps[LUMP_MODELS], sizeof(dmodel_t), sizeof(model_t), 0);