From 522904527fd8173d61880da7cef4892d36ef4cb7 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 23 Jan 2026 10:08:35 +0100 Subject: [PATCH 01/14] add missing HAVE_CURL --- src/d_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index c5499fb57..90ff81cc9 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -907,7 +907,9 @@ void D_ClearState(void) // okay, stop now // (otherwise the game still thinks we're playing!) +#ifdef HAVE_CURL CURLAbortFile(); +#endif SV_StopServer(); SV_ResetServer(); From 6c419ff22e569247e9d78ec2a9655da98120d588 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 23 Jan 2026 18:33:08 +0100 Subject: [PATCH 02/14] fix few more implicit double/float conversions --- src/d_netcmd.c | 1 - src/hardware/hw_main.cpp | 2 +- src/m_cheat.c | 2 +- src/r_plane.cpp | 8 ++++---- src/r_portal.c | 1 - src/r_things.cpp | 4 ++-- src/sdl/mixer_sound.c | 2 +- src/v_video.c | 8 ++++---- 8 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 641a026fd..a92532a80 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2655,7 +2655,6 @@ static void Command_Map_f(void) return; } - last_map_cmd = I_GetTime(); size_t first_option; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 24d3af8ae..5cc8eacf7 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -5444,7 +5444,7 @@ static void HWR_SetTransformAiming(FTransform *trans) fixed_t fixedaiming = AIMINGTODY(aimingangle); trans->viewaiming = FixedToFloat(fixedaiming) * (static_cast(vid.width) / static_cast(vid.height)) / (static_cast(BASEVIDWIDTH) / static_cast(BASEVIDHEIGHT)); if (splitscreen == 1) // only for 2 player splitscreen - trans->viewaiming *= 2.125; // splitscreen adjusts fov with 0.8, so compensate (but only halfway, since splitscreen means only half the screen is used) + trans->viewaiming *= 2.125f; // splitscreen adjusts fov with 0.8, so compensate (but only halfway, since splitscreen means only half the screen is used) trans->shearing = true; gl_aimingangle = 0; } diff --git a/src/m_cheat.c b/src/m_cheat.c index 58bc1401d..8223f2250 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -301,7 +301,7 @@ void Command_CheatNoTarget_f(void) void Command_Scale_f(void) { const double scaled = atof(COM_Argv(1)); - fixed_t scale = FLOAT_TO_FIXED(scaled); + fixed_t scale = DoubleToFixed(scaled); REQUIRE_DEVMODE; REQUIRE_INLEVEL; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index b2d30185d..c4ba7b8f1 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -920,12 +920,12 @@ static void R_SetSlopePlane(drawspandata_t* ds, pslope_t *slope, fixed_t xpos, f // m is the v direction vector in view space ang = ANG2RAD(ANGLE_180 - (angle + plangle)); - m->x = cos(ang); - m->z = sin(ang); + m->x = cosf(ang); + m->z = sinf(ang); // n is the u direction vector in view space - n->x = sin(ang); - n->z = -cos(ang); + n->x = sinf(ang); + n->z = -cosf(ang); plangle >>= ANGLETOFINESHIFT; temp = P_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle)); diff --git a/src/r_portal.c b/src/r_portal.c index 661034a3f..d84a99be4 100644 --- a/src/r_portal.c +++ b/src/r_portal.c @@ -246,7 +246,6 @@ static boolean TrimVisplaneBounds(const visplane_t* plane, INT16* start, INT16* if (!(*start < *end)) return true; - /** Trims a visplane's horizontal gap to match its render area. * * Visplanes' minx/maxx may sometimes exceed the area they're diff --git a/src/r_things.cpp b/src/r_things.cpp index d1c856238..aaff015a3 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -489,8 +489,8 @@ void R_InitSprites(void) for (angle = 1; angle < ROTANGLES; angle++) { fa = ANG2RAD(FixedAngle((ROTANGDIFF * angle)< 255.0f) working[0][q] = 255.0f; else if (working[0][q] < 0.0f) - working[0][q] = 0.0; + working[0][q] = 0.0f; } #undef dolerp From bb47b976a71317302778500e32c8e80f53003a78 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 23 Jan 2026 18:32:31 +0100 Subject: [PATCH 03/14] software: fix drawseg xrange item coord type being too small both sprite and drawseg coords are int32 might fix some clipping issues --- src/r_things.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index aaff015a3..2ced7cde2 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -70,7 +70,7 @@ INT16 *screenheightarray = NULL; typedef struct drawseg_xrange_item_s { - INT16 x1, x2; + INT32 x1, x2; drawseg_t *user; } drawseg_xrange_item_t; From c4581bd9a674beaa710402d50519061b3d262e11 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 24 Jan 2026 18:12:42 +0100 Subject: [PATCH 04/14] Only save and keep track of controller ids on SDL versions 2.32.4 and up Older versions break and have unstable ids on Windows, cant check for linux but ill just add a version check at this point This was part of updating sdl with v9, which got reverted due to other issues but this was not reverted oopsie --- src/sdl/i_system.cpp | 22 +++++++++++++++++++++- src/sdl/i_video.c | 12 ++++++++++++ src/sdl/sdlmain.h | 4 ++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 52a78232f..4dd32161e 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -726,7 +726,9 @@ static void JoyReset(SDLJoyInfo_t *JoySet) JoySet->dev = NULL; JoySet->oldjoy = -1; +#if (SDL_VERSION_ATLEAST(2,32,4)) JoySet->id = -1; +#endif } /** \brief SDL info about joystick @@ -783,7 +785,11 @@ void I_UpdateJoystickDeviceIndex(UINT8 player) /////////////////////////////////////////////// if (JoyInfo[player].dev) { +#if (SDL_VERSION_ATLEAST(2,32,4)) cv_usejoystick[player].value = JoyInfo[player].id + 1; +#else + cv_usejoystick[player].value = I_GetJoystickDeviceIndex(JoyInfo[player].dev) + 1; +#endif } else { @@ -939,7 +945,9 @@ static int joy_open(int playerIndex, int joyIndex) CONS_Debug(DBG_GAMELOGIC, "Joystick %d: %s\n", playerIndex+1, SDL_GameControllerName(JoyInfo[playerIndex].dev)); +#if (SDL_VERSION_ATLEAST(2,32,4)) JoyInfo[playerIndex].id = I_GetJoystickDeviceIndex(JoyInfo[playerIndex].dev); +#endif return SDL_CONTROLLER_AXIS_MAX; } @@ -985,7 +993,9 @@ void I_InitJoystick(UINT8 index) JoyInfo[index].dev = NULL; JoyInfo[index].oldjoy = -1; +#if (SDL_VERSION_ATLEAST(2,32,4)) JoyInfo[index].id = -1; +#endif if (cv_usejoystick[index].value) newcontroller = SDL_GameControllerOpen(cv_usejoystick[index].value-1); @@ -999,17 +1009,27 @@ void I_InitJoystick(UINT8 index) break; } +#if (SDL_VERSION_ATLEAST(2,32,4)) JoyInfo[index].id = I_GetJoystickDeviceIndex(JoyInfo[index].dev); +#endif if (newcontroller && i < MAXSPLITSCREENPLAYERS) // don't override an active device { +#if (SDL_VERSION_ATLEAST(2,32,4)) cv_usejoystick[index].value = JoyInfo[index].id + 1; +#else + cv_usejoystick[index].value = I_GetJoystickDeviceIndex(JoyInfo[index].dev) + 1; +#endif } else if (newcontroller && joy_open(index, cv_usejoystick[index].value) != -1) { +#if (SDL_VERSION_ATLEAST(2,32,4)) + JoyInfo[index].oldjoy = JoyInfo[index].id + 1; +#else // SDL's device indexes are unstable, so cv_usejoystick may not match // the actual device index. So let's cheat a bit and find the device's current index. - JoyInfo[index].oldjoy = JoyInfo[index].id + 1; + JoyInfo[index].oldjoy = I_GetJoystickDeviceIndex(JoyInfo[index].dev) + 1; +#endif } else { diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 1c23af6cd..8b2adfa7b 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -784,7 +784,11 @@ static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt) // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { +#if (SDL_VERSION_ATLEAST(2,32,4)) if (evt.which == JoyInfo[i].id) +#else + if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) +#endif { event.type = ev_joystick + i; break; @@ -844,7 +848,11 @@ static void Impl_HandleControllerHatEvent(SDL_ControllerButtonEvent evt, Uint32 // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { +#if (SDL_VERSION_ATLEAST(2,32,4)) if (evt.which == JoyInfo[i].id) +#else + if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) +#endif { event.data1 = hat_buttons_base[i]; break; @@ -906,7 +914,11 @@ static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint // Determine the Joystick IDs for each current open joystick for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { +#if (SDL_VERSION_ATLEAST(2,32,4)) if (evt.which == JoyInfo[i].id) +#else + if (evt.which == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev))) +#endif { event.data1 = buttons_base[i]; break; diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index f7f4c011c..11287fe55 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -23,6 +23,8 @@ extern "C" { #endif +#include "SDL_version.h" + #include "../m_fixed.h" // SDL2 stub macro @@ -39,8 +41,10 @@ typedef struct SDLJoyInfo_s { /// Controller handle SDL_GameController *dev; +#if (SDL_VERSION_ATLEAST(2,32,4)) /// Controller index INT32 id; +#endif /// number of old joystick int oldjoy; /// number of axies From 7a279a6fd9f0e3cb69c3d73bc408420c38a43301 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 28 Jan 2026 19:19:02 +0300 Subject: [PATCH 05/14] Prefix autoaccel cvars with 'kart' to avoid conflict with hostmod --- src/g_game.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 27a2922a8..94aaeb016 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -456,10 +456,10 @@ consvar_t cv_litesteer[MAXSPLITSCREENPLAYERS] = { //static CV_PossibleValue_t autoaccelcons_t[] = {{0, "Off"}, {1, "Manual"}, {2, "Automatic"}, {0, NULL}}; consvar_t cv_autoaccel[MAXSPLITSCREENPLAYERS] = { - {"autoaccel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, - {"autoaccel2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, - {"autoaccel3", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, - {"autoaccel4", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL} + {"kartautoaccel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"kartautoaccel2", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"kartautoaccel3", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"kartautoaccel4", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL} }; static CV_PossibleValue_t driftsparkpulse_t[] = {{0, "MIN"}, {FRACUNIT*3, "MAX"}, {0, NULL}}; From 3122c080391401a301f291539c1b7c173b933b67 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 1 Feb 2026 02:48:29 +0300 Subject: [PATCH 06/14] Add focus options for gamepad led and rumble --- src/d_netcmd.c | 3 +++ src/g_input.c | 7 +++++-- src/g_input.h | 3 +++ src/m_menudefs.c | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a92532a80..6ecc670d1 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1009,6 +1009,9 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_gamepadled[i]); } + CV_RegisterVar(&cv_gamepadledifunfocused); + CV_RegisterVar(&cv_rumbleifunfocused); + CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_invertmouse); CV_RegisterVar(&cv_mousexsens); diff --git a/src/g_input.c b/src/g_input.c index 1a420c996..d44edd6dc 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -81,6 +81,9 @@ consvar_t cv_gamepadled[MAXSPLITSCREENPLAYERS] = { {"gamepadled4", "Skincolor", CV_SAVE|CV_CALL|CV_NOINIT, gamepadled_cons_t, led_off_handle4, 0, NULL, NULL, 0, 0, NULL} }; +consvar_t cv_gamepadledifunfocused = {"gamepadledunfocused", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_rumbleifunfocused = {"rumbleifunfocused", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static void rumble_off_handle(void) { if (!cv_rumble[0].value) @@ -930,7 +933,7 @@ void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT8 color) I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); - if (cv_gamepadled[playernum].value == 0 + if (cv_gamepadled[playernum].value == 0 || (window_notinfocus && cv_gamepadledifunfocused.value == 0) || color >= MAXTRANSLATIONS) { return; @@ -1009,7 +1012,7 @@ void G_PlayerDeviceRumble(INT32 playernum, UINT16 low_strength, UINT16 high_stre { I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); - if (cv_rumble[playernum].value == 0) + if (cv_rumble[playernum].value == 0 || (window_notinfocus && cv_rumbleifunfocused.value == 0)) { return; } diff --git a/src/g_input.h b/src/g_input.h index 9831e6d8f..154f0805d 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -116,6 +116,9 @@ extern consvar_t cv_rumble[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_rumblestrength[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_gamepadled[MAXSPLITSCREENPLAYERS]; +extern consvar_t cv_gamepadledifunfocused; +extern consvar_t cv_rumbleifunfocused; + extern INT32 mousex, mousey; extern INT32 joyxmove[MAXSPLITSCREENPLAYERS][JOYAXISSET], joyymove[MAXSPLITSCREENPLAYERS][JOYAXISSET]; diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 0c4aef0d4..1a21ec455 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -1205,6 +1205,10 @@ static menuitem_t OP_FocusOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Show \"FOCUS LOST\"", &cv_showfocuslost, 100}, {IT_STRING|IT_CVAR, NULL, "Visible Mouse", &cv_mousevisible, 120}, + + {IT_STRING|IT_CVAR, NULL, "Gamepad LED Color While Unfocused ", &cv_gamepadledifunfocused, 140}, + {IT_STRING|IT_CVAR, NULL, "Gamepad Rumble While Unfocused", &cv_rumbleifunfocused, 150}, + }; static const char* OP_FocusOptionsTooltips[] = @@ -1216,6 +1220,8 @@ static const char* OP_FocusOptionsTooltips[] = "Set manual framerate cap while the game is unfocused.", "Should the FOCUS LOST window appear\n while the game is unfocused?", "Displays the mouse cursor while the game is in focus.", + "Should gamepad LED indicator change color when unfocused?", + "Should gamepad rumble apply when unfocused?", }; static menuitem_t OP_DataOptionsMenu[] = From 0ca6947f99070b66b3a10cf5b3c1bf25dcae3a31 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Feb 2026 16:27:16 +0100 Subject: [PATCH 07/14] fix a few type issues --- src/hardware/hw_md2.c | 2 +- src/r_plane.cpp | 2 +- src/r_segs.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 0a79ba6ec..56082e0fc 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -579,7 +579,7 @@ md2found: fclose(f); } -void HWR_AddPlayerMD2(int skin, boolean local) // For MD2's that were added after startup +void HWR_AddPlayerMD2(INT32 skin, boolean local) // For MD2's that were added after startup { FILE *f; char name[20], filename[32]; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index c4ba7b8f1..78375b8b6 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -136,7 +136,7 @@ void R_AllocPlaneMemory(void) } yslopetab = static_cast(Z_Realloc(yslopetab, sizeof(*yslopetab) * (viewheight * 16), PU_STATIC, NULL)); - spanstart = static_cast(Z_Realloc(spanstart, sizeof(*spanstart) * viewheight, PU_STATIC, NULL)); + spanstart = static_cast(Z_Realloc(spanstart, sizeof(*spanstart) * viewheight, PU_STATIC, NULL)); } // diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 6751befc9..660b91494 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -2880,7 +2880,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (markceiling) { if (ceilingplane) //SoM: 3/29/2000: Check for null ceiling planes - ceilingplane = R_CheckPlane (ceilingplane, rw_x, rw_stopx-1); + ceilingplane = R_CheckPlane(ceilingplane, rw_x, rw_stopx-1); else markceiling = false; @@ -2894,7 +2894,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (markfloor) { if (floorplane) //SoM: 3/29/2000: Check for null planes - floorplane = R_CheckPlane (floorplane, rw_x, rw_stopx-1); + floorplane = R_CheckPlane(floorplane, rw_x, rw_stopx-1); else markfloor = false; From 544e1d3b21cad200aee1b03f636ec17cb744437c Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Feb 2026 17:07:10 +0100 Subject: [PATCH 08/14] "fix" overflow in R_InitViewMapping with high resolutions --- src/r_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index e3bfb83fa..5fb224167 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1018,8 +1018,8 @@ static void R_InitViewMapping(void) for (INT32 i = 0; i < j; i++) { - fixed_t dy = (i - viewheight*8)< Date: Sun, 1 Feb 2026 18:25:03 +0100 Subject: [PATCH 09/14] r_plane: fix visplane hashing overflowing shift into "int" to prevent super large values during multiply --- src/r_plane.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 78375b8b6..05c4d943a 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -57,8 +57,11 @@ visffloor_t visffloor[MAXFFLOORS] = {}; INT32 numffloors = 0; //SoM: 3/23/2000: Boom visplane hashing routine. -#define visplane_hash(picnum,lightlevel,height) \ - ((unsigned)((picnum)*3+(lightlevel)+(height)*7) & VISPLANEHASHMASK) +constexpr unsigned int visplane_hash(const unsigned int picnum, const unsigned int lightlevel, + const unsigned int height) +{ + return ((picnum * 3) + lightlevel + (height * 7)) & VISPLANEHASHMASK; +} // // Clip values are the solid pixel bounding the range. @@ -451,7 +454,7 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, } } - hash = visplane_hash(picnum, lightlevel, height); + hash = visplane_hash(picnum, lightlevel, height >> FRACBITS); for (check = visplanes[hash]; check; check = check->next) { @@ -562,7 +565,7 @@ visplane_t *R_CheckPlane(visplane_t *pl, INT32 start, INT32 stop) } else { - unsigned hash = visplane_hash(pl->picnum, pl->lightlevel, pl->height); + unsigned hash = visplane_hash(pl->picnum, pl->lightlevel, pl->height >> FRACBITS); new_pl = new_visplane(hash); } From b23154fd938d7ace4a6c6c48da319b8be9d8542c Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 2 Feb 2026 02:28:27 +0300 Subject: [PATCH 10/14] Prevent replays menu scoll bar from disappearing --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index a98a230d5..cfbfea7c5 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4719,7 +4719,7 @@ static void M_DrawReplayHut(void) if (y > scaledviewheight-80) { V_DrawFill(BASEVIDWIDTH-4, 75, 4, scaledviewheight-80, V_SNAPTOTOP|V_SNAPTORIGHT|239); - V_DrawFill(BASEVIDWIDTH-3, 76 + (scaledviewheight-80) * replayhutmenuy / y, 2, (((scaledviewheight-80) * (scaledviewheight-80))-1) / y - 1, V_SNAPTOTOP|V_SNAPTORIGHT|229); + V_DrawFill(BASEVIDWIDTH-3, 76 + (scaledviewheight-80) * replayhutmenuy / y, 2, max((((scaledviewheight-80) * (scaledviewheight-80))-1) / y - 1, 1), V_SNAPTOTOP|V_SNAPTORIGHT|229); } // Draw the cursor From 10b9d96259a4283b55ac4def4fdb44ed62ca2d82 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Feb 2026 16:10:15 +0100 Subject: [PATCH 11/14] hw_clip: replace "RoundToInt" with lrint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit prefer to use standard lib functions if possible lrint does the same thing (well ofc as long as no one touches the rounding direction löl) and is even quite a lot faster (though this is negligible in this case) --- src/hardware/hw_clip.c | 2 +- src/m_fixed.h | 29 ----------------------------- 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 3f9536436..6790823f2 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -335,7 +335,7 @@ angle_t gld_FrustumAngle(angle_t tiltangle) floatangle = 2.0 + (45.0 + ((double)tilt / 1.9)) * clipfov / 90.0; if (floatangle >= 180.0) return 0xffffffff; - a1 = (angle_t)xs_CRoundToInt(ANG1 * floatangle); + a1 = (angle_t)lrint(ANG1 * floatangle); return a1; } diff --git a/src/m_fixed.h b/src/m_fixed.h index c0afae941..894e2b1cc 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -265,35 +265,6 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FixedRound(fixed_t x) return INT32_MAX; } -/** \brief The xs_CRoundToInt function - - \param val double number - - \return Round toward nearest, but ties round toward even -*/ -#if defined(SRB2_BIG_ENDIAN) - #define _xs_iexp_ 0 - #define _xs_iman_ 1 -#else - #define _xs_iexp_ 1 //intel is little endian - #define _xs_iman_ 0 -#endif //BigEndian_ - -typedef double real64; - -typedef union _xs_doubleints -{ - real64 val; - unsigned ival[2]; -} _xs_doubleints; - -FUNCMATH FUNCINLINE static ATTRINLINE int xs_CRoundToInt(real64 val) -{ - _xs_doubleints uval; - uval.val = val + 6755399441055744.0; - return uval.ival[_xs_iman_]; -} - typedef struct { fixed_t x; From e4dbf1ce114334ad998fb3d4c95ca51a12e79c54 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Feb 2026 16:11:41 +0100 Subject: [PATCH 12/14] plug a potential memory leak in M_SaveConfig --- src/hu_stuff.c | 15 +++++++++++---- src/m_misc.c | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 6cca391e9..21143ed76 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1484,6 +1484,7 @@ static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) x = 0; } } + return newstring; } @@ -1522,7 +1523,7 @@ static void HU_drawMiniChat(void) emote_t *emote = NULL; int emotelen = 0; - while(msg[j]) // iterate through msg + while (msg[j]) // iterate through msg { if (msg[j] < HU_FONTSTART) // don't draw { @@ -1554,14 +1555,17 @@ static void HU_drawMiniChat(void) { j++; } + prev_linereturn = false; dx += charwidth; + if (dx >= boxw) { dx = 0; linescount += 1; } } + dy = 0; dx = 0; msglines += linescount+1; @@ -1598,7 +1602,7 @@ static void HU_drawMiniChat(void) emote_t *emote = NULL; int emotelen = 0; - while(msg[j]) // iterate through msg + while (msg[j]) // iterate through msg { if (msg[j] < HU_FONTSTART) // don't draw { @@ -1643,12 +1647,14 @@ static void HU_drawMiniChat(void) dx += charwidth; prev_linereturn = false; + if (dx >= boxw) { dx = 0; dy += charheight; } } + dy += charheight; dx = 0; if (msg) @@ -1704,7 +1710,7 @@ static void HU_drawChatLog(INT32 offset) V_DrawFillConsoleMap(chatx, chat_topy, boxw, boxh*charheight +2, 239|V_SNAPTOBOTTOM|V_SNAPTOLEFT); // log box - for (i=0; i Date: Sun, 1 Feb 2026 21:49:49 +0100 Subject: [PATCH 13/14] delet all the Z_Free checks Z_Free already checks its input internally! --- src/f_finale.c | 4 +--- src/filesrch.c | 14 ++++++-------- src/g_game.c | 7 ++----- src/hu_stuff.c | 12 ++++-------- src/i_tcp.c | 14 ++++---------- src/k_stats.c | 3 +-- src/lua_hudlib_drawlist.c | 15 +++------------ src/m_anigif.c | 9 +++------ src/m_cond.c | 9 +++------ src/m_menu.c | 13 +++++++++---- src/p_setup.c | 4 +--- src/p_spec.c | 3 +-- src/r_data.c | 3 +-- src/r_main.cpp | 16 ++++++---------- src/r_patch.cpp | 6 ++---- src/r_things.cpp | 2 +- src/v_video.c | 4 +--- src/w_wad.c | 7 +++---- src/z_zone.h | 2 +- 19 files changed, 53 insertions(+), 94 deletions(-) diff --git a/src/f_finale.c b/src/f_finale.c index 32ed8c3ec..f7efbbced 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1172,9 +1172,7 @@ void F_StartWaitingPlayers(void) randskin = M_RandomKey(numskins); boolean waithires = skins[randskin].flags && SF_HIRES; - if (waitcolormap) - Z_Free(waitcolormap); - + Z_Free(waitcolormap); waitcolormap = R_GetTranslationColormap(randskin, skins[randskin].prefcolor, 0); if (waithires) diff --git a/src/filesrch.c b/src/filesrch.c index e34b51c47..0ba117a1e 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -317,8 +317,7 @@ void closefilemenu(boolean validsize) coredirmenu = NULL; } - if (refreshdirname) - Z_Free(refreshdirname); + Z_Free(refreshdirname); refreshdirname = NULL; } @@ -346,8 +345,7 @@ void searchfilemenu(char *tempname) if (!menusearch.length) { - if (dirmenu) - Z_Free(dirmenu); + Z_Free(dirmenu); dirmenu = coredirmenu; sizedirmenu = sizecoredirmenu; @@ -389,8 +387,8 @@ void searchfilemenu(char *tempname) I_Error("searchfilemenu(): could not create \"No results...\"."); sizedirmenu = 1; dir_on[menudepthleft] = 0; - if (tempname) - Z_Free(tempname); + Z_Free(tempname); + return; } @@ -505,8 +503,8 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) { closedir(dirhandle); closefilemenu(false); - if (tempname) - Z_Free(tempname); + Z_Free(tempname); + return false; } diff --git a/src/g_game.c b/src/g_game.c index 94aaeb016..a79a957ef 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -523,11 +523,8 @@ void G_ClearRecords(void) INT16 i; for (i = 0; i < NUMMAPS; ++i) { - if (mainrecords[i]) - { - Z_Free(mainrecords[i]); - mainrecords[i] = NULL; - } + Z_Free(mainrecords[i]); + mainrecords[i] = NULL; } } diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 21143ed76..653529bf4 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1072,8 +1072,7 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) HU_AddChatText(va(fmt2, prefix, cstart, dispname, textcolor, msg), cv_chatnotifications.value); // add to chat - if (tempchar) - Z_Free(tempchar); + Z_Free(tempchar); } #ifdef _DEBUG // I just want to point out while I'm here that because the data is still @@ -1569,8 +1568,7 @@ static void HU_drawMiniChat(void) dy = 0; dx = 0; msglines += linescount+1; - if (msg) - Z_Free(msg); + Z_Free(msg); } y = chaty - charheight*(msglines+1); @@ -1657,8 +1655,7 @@ static void HU_drawMiniChat(void) dy += charheight; dx = 0; - if (msg) - Z_Free(msg); + Z_Free(msg); } // decrement addy and make that shit smooth: @@ -1767,8 +1764,7 @@ static void HU_drawChatLog(INT32 offset) dy += charheight; dx = 0; - if (msg) - Z_Free(msg); + Z_Free(msg); } if (((chat_scroll >= chat_maxscroll) || (chat_scrollmedown)) && !(justscrolleddown || justscrolledup || chat_scrolltime)) // was already at the bottom of the page before new maxscroll calculation and was NOT scrolling. diff --git a/src/i_tcp.c b/src/i_tcp.c index 982b327d0..5b9b0237d 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -1510,11 +1510,8 @@ static boolean SOCK_SetBanUsername(const char *username) username = "Direct IP ban"; } - if (banned[numbans - 1].username) - { - Z_Free(banned[numbans - 1].username); - banned[numbans - 1].username = NULL; - } + Z_Free(banned[numbans - 1].username); + banned[numbans - 1].username = NULL; banned[numbans - 1].username = Z_StrDup(username); @@ -1528,11 +1525,8 @@ static boolean SOCK_SetBanReason(const char *reason) reason = "No reason given"; } - if (banned[numbans - 1].reason) - { - Z_Free(banned[numbans - 1].reason); - banned[numbans - 1].reason = NULL; - } + Z_Free(banned[numbans - 1].reason); + banned[numbans - 1].reason = NULL; banned[numbans - 1].reason = Z_StrDup(reason); diff --git a/src/k_stats.c b/src/k_stats.c index f4fac90d3..5675462fd 100644 --- a/src/k_stats.c +++ b/src/k_stats.c @@ -99,8 +99,7 @@ void K_EraseStats(void) // The only field we want to remember boolean vanilla = kartstats.vanilla; - if (kartstats.copy) - Z_Free(kartstats.copy); + Z_Free(kartstats.copy); memset(&kartstats, 0, sizeof(kartstats_t)); diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index f267c5fe3..6d3542c48 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -136,18 +136,9 @@ void LUA_HUD_DestroyDrawList(huddrawlist_h list) { if (list == NULL) return; - if (list->items) - { - Z_Free(list->items); - } - if (list->olditems) - { - Z_Free(list->olditems); - } - if (list->strbuf) - { - Z_Free(list->strbuf); - } + Z_Free(list->items); + Z_Free(list->olditems); + Z_Free(list->strbuf); Z_Free(list); } diff --git a/src/m_anigif.c b/src/m_anigif.c index a8cc21bcf..cd37b08d6 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -695,16 +695,13 @@ INT32 GIF_close(void) fclose(gif_out); gif_out = NULL; - if (gifbwr_buf) - Z_Free(gifbwr_buf); + Z_Free(gifbwr_buf); gifbwr_buf = gifbwr_cur = NULL; - if (gifframe_data) - Z_Free(gifframe_data); + Z_Free(gifframe_data); gifframe_data = NULL; - if (giflzw_hashTable) - Z_Free(giflzw_hashTable); + Z_Free(giflzw_hashTable); giflzw_hashTable = NULL; Z_Free(scrbuf_screens); diff --git a/src/m_cond.c b/src/m_cond.c index 126d5a49a..c22c966f3 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -248,12 +248,9 @@ void M_AddRawCondition(UINT8 set, UINT8 id, conditiontype_t c, INT32 r, INT16 x1 void M_ClearConditionSet(UINT8 set) { - if (conditionSets[set - 1].numconditions) - { - Z_Free(conditionSets[set - 1].condition); - conditionSets[set - 1].condition = NULL; - conditionSets[set - 1].numconditions = 0; - } + Z_Free(conditionSets[set - 1].condition); + conditionSets[set - 1].condition = NULL; + conditionSets[set - 1].numconditions = 0; conditionSets[set - 1].achieved = false; } diff --git a/src/m_menu.c b/src/m_menu.c index cfbfea7c5..f4271de1a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6560,17 +6560,22 @@ static void M_EraseGuest(INT32 choice) static void M_OverwriteGuest(const char *which) { - char *rguest = Z_StrDup(va("%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-guest.lmp", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value))); + char *rguest; UINT8 *buf; size_t len; len = FIL_ReadFile(va("%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-%s-%s.lmp", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value), cv_chooseskin.string, which), &buf); - if (!len) { + + if (!len) return; - } - if (FIL_FileExists(rguest)) { + + rguest = Z_StrDup(va("%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-guest.lmp", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value))); + + if (FIL_FileExists(rguest)) + { M_StopMessage(0); remove(rguest); } + FIL_WriteFile(rguest, buf, len); Z_Free(rguest); diff --git a/src/p_setup.c b/src/p_setup.c index 612530882..c9aba324a 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -320,9 +320,7 @@ void P_AddGradesForMare(INT16 i, UINT8 mare, char *gtext) */ void P_DeleteGrades(INT16 i) { - if (mapheaderinfo[i]->grades) - Z_Free(mapheaderinfo[i]->grades); - + Z_Free(mapheaderinfo[i]->grades); mapheaderinfo[i]->grades = NULL; mapheaderinfo[i]->numGradedMares = 0; } diff --git a/src/p_spec.c b/src/p_spec.c index 5045a8287..b313f77a1 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -6221,8 +6221,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) // Allocate each list for (i = 0; i < numsectors; i++) - if(secthinkers[i].thinkers) - Z_Free(secthinkers[i].thinkers); + Z_Free(secthinkers[i].thinkers); Z_Free(secthinkers); diff --git a/src/r_data.c b/src/r_data.c index 386f0e700..911413bb4 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1720,8 +1720,7 @@ void R_InitData(void) void R_ClearTextureNumCache(boolean btell) { - if (tidcache) - Z_Free(tidcache); + Z_Free(tidcache); tidcache = NULL; if (btell) CONS_Debug(DBG_SETUP, "Fun Fact: There are %d textures used in this map.\n", tidcachelen); diff --git a/src/r_main.cpp b/src/r_main.cpp index 5fb224167..430a7cd32 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -925,11 +925,11 @@ void R_ExecuteSetViewSize(void) viewheight = vid.height; if (splitscreen) + { viewheight >>= 1; - if (splitscreen > 1) - { - viewwidth >>= 1; + if (splitscreen > 1) + viewwidth >>= 1; } centerx = viewwidth/2; @@ -956,13 +956,9 @@ void R_ExecuteSetViewSize(void) screenheightarray[i] = (INT16)viewheight; } - if (ds_su) - Z_Free(ds_su); - if (ds_sv) - Z_Free(ds_sv); - if (ds_sz) - Z_Free(ds_sz); - + Z_Free(ds_su); + Z_Free(ds_sv); + Z_Free(ds_sz); ds_su = ds_sv = ds_sz = NULL; memset(scalelight, 0xFF, sizeof(scalelight)); diff --git a/src/r_patch.cpp b/src/r_patch.cpp index 60d4acb98..bca733c8b 100644 --- a/src/r_patch.cpp +++ b/src/r_patch.cpp @@ -405,10 +405,8 @@ static void Patch_FreeData(patch_t *patch) }*/ #endif - if (patch->columnofs) - Z_Free(patch->columnofs); - if (patch->columns) - Z_Free(patch->columns); + Z_Free(patch->columnofs); + Z_Free(patch->columns); } void Patch_Free(patch_t *patch) diff --git a/src/r_things.cpp b/src/r_things.cpp index 2ced7cde2..58a838eea 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -391,7 +391,7 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 // allocate space for the frames present and copy sprtemp to it if (spritedef->numframes && // has been allocated - spritedef->numframes < maxframe) // more frames are defined ? + spritedef->numframes < maxframe) // more frames are defined ? { Z_Free(spritedef->spriteframes); diff --git a/src/v_video.c b/src/v_video.c index a92575c96..fde09cc0b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3716,9 +3716,7 @@ void V_DoPostProcessor(INT32 view, INT32 param) // Make sure table is built if (heatshifter == NULL || lastheight != viewheight) { - if (heatshifter) - Z_Free(heatshifter); - + Z_Free(heatshifter); heatshifter = Z_Calloc(viewheight * sizeof(boolean), PU_STATIC, NULL); for (y = 0; y < viewheight; y++) diff --git a/src/w_wad.c b/src/w_wad.c index 432f1421f..20a2ccc87 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -122,7 +122,9 @@ void W_Shutdown(void) if (wad->handle) fclose(wad->handle); + Z_Free(wad->filename); + while (wad->numlumps--) { Z_Free(wad->lumpinfo[wad->numlumps].longname); @@ -2730,10 +2732,7 @@ void vres_Free(virtres_t* vres) while (vres->numlumps--) { - if (vres->vlumps[vres->numlumps].data) - { - Z_Free(vres->vlumps[vres->numlumps].data); - } + Z_Free(vres->vlumps[vres->numlumps].data); } Z_Free(vres->vlumps); diff --git a/src/z_zone.h b/src/z_zone.h index 90a55b465..38f00c48c 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -91,7 +91,7 @@ void Z_Init(void); // Z_Free and alloc with alignment #ifdef ZDEBUG -#define Z_Free(p) Z_Free2(p, __FILE__, __LINE__) +#define Z_Free(p) Z_Free2(p, __FILE__, __LINE__) #define Z_Malloc(s,t,u) Z_Malloc2(s, t, u, __FILE__, __LINE__) #define Z_Calloc(s,t,u) Z_Calloc2(s, t, u, __FILE__, __LINE__) #define Z_Realloc(p,s,t,u) Z_Realloc2(p,s, t, u, __FILE__, __LINE__) From 55c8546d68638703040342401217852cd2863034 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Feb 2026 17:21:36 +0100 Subject: [PATCH 14/14] do not use Zone Memory for masterserver rules this gets called from within non main threads! zone memory is not thread safe! --- src/m_menu.c | 3 +-- src/mserv.c | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index f4271de1a..83c2dce77 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5356,7 +5356,7 @@ void M_PopupMasterServerRules(void) { firstDismissedRulesThisBoot = false; M_StartMessage(va("%s\n(press any key)", rules), NULL, MM_NOTHING); - Z_Free(rules); + free(rules); } } #endif @@ -7592,7 +7592,6 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) static void M_DrawServerMenu(void) { - M_DrawLevelSelectOnly(false, false); #ifdef MASTERSERVER if (currentMenu == &MP_ServerDef && cv_advertise.value) // Remind players where they're hosting. diff --git a/src/mserv.c b/src/mserv.c index f830cd6e2..01af521e6 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -219,8 +219,9 @@ static void Get_masterserver_rules(boolean checkfirst) if (HMS_fetch_rules(rules, sizeof rules)) { Lock_state(); - Z_Free(MSRules); - MSRules = Z_StrDup(rules); + if (MSRules) + free(MSRules); + MSRules = strdup(rules); if (MSRegistered == true) { @@ -507,7 +508,7 @@ char *GetMasterServerRules(void) char *rules; Lock_state(); - rules = MSRules ? Z_StrDup(MSRules) : NULL; + rules = MSRules ? strdup(MSRules) : NULL; Unlock_state(); return rules;