diff --git a/src/client/refresh/files/models.c b/src/client/refresh/files/models.c index 744e314f..c8fc17f0 100644 --- a/src/client/refresh/files/models.c +++ b/src/client/refresh/files/models.c @@ -750,3 +750,43 @@ Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra) size = (size + 31) & ~31; return size; } + +/* +=============== +Mod_PointInLeaf +=============== +*/ +mleaf_t * +Mod_PointInLeaf(const vec3_t p, mnode_t *node) +{ + if (!node) + { + ri.Sys_Error(ERR_DROP, "%s: bad node.", __func__); + return NULL; + } + + while (1) + { + float d; + cplane_t *plane; + + if (node->contents != CONTENTS_NODE) + { + return (mleaf_t *)node; + } + + plane = node->plane; + d = DotProduct(p, plane->normal) - plane->dist; + + if (d > 0) + { + node = node->children[0]; + } + else + { + node = node->children[1]; + } + } + + return NULL; /* never reached */ +} diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index 13c3e111..508c0e7e 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -703,9 +703,15 @@ R_SetupFrame(void) /* current viewcluster */ if (!(r_newrefdef.rdflags & RDF_NOWORLDMODEL)) { + if (!r_worldmodel) + { + ri.Sys_Error(ERR_DROP, "%s: bad world model", __func__); + return; + } + r_oldviewcluster = r_viewcluster; r_oldviewcluster2 = r_viewcluster2; - leaf = Mod_PointInLeaf(r_origin, r_worldmodel); + leaf = Mod_PointInLeaf(r_origin, r_worldmodel->nodes); r_viewcluster = r_viewcluster2 = leaf->cluster; /* check above and below so crossing solid water doesn't draw wrong */ @@ -716,7 +722,7 @@ R_SetupFrame(void) VectorCopy(r_origin, temp); temp[2] -= 16; - leaf = Mod_PointInLeaf(temp, r_worldmodel); + leaf = Mod_PointInLeaf(temp, r_worldmodel->nodes); if (!(leaf->contents & CONTENTS_SOLID) && (leaf->cluster != r_viewcluster2)) @@ -731,7 +737,7 @@ R_SetupFrame(void) VectorCopy(r_origin, temp); temp[2] += 16; - leaf = Mod_PointInLeaf(temp, r_worldmodel); + leaf = Mod_PointInLeaf(temp, r_worldmodel->nodes); if (!(leaf->contents & CONTENTS_SOLID) && (leaf->cluster != r_viewcluster2)) diff --git a/src/client/refresh/gl1/gl1_model.c b/src/client/refresh/gl1/gl1_model.c index f9499448..6d1589fd 100644 --- a/src/client/refresh/gl1/gl1_model.c +++ b/src/client/refresh/gl1/gl1_model.c @@ -70,43 +70,6 @@ Mod_HasFreeSpace(void) return (mod_numknown + mod_max) < MAX_MOD_KNOWN; } -mleaf_t * -Mod_PointInLeaf(vec3_t p, model_t *model) -{ - mnode_t *node; - float d; - cplane_t *plane; - - if (!model || !model->nodes) - { - ri.Sys_Error(ERR_DROP, "%s: bad model", __func__); - } - - node = model->nodes; - - while (1) - { - if (node->contents != CONTENTS_NODE) - { - return (mleaf_t *)node; - } - - plane = node->plane; - d = DotProduct(p, plane->normal) - plane->dist; - - if (d > 0) - { - node = node->children[0]; - } - else - { - node = node->children[1]; - } - } - - return NULL; /* never reached */ -} - const byte * Mod_ClusterPVS(int cluster, const model_t *model) { diff --git a/src/client/refresh/gl1/header/model.h b/src/client/refresh/gl1/header/model.h index 87e071cc..36d57dfe 100644 --- a/src/client/refresh/gl1/header/model.h +++ b/src/client/refresh/gl1/header/model.h @@ -144,7 +144,6 @@ typedef struct model_s void Mod_Init(void); void Mod_ClearAll(void); -mleaf_t *Mod_PointInLeaf(vec3_t p, model_t *model); const byte *Mod_ClusterPVS(int cluster, const model_t *model); void Mod_Modellist_f(void); diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index cc8f2e75..c4729205 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -1200,9 +1200,15 @@ SetupFrame(void) /* current viewcluster */ if (!(gl3_newrefdef.rdflags & RDF_NOWORLDMODEL)) { + if (!gl3_worldmodel) + { + ri.Sys_Error(ERR_DROP, "%s: bad world model", __func__); + return; + } + gl3_oldviewcluster = gl3_viewcluster; gl3_oldviewcluster2 = gl3_viewcluster2; - leaf = GL3_Mod_PointInLeaf(gl3_origin, gl3_worldmodel); + leaf = Mod_PointInLeaf(gl3_origin, gl3_worldmodel->nodes); gl3_viewcluster = gl3_viewcluster2 = leaf->cluster; /* check above and below so crossing solid water doesn't draw wrong */ @@ -1213,7 +1219,7 @@ SetupFrame(void) VectorCopy(gl3_origin, temp); temp[2] -= 16; - leaf = GL3_Mod_PointInLeaf(temp, gl3_worldmodel); + leaf = Mod_PointInLeaf(temp, gl3_worldmodel->nodes); if (!(leaf->contents & CONTENTS_SOLID) && (leaf->cluster != gl3_viewcluster2)) @@ -1228,7 +1234,7 @@ SetupFrame(void) VectorCopy(gl3_origin, temp); temp[2] += 16; - leaf = GL3_Mod_PointInLeaf(temp, gl3_worldmodel); + leaf = Mod_PointInLeaf(temp, gl3_worldmodel->nodes); if (!(leaf->contents & CONTENTS_SOLID) && (leaf->cluster != gl3_viewcluster2)) diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c index cc784158..b54ca0dd 100644 --- a/src/client/refresh/gl3/gl3_model.c +++ b/src/client/refresh/gl3/gl3_model.c @@ -64,43 +64,6 @@ Mod_HasFreeSpace(void) return (mod_numknown + mod_max) < MAX_MOD_KNOWN; } -mleaf_t * -GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model) -{ - mnode_t *node; - float d; - cplane_t *plane; - - if (!model || !model->nodes) - { - ri.Sys_Error(ERR_DROP, "%s: bad model", __func__); - } - - node = model->nodes; - - while (1) - { - if (node->contents != CONTENTS_NODE) - { - return (mleaf_t *)node; - } - - plane = node->plane; - d = DotProduct(p, plane->normal) - plane->dist; - - if (d > 0) - { - node = node->children[0]; - } - else - { - node = node->children[1]; - } - } - - return NULL; /* never reached */ -} - const byte* GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model) { diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index 2a933d1d..94f9e31a 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -406,7 +406,6 @@ extern struct model_s * GL3_RegisterModel(char *name); extern void GL3_EndRegistration(void); extern void GL3_Mod_Modellist_f(void); extern const byte* GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model); -extern mleaf_t* GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model); // gl3_draw.c extern void GL3_Draw_InitLocal(void); diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index 21814478..c133337d 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -207,5 +207,6 @@ extern void Mod_LoadPlanes (const char *name, cplane_t **planes, int *numplanes, extern void Mod_LoadSurfedges (const char *name, int **surfedges, int *numsurfedges, const byte *mod_base, const lump_t *l, int extra); extern int Mod_CalcLumpHunkSize(const lump_t *l, int inSize, int outSize, int extra); +extern mleaf_t *Mod_PointInLeaf(const vec3_t p, mnode_t *node); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/client/refresh/soft/sw_misc.c b/src/client/refresh/soft/sw_misc.c index 09274f92..6c115733 100644 --- a/src/client/refresh/soft/sw_misc.c +++ b/src/client/refresh/soft/sw_misc.c @@ -27,7 +27,6 @@ cvar_t *sw_mipscale; float verticalFieldOfView; int d_minmip; float d_scalemip[NUM_MIPS-1]; -static mleaf_t *r_viewleaf; static int r_frustum_indexes[4*6]; static const float basemip[NUM_MIPS-1] = {1.0, 0.5*0.8, 0.25*0.8}; @@ -306,40 +305,6 @@ R_ViewChanged (const vrect_t *vr) D_ViewChanged (); } -/* -=============== -Mod_PointInLeaf -=============== -*/ -static mleaf_t * -Mod_PointInLeaf (const vec3_t p, const model_t *model) -{ - mnode_t *node; - - if (!model || !model->nodes) - { - ri.Sys_Error(ERR_DROP, "%s: bad model", __func__); - return NULL; - } - - node = model->nodes; - while (node->contents == CONTENTS_NODE) - { - float d; - cplane_t *plane; - - plane = node->plane; - d = DotProduct (p,plane->normal) - plane->dist; - if (d > 0) - node = node->children[0]; - else - node = node->children[1]; - } - - return (mleaf_t *)node; -} - - /* =============== R_SetupFrame @@ -369,9 +334,17 @@ R_SetupFrame (void) // current viewleaf if ( !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) ) { + mleaf_t *r_viewleaf; + + if (!r_worldmodel) + { + ri.Sys_Error(ERR_DROP, "%s: bad world model", __func__); + return; + } + // Determine what is the current view cluster (walking the BSP tree) // and store it in r_viewcluster - r_viewleaf = Mod_PointInLeaf (r_origin, r_worldmodel); + r_viewleaf = Mod_PointInLeaf (r_origin, r_worldmodel->nodes); r_viewcluster = r_viewleaf->cluster; }