From bf8bb383ab1a39240c0a3e34ec8caa7c1a5bbdac Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Wed, 14 Oct 2020 21:20:37 -0300 Subject: [PATCH] Simplify the floor splat clipping code a bit --- src/r_splats.c | 59 +++++++++++++++++++++++++++----------------------- src/r_splats.h | 1 - src/r_things.c | 4 +++- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/r_splats.c b/src/r_splats.c index ce45446d0..efcd6ea98 100644 --- a/src/r_splats.c +++ b/src/r_splats.c @@ -24,8 +24,6 @@ struct rastery_s *prastertab; // for ASM code static struct rastery_s rastertab[MAXVIDHEIGHT]; static void prepare_rastertab(void); -UINT8 ds_splatclip[MAXVIDWIDTH]; - // ========================================================================== // FLOOR SPLATS // ========================================================================== @@ -147,7 +145,8 @@ static void rasterize_segment_tex(INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT32 void R_RenderFloorSplat(floorsplat_t *pSplat, vector2_t *verts, vissprite_t *vis) { // rasterizing - INT32 miny = viewheight + 1, maxy = 0, y, x1, ry1, x2, y2, i, xclip; + INT32 miny = viewheight + 1, maxy = 0; + INT32 y, x1, ry1, x2, y2, i; fixed_t offsetx = 0, offsety = 0; fixed_t step; @@ -289,6 +288,8 @@ void R_RenderFloorSplat(floorsplat_t *pSplat, vector2_t *verts, vissprite_t *vis for (y = miny; y <= maxy; y++) { + boolean cliptab[MAXVIDWIDTH+1]; + x1 = rastertab[y].minx>>FRACBITS; x2 = rastertab[y].maxx>>FRACBITS; @@ -304,8 +305,34 @@ void R_RenderFloorSplat(floorsplat_t *pSplat, vector2_t *verts, vissprite_t *vis if (x1 < 0) x1 = 0; - if (x2 >= vid.width) - x2 = vid.width - 1; + if (x2 >= viewwidth) + x2 = viewwidth - 1; + + if (x1 >= viewwidth || x2 < 0) + continue; + + for (i = x1; i <= x2; i++) + cliptab[i] = (y >= mfloorclip[i]); + + // clip left + while (cliptab[x1]) + { + x1++; + if (x1 >= viewwidth) + break; + } + + // clip right + i = x2; + + while (i > x1) + { + if (cliptab[i]) + x2 = i-1; + i--; + if (i < 0) + break; + } ds_colormap = vis->colormap; ds_translation = R_GetSpriteTranslation(vis); @@ -320,28 +347,6 @@ void R_RenderFloorSplat(floorsplat_t *pSplat, vector2_t *verts, vissprite_t *vis ds_colormap = &vis->extra_colormap->colormap[ds_colormap - colormaps]; } - R_ClipVisSprite(vis, x1-1, x2+1, drawsegs, NULL); - memset(ds_splatclip, 0, sizeof(ds_splatclip)); - - if (x2 >= x1 && x1 < viewwidth && x1 >= 0) - { - for (xclip = x1; xclip <= x2; xclip++) - { - if (y >= mfloorclip[xclip]) - ds_splatclip[xclip] = 1; - } - } - - while (ds_splatclip[x1]) - x1++; - i = x2; - while (i > x1) - { - if (ds_splatclip[i]) - x2 = i-1; - i--; - } - if (!pSplat->tilted) { angle = (viewangle + pSplat->angle)>>ANGLETOFINESHIFT; diff --git a/src/r_splats.h b/src/r_splats.h index b0707e95b..ba5052fc9 100644 --- a/src/r_splats.h +++ b/src/r_splats.h @@ -44,7 +44,6 @@ typedef struct floorsplat_s } floorsplat_t; void R_RenderFloorSplat(floorsplat_t *pSplat, vector2_t *verts, vissprite_t *vis); -extern UINT8 ds_splatclip[MAXVIDWIDTH]; #endif #endif /*__R_SPLATS_H__*/ diff --git a/src/r_things.c b/src/r_things.c index e8c00b86b..6c1d8a879 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3213,7 +3213,9 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) for (; clippedvissprites < visspritecount; clippedvissprites++) { vissprite_t *spr = R_GetVisSprite(clippedvissprites); - R_ClipVisSprite(spr, spr->x1, spr->x2, dsstart, portal); + INT32 x1 = (spr->cut & SC_SPLAT) ? 0 : spr->x1; + INT32 x2 = (spr->cut & SC_SPLAT) ? viewwidth : spr->x2; + R_ClipVisSprite(spr, x1, x2, dsstart, portal); } }