From 8e4b304bed833e73dcacb8abffdfcb77fe1ea07b Mon Sep 17 00:00:00 2001 From: PAS Date: Wed, 9 Jul 2025 23:15:33 -0400 Subject: [PATCH 01/50] CMake: don't configure before CPACK_PACKAGE_DESCRIPTION_SUMMARY is set --- CMakeLists.txt | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1acd092bc..2d8354b44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,28 @@ if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.") endif() +##### PACKAGE CONFIGURATION ##### + +if(${CMAKE_SYSTEM} MATCHES "Windows") + set(CPACK_GENERATOR "ZIP") +endif() +if(${CMAKE_SYSTEM} MATCHES "Linux") + set(CPACK_GENERATOR "TGZ") +endif() +if(${CMAKE_SYSTEM} MATCHES "Darwin") + set(CPACK_GENERATOR "DragNDrop") +endif() + +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sonic Robo Blast 2 Kart" CACHE STRING "Program name for display purposes") +set(CPACK_PACKAGE_VENDOR "Kart Krew" CACHE STRING "Vendor name for display purposes") +#set(CPACK_PACKAGE_DESCRIPTION_FILE ) +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_PACKAGE_VERSION_MAJOR ${SRB2_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${SRB2_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${SRB2_VERSION_PATCH}) +set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}") +include(CPack) + # Set up CMAKE path set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") @@ -100,16 +122,11 @@ endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") -# Set EXE names so the assets CMakeLists can refer to its target -set(SRB2_SDL2_EXE_NAME srb2kart CACHE STRING "Executable binary output name") -set(SRB2_WIN_EXE_NAME srb2kartdd CACHE STRING "Executable binary output name for DirectDraw build") - include_directories(${CMAKE_CURRENT_BINARY_DIR}/src) add_subdirectory(src) add_subdirectory(assets) - ## config.h generation set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary") include(GitUtilities) @@ -118,25 +135,3 @@ git_current_branch(SRB2_GIT_BRANCH "${CMAKE_SOURCE_DIR}") set(SRB2_COMP_BRANCH "${SRB2_GIT_BRANCH}") set(SRB2_COMP_REVISION "${SRB2_COMP_COMMIT}") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h) - -##### PACKAGE CONFIGURATION ##### - -if(${CMAKE_SYSTEM} MATCHES "Windows") - set(CPACK_GENERATOR "ZIP") -endif() -if(${CMAKE_SYSTEM} MATCHES "Linux") - set(CPACK_GENERATOR "TGZ") -endif() -if(${CMAKE_SYSTEM} MATCHES "Darwin") - set(CPACK_GENERATOR "DragNDrop") -endif() - -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sonic Robo Blast 2 Kart" CACHE STRING "Program name for display purposes") -set(CPACK_PACKAGE_VENDOR "Kart Krew" CACHE STRING "Vendor name for display purposes") -#set(CPACK_PACKAGE_DESCRIPTION_FILE ) -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") -set(CPACK_PACKAGE_VERSION_MAJOR ${SRB2_VERSION_MAJOR}) -set(CPACK_PACKAGE_VERSION_MINOR ${SRB2_VERSION_MINOR}) -set(CPACK_PACKAGE_VERSION_PATCH ${SRB2_VERSION_PATCH}) -set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}") -include(CPack) From 9f5a5a735b17cc74040ff3eea4c906cbf7decc7e Mon Sep 17 00:00:00 2001 From: PAS Date: Wed, 9 Jul 2025 23:22:57 -0400 Subject: [PATCH 02/50] Allow changing Cpak generator (from upstream) --- CMakeLists.txt | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d8354b44..84aa73968 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,9 @@ cmake_minimum_required(VERSION 3.5) + +if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) + message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.") +endif() + # DO NOT CHANGE THIS SRB2 STRING! Some variable names depend on this string. # Version change is fine. project(SRB2 @@ -11,22 +16,21 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_C_EXTENSIONS ON) -if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) - message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.") -endif() - ##### PACKAGE CONFIGURATION ##### -if(${CMAKE_SYSTEM} MATCHES "Windows") - set(CPACK_GENERATOR "ZIP") -endif() -if(${CMAKE_SYSTEM} MATCHES "Linux") - set(CPACK_GENERATOR "TGZ") -endif() -if(${CMAKE_SYSTEM} MATCHES "Darwin") - set(CPACK_GENERATOR "DragNDrop") +set(SRB2_CPACK_GENERATOR "" CACHE STRING "Generator to use for making a package. E.g., ZIP, TGZ, DragNDrop (OSX only). Leave blank for default generator.") + +if("${SRB2_CPACK_GENERATOR}" STREQUAL "") + if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows") + set(SRB2_CPACK_GENERATOR "ZIP") + elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + set(SRB2_CPACK_GENERATOR "TGZ") + elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + set(SRB2_CPACK_GENERATOR "TGZ") + endif() endif() +set(CPACK_GENERATOR ${SRB2_CPACK_GENERATOR}) set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sonic Robo Blast 2 Kart" CACHE STRING "Program name for display purposes") set(CPACK_PACKAGE_VENDOR "Kart Krew" CACHE STRING "Vendor name for display purposes") #set(CPACK_PACKAGE_DESCRIPTION_FILE ) From 346b1456cd1f6aed166272fa4d9a56c3712af087 Mon Sep 17 00:00:00 2001 From: PAS Date: Mon, 21 Apr 2025 16:51:31 -0400 Subject: [PATCH 03/50] CMake: Fix FindOPENMPT --- cmake/Modules/FindOPENMPT.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/FindOPENMPT.cmake b/cmake/Modules/FindOPENMPT.cmake index 2d334b6f0..305a55ee1 100644 --- a/cmake/Modules/FindOPENMPT.cmake +++ b/cmake/Modules/FindOPENMPT.cmake @@ -1,6 +1,6 @@ include(LibFindMacros) -libfind_pkg_check_modules(OPENMPT_PKGCONF OPENMPT) +libfind_pkg_check_modules(OPENMPT_PKGCONF LIBOPENMPT) find_path(OPENMPT_INCLUDE_DIR NAMES libopenmpt.h @@ -8,6 +8,7 @@ find_path(OPENMPT_INCLUDE_DIR ${OPENMPT_PKGCONF_INCLUDE_DIRS} "/usr/include/libopenmpt" "/usr/local/include/libopenmpt" + PATH_SUFFIXES libopenmpt ) find_library(OPENMPT_LIBRARY @@ -20,4 +21,4 @@ find_library(OPENMPT_LIBRARY set(OPENMPT_PROCESS_INCLUDES OPENMPT_INCLUDE_DIR) set(OPENMPT_PROCESS_LIBS OPENMPT_LIBRARY) -libfind_process(OPENMPT) \ No newline at end of file +libfind_process(OPENMPT) From e7efd464196cae77d694a5f6bb34fd662877c944 Mon Sep 17 00:00:00 2001 From: PAS Date: Mon, 21 Apr 2025 17:51:48 -0400 Subject: [PATCH 04/50] Fix FindGME pkg-config command, update LibFindMacros.cmake --- cmake/Modules/FindGME.cmake | 4 +-- cmake/Modules/LibFindMacros.cmake | 55 +++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/cmake/Modules/FindGME.cmake b/cmake/Modules/FindGME.cmake index ea80af454..641274e75 100644 --- a/cmake/Modules/FindGME.cmake +++ b/cmake/Modules/FindGME.cmake @@ -1,6 +1,6 @@ include(LibFindMacros) -libfind_pkg_check_modules(GME_PKGCONF GME) +libfind_pkg_check_modules(GME_PKGCONF LIBGME) find_path(GME_INCLUDE_DIR NAMES gme.h @@ -20,4 +20,4 @@ find_library(GME_LIBRARY set(GME_PROCESS_INCLUDES GME_INCLUDE_DIR) set(GME_PROCESS_LIBS GME_LIBRARY) -libfind_process(GME) \ No newline at end of file +libfind_process(GME) diff --git a/cmake/Modules/LibFindMacros.cmake b/cmake/Modules/LibFindMacros.cmake index 81fef7d8e..0e29dea5e 100644 --- a/cmake/Modules/LibFindMacros.cmake +++ b/cmake/Modules/LibFindMacros.cmake @@ -1,4 +1,4 @@ -# Version 2.2 +# Version 2.4 # Public Domain, originally written by Lasse Kärkkäinen # Maintained at https://github.com/Tronic/cmake-modules # Please send your improvements as pull requests on Github. @@ -52,6 +52,10 @@ function (libfind_pkg_detect PREFIX) if (libraryargs) find_library(${PREFIX}_LIBRARY NAMES ${libraryargs} HINTS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}) endif() + # Read pkg-config version + if (${PREFIX}_PKGCONF_VERSION) + set(${PREFIX}_VERSION ${${PREFIX}_PKGCONF_VERSION} PARENT_SCOPE) + endif() endfunction() # Extracts a version #define from a version.h file, output stored to _VERSION. @@ -125,24 +129,39 @@ function (libfind_process PREFIX) # Process deps to add to foreach (i ${PREFIX} ${${PREFIX}_DEPENDENCIES}) - if (DEFINED ${i}_INCLUDE_OPTS OR DEFINED ${i}_LIBRARY_OPTS) + if (DEFINED ${i}_INCLUDE_OPTS) # The package seems to export option lists that we can use, woohoo! list(APPEND includeopts ${${i}_INCLUDE_OPTS}) + else() + if (DEFINED ${i}_INCLUDE_DIR) + # Singular forms can be used + list(APPEND includeopts ${i}_INCLUDE_DIR) + else() + if (DEFINED ${i}_INCLUDE_DIRS) + # Plural forms can be used + list(APPEND includeopts ${i}_INCLUDE_DIRS) + else() + # Oh no, we don't know the option names + message(FATAL_ERROR "We couldn't determine config variable names for ${i} includes. Aieeh!") + endif() + endif() + endif() + + if (DEFINED ${i}_LIBRARY_OPTS) + # The package seems to export option lists that we can use, woohoo! list(APPEND libraryopts ${${i}_LIBRARY_OPTS}) else() - # If plural forms don't exist or they equal singular forms - if ((NOT DEFINED ${i}_INCLUDE_DIRS AND NOT DEFINED ${i}_LIBRARIES) OR - ({i}_INCLUDE_DIR STREQUAL ${i}_INCLUDE_DIRS AND ${i}_LIBRARY STREQUAL ${i}_LIBRARIES)) + if (DEFINED ${i}_LIBRARY) # Singular forms can be used - if (DEFINED ${i}_INCLUDE_DIR) - list(APPEND includeopts ${i}_INCLUDE_DIR) - endif() - if (DEFINED ${i}_LIBRARY) - list(APPEND libraryopts ${i}_LIBRARY) - endif() + list(APPEND libraryopts ${i}_LIBRARY) else() - # Oh no, we don't know the option names - message(FATAL_ERROR "We couldn't determine config variable names for ${i} includes and libs. Aieeh!") + if (DEFINED ${i}_LIBRARIES) + # Plural forms can be used + list(APPEND libraryopts ${i}_LIBRARIES) + else() + # Oh no, we don't know the option names + message(FATAL_ERROR "We couldn't determine config variable names for ${i} libraries. Aieeh!") + endif() endif() endif() endforeach() @@ -209,12 +228,12 @@ function (libfind_process PREFIX) message(STATUS " ${PREFIX}_LIBRARY_OPTS=${libraryopts}") message(STATUS " ${PREFIX}_LIBRARIES=${libs}") endif() - set (${PREFIX}_INCLUDE_OPTS ${includeopts} PARENT_SCOPE) - set (${PREFIX}_LIBRARY_OPTS ${libraryopts} PARENT_SCOPE) - set (${PREFIX}_INCLUDE_DIRS ${includes} PARENT_SCOPE) - set (${PREFIX}_LIBRARIES ${libs} PARENT_SCOPE) - set (${PREFIX}_FOUND TRUE PARENT_SCOPE) endif() + set (${PREFIX}_INCLUDE_OPTS ${includeopts} PARENT_SCOPE) + set (${PREFIX}_LIBRARY_OPTS ${libraryopts} PARENT_SCOPE) + set (${PREFIX}_INCLUDE_DIRS ${includes} PARENT_SCOPE) + set (${PREFIX}_LIBRARIES ${libs} PARENT_SCOPE) + set (${PREFIX}_FOUND TRUE PARENT_SCOPE) return() endif() From 96eaf8850eb5d70bf6c4a2e727091bfc075055fb Mon Sep 17 00:00:00 2001 From: PAS Date: Wed, 20 Aug 2025 02:23:20 -0400 Subject: [PATCH 05/50] Add path suffix for libgme cmake module --- cmake/Modules/FindGME.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/Modules/FindGME.cmake b/cmake/Modules/FindGME.cmake index 641274e75..7e9087247 100644 --- a/cmake/Modules/FindGME.cmake +++ b/cmake/Modules/FindGME.cmake @@ -8,6 +8,7 @@ find_path(GME_INCLUDE_DIR ${GME_PKGCONF_INCLUDE_DIRS} "/usr/include/gme" "/usr/local/include/gme" + PATH_SUFFIXES gme ) find_library(GME_LIBRARY From d9a67faf4772fd9f6efaae2ea73c53c3de670b5a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 21 Jan 2026 21:09:33 +0100 Subject: [PATCH 06/50] fix windoze compile --- src/sdl/i_system.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 1d1a8b00f..52a78232f 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -30,7 +30,10 @@ #endif #include + +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) #include +#endif #ifdef _WIN32 #define RPC_NO_WINDOWS_H From a3557fadef9712f70c66ba4e166f7ea43be06c71 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 21 Jan 2026 23:38:41 +0300 Subject: [PATCH 07/50] P_PlayRinglossSound from lua might desynch so print warning about that --- src/lua_baselib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 0da8abfae..bc94e2949 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1293,6 +1293,7 @@ static int lib_pPlayRinglossSound(lua_State *L) player_t *player = NULL; mobj_t *damager = NULL; NOHUD + LUA_UsageWarning(L, "P_PlayRinglossSound: using this function from lua might cause desynchs, consider using S_StartSound(origin, sfx_khurt1 + P_RandomKey(2)) as workaround"); if (!source) return LUA_ErrInvalid(L, "mobj_t"); if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) From 4600da5782c5c5a6bcf25ef5d56a2ba40118e063 Mon Sep 17 00:00:00 2001 From: PAS Date: Wed, 21 Jan 2026 15:54:32 -0500 Subject: [PATCH 08/50] restore SRB2_SDL2_EXE_NAME --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84aa73968..3184252da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,6 +126,9 @@ endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") +# Set EXE names so the assets CMakeLists can refer to its target +set(SRB2_SDL2_EXE_NAME srb2kart CACHE STRING "Executable binary output name") + include_directories(${CMAKE_CURRENT_BINARY_DIR}/src) add_subdirectory(src) From 0f7001ef5c41eccfd9d64b8190f9899958ea8506 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Jan 2026 13:25:07 +0100 Subject: [PATCH 09/50] opengl: tiny optimiazation for vhs effect dont call rand within the loop, use xorshift instead while not massive, we dont need to call rand thousands of times, the xorshift is visually indistinguishable this is still rather slow due to the crapton of draw calls and should best be replaced by a shader or something --- src/hardware/r_opengl/r_opengl.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 2d1f8e255..e644f5bd0 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3591,22 +3591,29 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 1.0f, -1.0f, 1.0f }; - xfix = 1/((float)screen_texsizew/(float)screen_width); - yfix = 1/((float)screen_texsizeh/(float)screen_height); - const GLfloat scrwf = (float)screen_width; const GLfloat scrwh = (float)screen_height; + xfix = 1/((float)screen_texsizew/scrwf); + yfix = 1/((float)screen_texsizeh/scrwh); + + GL_SetBlend(PF_Modulated|PF_Translucent|PF_NoDepthTest); + // Slight fuzziness GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); - GL_SetBlend(PF_Modulated|PF_Translucent|PF_NoDepthTest); pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); - const float stride = 2.f/scrwh; + uint32_t r = rand(); + const float stride = 2.f/scrwh; for (i = 0; i < 1; i += stride) { - fix[2] = (float)(rand() % 128) / -22000.f * xfix; + // avoid calling rand thousands of times + r ^= r >> 13; + r ^= r >> 11; + r ^= r << 21; + + fix[2] = (float)(r & 127) / -22000.f * xfix; fix[0] = fix[2]; fix[6] = fix[0] + xfix; fix[4] = fix[2] + xfix; @@ -3648,6 +3655,7 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 fix[1] = fix[7] += (fix[3] - fix[7])*2; screenVerts[1] = screenVerts[10] += (screenVerts[4] - screenVerts[1])*2; + pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -3673,6 +3681,7 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 fix[1] = fix[7] += (fix[3] - fix[7])*2; screenVerts[1] = screenVerts[10] += (screenVerts[4] - screenVerts[1])*2; + pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -3712,7 +3721,7 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh { float xfix, yfix; float origaspect, newaspect; - float xoff = 1, yoff = 1; // xoffset and yoffset for the polygon to have black bars around the screen + float xoff = 1.0f, yoff = 1.0f; // xoffset and yoffset for the polygon to have black bars around the screen static float off[12] = { @@ -3735,19 +3744,19 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh if (origaspect < newaspect) { xoff = origaspect / newaspect; - yoff = 1; + yoff = 1.0f; } else if (origaspect > newaspect) { - xoff = 1; + xoff = 1.0f; yoff = newaspect / origaspect; } // float off[12]; off[0] = off[3] = -xoff; off[1] = off[10] = -yoff; - off[4] = off[7] = yoff; - off[6] = off[9] = xoff; + off[4] = off[7] = yoff; + off[6] = off[9] = xoff; // float fix[8]; fix[3] = fix[5] = yfix; From 2e0f5c02a41e5fd0daee9322125e40f1cea6a845 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Jan 2026 13:25:56 +0100 Subject: [PATCH 10/50] opengl: make vhs effect bars be affected by "fuzzines" makes stuff slightly slower, but matches the software effect --- src/hardware/r_opengl/r_opengl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e644f5bd0..0caf50636 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3631,8 +3631,8 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 } // Upward bar - //GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); - //pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); + pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); color[0] = color[1] = color[2] = 190; color[3] = 250; @@ -3661,8 +3661,8 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); // Downward bar - //GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); - //pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); + GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); + pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); fix[0] = 0.0f; fix[6] = xfix; From a1f70b0b312fb00ee09beecf8e8f951ea0c3035b Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Jan 2026 14:18:06 +0100 Subject: [PATCH 11/50] opengl: attempt to scale vhs effect "fuzzyness" this makes it appear more or less the same in all resolutions, similar to software, while also improving performance quite a bit on higher resolutions --- src/hardware/r_opengl/r_opengl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 0caf50636..8bc68d15e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3605,8 +3605,10 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 uint32_t r = rand(); - const float stride = 2.f/scrwh; - for (i = 0; i < 1; i += stride) + const float dup = min(scrwf / BASEVIDWIDTH, scrwh / BASEVIDHEIGHT); + const float ystep = 2.f/scrwh * dup/4.f; + + for (i = 0; i < 1; i += ystep) { // avoid calling rand thousands of times r ^= r >> 13; From bbf06b3376c87383d5f473279ae6d4500d5e9a8b Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Jan 2026 14:25:33 +0100 Subject: [PATCH 12/50] add "vid.udup" same as vid.dup but not scaled with "highreshudscale" --- src/hardware/r_opengl/r_opengl.c | 3 +-- src/screen.h | 1 + src/v_video.c | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 8bc68d15e..eeb40a8dc 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3605,8 +3605,7 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 uint32_t r = rand(); - const float dup = min(scrwf / BASEVIDWIDTH, scrwh / BASEVIDHEIGHT); - const float ystep = 2.f/scrwh * dup/4.f; + const float ystep = 2.f/scrwh * (float)vid.udup/4.f; for (i = 0; i < 1; i += ystep) { diff --git a/src/screen.h b/src/screen.h index 0a912e97a..bc42e4cd3 100644 --- a/src/screen.h +++ b/src/screen.h @@ -63,6 +63,7 @@ typedef struct viddef_s INT32 dup; // scale 1, 2, 3 value for menus & overlays INT32 fdup; // same as dup, but exact value when aspect ratio isn't 320/200 + INT32 udup; // same as dup but does not account for highreshudscale UINT8 smalldup; // factor for a little bit of scaling UINT8 meddup; // factor for moderate, but not full, scaling diff --git a/src/v_video.c b/src/v_video.c index b5be19a97..8a1f36c72 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1760,17 +1760,15 @@ void V_DrawVhsEffect(boolean rewind) if (cv_reducevfx.value) return; - const INT32 dup = min(vid.width / BASEVIDWIDTH, vid.height / BASEVIDHEIGHT); - - barsize = dup << 5; - updistort = dup << (rewind ? 5 : 3); + barsize = vid.udup << 5; + updistort = vid.udup << (rewind ? 5 : 3); downdistort = updistort >> 1; if (rewind) V_DrawVhsEffect(false); // experimentation - upbary -= renderdeltatics * (fixed_t)(dup * (rewind ? 3 : 1.8f)); - downbary += renderdeltatics * (dup * (rewind ? 2 : 1)); + upbary -= renderdeltatics * (fixed_t)(vid.udup * (rewind ? 3 : 1.8f)); + downbary += renderdeltatics * (vid.udup * (rewind ? 2 : 1)); if (upbary < -barsize*FRACUNIT) upbary = vid.height << FRACBITS; @@ -3930,6 +3928,8 @@ void V_Recalc(void) vid.fdup = (vid.height*FRACUNIT) / BASEVIDHEIGHT; } + vid.udup = vid.dup; + if (loaded_config // this could use a better name, since it is more and indicator that early startup is done and its safe to do sketchy shit now :chaosleep: && (vid.width > 720) && (vid.height > 1280)) // ehhhh well this thing has so many issues, so ill lock it to higher resolutions instead { From e2ecc315b4d5d045c31229e664f2e95ca8d50a1d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Jan 2026 14:44:47 +0100 Subject: [PATCH 13/50] cmake: attempt to fix dedicated build uhh building --- src/dedicated/CMakeLists.txt | 101 +++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 22 deletions(-) diff --git a/src/dedicated/CMakeLists.txt b/src/dedicated/CMakeLists.txt index 36f670251..84e36690f 100644 --- a/src/dedicated/CMakeLists.txt +++ b/src/dedicated/CMakeLists.txt @@ -1,21 +1,75 @@ # Declare dedicated interface sources -target_sourcefile(c) +set(SRB2_DEDICATED_SOURCES + i_system.c + i_main.c + i_video.c + i_sound.c + i_threads.c + dosstr.c + endtxt.c +) -target_sources(SRB2SDL2 PRIVATE) +set(SRB2_DEDICATED_HEADERS + endtxt.h +) + +source_group("Interface Code" FILES ${SRB2_DEDICATED_SOURCES} ${SRB2_DEDICATED_HEADERS}) + +set(SRB2_DEDICATED_TOTAL_SOURCES + ${SRB2_CORE_SOURCES} + ${SRB2_CORE_HEADERS} + ${SRB2_PNG_SOURCES} + ${SRB2_PNG_HEADERS} + ${SRB2_CORE_RENDER_SOURCES} + ${SRB2_CORE_GAME_SOURCES} + ${SRB2_LUA_SOURCES} + ${SRB2_LUA_HEADERS} + ${SRB2_BLUA_SOURCES} + ${SRB2_BLUA_HEADERS} + ${SRB2_DEDICATED_SOURCES} + ${SRB2_DEDICATED_HEADERS} +) + +source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) +source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) +source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) +source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) +source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) if(${CMAKE_SYSTEM} MATCHES Windows) - target_sources(SRB2SDL2 PRIVATE - ../win32/win_dbg.c - ../win32/Srb2win.rc) + set(SRB2_DEDICATED_TOTAL_SOURCES ${SRB2_DEDICATED_TOTAL_SOURCES} + ${CMAKE_SOURCE_DIR}/src/win32/win_dbg.c + ${CMAKE_SOURCE_DIR}/src/win32/Srb2win.rc + ) endif() +add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 ${SRB2_DEDICATED_TOTAL_SOURCES}) + if(${CMAKE_SYSTEM} MATCHES Windows) - set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME srb2legacy) + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME srb2kartd) elseif(${CMAKE_SYSTEM} MATCHES Linux) - set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME lsrb2dlegacy) + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME lsrb2kartd) else() - set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME srb2legacy) + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME srb2kartd) +endif() + +if(${CMAKE_SYSTEM} MATCHES Darwin) + find_library(CORE_FOUNDATION_LIBRARY "CoreFoundation") + target_link_libraries(SRB2SDL2 PRIVATE + ${CORE_FOUNDATION_LIBRARY} + ) + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") + + # Configure the app bundle icon and plist properties + target_sources(SRB2SDL2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/macosx/Srb2mac.icns") + set_target_properties(SRB2SDL2 PROPERTIES + MACOSX_BUNDLE_ICON_FILE "Srb2mac" + MACOSX_BUNDLE_BUNDLE_NAME "Sonic Robo Blast 2" + MACOSX_BUNDLE_BUNDLE_VERSION ${SRB2_VERSION} + + RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/macosx/Srb2mac.icns" + ) endif() if(${CMAKE_SYSTEM} MATCHES Darwin) @@ -24,25 +78,27 @@ if(${CMAKE_SYSTEM} MATCHES Darwin) ${CORE_LIB} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} + ${CURL_LIBRARIES} ) set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") else() target_link_libraries(SRB2SDL2 PRIVATE ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} + ${CURL_LIBRARIES} ) - if(${CMAKE_SYSTEM} MATCHES Linux) target_link_libraries(SRB2SDL2 PRIVATE m rt + pthread ) endif() endif() -#target_link_libraries(SRB2SDL2 PRIVATE SRB2Core) - -set_target_properties(SRB2SDL2 PROPERTIES VERSION ${SRB2_VERSION}) +if(${SRB2_HAVE_LIBBACKTRACE}) + target_link_libraries(SRB2SDL2 PRIVATE ${LIBBACKTRACE_LIBRARIES}) +endif() if(${CMAKE_SYSTEM} MATCHES Windows) target_link_libraries(SRB2SDL2 PRIVATE @@ -60,19 +116,20 @@ target_include_directories(SRB2SDL2 PRIVATE target_compile_definitions(SRB2SDL2 PRIVATE -DDEDICATED + -DHAVE_THREADS ) ## strip debug symbols into separate file when using gcc -if(CMAKE_COMPILER_IS_GNUCC) - if(${CMAKE_BUILD_TYPE} MATCHES Debug) - message(STATUS "Will make separate debug symbols in *.debug") - add_custom_command(TARGET SRB2SDL2 POST_BUILD - COMMAND ${OBJCOPY} --only-keep-debug $ $.debug - COMMAND ${OBJCOPY} --strip-debug $ - COMMAND ${OBJCOPY} --add-gnu-debuglink=$.debug $ - ) - endif() -endif() +# if(CMAKE_COMPILER_IS_GNUCC) +# if(${CMAKE_BUILD_TYPE} MATCHES Debug) +# message(STATUS "Will make separate debug symbols in *.debug") +# add_custom_command(TARGET SRB2SDL2 POST_BUILD +# COMMAND ${OBJCOPY} --only-keep-debug $ $.debug +# COMMAND ${OBJCOPY} --strip-debug $ +# COMMAND ${OBJCOPY} --add-gnu-debuglink=$.debug $ +# ) +# endif() +# endif() #### Installation #### if(${CMAKE_SYSTEM} MATCHES Darwin) From 30539371c268d27dcd8a77cf9cc6fcff972b3584 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 22 Jan 2026 14:46:04 +0100 Subject: [PATCH 14/50] more cmake stuffs -add LTO option, enabled by default -set optimization level to O3 and O0 for debug builds -add ASAN and UBSAN options -always compile with gnu debug symbols --- src/CMakeLists.txt | 25 ++++++++++++++++++------- src/dedicated/CMakeLists.txt | 14 ++++++++++++++ src/sdl/CMakeLists.txt | 17 +++++++++++++++-- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f09b95633..77a1f40fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -236,18 +236,23 @@ set(SRB2_CONFIG_HWRENDER ON CACHE BOOL "Enable hardware rendering through OpenGL.") set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL "Use statically linked OpenGL. NOT RECOMMENDED.") -set(SRB2_CONFIG_SCREENFBO ON CACHE BOOL - "Enable hardware renderer (OpenGL) FBO downsampling support") set(SRB2_CONFIG_DEDICATED OFF CACHE BOOL "Build a dedicated server.") +set(SRB2_CONFIG_LIBBACKTRACE ON CACHE BOOL + "Enable using libbacktrace for crashlogs.") +set(SRB2_CONFIG_LTO ON CACHE BOOL + "Enable link time optimizations, improves performance at the cost of longer link times.") +set(SRB2_CONFIG_ASAN OFF CACHE BOOL + "Compile with AddressSanitizer (libasan).") +set(SRB2_CONFIG_UBSAN OFF CACHE BOOL + "Compile with UndefinedBehaviorSanitizer (libubsan).") set(SRB2_CONFIG_SATURNPAK ON CACHE BOOL "Enable Saturn specific special packet. Required for using the newer resynch system") set(SRB2_CONFIG_SATURNJOIN ON CACHE BOOL "Enable Saturn specific allowjoin toggle.") - -set(SRB2_CONFIG_LIBBACKTRACE ON CACHE BOOL - "Enable using libbacktrace for crashlogs") +set(SRB2_CONFIG_SCREENFBO ON CACHE BOOL + "Enable hardware renderer (OpenGL) FBO downsampling support") if(${SRB2_CONFIG_DEDICATED}) set(SRB2_CONFIG_HAVE_GME NO) @@ -502,7 +507,6 @@ if(${SRB2_CONFIG_LIBBACKTRACE}) if(${LIBBACKTRACE_FOUND}) set(SRB2_HAVE_LIBBACKTRACE ON) add_definitions(-DHAVE_LIBBACKTRACE) - add_compile_options(-g) else() message(WARNING "You have specified that libbacktrace is available but it was not found.") endif() @@ -550,7 +554,6 @@ if(${SRB2_CONFIG_HWRENDER}) set(SRB2_R_OPENGL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.h ) - endif() if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) @@ -589,6 +592,14 @@ endif() # TODO: fix prng and P_CreateBlockmap overflow at some point add_compile_options(-fwrapv) +if (${CMAKE_BUILD_TYPE} MATCHES Debug) + add_compile_options(-O0) +else() + add_compile_options(-O3) +endif() + +add_compile_options(-g) + add_definitions(-DCMAKECONFIG) #add_library(SRB2Core STATIC diff --git a/src/dedicated/CMakeLists.txt b/src/dedicated/CMakeLists.txt index 84e36690f..38fb179f0 100644 --- a/src/dedicated/CMakeLists.txt +++ b/src/dedicated/CMakeLists.txt @@ -119,6 +119,20 @@ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS ) +if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE) + set_property(TARGET SRB2SDL2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) +endif() + +if(SRB2_CONFIG_ASAN) + target_compile_options(SRB2SDL2 PRIVATE -fsanitize=address) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) +endif() + +if(SRB2_CONFIG_UBSAN) + target_compile_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=undefined) +endif() + ## strip debug symbols into separate file when using gcc # if(CMAKE_COMPILER_IS_GNUCC) # if(${CMAKE_BUILD_TYPE} MATCHES Debug) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 1c7d52344..c7d612c80 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -169,7 +169,6 @@ if(${SDL2_FOUND}) target_link_libraries(SRB2SDL2 PRIVATE ${LIBBACKTRACE_LIBRARIES}) endif() - if(${CMAKE_SYSTEM} MATCHES Linux) target_link_libraries(SRB2SDL2 PRIVATE m @@ -230,6 +229,20 @@ if(${SDL2_FOUND}) -DHAVE_THREADS ) + if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE) + set_property(TARGET SRB2SDL2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + endif() + + if(SRB2_CONFIG_ASAN) + target_compile_options(SRB2SDL2 PRIVATE -fsanitize=address) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) + endif() + + if(SRB2_CONFIG_UBSAN) + target_compile_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + endif() + ## strip debug symbols into separate file when using gcc # if(CMAKE_COMPILER_IS_GNUCC) # if(${CMAKE_BUILD_TYPE} MATCHES Debug) @@ -296,7 +309,7 @@ if(${SDL2_FOUND}) else() find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}") list(APPEND win_extra_dll_list ${SRB2_SDL2_DLL_${dllname}}) - endif() + endif() endmacro() getwinlib(SDL2 "SDL2.dll") if(${SRB2_CONFIG_SDL2_USEMIXER}) From 522904527fd8173d61880da7cef4892d36ef4cb7 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 23 Jan 2026 10:08:35 +0100 Subject: [PATCH 15/50] 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 16/50] 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 17/50] 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 18/50] 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 19/50] 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 20/50] 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 21/50] 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 22/50] "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 23/50] 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 24/50] 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 25/50] 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 26/50] 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 27/50] 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 28/50] 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; From 8cab07a4b21c3fa148cbd143f5ca3e2271beae5c Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 3 Feb 2026 15:39:58 +0100 Subject: [PATCH 29/50] add missing "ifdef LOGMESSAGES" --- src/http-mserv.c | 3 ++- src/sdl/i_system.cpp | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/http-mserv.c b/src/http-mserv.c index fd63c5f69..9e4374353 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -225,9 +225,10 @@ HMS_connect (const char *format, ...) { cc = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); if (cc != CURLE_OK) I_OutputMsg("libcurl: %s\n", buffer->errbuf); - +#ifdef LOGMESSAGES cc = curl_easy_setopt(curl, CURLOPT_STDERR, logstream); if (cc != CURLE_OK) I_OutputMsg("libcurl: %s\n", buffer->errbuf); +#endif } if (M_CheckParm("-bindaddr") && M_IsNextParm()) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 4dd32161e..b90fbf898 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1841,18 +1841,15 @@ static void I_Fork(void) I_RegisterChildSignals(); break; default: +#ifdef LOGMESSAGES if (logstream) fclose(logstream);/* the child has this */ - +#endif c = wait(&status); - #ifdef LOGMESSAGES /* By the way, exit closes files. */ logstream = fopen(logfilename, "at"); -#else - logstream = 0; #endif - if (c == -1) { kill(child, SIGKILL); From 16e0c6f0f6b348bfa83cc2b2795cec9e2071fbf8 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Feb 2026 18:25:13 +0100 Subject: [PATCH 30/50] dont constantly fetch lookback joyaxis in p_ticker if replay recording is enabled minuscule optimization lul --- src/p_tick.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/p_tick.c b/src/p_tick.c index 88e8fb2fd..9365f5669 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -728,11 +728,12 @@ void P_Ticker(boolean run) if (cv_recordmultiplayerdemos.value) { - const INT32 axis = JoyAxis(AXISLOOKBACK, 1); - if (demo.savemode == DSM_NOTSAVING || demo.savemode == DSM_WILLAUTOSAVE) - if (demo.savebutton && demo.savebutton + 3*TICRATE < leveltime && (InputDown(gc_lookback, 1) || (cv_usejoystick[0].value && axis > 0))) + { + const INT32 axis = cv_usejoystick[0].value ? JoyAxis(AXISLOOKBACK, 1) : -1; + if (demo.savebutton && demo.savebutton + 3*TICRATE < leveltime && (InputDown(gc_lookback, 1) || (axis > 0))) demo.savemode = DSM_TITLEENTRY; + } // if there are no players left at all, stop demo recording // Demos that that dont have any players crash during playback, which can happen with dedicated servers From 0fbde146a973bdf696c9ab1a48959fd47c6fb99f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Feb 2026 20:07:28 +0100 Subject: [PATCH 31/50] remove some unused fields from precipmobj_t we do not have animating precip nor do we cast it to mobj_t anymore, so we can just get rid of this stuff reducing the struct size by 16bytes wowie --- src/p_mobj.c | 8 ++++---- src/p_mobj.h | 7 ++----- src/p_spec.c | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index d1b8b850a..11f12b5c5 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -335,7 +335,7 @@ static boolean P_SetPrecipMobjState(precipmobj_t *mobj, statenum_t state) mobj->tics = st->tics; mobj->sprite = st->sprite; mobj->frame = st->frame; - mobj->anim_duration = (UINT16)st->var2; // only used if FF_ANIMATE is set + //mobj->anim_duration = (UINT16)st->var2; // only used if FF_ANIMATE is set return true; } @@ -3620,7 +3620,7 @@ boolean P_PrecipThinker(precipmobj_t *mobj) mobj->lastThink = leveltime; R_ResetPrecipitationMobjInterpolationState(mobj); - P_CycleStateAnimation((mobj_t *)mobj); + //P_CycleStateAnimation((mobj_t *)mobj); // if we ever want animated precip, readd a specific function which does not need casting if (mobj->state == &states[S_RAINRETURN]) { @@ -10034,7 +10034,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype mobj->x = x; mobj->y = y; - mobj->flags = info->flags; + //mobj->flags = info->flags; // do not set the state with P_SetMobjState, // because action routines can not be called yet @@ -10044,7 +10044,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype mobj->tics = st->tics; mobj->sprite = st->sprite; mobj->frame = st->frame; // FF_FRAMEMASK for frame, and other bits.. - mobj->anim_duration = (UINT16)st->var2; // only used if FF_ANIMATE is set + //mobj->anim_duration = (UINT16)st->var2; // only used if FF_ANIMATE is set // set subsector and/or block links P_SetPrecipitationThingPosition(mobj); diff --git a/src/p_mobj.h b/src/p_mobj.h index 38bbe2e37..278c40d18 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -444,12 +444,10 @@ typedef struct precipmobj_s // More drawing info: to determine current sprite. spritenum_t sprite; // used to find patch_t and flip value UINT32 frame; // frame number, plus bits see p_pspr.h - UINT16 anim_duration; // for FF_ANIMATE states + //UINT16 anim_duration; // for FF_ANIMATE states INT16 lightlevel; // Add to sector lightlevel, -255 - 255 - struct mprecipsecnode_s *touching_sectorlist; // a linked list of sectors where this object appears - struct subsector_s *subsector; // Subsector the mobj resides in. // The closest interval over all contacted sectors (or things). @@ -458,11 +456,10 @@ typedef struct precipmobj_s // Momentums, used to update position. fixed_t momx, momy, momz; - fixed_t precipflags; // fixed_t so it uses the same spot as "pmomz" even as we use precipflags_t for it + precipflag_t precipflags; state_t *state; INT32 tics; // state tic counter - UINT32 flags; // flags from mobjinfo tables tic_t lastThink; } precipmobj_t; diff --git a/src/p_spec.c b/src/p_spec.c index b313f77a1..9c3c0c0c3 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1702,7 +1702,7 @@ void P_SwitchWeather(INT32 weathernum) precipmobj->type = type; // proper set the type precipmobj->info = &mobjinfo[type]; - precipmobj->flags = mobjinfo[type].flags; + //precipmobj->flags = mobjinfo[type].flags; st = &states[mobjinfo[type].spawnstate+z]; From 6ba97bc43cd4c2f7d8f5fbd73606f368eff7bd1d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Feb 2026 21:00:54 +0100 Subject: [PATCH 32/50] only do the anim texture maths if we need it idk why but this showed up during profiling best would be just to redo the whole system since it sucks lol --- src/p_spec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 9c3c0c0c3..99584bb3d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4532,9 +4532,12 @@ void P_UpdateSpecials(void) { for (i = 0; i < anim->numpics; i++) { - pic = anim->basepic + ((leveltime/anim->speed + i) % anim->numpics); if (anim->istexture) + { + pic = anim->basepic + ((leveltime/anim->speed + i) % anim->numpics); texturetranslation[anim->basepic+i] = pic; + } + } } From 277b202020cfd02eb721a5927fc1890143fe4c5c Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Feb 2026 23:31:04 +0100 Subject: [PATCH 33/50] hooklib: init all the hook states idk i aint trusting any of this lul --- src/lua_hooklib.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index e571f7649..59d1bc1f8 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -615,7 +615,7 @@ FUNCINLINE static ATTRINLINE void res_hud(Hook_State *hook) int LUA_HookMobj(mobj_t *mobj, int hook_type) { - Hook_State hook; + Hook_State hook = {}; if (prepare_mobj_hook(&hook, false, hook_type, mobj)) { LUA_PushUserdata(gL, mobj, META_MOBJ); @@ -626,7 +626,7 @@ int LUA_HookMobj(mobj_t *mobj, int hook_type) int LUA_Hook2Mobj(mobj_t *t1, mobj_t *t2, int hook_type) { - Hook_State hook; + Hook_State hook = {}; if (prepare_mobj_hook(&hook, 0, hook_type, t1)) { LUA_PushUserdata(gL, t1, META_MOBJ); @@ -638,14 +638,14 @@ int LUA_Hook2Mobj(mobj_t *t1, mobj_t *t2, int hook_type) void LUA_HookVoid(int type) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, 0, type)) call_hooks(&hook, 0, res_none); } void LUA_HookInt(INT32 number, int hook_type) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, 0, hook_type)) { lua_pushinteger(gL, number); @@ -655,7 +655,7 @@ void LUA_HookInt(INT32 number, int hook_type) /*void LUA_HookBool(boolean value, int hook_type) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, 0, hook_type)) { //lua_pushboolean(gL, value); @@ -665,7 +665,7 @@ void LUA_HookInt(INT32 number, int hook_type) int LUA_HookPlayer(player_t *player, int hook_type) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, false, hook_type)) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -676,7 +676,7 @@ int LUA_HookPlayer(player_t *player, int hook_type) int LUA_HookTiccmd(player_t *player, ticcmd_t *cmd, int hook_type) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, false, hook_type)) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -695,7 +695,7 @@ int LUA_HookTiccmd(player_t *player, ticcmd_t *cmd, int hook_type) void LUA_HookHUD(int hook_type, huddrawlist_h list) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hud_hook(&hook, hook_type)) { LUA_SetHudHook(hook_type, list); @@ -723,7 +723,7 @@ static void hook_think_frame(int type) int hook_index = 0; precise_t time_taken = 0; - Hook_State hook; + Hook_State hook = {}; const hook_t * map = &hookIds[type]; int k; @@ -783,7 +783,7 @@ void LUA_HookPostThinkFrame(void) int LUA_HookTouchSpecial(mobj_t *special, mobj_t *toucher) { - Hook_State hook; + Hook_State hook = {}; if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(TouchSpecial), special)) { LUA_PushUserdata(gL, special, META_MOBJ); @@ -802,7 +802,7 @@ static int damage_hook int hook_type, Hook_Callback results_handler ){ - Hook_State hook; + Hook_State hook = {}; if (prepare_mobj_hook(&hook, 0, hook_type, target)) { LUA_PushUserdata(gL, target, META_MOBJ); @@ -890,8 +890,8 @@ int LUA_HookBotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) { const char *skin = ((skin_t *)tails->skin)->name; - Hook_State hook; - BotAI_State botai; + Hook_State hook = {}; + BotAI_State botai = {}; if (prepare_string_hook(&hook, false, STRING_HOOK(BotAI), skin)) { @@ -911,7 +911,7 @@ int LUA_HookBotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd) void LUA_HookLinedefExecute(line_t *line, mobj_t *mo, sector_t *sector) { - Hook_State hook; + Hook_State hook = {}; if (prepare_string_hook (&hook, 0, STRING_HOOK(LinedefExecute), line->text)) { @@ -924,7 +924,7 @@ void LUA_HookLinedefExecute(line_t *line, mobj_t *mo, sector_t *sector) int LUA_HookPlayerMsg(int source, int target, int flags, char *msg, int mute) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, false, HOOK(PlayerMsg))) { LUA_PushUserdata(gL, &players[source], META_PLAYER); // Source player @@ -953,7 +953,7 @@ int LUA_HookPlayerMsg(int source, int target, int flags, char *msg, int mute) int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source) { - Hook_State hook; + Hook_State hook = {}; if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(HurtMsg), inflictor)) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -967,7 +967,7 @@ int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source) void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save) { const hook_t * map = &hookIds[HOOK(NetVars)]; - Hook_State hook; + Hook_State hook = {}; /* this is a remarkable case where the stack isn't reset */ if (map->numHooks > 0) { @@ -997,7 +997,7 @@ void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save) void LUA_HookPlayerQuit(player_t *plr, int reason) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, 0, HOOK(PlayerQuit))) { LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit @@ -1060,7 +1060,7 @@ int LUA_HookMusicChange(const char *oldname, struct MusicChange *param) const int type = HOOK(MusicChange); const hook_t * map = &hookIds[type]; - Hook_State hook; + Hook_State hook = {}; int k; @@ -1096,7 +1096,7 @@ int LUA_HookMusicChange(const char *oldname, struct MusicChange *param) int LUA_HookMusicCredit(musicdef_t *musicdef) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, 0, HOOK(MusicCredit))) { LUA_PushUserdata(gL, musicdef, META_MUSICDEF); @@ -1114,7 +1114,7 @@ static int kartdamage_hook int hook_type, Hook_Callback results_handler ){ - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, 0, hook_type)) { LUA_PushUserdata(gL, player, META_PLAYER); @@ -1163,7 +1163,7 @@ boolean LUA_HookPlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *sourc void LUA_HookSetupVote(INT16 result[], INT16 maxresults, UINT8 gt, UINT8 secondgt) { - Hook_State hook; + Hook_State hook = {}; if (prepare_hook(&hook, 0, HOOK(SetupVote))) { // { 0, 0, 0, 0, } From ecef8913b1220dcd577d60563baa324073ed9d8e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 6 Feb 2026 17:06:33 +0100 Subject: [PATCH 34/50] remove some more dead code as reported by clang-tidy --- src/k_hud.c | 2 -- src/k_kart.c | 1 - src/m_anigif.c | 2 +- src/m_menu.c | 9 --------- src/p_inter.c | 1 - src/p_mobj.c | 2 +- src/p_spec.c | 32 +++++++++++++------------------- src/p_user.c | 10 ---------- src/sdl/i_video.c | 4 ++-- src/w_wad.c | 2 +- 10 files changed, 18 insertions(+), 47 deletions(-) diff --git a/src/k_hud.c b/src/k_hud.c index d0146a38e..4f10bf749 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -1415,8 +1415,6 @@ static void K_drawKartStats(void) break; } } - else - spdoffset = 0; if (G_BattleGametype() && ((speedostyle != SPEEDO_DIAL) || splitscreen)) spdoffset += ((stplyr->kartstuff[k_bumper] ? -5 : -8)); diff --git a/src/k_kart.c b/src/k_kart.c index 6496f3e8e..747a032b2 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1480,7 +1480,6 @@ void K_KartBouncing(mobj_t *mobj1, mobj_t *mobj2, boolean bounce, boolean solid) fixed_t nx = FixedDiv(distx, dist); fixed_t ny = FixedDiv(disty, dist); - dist = dist ? dist : 1; distx = FixedMul(mobj1->radius+mobj2->radius, nx); disty = FixedMul(mobj1->radius+mobj2->radius, ny); diff --git a/src/m_anigif.c b/src/m_anigif.c index cd37b08d6..c9cda476e 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -556,7 +556,7 @@ static void GIF_framewrite(void) } else if (gif_dynamicdelay ==(UINT8) 1) { - float delayf = ceil(100.0f/NEWTICRATE); + float delayf = ceilf(100.0f/NEWTICRATE); delay = (UINT16)((I_GetPreciseTime() - gif_prevframetime)) / (I_GetPrecisePrecision() / 1000000) /10/1000; diff --git a/src/m_menu.c b/src/m_menu.c index 83c2dce77..5a2b92d92 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5522,7 +5522,6 @@ static void M_DrawChecklist(void) if (conditionSets[unlockables[i].conditionset - 1].numconditions) { - c = 0; lastid = -1; for (c = 0; c < conditionSets[unlockables[i].conditionset - 1].numconditions; c++) @@ -5682,9 +5681,6 @@ static void M_DrawMusicTest(void) { INT32 x, y, i; - x = 90<kartstuff[k_sneakertimer] = 0; K_SpinPlayer(player, source, 1, inflictor, false); - damage = player->mo->health - 1; P_RingDamage(player, inflictor, source); P_PlayerRingBurst(player, 5); diff --git a/src/p_mobj.c b/src/p_mobj.c index 11f12b5c5..acc09ab58 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6986,7 +6986,7 @@ static boolean P_MobjDeadThink(mobj_t *mobj) fixed_t ns; mobj_t *mo2; - i = P_RandomByte(); + i = P_RandomByte(); // grrrrrr z = mobj->subsector->sector->floorheight + ((P_RandomByte()&63)*FRACUNIT); for (j = 0; j < 2; j++) diff --git a/src/p_spec.c b/src/p_spec.c index 99584bb3d..e537e17e6 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3161,11 +3161,6 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers INT32 section1, section2, section3, section4; INT32 special; - section1 = GETSECSPECIAL(sector->special, 1); - section2 = GETSECSPECIAL(sector->special, 2); - section3 = GETSECSPECIAL(sector->special, 3); - section4 = GETSECSPECIAL(sector->special, 4); - // Ignore spectators if (player->spectator) return; @@ -3176,6 +3171,11 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers if (player->playerstate == PST_DEAD) return; + section1 = GETSECSPECIAL(sector->special, 1); + section2 = GETSECSPECIAL(sector->special, 2); + section3 = GETSECSPECIAL(sector->special, 3); + section4 = GETSECSPECIAL(sector->special, 4); + // Conveyor stuff if (section3 == 2 || section3 == 4) player->onconveyor = section3; @@ -4381,8 +4381,6 @@ static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector) } } -#define VDOORSPEED (FRACUNIT*2) - // // P_RunSpecialSectorCheck // @@ -4512,9 +4510,7 @@ void P_UpdateSpecials(void) { anim_t *anim; INT32 i; - INT32 pic; size_t j; - levelflat_t *foundflats; // for flat animation // LEVEL TIMER @@ -4534,10 +4530,9 @@ void P_UpdateSpecials(void) { if (anim->istexture) { - pic = anim->basepic + ((leveltime/anim->speed + i) % anim->numpics); - texturetranslation[anim->basepic+i] = pic; + texturetranslation[anim->basepic+i] = anim->basepic + + ((leveltime/anim->speed + i) % anim->numpics); } - } } @@ -4632,8 +4627,8 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f if (sec2->numattached == 0) { - sec2->attached = Z_Malloc(sizeof (*sec2->attached) * sec2->maxattached, PU_STATIC, NULL); - sec2->attachedsolid = Z_Malloc(sizeof (*sec2->attachedsolid) * sec2->maxattached, PU_STATIC, NULL); + sec2->attached = Z_Malloc(sizeof(*sec2->attached) * sec2->maxattached, PU_STATIC, NULL); + sec2->attachedsolid = Z_Malloc(sizeof(*sec2->attachedsolid) * sec2->maxattached, PU_STATIC, NULL); sec2->attached[0] = sec - sectors; sec2->numattached = 1; sec2->attachedsolid[0] = (flags & FF_SOLID); @@ -4647,8 +4642,8 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f if (sec2->numattached >= sec2->maxattached) { sec2->maxattached *= 2; - sec2->attached = Z_Realloc(sec2->attached, sizeof (*sec2->attached) * sec2->maxattached, PU_STATIC, NULL); - sec2->attachedsolid = Z_Realloc(sec2->attachedsolid, sizeof (*sec2->attachedsolid) * sec2->maxattached, PU_STATIC, NULL); + sec2->attached = Z_Realloc(sec2->attached, sizeof(*sec2->attached) * sec2->maxattached, PU_STATIC, NULL); + sec2->attachedsolid = Z_Realloc(sec2->attachedsolid, sizeof(*sec2->attachedsolid) * sec2->maxattached, PU_STATIC, NULL); } sec2->attached[sec2->numattached] = sec - sectors; sec2->attachedsolid[sec2->numattached] = (flags & FF_SOLID); @@ -4656,7 +4651,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f } // Add the floor - ffloor = Z_Calloc(sizeof (*ffloor), PU_LEVEL, NULL); + ffloor = Z_Calloc(sizeof(*ffloor), PU_LEVEL, NULL); ffloor->secnum = sec2 - sectors; ffloor->target = sec; ffloor->bottomheight = &sec2->floorheight; @@ -5471,7 +5466,6 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) break; case 10: // Vertical culling plane for sprites and FOFs - sec = sides[*lines[i].sidenum].sector - sectors; for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) sectors[s].cullheight = &lines[i]; // This allows it to change in realtime! break; @@ -5992,7 +5986,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) if (!virt) virt = vres_GetMap(lastloadedmaplumpnum); - data = (UINT8*) vres_Find(virt, "SIDEDEFS")->data; + data = (UINT8*)vres_Find(virt, "SIDEDEFS")->data; for (b = 0; b < (INT16)numsides; b++) { diff --git a/src/p_user.c b/src/p_user.c index 2a3ccc300..a930ec6a1 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1894,7 +1894,6 @@ static void P_3dMovement(player_t *player) ticcmd_t *cmd; angle_t movepushangle, movepushsideangle; // Analog fixed_t movepushforward = 0, movepushside = 0; - angle_t dangle; // replaces old quadrants bits boolean analogmove = false; fixed_t oldMagnitude, newMagnitude; vector3_t totalthrust; @@ -1952,15 +1951,6 @@ static void P_3dMovement(player_t *player) // Calculates player's speed based on distance-of-a-line formula player->speed = R_PointToDist2(0, 0, player->rmomx, player->rmomy); - // Monster Iestyn - 04-11-13 - // Quadrants are stupid, excessive and broken, let's do this a much simpler way! - // Get delta angle from rmom angle and player angle first - dangle = R_PointToAngle2(0,0, player->rmomx, player->rmomy) - player->mo->angle; - if (dangle > ANGLE_180) //flip to keep to one side - { - dangle = InvAngle(dangle); - } - // When sliding, don't allow forward/back if (player->pflags & PF_SLIDING) cmd->forwardmove = 0; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 8b2adfa7b..e367b612f 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1164,8 +1164,8 @@ void I_GetEvent(void) SDL_GetWindowSize(window, &wwidth, &wheight); event.type = ev_mouse; event.data1 = 0; - event.data2 = (INT32)lround(mousemovex * ((float)wwidth / (float)realwidth)); - event.data3 = (INT32)lround(mousemovey * ((float)wheight / (float)realheight)); + event.data2 = (INT32)lroundf(mousemovex * ((float)wwidth / (float)realwidth)); + event.data3 = (INT32)lroundf(mousemovey * ((float)wheight / (float)realheight)); D_PostEvent(&event); } diff --git a/src/w_wad.c b/src/w_wad.c index 20a2ccc87..3009d503f 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -455,7 +455,7 @@ static lumpinfo_t* ResGetLumpsWad(FILE* handle, UINT16* nlmp, const char* filena header.infotableofs = LONG(header.infotableofs); // read wad file directory - i = header.numlumps * sizeof (*fileinfo); + i = header.numlumps * sizeof(*fileinfo); fileinfov = fileinfo = malloc(i); if (fseek(handle, header.infotableofs, SEEK_SET) == -1 From 86b286fb0bd6284c2ed41bfa375effe3ca29778b Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 6 Feb 2026 20:03:54 +0100 Subject: [PATCH 35/50] fix few more cases of using potentially uninitialized garbage --- src/command.c | 2 +- src/g_demo.c | 2 +- src/hardware/hw_main.cpp | 3 +-- src/hu_stuff.c | 3 +++ src/m_menu.c | 2 +- src/s_sound.c | 3 +-- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/command.c b/src/command.c index 6b71dce73..0b1578381 100644 --- a/src/command.c +++ b/src/command.c @@ -1793,7 +1793,7 @@ void CV_AddValue(consvar_t *var, INT32 increment) if (newvalue == oldvalue) break; // don't loop forever if there's none of a certain gametype - if (newvalue >= 0 && !mapheaderinfo[newvalue]) + if (newvalue >= 0 && newvalue < NUMMAPS && !mapheaderinfo[newvalue]) continue; // Don't allocate the header. That just makes memory usage skyrocket. } while (!M_CanShowLevelInList(newvalue, gt)); diff --git a/src/g_demo.c b/src/g_demo.c index ede5adf18..9662ce517 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -2605,7 +2605,7 @@ void G_DoPlayDemo(char *defdemoname) boolean skiperrors = false; #endif boolean spectator; - UINT8 slots[MAXPLAYERS], kartspeed[MAXPLAYERS], kartweight[MAXPLAYERS], numslots = 0; + UINT8 slots[MAXPLAYERS] = {}, kartspeed[MAXPLAYERS] = {}, kartweight[MAXPLAYERS] = {}, numslots = 0; G_InitDemoRewind(); diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 5cc8eacf7..e9aa0532d 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1378,8 +1378,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom FSurfaceInfo Surf; - if (gl_frontsector) - Surf.PolyColor.s.alpha = 255; + Surf.PolyColor.s.alpha = 255; const INT32 gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture); GLMapTexture_t *glTex = NULL; diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 653529bf4..6ede89fc6 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -497,7 +497,9 @@ static void HU_removeChatText_Log(void) { chat_log[i] = chat_log[i+1]; } + chat_nummsg_log--; // lost 1 msg. + chat_log[chat_nummsg_log] = NULL; } static void Chatlogsize_OnChange(void) @@ -516,6 +518,7 @@ static void Chatlogsize_OnChange(void) if (new_chat_log == NULL) { free(chat_log); + chat_log = NULL; return; } chat_log = new_chat_log; diff --git a/src/m_menu.c b/src/m_menu.c index 5a2b92d92..0e753f621 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2936,7 +2936,7 @@ static void M_PrepareLevelSelect(void) boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) { // invalid mapnum - if (mapnum < -1) + if (mapnum < -1 || mapnum >= NUMMAPS) return false; // Random map! diff --git a/src/s_sound.c b/src/s_sound.c index 7f931671d..f2ee1dc03 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -473,13 +473,12 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) return; memset(listener, 0, sizeof(listener)); + memset(listenmobj, 0, sizeof(listenmobj)); for (i = 0; i <= splitscreen; i++) { player_t *player = &players[displayplayers[i]]; - listenmobj[i] = NULL; - if (player->awayviewtics) { listenmobj[i] = player->awayviewmobj; From 02f2464a00987624babbf527d378383eda36ddc7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Feb 2026 23:13:16 +0100 Subject: [PATCH 36/50] HWR_CreateBlendedTexture: init a bunch of stuff --- src/hardware/hw_md2.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 56082e0fc..2fd33f65b 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -693,17 +693,15 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi GLPatch_t *hwrBlendPatch = blendgpatch->hardware; UINT16 w = gpatch->width, h = gpatch->height; UINT32 size = w*h; - RGBA_t *image, *blendimage, *cur, blendcolor; + RGBA_t *image, *blendimage, *cur; + RGBA_t blendcolor = {}; RGBA_t *palette = HWR_GetTexturePalette(); - UINT8 translation[17]; // First the color index - UINT8 cutoff[17]; // Brightness cutoff before using the next color + UINT8 translation[17] = {}; // First the color index + UINT8 cutoff[17] = {}; // Brightness cutoff before using the next color UINT8 translen = 0; UINT8 i; - UINT8 colorbrightnesses[17]; - UINT8 color_match_lookup[256]; // optimization attempt - - memset(translation, 0, sizeof(translation)); - memset(cutoff, 0, sizeof(cutoff)); + UINT8 colorbrightnesses[17] = {}; + UINT8 color_match_lookup[256] = {}; // optimization attempt if (glMipmap->width == 0) { @@ -716,14 +714,10 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi glMipmap->format = GL_TEXFMT_RGBA; } - if (glMipmap->data) - { - Z_Free(glMipmap->data); - glMipmap->data = NULL; - } + Z_Free(glMipmap->data); + glMipmap->data = NULL; - cur = Z_Malloc(size*4, PU_HWRMODELTEXTURE, &glMipmap->data); - memset(cur, 0x00, size*4); + cur = Z_Calloc(size*4, PU_HWRMODELTEXTURE, &glMipmap->data); image = hwrPatch->mipmap->data; blendimage = hwrBlendPatch->mipmap->data; @@ -1037,7 +1031,6 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk GLPatch_t *glPatch = patch->hardware; GLMipmap_t *glMipmap, *newMipmap; - if (blendgpatch == NULL || colormap == colormaps || colormap == NULL) { // Don't do any blending From 38fc6d6ba173478f7bd5ae88946df9f5ffd7a8c5 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 9 Feb 2026 16:09:26 +0100 Subject: [PATCH 37/50] remove screen texture toggle from accessability menu + new tooltip --- src/m_menudefs.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 1a21ec455..00b927efd 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -986,7 +986,7 @@ static const char* OP_ExpTooltips[] = "Skips rendering frames if game logic takes too long\npreventing gameplay issues during performance drops.", // idk im shit as describing things "Different methods of scaling the votescreen backgrounds.", #ifdef HWRENDER - "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", + "Disabling Screen Textures may result in a performance boost\nbut will break certain effects.\nScreen textures are required at resolutions lower than your desktop resolution!" #ifdef USE_FBO_OGL "Allows the game to downsample from a higher resolution\nthan your display in OpenGL renderer mode.\nRequires a GPU with atleast OpenGL 2.1 support.", #endif @@ -1644,29 +1644,25 @@ static menuitem_t OP_AccessibilityMenu[] = {IT_STRING|IT_CVAR, NULL, "Minimum Sector Brightness", &cv_secbright, 45}, -#ifdef HWRENDER - {IT_STRING|IT_CVAR, NULL, "Screen Textures", &cv_glscreentextures, 50}, -#endif + {IT_STRING|IT_CVAR, NULL, "Water Surface Ripples", &cv_ripplewater, 50}, - {IT_STRING|IT_CVAR, NULL, "Water Surface Ripples", &cv_ripplewater, 55}, + {IT_STRING|IT_CVAR, NULL, "Fade Players near Camera", &cv_playerfade, 55}, - {IT_STRING|IT_CVAR, NULL, "Fade Players near Camera", &cv_playerfade, 60}, + {IT_STRING|IT_CVAR, NULL, "Quake Screenshakes", &cv_screenquake, 60}, - {IT_STRING|IT_CVAR, NULL, "Quake Screenshakes", &cv_screenquake, 65}, + {IT_CALL|IT_STRING, NULL, "Camera Options...", M_CameraMenu, 65}, - {IT_CALL|IT_STRING, NULL, "Camera Options...", M_CameraMenu, 70}, + {IT_HEADER, NULL, "Audio", NULL, 75}, - {IT_HEADER, NULL, "Audio", NULL, 80}, + {IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 85}, + {IT_STRING|IT_CVAR, NULL, "Same Sound Limit", &cv_samesoundlimit, 90}, - {IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 90}, - {IT_STRING|IT_CVAR, NULL, "Same Sound Limit", &cv_samesoundlimit, 95}, + {IT_HEADER, NULL, "Controls", NULL, 100}, - {IT_HEADER, NULL, "Controls", NULL, 105}, - - {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P1)", &cv_autoaccel[0], 115}, - {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P2)", &cv_autoaccel[1], 120}, - {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P3)", &cv_autoaccel[2], 125}, - {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P4)", &cv_autoaccel[3], 130}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P1)", &cv_autoaccel[0], 110}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P2)", &cv_autoaccel[1], 115}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P3)", &cv_autoaccel[2], 120}, + {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P4)", &cv_autoaccel[3], 125}, }; static const char* OP_AccessibilityTooltips[] = @@ -1679,9 +1675,6 @@ static const char* OP_AccessibilityTooltips[] = "Reduces or disables certain effects players might be sensitive to\nSuch as flashing, flickering, certain screen effects and more.", "Disables the flicker effect on Midnight Channel.", "Sets minimum sector brightness, useful for dark areas", -#ifdef HWRENDER - "Disabling Screen Textures will disable the Underwater and Heat screen effects.", -#endif "Toggles the ripple effect on water surfaces", "Fades other Players that are close to the camera in and out", "Toggles the screen shake effect during Earthquakes", From 6f75fab7ffbda9050e3102d5fc2d77583e59c3d4 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 9 Feb 2026 19:39:29 +0100 Subject: [PATCH 38/50] move gamepad led ticker after render logic this does not really matter but save a tiny little amount of time before rendering a frame --- src/d_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 90ff81cc9..b0a269ae9 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -783,11 +783,6 @@ void D_SRB2Loop(void) doDisplay = true; } - - if (!dedicated) - { - G_DeviceLEDTick(); - } } if (interp) @@ -829,6 +824,13 @@ void D_SRB2Loop(void) if (takescreenshot) M_DoScreenShot(); +#ifndef DEDICATED + if (!dedicated && renderisnewtic) + { + G_DeviceLEDTick(); + } +#endif + // consoleplayer -> displayplayers (hear sounds from viewpoint) S_UpdateSounds(); // move positional sounds From 513e5a7e3f46460a31811bc4ae3b021fbb1692eb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 10 Feb 2026 16:38:11 +0100 Subject: [PATCH 39/50] remove even more dead code lol --- src/d_main.c | 43 +++++++++++++++---------------------------- src/p_user.c | 3 +-- src/r_things.cpp | 3 --- src/st_stuff.c | 2 -- src/st_stuff.h | 2 -- 5 files changed, 16 insertions(+), 37 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index b0a269ae9..9d5b23f59 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -274,21 +274,17 @@ static void D_Renderview(void) R_ApplyLevelInterpolators(R_GetTimeFrac(RTF_LEVEL)); - if (rendermode == render_soft) + if (rendermode == render_soft && cv_homremoval.value) { - // if this is display player 1 - if (cv_homremoval.value) + if (cv_homremoval.value == 1) { - if (cv_homremoval.value == 1) - { - // Clear the software screen buffer to remove HOM - memset(vid.screens[0], 31, vid.width * vid.height); - } - else if (cv_homremoval.value == 2) - { - //'development' HOM removal -- makes it blindingly obvious if HOM is spotted. - memset(vid.screens[0], 32+(timeinmap&15), vid.width * vid.height); - } + // Clear the software screen buffer to remove HOM + memset(vid.screens[0], 31, vid.width * vid.height); + } + else if (cv_homremoval.value == 2) + { + //'development' HOM removal -- makes it blindingly obvious if HOM is spotted. + memset(vid.screens[0], 32+(timeinmap&15), vid.width * vid.height); } } @@ -322,7 +318,6 @@ static void D_Renderview(void) break; default: // Initialize for P1 viewwindowy = viewwindowx = 0; - objectsdrawn = 0; break; } @@ -333,19 +328,17 @@ static void D_Renderview(void) } else if (rendermode == render_soft) #endif + { R_RenderPlayerView(&players[displayplayers[i]]); - } - - if (rendermode == render_soft) - { - if (i == 0) - R_ApplyViewMorph(); + if (i == 0) + R_ApplyViewMorph(); #ifdef MOTIONBLUR - V_DoPostProcessor(i, postimgparam[i]); + V_DoPostProcessor(i, postimgparam[i]); #else - V_DoPostProcessor(i, 0); + V_DoPostProcessor(i, 0); #endif + } } } @@ -1645,12 +1638,6 @@ void D_SRB2Main(void) strcpy(srb2, "SRB2Kart"); D_MakeTitleString(srb2); -#if defined (__OS2__) && !defined (HAVE_SDL) - // set PM window title - snprintf(pmData->title, sizeof (pmData->title), "SRB2Kart" VERSIONSTRING ": %s", title); - pmData->title[sizeof (pmData->title) - 1] = '\0'; -#endif - if (devparm) CONS_Printf(M_GetText("Development mode ON.\n")); diff --git a/src/p_user.c b/src/p_user.c index a930ec6a1..15a71ebc8 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1822,7 +1822,6 @@ void P_DoJumpShield(player_t *player) player->pflags &= ~PF_JUMPED; //P_DoJump(player, false); - player->pflags &= ~PF_JUMPED; player->secondjump = 0; player->jumping = 0; player->pflags |= PF_THOKKED; @@ -4454,7 +4453,7 @@ static INT32 Quaketilt(player_t *player) lowb = FixedMul(lowb, player->mo->scale); moma = FixedMul(FixedDiv(delta, ANGLE_90), tilt); - speed = abs( player->mo->momx + player->mo->momy ); + speed = abs(player->mo->momx + player->mo->momy); if (speed < lowb) { diff --git a/src/r_things.cpp b/src/r_things.cpp index 58a838eea..60b0bbd52 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1855,9 +1855,6 @@ static void R_ProjectSprite(mobj_t *thing) if (thing->subsector->sector->numlights) R_SplitSprite(vis); - - // Debug - ++objectsdrawn; } static void R_ProjectPrecipitationSprite(precipmobj_t *thing) diff --git a/src/st_stuff.c b/src/st_stuff.c index 5ca3f9d91..6dc7111f3 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -52,8 +52,6 @@ #include "r_fps.h" -UINT16 objectsdrawn = 0; - // dumb fade thing for director toggle tic_t directortoggletimer = 0; diff --git a/src/st_stuff.h b/src/st_stuff.h index 8e7f8fa41..24202646a 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -134,8 +134,6 @@ typedef enum extern hudinfo_t hudinfo[NUMHUDITEMS]; -extern UINT16 objectsdrawn; - // variable to stop mayonaka static from flickering extern consvar_t cv_lessflicker; extern consvar_t cv_stagetitle; From d49001143f487e3b1d6e0894d82f7b346e2561c8 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 11 Feb 2026 17:44:31 +0100 Subject: [PATCH 40/50] fix new compiler warnings from new gcc version just throw const at everything :blobthumbsup: --- src/d_main.c | 2 +- src/doomtype.h | 2 +- src/g_game.c | 6 +++--- src/hardware/hw_shaders.c | 2 +- src/hardware/r_opengl/r_opengl.c | 6 +++--- src/m_misc.c | 2 +- src/strcasestr.c | 37 ++++++++++++++++---------------- 7 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 9d5b23f59..a04334a5f 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -2018,7 +2018,7 @@ void D_SRB2Main(void) if (M_CheckProtoParam("replay")) { const char *replayurl = M_GetProtoParam(); - char *replayname = strrchr(replayurl, '/'); + const char *replayname = strrchr(replayurl, '/'); if (!replayname || !replayurl) I_Error("REPLAY: Invalid URL."); diff --git a/src/doomtype.h b/src/doomtype.h index ed6248129..0f76500fd 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -68,7 +68,7 @@ extern "C" { #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif -char *nongnu_strcasestr(const char *in, const char *what); +const char *nongnu_strcasestr(const char *in, const char *what); #ifndef _GNU_SOURCE #define strcasestr nongnu_strcasestr #endif diff --git a/src/g_game.c b/src/g_game.c index a79a957ef..a498bde0a 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4152,7 +4152,7 @@ static void measurekeywords(mapsearchfreq_t *fr, const char *s, const char *q, boolean wanttable) { char *qp; - char *sp; + const char *sp; if (wanttable) (*dimp) = Z_Realloc((*dimp), 255 * sizeof (struct searchdim), PU_STATIC, NULL); @@ -4197,9 +4197,9 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, size_t mapnamelen; char *realmapname = NULL; - char *newmapname = NULL; + char *newmapname = NULL; char *apromapname = NULL; - char *aprop = NULL; + const char *aprop = NULL; mapsearchfreq_t *freq; boolean wanttable; diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 28f8e46d7..80f070099 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -109,7 +109,7 @@ boolean HWR_InitShaders(void) // returns INT32_MAX if not found static INT32 strstr_int(const char *str1, const char *str2) { - char *location = strstr(str1, str2); + const char *location = strstr(str1, str2); if (location) return location - str1; else diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index eeb40a8dc..9f5098002 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1383,19 +1383,19 @@ void GL_Flush(void) // -----------------+ INT32 GL_isExtAvailable(const char *extension, const GLubyte *start) { - GLubyte *where, *terminator; + const GLubyte *where, *terminator; if (!extension || !start) return 0; - where = (GLubyte *) strchr(extension, ' '); + where = (const GLubyte *)strchr(extension, ' '); if (where || *extension == '\0') return 0; for (;;) { - where = (GLubyte *) strstr((const char *) start, extension); + where = (const GLubyte *)strstr((const char *) start, extension); if (!where) break; diff --git a/src/m_misc.c b/src/m_misc.c index 3a456d7a7..c11514524 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1454,7 +1454,7 @@ INT32 axtoi(const char *hexStg) void CopyCaretColors(char *p, const char *s, int n) { - char *t; + const char *t; int m; int c; diff --git a/src/strcasestr.c b/src/strcasestr.c index f05449778..5859e57bd 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -28,10 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include static inline int -trycmp (char **pp, char *cp, +trycmp (const char **pp, const char *cp, const char *q, size_t qn) { - char *p; + const char *p; p = (*pp); if (strncasecmp(p, q, qn) == 0) return 0; @@ -40,10 +40,10 @@ trycmp (char **pp, char *cp, } static inline void -swapp (char ***ppap, char ***ppbp, char **cpap, char **cpbp) +swapp (const char ***ppap, const char ***ppbp, const char **cpap, const char **cpbp) { - char **pp; - char *p; + const char **pp; + const char *p; pp = *ppap; *ppap = *ppbp; @@ -54,28 +54,27 @@ swapp (char ***ppap, char ***ppbp, char **cpap, char **cpbp) *cpbp = p; } -char * -nongnu_strcasestr (const char *s, const char *q) +const char *nongnu_strcasestr(const char *in, const char *what) { size_t qn; char uc; char lc; - char *up; - char *lp; + const char *up; + const char *lp; - char **ppa; - char **ppb; + const char **ppa; + const char **ppb; - char *cpa; - char *cpb; + const char *cpa; + const char *cpb; - uc = toupper(*q); - lc = tolower(*q); + uc = toupper(*what); + lc = tolower(*what); - up = strchr(s, uc); - lp = strchr(s, lc); + up = strchr(in, uc); + lp = strchr(in, lc); if (up == NULL && lp == NULL) return NULL; @@ -97,11 +96,11 @@ nongnu_strcasestr (const char *s, const char *q) cpb = &uc; } - qn = strlen(q); + qn = strlen(what); for (;;) { - if (trycmp(ppa, cpa, q, qn) == 0) + if (trycmp(ppa, cpa, what, qn) == 0) return (*ppa); if (up == NULL && lp == NULL) From 5c28f6afd8e237660c9f4cd927701119238277d6 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 16 Feb 2026 19:04:51 +0100 Subject: [PATCH 41/50] Revert "fix new compiler warnings from new gcc version" This reverts commit d49001143f487e3b1d6e0894d82f7b346e2561c8. --- src/d_main.c | 2 +- src/doomtype.h | 2 +- src/g_game.c | 6 +++--- src/hardware/hw_shaders.c | 2 +- src/hardware/r_opengl/r_opengl.c | 6 +++--- src/m_misc.c | 2 +- src/strcasestr.c | 37 ++++++++++++++++---------------- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index a04334a5f..9d5b23f59 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -2018,7 +2018,7 @@ void D_SRB2Main(void) if (M_CheckProtoParam("replay")) { const char *replayurl = M_GetProtoParam(); - const char *replayname = strrchr(replayurl, '/'); + char *replayname = strrchr(replayurl, '/'); if (!replayname || !replayurl) I_Error("REPLAY: Invalid URL."); diff --git a/src/doomtype.h b/src/doomtype.h index 0f76500fd..ed6248129 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -68,7 +68,7 @@ extern "C" { #define strnicmp(x,y,n) strncasecmp(x,y,n) #endif -const char *nongnu_strcasestr(const char *in, const char *what); +char *nongnu_strcasestr(const char *in, const char *what); #ifndef _GNU_SOURCE #define strcasestr nongnu_strcasestr #endif diff --git a/src/g_game.c b/src/g_game.c index a498bde0a..a79a957ef 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4152,7 +4152,7 @@ static void measurekeywords(mapsearchfreq_t *fr, const char *s, const char *q, boolean wanttable) { char *qp; - const char *sp; + char *sp; if (wanttable) (*dimp) = Z_Realloc((*dimp), 255 * sizeof (struct searchdim), PU_STATIC, NULL); @@ -4197,9 +4197,9 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, size_t mapnamelen; char *realmapname = NULL; - char *newmapname = NULL; + char *newmapname = NULL; char *apromapname = NULL; - const char *aprop = NULL; + char *aprop = NULL; mapsearchfreq_t *freq; boolean wanttable; diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 80f070099..28f8e46d7 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -109,7 +109,7 @@ boolean HWR_InitShaders(void) // returns INT32_MAX if not found static INT32 strstr_int(const char *str1, const char *str2) { - const char *location = strstr(str1, str2); + char *location = strstr(str1, str2); if (location) return location - str1; else diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 9f5098002..eeb40a8dc 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1383,19 +1383,19 @@ void GL_Flush(void) // -----------------+ INT32 GL_isExtAvailable(const char *extension, const GLubyte *start) { - const GLubyte *where, *terminator; + GLubyte *where, *terminator; if (!extension || !start) return 0; - where = (const GLubyte *)strchr(extension, ' '); + where = (GLubyte *) strchr(extension, ' '); if (where || *extension == '\0') return 0; for (;;) { - where = (const GLubyte *)strstr((const char *) start, extension); + where = (GLubyte *) strstr((const char *) start, extension); if (!where) break; diff --git a/src/m_misc.c b/src/m_misc.c index c11514524..3a456d7a7 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1454,7 +1454,7 @@ INT32 axtoi(const char *hexStg) void CopyCaretColors(char *p, const char *s, int n) { - const char *t; + char *t; int m; int c; diff --git a/src/strcasestr.c b/src/strcasestr.c index 5859e57bd..f05449778 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -28,10 +28,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include static inline int -trycmp (const char **pp, const char *cp, +trycmp (char **pp, char *cp, const char *q, size_t qn) { - const char *p; + char *p; p = (*pp); if (strncasecmp(p, q, qn) == 0) return 0; @@ -40,10 +40,10 @@ trycmp (const char **pp, const char *cp, } static inline void -swapp (const char ***ppap, const char ***ppbp, const char **cpap, const char **cpbp) +swapp (char ***ppap, char ***ppbp, char **cpap, char **cpbp) { - const char **pp; - const char *p; + char **pp; + char *p; pp = *ppap; *ppap = *ppbp; @@ -54,27 +54,28 @@ swapp (const char ***ppap, const char ***ppbp, const char **cpap, const char **c *cpbp = p; } -const char *nongnu_strcasestr(const char *in, const char *what) +char * +nongnu_strcasestr (const char *s, const char *q) { size_t qn; char uc; char lc; - const char *up; - const char *lp; + char *up; + char *lp; - const char **ppa; - const char **ppb; + char **ppa; + char **ppb; - const char *cpa; - const char *cpb; + char *cpa; + char *cpb; - uc = toupper(*what); - lc = tolower(*what); + uc = toupper(*q); + lc = tolower(*q); - up = strchr(in, uc); - lp = strchr(in, lc); + up = strchr(s, uc); + lp = strchr(s, lc); if (up == NULL && lp == NULL) return NULL; @@ -96,11 +97,11 @@ const char *nongnu_strcasestr(const char *in, const char *what) cpb = &uc; } - qn = strlen(what); + qn = strlen(q); for (;;) { - if (trycmp(ppa, cpa, what, qn) == 0) + if (trycmp(ppa, cpa, q, qn) == 0) return (*ppa); if (up == NULL && lp == NULL) From 53321d33d57eaae56e6af1c7fa031fb836b6cddb Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 12 Feb 2026 18:41:53 +0100 Subject: [PATCH 42/50] mark some nightsmode stuff with likely/unlikely i missed and in some cases move around the conditionals i love backwards compat Zzz.... --- src/d_clisrv.c | 4 +++- src/p_inter.c | 4 ++-- src/p_local.h | 6 ------ src/p_mobj.c | 18 +++++++++--------- src/p_spec.c | 6 +++--- src/p_user.c | 2 +- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 68ab08c5a..2f3440362 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3350,7 +3350,7 @@ void CL_ClearPlayer(INT32 playernum) if (players[playernum].mo) { // Don't leave a NiGHTS ghost! - if ((players[playernum].pflags & PF_NIGHTSMODE) && players[playernum].mo->tracer) + if (UNLIKELY((players[playernum].pflags & PF_NIGHTSMODE) && players[playernum].mo->tracer)) P_RemoveMobj(players[playernum].mo->tracer); P_RemoveMobj(players[playernum].mo); } @@ -3496,6 +3496,7 @@ static void Command_GetPlayerNum(void) INT32 i; for (i = 0; i < MAXPLAYERS; i++) + { if (playeringame[i]) { if (serverplayer == i) @@ -3503,6 +3504,7 @@ static void Command_GetPlayerNum(void) else CONS_Printf(M_GetText("\x82num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]); } + } } SINT8 nametonum(const char *name) diff --git a/src/p_inter.c b/src/p_inter.c index 127f31c10..e11329b79 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -831,7 +831,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) { S_StartSound(toucher, special->info->seesound); - if (player->pflags & PF_NIGHTSMODE) + if (UNLIKELY(player->pflags & PF_NIGHTSMODE)) { player->bumpertime = TICRATE/2; if (special->threshold > 0) @@ -1131,7 +1131,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) S_StartSound(toucher, special->info->painsound); return; } - else if (((player->pflags & PF_NIGHTSMODE) && (player->pflags & PF_DRILLING)) || (player->pflags & (PF_JUMPED|PF_SPINNING|PF_GLIDING)) + else if (UNLIKELY((player->pflags & PF_NIGHTSMODE) && (player->pflags & PF_DRILLING)) || (player->pflags & (PF_JUMPED|PF_SPINNING|PF_GLIDING)) || player->powers[pw_invulnerability] || player->powers[pw_super]) // Do you possess the ability to subdue the object? { // Shatter the shield! diff --git a/src/p_local.h b/src/p_local.h index 82e3fb673..518bc12cb 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -30,8 +30,6 @@ extern "C" { #define FLOATSPEED (FRACUNIT*4) -//#define VIEWHEIGHTS "41" - // Maximum player score. #define MAXSCORE 999999990 @@ -239,14 +237,10 @@ void P_InstaThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move); boolean P_LookForEnemies(player_t *player); void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius); void P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user -//boolean P_SuperReady(player_t *player); boolean P_AnalogMove(player_t *player); -/*boolean P_TransferToNextMare(player_t *player); -UINT8 P_FindLowestMare(void);*/ UINT8 P_FindLowestLap(void); UINT8 P_FindHighestLap(void); void P_FindEmerald(void); -//void P_TransferToAxis(player_t *player, INT32 axisnum); boolean P_PlayerMoving(INT32 pnum); void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range); diff --git a/src/p_mobj.c b/src/p_mobj.c index acc09ab58..d44a48f1c 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -919,12 +919,7 @@ static void P_PlayerFlip(mobj_t *mo) G_GhostAddFlip((INT32) (mo->player - players)); // Flip aiming to match! - if (UNLIKELY(mo->player->pflags & PF_NIGHTSMODE)) // NiGHTS doesn't use flipcam - { - if (mo->tracer) - mo->tracer->eflags ^= MFE_VERTICALFLIP; - } - else if (mo->player->pflags & PF_FLIPCAM) + if (mo->player->pflags & PF_FLIPCAM) { UINT8 i; @@ -946,6 +941,11 @@ static void P_PlayerFlip(mobj_t *mo) camera[i].z += FixedMul(20*FRACUNIT, mo->scale); } } + else if (UNLIKELY(mo->player->pflags & PF_NIGHTSMODE)) // NiGHTS doesn't use flipcam + { + if (mo->tracer) + mo->tracer->eflags ^= MFE_VERTICALFLIP; + } } // @@ -3252,7 +3252,7 @@ void P_CalcChasePostImg(player_t *player, camera_t *thiscam) player_flipcam = cv_flipcam[pnum].value; } - const boolean flipcam = (player_flipcam && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP); + const boolean flipcam = (player_flipcam && player->mo->eflags & MFE_VERTICALFLIP && LIKELY(!(player->pflags & PF_NIGHTSMODE))); UINT8 postimgtype = 0; if (encoremode) @@ -8553,7 +8553,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (mobj->tracer && mobj->tracer->player) { - if (!(mobj->tracer->player->pflags & PF_NIGHTSMODE)) + if (LIKELY(!(mobj->tracer->player->pflags & PF_NIGHTSMODE))) { mobj->flags &= ~MF_NOGRAVITY; mobj->flags2 &= ~MF2_DONTDRAW; @@ -8577,7 +8577,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) P_SetTarget(&mobj->target, NULL); } - if (mobj->tracer->player->pflags & PF_NIGHTSMODE) + if (UNLIKELY(mobj->tracer->player->pflags & PF_NIGHTSMODE)) { if (mobj->tracer->player->bonustime) { diff --git a/src/p_spec.c b/src/p_spec.c index e537e17e6..919be8031 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4399,7 +4399,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector) // The list of specials that activate without floor touch // Check Section 1 - switch(GETSECSPECIAL(sector->special, 1)) + switch (GETSECSPECIAL(sector->special, 1)) { //case 2: // Damage (water) case 8: // Instant kill @@ -4410,7 +4410,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector) } // Check Section 2 - switch(GETSECSPECIAL(sector->special, 2)) + switch (GETSECSPECIAL(sector->special, 2)) { case 2: // Linedef executor (All players needed) case 4: // Linedef executor @@ -4421,7 +4421,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector) } // Check Section 4 - switch(GETSECSPECIAL(sector->special, 4)) + switch (GETSECSPECIAL(sector->special, 4)) { case 2: // Level Exit / GOAL Sector / Flag Return case 1: // Starpost activator diff --git a/src/p_user.c b/src/p_user.c index 15a71ebc8..99566aa24 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -4109,7 +4109,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall angle -= (angle - thiscam->pitch)/2; } - if (player->playerstate != PST_DEAD && !((player->pflags & PF_NIGHTSMODE) && player->exiting)) + if (player->playerstate != PST_DEAD && LIKELY(!((player->pflags & PF_NIGHTSMODE) && player->exiting))) angle += (focusaiming < ANGLE_180 ? focusaiming/2 : InvAngle(InvAngle(focusaiming)/2)); // overcomplicated version of '((signed)focusaiming)/2;' if (!camstill && !timeover) // Keep the view still... From d77508f4819b1380f829b413c5580977e5ba9b88 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 15 Feb 2026 18:07:20 +0100 Subject: [PATCH 43/50] init superactions global was missed before --- src/command.c | 2 +- src/dehacked.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/command.c b/src/command.c index 0b1578381..c37b8f1d3 100644 --- a/src/command.c +++ b/src/command.c @@ -1178,7 +1178,7 @@ consvar_t *CV_FindVar(const char *name) consvar_t *cvar; for (cvar = consvar_vars; cvar; cvar = cvar->next) - if (fasticmp(name,cvar->name)) + if (fasticmp(name, cvar->name)) return cvar; return NULL; diff --git a/src/dehacked.c b/src/dehacked.c index a3540fdff..a3513fbbe 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -173,7 +173,7 @@ FUNCPRINTF static void deh_warning(const char *first, ...) vsnprintf(buf, 1000, first, argptr); // sizeof only returned 4 here. it didn't like that pointer. va_end(argptr); - if(dbg_line == -1) // Not in a SOC, line number unknown. + if (dbg_line == -1) // Not in a SOC, line number unknown. CONS_Alert(CONS_WARNING, "%s\n", buf); else CONS_Alert(CONS_WARNING, "Line %u: %s\n", dbg_line, buf); @@ -8545,7 +8545,7 @@ static inline int lib_action(lua_State *L) // Hardcoded A_Action name to call for super() or NULL if super() would be invalid. // Set in lua_infolib. -const char *superactions[MAXRECURSION]; +const char *superactions[MAXRECURSION] = {}; UINT8 superstack = 0; static int lib_dummysuper(lua_State *L) From 22a4fe63db1bf696769b4d2efbdb1233cedbc978 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Feb 2026 13:28:00 +0100 Subject: [PATCH 44/50] Fix minimap angle display colour for skins that use non default startcolor i.e. they use a different colour than "green" to remap their skincolor on --- src/k_hud.c | 27 ++++++++++++++++++++++----- src/k_kart.c | 11 ++++++++++- src/r_draw.cpp | 3 +-- src/r_skins.h | 1 + 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/k_hud.c b/src/k_hud.c index 4f10bf749..3df6f7af7 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -3816,7 +3816,7 @@ static void K_drawKartMinimap(void) if (cv_showminimapangle.value && (minidoticon || minilighticon) && !playertimedout) { - UINT8 *colormap; + UINT8 *colormap = NULL; drawinfo_t dims; fixed_t interpx, interpy; fixed_t xoff = 0, yoff = 0; @@ -3827,10 +3827,27 @@ static void K_drawKartMinimap(void) if (encoremode) ang = ANGLE_180 - ang; - if (mobj->colorized) - colormap = R_GetTranslationColormap(TC_RAINBOW, mobj->color, GTC_CACHE); - else - colormap = R_GetLocalTranslationColormap(mobj->skin, mobj->localskin, mobj->color, GTC_CACHE, mobj->skinlocal); + if (mobj->color) + { + if (mobj->colorized) + { + colormap = R_GetTranslationColormap(TC_RAINBOW, mobj->color, GTC_CACHE); + } + else + { + const INT32 skinnum = K_GetMobjLocalSkinNum(mobj->skin, mobj->localskin, mobj->skinlocal); + + // special case if startcolor is not the default (160 / Green) + if (skinnum && skins[skinnum].starttranscolor != skins[0].starttranscolor) + { + colormap = R_GetTranslationColormap(TC_DEFAULT, mobj->color, GTC_CACHE); + } + else + { + colormap = R_GetLocalTranslationColormap(mobj->skin, mobj->localskin, mobj->color, GTC_CACHE, mobj->skinlocal); + } + } + } interpx = lerp(mobj->old_x, mobj->x); interpy = lerp(mobj->old_y, mobj->y); diff --git a/src/k_kart.c b/src/k_kart.c index 747a032b2..0efd3a48b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -660,13 +660,22 @@ INT32 K_GetSkinNum(player_t *player) // // returns the mobj skinnumber -// accounts for localskins +// accounts for localskins ? // INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local) { return skin - K_GetSkinArray(local); } +// +// returns the mobj skinnumber +// accounts for localskins +// +INT32 K_GetMobjLocalSkinNum(const skin_t *skin, const skin_t *localskin, boolean local) +{ + return localskin ? (localskin - K_GetSkinArray(local)) : (skin - skins); +} + // // returns the players skinnumber // accounts for localskins diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 639107daa..97872aee1 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -437,8 +437,7 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags) UINT8* R_GetLocalTranslationColormap(skin_t *skin, skin_t *localskin, skincolors_t color, UINT8 flags, boolean local) { - const INT32 skinnum = localskin ? (localskin - K_GetSkinArray(local)) : (skin - skins); - return RGetTranslationColormap(skinnum, color, flags, (localskin && local)); + return RGetTranslationColormap(K_GetMobjLocalSkinNum(skin, localskin, local), color, flags, (localskin && local)); } patch_t* R_GetSkinFaceRank(player_t* ply) diff --git a/src/r_skins.h b/src/r_skins.h index 6231e8a18..929753855 100644 --- a/src/r_skins.h +++ b/src/r_skins.h @@ -92,6 +92,7 @@ INT32 R_LocalSkinAvailable(const char *name, boolean local); // had to move those here Zzz... INT32 K_GetSkinNum(player_t *player); INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local); +INT32 K_GetMobjLocalSkinNum(const skin_t *skin, const skin_t *localskin, boolean local); skin_t *K_GetPlayerSkin(player_t *player); skin_t *K_GetMobjSkin(const mobj_t *mobj); patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum); From 90a88983f1265333aa7b8a62ad331966670c3b51 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Feb 2026 13:28:48 +0100 Subject: [PATCH 45/50] k_hud: make the hud offset vars static --- src/k_hud.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/k_hud.c b/src/k_hud.c index 3df6f7af7..3fc83c10b 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -931,21 +931,21 @@ const char *K_GetItemPatch(UINT8 item, boolean tiny) //} -INT32 ITEM_X, ITEM_Y; // Item Window -INT32 TIME_X, TIME_Y; // Time Sticker -INT32 LAPS_X, LAPS_Y; // Lap Sticker -INT32 SPDM_X, SPDM_Y; // Speedometer -INT32 POSI_X, POSI_Y; // Position Number -INT32 FACE_X, FACE_Y; // Top-four Faces -INT32 STCD_X, STCD_Y; // Starting countdown -INT32 CHEK_Y; // CHECK graphic -INT32 MINI_X, MINI_Y; // Minimap -INT32 WANT_X, WANT_Y; // Battle WANTED poster +static INT32 ITEM_X, ITEM_Y; // Item Window +static INT32 TIME_X, TIME_Y; // Time Sticker +static INT32 LAPS_X, LAPS_Y; // Lap Sticker +static INT32 SPDM_X, SPDM_Y; // Speedometer +static INT32 POSI_X, POSI_Y; // Position Number +static INT32 FACE_X, FACE_Y; // Top-four Faces +static INT32 STCD_X, STCD_Y; // Starting countdown +static INT32 CHEK_Y; // CHECK graphic +static INT32 MINI_X, MINI_Y; // Minimap +static INT32 WANT_X, WANT_Y; // Battle WANTED poster // This is for the P2 and P4 side of splitscreen. Then we'll flip P1's and P2's to the bottom with V_SPLITSCREEN. -INT32 ITEM2_X, ITEM2_Y; -INT32 LAPS2_X, LAPS2_Y; -INT32 POSI2_X, POSI2_Y; +static INT32 ITEM2_X, ITEM2_Y; +static INT32 LAPS2_X, LAPS2_Y; +static INT32 POSI2_X, POSI2_Y; static void K_initKartHUD(void) { From 7746e494cf87c8aca6444cffced42f5d9ef1de4f Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Feb 2026 13:32:04 +0100 Subject: [PATCH 46/50] fix memory leak within http masterserver handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit errbuf gets malloc´d! --- src/http-mserv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/http-mserv.c b/src/http-mserv.c index 9e4374353..7b5fac188 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -318,6 +318,7 @@ static void HMS_end (struct HMS_buffer *buffer) { curl_easy_cleanup(buffer->curl); + free(buffer->errbuf); free(buffer->buffer); free(buffer); } From 009df228d62a661024ed08c61aa580e4a5992aca Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Feb 2026 13:33:10 +0100 Subject: [PATCH 47/50] fix memory leak when fetching masterserver rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit strdup returns a malloc´d string! --- src/mserv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mserv.c b/src/mserv.c index 01af521e6..c91dacfcf 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -262,6 +262,7 @@ Finish_registration (void) { CONS_Printf("\n"); CONS_Alert(CONS_NOTICE, "%s\n", rules); + free(rules); } if (registered) From 1d6c27bacacf667130116049121e8da840d2e3d4 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Feb 2026 14:01:27 +0100 Subject: [PATCH 48/50] lua_pushlstring: prefer luaS_newlstr over luaS_new the latter calls strlen which is not needed as the empty string has no length --- src/blua/lapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blua/lapi.c b/src/blua/lapi.c index 557896f43..6a33983fe 100644 --- a/src/blua/lapi.c +++ b/src/blua/lapi.c @@ -434,7 +434,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { lua_lock(L); luaC_checkGC(L); - setsvalue2s(L, L->top, (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len)); + setsvalue2s(L, L->top, (len == 0) ? luaS_newlstr(L, "", 0) : luaS_newlstr(L, s, len)); api_incr_top(L); lua_unlock(L); } From f4dc161831a988e725e8639b9674984ebdf5f6bb Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 15:56:42 +0100 Subject: [PATCH 49/50] dont let SIGINT/SIGTERM do work in signal handler take 2 the earlier approach still raised the default signal within this, which basically just skipped everything and ended up NOT calling I_Quit at all Basically this is to ensure we dont call I_Quit at all from a signal handler as it is NOT async safe and can cause serious issues like deadlocks and such, instead SIGINT and SIGTERM will just signal the main loop/thread to safely call I_Quit instead --- src/d_main.c | 5 +++++ src/dedicated/i_system.c | 14 ++++++++++---- src/i_system.h | 4 ++++ src/sdl/i_system.cpp | 24 ++++++++++-------------- src/sdl/i_video.c | 3 ++- src/sdl/mixer_sound.c | 3 ++- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 9d5b23f59..8bae5ea91 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -697,6 +697,11 @@ 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 437439010..311e936f3 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1067,11 +1067,17 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) +static volatile sig_atomic_t interrupted = 0; + +boolean I_Interrupted(void) { - signal(num, SIG_DFL); //default signal action - raise(num); - I_Quit(); + return interrupted; +} + +static void quit_handler(int num) +{ + (void)num; + interrupted = 1; } #ifdef HAVE_LIBBACKTRACE diff --git a/src/i_system.h b/src/i_system.h index 97dfae9a1..958703a35 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -195,6 +195,10 @@ INT32 I_StartupSystem(void); */ void I_ShutdownSystem(void); +/** \brief To check if a Interrupt or Terminate Signal was fired + */ +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 b90fbf898..063b140e1 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1741,21 +1741,17 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) -{ -#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 volatile sig_atomic_t interrupted = 0; - signal(num, SIG_DFL); //default signal action - raise(num); - I_Quit(); +boolean I_Interrupted(void) +{ + return interrupted; +} + +static void quit_handler(int num) +{ + (void)num; + interrupted = 1; } static void I_RegisterSignals(void) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index e367b612f..813b6bfa0 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2027,7 +2027,8 @@ void I_ShutdownGraphics(void) SDL_DestroyWindow(window); window = NULL; - SDL_QuitSubSystem(SDL_INIT_VIDEO); + if (SDL_WasInit(SDL_INIT_VIDEO) == 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 8de4eb746..7dccd9673 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -237,7 +237,8 @@ void I_ShutdownSound(void) Mix_Quit(); #endif - SDL_QuitSubSystem(SDL_INIT_AUDIO); + if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) + SDL_QuitSubSystem(SDL_INIT_AUDIO); #ifdef HAVE_LIBGME if (gme) From e35dc9e0974da23276d6938e82f2e1057ed4fb92 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Feb 2026 16:20:48 +0100 Subject: [PATCH 50/50] fix g_in_exiting_signal_handler every "flag" set by signal handlers must be of type "volatile sig_atomic_t" everything else may fail to be correctly set, read or get optimized away which rendered this basically useless --- src/console.c | 10 +++++----- src/dedicated/i_system.c | 7 ++++++- src/i_system.h | 2 +- src/m_menu.c | 10 +++++----- src/sdl/i_system.cpp | 11 ++++++++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/console.c b/src/console.c index 88fe25000..09ac2e36d 100644 --- a/src/console.c +++ b/src/console.c @@ -46,16 +46,16 @@ #ifdef HAVE_THREADS I_mutex con_mutex; -// g_in_exiting_signal_handler is an evil hack +// I_In_Exiting_Signal_Handler is an evil hack // to avoid infinite SIGABRT recursion in the signal handler // due to poisoned locks or mach-o kernel not supporting locks in signals // or something like that. idk -# define Lock_state() if (!g_in_exiting_signal_handler) { I_lock_mutex(&con_mutex); } -# define Unlock_state() if (!g_in_exiting_signal_handler) { I_unlock_mutex(con_mutex); } -#else/*HAVE_THREADS*/ +# define Lock_state() if (!I_In_Exiting_Signal_Handler()) { I_LockMutex(&con_mutex); } +# define Unlock_state() if (!I_In_Exiting_Signal_Handler()) { I_UnlockMutex(con_mutex); } +#else /*HAVE_THREADS*/ # define Lock_state() # define Unlock_state() -#endif/*HAVE_THREADS*/ +#endif /*HAVE_THREADS*/ static boolean con_started = false; // console has been initialised boolean con_startup = false; // true at game startup, screen need refreshing diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 311e936f3..f6450134c 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -984,7 +984,7 @@ void I_SleepDuration(precise_t duration) #endif } -boolean g_in_exiting_signal_handler = false; +static volatile sig_atomic_t g_in_exiting_signal_handler = false; static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg) { @@ -1048,6 +1048,11 @@ static void I_ReportSignal(int num, int coredumped) I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); } +boolean I_In_Exiting_Signal_Handler(void) +{ + return g_in_exiting_signal_handler; +} + #ifndef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) { diff --git a/src/i_system.h b/src/i_system.h index 958703a35..45767f1f7 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -43,7 +43,7 @@ extern UINT8 graphics_started; extern UINT8 keyboard_started; /** \brief Set to true when inside a signal handler that will exit the program. */ -extern boolean g_in_exiting_signal_handler; +boolean I_In_Exiting_Signal_Handler(void); /** \brief The I_GetFreeMem function diff --git a/src/m_menu.c b/src/m_menu.c index 0e753f621..f2b3ac1bb 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4016,16 +4016,16 @@ boolean replaynamesloaded = false; #ifdef HAVE_THREADS I_mutex replayquerymutex; -// g_in_exiting_signal_handler is an evil hack +// I_In_Exiting_Signal_Handler is an evil hack // to avoid infinite SIGABRT recursion in the signal handler // due to poisoned locks or mach-o kernel not supporting locks in signals // or something like that. idk -# define Lock_search_state() if (!g_in_exiting_signal_handler) { I_lock_mutex(&replayquerymutex); } -# define Unlock_search_state() if (!g_in_exiting_signal_handler) { I_unlock_mutex(replayquerymutex); } -#else/*HAVE_THREADS*/ +# define Lock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_LockMutex(&replayquerymutex); } +# define Unlock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_UnlockMutex(replayquerymutex); } +#else /*HAVE_THREADS*/ # define Lock_search_state() # define Unlock_search_state() -#endif/*HAVE_THREADS*/ +#endif /*HAVE_THREADS*/ #define MAXREPLAYQUERY 37 diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 063b140e1..5310cc855 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1577,7 +1577,7 @@ static void write_backtrace(bt_crash_reason_t reason) static std::thread::id g_main_thread_id; #endif -boolean g_in_exiting_signal_handler = false; +static volatile sig_atomic_t g_in_exiting_signal_handler = false; static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg, char *signal_name) { @@ -1712,6 +1712,11 @@ static void I_ReportSignal(int num, int coredumped) I_ShowErrorBox(sigttl, sigmsg); } +boolean I_In_Exiting_Signal_Handler(void) +{ + return g_in_exiting_signal_handler; +} + #ifndef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) { @@ -1741,7 +1746,7 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -static volatile sig_atomic_t interrupted = 0; +static volatile sig_atomic_t interrupted = false; boolean I_Interrupted(void) { @@ -1751,7 +1756,7 @@ boolean I_Interrupted(void) static void quit_handler(int num) { (void)num; - interrupted = 1; + interrupted = true; } static void I_RegisterSignals(void)