R_ClipVisSprite: add SC_CULL, completely exclude sprite from sorting if it is fully clipped

The avoids wasting time sorting and drawing sprites that
are completely obscured by segs / FOFs.
This commit is contained in:
James R 2023-04-05 02:56:13 -07:00
parent 1a2dc9635b
commit 5be3a6c574
2 changed files with 21 additions and 3 deletions

View file

@ -2728,7 +2728,15 @@ static void R_SortVisSprites(vissprite_t* vsprsortedhead, UINT32 start, UINT32 e
for (i = start; i < end; ++i)
{
dsnext = R_GetVisSprite(i);
ds = R_GetVisSprite(i);
// Do not include this sprite, since it is completely obscured
if (ds->cut & SC_CULL)
{
continue;
}
dsnext = ds;
dsnext->linkdraw = NULL;
dsprev->next = dsnext;
@ -3259,6 +3267,7 @@ void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* portal)
fixed_t scale;
fixed_t lowscale;
INT32 silhouette;
INT32 xclip;
if ((spr->renderflags & RF_ALWAYSONTOP) || cv_debugrender_spriteclip.value)
{
@ -3441,7 +3450,7 @@ void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* portal)
// all clipping has been performed, so store the values - what, did you think we were drawing them NOW?
// check for unclipped columns
for (x = x1; x <= x2; x++)
for (xclip = x = x1; x <= x2; x++)
{
if (spr->clipbot[x] == CLIP_UNDEF)
spr->clipbot[x] = (INT16)viewheight;
@ -3449,9 +3458,17 @@ void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* portal)
if (spr->cliptop[x] == CLIP_UNDEF)
//Fab : 26-04-98: was -1, now clips against console bottom
spr->cliptop[x] = (INT16)con_clipviewtop;
// Sprite is completely above or below clip plane
if (spr->szt >= spr->clipbot[x] || spr->sz <= spr->cliptop[x])
xclip++;
}
if (portal)
if (xclip == x)
{
spr->cut |= SC_CULL; // completely skip this sprite going forward
}
else if (portal)
{
INT32 start_index = max(portal->start, x1);
INT32 end_index = min(portal->start + portal->end - portal->start, x2);

View file

@ -142,6 +142,7 @@ typedef enum
// srb2kart
SC_SEMIBRIGHT = 1<<12,
SC_BBOX = 1<<13,
SC_CULL = 1<<14,
// masks
SC_CUTMASK = SC_TOP|SC_BOTTOM,
SC_FLAGMASK = ~SC_CUTMASK