diff --git a/CMakeLists.txt b/CMakeLists.txt index 1acd092bc..3184252da 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,10 +16,31 @@ 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.") +##### PACKAGE CONFIGURATION ##### + +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 ) +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/") @@ -102,14 +128,12 @@ 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 +142,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) diff --git a/cmake/Modules/FindGME.cmake b/cmake/Modules/FindGME.cmake index ea80af454..7e9087247 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 @@ -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 @@ -20,4 +21,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/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) 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() 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/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); } diff --git a/src/command.c b/src/command.c index 6b71dce73..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; @@ -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/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/d_clisrv.c b/src/d_clisrv.c index 27206b337..a75c455a6 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3326,7 +3326,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); } @@ -3472,6 +3472,7 @@ static void Command_GetPlayerNum(void) INT32 i; for (i = 0; i < MAXPLAYERS; i++) + { if (playeringame[i]) { if (serverplayer == i) @@ -3479,6 +3480,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/d_main.c b/src/d_main.c index c5499fb57..8bae5ea91 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 + } } } @@ -704,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; @@ -783,11 +781,6 @@ void D_SRB2Loop(void) doDisplay = true; } - - if (!dedicated) - { - G_DeviceLEDTick(); - } } if (interp) @@ -829,6 +822,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 @@ -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(); @@ -1641,12 +1643,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/d_netcmd.c b/src/d_netcmd.c index 6b92c86db..d16b54be9 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); @@ -2313,7 +2316,6 @@ static void Command_Map_f(void) return; } - last_map_cmd = I_GetTime(); size_t first_option; diff --git a/src/dedicated/CMakeLists.txt b/src/dedicated/CMakeLists.txt index 36f670251..38fb179f0 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,20 +116,35 @@ 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() +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) +# 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) install(TARGETS SRB2SDL2 diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 437439010..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) { @@ -1067,11 +1072,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/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) 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_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/g_game.c b/src/g_game.c index f664aa1b2..196b2ec68 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -453,10 +453,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}}; @@ -520,11 +520,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/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/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/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 24d3af8ae..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; @@ -5444,7 +5443,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/hardware/hw_md2.c b/src/hardware/hw_md2.c index 0a79ba6ec..2fd33f65b 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]; @@ -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 diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 2d1f8e255..eeb40a8dc 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3591,22 +3591,30 @@ 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(); - for (i = 0; i < 1; i += stride) + const float ystep = 2.f/scrwh * (float)vid.udup/4.f; + + for (i = 0; i < 1; i += ystep) { - 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; @@ -3624,8 +3632,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; @@ -3648,13 +3656,14 @@ 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); // 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; @@ -3673,6 +3682,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 +3722,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 +3745,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; diff --git a/src/http-mserv.c b/src/http-mserv.c index fd63c5f69..7b5fac188 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()) @@ -317,6 +318,7 @@ static void HMS_end (struct HMS_buffer *buffer) { curl_easy_cleanup(buffer->curl); + free(buffer->errbuf); free(buffer->buffer); free(buffer); } diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 6cca391e9..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; @@ -1072,8 +1075,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 @@ -1484,6 +1486,7 @@ static char *CHAT_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) x = 0; } } + return newstring; } @@ -1522,7 +1525,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,19 +1557,21 @@ 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; - if (msg) - Z_Free(msg); + Z_Free(msg); } y = chaty - charheight*(msglines+1); @@ -1598,7 +1603,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,16 +1648,17 @@ static void HU_drawMiniChat(void) dx += charwidth; prev_linereturn = false; + if (dx >= boxw) { dx = 0; dy += charheight; } } + dy += charheight; dx = 0; - if (msg) - Z_Free(msg); + Z_Free(msg); } // decrement addy and make that shit smooth: @@ -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= 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_system.h b/src/i_system.h index 97dfae9a1..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 @@ -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/i_tcp.c b/src/i_tcp.c index 77cb940fd..9723d5b2d 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -1512,11 +1512,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); @@ -1530,11 +1527,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_hud.c b/src/k_hud.c index d0146a38e..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) { @@ -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)); @@ -3818,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; @@ -3829,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 6496f3e8e..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 @@ -1480,7 +1489,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/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_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)) 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, } 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..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; @@ -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_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/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_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; diff --git a/src/m_menu.c b/src/m_menu.c index a98a230d5..f2b3ac1bb 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! @@ -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 @@ -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 @@ -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 @@ -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<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! @@ -2420,7 +2420,6 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da { player->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_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 d1b8b850a..d44a48f1c 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; } @@ -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) @@ -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]) { @@ -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++) @@ -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) { @@ -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_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..919be8031 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]; @@ -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 // @@ -4401,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 @@ -4412,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 @@ -4423,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 @@ -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 @@ -4532,9 +4528,11 @@ void P_UpdateSpecials(void) { for (i = 0; i < anim->numpics; i++) { - pic = anim->basepic + ((leveltime/anim->speed + i) % anim->numpics); if (anim->istexture) - texturetranslation[anim->basepic+i] = pic; + { + texturetranslation[anim->basepic+i] = anim->basepic + + ((leveltime/anim->speed + i) % anim->numpics); + } } } @@ -4629,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); @@ -4644,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); @@ -4653,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; @@ -5468,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; @@ -5989,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++) { @@ -6221,8 +6218,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/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 diff --git a/src/p_user.c b/src/p_user.c index 2a3ccc300..99566aa24 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; @@ -1894,7 +1893,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 +1950,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; @@ -4120,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... @@ -4464,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_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_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_main.cpp b/src/r_main.cpp index e470e5b5d..2b318858a 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)); @@ -1018,8 +1014,8 @@ static void R_InitViewMapping(void) for (INT32 i = 0; i < j; i++) { - fixed_t dy = (i - viewheight*8)<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_plane.cpp b/src/r_plane.cpp index b2d30185d..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. @@ -136,7 +139,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)); } // @@ -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); } @@ -920,12 +923,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_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; 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); diff --git a/src/r_things.cpp b/src/r_things.cpp index d1c856238..60b0bbd52 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; @@ -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); @@ -489,8 +489,8 @@ void R_InitSprites(void) for (angle = 1; angle < ROTANGLES; angle++) { fa = ANG2RAD(FixedAngle((ROTANGDIFF * angle)<subsector->sector->numlights) R_SplitSprite(vis); - - // Debug - ++objectsdrawn; } static void R_ProjectPrecipitationSprite(precipmobj_t *thing) 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; 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/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}) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 1d1a8b00f..5310cc855 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 @@ -723,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 @@ -780,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 { @@ -936,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; } @@ -982,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); @@ -996,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 { @@ -1554,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) { @@ -1689,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) { @@ -1718,21 +1746,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 = false; - 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 = true; } static void I_RegisterSignals(void) @@ -1818,18 +1842,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); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 1c23af6cd..813b6bfa0 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; @@ -1152,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); } @@ -2015,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 272e48a1b..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) @@ -1107,7 +1108,7 @@ UINT32 I_GetSongPosition(void) void I_UpdateSongLagThreshold(void) { - stutter_threshold = cv_music_resync_powerups_only.value ? 0 : (cv_music_resync_threshold.value/1000.0*(4*44100)); + stutter_threshold = (UINT32)(cv_music_resync_powerups_only.value ? 0 : (cv_music_resync_threshold.value/1000.0*(4*44100))); } /// ------------------------ 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 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; diff --git a/src/v_video.c b/src/v_video.c index b5be19a97..fde09cc0b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -465,7 +465,7 @@ void V_CubeApply(RGBA_t *input) if (!Cubeapply) return; - linear = ((*input).s.red/255.0); + linear = ((*input).s.red/255.0f); #define dolerp(e1, e2) ((1 - linear)*e1 + linear*e2) for (q = 0; q < 3; q++) { @@ -475,21 +475,21 @@ void V_CubeApply(RGBA_t *input) working[3][q] = dolerp(Cubepal[0][1][1][q], Cubepal[1][1][1][q]); } - linear = ((*input).s.green/255.0); + linear = ((*input).s.green/255.0f); for (q = 0; q < 3; q++) { working[0][q] = dolerp(working[0][q], working[1][q]); working[1][q] = dolerp(working[2][q], working[3][q]); } - linear = ((*input).s.blue/255.0); + linear = ((*input).s.blue/255.0f); for (q = 0; q < 3; q++) { working[0][q] = 255*dolerp(working[0][q], working[1][q]); if (working[0][q] > 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 @@ -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; @@ -3718,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++) @@ -3930,6 +3926,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 { diff --git a/src/w_wad.c b/src/w_wad.c index 432f1421f..3009d503f 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); @@ -453,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 @@ -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__)