Skip to content

Commit ca61b90

Browse files
committed
Apply clipping optimization for R_ProjectSprite
1 parent d6ef55c commit ca61b90

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/r_things.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ void R_ProjectSprite (mobj_t* thing)
457457

458458
fixed_t gxt;
459459
fixed_t gyt;
460+
fixed_t gzt;
460461

461462
fixed_t tx;
462463
fixed_t tz;
@@ -544,15 +545,29 @@ void R_ProjectSprite (mobj_t* thing)
544545
if (x2 < 0)
545546
return;
546547

548+
// clip things which are out of view due to height
549+
gzt = thing->z + spritetopoffset[lump];
550+
if (thing->z > (int64_t)viewz + FixedDiv(viewheight << FRACBITS, xscale) ||
551+
gzt < viewz - FixedDiv((viewheight << FRACBITS) - viewheight, xscale))
552+
{
553+
return;
554+
}
555+
556+
// quickly reject sprites with bad x ranges
557+
if (x1 >= x2)
558+
{
559+
return;
560+
}
561+
547562
// store information in a vissprite
548563
vis = R_NewVisSprite ();
549564
vis->mobjflags = thing->flags;
550565
vis->scale = xscale;
551566
vis->gx = thing->x;
552567
vis->gy = thing->y;
553568
vis->gz = thing->z;
554-
vis->gzt = thing->z + spritetopoffset[lump];
555-
vis->texturemid = vis->gzt - viewz;
569+
vis->gzt = gzt;
570+
vis->texturemid = gzt - viewz;
556571
vis->x1 = x1 < 0 ? 0 : x1;
557572
vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2;
558573
const fixed_t iscale = FixedReciprocal(xscale);

0 commit comments

Comments
 (0)