diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index 1054c8f..8f05d41 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/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/files/models.c b/src/files/models.c index 8e84107..21d2017 100644 --- a/src/files/models.c +++ b/src/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/vk/header/model.h b/src/vk/header/model.h index f100528..533331b 100644 --- a/src/vk/header/model.h +++ b/src/vk/header/model.h @@ -168,7 +168,6 @@ typedef struct model_s //============================================================================ void Mod_Init (void); -mleaf_t *Mod_PointInLeaf (const 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/vk/vk_model.c b/src/vk/vk_model.c index 87002e4..1c8448e 100644 --- a/src/vk/vk_model.c +++ b/src/vk/vk_model.c @@ -33,37 +33,6 @@ static int models_known_max = 0; int registration_sequence; -/* -=============== -Mod_PointInLeaf -=============== -*/ -mleaf_t *Mod_PointInLeaf (const vec3_t p, model_t *model) -{ - mnode_t *node; - - if (!model || !model->nodes) - ri.Sys_Error (ERR_DROP, "%s: bad model", __func__); - - node = model->nodes; - while (1) - { - cplane_t *plane; - float d; - - 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/vk/vk_rmain.c b/src/vk/vk_rmain.c index 1cc8437..254cef6 100644 --- a/src/vk/vk_rmain.c +++ b/src/vk/vk_rmain.c @@ -698,9 +698,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 @@ -710,7 +716,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)) r_viewcluster2 = leaf->cluster; @@ -721,7 +727,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)) r_viewcluster2 = leaf->cluster;