diff --git a/CMakeLists.txt b/CMakeLists.txt index b7d280190..1acd092bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,13 @@ cmake_minimum_required(VERSION 3.5) # Version change is fine. project(SRB2 VERSION 1.6 - LANGUAGES C) + LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +#set(CMAKE_CXX_EXTENSIONS OFF) # optional but recommended: disables GNU extensions, forces pure ISO C++ +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.") @@ -73,6 +79,7 @@ endif() # OS macros if (UNIX) add_definitions(-DUNIXCOMMON) + add_link_options(-rdynamic) # Use -rdynamic so a backtrace log shows function names endif() if(CMAKE_COMPILER_IS_GNUCC) diff --git a/README.md b/README.md index d538288bb..698f55a9c 100644 --- a/README.md +++ b/README.md @@ -22,14 +22,14 @@ We also have a Flatpak available on [Flathub](https://flathub.org/en/apps/org.sr See [SRB2 Wiki/Source code compiling](http://wiki.srb2.org/wiki/Source_code_compiling). The compiling process for SRB2Kart is largely identical to SRB2. -Currently only the Makefile build system with GCC or Clang compiler is supported. -CMake is NOT supported at the moment, but will be availible again soon. - +For Windows only the Makefile build system with GCC or Clang compiler is supported. Visual C++ (MSVC) is unsupported. 64-bit Windows builds are supported and recommended over 32-bit builds, they will build automatically when using the MSYS2 MinGW 64-bit executable (requires the mingw-w64-x86_64-gcc package), no extra flags needed! The specific DLLs can be found under /libs/dll-binaries/(i686 for 32bit/x86_64 for 64-bit)/ or in the Release packages +MacOS and Linux can be build with CMake, but it is recommended to use the Makefile for Linux over CMake + Alternatively the [srb2bld](https://github.com/Bijman/srb2bld) script by Bijman can be used aswell! ## Disclaimer diff --git a/assets/CMakeLists.txt b/assets/CMakeLists.txt index 12be1c470..a34cf2dfc 100644 --- a/assets/CMakeLists.txt +++ b/assets/CMakeLists.txt @@ -1,5 +1,10 @@ ## Assets Target Configuration ## +if(${CMAKE_SYSTEM} MATCHES Linux) + # Asset installation isn't part of the Linux target + return() +endif() + # For prepending the current source path, later FUNCTION(PREPEND var prefix) SET(listVar "") diff --git a/cmake/Modules/Findlibbacktrace.cmake b/cmake/Modules/Findlibbacktrace.cmake new file mode 100644 index 000000000..81ebeb9dc --- /dev/null +++ b/cmake/Modules/Findlibbacktrace.cmake @@ -0,0 +1,33 @@ +include(LibFindMacros) + +libfind_pkg_check_modules(LIBBACKTRACE_PKGCONF LIBBACKTRACE) + +find_path(LIBBACKTRACE_INCLUDE_DIR + NAMES backtrace.h + PATHS + ${LIBBACKTRACE_PKGCONF_INCLUDE_DIRS} + "/usr/include" + "/usr/local/include" +) + +find_library(LIBBACKTRACE_LIBRARY + NAMES backtrace + PATHS + ${LIBBACKTRACE_PKGCONF_LIBRARY_DIRS} + "/usr/lib" + "/usr/local/lib" +) + +set(LIBBACKTRACE_PROCESS_INCLUDES LIBBACKTRACE_INCLUDE_DIR) +set(LIBBACKTRACE_PROCESS_LIBS LIBBACKTRACE_LIBRARY) +libfind_process(LIBBACKTRACE) + +if(LIBBACKTRACE_FOUND AND NOT TARGET libbacktrace) + add_library(libbacktrace UNKNOWN IMPORTED) + set_target_properties( + libbacktrace + PROPERTIES + IMPORTED_LOCATION "${LIBBACKTRACE_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBBACKTRACE_INCLUDE_DIR}" + ) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 361386622..f09b95633 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,8 @@ # Core sources set(SRB2_CORE_SOURCES + core/memory.cpp + core/thread_pool.cpp am_map.c b_bot.c command.c @@ -18,17 +20,21 @@ set(SRB2_CORE_SOURCES f_wipe.c filesrch.c g_game.c + g_demo.c g_input.c hu_stuff.c i_tcp.c info.c + k_hud.c lzf.c m_aatree.c m_anigif.c m_argv.c m_bbox.c m_cheat.c + m_curl.c m_cond.c + m_emotes.cpp m_fixed.c m_menu.c m_textinput.c @@ -40,19 +46,25 @@ set(SRB2_CORE_SOURCES mserv.c http-mserv.c qs22j.c + r_skins.c s_sound.c screen.c sounds.c st_stuff.c - #string.c + string.c tables.c v_video.c w_wad.c y_inter.c - z_zone.c + z_zone.cpp ) set(SRB2_CORE_HEADERS + core/memory.h + core/thread_pool.h + m_curl.h + m_emotes.h + k_hud.h am_map.h b_bot.h byteptr.h @@ -78,6 +90,7 @@ set(SRB2_CORE_HEADERS fastcmp.h filesrch.h g_game.h + g_demo.h g_input.h g_state.h hu_stuff.h @@ -109,6 +122,7 @@ set(SRB2_CORE_HEADERS md5.h mserv.h qs22j.h + r_skins.h s_sound.h screen.h sounds.h @@ -123,18 +137,18 @@ set(SRB2_CORE_HEADERS ) set(SRB2_CORE_RENDER_SOURCES - r_bsp.c + r_bsp.cpp r_data.c - r_draw.c - r_fps.c - r_main.c - r_patch.c - r_patchrotation.c - r_plane.c - r_segs.c + r_draw.cpp + r_fps.cpp + r_main.cpp + r_patch.cpp + r_patchrotation.cpp + r_plane.cpp + r_segs.cpp r_sky.c r_splats.c - r_things.c + r_things.cpp r_portal.c r_bsp.h @@ -162,7 +176,7 @@ set(SRB2_CORE_GAME_SOURCES p_inter.c p_lights.c p_map.c - p_maputl.c + p_maputl.cpp p_mobj.c p_polyobj.c p_saveg.c @@ -193,10 +207,6 @@ set(SRB2_CORE_GAME_SOURCES k_stats.h ) -if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) -endif() - prepend_sources(SRB2_CORE_SOURCES) prepend_sources(SRB2_CORE_HEADERS) prepend_sources(SRB2_CORE_RENDER_SOURCES) @@ -226,11 +236,19 @@ 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_USE_FBO_OGL ON CACHE BOOL - "Enable OpenGL FBO Downsampling support.") +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_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") + if(${SRB2_CONFIG_DEDICATED}) set(SRB2_CONFIG_HAVE_GME NO) set(SRB2_CONFIG_HAVE_OPENMPT NO) @@ -469,16 +487,37 @@ if(${SRB2_CONFIG_HAVE_CURL}) endif() endif() +if(${SRB2_CONFIG_LIBBACKTRACE}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(LIBBACKTRACE_FOUND ON) + set(LIBBACKTRACE_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libbacktrace/include) + set(LIBBACKTRACE_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libbacktrace/lib/x86_64 -lbacktrace") + else() # 32-bit + message(WARNING "libbacktrace is unsupported on 32-bit builds.") + endif() + else() + find_package(libbacktrace) + endif() + 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() +endif() + if(${SRB2_CONFIG_HWRENDER}) add_definitions(-DHWRENDER) set(SRB2_HWRENDER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_portal.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c @@ -493,7 +532,6 @@ if(${SRB2_CONFIG_HWRENDER}) ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_gl.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h @@ -525,24 +563,31 @@ if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) endif() endif() -if(${SRB2_CONFIG_HWRENDER}) - if(${SRB2_CONFIG_USE_FBO_OGL}) - set(SRB2_USE_FBO_OGL ON) - add_definitions(-DUSE_FBO_OGL) - endif() +if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_SCREENFBO}) + add_definitions(-DUSE_FBO_OGL) +endif() + +if(${SRB2_CONFIG_SATURNPAK}) + add_definitions(-DDOSATURNPAK) +endif() + +if(${SRB2_CONFIG_SATURNJOIN}) + add_definitions(-DDOSATURNJOIN) endif() # Targets # Compatibility flag with later versions of GCC # We should really fix our code to not need this -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|x64|amd64|AMD64|em64t|EM64T)") + add_compile_options(-mno-ms-bitfields) + endif() + add_compile_options(-Wno-trigraphs) endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) -endif() +# TODO: fix prng and P_CreateBlockmap overflow at some point +add_compile_options(-fwrapv) add_definitions(-DCMAKECONFIG) diff --git a/src/Makefile.d/detect.mk b/src/Makefile.d/detect.mk index 7ff978397..0816c5a03 100644 --- a/src/Makefile.d/detect.mk +++ b/src/Makefile.d/detect.mk @@ -66,7 +66,7 @@ endif gcc_versions:=\ 152 151 150 15\ 142 141 140 14\ - 132 131 130 13\ + 133 132 131 130 13\ 123 122 121 120 12\ 114 113 112 111 110 11\ 105 104 103 102 101 100 10\ diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk index e57119fb9..c3989bb4f 100644 --- a/src/Makefile.d/versions.mk +++ b/src/Makefile.d/versions.mk @@ -20,7 +20,10 @@ $(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\ CXXFLAGS+= -Wno-aggregate-return # -W -Wno-unused -WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference -Wzero-as-null-pointer-constant +WFLAGS:=-Wall -Wno-trigraphs -Wnull-dereference +ifdef GCC152 +WFLAGS+=-Wzero-as-null-pointer-constant +endif ifndef GCC295 #WFLAGS+=-Wno-packed endif diff --git a/src/command.h b/src/command.h index 7074158e1..d3bf09127 100644 --- a/src/command.h +++ b/src/command.h @@ -13,13 +13,13 @@ #ifndef __COMMAND_H__ #define __COMMAND_H__ +#include +#include "doomdef.h" + #ifdef __cplusplus extern "C" { #endif -#include -#include "doomdef.h" - //=================================== // Command buffer & command execution //=================================== diff --git a/src/config.h.in b/src/config.h.in index 5225c8b0b..4028ef2f0 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -11,21 +11,6 @@ #ifdef CMAKECONFIG -// Base SRB2 hashes -#define ASSET_HASH_SRB2_SRB "${SRB2_ASSET_srb2.srb_HASH}" -#ifdef USE_PATCH_DTA -#define ASSET_HASH_PATCH_DTA "${SRB2_ASSET_patch.dta_HASH}" -#endif - -// SRB2Kart-specific hashes -#define ASSET_HASH_GFX_KART "${SRB2_ASSET_gfx.kart_HASH}" -#define ASSET_HASH_TEXTURES_KART "${SRB2_ASSET_textures.kart_HASH}" -#define ASSET_HASH_CHARS_KART "${SRB2_ASSET_chars.kart_HASH}" -#define ASSET_HASH_MAPS_KART "${SRB2_ASSET_maps.kart_HASH}" -#ifdef USE_PATCH_KART -#define ASSET_HASH_PATCH_KART "00000000000000000000000000000000" -#endif - #define SRB2_COMP_REVISION "${SRB2_COMP_REVISION}" #define SRB2_COMP_BRANCH "${SRB2_COMP_BRANCH}" @@ -33,30 +18,10 @@ #else -/* Manually defined asset hashes for non-CMake builds - * Last updated 2015 / 05 / 03 - SRB2 v2.1.15 - srb2.srb - * Last updated 2018 / 12 / 23 - SRB2 v2.1.22 - patch.dta - * Last updated 2019 / 01 / 18 - Kart v1.0.2 - Main assets - * Last updated 2020 / 08 / 30 - Kart v1.3 - patch.kart - * Last updated 2022 / 08 / 16 - Kart v1.4 - Main assets - * Last updated 2022 / 08 / 19 - Kart v1.5 - gfx.kart - * Last updated 2022 / 11 / 01 - Kart v1.6 - gfx.kart, maps.kart - */ +#define SRB2_COMP_REVISION "" +#define SRB2_COMP_BRANCH "" -// Base SRB2 hashes -#define ASSET_HASH_SRB2_SRB "c1b9577687f8a795104aef4600720ea7" -#ifdef USE_PATCH_DTA -#define ASSET_HASH_PATCH_DTA "b04fd9624bfd94dc96dcf4f400f7deb4" -#endif - -// SRB2Kart-specific hashes -#define ASSET_HASH_GFX_KART "06f86ee16136eb8a7043b15001797034" -#define ASSET_HASH_TEXTURES_KART "abb53d56aba47c3a8cb0f764da1c8b80" -#define ASSET_HASH_CHARS_KART "e2c428347dde52858a3dacd29fc5b964" -#define ASSET_HASH_MAPS_KART "d051e55141ba736582228c456953cd98" -#ifdef USE_PATCH_KART -#define ASSET_HASH_PATCH_KART "00000000000000000000000000000000" -#endif +#define CMAKE_ASSETS_DIR "" #endif #endif diff --git a/src/d_main.c b/src/d_main.c index 3e474cec3..c5499fb57 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -80,6 +80,31 @@ #include "lua_script.h" +/* Manually defined asset hashes for non-CMake builds + * Last updated 2015 / 05 / 03 - SRB2 v2.1.15 - srb2.srb + * Last updated 2018 / 12 / 23 - SRB2 v2.1.22 - patch.dta + * Last updated 2019 / 01 / 18 - Kart v1.0.2 - Main assets + * Last updated 2020 / 08 / 30 - Kart v1.3 - patch.kart + * Last updated 2022 / 08 / 16 - Kart v1.4 - Main assets + * Last updated 2022 / 08 / 19 - Kart v1.5 - gfx.kart + * Last updated 2022 / 11 / 01 - Kart v1.6 - gfx.kart, maps.kart + */ + +// Base SRB2 hashes +#define ASSET_HASH_SRB2_SRB "c1b9577687f8a795104aef4600720ea7" +#ifdef USE_PATCH_DTA +#define ASSET_HASH_PATCH_DTA "b04fd9624bfd94dc96dcf4f400f7deb4" +#endif + +// SRB2Kart-specific hashes +#define ASSET_HASH_GFX_KART "06f86ee16136eb8a7043b15001797034" +#define ASSET_HASH_TEXTURES_KART "abb53d56aba47c3a8cb0f764da1c8b80" +#define ASSET_HASH_CHARS_KART "e2c428347dde52858a3dacd29fc5b964" +#define ASSET_HASH_MAPS_KART "d051e55141ba736582228c456953cd98" +#ifdef USE_PATCH_KART +#define ASSET_HASH_PATCH_KART "00000000000000000000000000000000" +#endif + #ifdef CMAKECONFIG #include "config.h" #else @@ -946,6 +971,9 @@ void D_ClearState(void) // void D_StartTitle(void) { + if (dedicated) + I_Error("D_StartTitle is called on dedicated server"); + D_ClearState(); multiplayer = netgame = false; // title menu shouldnt be a netgame or multiplayer lmao F_StartTitleScreen(); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index e9f814857..6b92c86db 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -54,6 +54,9 @@ #include "fastcmp.h" #include "m_perfstats.h" +#include "r_data.h" +#include "r_skins.h" + #ifdef NETGAME_DEVMODE #define CV_RESTRICT CV_NETVAR #else diff --git a/src/d_netfil.c b/src/d_netfil.c index 12f19dde2..67fd28a82 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -131,6 +131,8 @@ static UINT32 curl_origtotalfilesize; static char *curl_realname = NULL; fileneeded_t *curl_curfile = NULL; HTTP_login *curl_logins = NULL; + +static void CURLGetFile(void); #endif /** Fills a serverinfo packet with information about wad files loaded. @@ -1305,6 +1307,7 @@ void CURLPrepareFile(const char* url, int dfilenum) if (!multi_handle) { cc = curl_global_init(CURL_GLOBAL_ALL); + if (cc < 0) { I_OutputMsg("libcurl: curl_global_init() returned %d\n", cc); @@ -1313,6 +1316,7 @@ void CURLPrepareFile(const char* url, int dfilenum) { multi_handle = curl_multi_init(); } + if (!multi_handle) { I_OutputMsg("libcurl: curl_multi_init() failed\n"); @@ -1441,7 +1445,7 @@ void CURLAbortFile(void) #endif } -void CURLGetFile(void) +static void CURLGetFile(void) { #ifdef HAVE_THREADS I_lock_mutex(&downloadmutex); @@ -1483,7 +1487,8 @@ void CURLGetFile(void) e = m->easy_handle; easyres = m->data.result; - char *filename = Z_StrDup(curl_realname); + char *filename = malloc(strlen(curl_realname)+1); + strcpy(filename, curl_realname); nameonly(filename); if (easyres != CURLE_OK) @@ -1521,7 +1526,7 @@ void CURLGetFile(void) } } - Z_Free(filename); + free(filename); curl_curfile->file = NULL; filedownload.remaining--; mc = curl_multi_remove_handle(multi_handle, e); diff --git a/src/d_netfil.h b/src/d_netfil.h index 3c7502451..268cd80be 100644 --- a/src/d_netfil.h +++ b/src/d_netfil.h @@ -119,7 +119,6 @@ size_t nameonlylength(const char *s); #ifdef HAVE_CURL void CURLPrepareFile(const char* url, int dfilenum); void CURLAbortFile(void); -void CURLGetFile(void); HTTP_login * CURLGetLogin (const char *url, HTTP_login ***return_prev_next); size_t curlwrite_data(void *ptr, size_t size, size_t nmemb, FILE *stream); #endif diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 4d52ffa70..437439010 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -180,10 +180,6 @@ static char returnWadPath[256]; #include "../m_argv.h" -#ifdef MAC_ALERT -#include "macosx/mac_alert.h" -#endif - #include "../d_main.h" #if !defined(NOMUMBLE) && defined(HAVE_MUMBLE) diff --git a/src/doomdef.h b/src/doomdef.h index 492fa1185..23768d0f4 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -40,22 +40,45 @@ #define ASMCALL #endif -#ifdef __cplusplus -extern "C" { -#endif - #include "doomtype.h" +#ifdef __cplusplus /* Only when compiled as C++ */ + #include /* std::min, std::max, std::sort, … */ +#endif + +#ifdef __cplusplus +// Force libc++ to expose std::min/std::max even when is included first (Apple clang quirk) +#ifndef _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES +#define _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES +#endif +#ifndef _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS +#endif + +// Optional: only try if it actually exists (newer Xcode) +#if __has_include() +#include +#endif + +#define _USE_MATH_DEFINES +#include +#include +#include +#include +#include +#include +#include + +extern "C" { +#else +#include #include #include #include +#include #include -#define _USE_MATH_DEFINES // fixes M_PI errors in r_plane.c for Visual Studio -#ifdef __cplusplus -#include -#else -#include +#include #endif #include diff --git a/src/g_input.c b/src/g_input.c index 0082df273..1a420c996 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -945,6 +945,8 @@ void G_SetPlayerGamepadIndicatorColor(INT32 playernum, UINT8 color) static void G_ResetPlayerGamepadIndicatorColor(INT32 playernum) { + I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); + if (cv_gamepadled[playernum].value == 0) { I_SetGamepadIndicatorColor(playernum, 0, 0, 255); @@ -973,13 +975,8 @@ void G_DeviceLEDTick(void) newcolor = G_GetSkinColorForGamepad(i); - // compiler be absolutely tripping - // delet this if this gets fixed within gcc -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Warray-bounds" if (curcolor[i] == newcolor) // dont update if same colour continue; -#pragma GCC diagnostic pop G_SetPlayerGamepadIndicatorColor(i, newcolor); curcolor[i] = newcolor; @@ -994,6 +991,7 @@ void G_ResetDeviceLED(void) static void G_ResetPlayerDeviceRumble(INT32 playernum) { + I_Assert(playernum >= 0 && playernum < MAXSPLITSCREENPLAYERS); I_GamepadRumble(playernum, 0, 0, 0); } diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h index 7e167485e..de5ac6338 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -80,6 +80,9 @@ UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable); void GL_ClearLightTables(void); void GL_SetScreenPalette(RGBA_t *palette); +void GL_Draw2DModel(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, + FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 1622a4528..24d3af8ae 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -101,7 +101,8 @@ sector_t *gl_backsector = NULL; static constexpr float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f}; // values for bsp culling // slightly higher than the far clipping plane to compensate for impreciseness -static constexpr INT32 bsp_culling_distances[] = {(1024+512)*FRACUNIT, (2048+512)*FRACUNIT, (4096+512)*FRACUNIT, +static constexpr INT32 bsp_culling_distances[] = { + (1024+512)*FRACUNIT, (2048+512)*FRACUNIT, (4096+512)*FRACUNIT, (6144+512)*FRACUNIT, (8192+512)*FRACUNIT, (12288+512)*FRACUNIT, (16384+512)*FRACUNIT}; // Performance stats @@ -587,15 +588,11 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool const sector_t *sec = FOFsector ? FOFsector : gl_frontsector; // Get the slope pointer to simplify future code - if (sec->f_slope && !isceiling) + if (!isceiling && sec->f_slope) slope = sec->f_slope; - else if (sec->c_slope && isceiling) + else if (isceiling && sec->c_slope) slope = sec->c_slope; - // Set fixedheight to the slope's height from our viewpoint, if we have a slope - if (slope) - fixedheight = P_GetSlopeZAt(slope, viewx, viewy); - height = FixedToFloat(fixedheight); // Allocate plane-vertex buffer if we need to @@ -687,18 +684,19 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool vert->s = (tempxsow * cosangf) - (tempytow * sinangf);\ vert->t = (tempxsow * sinangf) + (tempytow * cosangf);\ }\ +\ + if (slope)\ + {\ + fixedheight = P_GetSlopeZAt(slope, FloatToFixed((vx)), FloatToFixed((vy)));\ + height = FixedToFloat(fixedheight);\ + }\ \ vert->x = (vx);\ vert->y = height;\ vert->z = (vy);\ \ - if (slope)\ - {\ - fixedheight = P_GetSlopeZAt(slope, FloatToFixed((vx)), FloatToFixed((vy)));\ - vert->y = FixedToFloat(fixedheight);\ - }\ } - for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++,pv++) + for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++, pv++) SETUP3DVERT(v3d, pv->x, pv->y); if (slope) @@ -1785,10 +1783,10 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // Single sided line... Deal only with the middletexture (if one exists) if (gl_midtexture && gl_linedef->special != HORIZONSPECIAL) // Ignore horizon line for OGL { - glTex = HWR_GetTexture(gl_midtexture, noencore); - fixed_t texturevpeg; + glTex = HWR_GetTexture(gl_midtexture, noencore); + // PEGGING if ((gl_linedef->flags & (ML_DONTPEGBOTTOM|ML_EFFECT2)) == (ML_DONTPEGBOTTOM|ML_EFFECT2)) texturevpeg = gl_frontsector->floorheight + textureheight[gl_sidedef->midtexture] - gl_frontsector->ceilingheight + gl_sidedef->rowoffset; @@ -1875,8 +1873,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom //Hurdler: 3d-floors test if (!gl_drawing_stencil && gl_backsector && gl_frontsector->tag != gl_backsector->tag && (gl_backsector->ffloors || gl_frontsector->ffloors)) { - ffloor_t * rover; - fixed_t highcut = 0, lowcut = 0; + ffloor_t *rover; + fixed_t highcut = 0, lowcut = 0; fixed_t lowcutslope = 0, highcutslope = 0; // Used for height comparisons and etc across FOFs and slopes @@ -2947,7 +2945,7 @@ static void HWR_Subsector(size_t num) static sector_t tempsec; //SoM: 4/7/2000 INT32 floorlightlevel; INT32 ceilinglightlevel; - INT32 locFloorHeight, locCeilingHeight; + INT32 locFloorHeight = 0, locCeilingHeight = 0; INT32 cullFloorHeight, cullCeilingHeight; INT32 light = 0; extracolormap_t *floorcolormap; @@ -2993,11 +2991,12 @@ static void HWR_Subsector(size_t num) cullFloorHeight = P_GetSectorFloorZAt (gl_frontsector, viewx, viewy); cullCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, viewx, viewy); - locFloorHeight = P_GetSectorFloorZAt (gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y); - locCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y); if (gl_frontsector->ffloors) { + locFloorHeight = P_GetSectorFloorZAt (gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y); + locCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y); + boolean anyMoved = gl_frontsector->moved; if (anyMoved == false) @@ -3052,8 +3051,7 @@ static void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[gl_frontsector->floorpic].lumpnum, R_NoEncore(gl_frontsector, false)); HWR_RenderPlane(sub, &extrasubsectors[num], false, - // Hack to make things continue to work around slopes. - locFloorHeight == cullFloorHeight ? locFloorHeight : gl_frontsector->floorheight, + gl_frontsector->floorheight, // We now return you to your regularly scheduled rendering. PF_Occlude, floorlightlevel, levelflats[gl_frontsector->floorpic].lumpnum, NULL, 255, floorcolormap); } @@ -3068,8 +3066,7 @@ static void HWR_Subsector(size_t num) { HWR_GetFlat(levelflats[gl_frontsector->ceilingpic].lumpnum, R_NoEncore(gl_frontsector, true)); HWR_RenderPlane(sub, &extrasubsectors[num], true, - // Hack to make things continue to work around slopes. - locCeilingHeight == cullCeilingHeight ? locCeilingHeight : gl_frontsector->ceilingheight, + gl_frontsector->ceilingheight, // We now return you to your regularly scheduled rendering. PF_Occlude, ceilinglightlevel, levelflats[gl_frontsector->ceilingpic].lumpnum, NULL, 255, ceilingcolormap); } diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index e45a56cda..0a79ba6ec 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1475,4 +1475,116 @@ void HWR_DrawMD2(gl_vissprite_t *spr) } } +// mostly copy paste of HWR_DrawMD2 +// very ugly but our model code kinda sucks +void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum, skincolors_t color, const UINT8 *colormap, fixed_t scale, INT32 frame, angle_t angle) +{ + patch_t *gpatch, *blendgpatch; + GLPatch_t *hwrPatch = NULL, *hwrBlendPatch = NULL; + FTransform p; + FSurfaceInfo Surf; + + if (!md2->model) + { + char filename[64]; + CONS_Debug(DBG_RENDER, "Loading model... (%s)\n", md2->filename); + sprintf(filename, "mdls/%s", md2->filename); + md2->model = md2_readModel(filename); + + if (md2->model) + { + md2_printModelInfo(md2->model); + GL_CreateModelVBOs(md2->model); + } + else + { + md2->error = true; + return; + } + } + + if (md2->model->meshes[0].numFrames > 0) + frame = frame % md2->model->meshes[0].numFrames; + else + frame = 0; + + gpatch = (patch_t *)(md2->glpatch); + if (gpatch) + hwrPatch = ((GLPatch_t *)gpatch->hardware); + + if (!gpatch || !hwrPatch || + ((!hwrPatch->mipmap->format || !hwrPatch->mipmap->downloaded) && !md2->notexturefile)) + md2_loadTexture(md2); + + gpatch = (patch_t*)(md2->glpatch); + if (gpatch) + hwrPatch = ((GLPatch_t *)gpatch->hardware); + + blendgpatch = (patch_t*)(md2->blendglpatch); + if (blendgpatch) + hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware); + + if ((gpatch && hwrPatch && hwrPatch->mipmap->format) && + (!blendgpatch || !hwrBlendPatch || + ((!hwrBlendPatch->mipmap->format || !hwrBlendPatch->mipmap->downloaded) && !md2->noblendfile))) + md2_loadBlendTexture(md2); + + blendgpatch = (patch_t*)(md2->blendglpatch); + if (blendgpatch) + hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware); + + memset(&Surf, 0x00, sizeof(FSurfaceInfo)); + Surf.PolyColor.rgba = 0xFFFFFFFF; + Surf.PolyFlags = PF_Occlude | PF_Modulated; + + Surf.LightInfo.light_level = 255; + Surf.LightInfo.fade_start = 0; + Surf.LightInfo.fade_end = 31; + + if (color != SKINCOLOR_NONE && + blendgpatch && hwrBlendPatch->mipmap->format && + gpatch->width == blendgpatch->width && gpatch->height == blendgpatch->height) + { + INT32 tcskinnum = TC_DEFAULT; + + if (color) + tcskinnum = skinnum; + + HWR_GetBlendedTexture(gpatch, blendgpatch, tcskinnum, colormap, color); + } + else if (hwrPatch && hwrPatch->mipmap->format) + { + GL_SetTexture(hwrPatch->mipmap); + } + + memset(&p, 0x00, sizeof(FTransform)); + + p.x = x*vid.dup + (float)(vid.width - BASEVIDWIDTH*vid.dup)/2.f; + p.y = -420.f; // push it back to prevent wonky culling, idk lul + p.z = y*vid.dup + (float)(vid.height - BASEVIDHEIGHT*vid.dup)/2.f; + + p.angley = FixedToFloat(AngleFixed(angle)); + p.anglex = 0.f; + p.anglez = 0.f; + + p.roll = false; + p.fliptype = TRANSFORM_NONE; + + const float fscale = FixedToFloat(scale*vid.dup); + + GL_Draw2DModel( + md2->model, + frame, + 0.f, + 0.f, + -1, + &p, + fscale, + fscale, + true, // flip it vertically lul + false, + &Surf + ); +} + #endif //HWRENDER diff --git a/src/hardware/hw_md2.h b/src/hardware/hw_md2.h index 62de1f35e..0f8bd5342 100644 --- a/src/hardware/hw_md2.h +++ b/src/hardware/hw_md2.h @@ -45,6 +45,9 @@ void HWR_InitMD2(void); void HWR_DrawMD2(gl_vissprite_t *spr); void HWR_AddPlayerMD2(INT32 skin, boolean local); void HWR_AddSpriteMD2(size_t spritenum); +void HWR_Draw2DModel(md2_t *md2, INT32 x, INT32 y, INT32 skinnum, + skincolors_t color, const UINT8 *colormap, + fixed_t scale, INT32 frame, angle_t angle); #ifdef __cplusplus } // extern "C" diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index fab0a8a6d..2d1f8e255 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -404,6 +404,14 @@ static PFNglEnableClientState pglEnableClientState; typedef void (APIENTRY * PFNglDisableClientState) (GLenum cap); static PFNglDisableClientState pglDisableClientState; +typedef void (APIENTRY * PFNglOrtho) (GLdouble left, + GLdouble right, + GLdouble bottom, + GLdouble top, + GLdouble nearVal, + GLdouble farVal); +static PFNglOrtho pglOrtho; + /* Lighting */ typedef void (APIENTRY * PFNglShadeModel) (GLenum mode); static PFNglShadeModel pglShadeModel; @@ -858,6 +866,8 @@ void SetupGLFunc4(void) GetGLfunc(glUniform3fv); GetGLfunc(glGetUniformLocation); + GetGLfunc(glOrtho); + #ifdef GLDEBUGMESSAGE GetGLfunc(glDebugMessageCallback); #endif @@ -3090,6 +3100,39 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics pglDisable(GL_NORMALIZE); } +void GL_Draw2DModel(model_t *model, INT32 frameIndex, INT32 duration, INT32 tics, INT32 nextFrameIndex, + FTransform *pos, float hscale, float vscale, UINT8 flipped, UINT8 hflipped, FSurfaceInfo *Surface) +{ + // save our matrix´s + pglMatrixMode(GL_PROJECTION); + pglPushMatrix(); + pglMatrixMode(GL_MODELVIEW); + pglPushMatrix(); + + pglMatrixMode(GL_PROJECTION); + pglLoadIdentity(); + + // switch to ortho mode to make our lives easier + // thisll make sure our coords will be remapped to pixel coords + pglOrtho(0.0f, (float)vid.width, (float)vid.height, 0.0f, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + + pglMatrixMode(GL_MODELVIEW); + pglLoadIdentity(); + + pglEnable(GL_DEPTH_TEST); + pglDepthMask(GL_TRUE); + pglClear(GL_DEPTH_BUFFER_BIT); + + GL_DrawModelEx(model, frameIndex, duration, tics, nextFrameIndex, + pos, hscale, vscale, flipped, hflipped, Surface); + + // restore the matrix´s + pglMatrixMode(GL_PROJECTION); + pglPopMatrix(); + pglMatrixMode(GL_MODELVIEW); + pglPopMatrix(); +} + // -----------------+ // SetTransform : // -----------------+ diff --git a/src/k_kart.c b/src/k_kart.c index 59271a1e4..6496f3e8e 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -484,7 +484,7 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = { // UINT8 K_RainbowColor(void) { - const INT32 time = cv_reducevfx.value ? (leveltime >> 3) : leveltime; + const tic_t time = cv_reducevfx.value ? (leveltime >> 3) : leveltime; return (UINT8)(1 + (time % (MAXSKINCOLORS-1))); } diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 68ca6b4d0..4c84c48d5 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -25,7 +25,7 @@ #include "lua_hook.h" // cmd errors boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor); -state_t *astate; +state_t *astate = NULL; boolean actionsoverridden[NUMACTIONS] = {false}; diff --git a/src/lua_script.c b/src/lua_script.c index 2aa88cd52..8982688a1 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -45,20 +45,20 @@ int hook_defrosting = 0; // List of internal libraries to load from SRB2 static lua_CFunction liblist[] = { - LUA_EnumLib, // global metatable for enums - LUA_SOCLib, // A_Action functions, freeslot - LUA_BaseLib, // string concatination by +, CONS_Printf, p_local.h stuff (P_InstaThrust, P_Move), etc. - LUA_MathLib, // fixed_t and angle_t math functions - LUA_HookLib, // hookAdd and hook-calling functions - LUA_ConsoleLib, // console command/variable functions and structs - LUA_InfoLib, // info.h stuff: mobjinfo_t, mobjinfo[], state_t, states[] - LUA_MobjLib, // mobj_t, mapthing_t - LUA_PlayerLib, // player_t - LUA_SkinLib, // skin_t, skins[] - LUA_ThinkerLib, // thinker_t - LUA_MapLib, // line_t, side_t, sector_t, subsector_t - LUA_BlockmapLib, // blockmap stuff - LUA_HudLib, // HUD stuff + LUA_EnumLib, // global metatable for enums + LUA_SOCLib, // A_Action functions, freeslot + LUA_BaseLib, // string concatination by +, CONS_Printf, p_local.h stuff (P_InstaThrust, P_Move), etc. + LUA_MathLib, // fixed_t and angle_t math functions + LUA_HookLib, // hookAdd and hook-calling functions + LUA_ConsoleLib, // console command/variable functions and structs + LUA_InfoLib, // info.h stuff: mobjinfo_t, mobjinfo[], state_t, states[] + LUA_MobjLib, // mobj_t, mapthing_t + LUA_PlayerLib, // player_t + LUA_SkinLib, // skin_t, skins[] + LUA_ThinkerLib, // thinker_t + LUA_MapLib, // line_t, side_t, sector_t, subsector_t + LUA_BlockmapLib, // blockmap stuff + LUA_HudLib, // HUD stuff NULL }; @@ -66,12 +66,8 @@ static lua_CFunction liblist[] = { static void *LUA_Alloc(void *ud, void *ptr, size_t osize, size_t nsize) { (void)ud; - if (nsize == 0) { - if (osize != 0) - Z_Free(ptr); - return NULL; - } else - return Z_Realloc(ptr, nsize, PU_LUA, NULL); + (void)osize; + return Z_Realloc(ptr, nsize, PU_LUA, NULL); } // Panic function Lua calls when there's an unprotected error. @@ -213,7 +209,8 @@ void LUA_ClearState(void) lua_setfield(L, LUA_REGISTRYINDEX, LREG_VALID); // open srb2 libraries - for(i = 0; liblist[i]; i++) { + for (i = 0; liblist[i]; i++) + { lua_pushcfunction(L, liblist[i]); lua_call(L, 0, 0); } diff --git a/src/m_emotes.h b/src/m_emotes.h index 594e219f8..d87dd438f 100644 --- a/src/m_emotes.h +++ b/src/m_emotes.h @@ -12,14 +12,14 @@ #ifndef __M_EMOTES__ #define __M_EMOTES__ -#ifdef __cplusplus -extern "C" { -#endif - #include "doomdef.h" #include "m_fixed.h" #include "command.h" +#ifdef __cplusplus +extern "C" { +#endif + extern consvar_t cv_emotes; #define MAXEMOTENAME 32 diff --git a/src/m_menu.c b/src/m_menu.c index 55112356b..a98a230d5 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -12,6 +12,8 @@ /// \file m_menu.c /// \brief XMOD's extremely revamped menu system. +#include "screen.h" +#include "tables.h" #ifdef __GNUC__ #include #endif @@ -7900,7 +7902,7 @@ static void M_HandleConnectIP(INT32 choice) if (exitmenu) { if (currentMenu->prevMenu) - M_SetupNextMenu (currentMenu->prevMenu); + M_SetupNextMenu(currentMenu->prevMenu); else M_ClearMenus(true); } @@ -7946,6 +7948,7 @@ static void M_DrawSetupMultiPlayerMenu(void) UINT8 i; UINT8 s, w; const UINT8 *flashcol = V_GetStringColormap(highlightflags); + INT32 skinnum = 0; INT32 statx, staty; UINT32 speenframe; INT32 sltw, actw, hetw; @@ -8268,10 +8271,9 @@ static void M_DrawSetupMultiPlayerMenu(void) INT32 curx = (((setupm_skinselect % SKINGRIDNEWWIDTH) * 18) + ((BASEVIDWIDTH / 2) - (18 * SKINGRIDNEWWIDTH/2)) + SKINXSHIFT) + 20; INT32 cury = (((setupm_skinselect / SKINGRIDNEWWIDTH) - setupm_skinypos) * 18) + ((BASEVIDHEIGHT / 2) - (18 * (SKINGRIDNEWWIDTH/2))+ gridyoffset); - UINT8 cursorframe = (I_GetTime() / 4) % 7; - - cursor = (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); - V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); + UINT8 cursorframe = (I_GetTime() / 4) % 7; + cursor = (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); + V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } break; @@ -8310,14 +8312,12 @@ static void M_DrawSetupMultiPlayerMenu(void) if (setupm_skinselect < numskins) { UINT8 *cmap = R_GetTranslationColormap(setupm_skinselect, setupm_fakecolor, GTC_MENUCACHE); - cursor = facewantprefix[skinsorted[setupm_skinselect]]; V_DrawFixedPatch(((curx-8) << FRACBITS), ((cury-8) << FRACBITS), FRACUNIT, 0, cursor, cmap); } else { UINT8 cursorframe = (I_GetTime() / 4) % 7; - cursor = (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } @@ -8381,7 +8381,6 @@ static void M_DrawSetupMultiPlayerMenu(void) else { UINT8 cursorframe = (I_GetTime() / 4) % 7; - cursor = (patch_t *)W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } @@ -8506,7 +8505,7 @@ static void M_DrawSetupMultiPlayerMenu(void) switch (cv_skinselectmenu.value) { case SKINMENUTYPE_2D: - skintodisplay = setupm_fakeskin; + skintodisplay = (UINT8)setupm_fakeskin; if (setupm_skinlockedselect) // show the skin we are trying to select skintodisplay = skinstats[setupm_skinxpos][setupm_skinypos][setupm_skinselect]; else if (skinstatscount[setupm_skinxpos][setupm_skinypos] && itemOn == 1) @@ -8514,19 +8513,22 @@ static void M_DrawSetupMultiPlayerMenu(void) break; case SKINMENUTYPE_EXTENDED: case SKINMENUTYPE_GRID: - skintodisplay = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin); + skintodisplay = ((itemOn == 1 && (setupm_skinselect < numskins)) ? skinsorted[setupm_skinselect] : (UINT8)setupm_fakeskin); break; default: - skintodisplay = setupm_fakeskin; + skintodisplay = (UINT8)setupm_fakeskin; break; } - const INT32 skinnum = R_SkinAvailable(skins[skintodisplay].name); + if (skintodisplay >= MAXSKINS) + skintodisplay = 0; - if (skinnum != -1) - sprdef = &skins[skinnum].spritedef; - else - sprdef = &skins[0].spritedef; + skinnum = R_SkinAvailable(skins[skintodisplay].name); + + if (skinnum < 0 || skinnum >= MAXSKINS) + skinnum = 0; + + sprdef = &skins[skinnum].spritedef; if (!sprdef->numframes) // No frames ?? return; // Can't render! @@ -8535,37 +8537,59 @@ static void M_DrawSetupMultiPlayerMenu(void) if (frame >= sprdef->numframes) // Walking animation missing frame = 0; // Try to use standing frame - sprframe = &sprdef->spriteframes[frame]; - - // minenice's speen css, it's a piece of shit but hey - speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; - - // this is a very shitty solution for checking if a sprite needs flipping - // but it works - if ((speenframe > 4) && (sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe])) - flags = V_FLIP; // This sprite is left/right flipped! - - patch = (patch_t *)W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); - // draw box around guy V_DrawFill(mx + 36 - (charw/2), my+65, charw, 84, 239); +#undef charw // draw player sprite if (setupm_fakecolor) // inverse should never happen { UINT8 *colormap = R_GetTranslationColormap(skintodisplay, setupm_fakecolor, GTC_MENUCACHE); - - if (skins[skintodisplay].flags & SF_HIRES) +#ifdef HWRENDER + md2_t *md2 = &md2_playermodels[skinnum]; +#endif + mx += 36; + my += 131; +#ifdef HWRENDER + // if we have 3d models enabled and a model exists + // try to show it instead of the sprite + if (rendermode == render_opengl && cv_glmdls.value + && !md2->error && !md2->notfound) { - V_DrawFixedPatch((mx+36)<spriteframes[frame]; + + // minenice's speen css, it's a piece of shit but hey + speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; + + // this is a very shitty solution for checking if a sprite needs flipping + // but it works + if ((speenframe > 4) && (sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe])) + { + flags = V_FLIP; // This sprite is left/right flipped! + } + + patch = (patch_t *)W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); + + if (skins[skintodisplay].flags & SF_HIRES) + { + V_DrawFixedPatch(mx<= sprdef->numframes) // Walking animation missing frame = 0; // Try to use standing frame - sprframe = &sprdef->spriteframes[frame]; - - //minenice's speen css, it's a piece of shit but hey - //patch = (patch_t *)W_CachePatchNum(sprframe->lumppat[1], PU_PATCH); - speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; - - //this is a very shitty solution for checking if a sprite needs flipping - //but it works - if ((speenframe > 4) && (sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe])) - { - flags = V_FLIP; // This sprite is left/right flipped! - } - patch = (patch_t *)W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); - // draw box around guy V_DrawFill(mx + 220 - (charw/2), my+54, charw, 84, 239); +#undef charw - // draw player sprite UINT8 *colormap = R_GetLocalTranslationColormap(&skins[displayskin.localnum], (displayskin.localskin ? &localskins[displayskin.localnum] : NULL), cv_playercolor.value, GTC_MENUCACHE, displayskin.localskin); V_DrawMappedPatch(mx, my+50, 0, (patch_t *)W_CachePatchName(displayskin.facewant, PU_PATCH), colormap); @@ -9949,13 +9959,48 @@ static void M_DrawLocalSkinMenu(void) else V_DrawString(mx+20, my+118, V_ALLOWLOWERCASE|highlightflags, displayskin.realname); - if (displayskin.flags & SF_HIRES) + // draw player sprite + mx += 220; + my += 120; + +#ifdef HWRENDER + md2_t *md2 = (displayskin.localskin ? &md2_localplayermodels[skintodisplay] : &md2_playermodels[skintodisplay]); + + // if we have 3d models enabled and a model exists + // try to show it instead of the sprite + if (rendermode == render_opengl && cv_glmdls.value + && !md2->error && !md2->notfound) { - V_DrawFixedPatch((mx+220)<spriteframes[frame]; + + // minenice's speen css, it's a piece of shit but hey + speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; + + // this is a very shitty solution for checking if a sprite needs flipping + // but it works + if ((speenframe > 4) && (sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe])) + { + flags = V_FLIP; // This sprite is left/right flipped! + } + + patch = (patch_t *)W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); + + if (displayskin.flags & SF_HIRES) + { + V_DrawFixedPatch(mx< + #include "r_portal.h" #include "r_splats.h" #include "r_fps.h" // newview diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index e4b0d4f37..1c7d52344 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -32,7 +32,7 @@ set(SRB2_SDL2_SOURCES hwsym_sdl.c i_main.c i_net.c - i_system.c + i_system.cpp i_ttf.c i_video.c i_threads.c @@ -123,8 +123,6 @@ if(${SDL2_FOUND}) set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns) set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") set(SRB2_SDL2_MAC_SOURCES - macosx/mac_alert.c - macosx/mac_alert.h macosx/mac_resources.c macosx/mac_resources.h macosx/Srb2mac.icns @@ -167,10 +165,16 @@ if(${SDL2_FOUND}) ${DISCORDRPC_LIBRARIES} ) + if(${SRB2_HAVE_LIBBACKTRACE}) + target_link_libraries(SRB2SDL2 PRIVATE ${LIBBACKTRACE_LIBRARIES}) + endif() + + if(${CMAKE_SYSTEM} MATCHES Linux) target_link_libraries(SRB2SDL2 PRIVATE m rt + pthread ) endif() diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 66d8e4bb4..1d1a8b00f 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -30,6 +30,7 @@ #endif #include +#include #ifdef _WIN32 #define RPC_NO_WINDOWS_H @@ -201,10 +202,6 @@ static char returnWadPath[256]; #include "../s_sound.h" -#ifdef MAC_ALERT -#include "macosx/mac_alert.h" -#endif - #include "../d_main.h" #if !defined(NOMUMBLE) && defined(HAVE_MUMBLE) @@ -727,12 +724,11 @@ static void JoyReset(SDLJoyInfo_t *JoySet) JoySet->dev = NULL; JoySet->oldjoy = -1; JoySet->id = -1; - JoySet->axises = JoySet->buttons = JoySet->hats = JoySet->balls = 0; } /** \brief SDL info about joystick */ -SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS]; +SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS] = {}; INT32 numcontrollers = 0; // @@ -740,26 +736,26 @@ INT32 numcontrollers = 0; // void I_JoyScale(void) { - Joystick[0].bGamepadStyle = cv_joyscale[0].value==0; - JoyInfo[0].scale = Joystick[0].bGamepadStyle?1:cv_joyscale[0].value; + Joystick[0].bGamepadStyle = cv_joyscale[0].value == 0; + JoyInfo[0].scale = Joystick[0].bGamepadStyle ? 1 : cv_joyscale[0].value; } void I_JoyScale2(void) { - Joystick[1].bGamepadStyle = cv_joyscale[1].value==0; - JoyInfo[1].scale = Joystick[1].bGamepadStyle?1:cv_joyscale[1].value; + Joystick[1].bGamepadStyle = cv_joyscale[1].value == 0; + JoyInfo[1].scale = Joystick[1].bGamepadStyle ? 1 : cv_joyscale[1].value; } void I_JoyScale3(void) { - Joystick[2].bGamepadStyle = cv_joyscale[2].value==0; - JoyInfo[2].scale = Joystick[2].bGamepadStyle?1:cv_joyscale[2].value; + Joystick[2].bGamepadStyle = cv_joyscale[2].value == 0; + JoyInfo[2].scale = Joystick[2].bGamepadStyle ? 1 : cv_joyscale[2].value; } void I_JoyScale4(void) { - Joystick[3].bGamepadStyle = cv_joyscale[3].value==0; - JoyInfo[3].scale = Joystick[3].bGamepadStyle?1:cv_joyscale[3].value; + Joystick[3].bGamepadStyle = cv_joyscale[3].value == 0; + JoyInfo[3].scale = Joystick[3].bGamepadStyle ? 1 : cv_joyscale[3].value; } // Cheat to get the device index for a joystick handle @@ -886,13 +882,13 @@ static int joy_open(int playerIndex, int joyIndex) if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { - CONS_Printf(M_GetText("Joystick subsystem not started\n")); + CONS_Printf("Joystick subsystem not started\n"); return -1; } if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0) { - CONS_Printf(M_GetText("Game Controller subsystem not started\n")); + CONS_Printf("Game Controller subsystem not started\n"); return -1; } @@ -903,7 +899,7 @@ static int joy_open(int playerIndex, int joyIndex) if (num_joy == 0) { - CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); + CONS_Printf("%s", "Found no joysticks on this system\n"); return -1; } @@ -926,38 +922,23 @@ static int joy_open(int playerIndex, int joyIndex) return SDL_CONTROLLER_AXIS_MAX; // Else, we're changing devices, so send neutral joy events - CONS_Debug(DBG_GAMELOGIC, "Joystick1 device is changing; resetting events...\n"); + CONS_Debug(DBG_GAMELOGIC, "Joystick %d device is changing; resetting events...\n", playerIndex+1); I_ShutdownJoystick(playerIndex); } JoyInfo[playerIndex].dev = newdev; - JoyInfo[playerIndex].id = I_GetJoystickDeviceIndex(JoyInfo[playerIndex].dev); if (JoyInfo[playerIndex].dev == NULL) { - CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick1: Couldn't open device - %s\n"), SDL_GetError()); + CONS_Debug(DBG_GAMELOGIC, "Joystick %d: Couldn't open device - %s\n", playerIndex+1, SDL_GetError()); return -1; } - else - { - CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick1: %s\n"), SDL_GameControllerName(JoyInfo[playerIndex].dev)); - JoyInfo[playerIndex].axises = SDL_CONTROLLER_AXIS_MAX; - if (JoyInfo[playerIndex].axises > JOYAXISSET*2) - JoyInfo[playerIndex].axises = JOYAXISSET*2; + CONS_Debug(DBG_GAMELOGIC, "Joystick %d: %s\n", playerIndex+1, SDL_GameControllerName(JoyInfo[playerIndex].dev)); - JoyInfo[playerIndex].buttons = SDL_CONTROLLER_BUTTON_MAX ; // dpad is 4 buttons - if (JoyInfo[playerIndex].buttons > JOYBUTTONS) - JoyInfo[playerIndex].buttons = JOYBUTTONS; + JoyInfo[playerIndex].id = I_GetJoystickDeviceIndex(JoyInfo[playerIndex].dev); - JoyInfo[playerIndex].hats = 4; - if (JoyInfo[playerIndex].hats > JOYHATS) - JoyInfo[playerIndex].hats = JOYHATS; - - JoyInfo[playerIndex].balls = 0; - - return JoyInfo[playerIndex].axises; - } + return SDL_CONTROLLER_AXIS_MAX; } // @@ -1002,7 +983,6 @@ void I_InitJoystick(UINT8 index) JoyInfo[index].dev = NULL; JoyInfo[index].oldjoy = -1; JoyInfo[index].id = -1; - JoyInfo[index].axises = JoyInfo[index].buttons = JoyInfo[index].hats = JoyInfo[index].balls = 0; if (cv_usejoystick[index].value) newcontroller = SDL_GameControllerOpen(cv_usejoystick[index].value-1); @@ -1386,7 +1366,7 @@ void I_SleepDuration(precise_t duration) #endif } -static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg); +static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg, char *signal_ttl); #ifdef HAVE_LIBBACKTRACE #include @@ -1482,6 +1462,7 @@ static void bt_error_cb(void *data, const char *msg, int errnum) static void write_backtrace(bt_crash_reason_t reason) { char sig_msg[512]; + char sig_name[128]; const char *filename = va("%s" PATHSEP CRASH_LOGFILE_NAME, srb2home); FILE *out = fopen(filename, "a+"); @@ -1538,8 +1519,8 @@ static void write_backtrace(bt_crash_reason_t reason) switch (reason.type) { case BTCRASH_SIGNAL: - I_PrintSignal(reason.value.signal, false, sig_msg); - fprintf(out, "%s", sig_msg); + I_PrintSignal(reason.value.signal, false, sig_msg, sig_name); + fprintf(out, "%s - %s", sig_name, sig_msg); break; case BTCRASH_ERRORMSG: @@ -1575,42 +1556,49 @@ static std::thread::id g_main_thread_id; boolean g_in_exiting_signal_handler = false; -static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg) +static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg, char *signal_name) { - const char *sigmsg; + const char *sigmsg, *signame; switch (signal_num) { #ifdef SIGINT case SIGINT: - sigmsg = ("SIGINT - SRB2Kart-Saturn was interrupted prematurely by the user."); + sigmsg = ("SRB2Kart-Saturn was interrupted prematurely by the user."); + signame = "SIGINT"; break; #endif case SIGILL: // illegal instruction - invalid function image - sigmsg = ("SIGILL - SRB2Kart-Saturn has attempted to execute an illegal instruction and needs to close."); + sigmsg = ("SRB2Kart-Saturn has attempted to execute an illegal instruction and needs to close."); + signame = "SIGILL"; break; case SIGFPE: // mathematical exception - sigmsg = ("SIGFPE - SRB2Kart-Saturn has encountered a mathematical exception and needs to close."); + sigmsg = ("SRB2Kart-Saturn has encountered a mathematical exception and needs to close."); + signame = "SIGFPE"; break; case SIGSEGV: // segment violation - sigmsg = ("SIGSEGV - SRB2Kart-Saturn has attempted to access a memory location that it shouldn't and needs to close."); + sigmsg = ("SRB2Kart-Saturn has attempted to access a memory location that it shouldn't and needs to close."); + signame = "SIGSEGV"; break; #ifdef SIGTERM case SIGTERM: // Software termination signal from kill - sigmsg = ("SIGTERM - SRB2Kart-Saturn was terminated by a kill signal."); + sigmsg = ("SRB2Kart-Saturn was terminated by a kill signal."); + signame = "SIGTERM"; break; #endif #ifdef SIGBREAK case SIGBREAK: // Ctrl-Break sequence sigmsg =("SIGBREAK - SRB2Kart-Saturn was terminated by a Ctrl-Break sequence."); + signame = "SIGBREAK"; break; #endif case SIGABRT: // abnormal termination triggered by abort call - sigmsg = ("SIGABRT - SRB2Kart-Saturn was terminated by an abort signal."); + sigmsg = ("SRB2Kart-Saturn was terminated by an abort signal."); + signame = "SIGABRT"; break; default: - sprintf(signal_msg, "Signal number %d", signal_num); - sigmsg = (core_dumped ? "Unknown signal" : signal_msg); + sigmsg = "SRB2Kart-Saturn was terminated by an unknown signal."; + signame = core_dumped ? "Unknown signal" : va("Signal number %d", signal_num); break; } @@ -1625,18 +1613,80 @@ static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_ms { sprintf(signal_msg, "%s", sigmsg); } + + sprintf(signal_name, "%s", signame); +} + +static int I_OpenURL(const char *url) +{ +#if SDL_VERSION_ATLEAST(2,0,14) + return SDL_OpenURL(va("%s", url)); +#else + return -1; +#endif +} + +static void I_ShowErrorBox(const char *title, const char *msg) +{ + if (M_CheckParm("-dedicated")) + return; + + const char *reportmsg = "\n\n\nTo help us figure out the cause, please report the issue to our github page with " CRASH_LOGFILE_NAME " attached.\n\nSorry for the inconvenience!"; + + const SDL_MessageBoxButtonData buttons[] = { + { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "OK" }, + { 0, 1, "Report Issue" }, + }; + + const SDL_MessageBoxData messageboxdata = { + SDL_MESSAGEBOX_ERROR, /* .flags */ + NULL, /* .window */ + title, /* .title */ + va("%s %s", msg, reportmsg), /* .message */ + SDL_arraysize(buttons), /* .numbuttons */ + buttons, /* .buttons */ + NULL /* .colorScheme */ + }; + + int buttonid; + + SDL_ShowMessageBox(&messageboxdata, &buttonid); + + if (buttonid == 1) + I_OpenURL("https://github.com/Indev450/SRB2Kart-Saturn/issues"); +} + +static void I_ShowSimpleErrorBox(const char *title, char *msg) +{ + if (M_CheckParm("-dedicated")) + return; + + // Implement message box with SDL_ShowSimpleMessageBox, + // which should fail gracefully if it can't put a message box up + // on the target system + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, msg, NULL); + // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be + // initialized at the time, so calling it after SDL_Quit() is + // perfectly okay! In addition, we do this on purpose so the + // fullscreen window is closed before displaying the error message + // in case the fullscreen window blocks it for some absurd reason. } static void I_ReportSignal(int num, int coredumped) { char sigmsg[512]; + char signame[128]; + char sigttl[512] = "Process killed by signal: "; - I_PrintSignal(num, coredumped, sigmsg); + I_PrintSignal(num, coredumped, sigmsg, signame); size_t len = strlen(sigmsg); snprintf(sigmsg + len, sizeof(sigmsg) - len, "\n\nCrash report has been saved into %s", CRASH_LOGFILE_NAME); - I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Process killed by signal", sigmsg, NULL); + + strcat(sigttl, signame); + I_OutputMsg("\n%s\n\n", sigttl); + //I_ShowSimpleErrorBox(sigttl, sigmsg); + I_ShowErrorBox(sigttl, sigmsg); } #ifndef NEWSIGNALHANDLER @@ -1744,10 +1794,7 @@ FUNCNORETURN static ATTRNORETURN void newsignalhandler_Warn(const char *pr) ); I_OutputMsg("%s\n", text); - - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Startup error", - text, NULL); + I_ShowSimpleErrorBox("Startup error", text); I_ShutdownConsole(); exit(-1); @@ -1909,6 +1956,7 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) { va_list argptr; char buffer[8192]; + const char *sigttl = ""; #ifdef HAVE_THREADS if (std::this_thread::get_id() != g_main_thread_id) @@ -1945,12 +1993,9 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) va_start(argptr, error); vsnprintf(buffer, 8192, error, argptr); va_end(argptr); - // Implement message box with SDL_ShowSimpleMessageBox, - // which should fail gracefully if it can't put a message box up - // on the target system - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "SRB2Kart " VERSIONSTRING " Recursive Error", - buffer, NULL); + + sigttl = "SRB2Kart " VERSIONSTRING " Recursive Error"; + I_ShowSimpleErrorBox(sigttl, buffer); W_Shutdown(); exit(-1); // recursive errors detected @@ -1990,15 +2035,9 @@ FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) I_ShutdownSystem(); SDL_Quit(); - // Implement message box with SDL_ShowSimpleMessageBox, - // which should fail gracefully if it can't put a message box up - // on the target system - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "SRB2Kart " VERSIONSTRING " Error", buffer, NULL); - // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be - // initialized at the time, so calling it after SDL_Quit() is - // perfectly okay! In addition, we do this on purpose so the - // fullscreen window is closed before displaying the error message - // in case the fullscreen window blocks it for some absurd reason. + sigttl = "SRB2Kart " VERSIONSTRING " Error"; + //I_ShowSimpleErrorBox(sigttl, buffer); + I_ShowErrorBox(sigttl, buffer); W_Shutdown(); @@ -2424,7 +2463,7 @@ static const char *locateWad(void) return NULL; } -const char *I_LocateWad(void) +extern "C" const char *I_LocateWad(void) { const char *waddir = NULL; diff --git a/src/sdl/i_threads.c b/src/sdl/i_threads.c index 078f4e0f4..26d3bbefe 100644 --- a/src/sdl/i_threads.c +++ b/src/sdl/i_threads.c @@ -9,6 +9,8 @@ /// \file i_threads.c /// \brief Multithreading abstraction +#ifdef HAVE_THREADS + #include "../doomdef.h" #include "../i_threads.h" @@ -354,3 +356,5 @@ I_wake_all_cond ( if (SDL_CondBroadcast(cond) == -1) abort(); } + +#endif // HAVE_THREADS diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 72354ca1e..1c23af6cd 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -467,7 +467,7 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) } else { - raxis = JoyInfo[pid].scale!=1?((raxis/JoyInfo[pid].scale)*JoyInfo[pid].scale):raxis; + raxis = JoyInfo[pid].scale != 1 ? ((raxis/JoyInfo[pid].scale)*JoyInfo[pid].scale) : raxis; #ifdef SDL_JDEADZONE if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE) diff --git a/src/sdl/macosx/mac_alert.c b/src/sdl/macosx/mac_alert.c deleted file mode 100644 index 2a139041a..000000000 --- a/src/sdl/macosx/mac_alert.c +++ /dev/null @@ -1,64 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 1993-1996 by id Software, Inc. -// Portions Copyright (C) 1998-2000 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief Graphical Alerts for MacOSX -/// -/// Shows alerts, since we can't just print these to the screen when -/// launched graphically on a mac. - -#ifdef __APPLE_CC__ - -#include "mac_alert.h" -#include - -#define CFSTRINGIFY(x) CFStringCreateWithCString(NULL, x, kCFStringEncodingASCII) - -int MacShowAlert(const char *title, const char *message, const char *button1, const char *button2, const char *button3) -{ - CFOptionFlags results; - - CFStringRef cf_title = CFSTRINGIFY(title); - CFStringRef cf_message = CFSTRINGIFY(message); - CFStringRef cf_button1 = NULL; - CFStringRef cf_button2 = NULL; - CFStringRef cf_button3 = NULL; - - if (button1 != NULL) - cf_button1 = CFSTRINGIFY(button1); - if (button2 != NULL) - cf_button2 = CFSTRINGIFY(button2); - if (button3 != NULL) - cf_button3 = CFSTRINGIFY(button3); - - CFOptionFlags alert_flags = kCFUserNotificationStopAlertLevel | kCFUserNotificationNoDefaultButtonFlag; - - CFUserNotificationDisplayAlert(0, alert_flags, NULL, NULL, NULL, cf_title, cf_message, - cf_button1, cf_button2, cf_button3, &results); - - if (cf_button1 != NULL) - CFRelease(cf_button1); - if (cf_button2 != NULL) - CFRelease(cf_button2); - if (cf_button3 != NULL) - CFRelease(cf_button3); - CFRelease(cf_message); - CFRelease(cf_title); - - return (int)results; -} - -#endif diff --git a/src/sdl/macosx/mac_alert.h b/src/sdl/macosx/mac_alert.h deleted file mode 100644 index 82a28d120..000000000 --- a/src/sdl/macosx/mac_alert.h +++ /dev/null @@ -1,27 +0,0 @@ -// Emacs style mode select -*- C++ -*- -//----------------------------------------------------------------------------- -// -// Copyright (C) 1993-1996 by id Software, Inc. -// Portions Copyright (C) 1998-2000 by DooM Legacy Team. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -//----------------------------------------------------------------------------- -/// \file -/// \brief Graphical Alerts for MacOSX -/// -/// Shows alerts, since we can't just print these to the screen when -/// launched graphically on a mac. - -#ifdef __APPLE_CC__ - -extern int MacShowAlert(const char *title, const char *message, const char *button1, const char *button2, const char *button3); - -#endif diff --git a/src/sdl/macosx/mac_resources.h b/src/sdl/macosx/mac_resources.h index 727ac9f6b..d63232dac 100644 --- a/src/sdl/macosx/mac_resources.h +++ b/src/sdl/macosx/mac_resources.h @@ -1,5 +1,11 @@ #ifndef __MAC_RESOURCES_H__ #define __MAC_RESOURCES_H__ +#ifdef __cplusplus +extern "C" { +#endif void OSX_GetResourcesPath(char * buffer); -#endif \ No newline at end of file +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index e5bdca395..f7f4c011c 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -44,15 +44,15 @@ typedef struct SDLJoyInfo_s /// number of old joystick int oldjoy; /// number of axies - int axises; + //int axises; /// scale of axises INT32 scale; /// number of buttons - int buttons; + //int buttons; /// number of hats - int hats; + //int hats; /// number of balls - int balls; + //int balls; } SDLJoyInfo_t; /** \brief SDL info about controller 1 diff --git a/src/st_stuff.c b/src/st_stuff.c index 99188e919..5ca3f9d91 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -720,7 +720,7 @@ void ST_DrawDemoTitleEntry(void) static void ST_MayonakaStatic(void) { INT32 flag; - if (cv_lessflicker.value) + if (cv_lessflicker.value || cv_reducevfx.value) flag = V_70TRANS; else flag = (leveltime%2) ? V_90TRANS : V_70TRANS; diff --git a/src/strcasestr.c b/src/strcasestr.c index f50141dcf..f05449778 100644 --- a/src/strcasestr.c +++ b/src/strcasestr.c @@ -23,6 +23,10 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include +#include + static inline int trycmp (char **pp, char *cp, const char *q, size_t qn) @@ -73,7 +77,7 @@ nongnu_strcasestr (const char *s, const char *q) up = strchr(s, uc); lp = strchr(s, lc); - if (up == NULL || lp == NULL) + if (up == NULL && lp == NULL) return NULL; if (!lp || ( up && up < lp )) @@ -100,7 +104,7 @@ nongnu_strcasestr (const char *s, const char *q) if (trycmp(ppa, cpa, q, qn) == 0) return (*ppa); - if (up == NULL || lp == NULL) + if (up == NULL && lp == NULL) break; if (!(*ppa) || ( (*ppb) && (*ppb) < (*ppa) )) diff --git a/src/v_video.c b/src/v_video.c index bb118d269..b5be19a97 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1742,6 +1742,7 @@ void V_DrawHorizontallyScaledFullScreenPatch(patch_t *patch) void V_DrawVhsEffect(boolean rewind) { fixed_t uby, dby; + // upbary is the bar going from top to bottom for some reason static fixed_t upbary = 100*FRACUNIT, downbary = 150*FRACUNIT; UINT8 barsize, updistort, downdistort; @@ -1759,20 +1760,26 @@ void V_DrawVhsEffect(boolean rewind) if (cv_reducevfx.value) return; - barsize = vid.dup << 5; - updistort = vid.dup << (rewind ? 5 : 3); + const INT32 dup = min(vid.width / BASEVIDWIDTH, vid.height / BASEVIDHEIGHT); + + barsize = dup << 5; + updistort = dup << (rewind ? 5 : 3); downdistort = updistort >> 1; if (rewind) V_DrawVhsEffect(false); // experimentation - upbary -= renderdeltatics * (vid.dup * (rewind ? 3 : 1.8f)); - downbary += renderdeltatics * (vid.dup * (rewind ? 2 : 1)); + upbary -= renderdeltatics * (fixed_t)(dup * (rewind ? 3 : 1.8f)); + downbary += renderdeltatics * (dup * (rewind ? 2 : 1)); if (upbary < -barsize*FRACUNIT) upbary = vid.height << FRACBITS; + if (upbary > vid.height << FRACBITS) + upbary = -barsize*FRACUNIT; if (downbary > vid.height << FRACBITS) downbary = -barsize*FRACUNIT; + if (downbary < -barsize*FRACUNIT) + downbary = vid.height << FRACBITS; uby = upbary >> FRACBITS; dby = downbary >> FRACBITS; @@ -3821,7 +3828,7 @@ void InitColorLUT(colorlookup_t *lut, RGBA_t *palette, boolean makecolors) lut->init = true; memcpy(lut->palette, palette, palsize); - for (i = 0; i < 0xFFFF; i++) + for (i = 0; i < 0x10000; i++) lut->table[i] = 0xFFFF; if (makecolors) @@ -3834,7 +3841,9 @@ void InitColorLUT(colorlookup_t *lut, RGBA_t *palette, boolean makecolors) { for (b = 0; b < 0xFF; b++) { - lut->table[i] = GetColorLUT(lut, r, g, b); + i = CLUTINDEX(r, g, b); + if (lut->table[i] == 0xFFFF) + lut->table[i] = NearestPaletteColor(r, g, b, palette); } } } diff --git a/src/win32/win_dbg.c b/src/win32/win_dbg.c index a5d1adc3f..d47117698 100644 --- a/src/win32/win_dbg.c +++ b/src/win32/win_dbg.c @@ -187,13 +187,13 @@ static VOID ShowModuleInfo(HANDLE LogFile, HMODULE ModuleHandle) // Open the code module file so that we can get its file date // and size. ModuleFile = CreateFileA(ModName, GENERIC_READ, - FILE_SHARE_READ, 0, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, 0); + FILE_SHARE_READ, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); if (ModuleFile != INVALID_HANDLE_VALUE) { FILETIME LastWriteTime; - FileSize = GetFileSize(ModuleFile, 0); - if (GetFileTime(ModuleFile, 0, 0, &LastWriteTime)) + FileSize = GetFileSize(ModuleFile, NULL); + if (GetFileTime(ModuleFile, NULL, NULL, &LastWriteTime)) { wsprintfA(TimeBuffer, " - file date is "); PrintTime(TimeBuffer + strlen(TimeBuffer), LastWriteTime); @@ -227,7 +227,7 @@ static VOID RecordModuleList(HANDLE LogFile) size_t PageSize; size_t NumPages; size_t pageNum = 0; - LPVOID LastAllocationBase = 0; + LPVOID LastAllocationBase = NULL; FPrintf(LogFile, "\r\n" "\tModule list: names, addresses, sizes, time stamps " @@ -385,7 +385,7 @@ LONG WINAPI RecordExceptionInfo(PEXCEPTION_POINTERS data/*, LPCSTR Message, LPST } // Append to the error log. - SetFilePointer(fileHandle, 0, 0, FILE_END); + SetFilePointer(fileHandle, 0, NULL, FILE_END); // Print out some blank lines to separate this error log from any previous ones. FPrintf(fileHandle, "Email Sonic Team Junior so we can fix the bugs\r\n"); // Tails