ADQuake's improved R_CullBox

This commit is contained in:
moto 2022-05-22 10:48:29 -04:00
parent 72288cf9ee
commit 4857dab378
4 changed files with 26 additions and 109 deletions

View file

@ -253,7 +253,6 @@ Returns 1, 2, or 1 + 2
// crow_bar's enhanced boxonplaneside // crow_bar's enhanced boxonplaneside
int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p) int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p)
{ {
#ifdef PSP_VFPU
int sides; int sides;
__asm__ ( __asm__ (
".set push\n" // save assembler option ".set push\n" // save assembler option
@ -428,58 +427,6 @@ int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p)
: "$8" : "$8"
); );
return sides; return sides;
#else
int sides = 0;
float dist1, dist2;
// general case
switch( p->signbits )
{
case 0:
dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
break;
case 1:
dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
break;
case 2:
dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
break;
case 3:
dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
break;
case 4:
dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
break;
case 5:
dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
break;
case 6:
dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
break;
case 7:
dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
break;
default:
// shut up compiler
dist1 = dist2 = 0;
break;
}
if( dist1 >= p->dist )
sides = 1;
if( dist2 < p->dist )
sides |= 2;
return sides;
#endif
} }

View file

@ -333,7 +333,7 @@ void EmitBothSkyLayers (msurface_t *fa);
void EmitUnderWaterPolys (void); void EmitUnderWaterPolys (void);
void EmitDetailPolys (void); void EmitDetailPolys (void);
void R_DrawSkyChain (msurface_t *s); void R_DrawSkyChain (msurface_t *s);
qboolean R_CullBox (vec3_t emins, vec3_t emaxs); int R_CullBox (vec3_t emins, vec3_t emaxs);
qboolean R_CullSphere (vec3_t centre, float radius); qboolean R_CullSphere (vec3_t centre, float radius);
void R_MarkLights (dlight_t *light, int bit, mnode_t *node); void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
void R_RotateForEntity (entity_t *e, int shadow); void R_RotateForEntity (entity_t *e, int shadow);

View file

@ -314,59 +314,29 @@ void R_RotateForViewEntity (entity_t *ent)
/* /*
================= =================
R_CullBox -- replaced with new function from lordhavoc R_CullBox
Returns true if the box is completely outside the frustom
Returns true if the box is completely outside the frustum
================= =================
*/ */
qboolean R_CullBox (vec3_t emins, vec3_t emaxs) int R_CullBox (vec3_t mins, vec3_t maxs)
{ {
int result = 1; // Default to "all inside".
int i; int i;
mplane_t *p;
for (i=0 ; i<4 ; i++)
for (i = 0;i < 4;i++)
{ {
p = frustum + i; const int plane_result = BoxOnPlaneSide(mins, maxs, &frustum[i]);
switch(p->signbits) if (plane_result == 2)
{ {
default: return 2;
case 0: }
if (p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2] < p->dist) else if (plane_result == 3)
return qtrue; {
break; result = 3;
case 1:
if (p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2] < p->dist)
return qtrue;
break;
case 2:
if (p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2] < p->dist)
return qtrue;
break;
case 3:
if (p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2] < p->dist)
return qtrue;
break;
case 4:
if (p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2] < p->dist)
return qtrue;
break;
case 5:
if (p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2] < p->dist)
return qtrue;
break;
case 6:
if (p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2] < p->dist)
return qtrue;
break;
case 7:
if (p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2] < p->dist)
return qtrue;
break;
} }
} }
return qfalse;
return result;
} }
/* /*
@ -2060,7 +2030,7 @@ void R_DrawTransparentAliasModel (entity_t *e)
VectorAdd (e->origin, clmodel->mins, mins); VectorAdd (e->origin, clmodel->mins, mins);
VectorAdd (e->origin, clmodel->maxs, maxs); VectorAdd (e->origin, clmodel->maxs, maxs);
if (R_CullBox(mins, maxs)) if (R_CullBox(mins, maxs) == 2)
return; return;
VectorCopy (e->origin, r_entorigin); VectorCopy (e->origin, r_entorigin);
@ -2194,7 +2164,7 @@ void R_DrawAliasModel (entity_t *e)
VectorAdd (e->origin, clmodel->mins, mins); VectorAdd (e->origin, clmodel->mins, mins);
VectorAdd (e->origin, clmodel->maxs, maxs); VectorAdd (e->origin, clmodel->maxs, maxs);
if (R_CullBox(mins, maxs)) if (R_CullBox(mins, maxs) == 2)
return; return;
//=============================================================================================== 97% at this point //=============================================================================================== 97% at this point
@ -2544,7 +2514,7 @@ void R_DrawMD2Model (entity_t *e)
//} //}
//else //else
//{ //{
if (R_CullBox(mins, maxs)) if (R_CullBox(mins, maxs) == 2)
return; return;
//} //}
@ -3279,7 +3249,7 @@ void R_DrawQ3Model (entity_t *ent)
} }
else else
{ {
if (R_CullBox(mins, maxs)) if (R_CullBox(mins, maxs) == 2)
return; return;
} }

View file

@ -1254,7 +1254,7 @@ void R_DrawBrushModel (entity_t *e)
VectorAdd (e->origin, clmodel->mins, mins); VectorAdd (e->origin, clmodel->mins, mins);
VectorAdd (e->origin, clmodel->maxs, maxs); VectorAdd (e->origin, clmodel->maxs, maxs);
if (R_CullBox (mins, maxs)) if (R_CullBox (mins, maxs) == 2)
return; return;
} }
@ -1435,7 +1435,7 @@ void R_RecursiveWorldNode (mnode_t *node)
if (node->visframe != r_visframecount) if (node->visframe != r_visframecount)
return; return;
if (R_CullBox (node->minmaxs, node->minmaxs+3)) if (R_CullBox (node->minmaxs, node->minmaxs+3) == 2)
return; return;
// if a leaf node, draw stuff // if a leaf node, draw stuff