Shpuld's static brushmodel opt

This commit is contained in:
Ian 2023-10-05 10:30:44 -04:00
parent 20b4095fdc
commit b76d859ca7
4 changed files with 98 additions and 0 deletions

View File

@ -61,6 +61,8 @@ dlight_t cl_dlights[MAX_DLIGHTS];
int cl_numvisedicts;
entity_t *cl_visedicts[MAX_VISEDICTS];
int cl_numstaticbrushmodels;
entity_t *cl_staticbrushmodels[MAX_VISEDICTS];
/*
=====================
@ -494,6 +496,7 @@ void CL_RelinkEntities (void)
frac = CL_LerpPoint ();
cl_numvisedicts = 0;
cl_numstaticbrushmodels = 0;
//
// interpolate player info
@ -535,6 +538,21 @@ void CL_RelinkEntities (void)
continue;
}
// shpuld: if brush model is at 0 with no angle changes, we can draw it with world
if (ent->model->type == mod_brush && cl_numstaticbrushmodels < MAX_VISEDICTS)
{
if (ent->msg_origins[0][0] == 0 &&
ent->msg_origins[0][1] == 0 &&
ent->msg_origins[0][2] == 0 &&
ent->msg_angles[0][0] == 0 &&
ent->msg_angles[0][1] == 0 &&
ent->msg_angles[0][2] == 0) {
cl_staticbrushmodels[cl_numstaticbrushmodels] = ent;
cl_numstaticbrushmodels++;
continue;
}
}
VectorCopy (ent->origin, oldorg);
if (ent->forcelink)

View File

@ -326,6 +326,8 @@ void CL_NextDemo (void);
#define MAX_VISEDICTS 256
extern int cl_numvisedicts;
extern entity_t *cl_visedicts[MAX_VISEDICTS];
extern int cl_numstaticbrushmodels;
extern entity_t *cl_staticbrushmodels[MAX_VISEDICTS];
// model indexes
typedef enum modelindex_s

View File

@ -166,6 +166,28 @@ void R_RotateForEntity (entity_t *e)
glRotatef (e->angles[2], 1, 0, 0);
}
/*
=================
R_FrustumCheckBox
Returns 0 if box completely inside frustum
Returns +N with intersected planes count as N
Returns -1 when completely outside frustum
=================
*/
int R_FrustumCheckBox (vec3_t mins, vec3_t maxs)
{
int i, res;
int intersections = 0;
for (i=0 ; i<4 ; i++)
{
res = BoxOnPlaneSide (mins, maxs, &frustum[i]);
if (res == 2) return -1;
if (res == 3) ++intersections;
}
return intersections;
}
/*
=============================================================

View File

@ -1391,6 +1391,60 @@ void R_RecursiveWorldNode (mnode_t *node)
}
void R_AddBrushModelToChains (entity_t * e)
{
model_t * clmodel = e->model;
vec3_t mins, maxs;
VectorAdd (e->origin, clmodel->mins, mins);
VectorAdd (e->origin, clmodel->maxs, maxs);
if (R_CullBox(mins, maxs))
{
return;
}
msurface_t * psurf = &clmodel->surfaces[clmodel->firstmodelsurface];
/*
if (clmodel->firstmodelsurface != 0)
{
for (int k = 0; k < MAX_DLIGHTS; k++)
{
if ((cl_dlights[k].die < cl.time) ||
(!cl_dlights[k].radius))
continue;
R_MarkLights (&cl_dlights[k], 1<<k, clmodel->nodes + clmodel->hulls[0].firstclipnode);
}
}
*/
for (int j = 0; j < clmodel->nummodelsurfaces; j++, psurf++)
{
// find which side of the node we are on
mplane_t * pplane = psurf->plane;
float dot = DotProduct (modelorg, pplane->normal) - pplane->dist;
// draw the polygon
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
{
// psurf->flags &= ~SURF_NEEDSCLIPPING;
// psurf->flags |= SURF_NEEDSCLIPPING * (frustum_check > 1);
psurf->texturechain = psurf->texinfo->texture->texturechain;
psurf->texinfo->texture->texturechain = psurf;
}
}
}
void R_AddStaticBrushModelsToChains ()
{
// Con_Printf("static models %d\n", cl_numstaticbrushmodels);
for (int i = 0; i < cl_numstaticbrushmodels; i++)
{
// if (i >= 1) return;
R_AddBrushModelToChains(cl_staticbrushmodels[i]);
}
}
/*
=============
@ -1418,6 +1472,8 @@ void R_DrawWorld (void)
R_RecursiveWorldNode (cl.worldmodel->nodes);
R_AddStaticBrushModelsToChains (); // shpuld
DrawTextureChains ();
R_BlendLightmaps (0);