From b7662f100a45abdda5196950f72d9f9c168ceefc Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Apr 2026 20:05:47 +0200 Subject: [PATCH] ok dont cache the holecols stuffs a mess and waste of memory honestly, just use a vector to avoid reallocations, caching them didnt really bring much benefit eitherwas --- src/r_data.c | 64 -------------------------------------------------- src/r_data.h | 1 - src/r_segs.cpp | 34 ++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 66 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index bd56f5674..507696925 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -504,45 +504,6 @@ UINT8 *R_GetColumn(fixed_t tex, INT32 col) return texturecache[tex] + LONG(texturecolumnofs[tex][wrap_column(tex, col)]); } -static UINT8 ***holecols; - -// used for R_DrawWallColumn -// convert "holey" columns into contigous columns -// filled with cyan in place of holes -UINT8 *R_GetHoleColumn(INT32 tex, INT32 col) -{ - col = wrap_column(tex, col); - - if (!holecols[tex][col]) - { - UINT8 *src = texturecache[tex] + LONG(texturecolumnofs[tex][col]); - column_t *coldata = (column_t *)(src - 3); - - INT32 texheight = textureheight[tex] >> FRACBITS; - - UINT8 *holecole = Z_Malloc(texheight, PU_STATIC, NULL); - // fill in everything with cyan so we can skip it - memset(holecole, TRANSPARENTPIXEL, texheight); - - // shamelessly copy pasted from R_GenerateTexture - INT32 topdelta, prevdelta = -1; - while (coldata->topdelta != 0xff) - { - topdelta = coldata->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - - memcpy(holecole + topdelta, (UINT8*)coldata + 4, coldata->length); - coldata = (column_t *)((UINT8*)coldata + coldata->length + 4); - } - - holecols[tex][col] = holecole; - } - - return holecols[tex][col]; -} - // convert flats to hicolor as they are requested // UINT8 *R_GetFlat(lumpnum_t flatlumpnum) @@ -718,30 +679,6 @@ static INT32 R_CountTextures(UINT16 wadnum) return count; } -static void R_AllocHoleColes(INT32 add) -{ - // only needed for software - if (rendermode != render_soft) - return; - - const INT32 newtextures = (numtextures + add); - - Z_Realloc(holecols, newtextures * sizeof(UINT8**), PU_STATIC, &holecols); - - for (INT32 tex = numtextures; tex < newtextures; tex++) - { - // FIXME: kinda wasteful but idk how to make shit not die skipping textures without holes.... - INT32 width = texturewidth[tex]; - - holecols[tex] = Z_Malloc(width * sizeof(UINT8*), PU_STATIC, NULL); - - for (INT32 col = 0; col < width; col++) - { - holecols[tex][col] = NULL; - } - } -} - static void R_AllocateTextures(INT32 add) { const INT32 newtextures = (numtextures + add); @@ -786,7 +723,6 @@ static INT32 R_DefineTextures(INT32 i, UINT16 w) static void R_FinishLoadingTextures(INT32 add) { - R_AllocHoleColes(add); numtextures += add; #ifdef HWRENDER diff --git a/src/r_data.h b/src/r_data.h index ff455427d..168f72bf0 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -81,7 +81,6 @@ void R_CheckTextureCache(INT32 tex); // Retrieve column data for span blitting. UINT8 *R_GetColumn(fixed_t tex, INT32 col); -UINT8 *R_GetHoleColumn(INT32 tex, INT32 col); UINT8 *R_GetFlat(lumpnum_t flatnum); diff --git a/src/r_segs.cpp b/src/r_segs.cpp index db959b68b..14c6cff0b 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1166,6 +1166,38 @@ static inline void R_ExpandPlaneY(visplane_t *pl, INT32 x, INT16 top, INT16 bott // CALLED: CORE LOOPING ROUTINE. // +#include +static std::vector holecol(256); + +// used for R_DrawWallColumn +// convert "holey" columns into contigous columns +// filled with cyan in place of holes +static UINT8 *R_GetHoleColumn(drawcolumndata_t* dc) +{ + column_t *col = (column_t *)(dc->source - 3); + + const INT32 texheight = dc->texheight; + holecol.resize(texheight); + + // fill in everything with cyan so we can skip it + memset(holecol.data(), TRANSPARENTPIXEL, texheight); + + // shamelessly copy pasted from R_GenerateTexture + INT32 topdelta, prevdelta = -1; + while (col->topdelta != 0xff) + { + topdelta = col->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + + memcpy(holecol.data() + topdelta, (UINT8*)col + 4, col->length); + col = (column_t *)((UINT8*)col + col->length + 4); + } + + return holecol.data(); +} + static void R_DrawWallColumn(drawcolumndata_t* dc, INT32 yl, INT32 yh, fixed_t mid, fixed_t texturecolumn, INT32 texture, boolean remap) { const INT32 itexturecolumn = texturecolumn >> FRACBITS; @@ -1181,7 +1213,7 @@ static void R_DrawWallColumn(drawcolumndata_t* dc, INT32 yl, INT32 yh, fixed_t m if (textures[texture]->holes) { - dc->source = R_GetHoleColumn(texture, itexturecolumn); + dc->source = R_GetHoleColumn(dc); // need to use multipatch drawers to cut cyan pixels if (R_CheckColumnFunc(COLDRAWFUNC_FUZZY) == true)