From c1a9c58eb50fe64dc28d0a27b8946ac00a1511cf Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 25 May 2024 02:02:06 +0200 Subject: [PATCH] Cull BSP behind a raised floor or lowered ceiling that covers the entire screen https://git.do.srb2.org/KartKrew/RingRacers/-/commit/7b8a564f69688515319ccd425f2b88ffe8b7b120 --- src/r_bsp.c | 18 ++++++++++++++---- src/r_bsp.h | 1 + src/r_segs.c | 25 ++++++++++++++----------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index 2e0fd6f4a..b1d62d979 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -39,6 +39,10 @@ drawseg_t *ds_p = NULL; // indicates doors closed wrt automap bugfix: INT32 doorclosed; +// A wall was drawn covering the whole screen, which means we +// can block off the BSP across that seg. +boolean g_walloffscreen; + boolean R_NoEncore(sector_t *sector, boolean ceiling) { boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 15); @@ -84,7 +88,7 @@ void R_AllocClipSegMemory(void) // // Replaces the old R_Clip*WallSegment functions. It draws bits of walls in those // columns which aren't solid, and updates the solidcol[] array appropriately -static void R_ClipWallSegment(INT32 first, INT32 last, boolean solid) +static void R_ClipWallSegment(INT32 first, INT32 last, boolean solid, boolean soliddontrender) { while (first < last) { @@ -108,7 +112,8 @@ static void R_ClipWallSegment(INT32 first, INT32 last, boolean solid) else to = p - solidcol; - R_StoreWallRange(first, to-1); + if (!soliddontrender) + R_StoreWallRange(first, to-1); if (solid) memset(solidcol+first, 1, to-first); @@ -492,11 +497,16 @@ static void R_AddLine(seg_t *line) return; clippass: - R_ClipWallSegment(x1, x2, false); + g_walloffscreen = false; + if (g_walloffscreen) + R_ClipWallSegment(x1, x2, false , true); + else + R_ClipWallSegment(x1, x2, false , false); return; clipsolid: - R_ClipWallSegment(x1, x2, true); + g_walloffscreen = false; + R_ClipWallSegment(x1, x2, false , false); } // diff --git a/src/r_bsp.h b/src/r_bsp.h index 6165f8789..a82866b2c 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -32,6 +32,7 @@ extern INT32 checkcoord[12][4]; extern drawseg_t *drawsegs; extern drawseg_t *ds_p; extern INT32 doorclosed; +extern boolean g_walloffscreen; extern UINT8 *solidcol; diff --git a/src/r_segs.c b/src/r_segs.c index 5f8270ef1..11afdf474 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2577,23 +2577,26 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (toptexture) { - pixhigh = (centeryfrac>>4) - FixedMul (worldhigh, rw_scale); - pixhighstep = -FixedMul (rw_scalestep,worldhigh); + fixed_t topfracend = (centeryfrac>>4) - FixedMul (worldhighslope, ds_p->scale2); - if (backsector->c_slope) { - fixed_t topfracend = (centeryfrac>>4) - FixedMul (worldhighslope, ds_p->scale2); - pixhighstep = (topfracend-pixhigh)/(range); - } + pixhigh = (centeryfrac>>4) - FixedMul (worldhigh, rw_scale); + pixhighstep = (topfracend-pixhigh)/(range); + + // If the lowest part of a ceiling stretching down covers the entire screen + if (min(pixhigh, topfracend)>>HEIGHTBITS >= viewheight-1) + g_walloffscreen = true; } if (bottomtexture) { + fixed_t bottomfracend = (centeryfrac>>4) - FixedMul (worldlowslope, ds_p->scale2); + pixlow = (centeryfrac>>4) - FixedMul (worldlow, rw_scale); - pixlowstep = -FixedMul (rw_scalestep,worldlow); - if (backsector->f_slope) { - fixed_t bottomfracend = (centeryfrac>>4) - FixedMul (worldlowslope, ds_p->scale2); - pixlowstep = (bottomfracend-pixlow)/(range); - } + pixlowstep = (bottomfracend-pixlow)/(range); + + // If the highest part of a floor stretching up covers the entire screen + if ((max(pixlow, bottomfracend)+HEIGHTUNIT-1)>>HEIGHTBITS <= 0) + g_walloffscreen = true; } {