From 6ad344f65d14eb32c4e52ee855faa03243e700ff Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Dec 2025 18:19:00 +0100 Subject: [PATCH 01/39] findfile: let files added with "-file" look in addon/downloads folders first due to https://github.com/Indev450/SRB2Kart-Saturn/commit/956fc099adcd7f33993c43c8ee3aea64df3fe9b4 IWADS shouldnt use findfile anymore If there should be such case we can always expose the startupiwad count to check if were currently searching for iwads iirc --- src/d_netfil.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index d35bb09b3..57f0f0f6c 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1162,8 +1162,12 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet filestatus_t homecheck; // store result of last file search boolean badmd5 = false; // store whether md5 was bad from either of the first two searches (if nothing was found in the third) - // skip for startup, our mainwads wont be in there - if (loaded_config) + // see IdentifyVersion + // Iwads skip findfile due to passing fullpath to W_OpenWadFile +#if 0 + // skip for Iwads, as they wont be in there + if (!startupiwadcount) +#endif { if (cv_addons_option.value == 3 && *cv_addons_folder.string != '\0') { From 1ccd3e37bcb50157359bbc8644cb4ed898c72636 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Dec 2025 21:37:31 +0300 Subject: [PATCH 02/39] Init playerinfo[i].node to 255 so if playerinfo packet gets lost, server join screen doesn't display empty player names --- src/d_clisrv.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8f2cc5afb..cd04fb3a2 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3475,6 +3475,9 @@ void CL_Reset(void) memset(player_muted, 0, sizeof(player_muted)); + for (INT32 i = 0; i < MAXPLAYERS; ++i) + playerinfo[i].node = 255; + // D_StartTitle should get done now, but the calling function will handle it } @@ -4263,6 +4266,9 @@ void D_ClientServerInit(void) #endif D_LoadBan(false); + for (INT32 i = 0; i < MAXPLAYERS; ++i) + playerinfo[i].node = 255; + gametic = 0; localgametic = 0; From 2c7c9ec32ab91a07a2a413ee69c6c6f24eedfc42 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Dec 2025 20:10:01 +0100 Subject: [PATCH 03/39] fastcmp.h: mark fastcmp functions as pure this might let the compiler optimize aways subsequent calls in some cases strcmp etc from glibc also does it prayin nothin changes the locale at runtime lmao --- src/fastcmp.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fastcmp.h b/src/fastcmp.h index 0f7c24aaa..1b92e42e8 100644 --- a/src/fastcmp.h +++ b/src/fastcmp.h @@ -3,14 +3,14 @@ // returns false if s != c // returns true if s == c -FUNCINLINE static ATTRINLINE boolean fasticmp(const char *s, const char *c) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fasticmp(const char *s, const char *c) { for (; *s && toupper(*s) == toupper(*c); s++, c++) ; return (*s == *c); // make sure both strings ended } // case-sensitive of the above -FUNCINLINE static ATTRINLINE boolean fastcmp(const char *s, const char *c) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fastcmp(const char *s, const char *c) { for (; *s && *s == *c; s++, c++) ; return (*s == *c); // make sure both strings ended @@ -18,7 +18,7 @@ FUNCINLINE static ATTRINLINE boolean fastcmp(const char *s, const char *c) // length-limited of the above // only true if both strings are at least l characters long AND match, case-sensitively! -FUNCINLINE static ATTRINLINE boolean fastncmp(const char *s, const char *c, UINT16 l) +FUNCINLINE static ATTRINLINE PUREFUNC boolean fastncmp(const char *s, const char *c, UINT16 l) { for (; *s && *s == *c && --l; s++, c++) ; return !l; // make sure you reached the end From 3828a9f8e07e7cffaf9fbbe70a28a8f45382f1d3 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Dec 2025 22:58:06 +0300 Subject: [PATCH 04/39] Add flipcammode toggle for using local flipcam settings instead of player flags --- src/m_menudefs.c | 11 +++++++---- src/p_mobj.c | 17 ++++++++++++++++- src/r_main.cpp | 5 +++++ src/r_main.h | 1 + 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/m_menudefs.c b/src/m_menudefs.c index cbdaac587..e6129d2d8 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -1339,16 +1339,19 @@ static menuitem_t OP_CamOptionsMenu[] = {IT_STRING | IT_CVAR | IT_CV_BIGFLOAT, NULL, "Field of View",&cv_fov, 30}, - {IT_STRING | IT_SUBMENU, NULL, "Player 1 Camera options...", &OP_Player1CamOptionsDef, 50}, - {IT_STRING | IT_SUBMENU, NULL, "Player 2 Camera options...", &OP_Player2CamOptionsDef, 60}, - {IT_STRING | IT_SUBMENU, NULL, "Player 3 Camera options...", &OP_Player3CamOptionsDef, 70}, - {IT_STRING | IT_SUBMENU, NULL, "Player 4 Camera options...", &OP_Player4CamOptionsDef, 80}, + {IT_STRING | IT_CVAR, NULL, "Flipcam Mode", &cv_flipcammode, 40}, + + {IT_STRING | IT_SUBMENU, NULL, "Player 1 Camera options...", &OP_Player1CamOptionsDef, 60}, + {IT_STRING | IT_SUBMENU, NULL, "Player 2 Camera options...", &OP_Player2CamOptionsDef, 70}, + {IT_STRING | IT_SUBMENU, NULL, "Player 3 Camera options...", &OP_Player3CamOptionsDef, 80}, + {IT_STRING | IT_SUBMENU, NULL, "Player 4 Camera options...", &OP_Player4CamOptionsDef, 90}, }; static const char* OP_CamOptionsTooltips[] = { NULL, "Player field of view.", + "Change flipcam mode.\nDisplayplayer - use currently viewed player option.\nLocal - use local flipcam toggle option.", NULL, NULL, NULL, diff --git a/src/p_mobj.c b/src/p_mobj.c index e59d087d8..cd7d44a62 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3237,7 +3237,22 @@ void P_DestroyRobots(void) // the below is chasecam only, if you're curious. check out P_CalcPostImg in p_user.c for first person void P_CalcChasePostImg(player_t *player, camera_t *thiscam) { - const boolean flipcam = (player->pflags & PF_FLIPCAM && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); + boolean player_flipcam = false; + + if (cv_flipcammode.value == 0) + player_flipcam = player->pflags & PF_FLIPCAM; + else + { + INT32 pnum = P_GetLocalPlayerNumForPlayer(player); + + // Shouldn't happen but just in case + if (pnum == -1) + pnum = 0; + + player_flipcam = cv_flipcam[pnum].value; + } + + const boolean flipcam = (player_flipcam && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); UINT8 postimgtype = 0; if (encoremode) diff --git a/src/r_main.cpp b/src/r_main.cpp index 1ad8e8be9..fecfba580 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -182,6 +182,9 @@ consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS] = { {"flipcam4", "No", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, FlipCam4_OnChange, 0, NULL, NULL, 0, 0, NULL} }; +static CV_PossibleValue_t flipcammode_cons_t[] = {{0, "Displayplayer"}, {1, "Local"}, {0, NULL}}; +consvar_t cv_flipcammode = {"flipcammode", "Displayplayer", CV_SAVE, flipcammode_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_shadow = {"shadow", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shadowoffs = {"offsetshadows", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skybox = {"skybox", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -1546,6 +1549,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_flipcam[i]); } + CV_RegisterVar(&cv_flipcammode); + // Enough for dedicated server if (dedicated) return; diff --git a/src/r_main.h b/src/r_main.h index 36c8756f8..d33d67606 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -205,6 +205,7 @@ extern consvar_t cv_showhud, cv_translucenthud, cv_uncappedhud; extern consvar_t cv_homremoval; extern consvar_t cv_chasecam[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_flipcam[MAXSPLITSCREENPLAYERS]; +extern consvar_t cv_flipcammode; extern consvar_t cv_shadow, cv_shadowoffs; extern consvar_t cv_ffloorclip, cv_spriteclip; extern consvar_t cv_softcyancut; From 6c98440f27f14c26d70c468915feb1d5cbb461e9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 16 Dec 2025 17:52:03 +0100 Subject: [PATCH 05/39] Remove pure attribute from fasticmp While i assume this to be fine currently, i quite frankly dont trust the srb2 codebase enough aswell as preventing any future issues if there should ever be need to switch locales, since toupper WILL change behaviour in such cases which does not qualify as pure --- src/fastcmp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fastcmp.h b/src/fastcmp.h index 1b92e42e8..ea87bee4d 100644 --- a/src/fastcmp.h +++ b/src/fastcmp.h @@ -3,7 +3,7 @@ // returns false if s != c // returns true if s == c -FUNCINLINE static ATTRINLINE PUREFUNC boolean fasticmp(const char *s, const char *c) +FUNCINLINE static ATTRINLINE boolean fasticmp(const char *s, const char *c) { for (; *s && toupper(*s) == toupper(*c); s++, c++) ; return (*s == *c); // make sure both strings ended From 0540b5656a2d95c21011d2617214de18c30b9e81 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 19 Nov 2025 19:10:23 +0100 Subject: [PATCH 06/39] OpenGL: keep around our drawnodes memory no need to constantly reallocate new memory we dont have renderer switch, and the next level will render drawnodes anyways those wont grow super big also, so theres no big worry about wasting tons of memory yes i like ceepeepee vectors, how can you tell --- src/hardware/hw_main.cpp | 51 ++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 9f1a90769..b363069b6 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -14,6 +14,7 @@ #ifdef HWRENDER #include +#include #include "../doomstat.h" #include "../doomdef.h" @@ -4174,6 +4175,7 @@ static int CompareVisSprites(const void *p1, const void *p2) static void HWR_SortVisSprites(void) { UINT32 i; + for (i = 0; i < gl_visspritecount; i++) { gl_vsprorder[i] = HWR_GetVisSprite(i); @@ -4242,38 +4244,29 @@ typedef struct // initial size of drawnode array #define DRAWNODES_INIT_SIZE 64 -gl_drawnode_t *drawnodes = NULL; -INT32 numdrawnodes = 0; -INT32 alloceddrawnodes = 0; +// no reason to waste all the allocations since every map will have atleast one translucent thing +static std::vector drawnodes; static void *HWR_CreateDrawNode(gl_drawnode_type_t type) { - gl_drawnode_t *drawnode; + // if we didnt alloc anything yet, reserve atleast 64 nodes + // dont declare with it as we want our size to be 0! + drawnodes.reserve(DRAWNODES_INIT_SIZE); - if (!drawnodes) - { - alloceddrawnodes = DRAWNODES_INIT_SIZE; - drawnodes = static_cast(Z_Malloc(alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes)); - } - else if (numdrawnodes >= alloceddrawnodes) - { - alloceddrawnodes *= 2; - Z_Realloc(drawnodes, alloceddrawnodes * sizeof(gl_drawnode_t), PU_LEVEL, &drawnodes); - } - - drawnode = &drawnodes[numdrawnodes++]; - drawnode->type = type; + drawnodes.emplace_back(); + drawnodes.back().type = type; // not sure if returning different pointers to a union is necessary switch (type) { case DRAWNODE_PLANE: - return &drawnode->u.plane; + return &drawnodes.back().u.plane; case DRAWNODE_POLYOBJECT_PLANE: - return &drawnode->u.polyplane; + return &drawnodes.back().u.polyplane; case DRAWNODE_WALL: - return &drawnode->u.wall; + return &drawnodes.back().u.wall; } + return NULL; } @@ -4337,11 +4330,15 @@ static int CompareDrawNodePlanes(const void *p1, const void *p2) // Sorts and renders the list of drawnodes for the scene being rendered. static void HWR_RenderDrawNodes(void) { - INT32 i = 0, run_start = 0; + size_t i = 0, run_start = 0; + static std::vector sortindex; + + sortindex.reserve(DRAWNODES_INIT_SIZE); // Array for storing the rendering order. // A list of indices into the drawnodes array. - INT32 *sortindex; + + const size_t numdrawnodes = drawnodes.size(); if (!numdrawnodes) return; @@ -4350,7 +4347,7 @@ static void HWR_RenderDrawNodes(void) PS_START_TIMING(ps_hw_nodesorttime); - sortindex = static_cast(Z_Malloc(sizeof(INT32) * numdrawnodes, PU_STATIC, NULL)); + sortindex.resize(numdrawnodes); // Reversed order for (i = 0; i < numdrawnodes; i++) @@ -4366,7 +4363,7 @@ static void HWR_RenderDrawNodes(void) if (drawnodes[sortindex[run_start]].type == DRAWNODE_PLANE) { // found it, now look for run end - INT32 run_end; // (inclusive) + size_t run_end; // (inclusive) for (i = run_start+1; i < numdrawnodes; i++) { @@ -4379,7 +4376,7 @@ static void HWR_RenderDrawNodes(void) if (run_end > run_start) // if there are multiple consecutive planes, not just one { // consecutive run of planes found, now sort it - qs22j(sortindex + run_start, run_end - run_start + 1, sizeof(INT32), CompareDrawNodePlanes); + qs22j(sortindex.data() + run_start, run_end - run_start + 1, sizeof(INT32), CompareDrawNodePlanes); } run_start = run_end + 1; // continue looking for runs coming right after this one @@ -4451,9 +4448,7 @@ static void HWR_RenderDrawNodes(void) PS_STOP_TIMING(ps_hw_nodedrawtime); - numdrawnodes = 0; - - Z_Free(sortindex); + drawnodes.clear(); // clear so our size is 0 again! } From 8b3d55fbc89ab0d20ab1c741442b34c8b5189639 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 9 Dec 2025 18:14:44 +0100 Subject: [PATCH 07/39] HWR_ProcessSeg: port softwares code to skip rendering inner sides that are "joined" to other fofs This seems to improve performance on maps with moderate to lots of fofs quite a bit. On maps with only a few fofs, this makes no difference or has very very little regression Need to test and check if there are any visual errors, but so far everything seems good --- src/hardware/hw_main.cpp | 104 +++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 26 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index b363069b6..afe899df2 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1881,6 +1881,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Used for height comparisons and etc across FOFs and slopes fixed_t high1, highslope1, low1, lowslope1; + fixed_t high2, highslope2, low2, lowslope2; INT32 texnum; @@ -1893,19 +1894,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_backsector->ffloors; rover; rover = rover->next) { - boolean bothsides = false; - // Skip if it exists on both sectors. - ffloor_t * r2; - for (r2 = gl_frontsector->ffloors; r2; r2 = r2->next) - if (rover->master == r2->master) - { - bothsides = true; - break; - } - - if (bothsides) - continue; - const ffloortype_e roverflags = rover->flags; if (!(roverflags & FF_EXISTS) || !(roverflags & FF_RENDERSIDES) || (roverflags & FF_INVERTSIDES)) @@ -1917,6 +1905,45 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((high1 < lowcut || highslope1 < lowcutslope) || (low1 > highcut || lowslope1 > highcutslope)) continue; + ffloor_t * r2; + for (r2 = gl_frontsector->ffloors; r2; r2 = r2->next) + { + if (r2->master == rover->master) // Skip if same control line. + break; + + const ffloortype_e r2flags = r2->flags; + + if (!(r2flags & FF_EXISTS) || !(r2flags & FF_RENDERSIDES)) + continue; + + if (rover->flags & FF_EXTRA) + { + if (!(r2flags & FF_CUTEXTRA)) + continue; + + if (r2flags & FF_EXTRA && (r2flags & (FF_TRANSLUCENT|FF_FOG)) != (rover->flags & (FF_TRANSLUCENT|FF_FOG))) + continue; + } + else + { + if (!(r2flags & FF_CUTSOLIDS)) + continue; + } + + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) + + if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) + continue; + if ((high1 > high2 || highslope1 > highslope2) || (low1 < low2 || lowslope1 < lowslope2)) + continue; + + break; + } + + if (r2) + continue; + side_t *side = R_GetFFloorSide(gl_curline->linedef, rover, gl_backsector); boolean do_texture_skew; @@ -2053,19 +2080,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_frontsector->ffloors; rover; rover = rover->next) { - boolean bothsides = false; - // Skip if it exists on both sectors. - ffloor_t * r2; - for (r2 = gl_backsector->ffloors; r2; r2 = r2->next) - if (rover->master == r2->master) - { - bothsides = true; - break; - } - - if (bothsides) - continue; - const ffloortype_e roverflags = rover->flags; if (!(roverflags & FF_EXISTS) || !(roverflags & FF_RENDERSIDES) || !(roverflags & FF_ALLSIDES)) @@ -2077,6 +2091,44 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((high1 < lowcut || highslope1 < lowcutslope) || (low1 > highcut || lowslope1 > highcutslope)) continue; + ffloor_t * r2; + for (r2 = gl_backsector->ffloors; r2; r2 = r2->next) + { + if (r2->master == rover->master) // Skip if same control line. + break; + + const ffloortype_e r2flags = r2->flags; + + if (!(r2flags & FF_EXISTS) || !(r2flags & FF_RENDERSIDES)) + continue; + + if (rover->flags & FF_EXTRA) + { + if (!(r2flags & FF_CUTEXTRA)) + continue; + + if (r2flags & FF_EXTRA && (r2flags & (FF_TRANSLUCENT|FF_FOG)) != (rover->flags & (FF_TRANSLUCENT|FF_FOG))) + continue; + } + else + { + if (!(r2flags & FF_CUTSOLIDS)) + continue; + } + + SLOPEPARAMS(*r2->t_slope, high2, highslope2, *r2->topheight) + SLOPEPARAMS(*r2->b_slope, low2, lowslope2, *r2->bottomheight) + + if ((high2 < lowcut || highslope2 < lowcutslope) || (low2 > highcut || lowslope2 > highcutslope)) + continue; + if ((high1 > high2 || highslope1 > highslope2) || (low1 < low2 || lowslope1 < lowslope2)) + continue; + + break; + } + if (r2) + continue; + side_t *side = R_GetFFloorSide(gl_curline->linedef, rover, gl_backsector); boolean do_texture_skew; From 860dc37fe476b2b9cf489cf88c83c12268a31d04 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 24 Nov 2025 20:51:53 +0100 Subject: [PATCH 08/39] Optimize: move a few strlen calls out of loops when applicable and the input does not get modified within the loop needs some testing incase i oversaw something --- src/command.c | 7 +++++-- src/d_clisrv.c | 6 ++++-- src/d_netfil.c | 11 ++++++----- src/hu_stuff.c | 41 ++++++++++++++++++++++++----------------- src/k_hud.c | 4 +++- src/m_menu.c | 3 ++- src/m_misc.c | 13 +++++++------ src/sdl/i_system.cpp | 9 +++++++-- src/v_video.c | 12 +++++++++--- 9 files changed, 67 insertions(+), 39 deletions(-) diff --git a/src/command.c b/src/command.c index 7e0c34d03..6b71dce73 100644 --- a/src/command.c +++ b/src/command.c @@ -237,10 +237,13 @@ void COM_ImmedExecute(const char *ptext) char line[1024] = ""; INT32 quotes; - while (i < strlen(ptext)) + const size_t txtlength = strlen(ptext); + + while (i < txtlength) { quotes = 0; - for (j = 0; i < strlen(ptext); i++,j++) + + for (j = 0; i < txtlength; i++,j++) { if (ptext[i] == '\"' && !quotes && i > 0 && ptext[i-1] != ' ') // Malformed command return; diff --git a/src/d_clisrv.c b/src/d_clisrv.c index cd04fb3a2..6cf50a4d3 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1457,12 +1457,14 @@ static inline void CL_DrawConnectionStatus(void) V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-58, dldlength, 8, 160); memset(tempname, 0, sizeof(tempname)); + // offset filename to just the name only part filename += strlen(filename) - nameonlylength(filename); + const size_t filenamelength = strlen(filename); - if (strlen(filename) > sizeof(tempname)-1) // too long to display fully + if (filenamelength > sizeof(tempname)-1) // too long to display fully { - size_t endhalfpos = strlen(filename)-10; + size_t endhalfpos = filenamelength-10; // display as first 14 chars + ... + last 10 chars // which should add up to 27 if our math(s) is correct snprintf(tempname, sizeof(tempname), "%.14s...%.10s", filename, filename+endhalfpos); diff --git a/src/d_netfil.c b/src/d_netfil.c index 57f0f0f6c..a4478fcc9 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1079,12 +1079,14 @@ void CloseNetFile(void) // Receiving a file? for (i = 0; i < MAX_WADFILES; i++) + { if (fileneeded[i].status == FS_DOWNLOADING && fileneeded[i].file) { fclose(fileneeded[i].file); // File is not complete delete it remove(fileneeded[i].filename); } + } // Remove PT_FILEFRAGMENT from acknowledge list Net_AbortPacketType(PT_FILEFRAGMENT); @@ -1098,17 +1100,16 @@ void nameonly(char *s) void *ns; for (j = strlen(s); j != (size_t)-1; j--) + { if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) { ns = &(s[j+1]); len = strlen(ns); -#if 0 - memcpy(s, ns, len+1); -#else - memmove(s, ns, len+1); -#endif + memmove(s, ns, len+1); + return; } + } } // Returns the length in characters of the last element of a path. diff --git a/src/hu_stuff.c b/src/hu_stuff.c index a61199b39..6cca391e9 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -596,12 +596,12 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) } // Only servers/admins can CSAY. - if(!server && !(IsPlayerAdmin(consoleplayer))) + if (!server && !(IsPlayerAdmin(consoleplayer))) flags &= ~HU_CSAY; // We handle HU_SERVER_SAY, not the caller. flags &= ~HU_SERVER_SAY; - if(dedicated && !(flags & HU_CSAY)) + if (dedicated && !(flags & HU_CSAY)) flags |= HU_SERVER_SAY; buf[0] = target; @@ -615,17 +615,20 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) strlcat(msg, COM_Argv(ix + usedargs), msgspace); } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + const size_t msglength = strlen(msg); + + if (msglength > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { // what we're gonna do now is check if the node exists // with that logic, characters 4 and 5 are our numbers: const char *newmsg; INT32 spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); + CLEANUP(pfree) char *nodenum = (char*) malloc(3); memcpy(nodenum, msg+3, 2); nodenum[2] = '\0'; + // check for undesirable characters in our "number" - if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) + if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) { // check if nodenum[1] is a space if (nodenum[1] == ' ') @@ -634,23 +637,21 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } + // I'm very bad at C, I swear I am, additional checks eww! if (spc != 0) { if (msg[5] != ' ') { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } target = atoi((const char*) nodenum); // turn that into a number - free(nodenum); //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -661,12 +662,13 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same return; } + buf[0] = target; newmsg = msg+5+spc; strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } - SendNetXCmd(XD_SAY, buf, strlen(msg) + 1 + msg-buf); + SendNetXCmd(XD_SAY, buf, msglength + 1 + msg-buf); } /** Send a message to everyone. @@ -917,10 +919,12 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) return; } + const size_t msglength = strlen(msg); + //check for invalid characters (0x80 or above) { size_t i; - const size_t j = strlen(msg); + const size_t j = msglength; for (i = 0; i < j; i++) { if (msg[i] & 0x80) @@ -967,7 +971,7 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) } // Handle "/me" actions, but only in messages to everyone. - if (target == 0 && strlen(msg) > 4 && strnicmp(msg, "/me ", 4) == 0) + if (target == 0 && msglength > 4 && strnicmp(msg, "/me ", 4) == 0) { msg += 4; action = true; @@ -1149,10 +1153,12 @@ static boolean HU_clearChatSpaces(void) size_t i = 0; // Used to just check our message char c; // current character we're iterating. boolean nothingbutspaces = true; + const size_t chatlength = strlen(w_chat_buf); - for (; i < strlen(w_chat_buf); i++) // iterate through message and eradicate all spaces that don't belong. + for (; i < chatlength; i++) // iterate through message and eradicate all spaces that don't belong. { c = w_chat_buf[i]; + if (!c) break; // if there's nothing, it's safe to assume our message has ended, so let's not waste any more time here. @@ -1161,6 +1167,7 @@ static boolean HU_clearChatSpaces(void) nothingbutspaces = false; } } + return nothingbutspaces; } @@ -1207,11 +1214,11 @@ static void HU_SendChatMessage(void) return; } - size_t len = strlen(msg); + const size_t msglength = strlen(msg); - if (len >= 5 && strnicmp(msg, "/mute", 5) == 0) // Used /mute + if (msglength >= 5 && strnicmp(msg, "/mute", 5) == 0) // Used /mute { - if (len > 6) + if (msglength > 6) DoMute(msg+6); else HU_AddChatText("\x82NOTICE: \x80Usage: /mute ", false); @@ -1219,7 +1226,7 @@ static void HU_SendChatMessage(void) return; } - if (len > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + if (msglength > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { INT32 spc = 1; // used if nodenum[1] is a space. const char *newmsg; @@ -1991,7 +1998,7 @@ static void HU_DrawChat(void) longest_name_length = max(longest_name_length, strlen(player_names[i])); } - for(i = 0; i < MAXPLAYERS; i++) + for (i = 0; i < MAXPLAYERS; i++) { if (!playeringame[i]) continue; diff --git a/src/k_hud.c b/src/k_hud.c index 59278a229..1d9b7fe5b 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -4468,7 +4468,9 @@ static void K_drawLapStartAnim(void) V_DrawFixedPatch(leftx, y, FRACUNIT, vflags, kp_lapanim_lap[min(progress/2, 6)], NULL); char *lapnum = va("%02d", stplyr->laps + 1); - for (int i = 0; i < (int)strlen(lapnum); i++) + const size_t laplength = strlen(lapnum); + + for (int i = 0; i < (int)laplength; i++) { int digit = lapnum[i] - '0'; int frame = min(2, progress/2 - 8 - (i*2)); diff --git a/src/m_menu.c b/src/m_menu.c index 3650853bc..c2978fe82 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2868,8 +2868,9 @@ static void M_DrawCenteredMenu(void) static inline size_t M_StringHeight(const char *string) { size_t h = 8, i; + const size_t strlength = strlen(string); - for (i = 0; i < strlen(string); i++) + for (i = 0; i < strlength; i++) if (string[i] == '\n') h += 8; diff --git a/src/m_misc.c b/src/m_misc.c index 655a28a24..cbc40d4e2 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1693,22 +1693,23 @@ char *M_GetToken(const char *inputString) } -const char * M_Ftrim (double f) +const char * M_Ftrim(double f) { static char dig[9];/* "0." + 6 digits (6 is printf's default) */ int i; + /* I know I said it's the default, but just in case... */ sprintf(dig, "%.6f", fabs(modf(f, &f))); + /* trim trailing zeroes */ for (i = strlen(dig)-1; dig[i] == '0'; --i) ; + if (dig[i] == '.')/* :NOTHING: */ return ""; - else - { - dig[i + 1] = '\0'; - return &dig[1];/* skip the 0 */ - } + + dig[i + 1] = '\0'; + return &dig[1];/* skip the 0 */ } /** Count bits in a number. diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 60e5108ac..8a9b8bd69 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -2315,12 +2315,17 @@ static void pathonly(char *s) size_t j; for (j = strlen(s); j != (size_t)-1; j--) + { if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) { - if (s[j] == ':') s[j+1] = 0; - else s[j] = 0; + if (s[j] == ':') + s[j+1] = 0; + else + s[j] = 0; + return; } + } } /** \brief search for srb2.srb in the given path diff --git a/src/v_video.c b/src/v_video.c index 213db7bfc..ac85715ef 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2992,7 +2992,9 @@ INT32 V_CreditStringWidth(const char *string) if (!string) return 0; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - CRED_FONTSTART; if (c < 0 || c >= CRED_FONTSIZE) @@ -3070,7 +3072,9 @@ INT32 V_LevelNameWidth(const char *string) INT32 c, w = 0; size_t i; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - LT_FONTSTART; if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) @@ -3089,7 +3093,9 @@ INT32 V_LevelNameHeight(const char *string) INT32 c, w = 0; size_t i; - for (i = 0; i < strlen(string); i++) + const size_t strlength = strlen(string); + + for (i = 0; i < strlength; i++) { c = toupper(string[i]) - LT_FONTSTART; if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) From a4af2546437b033693dc5fec2ece1a6535b0e3c9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 22 Dec 2025 20:16:04 +0100 Subject: [PATCH 09/39] Revert "dont call I_Quit from within "quit_handler", let it signal main loop to quit" This reverts commit a2feaa7fde4c2d3138cf21c40c2f8f671fac78ad. --- src/d_main.c | 3 --- src/dedicated/i_system.c | 12 ++---------- src/i_system.h | 3 +-- src/sdl/i_system.cpp | 20 +++++++++++--------- src/sdl/i_video.c | 3 +-- src/sdl/mixer_sound.c | 3 +-- 6 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index ab10af215..c46ef0c44 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -679,9 +679,6 @@ void D_SRB2Loop(void) for (;;) { - if (I_Interrupted()) - I_Quit(); - // capbudget is the minimum precise_t duration of a single loop iteration precise_t capbudget; precise_t elapsed; diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 5edb71a99..31eaf0346 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1075,19 +1075,11 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -static volatile sig_atomic_t interrupted = 0; - -boolean I_Interrupted(void) -{ - return interrupted; -} - -static void quit_handler(int num) +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) { signal(num, SIG_DFL); //default signal action raise(num); - //I_Quit(); - interrupted = true; + I_Quit(); } #ifdef HAVE_LIBBACKTRACE diff --git a/src/i_system.h b/src/i_system.h index 68d51f022..7084c655f 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -29,6 +29,7 @@ extern "C" { */ #define MAX_QUIT_FUNCS 16 + /** \brief Graphic system had started up */ extern UINT8 graphics_started; @@ -190,8 +191,6 @@ INT32 I_StartupSystem(void); */ void I_ShutdownSystem(void); -boolean I_Interrupted(void); - /** \brief The I_GetDiskFreeSpace function \param freespace a INT64 pointer to hold the free space amount diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 8a9b8bd69..0c024a5bd 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1670,19 +1670,21 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -static volatile sig_atomic_t interrupted = 0; - -boolean I_Interrupted(void) +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) { - return interrupted; -} +#ifdef HAVE_THREADS + if (g_main_thread_id != std::this_thread::get_id()) + { + // Do not attempt any sort of recovery if this signal triggers off the main thread + signal(num, SIG_DFL); + raise(num); + exit(-2); + } +#endif -static void quit_handler(int num) -{ signal(num, SIG_DFL); //default signal action raise(num); - //I_Quit(); - interrupted = true; + I_Quit(); } static void I_RegisterSignals(void) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ae2691359..c2d87e3f1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2012,8 +2012,7 @@ void I_ShutdownGraphics(void) SDL_DestroyWindow(window); window = NULL; - if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO) - SDL_QuitSubSystem(SDL_INIT_VIDEO); + SDL_QuitSubSystem(SDL_INIT_VIDEO); framebuffer = SDL_FALSE; } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index c455aab01..529b47399 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -237,8 +237,7 @@ void I_ShutdownSound(void) Mix_Quit(); #endif - if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) - SDL_QuitSubSystem(SDL_INIT_AUDIO); + SDL_QuitSubSystem(SDL_INIT_AUDIO); #ifdef HAVE_LIBGME if (gme) From 7c848f4be561876c4b833f711fe8458cbeb66580 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 24 Dec 2025 00:54:39 +0300 Subject: [PATCH 10/39] Sort directories too in replay list --- src/m_menu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index c2978fe82..15309dd2d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4170,8 +4170,6 @@ static int ReplayListSortComparator(const void *entry1, const void *entry2) return -1; else if (demo2->type == MD_SUBDIR && demo1->type != MD_SUBDIR) return 1; - else if (demo1->type == MD_SUBDIR && demo2->type == MD_SUBDIR) - return 0; memcpy(filepath1, demo1->filepath, sizeof(filepath1)); memcpy(filepath2, demo2->filepath, sizeof(filepath2)); From 1c95e5f40e58dabf8b22d7221e863b789327583b Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 24 Dec 2025 01:23:20 +0300 Subject: [PATCH 11/39] Actually add filepath to directories to sort them --- src/m_menu.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 15309dd2d..9a8c8bfba 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4174,8 +4174,14 @@ static int ReplayListSortComparator(const void *entry1, const void *entry2) memcpy(filepath1, demo1->filepath, sizeof(filepath1)); memcpy(filepath2, demo2->filepath, sizeof(filepath2)); - nameonly(filepath1); - nameonly(filepath2); + // nameonly will make filepath's empty for directories since they may end with PATHSEP + // this is a lazy solution but if we don't do nameonly, dirs still will be sorted in correct only, + // just not very efficently + if (demo1->type != MD_SUBDIR) + { + nameonly(filepath1); + nameonly(filepath2); + } // Comparing in opposite order to move new replays to the top return strncmp(filepath2, filepath1, sizeof(filepath1)); @@ -4211,6 +4217,9 @@ static void PrepReplayList(boolean reset) { demolist_all[i].type = MD_SUBDIR; strncpy(demolist_all[i].title, dirmenu[i] + DIR_STRING, 64); + snprintf(demolist_all[i].filepath, sizeof(demolist_all[i].filepath), + // 255 = UINT8 limit. dirmenu entries are restricted to this length (see DIR_LEN). + "%s%.255s", menupath, dirmenu[i] + DIR_STRING); } else { From 2bf4c442597768e83790e0d6688393a3a746e1c4 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 24 Dec 2025 01:36:00 +0300 Subject: [PATCH 12/39] Revert "Actually add filepath to directories to sort them" This reverts commit 1c95e5f40e58dabf8b22d7221e863b789327583b. --- src/m_menu.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 9a8c8bfba..15309dd2d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4174,14 +4174,8 @@ static int ReplayListSortComparator(const void *entry1, const void *entry2) memcpy(filepath1, demo1->filepath, sizeof(filepath1)); memcpy(filepath2, demo2->filepath, sizeof(filepath2)); - // nameonly will make filepath's empty for directories since they may end with PATHSEP - // this is a lazy solution but if we don't do nameonly, dirs still will be sorted in correct only, - // just not very efficently - if (demo1->type != MD_SUBDIR) - { - nameonly(filepath1); - nameonly(filepath2); - } + nameonly(filepath1); + nameonly(filepath2); // Comparing in opposite order to move new replays to the top return strncmp(filepath2, filepath1, sizeof(filepath1)); @@ -4217,9 +4211,6 @@ static void PrepReplayList(boolean reset) { demolist_all[i].type = MD_SUBDIR; strncpy(demolist_all[i].title, dirmenu[i] + DIR_STRING, 64); - snprintf(demolist_all[i].filepath, sizeof(demolist_all[i].filepath), - // 255 = UINT8 limit. dirmenu entries are restricted to this length (see DIR_LEN). - "%s%.255s", menupath, dirmenu[i] + DIR_STRING); } else { From 7518a6f181e59de80e56e707c5972926447ee871 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 24 Dec 2025 01:36:02 +0300 Subject: [PATCH 13/39] Revert "Sort directories too in replay list" This reverts commit 7c848f4be561876c4b833f711fe8458cbeb66580. --- src/m_menu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index 15309dd2d..c2978fe82 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4170,6 +4170,8 @@ static int ReplayListSortComparator(const void *entry1, const void *entry2) return -1; else if (demo2->type == MD_SUBDIR && demo1->type != MD_SUBDIR) return 1; + else if (demo1->type == MD_SUBDIR && demo2->type == MD_SUBDIR) + return 0; memcpy(filepath1, demo1->filepath, sizeof(filepath1)); memcpy(filepath2, demo2->filepath, sizeof(filepath2)); From c9afd4a2cd6005b0ad5308f386da39003a414cbb Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 24 Dec 2025 00:06:05 +0100 Subject: [PATCH 14/39] G_GetDemoDate: make safer and use static memory bunch of smaller issues before, no real checks for strltol and potential free on a null pointer lul also skips replays with shorter than 10 char names and handles errors better --- src/g_demo.c | 93 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index a714f8e48..312e57530 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -55,6 +55,8 @@ #include "k_stats.h" // SRB2kart #include "r_fps.h" // frame interpolation/uncapped +#include + #ifdef HAVE_DISCORDRPC #include "discord.h" #endif @@ -2401,49 +2403,69 @@ static long G_GetCreationTime(char *filepath) static char *G_GetDemoDate(menudemo_t *pdemo) { - char *datetime; - datetime = malloc(sizeof(pdemo->date)); // mallocma balls - - // no mallocma balls... :c - if (!datetime) - { - return NULL; - } - + char *endPos = NULL; + static char datetime[11]; time_t file_time = 0; + const char *format = NULL; + struct tm *tm_buf = NULL; + CLEANUP(pfree) char *filename = NULL; // get le filepath - char *filename; filename = strdup(pdemo->filepath); -#if defined (_WIN32) if (!filename) { - // if we cant get a filename try just getting the file create time +#if defined (_WIN32) + // if we cant get a filename try just getting the file creation time file_time = G_GetCreationTime(pdemo->filepath); goto skipfilenametime; - } #else - if (!filename) - { - free(datetime); return NULL; - } #endif + } // get the actual filename Zzz... nameonly(filename); - // convert it to long Zzz.... - file_time = strtol(filename, NULL, 10); - free(filename); // dont need this anymore a + // the first 10 characters of a replay name usually is a unix timestamp + + // not long enough to contain a valid timestamp + if (strlen(filename) < 10) + { +#if defined (_WIN32) + // try to get file creation time + file_time = G_GetCreationTime(pdemo->filepath); + goto skipfilenametime; +#else + return NULL; +#endif + } + +#ifndef AVOID_ERRNO + errno = 0; +#endif + // get the timestamp as actual numbers lul + file_time = strtol(filename, &endPos, 10); + + if (endPos == filename // Empty string +#ifndef AVOID_ERRNO + || errno == ERANGE // Number out-of-range +#endif + || file_time < 0) // Number is not positive + { +#if defined (_WIN32) + // just try and get the creation time then + file_time = G_GetCreationTime(pdemo->filepath); +#else + return NULL; +#endif + } #if defined (_WIN32) skipfilenametime: #endif // then throw it into localtime to get an actual human readable format lmao - struct tm *tm_buf = NULL; tm_buf = localtime(&file_time); // cant believe we ended up in 1970 @@ -2456,14 +2478,10 @@ skipfilenametime: tm_buf = localtime(&file_time); if (tm_buf == NULL || tm_buf->tm_year <= 110) - { - free(datetime); return NULL; - } goto gotcreationtime; #else - free(datetime); return NULL; #endif } @@ -2472,17 +2490,27 @@ skipfilenametime: gotcreationtime: #endif - const char *format; - // US ppl are special (: if (cv_demodateformat.value == 2) format = "%m.%d.%Y"; else if (cv_demodateformat.value == 1) format = "%d.%m.%Y"; else - format = strstr(setlocale(LC_TIME, NULL), "en_US") ? "%m.%d.%Y" : "%d.%m.%Y"; + { + const char *locale = setlocale(LC_TIME, NULL); - strftime(datetime, sizeof(pdemo->date), format, tm_buf); + if (locale == NULL) + format = "%d.%m.%Y"; // fallback to non US format + else if (strstr(locale, "en_US")) + format = "%m.%d.%Y"; + else + format = "%d.%m.%Y"; + } + + if (strftime(datetime, sizeof(datetime), format, tm_buf) == 0) + { + return NULL; + } return datetime; } @@ -2491,6 +2519,7 @@ void G_LoadDemoTitle(menudemo_t *pdemo) { UINT8 infobuffer[96], *info_p; UINT16 pdemoversion; + char *demodate = NULL; size_t count; FILE *handle = fopen(pdemo->filepath, "rb"); @@ -2529,13 +2558,13 @@ void G_LoadDemoTitle(menudemo_t *pdemo) memcpy(pdemo->title, info_p, 64); // demo date - char *demodate; demodate = G_GetDemoDate(pdemo); if (demodate) - strncpy(pdemo->date, demodate, sizeof(pdemo->date)); + { + strlcpy(pdemo->date, demodate, sizeof(pdemo->date)); + } - free(demodate); break; #ifdef DEMO_COMPAT_100 case 0x0001: From 0fe3086a5ad41d9ec61609bebbe3c7ccdcfa0cf6 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 18:58:41 +0100 Subject: [PATCH 15/39] Fixup the doomednum lookup properly match the old linear lookup by returning the FIRST match for doomednum also shrinks the array, doomednum max is 4095, no need for such massive array, also fixed a off by should fix some join desynchs and desynchs on certain maps --- src/d_netcmd.c | 2 -- src/info.h | 2 ++ src/p_local.h | 2 +- src/p_mobj.c | 15 +++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 870ceba69..c669da59b 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4751,8 +4751,6 @@ static void Command_LocateLump_f(void) } } -#define MAXDOOMEDNUM 4095 - static void Command_ListDoomednums_f(void) { INT16 i, j, k = 0, l = 0; diff --git a/src/info.h b/src/info.h index 4ee851cee..c84d63214 100644 --- a/src/info.h +++ b/src/info.h @@ -19,6 +19,8 @@ #include "sounds.h" #include "m_fixed.h" +#define MAXDOOMEDNUM 4095 + // dehacked.c now has lists for the more named enums! PLEASE keep them up to date! // For great modding!! diff --git a/src/p_local.h b/src/p_local.h index 4b6530eb9..3c16b5c62 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -272,7 +272,7 @@ extern consvar_t cv_gravity; void P_RespawnSpecials(void); -extern mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; +extern mobjtype_t g_doomednum_to_mobjtype[MAXDOOMEDNUM+1]; void CalculateDoomednumToMobjtype(void); mobj_t *P_AllocateMobj(void); diff --git a/src/p_mobj.c b/src/p_mobj.c index cd7d44a62..ad7982d87 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10463,17 +10463,20 @@ void P_PrecipitationEffects(void) } } -mobjtype_t g_doomednum_to_mobjtype[UINT16_MAX]; +mobjtype_t g_doomednum_to_mobjtype[MAXDOOMEDNUM+1] = {}; void CalculateDoomednumToMobjtype(void) { memset(g_doomednum_to_mobjtype, MT_NULL, sizeof(g_doomednum_to_mobjtype)); - for (size_t i = MT_NULL+1; i < NUMMOBJTYPES; i++) + for (size_t i = 0; i < NUMMOBJTYPES; i++) { - if (mobjinfo[i].doomednum > 0 && mobjinfo[i].doomednum <= UINT16_MAX) + const INT32 doomednum = mobjinfo[i].doomednum; + + if (doomednum > 0 && doomednum <= MAXDOOMEDNUM) { - g_doomednum_to_mobjtype[ mobjinfo[i].doomednum ] = i; + if (g_doomednum_to_mobjtype[doomednum] == MT_NULL) + g_doomednum_to_mobjtype[doomednum] = (mobjtype_t)i; } } } @@ -10551,7 +10554,7 @@ void P_RespawnSpecials(void) if (mthing) { - mobjtype_t i; + mobjtype_t i = MT_NULL; x = mthing->x << FRACBITS; y = mthing->y << FRACBITS; ss = R_PointInSubsector(x, y); @@ -10987,7 +10990,7 @@ INT32 numhuntemeralds = 0; // void P_SpawnMapThing(mapthing_t *mthing) { - mobjtype_t i; + mobjtype_t i = MT_NULL; mobj_t *mobj; fixed_t x, y, z; subsector_t *ss; From 25dd3b49762cc979f3ffe52395ff43446d3f0b5a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 1 Dec 2025 23:00:22 +0100 Subject: [PATCH 16/39] Revert "Fix static memory being re-tagged as purgable" This reverts commit c544cf9a7cc5b6c21d20e71672273be02035df92. --- src/z_zone.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index 549696bd7..9e5b4f41e 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -651,9 +651,6 @@ void Z_ChangeTag(void *ptr, INT32 tag) I_Error("Internal memory management error: " "tried to make block purgable but it has no owner"); - // No, please, don't make my PU_STATIC patch NULL! It supposed to be always valid! - if (block->tag < 10) return; - block->tag = tag; } From 40bd3e5e19d7dd853d65b0661e0bebece028cd82 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 23:18:19 +0100 Subject: [PATCH 17/39] simplify opengl vsync set --- src/sdl/i_video.c | 14 +++++++------- src/sdl/ogl_sdl.c | 10 +--------- src/sdl/ogl_sdl.h | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c2d87e3f1..6be6bf638 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1426,7 +1426,7 @@ void I_FinishUpdate(void) #ifdef HWRENDER if (rendermode == render_opengl) { - OglSdlFinishUpdate(cv_vidwait.value); + OglSdlFinishUpdate(); return; } #endif @@ -2028,17 +2028,17 @@ UINT32 I_GetRefreshRate(void) static void Impl_SetVsync(void) { -#if SDL_VERSION_ATLEAST(2,0,18) - if (renderer) - SDL_RenderSetVSync(renderer, cv_vidwait.value); -#endif #ifdef HWRENDER - if (!renderer && rendermode == render_opengl && - sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) + if (rendermode == render_opengl && + sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) { SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); } #endif +#if SDL_VERSION_ATLEAST(2,0,18) + if (renderer) + SDL_RenderSetVSync(renderer, cv_vidwait.value); +#endif } void I_SetBorderlessWindow(void) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 319acab4b..4177c121a 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -241,22 +241,14 @@ boolean OglSdlSurface(INT32 w, INT32 h) \return void */ -void OglSdlFinishUpdate(boolean waitvbl) +void OglSdlFinishUpdate(void) { - static boolean oldwaitvbl = false; int sdlw, sdlh; #ifdef USE_FBO_OGL const boolean usefbo = UseScreenFBO(); #endif - if (oldwaitvbl != waitvbl) - { - SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); - } - - oldwaitvbl = waitvbl; - SDL_GetWindowSize(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index 6d614cd22..8dd2b9e0e 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -20,7 +20,7 @@ boolean OglSdlSurface(INT32 w, INT32 h); -void OglSdlFinishUpdate(boolean vidwait); +void OglSdlFinishUpdate(void); boolean VID_LoadOGLAPI(void); extern SDL_Renderer *renderer; From 1af1e42daba79f343dc0b42ba3b5788a1079b434 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Dec 2025 23:20:30 +0100 Subject: [PATCH 18/39] FBO: remove nvidia xwayland hack this has been a non issue since a while now, so can remove this (we shouldnt work around driver bugs anyways) --- src/sdl/ogl_sdl.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 4177c121a..9e51efdc4 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -63,18 +63,9 @@ PFNglGetString pglGetString; #endif #ifdef USE_FBO_OGL - -#if defined (__unix__) -static boolean xwaylandcrap = false; -#endif - boolean UseScreenFBO(void) { - return ((supportFBO && cv_glframebuffer.value && downsample) -#if defined (__unix__) - || (supportFBO && xwaylandcrap) -#endif - ); + return (supportFBO && cv_glframebuffer.value && downsample); } #endif @@ -201,17 +192,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) supportNPO2tex = true; glanisotropicmode_cons_t[1].value = maximumAnisotropy; - -#if defined (__unix__) -#ifdef USE_FBO_OGL - // TODO: delet this since nvidia fixed their shit on 575 - char videodriver[4] = {'S','D','L',0}; - if (supportFBO && strstr((const char*)gl_renderer, "NVIDIA") - && (*strncpy(videodriver, SDL_GetCurrentVideoDriver(), sizeof(videodriver)-1) != '\0') - && (strncasecmp("x11", videodriver, 4) == 0)) - xwaylandcrap = true; -#endif -#endif } SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); @@ -281,13 +261,6 @@ void OglSdlFinishUpdate(void) if (!I_CheckNativeRes() || WipeInAction) #endif HWR_DrawScreenFinalTexture(realwidth, realheight, false); - -#if defined (__unix__) -#ifdef USE_FBO_OGL - if (loaded_config) - xwaylandcrap = false; -#endif -#endif } #endif //HWRENDER From 7866b769cc542c6d9062cc022f4bf2d3afaa31e8 Mon Sep 17 00:00:00 2001 From: LJ Sonic Date: Sun, 21 Dec 2025 21:37:57 +0100 Subject: [PATCH 19/39] Do not archive table values for nil keys --- src/lua_script.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 96ce94a22..2aa88cd52 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1064,9 +1064,13 @@ static void ArchiveTables(UINT8 **p) { // Write key e = ArchiveValue(p, TABLESINDEX, -2); // key should be either a number or a string, ArchiveValue can handle this. - if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) + if (e == 1) + n++; // the table contained a new table we'll have to archive. :( + else if (e == 2) // invalid key type (function, thread, lightuserdata, or anything we don't recognise) { CONS_Alert(CONS_ERROR, "Index '%s' (%s) of table %d could not be archived!\n", lua_tostring(gL, -2), luaL_typename(gL, -2), i); + lua_pop(gL, 1); + continue; } else if (e == 3) // nil key due to invalid userdata. NOT an error. { @@ -1077,15 +1081,12 @@ static void ArchiveTables(UINT8 **p) // Write value e = ArchiveValue(p, TABLESINDEX, -1); if (e == 1) - { n++; // the table contained a new table we'll have to archive. :( - } else if (e == 2) // invalid value type - { CONS_Alert(CONS_ERROR, "Type of value for table %d entry '%s' (%s) could not be archived!\n", i, lua_tostring(gL, -2), luaL_typename(gL, -1)); - } lua_pop(gL, 1); + } lua_pop(gL, 1); WRITEUINT8(*p, ARCH_TEND); @@ -1276,13 +1277,21 @@ static void UnArchiveTables(UINT8 **p, boolean network) UINT8 ret; ret = UnArchiveValue(p, TABLESINDEX, network); - if (ret == 3) + if (ret == 1) // End of table + break; + else if (ret == 2) // Key contains a new table + n++; + else if (ret == 3) { //CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); lua_pushnil(gL); } - else if (ret == 1) // read key - break; + + if (lua_isnil(gL, -1)) // If key is nil, skip this entry + { + lua_pop(gL, 1); + continue; + } ret = UnArchiveValue(p, TABLESINDEX, network); if (ret == 1) @@ -1291,21 +1300,15 @@ static void UnArchiveTables(UINT8 **p, boolean network) lua_pop(gL, 1); // Pop key break; } + else if (ret == 2) // read value + n++; else if (ret == 3) { //CONS_Alert(CONS_WARNING,"Couldn't read mobj_t\n"); lua_pushnil(gL); } - else if (ret == 2) // read value - n++; - if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) - { - CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); - lua_pop(gL, 2); // pop key and value instead of setting them in the table, to prevent Lua panic errors - } - else - lua_rawset(gL, -3); + lua_rawset(gL, -3); } lua_pop(gL, 1); From 35e4f35f6e9867b3b143755a6c276a5946dee617 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 10:31:45 +0100 Subject: [PATCH 20/39] fix some shadowed variables, enable -Wshadow by default --- src/Makefile.d/versions.mk | 5 +---- src/hardware/hw_cache.cpp | 7 ++----- src/hardware/hw_main.cpp | 6 +++--- src/p_polyobj.c | 3 +-- src/r_segs.cpp | 10 +++++----- src/r_things.cpp | 2 +- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 451ff72e7..48964c39f 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs +WFLAGS:=-Wall -Wno-trigraphs -Wshadow ifndef GCC295 #WFLAGS+=-Wno-packed endif @@ -37,9 +37,6 @@ WFLAGS+=-Wfloat-equal ifndef GCC295 WFLAGS+=-Wendif-labels endif -ifdef GCC41 - WFLAGS+=-Wshadow -endif #WFLAGS+=-Wlarger-than-%len% WFLAGS+=-Wpointer-arith CWFLAGS+=-Wbad-function-cast diff --git a/src/hardware/hw_cache.cpp b/src/hardware/hw_cache.cpp index c20d7e9bb..09f4f1a7b 100644 --- a/src/hardware/hw_cache.cpp +++ b/src/hardware/hw_cache.cpp @@ -619,7 +619,6 @@ static void HWR_PrecacheLevelFlats(void) // lookup for flats that may´ve been already loaded // too lazy to make a hashtable or smth so unordered set will do :carbuncle: std::unordered_set flatpresent; - lumpnum_t lump; size_t i, j; INT32 k; @@ -649,9 +648,8 @@ static void HWR_PrecacheLevelFlats(void) const INT32 pic = ceiling ? sec->ceilingpic : sec->floorpic; const levelflat_t *levelflat = &levelflats[pic]; - lump = levelflat->lumpnum; - load_flat(lump, R_NoEncore(sec, ceiling)); + load_flat(levelflat->lumpnum, R_NoEncore(sec, ceiling)); if (levelflat->speed) // is it an animated flat ? { @@ -672,9 +670,8 @@ static void HWR_PrecacheLevelFlats(void) for (i = 0; i < numlevelflats; i++) { const levelflat_t *levelflat = &levelflats[i]; - lump = levelflat->lumpnum; - load_flat(lump, false); + load_flat(levelflat->lumpnum, false); if (levelflat->speed) // is it an animated flat ? { diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index afe899df2..70a5a3a8d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5538,7 +5538,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool player_t *viewplayer = &players[displayplayers[viewssnum]]; const float fpov = FixedToFloat(R_GetPlayerFov(viewplayer)); - auto reset_viewstate = [&](const float fpov) + auto reset_viewstate = [&]() { HWR_SetTransform(fpov); HWR_ClearSprites(); @@ -5558,7 +5558,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool currentportallist = &portallist; HWR_SetPortalState(GLPORTAL_SEARCH); - reset_viewstate(fpov); + reset_viewstate(); if (rootportal) { @@ -5584,7 +5584,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool // draw normal things in current frame in current incremented stencil buffer area HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); - reset_viewstate(fpov); + reset_viewstate(); if constexpr (Type == RenderViewpointType::kPortal) { diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 7b5135c9e..94c808b22 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1385,8 +1385,7 @@ static void Polyobj_rotateThings(polyobj_t *po, vector2_t origin, angle_t delta, if (mo->player) { - angle_t localangle = P_GetLocalAngle(mo->player); - P_ForceLocalAngle(mo->player, localangle + delta); + P_ForceLocalAngle(mo->player, P_GetLocalAngle(mo->player) + delta); } } } diff --git a/src/r_segs.cpp b/src/r_segs.cpp index c0aab2bfc..3fe8042ae 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -2229,12 +2229,12 @@ void R_StoreWallRange(INT32 start, INT32 stop) lowcutslope = std::max(worldbottomslope, worldlowslope) + viewz; highcutslope = std::min(worldtopslope, worldhighslope) + viewz; - auto check_fof_offscreen = [&](ffloor_t* rover, INT32 bottom, INT32 bottomslope, INT32 top, INT32 topslope) + auto check_fof_offscreen = [&](ffloor_t* rrover, INT32 bottom, INT32 bottomslope, INT32 top, INT32 topslope) { - return ((P_GetFFloorTopZAt (rover, segleft .x, segleft .y) <= bottom + viewz - && P_GetFFloorTopZAt (rover, segright.x, segright.y) <= bottomslope + viewz) - || ( P_GetFFloorBottomZAt (rover, segleft .x, segleft .y) >= top + viewz - && P_GetFFloorBottomZAt (rover, segright.x, segright.y) >= topslope + viewz)); + return ((P_GetFFloorTopZAt (rrover, segleft .x, segleft .y) <= bottom + viewz + && P_GetFFloorTopZAt (rrover, segright.x, segright.y) <= bottomslope + viewz) + || ( P_GetFFloorBottomZAt (rrover, segleft .x, segleft .y) >= top + viewz + && P_GetFFloorBottomZAt (rrover, segright.x, segright.y) >= topslope + viewz)); }; if (frontsector->ffloors && backsector->ffloors) diff --git a/src/r_things.cpp b/src/r_things.cpp index 489ce8911..b62d9e5d7 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1577,7 +1577,7 @@ static void R_ProjectSprite(mobj_t *thing) else blendmode = thing->blendmode; - if (thing->flags2 & MF2_SHADOW || thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) + if (thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) trans = tr_trans80; // because now the translucency is set through FF_TRANSMASK else if (thing->frame & FF_TRANSMASK) { From b0bf588c27363f192b14e2b795fa7f761fce297b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 10:52:21 +0100 Subject: [PATCH 21/39] fix some null pointer dereferences and enable -Wnull-dereference by default --- src/Makefile.d/versions.mk | 2 +- src/m_misc.c | 9 +++++---- src/s_sound.c | 3 +++ src/w_wad.c | 19 ++++++++++++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 48964c39f..149fb30fc 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wshadow +WFLAGS:=-Wall -Wno-trigraphs -Wshadow -Wnull-dereference ifndef GCC295 #WFLAGS+=-Wno-packed endif diff --git a/src/m_misc.c b/src/m_misc.c index cbc40d4e2..8c7b34163 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1346,14 +1346,15 @@ void M_MinimapGenerate(void) minigen = AM_MinimapGenerate(mul); if (minigen == NULL || minigen->buf == NULL) - goto failure; + { + CONS_Alert(CONS_ERROR, M_GetText("Couldn't create %s\n"), filepath); + return; + } M_CreateScreenShotPalette(); ret = M_SavePNG(filepath, minigen->buf, minigen->w, minigen->h, screenshot_palette); -failure: - if (minigen->buf != NULL) - free(minigen->buf); + free(minigen->buf); if (ret) { diff --git a/src/s_sound.c b/src/s_sound.c index 5bc830252..e8075469c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1491,6 +1491,9 @@ musicdef_t *S_FindMusicCredit(const char *musname) { def = S_GetMusicCredit(i); + if (!def) + continue; + if (hash != def->hash) continue; diff --git a/src/w_wad.c b/src/w_wad.c index 640ee0367..9be91c8ea 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1997,6 +1997,9 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num)); + if (rspr == NULL) + return W_CachePatchNum(W_GetNumForName("MISSING"), tag); + if (rspr->patches[idx] == NULL) { INT32 xpivot = 0, ypivot = 0; @@ -2612,6 +2615,9 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. UINT8 *wadData = (UINT8*)(W_CacheLumpNum(lumpnum, PU_LEVEL)); + if (wadData == NULL) + I_Error("vres_GetMap: Invalid WadData!\n"); + filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)wadData)->infotableofs)); i = LONG(((wadinfo_t *)wadData)->numlumps); @@ -2628,6 +2634,8 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) } vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); // Build the lumps, skipping over empty entries. for (i = 0, realentry = 0; i < numlumps; realentry++) @@ -2663,7 +2671,11 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) lumpnum_t lumppos = lumpnum + 1; for (i = LUMPNUM(lumppos); i < wadfiles[WADFILENUM(lumpnum)]->numlumps; i++, lumppos++, numlumps++) { - if (memcmp(W_CheckNameForNum(lumppos), "MAP", 3) == 0 || W_LumpLength(lumppos) == 0) + const char *name = W_CheckNameForNum(lumppos); + if (name == NULL) + continue; + + if (memcmp(name, "MAP", 3) == 0 || W_LumpLength(lumppos) == 0) { break; } @@ -2671,10 +2683,15 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) numlumps++; vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); + if (vlumps == NULL) + I_Error("vres_GetMap: Out of memory!\n"); + for (i = 0; i < numlumps; i++, lumpnum++) { // Check if it is map marker. It is not always first lump sadly, so we need to expect it anywhere const char *name = W_CheckNameForNum(lumpnum); + if (name == NULL) + continue; if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) { From 495c34dd401b54cc2ee3aef2e55ec98802a1dccb Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 13:02:21 +0100 Subject: [PATCH 22/39] fix gcc version detection fallback stuff latest_gcc_version should always just be X.x not X.x.x this broke some warning flags for me --- src/Makefile.d/detect.mk | 4 ++-- src/Makefile.d/versions.mk | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Makefile.d/detect.mk b/src/Makefile.d/detect.mk index dd31d2f3e..7ff978397 100644 --- a/src/Makefile.d/detect.mk +++ b/src/Makefile.d/detect.mk @@ -64,7 +64,7 @@ endif # This must have high to low order. gcc_versions:=\ - 151 150 15\ + 152 151 150 15\ 142 141 140 14\ 132 131 130 13\ 123 122 121 120 12\ @@ -77,7 +77,7 @@ gcc_versions:=\ 55 54 53 52 51 50\ 49 48 47 46 45 44 43 42 41 40 -latest_gcc_version:=15.1.1 +latest_gcc_version:=15.2 # Automatically set version flag, but not if one was # manually set. And don't bother if this is a clean only diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 149fb30fc..2a80cfa39 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wshadow -Wnull-dereference +WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference ifndef GCC295 #WFLAGS+=-Wno-packed endif @@ -37,6 +37,9 @@ WFLAGS+=-Wfloat-equal ifndef GCC295 WFLAGS+=-Wendif-labels endif +ifdef GCC41 + WFLAGS+=-Wshadow +endif #WFLAGS+=-Wlarger-than-%len% WFLAGS+=-Wpointer-arith CWFLAGS+=-Wbad-function-cast From a2616778cc06a2f2c42a09da6b6eb4342a6f6d9d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 15:06:50 +0100 Subject: [PATCH 23/39] fix another -Wnull-dereference warning --- src/w_wad.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/w_wad.c b/src/w_wad.c index 9be91c8ea..524bd97de 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1998,13 +1998,15 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num)); if (rspr == NULL) - return W_CachePatchNum(W_GetNumForName("MISSING"), tag); + return W_CachePatchNum(num, tag); if (rspr->patches[idx] == NULL) { INT32 xpivot = 0, ypivot = 0; ptr = (patch_t *)W_CachePatchNum(num, PU_PATCH); + if (ptr == NULL) + return W_CachePatchNum(num, tag); // >y pivot centered // >x pivot not centered From 9639ace28a4c2ad1e1587fda4928c2e9e3a791d6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 15:07:13 +0100 Subject: [PATCH 24/39] fix dedicated server build warnings --- src/android/i_system.c | 4 ---- src/dedicated/i_system.c | 10 +++------- src/i_system.h | 4 ++++ src/i_video.h | 11 +++++++++-- src/sdl/i_system.cpp | 18 ++++++++---------- src/sdl/i_video.c | 9 ++++++--- src/sdl/mixer_sound.c | 4 ++-- src/sdl/ogl_sdl.c | 3 +-- src/sdl/ogl_sdl.h | 4 +--- src/sdl/sdlmain.h | 18 ------------------ 10 files changed, 34 insertions(+), 51 deletions(-) diff --git a/src/android/i_system.c b/src/android/i_system.c index 102bff461..ef10df5b5 100644 --- a/src/android/i_system.c +++ b/src/android/i_system.c @@ -226,10 +226,6 @@ const char *I_LocateWad(void) return "/sdcard/srb2"; } -void I_GetJoystickEvents(void){} - -void I_GetJoystick2Events(void){} - char *I_GetEnv(const char *name) { LOGW("I_GetEnv() called?!"); diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 31eaf0346..4d52ffa70 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -167,6 +167,8 @@ static char returnWadPath[256]; #include "../i_video.h" #include "../i_sound.h" #include "../i_system.h" +#include "../i_time.h" +#include "../i_net.h" #include "../screen.h" //vid.WndParent #include "../d_net.h" #include "../g_game.h" @@ -196,8 +198,6 @@ UINT8 keyboard_started = false; #ifdef HAVE_TERMIOS // TERMIOS console code from Quake3: thank you! -boolean stdin_active = true; - typedef struct { size_t cursor; @@ -699,11 +699,7 @@ void I_JoyScale4(void) */ -void I_ShutdownJoystick(void) -{ -} - -void I_GetJoystickEvents(UINT8 index) +void I_ShutdownJoystick(UINT8 index) { (void)index; } diff --git a/src/i_system.h b/src/i_system.h index 7084c655f..97dfae9a1 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -29,6 +29,10 @@ extern "C" { */ #define MAX_QUIT_FUNCS 16 +void I_GetConsoleEvents(void); + +extern boolean consolevent; +extern boolean framebuffer; /** \brief Graphic system had started up */ diff --git a/src/i_video.h b/src/i_video.h index f28b5a601..9a43f82a7 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -125,8 +125,6 @@ boolean I_CheckNativeRes(void); void I_SetBorderlessWindow(void); -void I_HandleControllerHatRepeat(void); - #ifdef USE_FBO_OGL void RefreshOGLSDLSurface(void); @@ -135,6 +133,15 @@ boolean UseScreenFBO(void); extern boolean downsample; #endif +// So we can call this from i_video event loop +void I_ShutdownJoystick(UINT8 index); + +// Quick thing to make SDL_JOYDEVICEADDED events less of an abomination +void I_UpdateJoystickDeviceIndex(UINT8 player); +void I_UpdateJoystickDeviceIndices(UINT8 excludePlayer); + +void I_HandleControllerHatRepeat(void); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 0c024a5bd..66d8e4bb4 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -213,14 +213,12 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif -SDL_bool consolevent = SDL_FALSE; -SDL_bool framebuffer = SDL_FALSE; +boolean consolevent = false; +boolean framebuffer = false; UINT8 keyboard_started = false; #ifdef HAVE_TERMIOS // TERMIOS console code from Quake3: thank you! -SDL_bool stdin_active = SDL_TRUE; - typedef struct { size_t cursor; @@ -282,7 +280,7 @@ static void I_ShutdownConsole(void) if (consolevent) { I_OutputMsg("Shutdown tty console\n"); - consolevent = SDL_FALSE; + consolevent = false; tcsetattr(STDIN_FILENO, TCSADRAIN, &tty_tc); } } @@ -301,7 +299,7 @@ static void I_StartupConsole(void) framebuffer = static_cast( M_CheckParm("-framebuffer")); if (framebuffer) - consolevent = SDL_FALSE; + consolevent = false; if (!consolevent) return; @@ -309,7 +307,7 @@ static void I_StartupConsole(void) if (isatty(STDIN_FILENO)!=1) { I_OutputMsg("stdin is not a tty, tty console mode failed\n"); - consolevent = SDL_FALSE; + consolevent = false; return; } @@ -511,7 +509,7 @@ static void I_StartupConsole(void) if (gotConsole) { SetConsoleTitleA("SRB2Kart Console"); - consolevent = SDL_TRUE; + consolevent = true; } //Let get the real console HANDLE, because Mingw's Bash is bad! @@ -544,7 +542,7 @@ static inline void I_StartupConsole(void) framebuffer = M_CheckParm("-framebuffer"); if (framebuffer) - consolevent = SDL_FALSE; + consolevent = false; } static inline void I_ShutdownConsole(void){} #endif @@ -765,7 +763,7 @@ void I_JoyScale4(void) } // Cheat to get the device index for a joystick handle -INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev) +static INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev) { SDL_Joystick *joystick = NULL; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6be6bf638..72354ca1e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -155,9 +155,12 @@ static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; // SDL2 vars -SDL_Window *window = NULL; -SDL_Renderer *renderer = NULL; +static SDL_Window *window = NULL; +static SDL_Renderer *renderer = NULL; static SDL_Texture *texture = NULL; +#ifdef HWRENDER +static SDL_GLContext sdlglcontext = NULL; +#endif static SDL_bool havefocus = SDL_TRUE; static const char *fallback_resolution_name = "Fallback"; @@ -1426,7 +1429,7 @@ void I_FinishUpdate(void) #ifdef HWRENDER if (rendermode == render_opengl) { - OglSdlFinishUpdate(); + OglSdlFinishUpdate(window); return; } #endif diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 529b47399..272e48a1b 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -461,7 +461,7 @@ void *I_GetSfx(sfxinfo_t *sfx) gme_track_info(emu, &info, 0); len = (info->play_length * 441 / 10) << 2; - mem = Z_Malloc(len, PU_SOUND, 0); + mem = Z_Malloc(len, PU_SOUND, NULL); gme_play(emu, len >> 1, mem); gme_free_info(info); @@ -499,7 +499,7 @@ void *I_GetSfx(sfxinfo_t *sfx) gme_track_info(emu, &info, 0); len = (info->play_length * 441 / 10) << 2; - mem = Z_Malloc(len, PU_SOUND, 0); + mem = Z_Malloc(len, PU_SOUND, NULL); gme_play(emu, len >> 1, mem); gme_free_info(info); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 9e51efdc4..d50cdbe93 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -72,7 +72,6 @@ boolean UseScreenFBO(void) /** \brief SDL video display surface */ INT32 oglflags = 0; -SDL_GLContext sdlglcontext = NULL; void *GetGLFunc(const char *proc) { @@ -221,7 +220,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) \return void */ -void OglSdlFinishUpdate(void) +void OglSdlFinishUpdate(SDL_Window *window) { int sdlw, sdlh; diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index 8dd2b9e0e..9bdebc715 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -20,11 +20,9 @@ boolean OglSdlSurface(INT32 w, INT32 h); -void OglSdlFinishUpdate(void); +void OglSdlFinishUpdate(SDL_Window *window); boolean VID_LoadOGLAPI(void); -extern SDL_Renderer *renderer; -extern SDL_GLContext sdlglcontext; extern Uint16 realwidth; extern Uint16 realheight; diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index c711d68d7..e5bdca395 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -23,9 +23,6 @@ extern "C" { #endif -extern SDL_bool consolevent; -extern SDL_bool framebuffer; - #include "../m_fixed.h" // SDL2 stub macro @@ -67,21 +64,6 @@ extern SDLJoyInfo_t JoyInfo[4]; //MAXSPLITSCREENPLAYERS #define SDL_JDEADZONE 153 #undef SDL_JDEADZONE -// So we can call this from i_video event loop -void I_ShutdownJoystick(UINT8 index); - -// Cheat to get the device index for a game controller handle -INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev); - -// Quick thing to make SDL_JOYDEVICEADDED events less of an abomination -void I_UpdateJoystickDeviceIndex(UINT8 player); -void I_UpdateJoystickDeviceIndices(UINT8 excludePlayer); - -void I_GetConsoleEvents(void); - -// Needed for some WIN32 functions -extern SDL_Window *window; - #ifdef __cplusplus } // extern "C" #endif From 67e74b5874a4edc19c504947421151eab77f307c Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 15:13:13 +0100 Subject: [PATCH 25/39] fix w_wad oopsie --- src/w_wad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 524bd97de..7e1ec30df 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1998,7 +1998,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num)); if (rspr == NULL) - return W_CachePatchNum(num, tag); + return W_CachePatchNum(W_GetNumForName("MISSING"), tag); if (rspr->patches[idx] == NULL) { @@ -2006,7 +2006,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) ptr = (patch_t *)W_CachePatchNum(num, PU_PATCH); if (ptr == NULL) - return W_CachePatchNum(num, tag); + return W_CachePatchNum(W_GetNumForName("MISSING"), tag); // >y pivot centered // >x pivot not centered From c0cce90e601c1948ba82bcfeda35093801712b11 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Dec 2025 15:34:18 +0100 Subject: [PATCH 26/39] properly handle getcwd error in IdentifyVersion if getcwd fails, the buffer contents will be undefined so we shall just overwrite it again with "." --- src/d_main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index c46ef0c44..f37d70a2c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1186,17 +1186,13 @@ static void IdentifyVersion(void) #endif char tempsrb2path[256] = "."; - getcwd(tempsrb2path, 256); + if (getcwd(tempsrb2path, 256) == NULL) + strcpy(tempsrb2path, "."); // get the current directory (possible problem on NT with "." as current dir) if (!srb2waddir) { - if (tempsrb2path[0]) - srb2waddir = tempsrb2path; - else - { - srb2waddir = "."; - } + srb2waddir = tempsrb2path; } #if (1) // reduce the amount of findfile by only using full cwd in this func From a2de1e24c5a835ab052238ad61ba7d0a7b47a53d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Dec 2025 17:46:37 +0100 Subject: [PATCH 27/39] d_cliserv: fix casts from nan to int type in few cases the files totalsize might be 0, which results in a nan, casting that to int type is undefined behavior --- src/d_clisrv.c | 68 ++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 6cf50a4d3..d4983daa2 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -365,7 +365,7 @@ void SendNetXCmdForPlayer(UINT8 playerid, netxcmd_t id, const void *param, size_ CONS_Alert(CONS_NOTICE, M_GetText("NetXCmd buffer full, delaying netcmd %d... (size: %d, needed: %s)\n"), id, localtextcmd[playerid][0], sizeu1(nparam)); if (buf == NULL) { - textcmdbuf[playerid] = Z_Malloc(sizeof(textcmdbuf_t), PU_STATIC, NULL); + textcmdbuf[playerid] = (textcmdbuf_t*)Z_Malloc(sizeof(textcmdbuf_t), PU_STATIC, NULL); textcmdbuf[playerid]->cmd[0] = 0; textcmdbuf[playerid]->next = NULL; WriteNetXCmd(textcmdbuf[playerid]->cmd, id, param, nparam); @@ -377,7 +377,7 @@ void SendNetXCmdForPlayer(UINT8 playerid, netxcmd_t id, const void *param, size_ if (buf->cmd[0]+2+nparam > MAXTEXTCMD) { - buf->next = Z_Malloc(sizeof(textcmdbuf_t), PU_STATIC, NULL); + buf->next = (textcmdbuf_t*)Z_Malloc(sizeof(textcmdbuf_t), PU_STATIC, NULL); buf->next->cmd[0] = 0; buf->next->next = NULL; WriteNetXCmd(buf->next->cmd, id, param, nparam); @@ -454,13 +454,13 @@ static UINT8* D_GetTextcmd(tic_t tic, INT32 playernum) // If we don't have an entry for the tic, make it. if (!textcmdtic) { - textcmdtic = *tctprev = Z_Calloc(sizeof (textcmdtic_t), PU_STATIC, NULL); + textcmdtic = *tctprev = (textcmdtic_t*)Z_Calloc(sizeof (textcmdtic_t), PU_STATIC, NULL); textcmdtic->tic = tic; } // If we don't have an entry for the player, make it. if (!textcmdtic->playercmds[playernum]) - textcmdtic->playercmds[playernum] = Z_Calloc(MAXTEXTCMD, PU_STATIC, NULL); + textcmdtic->playercmds[playernum] = (UINT8*)Z_Calloc(MAXTEXTCMD, PU_STATIC, NULL); return textcmdtic->playercmds[playernum]; } @@ -1141,7 +1141,7 @@ typedef enum static void GetPackets(void); static cl_mode_t cl_mode = CL_SEARCHING; -static UINT16 cl_lastcheckedfilecount = 0; // used for full file list +static UINT16 cl_lastcheckedfilecount = 0; // used for full file list // Player name send/load @@ -1182,7 +1182,7 @@ static void CV_LoadPlayerNames(UINT8 **p) // // Keep the local client informed of our status. // -static inline void CL_DrawConnectionStatus(void) +static void CL_DrawConnectionStatus(void) { INT32 ccstime = I_GetTime(); @@ -1217,21 +1217,23 @@ static inline void CL_DrawConnectionStatus(void) case CL_DOWNLOADSAVEGAME: if (filedownload.current != -1) { - UINT32 currentsize = fileneeded[filedownload.current].currentsize; - UINT32 totalsize = fileneeded[filedownload.current].totalsize; - INT32 dldlength; + INT32 dldlength = 0; + fileneeded_t *file = &fileneeded[filedownload.current]; + UINT32 currentsize = file->currentsize; + UINT32 totalsize = file->totalsize; cltext = M_GetText("Downloading game state..."); Net_GetNetStat(); - dldlength = (INT32)((currentsize/(double)totalsize) * 256); + if (totalsize != 0) + dldlength = (INT32)((currentsize/(double)totalsize) * 256); if (dldlength > 256) dldlength = 256; V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, 256, 8, 111); V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, dldlength, 8, 96); V_DrawString(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, - va(" %4uK/%4uK",currentsize>>10,totalsize>>10)); + va(" %4uK/%4uK", currentsize>>10, totalsize>>10)); V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, va("%3.1fK/s ", ((double)getbps)/1024)); @@ -1270,29 +1272,30 @@ static inline void CL_DrawConnectionStatus(void) { if (cl_mode == CL_CHECKFILES) { - INT32 totalfileslength; + INT32 totalfileslength = 0; INT32 checkednum = 0; INT32 i; V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24-24, V_YELLOWMAP|MENUCAPS, "Press ESC to abort"); - //ima just count files here + // ima just count files here for (i = 0; i < fileneedednum; i++) if (fileneeded[i].status != FS_NOTCHECKED) checkednum++; // Loading progress V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24-32, V_YELLOWMAP|MENUCAPS, "Checking server addons..."); - totalfileslength = (INT32)((checkednum/(double)(fileneedednum)) * 256); + if (fileneedednum != 0) + totalfileslength = (INT32)((checkednum/(double)fileneedednum) * 256); M_DrawTextBox(BASEVIDWIDTH/2-128-8, BASEVIDHEIGHT-24-8, 32, 1); V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, 256, 8, 175); V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, totalfileslength, 8, 160); V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE|MENUCAPS, - va(" %2u/%2u Files",checkednum,fileneedednum)); + va(" %2u/%2u Files", checkednum, fileneedednum)); } else if (cl_mode == CL_LOADFILES) { - INT32 totalfileslength; + INT32 totalfileslength = 0; INT32 loadcompletednum = 0; INT32 i; @@ -1305,12 +1308,13 @@ static inline void CL_DrawConnectionStatus(void) // Loading progress V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24-32, V_YELLOWMAP|MENUCAPS, "Loading server addons..."); - totalfileslength = (INT32)((loadcompletednum/(double)(fileneedednum)) * 256); + if (fileneedednum != 0) + totalfileslength = (INT32)((loadcompletednum/(double)fileneedednum) * 256); M_DrawTextBox(BASEVIDWIDTH/2-128-8, BASEVIDHEIGHT-24-8, 32, 1); V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, 256, 8, 175); V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, totalfileslength, 8, 160); V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE|MENUCAPS, - va(" %2u/%2u Files",loadcompletednum,fileneedednum)); + va(" %2u/%2u Files", loadcompletednum, fileneedednum)); } else if (cl_mode == CL_VIEWSERVER) { @@ -1438,19 +1442,22 @@ static inline void CL_DrawConnectionStatus(void) } else if (filedownload.current != -1) { - INT32 dldlength; - INT32 totalfileslength; - UINT32 totaldldsize; + INT32 dldlength = 0; + INT32 totalfileslength = 0; + UINT32 totaldldsize = 0; static char tempname[28]; fileneeded_t *file = &fileneeded[filedownload.current]; char *filename = file->filename; + UINT32 currentsize = file->currentsize; + UINT32 totalsize = file->totalsize; // Draw the bottom box. M_DrawTextBox(BASEVIDWIDTH/2-128-8, BASEVIDHEIGHT-58-8, 32, 1); V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-58-14, V_YELLOWMAP|MENUCAPS, "Press ESC to abort"); Net_GetNetStat(); - dldlength = (INT32)((file->currentsize/(double)file->totalsize) * 256); + if (totalsize != 0) + dldlength = (INT32)((currentsize/(double)totalsize) * 256); if (dldlength > 256) dldlength = 256; V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-58, 256, 8, 175); @@ -1483,29 +1490,30 @@ static inline void CL_DrawConnectionStatus(void) V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-58-22, V_YELLOWMAP|MENUCAPS, va(M_GetText("\"%s\""), tempname)); V_DrawString(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-58, V_20TRANS|V_MONOSPACE|MENUCAPS, - va(" %4uK/%4uK",file->currentsize>>10,file->totalsize>>10)); + va(" %4uK/%4uK", currentsize>>10, totalsize>>10)); V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-58, V_20TRANS|V_MONOSPACE|MENUCAPS, - va("%3.1fK/s ", ((double)getbps)/1024)); + va("%3.1fK/s ", ((double)getbps)/1024.0)); // Download progress - if (file->currentsize != file->totalsize) - totaldldsize = filedownload.completedsize+file->currentsize; //Add in single file progress download if applicable + if (currentsize != totalsize) + totaldldsize = filedownload.completedsize+currentsize; // Add in single file progress download if applicable else totaldldsize = filedownload.completedsize; V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24-14, V_YELLOWMAP|MENUCAPS, "Overall Download Progress"); - totalfileslength = (INT32)((totaldldsize/(double)filedownload.totalsize) * 256); + if (filedownload.totalsize != 0) + totalfileslength = (INT32)((totaldldsize/(double)filedownload.totalsize) * 256); M_DrawTextBox(BASEVIDWIDTH/2-128-8, BASEVIDHEIGHT-24-8, 32, 1); V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, 256, 8, 175); V_DrawFill(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, totalfileslength, 8, 160); - if (filedownload.totalsize>>20 >= 10) //display in MB if over 10MB + if (filedownload.totalsize>>20 >= 10) // display in MB if over 10MB V_DrawString(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE|MENUCAPS, - va(" %4uM/%4uM",totaldldsize>>20,filedownload.totalsize>>20)); + va(" %4uM/%4uM", totaldldsize>>20, filedownload.totalsize>>20)); else V_DrawString(BASEVIDWIDTH/2-128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE|MENUCAPS, - va(" %4uK/%4uK",totaldldsize>>10,filedownload.totalsize>>10)); + va(" %4uK/%4uK", totaldldsize>>10, filedownload.totalsize>>10)); V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE|MENUCAPS, va("%2u/%2u Files ", filedownload.completednum, filedownload.totalnum)); From 242dee499d516daf80d0205c864a9eda7612a052 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 2 Jan 2026 18:34:00 +0100 Subject: [PATCH 28/39] initialize more globals that have been missed --- src/d_main.c | 2 +- src/d_net.c | 4 ++-- src/filesrch.c | 7 +++++-- src/g_game.c | 6 +++--- src/hardware/r_opengl/r_opengl.c | 2 +- src/i_time.c | 2 +- src/k_hud.c | 2 +- src/r_things.cpp | 4 ++-- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index f37d70a2c..ab5fe7a10 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -639,7 +639,7 @@ void D_SRB2Loop(void) tic_t entertic = 0, oldentertics = 0, realtics = 0, rendertimeout = INFTICS; double deltatics = 0.0; double deltasecs = 0.0; - UINT64 precision; + UINT64 precision = 0; boolean interp = false; boolean doDisplay = false; diff --git a/src/d_net.c b/src/d_net.c index 59b31a1fb..c0d8c667b 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -59,7 +59,7 @@ static INT16 reboundsize[MAXREBOUND]; static INT32 rebound_head, rebound_tail; /// \brief max length per packet -INT16 hardware_MAXPACKETLENGTH; +INT16 hardware_MAXPACKETLENGTH = 0; boolean (*I_NetGet)(void) = NULL; void (*I_NetSend)(void) = NULL; @@ -96,7 +96,7 @@ INT32 ticruned = 0, ticmiss = 0; // globals INT32 getbps = 0, sendbps = 0; -float lostpercent = 0, duppercent = 0, gamelostpercent = 0; +float lostpercent = 0.0f, duppercent = 0.0f, gamelostpercent = 0.0f; INT32 packetheaderlength = 0; boolean Net_GetNetStat(void) diff --git a/src/filesrch.c b/src/filesrch.c index f7ff612bd..e34b51c47 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -49,7 +49,7 @@ size_t menupathindex[menudepth] = {}; size_t menudepthleft = menudepth; char menusearchbuf[MAXSTRINGLENGTH+1]; -textinput_t menusearch; +textinput_t menusearch = {}; char **dirmenu = NULL, **coredirmenu = NULL; // core only local for this file size_t sizedirmenu = 0, sizecoredirmenu = 0; // ditto @@ -271,10 +271,13 @@ static boolean filemenucmp(char *haystack, char *needle) { static char localhaystack[128]; strlcpy(localhaystack, haystack, 128); + if (!cv_addons_search_case.value) strupr(localhaystack); + if (cv_addons_search_type.value) - return (strstr(localhaystack, needle) != 0); + return (strstr(localhaystack, needle) != NULL); + return (!strncmp(localhaystack, needle, menusearch.length)); } diff --git a/src/g_game.c b/src/g_game.c index 2d2a49461..892579163 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -132,7 +132,7 @@ UINT8 skincolor_bluering = SKINCOLOR_STEEL; tic_t countdowntimer = 0; boolean countdowntimeup = false; -cutscene_t *cutscenes[128]; +cutscene_t *cutscenes[128] = {}; INT16 nextmapoverride = 0; boolean skipstats = false; @@ -144,7 +144,7 @@ mobj_t *blueflag = NULL; mapthing_t *rflagpoint = NULL; mapthing_t *bflagpoint = NULL; -struct quake quake; +struct quake quake = {}; // Map Header Information mapheader_t* mapheaderinfo[NUMMAPS] = {}; @@ -228,7 +228,7 @@ tic_t racecountdown = 0, exitcountdown = 0; // for racing fixed_t gravity = 0; fixed_t mapobjectscale = FRACUNIT; -struct maplighting maplighting; +struct maplighting maplighting = {}; INT16 autobalance = 0; //for CTF team balance INT16 teamscramble = 0; //for CTF team scramble diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 94656e843..edd2f51a7 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -745,7 +745,7 @@ typedef struct gl_shaderstate_s static gl_shaderstate_t gl_shaderstate; // Shader info -static float shader_leveltime = 0; +static float shader_leveltime = 0.0f; static float shader_light_x = 0.0f; static float shader_light_y = 0.0f; static float shader_light_z = 0.0f; diff --git a/src/i_time.c b/src/i_time.c index 09d5fb3fa..6e5cc3a4d 100644 --- a/src/i_time.c +++ b/src/i_time.c @@ -21,7 +21,7 @@ #include "m_fixed.h" #include "i_system.h" -timestate_t g_time; +timestate_t g_time = {}; static CV_PossibleValue_t timescale_cons_t[] = {{FRACUNIT/20, "MIN"}, {20*FRACUNIT, "MAX"}, {0, NULL}}; consvar_t cv_timescale = {"timescale", "1.0", CV_NETVAR|CV_CHEAT|CV_FLOAT, timescale_cons_t, NULL, FRACUNIT, NULL, NULL, 0, 0, NULL}; diff --git a/src/k_hud.c b/src/k_hud.c index 1d9b7fe5b..f4f7f1c1a 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -568,7 +568,7 @@ static patch_t *kp_racefinish[6]; static patch_t *kp_positionnum[NUMPOSNUMS][NUMPOSFRAMES]; static patch_t *kp_winnernum[NUMPOSFRAMES]; -patch_t *kp_facenum[MAXPLAYERS+1]; +patch_t *kp_facenum[MAXPLAYERS+1] = {}; static patch_t *kp_facehighlight[8]; static patch_t *kp_rankbumper; diff --git a/src/r_things.cpp b/src/r_things.cpp index b62d9e5d7..cab9512e3 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -658,7 +658,7 @@ void R_DrawMaskedColumn(drawcolumndata_t* dc, column_t *column) dc->texturemid = basetexturemid; } -INT32 lengthcol; // column->length : for flipped column function pointers and multi-patch on 2sided wall = texture->height +INT32 lengthcol = 0; // column->length : for flipped column function pointers and multi-patch on 2sided wall = texture->height static void R_DrawFlippedMaskedColumn(drawcolumndata_t* dc, column_t *column) { @@ -3086,7 +3086,7 @@ static void R_DrawMaskedList(drawnode_t* head) void R_DrawMasked(maskcount_t* masks, INT32 nummasks) { INT32 i; - drawnode_t *heads; /**< Drawnode lists; as many as number of views/portals. */ + drawnode_t *heads = NULL; /**< Drawnode lists; as many as number of views/portals. */ heads = static_cast(calloc(nummasks, sizeof(drawnode_t))); From edbebbf082ba1b078e9f5c22fa8d60bd00fcb609 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 2 Jan 2026 18:31:02 +0100 Subject: [PATCH 29/39] fix wrong type for K_DriftSparkColor all the colour stuff is still a bit of a mess, but generally its handled as an uint8 --- src/k_hud.c | 10 +++++----- src/k_kart.c | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/k_hud.c b/src/k_hud.c index f4f7f1c1a..d0146a38e 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -1065,7 +1065,7 @@ static void K_initKartHUD(void) } if (timeinmap > 113 || forceshowhud) - hudtrans = cv_translucenthud.value; + hudtrans = (UINT8)cv_translucenthud.value; else if (timeinmap > 105) hudtrans = ((((INT32)timeinmap) - 105)*cv_translucenthud.value)/(113-105); else @@ -1122,9 +1122,9 @@ void K_KartPlayerHUDUpdate(player_t *player) UINT8 K_GetHudColor(void) { if (cv_colorizedhud.value && cv_colorizedhudcolor.value) - return cv_colorizedhudcolor.value; + return (UINT8)cv_colorizedhudcolor.value; - return ((stplyr && gamestate == GS_LEVEL) ? stplyr->skincolor : cv_playercolor.value); + return ((stplyr && gamestate == GS_LEVEL) ? stplyr->skincolor : (UINT8)cv_playercolor.value); } boolean K_UseColorHud(void) @@ -1526,7 +1526,7 @@ static void K_drawKartItem(void) { localcolor = K_GetHudColor(); - switch((stplyr->kartstuff[k_itemroulette] % (14*3)) / 3) + switch ((stplyr->kartstuff[k_itemroulette] % (14*3)) / 3) { // Each case is handled in threes, to give three frames of in-game time to see the item on the roulette case 0: // Sneaker @@ -2195,7 +2195,7 @@ static boolean K_drawKartPositionFaces(void) return true; if (!LUA_HudEnabled(hud_minirankings)) - return false; // Don't proceed but still return true for free play above if HUD is disabled. + return false; // Don't proceed but still return true for free play above if HUD is disabled. for (j = 0; j < numplayersingame; j++) { diff --git a/src/k_kart.c b/src/k_kart.c index 767e041a1..bb4da62a5 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3103,17 +3103,18 @@ static mobj_t *K_SpawnKartMissile(mobj_t *source, mobjtype_t type, angle_t an, I return NULL; } -static UINT16 K_DriftSparkColor(player_t *player, INT32 charge) +static UINT8 K_DriftSparkColor(player_t *player, INT32 charge) { - UINT16 color = SKINCOLOR_NONE; + UINT8 color = SKINCOLOR_NONE; + const INT32 sparkval = K_GetKartDriftSparkValue(player); - if (charge >= K_GetKartDriftSparkValue(player)*4) + if (charge >= sparkval*4) { color = K_RainbowColor(); } - else if (charge >= K_GetKartDriftSparkValue(player)*2) + else if (charge >= sparkval*2) { - if (charge <= (K_GetKartDriftSparkValue(player)*2)+(24*3)) + if (charge <= (sparkval*2)+(24*3)) color = SKINCOLOR_RASPBERRY; // transition else color = SKINCOLOR_KETCHUP; From e1f0089627031b2f8f4f9e6e35d43e20cc6449e1 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 8 Jan 2026 00:33:43 +0100 Subject: [PATCH 30/39] enable "Wzero-as-null-pointer-constant", fix cases of it prevent ambiguity shoutout blankart for making me aware this exists --- src/Makefile.d/versions.mk | 2 +- src/blua/lstrlib.c | 2 +- src/blua/luaconf.h | 6 +++--- src/d_clisrv.c | 14 +++++++------- src/d_main.c | 3 ++- src/d_netcmd.c | 14 +++++++------- src/f_finale.c | 2 +- src/g_demo.c | 2 +- src/g_game.c | 14 +++++++------- src/hardware/hw_batching.c | 2 +- src/hardware/hw_md2load.c | 28 ++++++++++++++-------------- src/hardware/hw_md3load.c | 24 ++++++++++++------------ src/hardware/hw_model.c | 18 +++++++++--------- src/hardware/r_opengl/r_opengl.c | 12 ++++++------ src/http-mserv.c | 8 ++++---- src/lua_mobjlib.c | 2 +- src/m_cheat.c | 8 ++++---- src/m_cond.c | 2 +- src/m_menu.c | 8 ++++---- src/m_perfstats.c | 18 +++++++++--------- src/p_enemy.c | 8 ++++---- src/p_mobj.c | 24 ++++++++++++------------ src/p_setup.c | 4 ++-- src/p_spec.c | 6 +++--- src/r_main.cpp | 2 +- src/r_skins.c | 2 +- src/r_things.cpp | 4 ++-- src/s_sound.c | 6 +++--- src/s_sound.h | 4 ++-- src/strcasestr.c | 8 ++++---- src/w_wad.c | 18 +++++++++--------- src/y_inter.c | 8 ++++---- 32 files changed, 142 insertions(+), 141 deletions(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 2a80cfa39..e57119fb9 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,7 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference +WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference -Wzero-as-null-pointer-constant ifndef GCC295 #WFLAGS+=-Wno-packed endif diff --git a/src/blua/lstrlib.c b/src/blua/lstrlib.c index e2fd23604..6fe279bcb 100644 --- a/src/blua/lstrlib.c +++ b/src/blua/lstrlib.c @@ -527,7 +527,7 @@ static int str_find_aux (lua_State *L, int find) { if (find) { lua_pushinteger(L, s1-s+1); /* start */ lua_pushinteger(L, res-s); /* end */ - return push_captures(&ms, NULL, 0) + 2; + return push_captures(&ms, NULL, NULL) + 2; } else return push_captures(&ms, s1, res); diff --git a/src/blua/luaconf.h b/src/blua/luaconf.h index 76a798751..22fa8bf53 100644 --- a/src/blua/luaconf.h +++ b/src/blua/luaconf.h @@ -772,10 +772,10 @@ union luai_Cast { double l_d; long l_l; }; #include #if defined(__GNUC__) -#define l_likely(x) (__builtin_expect(((x) != 0), 1)) -#define l_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#define l_likely(x) (__builtin_expect(!!(x), 1)) +#define l_unlikely(x) (__builtin_expect(!!(x), 0)) #else -#define l_likely(x) (x) +#define l_likely(x) (x) #define l_unlikely(x) (x) #endif diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d4983daa2..68ab08c5a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -332,7 +332,7 @@ void RegisterNetXCmd(netxcmd_t id, void (*cmd_f)(const UINT8 **p, INT32 playernu #ifdef PARANOIA if (id >= MAXNETXCMD) I_Error("Command id %d too big", id); - if (listnetxcmd[id] != 0) + if (listnetxcmd[id] != NULL) I_Error("Command id %d already used", id); #endif listnetxcmd[id] = cmd_f; @@ -1236,7 +1236,7 @@ static void CL_DrawConnectionStatus(void) va(" %4uK/%4uK", currentsize>>10, totalsize>>10)); V_DrawRightAlignedString(BASEVIDWIDTH/2+128, BASEVIDHEIGHT-24, V_20TRANS|V_MONOSPACE, - va("%3.1fK/s ", ((double)getbps)/1024)); + va("%3.1fK/s ", ((double)getbps)/1024.0)); } else cltext = M_GetText("Waiting to download game state..."); @@ -1963,7 +1963,7 @@ static boolean SV_ResendingSavegameToAnyone(void) static void SV_SendSaveGame(INT32 node, boolean resending) { size_t length, compressedlen; - savebuffer_t save = {0}; + savebuffer_t save = {}; UINT8 *compressedsave; UINT8 *buffertosend; @@ -2033,7 +2033,7 @@ static consvar_t cv_dumpconsistency = {"dumpconsistency", "Off", CV_NETVAR, CV_O static void SV_SavedGame(void) { size_t length; - savebuffer_t save = {0}; + savebuffer_t save = {}; char tmpsave[264]; if (!cv_dumpconsistency.value) @@ -2073,7 +2073,7 @@ static void SV_SavedGame(void) static void CL_LoadReceivedSavegame(boolean reloading) { - savebuffer_t save = {0}; + savebuffer_t save = {}; size_t length, decompressedlen; char tmpsave[264]; @@ -7237,7 +7237,7 @@ void CL_ClearRewinds(void) rewind_t *CL_SaveRewindPoint(size_t demopos) { - savebuffer_t save = {0}; + savebuffer_t save = {}; rewind_t *rewind; if (rewindhead && rewindhead->leveltime + REWIND_POINT_INTERVAL > leveltime) @@ -7260,7 +7260,7 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) rewind_t *CL_RewindToTime(tic_t time) { - savebuffer_t save = {0}; + savebuffer_t save = {}; rewind_t *rewind; while (rewindhead && rewindhead->leveltime > time) diff --git a/src/d_main.c b/src/d_main.c index ab5fe7a10..3e474cec3 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1865,7 +1865,8 @@ void D_SRB2Main(void) if (M_CheckParm("-warp") && M_IsNextParm()) { const char *word = M_GetNextParm(); - pstartmap = G_FindMapByNameOrCode(word, 0); + pstartmap = G_FindMapByNameOrCode(word, NULL); + if (! pstartmap) I_Error("Cannot find a map remotely named '%s'\n", word); else diff --git a/src/d_netcmd.c b/src/d_netcmd.c index c669da59b..781120be2 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -249,7 +249,7 @@ consvar_t cv_competitionboxes = {"competitionboxes", "Random", CV_NETVAR|CV_CHEA #ifdef SEENAMES static CV_PossibleValue_t seenames_cons_t[] = {{0, "Off"}, {1, "Colorless"}, {2, "Team"}, {3, "Ally/Foe"}, {0, NULL}}; -consvar_t cv_seenames = {"seenames", "Off", CV_SAVE, seenames_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_seenames = {"seenames", "Off", CV_SAVE, seenames_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_allowseenames = {"allowseenames", "No", CV_NETVAR, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif @@ -458,16 +458,16 @@ consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0 static CV_PossibleValue_t pingmeasurement_cons_t[] = {{0, "Frames"}, {1, "Milliseconds"}, {0, NULL}}; consvar_t cv_pingmeasurement = {"pingmeasurement", "Frames", CV_SAVE, pingmeasurement_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pingicon = {"pingicon", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t cv_pingstyle_cons_t[] = {{0, "New"}, {1, "Old"}, {0, NULL}}; -consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_pingstyle = {"pingstyle", "New", CV_SAVE, cv_pingstyle_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_luaimmersion = {"luaimmersion", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showviewpointtext = {"showviewpointtext", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_showdownloadprompt = {"showdownloadprompt", "On", CV_SAVE, CV_OnOff, 0, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_showdownloadprompt = {"showdownloadprompt", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // Intermission time Tails 04-19-2002 static CV_PossibleValue_t inttime_cons_t[] = {{0, "MIN"}, {3600, "MAX"}, {0, NULL}}; @@ -2789,7 +2789,7 @@ static void Command_Map_f(void) // G_TOLFlag handles both multiplayer gametype and ignores it for !multiplayer else { - if (!mapheaderinfo[newmapnum-1]) + if (mapheaderinfo[newmapnum-1] == NULL) { CONS_Alert(CONS_WARNING, M_GetText("Invalid mapheaderinfo for Course %s (%s)\n"), realmapname, G_BuildMapName(newmapnum)); return; diff --git a/src/f_finale.c b/src/f_finale.c index 801af8ab5..32ed8c3ec 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1318,7 +1318,7 @@ boolean F_ContinueResponder(event_t *event) keypressed = true; imcontinuing = true; continuetime = TICRATE; - S_StartSound(0, sfx_itemup); + S_StartSound(NULL, sfx_itemup); return true; } diff --git a/src/g_demo.c b/src/g_demo.c index 312e57530..ede5adf18 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -76,7 +76,7 @@ static tic_t demostarttime; // for comparative timing purposes //@TODO put these all in a struct for namespacing purposes? static char demoname[128]; -savebuffer_t demobuf = {0}; +savebuffer_t demobuf = {}; static UINT8 *demotime_p, *demoinfo_p; static UINT8 *demoend; static UINT8 demoflags; diff --git a/src/g_game.c b/src/g_game.c index 892579163..27a2922a8 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3501,7 +3501,7 @@ void G_LoadGameData(void) INT32 i, j; UINT8 modded = false; UINT8 rtemp; - savebuffer_t save = {0}; + savebuffer_t save = {}; //For records tic_t rectime; @@ -3634,7 +3634,7 @@ void G_SaveGameData(boolean force) size_t length; INT32 i, j; UINT8 btemp; - savebuffer_t save = {0}; + savebuffer_t save = {}; (void)force; char backupfile[MAX_WADPATH+4]; @@ -3805,7 +3805,7 @@ void G_LoadGame(UINT32 slot, INT16 mapoverride) size_t length; char vcheck[VERSIONSIZE]; char savename[255]; - savebuffer_t save = {0}; + savebuffer_t save = {}; // memset savedata to all 0, fixes calling perfectly valid saves corrupt because of bots memset(&savedata, 0, sizeof(savedata)); @@ -3891,7 +3891,7 @@ void G_SaveGame(UINT32 savegameslot) boolean saved; char savename[256] = ""; const char *backup; - savebuffer_t save = {0}; + savebuffer_t save = {}; sprintf(savename, savegamename, savegameslot); backup = va("%s",savename); @@ -4161,7 +4161,7 @@ static void measurekeywords(mapsearchfreq_t *fr, PU_STATIC, NULL); for (qp = strtok(va("%s", q), " "); qp && fr->total < 255; - qp = strtok(0, " ")) + qp = strtok(NULL, " ")) { if (( sp = strcasestr(s, qp) )) { @@ -4242,7 +4242,7 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, { newmapnum = mapnum; newmapname = realmapname; - realmapname = 0; + realmapname = NULL; Z_Free(apromapname); if (!wanttable) break; @@ -4263,7 +4263,7 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, { apromapnum = mapnum; apromapname = realmapname; - realmapname = 0; + realmapname = NULL; } } else/* ...match individual keywords */ diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 4d6b1ea6e..8bf7f7375 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -391,7 +391,7 @@ void HWR_RenderBatches(void) nextSurfaceInfo = nextEntry->surf; if (nextPolyFlags & PF_NoTexture) - nextTexture = 0; + nextTexture = NULL; if (useshader && currentShader != nextShader) { diff --git a/src/hardware/hw_md2load.c b/src/hardware/hw_md2load.c index 3805deffb..d28ebf058 100644 --- a/src/hardware/hw_md2load.c +++ b/src/hardware/hw_md2load.c @@ -274,7 +274,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!f) return NULL; - retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); + retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, NULL); //size_t fileLen; @@ -288,13 +288,13 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) { texPos++; namelen = strlen(texPos) + 1; - texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, 0); + texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, NULL); strcpy(texturefilename, texPos); } else { namelen = strlen(fileName) + 1; - texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, 0); + texturefilename = (char*)Z_Malloc(namelen, PU_CACHE, NULL); strcpy(texturefilename, fileName); } @@ -316,7 +316,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) header = (md2header_t*)buffer; retModel->numMeshes = 1; // MD2 only has one mesh - retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, 0); + retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * retModel->numMeshes, ztag, NULL); retModel->meshes[0].numFrames = header->numFrames; // const float WUNITS = 1.0f; // float dataScale = WUNITS; @@ -332,7 +332,7 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) if (retModel->numMaterials <= 0) // Always at least one skin, duh retModel->numMaterials = 1; - retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, NULL); // int t; for (t = 0; t < retModel->numMaterials; t++) @@ -409,9 +409,9 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) float *uvptr; dataScale = 0.015624f; // 1 / 64.0f - retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, 0); + retModel->meshes[0].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*header->numFrames, ztag, NULL); retModel->meshes[0].numVertices = header->numXYZ; - retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, NULL); ptr = (char*)frames; for (i = 0; i < header->numFrames; i++, ptr += header->framesize) @@ -423,12 +423,12 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) md2vertex_t *vertex; md2frame_t *framePtr = (md2frame_t*)ptr; - retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, 0); - retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, 0); + retModel->meshes[0].tinyframes[i].vertices = (short*)Z_Malloc(sizeof(short) * 3 * header->numXYZ, ztag, NULL); + retModel->meshes[0].tinyframes[i].normals = (char*)Z_Malloc(sizeof(char) * 3 * header->numXYZ, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[0].tinyframes[i].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*header->numVerts, ztag); - retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, 0); + retModel->meshes[0].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * header->numTris, ztag, NULL); vertptr = retModel->meshes[0].tinyframes[i].vertices; normptr = retModel->meshes[0].tinyframes[i].normals; @@ -484,8 +484,8 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) char *ptr; retModel->meshes[0].numVertices = header->numTris * 3; - retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, 0); - retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, 0); + retModel->meshes[0].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*header->numFrames, ztag, NULL); + retModel->meshes[0].uvs = (float*)Z_Malloc(sizeof(float) * 2 * retModel->meshes[0].numVertices, ztag, NULL); trisPtr = tris; uvptr = retModel->meshes[0].uvs; @@ -507,8 +507,8 @@ model_t *MD2_LoadModel(const char *fileName, int ztag, boolean useFloat) md2vertex_t *vertex; md2frame_t *framePtr = (md2frame_t*)ptr; - retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); - retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, 0); + retModel->meshes[0].frames[i].normals = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, NULL); + retModel->meshes[0].frames[i].vertices = (float*)Z_Malloc(sizeof(float) * 3 * header->numTris * 3, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[0].frames[i].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*header->numTris*3, ztag); //float *vertptr, *normptr; diff --git a/src/hardware/hw_md3load.c b/src/hardware/hw_md3load.c index 53f6034c0..b536c7e73 100644 --- a/src/hardware/hw_md3load.c +++ b/src/hardware/hw_md3load.c @@ -168,7 +168,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) if (!f) return NULL; - retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, 0); + retModel = (model_t*)Z_Calloc(sizeof(model_t), ztag, NULL); // find length of file fseek(f, 0, SEEK_END); @@ -201,7 +201,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) if (retModel->numMaterials <= 0) // Always at least one skin, duh retModel->numMaterials = 1; - retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, 0); + retModel->materials = (material_t*)Z_Calloc(sizeof(material_t)*retModel->numMaterials, ztag, NULL); for (t = 0; t < retModel->numMaterials; t++) { @@ -225,7 +225,7 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) retModel->materials[t].spheremap = false; } - retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, 0); + retModel->meshes = (mesh_t*)Z_Calloc(sizeof(mesh_t)*retModel->numMeshes, ztag, NULL); matCount = 0; for (i = 0, surfEnd = 0; i < mdh->numSurfaces; i++) @@ -298,9 +298,9 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) unsigned short *indexptr; md3Triangle *mdT; - retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, 0); + retModel->meshes[i].tinyframes = (tinyframe_t*)Z_Calloc(sizeof(tinyframe_t)*mdS->numFrames, ztag, NULL); retModel->meshes[i].numVertices = mdS->numVerts; - retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, 0); + retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numVerts, ztag, NULL); for (j = 0; j < mdS->numFrames; j++) { short *vertptr; @@ -308,12 +308,12 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) // char *tanptr; int k; md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); - retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, 0); - retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, 0); + retModel->meshes[i].tinyframes[j].vertices = (short*)Z_Malloc(sizeof(short)*3*mdS->numVerts, ztag, NULL); + retModel->meshes[i].tinyframes[j].normals = (char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag, NULL); // if (retModel->materials[0].lightmap) // retModel->meshes[i].tinyframes[j].tangents = (char*)malloc(sizeof(char));//(char*)Z_Malloc(sizeof(char)*3*mdS->numVerts, ztag); - retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, 0); + retModel->meshes[i].indices = (unsigned short*)Z_Malloc(sizeof(unsigned short) * 3 * mdS->numTriangles, ztag, NULL); vertptr = retModel->meshes[i].tinyframes[j].vertices; normptr = retModel->meshes[i].tinyframes[j].normals; @@ -374,16 +374,16 @@ model_t *MD3_LoadModel(const char *fileName, int ztag, boolean useFloat) int k; retModel->meshes[i].numVertices = mdS->numTriangles * 3;//mdS->numVerts; - retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, 0); - retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, 0); + retModel->meshes[i].frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t)*mdS->numFrames, ztag, NULL); + retModel->meshes[i].uvs = (float*)Z_Malloc(sizeof(float)*2*mdS->numTriangles*3, ztag, NULL); for (j = 0; j < mdS->numFrames; j++) { float *vertptr; float *normptr; md3Vertex *mdV = (md3Vertex*)((char*)mdS + mdS->offsetXYZNormal + (mdS->numVerts*j*sizeof(md3Vertex))); - retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); - retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, 0); + retModel->meshes[i].frames[j].vertices = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, NULL); + retModel->meshes[i].frames[j].normals = (float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag, NULL); // if (retModel->materials[i].lightmap) // retModel->meshes[i].frames[j].tangents = (float*)malloc(sizeof(float));//(float*)Z_Malloc(sizeof(float)*3*mdS->numTriangles*3, ztag); vertptr = retModel->meshes[i].frames[j].vertices; diff --git a/src/hardware/hw_model.c b/src/hardware/hw_model.c index 8698365e4..274c23394 100644 --- a/src/hardware/hw_model.c +++ b/src/hardware/hw_model.c @@ -189,7 +189,7 @@ model_t *LoadModel(const char *filename, int ztag) return NULL; } - model->mdlFilename = (char*)Z_Malloc(strlen(filename)+1, ztag, 0); + model->mdlFilename = (char*)Z_Malloc(strlen(filename)+1, ztag, NULL); strcpy(model->mdlFilename, filename); Optimize(model); @@ -237,7 +237,7 @@ void GenerateVertexNormals(model_t *model) { mdlframe_t *frame = &mesh->frames[j]; int memTag = PU_STATIC; - float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, 0); + float *newNormals = (float*)Z_Malloc(sizeof(float)*3*mesh->numTriangles*3, memTag, NULL); int k; float *vertPtr = frame->vertices; float *oldNormals; @@ -309,7 +309,7 @@ static boolean AddMaterialToList(materiallist_t **head, material_t *material) } // Didn't find it, so add to the list - newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, 0); + newMatNode = (materiallist_t*)Z_Malloc(sizeof(materiallist_t), PU_CACHE, NULL); newMatNode->material = material; ListAdd(newMatNode, (listitem_t**)head); return true; @@ -351,7 +351,7 @@ void Optimize(model_t *model) } memTag = PU_STATIC; - newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, 0); + newMeshes = (mesh_t*)Z_Calloc(sizeof(mesh_t) * numMeshes, memTag, NULL); i = 0; for (node = matListHead; node; node = node->next) @@ -377,14 +377,14 @@ void Optimize(model_t *model) newMesh->numFrames = 1; newMesh->numTriangles = numTriangles; newMesh->numVertices = numTriangles * 3; - newMesh->uvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, 0); - newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, 0); + newMesh->uvs = (float*)Z_Malloc(sizeof(float)*2*numTriangles*3, memTag, NULL); + newMesh->frames = (mdlframe_t*)Z_Calloc(sizeof(mdlframe_t), memTag, NULL); curFrame = &newMesh->frames[0]; curFrame->material = curMat; - curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); - curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, 0); - curFrame->colors = (char*)Z_Malloc(sizeof(char)*4*numTriangles*3, memTag, 0); + curFrame->normals = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, NULL); + curFrame->vertices = (float*)Z_Malloc(sizeof(float)*3*numTriangles*3, memTag, NULL); + curFrame->colors = (char*)Z_Malloc(sizeof(char)*4*numTriangles*3, memTag, NULL); // Now traverse the meshes of the model, adding in // vertices/normals/uvs that match the current material diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index edd2f51a7..fab0a8a6d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -98,10 +98,10 @@ static size_t textureBufferSize = 0; static LTListItem *LightTablesTail = NULL; static LTListItem *LightTablesHead = NULL; -static RGBA_t screenPalette[256] = {0}; // the palette for the postprocessing step in palette rendering +static RGBA_t screenPalette[256] = {}; // the palette for the postprocessing step in palette rendering static GLuint screenPaletteTex = 0; // 1D texture containing the screen palette static GLuint paletteLookupTex = 0; // 3D texture containing RGB -> palette index lookup table -RGBA_t myPaletteData[256] = {0}; // the palette for converting textures to RGBA +RGBA_t myPaletteData[256] = {}; // the palette for converting textures to RGBA static GLint gltexformat = GL_RGB5_A1; GLint screen_width = 0; // used by Draw2DLine() @@ -127,9 +127,9 @@ GLuint gl_num_extensions; int majorGL = 0, minorGL = 0; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) -GLfloat modelMatrix[16] = {0}; -GLfloat projMatrix[16] = {0}; -static GLint viewport[4]; +GLfloat modelMatrix[16] = {}; +GLfloat projMatrix[16] = {}; +static GLint viewport[4]; #ifdef USE_FBO_OGL enum @@ -171,7 +171,7 @@ boolean supportstencil = false; // flush all of the stored textures, leaving them unavailable at times such as between levels // These need to start at 0 and be set to their number, and be reset to 0 when deleted so that Intel GPUs // can know when the textures aren't there, as textures are always considered resident in their virtual memory -static GLuint screenTextures[NUMSCREENTEXTURES] = {0}; +static GLuint screenTextures[NUMSCREENTEXTURES] = {}; #define byte2float(byte) (GLfloat)(byte / 255.0f) diff --git a/src/http-mserv.c b/src/http-mserv.c index 8e35f905d..fd63c5f69 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -189,7 +189,7 @@ HMS_connect (const char *format, ...) seek = strlen(hms_api) + 1;/* + '/' */ va_start (ap, format); - url = malloc(seek + vsnprintf(0, 0, format, ap) + sizeof HMS_QUERY_VERSION - 1 + token_length + 1); + url = malloc(seek + vsnprintf(NULL, 0, format, ap) + sizeof HMS_QUERY_VERSION - 1 + token_length + 1); va_end (ap); sprintf(url, "%s/", hms_api); @@ -471,8 +471,8 @@ HMS_fetch_servers (msg_server_t *list, int query_id) *end = '\0'; address = strtok(p, " "); - port = strtok(0, " "); - contact = strtok(0, ""); + port = strtok(NULL, " "); + contact = strtok(NULL, ""); if (address && port) { @@ -539,7 +539,7 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size) if (HMS_do(hms)) { version = strtok(hms->buffer, " "); - version_name = strtok(0, "\n"); + version_name = strtok(NULL, "\n"); if (version && version_name) { diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 45c3a9f19..9bd5f5203 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -475,7 +475,7 @@ int mobj_localskin_setter(lua_State *L) } else { - mo->localskin = 0; + mo->localskin = NULL; mo->skinlocal = false; } } diff --git a/src/m_cheat.c b/src/m_cheat.c index 2890c7196..58bc1401d 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -80,7 +80,7 @@ static UINT8 cheatf_warp(void) if (success) { G_SaveGameData(true); //G_SetGameModified(false); - S_StartSound(0, sfx_kc42); + S_StartSound(NULL, sfx_kc42); } // Refresh secrets menu existing. @@ -117,13 +117,13 @@ static UINT8 cheatf_devmode(void) #endif static cheatseq_t cheat_warp = { - 0, cheatf_warp, + NULL, cheatf_warp, //{ SCRAMBLE('r'), SCRAMBLE('e'), SCRAMBLE('d'), SCRAMBLE('x'), SCRAMBLE('v'), SCRAMBLE('i'), 0xff } { SCRAMBLE('b'), SCRAMBLE('a'), SCRAMBLE('n'), SCRAMBLE('a'), SCRAMBLE('n'), SCRAMBLE('a'), 0xff } }; static cheatseq_t cheat_warp_joy = { - 0, cheatf_warp, + NULL, cheatf_warp, /*{ SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_UPARROW), SCRAMBLE(KEY_RIGHTARROW), SCRAMBLE(KEY_RIGHTARROW), SCRAMBLE(KEY_UPARROW), SCRAMBLE(KEY_LEFTARROW), SCRAMBLE(KEY_UPARROW), @@ -136,7 +136,7 @@ static cheatseq_t cheat_warp_joy = { #ifdef DEVELOP static cheatseq_t cheat_devmode = { - 0, cheatf_devmode, + NULL, cheatf_devmode, { SCRAMBLE('d'), SCRAMBLE('e'), SCRAMBLE('v'), SCRAMBLE('m'), SCRAMBLE('o'), SCRAMBLE('d'), SCRAMBLE('e'), 0xff } }; #endif diff --git a/src/m_cond.c b/src/m_cond.c index acf78e6ef..126d5a49a 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -235,7 +235,7 @@ void M_AddRawCondition(UINT8 set, UINT8 id, conditiontype_t c, INT32 r, INT16 x1 wnum = conditionSets[set - 1].numconditions; num = ++conditionSets[set - 1].numconditions; - conditionSets[set - 1].condition = Z_Realloc(conditionSets[set - 1].condition, sizeof(condition_t)*num, PU_STATIC, 0); + conditionSets[set - 1].condition = Z_Realloc(conditionSets[set - 1].condition, sizeof(condition_t)*num, PU_STATIC, NULL); cond = conditionSets[set - 1].condition; diff --git a/src/m_menu.c b/src/m_menu.c index c2978fe82..55112356b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5385,7 +5385,7 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na { CONS_Printf("custom settings menu initiation\n"); for (CVARSETUP = 0; CVARSETUP < MAXMENUCCVARS; ++CVARSETUP) - OP_CustomCvarMenu[CVARSETUP] = (menuitem_t){IT_DISABLED, NULL, "", 0, INT16_MAX}; + OP_CustomCvarMenu[CVARSETUP] = (menuitem_t){IT_DISABLED, NULL, "", NULL, INT16_MAX}; } if (category && ((ccvarposition == 0 && category[0] != '\0') || !fasticmp(category, OP_CustomCvarMenu[ccvarlaststheader].text))) @@ -7494,7 +7494,7 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) if ((lumpnum = W_CheckNumForName(va("%sE", mapname))) != LUMPERROR) mappingforencore = (patch_t *)W_CachePatchNum(lumpnum, PU_PATCH);*/ - V_DrawFixedPatch((x+w)<>1), (staty+67)<>1, 0, statlr, flashcol); V_DrawFixedPatch((statx+40+GRIDSTATOFFSET)<>1, 0, statud, flashcol); // bg - V_DrawFixedPatch(((statx+48+GRIDSTATOFFSET)<>1), (staty+73)<>1, 0, statbg, 0); + V_DrawFixedPatch(((statx+48+GRIDSTATOFFSET)<>1), (staty+73)<>1, 0, statbg, NULL); for (i = 0; i < numskins; i++) // draw the stat dots { @@ -8218,7 +8218,7 @@ static void M_DrawSetupMultiPlayerMenu(void) V_DrawFixedPatch((statx+64)<flags2 & MF2_FRET) { P_SetMobjState(actor, S_BLACKEGG_DESTROYPLAT1); - S_StartSound(0, sfx_s3k53); + S_StartSound(NULL, sfx_s3k53); actor->flags2 &= ~MF2_FRET; return; } @@ -6011,7 +6011,7 @@ void A_Boss7Chase(void *thing) { // Punch him! P_SetMobjState(actor, actor->info->meleestate); - S_StartSound(0, sfx_begrnd); // warning sound + S_StartSound(NULL, sfx_begrnd); // warning sound return; } } @@ -6057,7 +6057,7 @@ void A_Boss7Chase(void *thing) case 2: // Homing Missile A_FaceTarget(actor); P_SetMobjState(actor, actor->info->missilestate); - S_StartSound(0, sfx_beflap); + S_StartSound(NULL, sfx_beflap); break; } @@ -10739,7 +10739,7 @@ void A_BrakChase(void *thing) { actor->reactiontime--; if (actor->reactiontime == 0 && actor->type == MT_CYBRAKDEMON) - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } // modify target threshold diff --git a/src/p_mobj.c b/src/p_mobj.c index ad7982d87..581edf2f0 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3606,10 +3606,10 @@ static void P_CalculatePrecipFloor(precipmobj_t *mobj) // Just the identification of a precip thinker. The thinker // should never actually be called! // -void P_NullPrecipThinker(precipmobj_t *mobj) +FUNCNORETURN void P_NullPrecipThinker(precipmobj_t *mobj) { (void)mobj; - I_Assert("P_NullPrecipThinker should not be called" == 0); + I_Error("P_NullPrecipThinker should not be called"); } boolean P_PrecipThinker(precipmobj_t *mobj) @@ -4012,7 +4012,7 @@ static void P_Boss3Thinker(mobj_t *mobj) if ((UINT32)mobj->extravalue1 + TICRATE*2 < leveltime) { mobj->extravalue1 = (INT32)leveltime; - S_StartSound(0, sfx_buzz1); + S_StartSound(NULL, sfx_buzz1); } // If in the center, check to make sure @@ -4631,7 +4631,7 @@ static void P_Boss7Thinker(mobj_t *mobj) if (mobj->health > 0) mobj->health--; - S_StartSound(0, (mobj->health) ? sfx_behurt : sfx_bedie2); + S_StartSound(NULL, (mobj->health) ? sfx_behurt : sfx_bedie2); mobj->reactiontime /= 3; @@ -4670,7 +4670,7 @@ static void P_Boss7Thinker(mobj_t *mobj) INT32 i; mobj->state->nextstate = mobj->info->painstate; // Reset - S_StartSound(0, sfx_bedeen); + S_StartSound(NULL, sfx_bedeen); for (i = 0; i < MAXPLAYERS; i++) { @@ -4694,7 +4694,7 @@ static void P_Boss7Thinker(mobj_t *mobj) mobj->state->nextstate = mobj->info->spawnstate; // Laugh - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } } } @@ -4714,7 +4714,7 @@ static void P_Boss7Thinker(mobj_t *mobj) var2 = 2*TICRATE + (80<<16); A_LobShot(mobj); - S_StartSound(0, sfx_begoop); + S_StartSound(NULL, sfx_begoop); } } else if (mobj->state == &states[S_BLACKEGG_SHOOT2]) @@ -4738,7 +4738,7 @@ static void P_Boss7Thinker(mobj_t *mobj) S_StopSound(missile); if (leveltime & 1) - S_StartSound(0, sfx_beshot); + S_StartSound(NULL, sfx_beshot); } else if (mobj->state == &states[S_BLACKEGG_JUMP1] && mobj->tics == 1) { @@ -4871,7 +4871,7 @@ static void P_Boss7Thinker(mobj_t *mobj) fixed_t x,y,z; mobj_t *mo2; - S_StartSound(0, sfx_befall); + S_StartSound(NULL, sfx_befall); z = mobj->floorz; for (j = 0; j < 2; j++) @@ -4910,13 +4910,13 @@ static void P_Boss7Thinker(mobj_t *mobj) P_DamageMobj(players[i].mo, mobj, mobj, 1); // Laugh - S_StartSound(0, sfx_bewar1 + P_RandomKey(4)); + S_StartSound(NULL, sfx_bewar1 + P_RandomKey(4)); } P_SetMobjState(mobj, mobj->info->spawnstate); } else if (mobj->state == &states[mobj->info->deathstate] && mobj->tics == mobj->state->tics) - S_StartSound(0, sfx_bedie1 + (P_RandomFixed() & 1)); + S_StartSound(NULL, sfx_bedie1 + (P_RandomFixed() & 1)); } // Metal Sonic battle boss @@ -10711,7 +10711,7 @@ void P_SpawnPlayer(INT32 playernum) // the dead body mobj retains the skin through the 'spritedef' override). mobj->skin = &skins[p->skin]; - mobj->localskin = (p->localskin ? K_GetPlayerSkin(p) : 0); + mobj->localskin = (p->localskin ? K_GetPlayerSkin(p) : NULL); mobj->skinlocal = p->skinlocal; mobj->health = p->health; diff --git a/src/p_setup.c b/src/p_setup.c index bf40afe9d..612530882 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1022,7 +1022,7 @@ void P_WriteThings(lumpnum_t lumpnum) size_t i, length; mapthing_t *mt; UINT8 *data; - savebuffer_t save = {0}; + savebuffer_t save = {}; INT16 temp; data = W_CacheLumpNum(lumpnum, PU_LEVEL); @@ -1166,7 +1166,7 @@ static void P_LoadLineDefs2(void) for (; i--; ld++) { ld->frontsector = sides[ld->sidenum[0]].sector; //e6y: Can't be -1 here - ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : 0; + ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : NULL; // Repeat count for midtexture if ((ld->flags & ML_EFFECT5) && (ld->sidenum[1] != 0xffff)) diff --git a/src/p_spec.c b/src/p_spec.c index 66901d234..5045a8287 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4579,8 +4579,8 @@ static inline void P_AddFFloorToList(sector_t *sec, ffloor_t *ffloor) if (!sec->ffloors) { sec->ffloors = ffloor; - ffloor->next = 0; - ffloor->prev = 0; + ffloor->next = NULL; + ffloor->prev = NULL; return; } @@ -4588,7 +4588,7 @@ static inline void P_AddFFloorToList(sector_t *sec, ffloor_t *ffloor) rover->next = ffloor; ffloor->prev = rover; - ffloor->next = 0; + ffloor->next = NULL; } /** Adds a 3Dfloor. diff --git a/src/r_main.cpp b/src/r_main.cpp index fecfba580..e3bfb83fa 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1087,7 +1087,7 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) ret = &subsectors[nodenum & ~NF_SUBSECTOR]; for (i = 0; i < ret->numlines; i++) if (P_PointOnLineSide(x, y, segs[ret->firstline + i].linedef) != segs[ret->firstline + i].side) - return 0; + return NULL; return ret; } diff --git a/src/r_skins.c b/src/r_skins.c index 538b8c38a..41971788c 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -302,7 +302,7 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) if (player->mo) { - player->mo->localskin = 0; + player->mo->localskin = NULL; player->mo->skinlocal = false; } } diff --git a/src/r_things.cpp b/src/r_things.cpp index cab9512e3..77b02b78c 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -532,8 +532,8 @@ void R_ClearSprites(void) visspritecount = numvisiblesprites = clippedvissprites = 0; } -static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {0}; -static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {0}; +static INT16 *vissprite_clipbot[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {}; +static INT16 *vissprite_cliptop[MAXVISSPRITES >> VISSPRITECHUNKBITS] = {}; static void R_AllocVisSpriteChunkMemory(UINT32 chunk) { diff --git a/src/s_sound.c b/src/s_sound.c index e8075469c..7f931671d 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -884,7 +884,7 @@ static void S_StopChannel(INT32 cnum) if (cnum != i && c->sfxinfo == channels[i].sfxinfo) break; - c->sfxinfo = 0; + c->sfxinfo = NULL; } c->origin = NULL; @@ -1271,7 +1271,7 @@ static musicdef_t *S_AddMusicCredit(void) return &musicdefs[chunk][i]; } -struct cursongcredit cursongcredit = {0}; // Currently displayed song credit info +struct cursongcredit cursongcredit = {}; // Currently displayed song credit info static boolean ReadMusicDefFields(UINT16 wadnum, int line, char *stoken, musicdef_t **defp) { @@ -1704,7 +1704,7 @@ static void S_UnloadMusic(void) music.flags = 0; music.looping = false; - music_refade_cv = 0; + music_refade_cv = NULL; } static boolean S_PlayMusic(boolean looping, UINT32 fadeinms) diff --git a/src/s_sound.h b/src/s_sound.h index 9e0296d2b..c7f487e92 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -253,9 +253,9 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 void S_ChangeMusicSpecial (const char *mmusic); -void S_SetRestoreMusicFadeInCvar (consvar_t *cvar); +void S_SetRestoreMusicFadeInCvar(consvar_t *cvar); #define S_ClearRestoreMusicFadeInCvar() \ - S_SetRestoreMusicFadeInCvar(0) + S_SetRestoreMusicFadeInCvar(NULL) int S_GetRestoreMusicFadeIn (void); // Stops the music. diff --git a/src/strcasestr.c b/src/strcasestr.c index d24a36e54..f50141dcf 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -73,8 +73,8 @@ nongnu_strcasestr (const char *s, const char *q) up = strchr(s, uc); lp = strchr(s, lc); - if (!( (intptr_t)up|(intptr_t)lp )) - return 0; + if (up == NULL || lp == NULL) + return NULL; if (!lp || ( up && up < lp )) { @@ -100,12 +100,12 @@ nongnu_strcasestr (const char *s, const char *q) if (trycmp(ppa, cpa, q, qn) == 0) return (*ppa); - if (!( (intptr_t)up|(intptr_t)lp )) + if (up == NULL || lp == NULL) break; if (!(*ppa) || ( (*ppb) && (*ppb) < (*ppa) )) swapp(&ppa, &ppb, &cpa, &cpb); } - return 0; + return NULL; } diff --git a/src/w_wad.c b/src/w_wad.c index 7e1ec30df..432f1421f 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -697,12 +697,12 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lump_p->name, '\0', 9); // Making sure they're initialized to 0. Is it necessary? @@ -1667,9 +1667,9 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si if (fread(rawData, 1, rawSize, handle) < rawSize) I_Error("wad %d, lump %d: cannot read compressed data", wad, lump); - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; + strm.zalloc = NULL; + strm.zfree = NULL; + strm.opaque = NULL; strm.total_in = strm.avail_in = rawSize; strm.total_out = strm.avail_out = decSize; @@ -2238,14 +2238,14 @@ static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. if (*trimname) // Ignore directories, well kinda { - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lumpname, '\0', 9); // Making sure they're initialized to 0. Is it necessary? @@ -2483,14 +2483,14 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist) strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1); // Strip away file address and extension for the 8char name. - if ((trimname = strrchr(fullname, '/')) != 0) + if ((trimname = strrchr(fullname, '/')) != NULL) trimname++; else trimname = fullname; // Care taken for root files. if (*trimname) // Ignore directories, well kinda { - if ((dotpos = strrchr(trimname, '.')) == 0) + if ((dotpos = strrchr(trimname, '.')) == NULL) dotpos = fullname + strlen(fullname); // Watch for files without extension. memset(lumpname, '\0', 9); // Making sure they're initialized to 0. Is it necessary? diff --git a/src/y_inter.c b/src/y_inter.c index d35fa7825..27e794ffc 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -104,7 +104,7 @@ typedef struct } y_voteclient; // votescreen stuff -votescreen_t VoteScreen = {0}; +votescreen_t VoteScreen = {}; static y_votelvlinfo levelinfo[5]; static y_voteclient voteclient; @@ -1093,7 +1093,7 @@ void Y_VoteDrawer(void) V_DrawSmallScaledPatch(BASEVIDWIDTH-100, y, V_SNAPTORIGHT, pic); else { - V_DrawFixedPatch((BASEVIDWIDTH-20)< Date: Thu, 8 Jan 2026 00:27:06 +0100 Subject: [PATCH 31/39] K_SpawnSparkleTrail: check for blend effect apply outside the loop tiny optimization --- src/k_kart.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index bb4da62a5..342414738 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3595,6 +3595,8 @@ void K_SpawnSparkleTrail(mobj_t *mo) I_Assert(mo != NULL); I_Assert(!P_MobjWasRemoved(mo)); + const boolean shouldblend = (mo->player && K_PlayerEffectsShouldBlend(mo->player)); + for (i = 0; i < 3; i++) { fixed_t newx = mo->x + mo->momx + (P_RandomRange(-rad, rad)<color = mo->color; - if (mo->player && K_PlayerEffectsShouldBlend(mo->player)) + if (shouldblend) sparkle->blendmode = AST_ADD; } From d938e38ad3d00a8fb0797d1d489446e026a4ab83 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 8 Jan 2026 00:26:02 +0100 Subject: [PATCH 32/39] Acessability: add basic "reducevfx" toggle to disable/reduce certain effects toggles certain effects, which may be troublesome to some players -disabled hyudoro flashing, instead makes player translucent - Makes rainbow colour effects, such as invul, change colours very slowly - Disables underwater and heatwave screen effects - Disables palette flashing - Disables vhs effect not the most pretty implementation, but im lazy and this works feel free to suggest more things --- src/g_game.h | 1 + src/hardware/hw_main.cpp | 24 ++++- src/hardware/hw_md2.c | 11 ++- src/k_kart.c | 11 ++- src/p_mobj.c | 3 +- src/r_things.cpp | 11 ++- src/v_video.c | 197 ++++++++++++++++++++------------------- 7 files changed, 150 insertions(+), 108 deletions(-) diff --git a/src/g_game.h b/src/g_game.h index 509749c5f..6ecc69dfa 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -130,6 +130,7 @@ extern consvar_t cv_spinoutroll; extern consvar_t cv_squishdance, cv_squishdancespeed; extern consvar_t cv_playerblendeffects; +extern consvar_t cv_reducevfx; extern consvar_t cv_cechotoggle; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 70a5a3a8d..1622a4528 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3786,8 +3786,15 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) blend = HWR_GetBlendModeFlag(blendmode)|PF_Occlude; } - if (cv_playerfade.value && sprmo->player) - Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); + if (sprmo->player) + { + // make hyu´d players translucent with reducevfx, could be done better, but im lazy as crap + if (cv_reducevfx.value && sprmo->player->kartstuff[k_hyudorotimer] > 0) + Surf.PolyColor.s.alpha = FixedMul(FRACUNIT/2, Surf.PolyColor.s.alpha); + + if (cv_playerfade.value) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); + } if (HWR_UseShader()) { @@ -4076,8 +4083,15 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) blend = HWR_GetBlendModeFlag(blendmode)|PF_Occlude; } - if (cv_playerfade.value && sprmo->player) - Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); + if (sprmo->player) + { + // make hyu´d players translucent with reducevfx, could be done better, but im lazy as crap + if (cv_reducevfx.value && sprmo->player->kartstuff[k_hyudorotimer] > 0) + Surf.PolyColor.s.alpha = FixedMul(FRACUNIT/2, Surf.PolyColor.s.alpha); + + if (cv_playerfade.value) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); + } if (HWR_UseShader()) { @@ -6100,7 +6114,7 @@ static void HWR_DoPostProcessor(void) const camera_t *thiscam = &camera[0]; // Not supported in splitscreen - someone want to add support? - const boolean screenwave = (!splitscreen && (thiscam->postimg & POSTIMG_WATER || thiscam->postimg & POSTIMG_HEAT)); + const boolean screenwave = (!splitscreen && !cv_reducevfx.value && (thiscam->postimg & POSTIMG_WATER || thiscam->postimg & POSTIMG_HEAT)); // Capture the screen for intermission and screen waving if ((lastdraw || screenwave) && gamestate != GS_INTERMISSION) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 763fb873c..e45a56cda 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1198,8 +1198,15 @@ void HWR_DrawMD2(gl_vissprite_t *spr) Surf.PolyFlags = HWR_GetBlendModeFlag(blendmode); } - if (cv_playerfade.value && spr->mobj->player) - Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + if (spr->mobj->player) + { + // make hyu´d players translucent with reducevfx, could be done better, but im lazy as crap + if (cv_reducevfx.value && spr->mobj->player->kartstuff[k_hyudorotimer] > 0) + Surf.PolyColor.s.alpha = FixedMul(FRACUNIT/2, Surf.PolyColor.s.alpha); + + if (cv_playerfade.value) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + } // dont forget to enabled the depth test because we can't do this like // before: polygons models are not sorted diff --git a/src/k_kart.c b/src/k_kart.c index 342414738..59271a1e4 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -47,6 +47,8 @@ consvar_t cv_airsparks = {"airdriftsparks", "Off", CV_SAVE, CV_OnOff, NULL, 0, N consvar_t cv_playerblendeffects = {"playerblendeffects", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_reducevfx = {"reducevfx", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + // funn-E streeetch static CV_PossibleValue_t stretchfactor_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0, NULL}}; consvar_t cv_gravstretch = {"gravstretch", "MIN", CV_SAVE|CV_FLOAT, stretchfactor_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -482,7 +484,8 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { // UINT8 K_RainbowColor(void) { - return (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1))); + const INT32 time = cv_reducevfx.value ? (leveltime >> 3) : leveltime; + return (UINT8)(1 + (time % (MAXSKINCOLORS-1))); } // Define for getting accurate color brightness readings according to how the human eye sees them. @@ -764,6 +767,8 @@ void K_RegisterClientKartStuff(void) CV_RegisterVar(&cv_playerblendeffects); + CV_RegisterVar(&cv_reducevfx); + CV_RegisterVar(&cv_saltyhop); CV_RegisterVar(&cv_saltyhopsfx); CV_RegisterVar(&cv_saltysquish); @@ -6768,7 +6773,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) { if (splitscreen) { - if (leveltime & 1) + if (!cv_reducevfx.value && leveltime & 1) player->mo->flags2 |= MF2_DONTDRAW; else player->mo->flags2 &= ~MF2_DONTDRAW; @@ -6794,7 +6799,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) if (P_IsDisplayPlayer(player) || (!P_IsDisplayPlayer(player) && (player->kartstuff[k_hyudorotimer] < (1*TICRATE/2) || player->kartstuff[k_hyudorotimer] > hyudorotime-(1*TICRATE/2)))) { - if (leveltime & 1) + if (!cv_reducevfx.value && leveltime & 1) player->mo->flags2 |= MF2_DONTDRAW; else player->mo->flags2 &= ~MF2_DONTDRAW; diff --git a/src/p_mobj.c b/src/p_mobj.c index 581edf2f0..d1b8b850a 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -12354,8 +12354,9 @@ mobj_t *P_SPMAngle(mobj_t *source, mobjtype_t type, angle_t angle, UINT8 allowai // void P_FlashPal(player_t *pl, UINT16 type, UINT16 duration) { - if (!pl) + if (!pl || cv_reducevfx.value) // no palette flashing with reducevfx return; + pl->flashcount = duration; pl->flashpal = type; } diff --git a/src/r_things.cpp b/src/r_things.cpp index 77b02b78c..d1c856238 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1588,8 +1588,15 @@ static void R_ProjectSprite(mobj_t *thing) else trans = 0; - if (cv_playerfade.value && thing->player) - trans = static_cast(R_GetThingTransTable(R_DoPlayerFade(thing), static_cast(trans))); + if (thing->player) + { + // make hyu´d players translucent with reducevfx, could be done better, but im lazy as crap + if (cv_reducevfx.value && thing->player->kartstuff[k_hyudorotimer] > 0) + trans = static_cast(R_GetThingTransTable(FRACUNIT/2, static_cast(trans))); + + if (cv_playerfade.value) + trans = static_cast(R_GetThingTransTable(R_DoPlayerFade(thing), static_cast(trans))); + } //SoM: 3/17/2000: Disregard sprites that are out of view.. if (vflip) diff --git a/src/v_video.c b/src/v_video.c index ac85715ef..bb118d269 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -15,6 +15,7 @@ #include "doomdef.h" #include "d_main.h" +#include "g_game.h" #include "r_local.h" #include "p_local.h" #include "v_video.h" @@ -1755,6 +1756,9 @@ void V_DrawVhsEffect(boolean rewind) #endif SINT8 offs; + if (cv_reducevfx.value) + return; + barsize = vid.dup << 5; updistort = vid.dup << (rewind ? 5 : 3); downdistort = updistort >> 1; @@ -3639,127 +3643,130 @@ void V_DoPostProcessor(INT32 view, INT32 param) UINT8 *tmpscr = vid.screens[4]; UINT8 *srcscr = vid.screens[0]; - if (thiscam->postimg & POSTIMG_WATER) + if (!cv_reducevfx.value) { - INT32 y; - // Set disStart to a range from 0 to FINEANGLE, incrementing by 128 per tic - angle_t disStart = (((leveltime-1)*128) + (R_GetTimeFrac(RTF_LEVEL) / (FRACUNIT/128))) & FINEMASK; - INT32 newpix; - INT32 sine; - //UINT8 *transme = transtables + ((tr_trans50-1)<postimg & POSTIMG_WATER) { - sine = (FINESINE(disStart)*5)>>FRACBITS; - newpix = abs(sine); + INT32 y; + // Set disStart to a range from 0 to FINEANGLE, incrementing by 128 per tic + angle_t disStart = (((leveltime-1)*128) + (R_GetTimeFrac(RTF_LEVEL) / (FRACUNIT/128))) & FINEMASK; + INT32 newpix; + INT32 sine; + //UINT8 *transme = transtables + ((tr_trans50-1)<>FRACBITS; + newpix = abs(sine); - // Cleanup edge - while (newpix) + if (sine < 0) { - tmpscr[(y*vid.width)+xoffset+newpix] = srcscr[(y*vid.width)+xoffset]; - newpix--; - } - } - else - { - memcpy(&tmpscr[(y*vid.width)+xoffset+0], &srcscr[(y*vid.width)+xoffset+sine], viewwidth-newpix); + memcpy(&tmpscr[(y*vid.width)+xoffset+newpix], &srcscr[(y*vid.width)+xoffset], viewwidth-newpix); - // Cleanup edge - while (newpix) + // Cleanup edge + while (newpix) + { + tmpscr[(y*vid.width)+xoffset+newpix] = srcscr[(y*vid.width)+xoffset]; + newpix--; + } + } + else { - tmpscr[(y*vid.width)+xoffset+viewwidth-newpix] = srcscr[(y*vid.width)+xoffset+(viewwidth-1)]; - newpix--; + memcpy(&tmpscr[(y*vid.width)+xoffset+0], &srcscr[(y*vid.width)+xoffset+sine], viewwidth-newpix); + + // Cleanup edge + while (newpix) + { + tmpscr[(y*vid.width)+xoffset+viewwidth-newpix] = srcscr[(y*vid.width)+xoffset+(viewwidth-1)]; + newpix--; + } } + + /* + Unoptimized version + for (x = 0; x < vid.width; x++) + { + newpix = (x + sine); + + if (newpix < 0) + newpix = 0; + else if (newpix >= vid.width) + newpix = vid.width-1; + + tmpscr[y*vid.width + x] = srcscr[y*vid.width+newpix]; // *(transme + (srcscr[y*vid.width+x]<<8) + srcscr[y*vid.width+newpix]); + }*/ + + disStart += 22;//the offset into the displacement map, increment each game loop + disStart &= FINEMASK; //clip it to FINEMASK } - /* - Unoptimized version - for (x = 0; x < vid.width; x++) - { - newpix = (x + sine); - - if (newpix < 0) - newpix = 0; - else if (newpix >= vid.width) - newpix = vid.width-1; - - tmpscr[y*vid.width + x] = srcscr[y*vid.width+newpix]; // *(transme + (srcscr[y*vid.width+x]<<8) + srcscr[y*vid.width+newpix]); - }*/ - - disStart += 22;//the offset into the displacement map, increment each game loop - disStart &= FINEMASK; //clip it to FINEMASK + UINT8 *tmp = tmpscr; + tmpscr = srcscr; + srcscr = tmp; } - - UINT8 *tmp = tmpscr; - tmpscr = srcscr; - srcscr = tmp; - } - else if (thiscam->postimg & POSTIMG_HEAT) // Heat wave - { - INT32 y; - - // Make sure table is built - if (heatshifter == NULL || lastheight != viewheight) + else if (thiscam->postimg & POSTIMG_HEAT) // Heat wave { - if (heatshifter) - Z_Free(heatshifter); + INT32 y; - heatshifter = Z_Calloc(viewheight * sizeof(boolean), PU_STATIC, NULL); - - for (y = 0; y < viewheight; y++) + // Make sure table is built + if (heatshifter == NULL || lastheight != viewheight) { - if (M_RandomChance(FRACUNIT/8)) // 12.5% - heatshifter[y] = true; + if (heatshifter) + Z_Free(heatshifter); + + heatshifter = Z_Calloc(viewheight * sizeof(boolean), PU_STATIC, NULL); + + for (y = 0; y < viewheight; y++) + { + if (M_RandomChance(FRACUNIT/8)) // 12.5% + heatshifter[y] = true; + } + + heatindex[0] = heatindex[1] = heatindex[2] = heatindex[3] = 0; + lastheight = viewheight; } - heatindex[0] = heatindex[1] = heatindex[2] = heatindex[3] = 0; - lastheight = viewheight; - } - - for (y = yoffset; y < yoffset+viewheight; y++) - { - if (heatshifter[heatindex[view]++]) + for (y = yoffset; y < yoffset+viewheight; y++) { - // Shift this row of pixels to the right by 2 - tmpscr[(y*vid.width)+xoffset] = srcscr[(y*vid.width)+xoffset]; - memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset+vid.dup], viewwidth-vid.dup); + if (heatshifter[heatindex[view]++]) + { + // Shift this row of pixels to the right by 2 + tmpscr[(y*vid.width)+xoffset] = srcscr[(y*vid.width)+xoffset]; + memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset+vid.dup], viewwidth-vid.dup); + } + else + memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset], viewwidth); + + heatindex[view] %= viewheight; } - else - memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset], viewwidth); - heatindex[view] %= viewheight; + if (renderisnewtic) // This isn't interpolated... but how do you interpolate a one-pixel shift? + { + heatindex[view]++; + heatindex[view] %= vid.height; + } + + UINT8 *tmp = tmpscr; + tmpscr = srcscr; + srcscr = tmp; } - if (renderisnewtic) // This isn't interpolated... but how do you interpolate a one-pixel shift? - { - heatindex[view]++; - heatindex[view] %= vid.height; - } - - UINT8 *tmp = tmpscr; - tmpscr = srcscr; - srcscr = tmp; - } - #ifdef MOTIONBLUR - if (thiscam->postimg & POSTIMG_MOTION) // Motion Blur! - { - INT32 x, y; - - // TODO: Add a postimg_param so that we can pick the translucency level... - UINT8 *transme = transtables + ((param-1)<postimg & POSTIMG_MOTION) // Motion Blur! { - for (x = xoffset; x < xoffset+viewwidth; x++) - tmpscr[y*vid.width + x] = colormaps[*(transme + (srcscr [(y*vid.width)+x ] <<8) + (tmpscr[(y*vid.width)+x]))]; + INT32 x, y; + + // TODO: Add a postimg_param so that we can pick the translucency level... + UINT8 *transme = transtables + ((param-1)<postimg & POSTIMG_FLIP) && !(thiscam->postimg & POSTIMG_MIRROR)) // Flip the screen upside-down { From bdc326b14e49d73ff19784cc7ce391f8cb57a95e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 8 Jan 2026 00:43:35 +0100 Subject: [PATCH 33/39] leveltime be tic_t :chaosleep: --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 59271a1e4..6496f3e8e 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -484,7 +484,7 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { // UINT8 K_RainbowColor(void) { - const INT32 time = cv_reducevfx.value ? (leveltime >> 3) : leveltime; + const tic_t time = cv_reducevfx.value ? (leveltime >> 3) : leveltime; return (UINT8)(1 + (time % (MAXSKINCOLORS-1))); } From 8fe3d13935370048eaf2b3c20bf750a876625848 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 9 Jan 2026 11:08:10 +0100 Subject: [PATCH 34/39] fix InitColorLUT --- src/v_video.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index bb118d269..dbb3b385b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3821,7 +3821,7 @@ void InitColorLUT(colorlookup_t *lut, RGBA_t *palette, boolean makecolors) lut->init = true; memcpy(lut->palette, palette, palsize); - for (i = 0; i < 0xFFFF; i++) + for (i = 0; i < 0x10000; i++) lut->table[i] = 0xFFFF; if (makecolors) @@ -3834,7 +3834,9 @@ void InitColorLUT(colorlookup_t *lut, RGBA_t *palette, boolean makecolors) { for (b = 0; b < 0xFF; b++) { - lut->table[i] = GetColorLUT(lut, r, g, b); + i = CLUTINDEX(r, g, b); + if (lut->table[i] == 0xFFFF) + lut->table[i] = NearestPaletteColor(r, g, b, palette); } } } From 291a4dbb25472b459d6b74b3b40f378140322fd4 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 9 Jan 2026 13:00:47 +0100 Subject: [PATCH 35/39] disable midnight channel border flicker with "reducevfx" --- src/st_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 99188e919..5ca3f9d91 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -720,7 +720,7 @@ void ST_DrawDemoTitleEntry(void) static void ST_MayonakaStatic(void) { INT32 flag; - if (cv_lessflicker.value) + if (cv_lessflicker.value || cv_reducevfx.value) flag = V_70TRANS; else flag = (leveltime%2) ? V_90TRANS : V_70TRANS; From 0914d5b8e29496a5662fb318f44739ffb7aa69d4 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 11 Jan 2026 00:49:48 +0300 Subject: [PATCH 36/39] -Wzero-as-null-pointer-constant is valid for c only since GCC 15.2 (from what i see) --- src/Makefile.d/versions.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index e57119fb9..9a1706cc7 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,10 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference -Wzero-as-null-pointer-constant +WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference +ifdef GCC152 +WFLAGS+-Wzero-as-null-pointer-constant +endif ifndef GCC295 #WFLAGS+=-Wno-packed endif From 310f67a06c20a8594d740b6b10a9feeaf70bc745 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 11 Jan 2026 03:49:07 +0300 Subject: [PATCH 37/39] Fix smol mistake in strcasestr --- src/strcasestr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strcasestr.c b/src/strcasestr.c index f50141dcf..3eb6af60f 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -73,7 +73,7 @@ nongnu_strcasestr (const char *s, const char *q) up = strchr(s, uc); lp = strchr(s, lc); - if (up == NULL || lp == NULL) + if (up == NULL && lp == NULL) return NULL; if (!lp || ( up && up < lp )) @@ -100,7 +100,7 @@ nongnu_strcasestr (const char *s, const char *q) if (trycmp(ppa, cpa, q, qn) == 0) return (*ppa); - if (up == NULL || lp == NULL) + if (up == NULL && lp == NULL) break; if (!(*ppa) || ( (*ppb) && (*ppb) < (*ppa) )) From e88773da4e81c51248666539c40d12be8b4f60aa Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 11 Jan 2026 13:08:23 +0300 Subject: [PATCH 38/39] How did i miss the = --- src/Makefile.d/versions.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index 9a1706cc7..c3989bb4f 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -22,7 +22,7 @@ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference ifdef GCC152 -WFLAGS+-Wzero-as-null-pointer-constant +WFLAGS+=-Wzero-as-null-pointer-constant endif ifndef GCC295 #WFLAGS+=-Wno-packed From 9f5a88377b3a83a76fb9de2bf82494c4efae9d61 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 11 Jan 2026 19:46:34 +0100 Subject: [PATCH 39/39] d_netfil: dont use zone memory in CURLGetFile --- src/d_netfil.c | 11 ++++++++--- src/d_netfil.h | 1 - 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index 12f19dde2..67fd28a82 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -131,6 +131,8 @@ static UINT32 curl_origtotalfilesize; static char *curl_realname = NULL; fileneeded_t *curl_curfile = NULL; HTTP_login *curl_logins = NULL; + +static void CURLGetFile(void); #endif /** Fills a serverinfo packet with information about wad files loaded. @@ -1305,6 +1307,7 @@ void CURLPrepareFile(const char* url, int dfilenum) if (!multi_handle) { cc = curl_global_init(CURL_GLOBAL_ALL); + if (cc < 0) { I_OutputMsg("libcurl: curl_global_init() returned %d\n", cc); @@ -1313,6 +1316,7 @@ void CURLPrepareFile(const char* url, int dfilenum) { multi_handle = curl_multi_init(); } + if (!multi_handle) { I_OutputMsg("libcurl: curl_multi_init() failed\n"); @@ -1441,7 +1445,7 @@ void CURLAbortFile(void) #endif } -void CURLGetFile(void) +static void CURLGetFile(void) { #ifdef HAVE_THREADS I_lock_mutex(&downloadmutex); @@ -1483,7 +1487,8 @@ void CURLGetFile(void) e = m->easy_handle; easyres = m->data.result; - char *filename = Z_StrDup(curl_realname); + char *filename = malloc(strlen(curl_realname)+1); + strcpy(filename, curl_realname); nameonly(filename); if (easyres != CURLE_OK) @@ -1521,7 +1526,7 @@ void CURLGetFile(void) } } - Z_Free(filename); + free(filename); curl_curfile->file = NULL; filedownload.remaining--; mc = curl_multi_remove_handle(multi_handle, e); diff --git a/src/d_netfil.h b/src/d_netfil.h index 3c7502451..268cd80be 100644 --- a/src/d_netfil.h +++ b/src/d_netfil.h @@ -119,7 +119,6 @@ size_t nameonlylength(const char *s); #ifdef HAVE_CURL void CURLPrepareFile(const char* url, int dfilenum); void CURLAbortFile(void); -void CURLGetFile(void); HTTP_login * CURLGetLogin (const char *url, HTTP_login ***return_prev_next); size_t curlwrite_data(void *ptr, size_t size, size_t nmemb, FILE *stream); #endif