From 4463e1fcd7b3a19986771b607b50f4b8c4acb709 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Mon, 24 Oct 2022 23:49:52 +0300 Subject: [PATCH] Share mnode_t and mleaf_t struct between renders. --- src/client/refresh/files/models.c | 80 ++++++++++++++++++++++++++ src/client/refresh/gl1/gl1_light.c | 4 +- src/client/refresh/gl1/gl1_model.c | 73 +---------------------- src/client/refresh/gl1/gl1_surf.c | 4 +- src/client/refresh/gl1/header/model.h | 36 ------------ src/client/refresh/gl3/gl3_light.c | 4 +- src/client/refresh/gl3/gl3_model.c | 73 +---------------------- src/client/refresh/gl3/gl3_surf.c | 2 +- src/client/refresh/gl3/header/model.h | 36 ------------ src/client/refresh/ref_shared.h | 45 ++++++++++++++- src/client/refresh/soft/header/model.h | 41 ------------- src/client/refresh/soft/sw_bsp.c | 8 +-- src/client/refresh/soft/sw_light.c | 4 +- src/client/refresh/soft/sw_misc.c | 2 +- src/client/refresh/soft/sw_model.c | 77 +------------------------ 15 files changed, 145 insertions(+), 344 deletions(-) diff --git a/src/client/refresh/files/models.c b/src/client/refresh/files/models.c index ece7ab29..be85a5ce 100644 --- a/src/client/refresh/files/models.c +++ b/src/client/refresh/files/models.c @@ -295,3 +295,83 @@ Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata, // Unknow format, no images associated with it return 0; } + +/* +================= +Mod_SetParent +================= +*/ +static void +Mod_SetParent(mnode_t *node, mnode_t *parent) +{ + node->parent = parent; + if (node->contents != CONTENTS_NODE) + { + return; + } + + Mod_SetParent (node->children[0], node); + Mod_SetParent (node->children[1], node); +} + +/* +================= +Mod_LoadNodes +================= +*/ +void +Mod_LoadNodes(const char *name, cplane_t *planes, struct mleaf_s *leafs, + mnode_t **nodes, int *numnodes, const byte *mod_base, const lump_t *l) +{ + int i, count; + dnode_t *in; + mnode_t *out; + + in = (void *)(mod_base + l->fileofs); + + if (l->filelen % sizeof(*in)) + { + ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s", + __func__, name); + } + + count = l->filelen / sizeof(*in); + out = Hunk_Alloc(count * sizeof(*out)); + + *nodes = out; + *numnodes = count; + + for (i = 0; i < count; i++, in++, out++) + { + int j, p; + + for (j = 0; j < 3; j++) + { + out->minmaxs[j] = LittleShort(in->mins[j]); + out->minmaxs[3 + j] = LittleShort(in->maxs[j]); + } + + p = LittleLong(in->planenum); + out->plane = planes + p; + + out->firstsurface = LittleShort(in->firstface); + out->numsurfaces = LittleShort(in->numfaces); + out->contents = CONTENTS_NODE; /* differentiate from leafs */ + + for (j = 0; j < 2; j++) + { + p = LittleLong(in->children[j]); + + if (p >= 0) + { + out->children[j] = *nodes + p; + } + else + { + out->children[j] = (mnode_t *)(leafs + (-1 - p)); + } + } + } + + Mod_SetParent(*nodes, NULL); /* sets nodes and leafs */ +} diff --git a/src/client/refresh/gl1/gl1_light.c b/src/client/refresh/gl1/gl1_light.c index 84f981f4..300d31df 100644 --- a/src/client/refresh/gl1/gl1_light.c +++ b/src/client/refresh/gl1/gl1_light.c @@ -129,7 +129,7 @@ R_MarkLights(dlight_t *light, int bit, mnode_t *node) int i; int sidebit; - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { return; } @@ -220,7 +220,7 @@ R_RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end) int maps; int r; - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { return -1; /* didn't hit anything */ } diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index a7d860e7..c84851b0 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -86,7 +86,7 @@ Mod_PointInLeaf(vec3_t p, model_t *model) while (1) { - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { return (mleaf_t *)node; } @@ -753,74 +753,6 @@ Mod_LoadFaces(model_t *loadmodel, byte *mod_base, lump_t *l) LM_EndBuildingLightmaps(); } -static void -Mod_SetParent(mnode_t *node, mnode_t *parent) -{ - node->parent = parent; - - if (node->contents != -1) - { - return; - } - - Mod_SetParent(node->children[0], node); - Mod_SetParent(node->children[1], node); -} - -static void -Mod_LoadNodes(model_t *loadmodel, byte *mod_base, lump_t *l) -{ - int i, j, count, p; - dnode_t *in; - mnode_t *out; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc(count * sizeof(*out)); - - loadmodel->nodes = out; - loadmodel->numnodes = count; - - for (i = 0; i < count; i++, in++, out++) - { - for (j = 0; j < 3; j++) - { - out->minmaxs[j] = LittleShort(in->mins[j]); - out->minmaxs[3 + j] = LittleShort(in->maxs[j]); - } - - p = LittleLong(in->planenum); - out->plane = loadmodel->planes + p; - - out->firstsurface = LittleShort(in->firstface); - out->numsurfaces = LittleShort(in->numfaces); - out->contents = -1; /* differentiate from leafs */ - - for (j = 0; j < 2; j++) - { - p = LittleLong(in->children[j]); - - if (p >= 0) - { - out->children[j] = loadmodel->nodes + p; - } - else - { - out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p)); - } - } - } - - Mod_SetParent(loadmodel->nodes, NULL); /* sets nodes and leafs */ -} - static void Mod_LoadLeafs(model_t *loadmodel, byte *mod_base, lump_t *l) { @@ -1063,7 +995,8 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen) Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]); Mod_LoadVisibility(mod, mod_base, &header->lumps[LUMP_VISIBILITY]); Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]); - Mod_LoadNodes(mod, mod_base, &header->lumps[LUMP_NODES]); + Mod_LoadNodes(mod->name, mod->planes, mod->leafs, &mod->nodes, + &mod->numnodes, mod_base, &header->lumps[LUMP_NODES]); Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]); mod->numframes = 2; /* regular and alternate animation */ } diff --git a/src/client/refresh/gl1/gl1_surf.c b/src/client/refresh/gl1/gl1_surf.c index f501f23b..f420dafa 100644 --- a/src/client/refresh/gl1/gl1_surf.c +++ b/src/client/refresh/gl1/gl1_surf.c @@ -122,7 +122,7 @@ R_DrawGLFlowingPoly(msurface_t *fa) glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); - + YQ2_VLAFREE(tex); } @@ -837,7 +837,7 @@ R_RecursiveWorldNode(entity_t *currententity, mnode_t *node) } /* if a leaf node, draw stuff */ - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { pleaf = (mleaf_t *)node; diff --git a/src/client/refresh/gl1/header/model.h b/src/client/refresh/gl1/header/model.h index 2da1e9f7..87e071cc 100644 --- a/src/client/refresh/gl1/header/model.h +++ b/src/client/refresh/gl1/header/model.h @@ -72,42 +72,6 @@ typedef struct msurface_s byte *samples; /* [numstyles*surfsize] */ } msurface_t; -typedef struct mnode_s -{ - /* common with leaf */ - int contents; /* -1, to differentiate from leafs */ - int visframe; /* node needs to be traversed if current */ - - float minmaxs[6]; /* for bounding box culling */ - - struct mnode_s *parent; - - /* node specific */ - cplane_t *plane; - struct mnode_s *children[2]; - - unsigned short firstsurface; - unsigned short numsurfaces; -} mnode_t; - -typedef struct mleaf_s -{ - /* common with node */ - int contents; /* wil be a negative contents number */ - int visframe; /* node needs to be traversed if current */ - - float minmaxs[6]; /* for bounding box culling */ - - struct mnode_s *parent; - - /* leaf specific */ - int cluster; - int area; - - msurface_t **firstmarksurface; - int nummarksurfaces; -} mleaf_t; - /* Whole model */ typedef struct model_s diff --git a/src/client/refresh/gl3/gl3_light.c b/src/client/refresh/gl3/gl3_light.c index f33594ad..78afab6e 100644 --- a/src/client/refresh/gl3/gl3_light.c +++ b/src/client/refresh/gl3/gl3_light.c @@ -45,7 +45,7 @@ GL3_MarkLights(dlight_t *light, int bit, mnode_t *node) int i; int sidebit; - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { return; } @@ -147,7 +147,7 @@ RecursiveLightPoint(mnode_t *node, vec3_t start, vec3_t end) int maps; int r; - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { return -1; /* didn't hit anything */ } diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index 2b1f3c85..770a41be 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -80,7 +80,7 @@ GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model) while (1) { - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { return (mleaf_t *)node; } @@ -623,74 +623,6 @@ Mod_LoadFaces(gl3model_t *loadmodel, byte *mod_base, lump_t *l) GL3_LM_EndBuildingLightmaps(); } -static void -Mod_SetParent(mnode_t *node, mnode_t *parent) -{ - node->parent = parent; - - if (node->contents != -1) - { - return; - } - - Mod_SetParent(node->children[0], node); - Mod_SetParent(node->children[1], node); -} - -static void -Mod_LoadNodes(gl3model_t *loadmodel, byte *mod_base, lump_t *l) -{ - int i, j, count, p; - dnode_t *in; - mnode_t *out; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc(count * sizeof(*out)); - - loadmodel->nodes = out; - loadmodel->numnodes = count; - - for (i = 0; i < count; i++, in++, out++) - { - for (j = 0; j < 3; j++) - { - out->minmaxs[j] = LittleShort(in->mins[j]); - out->minmaxs[3 + j] = LittleShort(in->maxs[j]); - } - - p = LittleLong(in->planenum); - out->plane = loadmodel->planes + p; - - out->firstsurface = LittleShort(in->firstface); - out->numsurfaces = LittleShort(in->numfaces); - out->contents = -1; /* differentiate from leafs */ - - for (j = 0; j < 2; j++) - { - p = LittleLong(in->children[j]); - - if (p >= 0) - { - out->children[j] = loadmodel->nodes + p; - } - else - { - out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p)); - } - } - } - - Mod_SetParent(loadmodel->nodes, NULL); /* sets nodes and leafs */ -} - static void Mod_LoadLeafs(gl3model_t *loadmodel, byte *mod_base, lump_t *l) { @@ -932,7 +864,8 @@ Mod_LoadBrushModel(gl3model_t *mod, void *buffer, int modfilelen) Mod_LoadMarksurfaces(mod, mod_base, &header->lumps[LUMP_LEAFFACES]); Mod_LoadVisibility(mod, mod_base, &header->lumps[LUMP_VISIBILITY]); Mod_LoadLeafs(mod, mod_base, &header->lumps[LUMP_LEAFS]); - Mod_LoadNodes(mod, mod_base, &header->lumps[LUMP_NODES]); + Mod_LoadNodes(mod->name, mod->planes, mod->leafs, &mod->nodes, + &mod->numnodes, mod_base, &header->lumps[LUMP_NODES]); Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]); mod->numframes = 2; /* regular and alternate animation */ } diff --git a/src/client/refresh/gl3/gl3_surf.c b/src/client/refresh/gl3/gl3_surf.c index 0647ea47..ece8098b 100644 --- a/src/client/refresh/gl3/gl3_surf.c +++ b/src/client/refresh/gl3/gl3_surf.c @@ -694,7 +694,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node) } /* if a leaf node, draw stuff */ - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { pleaf = (mleaf_t *)node; diff --git a/src/client/refresh/gl3/header/model.h b/src/client/refresh/gl3/header/model.h index 3c67c4be..738ff50a 100644 --- a/src/client/refresh/gl3/header/model.h +++ b/src/client/refresh/gl3/header/model.h @@ -88,42 +88,6 @@ typedef struct msurface_s byte *samples; /* [numstyles*surfsize] */ } msurface_t; -typedef struct mnode_s -{ - /* common with leaf */ - int contents; /* -1, to differentiate from leafs */ - int visframe; /* node needs to be traversed if current */ - - float minmaxs[6]; /* for bounding box culling */ - - struct mnode_s *parent; - - /* node specific */ - cplane_t *plane; - struct mnode_s *children[2]; - - unsigned short firstsurface; - unsigned short numsurfaces; -} mnode_t; - -typedef struct mleaf_s -{ - /* common with node */ - int contents; /* wil be a negative contents number */ - int visframe; /* node needs to be traversed if current */ - - float minmaxs[6]; /* for bounding box culling */ - - struct mnode_s *parent; - - /* leaf specific */ - int cluster; - int area; - - msurface_t **firstmarksurface; - int nummarksurfaces; -} mleaf_t; - /* Whole model */ // this, must be struct model_s, not gl3model_s, diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index c689308f..82254a07 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -137,6 +137,44 @@ typedef struct mtexinfo_s struct image_s *image; } mtexinfo_t; +#define CONTENTS_NODE -1 +typedef struct mnode_s +{ + /* common with leaf */ + int contents; /* CONTENTS_NODE, to differentiate from leafs */ + int visframe; /* node needs to be traversed if current */ + + float minmaxs[6]; /* for bounding box culling */ + + struct mnode_s *parent; + + /* node specific */ + cplane_t *plane; + struct mnode_s *children[2]; + + unsigned short firstsurface; + unsigned short numsurfaces; +} mnode_t; + +typedef struct mleaf_s +{ + /* common with leaf */ + int contents; /* CONTENTS_NODE, to differentiate from leafs */ + int visframe; /* node needs to be traversed if current */ + + float minmaxs[6]; /* for bounding box culling */ + + struct mnode_s *parent; + + /* leaf specific */ + int cluster; + int area; + + struct msurface_s **firstmarksurface; + int nummarksurfaces; + int key; /* BSP sequence number for leaf's contents */ +} mleaf_t; + /* Shared models func */ typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type); extern void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen, @@ -150,7 +188,8 @@ extern struct image_s *GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, findimage_t find_image); extern struct image_s *GetTexImage(const char *name, findimage_t find_image); extern struct image_s *R_FindPic(const char *name, findimage_t find_image); -extern struct image_s* R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type, - qboolean r_retexturing, loadimage_t load_image); - +extern struct image_s* R_LoadImage(const char *name, const char* namewe, const char *ext, + imagetype_t type, qboolean r_retexturing, loadimage_t load_image); +extern void Mod_LoadNodes(const char *name, cplane_t *planes, struct mleaf_s *leafs, + mnode_t **nodes, int *numnodes, const byte *mod_base, const lump_t *l); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/client/refresh/soft/header/model.h b/src/client/refresh/soft/header/model.h index 33f2ee6c..8156b417 100644 --- a/src/client/refresh/soft/header/model.h +++ b/src/client/refresh/soft/header/model.h @@ -69,47 +69,6 @@ typedef struct msurface_s struct msurface_s *nextalphasurface; } msurface_t; - -#define CONTENTS_NODE -1 -typedef struct mnode_s -{ - // common with leaf - int contents; // CONTENTS_NODE, to differentiate from leafs - int visframe; // node needs to be traversed if current - - /* FIXME: is different type in other renders */ - short minmaxs[6]; // for bounding box culling - - struct mnode_s *parent; - - // node specific - cplane_t *plane; - struct mnode_s *children[2]; - - unsigned short firstsurface; - unsigned short numsurfaces; -} mnode_t; - -typedef struct mleaf_s -{ - // common with node - int contents; // wil be something other than CONTENTS_NODE - int visframe; // node needs to be traversed if current - - short minmaxs[6]; // for bounding box culling - - struct mnode_s *parent; - - // leaf specific - int cluster; - int area; - - msurface_t **firstmarksurface; - int nummarksurfaces; - int key; // BSP sequence number for leaf's contents -} mleaf_t; - - //=================================================================== // diff --git a/src/client/refresh/soft/sw_bsp.c b/src/client/refresh/soft/sw_bsp.c index 3bde5244..61d0a80a 100644 --- a/src/client/refresh/soft/sw_bsp.c +++ b/src/client/refresh/soft/sw_bsp.c @@ -518,9 +518,9 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod d -= view_clipplanes[i].dist; if (d <= 0) return; - acceptpt[0] = (float)node->minmaxs[pindex[3+0]]; - acceptpt[1] = (float)node->minmaxs[pindex[3+1]]; - acceptpt[2] = (float)node->minmaxs[pindex[3+2]]; + acceptpt[0] = node->minmaxs[pindex[3+0]]; + acceptpt[1] = node->minmaxs[pindex[3+1]]; + acceptpt[2] = node->minmaxs[pindex[3+2]]; d = DotProduct (acceptpt, view_clipplanes[i].normal); d -= view_clipplanes[i].dist; @@ -533,7 +533,7 @@ R_RecursiveWorldNode (entity_t *currententity, const model_t *currentmodel, mnod c_drawnode++; // if a leaf node, draw stuff - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { msurface_t **mark; pleaf = (mleaf_t *)node; diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index a6c2aa81..106d0c24 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -42,7 +42,7 @@ R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount) msurface_t *surf; int i; - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) return; splitplane = node->plane; @@ -122,7 +122,7 @@ RecursiveLightPoint (mnode_t *node, vec3_t start, vec3_t end, vec3_t pointcolor) int maps; int r; - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) return -1; // didn't hit anything // calculate mid point diff --git a/src/client/refresh/soft/sw_misc.c b/src/client/refresh/soft/sw_misc.c index 282bbe93..09274f92 100644 --- a/src/client/refresh/soft/sw_misc.c +++ b/src/client/refresh/soft/sw_misc.c @@ -323,7 +323,7 @@ Mod_PointInLeaf (const vec3_t p, const model_t *model) } node = model->nodes; - while (node->contents == -1) + while (node->contents == CONTENTS_NODE) { float d; cplane_t *plane; diff --git a/src/client/refresh/soft/sw_model.c b/src/client/refresh/soft/sw_model.c index 44818884..0132529b 100644 --- a/src/client/refresh/soft/sw_model.c +++ b/src/client/refresh/soft/sw_model.c @@ -295,7 +295,7 @@ static int r_numvisleafs; static void R_NumberLeafs (model_t *loadmodel, mnode_t *node) { - if (node->contents != -1) + if (node->contents != CONTENTS_NODE) { mleaf_t *leaf; int leafnum; @@ -714,78 +714,6 @@ Mod_LoadFaces (model_t *loadmodel, byte *mod_base, lump_t *l) } } - -/* -================= -Mod_SetParent -================= -*/ -static void -Mod_SetParent (mnode_t *node, mnode_t *parent) -{ - node->parent = parent; - if (node->contents != -1) - return; - Mod_SetParent (node->children[0], node); - Mod_SetParent (node->children[1], node); -} - -/* -================= -Mod_LoadNodes -================= -*/ -static void -Mod_LoadNodes (model_t *loadmodel, byte *mod_base, lump_t *l) -{ - int i, count; - dnode_t *in; - mnode_t *out; - - in = (void *)(mod_base + l->fileofs); - - if (l->filelen % sizeof(*in)) - { - ri.Sys_Error(ERR_DROP, "%s: funny lump size in %s", - __func__, loadmodel->name); - } - - count = l->filelen / sizeof(*in); - out = Hunk_Alloc(count*sizeof(*out)); - - loadmodel->nodes = out; - loadmodel->numnodes = count; - - for ( i=0 ; iminmaxs[j] = LittleShort (in->mins[j]); - out->minmaxs[3+j] = LittleShort (in->maxs[j]); - } - - p = LittleLong(in->planenum); - out->plane = loadmodel->planes + p; - - out->firstsurface = LittleShort (in->firstface); - out->numsurfaces = LittleShort (in->numfaces); - out->contents = CONTENTS_NODE; // differentiate from leafs - - for (j=0 ; j<2 ; j++) - { - p = LittleLong (in->children[j]); - if (p >= 0) - out->children[j] = loadmodel->nodes + p; - else - out->children[j] = (mnode_t *)(loadmodel->leafs + (-1 - p)); - } - } - - Mod_SetParent (loadmodel->nodes, NULL); // sets nodes and leafs -} - /* ================= Mod_LoadLeafs @@ -1047,7 +975,8 @@ Mod_LoadBrushModel(model_t *mod, void *buffer, int modfilelen) Mod_LoadMarksurfaces (mod, mod_base, &header->lumps[LUMP_LEAFFACES]); Mod_LoadVisibility (mod, mod_base, &header->lumps[LUMP_VISIBILITY]); Mod_LoadLeafs (mod, mod_base, &header->lumps[LUMP_LEAFS]); - Mod_LoadNodes (mod, mod_base, &header->lumps[LUMP_NODES]); + Mod_LoadNodes (mod->name, mod->planes, mod->leafs, &mod->nodes, + &mod->numnodes, mod_base, &header->lumps[LUMP_NODES]); Mod_LoadSubmodels (mod, mod_base, &header->lumps[LUMP_MODELS]); r_numvisleafs = 0;