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
int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p)
{
#ifdef PSP_VFPU
int sides;
__asm__ (
".set push\n" // save assembler option
@ -412,7 +411,7 @@ int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p)
"bvt 0, 9f\n" // if ( CC[0] == 1 ) jump to 9
"nop\n" // ( delay slot )
"addiu %[sides], %[sides], 1\n"// sides = 1
"9:\n"
"9:\n"
"vcmp.s GE, S031, S032\n" // S031 >= S032
"bvt 0, 10f\n" // if ( CC[0] == 1 ) jump to 10
"nop\n" // ( delay slot )
@ -421,65 +420,13 @@ int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, mplane_t *p)
".set pop\n" // restore assembler option
: [sides] "=r" ( sides )
: [normal] "m" (*(p->normal)),
[emaxs] "m" ( *emaxs ),
[emaxs] "m" ( *emaxs ),
[emins] "m" ( *emins ),
[signbits] "r" ( p->signbits ),
[signbits] "r" ( p->signbits ),
[dist] "m" ( p->dist )
: "$8"
);
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 EmitDetailPolys (void);
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);
void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
void R_RotateForEntity (entity_t *e, int shadow);
@ -416,4 +416,4 @@ void D_DeleteBuffer (psp_particle* vertices);
int D_DrawParticleBuffered (psp_particle* vertices, particle2_t *pparticle, vec3_t up, vec3_t right, float scale);
extern int zombie_skins[2][2];
extern int zombie_skins[2][2];

View file

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

View file

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