mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 12:41:21 +00:00
Share Mod_PointInLeaf
This commit is contained in:
parent
442fe10f27
commit
42bfb2014c
9 changed files with 68 additions and 118 deletions
|
@ -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 */
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue