From 031e8ee47797efbd7cb2a2c20cc6def3ce13d8ca Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 18:14:59 +0200 Subject: [PATCH 01/40] WIP: column buffering/flushing system it "works" so far no performance improvement everything but fully opague columns dont work for now until fixed really messy and needs to be templated when working from prboom & eternity engine --- src/r_draw.h | 3 + src/r_draw_column.cpp | 183 ++++++++++++- src/r_draw_flush.cpp | 599 ++++++++++++++++++++++++++++++++++++++++++ src/r_main.cpp | 4 + src/r_plane.cpp | 11 +- 5 files changed, 783 insertions(+), 17 deletions(-) create mode 100644 src/r_draw_flush.cpp diff --git a/src/r_draw.h b/src/r_draw.h index bcd734e50..232e6c8ce 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -252,6 +252,9 @@ void R_Draw2sMultiPatchTranslucentColumn(drawcolumndata_t* dc); void R_DrawFogColumn(drawcolumndata_t* dc); +void R_ResetColumnBuffer(void); +void R_DrawSkyColumn(drawcolumndata_t *dc); + // span drawers void R_DrawSpan(drawspandata_t* ds); diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index bae220e6d..ccb5c5403 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -21,6 +21,8 @@ // a has a constant z depth from top to bottom. // +#include "r_draw_flush.cpp" + enum DrawColumnType { DC_BASIC = 0x0000, @@ -69,7 +71,9 @@ static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict } } - return R_GetColumnTranslucent(dc, dest, col, colormap); + //return R_GetColumnTranslucent(dc, dest, col, colormap); + // dont return any other shit for now + return col; } /** \brief The R_DrawColumn function @@ -150,6 +154,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) } R_DrawColumnTemplate(&dc_copy); + if (solid) { dc_copy.yl = bheight; @@ -184,16 +189,25 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) intptr_t frac; const intptr_t fracstep = dc->iscale; - const intptr_t heightmask = dc->sourcelength-1; + const intptr_t heightmask = dc->sourcelength-1; // CPhipps - specify type 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; + UINT8 * restrict dest; + // Framebuffer destination address. - UINT8 * restrict dest = R_Address(dc->x, dc->yl); + // SoM: MAGIC + /*if constexpr (Type & (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) + dest = R_GetBufferColormapTrans(dc); + else if constexpr (Type & DrawColumnType::DC_TRANSMAP) + dest = R_GetBufferTrans(dc); + else if constexpr (Type & DrawColumnType::DC_COLORMAP) + dest = R_GetBufferColormap(dc); + else*/ + dest = R_GetBufferOpaque(dc); count++; @@ -205,15 +219,15 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) case 255: case 127: { - while(count--) + while (count--) { *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - dest += stride; + dest += 4; frac += fracstep; } } break; - case -1: + case npow2min: { if (frac < 0) // adjust in case we underread @@ -223,7 +237,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) while (--count >= 0) { *dest = R_DrawColumnPixel(dc, dest, frac>>FRACBITS, source, colormap); - dest += stride; + dest += 4; frac += fracstep; } } @@ -235,11 +249,11 @@ 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 += stride; + dest += 4; frac += fracstep; *dest = R_DrawColumnPixel(dc, dest, (frac>>FRACBITS) & heightmask, source, colormap); - dest += stride; + dest += 4; frac += fracstep; } @@ -277,7 +291,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 += stride; + dest += 4; #if __SIZEOF_POINTER__ < 8 // 64-bit systems have large enough numbers for this to be a non-issue // Avoid overflow. @@ -354,3 +368,150 @@ 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_draw_flush.cpp b/src/r_draw_flush.cpp new file mode 100644 index 000000000..657e185b5 --- /dev/null +++ b/src/r_draw_flush.cpp @@ -0,0 +1,599 @@ +// SONIC ROBO BLAST 2 KART +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Kart Krew. +// Copyright (C) 2020 by Sonic Team Junior. +// Copyright (C) 2000 by DooM Legacy Team. +// Copyright (C) 1996 by id Software, Inc. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_draw_flush.cpp +/// \brief column flush functions +/// \note no includes because this is included as part of r_draw.cpp + +enum ColumnFlushType +{ + FLUSH_NONE, + FLUSH_OPAQUE, + FLUSH_TRANS, + FLUSH_COLORMAP, + FLUSH_COLORMAP_TRANS +}; + +static int temp_x = 0; +static int tempyl[4], tempyh[4]; +static UINT8 tempbuf[MAXVIDWIDTH * 4]; +static int startx = 0; +static int commontop, commonbot; +static ColumnFlushType temptype = FLUSH_NONE; +static const UINT8 *temptranmap = NULL; +static const UINT8 *temptranslation = NULL; + +static void R_FlushColumns(void); + +static void R_FlushWholeError(void) +{ + I_Error("R_FlushWholeColumns called without being initialized.\n"); +} + +static void R_FlushHTError(void) +{ + I_Error("R_FlushHTColumns called without being initialized.\n"); +} + +static void R_QuadFlushError(void) +{ + I_Error("R_FlushQuadColumn called without being initialized.\n"); +} + +// +// R_FlushWholeOpaque +// +// Flushes the entire columns in the buffer, one at a time. +// This is used when a quad flush isn't possible. +// Opaque version -- no remapping whatsoever. +// +static void R_FlushWholeOpaque(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count, yl; + const restrict INT32 stride = vid.width; + + while (--temp_x >= 0) + { + yl = tempyl[temp_x]; + source = &tempbuf[temp_x + (yl << 2)]; + dest = R_Address(startx + temp_x, yl); + count = tempyh[temp_x] - yl + 1; + + while (--count >= 0) + { + *dest = *source; + source += 4; + dest += stride; + } + } +} + +// +// R_FlushHTOpaque +// +// Flushes the head and tail of columns in the buffer in +// preparation for a quad flush. +// Opaque version -- no remapping whatsoever. +// +static void R_FlushHTOpaque(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count, colnum = 0; + INT32 yl, yh; + const restrict INT32 stride = vid.width; + + while (colnum < 4) + { + yl = tempyl[colnum]; + yh = tempyh[colnum]; + + // flush column head + if (yl < commontop) + { + source = &tempbuf[colnum + (yl << 2)]; + dest = R_Address(startx + colnum, yl); + count = commontop - yl; + + while (--count >= 0) + { + *dest = *source; + source += 4; + dest += stride; + } + } + + // flush column tail + if (yh > commonbot) + { + source = &tempbuf[colnum + ((commonbot + 1) << 2)]; + dest = R_Address(startx + colnum, commonbot + 1); + count = yh - commonbot; + + while (--count >= 0) + { + *dest = *source; + source += 4; + dest += stride; + } + } + ++colnum; + } +} + +static void R_FlushQuadOpaque(void) +{ + UINT8 *source = &tempbuf[commontop << 2]; + UINT8 *dest = R_Address(startx, commontop); + INT32 count; + const restrict INT32 stride = vid.width; + + count = commonbot - commontop + 1; + + if ((sizeof(int) == 4) && (((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) + { + while(--count >= 0) + { + *(int *)dest = *(int *)source; + source += 4 * sizeof(UINT8); + dest += stride * sizeof(UINT8); + } + } + else + { + while(--count >= 0) + { + dest[0] = source[0]; + dest[1] = source[1]; + dest[2] = source[2]; + dest[3] = source[3]; + source += 4 * sizeof(UINT8); + dest += stride * sizeof(UINT8); + } + } + + while(--count >= 0) + { + dest[0] = source[0]; + dest[1] = source[1]; + dest[2] = source[2]; + dest[3] = source[3]; + source += 4 * sizeof(UINT8); + dest += stride * sizeof(UINT8); + } +} + +static void R_FlushWholeTrans(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count, yl; + const restrict INT32 stride = vid.width; + + while (--temp_x >= 0) + { + yl = tempyl[temp_x]; + source = &tempbuf[temp_x + (yl << 2)]; + dest = R_Address(startx + temp_x, yl); + count = tempyh[temp_x] - yl + 1; + + while (--count >= 0) + { + *dest = temptranmap[(*dest << 8) + *source]; + source += 4; + dest += stride; + } + } +} + +static void R_FlushHTTrans(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count; + INT32 colnum = 0, yl, yh; + const restrict INT32 stride = vid.width; + + while (colnum < 4) + { + yl = tempyl[colnum]; + yh = tempyh[colnum]; + + // flush column head + if (yl < commontop) + { + source = &tempbuf[colnum + (yl << 2)]; + dest = R_Address(startx + colnum, yl); + count = commontop - yl; + + while (--count >= 0) + { + *dest = temptranmap[(*dest << 8) + *source]; + source += 4; + dest += stride; + } + } + + // flush column tail + if (yh > commonbot) + { + source = &tempbuf[colnum + ((commonbot + 1) << 2)]; + dest = R_Address(startx + colnum, commonbot + 1); + count = yh - commonbot; + + while (--count >= 0) + { + *dest = temptranmap[(*dest << 8) + *source]; + source += 4; + dest += stride; + } + } + + ++colnum; + } +} + +static void R_FlushQuadTrans(void) +{ + UINT8 *source = &tempbuf[commontop << 2]; + UINT8 *dest = R_Address(startx, commontop); + INT32 count; + const restrict INT32 stride = vid.width; + + count = commonbot - commontop + 1; + + while (--count >= 0) + { + dest[0] = temptranmap[(dest[0] << 8) + source[0]]; + dest[1] = temptranmap[(dest[1] << 8) + source[1]]; + dest[2] = temptranmap[(dest[2] << 8) + source[2]]; + dest[3] = temptranmap[(dest[3] << 8) + source[3]]; + source += 4; + dest += stride; + } +} + +static void R_FlushWholeColormap(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count, yl; + const restrict INT32 stride = vid.width; + + while (--temp_x >= 0) + { + yl = tempyl[temp_x]; + source = &tempbuf[temp_x + (yl << 2)]; + dest = R_Address(startx + temp_x, yl); + count = tempyh[temp_x] - yl + 1; + + while (--count >= 0) + { + *dest = temptranslation[*source]; + source += 4; + dest += stride; + } + } +} + +static void R_FlushHTColormap(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count; + INT32 colnum = 0, yl, yh; + const restrict INT32 stride = vid.width; + + while (colnum < 4) + { + yl = tempyl[colnum]; + yh = tempyh[colnum]; + + // flush column head + if (yl < commontop) + { + source = &tempbuf[colnum + (yl << 2)]; + dest = R_Address(startx + colnum, yl); + count = commontop - yl; + + while (--count >= 0) + { + *dest = temptranslation[*source]; + source += 4; + dest += stride; + } + } + + // flush column tail + if (yh > commonbot) + { + source = &tempbuf[colnum + ((commonbot + 1) << 2)]; + dest = R_Address(startx + colnum, commonbot + 1); + count = yh - commonbot; + + while (--count >= 0) + { + *dest = temptranslation[*source]; + source += 4; + dest += stride; + } + } + + ++colnum; + } +} + +static void R_FlushQuadColormap(void) +{ + UINT8 *source = &tempbuf[commontop << 2]; + UINT8 *dest = R_Address(startx, commontop); + INT32 count; + const restrict INT32 stride = vid.width; + + count = commonbot - commontop + 1; + + while (--count >= 0) + { + dest[0] = temptranslation[source[0]]; + dest[1] = temptranslation[source[1]]; + dest[2] = temptranslation[source[2]]; + dest[3] = temptranslation[source[3]]; + source += 4; + dest += stride; + } +} + +static void R_FlushWholeColormapTrans(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count, yl; + const restrict INT32 stride = vid.width; + + while (--temp_x >= 0) + { + yl = tempyl[temp_x]; + source = &tempbuf[temp_x + (yl << 2)]; + dest = R_Address(startx + temp_x, yl); + count = tempyh[temp_x] - yl + 1; + + while (--count >= 0) + { + *dest = temptranmap[(*dest << 8) + temptranslation[*source]]; + source += 4; + dest += stride; + } + } +} + +static void R_FlushHTColormapTrans(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count; + INT32 colnum = 0, yl, yh; + const restrict INT32 stride = vid.width; + + while (colnum < 4) + { + yl = tempyl[colnum]; + yh = tempyh[colnum]; + + // flush column head + if (yl < commontop) + { + source = &tempbuf[colnum + (yl << 2)]; + dest = R_Address(startx + colnum, yl); + count = commontop - yl; + + while (--count >= 0) + { + *dest = temptranmap[(*dest << 8) + temptranslation[*source]]; + source += 4; + dest += stride; + } + } + + // flush column tail + if (yh > commonbot) + { + source = &tempbuf[colnum + ((commonbot + 1) << 2)]; + dest = R_Address(startx + colnum, commonbot + 1); + count = yh - commonbot; + + while (--count >= 0) + { + *dest = temptranmap[(*dest << 8) + temptranslation[*source]]; + source += 4; + dest += stride; + } + } + + ++colnum; + } +} + +static void R_FlushQuadColormapTrans(void) +{ + UINT8 *source = &tempbuf[commontop << 2]; + UINT8 *dest = R_Address(startx, commontop); + INT32 count; + const restrict INT32 stride = vid.width; + + count = commonbot - commontop + 1; + + while (--count >= 0) + { + dest[0] = temptranmap[(dest[0] << 8) + temptranslation[source[0]]]; + dest[1] = temptranmap[(dest[1] << 8) + temptranslation[source[1]]]; + dest[2] = temptranmap[(dest[2] << 8) + temptranslation[source[2]]]; + dest[3] = temptranmap[(dest[3] << 8) + temptranslation[source[3]]]; + source += 4; + dest += stride; + } +} + +static void (*R_FlushWholeColumns)(void) = R_FlushWholeError; +static void (*R_FlushHTColumns)(void) = R_FlushHTError; +static void (*R_FlushQuadColumn)(void) = R_QuadFlushError; + +static void R_FlushColumns(void) +{ + if (temp_x != 4 || commontop >= commonbot) + R_FlushWholeColumns(); + else + { + R_FlushHTColumns(); + R_FlushQuadColumn(); + } + + temp_x = 0; +} + +// +// R_ResetColumnBuffer +// +void R_ResetColumnBuffer(void) +{ + if (temp_x) + R_FlushColumns(); + + temptype = FLUSH_NONE; + R_FlushWholeColumns = R_FlushWholeError; + R_FlushHTColumns = R_FlushHTError; + R_FlushQuadColumn = R_QuadFlushError; +} + +static UINT8 *R_GetBufferOpaque(drawcolumndata_t *dc) +{ + if (temp_x == 4 || + (temp_x && (temptype != FLUSH_OPAQUE || temp_x + startx != dc->x))) + R_FlushColumns(); + + if (!temp_x) + { + startx = dc->x; + tempyl[0] = commontop = dc->yl; + tempyh[0] = commonbot = dc->yh; + temptype = FLUSH_OPAQUE; + R_FlushWholeColumns = R_FlushWholeOpaque; + R_FlushHTColumns = R_FlushHTOpaque; + R_FlushQuadColumn = R_FlushQuadOpaque; + temp_x += 1; + return &tempbuf[dc->yl << 2]; + } + + tempyl[temp_x] = dc->yl; + tempyh[temp_x] = dc->yh; + + if (dc->yl > commontop) + commontop = dc->yl; + if (dc->yh < commonbot) + commonbot = dc->yh; + + return &tempbuf[(dc->yl << 2) + temp_x++]; +} + +static UINT8 *R_GetBufferTrans(drawcolumndata_t *dc) +{ + if (temp_x == 4 || dc->transmap != temptranmap || + (temp_x && (temptype != FLUSH_TRANS || temp_x + startx != dc->x))) + R_FlushColumns(); + + if (!temp_x) + { + startx = dc->x; + tempyl[0] = commontop = dc->yl; + tempyh[0] = commonbot = dc->yh; + temptype = FLUSH_TRANS; + temptranmap = dc->transmap; + R_FlushWholeColumns = R_FlushWholeTrans; + R_FlushHTColumns = R_FlushHTTrans; + R_FlushQuadColumn = R_FlushQuadTrans; + temp_x += 1; + return &tempbuf[dc->yl << 2]; + } + + tempyl[temp_x] = dc->yl; + tempyh[temp_x] = dc->yh; + + if (dc->yl > commontop) + commontop = dc->yl; + if (dc->yh < commonbot) + commonbot = dc->yh; + + return &tempbuf[(dc->yl << 2) + temp_x++]; +} + +static UINT8 *R_GetBufferColormap(drawcolumndata_t *dc) +{ + if (temp_x == 4 || dc->translation != temptranslation || + (temp_x && (temptype != FLUSH_COLORMAP || temp_x + startx != dc->x))) + R_FlushColumns(); + + if (!temp_x) + { + startx = dc->x; + tempyl[0] = commontop = dc->yl; + tempyh[0] = commonbot = dc->yh; + temptype = FLUSH_COLORMAP; + temptranslation = dc->translation; + R_FlushWholeColumns = R_FlushWholeColormap; + R_FlushHTColumns = R_FlushHTColormap; + R_FlushQuadColumn = R_FlushQuadColormap; + temp_x += 1; + return &tempbuf[dc->yl << 2]; + } + + tempyl[temp_x] = dc->yl; + tempyh[temp_x] = dc->yh; + + if (dc->yl > commontop) + commontop = dc->yl; + if (dc->yh < commonbot) + commonbot = dc->yh; + + return &tempbuf[(dc->yl << 2) + temp_x++]; +} + +static UINT8 *R_GetBufferColormapTrans(drawcolumndata_t *dc) +{ + if (temp_x == 4 || dc->translation != temptranslation || dc->transmap != temptranmap || + (temp_x && (temptype != FLUSH_COLORMAP_TRANS || temp_x + startx != dc->x))) + R_FlushColumns(); + + if (!temp_x) + { + startx = dc->x; + tempyl[0] = commontop = dc->yl; + tempyh[0] = commonbot = dc->yh; + temptype = FLUSH_COLORMAP_TRANS; + temptranslation = dc->translation; + temptranmap = dc->transmap; + R_FlushWholeColumns = R_FlushWholeColormapTrans; + R_FlushHTColumns = R_FlushHTColormapTrans; + R_FlushQuadColumn = R_FlushQuadColormapTrans; + temp_x += 1; + return &tempbuf[dc->yl << 2]; + } + + tempyl[temp_x] = dc->yl; + tempyh[temp_x] = dc->yh; + + if (dc->yl > commontop) + commontop = dc->yl; + if (dc->yh < commonbot) + commonbot = dc->yh; + + return &tempbuf[(dc->yl << 2) + temp_x++]; +} diff --git a/src/r_main.cpp b/src/r_main.cpp index 08f1e68a1..132349a82 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1409,7 +1409,9 @@ void R_RenderPlayerView(player_t *player) R_ClipSprites(drawsegs, NULL); R_DrawSkyPlanes(); // draw the fucker again to prevent some artifacts R_DrawPlanes(); + //R_ResetColumnBuffer(); R_DrawMasked(masks, nummasks); + //R_ResetColumnBuffer(); } PS_STOP_TIMING(ps_skyboxtime); @@ -1493,6 +1495,7 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_sw_planetime); if (!skybox) R_DrawSkyPlanes(); + R_ResetColumnBuffer(); R_DrawPlanes(); PS_STOP_TIMING(ps_sw_planetime); // draw mid texture and sprite @@ -1500,6 +1503,7 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_sw_maskedtime); R_DrawMasked(masks, nummasks); PS_STOP_TIMING(ps_sw_maskedtime); + R_ResetColumnBuffer(); free(masks); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 475e8a44d..16e344bdf 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -716,13 +716,10 @@ void R_DrawPlanes(void) visplane_t *pl; INT32 i; drawspandata_t ds = {}; -#ifdef HAVE_THREADS - srb2::ThreadPool::Sema tp_sema; -#endif - R_UpdatePlaneRipple(&ds); #ifdef HAVE_THREADS + srb2::ThreadPool::Sema tp_sema; srb2::g_main_threadpool->begin_sema(); #endif for (i = 0; i < MAXVISPLANES; i++, pl++) @@ -837,7 +834,8 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b dc.x = x + i; dc.source = R_GetColumn(texture, -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 - colfunc2(&dc); + //colfunc2(&dc); + R_DrawSkyColumn(&dc); } }; @@ -874,7 +872,8 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b R_GetColumn(texturetranslation[skytexture], -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 - colfunc2(&dc); + //colfunc2(&dc); + R_DrawSkyColumn(&dc); } #endif } -- 2.54.0 From e852c23441c74e35ab65152e6228689f1c1d6f51 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 18:34:03 +0200 Subject: [PATCH 02/40] move the temp columndata into a struct TODO:dynamic allocate our temporary screen buffer --- src/r_draw_flush.cpp | 356 ++++++++++++++++++++++--------------------- 1 file changed, 183 insertions(+), 173 deletions(-) diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index 657e185b5..8eb1d6266 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -22,14 +22,24 @@ enum ColumnFlushType FLUSH_COLORMAP_TRANS }; -static int temp_x = 0; -static int tempyl[4], tempyh[4]; -static UINT8 tempbuf[MAXVIDWIDTH * 4]; -static int startx = 0; -static int commontop, commonbot; -static ColumnFlushType temptype = FLUSH_NONE; -static const UINT8 *temptranmap = NULL; -static const UINT8 *temptranslation = NULL; +typedef struct drawcolumndata_temp_s +{ + intptr_t x; + intptr_t yl[4], yh[4]; + + // e6y: resolution limitation is removed + // not for now kek + UINT8 buf[MAXVIDWIDTH * 4]; + + intptr_t startx; + ColumnFlushType type; + intptr_t commontop, commonbot; + const UINT8 *tranmap; + // SoM 7-28-04: Fix the fuzz problem. + const UINT8 *translation; +} drawcolumndata_temp_t; + +drawcolumndata_temp_t temp_dc = {}; static void R_FlushColumns(void); @@ -62,12 +72,12 @@ static void R_FlushWholeOpaque(void) INT32 count, yl; const restrict INT32 stride = vid.width; - while (--temp_x >= 0) + while (--temp_dc.x >= 0) { - yl = tempyl[temp_x]; - source = &tempbuf[temp_x + (yl << 2)]; - dest = R_Address(startx + temp_x, yl); - count = tempyh[temp_x] - yl + 1; + yl = temp_dc.yl[temp_dc.x]; + source = &temp_dc.buf[temp_dc.x + (yl << 2)]; + dest = R_Address(temp_dc.startx + temp_dc.x, yl); + count = temp_dc.yh[temp_dc.x] - yl + 1; while (--count >= 0) { @@ -95,15 +105,15 @@ static void R_FlushHTOpaque(void) while (colnum < 4) { - yl = tempyl[colnum]; - yh = tempyh[colnum]; + yl = temp_dc.yl[colnum]; + yh = temp_dc.yh[colnum]; // flush column head - if (yl < commontop) + if (yl < temp_dc.commontop) { - source = &tempbuf[colnum + (yl << 2)]; - dest = R_Address(startx + colnum, yl); - count = commontop - yl; + source = &temp_dc.buf[colnum + (yl << 2)]; + dest = R_Address(temp_dc.startx + colnum, yl); + count = temp_dc.commontop - yl; while (--count >= 0) { @@ -114,11 +124,11 @@ static void R_FlushHTOpaque(void) } // flush column tail - if (yh > commonbot) + if (yh > temp_dc.commonbot) { - source = &tempbuf[colnum + ((commonbot + 1) << 2)]; - dest = R_Address(startx + colnum, commonbot + 1); - count = yh - commonbot; + source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; + dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); + count = yh - temp_dc.commonbot; while (--count >= 0) { @@ -133,12 +143,12 @@ static void R_FlushHTOpaque(void) static void R_FlushQuadOpaque(void) { - UINT8 *source = &tempbuf[commontop << 2]; - UINT8 *dest = R_Address(startx, commontop); + UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; + UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); INT32 count; const restrict INT32 stride = vid.width; - count = commonbot - commontop + 1; + count = temp_dc.commonbot - temp_dc.commontop + 1; if ((sizeof(int) == 4) && (((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) { @@ -180,16 +190,16 @@ static void R_FlushWholeTrans(void) INT32 count, yl; const restrict INT32 stride = vid.width; - while (--temp_x >= 0) + while (--temp_dc.x >= 0) { - yl = tempyl[temp_x]; - source = &tempbuf[temp_x + (yl << 2)]; - dest = R_Address(startx + temp_x, yl); - count = tempyh[temp_x] - yl + 1; + yl = temp_dc.yl[temp_dc.x]; + source = &temp_dc.buf[temp_dc.x + (yl << 2)]; + dest = R_Address(temp_dc.startx + temp_dc.x, yl); + count = temp_dc.yh[temp_dc.x] - yl + 1; while (--count >= 0) { - *dest = temptranmap[(*dest << 8) + *source]; + *dest = temp_dc.tranmap[(*dest << 8) + *source]; source += 4; dest += stride; } @@ -206,34 +216,34 @@ static void R_FlushHTTrans(void) while (colnum < 4) { - yl = tempyl[colnum]; - yh = tempyh[colnum]; + yl = temp_dc.yl[colnum]; + yh = temp_dc.yh[colnum]; // flush column head - if (yl < commontop) + if (yl < temp_dc.commontop) { - source = &tempbuf[colnum + (yl << 2)]; - dest = R_Address(startx + colnum, yl); - count = commontop - yl; + source = &temp_dc.buf[colnum + (yl << 2)]; + dest = R_Address(temp_dc.startx + colnum, yl); + count = temp_dc.commontop - yl; while (--count >= 0) { - *dest = temptranmap[(*dest << 8) + *source]; + *dest = temp_dc.tranmap[(*dest << 8) + *source]; source += 4; dest += stride; } } // flush column tail - if (yh > commonbot) + if (yh > temp_dc.commonbot) { - source = &tempbuf[colnum + ((commonbot + 1) << 2)]; - dest = R_Address(startx + colnum, commonbot + 1); - count = yh - commonbot; + source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; + dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); + count = yh - temp_dc.commonbot; while (--count >= 0) { - *dest = temptranmap[(*dest << 8) + *source]; + *dest = temp_dc.tranmap[(*dest << 8) + *source]; source += 4; dest += stride; } @@ -245,19 +255,19 @@ static void R_FlushHTTrans(void) static void R_FlushQuadTrans(void) { - UINT8 *source = &tempbuf[commontop << 2]; - UINT8 *dest = R_Address(startx, commontop); + UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; + UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); INT32 count; const restrict INT32 stride = vid.width; - count = commonbot - commontop + 1; + count = temp_dc.commonbot - temp_dc.commontop + 1; while (--count >= 0) { - dest[0] = temptranmap[(dest[0] << 8) + source[0]]; - dest[1] = temptranmap[(dest[1] << 8) + source[1]]; - dest[2] = temptranmap[(dest[2] << 8) + source[2]]; - dest[3] = temptranmap[(dest[3] << 8) + source[3]]; + dest[0] = temp_dc.tranmap[(dest[0] << 8) + source[0]]; + dest[1] = temp_dc.tranmap[(dest[1] << 8) + source[1]]; + dest[2] = temp_dc.tranmap[(dest[2] << 8) + source[2]]; + dest[3] = temp_dc.tranmap[(dest[3] << 8) + source[3]]; source += 4; dest += stride; } @@ -270,16 +280,16 @@ static void R_FlushWholeColormap(void) INT32 count, yl; const restrict INT32 stride = vid.width; - while (--temp_x >= 0) + while (--temp_dc.x >= 0) { - yl = tempyl[temp_x]; - source = &tempbuf[temp_x + (yl << 2)]; - dest = R_Address(startx + temp_x, yl); - count = tempyh[temp_x] - yl + 1; + yl = temp_dc.yl[temp_dc.x]; + source = &temp_dc.buf[temp_dc.x + (yl << 2)]; + dest = R_Address(temp_dc.startx + temp_dc.x, yl); + count = temp_dc.yh[temp_dc.x] - yl + 1; while (--count >= 0) { - *dest = temptranslation[*source]; + *dest = temp_dc.translation[*source]; source += 4; dest += stride; } @@ -296,34 +306,34 @@ static void R_FlushHTColormap(void) while (colnum < 4) { - yl = tempyl[colnum]; - yh = tempyh[colnum]; + yl = temp_dc.yl[colnum]; + yh = temp_dc.yh[colnum]; // flush column head - if (yl < commontop) + if (yl < temp_dc.commontop) { - source = &tempbuf[colnum + (yl << 2)]; - dest = R_Address(startx + colnum, yl); - count = commontop - yl; + source = &temp_dc.buf[colnum + (yl << 2)]; + dest = R_Address(temp_dc.startx + colnum, yl); + count = temp_dc.commontop - yl; while (--count >= 0) { - *dest = temptranslation[*source]; + *dest = temp_dc.translation[*source]; source += 4; dest += stride; } } // flush column tail - if (yh > commonbot) + if (yh > temp_dc.commonbot) { - source = &tempbuf[colnum + ((commonbot + 1) << 2)]; - dest = R_Address(startx + colnum, commonbot + 1); - count = yh - commonbot; + source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; + dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); + count = yh - temp_dc.commonbot; while (--count >= 0) { - *dest = temptranslation[*source]; + *dest = temp_dc.translation[*source]; source += 4; dest += stride; } @@ -335,19 +345,19 @@ static void R_FlushHTColormap(void) static void R_FlushQuadColormap(void) { - UINT8 *source = &tempbuf[commontop << 2]; - UINT8 *dest = R_Address(startx, commontop); + UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; + UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); INT32 count; const restrict INT32 stride = vid.width; - count = commonbot - commontop + 1; + count = temp_dc.commonbot - temp_dc.commontop + 1; while (--count >= 0) { - dest[0] = temptranslation[source[0]]; - dest[1] = temptranslation[source[1]]; - dest[2] = temptranslation[source[2]]; - dest[3] = temptranslation[source[3]]; + dest[0] = temp_dc.translation[source[0]]; + dest[1] = temp_dc.translation[source[1]]; + dest[2] = temp_dc.translation[source[2]]; + dest[3] = temp_dc.translation[source[3]]; source += 4; dest += stride; } @@ -360,16 +370,16 @@ static void R_FlushWholeColormapTrans(void) INT32 count, yl; const restrict INT32 stride = vid.width; - while (--temp_x >= 0) + while (--temp_dc.x >= 0) { - yl = tempyl[temp_x]; - source = &tempbuf[temp_x + (yl << 2)]; - dest = R_Address(startx + temp_x, yl); - count = tempyh[temp_x] - yl + 1; + yl = temp_dc.yl[temp_dc.x]; + source = &temp_dc.buf[temp_dc.x + (yl << 2)]; + dest = R_Address(temp_dc.startx + temp_dc.x, yl); + count = temp_dc.yh[temp_dc.x] - yl + 1; while (--count >= 0) { - *dest = temptranmap[(*dest << 8) + temptranslation[*source]]; + *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; source += 4; dest += stride; } @@ -386,34 +396,34 @@ static void R_FlushHTColormapTrans(void) while (colnum < 4) { - yl = tempyl[colnum]; - yh = tempyh[colnum]; + yl = temp_dc.yl[colnum]; + yh = temp_dc.yh[colnum]; // flush column head - if (yl < commontop) + if (yl < temp_dc.commontop) { - source = &tempbuf[colnum + (yl << 2)]; - dest = R_Address(startx + colnum, yl); - count = commontop - yl; + source = &temp_dc.buf[colnum + (yl << 2)]; + dest = R_Address(temp_dc.startx + colnum, yl); + count = temp_dc.commontop - yl; while (--count >= 0) { - *dest = temptranmap[(*dest << 8) + temptranslation[*source]]; + *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; source += 4; dest += stride; } } // flush column tail - if (yh > commonbot) + if (yh > temp_dc.commonbot) { - source = &tempbuf[colnum + ((commonbot + 1) << 2)]; - dest = R_Address(startx + colnum, commonbot + 1); - count = yh - commonbot; + source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; + dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); + count = yh - temp_dc.commonbot; while (--count >= 0) { - *dest = temptranmap[(*dest << 8) + temptranslation[*source]]; + *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; source += 4; dest += stride; } @@ -425,19 +435,19 @@ static void R_FlushHTColormapTrans(void) static void R_FlushQuadColormapTrans(void) { - UINT8 *source = &tempbuf[commontop << 2]; - UINT8 *dest = R_Address(startx, commontop); + UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; + UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); INT32 count; const restrict INT32 stride = vid.width; - count = commonbot - commontop + 1; + count = temp_dc.commonbot - temp_dc.commontop + 1; while (--count >= 0) { - dest[0] = temptranmap[(dest[0] << 8) + temptranslation[source[0]]]; - dest[1] = temptranmap[(dest[1] << 8) + temptranslation[source[1]]]; - dest[2] = temptranmap[(dest[2] << 8) + temptranslation[source[2]]]; - dest[3] = temptranmap[(dest[3] << 8) + temptranslation[source[3]]]; + dest[0] = temp_dc.tranmap[(dest[0] << 8) + temp_dc.translation[source[0]]]; + dest[1] = temp_dc.tranmap[(dest[1] << 8) + temp_dc.translation[source[1]]]; + dest[2] = temp_dc.tranmap[(dest[2] << 8) + temp_dc.translation[source[2]]]; + dest[3] = temp_dc.tranmap[(dest[3] << 8) + temp_dc.translation[source[3]]]; source += 4; dest += stride; } @@ -449,7 +459,7 @@ static void (*R_FlushQuadColumn)(void) = R_QuadFlushError; static void R_FlushColumns(void) { - if (temp_x != 4 || commontop >= commonbot) + if (temp_dc.x != 4 || temp_dc.commontop >= temp_dc.commonbot) R_FlushWholeColumns(); else { @@ -457,7 +467,7 @@ static void R_FlushColumns(void) R_FlushQuadColumn(); } - temp_x = 0; + temp_dc.x = 0; } // @@ -465,10 +475,10 @@ static void R_FlushColumns(void) // void R_ResetColumnBuffer(void) { - if (temp_x) + if (temp_dc.x) R_FlushColumns(); - temptype = FLUSH_NONE; + temp_dc.type = FLUSH_NONE; R_FlushWholeColumns = R_FlushWholeError; R_FlushHTColumns = R_FlushHTError; R_FlushQuadColumn = R_QuadFlushError; @@ -476,124 +486,124 @@ void R_ResetColumnBuffer(void) static UINT8 *R_GetBufferOpaque(drawcolumndata_t *dc) { - if (temp_x == 4 || - (temp_x && (temptype != FLUSH_OPAQUE || temp_x + startx != dc->x))) + if (temp_dc.x == 4 || + (temp_dc.x && (temp_dc.type != FLUSH_OPAQUE || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); - if (!temp_x) + if (!temp_dc.x) { - startx = dc->x; - tempyl[0] = commontop = dc->yl; - tempyh[0] = commonbot = dc->yh; - temptype = FLUSH_OPAQUE; + temp_dc.startx = dc->x; + temp_dc.yl[0] = temp_dc.commontop = dc->yl; + temp_dc.yh[0] = temp_dc.commonbot = dc->yh; + temp_dc.type = FLUSH_OPAQUE; R_FlushWholeColumns = R_FlushWholeOpaque; R_FlushHTColumns = R_FlushHTOpaque; R_FlushQuadColumn = R_FlushQuadOpaque; - temp_x += 1; - return &tempbuf[dc->yl << 2]; + temp_dc.x += 1; + return &temp_dc.buf[dc->yl << 2]; } - tempyl[temp_x] = dc->yl; - tempyh[temp_x] = dc->yh; + temp_dc.yl[temp_dc.x] = dc->yl; + temp_dc.yh[temp_dc.x] = dc->yh; - if (dc->yl > commontop) - commontop = dc->yl; - if (dc->yh < commonbot) - commonbot = dc->yh; + if (dc->yl > temp_dc.commontop) + temp_dc.commontop = dc->yl; + if (dc->yh < temp_dc.commonbot) + temp_dc.commonbot = dc->yh; - return &tempbuf[(dc->yl << 2) + temp_x++]; + return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; } static UINT8 *R_GetBufferTrans(drawcolumndata_t *dc) { - if (temp_x == 4 || dc->transmap != temptranmap || - (temp_x && (temptype != FLUSH_TRANS || temp_x + startx != dc->x))) + if (temp_dc.x == 4 || dc->transmap != temp_dc.tranmap || + (temp_dc.x && (temp_dc.type != FLUSH_TRANS || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); - if (!temp_x) + if (!temp_dc.x) { - startx = dc->x; - tempyl[0] = commontop = dc->yl; - tempyh[0] = commonbot = dc->yh; - temptype = FLUSH_TRANS; - temptranmap = dc->transmap; + temp_dc.startx = dc->x; + temp_dc.yl[0] = temp_dc.commontop = dc->yl; + temp_dc.yh[0] = temp_dc.commonbot = dc->yh; + temp_dc.type = FLUSH_TRANS; + temp_dc.tranmap = dc->transmap; R_FlushWholeColumns = R_FlushWholeTrans; R_FlushHTColumns = R_FlushHTTrans; R_FlushQuadColumn = R_FlushQuadTrans; - temp_x += 1; - return &tempbuf[dc->yl << 2]; + temp_dc.x += 1; + return &temp_dc.buf[dc->yl << 2]; } - tempyl[temp_x] = dc->yl; - tempyh[temp_x] = dc->yh; + temp_dc.yl[temp_dc.x] = dc->yl; + temp_dc.yh[temp_dc.x] = dc->yh; - if (dc->yl > commontop) - commontop = dc->yl; - if (dc->yh < commonbot) - commonbot = dc->yh; + if (dc->yl > temp_dc.commontop) + temp_dc.commontop = dc->yl; + if (dc->yh < temp_dc.commonbot) + temp_dc.commonbot = dc->yh; - return &tempbuf[(dc->yl << 2) + temp_x++]; + return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; } static UINT8 *R_GetBufferColormap(drawcolumndata_t *dc) { - if (temp_x == 4 || dc->translation != temptranslation || - (temp_x && (temptype != FLUSH_COLORMAP || temp_x + startx != dc->x))) + if (temp_dc.x == 4 || dc->translation != temp_dc.translation || + (temp_dc.x && (temp_dc.type != FLUSH_COLORMAP || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); - if (!temp_x) + if (!temp_dc.x) { - startx = dc->x; - tempyl[0] = commontop = dc->yl; - tempyh[0] = commonbot = dc->yh; - temptype = FLUSH_COLORMAP; - temptranslation = dc->translation; + temp_dc.startx = dc->x; + temp_dc.yl[0] = temp_dc.commontop = dc->yl; + temp_dc.yh[0] = temp_dc.commonbot = dc->yh; + temp_dc.type = FLUSH_COLORMAP; + temp_dc.translation = dc->translation; R_FlushWholeColumns = R_FlushWholeColormap; R_FlushHTColumns = R_FlushHTColormap; R_FlushQuadColumn = R_FlushQuadColormap; - temp_x += 1; - return &tempbuf[dc->yl << 2]; + temp_dc.x += 1; + return &temp_dc.buf[dc->yl << 2]; } - tempyl[temp_x] = dc->yl; - tempyh[temp_x] = dc->yh; + temp_dc.yl[temp_dc.x] = dc->yl; + temp_dc.yh[temp_dc.x] = dc->yh; - if (dc->yl > commontop) - commontop = dc->yl; - if (dc->yh < commonbot) - commonbot = dc->yh; + if (dc->yl > temp_dc.commontop) + temp_dc.commontop = dc->yl; + if (dc->yh < temp_dc.commonbot) + temp_dc.commonbot = dc->yh; - return &tempbuf[(dc->yl << 2) + temp_x++]; + return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; } static UINT8 *R_GetBufferColormapTrans(drawcolumndata_t *dc) { - if (temp_x == 4 || dc->translation != temptranslation || dc->transmap != temptranmap || - (temp_x && (temptype != FLUSH_COLORMAP_TRANS || temp_x + startx != dc->x))) + if (temp_dc.x == 4 || dc->translation != temp_dc.translation || dc->transmap != temp_dc.tranmap || + (temp_dc.x && (temp_dc.type != FLUSH_COLORMAP_TRANS || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); - if (!temp_x) + if (!temp_dc.x) { - startx = dc->x; - tempyl[0] = commontop = dc->yl; - tempyh[0] = commonbot = dc->yh; - temptype = FLUSH_COLORMAP_TRANS; - temptranslation = dc->translation; - temptranmap = dc->transmap; + temp_dc.startx = dc->x; + temp_dc.yl[0] = temp_dc.commontop = dc->yl; + temp_dc.yh[0] = temp_dc.commonbot = dc->yh; + temp_dc.type = FLUSH_COLORMAP_TRANS; + temp_dc.translation = dc->translation; + temp_dc.tranmap = dc->transmap; R_FlushWholeColumns = R_FlushWholeColormapTrans; R_FlushHTColumns = R_FlushHTColormapTrans; R_FlushQuadColumn = R_FlushQuadColormapTrans; - temp_x += 1; - return &tempbuf[dc->yl << 2]; + temp_dc.x += 1; + return &temp_dc.buf[dc->yl << 2]; } - tempyl[temp_x] = dc->yl; - tempyh[temp_x] = dc->yh; + temp_dc.yl[temp_dc.x] = dc->yl; + temp_dc.yh[temp_dc.x] = dc->yh; - if (dc->yl > commontop) - commontop = dc->yl; - if (dc->yh < commonbot) - commonbot = dc->yh; + if (dc->yl > temp_dc.commontop) + temp_dc.commontop = dc->yl; + if (dc->yh < temp_dc.commonbot) + temp_dc.commonbot = dc->yh; - return &tempbuf[(dc->yl << 2) + temp_x++]; + return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; } -- 2.54.0 From e68136de3eaa7080a5533af8993468754bf2b2fa Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 19:12:52 +0200 Subject: [PATCH 03/40] remove tempbuf resolution limit by allocating it dynamically per our actual screen resolution --- src/r_draw.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++ src/r_draw_flush.cpp | 76 ----------------------------------------- 2 files changed, 81 insertions(+), 76 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index c8a09745a..86b9fa5e1 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -489,6 +489,81 @@ void R_FlushTranslationColormapCache(void) // in reality, the few routines that can work for either mode, are // put here +enum ColumnFlushType +{ + FLUSH_NONE, + FLUSH_OPAQUE, + FLUSH_TRANS, + FLUSH_COLORMAP, + FLUSH_COLORMAP_TRANS +}; + +typedef struct drawcolumndata_temp_s +{ + intptr_t x; + intptr_t yl[4], yh[4]; + + // e6y: resolution limitation is removed + UINT8 *buf; + + intptr_t startx; + ColumnFlushType type; + intptr_t commontop, commonbot; + const UINT8 *tranmap; + // SoM 7-28-04: Fix the fuzz problem. + const UINT8 *translation; +} drawcolumndata_temp_t; + +drawcolumndata_temp_t temp_dc = {}; + +static void R_FlushColumns(void); + +static void R_FlushWholeError(void) +{ + I_Error("R_FlushWholeColumns called without being initialized.\n"); +} + +static void R_FlushHTError(void) +{ + I_Error("R_FlushHTColumns called without being initialized.\n"); +} + +static void R_QuadFlushError(void) +{ + I_Error("R_FlushQuadColumn called without being initialized.\n"); +} + +static void (*R_FlushWholeColumns)(void) = R_FlushWholeError; +static void (*R_FlushHTColumns)(void) = R_FlushHTError; +static void (*R_FlushQuadColumn)(void) = R_QuadFlushError; + +static void R_FlushColumns(void) +{ + if (temp_dc.x != 4 || temp_dc.commontop >= temp_dc.commonbot) + R_FlushWholeColumns(); + else + { + R_FlushHTColumns(); + R_FlushQuadColumn(); + } + + temp_dc.x = 0; +} + +// +// R_ResetColumnBuffer +// +void R_ResetColumnBuffer(void) +{ + if (temp_dc.x) + R_FlushColumns(); + + temp_dc.type = FLUSH_NONE; + R_FlushWholeColumns = R_FlushWholeError; + R_FlushHTColumns = R_FlushHTError; + R_FlushQuadColumn = R_QuadFlushError; +} + /** \brief The R_InitViewBuffer function Creates lookup tables for getting the framebuffer address @@ -536,6 +611,12 @@ void R_InitViewBuffer(INT32 width, INT32 height) linesize = vid.width; // killough 11/98 renderscreen = vid.screens[0]; // haleyjd 07/02/14 + + if (temp_dc.buf) + Z_Free(temp_dc.buf); + + memset(&temp_dc, 0, sizeof(temp_dc)); + temp_dc.buf = static_cast(Z_Calloc((vid.height * 4) * sizeof(*temp_dc.buf), PU_STATIC, NULL)); } /** \brief viewborder patches lump numbers diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index 8eb1d6266..b9b5ef04e 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -13,51 +13,6 @@ /// \brief column flush functions /// \note no includes because this is included as part of r_draw.cpp -enum ColumnFlushType -{ - FLUSH_NONE, - FLUSH_OPAQUE, - FLUSH_TRANS, - FLUSH_COLORMAP, - FLUSH_COLORMAP_TRANS -}; - -typedef struct drawcolumndata_temp_s -{ - intptr_t x; - intptr_t yl[4], yh[4]; - - // e6y: resolution limitation is removed - // not for now kek - UINT8 buf[MAXVIDWIDTH * 4]; - - intptr_t startx; - ColumnFlushType type; - intptr_t commontop, commonbot; - const UINT8 *tranmap; - // SoM 7-28-04: Fix the fuzz problem. - const UINT8 *translation; -} drawcolumndata_temp_t; - -drawcolumndata_temp_t temp_dc = {}; - -static void R_FlushColumns(void); - -static void R_FlushWholeError(void) -{ - I_Error("R_FlushWholeColumns called without being initialized.\n"); -} - -static void R_FlushHTError(void) -{ - I_Error("R_FlushHTColumns called without being initialized.\n"); -} - -static void R_QuadFlushError(void) -{ - I_Error("R_FlushQuadColumn called without being initialized.\n"); -} - // // R_FlushWholeOpaque // @@ -453,37 +408,6 @@ static void R_FlushQuadColormapTrans(void) } } -static void (*R_FlushWholeColumns)(void) = R_FlushWholeError; -static void (*R_FlushHTColumns)(void) = R_FlushHTError; -static void (*R_FlushQuadColumn)(void) = R_QuadFlushError; - -static void R_FlushColumns(void) -{ - if (temp_dc.x != 4 || temp_dc.commontop >= temp_dc.commonbot) - R_FlushWholeColumns(); - else - { - R_FlushHTColumns(); - R_FlushQuadColumn(); - } - - temp_dc.x = 0; -} - -// -// R_ResetColumnBuffer -// -void R_ResetColumnBuffer(void) -{ - if (temp_dc.x) - R_FlushColumns(); - - temp_dc.type = FLUSH_NONE; - R_FlushWholeColumns = R_FlushWholeError; - R_FlushHTColumns = R_FlushHTError; - R_FlushQuadColumn = R_QuadFlushError; -} - static UINT8 *R_GetBufferOpaque(drawcolumndata_t *dc) { if (temp_dc.x == 4 || -- 2.54.0 From 3c9292c13756f5ebfae337a33f8a6f0ffa702233 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 19:22:45 +0200 Subject: [PATCH 04/40] reorder column flush functions also add some comments that used to be in drawcolumn X) --- src/r_draw.cpp | 13 +- src/r_draw_column.cpp | 12 +- src/r_draw_flush.cpp | 308 +++++++++++++++++++++--------------------- 3 files changed, 175 insertions(+), 158 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 86b9fa5e1..b2cad26e0 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -516,8 +516,10 @@ typedef struct drawcolumndata_temp_s drawcolumndata_temp_t temp_dc = {}; -static void R_FlushColumns(void); - +// +// Error functions that will abort if R_FlushColumns tries to flush +// columns without a column type. +// static void R_FlushWholeError(void) { I_Error("R_FlushWholeColumns called without being initialized.\n"); @@ -553,10 +555,17 @@ static void R_FlushColumns(void) // // R_ResetColumnBuffer // +// haleyjd 09/13/04: new function to call from main rendering loop +// which gets rid of the unnecessary reset of various variables during +// column drawing. +// void R_ResetColumnBuffer(void) { + // haleyjd 10/06/05: this must not be done if x == 0! if (temp_dc.x) + { R_FlushColumns(); + } temp_dc.type = FLUSH_NONE; R_FlushWholeColumns = R_FlushWholeError; diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index ccb5c5403..cef7f85cd 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -84,8 +84,18 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) { INT32 count; + // leban 1/17/99: + // removed the + 1 here, adjusted the if test, and added an increment + // later. this helps a compiler pipeline a bit better. the x86 + // assembler also does this. count = dc->yh - dc->yl; + // leban 1/17/99: + // this case isn't executed too often. depending on how many instructions + // there are between here and the second if test below, this case could + // be moved down and might save instructions overall. since there are + // probably different wads that favor one way or the other, i'll leave + // this alone for now. if (count < 0) // Zero length, column does not exceed a pixel. { return; @@ -285,7 +295,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) { // Re-map color indices from wall texture column // using a lighting/special effects LUT. - // heightmask is the Tutti-Frutti fix + // heightmask is the Tutti-Frutti fix -- killough // -1 is the lower clamp bound because column posts have a "safe" byte before the real data // and a few bytes after as well diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index b9b5ef04e..b77ece5d5 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -14,11 +14,10 @@ /// \note no includes because this is included as part of r_draw.cpp // -// R_FlushWholeOpaque +// R_FlushWhole // // Flushes the entire columns in the buffer, one at a time. // This is used when a quad flush isn't possible. -// Opaque version -- no remapping whatsoever. // static void R_FlushWholeOpaque(void) { @@ -43,12 +42,80 @@ static void R_FlushWholeOpaque(void) } } +static void R_FlushWholeTrans(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count, yl; + const restrict INT32 stride = vid.width; + + while (--temp_dc.x >= 0) + { + yl = temp_dc.yl[temp_dc.x]; + source = &temp_dc.buf[temp_dc.x + (yl << 2)]; + dest = R_Address(temp_dc.startx + temp_dc.x, yl); + count = temp_dc.yh[temp_dc.x] - yl + 1; + + while (--count >= 0) + { + *dest = temp_dc.tranmap[(*dest << 8) + *source]; + source += 4; + dest += stride; + } + } +} + +static void R_FlushWholeColormap(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count, yl; + const restrict INT32 stride = vid.width; + + while (--temp_dc.x >= 0) + { + yl = temp_dc.yl[temp_dc.x]; + source = &temp_dc.buf[temp_dc.x + (yl << 2)]; + dest = R_Address(temp_dc.startx + temp_dc.x, yl); + count = temp_dc.yh[temp_dc.x] - yl + 1; + + while (--count >= 0) + { + *dest = temp_dc.translation[*source]; + source += 4; + dest += stride; + } + } +} + +static void R_FlushWholeColormapTrans(void) +{ + UINT8 *source; + UINT8 *dest; + INT32 count, yl; + const restrict INT32 stride = vid.width; + + while (--temp_dc.x >= 0) + { + yl = temp_dc.yl[temp_dc.x]; + source = &temp_dc.buf[temp_dc.x + (yl << 2)]; + dest = R_Address(temp_dc.startx + temp_dc.x, yl); + count = temp_dc.yh[temp_dc.x] - yl + 1; + + while (--count >= 0) + { + *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; + source += 4; + dest += stride; + } + } +} + // -// R_FlushHTOpaque +// R_FlushHT // // Flushes the head and tail of columns in the buffer in // preparation for a quad flush. -// Opaque version -- no remapping whatsoever. // static void R_FlushHTOpaque(void) { @@ -96,71 +163,6 @@ static void R_FlushHTOpaque(void) } } -static void R_FlushQuadOpaque(void) -{ - UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; - UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); - INT32 count; - const restrict INT32 stride = vid.width; - - count = temp_dc.commonbot - temp_dc.commontop + 1; - - if ((sizeof(int) == 4) && (((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) - { - while(--count >= 0) - { - *(int *)dest = *(int *)source; - source += 4 * sizeof(UINT8); - dest += stride * sizeof(UINT8); - } - } - else - { - while(--count >= 0) - { - dest[0] = source[0]; - dest[1] = source[1]; - dest[2] = source[2]; - dest[3] = source[3]; - source += 4 * sizeof(UINT8); - dest += stride * sizeof(UINT8); - } - } - - while(--count >= 0) - { - dest[0] = source[0]; - dest[1] = source[1]; - dest[2] = source[2]; - dest[3] = source[3]; - source += 4 * sizeof(UINT8); - dest += stride * sizeof(UINT8); - } -} - -static void R_FlushWholeTrans(void) -{ - UINT8 *source; - UINT8 *dest; - INT32 count, yl; - const restrict INT32 stride = vid.width; - - while (--temp_dc.x >= 0) - { - yl = temp_dc.yl[temp_dc.x]; - source = &temp_dc.buf[temp_dc.x + (yl << 2)]; - dest = R_Address(temp_dc.startx + temp_dc.x, yl); - count = temp_dc.yh[temp_dc.x] - yl + 1; - - while (--count >= 0) - { - *dest = temp_dc.tranmap[(*dest << 8) + *source]; - source += 4; - dest += stride; - } - } -} - static void R_FlushHTTrans(void) { UINT8 *source; @@ -208,49 +210,6 @@ static void R_FlushHTTrans(void) } } -static void R_FlushQuadTrans(void) -{ - UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; - UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); - INT32 count; - const restrict INT32 stride = vid.width; - - count = temp_dc.commonbot - temp_dc.commontop + 1; - - while (--count >= 0) - { - dest[0] = temp_dc.tranmap[(dest[0] << 8) + source[0]]; - dest[1] = temp_dc.tranmap[(dest[1] << 8) + source[1]]; - dest[2] = temp_dc.tranmap[(dest[2] << 8) + source[2]]; - dest[3] = temp_dc.tranmap[(dest[3] << 8) + source[3]]; - source += 4; - dest += stride; - } -} - -static void R_FlushWholeColormap(void) -{ - UINT8 *source; - UINT8 *dest; - INT32 count, yl; - const restrict INT32 stride = vid.width; - - while (--temp_dc.x >= 0) - { - yl = temp_dc.yl[temp_dc.x]; - source = &temp_dc.buf[temp_dc.x + (yl << 2)]; - dest = R_Address(temp_dc.startx + temp_dc.x, yl); - count = temp_dc.yh[temp_dc.x] - yl + 1; - - while (--count >= 0) - { - *dest = temp_dc.translation[*source]; - source += 4; - dest += stride; - } - } -} - static void R_FlushHTColormap(void) { UINT8 *source; @@ -298,49 +257,6 @@ static void R_FlushHTColormap(void) } } -static void R_FlushQuadColormap(void) -{ - UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; - UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); - INT32 count; - const restrict INT32 stride = vid.width; - - count = temp_dc.commonbot - temp_dc.commontop + 1; - - while (--count >= 0) - { - dest[0] = temp_dc.translation[source[0]]; - dest[1] = temp_dc.translation[source[1]]; - dest[2] = temp_dc.translation[source[2]]; - dest[3] = temp_dc.translation[source[3]]; - source += 4; - dest += stride; - } -} - -static void R_FlushWholeColormapTrans(void) -{ - UINT8 *source; - UINT8 *dest; - INT32 count, yl; - const restrict INT32 stride = vid.width; - - while (--temp_dc.x >= 0) - { - yl = temp_dc.yl[temp_dc.x]; - source = &temp_dc.buf[temp_dc.x + (yl << 2)]; - dest = R_Address(temp_dc.startx + temp_dc.x, yl); - count = temp_dc.yh[temp_dc.x] - yl + 1; - - while (--count >= 0) - { - *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; - source += 4; - dest += stride; - } - } -} - static void R_FlushHTColormapTrans(void) { UINT8 *source; @@ -388,6 +304,88 @@ static void R_FlushHTColormapTrans(void) } } +static void R_FlushQuadOpaque(void) +{ + UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; + UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); + INT32 count; + const restrict INT32 stride = vid.width; + + count = temp_dc.commonbot - temp_dc.commontop + 1; + + if ((sizeof(int) == 4) && (((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) + { + while(--count >= 0) + { + *(int *)dest = *(int *)source; + source += 4 * sizeof(UINT8); + dest += stride * sizeof(UINT8); + } + } + else + { + while(--count >= 0) + { + dest[0] = source[0]; + dest[1] = source[1]; + dest[2] = source[2]; + dest[3] = source[3]; + source += 4 * sizeof(UINT8); + dest += stride * sizeof(UINT8); + } + } + + while(--count >= 0) + { + dest[0] = source[0]; + dest[1] = source[1]; + dest[2] = source[2]; + dest[3] = source[3]; + source += 4 * sizeof(UINT8); + dest += stride * sizeof(UINT8); + } +} + +static void R_FlushQuadTrans(void) +{ + UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; + UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); + INT32 count; + const restrict INT32 stride = vid.width; + + count = temp_dc.commonbot - temp_dc.commontop + 1; + + while (--count >= 0) + { + dest[0] = temp_dc.tranmap[(dest[0] << 8) + source[0]]; + dest[1] = temp_dc.tranmap[(dest[1] << 8) + source[1]]; + dest[2] = temp_dc.tranmap[(dest[2] << 8) + source[2]]; + dest[3] = temp_dc.tranmap[(dest[3] << 8) + source[3]]; + source += 4; + dest += stride; + } +} + +static void R_FlushQuadColormap(void) +{ + UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; + UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); + INT32 count; + const restrict INT32 stride = vid.width; + + count = temp_dc.commonbot - temp_dc.commontop + 1; + + while (--count >= 0) + { + dest[0] = temp_dc.translation[source[0]]; + dest[1] = temp_dc.translation[source[1]]; + dest[2] = temp_dc.translation[source[2]]; + dest[3] = temp_dc.translation[source[3]]; + source += 4; + dest += stride; + } +} + static void R_FlushQuadColormapTrans(void) { UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; -- 2.54.0 From 2753052ee73e459b02c489a797ac49f1e49be5ee Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 19:45:31 +0200 Subject: [PATCH 05/40] fix FlushColumns being called without being initialized aack --- src/r_draw_flush.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index b77ece5d5..b1bbb464f 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -438,7 +438,7 @@ static UINT8 *R_GetBufferOpaque(drawcolumndata_t *dc) static UINT8 *R_GetBufferTrans(drawcolumndata_t *dc) { - if (temp_dc.x == 4 || dc->transmap != temp_dc.tranmap || + if (temp_dc.x == 4 || (temp_dc.x && (temp_dc.type != FLUSH_TRANS || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); @@ -469,7 +469,7 @@ static UINT8 *R_GetBufferTrans(drawcolumndata_t *dc) static UINT8 *R_GetBufferColormap(drawcolumndata_t *dc) { - if (temp_dc.x == 4 || dc->translation != temp_dc.translation || + if (temp_dc.x == 4 || (temp_dc.x && (temp_dc.type != FLUSH_COLORMAP || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); @@ -500,7 +500,7 @@ static UINT8 *R_GetBufferColormap(drawcolumndata_t *dc) static UINT8 *R_GetBufferColormapTrans(drawcolumndata_t *dc) { - if (temp_dc.x == 4 || dc->translation != temp_dc.translation || dc->transmap != temp_dc.tranmap || + if (temp_dc.x == 4 || (temp_dc.x && (temp_dc.type != FLUSH_COLORMAP_TRANS || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); -- 2.54.0 From 2b6185d7d6339917e2803bb392bd84f7b18ac47f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 20:02:58 +0200 Subject: [PATCH 06/40] reenable colormapped / translucent columns --- src/r_draw_column.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index cef7f85cd..d7954cf52 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -71,9 +71,7 @@ static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict } } - //return R_GetColumnTranslucent(dc, dest, col, colormap); - // dont return any other shit for now - return col; + return R_GetColumnTranslucent(dc, dest, col, colormap); } /** \brief The R_DrawColumn function @@ -210,13 +208,13 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) // Framebuffer destination address. // SoM: MAGIC - /*if constexpr (Type & (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) + if constexpr (Type & (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) dest = R_GetBufferColormapTrans(dc); else if constexpr (Type & DrawColumnType::DC_TRANSMAP) dest = R_GetBufferTrans(dc); else if constexpr (Type & DrawColumnType::DC_COLORMAP) dest = R_GetBufferColormap(dc); - else*/ + else dest = R_GetBufferOpaque(dc); count++; -- 2.54.0 From e4ac394d293b9769b12a9a83bba074426b698969 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 6 Oct 2025 21:17:36 +0300 Subject: [PATCH 07/40] Fix DC_COLORMAP and DC_TRANSMAP column drawers always using DC_COLORMAP|DC_TRANSMAP func --- src/r_draw_column.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index d7954cf52..a24318a35 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -208,7 +208,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) // Framebuffer destination address. // SoM: MAGIC - if constexpr (Type & (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) + 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); -- 2.54.0 From 955812bd8d0a1824dc7abb9cd47cddc0a6195653 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 22:09:27 +0200 Subject: [PATCH 08/40] template the flush functions --- src/r_draw_column.cpp | 7 +- src/r_draw_flush.cpp | 574 ++++++++++++++---------------------------- 2 files changed, 188 insertions(+), 393 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index a24318a35..c2275fbd4 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -204,11 +204,12 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) const UINT8 * restrict source = dc->source; const lighttable_t * restrict colormap = dc->colormap; - UINT8 * restrict dest; - // Framebuffer destination address. // SoM: MAGIC - if constexpr ((Type & (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) == (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) + UINT8 * restrict dest; + + 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); diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index b1bbb464f..23fd4beb3 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -19,10 +19,11 @@ // Flushes the entire columns in the buffer, one at a time. // This is used when a quad flush isn't possible. // -static void R_FlushWholeOpaque(void) +template +static void R_FlushWhole(void) { - UINT8 *source; - UINT8 *dest; + UINT8 * restrict source; + UINT8 * restrict dest; INT32 count, yl; const restrict INT32 stride = vid.width; @@ -35,81 +36,40 @@ static void R_FlushWholeOpaque(void) while (--count >= 0) { - *dest = *source; + if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) + { + *dest = *source; + } + else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) + { + *dest = temp_dc.tranmap[(*dest << 8) + *source]; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) + { + *dest = temp_dc.translation[*source]; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) + { + *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; + } + source += 4; dest += stride; } } } -static void R_FlushWholeTrans(void) -{ - UINT8 *source; - UINT8 *dest; - INT32 count, yl; - const restrict INT32 stride = vid.width; - - while (--temp_dc.x >= 0) - { - yl = temp_dc.yl[temp_dc.x]; - source = &temp_dc.buf[temp_dc.x + (yl << 2)]; - dest = R_Address(temp_dc.startx + temp_dc.x, yl); - count = temp_dc.yh[temp_dc.x] - yl + 1; - - while (--count >= 0) - { - *dest = temp_dc.tranmap[(*dest << 8) + *source]; - source += 4; - dest += stride; - } +#define DEFINE_GETFLUSHWHOLE_FUNC(name, flags) \ + static inline void name(void) \ + { \ + constexpr ColumnFlushType opt = static_cast(flags); \ + R_FlushWhole(); \ } -} -static void R_FlushWholeColormap(void) -{ - UINT8 *source; - UINT8 *dest; - INT32 count, yl; - const restrict INT32 stride = vid.width; - - while (--temp_dc.x >= 0) - { - yl = temp_dc.yl[temp_dc.x]; - source = &temp_dc.buf[temp_dc.x + (yl << 2)]; - dest = R_Address(temp_dc.startx + temp_dc.x, yl); - count = temp_dc.yh[temp_dc.x] - yl + 1; - - while (--count >= 0) - { - *dest = temp_dc.translation[*source]; - source += 4; - dest += stride; - } - } -} - -static void R_FlushWholeColormapTrans(void) -{ - UINT8 *source; - UINT8 *dest; - INT32 count, yl; - const restrict INT32 stride = vid.width; - - while (--temp_dc.x >= 0) - { - yl = temp_dc.yl[temp_dc.x]; - source = &temp_dc.buf[temp_dc.x + (yl << 2)]; - dest = R_Address(temp_dc.startx + temp_dc.x, yl); - count = temp_dc.yh[temp_dc.x] - yl + 1; - - while (--count >= 0) - { - *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; - source += 4; - dest += stride; - } - } -} +DEFINE_GETFLUSHWHOLE_FUNC(R_FlushWholeOpague, FLUSH_OPAQUE) +DEFINE_GETFLUSHWHOLE_FUNC(R_FlushWholeTrans, FLUSH_TRANS) +DEFINE_GETFLUSHWHOLE_FUNC(R_FlushWholeColormap, FLUSH_COLORMAP) +DEFINE_GETFLUSHWHOLE_FUNC(R_FlushWholeColormapTrans, FLUSH_COLORMAP_TRANS) // // R_FlushHT @@ -117,56 +77,11 @@ static void R_FlushWholeColormapTrans(void) // Flushes the head and tail of columns in the buffer in // preparation for a quad flush. // -static void R_FlushHTOpaque(void) +template +static void R_FlushHT(void) { - UINT8 *source; - UINT8 *dest; - INT32 count, colnum = 0; - INT32 yl, yh; - const restrict INT32 stride = vid.width; - - while (colnum < 4) - { - yl = temp_dc.yl[colnum]; - yh = temp_dc.yh[colnum]; - - // flush column head - if (yl < temp_dc.commontop) - { - source = &temp_dc.buf[colnum + (yl << 2)]; - dest = R_Address(temp_dc.startx + colnum, yl); - count = temp_dc.commontop - yl; - - while (--count >= 0) - { - *dest = *source; - source += 4; - dest += stride; - } - } - - // flush column tail - if (yh > temp_dc.commonbot) - { - source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; - dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); - count = yh - temp_dc.commonbot; - - while (--count >= 0) - { - *dest = *source; - source += 4; - dest += stride; - } - } - ++colnum; - } -} - -static void R_FlushHTTrans(void) -{ - UINT8 *source; - UINT8 *dest; + UINT8 * restrict source; + UINT8 * restrict dest; INT32 count; INT32 colnum = 0, yl, yh; const restrict INT32 stride = vid.width; @@ -185,7 +100,23 @@ static void R_FlushHTTrans(void) while (--count >= 0) { - *dest = temp_dc.tranmap[(*dest << 8) + *source]; + if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) + { + *dest = *source; + } + else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) + { + *dest = temp_dc.tranmap[(*dest << 8) + *source]; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) + { + *dest = temp_dc.translation[*source]; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) + { + *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; + } + source += 4; dest += stride; } @@ -200,7 +131,23 @@ static void R_FlushHTTrans(void) while (--count >= 0) { - *dest = temp_dc.tranmap[(*dest << 8) + *source]; + if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) + { + *dest = *source; + } + else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) + { + *dest = temp_dc.tranmap[(*dest << 8) + *source]; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) + { + *dest = temp_dc.translation[*source]; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) + { + *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; + } + source += 4; dest += stride; } @@ -210,206 +157,107 @@ static void R_FlushHTTrans(void) } } -static void R_FlushHTColormap(void) -{ - UINT8 *source; - UINT8 *dest; - INT32 count; - INT32 colnum = 0, yl, yh; - const restrict INT32 stride = vid.width; - - while (colnum < 4) - { - yl = temp_dc.yl[colnum]; - yh = temp_dc.yh[colnum]; - - // flush column head - if (yl < temp_dc.commontop) - { - source = &temp_dc.buf[colnum + (yl << 2)]; - dest = R_Address(temp_dc.startx + colnum, yl); - count = temp_dc.commontop - yl; - - while (--count >= 0) - { - *dest = temp_dc.translation[*source]; - source += 4; - dest += stride; - } - } - - // flush column tail - if (yh > temp_dc.commonbot) - { - source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; - dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); - count = yh - temp_dc.commonbot; - - while (--count >= 0) - { - *dest = temp_dc.translation[*source]; - source += 4; - dest += stride; - } - } - - ++colnum; +#define DEFINE_GETFLUSHHT_FUNC(name, flags) \ + static inline void name(void) \ + { \ + constexpr ColumnFlushType opt = static_cast(flags); \ + R_FlushHT(); \ } -} -static void R_FlushHTColormapTrans(void) +DEFINE_GETFLUSHHT_FUNC(R_FlushHTOpague, FLUSH_OPAQUE) +DEFINE_GETFLUSHHT_FUNC(R_FlushHTTrans, FLUSH_TRANS) +DEFINE_GETFLUSHHT_FUNC(R_FlushHTColormap, FLUSH_COLORMAP) +DEFINE_GETFLUSHHT_FUNC(R_FlushHTColormapTrans, FLUSH_COLORMAP_TRANS) + +template +static void R_FlushQuad(void) { - UINT8 *source; - UINT8 *dest; - INT32 count; - INT32 colnum = 0, yl, yh; - const restrict INT32 stride = vid.width; - - while (colnum < 4) - { - yl = temp_dc.yl[colnum]; - yh = temp_dc.yh[colnum]; - - // flush column head - if (yl < temp_dc.commontop) - { - source = &temp_dc.buf[colnum + (yl << 2)]; - dest = R_Address(temp_dc.startx + colnum, yl); - count = temp_dc.commontop - yl; - - while (--count >= 0) - { - *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; - source += 4; - dest += stride; - } - } - - // flush column tail - if (yh > temp_dc.commonbot) - { - source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; - dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); - count = yh - temp_dc.commonbot; - - while (--count >= 0) - { - *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; - source += 4; - dest += stride; - } - } - - ++colnum; - } -} - -static void R_FlushQuadOpaque(void) -{ - UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; - UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); + UINT8 * restrict source = &temp_dc.buf[temp_dc.commontop << 2]; + UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); INT32 count; const restrict INT32 stride = vid.width; count = temp_dc.commonbot - temp_dc.commontop + 1; - if ((sizeof(int) == 4) && (((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) + if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) { - while(--count >= 0) + if ((sizeof(int) == 4) && (((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) { - *(int *)dest = *(int *)source; - source += 4 * sizeof(UINT8); - dest += stride * sizeof(UINT8); + while(--count >= 0) + { + *(int *)dest = *(int *)source; + source += 4 * sizeof(UINT8); + dest += stride * sizeof(UINT8); + } + } + else + { + while(--count >= 0) + { + dest[0] = source[0]; + dest[1] = source[1]; + dest[2] = source[2]; + dest[3] = source[3]; + source += 4 * sizeof(UINT8); + dest += stride * sizeof(UINT8); + } } } - else + else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) { - while(--count >= 0) + while (--count >= 0) { - dest[0] = source[0]; - dest[1] = source[1]; - dest[2] = source[2]; - dest[3] = source[3]; - source += 4 * sizeof(UINT8); - dest += stride * sizeof(UINT8); + dest[0] = temp_dc.tranmap[(dest[0] << 8) + source[0]]; + dest[1] = temp_dc.tranmap[(dest[1] << 8) + source[1]]; + dest[2] = temp_dc.tranmap[(dest[2] << 8) + source[2]]; + dest[3] = temp_dc.tranmap[(dest[3] << 8) + source[3]]; + source += 4; + dest += stride; } } - - while(--count >= 0) + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) { - dest[0] = source[0]; - dest[1] = source[1]; - dest[2] = source[2]; - dest[3] = source[3]; - source += 4 * sizeof(UINT8); - dest += stride * sizeof(UINT8); + while (--count >= 0) + { + dest[0] = temp_dc.translation[source[0]]; + dest[1] = temp_dc.translation[source[1]]; + dest[2] = temp_dc.translation[source[2]]; + dest[3] = temp_dc.translation[source[3]]; + source += 4; + dest += stride; + } + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) + { + while (--count >= 0) + { + dest[0] = temp_dc.tranmap[(dest[0] << 8) + temp_dc.translation[source[0]]]; + dest[1] = temp_dc.tranmap[(dest[1] << 8) + temp_dc.translation[source[1]]]; + dest[2] = temp_dc.tranmap[(dest[2] << 8) + temp_dc.translation[source[2]]]; + dest[3] = temp_dc.tranmap[(dest[3] << 8) + temp_dc.translation[source[3]]]; + source += 4; + dest += stride; + } } } -static void R_FlushQuadTrans(void) -{ - UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; - UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); - INT32 count; - const restrict INT32 stride = vid.width; - - count = temp_dc.commonbot - temp_dc.commontop + 1; - - while (--count >= 0) - { - dest[0] = temp_dc.tranmap[(dest[0] << 8) + source[0]]; - dest[1] = temp_dc.tranmap[(dest[1] << 8) + source[1]]; - dest[2] = temp_dc.tranmap[(dest[2] << 8) + source[2]]; - dest[3] = temp_dc.tranmap[(dest[3] << 8) + source[3]]; - source += 4; - dest += stride; +#define DEFINE_GETFLUSHQUAD_FUNC(name, flags) \ + static inline void name(void) \ + { \ + constexpr ColumnFlushType opt = static_cast(flags); \ + R_FlushQuad(); \ } -} -static void R_FlushQuadColormap(void) -{ - UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; - UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); - INT32 count; - const restrict INT32 stride = vid.width; +DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadOpague, FLUSH_OPAQUE) +DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadTrans, FLUSH_TRANS) +DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadColormap, FLUSH_COLORMAP) +DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadColormapTrans, FLUSH_COLORMAP_TRANS) - count = temp_dc.commonbot - temp_dc.commontop + 1; - - while (--count >= 0) - { - dest[0] = temp_dc.translation[source[0]]; - dest[1] = temp_dc.translation[source[1]]; - dest[2] = temp_dc.translation[source[2]]; - dest[3] = temp_dc.translation[source[3]]; - source += 4; - dest += stride; - } -} - -static void R_FlushQuadColormapTrans(void) -{ - UINT8 *source = &temp_dc.buf[temp_dc.commontop << 2]; - UINT8 *dest = R_Address(temp_dc.startx, temp_dc.commontop); - INT32 count; - const restrict INT32 stride = vid.width; - - count = temp_dc.commonbot - temp_dc.commontop + 1; - - while (--count >= 0) - { - dest[0] = temp_dc.tranmap[(dest[0] << 8) + temp_dc.translation[source[0]]]; - dest[1] = temp_dc.tranmap[(dest[1] << 8) + temp_dc.translation[source[1]]]; - dest[2] = temp_dc.tranmap[(dest[2] << 8) + temp_dc.translation[source[2]]]; - dest[3] = temp_dc.tranmap[(dest[3] << 8) + temp_dc.translation[source[3]]]; - source += 4; - dest += stride; - } -} - -static UINT8 *R_GetBufferOpaque(drawcolumndata_t *dc) +template +static UINT8 *R_GetBuffer(drawcolumndata_t *dc) { if (temp_dc.x == 4 || - (temp_dc.x && (temp_dc.type != FLUSH_OPAQUE || temp_dc.x + temp_dc.startx != dc->x))) + (temp_dc.x && (temp_dc.type != Type || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); if (!temp_dc.x) @@ -417,10 +265,37 @@ static UINT8 *R_GetBufferOpaque(drawcolumndata_t *dc) temp_dc.startx = dc->x; temp_dc.yl[0] = temp_dc.commontop = dc->yl; temp_dc.yh[0] = temp_dc.commonbot = dc->yh; - temp_dc.type = FLUSH_OPAQUE; - R_FlushWholeColumns = R_FlushWholeOpaque; - R_FlushHTColumns = R_FlushHTOpaque; - R_FlushQuadColumn = R_FlushQuadOpaque; + temp_dc.type = Type; + + if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) + { + R_FlushWholeColumns = R_FlushWholeOpague; + R_FlushHTColumns = R_FlushHTOpague; + R_FlushQuadColumn = R_FlushQuadOpague; + } + else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) + { + temp_dc.tranmap = dc->transmap; + R_FlushWholeColumns = R_FlushWholeTrans; + R_FlushHTColumns = R_FlushHTTrans; + R_FlushQuadColumn = R_FlushQuadTrans; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) + { + temp_dc.translation = dc->translation; + R_FlushWholeColumns = R_FlushWholeColormap; + R_FlushHTColumns = R_FlushHTColormap; + R_FlushQuadColumn = R_FlushQuadColormap; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) + { + temp_dc.tranmap = dc->transmap; + temp_dc.translation = dc->translation; + R_FlushWholeColumns = R_FlushWholeColormapTrans; + R_FlushHTColumns = R_FlushHTColormapTrans; + R_FlushQuadColumn = R_FlushQuadColormapTrans; + } + temp_dc.x += 1; return &temp_dc.buf[dc->yl << 2]; } @@ -436,96 +311,15 @@ static UINT8 *R_GetBufferOpaque(drawcolumndata_t *dc) return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; } -static UINT8 *R_GetBufferTrans(drawcolumndata_t *dc) -{ - if (temp_dc.x == 4 || - (temp_dc.x && (temp_dc.type != FLUSH_TRANS || temp_dc.x + temp_dc.startx != dc->x))) - R_FlushColumns(); - - if (!temp_dc.x) - { - temp_dc.startx = dc->x; - temp_dc.yl[0] = temp_dc.commontop = dc->yl; - temp_dc.yh[0] = temp_dc.commonbot = dc->yh; - temp_dc.type = FLUSH_TRANS; - temp_dc.tranmap = dc->transmap; - R_FlushWholeColumns = R_FlushWholeTrans; - R_FlushHTColumns = R_FlushHTTrans; - R_FlushQuadColumn = R_FlushQuadTrans; - temp_dc.x += 1; - return &temp_dc.buf[dc->yl << 2]; +#define DEFINE_GETBUF_FUNC(name, flags) \ + static UINT8 *name(drawcolumndata_t *dc) \ + { \ + constexpr ColumnFlushType opt = static_cast(flags); \ + return R_GetBuffer(dc); \ } - temp_dc.yl[temp_dc.x] = dc->yl; - temp_dc.yh[temp_dc.x] = dc->yh; +DEFINE_GETBUF_FUNC(R_GetBufferOpaque, FLUSH_OPAQUE) +DEFINE_GETBUF_FUNC(R_GetBufferTrans, FLUSH_TRANS) +DEFINE_GETBUF_FUNC(R_GetBufferColormap, FLUSH_COLORMAP) +DEFINE_GETBUF_FUNC(R_GetBufferColormapTrans, FLUSH_COLORMAP_TRANS) - if (dc->yl > temp_dc.commontop) - temp_dc.commontop = dc->yl; - if (dc->yh < temp_dc.commonbot) - temp_dc.commonbot = dc->yh; - - return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; -} - -static UINT8 *R_GetBufferColormap(drawcolumndata_t *dc) -{ - if (temp_dc.x == 4 || - (temp_dc.x && (temp_dc.type != FLUSH_COLORMAP || temp_dc.x + temp_dc.startx != dc->x))) - R_FlushColumns(); - - if (!temp_dc.x) - { - temp_dc.startx = dc->x; - temp_dc.yl[0] = temp_dc.commontop = dc->yl; - temp_dc.yh[0] = temp_dc.commonbot = dc->yh; - temp_dc.type = FLUSH_COLORMAP; - temp_dc.translation = dc->translation; - R_FlushWholeColumns = R_FlushWholeColormap; - R_FlushHTColumns = R_FlushHTColormap; - R_FlushQuadColumn = R_FlushQuadColormap; - temp_dc.x += 1; - return &temp_dc.buf[dc->yl << 2]; - } - - temp_dc.yl[temp_dc.x] = dc->yl; - temp_dc.yh[temp_dc.x] = dc->yh; - - if (dc->yl > temp_dc.commontop) - temp_dc.commontop = dc->yl; - if (dc->yh < temp_dc.commonbot) - temp_dc.commonbot = dc->yh; - - return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; -} - -static UINT8 *R_GetBufferColormapTrans(drawcolumndata_t *dc) -{ - if (temp_dc.x == 4 || - (temp_dc.x && (temp_dc.type != FLUSH_COLORMAP_TRANS || temp_dc.x + temp_dc.startx != dc->x))) - R_FlushColumns(); - - if (!temp_dc.x) - { - temp_dc.startx = dc->x; - temp_dc.yl[0] = temp_dc.commontop = dc->yl; - temp_dc.yh[0] = temp_dc.commonbot = dc->yh; - temp_dc.type = FLUSH_COLORMAP_TRANS; - temp_dc.translation = dc->translation; - temp_dc.tranmap = dc->transmap; - R_FlushWholeColumns = R_FlushWholeColormapTrans; - R_FlushHTColumns = R_FlushHTColormapTrans; - R_FlushQuadColumn = R_FlushQuadColormapTrans; - temp_dc.x += 1; - return &temp_dc.buf[dc->yl << 2]; - } - - temp_dc.yl[temp_dc.x] = dc->yl; - temp_dc.yh[temp_dc.x] = dc->yh; - - if (dc->yl > temp_dc.commontop) - temp_dc.commontop = dc->yl; - if (dc->yh < temp_dc.commonbot) - temp_dc.commonbot = dc->yh; - - return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; -} -- 2.54.0 From b44548b7acf2a9ea254d8a2765f351ec2c99f7ef Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 22:43:49 +0200 Subject: [PATCH 09/40] dedupe those a bit --- src/r_draw_flush.cpp | 99 ++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 63 deletions(-) diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index 23fd4beb3..18bc207b9 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -13,6 +13,27 @@ /// \brief column flush functions /// \note no includes because this is included as part of r_draw.cpp +template +static inline UINT8 R_DrawFlushColumnPixel(UINT8 dest, UINT8 source) +{ + if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) + { + return source; + } + else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) + { + return temp_dc.tranmap[(dest << 8) + source]; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) + { + return temp_dc.translation[source]; + } + else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) + { + return temp_dc.tranmap[(dest << 8) + temp_dc.translation[source]]; + } +} + // // R_FlushWhole // @@ -24,8 +45,8 @@ static void R_FlushWhole(void) { UINT8 * restrict source; UINT8 * restrict dest; - INT32 count, yl; - const restrict INT32 stride = vid.width; + intptr_t count, yl; + const restrict intptr_t stride = vid.width; while (--temp_dc.x >= 0) { @@ -36,23 +57,7 @@ static void R_FlushWhole(void) while (--count >= 0) { - if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) - { - *dest = *source; - } - else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) - { - *dest = temp_dc.tranmap[(*dest << 8) + *source]; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) - { - *dest = temp_dc.translation[*source]; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) - { - *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; - } - + *dest = R_DrawFlushColumnPixel(*dest, *source); source += 4; dest += stride; } @@ -82,9 +87,9 @@ static void R_FlushHT(void) { UINT8 * restrict source; UINT8 * restrict dest; - INT32 count; - INT32 colnum = 0, yl, yh; - const restrict INT32 stride = vid.width; + intptr_t count, colnum = 0; + intptr_t yl, yh; + const restrict intptr_t stride = vid.width; while (colnum < 4) { @@ -95,28 +100,12 @@ static void R_FlushHT(void) if (yl < temp_dc.commontop) { source = &temp_dc.buf[colnum + (yl << 2)]; - dest = R_Address(temp_dc.startx + colnum, yl); - count = temp_dc.commontop - yl; + dest = R_Address(temp_dc.startx + colnum, yl); + count = temp_dc.commontop - yl; while (--count >= 0) { - if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) - { - *dest = *source; - } - else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) - { - *dest = temp_dc.tranmap[(*dest << 8) + *source]; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) - { - *dest = temp_dc.translation[*source]; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) - { - *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; - } - + *dest = R_DrawFlushColumnPixel(*dest, *source); source += 4; dest += stride; } @@ -126,28 +115,12 @@ static void R_FlushHT(void) if (yh > temp_dc.commonbot) { source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; - dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); - count = yh - temp_dc.commonbot; + dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); + count = yh - temp_dc.commonbot; while (--count >= 0) { - if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) - { - *dest = *source; - } - else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) - { - *dest = temp_dc.tranmap[(*dest << 8) + *source]; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) - { - *dest = temp_dc.translation[*source]; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) - { - *dest = temp_dc.tranmap[(*dest << 8) + temp_dc.translation[*source]]; - } - + *dest = R_DrawFlushColumnPixel(*dest, *source); source += 4; dest += stride; } @@ -174,8 +147,8 @@ static void R_FlushQuad(void) { UINT8 * restrict source = &temp_dc.buf[temp_dc.commontop << 2]; UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); - INT32 count; - const restrict INT32 stride = vid.width; + intptr_t count; + const restrict intptr_t stride = vid.width; count = temp_dc.commonbot - temp_dc.commontop + 1; @@ -312,7 +285,7 @@ static UINT8 *R_GetBuffer(drawcolumndata_t *dc) } #define DEFINE_GETBUF_FUNC(name, flags) \ - static UINT8 *name(drawcolumndata_t *dc) \ + static inline UINT8 *name(drawcolumndata_t *dc) \ { \ constexpr ColumnFlushType opt = static_cast(flags); \ return R_GetBuffer(dc); \ -- 2.54.0 From 23512f0a6c102db4b6c97978e85f69e38f0f7a4f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 6 Oct 2025 23:31:44 +0200 Subject: [PATCH 10/40] align our tempbuf --- src/r_draw.cpp | 19 +++++++++++++++++-- src/r_draw_flush.cpp | 8 ++++---- src/r_main.cpp | 10 +++++----- src/r_plane.cpp | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index b2cad26e0..eb43404df 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -621,11 +621,26 @@ void R_InitViewBuffer(INT32 width, INT32 height) linesize = vid.width; // killough 11/98 renderscreen = vid.screens[0]; // haleyjd 07/02/14 + INT32 bufsize = (linesize * 4) * sizeof(*temp_dc.buf); + if (temp_dc.buf) - Z_Free(temp_dc.buf); + { +#if defined(__SSE__) + aligned_free(temp_dc.buf); +#else + free(temp_dc.buf); +#endif + } memset(&temp_dc, 0, sizeof(temp_dc)); - temp_dc.buf = static_cast(Z_Calloc((vid.height * 4) * sizeof(*temp_dc.buf), PU_STATIC, NULL)); + +#if defined(__SSE__) + while (bufsize & 15) + bufsize++; + temp_dc.buf = static_cast(aligned_alloc(16, bufsize)); +#else + temp_dc.buf = static_cast(Z_Calloc(bufsize, PU_STATIC, NULL)); +#endif } /** \brief viewborder patches lump numbers diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index 18bc207b9..d27fb8cd8 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -65,7 +65,7 @@ static void R_FlushWhole(void) } #define DEFINE_GETFLUSHWHOLE_FUNC(name, flags) \ - static inline void name(void) \ + FUNCINLINE static ATTRINLINE void name(void) \ { \ constexpr ColumnFlushType opt = static_cast(flags); \ R_FlushWhole(); \ @@ -131,7 +131,7 @@ static void R_FlushHT(void) } #define DEFINE_GETFLUSHHT_FUNC(name, flags) \ - static inline void name(void) \ + FUNCINLINE static ATTRINLINE void name(void) \ { \ constexpr ColumnFlushType opt = static_cast(flags); \ R_FlushHT(); \ @@ -215,7 +215,7 @@ static void R_FlushQuad(void) } #define DEFINE_GETFLUSHQUAD_FUNC(name, flags) \ - static inline void name(void) \ + FUNCINLINE static ATTRINLINE void name(void) \ { \ constexpr ColumnFlushType opt = static_cast(flags); \ R_FlushQuad(); \ @@ -285,7 +285,7 @@ static UINT8 *R_GetBuffer(drawcolumndata_t *dc) } #define DEFINE_GETBUF_FUNC(name, flags) \ - static inline UINT8 *name(drawcolumndata_t *dc) \ + FUNCINLINE static ATTRINLINE UINT8 *name(drawcolumndata_t *dc) \ { \ constexpr ColumnFlushType opt = static_cast(flags); \ return R_GetBuffer(dc); \ diff --git a/src/r_main.cpp b/src/r_main.cpp index 132349a82..dd98f747b 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1409,9 +1409,9 @@ void R_RenderPlayerView(player_t *player) R_ClipSprites(drawsegs, NULL); R_DrawSkyPlanes(); // draw the fucker again to prevent some artifacts R_DrawPlanes(); - //R_ResetColumnBuffer(); + R_ResetColumnBuffer(); R_DrawMasked(masks, nummasks); - //R_ResetColumnBuffer(); + R_ResetColumnBuffer(); } PS_STOP_TIMING(ps_skyboxtime); @@ -1495,18 +1495,18 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_sw_planetime); if (!skybox) R_DrawSkyPlanes(); - R_ResetColumnBuffer(); R_DrawPlanes(); + R_ResetColumnBuffer(); PS_STOP_TIMING(ps_sw_planetime); // draw mid texture and sprite // And now 3D floors/sides! PS_START_TIMING(ps_sw_maskedtime); R_DrawMasked(masks, nummasks); PS_STOP_TIMING(ps_sw_maskedtime); - R_ResetColumnBuffer(); - free(masks); + R_ResetColumnBuffer(); + // Check for new console commands. NetUpdate(); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 16e344bdf..83508e16a 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1158,7 +1158,7 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle offset = (scry*vid.width) + scrx; // No idea if this works - VID_BlitLinearScreen(renderscreen + offset, + VID_BlitLinearScreen(vid.screens[0] + offset, vid.screens[1] + (top*vid.width), // intentionally not +offset viewwidth, bottom-top, vid.width, vid.width); -- 2.54.0 From fa8901f6b06003a744080b493c5c179a61f7b26e Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 00:25:27 +0200 Subject: [PATCH 11/40] fix ColumnFlushType enum --- src/r_draw.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index eb43404df..5234267e8 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -491,11 +491,11 @@ void R_FlushTranslationColormapCache(void) enum ColumnFlushType { - FLUSH_NONE, - FLUSH_OPAQUE, - FLUSH_TRANS, - FLUSH_COLORMAP, - FLUSH_COLORMAP_TRANS + FLUSH_NONE = 0x0000, + FLUSH_OPAQUE = 0x0001, + FLUSH_TRANS = 0x0002, + FLUSH_COLORMAP = 0x0004, + FLUSH_COLORMAP_TRANS = 0x0008, }; typedef struct drawcolumndata_temp_s -- 2.54.0 From 4deebf8912b6e7fc4bdeba81eef53529bc3c87d9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 00:28:34 +0200 Subject: [PATCH 12/40] translucency is handled on the flush side! --- src/r_draw_column.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index c2275fbd4..43107e721 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -48,11 +48,11 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * rest { col = R_GetColumnTranslated(dc, col, colormap); - if constexpr (Type & DrawColumnType::DC_TRANSMAP) + /*if constexpr (Type & DrawColumnType::DC_TRANSMAP) { return *(dc->transmap + (col << 8) + (*dest)); } - else + else*/ { return col; } -- 2.54.0 From e5a03dc3bb3a29ac41a481e7718e7254b2d50d19 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 01:01:13 +0200 Subject: [PATCH 13/40] fix translucency being only half as translucent oops lmao didnt notice in all of this doom uses the inverse of our blendlevels kek --- src/r_draw_column.cpp | 4 ++-- src/r_draw_flush.cpp | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 43107e721..b15294c75 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -44,7 +44,7 @@ static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, co } template -static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * restrict dest, UINT8 col, const UINT8 * restrict colormap) +static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 col, const UINT8 * restrict colormap) { col = R_GetColumnTranslated(dc, col, colormap); @@ -71,7 +71,7 @@ static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict } } - return R_GetColumnTranslucent(dc, dest, col, colormap); + return R_GetColumnTranslucent(dc, col, colormap); } /** \brief The R_DrawColumn function diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index d27fb8cd8..fcc94a767 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -22,7 +22,7 @@ static inline UINT8 R_DrawFlushColumnPixel(UINT8 dest, UINT8 source) } else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) { - return temp_dc.tranmap[(dest << 8) + source]; + return temp_dc.tranmap[(source << 8) + dest]; } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) { @@ -30,7 +30,7 @@ static inline UINT8 R_DrawFlushColumnPixel(UINT8 dest, UINT8 source) } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) { - return temp_dc.tranmap[(dest << 8) + temp_dc.translation[source]]; + return temp_dc.tranmap[(temp_dc.translation[source] << 8) + dest]; } } @@ -180,10 +180,10 @@ static void R_FlushQuad(void) { while (--count >= 0) { - dest[0] = temp_dc.tranmap[(dest[0] << 8) + source[0]]; - dest[1] = temp_dc.tranmap[(dest[1] << 8) + source[1]]; - dest[2] = temp_dc.tranmap[(dest[2] << 8) + source[2]]; - dest[3] = temp_dc.tranmap[(dest[3] << 8) + source[3]]; + dest[0] = temp_dc.tranmap[(source[0] << 8) + dest[0]]; + dest[1] = temp_dc.tranmap[(source[1] << 8) + dest[1]]; + dest[2] = temp_dc.tranmap[(source[2] << 8) + dest[2]]; + dest[3] = temp_dc.tranmap[(source[3] << 8) + dest[3]]; source += 4; dest += stride; } @@ -204,10 +204,10 @@ static void R_FlushQuad(void) { while (--count >= 0) { - dest[0] = temp_dc.tranmap[(dest[0] << 8) + temp_dc.translation[source[0]]]; - dest[1] = temp_dc.tranmap[(dest[1] << 8) + temp_dc.translation[source[1]]]; - dest[2] = temp_dc.tranmap[(dest[2] << 8) + temp_dc.translation[source[2]]]; - dest[3] = temp_dc.tranmap[(dest[3] << 8) + temp_dc.translation[source[3]]]; + dest[0] = temp_dc.tranmap[(temp_dc.translation[source[0]] << 8) + dest[0]]; + dest[1] = temp_dc.tranmap[(temp_dc.translation[source[1]] << 8) + dest[1]]; + dest[2] = temp_dc.tranmap[(temp_dc.translation[source[2]] << 8) + dest[2]]; + dest[3] = temp_dc.tranmap[(temp_dc.translation[source[3]] << 8) + dest[3]]; source += 4; dest += stride; } -- 2.54.0 From 39a5165d919e333d23fcb8ada6bdecf033ca599b Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 01:02:25 +0200 Subject: [PATCH 14/40] reset our column buffer directly after bsp traversal we do not need to wait for sky draw since the sky gets instantly drawn --- src/r_main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index dd98f747b..ac722dbdd 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1405,11 +1405,11 @@ void R_RenderPlayerView(player_t *player) R_ClearSprites(); R_RenderViewpoint(&masks[nummasks - 1], false); + R_ResetColumnBuffer(); R_ClipSprites(drawsegs, NULL); R_DrawSkyPlanes(); // draw the fucker again to prevent some artifacts R_DrawPlanes(); - R_ResetColumnBuffer(); R_DrawMasked(masks, nummasks); R_ResetColumnBuffer(); } @@ -1447,6 +1447,7 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_bsptime); R_RenderViewpoint(&masks[nummasks - 1], true); PS_STOP_TIMING(ps_bsptime); + R_ResetColumnBuffer(); PS_START_TIMING(ps_sw_spritecliptime); R_ClipSprites(drawsegs, NULL); PS_STOP_TIMING(ps_sw_spritecliptime); @@ -1496,7 +1497,6 @@ void R_RenderPlayerView(player_t *player) if (!skybox) R_DrawSkyPlanes(); R_DrawPlanes(); - R_ResetColumnBuffer(); PS_STOP_TIMING(ps_sw_planetime); // draw mid texture and sprite // And now 3D floors/sides! @@ -1504,7 +1504,6 @@ void R_RenderPlayerView(player_t *player) R_DrawMasked(masks, nummasks); PS_STOP_TIMING(ps_sw_maskedtime); free(masks); - R_ResetColumnBuffer(); // Check for new console commands. -- 2.54.0 From c9b6276a02aa46d662e6a66837bc90eb78d6259d Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 01:31:27 +0200 Subject: [PATCH 15/40] 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; -- 2.54.0 From 41b78feef5b2e81382fb354dce7c095fc101bf64 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 01:38:00 +0200 Subject: [PATCH 16/40] remove R_GetColumnTranslucent --- src/r_draw_column.cpp | 12 +++++++----- src/r_draw_flush.cpp | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 8ec979cde..4102035d1 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -44,20 +44,21 @@ static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, co return colormap[col]; } -template +// translucency is handled on flush side now! +/*template static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 col, const UINT8 * restrict colormap) { col = R_GetColumnTranslated(dc, col, colormap); - /*if constexpr (Type & DrawColumnType::DC_TRANSMAP) + if constexpr (Type & DrawColumnType::DC_TRANSMAP) { return *(dc->transmap + (col << 8) + (*dest)); } - else*/ + else { return col; } -} +}*/ template static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const UINT8 * restrict source, const UINT8 * restrict colormap) @@ -72,7 +73,8 @@ static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict } } - return R_GetColumnTranslucent(dc, col, colormap); + //return R_GetColumnTranslucent(dc, col, colormap); + return R_GetColumnTranslated(dc, col, colormap); } /** \brief The R_DrawColumn function diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index fcc94a767..53ce2f3f7 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -14,7 +14,7 @@ /// \note no includes because this is included as part of r_draw.cpp template -static inline UINT8 R_DrawFlushColumnPixel(UINT8 dest, UINT8 source) +FUNCINLINE static ATTRINLINE UINT8 R_DrawFlushColumnPixel(UINT8 restrict dest, UINT8 restrict source) { if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) { -- 2.54.0 From b6943ce92ef7e8f0efc477344b856909748441bc Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 01:48:34 +0200 Subject: [PATCH 17/40] can check on compile if sizeof int == 4 can prob remove it alltogether we dont support 16 bit cpus kek --- src/r_draw_flush.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index 53ce2f3f7..ff85f351d 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -154,7 +154,8 @@ static void R_FlushQuad(void) if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) { - if ((sizeof(int) == 4) && (((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) +#if __SIZEOF_INT__ == 4 + if ((((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) { while(--count >= 0) { @@ -164,6 +165,7 @@ static void R_FlushQuad(void) } } else +#endif { while(--count >= 0) { -- 2.54.0 From c9f50ca0c875a0c018052b375cf94acbaaf166ec Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 01:59:24 +0200 Subject: [PATCH 18/40] sizeof(UINT8) is 1 lel --- src/r_draw_flush.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index ff85f351d..96d58cccd 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -160,21 +160,21 @@ static void R_FlushQuad(void) while(--count >= 0) { *(int *)dest = *(int *)source; - source += 4 * sizeof(UINT8); - dest += stride * sizeof(UINT8); + source += 4; + dest += stride; } } else #endif { - while(--count >= 0) + while (--count >= 0) { dest[0] = source[0]; dest[1] = source[1]; dest[2] = source[2]; dest[3] = source[3]; - source += 4 * sizeof(UINT8); - dest += stride * sizeof(UINT8); + source += 4; + dest += stride; } } } -- 2.54.0 From ba3404d823a9da695fdc24f59dc26c14942eff46 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 16:00:12 +0200 Subject: [PATCH 19/40] cleanup + type fixes --- src/r_draw.cpp | 14 +++++----- src/r_draw_flush.cpp | 61 ++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 5234267e8..26184c158 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -500,18 +500,18 @@ enum ColumnFlushType typedef struct drawcolumndata_temp_s { - intptr_t x; - intptr_t yl[4], yh[4]; + INT32 x; + INT32 yl[4], yh[4]; // e6y: resolution limitation is removed UINT8 *buf; - intptr_t startx; + INT32 startx; ColumnFlushType type; - intptr_t commontop, commonbot; - const UINT8 *tranmap; + INT32 commontop, commonbot; + UINT8 *transmap; // SoM 7-28-04: Fix the fuzz problem. - const UINT8 *translation; + UINT8 *translation; } drawcolumndata_temp_t; drawcolumndata_temp_t temp_dc = {}; @@ -628,7 +628,7 @@ void R_InitViewBuffer(INT32 width, INT32 height) #if defined(__SSE__) aligned_free(temp_dc.buf); #else - free(temp_dc.buf); + Z_Free(temp_dc.buf); #endif } diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index 96d58cccd..bed7fd1fa 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -22,7 +22,7 @@ FUNCINLINE static ATTRINLINE UINT8 R_DrawFlushColumnPixel(UINT8 restrict dest, U } else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) { - return temp_dc.tranmap[(source << 8) + dest]; + return temp_dc.transmap[(source << 8) + dest]; } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) { @@ -30,7 +30,7 @@ FUNCINLINE static ATTRINLINE UINT8 R_DrawFlushColumnPixel(UINT8 restrict dest, U } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) { - return temp_dc.tranmap[(temp_dc.translation[source] << 8) + dest]; + return temp_dc.transmap[(temp_dc.translation[source] << 8) + dest]; } } @@ -45,8 +45,8 @@ static void R_FlushWhole(void) { UINT8 * restrict source; UINT8 * restrict dest; - intptr_t count, yl; - const restrict intptr_t stride = vid.width; + INT32 count, yl; + const INT32 stride = vid.width; while (--temp_dc.x >= 0) { @@ -87,9 +87,9 @@ static void R_FlushHT(void) { UINT8 * restrict source; UINT8 * restrict dest; - intptr_t count, colnum = 0; - intptr_t yl, yh; - const restrict intptr_t stride = vid.width; + INT32 count, colnum = 0; + INT32 yl, yh; + const INT32 stride = vid.width; while (colnum < 4) { @@ -147,19 +147,17 @@ static void R_FlushQuad(void) { UINT8 * restrict source = &temp_dc.buf[temp_dc.commontop << 2]; UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); - intptr_t count; - const restrict intptr_t stride = vid.width; - - count = temp_dc.commonbot - temp_dc.commontop + 1; + INT32 count = temp_dc.commonbot - temp_dc.commontop + 1; + const INT32 stride = vid.width; if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) { #if __SIZEOF_INT__ == 4 - if ((((intptr_t)source % 4) == 0) && (((intptr_t)dest % 4) == 0)) + if ((((uintptr_t)source | (uintptr_t)dest) & 3) == 0) { - while(--count >= 0) + while (--count >= 0) { - *(int *)dest = *(int *)source; + *(UINT32 *)dest = *(UINT32 *)source; source += 4; dest += stride; } @@ -180,36 +178,43 @@ static void R_FlushQuad(void) } else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) { + const UINT8 * restrict transmap = temp_dc.transmap; + while (--count >= 0) { - dest[0] = temp_dc.tranmap[(source[0] << 8) + dest[0]]; - dest[1] = temp_dc.tranmap[(source[1] << 8) + dest[1]]; - dest[2] = temp_dc.tranmap[(source[2] << 8) + dest[2]]; - dest[3] = temp_dc.tranmap[(source[3] << 8) + dest[3]]; + dest[0] = transmap[(source[0] << 8) + dest[0]]; + dest[1] = transmap[(source[1] << 8) + dest[1]]; + dest[2] = transmap[(source[2] << 8) + dest[2]]; + dest[3] = transmap[(source[3] << 8) + dest[3]]; source += 4; dest += stride; } } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) { + const UINT8 * restrict translation = temp_dc.translation; + while (--count >= 0) { - dest[0] = temp_dc.translation[source[0]]; - dest[1] = temp_dc.translation[source[1]]; - dest[2] = temp_dc.translation[source[2]]; - dest[3] = temp_dc.translation[source[3]]; + dest[0] = translation[source[0]]; + dest[1] = translation[source[1]]; + dest[2] = translation[source[2]]; + dest[3] = translation[source[3]]; source += 4; dest += stride; } } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) { + const UINT8 * restrict transmap = temp_dc.transmap; + const UINT8 * restrict translation = temp_dc.translation; + while (--count >= 0) { - dest[0] = temp_dc.tranmap[(temp_dc.translation[source[0]] << 8) + dest[0]]; - dest[1] = temp_dc.tranmap[(temp_dc.translation[source[1]] << 8) + dest[1]]; - dest[2] = temp_dc.tranmap[(temp_dc.translation[source[2]] << 8) + dest[2]]; - dest[3] = temp_dc.tranmap[(temp_dc.translation[source[3]] << 8) + dest[3]]; + dest[0] = transmap[(translation[source[0]] << 8) + dest[0]]; + dest[1] = transmap[(translation[source[1]] << 8) + dest[1]]; + dest[2] = transmap[(translation[source[2]] << 8) + dest[2]]; + dest[3] = transmap[(translation[source[3]] << 8) + dest[3]]; source += 4; dest += stride; } @@ -250,7 +255,7 @@ static UINT8 *R_GetBuffer(drawcolumndata_t *dc) } else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) { - temp_dc.tranmap = dc->transmap; + temp_dc.transmap = dc->transmap; R_FlushWholeColumns = R_FlushWholeTrans; R_FlushHTColumns = R_FlushHTTrans; R_FlushQuadColumn = R_FlushQuadTrans; @@ -264,7 +269,7 @@ static UINT8 *R_GetBuffer(drawcolumndata_t *dc) } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) { - temp_dc.tranmap = dc->transmap; + temp_dc.transmap = dc->transmap; temp_dc.translation = dc->translation; R_FlushWholeColumns = R_FlushWholeColormapTrans; R_FlushHTColumns = R_FlushHTColormapTrans; -- 2.54.0 From 32504b9e8ea568d13760b8dd6b51285f52d90930 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 16:50:43 +0200 Subject: [PATCH 20/40] speed up Opague quad flush from eternity engine --- src/r_draw_column.cpp | 7 ++++--- src/r_draw_flush.cpp | 41 ++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 4102035d1..aa5d03d91 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -199,6 +199,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) // killough 2/1/98: more performance tuning intptr_t frac; + // Looks familiar. const intptr_t fracstep = dc->iscale; const intptr_t heightmask = dc->sourcelength-1; // CPhipps - specify type constexpr INT32 npow2min = -1; @@ -223,12 +224,12 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) else dest = R_GetBufferOpaque(dc); - restrict INT32 stride = 4; + restrict INT32 stride = 4; //SoM: Oh, Oh it's MAGIC! You know... if constexpr (Type & DrawColumnType::DC_SKY) - stride = vid.width; + stride = vid.width; // no MAGIC for the sky here X) - count++; + count++; // killough 1/99: minor tuning // Determine scaling, which is the only mapping to be done. frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep)); diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index bed7fd1fa..f0fa37f14 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -145,39 +145,25 @@ DEFINE_GETFLUSHHT_FUNC(R_FlushHTColormapTrans, FLUSH_COLORMAP_TRANS) template static void R_FlushQuad(void) { - UINT8 * restrict source = &temp_dc.buf[temp_dc.commontop << 2]; - UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); - INT32 count = temp_dc.commonbot - temp_dc.commontop + 1; const INT32 stride = vid.width; + INT32 count = temp_dc.commonbot - temp_dc.commontop + 1; if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) { -#if __SIZEOF_INT__ == 4 - if ((((uintptr_t)source | (uintptr_t)dest) & 3) == 0) + const INT32 *source = reinterpret_cast(temp_dc.buf + (temp_dc.commontop << 2)); + INT32 *dest = reinterpret_cast(R_Address(temp_dc.startx, temp_dc.commontop)); + INT32 deststep = stride / 4; + + while(--count >= 0) { - while (--count >= 0) - { - *(UINT32 *)dest = *(UINT32 *)source; - source += 4; - dest += stride; - } - } - else -#endif - { - while (--count >= 0) - { - dest[0] = source[0]; - dest[1] = source[1]; - dest[2] = source[2]; - dest[3] = source[3]; - source += 4; - dest += stride; - } + *dest = *source++; + dest += deststep; } } else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) { + const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 2); + UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); const UINT8 * restrict transmap = temp_dc.transmap; while (--count >= 0) @@ -192,6 +178,8 @@ static void R_FlushQuad(void) } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) { + const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 2); + UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); const UINT8 * restrict translation = temp_dc.translation; while (--count >= 0) @@ -206,6 +194,8 @@ static void R_FlushQuad(void) } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) { + const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 2); + UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); const UINT8 * restrict transmap = temp_dc.transmap; const UINT8 * restrict translation = temp_dc.translation; @@ -236,12 +226,14 @@ DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadColormapTrans, FLUSH_COLORMAP_TRANS) template static UINT8 *R_GetBuffer(drawcolumndata_t *dc) { + // haleyjd: reordered predicates if (temp_dc.x == 4 || (temp_dc.x && (temp_dc.type != Type || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); if (!temp_dc.x) { + ++temp_dc.x; temp_dc.startx = dc->x; temp_dc.yl[0] = temp_dc.commontop = dc->yl; temp_dc.yh[0] = temp_dc.commonbot = dc->yh; @@ -276,7 +268,6 @@ static UINT8 *R_GetBuffer(drawcolumndata_t *dc) R_FlushQuadColumn = R_FlushQuadColormapTrans; } - temp_dc.x += 1; return &temp_dc.buf[dc->yl << 2]; } -- 2.54.0 From 57990100c563f828848a4ec37e49a699174aa264 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 17:18:30 +0200 Subject: [PATCH 21/40] speed up masked sprites a bit thx eternity engine! --- src/r_things.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index 4713bc50e..60dba8a32 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2810,6 +2810,11 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) drawseg_t* ds; INT32 i; + if (visspritecount - clippedvissprites <= 0) + { + return; + } + // e6y // Reducing of cache misses in the following R_DrawSprite() // Makes sense for scenes with huge amount of drawsegs. @@ -2819,13 +2824,9 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) drawsegs_xranges[i].count = 0; } - if (visspritecount - clippedvissprites <= 0) - { - return; - } - if (drawsegs_xrange_size < maxdrawsegs) { + // haleyjd: fix reallocation to track 2x size drawsegs_xrange_size = 2 * maxdrawsegs; for (i = 0; i < DS_RANGES_COUNT; i++) @@ -2865,6 +2866,9 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) } } + // haleyjd: terminate with a nullptr user for faster loop - adds ~3 FPS + drawsegs_xranges[0].items[drawsegs_xranges[0].count].user = nullptr; + for (; clippedvissprites < visspritecount; clippedvissprites++) { vissprite_t *spr = R_GetVisSprite(clippedvissprites); -- 2.54.0 From b12989f51ca3b0614bd16be9c427aaecabae5a54 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 17:19:07 +0200 Subject: [PATCH 22/40] lessen our manual column buffer resetting not really needed --- src/r_main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index ac722dbdd..f2ee2bc96 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1405,7 +1405,6 @@ void R_RenderPlayerView(player_t *player) R_ClearSprites(); R_RenderViewpoint(&masks[nummasks - 1], false); - R_ResetColumnBuffer(); R_ClipSprites(drawsegs, NULL); R_DrawSkyPlanes(); // draw the fucker again to prevent some artifacts @@ -1447,7 +1446,6 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_bsptime); R_RenderViewpoint(&masks[nummasks - 1], true); PS_STOP_TIMING(ps_bsptime); - R_ResetColumnBuffer(); PS_START_TIMING(ps_sw_spritecliptime); R_ClipSprites(drawsegs, NULL); PS_STOP_TIMING(ps_sw_spritecliptime); -- 2.54.0 From fe54f2fba2af916f658aea75f54caf4f2c4191cc Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 18:15:11 +0200 Subject: [PATCH 23/40] add Column drawer context switching reasoning explained in screen.c effectively, there are cases where drawing our columns directly to the screen is the better choice --- src/r_draw.cpp | 2 ++ src/r_draw.h | 21 ++++++++++++++++-- src/r_draw_column.cpp | 50 ++++++++++++++++++++++++++++--------------- src/r_main.cpp | 5 +++++ src/r_plane.cpp | 12 +++++------ src/screen.c | 43 +++++++++++++++++++++++++++++-------- src/screen.h | 1 + 7 files changed, 99 insertions(+), 35 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 26184c158..93638708b 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -489,6 +489,8 @@ void R_FlushTranslationColormapCache(void) // in reality, the few routines that can work for either mode, are // put here +enum columncontext_e columncontext = COLUMNCONTEXT_DIRECT; + enum ColumnFlushType { FLUSH_NONE = 0x0000, diff --git a/src/r_draw.h b/src/r_draw.h index 232e6c8ce..ae9d2ef40 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -102,6 +102,16 @@ extern floatv3_t *ds_su, *ds_sv, *ds_sz; extern float focallengthf; +enum columncontext_e +{ + COLUMNCONTEXT_DIRECT = 0, + COLUMNCONTEXT_FLUSH, +}; + +extern enum columncontext_e columncontext; +void R_SetColumnContext(enum columncontext_e _columncontext); + +void R_ResetColumnBuffer(void); typedef void (coldrawfunc_t)(drawcolumndata_t*); typedef void (spandrawfunc_t)(drawspandata_t*); @@ -250,10 +260,17 @@ void R_DrawTranslatedTranslucentColumn(drawcolumndata_t* dc); void R_Draw2sMultiPatchColumn(drawcolumndata_t* dc); void R_Draw2sMultiPatchTranslucentColumn(drawcolumndata_t* dc); +// column drawers which use buffered drawing with flush +void R_DrawColumnFlush(drawcolumndata_t* dc); +void R_DrawTranslucentColumnFlush(drawcolumndata_t* dc); +void R_DrawTranslatedColumnFlush(drawcolumndata_t* dc); +void R_DrawColumnShadowedFlush(drawcolumndata_t* dc); +void R_DrawTranslatedTranslucentColumnFlush(drawcolumndata_t* dc); +void R_Draw2sMultiPatchColumnFlush(drawcolumndata_t* dc); +void R_Draw2sMultiPatchTranslucentColumnFlush(drawcolumndata_t* dc); + void R_DrawFogColumn(drawcolumndata_t* dc); -void R_ResetColumnBuffer(void); -void R_DrawSkyColumn(drawcolumndata_t *dc); // span drawers void R_DrawSpan(drawspandata_t* ds); diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index aa5d03d91..27b570b0b 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -30,7 +30,7 @@ enum DrawColumnType DC_TRANSMAP = 0x0002, DC_HOLES = 0x0004, DC_LIGHTLIST = 0x0008, - DC_SKY = 0x0010, + DC_DIRECT = 0x0010, // draw our columns directly to screen! }; template @@ -45,8 +45,8 @@ static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, co } // translucency is handled on flush side now! -/*template -static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 col, const UINT8 * restrict colormap) +template +static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * restrict dest, UINT8 col, const UINT8 * restrict colormap) { col = R_GetColumnTranslated(dc, col, colormap); @@ -58,7 +58,7 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 col, c { return col; } -}*/ +} template static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const UINT8 * restrict source, const UINT8 * restrict colormap) @@ -73,8 +73,14 @@ static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict } } - //return R_GetColumnTranslucent(dc, col, colormap); - return R_GetColumnTranslated(dc, col, colormap); + if constexpr (Type & DrawColumnType::DC_DIRECT) + { // if we dont flush our columns, we need to handle translucency again + return R_GetColumnTranslucent(dc, dest, col, colormap); + } + else + { + return R_GetColumnTranslated(dc, col, colormap); + } } /** \brief The R_DrawColumn function @@ -212,7 +218,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) // SoM: MAGIC UINT8 * restrict dest; - if constexpr (Type & DrawColumnType::DC_SKY) + if constexpr (Type & DrawColumnType::DC_DIRECT) dest = R_Address(dc->x, dc->yl); else if constexpr ((Type & (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) == (DrawColumnType::DC_COLORMAP | DrawColumnType::DC_TRANSMAP)) @@ -226,8 +232,8 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) restrict INT32 stride = 4; //SoM: Oh, Oh it's MAGIC! You know... - if constexpr (Type & DrawColumnType::DC_SKY) - stride = vid.width; // no MAGIC for the sky here X) + if constexpr (Type & DrawColumnType::DC_DIRECT) + stride = vid.width; count++; // killough 1/99: minor tuning @@ -349,14 +355,24 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) R_DrawColumnTemplate(dc); \ } -DEFINE_COLUMN_FUNC(R_DrawColumn, DC_BASIC) -DEFINE_COLUMN_FUNC(R_DrawTranslucentColumn, DC_TRANSMAP) -DEFINE_COLUMN_FUNC(R_DrawTranslatedColumn, DC_COLORMAP) -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) +DEFINE_COLUMN_FUNC(R_DrawColumn, DC_DIRECT|DC_BASIC) +DEFINE_COLUMN_FUNC(R_DrawTranslucentColumn, DC_DIRECT|DC_TRANSMAP) +DEFINE_COLUMN_FUNC(R_DrawTranslatedColumn, DC_DIRECT|DC_COLORMAP) +DEFINE_COLUMN_FUNC(R_DrawColumnShadowed, DC_DIRECT|DC_LIGHTLIST) +DEFINE_COLUMN_FUNC(R_DrawTranslatedTranslucentColumn, DC_DIRECT|DC_COLORMAP|DC_TRANSMAP) +DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchColumn, DC_DIRECT|DC_HOLES) +DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumn, DC_DIRECT|DC_HOLES|DC_TRANSMAP) + +DEFINE_COLUMN_FUNC(R_DrawColumnFlush, DC_BASIC) +DEFINE_COLUMN_FUNC(R_DrawTranslucentColumnFlush, DC_TRANSMAP) +DEFINE_COLUMN_FUNC(R_DrawTranslatedColumnFlush, DC_COLORMAP) +DEFINE_COLUMN_FUNC(R_DrawColumnShadowedFlush, DC_LIGHTLIST) +DEFINE_COLUMN_FUNC(R_DrawTranslatedTranslucentColumnFlush, DC_COLORMAP|DC_TRANSMAP) +DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchColumnFlush, DC_HOLES) +DEFINE_COLUMN_FUNC(R_Draw2sMultiPatchTranslucentColumnFlush, DC_HOLES|DC_TRANSMAP) + +//skymyass +//DEFINE_COLUMN_FUNC(R_DrawSkyColumn, DC_SKY) /** \brief The R_DrawFogColumn function Fog wall. diff --git a/src/r_main.cpp b/src/r_main.cpp index f2ee2bc96..79e49438f 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1391,6 +1391,8 @@ void R_RenderPlayerView(player_t *player) R_SetFov(fov); } + R_SetColumnContext(COLUMNCONTEXT_FLUSH); + Portal_InitList(); PS_START_TIMING(ps_skyboxtime); @@ -1407,6 +1409,7 @@ void R_RenderPlayerView(player_t *player) R_RenderViewpoint(&masks[nummasks - 1], false); R_ClipSprites(drawsegs, NULL); + R_SetColumnContext(COLUMNCONTEXT_DIRECT); R_DrawSkyPlanes(); // draw the fucker again to prevent some artifacts R_DrawPlanes(); R_DrawMasked(masks, nummasks); @@ -1442,6 +1445,7 @@ void R_RenderPlayerView(player_t *player) // check for new console commands. NetUpdate(); + R_SetColumnContext(COLUMNCONTEXT_FLUSH); ps_numbspcalls.value.i = ps_numpolyobjects.value.i = ps_numdrawnodes.value.i = 0; PS_START_TIMING(ps_bsptime); R_RenderViewpoint(&masks[nummasks - 1], true); @@ -1491,6 +1495,7 @@ void R_RenderPlayerView(player_t *player) } PS_STOP_TIMING(ps_sw_portaltime); + R_SetColumnContext(COLUMNCONTEXT_DIRECT); PS_START_TIMING(ps_sw_planetime); if (!skybox) R_DrawSkyPlanes(); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 7c2ff271d..71e6a4dca 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, boolean allow_parallel); +static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), 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, cv_parallelsoftware.value); + R_DrawSkyPlane(pl, colfunc, cv_parallelsoftware.value); } } #ifdef HAVE_THREADS @@ -767,7 +767,7 @@ void R_DrawSkyPlanes(void) #endif } -static void R_DrawSkyPlane(visplane_t *pl, boolean allow_parallel) +static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), boolean allow_parallel) { INT32 x; @@ -834,8 +834,7 @@ static void R_DrawSkyPlane(visplane_t *pl, boolean allow_parallel) dc.x = x + i; dc.source = R_GetColumn(texture, -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 - //colfunc2(&dc); - R_DrawSkyColumn(&dc); + colfunc2(&dc); } }; @@ -872,8 +871,7 @@ static void R_DrawSkyPlane(visplane_t *pl, boolean allow_parallel) R_GetColumn(texturetranslation[skytexture], -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 - //colfunc2(&dc); - R_DrawSkyColumn(&dc); + colfunc2(&dc); } #endif } diff --git a/src/screen.c b/src/screen.c index 21ec0ed52..735bb88c4 100644 --- a/src/screen.c +++ b/src/screen.c @@ -84,7 +84,7 @@ UINT8 *scr_borderpatch; // flat used to fill the reduced view borders set at ST_ // ========================================================================= -static void SCR_SetDrawFuncs(void) +static void SCR_SetDrawFuncs(enum columncontext_e _columncontext) { // // setup the right draw routines @@ -103,13 +103,27 @@ static void SCR_SetDrawFuncs(void) spanfuncs[SPANDRAWFUNC_FOG] = R_DrawFogSpan; spanfuncs[SPANDRAWFUNC_TILTEDFOG] = R_DrawFogSpan_Tilted; - colfuncs[BASEDRAWFUNC] = R_DrawColumn; - colfuncs[COLDRAWFUNC_FUZZY] = R_DrawTranslucentColumn; - colfuncs[COLDRAWFUNC_TRANS] = R_DrawTranslatedColumn; - colfuncs[COLDRAWFUNC_SHADOWED] = R_DrawColumnShadowed; - colfuncs[COLDRAWFUNC_TRANSTRANS] = R_DrawTranslatedTranslucentColumn; - colfuncs[COLDRAWFUNC_TWOSMULTIPATCH] = R_Draw2sMultiPatchColumn; - colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS] = R_Draw2sMultiPatchTranslucentColumn; + if (_columncontext == COLUMNCONTEXT_FLUSH) + { + colfuncs[BASEDRAWFUNC] = R_DrawColumnFlush; + colfuncs[COLDRAWFUNC_FUZZY] = R_DrawTranslucentColumnFlush; + colfuncs[COLDRAWFUNC_TRANS] = R_DrawTranslatedColumnFlush; + colfuncs[COLDRAWFUNC_SHADOWED] = R_DrawColumnShadowedFlush; + colfuncs[COLDRAWFUNC_TRANSTRANS] = R_DrawTranslatedTranslucentColumnFlush; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCH] = R_Draw2sMultiPatchColumnFlush; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS] = R_Draw2sMultiPatchTranslucentColumnFlush; + } + else + { + colfuncs[BASEDRAWFUNC] = R_DrawColumn; + colfuncs[COLDRAWFUNC_FUZZY] = R_DrawTranslucentColumn; + colfuncs[COLDRAWFUNC_TRANS] = R_DrawTranslatedColumn; + colfuncs[COLDRAWFUNC_SHADOWED] = R_DrawColumnShadowed; + colfuncs[COLDRAWFUNC_TRANSTRANS] = R_DrawTranslatedTranslucentColumn; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCH] = R_Draw2sMultiPatchColumn; + colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS] = R_Draw2sMultiPatchTranslucentColumn; + } + colfuncs[COLDRAWFUNC_FOG] = R_DrawFogColumn; R_SetColumnFunc(BASEDRAWFUNC); @@ -131,12 +145,23 @@ void SCR_SetMode(void) V_SetPalette(0); - SCR_SetDrawFuncs(); + SCR_SetDrawFuncs(COLUMNCONTEXT_DIRECT); // set the apprpriate drawer for the sky (tall or INT16) setmodeneeded = 0; } +// used to switch between column buffering and drawing them directly to screen +// our sky "plane" drawer cannot handle the buffer system due to multithreading +// (that would require alot of extra complexity for smth with massive diminishing results) +// Our masked drawing step draws things in a very particular order, which results in alot of flushing to screen +// effectively adding massive overhead during buffering, so we draw our masked thing directly to screen instead +void R_SetColumnContext(enum columncontext_e _columncontext) +{ + columncontext = _columncontext; + SCR_SetDrawFuncs(_columncontext); // set our column drawers +} + void R_SetColumnFunc(size_t id) { I_Assert(id < COLDRAWFUNC_MAX); diff --git a/src/screen.h b/src/screen.h index ecad24a64..8cd90c23a 100644 --- a/src/screen.h +++ b/src/screen.h @@ -96,6 +96,7 @@ extern consvar_t cv_vidwait; extern consvar_t cv_votebgscaling; +//void R_SetColumnContext(enum columncontext_e _columncontext); // declared in r_draw! void R_SetColumnFunc(size_t id); void R_SetSpanFunc(size_t id); boolean R_CheckColumnFunc(size_t id); -- 2.54.0 From 55afe9be7e94967222a1ed3944c83850cfec1e74 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 20:47:47 +0200 Subject: [PATCH 24/40] update copyright header for draw flush stuff --- src/r_draw_flush.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index f0fa37f14..1baf98f31 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -4,13 +4,17 @@ // Copyright (C) 2020 by Sonic Team Junior. // Copyright (C) 2000 by DooM Legacy Team. // Copyright (C) 1996 by id Software, Inc. +// Copyright (C) 1999 by Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman +// Copyright (C) 1999-2000 by Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze +// Copyright (C) Copyright 2005, 2006 by Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko +// Copyright (C) 2013 by James Haley, Stephen McGranahan, et al. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- /// \file r_draw_flush.cpp -/// \brief column flush functions +/// \brief Optimized quad column buffer code. By SoM. /// \note no includes because this is included as part of r_draw.cpp template @@ -22,6 +26,7 @@ FUNCINLINE static ATTRINLINE UINT8 R_DrawFlushColumnPixel(UINT8 restrict dest, U } else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) { + // haleyjd 09/11/04: use temptranmap here return temp_dc.transmap[(source << 8) + dest]; } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) @@ -30,6 +35,7 @@ FUNCINLINE static ATTRINLINE UINT8 R_DrawFlushColumnPixel(UINT8 restrict dest, U } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) { + // haleyjd 09/11/04: use temptranmap here return temp_dc.transmap[(temp_dc.translation[source] << 8) + dest]; } } @@ -142,6 +148,7 @@ DEFINE_GETFLUSHHT_FUNC(R_FlushHTTrans, FLUSH_TRANS) DEFINE_GETFLUSHHT_FUNC(R_FlushHTColormap, FLUSH_COLORMAP) DEFINE_GETFLUSHHT_FUNC(R_FlushHTColormapTrans, FLUSH_COLORMAP_TRANS) +// Begin: Quad column flushing functions. template static void R_FlushQuad(void) { @@ -168,6 +175,7 @@ static void R_FlushQuad(void) while (--count >= 0) { + // haleyjd 09/11/04: use temptranmap here dest[0] = transmap[(source[0] << 8) + dest[0]]; dest[1] = transmap[(source[1] << 8) + dest[1]]; dest[2] = transmap[(source[2] << 8) + dest[2]]; @@ -201,6 +209,7 @@ static void R_FlushQuad(void) while (--count >= 0) { + // haleyjd 09/11/04: use temptranmap here dest[0] = transmap[(translation[source[0]] << 8) + dest[0]]; dest[1] = transmap[(translation[source[1]] << 8) + dest[1]]; dest[2] = transmap[(translation[source[2]] << 8) + dest[2]]; @@ -223,6 +232,9 @@ DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadTrans, FLUSH_TRANS) DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadColormap, FLUSH_COLORMAP) DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadColormapTrans, FLUSH_COLORMAP_TRANS) +// haleyjd 09/12/04: split up R_GetBuffer into various different +// functions to minimize the number of branches and take advantage +// of as much precalculated information as possible. template static UINT8 *R_GetBuffer(drawcolumndata_t *dc) { -- 2.54.0 From 8c8f96cf49758cf254d48796bd8ca1931e7d28d6 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 21:53:01 +0200 Subject: [PATCH 25/40] force flush our column buffer directly after bsp traversal (again) TODO: actually check what portals do --- src/r_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index 79e49438f..6dd5a8563 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1453,6 +1453,7 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_sw_spritecliptime); R_ClipSprites(drawsegs, NULL); PS_STOP_TIMING(ps_sw_spritecliptime); + R_ResetColumnBuffer(); ps_numsprites.value.i = numvisiblesprites; @@ -1507,7 +1508,6 @@ void R_RenderPlayerView(player_t *player) R_DrawMasked(masks, nummasks); PS_STOP_TIMING(ps_sw_maskedtime); free(masks); - R_ResetColumnBuffer(); // Check for new console commands. NetUpdate(); -- 2.54.0 From 0843a586f854b9fb99698c72b3b771e8c3a260e1 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 7 Oct 2025 22:45:25 +0200 Subject: [PATCH 26/40] fuckit, lets buffer 8 columns instead of 4 improves performance across the board on my ryzen 5600 cpu between 10 -15fps + in best case and around 5fps+ in worst case will need to check how this affects older cpus and 32bit builds since we do 64bit copies now (if needed can always add 32bit specific code) effectively, we also reduce the amount of flushing needed in many cases, writing more things at once during flushes --- src/r_draw.cpp | 6 ++--- src/r_draw_column.cpp | 2 +- src/r_draw_flush.cpp | 52 ++++++++++++++++++++++++++----------------- src/r_main.cpp | 2 +- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 93638708b..288cf462d 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -503,7 +503,7 @@ enum ColumnFlushType typedef struct drawcolumndata_temp_s { INT32 x; - INT32 yl[4], yh[4]; + INT32 yl[8], yh[8]; // e6y: resolution limitation is removed UINT8 *buf; @@ -543,7 +543,7 @@ static void (*R_FlushQuadColumn)(void) = R_QuadFlushError; static void R_FlushColumns(void) { - if (temp_dc.x != 4 || temp_dc.commontop >= temp_dc.commonbot) + if (temp_dc.x != 8 || temp_dc.commontop >= temp_dc.commonbot) R_FlushWholeColumns(); else { @@ -623,7 +623,7 @@ void R_InitViewBuffer(INT32 width, INT32 height) linesize = vid.width; // killough 11/98 renderscreen = vid.screens[0]; // haleyjd 07/02/14 - INT32 bufsize = (linesize * 4) * sizeof(*temp_dc.buf); + INT32 bufsize = (linesize * 8) * sizeof(*temp_dc.buf); if (temp_dc.buf) { diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 27b570b0b..58de4eebd 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -230,7 +230,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) else dest = R_GetBufferOpaque(dc); - restrict INT32 stride = 4; //SoM: Oh, Oh it's MAGIC! You know... + restrict INT32 stride = 8; //SoM: Oh, Oh it's MAGIC! You know... if constexpr (Type & DrawColumnType::DC_DIRECT) stride = vid.width; diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index 1baf98f31..3ef763a4e 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -57,14 +57,14 @@ static void R_FlushWhole(void) while (--temp_dc.x >= 0) { yl = temp_dc.yl[temp_dc.x]; - source = &temp_dc.buf[temp_dc.x + (yl << 2)]; + source = &temp_dc.buf[temp_dc.x + (yl << 3)]; dest = R_Address(temp_dc.startx + temp_dc.x, yl); count = temp_dc.yh[temp_dc.x] - yl + 1; while (--count >= 0) { *dest = R_DrawFlushColumnPixel(*dest, *source); - source += 4; + source += 8; dest += stride; } } @@ -97,7 +97,7 @@ static void R_FlushHT(void) INT32 yl, yh; const INT32 stride = vid.width; - while (colnum < 4) + while (colnum < 8) { yl = temp_dc.yl[colnum]; yh = temp_dc.yh[colnum]; @@ -105,14 +105,14 @@ static void R_FlushHT(void) // flush column head if (yl < temp_dc.commontop) { - source = &temp_dc.buf[colnum + (yl << 2)]; + source = &temp_dc.buf[colnum + (yl << 3)]; dest = R_Address(temp_dc.startx + colnum, yl); count = temp_dc.commontop - yl; while (--count >= 0) { *dest = R_DrawFlushColumnPixel(*dest, *source); - source += 4; + source += 8; dest += stride; } } @@ -120,14 +120,14 @@ static void R_FlushHT(void) // flush column tail if (yh > temp_dc.commonbot) { - source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 2)]; + source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 3)]; dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); count = yh - temp_dc.commonbot; while (--count >= 0) { *dest = R_DrawFlushColumnPixel(*dest, *source); - source += 4; + source += 8; dest += stride; } } @@ -157,11 +157,11 @@ static void R_FlushQuad(void) if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) { - const INT32 *source = reinterpret_cast(temp_dc.buf + (temp_dc.commontop << 2)); - INT32 *dest = reinterpret_cast(R_Address(temp_dc.startx, temp_dc.commontop)); - INT32 deststep = stride / 4; + const INT64 *source = reinterpret_cast(temp_dc.buf + (temp_dc.commontop << 3)); + INT64 *dest = reinterpret_cast(R_Address(temp_dc.startx, temp_dc.commontop)); + INT32 deststep = stride / 8; - while(--count >= 0) + while (--count >= 0) { *dest = *source++; dest += deststep; @@ -169,7 +169,7 @@ static void R_FlushQuad(void) } else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) { - const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 2); + const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 3); UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); const UINT8 * restrict transmap = temp_dc.transmap; @@ -180,13 +180,17 @@ static void R_FlushQuad(void) dest[1] = transmap[(source[1] << 8) + dest[1]]; dest[2] = transmap[(source[2] << 8) + dest[2]]; dest[3] = transmap[(source[3] << 8) + dest[3]]; - source += 4; + dest[4] = transmap[(source[4] << 8) + dest[4]]; + dest[5] = transmap[(source[5] << 8) + dest[5]]; + dest[6] = transmap[(source[6] << 8) + dest[6]]; + dest[7] = transmap[(source[7] << 8) + dest[7]]; + source += 8; dest += stride; } } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) { - const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 2); + const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 3); UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); const UINT8 * restrict translation = temp_dc.translation; @@ -196,13 +200,17 @@ static void R_FlushQuad(void) dest[1] = translation[source[1]]; dest[2] = translation[source[2]]; dest[3] = translation[source[3]]; - source += 4; + dest[4] = translation[source[4]]; + dest[5] = translation[source[5]]; + dest[6] = translation[source[6]]; + dest[7] = translation[source[7]]; + source += 8; dest += stride; } } else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) { - const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 2); + const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 3); UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); const UINT8 * restrict transmap = temp_dc.transmap; const UINT8 * restrict translation = temp_dc.translation; @@ -214,7 +222,11 @@ static void R_FlushQuad(void) dest[1] = transmap[(translation[source[1]] << 8) + dest[1]]; dest[2] = transmap[(translation[source[2]] << 8) + dest[2]]; dest[3] = transmap[(translation[source[3]] << 8) + dest[3]]; - source += 4; + dest[4] = transmap[(translation[source[4]] << 8) + dest[4]]; + dest[5] = transmap[(translation[source[5]] << 8) + dest[5]]; + dest[6] = transmap[(translation[source[6]] << 8) + dest[6]]; + dest[7] = transmap[(translation[source[7]] << 8) + dest[7]]; + source += 8; dest += stride; } } @@ -239,7 +251,7 @@ template static UINT8 *R_GetBuffer(drawcolumndata_t *dc) { // haleyjd: reordered predicates - if (temp_dc.x == 4 || + if (temp_dc.x == 8 || (temp_dc.x && (temp_dc.type != Type || temp_dc.x + temp_dc.startx != dc->x))) R_FlushColumns(); @@ -280,7 +292,7 @@ static UINT8 *R_GetBuffer(drawcolumndata_t *dc) R_FlushQuadColumn = R_FlushQuadColormapTrans; } - return &temp_dc.buf[dc->yl << 2]; + return &temp_dc.buf[dc->yl << 3]; } temp_dc.yl[temp_dc.x] = dc->yl; @@ -291,7 +303,7 @@ static UINT8 *R_GetBuffer(drawcolumndata_t *dc) if (dc->yh < temp_dc.commonbot) temp_dc.commonbot = dc->yh; - return &temp_dc.buf[(dc->yl << 2) + temp_dc.x++]; + return &temp_dc.buf[(dc->yl << 3) + temp_dc.x++]; } #define DEFINE_GETBUF_FUNC(name, flags) \ diff --git a/src/r_main.cpp b/src/r_main.cpp index 6dd5a8563..2a04c6600 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1409,11 +1409,11 @@ void R_RenderPlayerView(player_t *player) R_RenderViewpoint(&masks[nummasks - 1], false); R_ClipSprites(drawsegs, NULL); + R_ResetColumnBuffer(); R_SetColumnContext(COLUMNCONTEXT_DIRECT); R_DrawSkyPlanes(); // draw the fucker again to prevent some artifacts R_DrawPlanes(); R_DrawMasked(masks, nummasks); - R_ResetColumnBuffer(); } PS_STOP_TIMING(ps_skyboxtime); -- 2.54.0 From 48dc5461cdc9049e671ceb5dd99937f318bdfcb9 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Oct 2025 16:47:01 +0200 Subject: [PATCH 27/40] cleanup column flusher stuff - properly make use of templates!, reduce code dupe - inline the "DrawPixel" stuff - use local "const" pointers everywhere --- src/r_draw_column.cpp | 11 +- src/r_draw_flush.cpp | 269 +++++++++++++++--------------------------- src/r_draw_span.cpp | 9 +- src/screen.c | 2 +- 4 files changed, 112 insertions(+), 179 deletions(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 58de4eebd..08cfa00a1 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -34,7 +34,8 @@ enum DrawColumnType }; template -static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, const UINT8 * restrict colormap) +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_GetColumnTranslated(const drawcolumndata_t* dc, UINT8 col, const UINT8 * restrict colormap) { if constexpr (Type & DrawColumnType::DC_COLORMAP) { @@ -46,7 +47,8 @@ static constexpr UINT8 R_GetColumnTranslated(drawcolumndata_t* dc, UINT8 col, co // translucency is handled on flush side now! template -static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * restrict dest, UINT8 col, const UINT8 * restrict colormap) +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_GetColumnTranslucent(const drawcolumndata_t* dc, UINT8 * restrict dest, UINT8 col, const UINT8 * restrict colormap) { col = R_GetColumnTranslated(dc, col, colormap); @@ -61,7 +63,8 @@ static constexpr UINT8 R_GetColumnTranslucent(drawcolumndata_t* dc, UINT8 * rest } template -static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const UINT8 * restrict source, const UINT8 * restrict colormap) +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_DrawColumnPixel(const drawcolumndata_t* dc, UINT8 * restrict dest, UINT32 bit, const UINT8 * restrict source, const UINT8 * restrict colormap) { UINT8 col = source[bit]; @@ -74,7 +77,7 @@ static constexpr UINT8 R_DrawColumnPixel(drawcolumndata_t* dc, UINT8 * restrict } if constexpr (Type & DrawColumnType::DC_DIRECT) - { // if we dont flush our columns, we need to handle translucency again + { // if we dont buffer our columns, we need to handle translucency again return R_GetColumnTranslucent(dc, dest, col, colormap); } else diff --git a/src/r_draw_flush.cpp b/src/r_draw_flush.cpp index 3ef763a4e..80da61705 100644 --- a/src/r_draw_flush.cpp +++ b/src/r_draw_flush.cpp @@ -18,28 +18,42 @@ /// \note no includes because this is included as part of r_draw.cpp template -FUNCINLINE static ATTRINLINE UINT8 R_DrawFlushColumnPixel(UINT8 restrict dest, UINT8 restrict source) +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_GetFlushPixelTranslated(const drawcolumndata_temp_t *t_dc, UINT8 col) { - if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) + if constexpr (Type & (ColumnFlushType::FLUSH_COLORMAP | ColumnFlushType::FLUSH_COLORMAP_TRANS)) { - return source; + col = t_dc->translation[col]; } - else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) + + return col; +} + +template +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_GetFlushPixelTranslucent(const drawcolumndata_temp_t *t_dc, UINT8 * restrict dest, UINT8 col) +{ + col = R_GetFlushPixelTranslated(t_dc, col); + + if constexpr (Type & (ColumnFlushType::FLUSH_TRANS | ColumnFlushType::FLUSH_COLORMAP_TRANS)) { // haleyjd 09/11/04: use temptranmap here - return temp_dc.transmap[(source << 8) + dest]; + return *(t_dc->transmap + (col << 8) + (*dest)); } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) + else { - return temp_dc.translation[source]; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) - { - // haleyjd 09/11/04: use temptranmap here - return temp_dc.transmap[(temp_dc.translation[source] << 8) + dest]; + return col; } } +template +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_DrawFlushPixel(const drawcolumndata_temp_t *t_dc, UINT8 * restrict dest, const UINT8 * restrict source) +{ + UINT8 col = *source; + return R_GetFlushPixelTranslucent(t_dc, dest, col); +} + // // R_FlushWhole // @@ -53,35 +67,25 @@ static void R_FlushWhole(void) UINT8 * restrict dest; INT32 count, yl; const INT32 stride = vid.width; + drawcolumndata_temp_t *t_dc = &temp_dc; + UINT8 *restrict buf = t_dc->buf; - while (--temp_dc.x >= 0) + while (--t_dc->x >= 0) { - yl = temp_dc.yl[temp_dc.x]; - source = &temp_dc.buf[temp_dc.x + (yl << 3)]; - dest = R_Address(temp_dc.startx + temp_dc.x, yl); - count = temp_dc.yh[temp_dc.x] - yl + 1; + yl = t_dc->yl[t_dc->x]; + source = &buf[t_dc->x + (yl << 3)]; + dest = R_Address(t_dc->startx + t_dc->x, yl); + count = t_dc->yh[t_dc->x] - yl + 1; while (--count >= 0) { - *dest = R_DrawFlushColumnPixel(*dest, *source); + *dest = R_DrawFlushPixel(t_dc, dest, source); source += 8; - dest += stride; + dest += stride; } } } -#define DEFINE_GETFLUSHWHOLE_FUNC(name, flags) \ - FUNCINLINE static ATTRINLINE void name(void) \ - { \ - constexpr ColumnFlushType opt = static_cast(flags); \ - R_FlushWhole(); \ - } - -DEFINE_GETFLUSHWHOLE_FUNC(R_FlushWholeOpague, FLUSH_OPAQUE) -DEFINE_GETFLUSHWHOLE_FUNC(R_FlushWholeTrans, FLUSH_TRANS) -DEFINE_GETFLUSHWHOLE_FUNC(R_FlushWholeColormap, FLUSH_COLORMAP) -DEFINE_GETFLUSHWHOLE_FUNC(R_FlushWholeColormapTrans, FLUSH_COLORMAP_TRANS) - // // R_FlushHT // @@ -96,39 +100,41 @@ static void R_FlushHT(void) INT32 count, colnum = 0; INT32 yl, yh; const INT32 stride = vid.width; + const drawcolumndata_temp_t *t_dc = &temp_dc; + UINT8 *restrict buf = t_dc->buf; while (colnum < 8) { - yl = temp_dc.yl[colnum]; - yh = temp_dc.yh[colnum]; + yl = t_dc->yl[colnum]; + yh = t_dc->yh[colnum]; // flush column head - if (yl < temp_dc.commontop) + if (yl < t_dc->commontop) { - source = &temp_dc.buf[colnum + (yl << 3)]; - dest = R_Address(temp_dc.startx + colnum, yl); - count = temp_dc.commontop - yl; + source = &buf[colnum + (yl << 3)]; + dest = R_Address(t_dc->startx + colnum, yl); + count = t_dc->commontop - yl; while (--count >= 0) { - *dest = R_DrawFlushColumnPixel(*dest, *source); + *dest = R_DrawFlushPixel(t_dc, dest, source); source += 8; - dest += stride; + dest += stride; } } // flush column tail - if (yh > temp_dc.commonbot) + if (yh > t_dc->commonbot) { - source = &temp_dc.buf[colnum + ((temp_dc.commonbot + 1) << 3)]; - dest = R_Address(temp_dc.startx + colnum, temp_dc.commonbot + 1); - count = yh - temp_dc.commonbot; + source = &buf[colnum + ((t_dc->commonbot + 1) << 3)]; + dest = R_Address(t_dc->startx + colnum, t_dc->commonbot + 1); + count = yh - t_dc->commonbot; while (--count >= 0) { - *dest = R_DrawFlushColumnPixel(*dest, *source); + *dest = R_DrawFlushPixel(t_dc, dest, source); source += 8; - dest += stride; + dest += stride; } } @@ -136,30 +142,20 @@ static void R_FlushHT(void) } } -#define DEFINE_GETFLUSHHT_FUNC(name, flags) \ - FUNCINLINE static ATTRINLINE void name(void) \ - { \ - constexpr ColumnFlushType opt = static_cast(flags); \ - R_FlushHT(); \ - } - -DEFINE_GETFLUSHHT_FUNC(R_FlushHTOpague, FLUSH_OPAQUE) -DEFINE_GETFLUSHHT_FUNC(R_FlushHTTrans, FLUSH_TRANS) -DEFINE_GETFLUSHHT_FUNC(R_FlushHTColormap, FLUSH_COLORMAP) -DEFINE_GETFLUSHHT_FUNC(R_FlushHTColormapTrans, FLUSH_COLORMAP_TRANS) - // Begin: Quad column flushing functions. template static void R_FlushQuad(void) { const INT32 stride = vid.width; - INT32 count = temp_dc.commonbot - temp_dc.commontop + 1; + const drawcolumndata_temp_t *t_dc = &temp_dc; + INT32 count = t_dc->commonbot - t_dc->commontop + 1; + const UINT8 *restrict buf = t_dc->buf; if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) { - const INT64 *source = reinterpret_cast(temp_dc.buf + (temp_dc.commontop << 3)); - INT64 *dest = reinterpret_cast(R_Address(temp_dc.startx, temp_dc.commontop)); - INT32 deststep = stride / 8; + const INT64 *source = reinterpret_cast(buf + (t_dc->commontop << 3)); + INT64 *dest = reinterpret_cast(R_Address(t_dc->startx, t_dc->commontop)); + const INT32 deststep = stride / 8; while (--count >= 0) { @@ -167,143 +163,74 @@ static void R_FlushQuad(void) dest += deststep; } } - else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) + else { - const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 3); - UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); - const UINT8 * restrict transmap = temp_dc.transmap; + const UINT8 * restrict source = buf + (t_dc->commontop << 3); + UINT8 * restrict dest = R_Address(t_dc->startx, t_dc->commontop); while (--count >= 0) { - // haleyjd 09/11/04: use temptranmap here - dest[0] = transmap[(source[0] << 8) + dest[0]]; - dest[1] = transmap[(source[1] << 8) + dest[1]]; - dest[2] = transmap[(source[2] << 8) + dest[2]]; - dest[3] = transmap[(source[3] << 8) + dest[3]]; - dest[4] = transmap[(source[4] << 8) + dest[4]]; - dest[5] = transmap[(source[5] << 8) + dest[5]]; - dest[6] = transmap[(source[6] << 8) + dest[6]]; - dest[7] = transmap[(source[7] << 8) + dest[7]]; + dest[0] = R_DrawFlushPixel(t_dc, &dest[0], &source[0]); + dest[1] = R_DrawFlushPixel(t_dc, &dest[1], &source[1]); + dest[2] = R_DrawFlushPixel(t_dc, &dest[2], &source[2]); + dest[3] = R_DrawFlushPixel(t_dc, &dest[3], &source[3]); + dest[4] = R_DrawFlushPixel(t_dc, &dest[4], &source[4]); + dest[5] = R_DrawFlushPixel(t_dc, &dest[5], &source[5]); + dest[6] = R_DrawFlushPixel(t_dc, &dest[6], &source[6]); + dest[7] = R_DrawFlushPixel(t_dc, &dest[7], &source[7]); source += 8; - dest += stride; - } - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) - { - const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 3); - UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); - const UINT8 * restrict translation = temp_dc.translation; - - while (--count >= 0) - { - dest[0] = translation[source[0]]; - dest[1] = translation[source[1]]; - dest[2] = translation[source[2]]; - dest[3] = translation[source[3]]; - dest[4] = translation[source[4]]; - dest[5] = translation[source[5]]; - dest[6] = translation[source[6]]; - dest[7] = translation[source[7]]; - source += 8; - dest += stride; - } - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) - { - const UINT8 * restrict source = temp_dc.buf + (temp_dc.commontop << 3); - UINT8 * restrict dest = R_Address(temp_dc.startx, temp_dc.commontop); - const UINT8 * restrict transmap = temp_dc.transmap; - const UINT8 * restrict translation = temp_dc.translation; - - while (--count >= 0) - { - // haleyjd 09/11/04: use temptranmap here - dest[0] = transmap[(translation[source[0]] << 8) + dest[0]]; - dest[1] = transmap[(translation[source[1]] << 8) + dest[1]]; - dest[2] = transmap[(translation[source[2]] << 8) + dest[2]]; - dest[3] = transmap[(translation[source[3]] << 8) + dest[3]]; - dest[4] = transmap[(translation[source[4]] << 8) + dest[4]]; - dest[5] = transmap[(translation[source[5]] << 8) + dest[5]]; - dest[6] = transmap[(translation[source[6]] << 8) + dest[6]]; - dest[7] = transmap[(translation[source[7]] << 8) + dest[7]]; - source += 8; - dest += stride; + dest += stride; } } } -#define DEFINE_GETFLUSHQUAD_FUNC(name, flags) \ - FUNCINLINE static ATTRINLINE void name(void) \ - { \ - constexpr ColumnFlushType opt = static_cast(flags); \ - R_FlushQuad(); \ - } - -DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadOpague, FLUSH_OPAQUE) -DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadTrans, FLUSH_TRANS) -DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadColormap, FLUSH_COLORMAP) -DEFINE_GETFLUSHQUAD_FUNC(R_FlushQuadColormapTrans, FLUSH_COLORMAP_TRANS) - // haleyjd 09/12/04: split up R_GetBuffer into various different // functions to minimize the number of branches and take advantage // of as much precalculated information as possible. template static UINT8 *R_GetBuffer(drawcolumndata_t *dc) { + drawcolumndata_temp_t *t_dc = &temp_dc; + // haleyjd: reordered predicates - if (temp_dc.x == 8 || - (temp_dc.x && (temp_dc.type != Type || temp_dc.x + temp_dc.startx != dc->x))) + if (t_dc->x == 8 || + (t_dc->x && (t_dc->type != Type || t_dc->x + t_dc->startx != dc->x))) R_FlushColumns(); - if (!temp_dc.x) + if (!t_dc->x) { - ++temp_dc.x; - temp_dc.startx = dc->x; - temp_dc.yl[0] = temp_dc.commontop = dc->yl; - temp_dc.yh[0] = temp_dc.commonbot = dc->yh; - temp_dc.type = Type; + ++t_dc->x; + t_dc->startx = dc->x; + t_dc->yl[0] = t_dc->commontop = dc->yl; + t_dc->yh[0] = t_dc->commonbot = dc->yh; + t_dc->type = Type; - if constexpr (Type & ColumnFlushType::FLUSH_OPAQUE) + if constexpr (Type & (ColumnFlushType::FLUSH_TRANS | ColumnFlushType::FLUSH_COLORMAP_TRANS)) { - R_FlushWholeColumns = R_FlushWholeOpague; - R_FlushHTColumns = R_FlushHTOpague; - R_FlushQuadColumn = R_FlushQuadOpague; - } - else if constexpr (Type & ColumnFlushType::FLUSH_TRANS) - { - temp_dc.transmap = dc->transmap; - R_FlushWholeColumns = R_FlushWholeTrans; - R_FlushHTColumns = R_FlushHTTrans; - R_FlushQuadColumn = R_FlushQuadTrans; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP) - { - temp_dc.translation = dc->translation; - R_FlushWholeColumns = R_FlushWholeColormap; - R_FlushHTColumns = R_FlushHTColormap; - R_FlushQuadColumn = R_FlushQuadColormap; - } - else if constexpr (Type & ColumnFlushType::FLUSH_COLORMAP_TRANS) - { - temp_dc.transmap = dc->transmap; - temp_dc.translation = dc->translation; - R_FlushWholeColumns = R_FlushWholeColormapTrans; - R_FlushHTColumns = R_FlushHTColormapTrans; - R_FlushQuadColumn = R_FlushQuadColormapTrans; + t_dc->transmap = dc->transmap; } - return &temp_dc.buf[dc->yl << 3]; + if constexpr (Type & (ColumnFlushType::FLUSH_COLORMAP | ColumnFlushType::FLUSH_COLORMAP_TRANS)) + { + t_dc->translation = dc->translation; + } + + R_FlushWholeColumns = R_FlushWhole; + R_FlushHTColumns = R_FlushHT; + R_FlushQuadColumn = R_FlushQuad; + + return &t_dc->buf[dc->yl << 3]; } - temp_dc.yl[temp_dc.x] = dc->yl; - temp_dc.yh[temp_dc.x] = dc->yh; + t_dc->yl[t_dc->x] = dc->yl; + t_dc->yh[t_dc->x] = dc->yh; - if (dc->yl > temp_dc.commontop) - temp_dc.commontop = dc->yl; - if (dc->yh < temp_dc.commonbot) - temp_dc.commonbot = dc->yh; + if (dc->yl > t_dc->commontop) + t_dc->commontop = dc->yl; + if (dc->yh < t_dc->commonbot) + t_dc->commonbot = dc->yh; - return &temp_dc.buf[(dc->yl << 3) + temp_dc.x++]; + return &t_dc->buf[(dc->yl << 3) + t_dc->x++]; } #define DEFINE_GETBUF_FUNC(name, flags) \ diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index cfa053382..bc18382a2 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -50,7 +50,8 @@ enum DrawSpanType }; template -static constexpr UINT8 R_GetSpanTranslated(drawspandata_t* ds, UINT8 col) +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_GetSpanTranslated(const drawspandata_t* ds, UINT8 col) { if constexpr (Type & DrawSpanType::DS_COLORMAP) { @@ -63,7 +64,8 @@ static constexpr UINT8 R_GetSpanTranslated(drawspandata_t* ds, UINT8 col) } template -static constexpr UINT8 R_GetSpanTranslucent(drawspandata_t* ds, UINT8 *dsrc, const UINT8 *colormap, UINT8 col) +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_GetSpanTranslucent(const drawspandata_t* ds, UINT8 *dsrc, const UINT8 *colormap, UINT8 col) { col = colormap[R_GetSpanTranslated(ds, col)]; @@ -78,7 +80,8 @@ static constexpr UINT8 R_GetSpanTranslucent(drawspandata_t* ds, UINT8 *dsrc, con } template -static constexpr UINT8 R_DrawSpanPixel(drawspandata_t* ds, UINT8 *dsrc, const UINT8 *colormap, UINT32 bit, const UINT8 *source) +FUNCINLINE static ATTRINLINE constexpr UINT8 +R_DrawSpanPixel(const drawspandata_t* ds, UINT8 *dsrc, const UINT8 *colormap, UINT32 bit, const UINT8 *source) { UINT8 col = source[bit]; diff --git a/src/screen.c b/src/screen.c index 735bb88c4..d67ac73eb 100644 --- a/src/screen.c +++ b/src/screen.c @@ -155,7 +155,7 @@ void SCR_SetMode(void) // our sky "plane" drawer cannot handle the buffer system due to multithreading // (that would require alot of extra complexity for smth with massive diminishing results) // Our masked drawing step draws things in a very particular order, which results in alot of flushing to screen -// effectively adding massive overhead during buffering, so we draw our masked thing directly to screen instead +// effectively adding massive overhead due to excessive flushing, so we draw our masked thing directly to screen instead void R_SetColumnContext(enum columncontext_e _columncontext) { columncontext = _columncontext; -- 2.54.0 From 90c3d02dbffeac3156b608ca302317b0e46fbc75 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Oct 2025 20:46:27 +0200 Subject: [PATCH 28/40] ensure columnbuffer gets flushed during portal traversal in worst case this does nothing btw --- src/r_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r_main.cpp b/src/r_main.cpp index 2a04c6600..1dabe4b21 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1490,6 +1490,7 @@ void R_RenderPlayerView(player_t *player) R_RenderViewpoint(&masks[nummasks - 1], true); R_ClipSprites(ds_p - (masks[nummasks - 1].drawsegs[1] - masks[nummasks - 1].drawsegs[0]), portal); + R_ResetColumnBuffer(); Portal_Remove(portal); } -- 2.54.0 From c82495f48b97706014e5d8e7f10228567e0a8ed8 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 12 Oct 2025 22:03:04 +0200 Subject: [PATCH 29/40] tiny optimization span drawers if we dont "ripple" our spans, we dont need to increment an additional pointer for them --- src/r_draw_span.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index bc18382a2..983a89698 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -160,14 +160,18 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) { bit = ((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift); - dest[i] = R_DrawSpanPixel(ds, &dsrc[i], colormap, bit, source); + if constexpr (Type & DS_RIPPLE) + dest[i] = R_DrawSpanPixel(ds, &dsrc[i], colormap, bit, source); + else + dest[i] = R_DrawSpanPixel(ds, &dest[i], colormap, bit, source); xposition += xstep; yposition += ystep; } dest += 8; - dsrc += 8; + if constexpr (Type & DS_RIPPLE) + dsrc += 8; count -= 8; } @@ -176,10 +180,14 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) { bit = ((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift); - *dest = R_DrawSpanPixel(ds, dsrc, colormap, bit, source); + if constexpr (Type & DS_RIPPLE) + *dest = R_DrawSpanPixel(ds, dsrc, colormap, bit, source); + else + *dest = R_DrawSpanPixel(ds, dest, colormap, bit, source); dest++; - dsrc++; + if constexpr (Type & DS_RIPPLE) + dsrc++; xposition += xstep; yposition += ystep; @@ -321,7 +329,8 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) ds->x1 += SPANSIZE; dest += SPANSIZE; - dsrc += SPANSIZE; + if constexpr (Type & DS_RIPPLE) + dsrc += SPANSIZE; startu = endu; startv = endv; width -= SPANSIZE; @@ -335,7 +344,10 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) v = (INT64)(startv); bit = ((v >> nflatyshift) & nflatmask) | (u >> nflatxshift); colormap = ds->planezlight[tiltlighting[ds->x1]] + (ds->colormap - colormaps); - *dest = R_DrawSpanPixel(ds, dsrc, colormap, bit, source); + if constexpr (Type & DS_RIPPLE) + *dest = R_DrawSpanPixel(ds, dsrc, colormap, bit, source); + else + *dest = R_DrawSpanPixel(ds, dest, colormap, bit, source); ds->x1++; } else @@ -358,10 +370,14 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) { bit = ((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift); colormap = ds->planezlight[tiltlighting[ds->x1]] + (ds->colormap - colormaps); - *dest = R_DrawSpanPixel(ds, dsrc, colormap, bit, source); + if constexpr (Type & DS_RIPPLE) + *dest = R_DrawSpanPixel(ds, dsrc, colormap, bit, source); + else + *dest = R_DrawSpanPixel(ds, dest, colormap, bit, source); dest++; + if constexpr (Type & DS_RIPPLE) + dsrc++; ds->x1++; - dsrc++; u += stepu; v += stepv; } @@ -404,7 +420,7 @@ void R_DrawFogSpan(drawspandata_t* ds) dest[2] = colormap[dest[2]]; dest[3] = colormap[dest[3]]; - dest += 4; + dest += 4; count -= 4; } -- 2.54.0 From 8488da4b1ae8ce7eb13243cfbcacd9bb82445580 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 12 Oct 2025 22:03:30 +0200 Subject: [PATCH 30/40] smol style adjustment span stuff --- src/r_draw_span.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 983a89698..aa14785a0 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -254,15 +254,14 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) local_for_thread std::vector tiltlighting; iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); + uz = ds->sup.z + ds->sup.y*(centery-ds->y) + ds->sup.x*(ds->x1-centerx); + vz = ds->svp.z + ds->svp.y*(centery-ds->y) + ds->svp.x*(ds->x1-centerx); // Lighting is simple. It's just linear interpolation from start to end R_GetTiltedLighting(tiltlighting, ds, iz, width, stride); - uz = ds->sup.z + ds->sup.y*(centery-ds->y) + ds->sup.x*(ds->x1-centerx); - vz = ds->svp.z + ds->svp.y*(centery-ds->y) + ds->svp.x*(ds->x1-centerx); - - const UINT8 *source = ds->source; - const UINT8 *colormap = ds->colormap; + const UINT8 * restrict source = ds->source; + const UINT8 * restrict colormap = ds->colormap; if constexpr (Type & DS_RIPPLE) { @@ -408,11 +407,11 @@ DEFINE_SPAN_COMBO(R_DrawTranslucentWaterSpan, DS_TRANSMAP|DS_RIPPLE) */ void R_DrawFogSpan(drawspandata_t* ds) { + INT32 count = ds->x2 - ds->x1 + 1; + const UINT8 * restrict colormap = ds->colormap; UINT8 * restrict dest = R_Address(ds->x1, ds->y); - intptr_t count = ds->x2 - ds->x1 + 1; - while (count >= 4) { dest[0] = colormap[dest[0]]; -- 2.54.0 From 5765f3df5a635bef4738a2ee94506eef17161877 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 12 Oct 2025 22:30:16 +0200 Subject: [PATCH 31/40] this does not need marked as restrict --- src/r_draw_column.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 08cfa00a1..3ac814e8d 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -233,7 +233,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc) else dest = R_GetBufferOpaque(dc); - restrict INT32 stride = 8; //SoM: Oh, Oh it's MAGIC! You know... + INT32 stride = 8; //SoM: Oh, Oh it's MAGIC! You know... if constexpr (Type & DrawColumnType::DC_DIRECT) stride = vid.width; -- 2.54.0 From 459b2e62ce642940b7e9a896e989c1a0bee679a3 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 12 Oct 2025 23:12:18 +0200 Subject: [PATCH 32/40] oops missed this case --- src/r_draw_span.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index aa14785a0..b1870685c 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -323,7 +323,10 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) { bit = (((v + stepv * i) >> nflatyshift) & nflatmask) | ((u + stepu * i) >> nflatxshift); colormap = ds->planezlight[tiltlighting[x1 + i]] + (ds->colormap - colormaps); - dest[i] = R_DrawSpanPixel(ds, &dsrc[i], colormap, bit, source); + if constexpr (Type & DS_RIPPLE) + dest[i] = R_DrawSpanPixel(ds, &dsrc[i], colormap, bit, source); + else + dest[i] = R_DrawSpanPixel(ds, &dest[i], colormap, bit, source); } ds->x1 += SPANSIZE; -- 2.54.0 From b2260bbebbe974dd87f5476cbe098f1ee16c4616 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 13 Oct 2025 21:26:53 +0200 Subject: [PATCH 33/40] move R_SetColumnContext call we set this later to flush eitherway for non skybox draw --- src/r_main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index 1dabe4b21..88435ba93 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1391,8 +1391,6 @@ void R_RenderPlayerView(player_t *player) R_SetFov(fov); } - R_SetColumnContext(COLUMNCONTEXT_FLUSH); - Portal_InitList(); PS_START_TIMING(ps_skyboxtime); @@ -1406,6 +1404,7 @@ void R_RenderPlayerView(player_t *player) R_ClearPlanes(); R_ClearSprites(); + R_SetColumnContext(COLUMNCONTEXT_FLUSH); R_RenderViewpoint(&masks[nummasks - 1], false); R_ClipSprites(drawsegs, NULL); -- 2.54.0 From 9310a68cffead926d2e429304c64993b4d72f581 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Oct 2025 22:43:58 +0200 Subject: [PATCH 34/40] delet gl_viewwidth, gl_viewheight, gl_baseviewwindowx, gl_baseviewwindowy gl_basewindowcenterx, gl_basewindowcentery they were effectively unused the last two werent ever even initialized to anything, using HWR_DrawViewBorder wouldve crashed --- src/hardware/hw_draw.c | 12 ++++++---- src/hardware/hw_main.cpp | 48 +++++++--------------------------------- src/hardware/hw_main.h | 4 ---- 3 files changed, 16 insertions(+), 48 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 2b8ace584..1c014ce4c 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -649,6 +649,7 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height) // ------------------ void HWR_DrawViewBorder(INT32 clearlines) { +#if 0 INT32 x, y; INT32 top, side; INT32 baseviewwidth, baseviewheight; @@ -659,10 +660,10 @@ void HWR_DrawViewBorder(INT32 clearlines) clearlines = BASEVIDHEIGHT; // refresh all // calc view size based on original game resolution - baseviewwidth = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewwidth), vid.fdup)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; - baseviewheight = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewheight), vid.fdup)); - top = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowy), vid.fdup)); - side = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowx), vid.fdup)); + baseviewwidth = FixedInt(FixedDiv(viewwidth * FRACUNIT, vid.fdup)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; + baseviewheight = FixedInt(FixedDiv(viewheight * FRACUNIT, vid.fdup)); + top = FixedInt(FixedDiv(baseviewwindowy * FRACUNIT, vid.fdup)); + side = FixedInt(FixedDiv(baseviewwindowx * FRACUNIT, vid.fdup)); // top HWR_DrawFlatFill(0, 0, @@ -759,6 +760,9 @@ void HWR_DrawViewBorder(INT32 clearlines) PU_PATCH), basewindowx + baseviewwidth, basewindowy + baseviewheight, 0); +#else + (void)clearlines; +#endif } diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 2ccb3f6d9..88584a9da 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -77,11 +77,6 @@ boolean gl_drawing_stencil = false; static INT32 current_bsp_culling_distance = 0; -// base values set at SetViewSize -float gl_baseviewwindowy, gl_baseviewwindowx; -static float gl_viewwindowy, gl_viewwindowx; // top left corner of view window -float gl_viewwidth, gl_viewheight; // viewport clipping boundaries (screen coords) - FTransform atransform; // Float variants of viewx, viewy, viewz, etc. @@ -5316,10 +5311,10 @@ static void HWR_DrawSkyBackground(void) // -----------------+ static inline void HWR_ClearView(void) { - GL_GClipRect((INT32)gl_viewwindowx, - (INT32)gl_viewwindowy, - (INT32)(gl_viewwindowx + gl_viewwidth), - (INT32)(gl_viewwindowy + gl_viewheight), + GL_GClipRect(viewwindowx, + viewwindowy, + (viewwindowx + viewwidth), + (viewwindowy + viewheight), ZCLIP_PLANE, FAR_ZCLIP_DEFAULT); GL_ClearBuffer(false, true, true, NULL); } @@ -5329,19 +5324,6 @@ static inline void HWR_ClearView(void) // -----------------+ void HWR_SetViewSize(void) { - // setup view size - gl_viewwidth = (float)vid.width; - gl_viewheight = (float)vid.height; - - if (splitscreen) - gl_viewheight /= 2; - - if (splitscreen > 1) - gl_viewwidth /= 2; - - gl_baseviewwindowy = 0; - gl_baseviewwindowx = 0; - GL_FlushScreenTextures(); } @@ -5596,20 +5578,6 @@ extern "C" { // ========================================================================== static void HWR_RenderFrame(player_t *player, boolean skybox) { - // set window position - gl_viewwindowx = gl_baseviewwindowx; - gl_viewwindowy = gl_baseviewwindowy; - - if ((splitscreen == 1 && viewssnum == 1) || (splitscreen > 1 && viewssnum > 1)) - { - gl_viewwindowy += gl_viewheight; - } - - if (splitscreen > 1 && viewssnum & 1) - { - gl_viewwindowx += gl_viewwidth; - } - // check for new console commands. NetUpdate(); @@ -5625,10 +5593,10 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) if (!skybox && cv_glrenderdistance.value) { - GL_GClipRect((INT32)gl_viewwindowx, - (INT32)gl_viewwindowy, - (INT32)(gl_viewwindowx + gl_viewwidth), - (INT32)(gl_viewwindowy + gl_viewheight), + GL_GClipRect(viewwindowx, + viewwindowy, + (viewwindowx + viewwidth), + (viewwindowy + viewheight), ZCLIP_PLANE, clipping_distances[cv_glrenderdistance.value - 1]); current_bsp_culling_distance = bsp_culling_distances[cv_glrenderdistance.value - 1]; } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 4060b6540..43a292c57 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -42,10 +42,6 @@ extern "C" { void HWR_Startup(void); void HWR_Shutdown(void); -extern float gl_viewwidth, gl_viewheight, gl_baseviewwindowx, gl_baseviewwindowy; - -extern float gl_basewindowcenterx, gl_basewindowcentery; - extern unsigned msaa; extern boolean a2c; -- 2.54.0 From af8ce028ba8ea8b3707c4d88d0fe265ce6776bb9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Oct 2025 22:45:08 +0200 Subject: [PATCH 35/40] use stdlibs abs for CompareDrawNodePlanes we dont need our own abs for this --- src/hardware/hw_main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 88584a9da..382143dcb 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -65,8 +65,6 @@ // Globals // ========================================================================== -#define ABS(x) ((x) < 0 ? -(x) : (x)) - // false if shaders have not been initialized yet, or if shaders are not available boolean gl_shadersavailable = false; @@ -4330,7 +4328,7 @@ static int CompareDrawNodePlanes(const void *p1, const void *p2) const INT32 n1 = *(const INT32*)p1; const INT32 n2 = *(const INT32*)p2; - return ABS(drawnodes[n2].u.plane.fixedheight - viewz) - ABS(drawnodes[n1].u.plane.fixedheight - viewz); + return abs(drawnodes[n2].u.plane.fixedheight - viewz) - abs(drawnodes[n1].u.plane.fixedheight - viewz); } // -- 2.54.0 From 37579187cc387595db217adc61f1e2c363af3f04 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Oct 2025 23:13:39 +0200 Subject: [PATCH 36/40] remove dead renderer code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remove - broken viewborder code (if we really want it back for some reason, we should rather port RR´s fixed version of it) - remove console clipping code for software (this was broken eiherway) - remove hud message clearing stuff - remove renderscreen and linesize variables (they just pointed to vid.screen and vid.widht) --- src/Makefile.d/sdl.mk | 2 +- src/console.c | 31 ------- src/console.h | 5 -- src/d_main.c | 9 -- src/doomtype.h | 1 - src/hardware/hw_draw.c | 200 +---------------------------------------- src/hardware/hw_main.h | 2 - src/hu_stuff.c | 70 --------------- src/hu_stuff.h | 1 - src/i_video.h | 2 +- src/m_menu.c | 3 +- src/r_draw.cpp | 147 +----------------------------- src/r_draw.h | 34 +------ src/r_main.cpp | 2 - src/r_plane.cpp | 2 +- src/r_segs.cpp | 5 +- src/r_things.cpp | 2 - src/screen.c | 7 +- src/screen.h | 2 - src/sdl/Srb2SDL.dsp | 4 +- src/sdl/Srb2SDL.props | 4 +- src/st_stuff.c | 4 - 22 files changed, 14 insertions(+), 525 deletions(-) diff --git a/src/Makefile.d/sdl.mk b/src/Makefile.d/sdl.mk index c704a83eb..95fe34e6a 100644 --- a/src/Makefile.d/sdl.mk +++ b/src/Makefile.d/sdl.mk @@ -10,7 +10,7 @@ makedir:=$(makedir)/SDL -opts+=-DDIRECTFULLSCREEN -DHAVE_SDL +opts+=-DHAVE_SDL sources+=$(call List,sdl/Sourcefile) NOUPNP=1 diff --git a/src/console.c b/src/console.c index fe91df0f3..3959d9b98 100644 --- a/src/console.c +++ b/src/console.c @@ -69,14 +69,9 @@ static boolean consoleready; // console prompt is ready INT32 con_destlines; // vid lines used by console at final position static INT32 con_curlines; // vid lines currently used by console - INT32 con_clipviewtop; // (useless) - static UINT8 con_hudlines; // number of console heads up message lines static UINT32 con_hudtime[MAXHUDLINES]; // remaining time of display for hud msg lines - INT32 con_clearlines; // top screen lines to refresh when view reduced - boolean con_hudupdate; // when messages scroll, we need a backgrnd refresh - // console text output static char *con_line; // console text output current line static size_t con_cx; // cursor position in current line @@ -393,9 +388,6 @@ void CON_Init(void) Lock_state(); - //note: CON_Ticker should always execute at least once before D_Display() - con_clipviewtop = -1; // -1 does not clip - con_hudlines = atoi(cons_hudlines.defaultvalue); Unlock_state(); @@ -727,7 +719,6 @@ void CON_ToggleOff(void) con_curlines = 0; CON_ClearHUD(); con_forcepic = 0; - con_clipviewtop = -1; // remove console clipping of view I_SetTextInput(false); @@ -779,18 +770,6 @@ void CON_Ticker(void) } } - // clip the view, so that the part under the console is not drawn - con_clipviewtop = -1; - if (cons_backpic.value) // clip only when using an opaque background - { - if (con_curlines > 0) - con_clipviewtop = con_curlines - viewwindowy - 1 - 10; - // NOTE: BIG HACK::SUBTRACT 10, SO THAT WATER DON'T COPY LINES OF THE CONSOLE - // WINDOW!!! (draw some more lines behind the bottom of the console) - if (con_clipviewtop < 0) - con_clipviewtop = -1; // maybe not necessary, provided it's < 0 - } - // check if console ready for prompt if (con_destlines >= minheight) { @@ -1100,9 +1079,6 @@ static void CON_Linefeed(void) con_line = &con_buffer[(con_cy%con_totallines)*con_width]; memset(con_line, ' ', con_width); - - // make sure the view borders are refreshed if hud messages scroll - con_hudupdate = true; // see HU_Erase() } // Outputs text into the console text buffer @@ -1489,9 +1465,6 @@ static void CON_DrawHudlines(void) //V_DrawCharacter(x, y, (p[c]&0xff) | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); y += charheight; } - - // top screen lines that might need clearing when view is reduced - con_clearlines = y; // this is handled by HU_Erase(); } // draw the console background, text, and prompt if enough place @@ -1509,10 +1482,6 @@ static void CON_DrawConsole(void) if (con_curlines <= 0) return; - //FIXME: refresh borders only when console bg is translucent - con_clearlines = con_curlines; // clear console draw from view borders - con_hudupdate = true; // always refresh while console is on - // draw console background if (cons_backpic.value || con_forcepic) { diff --git a/src/console.h b/src/console.h index e704a87f1..79af2e48f 100644 --- a/src/console.h +++ b/src/console.h @@ -30,14 +30,9 @@ extern boolean con_recalc; extern boolean con_startup; -// top clip value for view render: do not draw part of view hidden by console -extern INT32 con_clipviewtop; - // 0 means console if off, or moving out extern INT32 con_destlines; -extern INT32 con_clearlines; // lines of top of screen to refresh -extern boolean con_hudupdate; // hud messages have changed, need refresh extern UINT32 con_scalefactor; // console text scale factor extern consvar_t cons_backcolor, cons_menuhighlight; diff --git a/src/d_main.c b/src/d_main.c index dd13c7b77..33dc57689 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -522,19 +522,16 @@ static boolean D_Display(void) case GS_LEVEL: if (!gametic) break; - HU_Erase(); AM_Drawer(); break; case GS_INTERMISSION: Y_IntermissionDrawer(); - HU_Erase(); HU_Drawer(); break; case GS_VOTING: Y_VoteDrawer(); - HU_Erase(); HU_Drawer(); break; @@ -549,7 +546,6 @@ static boolean D_Display(void) case GS_CUTSCENE: F_CutsceneDrawer(); - HU_Erase(); HU_Drawer(); break; @@ -559,7 +555,6 @@ static boolean D_Display(void) case GS_EVALUATION: F_GameEvaluationDrawer(); - HU_Erase(); HU_Drawer(); break; @@ -569,7 +564,6 @@ static boolean D_Display(void) case GS_CREDITS: F_CreditDrawer(); - HU_Erase(); HU_Drawer(); break; @@ -586,7 +580,6 @@ static boolean D_Display(void) { // I don't think HOM from nothing drawing is independent... F_WaitingPlayersDrawer(); - HU_Erase(); HU_Drawer(); } case GS_TIMEATTACK: @@ -1925,9 +1918,7 @@ void D_SRB2Main(void) G_LoadGameData(); -#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) VID_PrepareModeList(); // Regenerate Modelist according to cv_fullscreen -#endif // set user default mode or mode set at cmdline SCR_CheckDefaultMode(); diff --git a/src/doomtype.h b/src/doomtype.h index 81c09c007..78867ed69 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -43,7 +43,6 @@ extern "C" { #define UINT64 uint64_t #ifdef __APPLE_CC__ -#define DIRECTFULLSCREEN 1 #define DEBUG_LOG #define NOIPX #endif diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 1c014ce4c..cf8ab29e3 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -31,11 +31,6 @@ #include "../st_stuff.h" #include -#include "../i_video.h" // for rendermode != render_glide - -#ifndef O_BINARY -#define O_BINARY 0 -#endif typedef struct { @@ -58,68 +53,6 @@ static UINT8 softwaretranstogl_lo[11] = { 0, 12, 24, 36, 48, 60, 71, 83, 95,111 static const float FLOATBASEVIDWIDTH = (float)BASEVIDWIDTH; static const float FLOATBASEVIDHEIGHT = (float)BASEVIDHEIGHT; -// -// -----------------+ -// HWR_DrawPatch : Draw a 'tile' graphic -// Notes : x,y : positions relative to the original Doom resolution -// : textes(console+score) + menus + status bar -// -----------------+ -void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) -{ - FOutVector v[4]; - FBITFIELD flags; - GLPatch_t *hwrPatch; - -// 3--2 -// | /| -// |/ | -// 0--1 - float sdup = FIXED_TO_FLOAT(vid.fdup)*2.0f; - float pdup = FIXED_TO_FLOAT(vid.fdup)*2.0f; - - // make patch ready in hardware cache - HWR_GetPatch(gpatch); - hwrPatch = ((GLPatch_t *)gpatch->hardware); - - switch (option & V_SCALEPATCHMASK) - { - case V_NOSCALEPATCH: - pdup = 2.0f; - break; - case V_SMALLSCALEPATCH: - pdup = 2.0f * FIXED_TO_FLOAT(vid.smalldup*FRACUNIT); - break; - case V_MEDSCALEPATCH: - pdup = 2.0f * FIXED_TO_FLOAT(vid.meddup*FRACUNIT); - break; - } - - if (option & V_NOSCALESTART) - sdup = 2.0f; - - v[0].x = v[3].x = (x*sdup-gpatch->leftoffset*pdup)/vid.width - 1; - v[2].x = v[1].x = (x*sdup+(gpatch->width - gpatch->leftoffset)*pdup)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdup-gpatch->topoffset*pdup)/vid.height; - v[2].y = v[3].y = 1-(y*sdup+(gpatch->height - gpatch->topoffset)*pdup)/vid.height; - - v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - - v[0].s = v[3].s = 0.0f; - v[2].s = v[1].s = hwrPatch->max_s; - v[0].t = v[1].t = 0.0f; - v[2].t = v[3].t = hwrPatch->max_t; - - flags = PF_Translucent|PF_NoDepthTest; - - if (option & V_WRAPX) - flags |= PF_ForceWrapX; - if (option & V_WRAPY) - flags |= PF_ForceWrapY; - - // clip it since it is used for bunny scroll in doom I - GL_DrawPolygon(NULL, v, 4, flags); -} - void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags) { FOutVector v[4]; @@ -636,137 +569,6 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height) } -// ========================================================================== -// R_DRAW.C STUFF -// ========================================================================== - -// ------------------ -// HWR_DrawViewBorder -// Fill the space around the view window with a Doom flat texture, draw the -// beveled edges. -// 'clearlines' is useful to clear the heads up messages, when the view -// window is reduced, it doesn't refresh all the view borders. -// ------------------ -void HWR_DrawViewBorder(INT32 clearlines) -{ -#if 0 - INT32 x, y; - INT32 top, side; - INT32 baseviewwidth, baseviewheight; - INT32 basewindowx, basewindowy; - patch_t *patch; - - if (!clearlines) - clearlines = BASEVIDHEIGHT; // refresh all - - // calc view size based on original game resolution - baseviewwidth = FixedInt(FixedDiv(viewwidth * FRACUNIT, vid.fdup)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; - baseviewheight = FixedInt(FixedDiv(viewheight * FRACUNIT, vid.fdup)); - top = FixedInt(FixedDiv(baseviewwindowy * FRACUNIT, vid.fdup)); - side = FixedInt(FixedDiv(baseviewwindowx * FRACUNIT, vid.fdup)); - - // top - HWR_DrawFlatFill(0, 0, - BASEVIDWIDTH, (top < clearlines ? top : clearlines), - st_borderpatchnum); - - // left - if (top < clearlines) - HWR_DrawFlatFill(0, top, side, - (clearlines-top < baseviewheight ? clearlines-top : baseviewheight), - st_borderpatchnum); - - // right - if (top < clearlines) - HWR_DrawFlatFill(side + baseviewwidth, top, side, - (clearlines-top < baseviewheight ? clearlines-top : baseviewheight), - st_borderpatchnum); - - // bottom - if (top + baseviewheight < clearlines) - HWR_DrawFlatFill(0, top + baseviewheight, - BASEVIDWIDTH, BASEVIDHEIGHT, st_borderpatchnum); - - // - // draw the view borders - // - - basewindowx = (BASEVIDWIDTH - baseviewwidth)>>1; - if (baseviewwidth == BASEVIDWIDTH) - basewindowy = 0; - else - basewindowy = top; - - // top edge - if (clearlines > basewindowy - 8) - { - patch = W_CachePatchNum(viewborderlump[BRDR_T], PU_PATCH); - for (x = 0; x < baseviewwidth; x += 8) - HWR_DrawPatch(patch, basewindowx + x, basewindowy - 8, - 0); - } - - // bottom edge - if (clearlines > basewindowy + baseviewheight) - { - patch = W_CachePatchNum(viewborderlump[BRDR_B], PU_PATCH); - for (x = 0; x < baseviewwidth; x += 8) - HWR_DrawPatch(patch, basewindowx + x, - basewindowy + baseviewheight, 0); - } - - // left edge - if (clearlines > basewindowy) - { - patch = W_CachePatchNum(viewborderlump[BRDR_L], PU_PATCH); - for (y = 0; y < baseviewheight && basewindowy + y < clearlines; - y += 8) - { - HWR_DrawPatch(patch, basewindowx - 8, basewindowy + y, - 0); - } - } - - // right edge - if (clearlines > basewindowy) - { - patch = W_CachePatchNum(viewborderlump[BRDR_R], PU_PATCH); - for (y = 0; y < baseviewheight && basewindowy+y < clearlines; - y += 8) - { - HWR_DrawPatch(patch, basewindowx + baseviewwidth, - basewindowy + y, 0); - } - } - - // Draw beveled corners. - if (clearlines > basewindowy - 8) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TL], - PU_PATCH), - basewindowx - 8, basewindowy - 8, 0); - - if (clearlines > basewindowy - 8) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TR], - PU_PATCH), - basewindowx + baseviewwidth, basewindowy - 8, 0); - - if (clearlines > basewindowy+baseviewheight) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BL], - PU_PATCH), - basewindowx - 8, basewindowy + baseviewheight, 0); - - if (clearlines > basewindowy + baseviewheight) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BR], - PU_PATCH), - basewindowx + baseviewwidth, - basewindowy + baseviewheight, 0); -#else - (void)clearlines; -#endif -} - - - // ========================================================================== // AM_MAP.C DRAWING STUFF // ========================================================================== @@ -1172,7 +974,7 @@ static inline boolean saveTGA(const char *file_name, void *buffer, INT32 i; UINT8 *buf8 = buffer; - fd = open(file_name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); + fd = open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) return false; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 43a292c57..30906b611 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -85,7 +85,6 @@ extern ps_metric_t ps_hw_batchdrawtime; extern boolean gl_shadersavailable; // hw_draw.c -void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option); void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags); void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h); void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color); @@ -94,7 +93,6 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color); void HWR_drawAMline(const fline_t *fl, INT32 color); void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength); void HWR_DrawConsoleBack(UINT32 color, INT32 height); -void HWR_DrawViewBorder(INT32 clearlines); void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum); UINT8 *HWR_GetScreenshot(INT32 scale); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 6ca275aff..fa7060dff 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2391,76 +2391,6 @@ void HU_Drawer(void) } } -//====================================================================== -// HUD MESSAGES CLEARING FROM SCREEN -//====================================================================== - -// Clear old messages from the borders around the view window -// (only for reduced view, refresh the borders when needed) -// -// startline: y coord to start clear, -// clearlines: how many lines to clear. -// -static INT32 oldclearlines; - -void HU_Erase(void) -{ - INT32 topline, bottomline; - INT32 y, yoffset; - -#ifdef HWRENDER - // clear hud msgs on double buffer (OpenGL mode) - boolean secondframe; - static INT32 secondframelines; -#endif - - if (con_clearlines == oldclearlines && !con_hudupdate && !chat_on) - return; - -#ifdef HWRENDER - // clear the other frame in double-buffer modes - secondframe = (con_clearlines != oldclearlines); - if (secondframe) - secondframelines = oldclearlines; -#endif - - // clear the message lines that go away, so use _oldclearlines_ - bottomline = oldclearlines; - oldclearlines = con_clearlines; - if (chat_on && OLDCHAT) - if (bottomline < 8) - bottomline = 8; // only do it for consolechat. consolechat is gay. - - if (automapactive || viewwindowx == 0) // hud msgs don't need to be cleared - return; - - // software mode copies view border pattern & beveled edges from the backbuffer - if (rendermode == render_soft) - { - topline = 0; - for (y = topline, yoffset = y*vid.width; y < bottomline; y++, yoffset += vid.width) - { - if (y < viewwindowy || y >= viewwindowy + viewheight) - R_VideoErase(yoffset, vid.width); // erase entire line - else - { - R_VideoErase(yoffset, viewwindowx); // erase left border - // erase right border - R_VideoErase(yoffset + viewwindowx + viewwidth, viewwindowx); - } - } - con_hudupdate = false; // if it was set.. - } -#ifdef HWRENDER - else if (rendermode != render_none) - { - // refresh just what is needed from the view borders - HWR_DrawViewBorder(secondframelines); - con_hudupdate = secondframe; - } -#endif -} - //====================================================================== // IN-LEVEL MULTIPLAYER RANKINGS //====================================================================== diff --git a/src/hu_stuff.h b/src/hu_stuff.h index d134f319e..64d369a33 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -117,7 +117,6 @@ void HU_TickSongCredits(void); void HU_DrawSongCredits(void); void HU_Drawer(void); char HU_dequeueChatChar(void); -void HU_Erase(void); void HU_clearChatChars(void); void HU_drawPlayerPing(INT32 x, INT32 y, INT32 pnum, INT32 flags); // Lat': Ping drawer for scoreboard. //void HU_DrawTeamTabRankings(playersort_t *tab, INT32 whiteplayer); diff --git a/src/i_video.h b/src/i_video.h index 822a1bada..852645c30 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -94,8 +94,8 @@ INT32 VID_SetMode(INT32 modenum); \return name of video mode */ const char *VID_GetModeName(INT32 modenum); -void VID_PrepareModeList(void); /// note hack for SDL +void VID_PrepareModeList(void); /** \brief can video system do fullscreen */ diff --git a/src/m_menu.c b/src/m_menu.c index 95824c7dd..ed39e053f 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9442,9 +9442,8 @@ static void M_VideoModeMenu(INT32 choice) memset(modedescs, 0, sizeof(modedescs)); -#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) VID_PrepareModeList(); // FIXME: hack -#endif + vidm_nummodes = 0; vidm_selected = 0; nummodes = VID_NumModes(); diff --git a/src/r_draw.cpp b/src/r_draw.cpp index c8a09745a..91de5e102 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -41,8 +41,7 @@ /** \brief view info */ -INT32 linesize, viewwidth, viewheight, viewwindowx, viewwindowy; -UINT8 *renderscreen; // haleyjd +INT32 viewwidth, viewheight, viewwindowx, viewwindowy; // ========================================================================= // COLUMN DRAWING CODE STUFF @@ -521,7 +520,6 @@ static void R_AllocViewMemory(void) R_AllocVisSpriteMemory(); } - void R_InitViewBuffer(INT32 width, INT32 height) { if (width > MAXVIDWIDTH) @@ -534,27 +532,7 @@ void R_InitViewBuffer(INT32 width, INT32 height) viewwindowx = 0; viewwindowy = 0; - linesize = vid.width; // killough 11/98 - renderscreen = vid.screens[0]; // haleyjd 07/02/14 -} -/** \brief viewborder patches lump numbers -*/ -lumpnum_t viewborderlump[8]; - -/** \brief Store the lumpnumber of the viewborder patches -*/ - -void R_InitViewBorder(void) -{ - viewborderlump[BRDR_T] = W_GetNumForName("brdr_t"); - viewborderlump[BRDR_B] = W_GetNumForName("brdr_b"); - viewborderlump[BRDR_L] = W_GetNumForName("brdr_l"); - viewborderlump[BRDR_R] = W_GetNumForName("brdr_r"); - viewborderlump[BRDR_TL] = W_GetNumForName("brdr_tl"); - viewborderlump[BRDR_BL] = W_GetNumForName("brdr_bl"); - viewborderlump[BRDR_TR] = W_GetNumForName("brdr_tr"); - viewborderlump[BRDR_BR] = W_GetNumForName("brdr_br"); } /** \brief The R_VideoErase function @@ -578,129 +556,6 @@ void R_VideoErase(size_t ofs, INT32 count) M_Memcpy(vid.screens[0] + ofs, vid.screens[1] + ofs, count); } - -#if 0 -/** \brief R_FillBackScreen - - Fills the back screen with a pattern for variable screen sizes - Also draws a beveled edge. -*/ -void R_FillBackScreen(void) -{ - UINT8 *src, *dest; - patch_t *patch; - INT32 x, y, step, boff; - - // quickfix, don't cache lumps in both modes - if (rendermode != render_soft) - return; - - // draw pattern around the status bar too (when hires), - // so return only when in full-screen without status bar. - if (scaledviewwidth == vid.width && viewheight == vid.height) - return; - - src = scr_borderpatch; - dest = vid.screens[1]; - - for (y = 0; y < vid.height; y++) - { - for (x = 0; x < vid.width/128; x++) - { - M_Memcpy (dest, src+((y&127)<<7), 128); - dest += 128; - } - - if (vid.width&127) - { - M_Memcpy(dest, src+((y&127)<<7), vid.width&127); - dest += (vid.width&127); - } - } - - // don't draw the borders when viewwidth is full vid.width. - if (scaledviewwidth == vid.width) - return; - - step = 8; - boff = 8; - - patch = W_CacheLumpNum(viewborderlump[BRDR_T], PU_CACHE); - for (x = 0; x < scaledviewwidth; x += step) - V_DrawPatch(viewwindowx + x, viewwindowy - boff, 1, patch); - - patch = W_CacheLumpNum(viewborderlump[BRDR_B], PU_CACHE); - for (x = 0; x < scaledviewwidth; x += step) - V_DrawPatch(viewwindowx + x, viewwindowy + viewheight, 1, patch); - - patch = W_CacheLumpNum(viewborderlump[BRDR_L], PU_CACHE); - for (y = 0; y < viewheight; y += step) - V_DrawPatch(viewwindowx - boff, viewwindowy + y, 1, patch); - - patch = W_CacheLumpNum(viewborderlump[BRDR_R],PU_CACHE); - for (y = 0; y < viewheight; y += step) - V_DrawPatch(viewwindowx + scaledviewwidth, viewwindowy + y, 1, - patch); - - // Draw beveled corners. - V_DrawPatch(viewwindowx - boff, viewwindowy - boff, 1, - W_CacheLumpNum(viewborderlump[BRDR_TL], PU_CACHE)); - V_DrawPatch(viewwindowx + scaledviewwidth, viewwindowy - boff, 1, - W_CacheLumpNum(viewborderlump[BRDR_TR], PU_CACHE)); - V_DrawPatch(viewwindowx - boff, viewwindowy + viewheight, 1, - W_CacheLumpNum(viewborderlump[BRDR_BL], PU_CACHE)); - V_DrawPatch(viewwindowx + scaledviewwidth, viewwindowy + viewheight, 1, - W_CacheLumpNum(viewborderlump[BRDR_BR], PU_CACHE)); -} - -/** \brief The R_DrawViewBorder - - Draws the border around the view - for different size windows? -*/ -void R_DrawViewBorder(void) -{ - INT32 top, side, ofs; - - if (rendermode == render_none) - return; -#ifdef HWRENDER - if (rendermode != render_soft) - { - HWR_DrawViewBorder(0); - return; - } - else -#endif - -#ifdef DEBUG - fprintf(stderr,"RDVB: vidwidth %d vidheight %d scaledviewwidth %d viewheight %d\n", - vid.width, vid.height, scaledviewwidth, viewheight); -#endif - - if (scaledviewwidth == vid.width) - return; - - top = (vid.height - viewheight)>>1; - side = (vid.width - scaledviewwidth)>>1; - - // copy top and one line of left side - R_VideoErase(0, top*vid.width+side); - - // copy one line of right side and bottom - ofs = (viewheight+top)*vid.width - side; - R_VideoErase(ofs, top*vid.width + side); - - // copy sides using wraparound - ofs = top*vid.width + vid.width-side; - side <<= 1; - - // simpler using our VID_Blit routine - VID_BlitLinearScreen(vid.screens[1] + ofs, vid.screens[0] + ofs, side, viewheight - 1, - vid.width, vid.width); -} -#endif - // ========================================================================== // INCLUDE DRAWING CODE HERE // ========================================================================== diff --git a/src/r_draw.h b/src/r_draw.h index bcd734e50..eaee19039 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -25,12 +25,10 @@ extern "C" { // ------------------------------- // COMMON STUFF FOR 8bpp AND 16bpp // ------------------------------- -extern UINT8 *renderscreen; -extern INT32 linesize; FUNCINLINE static ATTRINLINE UINT8 *R_Address(INT32 px, INT32 py) { - return renderscreen + (py + viewwindowy) * linesize + (viewwindowx + px); + return vid.screens[0] + (py + viewwindowy) * vid.width + (viewwindowx + px); } @@ -152,27 +150,8 @@ extern spandrawfunc_t *spanfuncs[SPANDRAWFUNC_MAX]; void R_DrawMaskedColumn(drawcolumndata_t* dc, column_t *column); -/// \brief Top border -#define BRDR_T 0 -/// \brief Bottom border -#define BRDR_B 1 -/// \brief Left border -#define BRDR_L 2 -/// \brief Right border -#define BRDR_R 3 -/// \brief Topleft border -#define BRDR_TL 4 -/// \brief Topright border -#define BRDR_TR 5 -/// \brief Bottomleft border -#define BRDR_BL 6 -/// \brief Bottomright border -#define BRDR_BR 7 - -extern lumpnum_t viewborderlump[8]; - // ------------------------------------------------ -// r_draw.c COMMON ROUTINES FOR BOTH 8bpp and 16bpp +// r_draw.c // ------------------------------------------------ #define GTC_CACHE 1 @@ -221,17 +200,8 @@ boolean R_BlendLevelVisible(INT32 blendmode, INT32 alphalevel); // Custom player skin translation void R_InitViewBuffer(INT32 width, INT32 height); -void R_InitViewBorder(void); void R_VideoErase(size_t ofs, INT32 count); -// Rendering function. -#if 0 -void R_FillBackScreen(void); - -// If the view size is not full screen, draws a border around it. -void R_DrawViewBorder(void); -#endif - #define TRANSPARENTPIXEL 247 // ----------------- diff --git a/src/r_main.cpp b/src/r_main.cpp index 08f1e68a1..a392db087 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1023,8 +1023,6 @@ void R_Init(void) //I_OutputMsg("\nR_InitData"); R_InitData(); - //I_OutputMsg("\nR_InitViewBorder"); - R_InitViewBorder(); R_SetViewSize(); // setsizeneeded is set true // this is now done by SCR_Recalc() at the first mode set diff --git a/src/r_plane.cpp b/src/r_plane.cpp index de713dc9c..484aab49c 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -787,7 +787,7 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b drawcolumndata_t dc = {}; const INT32 texture = texturetranslation[skytexture]; - // Reset column drawer function (note: couldn't we just call walldrawerfunc directly?) + // Reset column drawer function (note: couldn't we just call colfuncs[BASEDRAWFUNC] directly?) // (that is, unless we'll need to switch drawers in future for some reason) R_SetColumnFunc(BASEDRAWFUNC); diff --git a/src/r_segs.cpp b/src/r_segs.cpp index c83b45593..b4f8cdbcd 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -26,7 +26,6 @@ #include "p_local.h" // Camera... #include "p_setup.h" #include "p_slopes.h" -#include "console.h" // con_clipviewtop #include "screen.h" #include "core/memory.h" @@ -628,8 +627,6 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf sector_t tempsec; INT32 templight; INT32 i, p; - fixed_t bottombounds = viewheight << FRACBITS; - fixed_t topbounds = (con_clipviewtop - 1) << FRACBITS; fixed_t offsetvalue = 0; lightlist_t *light; r_lightlist_t *rlight; @@ -936,7 +933,7 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf bottom_frac += bottom_step; // SoM: If column is out of range, why bother with it?? - if (windowbottom < topbounds || windowtop > bottombounds) + if (windowbottom < 0 || windowtop > (viewheight << FRACBITS)) { if (dc->numlights) { diff --git a/src/r_things.cpp b/src/r_things.cpp index 12d02d329..d69e7ea4e 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2518,8 +2518,6 @@ void R_InitDrawNodes(void) // R_DrawSprite // //Fab : 26-04-98: -// NOTE : uses con_clipviewtop, so that when console is on, -// don't draw the part of sprites hidden under the console static void R_DrawSprite(vissprite_t *spr) { mfloorclip = spr->clipbot; diff --git a/src/screen.c b/src/screen.c index 8d2782ab8..9a8109066 100644 --- a/src/screen.c +++ b/src/screen.c @@ -80,10 +80,6 @@ consvar_t cv_accuratefps = {"fpssampling", "1", CV_SAVE, accuratefps_cons_t, NUL // SCREEN VARIABLES // ========================================================================= -UINT8 *scr_borderpatch; // flat used to fill the reduced view borders set at ST_Init() - -// ========================================================================= - static void SCR_SetDrawFuncs(void) { // @@ -298,7 +294,6 @@ void SCR_SetDefaultMode(void) // Change fullscreen on/off according to cv_fullscreen void SCR_ChangeFullscreen(void) { -#ifdef DIRECTFULLSCREEN I_SetBorderlessWindow(); // Running this here so we can have borderless window at startup // allow_fullscreen is set by VID_PrepareModeList @@ -311,8 +306,8 @@ void SCR_ChangeFullscreen(void) VID_PrepareModeList(); setmodeneeded = VID_GetModeForSize(vid.width, vid.height) + 1; } + return; -#endif } boolean SCR_IsAspectCorrect(INT32 width, INT32 height) diff --git a/src/screen.h b/src/screen.h index ecad24a64..fb234324f 100644 --- a/src/screen.h +++ b/src/screen.h @@ -84,8 +84,6 @@ enum extern viddef_t vid; extern INT32 setmodeneeded; // mode number to set if needed, or 0 -extern UINT8 *scr_borderpatch; // patch used to fill the view borders - extern consvar_t cv_scr_width, cv_scr_height, cv_renderview, cv_frameskip, cv_fullscreen, cv_vhseffect, cv_shittyscreen; extern consvar_t cv_parallelsoftware; extern consvar_t cv_paralleldrawmasked; diff --git a/src/sdl/Srb2SDL.dsp b/src/sdl/Srb2SDL.dsp index 47ede4126..96d3e8418 100644 --- a/src/sdl/Srb2SDL.dsp +++ b/src/sdl/Srb2SDL.dsp @@ -45,7 +45,7 @@ MTL=midl.exe # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /G5 /W3 /GX /Zi /Ot /Og /Oi /Op /Oy /Ob1 /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "NDEBUG" /D "SDLMAIN" /D "NO_STDIO_REDIRECT" /D "USE_WGL_SWAP" /D "DIRECTFULLSCREEN" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GF /c +# ADD CPP /nologo /G5 /W3 /GX /Zi /Ot /Og /Oi /Op /Oy /Ob1 /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "NDEBUG" /D "SDLMAIN" /D "NO_STDIO_REDIRECT" /D "USE_WGL_SWAP" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GF /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" # SUBTRACT RSC /x @@ -72,7 +72,7 @@ LINK32=link.exe # PROP Target_Dir "" MTL=midl.exe # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /G6 /W4 /WX /Gm /GX /ZI /Od /Op /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "_DEBUG" /D "USE_WGL_SWAP" /D "DIRECTFULLSCREEN" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GZ /c +# ADD CPP /nologo /G6 /W4 /WX /Gm /GX /ZI /Od /Op /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "_DEBUG" /D "USE_WGL_SWAP" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GZ /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" diff --git a/src/sdl/Srb2SDL.props b/src/sdl/Srb2SDL.props index f02b9b35e..8c4799f20 100644 --- a/src/sdl/Srb2SDL.props +++ b/src/sdl/Srb2SDL.props @@ -6,9 +6,9 @@ - HAVE_ZLIB;HAVE_LIBGME;USE_WGL_SWAP;DIRECTFULLSCREEN;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) + HAVE_ZLIB;HAVE_LIBGME;USE_WGL_SWAP;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) - USE_WGL_SWAP;DIRECTFULLSCREEN;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) + USE_WGL_SWAP;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) diff --git a/src/st_stuff.c b/src/st_stuff.c index f5634423c..fade7c484 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -219,10 +219,6 @@ void ST_UnloadGraphics(void) void ST_LoadGraphics(void) { - // SRB2 border patch - //st_borderpatchnum = W_GetNumForName("GFZFLR01"); - //scr_borderpatch = W_CacheLumpNum(st_borderpatchnum, PU_HUDGFX); - // the original Doom uses 'STF' as base name for all face graphics // Graue 04-08-2004: face/name graphics are now indexed by skins // but load them in R_AddSkins, that gets called -- 2.54.0 From 9c014eb2eaadfc09f09251f6361b570d93c0cc4b Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Oct 2025 22:43:58 +0200 Subject: [PATCH 37/40] delet gl_viewwidth, gl_viewheight, gl_baseviewwindowx, gl_baseviewwindowy gl_basewindowcenterx, gl_basewindowcentery they were effectively unused the last two werent ever even initialized to anything, using HWR_DrawViewBorder wouldve crashed --- src/hardware/hw_draw.c | 12 ++++++---- src/hardware/hw_main.cpp | 48 +++++++--------------------------------- src/hardware/hw_main.h | 4 ---- 3 files changed, 16 insertions(+), 48 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 2b8ace584..1c014ce4c 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -649,6 +649,7 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height) // ------------------ void HWR_DrawViewBorder(INT32 clearlines) { +#if 0 INT32 x, y; INT32 top, side; INT32 baseviewwidth, baseviewheight; @@ -659,10 +660,10 @@ void HWR_DrawViewBorder(INT32 clearlines) clearlines = BASEVIDHEIGHT; // refresh all // calc view size based on original game resolution - baseviewwidth = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewwidth), vid.fdup)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; - baseviewheight = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewheight), vid.fdup)); - top = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowy), vid.fdup)); - side = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowx), vid.fdup)); + baseviewwidth = FixedInt(FixedDiv(viewwidth * FRACUNIT, vid.fdup)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; + baseviewheight = FixedInt(FixedDiv(viewheight * FRACUNIT, vid.fdup)); + top = FixedInt(FixedDiv(baseviewwindowy * FRACUNIT, vid.fdup)); + side = FixedInt(FixedDiv(baseviewwindowx * FRACUNIT, vid.fdup)); // top HWR_DrawFlatFill(0, 0, @@ -759,6 +760,9 @@ void HWR_DrawViewBorder(INT32 clearlines) PU_PATCH), basewindowx + baseviewwidth, basewindowy + baseviewheight, 0); +#else + (void)clearlines; +#endif } diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index c88b075a1..2b0799807 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -77,11 +77,6 @@ boolean gl_drawing_stencil = false; static INT32 current_bsp_culling_distance = 0; -// base values set at SetViewSize -float gl_baseviewwindowy, gl_baseviewwindowx; -static float gl_viewwindowy, gl_viewwindowx; // top left corner of view window -float gl_viewwidth, gl_viewheight; // viewport clipping boundaries (screen coords) - FTransform atransform; // Float variants of viewx, viewy, viewz, etc. @@ -5316,10 +5311,10 @@ static void HWR_DrawSkyBackground(void) // -----------------+ static inline void HWR_ClearView(void) { - GL_GClipRect((INT32)gl_viewwindowx, - (INT32)gl_viewwindowy, - (INT32)(gl_viewwindowx + gl_viewwidth), - (INT32)(gl_viewwindowy + gl_viewheight), + GL_GClipRect(viewwindowx, + viewwindowy, + (viewwindowx + viewwidth), + (viewwindowy + viewheight), ZCLIP_PLANE, FAR_ZCLIP_DEFAULT); GL_ClearBuffer(false, true, true, NULL); } @@ -5329,19 +5324,6 @@ static inline void HWR_ClearView(void) // -----------------+ void HWR_SetViewSize(void) { - // setup view size - gl_viewwidth = (float)vid.width; - gl_viewheight = (float)vid.height; - - if (splitscreen) - gl_viewheight /= 2; - - if (splitscreen > 1) - gl_viewwidth /= 2; - - gl_baseviewwindowy = 0; - gl_baseviewwindowx = 0; - GL_FlushScreenTextures(); } @@ -5594,20 +5576,6 @@ extern "C" { // ========================================================================== static void HWR_RenderFrame(player_t *player, boolean skybox) { - // set window position - gl_viewwindowx = gl_baseviewwindowx; - gl_viewwindowy = gl_baseviewwindowy; - - if ((splitscreen == 1 && viewssnum == 1) || (splitscreen > 1 && viewssnum > 1)) - { - gl_viewwindowy += gl_viewheight; - } - - if (splitscreen > 1 && viewssnum & 1) - { - gl_viewwindowx += gl_viewwidth; - } - // check for new console commands. NetUpdate(); @@ -5623,10 +5591,10 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) if (!skybox && cv_glrenderdistance.value) { - GL_GClipRect((INT32)gl_viewwindowx, - (INT32)gl_viewwindowy, - (INT32)(gl_viewwindowx + gl_viewwidth), - (INT32)(gl_viewwindowy + gl_viewheight), + GL_GClipRect(viewwindowx, + viewwindowy, + (viewwindowx + viewwidth), + (viewwindowy + viewheight), ZCLIP_PLANE, clipping_distances[cv_glrenderdistance.value - 1]); current_bsp_culling_distance = bsp_culling_distances[cv_glrenderdistance.value - 1]; } diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 4060b6540..43a292c57 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -42,10 +42,6 @@ extern "C" { void HWR_Startup(void); void HWR_Shutdown(void); -extern float gl_viewwidth, gl_viewheight, gl_baseviewwindowx, gl_baseviewwindowy; - -extern float gl_basewindowcenterx, gl_basewindowcentery; - extern unsigned msaa; extern boolean a2c; -- 2.54.0 From a4684b30047589d0320f6ea7e26642f6c945bad7 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Oct 2025 22:45:08 +0200 Subject: [PATCH 38/40] use stdlibs abs for CompareDrawNodePlanes we dont need our own abs for this --- src/hardware/hw_main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 2b0799807..f9f11a474 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -65,8 +65,6 @@ // Globals // ========================================================================== -#define ABS(x) ((x) < 0 ? -(x) : (x)) - // false if shaders have not been initialized yet, or if shaders are not available boolean gl_shadersavailable = false; @@ -4330,7 +4328,7 @@ static int CompareDrawNodePlanes(const void *p1, const void *p2) const INT32 n1 = *(const INT32*)p1; const INT32 n2 = *(const INT32*)p2; - return ABS(drawnodes[n2].u.plane.fixedheight - viewz) - ABS(drawnodes[n1].u.plane.fixedheight - viewz); + return abs(drawnodes[n2].u.plane.fixedheight - viewz) - abs(drawnodes[n1].u.plane.fixedheight - viewz); } // -- 2.54.0 From 0eeacaf51ea2fc291b35159f02817bf5d6bbd6cb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Oct 2025 23:12:36 +0200 Subject: [PATCH 39/40] remove dead renderer code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remove - broken viewborder code (if we really want it back for some reason, we should rather port RR´s fixed version of it) - remove console clipping code for software (this was broken eiherway) - remove hud message clearing stuff - remove renderscreen and linesize variables (they just pointed to vid.screen and vid.widht) --- src/Makefile.d/sdl.mk | 2 +- src/console.c | 31 ------- src/console.h | 5 -- src/d_main.c | 9 -- src/doomtype.h | 1 - src/hardware/hw_draw.c | 200 +---------------------------------------- src/hardware/hw_main.h | 2 - src/hu_stuff.c | 70 --------------- src/hu_stuff.h | 1 - src/i_video.h | 2 +- src/m_menu.c | 3 +- src/r_draw.cpp | 151 +------------------------------ src/r_draw.h | 34 +------ src/r_main.cpp | 2 - src/r_plane.cpp | 2 +- src/r_segs.cpp | 5 +- src/r_things.cpp | 2 - src/screen.c | 7 +- src/screen.h | 2 - src/sdl/Srb2SDL.dsp | 4 +- src/sdl/Srb2SDL.props | 4 +- src/st_stuff.c | 4 - 22 files changed, 15 insertions(+), 528 deletions(-) diff --git a/src/Makefile.d/sdl.mk b/src/Makefile.d/sdl.mk index c704a83eb..95fe34e6a 100644 --- a/src/Makefile.d/sdl.mk +++ b/src/Makefile.d/sdl.mk @@ -10,7 +10,7 @@ makedir:=$(makedir)/SDL -opts+=-DDIRECTFULLSCREEN -DHAVE_SDL +opts+=-DHAVE_SDL sources+=$(call List,sdl/Sourcefile) NOUPNP=1 diff --git a/src/console.c b/src/console.c index fe91df0f3..3959d9b98 100644 --- a/src/console.c +++ b/src/console.c @@ -69,14 +69,9 @@ static boolean consoleready; // console prompt is ready INT32 con_destlines; // vid lines used by console at final position static INT32 con_curlines; // vid lines currently used by console - INT32 con_clipviewtop; // (useless) - static UINT8 con_hudlines; // number of console heads up message lines static UINT32 con_hudtime[MAXHUDLINES]; // remaining time of display for hud msg lines - INT32 con_clearlines; // top screen lines to refresh when view reduced - boolean con_hudupdate; // when messages scroll, we need a backgrnd refresh - // console text output static char *con_line; // console text output current line static size_t con_cx; // cursor position in current line @@ -393,9 +388,6 @@ void CON_Init(void) Lock_state(); - //note: CON_Ticker should always execute at least once before D_Display() - con_clipviewtop = -1; // -1 does not clip - con_hudlines = atoi(cons_hudlines.defaultvalue); Unlock_state(); @@ -727,7 +719,6 @@ void CON_ToggleOff(void) con_curlines = 0; CON_ClearHUD(); con_forcepic = 0; - con_clipviewtop = -1; // remove console clipping of view I_SetTextInput(false); @@ -779,18 +770,6 @@ void CON_Ticker(void) } } - // clip the view, so that the part under the console is not drawn - con_clipviewtop = -1; - if (cons_backpic.value) // clip only when using an opaque background - { - if (con_curlines > 0) - con_clipviewtop = con_curlines - viewwindowy - 1 - 10; - // NOTE: BIG HACK::SUBTRACT 10, SO THAT WATER DON'T COPY LINES OF THE CONSOLE - // WINDOW!!! (draw some more lines behind the bottom of the console) - if (con_clipviewtop < 0) - con_clipviewtop = -1; // maybe not necessary, provided it's < 0 - } - // check if console ready for prompt if (con_destlines >= minheight) { @@ -1100,9 +1079,6 @@ static void CON_Linefeed(void) con_line = &con_buffer[(con_cy%con_totallines)*con_width]; memset(con_line, ' ', con_width); - - // make sure the view borders are refreshed if hud messages scroll - con_hudupdate = true; // see HU_Erase() } // Outputs text into the console text buffer @@ -1489,9 +1465,6 @@ static void CON_DrawHudlines(void) //V_DrawCharacter(x, y, (p[c]&0xff) | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); y += charheight; } - - // top screen lines that might need clearing when view is reduced - con_clearlines = y; // this is handled by HU_Erase(); } // draw the console background, text, and prompt if enough place @@ -1509,10 +1482,6 @@ static void CON_DrawConsole(void) if (con_curlines <= 0) return; - //FIXME: refresh borders only when console bg is translucent - con_clearlines = con_curlines; // clear console draw from view borders - con_hudupdate = true; // always refresh while console is on - // draw console background if (cons_backpic.value || con_forcepic) { diff --git a/src/console.h b/src/console.h index e704a87f1..79af2e48f 100644 --- a/src/console.h +++ b/src/console.h @@ -30,14 +30,9 @@ extern boolean con_recalc; extern boolean con_startup; -// top clip value for view render: do not draw part of view hidden by console -extern INT32 con_clipviewtop; - // 0 means console if off, or moving out extern INT32 con_destlines; -extern INT32 con_clearlines; // lines of top of screen to refresh -extern boolean con_hudupdate; // hud messages have changed, need refresh extern UINT32 con_scalefactor; // console text scale factor extern consvar_t cons_backcolor, cons_menuhighlight; diff --git a/src/d_main.c b/src/d_main.c index dd13c7b77..33dc57689 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -522,19 +522,16 @@ static boolean D_Display(void) case GS_LEVEL: if (!gametic) break; - HU_Erase(); AM_Drawer(); break; case GS_INTERMISSION: Y_IntermissionDrawer(); - HU_Erase(); HU_Drawer(); break; case GS_VOTING: Y_VoteDrawer(); - HU_Erase(); HU_Drawer(); break; @@ -549,7 +546,6 @@ static boolean D_Display(void) case GS_CUTSCENE: F_CutsceneDrawer(); - HU_Erase(); HU_Drawer(); break; @@ -559,7 +555,6 @@ static boolean D_Display(void) case GS_EVALUATION: F_GameEvaluationDrawer(); - HU_Erase(); HU_Drawer(); break; @@ -569,7 +564,6 @@ static boolean D_Display(void) case GS_CREDITS: F_CreditDrawer(); - HU_Erase(); HU_Drawer(); break; @@ -586,7 +580,6 @@ static boolean D_Display(void) { // I don't think HOM from nothing drawing is independent... F_WaitingPlayersDrawer(); - HU_Erase(); HU_Drawer(); } case GS_TIMEATTACK: @@ -1925,9 +1918,7 @@ void D_SRB2Main(void) G_LoadGameData(); -#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) VID_PrepareModeList(); // Regenerate Modelist according to cv_fullscreen -#endif // set user default mode or mode set at cmdline SCR_CheckDefaultMode(); diff --git a/src/doomtype.h b/src/doomtype.h index 81c09c007..78867ed69 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -43,7 +43,6 @@ extern "C" { #define UINT64 uint64_t #ifdef __APPLE_CC__ -#define DIRECTFULLSCREEN 1 #define DEBUG_LOG #define NOIPX #endif diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 1c014ce4c..cf8ab29e3 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -31,11 +31,6 @@ #include "../st_stuff.h" #include -#include "../i_video.h" // for rendermode != render_glide - -#ifndef O_BINARY -#define O_BINARY 0 -#endif typedef struct { @@ -58,68 +53,6 @@ static UINT8 softwaretranstogl_lo[11] = { 0, 12, 24, 36, 48, 60, 71, 83, 95,111 static const float FLOATBASEVIDWIDTH = (float)BASEVIDWIDTH; static const float FLOATBASEVIDHEIGHT = (float)BASEVIDHEIGHT; -// -// -----------------+ -// HWR_DrawPatch : Draw a 'tile' graphic -// Notes : x,y : positions relative to the original Doom resolution -// : textes(console+score) + menus + status bar -// -----------------+ -void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) -{ - FOutVector v[4]; - FBITFIELD flags; - GLPatch_t *hwrPatch; - -// 3--2 -// | /| -// |/ | -// 0--1 - float sdup = FIXED_TO_FLOAT(vid.fdup)*2.0f; - float pdup = FIXED_TO_FLOAT(vid.fdup)*2.0f; - - // make patch ready in hardware cache - HWR_GetPatch(gpatch); - hwrPatch = ((GLPatch_t *)gpatch->hardware); - - switch (option & V_SCALEPATCHMASK) - { - case V_NOSCALEPATCH: - pdup = 2.0f; - break; - case V_SMALLSCALEPATCH: - pdup = 2.0f * FIXED_TO_FLOAT(vid.smalldup*FRACUNIT); - break; - case V_MEDSCALEPATCH: - pdup = 2.0f * FIXED_TO_FLOAT(vid.meddup*FRACUNIT); - break; - } - - if (option & V_NOSCALESTART) - sdup = 2.0f; - - v[0].x = v[3].x = (x*sdup-gpatch->leftoffset*pdup)/vid.width - 1; - v[2].x = v[1].x = (x*sdup+(gpatch->width - gpatch->leftoffset)*pdup)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdup-gpatch->topoffset*pdup)/vid.height; - v[2].y = v[3].y = 1-(y*sdup+(gpatch->height - gpatch->topoffset)*pdup)/vid.height; - - v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - - v[0].s = v[3].s = 0.0f; - v[2].s = v[1].s = hwrPatch->max_s; - v[0].t = v[1].t = 0.0f; - v[2].t = v[3].t = hwrPatch->max_t; - - flags = PF_Translucent|PF_NoDepthTest; - - if (option & V_WRAPX) - flags |= PF_ForceWrapX; - if (option & V_WRAPY) - flags |= PF_ForceWrapY; - - // clip it since it is used for bunny scroll in doom I - GL_DrawPolygon(NULL, v, 4, flags); -} - void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags) { FOutVector v[4]; @@ -636,137 +569,6 @@ void HWR_DrawConsoleBack(UINT32 color, INT32 height) } -// ========================================================================== -// R_DRAW.C STUFF -// ========================================================================== - -// ------------------ -// HWR_DrawViewBorder -// Fill the space around the view window with a Doom flat texture, draw the -// beveled edges. -// 'clearlines' is useful to clear the heads up messages, when the view -// window is reduced, it doesn't refresh all the view borders. -// ------------------ -void HWR_DrawViewBorder(INT32 clearlines) -{ -#if 0 - INT32 x, y; - INT32 top, side; - INT32 baseviewwidth, baseviewheight; - INT32 basewindowx, basewindowy; - patch_t *patch; - - if (!clearlines) - clearlines = BASEVIDHEIGHT; // refresh all - - // calc view size based on original game resolution - baseviewwidth = FixedInt(FixedDiv(viewwidth * FRACUNIT, vid.fdup)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; - baseviewheight = FixedInt(FixedDiv(viewheight * FRACUNIT, vid.fdup)); - top = FixedInt(FixedDiv(baseviewwindowy * FRACUNIT, vid.fdup)); - side = FixedInt(FixedDiv(baseviewwindowx * FRACUNIT, vid.fdup)); - - // top - HWR_DrawFlatFill(0, 0, - BASEVIDWIDTH, (top < clearlines ? top : clearlines), - st_borderpatchnum); - - // left - if (top < clearlines) - HWR_DrawFlatFill(0, top, side, - (clearlines-top < baseviewheight ? clearlines-top : baseviewheight), - st_borderpatchnum); - - // right - if (top < clearlines) - HWR_DrawFlatFill(side + baseviewwidth, top, side, - (clearlines-top < baseviewheight ? clearlines-top : baseviewheight), - st_borderpatchnum); - - // bottom - if (top + baseviewheight < clearlines) - HWR_DrawFlatFill(0, top + baseviewheight, - BASEVIDWIDTH, BASEVIDHEIGHT, st_borderpatchnum); - - // - // draw the view borders - // - - basewindowx = (BASEVIDWIDTH - baseviewwidth)>>1; - if (baseviewwidth == BASEVIDWIDTH) - basewindowy = 0; - else - basewindowy = top; - - // top edge - if (clearlines > basewindowy - 8) - { - patch = W_CachePatchNum(viewborderlump[BRDR_T], PU_PATCH); - for (x = 0; x < baseviewwidth; x += 8) - HWR_DrawPatch(patch, basewindowx + x, basewindowy - 8, - 0); - } - - // bottom edge - if (clearlines > basewindowy + baseviewheight) - { - patch = W_CachePatchNum(viewborderlump[BRDR_B], PU_PATCH); - for (x = 0; x < baseviewwidth; x += 8) - HWR_DrawPatch(patch, basewindowx + x, - basewindowy + baseviewheight, 0); - } - - // left edge - if (clearlines > basewindowy) - { - patch = W_CachePatchNum(viewborderlump[BRDR_L], PU_PATCH); - for (y = 0; y < baseviewheight && basewindowy + y < clearlines; - y += 8) - { - HWR_DrawPatch(patch, basewindowx - 8, basewindowy + y, - 0); - } - } - - // right edge - if (clearlines > basewindowy) - { - patch = W_CachePatchNum(viewborderlump[BRDR_R], PU_PATCH); - for (y = 0; y < baseviewheight && basewindowy+y < clearlines; - y += 8) - { - HWR_DrawPatch(patch, basewindowx + baseviewwidth, - basewindowy + y, 0); - } - } - - // Draw beveled corners. - if (clearlines > basewindowy - 8) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TL], - PU_PATCH), - basewindowx - 8, basewindowy - 8, 0); - - if (clearlines > basewindowy - 8) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TR], - PU_PATCH), - basewindowx + baseviewwidth, basewindowy - 8, 0); - - if (clearlines > basewindowy+baseviewheight) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BL], - PU_PATCH), - basewindowx - 8, basewindowy + baseviewheight, 0); - - if (clearlines > basewindowy + baseviewheight) - HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BR], - PU_PATCH), - basewindowx + baseviewwidth, - basewindowy + baseviewheight, 0); -#else - (void)clearlines; -#endif -} - - - // ========================================================================== // AM_MAP.C DRAWING STUFF // ========================================================================== @@ -1172,7 +974,7 @@ static inline boolean saveTGA(const char *file_name, void *buffer, INT32 i; UINT8 *buf8 = buffer; - fd = open(file_name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); + fd = open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) return false; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 43a292c57..30906b611 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -85,7 +85,6 @@ extern ps_metric_t ps_hw_batchdrawtime; extern boolean gl_shadersavailable; // hw_draw.c -void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option); void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags); void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h); void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color); @@ -94,7 +93,6 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color); void HWR_drawAMline(const fline_t *fl, INT32 color); void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength); void HWR_DrawConsoleBack(UINT32 color, INT32 height); -void HWR_DrawViewBorder(INT32 clearlines); void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum); UINT8 *HWR_GetScreenshot(INT32 scale); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 6ca275aff..fa7060dff 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2391,76 +2391,6 @@ void HU_Drawer(void) } } -//====================================================================== -// HUD MESSAGES CLEARING FROM SCREEN -//====================================================================== - -// Clear old messages from the borders around the view window -// (only for reduced view, refresh the borders when needed) -// -// startline: y coord to start clear, -// clearlines: how many lines to clear. -// -static INT32 oldclearlines; - -void HU_Erase(void) -{ - INT32 topline, bottomline; - INT32 y, yoffset; - -#ifdef HWRENDER - // clear hud msgs on double buffer (OpenGL mode) - boolean secondframe; - static INT32 secondframelines; -#endif - - if (con_clearlines == oldclearlines && !con_hudupdate && !chat_on) - return; - -#ifdef HWRENDER - // clear the other frame in double-buffer modes - secondframe = (con_clearlines != oldclearlines); - if (secondframe) - secondframelines = oldclearlines; -#endif - - // clear the message lines that go away, so use _oldclearlines_ - bottomline = oldclearlines; - oldclearlines = con_clearlines; - if (chat_on && OLDCHAT) - if (bottomline < 8) - bottomline = 8; // only do it for consolechat. consolechat is gay. - - if (automapactive || viewwindowx == 0) // hud msgs don't need to be cleared - return; - - // software mode copies view border pattern & beveled edges from the backbuffer - if (rendermode == render_soft) - { - topline = 0; - for (y = topline, yoffset = y*vid.width; y < bottomline; y++, yoffset += vid.width) - { - if (y < viewwindowy || y >= viewwindowy + viewheight) - R_VideoErase(yoffset, vid.width); // erase entire line - else - { - R_VideoErase(yoffset, viewwindowx); // erase left border - // erase right border - R_VideoErase(yoffset + viewwindowx + viewwidth, viewwindowx); - } - } - con_hudupdate = false; // if it was set.. - } -#ifdef HWRENDER - else if (rendermode != render_none) - { - // refresh just what is needed from the view borders - HWR_DrawViewBorder(secondframelines); - con_hudupdate = secondframe; - } -#endif -} - //====================================================================== // IN-LEVEL MULTIPLAYER RANKINGS //====================================================================== diff --git a/src/hu_stuff.h b/src/hu_stuff.h index d134f319e..64d369a33 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -117,7 +117,6 @@ void HU_TickSongCredits(void); void HU_DrawSongCredits(void); void HU_Drawer(void); char HU_dequeueChatChar(void); -void HU_Erase(void); void HU_clearChatChars(void); void HU_drawPlayerPing(INT32 x, INT32 y, INT32 pnum, INT32 flags); // Lat': Ping drawer for scoreboard. //void HU_DrawTeamTabRankings(playersort_t *tab, INT32 whiteplayer); diff --git a/src/i_video.h b/src/i_video.h index 822a1bada..852645c30 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -94,8 +94,8 @@ INT32 VID_SetMode(INT32 modenum); \return name of video mode */ const char *VID_GetModeName(INT32 modenum); -void VID_PrepareModeList(void); /// note hack for SDL +void VID_PrepareModeList(void); /** \brief can video system do fullscreen */ diff --git a/src/m_menu.c b/src/m_menu.c index 95824c7dd..ed39e053f 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9442,9 +9442,8 @@ static void M_VideoModeMenu(INT32 choice) memset(modedescs, 0, sizeof(modedescs)); -#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) VID_PrepareModeList(); // FIXME: hack -#endif + vidm_nummodes = 0; vidm_selected = 0; nummodes = VID_NumModes(); diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 288cf462d..e5596e4c8 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -41,8 +41,7 @@ /** \brief view info */ -INT32 linesize, viewwidth, viewheight, viewwindowx, viewwindowy; -UINT8 *renderscreen; // haleyjd +INT32 viewwidth, viewheight, viewwindowx, viewwindowy; // ========================================================================= // COLUMN DRAWING CODE STUFF @@ -607,7 +606,6 @@ static void R_AllocViewMemory(void) R_AllocVisSpriteMemory(); } - void R_InitViewBuffer(INT32 width, INT32 height) { if (width > MAXVIDWIDTH) @@ -620,10 +618,7 @@ void R_InitViewBuffer(INT32 width, INT32 height) viewwindowx = 0; viewwindowy = 0; - linesize = vid.width; // killough 11/98 - renderscreen = vid.screens[0]; // haleyjd 07/02/14 - - INT32 bufsize = (linesize * 8) * sizeof(*temp_dc.buf); + INT32 bufsize = (vid.width * 8) * sizeof(*temp_dc.buf); if (temp_dc.buf) { @@ -645,25 +640,6 @@ void R_InitViewBuffer(INT32 width, INT32 height) #endif } -/** \brief viewborder patches lump numbers -*/ -lumpnum_t viewborderlump[8]; - -/** \brief Store the lumpnumber of the viewborder patches -*/ - -void R_InitViewBorder(void) -{ - viewborderlump[BRDR_T] = W_GetNumForName("brdr_t"); - viewborderlump[BRDR_B] = W_GetNumForName("brdr_b"); - viewborderlump[BRDR_L] = W_GetNumForName("brdr_l"); - viewborderlump[BRDR_R] = W_GetNumForName("brdr_r"); - viewborderlump[BRDR_TL] = W_GetNumForName("brdr_tl"); - viewborderlump[BRDR_BL] = W_GetNumForName("brdr_bl"); - viewborderlump[BRDR_TR] = W_GetNumForName("brdr_tr"); - viewborderlump[BRDR_BR] = W_GetNumForName("brdr_br"); -} - /** \brief The R_VideoErase function Copy a screen buffer. @@ -685,129 +661,6 @@ void R_VideoErase(size_t ofs, INT32 count) M_Memcpy(vid.screens[0] + ofs, vid.screens[1] + ofs, count); } - -#if 0 -/** \brief R_FillBackScreen - - Fills the back screen with a pattern for variable screen sizes - Also draws a beveled edge. -*/ -void R_FillBackScreen(void) -{ - UINT8 *src, *dest; - patch_t *patch; - INT32 x, y, step, boff; - - // quickfix, don't cache lumps in both modes - if (rendermode != render_soft) - return; - - // draw pattern around the status bar too (when hires), - // so return only when in full-screen without status bar. - if (scaledviewwidth == vid.width && viewheight == vid.height) - return; - - src = scr_borderpatch; - dest = vid.screens[1]; - - for (y = 0; y < vid.height; y++) - { - for (x = 0; x < vid.width/128; x++) - { - M_Memcpy (dest, src+((y&127)<<7), 128); - dest += 128; - } - - if (vid.width&127) - { - M_Memcpy(dest, src+((y&127)<<7), vid.width&127); - dest += (vid.width&127); - } - } - - // don't draw the borders when viewwidth is full vid.width. - if (scaledviewwidth == vid.width) - return; - - step = 8; - boff = 8; - - patch = W_CacheLumpNum(viewborderlump[BRDR_T], PU_CACHE); - for (x = 0; x < scaledviewwidth; x += step) - V_DrawPatch(viewwindowx + x, viewwindowy - boff, 1, patch); - - patch = W_CacheLumpNum(viewborderlump[BRDR_B], PU_CACHE); - for (x = 0; x < scaledviewwidth; x += step) - V_DrawPatch(viewwindowx + x, viewwindowy + viewheight, 1, patch); - - patch = W_CacheLumpNum(viewborderlump[BRDR_L], PU_CACHE); - for (y = 0; y < viewheight; y += step) - V_DrawPatch(viewwindowx - boff, viewwindowy + y, 1, patch); - - patch = W_CacheLumpNum(viewborderlump[BRDR_R],PU_CACHE); - for (y = 0; y < viewheight; y += step) - V_DrawPatch(viewwindowx + scaledviewwidth, viewwindowy + y, 1, - patch); - - // Draw beveled corners. - V_DrawPatch(viewwindowx - boff, viewwindowy - boff, 1, - W_CacheLumpNum(viewborderlump[BRDR_TL], PU_CACHE)); - V_DrawPatch(viewwindowx + scaledviewwidth, viewwindowy - boff, 1, - W_CacheLumpNum(viewborderlump[BRDR_TR], PU_CACHE)); - V_DrawPatch(viewwindowx - boff, viewwindowy + viewheight, 1, - W_CacheLumpNum(viewborderlump[BRDR_BL], PU_CACHE)); - V_DrawPatch(viewwindowx + scaledviewwidth, viewwindowy + viewheight, 1, - W_CacheLumpNum(viewborderlump[BRDR_BR], PU_CACHE)); -} - -/** \brief The R_DrawViewBorder - - Draws the border around the view - for different size windows? -*/ -void R_DrawViewBorder(void) -{ - INT32 top, side, ofs; - - if (rendermode == render_none) - return; -#ifdef HWRENDER - if (rendermode != render_soft) - { - HWR_DrawViewBorder(0); - return; - } - else -#endif - -#ifdef DEBUG - fprintf(stderr,"RDVB: vidwidth %d vidheight %d scaledviewwidth %d viewheight %d\n", - vid.width, vid.height, scaledviewwidth, viewheight); -#endif - - if (scaledviewwidth == vid.width) - return; - - top = (vid.height - viewheight)>>1; - side = (vid.width - scaledviewwidth)>>1; - - // copy top and one line of left side - R_VideoErase(0, top*vid.width+side); - - // copy one line of right side and bottom - ofs = (viewheight+top)*vid.width - side; - R_VideoErase(ofs, top*vid.width + side); - - // copy sides using wraparound - ofs = top*vid.width + vid.width-side; - side <<= 1; - - // simpler using our VID_Blit routine - VID_BlitLinearScreen(vid.screens[1] + ofs, vid.screens[0] + ofs, side, viewheight - 1, - vid.width, vid.width); -} -#endif - // ========================================================================== // INCLUDE DRAWING CODE HERE // ========================================================================== diff --git a/src/r_draw.h b/src/r_draw.h index ae9d2ef40..cd1356522 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -25,12 +25,10 @@ extern "C" { // ------------------------------- // COMMON STUFF FOR 8bpp AND 16bpp // ------------------------------- -extern UINT8 *renderscreen; -extern INT32 linesize; FUNCINLINE static ATTRINLINE UINT8 *R_Address(INT32 px, INT32 py) { - return renderscreen + (py + viewwindowy) * linesize + (viewwindowx + px); + return vid.screens[0] + (py + viewwindowy) * vid.width + (viewwindowx + px); } @@ -162,27 +160,8 @@ extern spandrawfunc_t *spanfuncs[SPANDRAWFUNC_MAX]; void R_DrawMaskedColumn(drawcolumndata_t* dc, column_t *column); -/// \brief Top border -#define BRDR_T 0 -/// \brief Bottom border -#define BRDR_B 1 -/// \brief Left border -#define BRDR_L 2 -/// \brief Right border -#define BRDR_R 3 -/// \brief Topleft border -#define BRDR_TL 4 -/// \brief Topright border -#define BRDR_TR 5 -/// \brief Bottomleft border -#define BRDR_BL 6 -/// \brief Bottomright border -#define BRDR_BR 7 - -extern lumpnum_t viewborderlump[8]; - // ------------------------------------------------ -// r_draw.c COMMON ROUTINES FOR BOTH 8bpp and 16bpp +// r_draw.c // ------------------------------------------------ #define GTC_CACHE 1 @@ -231,17 +210,8 @@ boolean R_BlendLevelVisible(INT32 blendmode, INT32 alphalevel); // Custom player skin translation void R_InitViewBuffer(INT32 width, INT32 height); -void R_InitViewBorder(void); void R_VideoErase(size_t ofs, INT32 count); -// Rendering function. -#if 0 -void R_FillBackScreen(void); - -// If the view size is not full screen, draws a border around it. -void R_DrawViewBorder(void); -#endif - #define TRANSPARENTPIXEL 247 // ----------------- diff --git a/src/r_main.cpp b/src/r_main.cpp index 88435ba93..37cfed8c5 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1023,8 +1023,6 @@ void R_Init(void) //I_OutputMsg("\nR_InitData"); R_InitData(); - //I_OutputMsg("\nR_InitViewBorder"); - R_InitViewBorder(); R_SetViewSize(); // setsizeneeded is set true // this is now done by SCR_Recalc() at the first mode set diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 435365f12..f4eb61410 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -784,7 +784,7 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b drawcolumndata_t dc = {}; const INT32 texture = texturetranslation[skytexture]; - // Reset column drawer function (note: couldn't we just call walldrawerfunc directly?) + // Reset column drawer function (note: couldn't we just call colfuncs[BASEDRAWFUNC] directly?) // (that is, unless we'll need to switch drawers in future for some reason) R_SetColumnFunc(BASEDRAWFUNC); diff --git a/src/r_segs.cpp b/src/r_segs.cpp index c83b45593..b4f8cdbcd 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -26,7 +26,6 @@ #include "p_local.h" // Camera... #include "p_setup.h" #include "p_slopes.h" -#include "console.h" // con_clipviewtop #include "screen.h" #include "core/memory.h" @@ -628,8 +627,6 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf sector_t tempsec; INT32 templight; INT32 i, p; - fixed_t bottombounds = viewheight << FRACBITS; - fixed_t topbounds = (con_clipviewtop - 1) << FRACBITS; fixed_t offsetvalue = 0; lightlist_t *light; r_lightlist_t *rlight; @@ -936,7 +933,7 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf bottom_frac += bottom_step; // SoM: If column is out of range, why bother with it?? - if (windowbottom < topbounds || windowtop > bottombounds) + if (windowbottom < 0 || windowtop > (viewheight << FRACBITS)) { if (dc->numlights) { diff --git a/src/r_things.cpp b/src/r_things.cpp index a5ba974ba..673fdfc6c 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2518,8 +2518,6 @@ void R_InitDrawNodes(void) // R_DrawSprite // //Fab : 26-04-98: -// NOTE : uses con_clipviewtop, so that when console is on, -// don't draw the part of sprites hidden under the console static void R_DrawSprite(vissprite_t *spr) { mfloorclip = spr->clipbot; diff --git a/src/screen.c b/src/screen.c index c298b0b75..78cfefd4f 100644 --- a/src/screen.c +++ b/src/screen.c @@ -80,10 +80,6 @@ consvar_t cv_accuratefps = {"fpssampling", "1", CV_SAVE, accuratefps_cons_t, NUL // SCREEN VARIABLES // ========================================================================= -UINT8 *scr_borderpatch; // flat used to fill the reduced view borders set at ST_Init() - -// ========================================================================= - static void SCR_SetDrawFuncs(enum columncontext_e _columncontext) { // @@ -323,7 +319,6 @@ void SCR_SetDefaultMode(void) // Change fullscreen on/off according to cv_fullscreen void SCR_ChangeFullscreen(void) { -#ifdef DIRECTFULLSCREEN I_SetBorderlessWindow(); // Running this here so we can have borderless window at startup // allow_fullscreen is set by VID_PrepareModeList @@ -336,8 +331,8 @@ void SCR_ChangeFullscreen(void) VID_PrepareModeList(); setmodeneeded = VID_GetModeForSize(vid.width, vid.height) + 1; } + return; -#endif } boolean SCR_IsAspectCorrect(INT32 width, INT32 height) diff --git a/src/screen.h b/src/screen.h index 8cd90c23a..0a912e97a 100644 --- a/src/screen.h +++ b/src/screen.h @@ -84,8 +84,6 @@ enum extern viddef_t vid; extern INT32 setmodeneeded; // mode number to set if needed, or 0 -extern UINT8 *scr_borderpatch; // patch used to fill the view borders - extern consvar_t cv_scr_width, cv_scr_height, cv_renderview, cv_frameskip, cv_fullscreen, cv_vhseffect, cv_shittyscreen; extern consvar_t cv_parallelsoftware; extern consvar_t cv_paralleldrawmasked; diff --git a/src/sdl/Srb2SDL.dsp b/src/sdl/Srb2SDL.dsp index 47ede4126..96d3e8418 100644 --- a/src/sdl/Srb2SDL.dsp +++ b/src/sdl/Srb2SDL.dsp @@ -45,7 +45,7 @@ MTL=midl.exe # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /G5 /W3 /GX /Zi /Ot /Og /Oi /Op /Oy /Ob1 /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "NDEBUG" /D "SDLMAIN" /D "NO_STDIO_REDIRECT" /D "USE_WGL_SWAP" /D "DIRECTFULLSCREEN" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GF /c +# ADD CPP /nologo /G5 /W3 /GX /Zi /Ot /Og /Oi /Op /Oy /Ob1 /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "NDEBUG" /D "SDLMAIN" /D "NO_STDIO_REDIRECT" /D "USE_WGL_SWAP" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GF /c # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" # SUBTRACT RSC /x @@ -72,7 +72,7 @@ LINK32=link.exe # PROP Target_Dir "" MTL=midl.exe # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /G6 /W4 /WX /Gm /GX /ZI /Od /Op /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "_DEBUG" /D "USE_WGL_SWAP" /D "DIRECTFULLSCREEN" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GZ /c +# ADD CPP /nologo /G6 /W4 /WX /Gm /GX /ZI /Od /Op /I "..\..\libs\libpng-src" /I "..\..\libs\zlib" /D "_DEBUG" /D "USE_WGL_SWAP" /D "HAVE_SDL" /D "HWRENDER" /D "HAVE_FILTER" /D "HAVE_MIXER" /D "USEASM" /D "HAVE_PNG" /FR /FD /GZ /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" diff --git a/src/sdl/Srb2SDL.props b/src/sdl/Srb2SDL.props index f02b9b35e..8c4799f20 100644 --- a/src/sdl/Srb2SDL.props +++ b/src/sdl/Srb2SDL.props @@ -6,9 +6,9 @@ - HAVE_ZLIB;HAVE_LIBGME;USE_WGL_SWAP;DIRECTFULLSCREEN;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) + HAVE_ZLIB;HAVE_LIBGME;USE_WGL_SWAP;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) - USE_WGL_SWAP;DIRECTFULLSCREEN;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) + USE_WGL_SWAP;HAVE_SDL;HWRENDER;HAVE_FILTER;HAVE_MIXER;SDLMAIN;%(PreprocessorDefinitions) diff --git a/src/st_stuff.c b/src/st_stuff.c index f5634423c..fade7c484 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -219,10 +219,6 @@ void ST_UnloadGraphics(void) void ST_LoadGraphics(void) { - // SRB2 border patch - //st_borderpatchnum = W_GetNumForName("GFZFLR01"); - //scr_borderpatch = W_CacheLumpNum(st_borderpatchnum, PU_HUDGFX); - // the original Doom uses 'STF' as base name for all face graphics // Graue 04-08-2004: face/name graphics are now indexed by skins // but load them in R_AddSkins, that gets called -- 2.54.0 From da16ce3a234da75ce225bb90aac28f3bd016bcb5 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 15 Oct 2025 06:28:39 +0200 Subject: [PATCH 40/40] mark flush error functions with noreturn silences clang --- src/r_draw.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index e5596e4c8..ed233e387 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -521,17 +521,17 @@ drawcolumndata_temp_t temp_dc = {}; // Error functions that will abort if R_FlushColumns tries to flush // columns without a column type. // -static void R_FlushWholeError(void) +FUNCNORETURN static ATTRNORETURN void R_FlushWholeError(void) { I_Error("R_FlushWholeColumns called without being initialized.\n"); } -static void R_FlushHTError(void) +FUNCNORETURN static ATTRNORETURN void R_FlushHTError(void) { I_Error("R_FlushHTColumns called without being initialized.\n"); } -static void R_QuadFlushError(void) +FUNCNORETURN static ATTRNORETURN void R_QuadFlushError(void) { I_Error("R_FlushQuadColumn called without being initialized.\n"); } -- 2.54.0