From c9b6276a02aa46d662e6a66837bc90eb78d6259d Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 01:31:27 +0200 Subject: [PATCH] merge sky column drawer back lets hope this is safe lulul --- src/r_draw_column.cpp | 174 +++++------------------------------------- src/r_plane.cpp | 6 +- 2 files changed, 23 insertions(+), 157 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index b15294c75..8ec979cde 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -30,6 +30,7 @@ enum DrawColumnType DC_TRANSMAP = 0x0002, DC_HOLES = 0x0004, DC_LIGHTLIST = 0x0008, + DC_SKY = 0x0010, }; template @@ -208,8 +209,10 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) // SoM: MAGIC UINT8 * restrict dest; - if constexpr ((Type & (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) - == (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) + if constexpr (Type & DrawColumnType::DC_SKY) + dest = R_Address(dc->x, dc->yl); + else if constexpr ((Type & (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) + == (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) dest = R_GetBufferColormapTrans(dc); else if constexpr (Type & DrawColumnType::DC_TRANSMAP) dest = R_GetBufferTrans(dc); @@ -218,6 +221,11 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) else dest = R_GetBufferOpaque(dc); + restrict INT32 stride = 4; + + if constexpr (Type & DrawColumnType::DC_SKY) + stride = vid.width; + count++; // Determine scaling, which is the only mapping to be done. @@ -231,7 +239,8 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) while (count--) { *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - dest += 4; + + dest += stride; frac += fracstep; } } @@ -246,7 +255,8 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) while (--count >= 0) { *dest = R_DrawColumnPixel(dc, dest, frac>>FRACBITS, source, colormap); - dest += 4; + + dest += stride; frac += fracstep; } } @@ -258,11 +268,13 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) while ((count -= 2) >= 0) // texture height is a power of 2 -- killough { *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - dest += 4; + + dest += stride; frac += fracstep; *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - dest += 4; + + dest += stride; frac += fracstep; } @@ -300,7 +312,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) // and a few bytes after as well *dest = R_DrawColumnPixel(dc, dest, CLAMP((frac >> FRACBITS), npow2min, npow2max), source, colormap); - dest += 4; + dest += stride; #if __SIZEOF_POINTER__ < 8 // 64-bit systems have large enough numbers for this to be a non-issue // Avoid overflow. @@ -341,6 +353,7 @@ DEFINE_COLUMN_FUNC(R_DrawColumnShadowed, DC_LIGHTLIST) DEFINE_COLUMN_FUNC(R_DrawTranslatedTranslucentColumn, DC_COLORMAP|DC_TRANSMAP) DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchColumn, DC_HOLES) DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumn, DC_HOLES|DC_TRANSMAP) +DEFINE_COLUMN_FUNC(R_DrawSkyColumn, DC_SKY) /** \brief The R_DrawFogColumn function Fog wall. @@ -377,150 +390,3 @@ void R_DrawFogColumn(drawcolumndata_t* dc) dest += stride; } while (count--); } - -// blunt copy paste for now -// cant share a global buffer between threads for obvious reasons lmao -void R_DrawSkyColumn(drawcolumndata_t *dc) -{ - INT32 count; - - count = dc->yh - dc->yl; - - if (count < 0) // Zero length, column does not exceed a pixel. - { - return; - } - - if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height) - { - return; - } - - { - // Inner loop that does the actual texture mapping, - // e.g. a DDA-lile scaling. - // This is as fast as it gets. (Yeah, right!!! -- killough) - // - // killough 2/1/98: more performance tuning - - intptr_t frac; - const intptr_t fracstep = dc->iscale; - const intptr_t heightmask = dc->sourcelength-1; - constexpr INT32 npow2min = -1; - const INT32 npow2max = dc->sourcelength; - const INT32 stride = vid.width; - - const UINT8 * restrict source = dc->source; - const lighttable_t * restrict colormap = dc->colormap; - - // Framebuffer destination address. - UINT8 * restrict dest = R_Address(dc->x, dc->yl); - - count++; - - // Determine scaling, which is the only mapping to be done. - frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep)); - - switch (heightmask) - { - case 255: - case 127: - { - while(count--) - { - *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - dest += stride; - frac += fracstep; - } - } - break; - case -1: - { - if (frac < 0) - // adjust in case we underread - frac += fracstep; - - // texture has no height, so just go - while (--count >= 0) - { - *dest = R_DrawColumnPixel(dc, dest, frac>>FRACBITS, source, colormap); - dest += stride; - frac += fracstep; - } - } - break; - default: - { - if (!(dc->sourcelength & heightmask)) // power of 2 -- killough - { - while ((count -= 2) >= 0) // texture height is a power of 2 -- killough - { - *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - dest += stride; - frac += fracstep; - - *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - dest += stride; - frac += fracstep; - } - - if (count & 1) - { - *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - } - } - else - { - const intptr_t fixed_heightmask = dc->texheight << FRACBITS; - - if (frac < 0) - { - while ((frac += fixed_heightmask) < 0) - { - ; - } - } - else - { - while (frac >= fixed_heightmask) - { - frac -= fixed_heightmask; - } - } - - do - { - // Re-map color indices from wall texture column - // using a lighting/special effects LUT. - // heightmask is the Tutti-Frutti fix - - // -1 is the lower clamp bound because column posts have a "safe" byte before the real data - // and a few bytes after as well - *dest = R_DrawColumnPixel(dc, dest, CLAMP((frac >> FRACBITS), npow2min, npow2max), source, colormap); - - dest += stride; - -#if __SIZEOF_POINTER__ < 8 // 64-bit systems have large enough numbers for this to be a non-issue - // Avoid overflow. - if (fracstep > 0x7FFFFFFF - frac) - { - frac += fracstep - fixed_heightmask; - } - else -#endif - { - frac += fracstep; - } - - while (frac >= fixed_heightmask) - { - frac -= fixed_heightmask; - } - } - while (--count); - } - } - break; - } - } -} diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 83508e16a..7c2ff271d 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -739,7 +739,7 @@ void R_DrawPlanes(void) #endif } -static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), boolean allow_parallel); +static void R_DrawSkyPlane(visplane_t *pl, boolean allow_parallel); void R_DrawSkyPlanes(void) { @@ -757,7 +757,7 @@ void R_DrawSkyPlanes(void) if (pl->picnum != skyflatnum || pl->ffloor || pl->polyobj) continue; - R_DrawSkyPlane(pl, colfunc, cv_parallelsoftware.value); + R_DrawSkyPlane(pl, cv_parallelsoftware.value); } } #ifdef HAVE_THREADS @@ -767,7 +767,7 @@ void R_DrawSkyPlanes(void) #endif } -static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), boolean allow_parallel) +static void R_DrawSkyPlane(visplane_t *pl, boolean allow_parallel) { INT32 x;