From f85c7ef961cca8d75b53e6f5d58aaad137f904d4 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 4 Oct 2025 17:25:03 +0300 Subject: [PATCH 01/25] Copyleft :3 --- src/k_stats.c | 11 +++++++++++ src/k_stats.h | 11 +++++++++++ src/lua_udatalib.c | 11 +++++++++++ src/lua_udatalib.h | 13 ++++++++++++- src/m_curl.c | 11 +++++++++++ src/m_curl.h | 11 +++++++++++ src/m_emotes.cpp | 11 +++++++++++ src/m_emotes.h | 11 +++++++++++ src/m_textinput.c | 11 +++++++++++ src/m_textinput.h | 11 +++++++++++ 10 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/k_stats.c b/src/k_stats.c index 538b4e3e3..9063aa854 100644 --- a/src/k_stats.c +++ b/src/k_stats.c @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 k_stats.h +/// \brief Game statistics handling + #include "k_stats.h" #include "doomstat.h" #include "g_game.h" diff --git a/src/k_stats.h b/src/k_stats.h index bd145de56..00dfff021 100644 --- a/src/k_stats.h +++ b/src/k_stats.h @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 k_stats.h +/// \brief Game statistics handling + #ifndef __K_STATS__ #define __K_STATS__ diff --git a/src/lua_udatalib.c b/src/lua_udatalib.c index d7cd68278..962fb0638 100644 --- a/src/lua_udatalib.c +++ b/src/lua_udatalib.c @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 lua_udatalib.c +/// \brief Implementation of lua userdata object metatables based on getter/setter functions + #include "doomtype.h" #include "m_fixed.h" #include "lua_udatalib.h" diff --git a/src/lua_udatalib.h b/src/lua_udatalib.h index acff4cf3b..ad23bf898 100644 --- a/src/lua_udatalib.h +++ b/src/lua_udatalib.h @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 lua_udatalib.h +/// \brief Implementation of lua userdata object metatables based on getter/setter functions + #ifndef __LUA_UDATALIB_H__ #define __LUA_UDATALIB_H__ @@ -100,4 +111,4 @@ void udatalib_addfields(lua_State *L, int mt, const udata_field_t fields[]); return 0; \ } -#endif \ No newline at end of file +#endif diff --git a/src/m_curl.c b/src/m_curl.c index c96007996..77588a3fb 100644 --- a/src/m_curl.c +++ b/src/m_curl.c @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 m_curl.c +/// \brief Common curl-related functions shared across http-mserv and file download + #include "m_curl.h" #include "doomtype.h" #include "i_system.h" // I_OutputMsg diff --git a/src/m_curl.h b/src/m_curl.h index 928a164e9..adbabda21 100644 --- a/src/m_curl.h +++ b/src/m_curl.h @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 m_curl.h +/// \brief Common curl-related functions shared across http-mserv and file download + #ifndef __M_CURL__ #define __M_CURL__ diff --git a/src/m_emotes.cpp b/src/m_emotes.cpp index facc7fb54..9ae434547 100644 --- a/src/m_emotes.cpp +++ b/src/m_emotes.cpp @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 m_emotes.cpp +/// \brief Chat emotes handling + #include #include #include diff --git a/src/m_emotes.h b/src/m_emotes.h index 783c6ec17..9921e4444 100644 --- a/src/m_emotes.h +++ b/src/m_emotes.h @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 m_emotes.h +/// \brief Chat emotes handling + #ifndef __M_EMOTES__ #define __M_EMOTES__ diff --git a/src/m_textinput.c b/src/m_textinput.c index 353c8122b..882d35e35 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 m_textinput.c +/// \brief User text input implementation + #include "m_textinput.h" #include "m_menu.h" // MAXSTRINGLENGTH #include "v_video.h" diff --git a/src/m_textinput.h b/src/m_textinput.h index 1cc1c5005..512a47b7c 100644 --- a/src/m_textinput.h +++ b/src/m_textinput.h @@ -1,3 +1,14 @@ +// SONIC ROBO BLAST 2 KART SATURN +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by Indev. +// +// 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 m_textinput.h +/// \brief User text input implementation + #ifndef __M_TEXTINPUT__ #define __M_TEXTINPUT__ From c5dce0e785ff379ec88f8589464564431cb3546f Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 4 Oct 2025 17:25:39 +0300 Subject: [PATCH 02/25] oops --- src/k_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_stats.c b/src/k_stats.c index 9063aa854..f4fac90d3 100644 --- a/src/k_stats.c +++ b/src/k_stats.c @@ -6,7 +6,7 @@ // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- -/// \file k_stats.h +/// \file k_stats.c /// \brief Game statistics handling #include "k_stats.h" From b03d5c53edb85c4e5a4c3f3304da65418557265d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 4 Oct 2025 22:02:50 +0200 Subject: [PATCH 03/25] simplify titledlighting stuff for span drawers - use a std::vector for the tiltlightbufffer, only for easier checking if it needs to be resized from resolution change - move stuff into its own function - simplify R_CalcTiltedLighting no functional change, no performance improvement, just looks neater --- src/r_draw_span.cpp | 80 ++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 52 deletions(-) diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 92d64fd6e..cfa053382 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -25,6 +25,9 @@ #define local_for_thread static #endif +#include +#include + // ========================================================================== // SPANS // ========================================================================== @@ -182,31 +185,39 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) // R_CalcTiltedLighting // Exactly what it says on the tin. I wish I wasn't too lazy to explain things properly. -static void R_CalcTiltedLighting(INT32 *lightbuffer, INT32 x1, INT32 x2, fixed_t start, fixed_t end) +static void R_CalcTiltedLighting(std::vector& lightbuffer, INT32 x1, INT32 x2, fixed_t start, fixed_t end) { // ZDoom uses a different lighting setup to us, and I couldn't figure out how to adapt their version // of this function. Here's my own. - INT32 i, left = x1, right = x2; + INT32 i; const fixed_t step = (end-start)/(x2 - x1 + 1); // I wanna do some optimizing by checking for out-of-range segments on either side to fill in all at once, // but I'm too bad at coding to not crash the game trying to do that. I guess this is fast enough for now... - for (i = left; i <= right; i++) + for (i = x1; i <= x2; i++) { - lightbuffer[i] = (start += step) >> FRACBITS; - - if (lightbuffer[i] < 0) - { - lightbuffer[i] = 0; - } - else if (lightbuffer[i] >= MAXLIGHTSCALE) - { - lightbuffer[i] = MAXLIGHTSCALE-1; - } + fixed_t light = start >> FRACBITS; + lightbuffer[i] = CLAMP(light, 0, MAXLIGHTSCALE - 1); + start += step; } } +static void R_GetTiltedLighting(std::vector& tiltlighting, const drawspandata_t* ds, const float iz, const int width, const INT32 stride) +{ + float planelightfloat = PLANELIGHTFLOAT; + const fixed_t lightstart = FloatToFixed(iz * planelightfloat); + const fixed_t lightend = FloatToFixed((iz + ds->szp.x * width) * planelightfloat); + + if (tiltlighting.size() != (size_t)viewwidth) + { + tiltlighting.resize(viewwidth); + } + + R_CalcTiltedLighting(tiltlighting, ds->x1, ds->x2, lightstart, lightend); + //CONS_Printf("tilted lighting %f to %f (foc %f)\n", FixedToFloat(lightstart), FixedToFloat(lightend), focallengthf); +} + template static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) { @@ -223,35 +234,18 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) float endz, endu, endv; UINT32 stepu, stepv; UINT32 bit; - local_for_thread INT32 *tiltlighting = NULL; - local_for_thread INT32 oldviewwidth = 0; - - // dont realloc every frame pls thx - if (tiltlighting == NULL || oldviewwidth != viewwidth) - { - tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); - oldviewwidth = viewwidth; - } INT32 x1 = ds->x1; const INT32 nflatxshift = ds->nflatxshift; const INT32 nflatyshift = ds->nflatyshift; const INT32 nflatmask = ds->nflatmask; const INT32 stride = vid.width; + local_for_thread std::vector tiltlighting; iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); // Lighting is simple. It's just linear interpolation from start to end - { - float planelightfloat = PLANELIGHTFLOAT; - float lightstart, lightend; - - lightend = (iz + ds->szp.x*width) * planelightfloat; - lightstart = iz * planelightfloat; - - R_CalcTiltedLighting(tiltlighting, ds->x1, ds->x2, FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend)); - //CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf); - } + 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); @@ -423,31 +417,13 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) int width = ds->x2 - ds->x1; float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); UINT8 * restrict dest; - - local_for_thread INT32 *tiltlighting = NULL; - local_for_thread INT32 oldviewwidth = 0; - - // dont realloc every frame pls thx - if (tiltlighting == NULL || oldviewwidth != viewwidth) - { - tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); - oldviewwidth = viewwidth; - } + local_for_thread std::vector tiltlighting; dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width; // Lighting is simple. It's just linear interpolation from start to end - { - float planelightfloat = PLANELIGHTFLOAT; - float lightstart, lightend; - - lightend = (iz + ds->szp.x*width) * planelightfloat; - lightstart = iz * planelightfloat; - - R_CalcTiltedLighting(tiltlighting, ds->x1, ds->x2, FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend)); - //CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf); - } + R_GetTiltedLighting(tiltlighting, ds, iz, width, stride); do { From 78ad3e9710cc439a8b7c22d87ef22f26757b7233 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 02:26:55 +0200 Subject: [PATCH 04/25] some fixes for texture generation - Fix negative y offsets for both normal and y-flipped patches - simplify column wrapping/nonpow2 handling - Single-patch textures: print an error if patch header is missing, cease memory errors sadly does not fix our invalid columns we get occasionally --- src/r_data.c | 158 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 100 insertions(+), 58 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index 65c6c4435..c6ffd6945 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -94,7 +94,7 @@ static UINT32 **texturecolumnofs; // column offset lookup table for each texture UINT8 **texturecache; // graphics data for each generated full-size texture // texture width is a power of 2, so it can easily repeat along sidedefs using a simple mask -static INT32 *texturewidthmask; +static INT32 *texturewidth; fixed_t *textureheight; // needed for texture pegging @@ -260,6 +260,7 @@ static inline void R_DrawColumnInCache(column_t *patch, UINT8 *cache, INT32 orig if (position < 0) { count += position; + source -= position; // start further down the column position = 0; } @@ -273,6 +274,50 @@ static inline void R_DrawColumnInCache(column_t *patch, UINT8 *cache, INT32 orig } } +static UINT8 *R_AllocateTextureBlock(size_t blocksize, UINT8 **user) +{ + texturememory += blocksize; + + return Z_Malloc(blocksize, PU_LEVEL, user); +} + +static UINT8 *R_AllocateDummyTextureBlock(size_t width, UINT8 **user) +{ + // Allocate dummy data. Keep 4-bytes aligned. + // Column offsets will be initialized to 0, which points to the 0xff byte (empty column flag). + size_t blocksize = 4 + (width * 4); + UINT8 *block = R_AllocateTextureBlock(blocksize, user); + + memset(block, 0, blocksize); + block[0] = 0xff; + + return block; +} + +static boolean R_CheckTextureLumpLength(texture_t *texture, size_t patch) +{ + UINT16 wadnum = texture->patches[patch].wad; + UINT16 lumpnum = texture->patches[patch].lump; + size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); + + // The header does not exist + if (lumplength < offsetof(softwarepatch_t, columnofs)) + { + CONS_Alert( + CONS_ERROR, + "%.8s: texture lump data is too small. Expected %s bytes, got %s. (%s)\n", + texture->name, + sizeu1(offsetof(softwarepatch_t, columnofs)), + sizeu2(lumplength), + wadfiles[wadnum]->lumpinfo[lumpnum].fullname + ); + + return false; + } + + return true; +} + // // R_GenerateTexture // @@ -297,6 +342,10 @@ UINT8 *R_GenerateTexture(size_t texnum) column_t *patchcol; UINT8 *colofs; + UINT16 wadnum; + lumpnum_t lumpnum; + size_t lumplength; + I_Assert(texnum <= (size_t)numtextures); texture = textures[texnum]; I_Assert(texture != NULL); @@ -311,45 +360,57 @@ UINT8 *R_GenerateTexture(size_t texnum) { boolean holey = false; patch = texture->patches; + + wadnum = patch->wad; + lumpnum = patch->lump; + lumplength = W_LumpLengthPwad(wadnum, lumpnum); + + // The header does not exist + if (R_CheckTextureLumpLength(texture, 0) == false) + { + block = R_AllocateDummyTextureBlock(texture->width, &texturecache[texnum]); + texturecolumnofs[texnum] = (UINT32*)&block[4]; + textures[texnum]->holes = true; + return block; + } + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; // Check the patch for holes. if (texture->width > SHORT(realpatch->width) || texture->height > SHORT(realpatch->height)) holey = true; - else + + colofs = (UINT8 *)realpatch->columnofs; + + for (x = 0; x < texture->width; x++) { - colofs = (UINT8 *)realpatch->columnofs; + column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2])); - for (x = 0; x < texture->width; x++) + INT32 topdelta, prevdelta = -1, y = 0; + + while (col->topdelta != 0xff) { - column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2])); - - INT32 topdelta, prevdelta = -1, y = 0; - - while (col->topdelta != 0xff) - { - topdelta = col->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - if (topdelta > y) - break; - y = topdelta + col->length + 1; - col = (column_t *)((UINT8 *)col + col->length + 4); - } - - if (y < texture->height) - holey = true; // this texture is HOLEy! D: + topdelta = col->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + if (topdelta > y) + break; + y = topdelta + col->length + 1; + col = (column_t *)((UINT8 *)col + col->length + 4); } + + if (y < texture->height) + holey = true; // this texture is HOLEy! D: } // If the patch uses transparency, we have to save it this way. if (holey) { texture->holes = true; - blocksize = W_LumpLengthPwad(patch->wad, patch->lump); - block = Z_Calloc(blocksize, PU_LEVEL, &texturecache[texnum]); + blocksize = lumplength; + block = Z_Calloc(blocksize, PU_LEVEL, &texturecache[texnum]); // will change tag at end of this function M_Memcpy(block, realpatch, blocksize); texturememory += blocksize; @@ -365,7 +426,6 @@ UINT8 *R_GenerateTexture(size_t texnum) goto done; } - // Otherwise, do multipatch format. } @@ -387,7 +447,10 @@ UINT8 *R_GenerateTexture(size_t texnum) // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); + wadnum = patch->wad; + lumpnum = patch->lump; + pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_LEVEL); + lumplength = W_LumpLengthPwad(wadnum, lumpnum); realpatch = (softwarepatch_t *)pdata; x1 = patch->originx; @@ -439,6 +502,7 @@ INT32 R_GetTextureNum(INT32 texnum) { if (texnum < 0 || texnum >= numtextures) return 0; + return texturetranslation[texnum]; } @@ -456,17 +520,12 @@ void R_CheckTextureCache(INT32 tex) static inline INT32 wrap_column(fixed_t tex, INT32 col) { - if (texturewidthmask[tex]) - col &= texturewidthmask[tex]; // set by load textures - else - { - const INT16 texwidth = textures[tex]->width; + INT32 width = texturewidth[tex]; - // Odd width texture, cannot just mask. - // Sometime gets colnum = -1 or = width, even without tiling. - // Test LostCiv, Map 20, crates. - col = ((col % texwidth) + texwidth) % texwidth; - } + if (width & (width - 1)) + col = (UINT32)col % width; + else + col &= (width - 1); return col; } @@ -516,7 +575,6 @@ static INT32 Rloadtextures (INT32 i, INT32 w) { UINT16 j, numlumps = 0; - INT32 k; UINT16 texstart, texend, texturesLumpPos; softwarepatch_t *patchlump; texpatch_t *patch; @@ -568,8 +626,10 @@ Rloadtextures (INT32 i, INT32 w) // Set texture properties. M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name)); texture->hash = quickncasehash(texture->name, 8); + texture->width = SHORT(patchlump->width); texture->height = SHORT(patchlump->height); + texture->type = TEXTURETYPE_SINGLEPATCH; texture->patchcount = 1; texture->holes = false; @@ -583,25 +643,7 @@ Rloadtextures (INT32 i, INT32 w) Z_Free(patchlump); - // determine width power of 2 -#if 1 - // [WDJ] only need to determine if exact power of 2. - k = 1; - while (k < texture->width) - k<<=1; -#else - // Largest power of 2 that fits within width. - k = 1; - while (k << 1 <= texture->width) - k <<= 1; -#endif - if (k != texture->width) - { - // Odd width - k = 1; // make texturewidthmask = 0 - } - - texturewidthmask[i] = k - 1; + texturewidth[i] = texture->width; textureheight[i] = texture->height << FRACBITS; i++; } @@ -709,7 +751,7 @@ static void R_AllocateTextures(INT32 add) // Allocate texture referencing cache. recallocuser(&texturecache, oldsize, newsize); // Allocate texture width table. - recallocuser(&texturewidthmask, oldsize, newsize); + recallocuser(&texturewidth, oldsize, newsize); // Allocate texture height table. recallocuser(&textureheight, oldsize, newsize); // Create translation table for global animation. @@ -1181,7 +1223,7 @@ void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *texindex) newTexture = R_ParseTexture(true); // Store the new texture textures[*texindex] = newTexture; - texturewidthmask[*texindex] = newTexture->width - 1; + texturewidth[*texindex] = newTexture->width; textureheight[*texindex] = newTexture->height << FRACBITS; // Increment i back in R_LoadTextures() (*texindex)++; From f5b60c3f36af7c9ac1c31cfff1638ca3739ab8e7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 03:10:28 +0200 Subject: [PATCH 05/25] port "Use separate table for maskedtexturecol" from: https://git.do.srb2.org/STJr/SRB2/-/commit/97311dc5b00ab232a6e898c085c20d2f6bdbfa3b ~~cherry-picking this would be horrendous sry~~ --- src/r_defs.h | 4 +- src/r_main.cpp | 2 + src/r_plane.cpp | 8 +- src/r_plane.h | 2 - src/r_segs.cpp | 418 ++++++++++++++++++++++++++--------------------- src/r_segs.h | 1 + src/r_things.cpp | 4 +- 7 files changed, 244 insertions(+), 195 deletions(-) diff --git a/src/r_defs.h b/src/r_defs.h index 3d49b70a8..5f9a0d41a 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -615,12 +615,12 @@ typedef struct drawseg_s // Pointers to lists for sprite clipping, all three adjusted so [x1] is first value. INT16 *sprtopclip; INT16 *sprbottomclip; - INT16 *maskedtexturecol; + fixed_t *maskedtexturecol; struct visplane_s *ffloorplanes[MAXFFLOORS]; INT32 numffloorplanes; struct ffloor_s *thicksides[MAXFFLOORS]; - INT16 *thicksidecol; + fixed_t *thicksidecol; INT32 numthicksides; fixed_t *frontscale; diff --git a/src/r_main.cpp b/src/r_main.cpp index ee5fcd0f8..08f1e68a1 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1400,6 +1400,7 @@ void R_RenderPlayerView(player_t *player) R_ClearClipSegs(); R_ClearDrawSegs(); + R_ClearSegTables(); R_ClearPlanes(); R_ClearSprites(); @@ -1434,6 +1435,7 @@ void R_RenderPlayerView(player_t *player) R_ClearClipSegs(); } R_ClearDrawSegs(); + R_ClearSegTables(); R_ClearSprites(); // check for new console commands. diff --git a/src/r_plane.cpp b/src/r_plane.cpp index d4b718123..e76b0374a 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -60,10 +60,6 @@ INT32 numffloors; #define visplane_hash(picnum,lightlevel,height) \ ((unsigned)((picnum)*3+(lightlevel)+(height)*7) & VISPLANEHASHMASK) -//SoM: 3/23/2000: Use boom opening limit removal -size_t maxopenings; -INT16 *openings, *lastopening; /// \todo free leak - // // Clip values are the solid pixel bounding the range. // floorclip starts out SCREENHEIGHT @@ -339,13 +335,13 @@ void R_ClearPlanes(void) R_ClearFFloorClips(); for (i = 0; i < MAXVISPLANES; i++) + { for (*freehead = visplanes[i], visplanes[i] = NULL; freehead && *freehead ;) { freehead = &(*freehead)->next; } - - lastopening = openings; + } // left to right mapping angle = (viewangle-ANGLE_90)>>ANGLETOFINESHIFT; diff --git a/src/r_plane.h b/src/r_plane.h index d3b22ea30..c76f9d6c0 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -67,8 +67,6 @@ extern visplane_t *floorplane; extern visplane_t *ceilingplane; // Visplane related. -extern INT16 *lastopening, *openings; -extern size_t maxopenings; extern INT16 *floorclip, *ceilingclip; extern fixed_t *frontscale, *yslopetab; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 70740eb5b..bedec68ab 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -78,9 +78,21 @@ static fixed_t topfrac, topstep; static fixed_t bottomfrac, bottomstep; static lighttable_t **walllights; -static INT16 *maskedtexturecol; +static fixed_t *maskedtexturecol; static fixed_t *maskedtextureheight = NULL; +static size_t numopenings; +static INT16 *openings, *lastopening; + +static size_t texturecolumntablesize; +static fixed_t *texturecolumntable, *curtexturecolumntable; + +void R_ClearSegTables(void) +{ + lastopening = openings; + curtexturecolumntable = texturecolumntable; +} + // ========================================================================== // R_RenderMaskedSegRange // ========================================================================== @@ -306,141 +318,137 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 else dc->texturemid -= (textureheight[texnum])*times; - const INT16 colnum = maskedtexturecol[dc->x]; + // Check for overflows first + if (R_OverflowTest(dc)) + { + // Eh, no, go away, don't waste our time + if (dc->numlights) + { + for (i = 0; i < dc->numlights; i++) + { + rlight = &dc->lightlist[i]; + rlight->height += rlight->heightstep; + } + } + + spryscale += rw_scalestep; + continue; + } // calculate lighting - if (colnum != INT16_MAX) + if (dc->numlights) { - // Check for overflows first - if (R_OverflowTest(dc)) + lighttable_t **xwalllights; + + sprbotscreen = INT32_MAX; + sprtopscreen = windowtop = (centeryfrac - FixedMul(dc->texturemid, spryscale)); + + realbot = windowbottom = FixedMul(textureheight[texnum], spryscale) + sprtopscreen; + dc->iscale = 0xffffffffu / (unsigned)spryscale; + + // draw the texture + col = (column_t *)((UINT8 *)R_GetColumn(texnum, (maskedtexturecol[dc->x] >> FRACBITS)) - 3); + + auto set_light_vars = [&](INT32 k) { - // Eh, no, go away, don't waste our time - if (dc->numlights) + rlight = &dc->lightlist[k]; + + lightnum = rlight->lightnum; + + if (lightnum < 0) + xwalllights = scalelight[0]; + else if (lightnum >= LIGHTLEVELS) + xwalllights = scalelight[LIGHTLEVELS-1]; + else + xwalllights = scalelight[lightnum]; + + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; + + if (pindex >= MAXLIGHTSCALE) + pindex = MAXLIGHTSCALE - 1; + + if (rlight->extra_colormap) + rlight->rcolormap = rlight->extra_colormap->colormap + (xwalllights[pindex] - colormaps); + else + rlight->rcolormap = xwalllights[pindex]; + }; + + auto set_colormap_below_light = [&] + { + dc->colormap = rlight->rcolormap; + if (encoremap && !(ldef->flags & ML_TFERLINE)) + dc->colormap += COLORMAP_REMAPOFFSET; + }; + + // Use the base sector's light level above the first FOF. + // You can imagine it as the sky casting its light on top of the highest FOF. + set_light_vars(0); + set_colormap_below_light(); + + for (i = 0; i < dc->numlights; i++) + { + if ((dc->lightlist[i].flags & FF_NOSHADE)) + continue; + + set_light_vars(i); + + height = rlight->height; + rlight->height += rlight->heightstep; + + if (height <= windowtop) { - for (i = 0; i < dc->numlights; i++) + set_colormap_below_light(); + continue; + } + + windowbottom = height; + if (windowbottom >= realbot) + { + windowbottom = realbot; + colfunc_2s(dc, col); + for (i++; i < dc->numlights; i++) { rlight = &dc->lightlist[i]; rlight->height += rlight->heightstep; } + + continue; } - spryscale += rw_scalestep; - continue; - } + colfunc_2s(dc, col); - if (dc->numlights) - { - lighttable_t **xwalllights; - - sprbotscreen = INT32_MAX; - sprtopscreen = windowtop = (centeryfrac - FixedMul(dc->texturemid, spryscale)); - - realbot = windowbottom = FixedMul(textureheight[texnum], spryscale) + sprtopscreen; - dc->iscale = 0xffffffffu / (unsigned)spryscale; - - // draw the texture - col = (column_t *)((UINT8 *)R_GetColumn(texnum, colnum) - 3); - - auto set_light_vars = [&](INT32 k) - { - rlight = &dc->lightlist[k]; - - lightnum = rlight->lightnum; - - if (lightnum < 0) - xwalllights = scalelight[0]; - else if (lightnum >= LIGHTLEVELS) - xwalllights = scalelight[LIGHTLEVELS-1]; - else - xwalllights = scalelight[lightnum]; - - pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; - - if (pindex >= MAXLIGHTSCALE) - pindex = MAXLIGHTSCALE - 1; - - if (rlight->extra_colormap) - rlight->rcolormap = rlight->extra_colormap->colormap + (xwalllights[pindex] - colormaps); - else - rlight->rcolormap = xwalllights[pindex]; - }; - - auto set_colormap_below_light = [&] - { - dc->colormap = rlight->rcolormap; - if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc->colormap += COLORMAP_REMAPOFFSET; - }; - - // Use the base sector's light level above the first FOF. - // You can imagine it as the sky casting its light on top of the highest FOF. - set_light_vars(0); + windowtop = windowbottom + 1; set_colormap_below_light(); - - for (i = 0; i < dc->numlights; i++) - { - if ((dc->lightlist[i].flags & FF_NOSHADE)) - continue; - - set_light_vars(i); - - height = rlight->height; - rlight->height += rlight->heightstep; - - if (height <= windowtop) - { - set_colormap_below_light(); - continue; - } - - windowbottom = height; - if (windowbottom >= realbot) - { - windowbottom = realbot; - colfunc_2s(dc, col); - for (i++; i < dc->numlights; i++) - { - rlight = &dc->lightlist[i]; - rlight->height += rlight->heightstep; - } - - continue; - } - colfunc_2s(dc, col); - - windowtop = windowbottom + 1; - set_colormap_below_light(); - } - windowbottom = realbot; - if (windowtop < windowbottom) - colfunc_2s(dc, col); - - spryscale += rw_scalestep; - continue; } + windowbottom = realbot; + if (windowtop < windowbottom) + colfunc_2s(dc, col); - // calculate lighting - pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; - - if (pindex >= MAXLIGHTSCALE) - pindex = MAXLIGHTSCALE - 1; - - dc->colormap = walllights[pindex]; - if (encoremap && !(ldef->flags & ML_TFERLINE)) - dc->colormap += COLORMAP_REMAPOFFSET; - - if (frontsector->extra_colormap) - dc->colormap = frontsector->extra_colormap->colormap + (dc->colormap - colormaps); - - sprtopscreen = centeryfrac - FixedMul(dc->texturemid, spryscale); - dc->iscale = 0xffffffffu / (unsigned)spryscale; - - // draw the texture - col = (column_t *)((UINT8 *)R_GetColumn(texnum, colnum) - 3); - - colfunc_2s(dc, col); + spryscale += rw_scalestep; + continue; } + // calculate lighting + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; + + if (pindex >= MAXLIGHTSCALE) + pindex = MAXLIGHTSCALE - 1; + + dc->colormap = walllights[pindex]; + if (encoremap && !(ldef->flags & ML_TFERLINE)) + dc->colormap += COLORMAP_REMAPOFFSET; + + if (frontsector->extra_colormap) + dc->colormap = frontsector->extra_colormap->colormap + (dc->colormap - colormaps); + + sprtopscreen = centeryfrac - FixedMul(dc->texturemid, spryscale); + dc->iscale = 0xffffffffu / (unsigned)spryscale; + + // draw the texture + col = (column_t *)((UINT8 *)R_GetColumn(texnum, (maskedtexturecol[dc->x] >> FRACBITS)) - 3); + + colfunc_2s(dc, col); + spryscale += rw_scalestep; } } @@ -632,6 +640,7 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf void (*colfunc_2s) (drawcolumndata_t* dc, column_t *); + // Calculate light table. // Use different light tables // for horizontal / vertical / diagonal. Diagonal? @@ -899,14 +908,11 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf // draw the columns for (dc->x = x1; dc->x <= x2; dc->x++) { - if (maskedtexturecol[dc->x] == INT16_MAX) - continue; - // skew FOF walls if (ffloortextureslide) { if (oldx != -1) - dc->texturemid += FixedMul(ffloortextureslide, (maskedtexturecol[oldx]-maskedtexturecol[dc->x])<texturemid += FixedMul(ffloortextureslide, (maskedtexturecol[oldx]-maskedtexturecol[dc->x])); oldx = dc->x; } @@ -936,9 +942,6 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf continue; } - // Get data for the column - col = (column_t *)((UINT8 *)R_GetColumn(texnum, maskedtexturecol[dc->x]) - 3); - if (!fog) { dc->iscale = 0xffffffffu / (unsigned)spryscale; @@ -949,6 +952,9 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf R_SetColumnFunc(BASEDRAWFUNC); } + // Get data for the column + col = (column_t *)((UINT8 *)R_GetColumn(texnum, (maskedtexturecol[dc->x] >> FRACBITS)) - 3); + // SoM: New code does not rely on R_DrawColumnShadowed which // will (hopefully) put less strain on the stack. if (dc->numlights) @@ -1159,13 +1165,14 @@ static inline void R_ExpandPlaneY(visplane_t *pl, INT32 x, INT16 top, INT16 bott 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; dc->yl = yl; dc->yh = yh; dc->texturemid = mid; - dc->source = R_GetColumn(texture, texturecolumn); + dc->source = R_GetColumn(texture, itexturecolumn); dc->texheight = textureheight[texture] >> FRACBITS; dc->sourcelength = dc->texheight; - //R_SetColumnFunc(colfunctype); + R_SetColumnFunc(colfunctype); coldrawfunc_t* colfunccopy = colfunc; drawcolumndata_t dc_copy = *dc; if (remap) @@ -1346,7 +1353,7 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) // calculate texture offset angle = (rw_centerangle + xtoviewangle[rw_x])>>ANGLETOFINESHIFT; // Mask 4095 to guarantee this index is within bounds - texturecolumn = rw_offset-FixedMul(FINETANGENT(angle & 4095),rw_distance); + texturecolumn = rw_offset-FixedMul(FINETANGENT(angle & 4095), rw_distance); if (oldtexturecolumn != -1) { @@ -1357,8 +1364,6 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) } oldtexturecolumn = texturecolumn; - texturecolumn >>= FRACBITS; - // texturecolumn and lighting are independent of wall tiers if (segtextured) { @@ -1515,7 +1520,7 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) if (maskedtexture || numthicksides) { // save texturecol for backdrawing of masked mid texture - maskedtexturecol[rw_x] = (INT16)texturecolumn; + maskedtexturecol[rw_x] = texturecolumn; if (maskedtextureheight != NULL) { @@ -1616,7 +1621,7 @@ static void R_MarkSegBounds(void) if (markfloor) // no bottom wall floorclip[rw_x] = bottomclip; - if (floorclip[rw_x] <= ceilingclip[rw_x] + 1) + if ((markceiling || markfloor) && (floorclip[rw_x] <= ceilingclip[rw_x] + 1)) { solidcol[rw_x] = 1; didsolidcol = true; @@ -1672,6 +1677,78 @@ void R_AllocSegMemory(void) } } + +//SoM: Code to remove limits on openings. +static void R_AllocClippingTables(size_t range) +{ + size_t pos = lastopening - openings; + size_t need = range * 2; // for both sprtopclip and sprbottomclip + + if (pos + need < numopenings) + return; + + INT16 *oldopenings = openings; + INT16 *oldlast = lastopening; + + if (numopenings == 0) + numopenings = 16384; + + numopenings += need; + openings = static_cast(Z_Realloc(openings, numopenings * sizeof (*openings), PU_STATIC, NULL)); + lastopening = openings + pos; + + if (!oldopenings) + return; + + // borrowed fix from *cough* zdoom *cough* + // [RH] We also need to adjust the openings pointers that + // were already stored in drawsegs. + for (drawseg_t *ds = drawsegs; ds < ds_p; ds++) + { + // Check if it's in range of the openings +#define CHECK(which) \ + if (which + ds->x1 >= oldopenings && which + ds->x1 <= oldlast) \ + which = (which - oldopenings) + openings + CHECK(ds->sprtopclip); + CHECK(ds->sprbottomclip); +#undef CHECK + } +} + +static void R_AllocTextureColumnTables(size_t range) +{ + size_t pos = curtexturecolumntable - texturecolumntable; + + // For both tables, we reserve exactly an amount of memory that's equivalent to + // how many columns the seg will take on the entire screen (think about it) + if (pos + range < texturecolumntablesize) + return; + + fixed_t *oldtable = texturecolumntable; + fixed_t *oldlast = curtexturecolumntable; + + if (texturecolumntablesize == 0) + texturecolumntablesize = 16384; + + texturecolumntablesize += range; + texturecolumntable = static_cast(Z_Realloc(texturecolumntable, texturecolumntablesize * sizeof (*texturecolumntable), PU_STATIC, NULL)); + curtexturecolumntable = texturecolumntable + pos; + + if (!oldtable) + return; + + for (drawseg_t *ds = drawsegs; ds < ds_p; ds++) + { + // Check if it's in range of the tables +#define CHECK(which) \ + if (which + ds->x1 >= oldtable && which + ds->x1 <= oldlast) \ + which = (which - oldtable) + texturecolumntable + CHECK(ds->maskedtexturecol); + CHECK(ds->thicksidecol); +#undef CHECK + } +} + // // R_StoreWallRange // A wall segment will be drawn @@ -1745,41 +1822,6 @@ void R_StoreWallRange(INT32 start, INT32 stop) ds_p->curline = curline; rw_stopx = stop+1; - //SoM: Code to remove limits on openings. - { - size_t pos = lastopening - openings; - size_t need = (rw_stopx - start)*4 + pos; - - if (need > maxopenings) - { - drawseg_t *ds; //needed for fix from *cough* zdoom *cough* - INT16 *oldopenings = openings; - INT16 *oldlast = lastopening; - - do - maxopenings = maxopenings ? maxopenings*2 : 16384; - while (need > maxopenings); - openings = static_cast(Z_Realloc(openings, maxopenings * sizeof (*openings), PU_STATIC, NULL)); - lastopening = openings + pos; - - if (oldopenings == NULL) - return; - - // borrowed fix from *cough* zdoom *cough* - // [RH] We also need to adjust the openings pointers that - // were already stored in drawsegs. - for (ds = drawsegs; ds < ds_p; ds++) - { -#define ADJUST(p) if (ds->p + ds->x1 >= oldopenings && ds->p + ds->x1 <= oldlast) ds->p = (ds->p - oldopenings) + openings; - ADJUST(maskedtexturecol); - ADJUST(sprtopclip); - ADJUST(sprbottomclip); - ADJUST(thicksidecol); -#undef ADJUST - } - } - } // end of code to remove limits on openings - // calculate scale at both ends and step ds_p->scale1 = rw_scale = R_ScaleFromGlobalAngle(viewangle + xtoviewangle[start]); @@ -2160,6 +2202,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) rw_toptexturemid += sidedef->rowoffset; rw_bottomtexturemid += sidedef->rowoffset; + R_AllocTextureColumnTables(rw_stopx - start); + // allocate space for masked texture tables if (frontsector && backsector && (frontsector->tag != backsector->tag) && (backsector->ffloors || frontsector->ffloors)) { @@ -2173,8 +2217,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) maskedtexture = true; - ds_p->thicksidecol = maskedtexturecol = lastopening - rw_x; - lastopening += rw_stopx - rw_x; + ds_p->thicksidecol = maskedtexturecol = curtexturecolumntable - rw_x; + curtexturecolumntable += rw_stopx - rw_x; lowcut = std::max(worldbottom, worldlow) + viewz; highcut = std::min(worldtop, worldhigh) + viewz; @@ -2356,10 +2400,11 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) { // masked midtexture + if (!ds_p->thicksidecol) { - ds_p->maskedtexturecol = maskedtexturecol = lastopening - rw_x; - lastopening += rw_stopx - rw_x; + ds_p->maskedtexturecol = maskedtexturecol = curtexturecolumntable - rw_x; + curtexturecolumntable += rw_stopx - rw_x; } else ds_p->maskedtexturecol = ds_p->thicksidecol; @@ -2939,18 +2984,23 @@ void R_StoreWallRange(INT32 start, INT32 stop) } // save sprite clipping info - if (((ds_p->silhouette & SIL_TOP) || maskedtexture) && !ds_p->sprtopclip) + if (maskedtexture || (ds_p->silhouette & (SIL_TOP | SIL_BOTTOM))) { - M_Memcpy(lastopening, ceilingclip+start, 2*(rw_stopx - start)); - ds_p->sprtopclip = lastopening - start; - lastopening += rw_stopx - start; - } + R_AllocClippingTables(rw_stopx - start); - if (((ds_p->silhouette & SIL_BOTTOM) || maskedtexture) && !ds_p->sprbottomclip) - { - M_Memcpy(lastopening, floorclip + start, 2*(rw_stopx-start)); - ds_p->sprbottomclip = lastopening - start; - lastopening += rw_stopx - start; + if (((ds_p->silhouette & SIL_TOP) || maskedtexture) && !ds_p->sprtopclip) + { + M_Memcpy(lastopening, ceilingclip + start, 2*(rw_stopx - start)); + ds_p->sprtopclip = lastopening - start; + lastopening += rw_stopx - start; + } + + if (((ds_p->silhouette & SIL_BOTTOM) || maskedtexture) && !ds_p->sprbottomclip) + { + M_Memcpy(lastopening, floorclip + start, 2*(rw_stopx - start)); + ds_p->sprbottomclip = lastopening - start; + lastopening += rw_stopx - start; + } } if (maskedtexture) @@ -2958,13 +3008,13 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (!(ds_p->silhouette & SIL_TOP)) { ds_p->silhouette |= SIL_TOP; - ds_p->tsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MIN: INT32_MAX; + ds_p->tsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MIN : INT32_MAX; } if (!(ds_p->silhouette & SIL_BOTTOM)) { ds_p->silhouette |= SIL_BOTTOM; - ds_p->bsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MAX: INT32_MIN; + ds_p->bsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MAX : INT32_MIN; } } diff --git a/src/r_segs.h b/src/r_segs.h index 27dbbe54f..c40fcd331 100644 --- a/src/r_segs.h +++ b/src/r_segs.h @@ -25,6 +25,7 @@ extern "C" { void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2); void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pffloor); void R_StoreWallRange(INT32 start, INT32 stop); +void R_ClearSegTables(void); void R_AllocSegMemory(void); diff --git a/src/r_things.cpp b/src/r_things.cpp index 7f1d5af54..8229369a7 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2249,11 +2249,13 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps } ds->curline->polyseg->visplane = NULL; } + if (ds->maskedtexturecol) { entry = R_CreateDrawNode(head); entry->seg = ds; } + if (ds->numffloorplanes) { for (i = 0; i < ds->numffloorplanes; i++) @@ -3028,7 +3030,7 @@ static void R_DrawMaskedList(drawnode_t* head) else if (r2->seg && r2->seg->maskedtexturecol != NULL) { next = r2->prev; - R_RenderMaskedSegRange( r2->seg, r2->seg->x1, r2->seg->x2); + R_RenderMaskedSegRange(r2->seg, r2->seg->x1, r2->seg->x2); r2->seg->maskedtexturecol = NULL; R_DoneWithNode(r2); r2 = next; From 1d0fedddfd6e280db0a2f4f1de7ecbceffee41be Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 04:05:45 +0200 Subject: [PATCH 06/25] add bounds check to R_GetLinedefTransTable --- src/r_segs.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index bedec68ab..e5a542c72 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -152,7 +152,18 @@ static void R_Render2sidedMultiPatchColumn(drawcolumndata_t* dc, column_t *colum transnum_t R_GetLinedefTransTable(fixed_t alpha) { - return static_cast((20*(FRACUNIT - alpha - 1) + FRACUNIT) >> (FRACBITS+1)); + if (alpha >= FRACUNIT) + { + return static_cast(0); + } + else if (alpha <= 0) + { + return NUMTRANSMAPS; + } + else + { + return static_cast((20*(FRACUNIT - alpha - 1) + FRACUNIT) >> (FRACBITS+1)); + } } static inline boolean R_OverflowTest(drawcolumndata_t* dc) @@ -1916,8 +1927,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) numbackffloors = 0; - for (i = 0; i < MAXFFLOORS; i++) - ds_p->thicksides[i] = NULL; + memset(ds_p->thicksides, 0, MAXFFLOORS * sizeof(*ds_p->thicksides)); if (numffloors) { From 90ff1c4fc02b7242be8a0503e112768bd9bd53d2 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 04:57:18 +0200 Subject: [PATCH 07/25] small fixups for r_segs --- src/r_segs.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index e5a542c72..e6a603192 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -196,7 +196,7 @@ static void R_RenderMaskedSegLoop(drawcolumndata_t* dc, drawseg_t *drawseg, INT3 ldef = curline->linedef; - range = std::max(drawseg->x2-drawseg->x1, 1); + range = std::max(drawseg->x2-drawseg->x1, 1); // Setup lighting based on the presence/lack-of 3D floors. dc->numlights = 0; @@ -694,7 +694,7 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf fog = true; } - range = std::max(drawseg->x2-drawseg->x1, 1); + range = std::max(drawseg->x2-drawseg->x1, 1); //SoM: Moved these up here so they are available for my lightlist calculations rw_scalestep = drawseg->scalestep; spryscale = drawseg->scale1 + (x1 - drawseg->x1)*rw_scalestep; @@ -1679,10 +1679,10 @@ void R_AllocSegMemory(void) fixed_t *frontscale_p = frontscaletable; fixed_t *maskedheight_p = maskedheighttable; - for (drawseg_t *ds = drawsegs; ds < lastseg; ds++) + for (drawseg_t *drawseg = drawsegs; drawseg < lastseg; drawseg++) { - ds->frontscale = frontscale_p; - ds->maskedtextureheight = maskedheight_p; + drawseg->frontscale = frontscale_p; + drawseg->maskedtextureheight = maskedheight_p; frontscale_p += viewwidth; maskedheight_p += viewwidth; } @@ -1708,20 +1708,20 @@ static void R_AllocClippingTables(size_t range) openings = static_cast(Z_Realloc(openings, numopenings * sizeof (*openings), PU_STATIC, NULL)); lastopening = openings + pos; - if (!oldopenings) + if (oldopenings == NULL) return; // borrowed fix from *cough* zdoom *cough* // [RH] We also need to adjust the openings pointers that // were already stored in drawsegs. - for (drawseg_t *ds = drawsegs; ds < ds_p; ds++) + for (drawseg_t *drawseg = drawsegs; drawseg < ds_p; drawseg++) { // Check if it's in range of the openings #define CHECK(which) \ - if (which + ds->x1 >= oldopenings && which + ds->x1 <= oldlast) \ + if (which + drawseg->x1 >= oldopenings && which + drawseg->x1 <= oldlast) \ which = (which - oldopenings) + openings - CHECK(ds->sprtopclip); - CHECK(ds->sprbottomclip); + CHECK(drawseg->sprtopclip); + CHECK(drawseg->sprbottomclip); #undef CHECK } } @@ -1745,17 +1745,17 @@ static void R_AllocTextureColumnTables(size_t range) texturecolumntable = static_cast(Z_Realloc(texturecolumntable, texturecolumntablesize * sizeof (*texturecolumntable), PU_STATIC, NULL)); curtexturecolumntable = texturecolumntable + pos; - if (!oldtable) + if (oldtable == NULL) return; - for (drawseg_t *ds = drawsegs; ds < ds_p; ds++) + for (drawseg_t *drawseg = drawsegs; drawseg < ds_p; drawseg++) { // Check if it's in range of the tables #define CHECK(which) \ - if (which + ds->x1 >= oldtable && which + ds->x1 <= oldlast) \ + if (which + drawseg->x1 >= oldtable && which + drawseg->x1 <= oldlast) \ which = (which - oldtable) + texturecolumntable - CHECK(ds->maskedtexturecol); - CHECK(ds->thicksidecol); + CHECK(drawseg->maskedtexturecol); + CHECK(drawseg->thicksidecol); #undef CHECK } } @@ -1778,6 +1778,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) INT32 range; vertex_t segleft, segright; fixed_t ceilingfrontslide, floorfrontslide, ceilingbackslide, floorbackslide; + const INT32 twosidedmidtexture = R_GetTextureNum(curline->sidedef->midtexture); drawcolumndata_t dc = {}; maskedtextureheight = NULL; @@ -2407,7 +2408,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) ds_p->numthicksides = numthicksides = i; } - if (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) + if (twosidedmidtexture) { // masked midtexture @@ -3018,13 +3019,13 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (!(ds_p->silhouette & SIL_TOP)) { ds_p->silhouette |= SIL_TOP; - ds_p->tsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MIN : INT32_MAX; + ds_p->tsilheight = (twosidedmidtexture) ? INT32_MIN : INT32_MAX; } if (!(ds_p->silhouette & SIL_BOTTOM)) { ds_p->silhouette |= SIL_BOTTOM; - ds_p->bsilheight = (sidedef->midtexture > 0 && sidedef->midtexture < numtextures) ? INT32_MAX : INT32_MIN; + ds_p->bsilheight = (twosidedmidtexture) ? INT32_MAX : INT32_MIN; } } From c1660757541440588beb1af829a6a41c4523125a Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Tue, 1 Aug 2023 19:04:47 -0300 Subject: [PATCH 08/25] Don't generate textures in R_GetColumn --- src/r_data.c | 7 ------- src/r_plane.cpp | 12 ++++-------- src/r_segs.cpp | 7 +++++++ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index c6ffd6945..031be761b 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -535,13 +535,6 @@ static inline INT32 wrap_column(fixed_t tex, INT32 col) // UINT8 *R_GetColumn(fixed_t tex, INT32 col) { - if (!texturecache[tex]) - { - // This must be here because cache can be freed by other operations. - // To prevent must lock individual texture cache on every draw. - R_GenerateTexture(tex); - } - return texturecache[tex] + LONG(texturecolumnofs[tex][wrap_column(tex, col)]); } diff --git a/src/r_plane.cpp b/src/r_plane.cpp index e76b0374a..475e8a44d 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -785,6 +785,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?) // (that is, unless we'll need to switch drawers in future for some reason) @@ -803,16 +804,13 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b dc.colormap += COLORMAP_REMAPOFFSET; dc.texturemid = skytexturemid; - dc.texheight = textureheight[skytexture] >>FRACBITS; + dc.texheight = textureheight[texture] >>FRACBITS; dc.sourcelength = dc.texheight; x = pl->minx; // Precache the texture so we don't corrupt the zoned heap off-main thread - if (!texturecache[texturetranslation[skytexture]]) - { - R_GenerateTexture(texturetranslation[skytexture]); - } + R_CheckTextureCache(texture); #ifdef HAVE_THREADS while (x <= pl->maxx) @@ -837,9 +835,7 @@ static void R_DrawSkyPlane(visplane_t *pl, void(*colfunc2)(drawcolumndata_t*), b dc.iscale = FixedMul(skyscale, FINECOSINE(xtoviewangle[x + i]>>ANGLETOFINESHIFT)); dc.x = x + i; - dc.source = - R_GetColumn(texturetranslation[skytexture], - -angle); // get negative of angle for each column to display sky correct way round! --Monster Iestyn 27/01/18 + 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); } diff --git a/src/r_segs.cpp b/src/r_segs.cpp index e6a603192..e62d1e4aa 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1209,6 +1209,13 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) INT32 bottom; INT32 i; + if (midtexture) + R_CheckTextureCache(midtexture); + if (toptexture) + R_CheckTextureCache(toptexture); + if (bottomtexture) + R_CheckTextureCache(bottomtexture); + // Loop over width for (; rw_x < rw_stopx; rw_x++) { From 0c56755e0958cbf486314418a9ae0cdde70f1892 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 16:08:04 +0200 Subject: [PATCH 09/25] fix R_MarkSegBounds --- src/r_segs.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index e62d1e4aa..25cf5157d 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1221,8 +1221,9 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) { // mark floor / ceiling areas yl = (topfrac+HEIGHTUNIT-1)>>HEIGHTBITS; + yh = bottomfrac>>HEIGHTBITS; - // no space above wall? + // Mark ceiling top = ceilingclip[rw_x]+1; // no space above wall? @@ -1239,10 +1240,10 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) } } - yh = bottomfrac>>HEIGHTBITS; - + // Mark floor bottom = floorclip[rw_x]-1; + // no space below floor? if (yh > bottom) yh = bottom; @@ -1584,7 +1585,7 @@ static void R_RenderSegLoop(drawcolumndata_t* dc) static void R_MarkSegBounds(void) { - INT32 yl, yh; + INT32 yl, yh; INT32 top, bottom; INT16 topclip, bottomclip; @@ -1593,8 +1594,9 @@ static void R_MarkSegBounds(void) { // mark floor / ceiling areas yl = (topfrac+HEIGHTUNIT-1)>>HEIGHTBITS; + yh = bottomfrac>>HEIGHTBITS; - // no space above wall? + // Mark ceiling top = ceilingclip[rw_x]+1; // no space above wall? @@ -1611,10 +1613,10 @@ static void R_MarkSegBounds(void) } } - yh = bottomfrac>>HEIGHTBITS; - + // Mark floor bottom = floorclip[rw_x]-1; + // no space below floor? if (yh > bottom) yh = bottom; @@ -1639,12 +1641,6 @@ static void R_MarkSegBounds(void) if (markfloor) // no bottom wall floorclip[rw_x] = bottomclip; - if ((markceiling || markfloor) && (floorclip[rw_x] <= ceilingclip[rw_x] + 1)) - { - solidcol[rw_x] = 1; - didsolidcol = true; - } - rw_scale += rw_scalestep; topfrac += topstep; bottomfrac += bottomstep; From 953d9d15d6a73b73c6fc124175423b300733e8c8 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 3 Feb 2024 00:53:06 -0800 Subject: [PATCH 10/25] Clear g_dc each frame I was running into a memcpy of overlapping memory regions in R_RenderMaskedSegRange. - This is because of the reallocation of lightlists, which uses Z_Frame_Alloc. - The memory pool that Z_Frame_Alloc draws from is cleared each frame. - g_dc was not cleared though, so when the lightlists were reallocated, it'd try to copy from invalidated pointers. - Access to invalid pointers within the memory pool does not cause a segfault directly (because the memory pool is allocated once). However, a memcpy involving such an invalid pointer leads to overlap, which may cause memory corruption. --- src/d_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/d_main.c b/src/d_main.c index 39951f70c..e2bf44008 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -774,6 +774,7 @@ void D_SRB2Loop(void) precise_t capbudget; precise_t enterprecise = I_GetPreciseTime(); + memset(&g_dc, 0, sizeof(g_dc)); Z_Frame_Reset(); // Casting the return value of a function is bad practice (apparently) From 6be5478fa84e37b3adc39270b8e65440a95d9c80 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 16:55:56 +0200 Subject: [PATCH 11/25] dont free levelstate in D_ClearState Titledemos be damned! --- src/d_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index e2bf44008..fd3e93649 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1027,7 +1027,7 @@ void D_ClearState(void) S_StopSounds(); S_ResetKeepAndSpecialMus(); // just in case - P_FreeLevelState(); + //P_FreeLevelState(); G_SetGamestate(GS_NULL); wipegamestate = GS_NULL; From 48722ef59131086574dbd40502c7c8bea822aa08 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 17:14:31 +0200 Subject: [PATCH 12/25] fix oob access in CV_AddValue and M_CanShowLevelInList lets hope this doesent break anything Zzz.... --- src/command.c | 4 ++-- src/m_menu.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/command.c b/src/command.c index 292c51861..341e57ce5 100644 --- a/src/command.c +++ b/src/command.c @@ -1771,7 +1771,7 @@ void CV_AddValue(consvar_t *var, INT32 increment) newvalue = var->value - 1; do { - if(increment > 0) // Going up! + if (increment > 0) // Going up! { if (++newvalue == NUMMAPS) newvalue = -1; @@ -1785,7 +1785,7 @@ void CV_AddValue(consvar_t *var, INT32 increment) if (newvalue == oldvalue) break; // don't loop forever if there's none of a certain gametype - if(!mapheaderinfo[newvalue]) + if (newvalue >= 0 && !mapheaderinfo[newvalue]) continue; // Don't allocate the header. That just makes memory usage skyrocket. } while (!M_CanShowLevelInList(newvalue, gt)); diff --git a/src/m_menu.c b/src/m_menu.c index af63de94f..95824c7dd 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2713,6 +2713,10 @@ static void M_PrepareLevelSelect(void) // boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) { + // invalid mapnum + if (mapnum < -1) + return false; + // Random map! if (mapnum == -1) return (gamestate != GS_TIMEATTACK && !modeattacking); @@ -7220,7 +7224,7 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) if (i == oldval) return; - if(!mapheaderinfo[i]) + if (i >= 0 && !mapheaderinfo[i]) continue; // Don't allocate the header. That just makes memory usage skyrocket. } while (!M_CanShowLevelInList(i, cv_newgametype.value)); @@ -7258,7 +7262,7 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) if (i == oldval) return; - if(!mapheaderinfo[i]) + if (i >= 0 && !mapheaderinfo[i]) continue; // Don't allocate the header. That just makes memory usage skyrocket. } while (!M_CanShowLevelInList(i, cv_newgametype.value)); From 79140b3bdcf20115f40b876fc57dc4675e390f77 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 17:37:58 +0200 Subject: [PATCH 13/25] fix oopsie in R_GenerateTexture --- src/r_data.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index 031be761b..5946ff336 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -241,11 +241,12 @@ static INT32 tidcachelen = 0; // R_DrawColumnInCache // Clip and draw a column from a patch into a cached post. // -static inline void R_DrawColumnInCache(column_t *patch, UINT8 *cache, INT32 originy, INT32 cacheheight) +static inline void R_DrawColumnInCache(column_t *patch, UINT8 *cache, texpatch_t *originPatch, INT32 cacheheight) { INT32 count, position; UINT8 *source; INT32 topdelta, prevdelta = -1; + INT32 originy = originPatch->originy; while (patch->topdelta != 0xff) { @@ -374,7 +375,7 @@ UINT8 *R_GenerateTexture(size_t texnum) return block; } - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); + pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; // Check the patch for holes. @@ -383,7 +384,7 @@ UINT8 *R_GenerateTexture(size_t texnum) colofs = (UINT8 *)realpatch->columnofs; - for (x = 0; x < texture->width; x++) + for (x = 0; x < texture->width && !holey; x++) { column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2])); @@ -483,7 +484,7 @@ UINT8 *R_GenerateTexture(size_t texnum) // generate column ofset lookup *(UINT32 *)&colofs[x<<2] = LONG((x * texture->height) + (texture->width*4)); - R_DrawColumnInCache(patchcol, block + LONG(*(UINT32 *)&colofs[x<<2]), patch->originy, texture->height); + R_DrawColumnInCache(patchcol, block + LONG(*(UINT32 *)&colofs[x<<2]), patch, texture->height); } } From f817676033a5234f2fe9b4b15ae690545f4637a9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 18:33:54 +0200 Subject: [PATCH 14/25] fix uninitialized "i" counter in R_StoreWallRange --- src/r_segs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 25cf5157d..c83b45593 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1775,7 +1775,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) angle_t distangle, offsetangle; boolean longboi; INT32 lightnum; - INT32 i, p; + INT32 i = 0, p; lightlist_t *light; r_lightlist_t *rlight; INT32 range; From 005af4362e76bbfad124beec4e96cd697bfa8093 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 20:08:20 +0200 Subject: [PATCH 15/25] remove unused W_LumpLenghtPwad call from R_GenerateTexture --- src/r_data.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index 5946ff336..ec866b79e 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -375,7 +375,7 @@ UINT8 *R_GenerateTexture(size_t texnum) return block; } - pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_LEVEL); + pdata = (UINT8*)W_CacheLumpNumPwad(wadnum, lumpnum, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; // Check the patch for holes. @@ -450,8 +450,7 @@ UINT8 *R_GenerateTexture(size_t texnum) { wadnum = patch->wad; lumpnum = patch->lump; - pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_LEVEL); - lumplength = W_LumpLengthPwad(wadnum, lumpnum); + pdata = (UINT8*)W_CacheLumpNumPwad(wadnum, lumpnum, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; x1 = patch->originx; From 3964d4e1880d92d256eee928f45a1353813ac091 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 5 Oct 2025 21:12:46 +0300 Subject: [PATCH 16/25] Always initialize all column offsets inside multi-patch textures --- src/r_data.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index ec866b79e..ab704675c 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -445,6 +445,12 @@ UINT8 *R_GenerateTexture(size_t texnum) // texture data after the lookup table blocktex = block + (texture->width*4); + for (x = 0; x < texture->width; ++x) + { + // generate column ofset lookup + *(UINT32 *)&colofs[x<<2] = LONG((x * texture->height) + (texture->width*4)); + } + // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { @@ -481,8 +487,6 @@ UINT8 *R_GenerateTexture(size_t texnum) { patchcol = (column_t *)((UINT8 *)realpatch + LONG(realpatch->columnofs[x-x1])); - // generate column ofset lookup - *(UINT32 *)&colofs[x<<2] = LONG((x * texture->height) + (texture->width*4)); R_DrawColumnInCache(patchcol, block + LONG(*(UINT32 *)&colofs[x<<2]), patch, texture->height); } } From 9e8ddd5f9eb922dabbee5975de6281f33113e704 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 5 Oct 2025 20:38:58 +0200 Subject: [PATCH 17/25] add a print to Joinable_OnChange also change the other cvar messages to CONS_NOTICE --- src/command.c | 19 +++++++++---------- src/d_clisrv.c | 3 +++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/command.c b/src/command.c index 341e57ce5..ee3b36247 100644 --- a/src/command.c +++ b/src/command.c @@ -1650,13 +1650,13 @@ static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth) UINT8 *p = buf; if (!(server || (IsPlayerAdmin(consoleplayer)))) { - CONS_Printf(M_GetText("Only the server or admin can change: %s %s\n"), var->name, var->string); + CONS_Alert(CONS_NOTICE, "Only the server or admin can change: %s %s\n", var->name, var->string); return; } if (var == &cv_kartencore && !M_SecretUnlocked(SECRET_ENCORE)) { - CONS_Printf(M_GetText("You haven't unlocked Encore Mode yet!\n")); + CONS_Alert(CONS_NOTICE, "You haven't unlocked Encore Mode yet!\n"); return; } @@ -1664,7 +1664,7 @@ static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth) { if (!stricmp(value, "Hard") || atoi(value) == 2) { - CONS_Printf(M_GetText("You haven't unlocked this yet!\n")); + CONS_Alert(CONS_NOTICE, "You haven't unlocked this yet!\n"); return; } } @@ -1681,14 +1681,13 @@ static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth) else Setvalue(var, value, stealth); } + else if ((var->flags & CV_NOTINNET) && netgame) + { + CONS_Alert(CONS_NOTICE, "This variable can't be changed while in netgame: %s %s\n", var->name, var->string); + return; + } else - if ((var->flags & CV_NOTINNET) && netgame) - { - CONS_Printf(M_GetText("This variable can't be changed while in netgame: %s %s\n"), var->name, var->string); - return; - } - else - Setvalue(var, value, stealth); + Setvalue(var, value, stealth); } /** Sets a value to a variable without calling its callback function. diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9c9d95322..a62ebde7c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4161,7 +4161,10 @@ static void Joinable_OnChange(void) UINT8 maxplayer; if (!server) + { + CONS_Alert(CONS_NOTICE, ("Only the server can change: %s %s\n"), cv_allownewplayer.name, cv_allownewplayer.string); return; + } #ifdef SATURNJOIN // disabling joins should also disable saturn joins unless its called with CV_StealthSet and vice versa to make life a bit easier From 0bbd8246cc9c9950e7087152df25235efd9ee052 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 15 Dec 2021 14:02:56 -0800 Subject: [PATCH 18/25] Read only header bytes when creating textures list R_LoadTextures was reading in the entirety of every texture lump, now it only reads the 8 byte PNG header. This saved more than 1 second for me (1.68 s -> 0.24 s). PNG still need to be read in entirely to check their dimensions; I didn't bother looking into optimizing it since we don't have many PNG textures right now. --- src/r_data.c | 10 ++++------ src/r_patch.h | 2 ++ src/r_things.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index ab704675c..6c999d1ae 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -573,9 +573,9 @@ Rloadtextures (INT32 i, INT32 w) { UINT16 j, numlumps = 0; UINT16 texstart, texend, texturesLumpPos; - softwarepatch_t *patchlump; texpatch_t *patch; texture_t *texture; + softwarepatch_t patchlump; // Get the lump numbers for the markers in the WAD, if they exist. if (W_FileHasFolders(wadfiles[w])) @@ -615,7 +615,7 @@ Rloadtextures (INT32 i, INT32 w) continue; // If it is then SKIP IT } - patchlump = (softwarepatch_t *)W_CacheLumpNumPwad(wadnum, lumpnum, PU_STATIC); + W_ReadLumpHeaderPwad(wadnum, lumpnum, &patchlump, PNG_HEADER_SIZE, 0); //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((wadnum, lumpnum), patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); @@ -624,8 +624,8 @@ Rloadtextures (INT32 i, INT32 w) M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name)); texture->hash = quickncasehash(texture->name, 8); - texture->width = SHORT(patchlump->width); - texture->height = SHORT(patchlump->height); + texture->width = SHORT(patchlump.width); + texture->height = SHORT(patchlump.height); texture->type = TEXTURETYPE_SINGLEPATCH; texture->patchcount = 1; @@ -638,8 +638,6 @@ Rloadtextures (INT32 i, INT32 w) patch->wad = wadnum; patch->lump = texstart + j; - Z_Free(patchlump); - texturewidth[i] = texture->width; textureheight[i] = texture->height << FRACBITS; i++; diff --git a/src/r_patch.h b/src/r_patch.h index 2dc9c2f4e..4d44b5416 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -36,6 +36,8 @@ typedef struct boolean available; } spriteinfo_t; +#define PNG_HEADER_SIZE (8) + // Patch functions patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest); void Patch_Free(patch_t *patch); diff --git a/src/r_things.cpp b/src/r_things.cpp index 8229369a7..4713bc50e 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -312,7 +312,7 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 // store sprite info in lookup tables //FIXME : numspritelumps do not duplicate sprite replacements - W_ReadLumpHeaderPwad(wadnum, l, &patch, (sizeof(INT16) *4), 0); + W_ReadLumpHeaderPwad(wadnum, l, &patch, PNG_HEADER_SIZE, 0); spritecachedinfo[numspritelumps].width = (INT32)(SHORT(patch.width))< Date: Mon, 6 Oct 2025 17:44:47 +0300 Subject: [PATCH 19/25] Don't I_Error in W_InitFileError, that causes dedicated servers to bootloop --- src/w_wad.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 4a993a7f4..1cfb3f616 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -45,6 +45,7 @@ #include "w_wad.h" #include "z_zone.h" #include "fastcmp.h" +#include "console.h" #include "g_game.h" // G_LoadGameData #include "d_main.h" @@ -760,11 +761,7 @@ static UINT16 W_InitFileError(const char *filename, boolean exitworthy) { if (exitworthy) { -#ifdef _DEBUG CONS_Error(va("%s was not found or not valid.\nCheck the log for more details.\n", filename)); -#else - I_Error("%s was not found or not valid.\nCheck the log for more details.\n", filename); -#endif } else CONS_Printf(M_GetText("Errors occurred while loading %s; not added.\n"), filename); From b3106d55d1c0dfaf1342ab6e97e0d5f379e36295 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Oct 2025 21:36:29 +0200 Subject: [PATCH 20/25] inline R_ThingLightLevel just points to thing->lightlevel field eitherway --- src/r_things.cpp | 7 ------- src/r_things.h | 7 +++++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index 4713bc50e..b41d44db1 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -94,13 +94,6 @@ static drawseg_xrange_item_t *drawsegs_xrange; static size_t drawsegs_xrange_size = 0; static INT32 drawsegs_xrange_count = 0; -INT32 R_ThingLightLevel(mobj_t* thing) -{ - INT32 lightlevel = thing->lightlevel; - - return lightlevel; -} - // // Sprite rotation 0 is facing the viewer, // rotation 1 is one angle turn CLOCKWISE around the axis. diff --git a/src/r_things.h b/src/r_things.h index 9cba7340d..2f9269c68 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -63,7 +63,10 @@ extern fixed_t windowtop; extern fixed_t windowbottom; extern INT32 lengthcol; -INT32 R_ThingLightLevel(mobj_t *thing); +FUNCINLINE static ATTRINLINE INT32 R_ThingLightLevel(mobj_t* thing) +{ + return (INT32)thing->lightlevel; +} fixed_t R_GetSpriteDirectionalLighting(angle_t angle); fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope); @@ -83,7 +86,7 @@ typedef struct { size_t drawsegs[2]; size_t vissprites[2]; - fixed_t viewx, viewy, viewz; /**< View z stored at the time of the BSP traversal for the view/portal. Masked sorting/drawing needs it. */ + fixed_t viewx, viewy, viewz; /**< View z stored at the time of the BSP traversal for the view/portal. Masked sorting/drawing needs it. */ sector_t* viewsector; } maskcount_t; From 2ec467f062d086e3aad93a9cc824bf6d0c6bea0f Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 8 Oct 2025 21:38:06 +0200 Subject: [PATCH 21/25] check with "__SIZEOF_POINTER__" --- src/r_things.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_things.h b/src/r_things.h index 2f9269c68..fd03a6611 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -23,10 +23,10 @@ extern "C" { // number of sprite lumps for spritewidth,offset,topoffset lookup tables // Fab: this is a hack : should allocate the lookup tables per sprite -#if defined(__x86_64__) || defined(__amd64__) || defined(__aarch64__) || defined(__arm64__) // only for 64bit (idk how else to proper check lmao) -#define MAXVISSPRITES 4096 -#else +#if __SIZEOF_POINTER__ < 8 #define MAXVISSPRITES 2048 // added 2-2-98 was 128 +#else +#define MAXVISSPRITES 4096 // only for 64bit #endif #define VISSPRITECHUNKBITS 6 // 2^6 = 64 sprites per chunk From ff80a34627d8bd1947e21b11f0107dcd90435cd6 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 9 Oct 2025 18:01:02 +0200 Subject: [PATCH 22/25] unnest fsp counter and ping display stuff --- src/hu_stuff.c | 159 ++++++++++++++++++++++++++----------------------- src/screen.c | 146 ++++++++++++++++++++++++++------------------- 2 files changed, 169 insertions(+), 136 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 0132659e4..6ca275aff 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2540,17 +2540,91 @@ Ping_conversion (UINT32 lag) // HU_drawPing // +static void HU_drawOldPing(INT32 x, INT32 y, UINT32 lag, INT32 flags, boolean gentleman) +{ + const INT32 measureid = cv_pingmeasurement.value ? 1 : 0; + + if (vid.width >= 640) // how sad, we're using a shit resolution. + { + if (measureid == 1) + { + V_DrawRightAlignedSmallString(x+12, y+13, V_ALLOWLOWERCASE|flags, va("%dms", Ping_conversion(lag))); + } + else if (measureid == 0) + { + V_DrawRightAlignedSmallString(x+12, y+13, flags, va("d%d", Ping_conversion(lag))); + } + } + + if (cv_pingicon.value) + { + UINT8 numbars = 0; // how many ping bars do we draw? + UINT8 barcolor = 31; // color we use for the bars (green, yellow, red or black) + SINT8 i = 0; + SINT8 yoffset = 6; + + switch (lag) + { + case 0 ... 1: + numbars = 3; + barcolor = 215; // Blue + break; + case 2 ... 3: + numbars = 3; + barcolor = 184; // Green + break; + case 4 ... 6: + numbars = 2; // Apparently ternaries w/ multiple statements don't look good in C so I decided against it. + barcolor = 103; // Yellow + break; + case 7 ... 9: + numbars = 1; + barcolor = 155; // Red + break; + default: // Brazil + numbars = 0; + barcolor = 31; // black + break; + } + + if (gentleman) + { + barcolor = 194; // make it purplish + // bars get indirectly set earlier + } + + for (i = 0; (i < 3); i++) // Draw the ping bar + { + V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-4, 2, 8-yoffset, 31|flags); + if (i < numbars) + V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-3, 1, 8-yoffset-1, barcolor|flags); + + yoffset -= 2; + } + } +} + +static void HU_drawKartPing(INT32 x, INT32 y, UINT32 lag, INT32 flags, boolean gentleman) +{ + const INT32 measureid = cv_pingmeasurement.value ? 1 : 0; + + if (measureid == 1) + V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + + if (cv_pingicon.value) + { + INT32 gfxnum = Ping_gfx_num(lag); // gfx to draw + V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); + } + + x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, Ping_conversion(lag), Ping_gfx_colormap(lag, gentleman)); + + if (measureid == 0) + V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); +} + void HU_drawPlayerPing(INT32 x, INT32 y, INT32 pnum, INT32 flags) { - INT32 measureid = cv_pingmeasurement.value ? 1 : 0; - INT32 gfxnum; // gfx to draw - - //SRB2/Kart v1.0 style - UINT8 numbars = 0; // how many ping bars do we draw? - UINT8 barcolor = 31; // color we use for the bars (green, yellow, red or black) - SINT8 i = 0; - SINT8 yoffset = 6; - UINT32 lag = playerpingtable[pnum]; const boolean gentleman = (cv_mindelay.value && (lag < (tic_t)simulated_lag)); @@ -2561,74 +2635,11 @@ void HU_drawPlayerPing(INT32 x, INT32 y, INT32 pnum, INT32 flags) if (cv_pingstyle.value == 0) // kart { - gfxnum = Ping_gfx_num(lag); - - if (measureid == 1) - V_DrawScaledPatch(x+11 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); - - if (cv_pingicon.value) - V_DrawScaledPatch(x+2, y, flags, pinggfx[gfxnum]); - - x = V_DrawPingNum(x + (measureid == 1 ? 11 - pingmeasure[measureid]->width : 10), y+9, flags, Ping_conversion(lag), Ping_gfx_colormap(lag, gentleman)); - - if (measureid == 0) - V_DrawScaledPatch(x+1 - pingmeasure[measureid]->width, y+9, flags, pingmeasure[measureid]); + HU_drawKartPing(x, y, lag, flags, gentleman); } else if (cv_pingstyle.value == 1) // old style ping { - if (vid.width >= 640) // how sad, we're using a shit resolution. - { - if (measureid == 1) - { - V_DrawRightAlignedSmallString(x+12, y+13, V_ALLOWLOWERCASE|flags, va("%dms", Ping_conversion(lag))); - } - else if (measureid == 0) - { - V_DrawRightAlignedSmallString(x+12, y+13, flags, va("d%d", Ping_conversion(lag))); - } - } - - if (cv_pingicon.value) - { - switch (lag) - { - case 0 ... 1: - numbars = 3; - barcolor = 215; // Blue - break; - case 2 ... 3: - numbars = 3; - barcolor = 184; // Green - break; - case 4 ... 6: - numbars = 2; // Apparently ternaries w/ multiple statements don't look good in C so I decided against it. - barcolor = 103; // Yellow - break; - case 7 ... 9: - numbars = 1; - barcolor = 155; // Red - break; - default: // Brazil - numbars = 0; - barcolor = 31; // black - break; - } - - if (gentleman) - { - barcolor = 194; // make it purplish - // bars get indirectly set earlier - } - - for (i = 0; (i < 3); i++) // Draw the ping bar - { - V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-4, 2, 8-yoffset, 31|flags); - if (i < numbars) - V_DrawFill(x+2 *(i-1)+7, y+8+yoffset-3, 1, 8-yoffset-1, barcolor|flags); - - yoffset -= 2; - } - } + HU_drawOldPing(x, y, lag, flags, gentleman); } } diff --git a/src/screen.c b/src/screen.c index 21ec0ed52..8d2782ab8 100644 --- a/src/screen.c +++ b/src/screen.c @@ -400,74 +400,97 @@ void SCR_CalculateFPS(void) #endif } +static void SCR_DrawOldTicRate(UINT32 cap, UINT32 benchmark, double fps, INT32 fpsflags) +{ + const char *fps_string; + INT32 ticcntcolor = 0; + + if (fps > (benchmark - 5)) + ticcntcolor = V_GREENMAP; + else if (fps < 20) + ticcntcolor = V_REDMAP; + + if (cap != 0) + fps_string = va("%d/%d\x82", (INT32)fps, cap); + else + fps_string = va("%d\x82", (INT32)fps); + + // draw "FPS" + if (cv_ticrate.value == 3) + V_DrawRightAlignedString(319, 181, V_YELLOWMAP|fpsflags, "FPS"); + + V_DrawRightAlignedString(319, 190, ticcntcolor|fpsflags, fps_string); +} + +static void SCR_DrawKartTicRate(UINT32 cap, UINT32 benchmark, double fps, INT32 fpsflags) +{ + UINT8 *ticcntcolor = NULL; + INT32 x = 318; + + // draw "FPS" + if (cv_ticrate.value == 1) + { + ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_YELLOW, GTC_CACHE); + V_DrawFixedPatch(306< (benchmark - 5)) + ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); + else if (fps < 20) + ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); + else + ticcntcolor = NULL; + + if (cap != 0) + { + UINT32 digits = 1; + UINT32 c2 = cap; + + while (c2 > 0) + { + c2 = c2 / 10; + digits++; + } + + // draw total frame: + V_DrawPingNum(x, 190, fpsflags, cap, ticcntcolor); + + x -= digits * 4; + + // draw "/" + V_DrawFixedPatch(x< (benchmark - 5)) - ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_MINT, GTC_CACHE); - else if (fps < 20) - ticcntcolor = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_RASPBERRY, GTC_CACHE); - - if (cap != 0) - { - UINT32 digits = 1; - UINT32 c2 = cap; - - while (c2 > 0) - { - c2 = c2 / 10; - digits++; - } - - // draw total frame: - V_DrawPingNum(x, 190, fpsflags, cap, ticcntcolor); - - x -= digits * 4; - - // draw "/" - V_DrawFixedPatch(x< (benchmark - 5)) - ticcntcolor2 = V_GREENMAP; - else if (fps < 20) - ticcntcolor2 = V_REDMAP; - - if (cap != 0) - fps_string = va("%d/%d\x82", (INT32)fps, cap); - else - fps_string = va("%d\x82", (INT32)fps); - - // draw "FPS" - if (cv_ticrate.value == 3) - V_DrawRightAlignedString(319, 181, V_YELLOWMAP|fpsflags, "FPS"); - - V_DrawRightAlignedString(319, 190, ticcntcolor2|fpsflags, fps_string); + case 1: // new kart counter + case 2: + SCR_DrawKartTicRate(cap, benchmark, fps, fpsflags); + break; + case 3: // kart v1.0/srb2 counter + case 4: + SCR_DrawOldTicRate(cap, benchmark, fps, fpsflags); + break; + default: + break; } } @@ -482,7 +505,6 @@ void SCR_DisplayLocalPing(void) if (cv_showping.value == 1 || (cv_showping.value == 2 && ping > servermaxping)) // only show 2 (warning) if our ping is at a bad level { INT32 dispy = (cv_ticrate.value == 1) ? 165 : ((cv_ticrate.value == 2 || cv_ticrate.value == 4) ? 172 : ((cv_ticrate.value == 3) ? 163 : 181)); // absolute buttpain - HU_drawPlayerPing(308, dispy, consoleplayer, pingflags); // consoleplayer's ping is everyone's ping in a splitnetgame :P } } From 3783e30a8ae54c394d385fb3ab60e258e5809939 Mon Sep 17 00:00:00 2001 From: K J Date: Wed, 13 Aug 2025 14:11:13 -0400 Subject: [PATCH 23/25] fix: multiple additional buffer overruns found by Zwip-Zwap_Zapony --- src/android/i_system.c | 4 ++-- src/console.c | 4 ++-- src/sdl/i_system.cpp | 4 ++-- src/win32/win_dbg.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/android/i_system.c b/src/android/i_system.c index b20625587..102bff461 100644 --- a/src/android/i_system.c +++ b/src/android/i_system.c @@ -110,7 +110,7 @@ void I_Error(const char *error, ...) char logbuf[8192]; va_start(argptr, error); - vsprintf(logbuf, error, argptr); + vsnprintf(logbuf, 8192, error, argptr); va_end(argptr); LOGE(logbuf); @@ -166,7 +166,7 @@ void I_OutputMsg(const char *fmt, ...) char logbuf[8192]; va_start(argptr, fmt); - vsprintf(logbuf, fmt, argptr); + vsnprintf(logbuf, 8192, fmt, argptr); va_end(argptr); LOGD(logbuf); diff --git a/src/console.c b/src/console.c index a01c72062..fe91df0f3 100644 --- a/src/console.c +++ b/src/console.c @@ -1282,7 +1282,7 @@ void CONS_Alert(alerttype_t level, const char *fmt, ...) txt = malloc(8192); va_start(argptr, fmt); - vsprintf(txt, fmt, argptr); + vsnprintf(txt, 8192, fmt, argptr); va_end(argptr); switch (level) @@ -1318,7 +1318,7 @@ void CONS_Debug(INT32 debugflags, const char *fmt, ...) txt = malloc(8192); va_start(argptr, fmt); - vsprintf(txt, fmt, argptr); + vsnprintf(txt, 8192, fmt, argptr); va_end(argptr); // Again I am lazy, oh well diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 7314995e8..2663887d6 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -2021,7 +2021,7 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) if (errorcount > 20) { va_start(argptr, error); - vsprintf(buffer, error, argptr); + vsnprintf(buffer, 8192, error, argptr); va_end(argptr); // Implement message box with SDL_ShowSimpleMessageBox, // which should fail gracefully if it can't put a message box up @@ -2039,7 +2039,7 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) // Display error message in the console before we start shutting it down va_start(argptr, error); - vsprintf(buffer, error, argptr); + vsnprintf(buffer, 8192, error, argptr); va_end(argptr); I_OutputMsg("\nI_Error(): %s\n", buffer); diff --git a/src/win32/win_dbg.c b/src/win32/win_dbg.c index 290227b09..a5d1adc3f 100644 --- a/src/win32/win_dbg.c +++ b/src/win32/win_dbg.c @@ -118,7 +118,7 @@ static VOID FPrintf(HANDLE fileHandle, LPCSTR lpFmt, ...) DWORD bytesWritten; va_start(arglist, lpFmt); - vsprintf(str, lpFmt, arglist); + vsnprintf(str, 1999, lpFmt, arglist); va_end(arglist); WriteFile(fileHandle, str, (DWORD)strlen(str), &bytesWritten, NULL); From f2afc5135c340b69d2c3de64d9423d03d0df07fa Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 9 Oct 2025 18:16:57 +0200 Subject: [PATCH 24/25] fix buffer overflows in dedi build too --- src/dedicated/i_system.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index d0914be56..865ae4584 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1468,7 +1468,7 @@ void I_Error(const char *error, ...) if (errorcount > 20) { va_start(argptr, error); - vsprintf(buffer, error, argptr); + vsnprintf(buffer, 8192, error, argptr); va_end(argptr); I_OutputMsg("SRB2Kart %s Recursive Error", buffer); @@ -1482,7 +1482,7 @@ void I_Error(const char *error, ...) // Display error message in the console before we start shutting it down va_start(argptr, error); - vsprintf(buffer, error, argptr); + vsnprintf(buffer, 8192, error, argptr); va_end(argptr); I_OutputMsg("\nI_Error(): %s\n", buffer); From 513613d83b8aaba7d8f56f2582b23d26df076b2b Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 9 Oct 2025 19:13:00 +0200 Subject: [PATCH 25/25] dont update hud during skipped frames this was to fix issues with some lua huds looking really bad during frameskip but this causes issues with the hud flashing during gif recording --- src/d_main.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index fd3e93649..dd13c7b77 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -890,12 +890,6 @@ void D_SRB2Loop(void) // always update console and hud // otherwise it may take minutes to open it CON_Drawer(); - - if (gamestate == GS_LEVEL) - { - ST_Drawer(); - HU_Drawer(); - } } }