From b9e399f269c066660ce307dba99379bd98cbaa2d Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 01/10] Add ninja-x64_windows presets (for clang on windows) --- CMakePresets.json | 86 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index 141e76486..ec794936d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -40,12 +40,43 @@ "SRB2_CONFIG_TESTERS": "ON" } }, + { + "name": "__debug-cl", + "hidden": true, + "cacheVariables": { + "CMAKE_C_FLAGS_DEBUG": "/MDd /Zi /Ob0 /Od /RTC0", + "CMAKE_CXX_FLAGS_DEBUG": "/MDd /Zi /Ob0 /Od /RTC0", + "SRB2_CONFIG_DEV_BUILD": "ON", + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "__develop-cl", + "hidden": true, + "cacheVariables": { + "CMAKE_C_FLAGS_RELWITHDEBINFO": "/MD /O2 /Ob2 /DNDEBUG", + "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "/MD /O2 /Ob2 /DNDEBUG", + "SRB2_CONFIG_DEV_BUILD": "ON", + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "__release-cl", + "hidden": true, + "cacheVariables": { + "CMAKE_C_FLAGS_RELWITHDEBINFO": "/MD /O2 /Ob2 /DNDEBUG", + "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "/MD /O2 /Ob2 /DNDEBUG", + "SRB2_CONFIG_DEV_BUILD": "OFF", + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, { "name": "__ninja", "hidden": true, "generator": "Ninja", "cacheVariables": { - "CMAKE_COLOR_DIAGNOSTICS": "ON" + "CMAKE_COLOR_DIAGNOSTICS": "ON", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" } }, { @@ -78,6 +109,16 @@ "VCPKG_TARGET_TRIPLET": "x86-mingw-static" } }, + { + "name": "__x64-windows", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl", + "VCPKG_HOST_TRIPLET": "x64-windows-static-md", + "VCPKG_TARGET_TRIPLET": "x64-windows-static-md" + } + }, { "name": "__osx_x64", "hidden": true, @@ -172,6 +213,25 @@ "inherits": [ "__testers", "__compiler-mingw-w64-i686", "__ninja", "__vcpkg-toolchain", "__mingw-static" ] }, + { + "name": "ninja-x64_windows_vcpkg-debug", + "hidden": false, + "binaryDir": "${sourceDir}/build/${presetName}", + "inherits": [ "__debug-cl", "__ninja", "__vcpkg-toolchain", "__x64-windows" ] + }, + { + "name": "ninja-x64_windows_vcpkg-develop", + "hidden": false, + "binaryDir": "${sourceDir}/build/${presetName}", + "inherits": [ "__develop-cl", "__ninja", "__vcpkg-toolchain", "__x64-windows" ] + }, + { + "name": "ninja-x64_windows_vcpkg-release", + "hidden": false, + "binaryDir": "${sourceDir}/build/${presetName}", + "inherits": [ "__release-cl", "__ninja", "__vcpkg-toolchain", "__x64-windows" ] + }, + { "name": "ninja-x64_osx_vcpkg-debug", "hidden": false, @@ -224,6 +284,18 @@ "name": "ninja-release", "configurePreset": "ninja-release" }, + { + "name": "ninja-vcpkg-debug", + "configurePreset": "ninja-vcpkg-debug" + }, + { + "name": "ninja-vcpkg-develop", + "configurePreset": "ninja-vcpkg-develop" + }, + { + "name": "ninja-vcpkg-release", + "configurePreset": "ninja-vcpkg-release" + }, { "name": "ninja-x86_mingw_static_vcpkg-debug", "configurePreset": "ninja-x86_mingw_static_vcpkg-debug" @@ -240,6 +312,18 @@ "name": "ninja-x86_mingw_static_vcpkg-testers", "configurePreset": "ninja-x86_mingw_static_vcpkg-testers" }, + { + "name": "ninja-x64_windows_vcpkg-debug", + "configurePreset": "ninja-x64_windows_vcpkg-debug" + }, + { + "name": "ninja-x64_windows_vcpkg-develop", + "configurePreset": "ninja-x64_windows_vcpkg-develop" + }, + { + "name": "ninja-x64_windows_vcpkg-release", + "configurePreset": "ninja-x64_windows_vcpkg-release" + }, { "name": "ninja-x64_osx_vcpkg-debug", "configurePreset": "ninja-x64_osx_vcpkg-debug" From 9d6f9c704e8d102df52f20f5c093fd9aa7d3bb6b Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 02/10] Vendor overlay port for libyuv to support clang windows build --- thirdparty/overlay-ports/libyuv/cmake.diff | 63 ++++++++++++ .../overlay-ports/libyuv/libyuv-config.cmake | 5 + .../overlay-ports/libyuv/portfile.cmake | 95 +++++++++++++++++++ thirdparty/overlay-ports/libyuv/usage | 5 + thirdparty/overlay-ports/libyuv/vcpkg.json | 29 ++++++ 5 files changed, 197 insertions(+) create mode 100644 thirdparty/overlay-ports/libyuv/cmake.diff create mode 100644 thirdparty/overlay-ports/libyuv/libyuv-config.cmake create mode 100644 thirdparty/overlay-ports/libyuv/portfile.cmake create mode 100644 thirdparty/overlay-ports/libyuv/usage create mode 100644 thirdparty/overlay-ports/libyuv/vcpkg.json diff --git a/thirdparty/overlay-ports/libyuv/cmake.diff b/thirdparty/overlay-ports/libyuv/cmake.diff new file mode 100644 index 000000000..843afb9aa --- /dev/null +++ b/thirdparty/overlay-ports/libyuv/cmake.diff @@ -0,0 +1,63 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9a20941d..d161326c 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -4,8 +4,9 @@ + + include(CheckCSourceCompiles) + ++cmake_minimum_required(VERSION 3.12) + project ( YUV C CXX ) # "C" is required even for C++ projects +-cmake_minimum_required( VERSION 2.8.12 ) ++option( BUILD_TOOLS "Build tools" OFF ) + option( UNIT_TEST "Built unit tests" OFF ) + + set ( ly_base_dir ${PROJECT_SOURCE_DIR} ) +@@ -149,6 +150,8 @@ if(WIN32) + set_target_properties( ${ly_lib_shared} PROPERTIES IMPORT_PREFIX "lib" ) + endif() + ++if (BUILD_TOOLS) ++ + # this creates the cpuid tool + add_executable ( cpuid ${ly_base_dir}/util/cpuid.c ) + target_link_libraries ( cpuid ${ly_lib_static} ) +@@ -161,10 +164,13 @@ target_link_libraries ( yuvconvert ${ly_lib_static} ) + add_executable ( yuvconstants ${ly_base_dir}/util/yuvconstants.c ) + target_link_libraries ( yuvconstants ${ly_lib_static} ) + ++endif() ++ + find_package ( JPEG ) + if (JPEG_FOUND) + include_directories( ${JPEG_INCLUDE_DIR} ) +- target_link_libraries( ${ly_lib_shared} ${JPEG_LIBRARY} ) ++ target_link_libraries( ${ly_lib_static} PRIVATE JPEG::JPEG ) ++ target_link_libraries( ${ly_lib_shared} PRIVATE JPEG::JPEG ) + add_definitions( -DHAVE_JPEG ) + endif() + +@@ -211,9 +217,20 @@ endif() + + + # install the conversion tool, .so, .a, and all the header files +-install ( TARGETS yuvconvert DESTINATION bin ) +-install ( TARGETS ${ly_lib_static} DESTINATION lib ) +-install ( TARGETS ${ly_lib_shared} LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib ) ++if (BUILD_TOOLS) ++ install(TARGETS yuvconvert yuvconstants) ++endif() ++if(BUILD_SHARED_LIBS) ++ target_include_directories(${ly_lib_shared} PUBLIC $) ++ install(TARGETS ${ly_lib_shared} EXPORT libyuv-targets) ++ set_target_properties(${ly_lib_shared} PROPERTIES EXPORT_NAME "${ly_lib_static}") # vcpkg legacy ++ add_definitions(-DLIBYUV_BUILDING_SHARED_LIBRARY) ++else() ++ target_include_directories(${ly_lib_static} PUBLIC $) ++ install(TARGETS ${ly_lib_static} EXPORT libyuv-targets) ++ set_target_properties(${ly_lib_shared} PROPERTIES EXCLUDE_FROM_ALL 1) ++endif() ++install(EXPORT libyuv-targets DESTINATION share/libyuv) + install ( DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include ) + + # create the .deb and .rpm packages using cpack diff --git a/thirdparty/overlay-ports/libyuv/libyuv-config.cmake b/thirdparty/overlay-ports/libyuv/libyuv-config.cmake new file mode 100644 index 000000000..1e68c1540 --- /dev/null +++ b/thirdparty/overlay-ports/libyuv/libyuv-config.cmake @@ -0,0 +1,5 @@ +include(CMakeFindDependencyMacro) +find_dependency(JPEG) + +set(libyuv_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../include") +include("${CMAKE_CURRENT_LIST_DIR}/libyuv-targets.cmake") diff --git a/thirdparty/overlay-ports/libyuv/portfile.cmake b/thirdparty/overlay-ports/libyuv/portfile.cmake new file mode 100644 index 000000000..c0e88dc79 --- /dev/null +++ b/thirdparty/overlay-ports/libyuv/portfile.cmake @@ -0,0 +1,95 @@ +vcpkg_from_git( + OUT_SOURCE_PATH SOURCE_PATH + URL https://chromium.googlesource.com/libyuv/libyuv + REF a37e6bc81b52d39cdcfd0f1428f5d6c2b2bc9861 # 1896 Fixes build error on macOS Homebrew LLVM 19 + # Check https://chromium.googlesource.com/libyuv/libyuv/+/refs/heads/main/include/libyuv/version.h for a version! + PATCHES + cmake.diff +) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + tools BUILD_TOOLS +) + +# BEGIN CLANG-CL HACK FOR MSVC +vcpkg_cmake_get_vars(cmake_vars_file) +include("${cmake_vars_file}") +if (VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT VCPKG_TARGET_IS_UWP) + # Most of libyuv accelerated features need to be compiled by clang/gcc, so force use clang-cl, otherwise the performance is too poor. + # Manually build the port with clang-cl when using MSVC as compiler + + message(STATUS "Set compiler to clang-cl when using MSVC") + + # https://github.com/microsoft/vcpkg/pull/10398 + set(VCPKG_POLICY_SKIP_ARCHITECTURE_CHECK enabled) + + vcpkg_find_acquire_program(CLANG) + if (CLANG MATCHES "-NOTFOUND") + message(FATAL_ERROR "Clang is required.") + endif () + get_filename_component(CLANG "${CLANG}" DIRECTORY) + + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") + set(CLANG_TARGET "arm") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + set(CLANG_TARGET "aarch64") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") + set(CLANG_TARGET "i686") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(CLANG_TARGET "x86_64") + else() + message(FATAL_ERROR "Unsupported target architecture") + endif() + + set(CLANG_TARGET "${CLANG_TARGET}-pc-windows-msvc") + + message(STATUS "Using clang target ${CLANG_TARGET}") + string(APPEND VCPKG_DETECTED_CMAKE_CXX_FLAGS --target=${CLANG_TARGET}) + string(APPEND VCPKG_DETECTED_CMAKE_C_FLAGS --target=${CLANG_TARGET}) + + set(BUILD_OPTIONS + -DCMAKE_CXX_COMPILER=${CLANG}/clang-cl.exe + -DCMAKE_C_COMPILER=${CLANG}/clang-cl.exe + -DCMAKE_CXX_FLAGS=${VCPKG_DETECTED_CMAKE_CXX_FLAGS} + -DCMAKE_C_FLAGS=${VCPKG_DETECTED_CMAKE_C_FLAGS}) +endif () +# END CLANG-CL HACK FOR MSVC + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} + OPTIONS_DEBUG + -DBUILD_TOOLS=OFF +) + +vcpkg_cmake_install() +vcpkg_cmake_config_fixup() +if("tools" IN_LIST FEATURES) + vcpkg_copy_tools(TOOL_NAMES yuvconvert yuvconstants AUTO_CLEAN) +endif() + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/libyuv/basic_types.h" "defined(LIBYUV_USING_SHARED_LIBRARY)" "1") +endif() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") + +file(COPY "${CMAKE_CURRENT_LIST_DIR}/libyuv-config.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") + +#vcpkg_cmake_get_vars(cmake_vars_file) +#include("${cmake_vars_file}") +#if(VCPKG_DETECTED_CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") +# file(APPEND "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" [[ +# +#Attention: +#You are using MSVC to compile libyuv. This build won't compile any +#of the acceleration codes, which results in a very slow library. +#See workarounds: https://github.com/microsoft/vcpkg/issues/28446 +#]]) +#endif() + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/thirdparty/overlay-ports/libyuv/usage b/thirdparty/overlay-ports/libyuv/usage new file mode 100644 index 000000000..6de3d961d --- /dev/null +++ b/thirdparty/overlay-ports/libyuv/usage @@ -0,0 +1,5 @@ +libyuv provides CMake targets: + + # Unofficial config package and target from vcpkg + find_package(libyuv CONFIG REQUIRED) + target_link_libraries(main PRIVATE yuv) diff --git a/thirdparty/overlay-ports/libyuv/vcpkg.json b/thirdparty/overlay-ports/libyuv/vcpkg.json new file mode 100644 index 000000000..4b8c9cef5 --- /dev/null +++ b/thirdparty/overlay-ports/libyuv/vcpkg.json @@ -0,0 +1,29 @@ +{ + "name": "libyuv", + "version": "1896", + "port-version": 1, + "description": "libyuv is an open source project that includes YUV scaling and conversion functionality", + "homepage": "https://chromium.googlesource.com/libyuv/libyuv", + "license": null, + "dependencies": [ + "libjpeg-turbo", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + { + "name": "vcpkg-cmake-get-vars", + "host": true + } + ], + "features": { + "tools": { + "description": "build command line tool", + "supports": "!android & !ios & !xbox & !wasm32" + } + } +} From 7196ac4ee338249a957d3bd6d39fc274d24549c0 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 03/10] Add overlay ports to presets --- CMakePresets.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index ec794936d..199d9bcf4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -83,7 +83,8 @@ "name": "__vcpkg-toolchain", "hidden": true, "cacheVariables": { - "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "VCPKG_OVERLAY_PORTS": "${sourceDir}/thirdparty/overlay-ports" } }, { From 2346ad674c8c0372fd17f0cd9b2bbb28206a4ed6 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 04/10] Disable libfmt unicode support for annoying windows reasons --- thirdparty/fmt/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/thirdparty/fmt/CMakeLists.txt b/thirdparty/fmt/CMakeLists.txt index f926d89eb..f9705db3b 100644 --- a/thirdparty/fmt/CMakeLists.txt +++ b/thirdparty/fmt/CMakeLists.txt @@ -6,4 +6,5 @@ add_library(fmt INTERFACE) target_include_directories(fmt INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_compile_features(fmt INTERFACE cxx_std_11) target_compile_definitions(fmt INTERFACE -DFMT_HEADER_ONLY) +target_compile_definitions(fmt INTERFACE "-DFMT_UNICODE=0") add_library(fmt::fmt-header-only ALIAS fmt) From 58bbabc1b1f51e335e62b818fa1a0c31e8de0cd6 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 05/10] Realign some byteptr.h macros --- src/byteptr.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/byteptr.h b/src/byteptr.h index 56d18e93f..842a641bc 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -63,13 +63,13 @@ extern "C" { #define READFIXED(p) ({ const fixed_t *p_tmp = (const fixed_t *)p; fixed_t b; memcpy(&b, p, sizeof(fixed_t)); p_tmp++; *(const void**)(&(p)) = (const void *)p_tmp; b; }) #define READANGLE(p) ({ const angle_t *p_tmp = (const angle_t *)p; angle_t b; memcpy(&b, p, sizeof(angle_t)); p_tmp++; *(const void**)(&(p)) = (const void *)p_tmp; b; }) #else -#define READUINT8(p) ((const UINT8*)(*(const void**)(&(p)) = (const void*)&((const UINT8*)(p))[1]))[-1] -#define READSINT8(p) ((const SINT8*)(*(const void**)(&(p)) = (const void*)&((const SINT8*)(p))[1]))[-1] -#define READINT16(p) ((const INT16*)(*(const void**)(&(p)) = (const void*)&((const INT16*)(p))[1]))[-1] -#define READUINT16(p) ((const UINT16*)(*(const void**)(&(p)) = (const void*)&((const UINT16*)(p))[1]))[-1] -#define READINT32(p) ((const INT32*)(*(const void**)(&(p)) = (const void*)&((const INT32*)(p))[1]))[-1] -#define READUINT32(p) ((const UINT32*)(*(const void**)(&(p)) = (const void*)&((const UINT32*)(p))[1]))[-1] -#define READCHAR(p) ((const char*)(*(const void**)(&(p)) = (const void*)&((const char*)(p))[1]))[-1] +#define READUINT8(p) ((const UINT8*) (*(const void**)(&(p)) = (const void*)&((const UINT8*) (p))[1]))[-1] +#define READSINT8(p) ((const SINT8*) (*(const void**)(&(p)) = (const void*)&((const SINT8*) (p))[1]))[-1] +#define READINT16(p) ((const INT16*) (*(const void**)(&(p)) = (const void*)&((const INT16*) (p))[1]))[-1] +#define READUINT16(p) ((const UINT16*) (*(const void**)(&(p)) = (const void*)&((const UINT16*) (p))[1]))[-1] +#define READINT32(p) ((const INT32*) (*(const void**)(&(p)) = (const void*)&((const INT32*) (p))[1]))[-1] +#define READUINT32(p) ((const UINT32*) (*(const void**)(&(p)) = (const void*)&((const UINT32*) (p))[1]))[-1] +#define READCHAR(p) ((const char*) (*(const void**)(&(p)) = (const void*)&((const char*) (p))[1]))[-1] #define READFIXED(p) ((const fixed_t*)(*(const void**)(&(p)) = (const void*)&((const fixed_t*)(p))[1]))[-1] #define READANGLE(p) ((const angle_t*)(*(const void**)(&(p)) = (const void*)&((const angle_t*)(p))[1]))[-1] #endif From 8336c1561104c98a9b0f3b096d8f4477404de960 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 06/10] Prevent auto win32 manifest generation on link/lld-link --- src/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7d26a4b9b..104824c3d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -224,6 +224,10 @@ if(("${CMAKE_COMPILER_IS_GNUCC}" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND endif() endif() +if(MSVC OR CMAKE_CXX_LINK_EXECUTABLE MATCHES "lld-link.exe") + target_link_options(SRB2SDL2 PRIVATE /MANIFEST:NO) +endif() + target_compile_features(SRB2SDL2 PRIVATE c_std_11 cxx_std_17) set_target_properties(SRB2SDL2 PROPERTIES C_STANDARD 11 From 4f7f0587b228c77083166c0aab0725e620b9ac3d Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 07/10] Adjust compiler warnings for upcoming clang-cl --- src/CMakeLists.txt | 53 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 104824c3d..6f17d49ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -539,13 +539,21 @@ target_compile_options(SRB2SDL2 PRIVATE # C, Clang and Apple Clang $<$,$,$>>: - -Wall - -Wno-absolute-value - -Wno-trigraphs - -Wno-error=non-literal-null-conversion - -Wno-error=constant-conversion - -Wno-unused-but-set-variable - -Wno-error=unused-but-set-variable + #-Wall + -Werror=microsoft + -Wreturn-type # Missing returns in non-void function + -Wduplicate-decl-specifier + -Wsometimes-uninitialized + -Wno-trigraphs # Trigraphs are disabled + -Wc11-extensions # Don't use C11 language extensions not part of baseline + -Wno-unused-but-set-variable # Setting unread variables is fine + -Wno-misleading-indentation # Some cases in code currently + -Wno-deprecated-non-prototype # We have no intention of using C23 yet. + -Wno-parentheses-equality + -Wno-unsafe-buffer-usage # Very common in this codebase + -Wno-unused-const-variable + -Wno-unused-variable + -Wno-unused-function > # C, MSVC @@ -555,16 +563,35 @@ target_compile_options(SRB2SDL2 PRIVATE /Wv:19.20.27004.0 > - # C++, GNU, Clang and Apple Clang - $<$,$,$,$>>: + # C++, GNU + $<$,$>: -Wall + > + + # C++, GNU, Clang and Apple Clang + $<$,$,$>>: + #-Wall + -Werror=microsoft + -Wdelete-abstract-non-virtual-dtor + -Wreturn-type # Missing returns in non-void function + -Wduplicate-decl-specifier + -Wsometimes-uninitialized + -Wno-trigraphs # Trigraphs are disabled + -Wno-c++98-compat + -Wno-c++11-compat + -Wno-c++14-compat # No C++14 compat needed + -Wno-unused-but-set-variable # Setting unread variables is fine (nontrivial C++ types issue) + -Wno-misleading-indentation # Some cases in code currently + -Wno-deprecated-non-prototype # We have no intention of using C23 yet. + -Wno-parentheses-equality + -Wno-unsafe-buffer-usage # Very common in this codebase + -Wno-unused-const-variable + -Wno-unused-variable -Wno-unused-function - -Wno-unused-but-set-variable - -Wno-unused-private-field > # C++, MSVC - $<$,$>: + $<$,$>: /Wv:19.20.27004.0 > @@ -645,7 +672,7 @@ add_subdirectory(modp_b64) # strip debug symbols into separate file when using gcc or clang. # to be consistent with Makefile, don't generate for OS X. -if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)) +if((CMAKE_COMPILER_IS_GNUCC) AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)) if(${CMAKE_BUILD_TYPE} MATCHES RelWithDebInfo OR SRB2_CONFIG_ALWAYS_MAKE_DEBUGLINK) message(STATUS "Will make separate debug symbols in *.debug") add_custom_command(TARGET SRB2SDL2 POST_BUILD From b9a8e355d3bbc68f773d43bf58fefaab2cecd91c Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 08/10] Add more defs for clang-cl to suppress API deprecation warnings --- src/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f17d49ce..bcb627f1a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -445,8 +445,12 @@ if (NOT SRB2_CONFIG_FORCE_NO_MS_BITFIELDS) endif() # Yes we know we use insecure CRT functions... -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - target_compile_definitions(SRB2SDL2 PRIVATE -D_CRT_SECURE_NO_WARNINGS) +if(WIN32 OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + target_compile_definitions(SRB2SDL2 PRIVATE + -D_CRT_SECURE_NO_WARNINGS + -D_CRT_NONSTDC_NO_WARNINGS + -D_WINSOCK_DEPRECATED_NO_WARNINGS + ) endif() # Compiler warnings configuration From e22d14bd9d61eb0f75f4c1bd20e03a713d3fdac1 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 09/10] Disable runtime dll copies for clang-cl --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bcb627f1a..e3bb3c070 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -689,7 +689,7 @@ if((CMAKE_COMPILER_IS_GNUCC) AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)) endif() # copy DLLs to bin/ directory if building internal shared on windows -if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows AND NOT "${SRB2_CONFIG_INTERNAL_LIBRARIES}") +if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows AND NOT "${SRB2_CONFIG_INTERNAL_LIBRARIES}" AND NOT MSVC) # also copy implicitly linked system libraries set(ADDITIONAL_DLLS "") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL GNU) From 0dc337c9a5a7bd95d3ea966a9a55172720a8c625 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Mon, 25 Aug 2025 21:28:53 -0500 Subject: [PATCH 10/10] Fix lots of code for clang-cl compatibility --- src/acs/thread.hpp | 2 - src/blua/luaconf.h | 18 ++-- src/core/json.cpp | 85 +++++++++++-------- src/core/string.cpp | 6 +- src/core/vector.hpp | 5 +- src/cvars.cpp | 5 +- src/d_player.h | 2 + src/doomdef.h | 8 ++ src/doomtype.h | 40 ++------- src/filesrch.c | 4 +- src/g_demo.cpp | 8 +- src/g_game.c | 3 +- src/hardware/r_opengl/r_opengl.c | 2 +- src/hwr2/patch_atlas.cpp | 2 +- src/i_tcp.c | 10 +-- src/io/streams.hpp | 27 +++--- src/k_collide.cpp | 7 +- src/k_grandprix.cpp | 4 +- src/k_hud.cpp | 2 +- src/k_menu.h | 24 ++++++ src/k_menudraw.c | 8 +- src/k_profiles.cpp | 2 +- src/m_fixed.h | 2 - src/m_misc.cpp | 12 ++- src/md5.h | 2 +- src/media/options.cpp | 6 +- src/menus/extras-egg-tv.cpp | 10 +-- src/menus/main-goner.cpp | 18 ++-- .../options-profiles-edit-accessibility.cpp | 24 +++--- src/menus/options-sound.cpp | 24 +++--- src/menus/options-voice.cpp | 16 ++-- src/menus/transient/pause-addonoptions.cpp | 4 +- src/menus/transient/pause-cheats.cpp | 4 +- src/objects/battle-ufo.cpp | 6 +- src/objects/checkpoint.cpp | 25 +++--- src/p_setup.cpp | 3 +- src/r_things.cpp | 2 +- src/sdl/CMakeLists.txt | 6 +- src/sdl/i_main.cpp | 13 ++- src/sdl/i_system.cpp | 6 +- src/sdl/i_video.cpp | 12 +-- src/st_stuff.c | 6 +- src/v_video.cpp | 2 + src/win32/Srb2win.rc | 12 ++- src/y_inter.cpp | 3 +- 45 files changed, 271 insertions(+), 221 deletions(-) diff --git a/src/acs/thread.hpp b/src/acs/thread.hpp index 88d8d4307..b7eccedda 100644 --- a/src/acs/thread.hpp +++ b/src/acs/thread.hpp @@ -16,7 +16,6 @@ #include "acsvm.hpp" -extern "C" { #include "../doomtype.h" #include "../doomdef.h" #include "../doomstat.h" @@ -24,7 +23,6 @@ extern "C" { #include "../r_defs.h" #include "../r_state.h" #include "../p_spec.h" -} namespace srb2::acs { diff --git a/src/blua/luaconf.h b/src/blua/luaconf.h index 9e2948f41..618d80635 100644 --- a/src/blua/luaconf.h +++ b/src/blua/luaconf.h @@ -10,13 +10,7 @@ #include #include - -#ifdef _MSC_VER -#define INT32 __int32 -#else #include -#define INT32 int32_t -#endif /* @@ -147,7 +141,7 @@ ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most ** machines, ptrdiff_t gives a good choice between int or long.) */ -#define LUA_INTEGER INT32 +#define LUA_INTEGER int32_t /* @@ -418,9 +412,9 @@ ** longs.) Probably you do not need to change this. */ #if LUAI_BITSINT >= 32 -#define LUAI_UINT32 unsigned int -#define LUAI_INT32 int -#define LUAI_MAXINT32 INT_MAX +#define LUAI_UINT32 uint32_t +#define LUAI_INT32 int32_t +#define LUAI_MAXINT32 INT32_MAX #define LUAI_UMEM size_t #define LUAI_MEM ptrdiff_t #else @@ -509,13 +503,13 @@ */ //#define LUA_NUMBER_DOUBLE -#define LUA_NUMBER INT32 +#define LUA_NUMBER int32_t /* @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' @* over a number. */ -#define LUAI_UACNUMBER INT32 +#define LUAI_UACNUMBER int32_t /* diff --git a/src/core/json.cpp b/src/core/json.cpp index d123637e3..4918c2de4 100644 --- a/src/core/json.cpp +++ b/src/core/json.cpp @@ -1238,90 +1238,93 @@ static JsonValue parse_number(const Token& token) throw JsonParseError("only sign present on number"); } - const char* integral_start = s.begin(); - const char* integral_end; - const char* decimal = nullptr; - while (!s.empty()) + std::string_view::const_iterator integral_start = s.begin(); + std::string_view::const_iterator integral_end; + bool decimal_found = false; + std::string_view::const_iterator decimal; + size_t pos = 0; + while (pos < s.size()) { - if (s[0] == '.') + if (s[pos] == '.') { - decimal = s.begin(); - integral_end = s.begin(); - s.remove_prefix(1); + decimal_found = true; + decimal = std::next(s.begin(), pos); + integral_end = std::next(s.begin(), pos); + pos += 1; break; } - else if (s[0] < '0' || s[0] > '9') + else if (s[pos] < '0' || s[pos] > '9') { - integral_end = s.begin() - 1; + integral_end = std::next(s.begin(), pos - 1); break; } - integral_end = s.begin() + 1; - s.remove_prefix(1); + integral_end = std::next(s.begin(), pos + 1); + pos += 1; } - const char* decimal_start = s.end(); - const char* decimal_end = s.end(); - const char* exponent_start = s.end(); - const char* exponent_end = s.end(); + std::string_view::const_iterator decimal_start = s.end(); + std::string_view::const_iterator decimal_end = s.end(); + std::string_view::const_iterator exponent_start = s.end(); + std::string_view::const_iterator exponent_end = s.end(); bool should_have_exponent = false; - if (decimal != nullptr && (decimal + 1) < s.end()) + if (decimal_found && (decimal + 1) < s.end()) { decimal_start = decimal + 1; } - while (!s.empty()) + while (pos < s.size()) { // ingest decimal - if (s[0] == 'E' || s[0] == 'e') + if (s[pos] == 'E' || s[pos] == 'e') { if (decimal_start != s.end()) decimal_end = s.begin(); - exponent_start = s.begin() + 1; + exponent_start = std::next(s.begin(), pos + 1); should_have_exponent = true; - s.remove_prefix(1); + pos += 1; break; } - else if ((s[0] < '0' || s[0] > '9') && s[0] != '+' && s[0] != '-') + else if ((s[pos] < '0' || s[pos] > '9') && s[pos] != '+' && s[pos] != '-') { throw JsonParseError("invalid character after decimal"); } - decimal_end = s.begin() + 1; - s.remove_prefix(1); + decimal_end = std::next(s.begin(), pos + 1); + pos += 1; } bool exponent_negative = false; if (should_have_exponent) { - if (s.empty()) + if (pos >= s.size()) { throw JsonParseError("exponent started but not specified"); } bool exponent_was_signed = false; while (!s.empty()) { - if (s[0] == '-') + if (s[pos] == '-') { if (exponent_was_signed) throw JsonParseError("multiple signs on exponent"); exponent_negative = true; exponent_start++; exponent_was_signed = true; - s.remove_prefix(1); + pos += 1; continue; } - else if (s[0] == '+') + else if (s[pos] == '+') { if (exponent_was_signed) throw JsonParseError("multiple signs on exponent"); exponent_start++; exponent_was_signed = true; - s.remove_prefix(1); + pos += 1; continue; } - if (s[0] < '0' || s[0] > '9') + if (s[pos] < '0' || s[pos] > '9') { throw JsonParseError("invalid character after exponent"); } - exponent_end = s.begin() + 1; - s.remove_prefix(1); + exponent_end = std::next(s.begin(), pos + 1); + pos += 1; } if ((exponent_end - exponent_start) == 0) { @@ -1329,9 +1332,21 @@ static JsonValue parse_number(const Token& token) } } - std::string_view integral_view { integral_start, (size_t)(integral_end - integral_start) }; - std::string_view decimal_view { decimal_start, (size_t)(decimal_end - decimal_start) }; - std::string_view exponent_view { exponent_start, (size_t)(exponent_end - exponent_start) }; + std::string_view integral_view = ""; + if (integral_start != s.end()) + { + integral_view = std::string_view { &*integral_start, (size_t)(integral_end - integral_start) }; + } + std::string_view decimal_view = ""; + if (decimal_start != s.end()) + { + decimal_view = std::string_view { &*decimal_start, (size_t)(decimal_end - decimal_start) }; + } + std::string_view exponent_view = ""; + if (exponent_start != s.end()) + { + std::string_view { &*exponent_start, (size_t)(exponent_end - exponent_start) }; + } if (should_have_exponent && decimal_start != s.end() && decimal_view.empty()) { diff --git a/src/core/string.cpp b/src/core/string.cpp index 2bd0bd24f..4ef99823b 100644 --- a/src/core/string.cpp +++ b/src/core/string.cpp @@ -171,11 +171,13 @@ String& String::insert(size_type index, const char* s, size_type count) String& String::insert(size_type index, std::string_view str) { - return insert(index, str.begin(), (size_type)str.size()); + if (str.empty()) return *this; + return insert(index, &*str.begin(), (size_type)str.size()); } String& String::insert(size_type index, std::string_view str, size_t s_index, size_t count) { + if (str.empty()) return *this; if (s_index > str.size()) { throw std::out_of_range("s_index > str.size()"); @@ -343,7 +345,7 @@ String& String::replace(const_iterator first, const_iterator last, std::string_v { throw std::out_of_range("string replacement range out of bounds"); } - size_type index = first - data_.data(); + size_type index = &*first - data_.data(); size_type count = last - first; return replace(index, count, str); diff --git a/src/core/vector.hpp b/src/core/vector.hpp index ec26334ea..157702d65 100644 --- a/src/core/vector.hpp +++ b/src/core/vector.hpp @@ -230,7 +230,10 @@ public: size_t count_destroyed = 0; for (auto itr = itr_begin; itr != itr_end; itr++) { - itr->~T(); + if constexpr (std::is_destructible_v) + { + (*itr).~T(); + } count_destroyed++; } size_ = s; diff --git a/src/cvars.cpp b/src/cvars.cpp index 82645415a..39593fd89 100644 --- a/src/cvars.cpp +++ b/src/cvars.cpp @@ -292,7 +292,8 @@ const auto GraphicsDriver = consvar_t::Builder(cvlist_graphics_driver).save(); // Player local, not available on dedicated servers. // These usually save... // - +extern "C" +{ consvar_t cv_addons_md5 = Player("addons_md5", "Name").values({{0, "Name"}, {1, "Contents"}}); consvar_t cv_addons_search_case = Player("addons_search_case", "No").yes_no(); consvar_t cv_addons_search_type = Player("addons_search_type", "Anywhere").values({{0, "Start"}, {1, "Anywhere"}}); @@ -1543,7 +1544,7 @@ consvar_t cv_globalsaturation; consvar_t cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma; consvar_t cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue; consvar_t cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation; - +} // clang-format on // This function can be used for more advanced cvar diff --git a/src/d_player.h b/src/d_player.h index 4b704519c..9a1e441b9 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -15,6 +15,8 @@ #ifndef __D_PLAYER__ #define __D_PLAYER__ +#include + // The player data structure depends on a number // of other structs: items (internal inventory), // animation states (closely tied to the sprites diff --git a/src/doomdef.h b/src/doomdef.h index 9afedf74c..9529e1bb6 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -66,10 +66,16 @@ extern "C" { // If you don't disable ALL debug first, you get ALL debug enabled #if !defined (NDEBUG) +#ifndef PACKETDROP #define PACKETDROP +#endif +#ifndef PARANOIA #define PARANOIA +#endif +#ifndef ZDEBUG #define ZDEBUG #endif +#endif // Uncheck this to compile debugging code //#ifndef PARANOIA @@ -90,7 +96,9 @@ extern char logfilename[1024]; //#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3 #ifdef DEVELOP +#ifndef PARANOIA #define PARANOIA // On by default for DEVELOP builds +#endif #define VERSIONSTRING "Development EXE" #define VERSIONSTRING_RC "Development EXE" "\0" // most interface strings are ignored in development mode. diff --git a/src/doomtype.h b/src/doomtype.h index 6f2d80794..670d4b9b3 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -23,48 +23,20 @@ extern "C" { #endif #ifdef _WIN32 -//#define WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN #define RPC_NO_WINDOWS_H #include +// win32 sucks +#undef min +#undef max #endif /* 7.18.1.1 Exact-width integer types */ -#ifdef _MSC_VER -// libopenmpt.h will include stdint.h later; -// include it now so that INT8_MAX etc. don't get redefined -#ifdef HAVE_OPENMPT -#include -#endif - -#define UINT8 unsigned __int8 -#define SINT8 signed __int8 - -#define UINT16 unsigned __int16 -#define INT16 __int16 - -#define INT32 __int32 -#define UINT32 unsigned __int32 - -#define INT64 __int64 -#define UINT64 unsigned __int64 - -typedef long ssize_t; - -/* Older Visual C++ headers don't have the Win64-compatible typedefs... */ -#if (_MSC_VER <= 1200) - #ifndef DWORD_PTR - #define DWORD_PTR DWORD - #endif - #ifndef PDWORD_PTR - #define PDWORD_PTR PDWORD - #endif -#endif -#else #define __STDC_LIMIT_MACROS #include +#ifndef _MSC_VER #define UINT8 uint8_t -#define SINT8 int8_t #define UINT16 uint16_t #define INT16 int16_t @@ -75,6 +47,8 @@ typedef long ssize_t; #define UINT64 uint64_t #endif +#define SINT8 int8_t + #ifdef __APPLE_CC__ #define DIRECTFULLSCREEN 1 #define DEBUG_LOG diff --git a/src/filesrch.c b/src/filesrch.c index ba626618c..077dbd51c 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -28,7 +28,7 @@ #include #endif #if defined (_WIN32) && !defined (_XBOX) -//#define WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN #define RPC_NO_WINDOWS_H #include #endif @@ -147,7 +147,7 @@ opendir (const CHAR *szPath) /* Allocate enough space to store DIR structure and the complete * directory path given. */ - nd = (DIR *) malloc (sizeof (DIR) + (strlen(szFullPath) + strlen (SLASH) + + nd = (DIR *) malloc (sizeof (DIR) + (strlen(szFullPath) + strlen(PATHSEP) + 1) * sizeof (CHAR)); if (!nd) diff --git a/src/g_demo.cpp b/src/g_demo.cpp index d4612b92d..736abc752 100644 --- a/src/g_demo.cpp +++ b/src/g_demo.cpp @@ -123,6 +123,7 @@ static char demoname[MAX_WADPATH]; static savebuffer_t demobuf = {0}; static UINT8 *demotime_p, *demoinfo_p, *demoattack_p, *demosplits_p; static UINT16 demoflags; +extern "C" boolean demosynced; boolean demosynced = true; // console warning message struct demovars_s demo; @@ -1683,6 +1684,11 @@ skippedghosttic: } } +extern "C" +{ +extern consvar_t cv_netdemosize; +} + // // G_RecordDemo // @@ -1691,8 +1697,6 @@ void G_RecordDemo(const char *name) if (demo.recording) G_CheckDemoStatus(); - extern consvar_t cv_netdemosize; - INT32 maxsize; strcpy(demoname, name); diff --git a/src/g_game.c b/src/g_game.c index 88f64d126..17c256756 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1867,6 +1867,8 @@ void G_UpdateAllPlayerPreferences(void) } } +extern boolean demosynced; + // // G_Ticker // Make ticcmd_ts for the players. @@ -1883,7 +1885,6 @@ void G_Ticker(boolean run) P_MapStart(); - extern boolean demosynced; if (demo.playback && staffsync && !demosynced) { G_ClearRetryFlag(); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 941808f60..900bae98d 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -11,7 +11,7 @@ /// \brief OpenGL API for Sonic Robo Blast 2 #if defined (_WIN32) -//#define WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN #define RPC_NO_WINDOWS_H #include #endif diff --git a/src/hwr2/patch_atlas.cpp b/src/hwr2/patch_atlas.cpp index 5dad04e5f..395b28601 100644 --- a/src/hwr2/patch_atlas.cpp +++ b/src/hwr2/patch_atlas.cpp @@ -278,7 +278,7 @@ void PatchAtlasCache::pack(Rhi& rhi) atlas.entries_.insert_or_assign(patch, std::move(entry)); patch_lookup_.insert_or_assign(patch, atlas_index); patches_to_upload_.insert(patch); - rects.erase(itr); + itr = rects.erase(itr); continue; } ++itr; diff --git a/src/i_tcp.c b/src/i_tcp.c index ce4abb740..4dddd1522 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -399,7 +399,7 @@ void Command_Numnodes(void) connected, ingame); } -static boolean hole_punch(ssize_t c) +static boolean hole_punch(ptrdiff_t c) { if (c == 10 && holepunchpacket->magic == hole_punch_magic) { @@ -425,7 +425,7 @@ static boolean SOCK_Get(void) { size_t n; int j; - ssize_t c; + ptrdiff_t c; mysockaddr_t fromaddress; socklen_t fromlen; @@ -534,7 +534,7 @@ static boolean SOCK_CanGet(void) } #endif -static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr) +static inline ptrdiff_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t* sockaddr) { socklen_t d4 = (socklen_t)sizeof(struct sockaddr_in); #ifdef HAVE_IPV6 @@ -556,8 +556,8 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr static void SOCK_Send(void) { - ssize_t c = ERRSOCKET; - size_t i, j; + ptrdiff_t c = ERRSOCKET; + ptrdiff_t i, j; if (!nodeconnected[doomcom->remotenode]) return; diff --git a/src/io/streams.hpp b/src/io/streams.hpp index e46093e93..47d92ee8f 100644 --- a/src/io/streams.hpp +++ b/src/io/streams.hpp @@ -11,6 +11,7 @@ #ifndef __SRB2_IO_STREAMS_HPP__ #define __SRB2_IO_STREAMS_HPP__ +#include #include #include #include @@ -408,9 +409,9 @@ public: if (head_ >= span_.size()) return 0; - const auto begin = buffer.begin(); - const auto end = std::copy( - span_.begin() + head_, span_.begin() + head_ + std::min(buffer.size(), span_.size() - head_), begin); + auto begin = buffer.begin(); + auto end = std::copy( + span_.begin() + head_, span_.begin() + head_ + std::min(buffer.size(), span_.size() - head_), begin); head_ += std::distance(begin, end); return std::distance(begin, end); } @@ -419,9 +420,9 @@ public: if (head_ >= span_.size()) return 0; - const auto begin = span_.begin() + head_; - const auto end = - std::copy(buffer.begin(), buffer.begin() + std::min(span_.size() - head_, buffer.size()), begin); + auto begin = span_.begin() + head_; + auto end = + std::copy(buffer.begin(), buffer.begin() + std::min(span_.size() - head_, buffer.size()), begin); head_ += std::distance(begin, end); return std::distance(begin, end); } @@ -501,9 +502,9 @@ public: if (head_ >= vec_.size()) return 0; - const auto begin = buffer.begin(); - const auto end = - std::copy(vec_.begin() + head_, vec_.begin() + head_ + std::min(buffer.size(), vec_.size() - head_), begin); + auto begin = buffer.begin(); + auto end = + std::copy(vec_.begin() + head_, vec_.begin() + head_ + std::min(buffer.size(), vec_.size() - head_), begin); head_ += std::distance(begin, end); return std::distance(begin, end); } @@ -514,9 +515,9 @@ public: vec_.resize(head_ + buffer_size); } - const auto begin = vec_.begin() + head_; - const auto end = - std::copy(buffer.begin(), buffer.begin() + std::min(vec_.size() - head_, buffer.size()), begin); + auto begin = vec_.begin() + head_; + auto end = + std::copy(buffer.begin(), buffer.begin() + std::min(vec_.size() - head_, buffer.size()), begin); head_ += std::distance(begin, end); return std::distance(begin, end); } @@ -901,7 +902,7 @@ public: StreamSize bytesread = inner_.read(readspan); buf_.resize(prereadsize + bytesread); - StreamSize tocopyfrombuf = std::min(buffer.size(), buf_.size()); + StreamSize tocopyfrombuf = std::min(buffer.size(), buf_.size()); std::copy(buf_.begin(), std::next(buf_.begin(), tocopyfrombuf), buffer.begin()); buffer = buffer.subspan(tocopyfrombuf); totalread += tocopyfrombuf; diff --git a/src/k_collide.cpp b/src/k_collide.cpp index 13d4bd3b6..c2b2eae68 100644 --- a/src/k_collide.cpp +++ b/src/k_collide.cpp @@ -55,6 +55,8 @@ angle_t K_GetCollideAngle(mobj_t *t1, mobj_t *t2) return R_PointToAngle2(0, 0, momux, momuy); } +extern "C" consvar_t cv_debugpickmeup; + boolean K_BananaBallhogCollide(mobj_t *t1, mobj_t *t2) { boolean damageitem = false; @@ -75,7 +77,6 @@ boolean K_BananaBallhogCollide(mobj_t *t1, mobj_t *t2) if (t1->type == MT_BALLHOGBOOM && t2->type == MT_BALLHOGBOOM) return true; // Ballhogs don't collide with eachother - extern consvar_t cv_debugpickmeup; if (t1->type == MT_BALLHOGBOOM && t2->type == MT_PLAYER && t1->target == t2 && !cv_debugpickmeup.value) return true; // Allied hog explosion, not snatchable but shouldn't damage @@ -258,6 +259,8 @@ static inline boolean PIT_SSMineChecks(mobj_t *thing) return false; } +extern "C" consvar_t cv_debugpickmeup; + static inline BlockItReturn_t PIT_SSMineSearch(mobj_t *thing) { if (grenade == NULL || P_MobjWasRemoved(grenade)) @@ -276,8 +279,6 @@ static inline BlockItReturn_t PIT_SSMineSearch(mobj_t *thing) return BMIT_CONTINUE; } - extern consvar_t cv_debugpickmeup; - if (!cv_debugpickmeup.value) { if (grenade->target && !P_MobjWasRemoved(grenade->target)) diff --git a/src/k_grandprix.cpp b/src/k_grandprix.cpp index 1732d0bd1..ac4ffb938 100644 --- a/src/k_grandprix.cpp +++ b/src/k_grandprix.cpp @@ -1149,6 +1149,8 @@ boolean K_CanChangeRules(boolean allowdemos) return true; } +extern "C" consvar_t cv_forcebots; + /*-------------------------------------------------- boolean K_BotDefaultSpectator(player_t *player); @@ -1156,8 +1158,6 @@ boolean K_CanChangeRules(boolean allowdemos) --------------------------------------------------*/ boolean K_BotDefaultSpectator(void) { - extern consvar_t cv_forcebots; - if (cv_forcebots.value) { return false; diff --git a/src/k_hud.cpp b/src/k_hud.cpp index c2a68bc9d..6426f04a7 100644 --- a/src/k_hud.cpp +++ b/src/k_hud.cpp @@ -5834,7 +5834,7 @@ position_t K_GetKartObjectPosToMinimapPos(fixed_t objx, fixed_t objy) if (encoremode) amnumxpos = -amnumxpos; - return (position_t){amnumxpos, amnumypos}; + return position_t{amnumxpos, amnumypos}; } static void K_drawKartMinimapIcon(fixed_t objx, fixed_t objy, INT32 hudx, INT32 hudy, INT32 flags, patch_t *icon, UINT8 *colormap) diff --git a/src/k_menu.h b/src/k_menu.h index d9fe1186c..3fff5ac26 100644 --- a/src/k_menu.h +++ b/src/k_menu.h @@ -1631,4 +1631,28 @@ const char *M_GetDiscordName(discordRequest_t *r); } // extern "C" #endif +#ifdef __cplusplus +namespace srb2 +{ +constexpr inline itemaction_t itemaction(menu_t* menu) +{ + itemaction_t ret {}; + ret.submenu = menu; + return ret; +} +constexpr inline itemaction_t itemaction(consvar_t* consvar) +{ + itemaction_t ret {}; + ret.cvar = consvar; + return ret; +} +constexpr inline itemaction_t itemaction(void (*routine)(INT32 choice)) +{ + itemaction_t ret {}; + ret.routine = routine; + return ret; +} +} +#endif + #endif //__K_MENU__ diff --git a/src/k_menudraw.c b/src/k_menudraw.c index eab2a1988..b9fd2c623 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -6712,7 +6712,7 @@ static void M_CacheAddonPatches(void) void M_DrawAddons(void) { INT32 x, y; - ssize_t i, m; + ptrdiff_t i, m; const UINT8 *flashcol = NULL; UINT8 hilicol; @@ -6763,7 +6763,7 @@ void M_DrawAddons(void) i = 0; else { - ssize_t q = m; + ptrdiff_t q = m; m = ((2*numaddonsshown + 1) * m)/sizedirmenu; if (dir_on[menudepthleft] <= numaddonsshown) // all the way up i = 0; @@ -6777,7 +6777,7 @@ void M_DrawAddons(void) // get bottom... m = dir_on[menudepthleft] + numaddonsshown + 1; - if (m > (ssize_t)sizedirmenu) + if (m > (ptrdiff_t) sizedirmenu) m = sizedirmenu; // then compute top and adjust bottom if needed! @@ -6830,7 +6830,7 @@ void M_DrawAddons(void) y += addonsseperation; } - if (m != (ssize_t)sizedirmenu) + if (m != (ptrdiff_t) sizedirmenu) V_DrawMenuString(19, y-12 + (skullAnimCounter/5), highlightflags, "\x1B"); if (m < (2*numaddonsshown + 1)) diff --git a/src/k_profiles.cpp b/src/k_profiles.cpp index 06febe5c7..ea3079261 100644 --- a/src/k_profiles.cpp +++ b/src/k_profiles.cpp @@ -35,7 +35,7 @@ extern "C" consvar_t cv_dummyprofilefov, cv_fov[MAXSPLITSCREENPLAYERS]; -CV_PossibleValue_t lastprofile_cons_t[] = {{-1, "MIN"}, {MAXPROFILES, "MAX"}, {0, NULL}}; +extern "C" CV_PossibleValue_t lastprofile_cons_t[] = {{-1, "MIN"}, {MAXPROFILES, "MAX"}, {0, NULL}}; // List of all the profiles. static profile_t *profilesList[MAXPROFILES+1]; // +1 because we're gonna add a default "GUEST' profile. diff --git a/src/m_fixed.h b/src/m_fixed.h index 13c46ac77..de4b0f252 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -17,9 +17,7 @@ #define __M_FIXED__ #include "doomtype.h" -#ifdef __GNUC__ #include -#endif #ifdef __cplusplus extern "C" { diff --git a/src/m_misc.cpp b/src/m_misc.cpp index be30404ff..84f3f520c 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -21,12 +21,12 @@ #pragma GCC diagnostic ignored "-Wclobbered" #endif -#include - #include #endif + #include +#include #include // Extended map support. @@ -115,14 +115,17 @@ typedef off_t off64_t; #endif #endif +extern "C" CV_PossibleValue_t lossless_recorder_cons_t[]; CV_PossibleValue_t lossless_recorder_cons_t[] = {{MM_GIF, "GIF"}, {MM_APNG, "aPNG"}, {MM_SCREENSHOT, "Screenshots"}, {0, NULL}}; +extern "C" CV_PossibleValue_t zlib_mem_level_t[]; CV_PossibleValue_t zlib_mem_level_t[] = { {1, "(Min Memory) 1"}, {2, "2"}, {3, "3"}, {4, "4"}, {5, "5"}, {6, "6"}, {7, "7"}, {8, "(Optimal) 8"}, //libpng Default {9, "(Max Memory) 9"}, {0, NULL}}; +extern "C" CV_PossibleValue_t zlib_level_t[]; CV_PossibleValue_t zlib_level_t[] = { {0, "No Compression"}, //Z_NO_COMPRESSION {1, "(Fastest) 1"}, //Z_BEST_SPEED @@ -132,6 +135,7 @@ CV_PossibleValue_t zlib_level_t[] = { {9, "(Maximum) 9"}, //Z_BEST_COMPRESSION {0, NULL}}; +extern "C" CV_PossibleValue_t zlib_strategy_t[]; CV_PossibleValue_t zlib_strategy_t[] = { {0, "Normal"}, //Z_DEFAULT_STRATEGY {1, "Filtered"}, //Z_FILTERED @@ -140,6 +144,7 @@ CV_PossibleValue_t zlib_strategy_t[] = { {4, "Fixed"}, //Z_FIXED {0, NULL}}; +extern "C" CV_PossibleValue_t zlib_window_bits_t[]; CV_PossibleValue_t zlib_window_bits_t[] = { #ifdef WBITS_8_OK {8, "256"}, @@ -618,6 +623,8 @@ void Command_ChangeConfig_f(void) COM_BufAddText(va("loadconfig \"%s\"\n", COM_Argv(1))); } +extern "C" struct CVarList* cvlist_execversion; + /** Loads the default config file. * * \sa Command_LoadConfig_f @@ -645,7 +652,6 @@ void M_FirstLoadConfig(void) // register execversion here before we load any configs { - extern struct CVarList *cvlist_execversion; CV_RegisterList(cvlist_execversion); } diff --git a/src/md5.h b/src/md5.h index 7caf56d54..13fc3410a 100644 --- a/src/md5.h +++ b/src/md5.h @@ -68,7 +68,7 @@ typedef u_int32_t md5_uint32; #endif #undef __P -#if defined (__STDC__) && __STDC__ +#if (defined (__STDC__) && __STDC__) || _MSC_VER #define __P(x) x #else #define __P(x) () diff --git a/src/media/options.cpp b/src/media/options.cpp index e2f7756a7..5831560bf 100644 --- a/src/media/options.cpp +++ b/src/media/options.cpp @@ -53,14 +53,12 @@ float Options::get(const char* option) const template consvar_t Options::values(const char* default_value, const Range range, std::map list) { - constexpr bool is_float = std::is_floating_point_v; - const std::size_t min_max_size = (range.min || range.max) ? 2 : 0; auto* arr = new CV_PossibleValue_t[list.size() + min_max_size + 1]; auto cast = [](T n) { - if constexpr (is_float) + if constexpr (std::is_floating_point_v) { return FloatToFixed(n); } @@ -94,7 +92,7 @@ consvar_t Options::values(const char* default_value, const Range range, std:: int32_t flags = CV_SAVE; - if constexpr (is_float) + if constexpr (std::is_floating_point_v) { flags |= CV_FLOAT; } diff --git a/src/menus/extras-egg-tv.cpp b/src/menus/extras-egg-tv.cpp index ae62e06d3..921a76aae 100644 --- a/src/menus/extras-egg-tv.cpp +++ b/src/menus/extras-egg-tv.cpp @@ -98,17 +98,17 @@ void M_FavoriteReplay(INT32 c) // extras menu: replay hut menuitem_t EXTRAS_EggTV[] = { - {IT_STRING | IT_CALL, "WATCH REPLAY", NULL, NULL, {.routine = [](auto) { g_egg_tv->watch(); }}, 0, 0}, - {IT_STRING | IT_CALL, "STANDINGS", NULL, NULL, {.routine = [](auto) { g_egg_tv->standings(); }}, 0, 0}, - {IT_STRING | IT_CALL, "FAVORITE", NULL, NULL, {.routine = M_FavoriteReplay}, 0, 0}, + {IT_STRING | IT_CALL, "WATCH REPLAY", NULL, NULL, srb2::itemaction([](auto) -> void { g_egg_tv->watch(); }), 0, 0 }, + {IT_STRING | IT_CALL, "STANDINGS", NULL, NULL, srb2::itemaction([](auto) { g_egg_tv->standings(); }), 0, 0}, + {IT_STRING | IT_CALL, "FAVORITE", NULL, NULL, srb2::itemaction(M_FavoriteReplay), 0, 0}, {IT_SPACE}, - {IT_STRING | IT_CALL, "DELETE REPLAY", NULL, NULL, {.routine = M_DeleteReplay}, 0, 0}, + {IT_STRING | IT_CALL, "DELETE REPLAY", NULL, NULL, srb2::itemaction(M_DeleteReplay), 0, 0}, {IT_SPACE}, - {IT_STRING | IT_CALL, "GO BACK", NULL, NULL, {.routine = [](auto) { g_egg_tv->back(); }}, 0, 0}, + {IT_STRING | IT_CALL, "GO BACK", NULL, NULL, srb2::itemaction([](auto) { g_egg_tv->back(); }), 0, 0}, }; menu_t EXTRAS_EggTVDef = diff --git a/src/menus/main-goner.cpp b/src/menus/main-goner.cpp index 8074bc8a2..41e1d5907 100644 --- a/src/menus/main-goner.cpp +++ b/src/menus/main-goner.cpp @@ -129,31 +129,31 @@ static menuitem_t MAIN_Goner[] = { {IT_STRING | IT_CVAR | IT_CV_STRING, "PASSWORD", "ATTEMPT ADMINISTRATOR ACCESS.", NULL, - {.cvar = &cv_dummyextraspassword}, 0, 0}, + srb2::itemaction(& cv_dummyextraspassword), 0, 0}, {IT_STRING | IT_CALL, "EXIT PROGRAM", "CONCLUDE OBSERVATIONS NOW.", NULL, - {.routine = M_QuitSRB2}, 0, 0}, + srb2::itemaction(M_QuitSRB2), 0, 0}, {IT_STRING | IT_CALL, "VIDEO OPTIONS", "CONFIGURE OCULAR PATHWAYS.", NULL, - {.routine = M_VideoOptions}, 0, 0}, + srb2::itemaction(M_VideoOptions), 0, 0}, {IT_STRING | IT_CALL, "SOUND OPTIONS", "CALIBRATE AURAL DATASTREAM.", NULL, - {.routine = M_SoundOptions}, 0, 0}, + srb2::itemaction(M_SoundOptions), 0, 0}, {IT_STRING | IT_CALL, "PROFILE SETUP", "ASSIGN VEHICLE INPUTS.", NULL, - {.routine = M_GonerProfile}, 0, 0}, + srb2::itemaction(M_GonerProfile), 0, 0}, {IT_STRING | IT_CALL, "MAKE CHOICE", "PREPARE FOR INTEGRATION?", NULL, - {.routine = M_GonerChoice}, 0, 0}, + srb2::itemaction(M_GonerChoice), 0, 0}, {IT_STRING | IT_CALL, "START GAME", "I WILL SUCCEED.", NULL, - {.routine = M_GonerConclude}, 0, 0}, + srb2::itemaction(M_GonerConclude), 0, 0}, }; menu_t MAIN_GonerDef = { @@ -183,7 +183,7 @@ static menuitem_t MAIN_GonerChoice[] = "\n" "This is a structured, back-to-basics tutorial\n" "that will likely take ""\x88""10-20 minutes""\x80"" of your time.", - NULL, {.routine = M_GonerTutorial}, 0, 0}, + NULL, srb2::itemaction(M_GonerTutorial), 0, 0}, //{IT_STRING, NULL, NULL, NULL, {.routine = M_QuitSRB2}, 0, 0}, // will be replaced @@ -194,7 +194,7 @@ static menuitem_t MAIN_GonerChoice[] = "\n" "You can ""\x88""exit immediately""\x80"" and get to racing...\n" "or spend ""\x88""as long as you want""\x80"" in the playground!", - NULL, {.routine = M_GonerPlayground}, 0, 0}, + NULL, srb2::itemaction(M_GonerPlayground), 0, 0}, }; static menu_t MAIN_GonerChoiceDef = { diff --git a/src/menus/options-profiles-edit-accessibility.cpp b/src/menus/options-profiles-edit-accessibility.cpp index d347b3ca4..f7cf362f6 100644 --- a/src/menus/options-profiles-edit-accessibility.cpp +++ b/src/menus/options-profiles-edit-accessibility.cpp @@ -100,25 +100,25 @@ menuitem_t OPTIONS_ProfileAccessibility[] = { NULL, {NULL}, 0, 0}, {IT_STRING | IT_CVAR, "Rumble", "For gamepad users - should your device rumble?", - NULL, {.cvar = &cv_dummyprofilerumble}, 0, 0}, + NULL, srb2::itemaction(&cv_dummyprofilerumble), 0, 0}, {IT_STRING | IT_CVAR, "Auto Roulette", "Item roulette auto-stops on a random result.", - NULL, {.cvar = &cv_dummyprofileautoroulette}, 0, 0}, + NULL, srb2::itemaction(&cv_dummyprofileautoroulette), 0, 0}, {IT_STRING | IT_CVAR, "Auto Ring", "Auto-use rings to maintain momentum.", - NULL, {.cvar = &cv_dummyprofileautoring}, 0, 0}, + NULL, srb2::itemaction(&cv_dummyprofileautoring), 0, 0}, {IT_STRING | IT_CVAR, "Kickstart Accel", "Hold A to auto-accel. Tap it to cancel.", - NULL, {.cvar = &cv_dummyprofilekickstart}, 0, 0}, + NULL, srb2::itemaction(&cv_dummyprofilekickstart), 0, 0}, {IT_STRING | IT_CVAR, "Lite Steer", "Hold DOWN on d-pad/keyboard for shallow turns.", - NULL, {.cvar = &cv_dummyprofilelitesteer}, 0, 0}, + NULL, srb2::itemaction(&cv_dummyprofilelitesteer), 0, 0}, {IT_STRING | IT_CVAR, "Strict Fastfall", "Fastfall only with the Spindash button.", - NULL, {.cvar = &cv_dummyprofilestrictfastfall}, 0, 0}, + NULL, srb2::itemaction(&cv_dummyprofilestrictfastfall), 0, 0}, {IT_STRING | IT_CVAR, "Field of View", "Higher FOV lets you see more.", - NULL, {.cvar = &cv_dummyprofilefov}, 0, 0}, + NULL, srb2::itemaction(&cv_dummyprofilefov), 0, 0}, {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, @@ -127,19 +127,19 @@ menuitem_t OPTIONS_ProfileAccessibility[] = { NULL, {NULL}, 0, 0}, {IT_STRING | IT_CVAR, "Minimum Input Delay", "Practice for online play! 0 = instant response.", - NULL, {.cvar = &cv_mindelay}, 0, 0}, + NULL, srb2::itemaction(&cv_mindelay), 0, 0}, {IT_STRING | IT_CVAR, "Screen Tilting", "View rotation on inclines.", - NULL, {.cvar = &cv_tilting}, 0, 0}, + NULL, srb2::itemaction(&cv_tilting), 0, 0}, {IT_STRING | IT_CVAR, "Reduce Effects", "If overwhelmed, hide less-important particle cues.", - NULL, {.cvar = &cv_reducevfx}, 0, 0}, + NULL, srb2::itemaction(&cv_reducevfx), 0, 0}, {IT_STRING | IT_CVAR, "Screenshake", "Adjust shake intensity from hazards and offroad.", - NULL, {.cvar = &cv_screenshake}, 0, 0}, + NULL, srb2::itemaction(&cv_screenshake), 0, 0}, {IT_STRING | IT_CVAR, "Input Display", "Show virtual controller on the HUD.", - NULL, {.cvar = &cv_drawinput}, 0, 0}, + NULL, srb2::itemaction(&cv_drawinput), 0, 0}, }; menu_t OPTIONS_ProfileAccessibilityDef = { diff --git a/src/menus/options-sound.cpp b/src/menus/options-sound.cpp index 35dc448ac..6b1053e0c 100644 --- a/src/menus/options-sound.cpp +++ b/src/menus/options-sound.cpp @@ -285,16 +285,16 @@ menuitem_t OPTIONS_Sound[] = { {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "Volume", "Loudness of all game audio.", - NULL, {.routine = slider_routine}, 0, Slider::kMasterVolume}, + NULL, srb2::itemaction(slider_routine), 0, Slider::kMasterVolume}, {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "SFX Volume", "Loudness of sound effects.", - NULL, {.routine = slider_routine}, 0, Slider::kSfxVolume}, + NULL, srb2::itemaction(slider_routine), 0, Slider::kSfxVolume}, {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "Music Volume", "Loudness of music.", - NULL, {.routine = slider_routine}, 0, Slider::kMusicVolume}, + NULL, srb2::itemaction(slider_routine), 0, Slider::kMusicVolume}, {IT_STRING | IT_ARROWS | IT_CV_SLIDER, "Voice Volume", "Loudness of voice chat.", - NULL, {.routine = slider_routine}, 0, Slider::kVoiceVolume}, + NULL, srb2::itemaction(slider_routine), 0, Slider::kVoiceVolume}, {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, @@ -303,19 +303,19 @@ menuitem_t OPTIONS_Sound[] = NULL, {NULL}, 0, 0}, {IT_STRING | IT_CVAR, "Chat Notifications", "Play a sound effect when chat messages appear.", - NULL, {.cvar = &cv_chatnotifications}, 0, 0}, + NULL, srb2::itemaction(&cv_chatnotifications), 0, 0}, {IT_STRING | IT_CVAR, "Character Voices", "Characters speak when interacting on the course.", - NULL, {.cvar = &cv_kartvoices}, 0, 0}, + NULL, srb2::itemaction(&cv_kartvoices), 0, 0}, {IT_STRING | IT_CVAR, "Follower Horns", NULL, // set in init_routine - NULL, {.cvar = &cv_karthorns}, 0, 0}, + NULL, srb2::itemaction(&cv_karthorns), 0, 0}, {IT_STRING | IT_CVAR, "Continuous Attack Music", "Keep music playing seamlessly when retrying in Attack modes.", - NULL, {.cvar = &cv_continuousmusic}, 0, 0}, + NULL, srb2::itemaction(&cv_continuousmusic), 0, 0}, {IT_STRING | IT_CVAR, "Streamer-Safe Music", "Only play music safe for video platforms.", - NULL, {.cvar = &cv_streamersafemusic}, 0, 0}, + NULL, srb2::itemaction(&cv_streamersafemusic), 0, 0}, {IT_SPACE | IT_DYBIGSPACE, NULL, NULL, NULL, {NULL}, 0, 0}, @@ -324,16 +324,16 @@ menuitem_t OPTIONS_Sound[] = NULL, {NULL}, 0, 0}, {IT_STRING | IT_CVAR, "Hear Tabbed-out", "Keep playing game audio when the window is out of focus (FOCUS LOST).", - NULL, {.cvar = &cv_bgaudio}, 0, 0}, + NULL, srb2::itemaction(&cv_bgaudio), 0, 0}, {IT_STRING | IT_CVAR, "Mixing Buffer Size", "Audio buffer size. Higher is faster but more delay.", - NULL, {.cvar = &cv_soundmixingbuffersize}, 0, 0}, + NULL, srb2::itemaction(&cv_soundmixingbuffersize), 0, 0}, {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, {IT_STRING | IT_CALL, "\x85" "Restart Audio", "Reboot the game's audio system.", - NULL, {.routine = restartaudio_routine}, 0, 0}, + NULL, srb2::itemaction(restartaudio_routine), 0, 0}, }; menu_t OPTIONS_SoundDef = { diff --git a/src/menus/options-voice.cpp b/src/menus/options-voice.cpp index bbb512943..d69cd6520 100644 --- a/src/menus/options-voice.cpp +++ b/src/menus/options-voice.cpp @@ -17,25 +17,25 @@ menuitem_t OPTIONS_Voice[] = { {IT_STRING | IT_CVAR, "Mute Self", "Whether your voice is transmitted or not.", - NULL, {.cvar = &cv_voice_selfmute}, 0, 0}, + NULL, srb2::itemaction(&cv_voice_selfmute), 0, 0 }, {IT_STRING | IT_CVAR, "Deafen Self", "Choose to opt-in to voice chat at all, for yourself.", - NULL, {.cvar = &cv_voice_selfdeafen}, 0, 0}, + NULL, srb2::itemaction(&cv_voice_selfdeafen), 0, 0}, {IT_STRING | IT_CVAR, "Input Mode", "When to transmit your own voice.", - NULL, {.cvar = &cv_voice_mode}, 0, 0}, + NULL, srb2::itemaction(&cv_voice_mode), 0, 0}, {IT_STRING | IT_CVAR, "Input Amplifier", "Amplify your voice, in decibels. Negative values are quieter.", - NULL, {.cvar = &cv_voice_inputamp}, 0, 0}, + NULL, srb2::itemaction(&cv_voice_inputamp), 0, 0}, {IT_STRING | IT_CVAR, "Input Noise Suppression", "Suppress background noise from your voice.", NULL, {.cvar = &cv_voice_denoise}, 0, 0}, {IT_STRING | IT_CVAR, "Input Sensitivity", "Voice higher than this threshold will transmit, in decibels.", - NULL, {.cvar = &cv_voice_activationthreshold}, 0, 0}, + NULL, srb2::itemaction(&cv_voice_activationthreshold), 0, 0 }, {IT_STRING | IT_CVAR, "Voice Loopback", "Play your own voice back simultaneously.", - NULL, {.cvar = &cv_voice_loopback}, 0, 0}, + NULL, srb2::itemaction(&cv_voice_loopback), 0, 0 }, {IT_SPACE | IT_NOTHING, NULL, NULL, NULL, {NULL}, 0, 0}, @@ -44,10 +44,10 @@ menuitem_t OPTIONS_Voice[] = NULL, {NULL}, 0, 0}, {IT_STRING | IT_CVAR, "Server Voice Chat", "All voice chat will be enabled on your server.", - NULL, {.cvar = &cv_voice_allowservervoice}, 0, 0}, + NULL, srb2::itemaction(&cv_voice_allowservervoice), 0, 0 }, {IT_STRING | IT_CVAR, "Proximity Effects", "Player voices will be adjusted relative to you.", - NULL, {.cvar = &cv_voice_proximity}, 0, 0}, + NULL, srb2::itemaction(&cv_voice_proximity), 0, 0 }, }; static void draw_routine() diff --git a/src/menus/transient/pause-addonoptions.cpp b/src/menus/transient/pause-addonoptions.cpp index 5b7c11896..8737f03ad 100644 --- a/src/menus/transient/pause-addonoptions.cpp +++ b/src/menus/transient/pause-addonoptions.cpp @@ -97,7 +97,7 @@ void list_cvars() height += 16; } - g_menu.push_back(menuitem_t {status, var->name, var->description, nullptr, {.cvar = var}, 0, height}); + g_menu.push_back(menuitem_t{ status, var->name, var->description, nullptr, srb2::itemaction(var), 0, height }); } } @@ -146,7 +146,7 @@ void list_commands() if (flags & COM_NOSHOWHELP) continue; - g_menu.push_back(menuitem_t {IT_STRING | IT_CALL, cmd->name, "No information available for commands. Press to execute.", nullptr, {.routine = call}, 0, 8}); + g_menu.push_back(menuitem_t{ IT_STRING | IT_CALL, cmd->name, "No information available for commands. Press to execute.", nullptr, srb2::itemaction(call), 0, 8 }); } } diff --git a/src/menus/transient/pause-cheats.cpp b/src/menus/transient/pause-cheats.cpp index 5dc70fc39..b416207b4 100644 --- a/src/menus/transient/pause-cheats.cpp +++ b/src/menus/transient/pause-cheats.cpp @@ -79,7 +79,7 @@ void list_cvars() height += 16; } - g_menu.push_back(menuitem_t {status, var->name, var->description, nullptr, {.cvar = var}, 0, height}); + g_menu.push_back(menuitem_t {status, var->name, var->description, nullptr, srb2::itemaction(var), 0, height}); } } @@ -94,7 +94,7 @@ void list_commands() continue; } - g_menu.push_back(menuitem_t {IT_STRING | IT_CALL, cmd->name, nullptr, nullptr, {.routine = call}, 0, 8}); + g_menu.push_back(menuitem_t {IT_STRING | IT_CALL, cmd->name, nullptr, nullptr, srb2::itemaction(call), 0, 8}); } } diff --git a/src/objects/battle-ufo.cpp b/src/objects/battle-ufo.cpp index ca56f0a18..2e94d36d6 100644 --- a/src/objects/battle-ufo.cpp +++ b/src/objects/battle-ufo.cpp @@ -31,7 +31,7 @@ using srb2::math::Fixed; using srb2::Mobj; using srb2::MobjList; -extern consvar_t cv_battleufotest; +extern "C" consvar_t cv_battleufotest; extern mobj_t* svg_battleUfoSpawners; @@ -132,7 +132,7 @@ public: Spawner* spawner = next(g_battleufo.previousId); UFO* ufo = static_cast(P_SpawnMobjFromMobj(spawner, 0, 0, 250*FRACUNIT - ofs, MT_BATTLEUFO)); - + K_AddMessage("Crack the Combat UFO!", true, false); S_StartSound(NULL, sfx_mbs54); @@ -291,4 +291,4 @@ INT32 Obj_BattleUFOSpawnerID(const mobj_t *spawner) mobj_t *Obj_GetNextUFOSpawner(void) { return g_spawners.next(g_battleufo.previousId); -} \ No newline at end of file +} diff --git a/src/objects/checkpoint.cpp b/src/objects/checkpoint.cpp index 507d23aa1..432d31f86 100644 --- a/src/objects/checkpoint.cpp +++ b/src/objects/checkpoint.cpp @@ -59,18 +59,24 @@ namespace struct LineOnDemand : line_t { +private: + vertex_t v1_data_; + +public: LineOnDemand(const line_t* line) {} LineOnDemand(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2) : - line_t { - .v1 = &v1_data_, - .dx = x2 - x1, - .dy = y2 - y1, - .bbox = {max(y1, y2), min(y1, y2), min(x1, x2), max(x1, x2)}, - }, - v1_data_ {.x = x1, .y = y1} + line_t {}, + v1_data_{ x1, y1 } { - } + v1 = &v1_data_; + dx = x2 - x1; + dy = y2 - y1; + bbox[0] = max(y1, y2); + bbox[1] = min(y1, y2); + bbox[2] = min(x1, x2); + bbox[3] = max(x1, x2); + }; LineOnDemand(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, fixed_t r) : LineOnDemand(x1, y1, x2, y2) { @@ -91,9 +97,6 @@ struct LineOnDemand : line_t return bbox[BOXTOP] >= other.bbox[BOXBOTTOM] && bbox[BOXBOTTOM] <= other.bbox[BOXTOP] && bbox[BOXLEFT] <= other.bbox[BOXRIGHT] && bbox[BOXRIGHT] >= other.bbox[BOXLEFT]; } - -private: - vertex_t v1_data_; }; struct Checkpoint : mobj_t diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 2d610b0b1..ee8b8a9b2 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -7606,6 +7606,8 @@ void P_SetupLevelSky(const char *skytexname, boolean global) static const char *maplumpname; lumpnum_t lastloadedmaplumpnum; // for comparative savegame +extern "C" boolean blockreset; + // // P_LevelInitStuff // @@ -7618,7 +7620,6 @@ static void P_InitLevelSettings(void) leveltime = 0; modulothing = 0; - extern boolean blockreset; blockreset = 0; P_SetFreezeLevel(false); diff --git a/src/r_things.cpp b/src/r_things.cpp index ff616d6f5..7e608da9c 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1686,7 +1686,7 @@ static void R_ProjectBoundingBox(mobj_t *thing, vissprite_t *vis) fixed_t R_GetSpriteDirectionalLighting(angle_t angle) { // Copied from P_UpdateSegLightOffset - const UINT8 contrast = std::min(std::max(0, maplighting.contrast - maplighting.backlight), UINT8_MAX); + const UINT8 contrast = std::min(std::max(0, maplighting.contrast - maplighting.backlight), UINT8_MAX); const fixed_t contrastFixed = ((fixed_t)contrast) * FRACUNIT; fixed_t light = FRACUNIT; diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 8c5bde549..d6f32a67c 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -83,9 +83,9 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES Windows) target_link_libraries(SRB2SDL2 PRIVATE ws2_32 ) - target_compile_options(SRB2SDL2 PRIVATE - -U_WINDOWS - ) + # target_compile_options(SRB2SDL2 PRIVATE + # -U_WINDOWS + # ) endif() target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXER -DSOUND=SOUND_MIXER) diff --git a/src/sdl/i_main.cpp b/src/sdl/i_main.cpp index 827d6314b..e4bbbb894 100644 --- a/src/sdl/i_main.cpp +++ b/src/sdl/i_main.cpp @@ -195,7 +195,7 @@ static void InitLogging(void) } #endif -#ifdef _WIN32 +#if defined(_WIN32) && !defined(_MSC_VER) static void init_exchndl() { HMODULE exchndl_module = LoadLibraryA("exchndl.dll"); @@ -212,6 +212,10 @@ static void init_exchndl() if (pfnExcHndlInit != NULL) (pfnExcHndlInit)(); } +#else +static void init_exchndl() +{ +} #endif #ifdef _WIN32 @@ -351,6 +355,13 @@ int main(int argc, char **argv) #endif +#ifdef _MSC_VER +int WINAPI WinMain(HINSTANCE pInstance, HINSTANCE pPrevInstance, LPSTR lpCmdLine, int nShowCmd) +{ + return main(__argc, __argv); +} +#endif + void* operator new(size_t count) { auto p = malloc(count); diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 4014e980c..31115219c 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -29,6 +29,7 @@ #include #ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN #define RPC_NO_WINDOWS_H #include #include "../doomtype.h" @@ -1729,6 +1730,8 @@ static INT32 errorcount = 0; */ static boolean shutdowning = false; +extern "C" consvar_t cv_fuzz; + void I_Error(const char *error, ...) { va_list argptr; @@ -1813,7 +1816,6 @@ void I_Error(const char *error, ...) I_ShutdownGraphics(); I_ShutdownInput(); - extern consvar_t cv_fuzz; if (!cv_fuzz.value) I_ShowErrorMessageBox(buffer, false); @@ -1974,7 +1976,7 @@ void I_GetDiskFreeSpace(INT64 *freespace) if (!testwin95) { - *(void**)&pfnGetDiskFreeSpaceEx = FUNCPTRCAST(GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetDiskFreeSpaceExA")); + pfnGetDiskFreeSpaceEx = reinterpret_cast(GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetDiskFreeSpaceExA")); testwin95 = true; } if (pfnGetDiskFreeSpaceEx) diff --git a/src/sdl/i_video.cpp b/src/sdl/i_video.cpp index de95734af..4cac6d48d 100644 --- a/src/sdl/i_video.cpp +++ b/src/sdl/i_video.cpp @@ -34,6 +34,8 @@ #include "SDL.h" #ifdef _MSC_VER +#define WIN32_LEAN_AND_MEAN +#define RPC_NO_WINDOWS_H #include #pragma warning(default : 4214 4244) #endif @@ -348,9 +350,10 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) return 0; } +extern "C" consvar_t cv_alwaysgrabmouse; + static boolean IgnoreMouse(void) { - extern consvar_t cv_alwaysgrabmouse; if (cv_alwaysgrabmouse.value) return false; if (menuactive) @@ -1517,6 +1520,8 @@ static void Impl_VideoSetupBuffer(void) } } +extern "C" CVarList* cvlist_graphics_driver; + void I_StartupGraphics(void) { if (dedicated) @@ -1531,10 +1536,7 @@ void I_StartupGraphics(void) COM_AddCommand ("vid_info", VID_Command_Info_f); COM_AddCommand ("vid_modelist", VID_Command_ModeList_f); COM_AddCommand ("vid_mode", VID_Command_Mode_f); - { - extern CVarList *cvlist_graphics_driver; - CV_RegisterList(cvlist_graphics_driver); - } + CV_RegisterList(cvlist_graphics_driver); disable_mouse = static_cast(M_CheckParm("-nomouse")); disable_fullscreen = M_CheckParm("-win") ? SDL_TRUE : SDL_FALSE; diff --git a/src/st_stuff.c b/src/st_stuff.c index f942c23ce..8862947ac 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -1380,11 +1380,11 @@ static INT32 ST_ServerSplash_OpacityFlag(INT32 opacity) return (NUMTRANSMAPS - opacity) << V_ALPHASHIFT; } +#define SPLASH_LEN ((FRACUNIT * TICRATE) * 3) +#define SPLASH_WAIT ((FRACUNIT * TICRATE) / 2) + void ST_DrawServerSplash(boolean timelimited) { - static const fixed_t SPLASH_LEN = (FRACUNIT * TICRATE) * 3; - static const fixed_t SPLASH_WAIT = (FRACUNIT * TICRATE) / 2; - static fixed_t splashTime = -SPLASH_WAIT; static char prevContext[8] = {0}; diff --git a/src/v_video.cpp b/src/v_video.cpp index d47125972..dac9cfcbe 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -61,8 +61,10 @@ UINT8 *screens[5]; #define huecoloursteps 4 +extern "C" CV_PossibleValue_t hue_cons_t[]; CV_PossibleValue_t hue_cons_t[] = {{0, "MIN"}, {(huecoloursteps*6)-1, "MAX"}, {0, NULL}}; +extern "C" CV_PossibleValue_t constextsize_cons_t[]; CV_PossibleValue_t constextsize_cons_t[] = { {V_NOSCALEPATCH, "Small"}, {V_SMALLSCALEPATCH, "Medium"}, {V_MEDSCALEPATCH, "Large"}, {0, "Huge"}, {0, NULL}}; diff --git a/src/win32/Srb2win.rc b/src/win32/Srb2win.rc index befa01d70..69dd90b5c 100644 --- a/src/win32/Srb2win.rc +++ b/src/win32/Srb2win.rc @@ -1,4 +1,4 @@ -#include +#include //Microsoft Developer Studio generated resource script. // @@ -75,11 +75,9 @@ END // Version // -#include "../doomdef.h" // Needed for version string - VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,2,0,0 - PRODUCTVERSION 2,2,0,0 + FILEVERSION 2,4,0,0 + PRODUCTVERSION 2,4,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -97,14 +95,14 @@ BEGIN VALUE "Comments", "Go go-karting with Dr. Robotnik!\0" VALUE "CompanyName", "Kart Krew Dev\0" VALUE "FileDescription", "Dr. Robotnik's Ring Racers\0" - VALUE "FileVersion", VERSIONSTRING_RC + VALUE "FileVersion", "2.4" VALUE "InternalName", "ringracers\0" VALUE "LegalCopyright", "Copyright 2018-2024 Kart Krew Dev\0" VALUE "LegalTrademarks", "Dr. Robotnik and related characters are trademarks of Sega.\0" VALUE "OriginalFilename", "ringracers.exe\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "Dr. Robotnik's Ring Racers\0" - VALUE "ProductVersion", VERSIONSTRING_RC + VALUE "ProductVersion", "2.4" VALUE "SpecialBuild", "\0" END END diff --git a/src/y_inter.cpp b/src/y_inter.cpp index a613cf3ff..452a6850b 100644 --- a/src/y_inter.cpp +++ b/src/y_inter.cpp @@ -2516,6 +2516,8 @@ void Y_PlayIntermissionMusic(void) Music_Play("intermission"); } +extern "C" boolean blockreset; + // // Y_StartIntermission // @@ -2538,7 +2540,6 @@ void Y_StartIntermission(void) I_Error("endtic is dirty"); #endif - extern boolean blockreset; blockreset = false; // set player Power Level type