From 8f4385c39bba5adf0ea7e95849d16e3698756fb4 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Sep 2025 17:46:59 +0100 Subject: [PATCH 01/39] fix windoze compile --- src/m_misc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/m_misc.c b/src/m_misc.c index c59b10a6a..9e7ec309e 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1243,8 +1243,10 @@ void M_SaveFrame(void) I_ReadScreen(linear, 1); } #ifdef HWRENDER - else - linear = HWR_GetScreenshot(); + else if (rendermode == render_opengl) + { + linear = HWR_GetScreenshot(1); + } #endif M_PNGFrame(apng_ptr, apng_info_ptr, (png_bytep)linear); #ifdef HWRENDER @@ -1506,7 +1508,7 @@ void M_DoScreenShot(void) char pathname[MAX_WADPATH]; boolean ret = false; UINT8 *linear = NULL; - UINT8 *palette; + UINT8 *palette = NULL; // Don't take multiple screenshots, obviously takescreenshot = false; From 9edcbe22f436b6c81ef7df98da019a9fc77668fa Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Sep 2025 20:13:51 +0200 Subject: [PATCH 02/39] delet apng support this never really worked so get rid of it --- src/CMakeLists.txt | 7 +- src/Makefile.d/features.mk | 2 - src/apng.c | 289 -------------- src/apng.h | 78 ---- src/d_netcmd.c | 6 - src/m_menudefs.c | 15 +- src/m_misc.c | 366 +----------------- src/m_misc.h | 3 - .../macosx/Srb2mac.xcodeproj/project.pbxproj | 5 - 9 files changed, 5 insertions(+), 766 deletions(-) delete mode 100644 src/apng.c delete mode 100644 src/apng.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4ce38953d..361386622 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -442,12 +442,7 @@ if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) set(SRB2_HAVE_PNG ON) add_definitions(-DHAVE_PNG) add_definitions(-D_LARGEFILE64_SOURCE) - set(SRB2_PNG_SOURCES apng.c) - set(SRB2_PNG_HEADERS apng.h) - prepend_sources(SRB2_PNG_SOURCES) - prepend_sources(SRB2_PNG_HEADERS) - source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS} - ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS}) + source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) else() message(WARNING "You have specified that PNG is available but it was not found. SRB2Kart may not compile correctly.") endif() diff --git a/src/Makefile.d/features.mk b/src/Makefile.d/features.mk index 1b0bb5eca..427b5417f 100644 --- a/src/Makefile.d/features.mk +++ b/src/Makefile.d/features.mk @@ -51,8 +51,6 @@ endif ifdef LINUX opts+=-D_LARGEFILE64_SOURCE endif -opts+=-DHAVE_PNG -sources+=apng.c endif endif diff --git a/src/apng.c b/src/apng.c deleted file mode 100644 index 711024ee3..000000000 --- a/src/apng.c +++ /dev/null @@ -1,289 +0,0 @@ -/* -Copyright 2019, James R. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include - -#include "apng.h" - -#define APNG_INFO_acTL 0x20000U - -#define APNG_WROTE_acTL 0x10000U - -struct apng_info_def -{ - png_uint_32 mode; - png_uint_32 valid; - - png_uint_32 num_frames; - png_uint_32 num_plays; - - long start_acTL;/* acTL is written here */ - - png_flush_ptr output_flush_fn; - apng_seek_ptr output_seek_fn; - apng_tell_ptr output_tell_fn; - - apng_set_acTL_ptr set_acTL_fn; -}; - -/* PROTOS (FUCK COMPILER) */ -void apng_seek (png_structp, apng_const_infop, size_t); -size_t apng_tell (png_structp, apng_const_infop); -#ifdef PNG_WRITE_FLUSH_SUPPORTED -void apng_flush (png_structp, apng_infop); -#ifdef PNG_STDIO_SUPPORTED -void apng_default_flush (png_structp); -#endif/* PNG_STDIO_SUPPORTED */ -#endif/* PNG_WRITE_FLUSH_SUPPORTED */ -#ifdef PNG_STDIO_SUPPORTED -void apng_default_seek (png_structp, size_t); -size_t apng_default_tell (png_structp); -#endif/* PNG_STDIO_SUPPORTED */ -void apng_write_IEND (png_structp); -void apng_write_acTL (png_structp, png_uint_32, png_uint_32); -#ifndef PNG_WRITE_APNG_SUPPORTED -png_uint_32 apng_set_acTL_dummy (png_structp, png_infop, - png_uint_32, png_uint_32); -#endif/* PNG_WRITE_APNG_SUPPORTED */ - -apng_infop -apng_create_info_struct (png_structp pngp) -{ - apng_infop ainfop; - (void)pngp; - if (( ainfop = calloc(1, sizeof (apng_info)) )) - { - apng_set_write_fn(pngp, ainfop, 0, 0, 0, 0, 0); - apng_set_set_acTL_fn(pngp, ainfop, 0); - } - return ainfop; -} - -void -apng_destroy_info_struct (png_structp pngp, apng_infopp ainfopp) -{ - (void)pngp; - if (!( pngp && ainfopp )) - return; - - free((*ainfopp)); -} - -void -apng_seek (png_structp pngp, apng_const_infop ainfop, size_t l) -{ - (*(ainfop->output_seek_fn))(pngp, l); -} - -size_t -apng_tell (png_structp pngp, apng_const_infop ainfop) -{ - return (*(ainfop->output_tell_fn))(pngp); -} - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -void -apng_flush (png_structp pngp, apng_infop ainfop) -{ - if (ainfop->output_flush_fn) - (*(ainfop->output_flush_fn))(pngp); -} - -#ifdef PNG_STDIO_SUPPORTED -void -apng_default_flush (png_structp pngp) -{ - if (!( pngp )) - return; - - fflush((png_FILE_p)png_get_io_ptr); -} -#endif/* PNG_STDIO_SUPPORTED */ -#endif/* PNG_WRITE_FLUSH_SUPPORTED */ - -#ifdef PNG_STDIO_SUPPORTED -void -apng_default_seek (png_structp pngp, size_t l) -{ - if (!( pngp )) - return; - - if (fseek((png_FILE_p)png_get_io_ptr(pngp), (long)l, SEEK_SET) == -1) - png_error(pngp, "Seek Error"); -} - -size_t -apng_default_tell (png_structp pngp) -{ - long l; - - if (!( pngp )) - { - png_error(pngp, "Call to apng_default_tell with NULL pngp failed"); - } - - if (( l = ftell((png_FILE_p)png_get_io_ptr(pngp)) ) == -1) - png_error(pngp, "Tell Error"); - - return (size_t)l; -} -#endif/* PNG_STDIO_SUPPORTED */ - -void -apng_set_write_fn (png_structp pngp, apng_infop ainfop, png_voidp iop, - png_rw_ptr write_f, png_flush_ptr flush_f, - apng_seek_ptr seek_f, apng_tell_ptr tell_f) -{ - if (!( pngp && ainfop )) - return; - - png_set_write_fn(pngp, iop, write_f, flush_f); - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -#ifdef PNG_STDIO_SUPPORTED - if (!flush_f) - ainfop->output_flush_fn = &apng_default_flush; - else -#endif/* PNG_STDIO_SUPPORTED */ - ainfop->output_flush_fn = flush_f; -#endif/* PNG_WRITE_FLUSH_SUPPORTED */ -#ifdef PNG_STDIO_SUPPORTED - if (!seek_f) - ainfop->output_seek_fn = &apng_default_seek; - else -#endif/* PNG_STDIO_SUPPORTED */ - ainfop->output_seek_fn = seek_f; -#ifdef PNG_STDIO_SUPPORTED - if (!seek_f) - ainfop->output_tell_fn = apng_default_tell; - else -#endif/* PNG_STDIO_SUPPORTED */ - ainfop->output_tell_fn = tell_f; -} - -void -apng_write_IEND (png_structp pngp) -{ - png_byte chunkc[] = "IEND"; - png_write_chunk(pngp, chunkc, 0, 0); -} - -void -apng_write_acTL (png_structp pngp, png_uint_32 frames, png_uint_32 plays) -{ - png_byte chunkc[] = "acTL"; - png_byte buf[8]; - png_save_uint_32(buf, frames); - png_save_uint_32(buf + 4, plays); - png_write_chunk(pngp, chunkc, buf, 8); -} - -png_uint_32 -apng_set_acTL (png_structp pngp, png_infop infop, apng_infop ainfop, - png_uint_32 frames, png_uint_32 plays) -{ - (void)pngp; - (void)infop; - if (!( pngp && infop && ainfop )) - return 0; - - ainfop->num_frames = frames; - ainfop->num_plays = plays; - - ainfop->valid |= APNG_INFO_acTL; - - return 1; -} - -void -apng_write_info_before_PLTE (png_structp pngp, png_infop infop, - apng_infop ainfop) -{ - if (!( pngp && infop && ainfop )) - return; - - png_write_info_before_PLTE(pngp, infop); - - if (( ainfop->valid & APNG_INFO_acTL )&&!( ainfop->mode & APNG_WROTE_acTL )) - { - ainfop->start_acTL = apng_tell(pngp, ainfop); - - apng_write_acTL(pngp, 0, 0); - /* modified for runtime dynamic linking */ - (*(ainfop->set_acTL_fn))(pngp, infop, PNG_UINT_31_MAX, 0); - - ainfop->mode |= APNG_WROTE_acTL; - } -} - -void -apng_write_info (png_structp pngp, png_infop infop, - apng_infop ainfop) -{ - apng_write_info_before_PLTE(pngp, infop, ainfop); - png_write_info(pngp, infop); -} - -void -apng_write_end (png_structp pngp, png_infop infop, apng_infop ainfop) -{ - (void)infop; - apng_write_IEND(pngp); - apng_seek(pngp, ainfop, ainfop->start_acTL); - apng_write_acTL(pngp, ainfop->num_frames, ainfop->num_plays); - -#ifdef PNG_WRITE_FLUSH_SUPPORTED -#ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED - apng_flush(pngp, infop); -#endif/* PNG_WRITE_FLUSH_SUPPORTED */ -#endif/* PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED */ -} - -#ifndef PNG_WRITE_APNG_SUPPORTED -png_uint_32 -apng_set_acTL_dummy (png_structp pngp, png_infop infop, - png_uint_32 frames, png_uint_32 plays) -{ - (void)pngp; - (void)infop; - (void)frames; - (void)plays; - return 0; -} -#endif/* PNG_WRITE_APNG_SUPPORTED */ - -/* Dynamic runtime linking capable! (Hopefully.) */ -void -apng_set_set_acTL_fn (png_structp pngp, apng_infop ainfop, - apng_set_acTL_ptr set_acTL_f) -{ - (void)pngp; - if (!ainfop->set_acTL_fn) -#ifndef PNG_WRITE_APNG_SUPPORTED - ainfop->set_acTL_fn = &apng_set_acTL_dummy; -#else - ainfop->set_acTL_fn = &png_set_acTL; -#endif/* PNG_WRITE_APNG_SUPPORTED */ - else - ainfop->set_acTL_fn = set_acTL_f; -} diff --git a/src/apng.h b/src/apng.h deleted file mode 100644 index 8be4708a8..000000000 --- a/src/apng.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -Copyright 2019, James R. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef APNG_H -#define APNG_H - -#ifndef _LARGEFILE64_SOURCE -#define _LARGEFILE64_SOURCE -#endif - -#ifndef _LFS64_LARGEFILE -#define _LFS64_LARGEFILE -#endif - -#ifndef _FILE_OFFSET_BITS -#define _FILE_OFFSET_BITS 0 -#endif - -#include - -typedef struct apng_info_def apng_info; -typedef apng_info * apng_infop; -typedef const apng_info * apng_const_infop; -typedef apng_info * * apng_infopp; - -typedef void (*apng_seek_ptr)(png_structp, size_t); -typedef size_t (*apng_tell_ptr)(png_structp); - -typedef png_uint_32 (*apng_set_acTL_ptr)(png_structp, png_infop, - png_uint_32, png_uint_32); - -apng_infop apng_create_info_struct (png_structp png_ptr); - -void apng_destroy_info_struct (png_structp png_ptr, - apng_infopp info_ptr_ptr); - -/* Call the following functions in place of the libpng counterparts. */ - -png_uint_32 apng_set_acTL (png_structp png_ptr, png_infop info_ptr, - apng_infop ainfo_ptr, - png_uint_32 num_frames, png_uint_32 num_plays); - -void apng_write_info_before_PLTE (png_structp png_ptr, png_infop info_ptr, - apng_infop ainfo_ptr); -void apng_write_info (png_structp png_ptr, png_infop info_ptr, - apng_infop ainfo_ptr); - -void apng_write_end (png_structp png_ptr, png_infop info_ptr, - apng_infop ainfo_ptr); - -void apng_set_write_fn (png_structp png_ptr, apng_infop ainfo_ptr, - png_voidp io_ptr, - png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn, - apng_seek_ptr output_seek_fn, apng_tell_ptr output_tell_fn); - -void apng_set_set_acTL_fn (png_structp png_ptr, apng_infop ainfo_ptr, - apng_set_acTL_ptr set_acTL_fn); - -#endif/* APNG_H */ diff --git a/src/d_netcmd.c b/src/d_netcmd.c index de96bf150..d71e4f88a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -850,12 +850,6 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_zlib_memory); CV_RegisterVar(&cv_zlib_strategy); CV_RegisterVar(&cv_zlib_window_bits); - // APNG variables - CV_RegisterVar(&cv_zlib_levela); - CV_RegisterVar(&cv_zlib_memorya); - CV_RegisterVar(&cv_zlib_strategya); - CV_RegisterVar(&cv_zlib_window_bitsa); - CV_RegisterVar(&cv_apng_delay); // GIF variables CV_RegisterVar(&cv_gif_optimize); CV_RegisterVar(&cv_gif_downscale); diff --git a/src/m_menudefs.c b/src/m_menudefs.c index d3d95a296..7e0dd10d8 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -1227,11 +1227,6 @@ static menuitem_t OP_ScreenshotOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Region Optimizing", &cv_gif_optimize, 90}, {IT_STRING|IT_CVAR, NULL, "Downscaling", &cv_gif_downscale, 95}, - - {IT_STRING|IT_CVAR, NULL, "Memory Level", &cv_zlib_memorya, 90}, - {IT_STRING|IT_CVAR, NULL, "Compression Level", &cv_zlib_levela, 95}, - {IT_STRING|IT_CVAR, NULL, "Strategy", &cv_zlib_strategya, 100}, - {IT_STRING|IT_CVAR, NULL, "Window Size", &cv_zlib_window_bitsa, 105}, }; enum @@ -1241,11 +1236,8 @@ enum op_screenshot_capture = 10, op_screenshot_gif_start = 11, op_screenshot_gif_end = 12, - op_screenshot_apng_start = 13, - op_screenshot_apng_end = 16, }; - static menuitem_t OP_EraseDataMenu[] = { {IT_STRING | IT_CALL, NULL, "Erase Record Data", M_EraseData, 10}, @@ -2821,7 +2813,7 @@ void Screenshot_option_Onchange(void) void Moviemode_mode_Onchange(void) { INT32 i, cstart, cend; - for (i = op_screenshot_gif_start; i <= op_screenshot_apng_end; ++i) + for (i = op_screenshot_gif_start; i <= op_screenshot_gif_end; ++i) OP_ScreenshotOptionsMenu[i].status = IT_DISABLED; switch (cv_moviemode.value) @@ -2830,13 +2822,10 @@ void Moviemode_mode_Onchange(void) cstart = op_screenshot_gif_start; cend = op_screenshot_gif_end; break; - case MM_APNG: - cstart = op_screenshot_apng_start; - cend = op_screenshot_apng_end; - break; default: return; } + for (i = cstart; i <= cend; ++i) OP_ScreenshotOptionsMenu[i].status = IT_STRING|IT_CVAR; } diff --git a/src/m_misc.c b/src/m_misc.c index 9e7ec309e..9d88a1894 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -98,10 +98,6 @@ typedef off_t off64_t; #endif #ifdef PNG_WRITE_SUPPORTED #define USE_PNG // Only actually use PNG if write is supported. - #if defined (PNG_WRITE_APNG_SUPPORTED) //|| !defined(PNG_STATIC) - #include "apng.h" - #define USE_APNG - #endif // See hardware/hw_draw.c for a similar check to this one. #endif #endif @@ -110,7 +106,7 @@ static CV_PossibleValue_t screenshot_cons_t[] = {{0, "Default"}, {1, "HOME"}, {2 consvar_t cv_screenshot_option = {"screenshot_option", "Default", CV_SAVE|CV_CALL, screenshot_cons_t, Screenshot_option_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_screenshot_folder = {"screenshot_folder", "", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; -static CV_PossibleValue_t moviemode_cons_t[] = {{MM_GIF, "GIF"}, {MM_APNG, "aPNG"}, {MM_SCREENSHOT, "Screenshots"}, {0, NULL}}; +static CV_PossibleValue_t moviemode_cons_t[] = {{MM_GIF, "GIF"}, {MM_SCREENSHOT, "Screenshots"}, {0, NULL}}; consvar_t cv_moviemode = {"moviemode_mode", "GIF", CV_SAVE|CV_CALL, moviemode_cons_t, Moviemode_mode_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_movie_option = {"movie_option", "Default", CV_SAVE|CV_CALL, screenshot_cons_t, Moviemode_option_Onchange, 0, NULL, NULL, 0, 0, NULL}; @@ -147,13 +143,6 @@ static CV_PossibleValue_t zlib_window_bits_t[] = { {14, "16k"}, {15, "32k"}, {0, NULL}}; -static CV_PossibleValue_t apng_delay_t[] = { - {1, "1x"}, - {2, "1/2x"}, - {3, "1/3x"}, - {4, "1/4x"}, - {0, NULL}}; - // zlib memory usage is as follows: // (1 << (zlib_window_bits+2)) + (1 << (zlib_level+9)) consvar_t cv_zlib_memory = {"png_memory_level", "7", CV_SAVE, zlib_mem_level_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -161,12 +150,6 @@ consvar_t cv_zlib_level = {"png_compress_level", "(Optimal) 6", CV_SAVE, zlib_le consvar_t cv_zlib_strategy = {"png_strategy", "Normal", CV_SAVE, zlib_strategy_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_zlib_window_bits = {"png_window_size", "32k", CV_SAVE, zlib_window_bits_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_zlib_memorya = {"apng_memory_level", "(Max Memory) 9", CV_SAVE, zlib_mem_level_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_zlib_levela = {"apng_compress_level", "4", CV_SAVE, zlib_level_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_zlib_strategya = {"apng_strategy", "RLE", CV_SAVE, zlib_strategy_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_zlib_window_bitsa = {"apng_window_size", "32k", CV_SAVE, zlib_window_bits_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_apng_delay = {"apng_speed", "1/2x", CV_SAVE, apng_delay_t, NULL, 0, NULL, NULL, 0, 0, NULL}; - boolean takescreenshot = false; // Take a screenshot this tic moviemode_t moviemode = MM_OFF; @@ -201,30 +184,6 @@ INT32 M_MapNumber(char first, char second) // FILE INPUT / OUTPUT // ========================================================================== -// some libcs has no access function, make our own -#if 0 -int access(const char *path, int amode) -{ - int accesshandle = -1; - FILE *handle = NULL; - if (amode == 6) // W_OK|R_OK - handle = fopen(path, "r+"); - else if (amode == 4) // R_OK - handle = fopen(path, "r"); - else if (amode == 2) // W_OK - handle = fopen(path, "a+"); - else if (amode == 0) //F_OK - handle = fopen(path, "rb"); - if (handle) - { - accesshandle = 0; - fclose(handle); - } - return accesshandle; -} -#endif - - // // FIL_WriteFile // @@ -782,8 +741,6 @@ static void M_PNGText(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png char interfacetxt[] = #ifdef HAVE_SDL "SDL"; -#elif defined (_WINDOWS) - "DirectX"; #else "Unknown"; #endif @@ -869,265 +826,12 @@ static inline void M_PNGImage(png_structp png_ptr, png_infop png_info_ptr, PNG_C png_write_image(png_ptr, row_pointers); png_free(png_ptr, (png_voidp)row_pointers); } - -#ifdef USE_APNG -static png_structp apng_ptr = NULL; -static png_infop apng_info_ptr = NULL; -static apng_infop apng_ainfo_ptr = NULL; -static png_FILE_p apng_FILE = NULL; -static png_uint_32 apng_frames = 0; -#ifdef PNG_STATIC // Win32 build have static libpng -#define aPNG_set_acTL png_set_acTL -#define aPNG_write_frame_head png_write_frame_head -#define aPNG_write_frame_tail png_write_frame_tail -#else // outside libpng may not have apng support - -#ifndef PNG_WRITE_APNG_SUPPORTED // libpng header may not have apng patch - -#ifndef PNG_INFO_acTL -#define PNG_INFO_acTL 0x10000L -#endif -#ifndef PNG_INFO_fcTL -#define PNG_INFO_fcTL 0x20000L -#endif -#ifndef PNG_FIRST_FRAME_HIDDEN -#define PNG_FIRST_FRAME_HIDDEN 0x0001 -#endif -#ifndef PNG_DISPOSE_OP_NONE -#define PNG_DISPOSE_OP_NONE 0x00 -#endif -#ifndef PNG_DISPOSE_OP_BACKGROUND -#define PNG_DISPOSE_OP_BACKGROUND 0x01 -#endif -#ifndef PNG_DISPOSE_OP_PREVIOUS -#define PNG_DISPOSE_OP_PREVIOUS 0x02 -#endif -#ifndef PNG_BLEND_OP_SOURCE -#define PNG_BLEND_OP_SOURCE 0x00 -#endif -#ifndef PNG_BLEND_OP_OVER -#define PNG_BLEND_OP_OVER 0x01 -#endif -#ifndef PNG_HAVE_acTL -#define PNG_HAVE_acTL 0x4000 -#endif -#ifndef PNG_HAVE_fcTL -#define PNG_HAVE_fcTL 0x8000L -#endif - -#endif -typedef png_uint_32 (*P_png_set_acTL) (png_structp png_ptr, - png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays); -typedef void (*P_png_write_frame_head) (png_structp png_ptr, - png_infop info_ptr, png_bytepp row_pointers, - png_uint_32 width, png_uint_32 height, - png_uint_32 x_offset, png_uint_32 y_offset, - png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, - png_byte blend_op); - -typedef void (*P_png_write_frame_tail) (png_structp png_ptr, - png_infop info_ptr); -static P_png_set_acTL aPNG_set_acTL = NULL; -static P_png_write_frame_head aPNG_write_frame_head = NULL; -static P_png_write_frame_tail aPNG_write_frame_tail = NULL; -#endif - -static inline boolean M_PNGLib(void) -{ -#ifdef PNG_STATIC // Win32 build have static libpng - return true; -#else - static void *pnglib = NULL; - if (aPNG_set_acTL && aPNG_write_frame_head && aPNG_write_frame_tail) - return true; - if (pnglib) - return false; -#ifdef _WIN32 - pnglib = GetModuleHandleA("libpng.dll"); - if (!pnglib) - pnglib = GetModuleHandleA("libpng12.dll"); - if (!pnglib) - pnglib = GetModuleHandleA("libpng13.dll"); -#elif defined (HAVE_SDL) -#ifdef __APPLE__ - pnglib = hwOpen("libpng.dylib"); -#else - pnglib = hwOpen("libpng.so"); -#endif -#endif - if (!pnglib) - return false; -#ifdef HAVE_SDL - aPNG_set_acTL = hwSym("png_set_acTL", pnglib); - aPNG_write_frame_head = hwSym("png_write_frame_head", pnglib); - aPNG_write_frame_tail = hwSym("png_write_frame_tail", pnglib); -#endif -#ifdef _WIN32 - aPNG_set_acTL = GetProcAddress("png_set_acTL", pnglib); - aPNG_write_frame_head = GetProcAddress("png_write_frame_head", pnglib); - aPNG_write_frame_tail = GetProcAddress("png_write_frame_tail", pnglib); -#endif - return (aPNG_set_acTL && aPNG_write_frame_head && aPNG_write_frame_tail); -#endif -} - -static void M_PNGFrame(png_structp png_ptr, png_infop png_info_ptr, png_bytep png_buf) -{ - png_uint_32 pitch = png_get_rowbytes(png_ptr, png_info_ptr); - PNG_CONST png_uint_32 height = vid.height; - png_bytepp row_pointers = png_malloc(png_ptr, height* sizeof (png_bytep)); - png_uint_32 y; - png_uint_16 framedelay = (png_uint_16)cv_apng_delay.value; - - apng_frames++; - - for (y = 0; y < height; y++) - { - row_pointers[y] = png_buf; - png_buf += pitch; - } - -#ifndef PNG_STATIC - if (aPNG_write_frame_head) -#endif - aPNG_write_frame_head(apng_ptr, apng_info_ptr, row_pointers, - vid.width, /* width */ - height, /* height */ - 0, /* x offset */ - 0, /* y offset */ - framedelay, TICRATE,/* delay numerator and denominator */ - PNG_DISPOSE_OP_BACKGROUND, /* dispose */ - PNG_BLEND_OP_SOURCE /* blend */ - ); - - png_write_image(png_ptr, row_pointers); - -#ifndef PNG_STATIC - if (aPNG_write_frame_tail) -#endif - aPNG_write_frame_tail(apng_ptr, apng_info_ptr); - - png_free(png_ptr, (png_voidp)row_pointers); -} - -static void M_PNGfix_acTL(png_structp png_ptr, png_infop png_info_ptr, - apng_infop png_ainfo_ptr) -{ - apng_set_acTL(png_ptr, png_info_ptr, png_ainfo_ptr, apng_frames, 0); - -#ifndef NO_PNG_DEBUG - png_debug(1, "in png_write_acTL\n"); -#endif -} - -static boolean M_SetupaPNG(png_const_charp filename, png_bytep pal) -{ - apng_FILE = fopen(filename,"wb+"); // + mode for reading - if (!apng_FILE) - { - CONS_Debug(DBG_RENDER, "M_StartMovie: Error on opening %s for write\n", filename); - return false; - } - - apng_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, - PNG_error, PNG_warn); - if (!apng_ptr) - { - CONS_Debug(DBG_RENDER, "M_StartMovie: Error on initialize libpng\n"); - fclose(apng_FILE); - remove(filename); - return false; - } - - apng_info_ptr = png_create_info_struct(apng_ptr); - if (!apng_info_ptr) - { - CONS_Debug(DBG_RENDER, "M_StartMovie: Error on allocate for libpng\n"); - png_destroy_write_struct(&apng_ptr, NULL); - fclose(apng_FILE); - remove(filename); - return false; - } - - apng_ainfo_ptr = apng_create_info_struct(apng_ptr); - if (!apng_ainfo_ptr) - { - CONS_Debug(DBG_RENDER, "M_StartMovie: Error on allocate for apng\n"); - png_destroy_write_struct(&apng_ptr, &apng_info_ptr); - fclose(apng_FILE); - remove(filename); - return false; - } - - png_init_io(apng_ptr, apng_FILE); - -#ifdef PNG_SET_USER_LIMITS_SUPPORTED - png_set_user_limits(apng_ptr, MAXVIDWIDTH, MAXVIDHEIGHT); -#endif - - //png_set_filter(apng_ptr, 0, PNG_ALL_FILTERS); - - png_set_compression_level(apng_ptr, cv_zlib_levela.value); - png_set_compression_mem_level(apng_ptr, cv_zlib_memorya.value); - png_set_compression_strategy(apng_ptr, cv_zlib_strategya.value); - png_set_compression_window_bits(apng_ptr, cv_zlib_window_bitsa.value); - - M_PNGhdr(apng_ptr, apng_info_ptr, vid.width, vid.height, pal); - - M_PNGText(apng_ptr, apng_info_ptr, true); - - apng_set_set_acTL_fn(apng_ptr, apng_ainfo_ptr, aPNG_set_acTL); - - apng_set_acTL(apng_ptr, apng_info_ptr, apng_ainfo_ptr, PNG_UINT_31_MAX, 0); - - apng_write_info(apng_ptr, apng_info_ptr, apng_ainfo_ptr); - - apng_frames = 0; - - return true; -} -#endif #endif // ========================================================================== // MOVIE MODE // ========================================================================== #if NUMSCREENS > 2 -static inline moviemode_t M_StartMovieAPNG(const char *pathname) -{ -#ifdef USE_APNG - UINT8 *palette; - const char *freename = NULL; - boolean ret = false; - - if (!M_PNGLib()) - { - CONS_Alert(CONS_ERROR, "Couldn't create aPNG: libpng not found\n"); - return MM_OFF; - } - - if (!(freename = Newsnapshotfile(pathname,"png"))) - { - CONS_Alert(CONS_ERROR, "Couldn't create aPNG: no slots open in %s\n", pathname); - return MM_OFF; - } - - if (rendermode == render_soft) M_CreateScreenShotPalette(); - ret = M_SetupaPNG(va(pandf,pathname,freename), (palette = screenshot_palette)); - - if (!ret) - { - CONS_Alert(CONS_ERROR, "Couldn't create aPNG: error creating %s in %s\n", freename, pathname); - return MM_OFF; - } - return MM_APNG; -#else - // no APNG support exists - (void)pathname; - CONS_Alert(CONS_ERROR, "Couldn't create aPNG: this build lacks aPNG support\n"); - return MM_OFF; -#endif -} static inline moviemode_t M_StartMovieGIF(const char *pathname) { @@ -1186,9 +890,6 @@ void M_StartMovie(void) case MM_GIF: moviemode = M_StartMovieGIF(pathname); break; - case MM_APNG: - moviemode = M_StartMovieAPNG(pathname); - break; case MM_SCREENSHOT: moviemode = MM_SCREENSHOT; break; @@ -1196,14 +897,10 @@ void M_StartMovie(void) return; } - if (moviemode == MM_APNG) - CONS_Printf(M_GetText("Movie mode enabled (%s).\n"), "aPNG"); - else if (moviemode == MM_GIF) + if (moviemode == MM_GIF) CONS_Printf(M_GetText("Movie mode enabled (%s).\n"), "GIF"); else if (moviemode == MM_SCREENSHOT) CONS_Printf(M_GetText("Movie mode enabled (%s).\n"), "screenshots"); - - //singletics = (moviemode != MM_OFF); #endif } @@ -1226,44 +923,6 @@ void M_SaveFrame(void) case MM_GIF: GIF_frame(); return; - case MM_APNG: -#ifdef USE_APNG - { - UINT8 *linear = NULL; - if (!apng_FILE) // should not happen!! - { - moviemode = MM_OFF; - return; - } - - if (rendermode == render_soft) - { - // munge planar buffer to linear - linear = vid.screens[2]; - I_ReadScreen(linear, 1); - } -#ifdef HWRENDER - else if (rendermode == render_opengl) - { - linear = HWR_GetScreenshot(1); - } -#endif - M_PNGFrame(apng_ptr, apng_info_ptr, (png_bytep)linear); -#ifdef HWRENDER - if (rendermode != render_soft && linear) - free(linear); -#endif - - if (apng_frames == PNG_UINT_31_MAX) - { - CONS_Alert(CONS_NOTICE, M_GetText("Max movie size reached\n")); - M_StopMovie(); - } - } -#else - moviemode = MM_OFF; -#endif - return; default: return; } @@ -1279,27 +938,6 @@ void M_StopMovie(void) if (!GIF_close()) return; break; - case MM_APNG: -#ifdef USE_APNG - if (!apng_FILE) - return; - - if (apng_frames) - { - M_PNGfix_acTL(apng_ptr, apng_info_ptr, apng_ainfo_ptr); - apng_write_end(apng_ptr, apng_info_ptr, apng_ainfo_ptr); - } - - png_destroy_write_struct(&apng_ptr, &apng_info_ptr); - - fclose(apng_FILE); - apng_FILE = NULL; - CONS_Printf("aPNG closed; wrote %u frames\n", (UINT32)apng_frames); - apng_frames = 0; - break; -#else - return; -#endif case MM_SCREENSHOT: break; default: diff --git a/src/m_misc.h b/src/m_misc.h index 2cdad977a..ab7c8986f 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -27,7 +27,6 @@ extern "C" { typedef enum { MM_OFF = 0, - MM_APNG, MM_GIF, MM_SCREENSHOT } moviemode_t; @@ -36,8 +35,6 @@ extern moviemode_t moviemode; extern consvar_t cv_screenshot_option, cv_screenshot_folder; extern consvar_t cv_moviemode, cv_movie_folder, cv_movie_option; extern consvar_t cv_zlib_memory, cv_zlib_level, cv_zlib_strategy, cv_zlib_window_bits; -extern consvar_t cv_zlib_memorya, cv_zlib_levela, cv_zlib_strategya, cv_zlib_window_bitsa; -extern consvar_t cv_apng_delay; void M_StartMovie(void); void M_SaveFrame(void); diff --git a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj index bbdbff9ed..a8b67f1b2 100644 --- a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj @@ -40,7 +40,6 @@ 1E44AF0D0B67CDE900BAD059 /* m_fixed.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AEFE0B67CDE900BAD059 /* m_fixed.c */; }; 1E44AF0F0B67CDE900BAD059 /* m_menu.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AF000B67CDE900BAD059 /* m_menu.c */; }; 1E44AF110B67CDE900BAD059 /* m_misc.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AF020B67CDE900BAD059 /* m_misc.c */; }; - 1E44AF110B67CDE900BAD059 /* apng.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AF020B67CDE900BAD059 /* apng.c */; }; 1E44AF130B67CDE900BAD059 /* m_random.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AF040B67CDE900BAD059 /* m_random.c */; }; 1E44AF1A0B67CE2A00BAD059 /* info.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AF180B67CE2A00BAD059 /* info.c */; }; 1E44AF1E0B67CE3600BAD059 /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 1E44AF1C0B67CE3600BAD059 /* md5.c */; }; @@ -242,9 +241,7 @@ 1E44AF000B67CDE900BAD059 /* m_menu.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = m_menu.c; path = ../../m_menu.c; sourceTree = SOURCE_ROOT; }; 1E44AF010B67CDE900BAD059 /* m_menu.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = m_menu.h; path = ../../m_menu.h; sourceTree = SOURCE_ROOT; }; 1E44AF020B67CDE900BAD059 /* m_misc.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = m_misc.c; path = ../../m_misc.c; sourceTree = SOURCE_ROOT; }; - 1E44AF020B67CDE900BAD059 /* apng.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = apng.c; path = ../../m_misc.c; sourceTree = SOURCE_ROOT; }; 1E44AF030B67CDE900BAD059 /* m_misc.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = m_misc.h; path = ../../m_misc.h; sourceTree = SOURCE_ROOT; }; - 1E44AF020B67CDE900BAD059 /* apng.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = apng.h; path = ../../m_misc.c; sourceTree = SOURCE_ROOT; }; 1E44AF040B67CDE900BAD059 /* m_random.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = m_random.c; path = ../../m_random.c; sourceTree = SOURCE_ROOT; }; 1E44AF050B67CDE900BAD059 /* m_random.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = m_random.h; path = ../../m_random.h; sourceTree = SOURCE_ROOT; }; 1E44AF060B67CDE900BAD059 /* m_swap.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = m_swap.h; path = ../../m_swap.h; sourceTree = SOURCE_ROOT; }; @@ -661,8 +658,6 @@ 1E44AEFF0B67CDE900BAD059 /* m_fixed.h */, 1E44AF020B67CDE900BAD059 /* m_misc.c */, 1E44AF030B67CDE900BAD059 /* m_misc.h */, - 1E44AF020B67CDE900BAD059 /* apng.c */, - 1E44AF030B67CDE900BAD059 /* apng.h */, 676BB51C0E0DE06100C95963 /* m_queue.c */, 676BB51D0E0DE06100C95963 /* m_queue.h */, 1E44AF040B67CDE900BAD059 /* m_random.c */, From a25b3f6e59634ceba9d5bc75793a6c33ab5d4c67 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 26 Sep 2025 21:41:04 +0200 Subject: [PATCH 03/39] oops lmfao this got lost by accident fixes models kek --- src/Makefile.d/features.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.d/features.mk b/src/Makefile.d/features.mk index 427b5417f..ab02efc4b 100644 --- a/src/Makefile.d/features.mk +++ b/src/Makefile.d/features.mk @@ -51,6 +51,7 @@ endif ifdef LINUX opts+=-D_LARGEFILE64_SOURCE endif +opts+=-DHAVE_PNG endif endif From 2d5664b54a14aebbe2d6fd6c297daa6d7e3cfccc Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Fri, 26 Sep 2025 23:59:53 +0200 Subject: [PATCH 04/39] Fix VID_BlitLinearScreen's SSE version ignoring width (closes #128) --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 822eb5a1c..17b6a22ba 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -615,7 +615,7 @@ static void CV_constextsize_OnChange(void) void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT32 height, size_t srcrowbytes, size_t destrowbytes) { - if (srcrowbytes == destrowbytes) + if (srcrowbytes == destrowbytes && srcrowbytes == width) { size_t i = srcrowbytes * height; #if defined(__SSE__) From a6d6c03a58f1f0c4f04111d7b22e6d4102fc29bf Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 00:22:39 +0200 Subject: [PATCH 05/39] fix compiler warning --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 17b6a22ba..1522d9fd9 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -615,7 +615,7 @@ static void CV_constextsize_OnChange(void) void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT32 height, size_t srcrowbytes, size_t destrowbytes) { - if (srcrowbytes == destrowbytes && srcrowbytes == width) + if (srcrowbytes == destrowbytes && srcrowbytes == (size_t)width) { size_t i = srcrowbytes * height; #if defined(__SSE__) From 0efedae2c3ffbdbcd422bdb358f23e5b6f4aa94e Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 00:16:45 +0200 Subject: [PATCH 06/39] remove vid.rowbytes it was just vid.width lel --- src/d_main.c | 2 +- src/r_draw_span.cpp | 2 +- src/screen.h | 1 - src/sdl/i_video.c | 39 +++++++++++++++++++------------------ src/v_video.c | 47 ++++++++++++++++++++++++--------------------- src/y_inter.c | 2 +- 6 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 061be7537..afd480565 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -610,7 +610,7 @@ static boolean D_Display(void) { if (rendermode == render_soft) { - VID_BlitLinearScreen(vid.screens[0], vid.screens[1], vid.width, vid.height, vid.width, vid.rowbytes); + VID_BlitLinearScreen(vid.screens[0], vid.screens[1], vid.width, vid.height, vid.width, vid.width); } lastdraw = false; diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 818b19182..92d64fd6e 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -104,7 +104,7 @@ static void R_DrawSpanTemplate(drawspandata_t* ds) UINT8 * restrict dest = R_Address(ds->x1, ds->y); UINT8 * restrict dsrc; - const UINT8 * restrict deststop = vid.screens[0] + vid.rowbytes * vid.height; + const UINT8 * restrict deststop = vid.screens[0] + vid.width * vid.height; if (dest+8 > deststop) { diff --git a/src/screen.h b/src/screen.h index 665466dde..e860be6fa 100644 --- a/src/screen.h +++ b/src/screen.h @@ -58,7 +58,6 @@ typedef struct viddef_s // screens[4] = fade screen end, postimage tempoarary buffer UINT8 *buffer; // invisible screens buffer - size_t rowbytes; // bytes per scanline of the VIDEO mode INT32 width; // PIXELS per scanline INT32 height; boolean recalc; // if true, recalc vid-based stuff diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index db2c8d90a..86615dfe2 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1207,7 +1207,7 @@ void I_OsPolling(void) if (consolevent) I_GetConsoleEvents(); - if (SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == (SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)) + if (SDL_WasInit(SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER) == (SDL_INIT_JOYSTICK|SDL_INIT_GAMECONTROLLER)) { SDL_GameControllerUpdate(); @@ -1415,7 +1415,7 @@ void I_ReadScreen(UINT8 * restrict scr, INT32 scale) if (rendermode != render_soft) I_Error ("I_ReadScreen: called while in non-software mode"); else if (scale == 1) - VID_BlitLinearScreen(vid.screens[0], scr, vid.width, vid.height, vid.rowbytes, vid.rowbytes); + VID_BlitLinearScreen(vid.screens[0], scr, vid.width, vid.height, vid.width, vid.width); else { UINT8 * restrict source = vid.screens[0]; @@ -1546,6 +1546,7 @@ INT32 VID_SetMode(INT32 modeNum) // just set the desktop resolution as a fallback SDL_DisplayMode mode; SDL_GetWindowDisplayMode(window, &mode); + if (mode.w >= 2048) { vid.width = 1920; @@ -1556,6 +1557,7 @@ INT32 VID_SetMode(INT32 modeNum) vid.width = mode.w; vid.height = mode.h; } + vid.modenum = -1; } @@ -1594,8 +1596,11 @@ static SDL_bool Impl_CreateContext(void) if (rendermode == render_soft) { int flags = 0; // Use this to set SDL_RENDERER_* flags now + if (usesdl2soft) + { flags |= SDL_RENDERER_SOFTWARE; + } else if (cv_vidwait.value) { #if SDL_VERSION_ATLEAST(2, 0, 18) @@ -1650,9 +1655,9 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) flags |= SDL_WINDOW_OPENGL; if (msaa) - { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa); + { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa); } // Without a 24-bit depth buffer many visuals are ruined by z-fighting. @@ -1667,8 +1672,7 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) #endif // Create a window - window = SDL_CreateWindow("SRB2Kart "VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - realwidth, realheight, flags); + window = SDL_CreateWindow("SRB2Kart "VERSIONSTRING, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, realwidth, realheight, flags); if (window == NULL) { @@ -1694,12 +1698,10 @@ static void Impl_VideoSetupBuffer(void) // Set up game's software render buffer size_t size; - vid.rowbytes = vid.width; - if (vid.buffer) free(vid.buffer); - size = vid.rowbytes*vid.height * NUMSCREENS; + size = vid.width*vid.height * NUMSCREENS; vid.buffer = calloc(size, NUMSCREENS); @@ -1709,8 +1711,7 @@ static void Impl_VideoSetupBuffer(void) } } -static FILE * -OpenRendererFile (const char * mode) +static FILE * OpenRendererFile(const char * mode) { char * path = va(pandf,srb2home,"renderer.txt"); return fopen(path, mode); @@ -1727,11 +1728,11 @@ void I_StartupGraphics(void) if (graphics_started) return; - COM_AddCommand ("vid_nummodes", VID_Command_NumModes_f); - COM_AddCommand ("vid_modelist", VID_Command_ModeList_f); - COM_AddCommand ("vid_mode", VID_Command_Mode_f); - CV_RegisterVar (&cv_vidwait); - CV_RegisterVar (&cv_stretch); + COM_AddCommand("vid_nummodes", VID_Command_NumModes_f); + COM_AddCommand("vid_modelist", VID_Command_ModeList_f); + COM_AddCommand("vid_mode", VID_Command_Mode_f); + CV_RegisterVar(&cv_vidwait); + CV_RegisterVar(&cv_stretch); disable_mouse = M_CheckParm("-nomouse"); disable_fullscreen = M_CheckParm("-win") ? 1 : 0; @@ -1830,7 +1831,6 @@ void I_StartupGraphics(void) if (strcasecmp(word, "a2c") == 0) { a2c = true; - CONS_Printf("Using a2c because it was specified to be used earlier\n"); } } @@ -1984,7 +1984,8 @@ static void Impl_SetVsync(void) SDL_RenderSetVSync(renderer, cv_vidwait.value); #endif #ifdef HWRENDER - if (!renderer && rendermode == render_opengl && sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) + if (!renderer && rendermode == render_opengl && + sdlglcontext != NULL && SDL_GL_GetCurrentContext() == sdlglcontext) { SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); } diff --git a/src/v_video.c b/src/v_video.c index 1522d9fd9..9faa6dcb4 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -612,8 +612,7 @@ static void CV_constextsize_OnChange(void) // -------------------------------------------------------------------------- // Copy a rectangular area from one bitmap to another (8bpp) // -------------------------------------------------------------------------- -void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT32 height, size_t srcrowbytes, - size_t destrowbytes) +void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT32 height, size_t srcrowbytes, size_t destrowbytes) { if (srcrowbytes == destrowbytes && srcrowbytes == (size_t)width) { @@ -790,7 +789,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca if (!desttop) return; - deststop = desttop + vid.rowbytes * vid.height; + deststop = desttop + vid.width * vid.height; if (scrn & V_NOSCALESTART) { @@ -1041,7 +1040,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ if (!desttop) return; - deststop = desttop + vid.rowbytes * vid.height; + deststop = desttop + vid.width * vid.height; if (scrn & V_NOSCALESTART) { @@ -1191,7 +1190,7 @@ void V_DrawBlock(INT32 x, INT32 y, INT32 scrn, INT32 width, INT32 height, const #endif dest = vid.screens[scrn] + y*vid.width + x; - deststop = vid.screens[scrn] + vid.rowbytes * vid.height; + deststop = vid.screens[scrn] + vid.width * vid.height; while (height--) { @@ -1288,7 +1287,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) h = vid.height-y; dest = vid.screens[0] + y*vid.width + x; - deststop = vid.screens[0] + vid.rowbytes * vid.height; + deststop = vid.screens[0] + vid.width * vid.height; if (alphalevel) { @@ -1573,7 +1572,7 @@ void V_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 c) h = w; dest = vid.screens[0] + y*vid.width + x; - deststop = vid.screens[0] + vid.rowbytes * vid.height; + deststop = vid.screens[0] + vid.width * vid.height; c &= 255; @@ -1645,7 +1644,7 @@ void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) dupx = dupy = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); dest = vid.screens[0] + y*dupy*vid.width + x*dupx; - deststop = vid.screens[0] + vid.rowbytes * vid.height; + deststop = vid.screens[0] + vid.width * vid.height; // from V_DrawScaledPatch if (vid.width != BASEVIDWIDTH * dupx) @@ -1767,8 +1766,10 @@ void V_DrawVhsEffect(boolean rewind) upbary -= renderdeltatics * (vid.dupy * (rewind ? 3 : 1.8f)); downbary += renderdeltatics * (vid.dupy * (rewind ? 2 : 1)); - if (upbary < -barsize*FRACUNIT) upbary = vid.height< vid.height< vid.height<>FRACBITS, dby = downbary>>FRACBITS; @@ -1790,18 +1791,20 @@ void V_DrawVhsEffect(boolean rewind) thismapstart -= (2<= dby && y < dby+barsize) { thismapstart -= (2<= vid.height-2 && offs > 0) offs = 0; + if ((y == 0 && offs < 0) || (y >= vid.height-2 && offs > 0)) + offs = 0; - for (x = min(pos+vid.rowbytes*2, vid.rowbytes*vid.height); pos < x; pos++) + for (x = min(pos+(size_t)vid.width*2, (size_t)vid.width*vid.height); pos < x; pos++) { tmp[pos] = thismapstart[buf[pos+offs]]; #ifdef HQ_VHS @@ -1810,7 +1813,7 @@ void V_DrawVhsEffect(boolean rewind) } } - memcpy(buf, tmp, vid.rowbytes*vid.height); + memcpy(buf, tmp, vid.width*vid.height); } // @@ -1825,11 +1828,11 @@ void V_DrawVhsEffect(boolean rewind) void V_DrawFadeScreen(UINT16 color, UINT8 strength) { #ifdef HWRENDER - if (rendermode != render_soft && rendermode != render_none) - { - HWR_FadeScreenMenuBack(color, strength); - return; - } + if (rendermode == render_opengl) + { + HWR_FadeScreenMenuBack(color, strength); + return; + } #endif const UINT8 *fadetable = @@ -1838,7 +1841,7 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength) : ((color & 0xFF00) // Color is not palette index? ? ((UINT8 *)colormaps + strength*256) // Do COLORMAP fade. : ((UINT8 *)transtables + ((9-strength)< Date: Sat, 27 Sep 2025 01:43:32 +0200 Subject: [PATCH 07/39] handle rotated patch img buffer allocations better just always initally allocate it with 1mb size, this is enough for just about everything including gigantamax eevee if thats not enough, just double our capacity until it fits what we need this way we save effectively reallocating 99% of the time this prob can be used for out imgbuf in r_patch, but that needs it allocation size be handled a little differently --- src/r_patchrotation.c | 45 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/r_patchrotation.c b/src/r_patchrotation.c index 15a54d88e..862febf2f 100644 --- a/src/r_patchrotation.c +++ b/src/r_patchrotation.c @@ -122,6 +122,28 @@ static void RotatedPatch_CalculateDimensions( *newheight = max(height, max(h1, h2)); } +static void RotatedPatch_AllocImgBuf(UINT16 **buf, size_t size, size_t *capacity) +{ + if (!*buf) + { + *buf = Z_Malloc(*capacity, PU_STATIC, NULL); + } + + size_t allocsize = size * sizeof(UINT16); + + // make sure our buffer always fits with what we need + if (allocsize > *capacity) + { + while (*capacity < allocsize) + *capacity *= 2; + + Z_Free(*buf); + *buf = Z_Malloc(*capacity, PU_STATIC, NULL); + } + + //CONS_Printf("RotatedPatch_AllocBuf: Allocated %.2f KB\n", *capacity / 1024.0); +} + void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) { UINT32 i; @@ -130,7 +152,7 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle static UINT16 *rawdst = NULL, *rawconv = NULL; UINT16 *rawout; size_t size; - static size_t dst_capacity = 0, conv_capacity = 0; + static size_t dst_capacity = (1024 * 1024), conv_capacity = (1024 * 1024); // 1 MB should be enough for most cases INT32 bflip = (flip != 0x00); INT32 width = patch->width; @@ -184,13 +206,7 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle if (!size) size = (width * height); - if (size > dst_capacity) - { - // no realloc since we dont care about the old data - Z_Free(rawdst); - rawdst = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL); - dst_capacity = size; - } + RotatedPatch_AllocImgBuf(&rawdst, size, &dst_capacity); for (i = 0; i < size; i++) rawdst[i] = 0xFF00; @@ -234,17 +250,8 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle size = (width * height); - if (size > conv_capacity) - { - // no realloc since we dont care about the old data - Z_Free(rawconv); - rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); - conv_capacity = size; - } - else - { - memset(rawconv, 0, conv_capacity * sizeof(UINT16)); - } + RotatedPatch_AllocImgBuf(&rawconv, size, &conv_capacity); + memset(rawconv, 0, conv_capacity * sizeof(UINT16)); src = &rawdst[(miny * newwidth) + minx]; dest = rawconv; From f05ac73df66f45c70d4481b2c62f892e4cd18f92 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 03:21:12 +0200 Subject: [PATCH 08/39] cache this stuff slight sprites optimization --- src/hardware/hw_main.cpp | 54 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index d634ed5d9..6a0576284 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3645,7 +3645,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) float towtop, towbot, towmult; float bheight; float realheight, heightmult; - const sector_t *sector = spr->mobj->subsector->sector; + mobj_t *sprmo = spr->mobj; + const sector_t *sector = sprmo->subsector->sector; const lightlist_t *list = sector->lightlist; float endrealtop, endrealbot, endtop, endbot; float endbheight; @@ -3665,9 +3666,9 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) // Draw shadow BEFORE sprite if (UNLIKELY(cv_shadow.value // Shadows enabled - && (spr->mobj->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. - && !(spr->mobj->flags2 & MF2_DEBRIS) // Debris have no corona or shadow. - && (spr->mobj->z >= spr->mobj->floorz))) // Without this, your shadow shows on the floor, even after you die and fall through the ground. + && (sprmo->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. + && !(sprmo->flags2 & MF2_DEBRIS) // Debris have no corona or shadow. + && (sprmo->z >= sprmo->floorz))) // Without this, your shadow shows on the floor, even after you die and fall through the ground. { //////////////////// // SHADOW SPRITE! // @@ -3729,24 +3730,24 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) memcpy(wallVerts, baseWallVerts, sizeof(baseWallVerts)); INT32 blendmode; - if (spr->mobj->frame & FF_BLENDMASK) - blendmode = ((spr->mobj->frame & FF_BLENDMASK) >> FF_BLENDSHIFT) + 1; + if (sprmo->frame & FF_BLENDMASK) + blendmode = ((sprmo->frame & FF_BLENDMASK) >> FF_BLENDSHIFT) + 1; else - blendmode = spr->mobj->blendmode; + blendmode = sprmo->blendmode; if (UNLIKELY(!cv_translucency.value)) // translucency disabled { Surf.PolyColor.s.alpha = 0xFF; blend = PF_Translucent|PF_Occlude; } - else if (spr->mobj->flags2 & MF2_SHADOW) + else if (sprmo->flags2 & MF2_SHADOW) { Surf.PolyColor.s.alpha = 0x40; blend = HWR_GetBlendModeFlag(blendmode); } - else if (spr->mobj->frame & FF_TRANSMASK) + else if (sprmo->frame & FF_TRANSMASK) { - INT32 trans = (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; + INT32 trans = (sprmo->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; blend = HWR_SurfaceBlend(blendmode, trans, &Surf); } else @@ -3759,8 +3760,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) blend = HWR_GetBlendModeFlag(blendmode)|PF_Occlude; } - if (cv_playerfade.value && spr->mobj->player) - Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + if (cv_playerfade.value && sprmo->player) + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); if (HWR_UseShader()) { @@ -3777,11 +3778,11 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) i = 0; temp = FloatToFixed(realtop); - lightset = HWR_OverrideObjectLightLevel(spr->mobj, &lightlevel); + lightset = HWR_OverrideObjectLightLevel(sprmo, &lightlevel); for (i = 1; i < sector->numlights; i++) { - const fixed_t h = P_GetLightZAt(§or->lightlist[i], spr->mobj->x, spr->mobj->y); + const fixed_t h = P_GetLightZAt(§or->lightlist[i], sprmo->x, sprmo->y); if (!(h <= temp)) continue; @@ -3845,7 +3846,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) wallVerts[1].y = endbot; // The x and y only need to be adjusted in the case that it's not a papersprite - if (cv_glspritebillboarding.value && spr->mobj && !papersprite) + if (cv_glspritebillboarding.value && sprmo && !papersprite) { // Get the x and z of the vertices so billboarding draws correctly realheight = realbot - realtop; @@ -3867,7 +3868,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) wallVerts[1].z = baseWallVerts[2].z + (baseWallVerts[2].z - baseWallVerts[1].z) * heightmult; } - HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector) && !(spr->mobj->frame & FF_FULLBRIGHT)); + HWR_Lighting(&Surf, lightlevel, colormap, P_SectorUsesDirectionalLighting(sector) && !(sprmo->frame & FF_FULLBRIGHT)); Surf.PolyColor.s.alpha = alpha; @@ -3916,7 +3917,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) INT32 shader = SHADER_NONE; - const mobj_t *sprmo = spr->mobj; + mobj_t *sprmo = spr->mobj; if (UNLIKELY(!sprmo || !sprmo->subsector)) return; @@ -4007,9 +4008,9 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) // colormap test INT32 lightlevel = 255; - const boolean lightset = HWR_OverrideObjectLightLevel(spr->mobj, &lightlevel); + const boolean lightset = HWR_OverrideObjectLightLevel(sprmo, &lightlevel); extracolormap_t *colormap = sector->extra_colormap; - const boolean fullbright = R_ThingIsFullBright(spr->mobj); + const boolean fullbright = R_ThingIsFullBright(sprmo); if (!lightset) { @@ -4051,7 +4052,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) } if (cv_playerfade.value && sprmo->player) - Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(spr->mobj), Surf.PolyColor.s.alpha); + Surf.PolyColor.s.alpha = FixedMul(R_DoPlayerFade(sprmo), Surf.PolyColor.s.alpha); if (HWR_UseShader()) { @@ -4189,7 +4190,7 @@ static int CompareVisSprites(const void *p1, const void *p2) idiff = transparency1 - transparency2; if (idiff != 0) return idiff; - fdiff = spr2->tz - spr1->tz;// this order seems correct when checking with apitrace. Back to front. + fdiff = spr2->tz - spr1->tz; // this order seems correct when checking with apitrace. Back to front. if (fabsf(fdiff) < 1.0E-36f) return spr1->dispoffset - spr2->dispoffset;// smallest dispoffset first if sprites are at (almost) same location. else if (fdiff > 0) @@ -4675,6 +4676,7 @@ static void HWR_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE spriteinfo_t *sprinfo; #endif + skin_t *sprskin = NULL; size_t lumpoff; unsigned rot; UINT8 flip; @@ -4750,9 +4752,11 @@ static void HWR_ProjectSprite(mobj_t *thing) //Fab : 02-08-98: 'skin' override spritedef currently used for skin if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) { - sprdef = &K_GetMobjSkin(thing)->spritedef; + sprskin = K_GetMobjSkin(thing); + + sprdef = &sprskin->spritedef; #ifdef ROTSPRITE - sprinfo = &K_GetMobjSkin(thing)->sprinfo; + sprinfo = &sprskin->sprinfo; #endif } else @@ -4837,8 +4841,8 @@ static void HWR_ProjectSprite(mobj_t *thing) flip ^= (1<skin || thing->localskin) && K_GetMobjSkin(thing)->flags & SF_HIRES) - this_scale *= FixedToFloat(K_GetMobjSkin(thing)->highresscale); + if (sprskin && (sprskin->flags & SF_HIRES)) + this_scale *= FixedToFloat(sprskin->highresscale); spr_width = spritecachedinfo[lumpoff].width; spr_height = spritecachedinfo[lumpoff].height; From a6dce95ecab165a2b8391e7cccabf30af6dc9e73 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 16:26:32 +0200 Subject: [PATCH 09/39] delet vid.buffer unused memory allocation --- src/android/i_video.c | 1 - src/screen.h | 1 - src/sdl/i_video.c | 39 ++------------------------------------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/src/android/i_video.c b/src/android/i_video.c index 23c06dfb2..f3054038e 100644 --- a/src/android/i_video.c +++ b/src/android/i_video.c @@ -42,7 +42,6 @@ INT32 VID_SetMode(INT32 modenum) vid.modenum = 0; vid.width = 320; vid.height = 240; - vid.buffer = android_surface; return 0; } diff --git a/src/screen.h b/src/screen.h index e860be6fa..ce72e168e 100644 --- a/src/screen.h +++ b/src/screen.h @@ -57,7 +57,6 @@ typedef struct viddef_s // screens[3] = fade screen start // screens[4] = fade screen end, postimage tempoarary buffer - UINT8 *buffer; // invisible screens buffer INT32 width; // PIXELS per scanline INT32 height; boolean recalc; // if true, recalc vid-based stuff diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 86615dfe2..78f38f2d3 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -198,7 +198,6 @@ static INT32 windowedModes[MAXWINMODES][2] = static INT32 custom_width = 0; static INT32 custom_height = 0; -static void Impl_VideoSetupBuffer(void); static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); static void Impl_SetWindowIcon(void); @@ -1302,12 +1301,6 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) } texture = SDL_CreateTexture(renderer, sw_texture_format, SDL_TEXTUREACCESS_STREAMING, width, height); - - if (vid.buffer) - { - free(vid.buffer); - vid.buffer = NULL; - } } } @@ -1413,7 +1406,7 @@ void I_UpdateNoVsync(void) void I_ReadScreen(UINT8 * restrict scr, INT32 scale) { if (rendermode != render_soft) - I_Error ("I_ReadScreen: called while in non-software mode"); + I_Error("I_ReadScreen: called while in non-software mode"); else if (scale == 1) VID_BlitLinearScreen(vid.screens[0], scr, vid.width, vid.height, vid.width, vid.width); else @@ -1562,7 +1555,6 @@ INT32 VID_SetMode(INT32 modeNum) } SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); - Impl_VideoSetupBuffer(); src_rect.w = vid.width; src_rect.h = vid.height; @@ -1693,24 +1685,6 @@ static void Impl_SetWindowIcon(void) SDL_SetWindowIcon(window, icoSurface); } -static void Impl_VideoSetupBuffer(void) -{ - // Set up game's software render buffer - size_t size; - - if (vid.buffer) - free(vid.buffer); - - size = vid.width*vid.height * NUMSCREENS; - - vid.buffer = calloc(size, NUMSCREENS); - - if (!vid.buffer) - { - I_Error("%s", M_GetText("Not enough memory for video buffer\n")); - } -} - static FILE * OpenRendererFile(const char * mode) { char * path = va(pandf,srb2home,"renderer.txt"); @@ -1871,7 +1845,6 @@ void I_StartupGraphics(void) if (a2c) fputs("a2c\n", file); #endif - fclose(file); } else @@ -1930,21 +1903,12 @@ void I_StartupGraphics(void) void I_ShutdownGraphics(void) { - const rendermode_t oldrendermode = rendermode; - rendermode = render_none; if (icoSurface) SDL_FreeSurface(icoSurface); icoSurface = NULL; - if (oldrendermode == render_soft) - { - if (vid.buffer) - free(vid.buffer); - vid.buffer = NULL; - } - I_OutputMsg("I_ShutdownGraphics(): "); // was graphics initialized anyway? @@ -1963,6 +1927,7 @@ void I_ShutdownGraphics(void) SDL_GL_DeleteContext(sdlglcontext); } #endif + SDL_QuitSubSystem(SDL_INIT_VIDEO); framebuffer = SDL_FALSE; } From a0e023527cb8b0b7e41edf325e6aebe2b62cfb33 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 16:32:16 +0200 Subject: [PATCH 10/39] move the "video" stuff in i_video so its mostly together in the file --- src/hardware/r_opengl/r_opengl.c | 2 +- src/sdl/i_video.c | 232 ++++++++++++++++--------------- src/sdl/ogl_sdl.c | 2 +- 3 files changed, 121 insertions(+), 115 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 93a2c0ff4..23c2a8da0 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1428,7 +1428,7 @@ INT32 GL_isExtAvailable(const char *extension, const GLubyte *start) // Init : Initialise the OpenGL interface API // Returns : // -----------------+ -boolean GL_Init (void) +boolean GL_Init(void) { return SetupGLfunc(); } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 78f38f2d3..1a5ea118d 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -203,11 +203,6 @@ static void Impl_SetWindowIcon(void); #ifdef USE_FBO_OGL boolean downsample = false; -void RefreshOGLSDLSurface(void) -{ - if (rendermode == render_opengl) - OglSdlSurface(vid.width, vid.height); -} #endif void I_SetTextInput(void) @@ -428,44 +423,6 @@ static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) return Impl_SDL_Scancode_To_Keycode(scancode); } -static void VID_Command_NumModes_f (void) -{ - CONS_Printf(M_GetText("%d video mode(s) available(s)\n"), VID_NumModes()); -} - -static void VID_Command_ModeList_f(void) -{ - // List windowed modes - INT32 i = 0; - - CONS_Printf("NOTE: Under SDL2, all modes are supported on all platforms.\n"); - CONS_Printf("Under opengl, fullscreen only supports native desktop resolution.\n"); - CONS_Printf("Under software, the mode is stretched up to desktop resolution.\n"); - - for (i = 0; i < MAXWINMODES; i++) - { - CONS_Printf("%2d: %dx%d\n", i, windowedModes[i][0], windowedModes[i][1]); - } -} - -static void VID_Command_Mode_f (void) -{ - INT32 modenum; - - if (COM_Argc()!= 2) - { - CONS_Printf(M_GetText("vid_mode : set video mode, current video mode %i\n"), vid.modenum); - return; - } - - modenum = atoi(COM_Argv(1)); - - if (modenum >= VID_NumModes()) - CONS_Printf(M_GetText("Video mode not present\n")); - else - setmodeneeded = modenum+1; // request vid mode change -} - static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) { // -32768 to 32767 @@ -512,75 +469,6 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } -// Get the desktop resolution from the current display the gamewindow resides on -static void I_CheckDesktopRes(void) -{ - int currentDisplayIndex = -1; - SDL_DisplayMode curmode; - - desktopwidth = 0; - desktopheight = 0; - - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - - // No valid index - if (currentDisplayIndex < 0) - { - return; - } - - if (SDL_GetDesktopDisplayMode(currentDisplayIndex, &curmode) != 0) - { - return; - } - - desktopwidth = curmode.w; - desktopheight = curmode.h; -} - -// Check if the game resolution matches the desktop resolution -boolean I_CheckNativeRes(void) -{ - return (vid.width == desktopwidth && vid.height == desktopheight); -} - -#ifdef USE_FBO_OGL -void I_DownSample(void) -{ - boolean needrefresh = false; - - if (!cv_glframebuffer.value || !supportFBO || (cv_glscreentextures.value == 0)) // no sense to do this crap if we cant benefit from it - { - downsample = false; - return; - } - - if (I_CheckNativeRes() && (downsample == true)) - { - downsample = false; - RefreshOGLSDLSurface(); - return; - } - - if ((vid.width > desktopwidth) || (vid.height > desktopheight)) //check if current resolution is higher than current display resolution - { - downsample = true; - needrefresh = true; - } - else if (downsample == true) - { - downsample = false; - needrefresh = true; - } - - if (needrefresh) - { - RefreshOGLSDLSurface(); - needrefresh = false; - } -} -#endif - static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { #define FOCUSUNION (mousefocus | (kbfocus << 1) | (windowmoved << 2)) @@ -1229,6 +1117,120 @@ void I_OsPolling(void) if (mod & KMOD_CAPS) capslock = true; } +static void VID_Command_NumModes_f (void) +{ + CONS_Printf(M_GetText("%d video mode(s) available(s)\n"), VID_NumModes()); +} + +static void VID_Command_ModeList_f(void) +{ + // List windowed modes + INT32 i = 0; + + CONS_Printf("NOTE: Under SDL2, all modes are supported on all platforms.\n" + "Under opengl, fullscreen only supports native desktop resolution.\n" + "Under software, the mode is stretched up to desktop resolution.\n"); + + for (i = 0; i < MAXWINMODES; i++) + { + CONS_Printf("%2d: %dx%d\n", i, windowedModes[i][0], windowedModes[i][1]); + } +} + +static void VID_Command_Mode_f (void) +{ + INT32 modenum; + + if (COM_Argc()!= 2) + { + CONS_Printf("vid_mode : set video mode, current video mode %i\n", vid.modenum); + return; + } + + modenum = atoi(COM_Argv(1)); + + if (modenum >= VID_NumModes()) + CONS_Printf("Video mode not present\n"); + else + setmodeneeded = modenum+1; // request vid mode change +} + +// Get the desktop resolution from the current display the gamewindow resides on +static void I_CheckDesktopRes(void) +{ + int currentDisplayIndex = -1; + SDL_DisplayMode curmode; + + desktopwidth = 0; + desktopheight = 0; + + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + + // No valid index + if (currentDisplayIndex < 0) + { + return; + } + + if (SDL_GetDesktopDisplayMode(currentDisplayIndex, &curmode) != 0) + { + return; + } + + desktopwidth = curmode.w; + desktopheight = curmode.h; +} + +// Check if the game resolution matches the desktop resolution +boolean I_CheckNativeRes(void) +{ + return (vid.width == desktopwidth && vid.height == desktopheight); +} + +#ifdef USE_FBO_OGL + +void RefreshOGLSDLSurface(void) +{ + if (rendermode == render_opengl) + OglSdlSurface(vid.width, vid.height); +} + +void I_DownSample(void) +{ + boolean needrefresh = false; + + if (!cv_glframebuffer.value || !supportFBO || (cv_glscreentextures.value == 0)) // no sense to do this crap if we cant benefit from it + { + downsample = false; + return; + } + + if (I_CheckNativeRes() && (downsample == true)) + { + downsample = false; + RefreshOGLSDLSurface(); + return; + } + + if ((vid.width > desktopwidth) || (vid.height > desktopheight)) //check if current resolution is higher than current display resolution + { + downsample = true; + needrefresh = true; + } + else if (downsample == true) + { + downsample = false; + needrefresh = true; + } + + if (needrefresh) + { + RefreshOGLSDLSurface(); + needrefresh = false; + } +} +#endif + static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { static SDL_bool wasfullscreen = SDL_FALSE; @@ -1348,7 +1350,9 @@ void I_FinishUpdate(void) if (cv_ticrate.value) SCR_DisplayTicRate(); - if (cv_showping.value && ((netgame && consoleplayer != serverplayer) || (simulated_lag != 0 && consoleplayer == serverplayer && Playing()))) + const boolean isserverplayer = consoleplayer == serverplayer; + + if (cv_showping.value && ((netgame && !isserverplayer) || (simulated_lag != 0 && isserverplayer && Playing()))) SCR_DisplayLocalPing(); } @@ -1828,6 +1832,7 @@ void I_StartupGraphics(void) { FILE * file = OpenRendererFile("w"); + if (file != NULL) { if (rendermode == render_soft) @@ -1865,6 +1870,7 @@ void I_StartupGraphics(void) if (vid.glstate == VID_GL_LIBRARY_ERROR) { + CONS_Alert(CONS_ERROR, "Could not initialize OpenGL\n" "Falling back to Software mode.\n"); rendermode = render_soft; } } diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 4465c6094..4e60801b3 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -98,7 +98,7 @@ boolean VID_LoadOGLAPI(void) if (SDL_GL_LoadLibrary(OGLLibname) != 0) { - CONS_Alert(CONS_ERROR, "Could not load OpenGL Library: %s\n" "Falling back to Software mode.\n", SDL_GetError()); + CONS_Alert(CONS_ERROR, "Could not load OpenGL Library: %s\n", SDL_GetError()); if (!M_CheckParm("-OGLlib")) CONS_Printf("If you know what is the OpenGL library's name, use -OGLlib\n"); return false; From b85a718500fe95ecd1de026870f728690c71ab1a Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 16:32:40 +0200 Subject: [PATCH 11/39] merge vid dupx and dupy they always contained the same value, so just remove it --- src/console.c | 26 +-- src/d_main.c | 3 +- src/f_finale.c | 11 +- src/hardware/hw_draw.c | 207 ++++++++--------- src/hu_stuff.c | 12 +- src/k_hud.c | 114 +++++----- src/lua_hudlib.c | 21 +- src/lua_hudlib_drawlist.c | 78 +++---- src/m_anigif.c | 2 +- src/m_menu.c | 377 +++++++++++++++---------------- src/r_sky.c | 4 +- src/screen.c | 38 +--- src/screen.h | 18 +- src/st_stuff.c | 5 +- src/v_video.c | 464 +++++++++++++++++++++----------------- src/v_video.h | 1 + src/y_inter.c | 12 +- 17 files changed, 687 insertions(+), 706 deletions(-) diff --git a/src/console.c b/src/console.c index 420740b37..e018e1a1c 100644 --- a/src/console.c +++ b/src/console.c @@ -479,18 +479,18 @@ static void CON_RecalcSize(void) switch (cv_constextsize.value) { - case V_NOSCALEPATCH: - con_scalefactor = 1; - break; - case V_SMALLSCALEPATCH: - con_scalefactor = vid.smalldupx; - break; - case V_MEDSCALEPATCH: - con_scalefactor = vid.meddupx; - break; - default: // Full scaling - con_scalefactor = vid.dupx; - break; + case V_NOSCALEPATCH: + con_scalefactor = 1; + break; + case V_SMALLSCALEPATCH: + con_scalefactor = vid.smalldup; + break; + case V_MEDSCALEPATCH: + con_scalefactor = vid.meddup; + break; + default: // Full scaling + con_scalefactor = vid.dup; + break; } con_recalc = false; @@ -607,7 +607,7 @@ static void CON_MoveConsole(void) } // Not instant - Increment fracmovement fractionally - fracmovement += FixedMul(cons_speed.value*vid.fdupy, (cv_uncappedhud.value ? renderdeltatics : FRACUNIT)); + fracmovement += FixedMul(cons_speed.value*vid.fdup, (cv_uncappedhud.value ? renderdeltatics : FRACUNIT)); if (con_curlines < con_destlines) // Move the console downwards { diff --git a/src/d_main.c b/src/d_main.c index afd480565..f37675db2 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -352,8 +352,7 @@ static void D_Renderview(void) { // V_DrawPatchFill, but for the fourth screen only patch_t *pat = W_CachePatchName("SRB2BACK", PU_CACHE); - INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - INT32 x, y, pw = SHORT(pat->width) * dupz, ph = SHORT(pat->height) * dupz; + INT32 x, y, pw = SHORT(pat->width) * vid.dup, ph = SHORT(pat->height) * vid.dup; for (x = vid.width>>1; x < vid.width; x += pw) { diff --git a/src/f_finale.c b/src/f_finale.c index 6126b51b6..f8d2064c8 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -169,7 +169,7 @@ static void F_SkyScroll(INT32 scrollspeed) pat = W_CachePatchName("TITLEBG1", PU_PATCH_LOWPRIORITY); pat2 = W_CachePatchName("TITLEBG2", PU_PATCH_LOWPRIORITY); - w = (vid.width / vid.dupx)<width*16))<>FRACBITS) * vid.dupy) > vid.height) + if (((y>>FRACBITS) * vid.dup) > vid.height) break; } @@ -685,8 +685,8 @@ void F_CreditDrawer(void) if (finalecount) { const char *goodbyefornow = "See you in ""\x82""Dr. Robotnik's Ring Racers""\x80""!"; - fixed_t lpad = ((vid.width/vid.dupx) - BASEVIDWIDTH)<>FRACBITS, y>>FRACBITS, V_ALLOWLOWERCASE, goodbyefornow); // for some reason DrawStringAtFixed can't tolerate colour codes } @@ -707,7 +707,8 @@ void F_CreditTicker(void) case 1: y += 30< vid.height) + + if (FixedMul(y, vid.dup) > vid.height) break; } diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 5902f8d81..2b8ace584 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -74,10 +74,8 @@ void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) // | /| // |/ | // 0--1 - float sdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; - float sdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; - float pdupx = FIXED_TO_FLOAT(vid.fdupx)*2.0f; - float pdupy = FIXED_TO_FLOAT(vid.fdupy)*2.0f; + float sdup = FIXED_TO_FLOAT(vid.fdup)*2.0f; + float pdup = FIXED_TO_FLOAT(vid.fdup)*2.0f; // make patch ready in hardware cache HWR_GetPatch(gpatch); @@ -86,25 +84,23 @@ void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) switch (option & V_SCALEPATCHMASK) { case V_NOSCALEPATCH: - pdupx = pdupy = 2.0f; + pdup = 2.0f; break; case V_SMALLSCALEPATCH: - pdupx = 2.0f * FIXED_TO_FLOAT(vid.smalldupx*FRACUNIT); - pdupy = 2.0f * FIXED_TO_FLOAT(vid.smalldupy*FRACUNIT); + pdup = 2.0f * FIXED_TO_FLOAT(vid.smalldup*FRACUNIT); break; case V_MEDSCALEPATCH: - pdupx = 2.0f * FIXED_TO_FLOAT(vid.meddupx*FRACUNIT); - pdupy = 2.0f * FIXED_TO_FLOAT(vid.meddupx*FRACUNIT); + pdup = 2.0f * FIXED_TO_FLOAT(vid.meddup*FRACUNIT); break; } if (option & V_NOSCALESTART) - sdupx = sdupy = 2.0f; + sdup = 2.0f; - v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; - v[2].x = v[1].x = (x*sdupx+(gpatch->width - gpatch->leftoffset)*pdupx)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; - v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height - gpatch->topoffset)*pdupy)/vid.height; + v[0].x = v[3].x = (x*sdup-gpatch->leftoffset*pdup)/vid.width - 1; + v[2].x = v[1].x = (x*sdup+(gpatch->width - gpatch->leftoffset)*pdup)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdup-gpatch->topoffset*pdup)/vid.height; + v[2].y = v[3].y = 1-(y*sdup+(gpatch->height - gpatch->topoffset)*pdup)/vid.height; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; @@ -138,7 +134,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p // | /| // |/ | // 0--1 - float dupx, dupy, fscalew, fscaleh, fwidth, fheight; + float dup, fscalew, fscaleh, fwidth, fheight; if (alphalevel >= 10 && alphalevel < 13) return; @@ -154,25 +150,21 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p hwrPatch = ((GLPatch_t *)gpatch->hardware); - dupx = (float)vid.dupx; - dupy = (float)vid.dupy; + dup = (float)vid.dup; switch (option & V_SCALEPATCHMASK) { case V_NOSCALEPATCH: - dupx = dupy = 1.0f; + dup = 1.0f; break; case V_SMALLSCALEPATCH: - dupx = (float)vid.smalldupx; - dupy = (float)vid.smalldupy; + dup = (float)vid.smalldup; break; case V_MEDSCALEPATCH: - dupx = (float)vid.meddupx; - dupy = (float)vid.meddupy; + dup = (float)vid.meddup; break; } - dupx = dupy = (dupx < dupy ? dupx : dupy); fscalew = fscaleh = FIXED_TO_FLOAT(pscale); if (vscale != pscale) fscaleh = FIXED_TO_FLOAT(vscale); @@ -192,10 +184,10 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? offsety = (float)(gpatch->topoffset) * fscaleh; - if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dupx/dupy for crosshairs + if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dup for crosshairs { - offsetx *= dupx; - offsety *= dupy; + offsetx *= dup; + offsety *= dup; } cx -= offsetx; @@ -210,8 +202,8 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p if (!(option & V_NOSCALESTART)) { - cx = cx * dupx; - cy = cy * dupy; + cx = cx * dup; + cy = cy * dup; if (!(option & V_SCALEPATCHMASK)) { @@ -228,28 +220,30 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p HWR_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0])); } } + // centre screen - if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f) + if (fabsf(fvw - FLOATBASEVIDWIDTH * dup) > 1.0E-36f) { if (option & V_SNAPTORIGHT) - cx += (fvw - (FLOATBASEVIDWIDTH * dupx)); + cx += (fvw - (FLOATBASEVIDWIDTH * dup)); else if (!(option & V_SNAPTOLEFT)) - cx += (fvw - (FLOATBASEVIDWIDTH * dupx))/2.0f; + cx += (fvw - (FLOATBASEVIDWIDTH * dup))/2.0f; } - if (fabsf(fvh - FLOATBASEVIDHEIGHT * dupy) > 1.0E-36f) + + if (fabsf(fvh - FLOATBASEVIDHEIGHT * dup) > 1.0E-36f) { if ((option & (V_SPLITSCREEN|V_SNAPTOTOP)) == (V_SPLITSCREEN|V_SNAPTOTOP)) - cy += (fvh/2.0f - (FLOATBASEVIDHEIGHT/2.0f * dupy)); + cy += (fvh/2.0f - (FLOATBASEVIDHEIGHT/2.0f * dup)); else if (option & V_SNAPTOBOTTOM) - cy += (fvh - (FLOATBASEVIDHEIGHT * dupy)); + cy += (fvh - (FLOATBASEVIDHEIGHT * dup)); else if (!(option & V_SNAPTOTOP)) - cy += (fvh - (FLOATBASEVIDHEIGHT * dupy))/2.0f; + cy += (fvh - (FLOATBASEVIDHEIGHT * dup))/2.0f; } } } - fwidth = (float)(gpatch->width) * fscalew * dupx; - fheight = (float)(gpatch->height) * fscaleh * dupy; + fwidth = (float)(gpatch->width) * fscalew * dup; + fheight = (float)(gpatch->height) * fscaleh * dup; // positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1 cx = -1.0f + (cx / (fvw / 2.0f)); @@ -326,7 +320,7 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, // | /| // |/ | // 0--1 - float dupx, dupy, fscale, fwidth, fheight; + float dup, fscale, fwidth, fheight; if (alphalevel >= 10 && alphalevel < 13) return; @@ -338,25 +332,21 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, HWR_GetPatch(gpatch); hwrPatch = ((GLPatch_t *)gpatch->hardware); - dupx = (float)vid.dupx; - dupy = (float)vid.dupy; + dup = (float)vid.dup; switch (option & V_SCALEPATCHMASK) { case V_NOSCALEPATCH: - dupx = dupy = 1.0f; + dup = 1.0f; break; case V_SMALLSCALEPATCH: - dupx = (float)vid.smalldupx; - dupy = (float)vid.smalldupy; + dup = (float)vid.smalldup; break; case V_MEDSCALEPATCH: - dupx = (float)vid.meddupx; - dupy = (float)vid.meddupy; + dup = (float)vid.meddup; break; } - dupx = dupy = (dupx < dupy ? dupx : dupy); fscale = FIXED_TO_FLOAT(pscale); cy -= (float)(gpatch->topoffset) * fscale; @@ -364,8 +354,8 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, if (!(option & V_NOSCALESTART)) { - cx = cx * dupx; - cy = cy * dupy; + cx = cx * dup; + cy = cy * dup; if (!(option & V_SCALEPATCHMASK)) { @@ -382,22 +372,24 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, HWR_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0])); } } + // centre screen - if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f) + if (fabsf(fvw - FLOATBASEVIDWIDTH * dup) > 1.0E-36f) { if (option & V_SNAPTORIGHT) - cx += (fvw - (FLOATBASEVIDWIDTH * dupx)); + cx += (fvw - (FLOATBASEVIDWIDTH * dup)); else if (!(option & V_SNAPTOLEFT)) - cx += (fvw - (FLOATBASEVIDWIDTH * dupx))/2.0f; + cx += (fvw - (FLOATBASEVIDWIDTH * dup))/2.0f; } - if (fabsf(fvh - FLOATBASEVIDHEIGHT * dupy) > 1.0E-36f) + + if (fabsf(fvh - FLOATBASEVIDHEIGHT * dup) > 1.0E-36f) { if ((option & (V_SPLITSCREEN|V_SNAPTOTOP)) == (V_SPLITSCREEN|V_SNAPTOTOP)) - cy += (fvh/2.0f - (FLOATBASEVIDHEIGHT/2.0f * dupy)); + cy += (fvh/2.0f - (FLOATBASEVIDHEIGHT/2.0f * dup)); else if (option & V_SNAPTOBOTTOM) - cy += (fvh - (FLOATBASEVIDHEIGHT * dupy)); + cy += (fvh - (FLOATBASEVIDHEIGHT * dup)); else if (!(option & V_SNAPTOTOP)) - cy += (fvh - (FLOATBASEVIDHEIGHT * dupy))/2.0f; + cy += (fvh - (FLOATBASEVIDHEIGHT * dup))/2.0f; } } } @@ -419,13 +411,13 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, if (pscale != FRACUNIT) { - fwidth *= fscale * dupx; - fheight *= fscale * dupy; + fwidth *= fscale * dup; + fheight *= fscale * dup; } else { - fwidth *= dupx; - fheight *= dupy; + fwidth *= dup; + fheight *= dup; } // positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1 @@ -488,7 +480,7 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, // -------------------------------------------------------------------------- void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum) { - FOutVector v[4]; + FOutVector v[4]; float dflatsize; INT32 flatflag; const size_t len = W_LumpLength(flatlumpnum); @@ -591,7 +583,6 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) GL_SetShader(HWR_GetShaderFromTarget(SHADER_UI_COLORMAP_FADE)); GL_DrawScreenTexture(scr_tex, &Surf, PF_ColorMapped|PF_NoDepthTest); GL_UnSetShader(); - return; } else @@ -664,17 +655,14 @@ void HWR_DrawViewBorder(INT32 clearlines) INT32 basewindowx, basewindowy; patch_t *patch; -// if (gl_viewwidth == vid.width) -// return; - if (!clearlines) clearlines = BASEVIDHEIGHT; // refresh all // calc view size based on original game resolution - baseviewwidth = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewwidth), vid.fdupx)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; - baseviewheight = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewheight), vid.fdupy)); - top = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowy), vid.fdupy)); - side = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowx), vid.fdupx)); + baseviewwidth = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewwidth), vid.fdup)); //(cv_viewsize.value * BASEVIDWIDTH/10)&~7; + baseviewheight = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_viewheight), vid.fdup)); + top = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowy), vid.fdup)); + side = FixedInt(FixedDiv(FLOAT_TO_FIXED(gl_baseviewwindowx), vid.fdup)); // top HWR_DrawFlatFill(0, 0, @@ -827,27 +815,28 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) if (!(color & V_NOSCALESTART)) { - float dupx = (float)vid.dupx, dupy = (float)vid.dupy; + const float dup = (float)vid.dup; - fx *= dupx; - fy *= dupy; - fw *= dupx; - fh *= dupy; + fx *= dup; + fy *= dup; + fw *= dup; + fh *= dup; - if (fabsf(fvw - (FLOATBASEVIDWIDTH * dupx)) > 1.0E-36f) + if (fabsf(fvw - (FLOATBASEVIDWIDTH * dup)) > 1.0E-36f) { if (color & V_SNAPTORIGHT) - fx += (fvw - (FLOATBASEVIDWIDTH * dupx)); + fx += (fvw - (FLOATBASEVIDWIDTH * dup)); else if (!(color & V_SNAPTOLEFT)) - fx += (fvw - (FLOATBASEVIDWIDTH * dupx)) / 2.0f; + fx += (fvw - (FLOATBASEVIDWIDTH * dup)) / 2.0f; } - if (fabsf(fvh - (FLOATBASEVIDHEIGHT * dupy)) > 1.0E-36f) + + if (fabsf(fvh - (FLOATBASEVIDHEIGHT * dup)) > 1.0E-36f) { // same thing here if (color & V_SNAPTOBOTTOM) - fy += (fvh - (FLOATBASEVIDHEIGHT * dupy)); + fy += (fvh - (FLOATBASEVIDHEIGHT * dup)); else if (!(color & V_SNAPTOTOP)) - fy += (fvh - (FLOATBASEVIDHEIGHT * dupy)) / 2.0f; + fy += (fvh - (FLOATBASEVIDHEIGHT * dup)) / 2.0f; } } @@ -900,8 +889,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) Surf.PolyColor = palette[color&0xFF]; - GL_DrawPolygon(&Surf, v, 4, - PF_Modulated|PF_NoTexture|PF_NoDepthTest); + GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest); } // -------------------+ @@ -931,7 +919,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 if (!(options & V_NOSCALESTART)) { - float dupx = (float)vid.dupx, dupy = (float)vid.dupy; + const float dup = (float)vid.dup; if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { @@ -946,32 +934,32 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 return; } - fx *= dupx; - fy *= dupy; - fw *= dupx; - fh *= dupy; + fx *= dup; + fy *= dup; + fw *= dup; + fh *= dup; - if (fabsf(fvw - (FLOATBASEVIDWIDTH * dupx)) > 1.0E-36f) + if (fabsf(fvw - (FLOATBASEVIDWIDTH * dup)) > 1.0E-36f) { if (options & V_SNAPTORIGHT) - fx += (fvw - (FLOATBASEVIDWIDTH * dupx)); + fx += (fvw - (FLOATBASEVIDWIDTH * dup)); else if (!(options & V_SNAPTOLEFT)) - fx += (fvw - (FLOATBASEVIDWIDTH * dupx)) / 2; + fx += (fvw - (FLOATBASEVIDWIDTH * dup)) / 2; } - if (fabsf(fvh - (FLOATBASEVIDHEIGHT * dupy)) > 1.0E-36f) + + if (fabsf(fvh - (FLOATBASEVIDHEIGHT * dup)) > 1.0E-36f) { // same thing here if (options & V_SNAPTOBOTTOM) - fy += (fvh - (FLOATBASEVIDHEIGHT * dupy)); + fy += (fvh - (FLOATBASEVIDHEIGHT * dup)); else if (!(options & V_SNAPTOTOP)) - fy += (fvh - (FLOATBASEVIDHEIGHT * dupy)) / 2; + fy += (fvh - (FLOATBASEVIDHEIGHT * dup)) / 2; } if (options & V_SPLITSCREEN) - fy += (FLOATBASEVIDHEIGHT * dupy)/2; + fy += (FLOATBASEVIDHEIGHT * dup)/2; if (options & V_HORZSCREEN) - fx += (FLOATBASEVIDWIDTH * dupx)/2; - + fx += (FLOATBASEVIDWIDTH * dup)/2; } if (fx >= vid.width || fy >= vid.height) @@ -1052,7 +1040,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) if (!(color & V_NOSCALESTART)) { - float dupx = (float)vid.dupx, dupy = (float)vid.dupy; + const float dup = (float)vid.dup; if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { @@ -1066,30 +1054,32 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) return; } - fx *= dupx; - fy *= dupy; - fw *= dupx; - fh *= dupy; + fx *= dup; + fy *= dup; + fw *= dup; + fh *= dup; - if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f) + if (fabsf(fvw - FLOATBASEVIDWIDTH * dup) > 1.0E-36f) { if (color & V_SNAPTORIGHT) - fx += (fvw - (FLOATBASEVIDWIDTH * dupx)); + fx += (fvw - (FLOATBASEVIDWIDTH * dup)); else if (!(color & V_SNAPTOLEFT)) - fx += (fvw - (FLOATBASEVIDWIDTH * dupx)) / 2; + fx += (fvw - (FLOATBASEVIDWIDTH * dup)) / 2; } - if (fabsf(fvh - FLOATBASEVIDHEIGHT * dupy) > 1.0E-36f) + + if (fabsf(fvh - FLOATBASEVIDHEIGHT * dup) > 1.0E-36f) { // same thing here if (color & V_SNAPTOBOTTOM) - fy += (fvh - (FLOATBASEVIDHEIGHT * dupy)); + fy += (fvh - (FLOATBASEVIDHEIGHT * dup)); else if (!(color & V_SNAPTOTOP)) - fy += (fvh - (FLOATBASEVIDHEIGHT * dupy)) / 2; + fy += (fvh - (FLOATBASEVIDHEIGHT * dup)) / 2; } + if (color & V_SPLITSCREEN) - fy += (FLOATBASEVIDHEIGHT * dupy)/2; + fy += (FLOATBASEVIDHEIGHT * dup)/2; if (color & V_HORZSCREEN) - fx += (FLOATBASEVIDWIDTH * dupx)/2; + fx += (FLOATBASEVIDWIDTH * dup)/2; } if (fx >= vid.width || fy >= vid.height) @@ -1107,6 +1097,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) if (fw <= 0 || fh <= 0) return; + if (fx + fw > vid.width) fw = fvw - fx; if (fy + fh > vid.height) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index df130d020..714198e5c 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2278,10 +2278,10 @@ static void HU_DrawSongCreditsBox(void) INT32 strwidth = V_SmallStringWidth(str, V_ALLOWLOWERCASE) + 4; // dup dup dup dup - INT32 dup = min(vid.dupx, vid.dupy); + INT32 dup = vid.dup; // Center it - INT32 x = (BASEVIDWIDTH/2 - strwidth/2)*dup + ((vid.width - (BASEVIDWIDTH * vid.dupx)) / 2); + INT32 x = (BASEVIDWIDTH/2 - strwidth/2)*dup + ((vid.width - (BASEVIDWIDTH * dup)) / 2); INT32 y = 0; INT32 flags = V_SNAPTOTOP|V_NOSCALESTART; @@ -2667,14 +2667,14 @@ static inline void HU_DrawSpectatorTicker(void) INT32 i; INT32 length = 0, height = 174; INT32 totallength = 0, templength = -8; - INT32 dupadjust = (vid.width/vid.dupx), duptweak = (dupadjust - BASEVIDWIDTH)/2; + INT32 duptweak = (vid.scaledwidth - BASEVIDWIDTH)/2; for (i = 0; i < MAXPLAYERS; i++) if (playeringame[i] && players[i].spectator) totallength += (signed)strlen(player_names[i]) * 8 + 16; - length -= (leveltime % (totallength + dupadjust+8)); - length += dupadjust; + length -= (leveltime % (totallength + vid.scaledwidth+8)); + length += vid.scaledwidth; for (i = 0; i < MAXPLAYERS; i++) { @@ -2742,7 +2742,7 @@ static inline void HU_DrawSpectatorTicker(void) } } - if ((length += len) >= dupadjust+8) + if ((length += len) >= vid.scaledwidth+8) break; } } diff --git a/src/k_hud.c b/src/k_hud.c index 8f4c3ad1f..71af43f5d 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -2271,7 +2271,7 @@ void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, I { INT32 i, rightoffset = 240; const UINT8 *colormap; - const INT32 dupadjust = cv_betainterscreen.value ? 314 : (vid.width/vid.dupx), duptweak = cv_betainterscreen.value ? -3 : (dupadjust - BASEVIDWIDTH)/2; + const INT32 dupadjust = cv_betainterscreen.value ? 314 : vid.scaledwidth, duptweak = cv_betainterscreen.value ? -3 : (dupadjust - BASEVIDWIDTH)/2; boolean (*_isHighlightedPlayer)(const player_t *) = (demo.playback ? P_IsDisplayPlayer : P_IsLocalPlayer); @@ -2454,7 +2454,7 @@ static void K_DrawDialNum(INT32 x, INT32 y, boolean colorized, INT32 flags, INT3 w = skp_dialnum[0]->width; if (flags & V_NOSCALESTART) - w *= vid.dupx; + w *= vid.dup; if (num < 0) num = -num; @@ -2980,7 +2980,6 @@ static void K_drawNameTags(void) char *tag; patch_t *icon = NULL; - INT32 dup; UINT8 *cm = NULL; UINT8 tagcolor = 0; INT32 vflags = 0; @@ -3065,13 +3064,12 @@ static void K_drawNameTags(void) tag = va("%s%s ", HU_SkinColorToConsoleColor(players[i].mo->color), player_names[i]); icon = R_GetSkinFaceMini(players[i].mo->player); - dup = vid.dupx; cm = R_GetTranslationColormap(players[i].skin, players[i].mo->color, GTC_CACHE); tagcolor = colortranslations[players[i].mo->color][7]; vflags = trans | V_NOSCALESTART; usenametagrestat = ((cv_nametagrestat.value == 1 && (players[i].kartspeed != skins[players[i].skin].kartspeed || players[i].kartweight != skins[players[i].skin].kartweight)) || cv_nametagrestat.value == 2); tagwidthsmall = cv_smallnametags.value ? V_SmallStringWidth(player_names[i], V_ALLOWLOWERCASE) : V_ThinStringWidth(player_names[i], V_ALLOWLOWERCASE); - tagwidth = dup*tagwidthsmall; + tagwidth = vid.dup*tagwidthsmall; // If flipcam is on, other player is flipped relative to us when we have different // verticalflip flag value. Otherwise, they are simply flipped when verticalflip flag says so @@ -3083,36 +3081,36 @@ static void K_drawNameTags(void) #ifdef HWRENDER // Needs extra offset. Not perfect but this will do for now if (rendermode == render_opengl && !cv_glshearing.value && cv_smallnametags.value) - namey -= dup*6; + namey -= vid.dup*6; #endif if (cv_smallnametags.value || !nametaggfx) { if (flipped) - namey += dup*5; + namey += vid.dup*5; else // small offset - namey -= dup*3; + namey -= vid.dup*3; if (nametaggfx && cv_smallnametags.value == 1) { if (cv_nametagfacerank.value) - tagwidthsmall += icon->width - dup; + tagwidthsmall += icon->width - vid.dup; // Have to draw the nametag using patches here since drawfill can't draw at this scale... if (!flipped) V_DrawFixedPatch(namex<height/2)<width/2); // add offset to other stuff + namex += vid.dup*(1+icon->width/2); // add offset to other stuff } //Name @@ -3120,71 +3118,72 @@ static void K_drawNameTags(void) if (usenametagrestat) { - V_DrawSmallString(namex, namey - dup*5, vflags, va("\x84S%d ", players[i].kartspeed)); - V_DrawSmallString(namex + dup*10, namey - dup*5, vflags, va("\x87W%d ", players[i].kartweight)); + V_DrawSmallString(namex, namey - vid.dup*5, vflags, va("\x84S%d ", players[i].kartspeed)); + V_DrawSmallString(namex + vid.dup*10, namey - vid.dup*5, vflags, va("\x87W%d ", players[i].kartweight)); } if (cv_nametagscore.value) { INT32 yofs = usenametagrestat ? 10 : 5; - V_DrawSmallString(namex, namey - dup*yofs, V_ALLOWLOWERCASE | vflags, va("\x8A%d ", players[i].score)); + V_DrawSmallString(namex, namey - vid.dup*yofs, V_ALLOWLOWERCASE | vflags, va("\x8A%d ", players[i].score)); } } else { if (cv_nametagfacerank.value) - tagwidth += dup*(icon->width+1); + tagwidth += vid.dup*(icon->width+1); if (flipped) { - for (j = 0; j < 4; j++) + for (j = 0; j < 4; j++) { - V_DrawFill(namex, namey, dup*3, dup*4, 31 | vflags); - V_DrawFill(namex+dup, namey, dup, dup*4, tagcolor | vflags); - namey += dup*4; - namex += dup; + V_DrawFill(namex, namey, vid.dup*3, vid.dup*4, 31 | vflags); + V_DrawFill(namex+vid.dup, namey, vid.dup, vid.dup*4, tagcolor | vflags); + namey += vid.dup*4; + namex += vid.dup; } - namey -= dup*3; - V_DrawFill(namex, namey+dup*2, dup, dup, 31 | vflags); // a single black pixel - V_DrawFill(namex+dup, namey, tagwidth, dup*3, 31 | vflags); - V_DrawFill(namex+dup, namey+dup, tagwidth - dup, dup, tagcolor | vflags); - namex += dup*2; + + namey -= vid.dup*3; + V_DrawFill(namex, namey+vid.dup*2, vid.dup, vid.dup, 31 | vflags); // a single black pixel + V_DrawFill(namex+vid.dup, namey, tagwidth, vid.dup*3, 31 | vflags); + V_DrawFill(namex+vid.dup, namey+vid.dup, tagwidth - vid.dup, vid.dup, tagcolor | vflags); + namex += vid.dup*2; } else { for (j = 0; j < 4; j++) { - namey -= dup*4; - V_DrawFill(namex, namey, dup*3, dup*4, 31 | vflags); - V_DrawFill(namex+dup, namey, dup, dup*4, tagcolor | vflags); - namex += dup; + namey -= vid.dup*4; + V_DrawFill(namex, namey, vid.dup*3, vid.dup*4, 31 | vflags); + V_DrawFill(namex+vid.dup, namey, vid.dup, vid.dup*4, tagcolor | vflags); + namex += vid.dup; } - V_DrawFill(namex, namey, dup, dup, 31 | vflags); - V_DrawFill(namex+dup, namey, tagwidth - dup*2, dup*3, 31 | vflags); - V_DrawFill(namex+dup, namey+dup, tagwidth - dup*3, dup, tagcolor | vflags); + V_DrawFill(namex, namey, vid.dup, vid.dup, 31 | vflags); + V_DrawFill(namex+vid.dup, namey, tagwidth - vid.dup*2, vid.dup*3, 31 | vflags); + V_DrawFill(namex+vid.dup, namey+vid.dup, tagwidth - vid.dup*3, vid.dup, tagcolor | vflags); } if (cv_nametagfacerank.value) { - V_DrawMappedPatch(namex, namey - dup*(icon->height+1), vflags, icon, cm); - namex += dup*(icon->height+1); // add offset to other stuff + V_DrawMappedPatch(namex, namey - vid.dup*(icon->height+1), vflags, icon, cm); + namex += vid.dup*(icon->height+1); // add offset to other stuff } - V_DrawThinString(namex, namey - dup*10, V_ALLOWLOWERCASE | vflags, tag); + V_DrawThinString(namex, namey - vid.dup*10, V_ALLOWLOWERCASE | vflags, tag); if (usenametagrestat) { - V_DrawScaledPatch(namex, namey - dup*20, vflags, nametagspeed); - V_DrawScaledPatch(namex + dup*18, namey - dup*20, vflags, nametagweight); - V_DrawString(namex + dup*9, namey - dup*19, V_ALLOWLOWERCASE | vflags, va("\x84%d ", players[i].kartspeed)); - V_DrawString(namex + dup*27, namey - dup*19, V_ALLOWLOWERCASE | vflags, va("\x87%d ", players[i].kartweight)); + V_DrawScaledPatch(namex, namey - vid.dup*20, vflags, nametagspeed); + V_DrawScaledPatch(namex + vid.dup*18, namey - vid.dup*20, vflags, nametagweight); + V_DrawString(namex + vid.dup*9, namey - vid.dup*19, V_ALLOWLOWERCASE | vflags, va("\x84%d ", players[i].kartspeed)); + V_DrawString(namex + vid.dup*27, namey - vid.dup*19, V_ALLOWLOWERCASE | vflags, va("\x87%d ", players[i].kartweight)); } if (cv_nametagscore.value) { INT32 yofs = usenametagrestat ? 25 : 15; - V_DrawSmallString(namex, namey - dup*yofs, V_ALLOWLOWERCASE | vflags, va("\x8A%d ", players[i].score)); + V_DrawSmallString(namex, namey - vid.dup*yofs, V_ALLOWLOWERCASE | vflags, va("\x8A%d ", players[i].score)); } } } @@ -3195,7 +3194,6 @@ static void K_drawDriftGauge(void) { vector2_t pos = {0}; fixed_t basex, basey; - const int dup = vid.dupx; int i; UINT8 *colormap = NULL; @@ -3259,16 +3257,16 @@ skipcrap: if (gaugestyle == GAUGE_DEFAULT || gaugestyle == GAUGE_BIGNUM || gaugestyle == GAUGE_EXTRA) { - barx = basex - dup*23; - BAR_WIDTH = dup*47; + barx = basex - vid.dup*23; + BAR_WIDTH = vid.dup*47; } else { - barx = basex - dup*12; - BAR_WIDTH = dup*23; + barx = basex - vid.dup*12; + BAR_WIDTH = vid.dup*23; } - bary = basey - dup*2; + bary = basey - vid.dup*2; if (gaugestyle == GAUGE_EXTRA) // i hate hud code i hate hud code i hate hud code i hate hud code i hate hud code..... { @@ -3280,7 +3278,7 @@ skipcrap: else driftpatch = skp_smallsticker3; - V_DrawStretchyFixedPatch((basex - dup*30)<= driftval*4) // rainbow sparks @@ -3300,7 +3298,7 @@ skipcrap: colormap = R_GetTranslationColormap(TC_RAINBOW, K_RainbowColor(), GTC_CACHE); for (i = 0; i < 4; i++) - V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, (driftrainbow[min((leveltime % 18) + 1, 17)] + i*2) | V_NOSCALESTART|drifttrans); + V_DrawFill(barx, bary+vid.dup*1+vid.dup*i, BAR_WIDTH, vid.dup, (driftrainbow[min((leveltime % 18) + 1, 17)] + i*2) | V_NOSCALESTART|drifttrans); } else // none/blue/red { @@ -3312,17 +3310,17 @@ skipcrap: for (i = 0; i < 4; i++) { if (driftcharge >= driftval) - V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, driftcolors[driftlevel-1][i] | V_NOSCALESTART|drifttrans); + V_DrawFill(barx, bary+vid.dup*1+vid.dup*i, BAR_WIDTH, vid.dup, driftcolors[driftlevel-1][i] | V_NOSCALESTART|drifttrans); - V_DrawFill(barx, bary+dup*1+dup*i, width, dup, driftcolors[driftlevel][i] | V_NOSCALESTART|drifttrans); + V_DrawFill(barx, bary+vid.dup*1+vid.dup*i, width, vid.dup, driftcolors[driftlevel][i] | V_NOSCALESTART|drifttrans); } } // right, also draw a cool number if (gaugestyle == GAUGE_BIGNUM) - V_DrawPaddedTallColorNum(basex + (dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, colormap); + V_DrawPaddedTallColorNum(basex + (vid.dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, colormap); else - V_DrawPingNum((gaugestyle == GAUGE_SMALL ? basex + (dup*22) : basex + (dup*32)), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, colormap); + V_DrawPingNum((gaugestyle == GAUGE_SMALL ? basex + (vid.dup*22) : basex + (vid.dup*32)), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, colormap); } break; case GAUGE_NUMONLY: @@ -3332,7 +3330,7 @@ skipcrap: else colormap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel], GTC_CACHE); - V_DrawPaddedTallColorNum(basex + (dup*16), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, colormap); + V_DrawPaddedTallColorNum(basex + (vid.dup*16), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, colormap); } break; default: @@ -3881,7 +3879,7 @@ static void K_drawKartFinish(void) if (splitscreen) // wide splitscreen pnum += 4; - x = ((vid.width<width<kartstuff[k_cardanimation])< x ? xval : x))/TICRATE; @@ -4101,7 +4099,7 @@ static void K_drawKartFirstPerson(void) if (splitscreen == 1) { scale = (2*FRACUNIT)/3; - y += FRACUNIT/(vid.dupx < vid.dupy ? vid.dupx : vid.dupy); // correct a one-pixel gap on the screen view (not the basevid view) + y += FRACUNIT/vid.dup; // correct a one-pixel gap on the screen view (not the basevid view) } else if (splitscreen) scale = FRACUNIT/2; diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index c6dbd97d2..251a1013c 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -715,7 +715,7 @@ static int libd_drawOnMinimap(lua_State *L) // and NOW we can FINALLY DRAW OUR GOD DAMN PATCH :V lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); - list = (huddrawlist_h) lua_touserdata(L, -1); + list = (huddrawlist_h)lua_touserdata(L, -1); lua_pop(L, 1); if (LUA_HUD_IsDrawListValid(list)) @@ -1095,22 +1095,13 @@ FUNCINLINE static ATTRINLINE int libd_height(lua_State *L) return 1; } -FUNCINLINE static ATTRINLINE int libd_dupx(lua_State *L) +FUNCINLINE static ATTRINLINE int libd_dup(lua_State *L) { HUDONLY - lua_pushinteger(L, vid.dupx); // push integral scale (patch scale) - lua_pushfixed(L, vid.fdupx); // push fixed point scale (position scale) + lua_pushinteger(L, vid.dup); // push integral scale (patch scale) + lua_pushfixed(L, vid.fdup); // push fixed point scale (position scale) return 2; } - -FUNCINLINE static ATTRINLINE int libd_dupy(lua_State *L) -{ - HUDONLY - lua_pushinteger(L, vid.dupy); // push integral scale (patch scale) - lua_pushfixed(L, vid.fdupy); // push fixed point scale (position scale) - return 2; -} - FUNCINLINE static ATTRINLINE int libd_renderer(lua_State *L) { HUDONLY @@ -1208,8 +1199,8 @@ static luaL_Reg lib_draw[] = { {"getColormap", libd_getColormap}, {"width", libd_width}, {"height", libd_height}, - {"dupx", libd_dupx}, - {"dupy", libd_dupy}, + {"dupx", libd_dup}, + {"dupy", libd_dup}, {"renderer", libd_renderer}, {"localTransFlag", libd_getlocaltransflag}, {"drawOnMinimap", libd_drawOnMinimap}, diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index e13e4e099..f267c5fe3 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -201,73 +201,68 @@ static void CalcStringCoords(drawitem_t *item, const char *string) { if (!(item->flags & V_NOSCALESTART) && cv_uncappedhud.value) { - INT32 dupx = vid.dupx; - INT32 dupy = vid.dupy; + INT32 dup = vid.dup; item->flags |= V_NOSCALESTART; if (item->flags & V_SCALEPATCHMASK) switch ((item->flags & V_SCALEPATCHMASK) >> V_SCALEPATCHSHIFT) { case 1: // V_NOSCALEPATCH - dupx = dupy = 1; + dup = 1; break; case 2: // V_SMALLSCALEPATCH - dupx = vid.smalldupx; - dupy = vid.smalldupy; + dup = vid.smalldup; break; case 3: // V_MEDSCALEPATCH - dupx = vid.meddupx; - dupy = vid.meddupy; + dup = vid.meddup; break; default: break; } - // only use one dup, to avoid stretching (har har) - dupx = dupy = (dupx < dupy ? dupx : dupy); - - INT32 x = item->x * dupx; - INT32 y = item->y * dupy; + INT32 x = item->x * dup; + INT32 y = item->y * dup; if (item->flags & V_SPLITSCREEN) - y += (BASEVIDHEIGHT * (dupy - 1))/2; + y += (BASEVIDHEIGHT * (dup - 1))/2; if (item->flags & V_HORZSCREEN) - x += (BASEVIDWIDTH * (dupx - 1))/2; + x += (BASEVIDWIDTH * (dup - 1))/2; - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen if ((item->flags & (V_HORZSCREEN|V_SNAPTOLEFT)) == (V_HORZSCREEN|V_SNAPTOLEFT)) - x += (vid.width/2 - (BASEVIDWIDTH/2 * dupx)); + x += (vid.width/2 - (BASEVIDWIDTH/2 * dup)); else if (item->flags & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * dup)); else if (!(item->flags & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + + if (vid.height != BASEVIDHEIGHT * dup) { // same thing here if ((item->flags & (V_SPLITSCREEN|V_SNAPTOTOP)) == (V_SPLITSCREEN|V_SNAPTOTOP)) - y += (vid.height/2 - (BASEVIDHEIGHT/2 * dupy)); + y += (vid.height/2 - (BASEVIDHEIGHT/2 * dup)); else if (item->flags & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * dup)); else if (!(item->flags & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * dup)) / 2; } // need to compensate for dup here if (item->type == DI_DrawString) { if (item->align == align_center) - x -= (V_StringWidth(string, item->flags) * (dupx - 1))/2; + x -= (V_StringWidth(string, item->flags) * (dup - 1))/2; if (item->align == align_right) - x -= V_StringWidth(string, item->flags) * (dupx - 1); + x -= V_StringWidth(string, item->flags) * (dup - 1); if (item->align == align_smallright) - x -= V_SmallStringWidth(string, item->flags) * (dupx - 1); + x -= V_SmallStringWidth(string, item->flags) * (dup - 1); if (item->align == align_thinright) - x -= V_ThinStringWidth(string, item->flags) * (dupx - 1); + x -= V_ThinStringWidth(string, item->flags) * (dup - 1); } item->x = x; @@ -279,40 +274,39 @@ static void CalcFillCoords(drawitem_t *item) { if (!(item->flags & V_NOSCALESTART) && cv_uncappedhud.value) { - INT32 dupx = vid.dupx; - INT32 dupy = vid.dupy; - INT32 x = item->x * dupx; - INT32 y = item->y * dupy; + INT32 dup = vid.dup; + INT32 x = item->x * dup; + INT32 y = item->y * dup; INT32 c = item->c; item->flags |= V_NOSCALESTART; - item->w *= dupx; - item->h *= dupy; + item->w *= dup; + item->h *= dup; // Center it if necessary - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen if (c & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * dup)); else if (!(c & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + if (vid.height != BASEVIDHEIGHT * dup) { // same thing here if (c & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * dup)); else if (!(c & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * dup)) / 2; } if (c & V_SPLITSCREEN) - y += (BASEVIDHEIGHT * dupy)/2; + y += (BASEVIDHEIGHT * dup)/2; if (c & V_HORZSCREEN) - x += (BASEVIDWIDTH * dupx)/2; + x += (BASEVIDWIDTH * dup)/2; item->x = x; item->y = y; diff --git a/src/m_anigif.c b/src/m_anigif.c index 3d2ef2e5f..a8cc21bcf 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -421,7 +421,7 @@ static void GIF_headwrite(void) // Image width/height if (gif_downscale) { - scrbuf_downscaleamt = vid.dupx; + scrbuf_downscaleamt = vid.dup; scrbuf_width = (vid.width / scrbuf_downscaleamt); scrbuf_height = (vid.height / scrbuf_downscaleamt); } diff --git a/src/m_menu.c b/src/m_menu.c index 8c459b1c0..c07d0f270 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1358,8 +1358,8 @@ boolean M_DemoResponder(event_t *ev) default: break; } - } + return eatinput; } @@ -1376,7 +1376,10 @@ static boolean ShouldDrawMenuBG(void) return false; // camera options stuff, only do when in level - if (gamestate == GS_LEVEL && (currentMenu == &OP_CamOptionsDef || currentMenu == &OP_Player1CamOptionsDef || currentMenu == &OP_Player2CamOptionsDef || currentMenu == &OP_Player3CamOptionsDef || currentMenu == &OP_Player4CamOptionsDef)) + if (gamestate == GS_LEVEL && + (currentMenu == &OP_CamOptionsDef || currentMenu == &OP_Player1CamOptionsDef + || currentMenu == &OP_Player2CamOptionsDef || currentMenu == &OP_Player3CamOptionsDef + || currentMenu == &OP_Player4CamOptionsDef)) return false; return true; @@ -1414,17 +1417,17 @@ void M_Drawer(void) { if (customversionstring[0] != '\0') { - V_DrawThinString(vid.dupx, vid.height - 20*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT, "Mod version:"); - V_DrawThinString(vid.dupx, vid.height - 10*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, customversionstring); + V_DrawThinString(vid.dup, vid.height - 20*vid.dup, V_NOSCALESTART|V_TRANSLUCENT, "Mod version:"); + V_DrawThinString(vid.dup, vid.height - 10*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, customversionstring); } else { #ifdef DEVELOP // Development -- show revision / branch info - V_DrawThinString(vid.dupx, vid.height - 20*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, compbranch); - V_DrawThinString(vid.dupx, vid.height - 10*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, comprevision); + V_DrawThinString(vid.dup, vid.height - 20*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, compbranch); + V_DrawThinString(vid.dup, vid.height - 10*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, comprevision); #else // Regular build - V_DrawThinString(vid.dupx, vid.height - 20*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, comprevision); // Removeur this for release! im just lazy to make a new flag or smth - V_DrawThinString(vid.dupx, vid.height - 10*vid.dupy, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, va("%s", VERSIONSTRING)); + V_DrawThinString(vid.dup, vid.height - 20*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, comprevision); // Removeur this for release! im just lazy to make a new flag or smth + V_DrawThinString(vid.dup, vid.height - 10*vid.dup, V_NOSCALESTART|V_TRANSLUCENT|V_ALLOWLOWERCASE, va("%s", VERSIONSTRING)); #endif #ifdef HWRENDER @@ -1633,7 +1636,6 @@ void M_StartControlPanel(void) M_RefreshPauseMenu(); } #endif - currentMenu = &MPauseDef; itemOn = mpause_continue; } @@ -1964,19 +1966,19 @@ static void M_DrawThermo(INT32 x, INT32 y, consvar_t *cv) centerlump[1] = W_GetNumForName("M_THERMM"); cursorlump = W_GetNumForName("M_THERMO"); - V_DrawScaledPatch(xx, y, 0, p = W_CachePatchNum(leftlump, PU_PATCH)); + V_DrawScaledPatch(xx, y, 0, p = (patch_t *)W_CachePatchNum(leftlump, PU_PATCH)); xx += p->width - p->leftoffset; for (i = 0; i < 16; i++) { - V_DrawScaledPatch(xx, y, V_WRAPX, W_CachePatchNum(centerlump[i & 1], PU_PATCH)); + V_DrawScaledPatch(xx, y, V_WRAPX, (patch_t *)W_CachePatchNum(centerlump[i & 1], PU_PATCH)); xx += 8; } - V_DrawScaledPatch(xx, y, 0, W_CachePatchNum(rightlump, PU_PATCH)); + V_DrawScaledPatch(xx, y, 0, (patch_t *)W_CachePatchNum(rightlump, PU_PATCH)); xx = (cv->value - cv->PossibleValue[0].value) * (15*8) / (cv->PossibleValue[1].value - cv->PossibleValue[0].value); - V_DrawScaledPatch((x + 8) + xx, y, 0, W_CachePatchNum(cursorlump, PU_PATCH)); + V_DrawScaledPatch((x + 8) + xx, y, 0, (patch_t *)W_CachePatchNum(cursorlump, PU_PATCH)); } // A smaller 'Thermo', with range given as percents (0-100) @@ -1988,18 +1990,18 @@ static void M_DrawSlider(INT32 x, INT32 y, const consvar_t *cv, boolean ontop) x = BASEVIDWIDTH - x - SLIDER_WIDTH; - p = W_CachePatchName("M_SLIDEL", PU_PATCH); + p = (patch_t *)W_CachePatchName("M_SLIDEL", PU_PATCH); V_DrawScaledPatch(x - 8, y, 0, p); - p = W_CachePatchName("M_SLIDEM", PU_PATCH); + p = (patch_t *)W_CachePatchName("M_SLIDEM", PU_PATCH); for (i = 0; i < SLIDER_RANGE; i++) V_DrawScaledPatch (x+i*8, y, 0,p); - p = W_CachePatchName("M_SLIDER", PU_PATCH); + p = (patch_t *)W_CachePatchName("M_SLIDER", PU_PATCH); V_DrawScaledPatch(x+i*8, y, 0, p); // draw the slider cursor - p = W_CachePatchName("M_SLIDEC", PU_PATCH); + p = (patch_t *)W_CachePatchName("M_SLIDEC", PU_PATCH); for (i = 0; cv->PossibleValue[i+1].strvalue; i++); @@ -2093,10 +2095,10 @@ static void M_DrawMapEmblems(INT32 mapnum, INT32 x, INT32 y) lasttype = curtype; if (emblem->collected) - V_DrawSmallMappedPatch(x, y, 0, W_CachePatchName(M_GetEmblemPatch(emblem), PU_PATCH), + V_DrawSmallMappedPatch(x, y, 0, (patch_t *)W_CachePatchName(M_GetEmblemPatch(emblem), PU_PATCH), R_GetTranslationColormap(TC_DEFAULT, M_GetEmblemColor(emblem), GTC_MENUCACHE)); else - V_DrawSmallScaledPatch(x, y, 0, W_CachePatchName("NEEDIT", PU_PATCH)); + V_DrawSmallScaledPatch(x, y, 0, (patch_t *)W_CachePatchName("NEEDIT", PU_PATCH)); emblem = M_GetLevelEmblems(-1); x -= 8; @@ -2107,7 +2109,7 @@ static void M_DrawMenuTitle(void) { if (currentMenu->menutitlepic) { - patch_t *p = W_CachePatchName(currentMenu->menutitlepic, PU_PATCH); + patch_t *p = (patch_t *)W_CachePatchName(currentMenu->menutitlepic, PU_PATCH); if (p->height > 24) // title is larger than normal { @@ -2237,13 +2239,13 @@ static void M_DrawGenericMenu(void) if (currentMenu->menuitems[i].status & IT_CENTER) { patch_t *p; - p = W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); + p = (patch_t *)W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); V_DrawScaledPatch((BASEVIDWIDTH - p->width)/2, y, 0, p); } else { V_DrawScaledPatch(x, y, 0, - W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH)); + (patch_t *)W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH)); } } /* FALLTHRU */ @@ -2315,7 +2317,7 @@ static void M_DrawGenericMenu(void) case IT_GRAYPATCH: if (currentMenu->menuitems[i].patch && currentMenu->menuitems[i].patch[0]) V_DrawMappedPatch(x, y, 0, - W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH), graymap); + (patch_t *)W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH), graymap); y += LINEHEIGHT; break; case IT_TRANSTEXT: @@ -2348,12 +2350,12 @@ static void M_DrawGenericMenu(void) || ((currentMenu->menuitems[itemOn].status & IT_DISPLAY) == IT_NOTHING)) { V_DrawScaledPatch(currentMenu->x + SKULLXOFF, cursory - 5, 0, - W_CachePatchName("M_CURSOR", PU_PATCH)); + (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); } else { V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, - W_CachePatchName("M_CURSOR", PU_PATCH)); + (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawString(currentMenu->x, cursory, MENUCAPS|highlightflags, currentMenu->menuitems[itemOn].text); } @@ -2364,7 +2366,7 @@ static void M_DrawGenericMenu(void) static void M_DrawGenericBackgroundMenu(void) { - V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); + V_DrawPatchFill((patch_t *)W_CachePatchName("SRB2BACK", PU_PATCH)); M_DrawGenericMenu(); } @@ -2486,7 +2488,7 @@ static void M_DrawGenericScrollMenu(void) // DRAW THE SKULL CURSOR V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, - W_CachePatchName("M_CURSOR", PU_PATCH)); + (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); // dumb hack // tooltips @@ -2507,7 +2509,7 @@ static void M_DrawPauseMenu(void) (currentMenu->y + MPauseMenu[mpause_discordrequests].alphaKey - 1) * FRACUNIT, FRACUNIT, 0, - W_CachePatchName("K_REQUE2", PU_PATCH), + (patch_t *)W_CachePatchName("K_REQUE2", PU_PATCH), NULL ); } @@ -2537,7 +2539,7 @@ static void M_DrawCenteredMenu(void) case IT_PATCH: if (currentMenu->menuitems[i].patch && currentMenu->menuitems[i].patch[0]) { - patch_t *p = W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); + patch_t *p = (patch_t *)W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); if (currentMenu->menuitems[i].status & IT_CENTER) { @@ -2615,7 +2617,7 @@ static void M_DrawCenteredMenu(void) case IT_GRAYPATCH: if (currentMenu->menuitems[i].patch && currentMenu->menuitems[i].patch[0]) V_DrawMappedPatch(x, y, 0, - W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH), graymap); + (patch_t *)W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH), graymap); y += LINEHEIGHT; break; } @@ -2626,12 +2628,12 @@ static void M_DrawCenteredMenu(void) || ((currentMenu->menuitems[itemOn].status & IT_DISPLAY) == IT_NOTHING)) { V_DrawScaledPatch(x + SKULLXOFF, cursory - 5, 0, - W_CachePatchName("M_CURSOR", PU_PATCH)); + (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); } else { V_DrawScaledPatch(x - V_StringWidth(currentMenu->menuitems[itemOn].text, 0)/2 - 24, cursory, 0, - W_CachePatchName("M_CURSOR", PU_PATCH)); + (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawCenteredString(x, cursory, highlightflags|MENUCAPS, currentMenu->menuitems[itemOn].text); } } @@ -2934,7 +2936,7 @@ static void M_DrawMessageMenu(void) // hack: draw RA background in RA menus if (gamestate == GS_TIMEATTACK) - V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); + V_DrawPatchFill((patch_t *)W_CachePatchName("SRB2BACK", PU_PATCH)); M_DrawTextBox(currentMenu->x, y - 8, (max+7)>>3, mlines); @@ -3000,7 +3002,7 @@ static void M_StopMessage(INT32 choice) // You can even put multiple images in one menu! static void M_DrawImageDef(void) { - patch_t *patch = W_CachePatchName(currentMenu->menuitems[itemOn].text, PU_PATCH); + patch_t *patch = (patch_t *)W_CachePatchName(currentMenu->menuitems[itemOn].text, PU_PATCH); if (patch->width <= BASEVIDWIDTH) V_DrawScaledPatch(0,0,0,patch); else @@ -3124,23 +3126,23 @@ static void M_AddonsInternal(void) W_UnlockCachedPatch(addonsp[i]); } - addonsp[EXT_FOLDER] = W_CachePatchName("M_FFLDR", PU_PATCH); - addonsp[EXT_UP] = W_CachePatchName("M_FBACK", PU_PATCH); - addonsp[EXT_NORESULTS] = W_CachePatchName("M_FNOPE", PU_PATCH); - addonsp[EXT_TXT] = W_CachePatchName("M_FTXT", PU_PATCH); - addonsp[EXT_CFG] = W_CachePatchName("M_FCFG", PU_PATCH); - addonsp[EXT_WAD] = W_CachePatchName("M_FWAD", PU_PATCH); + addonsp[EXT_FOLDER] = (patch_t *)W_CachePatchName("M_FFLDR", PU_PATCH); + addonsp[EXT_UP] = (patch_t *)W_CachePatchName("M_FBACK", PU_PATCH); + addonsp[EXT_NORESULTS] = (patch_t *)W_CachePatchName("M_FNOPE", PU_PATCH); + addonsp[EXT_TXT] = (patch_t *)W_CachePatchName("M_FTXT", PU_PATCH); + addonsp[EXT_CFG] = (patch_t *)W_CachePatchName("M_FCFG", PU_PATCH); + addonsp[EXT_WAD] = (patch_t *)W_CachePatchName("M_FWAD", PU_PATCH); #ifdef USE_KART - addonsp[EXT_KART] = W_CachePatchName("M_FKART", PU_PATCH); + addonsp[EXT_KART] = (patch_t *)W_CachePatchName("M_FKART", PU_PATCH); #endif - addonsp[EXT_PK3] = W_CachePatchName("M_FPK3", PU_PATCH); - addonsp[EXT_SOC] = W_CachePatchName("M_FSOC", PU_PATCH); - addonsp[EXT_LUA] = W_CachePatchName("M_FLUA", PU_PATCH); - addonsp[NUM_EXT] = W_CachePatchName("M_FUNKN", PU_PATCH); - addonsp[NUM_EXT+1] = W_CachePatchName("M_FSEL", PU_PATCH); - addonsp[NUM_EXT+2] = W_CachePatchName("M_FLOAD", PU_PATCH); - addonsp[NUM_EXT+3] = W_CachePatchName("M_FSRCH", PU_PATCH); - addonsp[NUM_EXT+4] = W_CachePatchName("M_FSAVE", PU_PATCH); + addonsp[EXT_PK3] = (patch_t *)W_CachePatchName("M_FPK3", PU_PATCH); + addonsp[EXT_SOC] = (patch_t *)W_CachePatchName("M_FSOC", PU_PATCH); + addonsp[EXT_LUA] = (patch_t *)W_CachePatchName("M_FLUA", PU_PATCH); + addonsp[NUM_EXT] = (patch_t *)W_CachePatchName("M_FUNKN", PU_PATCH); + addonsp[NUM_EXT+1] = (patch_t *)W_CachePatchName("M_FSEL", PU_PATCH); + addonsp[NUM_EXT+2] = (patch_t *)W_CachePatchName("M_FLOAD", PU_PATCH); + addonsp[NUM_EXT+3] = (patch_t *)W_CachePatchName("M_FSRCH", PU_PATCH); + addonsp[NUM_EXT+4] = (patch_t *)W_CachePatchName("M_FSAVE", PU_PATCH); MISC_AddonsDef.prevMenu = currentMenu; M_SetupNextMenu(&MISC_AddonsDef); @@ -4183,8 +4185,6 @@ static void M_HandleReplayHutList(INT32 choice) } } -#define SCALEDVIEWWIDTH (vid.width/vid.dupx) -#define SCALEDVIEWHEIGHT (vid.height/vid.dupy) static void DrawReplayHutReplayInfo(void) { lumpnum_t lumpnum; @@ -4216,9 +4216,9 @@ static void DrawReplayHutReplayInfo(void) //CONS_Printf("%d %s\n", demolist[dir_on[menudepthleft]].map, G_BuildMapName(demolist[dir_on[menudepthleft]].map)); lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(demolist[dir_on[menudepthleft]].map))); if (lumpnum != LUMPERROR) - patch = W_CachePatchNum(lumpnum, PU_PATCH); + patch = (patch_t *)W_CachePatchNum(lumpnum, PU_PATCH); else - patch = W_CachePatchName("M_NOLVL", PU_PATCH); + patch = (patch_t *)W_CachePatchName("M_NOLVL", PU_PATCH); if (!(demolist[dir_on[menudepthleft]].kartspeed & DF_ENCORE)) V_DrawSmallScaledPatch(x, y, V_SNAPTOTOP, patch); @@ -4231,7 +4231,7 @@ static void DrawReplayHutReplayInfo(void) { static angle_t rubyfloattime = 0; const fixed_t rubyheight = FINESINE(rubyfloattime>>ANGLETOFINESHIFT); - V_DrawFixedPatch((x+(w>>2))<>2))<>2))<>2))<numitems-2; boolean processed_one_this_frame = false; + const INT32 scaledviewheight = (vid.height/vid.dup); static UINT16 replayhutmenuy = 0; - V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); + V_DrawPatchFill((patch_t *)W_CachePatchName("SRB2BACK", PU_PATCH)); if (cv_vhseffect.value) V_DrawVhsEffect(false); @@ -4365,8 +4366,8 @@ static void M_DrawReplayHut(void) if (cursory > maxy - 20) cursory = maxy - 20; - if (cursory - replayhutmenuy > SCALEDVIEWHEIGHT-50) - replayhutmenuy += (cursory-SCALEDVIEWHEIGHT-replayhutmenuy + 51)/2; + if (cursory - replayhutmenuy > scaledviewheight-50) + replayhutmenuy += (cursory-scaledviewheight-replayhutmenuy + 51)/2; else if (cursory - replayhutmenuy < 110) replayhutmenuy += (max(0, cursory-110)-replayhutmenuy - 1)/2; } @@ -4407,7 +4408,7 @@ static void M_DrawReplayHut(void) if (localy < 65) continue; - if (localy >= SCALEDVIEWHEIGHT - 24) + if (localy >= scaledviewheight - 24) break; if (demolist[i].type == MD_NOTLOADED && !processed_one_this_frame) @@ -4419,7 +4420,7 @@ static void M_DrawReplayHut(void) if (demolist[i].type == MD_SUBDIR) { localx += 8; - V_DrawScaledPatch(x - 4, localy, V_SNAPTOTOP|V_SNAPTOLEFT, W_CachePatchName(dirmenu[i][DIR_TYPE] == EXT_UP ? "M_RBACK" : "M_RFLDR", PU_PATCH)); + V_DrawScaledPatch(x - 4, localy, V_SNAPTOTOP|V_SNAPTOLEFT, (patch_t *)W_CachePatchName(dirmenu[i][DIR_TYPE] == EXT_UP ? "M_RBACK" : "M_RFLDR", PU_PATCH)); } if (itemOn == replaylistitem && i == (INT16)dir_on[menudepthleft]) @@ -4432,7 +4433,7 @@ static void M_DrawReplayHut(void) replayScrollDelay--; else if (replayScrollDir > 0) { - if (replayScrollTitle < (V_StringWidth(demolist[i].title, 0) - (SCALEDVIEWWIDTH - (x<<1)))<<1) + if (replayScrollTitle < (V_StringWidth(demolist[i].title, 0) - (vid.scaledwidth - (x<<1)))<<1) replayScrollTitle++; else { @@ -4459,15 +4460,15 @@ static void M_DrawReplayHut(void) // Draw scrollbar y = replayqueryfound*10 + currentMenu->menuitems[replaylistitem].alphaKey + 30; - if (y > SCALEDVIEWHEIGHT-80) + if (y > scaledviewheight-80) { - V_DrawFill(BASEVIDWIDTH-4, 75, 4, SCALEDVIEWHEIGHT-80, V_SNAPTOTOP|V_SNAPTORIGHT|239); - V_DrawFill(BASEVIDWIDTH-3, 76 + (SCALEDVIEWHEIGHT-80) * replayhutmenuy / y, 2, (((SCALEDVIEWHEIGHT-80) * (SCALEDVIEWHEIGHT-80))-1) / y - 1, V_SNAPTOTOP|V_SNAPTORIGHT|229); + V_DrawFill(BASEVIDWIDTH-4, 75, 4, scaledviewheight-80, V_SNAPTOTOP|V_SNAPTORIGHT|239); + V_DrawFill(BASEVIDWIDTH-3, 76 + (scaledviewheight-80) * replayhutmenuy / y, 2, (((scaledviewheight-80) * (scaledviewheight-80))-1) / y - 1, V_SNAPTOTOP|V_SNAPTORIGHT|229); } // Draw the cursor V_DrawScaledPatch(currentMenu->x - 24, cursory, V_SNAPTOTOP|V_SNAPTOLEFT, - W_CachePatchName("M_CURSOR", PU_PATCH)); + (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawString(currentMenu->x, cursory, V_SNAPTOTOP|V_SNAPTOLEFT|highlightflags, currentMenu->menuitems[itemOn].text); // Now draw some replay info! @@ -4531,7 +4532,7 @@ static void M_DrawReplayStartMenu(void) } else { - patch = W_CachePatchName("M_NORANK", PU_PATCH); + patch = (patch_t *)W_CachePatchName("M_NORANK", PU_PATCH); colormap = R_GetTranslationColormap( TC_RAINBOW, demolist[dir_on[menudepthleft]].standings[i].color, @@ -4549,7 +4550,7 @@ static void M_DrawReplayStartMenu(void) replayScrollDelay--; else if (replayScrollDir > 0) { - if (replayScrollTitle < (i*20 - SCALEDVIEWHEIGHT + 100)<<1) + if (replayScrollTitle < (i*20 - (vid.height/vid.dup) + 100)<<1) replayScrollTitle++; else { @@ -4576,25 +4577,25 @@ static void M_DrawReplayStartMenu(void) // Draw a warning prompt if needed switch (demolist[dir_on[menudepthleft]].addonstatus) { - case DFILE_ERROR_CANNOTLOAD: - warning = "Some addons in this replay cannot be loaded.\nYou can watch anyway, but desyncs may occur."; - break; + case DFILE_ERROR_CANNOTLOAD: + warning = "Some addons in this replay cannot be loaded.\nYou can watch anyway, but desyncs may occur."; + break; - case DFILE_ERROR_NOTLOADED: - case DFILE_ERROR_INCOMPLETEOUTOFORDER: - warning = "Loading addons will mark your game as modified, and Record Attack may be unavailable.\nYou can watch without loading addons, but desyncs may occur."; - break; + case DFILE_ERROR_NOTLOADED: + case DFILE_ERROR_INCOMPLETEOUTOFORDER: + warning = "Loading addons will mark your game as modified, and Record Attack may be unavailable.\nYou can watch without loading addons, but desyncs may occur."; + break; - case DFILE_ERROR_EXTRAFILES: - warning = "You have addons loaded that were not present in this replay.\nYou can watch anyway, but desyncs may occur."; - break; + case DFILE_ERROR_EXTRAFILES: + warning = "You have addons loaded that were not present in this replay.\nYou can watch anyway, but desyncs may occur."; + break; - case DFILE_ERROR_OUTOFORDER: - warning = "You have this replay's addons loaded, but they are out of order.\nYou can watch anyway, but desyncs may occur."; - break; + case DFILE_ERROR_OUTOFORDER: + warning = "You have this replay's addons loaded, but they are out of order.\nYou can watch anyway, but desyncs may occur."; + break; - default: - return; + default: + return; } if (warning) @@ -4707,16 +4708,16 @@ static void M_DrawPlaybackMenu(void) inactivemap = R_GetTranslationColormap(players[ply].skin, players[ply].skincolor, GTC_MENUCACHE); } else if (currentMenu->menuitems[i].patch && W_CheckNumForName(currentMenu->menuitems[i].patch) != LUMPERROR) - icon = W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); + icon = (patch_t *)W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); else - icon = W_CachePatchName("PLAYRANK", PU_PATCH); // temp + icon = (patch_t *)W_CachePatchName("PLAYRANK", PU_PATCH); // temp } else if (currentMenu->menuitems[i].status == IT_DISABLED) continue; else if (currentMenu->menuitems[i].patch && W_CheckNumForName(currentMenu->menuitems[i].patch) != LUMPERROR) - icon = W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); + icon = (patch_t *)W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); else - icon = W_CachePatchName("PLAYRANK", PU_PATCH); // temp + icon = (patch_t *)W_CachePatchName("PLAYRANK", PU_PATCH); // temp if ((i == playback_fastforward && cv_playbackspeed.value > 1) || (i == playback_rewind && demo.rewinding)) V_DrawMappedPatch(currentMenu->x + currentMenu->menuitems[i].alphaKey, currentMenu->y, transmap|V_SNAPTOTOP, icon, R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_JAWZ, GTC_MENUCACHE)); @@ -5410,9 +5411,9 @@ static void M_DrawMusicTest(void) x = 90<usage[0]) - V_DrawString(vid.dupx, vid.height - 10*vid.dupy, V_NOSCALESTART|V_ALLOWLOWERCASE, va("%.6s", curplaying->name)); + V_DrawString(vid.dup, vid.height - 10*vid.dup, V_NOSCALESTART|V_ALLOWLOWERCASE, va("%.6s", curplaying->name)); else - V_DrawSmallString(vid.dupx, vid.height - 5*vid.dupy, V_NOSCALESTART|V_ALLOWLOWERCASE, va("%.6s - %.255s\n", curplaying->name, curplaying->usage)); + V_DrawSmallString(vid.dup, vid.height - 5*vid.dup, V_NOSCALESTART|V_ALLOWLOWERCASE, va("%.6s - %.255s\n", curplaying->name, curplaying->usage)); if (cv_showmusicfilename.value) V_DrawSmallString(0, 0, V_SNAPTOTOP|V_SNAPTOLEFT|V_ALLOWLOWERCASE, curplaying->filename); @@ -5611,6 +5612,7 @@ static void M_HandleMusicTest(INT32 choice) default: break; } + if (exitmenu) { if (currentMenu->prevMenu) @@ -5731,7 +5733,7 @@ static void M_DrawStatsMaps(void) V_DrawRightAlignedString(BASEVIDWIDTH-16, 50, recommendedflags|MENUCAPS, "(complete)"); V_DrawString(32, 50, MENUCAPS, va("x %d/%d", M_CountEmblems(), numemblems+numextraemblems)); - V_DrawSmallScaledPatch(20, 50, 0, W_CachePatchName("GOTITA", PU_PATCH)); + V_DrawSmallScaledPatch(20, 50, 0, (patch_t *)W_CachePatchName("GOTITA", PU_PATCH)); if (location) V_DrawCharacter(10, y-(skullAnimCounter/5), @@ -5802,10 +5804,10 @@ static void M_DrawStatsMaps(void) exemblem = &extraemblems[i]; if (exemblem->collected) - V_DrawSmallMappedPatch(295, y, 0, W_CachePatchName(M_GetExtraEmblemPatch(exemblem), PU_PATCH), + V_DrawSmallMappedPatch(295, y, 0, (patch_t *)W_CachePatchName(M_GetExtraEmblemPatch(exemblem), PU_PATCH), R_GetTranslationColormap(TC_DEFAULT, M_GetExtraEmblemColor(exemblem), GTC_MENUCACHE)); else - V_DrawSmallScaledPatch(295, y, 0, W_CachePatchName("NEEDIT", PU_PATCH)); + V_DrawSmallScaledPatch(295, y, 0, (patch_t *)W_CachePatchName("NEEDIT", PU_PATCH)); V_DrawString(20, y, MENUCAPS, va("%s", exemblem->description)); } @@ -5972,7 +5974,7 @@ void M_DrawTimeAttackMenu(void) //S_ChangeMusicInternal("racent", true); // Eww, but needed for when user hits escape during demo playback - V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); + V_DrawPatchFill((patch_t *)W_CachePatchName("SRB2BACK", PU_PATCH)); M_DrawMenuTitle(); if (currentMenu == &SP_TimeAttackDef) @@ -6056,21 +6058,21 @@ void M_DrawTimeAttackMenu(void) y = currentMenu->y; // DRAW THE SKULL CURSOR - V_DrawScaledPatch(x - 24, cursory, 0, W_CachePatchName("M_CURSOR", PU_PATCH)); + V_DrawScaledPatch(x - 24, cursory, 0, (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawString(x, cursory, highlightflags|MENUCAPS, currentMenu->menuitems[itemOn].text); // Level record list if (cv_nextmap.value) { - INT32 dupadjust = (vid.width/vid.dupx); tic_t lap = 0, time = 0; + if (mainrecords[cv_nextmap.value-1]) { lap = mainrecords[cv_nextmap.value-1]->lap; time = mainrecords[cv_nextmap.value-1]->time; } - V_DrawFill((BASEVIDWIDTH - dupadjust)>>1, 78, dupadjust, 36, 239); + V_DrawFill((BASEVIDWIDTH - vid.scaledwidth)>>1, 78, vid.scaledwidth, 36, 239); V_DrawRightAlignedString(149, 80, highlightflags|MENUCAPS, "Best Lap:"); K_drawKartTimestamp(lap, 19, 86, 0, 2); @@ -6380,10 +6382,8 @@ static void M_ExitGameResponse(INT32 ch) static void M_EndGame(INT32 choice) { (void)choice; - if (demo.playback) - return; - if (!Playing()) + if (demo.playback || !Playing()) return; M_StartMessage(M_GetText("Are you sure you want to end the game?\n\n(Press 'Y' to confirm)\n"), M_ExitGameResponse, MM_YESNO); @@ -6393,8 +6393,7 @@ static void M_EndGame(INT32 choice) // Connect Menu //=========================================================================== -void -M_SetWaitingMode (int mode) +void M_SetWaitingMode(int mode) { #ifdef HAVE_THREADS I_lock_mutex(&m_menu_mutex); @@ -6407,8 +6406,7 @@ M_SetWaitingMode (int mode) #endif } -int -M_GetWaitingMode (void) +int M_GetWaitingMode(void) { int mode; @@ -6427,8 +6425,7 @@ M_GetWaitingMode (void) #ifdef MASTERSERVER #ifdef HAVE_THREADS -static void -Spawn_masterserver_thread (const char *name, void (*thread)(int*)) +static void Spawn_masterserver_thread(const char *name, void (*thread)(int*)) { int *id = malloc(sizeof *id); @@ -6441,8 +6438,7 @@ Spawn_masterserver_thread (const char *name, void (*thread)(int*)) I_spawn_thread(name, (I_thread_fn)thread, id); } -static int -Same_instance (int id) +static int Same_instance(int id) { int okay; @@ -6456,8 +6452,7 @@ Same_instance (int id) } #endif/*HAVE_THREADS*/ -static void -Fetch_servers_thread (int *id) +static void Fetch_servers_thread(int *id) { msg_server_t * server_list; @@ -6554,6 +6549,7 @@ static void M_HandleServerSearch(INT32 choice) } break; } + if (exitmenu) { if (currentMenu->prevMenu) @@ -6899,8 +6895,7 @@ static void M_CheckMODVersion(int id) #if defined (UPDATE_ALERT) && defined (HAVE_THREADS) #ifdef MASTERSERVER -static void -Check_new_version_thread (int *id) +static void Check_new_version_thread(int *id) { M_SetWaitingMode(M_WAITING_VERSION); @@ -7032,7 +7027,6 @@ void M_PopupMasterServerConnectError(void) static void M_PreStartServerMenu(INT32 choice) { - (void)choice; #ifdef MASTERSERVER connect_error_continue = STARTSERVER_MENU; @@ -7144,7 +7138,7 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) { lumpnum_t lumpnum; patch_t *PictureOfLevel; - INT32 x, y, w, i, oldval, trans, dupadjust = ((vid.width/vid.dupx) - BASEVIDWIDTH)>>1; + INT32 x, y, w, i, oldval, trans, dupadjust = (vid.scaledwidth - BASEVIDWIDTH)>>1; if (levellistmode != LLM_RECORDATTACK) // so it doesent show in record attack menu { @@ -7165,12 +7159,12 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) { lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(cv_nextmap.value))); if (lumpnum != LUMPERROR) - PictureOfLevel = W_CachePatchNum(lumpnum, PU_PATCH); + PictureOfLevel = (patch_t *)W_CachePatchNum(lumpnum, PU_PATCH); else - PictureOfLevel = W_CachePatchName("BLANKLVL", PU_PATCH); + PictureOfLevel = (patch_t *)W_CachePatchName("BLANKLVL", PU_PATCH); } else - PictureOfLevel = W_CachePatchName("RANDOMLV", PU_PATCH); + PictureOfLevel = (patch_t *)W_CachePatchName("RANDOMLV", PU_PATCH); w = PictureOfLevel->width/2; i = PictureOfLevel->height/2; @@ -7216,14 +7210,14 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) { /*UINT8 *mappingforencore = NULL; if ((lumpnum = W_CheckNumForName(va("%sE", mapname))) != LUMPERROR) - mappingforencore = W_CachePatchNum(lumpnum, PU_PATCH);*/ + mappingforencore = (patch_t *)W_CachePatchNum(lumpnum, PU_PATCH);*/ V_DrawFixedPatch((x+w)<>ANGLETOFINESHIFT); - V_DrawFixedPatch((x+w/2)< 7 * FRACUNIT; cursorframe -= 7 * FRACUNIT) {} - V_DrawFixedPatch(x<> FRACBITS) + 1), PU_PATCH), NULL); + V_DrawFixedPatch(x<> FRACBITS) + 1), PU_PATCH), NULL); } x += incrwidth; @@ -7706,10 +7700,10 @@ static void M_DrawSetupMultiPlayerMenu(void) INT32 tw = 0; spritedef_t *sprdef; spriteframe_t *sprframe; - patch_t *statbg = W_CachePatchName("K_STATBG", PU_PATCH); - patch_t *statlr = W_CachePatchName("K_STATLR", PU_PATCH); - patch_t *statud = W_CachePatchName("K_STATUD", PU_PATCH); - patch_t *statdot = W_CachePatchName("K_SDOT0", PU_PATCH); + patch_t *statbg = (patch_t *)W_CachePatchName("K_STATBG", PU_PATCH); + patch_t *statlr = (patch_t *)W_CachePatchName("K_STATLR", PU_PATCH); + patch_t *statud = (patch_t *)W_CachePatchName("K_STATUD", PU_PATCH); + patch_t *statdot = (patch_t *)W_CachePatchName("K_SDOT0", PU_PATCH); patch_t *patch; UINT8 frame; UINT8 speed; @@ -7737,15 +7731,15 @@ static void M_DrawSetupMultiPlayerMenu(void) // Offsets switch (cv_skinselectmenu.value) { - case SKINMENUTYPE_EXTENDED: - nameboxaddy = 6; - break; - case SKINMENUTYPE_GRID: - nameboxaddy = 6; - break; - default: - nameboxaddy = 0; - break; + case SKINMENUTYPE_EXTENDED: + nameboxaddy = 6; + break; + case SKINMENUTYPE_GRID: + nameboxaddy = 6; + break; + default: + nameboxaddy = 0; + break; } M_DrawTextBox(mx + 32, my - 8 + nameboxaddy, MAXPLAYERNAME, 1); @@ -7889,17 +7883,17 @@ static void M_DrawSetupMultiPlayerMenu(void) if (statdp == true) { //Background - V_DrawScaledPatch(statx - 50, staty + 4, 0, W_CachePatchName("K_STATNB", PU_PATCH)); + V_DrawScaledPatch(statx - 50, staty + 4, 0, (patch_t *)W_CachePatchName("K_STATNB", PU_PATCH)); //Speed for (i = 0; i < GETSELECTEDSPEED; i++) // draw the stat bars { if (i == 0) - V_DrawScaledPatch(statx - 45, staty + 63, 0, W_CachePatchName("K_STATN1", PU_PATCH)); + V_DrawScaledPatch(statx - 45, staty + 63, 0, (patch_t *)W_CachePatchName("K_STATN1", PU_PATCH)); else if (i == GETSELECTEDSPEED -1 ) - V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN3", PU_PATCH)); + V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, (patch_t *)W_CachePatchName("K_STATN3", PU_PATCH)); else - V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN2", PU_PATCH)); + V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, (patch_t *)W_CachePatchName("K_STATN2", PU_PATCH)); } //Weight @@ -7907,11 +7901,11 @@ static void M_DrawSetupMultiPlayerMenu(void) { if (i == 0) - V_DrawScaledPatch(statx - 30, staty + 63, 0, W_CachePatchName("K_STATN4", PU_PATCH)); + V_DrawScaledPatch(statx - 30, staty + 63, 0, (patch_t *)W_CachePatchName("K_STATN4", PU_PATCH)); else if (i == GETSELECTEDWEIGHT -1) - V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN6", PU_PATCH)); + V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, (patch_t *)W_CachePatchName("K_STATN6", PU_PATCH)); else - V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN5", PU_PATCH)); + V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, (patch_t *)W_CachePatchName("K_STATN5", PU_PATCH)); } } @@ -8041,7 +8035,7 @@ static void M_DrawSetupMultiPlayerMenu(void) UINT8 cursorframe = (I_GetTime() / 4) % 7; - cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); + 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); } @@ -8089,7 +8083,7 @@ static void M_DrawSetupMultiPlayerMenu(void) { UINT8 cursorframe = (I_GetTime() / 4) % 7; - cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); + 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); } } @@ -8098,13 +8092,13 @@ static void M_DrawSetupMultiPlayerMenu(void) INT32 selectedskin = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin); speed = skins[selectedskin].kartspeed; weight = skins[selectedskin].kartweight; - statdot = W_CachePatchName("K_SDOT1", PU_PATCH); + statdot = (patch_t *)W_CachePatchName("K_SDOT1", PU_PATCH); if (skullAnimCounter < 4) // SRB2Kart: we draw this dot later so that it's not covered if there's multiple skins with the same stats V_DrawFixedPatch((((statx+46+GRIDSTATOFFSET) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, flashcol); else V_DrawFixedPatch((((statx+46+GRIDSTATOFFSET) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, NULL); - statdot = W_CachePatchName("K_SDOT2", PU_PATCH); // coloured center + statdot = (patch_t *)W_CachePatchName("K_SDOT2", PU_PATCH); // coloured center if (setupm_fakecolor) V_DrawFixedPatch((((statx+46+GRIDSTATOFFSET) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, R_GetTranslationColormap(0, setupm_fakecolor, GTC_MENUCACHE)); } @@ -8153,7 +8147,7 @@ static void M_DrawSetupMultiPlayerMenu(void) { UINT8 cursorframe = (I_GetTime() / 4) % 7; - cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); + 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); } } @@ -8164,13 +8158,13 @@ static void M_DrawSetupMultiPlayerMenu(void) speed = skins[setupm_fakeskin].kartspeed; weight = skins[setupm_fakeskin].kartweight; - statdot = W_CachePatchName("K_SDOT1", PU_PATCH); + statdot = (patch_t *)W_CachePatchName("K_SDOT1", PU_PATCH); if (skullAnimCounter < 4) // SRB2Kart: we draw this dot later so that it's not covered if there's multiple skins with the same stats V_DrawFixedPatch(((BASEVIDWIDTH - mx - 80) + ((speed-1)*8))< 7 * FRACUNIT; cursorframe -= 7 * FRACUNIT) {} - cursor = W_CachePatchName(va("K_BHILI%d", (cursorframe >> FRACBITS) + 1), PU_PATCH); + cursor = (patch_t *)W_CachePatchName(va("K_BHILI%d", (cursorframe >> FRACBITS) + 1), PU_PATCH); if (col < 0) col += numskins; @@ -8309,7 +8303,6 @@ static void M_DrawSetupMultiPlayerMenu(void) sprframe = &sprdef->spriteframes[frame]; //minenice's speen css, it's a piece of shit but hey - //patch = 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 @@ -8317,7 +8310,7 @@ static void M_DrawSetupMultiPlayerMenu(void) if ((sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe]) && (speenframe > 4)) flags = V_FLIP; // This sprite is left/right flipped! - patch = W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); + 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); @@ -9276,8 +9269,7 @@ static void M_DrawControl(void) y += SMALLLINEHEIGHT; } - V_DrawScaledPatch(currentMenu->x - 20, cursory, 0, - W_CachePatchName("M_CURSOR", PU_PATCH)); + V_DrawScaledPatch(currentMenu->x - 20, cursory, 0, (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); } #undef controlheight @@ -9666,7 +9658,7 @@ static void M_DrawLocalSkinMenu(void) sprframe = &sprdef->spriteframes[frame]; //minenice's speen css, it's a piece of shit but hey - //patch = W_CachePatchNum(sprframe->lumppat[1], PU_PATCH); + //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 @@ -9675,7 +9667,7 @@ static void M_DrawLocalSkinMenu(void) { flags = V_FLIP; // This sprite is left/right flipped! } - patch = W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); + 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); @@ -9683,9 +9675,11 @@ static void M_DrawLocalSkinMenu(void) // 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, W_CachePatchName(displayskin.facewant, PU_PATCH), colormap); - V_DrawMappedPatch(mx+8, my+85, 0, W_CachePatchName(displayskin.facerank, PU_PATCH), colormap); + V_DrawMappedPatch(mx, my+50, 0, (patch_t *)W_CachePatchName(displayskin.facewant, PU_PATCH), colormap); + V_DrawMappedPatch(mx+8, my+85, 0, (patch_t *)W_CachePatchName(displayskin.facerank, PU_PATCH), colormap); + V_DrawString(mx, my+108, V_ALLOWLOWERCASE, "Character"); + if (strlen(displayskin.realname) > 10) V_DrawThinString(mx+20, my+118, V_ALLOWLOWERCASE|highlightflags, displayskin.realname); else @@ -9693,10 +9687,7 @@ static void M_DrawLocalSkinMenu(void) if (displayskin.flags & SF_HIRES) { - V_DrawFixedPatch((mx+220)<x - 24, cursory, 0, - W_CachePatchName("M_CURSOR", PU_PATCH)); + V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); } @@ -10043,14 +10032,14 @@ static void M_DrawMonitorToggles(void) #ifdef ITEMTOGGLEBOTTOMRIGHT if (currentMenu->menuitems[thisitem].alphaKey == 255) { - V_DrawScaledPatch(x, y, V_TRANSLUCENT, W_CachePatchName("K_ISBG", PU_PATCH)); + V_DrawScaledPatch(x, y, V_TRANSLUCENT, (patch_t *)W_CachePatchName("K_ISBG", PU_PATCH)); continue; } #endif if (currentMenu->menuitems[thisitem].alphaKey == 0) { - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBG", PU_PATCH)); - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISTOGL", PU_PATCH)); + V_DrawScaledPatch(x, y, 0, (patch_t *)W_CachePatchName("K_ISBG", PU_PATCH)); + V_DrawScaledPatch(x, y, 0, (patch_t *)W_CachePatchName("K_ISTOGL", PU_PATCH)); continue; } @@ -10079,18 +10068,18 @@ static void M_DrawMonitorToggles(void) } if (cv->value) - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBG", PU_PATCH)); + V_DrawScaledPatch(x, y, 0, (patch_t *)W_CachePatchName("K_ISBG", PU_PATCH)); else - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBGD", PU_PATCH)); + V_DrawScaledPatch(x, y, 0, (patch_t *)W_CachePatchName("K_ISBGD", PU_PATCH)); if (drawnum != 0) { - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISMUL", PU_PATCH)); - V_DrawScaledPatch(x, y, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[thisitem].alphaKey, true), PU_PATCH)); + V_DrawScaledPatch(x, y, 0, (patch_t *)W_CachePatchName("K_ISMUL", PU_PATCH)); + V_DrawScaledPatch(x, y, translucent, (patch_t *)W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[thisitem].alphaKey, true), PU_PATCH)); V_DrawString(x+24, y+31, V_ALLOWLOWERCASE|translucent, va("x%d", drawnum)); } else - V_DrawScaledPatch(x, y, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[thisitem].alphaKey, true), PU_PATCH)); + V_DrawScaledPatch(x, y, translucent, (patch_t *)W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[thisitem].alphaKey, true), PU_PATCH)); y += spacing; } @@ -10103,7 +10092,7 @@ static void M_DrawMonitorToggles(void) #ifdef ITEMTOGGLEBOTTOMRIGHT if (currentMenu->menuitems[itemOn].alphaKey == 255) { - V_DrawScaledPatch(onx-1, ony-2, V_TRANSLUCENT, W_CachePatchName("K_ITBG", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, V_TRANSLUCENT, (patch_t *)W_CachePatchName("K_ITBG", PU_PATCH)); if (shitsfree) { INT32 trans = V_TRANSLUCENT; @@ -10111,15 +10100,15 @@ static void M_DrawMonitorToggles(void) trans = ((10-TICRATE)+shitsfree-1)<menuitems[itemOn].alphaKey == 0) { - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBG", PU_PATCH)); - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITTOGL", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, 0, (patch_t *)W_CachePatchName("K_ITBG", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, 0, (patch_t *)W_CachePatchName("K_ITTOGL", PU_PATCH)); } else { @@ -10144,19 +10133,19 @@ static void M_DrawMonitorToggles(void) } if (cv->value) - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBG", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, 0, (patch_t *)W_CachePatchName("K_ITBG", PU_PATCH)); else - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBGD", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, 0, (patch_t *)W_CachePatchName("K_ITBGD", PU_PATCH)); if (drawnum != 0) { - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITMUL", PU_PATCH)); - V_DrawScaledPatch(onx-1, ony-2, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[itemOn].alphaKey, false), PU_PATCH)); - V_DrawScaledPatch(onx+27, ony+39, translucent, W_CachePatchName("K_ITX", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, 0, (patch_t *)W_CachePatchName("K_ITMUL", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, translucent, (patch_t *)W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[itemOn].alphaKey, false), PU_PATCH)); + V_DrawScaledPatch(onx+27, ony+39, translucent, (patch_t *)W_CachePatchName("K_ITX", PU_PATCH)); V_DrawKartString(onx+37, ony+34, translucent, va("%d", drawnum)); } else - V_DrawScaledPatch(onx-1, ony-2, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[itemOn].alphaKey, false), PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, translucent, (patch_t *)W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[itemOn].alphaKey, false), PU_PATCH)); } } @@ -10318,7 +10307,7 @@ void M_QuitResponse(INT32 ch) while (ptime > I_GetTime()) { V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); - V_DrawSmallScaledPatch(0, 0, 0, W_CachePatchName("GAMEQUIT", PU_PATCH)); // Demo 3 Quit Screen Tails 06-16-2001 + V_DrawSmallScaledPatch(0, 0, 0, (patch_t *)W_CachePatchName("GAMEQUIT", PU_PATCH)); // Demo 3 Quit Screen Tails 06-16-2001 I_FinishUpdate(); // Update the screen with the image Tails 06-19-2001 I_Sleep(cv_sleep.value); I_UpdateTime(cv_timescale.value); @@ -10387,12 +10376,12 @@ static void M_DrawSticker(INT32 x, INT32 y, INT32 width, INT32 flags, boolean is if (isSmall == true) { - stickerEnd = W_CachePatchName("K_STIKE2", PU_PATCH); + stickerEnd = (patch_t *)W_CachePatchName("K_STIKE2", PU_PATCH); height = 6; } else { - stickerEnd = W_CachePatchName("K_STIKEN", PU_PATCH); + stickerEnd = (patch_t *)W_CachePatchName("K_STIKEN", PU_PATCH); height = 11; } @@ -10422,12 +10411,12 @@ static void M_DrawDiscordRequests(void) if (confirmAccept == true) { colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_GREEN, GTC_MENUCACHE); - hand = W_CachePatchName("K_LAPH02", PU_PATCH); + hand = (patch_t *)W_CachePatchName("K_LAPH02", PU_PATCH); } else { colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_RED, GTC_MENUCACHE); - hand = W_CachePatchName("K_LAPH03", PU_PATCH); + hand = (patch_t *)W_CachePatchName("K_LAPH03", PU_PATCH); } slide = confirmLength - confirmDelay; @@ -10442,7 +10431,7 @@ static void M_DrawDiscordRequests(void) colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_GREY, GTC_MENUCACHE); } - V_DrawFixedPatch(56*FRACUNIT, 150*FRACUNIT, FRACUNIT, 0, W_CachePatchName("K_LAPE01", PU_PATCH), colormap); + V_DrawFixedPatch(56*FRACUNIT, 150*FRACUNIT, FRACUNIT, 0, (patch_t *)W_CachePatchName("K_LAPE01", PU_PATCH), colormap); if (hand != NULL) { diff --git a/src/r_sky.c b/src/r_sky.c index 8cbdd3a59..9b0a9262c 100644 --- a/src/r_sky.c +++ b/src/r_sky.c @@ -92,6 +92,6 @@ void R_SetupSkyDraw(void) void R_SetSkyScale(void) { //skyscale = FixedDiv(fovtan, FixedDiv(vid.width*FRACUNIT, BASEVIDWIDTH*FRACUNIT)); - fixed_t difference = vid.fdupx-(vid.dupx<> 1) + 1; - vid.meddupy = (UINT8)(vid.dupy >> 1) + 1; - - vid.smalldupx = (UINT8)(vid.dupx / 3) + 1; - vid.smalldupy = (UINT8)(vid.dupy / 3) + 1; + V_Recalc(); V_Init(); CV_RegisterVar(&cv_highreshudscale); @@ -239,29 +227,7 @@ void SCR_Recalc(void) if (dedicated) return; - // scale 1,2,3 times in x and y the patches for the menus and overlays... - // calculated once and for all, used by routines in v_video.c - vid.dupx = vid.width / BASEVIDWIDTH; - vid.dupy = vid.height / BASEVIDHEIGHT; - vid.dupx = vid.dupy = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - vid.fdupx = FixedDiv(vid.width*FRACUNIT, BASEVIDWIDTH*FRACUNIT); - vid.fdupy = FixedDiv(vid.height*FRACUNIT, BASEVIDHEIGHT*FRACUNIT); - - if ((vid.width > 720) && (vid.height > 1280)) // ehhhh well this thing has so many issues, so ill lock it to higher resolutions instead - { - vid.dupx = FixedDiv(vid.dupx, cv_highreshudscale.value); - vid.dupy = FixedDiv(vid.dupy, cv_highreshudscale.value); - vid.fdupx = FixedDiv(vid.fdupx, cv_highreshudscale.value); - vid.fdupy = FixedDiv(vid.fdupy, cv_highreshudscale.value); - } - - vid.fdupx = vid.fdupy = (vid.fdupx < vid.fdupy ? vid.fdupx : vid.fdupy); - - vid.meddupx = (UINT8)(vid.dupx >> 1) + 1; - vid.meddupy = (UINT8)(vid.dupy >> 1) + 1; - - vid.smalldupx = (UINT8)(vid.dupx / 3) + 1; - vid.smalldupy = (UINT8)(vid.dupy / 3) + 1; + V_Recalc(); // toggle off (then back on) the automap because some screensize-dependent values will // be calculated next time the automap is activated. diff --git a/src/screen.h b/src/screen.h index ce72e168e..df5baee18 100644 --- a/src/screen.h +++ b/src/screen.h @@ -47,8 +47,6 @@ // global video state typedef struct viddef_s { - INT32 modenum; // vidmode num indexes videomodes list - // Each screen is [vid.width*vid.height]; UINT8 *screens[5]; // screens[0] = main display window @@ -57,14 +55,18 @@ typedef struct viddef_s // screens[3] = fade screen start // screens[4] = fade screen end, postimage tempoarary buffer - INT32 width; // PIXELS per scanline + INT32 width; // PIXELS per scanline INT32 height; - boolean recalc; // if true, recalc vid-based stuff - INT32 dupx, dupy; // scale 1, 2, 3 value for menus & overlays - INT32/*fixed_t*/ fdupx, fdupy; // same as dupx, dupy, but exact value when aspect ratio isn't 320/200 - UINT8 smalldupx, smalldupy; // factor for a little bit of scaling - UINT8 meddupx, meddupy; // factor for moderate, but not full, scaling + INT32 modenum; // vidmode num indexes videomodes list + boolean recalc; // if true, recalc vid-based stuff + + INT32 dup; // scale 1, 2, 3 value for menus & overlays + INT32 fdup; // same as dup, but exact value when aspect ratio isn't 320/200 + UINT8 smalldup; // factor for a little bit of scaling + UINT8 meddup; // factor for moderate, but not full, scaling + + INT32 scaledwidth; // width / dup #ifdef HWRENDER INT32 glstate; #endif diff --git a/src/st_stuff.c b/src/st_stuff.c index 976de5686..5d0b75b9e 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -437,8 +437,7 @@ static void ST_drawLevelTitle(void) subttl = mapheaderinfo[gamemap-1]->subttl; zonttl = mapheaderinfo[gamemap-1]->zonttl; // SRB2kart actnum = mapheaderinfo[gamemap-1]->actnum; - dupcalc = (vid.width/vid.dupx); - + dupcalc = vid.scaledwidth; bary = (splitscreen) ? BASEVIDHEIGHT/2 : 163; if (K_UseColorHud()) @@ -601,7 +600,7 @@ static void ST_overlayDrawer(void) } else if (splitscreen) { - V_DrawCenteredThinString((vid.width/vid.dupx)/4, BASEVIDHEIGHT/2 - 12, V_HUDTRANSHALF|V_ALLOWLOWERCASE|K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT), player_names[stplyr-players]); + V_DrawCenteredThinString(vid.scaledwidth/4, BASEVIDHEIGHT/2 - 12, V_HUDTRANSHALF|V_ALLOWLOWERCASE|K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT), player_names[stplyr-players]); } } } diff --git a/src/v_video.c b/src/v_video.c index 9faa6dcb4..5ee222988 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -661,7 +661,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca UINT32 blendmode; fixed_t col, ofs, colfrac, rowfrac, fdup, vdup; - INT32 dupx, dupy; + INT32 dup; const column_t *column; UINT8 *desttop, *dest, *deststart, *destend; const UINT8 *source, *deststop; @@ -719,36 +719,38 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca patchdrawtype = (v_translevel) ? TRANSMAPPEDDRAW : MAPPEDDRAW; } - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; if (scrn & V_SCALEPATCHMASK) { switch ((scrn & V_SCALEPATCHMASK) >> V_SCALEPATCHSHIFT) { case 1: // V_NOSCALEPATCH - dupx = dupy = 1; + dup = 1; break; case 2: // V_SMALLSCALEPATCH - dupx = vid.smalldupx; - dupy = vid.smalldupy; + dup = vid.smalldup; break; case 3: // V_MEDSCALEPATCH - dupx = vid.meddupx; - dupy = vid.meddupy; + dup = vid.meddup; break; default: break; } } - // only use one dup, to avoid stretching (har har) - dupx = dupy = (dupx < dupy ? dupx : dupy); - fdup = vdup = FixedMul(dupx<topoffset<>= FRACBITS; y >>= FRACBITS; @@ -818,26 +820,27 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca } } - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // dup adjustments pretend that screen width is BASEVIDWIDTH * dup, // so center this imaginary screen if ((scrn & (V_HORZSCREEN|V_SNAPTOLEFT)) == (V_HORZSCREEN|V_SNAPTOLEFT)) - x += (vid.width/2 - (BASEVIDWIDTH/2 * dupx)); + x += (vid.width/2 - (BASEVIDWIDTH/2 * dup)); else if (scrn & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * dup)); else if (!(scrn & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + + if (vid.height != BASEVIDHEIGHT * dup) { // same thing here if ((scrn & (V_SPLITSCREEN|V_SNAPTOTOP)) == (V_SPLITSCREEN|V_SNAPTOTOP)) - y += (vid.height/2 - (BASEVIDHEIGHT/2 * dupy)); + y += (vid.height/2 - (BASEVIDHEIGHT/2 * dup)); else if (scrn & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * dup)); else if (!(scrn & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * dup)) / 2; } } @@ -848,11 +851,11 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca { pwidth = patch->width<>= FRACBITS; } else - pwidth = patch->width * dupx; + pwidth = patch->width * dup; deststart = desttop; destend = desttop + pwidth; @@ -982,7 +985,6 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ UINT32 alphalevel = 0; fixed_t col, ofs, colfrac, rowfrac, fdup; - INT32 dupx, dupy; const column_t *column; UINT8 *desttop, *dest; const UINT8 *source, *deststop; @@ -1026,11 +1028,8 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ } } - // only use one dup, to avoid stretching (har har) - dupx = dupy = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - fdup = FixedMul(dupx<topoffset<leftoffset<>= FRACBITS; y >>= FRACBITS; @@ -1061,22 +1060,23 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ // if it's meant to cover the whole screen, black out the rest // no the patch is cropped do not do this ever - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // vid.dup adjustments pretend that screen width is BASEVIDWIDTH * vid.dup, // so center this imaginary screen if (scrn & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * vid.dup)); else if (!(scrn & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here if (scrn & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * vid.dup)); else if (!(scrn & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 2; } } @@ -1226,42 +1226,41 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) if (!(c & V_NOSCALESTART)) { - INT32 dupx = vid.dupx, dupy = vid.dupy; - if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { // Clear the entire screen, from dest to deststop. Yes, this really works. memset(vid.screens[0], (c&255), vid.width * vid.height); return; } - x *= dupx; - y *= dupy; - w *= dupx; - h *= dupy; + x *= vid.dup; + y *= vid.dup; + w *= vid.dup; + h *= vid.dup; // Center it if necessary - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // vid.dup adjustments pretend that screen width is BASEVIDWIDTH * vid.dup, // so center this imaginary screen if (c & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * vid.dup)); else if (!(c & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here if (c & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * vid.dup)); else if (!(c & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 2; } if (c & V_SPLITSCREEN) - y += (BASEVIDHEIGHT * dupy)/2; + y += (BASEVIDHEIGHT * vid.dup)/2; if (c & V_HORZSCREEN) - x += (BASEVIDWIDTH * dupx)/2; + x += (BASEVIDWIDTH * vid.dup)/2; } if (x >= vid.width || y >= vid.height) @@ -1386,36 +1385,35 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) if (!(c & V_NOSCALESTART)) { - INT32 dupx = vid.dupx, dupy = vid.dupy; - if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { // Clear the entire screen, from dest to deststop. Yes, this really works. memset(vid.screens[0], (UINT8)(c&255), vid.width * vid.height); return; } - x *= dupx; - y *= dupy; - w *= dupx; - h *= dupy; + x *= vid.dup; + y *= vid.dup; + w *= vid.dup; + h *= vid.dup; // Center it if necessary - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // vid.dup adjustments pretend that screen width is BASEVIDWIDTH * vid.dup, // so center this imaginary screen if (c & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * vid.dup)); else if (!(c & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here if (c & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * vid.dup)); else if (!(c & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 2; } } @@ -1477,8 +1475,10 @@ void V_DrawFillConsoleMap(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) w = clip(w,vid.width); h = clip(h,vid.height); #undef clip - for (v = 0; v < h; v++, dest += vid.width) { - for (u = 0; u < w; u++) { + for (v = 0; v < h; v++, dest += vid.width) + { + for (u = 0; u < w; u++) + { dest[u] = fadetable[consolebgmap[dest[u]]]; } } @@ -1511,34 +1511,32 @@ void V_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 c) if (!(c & V_NOSCALESTART)) { - INT32 dupx = vid.dupx, dupy = vid.dupy; - - x *= dupx; - y *= dupy; - wh *= dupx; + x *= vid.dup; + y *= vid.dup; + wh *= vid.dup; // Center it if necessary - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // vid.dup adjustments pretend that screen width is BASEVIDWIDTH * vid.dup, // so center this imaginary screen if (c & V_SNAPTORIGHT) - x += (vid.width - (BASEVIDWIDTH * dupx)); + x += (vid.width - (BASEVIDWIDTH * vid.dup)); else if (!(c & V_SNAPTOLEFT)) - x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + x += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here if (c & V_SNAPTOBOTTOM) - y += (vid.height - (BASEVIDHEIGHT * dupy)); + y += (vid.height - (BASEVIDHEIGHT * vid.dup)); else if (!(c & V_SNAPTOTOP)) - y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + y += (vid.height - (BASEVIDHEIGHT * vid.dup)) / 2; } if (c & V_SPLITSCREEN) - y += (BASEVIDHEIGHT * dupy)/2; + y += (BASEVIDHEIGHT * vid.dup)/2; if (c & V_HORZSCREEN) - x += (BASEVIDWIDTH * dupx)/2; + x += (BASEVIDWIDTH * vid.dup)/2; } if (x >= vid.width || y >= vid.height) @@ -1591,7 +1589,7 @@ void V_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 c) // void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) { - INT32 u, v, dupx, dupy; + INT32 u, v; fixed_t dx, dy, xfrac, yfrac; const UINT8 *src, *deststop; UINT8 *flat, *dest; @@ -1641,29 +1639,28 @@ void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) flat = W_CacheLumpNum(flatnum, PU_CACHE); - dupx = dupy = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - - dest = vid.screens[0] + y*dupy*vid.width + x*dupx; + dest = vid.screens[0] + y*vid.dup*vid.width + x*vid.dup; deststop = vid.screens[0] + vid.width * vid.height; // from V_DrawScaledPatch - if (vid.width != BASEVIDWIDTH * dupx) + if (vid.width != BASEVIDWIDTH * vid.dup) { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // vid.dup adjustments pretend that screen width is BASEVIDWIDTH * vid.dup, // so center this imaginary screen - dest += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + dest += (vid.width - (BASEVIDWIDTH * vid.dup)) / 2; } - if (vid.height != BASEVIDHEIGHT * dupy) + + if (vid.height != BASEVIDHEIGHT * vid.dup) { // same thing here - dest += (vid.height - (BASEVIDHEIGHT * dupy)) * vid.width / 2; + dest += (vid.height - (BASEVIDHEIGHT * vid.dup)) * vid.width / 2; } - w *= dupx; - h *= dupy; + w *= vid.dup; + h *= vid.dup; - dx = FixedDiv(FRACUNIT, dupx<<(FRACBITS-2)); - dy = FixedDiv(FRACUNIT, dupy<<(FRACBITS-2)); + dx = FixedDiv(FRACUNIT, vid.dup<<(FRACBITS-2)); + dy = FixedDiv(FRACUNIT, vid.dup<<(FRACBITS-2)); yfrac = 0; for (v = 0; v < h; v++, dest += vid.width) @@ -1686,8 +1683,7 @@ void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) // void V_DrawPatchFill(patch_t *pat) { - INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - INT32 x, y, pw = pat->width * dupz, ph = pat->height * dupz; + INT32 x, y, pw = pat->width * vid.dup, ph = pat->height * vid.dup; for (x = 0; x < vid.width; x += pw) { @@ -1756,15 +1752,15 @@ void V_DrawVhsEffect(boolean rewind) UINT8 *thismapstart; SINT8 offs; - UINT8 barsize = vid.dupy<<5; - UINT8 updistort = vid.dupx<<(rewind ? 5 : 3); + UINT8 barsize = vid.dup<<5; + UINT8 updistort = vid.dup<<(rewind ? 5 : 3); UINT8 downdistort = updistort>>1; if (rewind) V_DrawVhsEffect(false); // experimentation - upbary -= renderdeltatics * (vid.dupy * (rewind ? 3 : 1.8f)); - downbary += renderdeltatics * (vid.dupy * (rewind ? 2 : 1)); + upbary -= renderdeltatics * (vid.dup * (rewind ? 3 : 1.8f)); + downbary += renderdeltatics * (vid.dup * (rewind ? 2 : 1)); if (upbary < -barsize*FRACUNIT) upbary = vid.height<= vid.height-2 && offs > 0)) @@ -2045,7 +2041,7 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) // void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2056,14 +2052,14 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.scaledwidth; + if (!(option & V_SNAPTOLEFT)) { left = (scrwidth - BASEVIDWIDTH)/2; @@ -2107,9 +2103,9 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) cx = x; if (option & V_RETURN8) - cy += 8*dupy; + cy += 8*dup; else - cy += 12*dupy; + cy += 12*dup; continue; } @@ -2122,17 +2118,17 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) // character does not exist or is a space if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) { - cx += spacewidth * dupx; + cx += spacewidth * dup; continue; } if (charwidth) { - w = charwidth * dupx; - center = w/2 - hu_font[c]->width*dupx/2; + w = charwidth * dup; + center = w/2 - hu_font[c]->width*dup/2; } else - w = hu_font[c]->width * dupx; + w = hu_font[c]->width * dup; if (cx > scrwidth) break; @@ -2151,7 +2147,7 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) // SRB2kart void V_DrawKartString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2162,14 +2158,13 @@ void V_DrawKartString(INT32 x, INT32 y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.scaledwidth; left = (scrwidth - BASEVIDWIDTH)/2; } @@ -2209,9 +2204,9 @@ void V_DrawKartString(INT32 x, INT32 y, INT32 option, const char *string) cx = x; if (option & V_RETURN8) - cy += 8*dupy; + cy += 8*dup; else - cy += 12*dupy; + cy += 12*dup; continue; } @@ -2224,17 +2219,17 @@ void V_DrawKartString(INT32 x, INT32 y, INT32 option, const char *string) // character does not exist or is a space if (c < 0 || c >= KART_FONTSIZE || !kart_font[c]) { - cx += spacewidth * dupx; + cx += spacewidth * dup; continue; } if (charwidth) { - w = charwidth * dupx; - center = w/2 - kart_font[c]->width*dupx/2; + w = charwidth * dup; + center = w/2 - kart_font[c]->width*dup/2; } else - w = kart_font[c]->width * dupx; + w = kart_font[c]->width * dup; if (cx > scrwidth) break; @@ -2269,7 +2264,7 @@ void V_DrawRightAlignedString(INT32 x, INT32 y, INT32 option, const char *string // void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2280,14 +2275,13 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.scaledwidth; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } @@ -2328,9 +2322,9 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) cx = x; if (option & V_RETURN8) - cy += 4*dupy; + cy += 4*dup; else - cy += 6*dupy; + cy += 6*dup; continue; } @@ -2342,19 +2336,21 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) { - cx += spacewidth * dupx; + cx += spacewidth * dup; continue; } if (charwidth) { - w = charwidth * dupx; - center = w/2 - hu_font[c]->width*dupx/4; + w = charwidth * dup; + center = w/2 - hu_font[c]->width*dup/4; } else - w = hu_font[c]->width * dupx / 2; + w = hu_font[c]->width * dup / 2; + if (cx > scrwidth) break; + if (cx+left + w < 0) //left boundary check { cx += w; @@ -2385,7 +2381,7 @@ void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *s // void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -2396,14 +2392,13 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.scaledwidth; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } @@ -2445,9 +2440,9 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) cx = x; if (option & V_RETURN8) - cy += 8*dupy; + cy += 8*dup; else - cy += 12*dupy; + cy += 12*dup; continue; } @@ -2459,18 +2454,19 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) if (c < 0 || c >= HU_FONTSIZE || !tny_font[c]) { - cx += spacewidth * dupx; + cx += spacewidth * dup; continue; } if (charwidth) - w = charwidth * dupx; + w = charwidth * dup; else w = ((option & V_6WIDTHSPACE ? max(1, tny_font[c]->width-1) // Reuse this flag for the alternate bunched-up spacing - : tny_font[c]->width) * dupx); + : tny_font[c]->width) * dup); if (cx > scrwidth) break; + if (cx+left + w < 0) //left boundary check { cx += w; @@ -2499,7 +2495,7 @@ void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *st void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { fixed_t cx = x, cy = y; - INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; + INT32 w, c, dup, scrwidth, center = 0, left = 0; const char *ch = string; INT32 spacewidth = 4, charwidth = 0; @@ -2508,14 +2504,13 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.scaledwidth; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } @@ -2538,16 +2533,18 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { if (!*ch) break; + if (*ch & 0x80) //color ignoring continue; + if (*ch == '\n') { cx = x; if (option & V_RETURN8) - cy += (8*dupy)<= HU_FONTSIZE || !hu_font[c]) { - cx += (spacewidth * dupx)<width*(dupx/2); + w = charwidth * dup; + center = w/2 - hu_font[c]->width*(dup/2); } else - w = hu_font[c]->width * dupx; + w = hu_font[c]->width * dup; if ((cx>>FRACBITS) > scrwidth) break; + if ((cx>>FRACBITS)+left + w < 0) //left boundary check { cx += w<= HU_FONTSIZE || !hu_font[c]) { - cx += (spacewidth * dupx)<width*(dupx/4); + w = charwidth * dup; + center = w/2 - hu_font[c]->width*(dup/4); } else - w = hu_font[c]->width * dupx / 2; + w = hu_font[c]->width * dup / 2; + if ((cx>>FRACBITS) > scrwidth) break; + if ((cx>>FRACBITS)+left + w < 0) //left boundary check { cx += w<= HU_FONTSIZE || !tny_font[c]) { - cx += (spacewidth * dupx)<width*(dupx/2); + w = charwidth * dup; + center = w/2 - tny_font[c]->width*(dup/2); } else - w = tny_font[c]->width * dupx; + w = tny_font[c]->width * dup; if ((cx>>FRACBITS) > scrwidth) break; + if ((cx>>FRACBITS)+left + w < 0) //left boundary check { cx += w<width; if (flags & V_NOSCALESTART) - w *= vid.dupx; + w *= vid.dup; if (num < 0) num = -num; @@ -2838,7 +2851,7 @@ void V_DrawPaddedTallColorNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 di INT32 w = tallnum[0]->width; if (flags & V_NOSCALESTART) - w *= vid.dupx; + w *= vid.dup; if (num < 0) num = -num; @@ -2860,7 +2873,7 @@ INT32 V_DrawPingNum(INT32 x, INT32 y, INT32 flags, INT32 num, const UINT8 *color INT32 w = pingnum[0]->width; // this SHOULD always be 5 but I guess custom graphics exist. if (flags & V_NOSCALESTART) - w *= vid.dupx; + w *= vid.dup; if (num < 0) num = -num; @@ -2883,7 +2896,7 @@ void V_DrawRankNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits, const INT32 w = ranknum[0]->width - 1; if (flags & V_NOSCALESTART) - w *= vid.dupx; + w *= vid.dup; if (num < 0) num = -num; @@ -2903,7 +2916,7 @@ void V_DrawRankNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits, const // void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) { - INT32 w, c, dupx, dupy, scrwidth = BASEVIDWIDTH; + INT32 w, c, dup, scrwidth = BASEVIDWIDTH; fixed_t cx = x, cy = y; const char *ch = string; @@ -2913,33 +2926,36 @@ void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else - dupx = dupy = 1; + dup = 1; for (;;) { c = *ch++; + if (!c) break; + if (c == '\n') { cx = x; - cy += (12*dupy)<= CRED_FONTSIZE) { - cx += (16*dupx)<width * dupx; + w = cred_font[c]->width * dup; + if ((cx>>FRACBITS) > scrwidth) break; @@ -2976,19 +2992,18 @@ INT32 V_CreditStringWidth(const char *string) // void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, left = 0; + INT32 w, c, cx = x, cy = y, dup, scrwidth, left = 0; const char *ch = string; if (option & V_NOSCALESTART) { - dupx = vid.dupx; - dupy = vid.dupy; + dup = vid.dup; scrwidth = vid.width; } else { - dupx = dupy = 1; - scrwidth = vid.width/vid.dupx; + dup = 1; + scrwidth = vid.scaledwidth; left = (scrwidth - BASEVIDWIDTH)/2; scrwidth -= left; } @@ -2996,25 +3011,30 @@ void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) for (;;) { c = *ch++; + if (!c) break; + if (c == '\n') { cx = x; - cy += 12*dupy; + cy += 12*dup; continue; } c = toupper(c) - LT_FONTSTART; + if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) { - cx += 12*dupx; + cx += 12*dup; continue; } - w = lt_font[c]->width * dupx; + w = lt_font[c]->width * dup; + if (cx > scrwidth) break; + if (cx+left + w < 0) //left boundary check { cx += w; @@ -3664,7 +3684,7 @@ void V_DoPostProcessor(INT32 view, INT32 param) { // Shift this row of pixels to the right by 2 tmpscr[(y*vid.width)+xoffset] = srcscr[(y*vid.width)+xoffset]; - M_Memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset+vid.dupx], viewwidth-vid.dupx); + M_Memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset+vid.dup], viewwidth-vid.dup); } else M_Memcpy(&tmpscr[(y*vid.width)+xoffset], &srcscr[(y*vid.width)+xoffset], viewwidth); @@ -3826,3 +3846,33 @@ void V_Init(void) CONS_Debug(DBG_RENDER, " screens[%d] = %x\n", i, screens[i]); #endif } + +void V_Recalc(void) +{ + // scale 1,2,3 times in x and y the patches for the menus and overlays... + // calculated once and for all, used by routines in v_video.c and v_draw.c + + // Set dup based on width or height, whichever is less + if (((vid.width*FRACUNIT) / BASEVIDWIDTH) < ((vid.height*FRACUNIT) / BASEVIDHEIGHT)) + { + vid.dup = vid.width / BASEVIDWIDTH; + vid.fdup = (vid.width*FRACUNIT) / BASEVIDWIDTH; + } + else + { + vid.dup = vid.height / BASEVIDHEIGHT; + vid.fdup = (vid.height*FRACUNIT) / BASEVIDHEIGHT; + } + + if (loaded_config // this could use a better name, since it is more and indicator that early startup is done and its safe to do sketchy shit now :chaosleep: + && (vid.width > 720) && (vid.height > 1280)) // ehhhh well this thing has so many issues, so ill lock it to higher resolutions instead + { + vid.dup = FixedDiv(vid.dup, cv_highreshudscale.value); + vid.fdup = FixedDiv(vid.fdup, cv_highreshudscale.value); + } + + vid.scaledwidth = (vid.width/vid.dup); + + vid.meddup = (UINT8)(vid.dup >> 1) + 1; + vid.smalldup = (UINT8)(vid.dup / 3) + 1; +} diff --git a/src/v_video.h b/src/v_video.h index 1032082be..6213dc1bb 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -48,6 +48,7 @@ cv_palette, cv_palettenum; // Allocates buffer screens, call before R_Init. void V_Init(void); +void V_Recalc(void); // Color look-up table #define CLUTINDEX(r, g, b) (((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3) diff --git a/src/y_inter.c b/src/y_inter.c index 76479aa42..c1bdafd32 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -283,7 +283,7 @@ static void Y_PlayerStandingsDrawer(y_data_t *standings, INT32 x, INT32 hilicol) #define NUMFORNEWCOLUMN 8 INT32 y = 41, gutter = ((standings->numplayers > NUMFORNEWCOLUMN) ? 0 : (BASEVIDWIDTH/2)); - INT32 dupadjust = cv_betainterscreen.value ? 314 : (vid.width/vid.dupx), duptweak = cv_betainterscreen.value ? -3 : (dupadjust - BASEVIDWIDTH)/2; + INT32 dupadjust = cv_betainterscreen.value ? 314 : vid.scaledwidth, duptweak = cv_betainterscreen.value ? -3 : (dupadjust - BASEVIDWIDTH)/2; const char *timeheader; if (standings->rankingsmode) @@ -473,9 +473,9 @@ void Y_IntermissionDrawer(void) INT64 count = (intertic - sorttic); if (count < 8) - x -= ((((count<>FRACBITS) / (8 * vid.dupx); + x -= ((((count<>FRACBITS) / (8 * vid.dup); else if (count < 16) - x += (((((16 - count)<>FRACBITS) / (8 * vid.dupx); + x += (((((16 - count)<>FRACBITS) / (8 * vid.dup); } if (intertype == int_race || intertype == int_match) @@ -883,8 +883,8 @@ static void Y_VoteBackgroundDrawer(patch_t *patch) break; case 0: // vanilla default: - V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (patch->width/2), - (vid.height / vid.dupy) - patch->height, + V_DrawScaledPatch(((vid.width/2) / vid.dup) - (patch->width/2), + (vid.height / vid.dup) - patch->height, V_SNAPTOTOP|V_SNAPTOLEFT, patch); break; } @@ -935,7 +935,7 @@ static void Y_DrawLuaVoteScreenPatch(boolean widePatch) static void Y_DrawVoteScreenPatch(void) { patch_t *votebg = NULL; - const boolean widescreen = (vid.width / vid.dupx > 320); + const boolean widescreen = (vid.scaledwidth > 320); if (VoteScreen.foundLuaVoteWideFrames || VoteScreen.foundLuaVoteFrames) { From 2434acf825e6151728b8cea84921f091a9f3cccc Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 16:33:44 +0200 Subject: [PATCH 12/39] change comment for PU_PATCH_ROTATED --- src/z_zone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/z_zone.h b/src/z_zone.h index 0d482ad62..90a55b465 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -51,7 +51,7 @@ enum PU_PATCH = 14, // static entire execution time PU_PATCH_LOWPRIORITY = 15, // lower priority patch, static until level exited - PU_PATCH_ROTATED = 16, // rotated patch, static until level exited or WAD added + PU_PATCH_ROTATED = 16, // rotated patch, static entire execution time PU_PATCH_DATA = 17, // patch data, lifetime depends on the patch that owns it PU_SPRITE = 18, // sprite patch, static until WAD added PU_HUDGFX = 19, // HUD patch, static until WAD added From 65bd06aae580738ea7a2ae897e12455adee6bb93 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 18:16:23 +0200 Subject: [PATCH 13/39] fix some potential leaks --- src/g_game.c | 2 ++ src/hardware/hw_batching.c | 4 ---- src/hardware/hw_bsp.c | 12 +++++++----- src/hu_stuff.c | 6 ++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 0b74aca5c..b25db24d3 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3584,6 +3584,8 @@ void G_SaveGameData(boolean force) if (!FIL_CopyFile(gamedatafilename, backupfile)) { CONS_Alert(CONS_WARNING,"Failed to create a backup of save data. Will not attempt to write to save data\n"); + free(save.buffer); + save.p = save.buffer = NULL; return; } } diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 5dcbfb4cf..3e0c2320b 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -455,7 +455,6 @@ void HWR_RenderBatches(void) { GL_SetShader(nextShader); currentShader = nextShader; - changeShader = false; ps_hw_numshaders.value.i++; } @@ -465,7 +464,6 @@ void HWR_RenderBatches(void) // texture should be already ready for use from calls to GL_SetTexture during batch collection GL_SetTexture(nextTexture); currentTexture = nextTexture; - changeTexture = false; ps_hw_numtextures.value.i++; } @@ -473,7 +471,6 @@ void HWR_RenderBatches(void) if (changePolyFlags) { currentPolyFlags = nextPolyFlags; - changePolyFlags = false; ps_hw_numpolyflags.value.i++; } @@ -481,7 +478,6 @@ void HWR_RenderBatches(void) if (changeSurfaceInfo) { currentSurfaceInfo = nextSurfaceInfo; - changeSurfaceInfo = false; ps_hw_numcolors.value.i++; } diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index d2a5ac498..8cad91168 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -974,7 +974,7 @@ void HWR_CreatePlanePolygons(INT32 bspnum) CONS_Debug(DBG_RENDER, "Looking for boundaries of map...\n"); #endif M_ClearBox(rootbbox); - for (i = 0;i < numvertexes; i++) + for (i = 0; i < numvertexes; i++) M_AddToBox(rootbbox, vertexes[i].x, vertexes[i].y); #ifdef DEBUG_HWBSP @@ -985,8 +985,8 @@ void HWR_CreatePlanePolygons(INT32 bspnum) // allocate extra data for each subsector present in map totsubsectors = numsubsectors + NEWSUBSECTORS; - extrasubsectors = calloc(totsubsectors, sizeof (*extrasubsectors)); - if (UNLIKELY(extrasubsectors == NULL)) + extrasubsectors = calloc(totsubsectors, sizeof(*extrasubsectors)); + if (UNLIKELY(!extrasubsectors)) I_Error("couldn't malloc extrasubsectors totsubsectors %s\n", sizeu1(totsubsectors)); // number of the first new subsector that might be added @@ -1009,11 +1009,13 @@ void HWR_CreatePlanePolygons(INT32 bspnum) rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXBOTTOM]); //ll rootpv++; - WalkBSPNode(bspnum, rootp, NULL,rootbbox); + WalkBSPNode(bspnum, rootp, NULL, rootbbox); - i = SolveTProblem(); #ifdef DEBUG_HWBSP + i = SolveTProblem(); CONS_Debug(DBG_RENDER, "%d point divides a polygon line\n",i); +#else + SolveTProblem(); #endif AdjustSegs(); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 714198e5c..2f9171a9f 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1234,8 +1234,8 @@ static void HU_SendChatMessage(void) if (len > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { INT32 spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); const char *newmsg; + CLEANUP(pfree) char *nodenum = (char*) malloc(3); // what we're gonna do now is check if the node exists // with that logic, characters 4 and 5 are our numbers: @@ -1260,7 +1260,6 @@ static void HU_SendChatMessage(void) else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } @@ -1270,13 +1269,11 @@ static void HU_SendChatMessage(void) if (msg[5] != ' ') { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } target = atoi((const char*) nodenum); // turn that into a number - free(nodenum); //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -1292,6 +1289,7 @@ static void HU_SendChatMessage(void) newmsg = msg+5+spc; strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } + if (ci > 3) // don't send target+flags+empty message. { if (teamtalk) From ba985248eaacd613e527cd7c497aa5e92f6399f2 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 20:29:54 +0200 Subject: [PATCH 14/39] fix crash when theres no minimap patch fall back to the "inaccurate" calc from before, so automap may still work --- src/p_setup.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 8c6750c50..072cfb934 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2442,10 +2442,38 @@ static void P_InitMinimapInfo(void) minimapinfo.map_w = minimapinfo.max_x - minimapinfo.min_x; minimapinfo.map_h = minimapinfo.max_y - minimapinfo.min_y; - minimapinfo.minimap_w = FixedDiv(minimapinfo.minimap_pic->width, minimapinfo.map_w); - minimapinfo.minimap_h = FixedDiv(minimapinfo.minimap_pic->height, minimapinfo.map_h); + if (minimapinfo.minimap_pic) + { + minimapinfo.minimap_w = FixedDiv(minimapinfo.minimap_pic->width, minimapinfo.map_w); + minimapinfo.minimap_h = FixedDiv(minimapinfo.minimap_pic->height, minimapinfo.map_h); + minimapinfo.zoom = FixedMul(min(minimapinfo.minimap_w, minimapinfo.minimap_h), FRACUNIT-FRACUNIT/20); + } + else // fallback to somewhat inaccurate calc, so automap can still work + { + fixed_t a, b; + minimapinfo.minimap_w = minimapinfo.minimap_h = 100; - minimapinfo.zoom = FixedMul(min(minimapinfo.minimap_w, minimapinfo.minimap_h), FRACUNIT-FRACUNIT/20); + a = FixedDiv(minimapinfo.minimap_w<>(FRACBITS-4); + minimapinfo.zoom = a; + } + else + { + if (a != b) + { + minimapinfo.minimap_w = FixedMul(b, minimapinfo.map_w)>>(FRACBITS-4); + } + + minimapinfo.zoom = b; + } + + minimapinfo.zoom >>= (FRACBITS-4); + minimapinfo.zoom -= (minimapinfo.zoom/20); + } // These should always be small enough to be bitshift back right now minimapinfo.offs_x = FixedMul((minimapinfo.min_x + minimapinfo.map_w/2) << FRACBITS, minimapinfo.zoom); From e94ef8d9c3744cca6753fba087ff866b71088bdd Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Sep 2025 06:57:28 +0200 Subject: [PATCH 15/39] handle W_VerifyNMUSlumps error in W_InitFile --- src/w_wad.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index bbb61db07..623efe118 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -797,7 +797,7 @@ UINT16 W_InitFile(const char *filename, boolean local, boolean startup) size_t i; #endif UINT8 md5sum[16]; - boolean important; + int important; if (!(refreshdirmenu & REFRESHDIR_ADDFILE)) refreshdirmenu = REFRESHDIR_NORMAL|REFRESHDIR_ADDFILE; // clean out cons_alerts that happened earlier @@ -827,7 +827,22 @@ UINT16 W_InitFile(const char *filename, boolean local, boolean startup) if ((handle = W_OpenWadFile(&filename, true)) == NULL) return W_InitFileError(filename, startup); - important = !local && !W_VerifyNMUSlumps(filename, handle, startup); + if (local) + { + important = 0; + } + else + { + important = W_VerifyNMUSlumps(filename, handle, startup); + + if (important == -1) + { + fclose(handle); + return INT16_MAX; + } + + important = !important; + } #ifndef NOMD5 // From 934184a0066e1dd040365cba9e213fda6cb14681 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Sep 2025 07:22:07 +0200 Subject: [PATCH 16/39] revert localfile check hack in CL_CheckFiles this was added ages ago and broke server joining with actual modifieng addons that were not added locally W_InitFile should already handle this and mark local addons not as important, which would skip those checks eitherway atleast thats what im hoping --- src/d_netfil.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index 112c9e9c3..34fa0f96d 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -494,9 +494,6 @@ INT32 CL_CheckFiles(void) size_t filestoload = 0; boolean downloadrequired = false; -// if (M_CheckParm("-nofiles")) -// return 1; - // the first is the iwad (the main wad file) // we don't care if it's called srb2.srb or srb2.wad. // Never download the IWAD, just assume it's there and identical @@ -510,8 +507,6 @@ INT32 CL_CheckFiles(void) { CONS_Debug(DBG_NETPLAY, "game is modified; only doing basic checks\n"); - boolean have_important = false; - for (i = 0, j = mainwads+1; i < fileneedednum || j < numwadfiles;) { if (j < numwadfiles && (!wadfiles[j]->important || wadfiles[j]->localfile)) @@ -523,15 +518,7 @@ INT32 CL_CheckFiles(void) // If this test is true, we've reached the end of one file list. if (i >= fileneedednum || j >= numwadfiles) - { - // We are missing some of important files, or have too much - // important files. - if (have_important) - return 2; - - // All checked files weren't important, don't care about them. - break; - } + return 2; // For the sake of speed, only bother with a md5 check if (memcmp(wadfiles[j]->md5sum, fileneeded[i].md5sum, 16)) @@ -539,14 +526,12 @@ INT32 CL_CheckFiles(void) // It's accounted for! let's keep going. CONS_Debug(DBG_NETPLAY, "'%s' accounted for\n", fileneeded[i].filename); - have_important = true; fileneeded[i].status = FS_OPEN; ++i; ++j; } - if (have_important) - return 1; + return 1; } for (i = 0; i < fileneedednum; i++) From 418ee2ce5f6d524df26b9b782d6d3c4c2c17cf93 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Sep 2025 07:38:03 +0200 Subject: [PATCH 17/39] remove localfile from wadfile struct this was a leftover from localskins we check for the "important" flag instead --- src/d_netfil.c | 2 +- src/p_setup.c | 2 -- src/w_wad.h | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/d_netfil.c b/src/d_netfil.c index 34fa0f96d..8724fab6d 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -509,7 +509,7 @@ INT32 CL_CheckFiles(void) for (i = 0, j = mainwads+1; i < fileneedednum || j < numwadfiles;) { - if (j < numwadfiles && (!wadfiles[j]->important || wadfiles[j]->localfile)) + if (j < numwadfiles && !wadfiles[j]->important) // TODO: add checks for localfiles that dont contain anything "allowed" (maps and stuff like that) { // Unimportant on our side. still don't care. ++j; diff --git a/src/p_setup.c b/src/p_setup.c index 072cfb934..acadcd194 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3157,8 +3157,6 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (wadfiles[wadnum]->important) partadd_important = true; - wadfiles[wadnum]->localfile = local; - lumpinfo = wadfiles[wadnum]->lumpinfo; for (i = 0; i < numlumps; i++, lumpinfo++) { diff --git a/src/w_wad.h b/src/w_wad.h index 3e0b9e0dc..c3cae627f 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -145,7 +145,6 @@ typedef struct wadfile_s UINT8 md5sum[16]; boolean important; boolean majormod; - boolean localfile; // only for skins } wadfile_t; #define WADFILENUM(lumpnum) (UINT16)((lumpnum)>>16) // wad flumpnum>>16) // wad file number in upper word From 939354f4834a3c62dd051fb4150e21e818ad4a3a Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Sep 2025 16:13:00 +0200 Subject: [PATCH 18/39] port over most fixes from srb2classics clang-tidy pr mostly taken from https://codeberg.org/srb2classic/srb2classic/pulls/156 manually done to ensure we only port things that are guaranteed to not cause any potential desynchs we should probably run this ourselves sometimes aswell --- src/am_map.c | 9 +++++- src/command.c | 6 ++-- src/d_main.c | 4 +-- src/d_netcmd.c | 2 +- src/d_protocol.c | 10 ++++--- src/dedicated/i_system.c | 2 +- src/dehacked.c | 18 ++++++------ src/f_finale.c | 7 ----- src/filesrch.c | 9 ++++-- src/g_game.c | 3 +- src/hardware/hw_cache.c | 4 ++- src/hardware/hw_main.cpp | 61 ++++++++++++++++++++-------------------- src/hardware/hw_md2.c | 26 ++--------------- src/http-mserv.c | 1 + src/hu_stuff.c | 16 +++++------ src/lua_baselib.c | 2 -- src/lua_hooklib.c | 2 +- src/m_aatree.c | 2 ++ src/m_fixed.c | 4 +-- src/m_menu.c | 57 +++++++++++++------------------------ src/m_misc.c | 4 +++ src/m_perfstats.c | 37 +++++++++++++++--------- src/p_enemy.c | 11 ++++---- src/p_inter.c | 29 ++++++++++++------- src/p_map.c | 12 ++++---- src/p_mobj.c | 10 +++---- src/p_pspr.h | 3 +- src/p_saveg.c | 1 - src/p_spec.c | 2 -- src/p_user.c | 30 ++++++++++---------- src/r_skins.c | 46 ++++++++++++++++-------------- src/r_things.cpp | 19 +++++-------- src/sdl/i_system.cpp | 2 +- src/tables.c | 5 ++-- src/v_video.c | 4 +-- 35 files changed, 220 insertions(+), 240 deletions(-) diff --git a/src/am_map.c b/src/am_map.c index f05f2def1..e3c3c988c 100644 --- a/src/am_map.c +++ b/src/am_map.c @@ -265,6 +265,11 @@ static void AM_findMinMaxBoundaries(void) max_w = minimapinfo.map_w << MAPBITS; max_h = minimapinfo.map_h << MAPBITS; + if (max_w == 0) + max_w = 1; + if (max_h == 0) + max_h = 1; + a = FixedDiv(f_w< max_scale_mtof) - scale_mtof = min_scale_mtof; + scale_mtof = max_scale_mtof; + if (scale_mtof == 0) + scale_mtof = 1; scale_ftom = FixedDiv(FRACUNIT, scale_mtof); } diff --git a/src/command.c b/src/command.c index 63cb834e6..292c51861 100644 --- a/src/command.c +++ b/src/command.c @@ -712,12 +712,10 @@ static void COM_CEcho_f(void) for (i = 1; i < COM_Argc(); i++) { - strncat(cechotext, COM_Argv(i), sizeof(cechotext)-1); - strncat(cechotext, " ", sizeof(cechotext)-1); + strlcpy(cechotext, COM_Argv(i), sizeof(cechotext)-1); + strlcat(cechotext, " ", sizeof(cechotext)-1); } - cechotext[sizeof(cechotext) - 1] = '\0'; - HU_DoCEcho(cechotext); } diff --git a/src/d_main.c b/src/d_main.c index f37675db2..b9cfbcd06 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -773,7 +773,6 @@ void D_SRB2Loop(void) // capbudget is the minimum precise_t duration of a single loop iteration precise_t capbudget; precise_t enterprecise = I_GetPreciseTime(); - precise_t finishprecise = enterprecise; Z_Frame_Reset(); @@ -917,7 +916,7 @@ void D_SRB2Loop(void) } #endif // Fully completed frame made. - finishprecise = I_GetPreciseTime(); + precise_t finishprecise = I_GetPreciseTime(); // Use the time before sleep for frameskip calculations: // post-sleep time is literally being intentionally wasted @@ -1114,6 +1113,7 @@ static void D_AutoloadFile(const char *file, char **filearray) if (!fileType) { CONS_Printf("D_AutoloadFile: File %s is unknown or invalid\n", file); + free(newfile); return; } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index d71e4f88a..71a807652 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5281,7 +5281,7 @@ retryscramble: memset(&scrambleplayers, 0, sizeof(scrambleplayers)); memset(&scrambleteams, 0, sizeof(scrambleplayers)); scrambletotal = scramblecount = 0; - blue = red = maxcomposition = newteam = playercount = 0; + blue = red = newteam = playercount = 0; repick = true; // Put each player's node in the array. diff --git a/src/d_protocol.c b/src/d_protocol.c index ee943f08d..eb65b6f70 100644 --- a/src/d_protocol.c +++ b/src/d_protocol.c @@ -207,13 +207,14 @@ void D_SetupProtocol(void) fp = fopen(protocolfile, "a+"); result = fgets(buffer, PATH_MAX, fp); + if (result) { if (strcmp(buffer, "no") == 0) - { - fclose(fp); - return; - } + { + fclose(fp); + return; + } else if (strcmp(buffer, exe_path) != 0) { // overwrite @@ -232,6 +233,7 @@ void D_SetupProtocol(void) else fprintf(fp, "no"); } + fclose(fp); } diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index c35dc0346..585c82de8 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -2017,7 +2017,7 @@ const char *I_LocateWad(void) #if defined (_WIN32) SetCurrentDirectoryA(waddir); #else - if (chdir(waddir) == -1) + if (waddir == NULL || chdir(waddir) == -1) I_OutputMsg("Couldn't change working directory\n"); #endif } diff --git a/src/dehacked.c b/src/dehacked.c index 442e6d0d4..1e2fd5798 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -754,7 +754,7 @@ static void readlevelheader(MYFILE *f, INT32 num, INT32 wadnum) strupr(word); // Now get the part after - word2 = tmp += 2; + word2 = tmp + 2; i = atoi(word2); // used for numerical settings // CHEAP HACK: move this over here for lowercase subtitles @@ -1393,7 +1393,7 @@ static void readhuditem(MYFILE *f, INT32 num) strupr(word); // Now get the part after - word2 = tmp += 2; + word2 = tmp + 2; strupr(word2); i = atoi(word2); // used for numerical settings @@ -1862,7 +1862,7 @@ static void reademblemdata(MYFILE *f, INT32 num) strupr(word); // Now get the part after - word2 = tmp += 2; + word2 = tmp + 2; value = atoi(word2); // used for numerical settings // Up here to allow lowercase in hints @@ -1989,7 +1989,7 @@ static void readextraemblemdata(MYFILE *f, INT32 num) strupr(word); // Now get the part after - word2 = tmp += 2; + word2 = tmp + 2; strupr(word2); value = atoi(word2); // used for numerical settings @@ -2067,7 +2067,7 @@ static void readunlockable(MYFILE *f, INT32 num) strupr(word); // Now get the part after - word2 = tmp += 2; + word2 = tmp + 2; strupr(word2); i = atoi(word2); // used for numerical settings @@ -2336,7 +2336,7 @@ static void readconditionset(MYFILE *f, UINT8 setnum) strupr(word); // Now get the part after - word2 = tmp += 2; + word2 = tmp + 2; strupr(word2); if (fastncmp(word, "CONDITION", 9)) @@ -2470,7 +2470,7 @@ static void readmaincfg(MYFILE *f) strupr(word); // Now get the part after - word2 = tmp += 2; + word2 = tmp + 2; strupr(word2); value = atoi(word2); // used for numerical settings @@ -2649,7 +2649,7 @@ static void readwipes(MYFILE *f) { char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); char *word = s; - char *pword = word; + char *pword; char *word2; char *tmp; INT32 value; @@ -2682,7 +2682,7 @@ static void readwipes(MYFILE *f) strupr(word); // Now get the part after - word2 = tmp += 2; + word2 = tmp + 2; value = atoi(word2); // used for numerical settings if (value < -1 || value > 99) diff --git a/src/f_finale.c b/src/f_finale.c index f8d2064c8..0fe0effc4 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1150,13 +1150,6 @@ void F_TitleScreenTicker(boolean run) // Setup demo name snprintf(dname, 9, "%sS%02u", mapname, numstaff); - /*if ((l = W_CheckNumForName(dname)) == LUMPERROR) -- we KNOW it exists now - { - CONS_Alert(CONS_ERROR, M_GetText("Demo lump \"%s\" doesn't exist\n"), dname); - F_StartIntro(); - return; - }*/ - loadreplay: demo.title = demo.fromtitle = true; demo.ignorefiles = true; diff --git a/src/filesrch.c b/src/filesrch.c index 0b112556c..27b519edf 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -444,10 +444,13 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) Z_Free(dirmenu); dirmenu = NULL; - for (; sizecoredirmenu > 0; sizecoredirmenu--) // clear out existing items + if (coredirmenu != NULL) { - Z_Free(coredirmenu[sizecoredirmenu-1]); - coredirmenu[sizecoredirmenu-1] = NULL; + for (; sizecoredirmenu > 0; sizecoredirmenu--) // clear out existing items + { + Z_Free(coredirmenu[sizecoredirmenu-1]); + coredirmenu[sizecoredirmenu-1] = NULL; + } } while (true) diff --git a/src/g_game.c b/src/g_game.c index b25db24d3..23b291c74 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4143,8 +4143,6 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, if (!( realmapname = G_BuildMapTitle(mapnum) )) continue; - aprop = realmapname; - /* Now that we found a perfect match no need to fucking guess. */ if (strnicmp(realmapname, mapname, mapnamelen) == 0) { @@ -4172,6 +4170,7 @@ INT32 G_FindMap(const char *mapname, char **foundmapnamep, writesimplefreq(freq, &freqc, mapnum, aprop - realmapname, mapnamelen); } + if (apromapnum == 0) { apromapnum = mapnum; diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index c1de7ba17..e48e2772a 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1190,7 +1190,9 @@ static void HWR_CacheFadeMask(GLMipmap_t *glMipmap, lumpnum_t fademasklumpnum) break; default: // Bad lump CONS_Alert(CONS_WARNING, "Fade mask lump of incorrect size, ignored\n"); // I should avoid this by checking the lumpnum in HWR_RunWipe - break; + glMipmap->width = 0; + glMipmap->height = 0; + return; } // Thankfully, this will still work for this scenario diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 6a0576284..04726315a 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3722,7 +3722,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) towmult = (towbot - towtop) / (top - bot); endrealtop = endtop = baseWallVerts[2].y; - endrealbot = endbot = baseWallVerts[1].y; + endrealbot = baseWallVerts[1].y; // copy the contents of baseWallVerts into the drawn wallVerts array // baseWallVerts is used to know the final shape to easily get the vertex @@ -3775,7 +3775,6 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) lightlevel = *list[sector->numlights - 1].lightlevel; colormap = list[sector->numlights - 1].extra_colormap; - i = 0; temp = FloatToFixed(realtop); lightset = HWR_OverrideObjectLightLevel(sprmo, &lightlevel); @@ -3919,7 +3918,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) mobj_t *sprmo = spr->mobj; - if (UNLIKELY(!sprmo || !sprmo->subsector)) + if (UNLIKELY(!sprmo->subsector)) return; const boolean papersprite = (sprmo->frame & FF_PAPERSPRITE); @@ -4510,42 +4509,44 @@ static void HWR_DrawSprites(void) HWR_DrawPrecipitationSprite(spr); continue; } - - if constexpr (Type == DrawSpritesType::kModels) + else if (spr->mobj) { - if (spr->mobj && spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) + if constexpr (Type == DrawSpritesType::kModels) { - md2_t *md2; - - if (spr->mobj->localskin) + if (spr->mobj->skin && spr->mobj->sprite == SPR_PLAY) { - if (spr->mobj->skinlocal) - md2 = &md2_localplayermodels[(skin_t *)spr->mobj->localskin - localskins]; + md2_t *md2; + + if (spr->mobj->localskin) + { + if (spr->mobj->skinlocal) + md2 = &md2_localplayermodels[(skin_t *)spr->mobj->localskin - localskins]; + else + md2 = &md2_playermodels [(skin_t *)spr->mobj->localskin - skins]; + } else - md2 = &md2_playermodels [(skin_t *)spr->mobj->localskin - skins]; + md2 = &md2_playermodels[(skin_t *)spr->mobj->skin - skins]; + + // 8/1/19: Only don't display player models if no default SPR_PLAY is found. + if (((md2->notfound || md2->scale < 0.0f) && ((!cv_glfallbackplayermodel.value) || md2_models[SPR_PLAY].notfound || md2_models[SPR_PLAY].scale < 0.0f)) || spr->mobj->state == &states[S_PLAY_SIGN]) + HWR_DrawSprite(spr); + else + HWR_DrawMD2(spr); } else - md2 = &md2_playermodels[(skin_t *)spr->mobj->skin - skins]; - - // 8/1/19: Only don't display player models if no default SPR_PLAY is found. - if (((md2->notfound || md2->scale < 0.0f) && ((!cv_glfallbackplayermodel.value) || md2_models[SPR_PLAY].notfound || md2_models[SPR_PLAY].scale < 0.0f)) || spr->mobj->state == &states[S_PLAY_SIGN]) - HWR_DrawSprite(spr); - else - HWR_DrawMD2(spr); + { + if (md2_models[spr->mobj->sprite].notfound || md2_models[spr->mobj->sprite].scale < 0.0f) + HWR_DrawSprite(spr); + else + HWR_DrawMD2(spr); + } } - else + + if constexpr (Type == DrawSpritesType::kSprites) { - if (md2_models[spr->mobj->sprite].notfound || md2_models[spr->mobj->sprite].scale < 0.0f) - HWR_DrawSprite(spr); - else - HWR_DrawMD2(spr); + HWR_DrawSprite(spr); } } - - if constexpr (Type == DrawSpritesType::kSprites) - { - HWR_DrawSprite(spr); - } } } } @@ -5264,8 +5265,6 @@ void HWR_BuildSkyDome(void) sky->loops[sky->loopcount].use_texture = false; sky->loopcount++; - delta = 0.0f; - for (c = 0; c < col_count; c++) { HWR_SkyDomeVertex(sky, vertex_p, 1, c, yflip, 0.0f, true); diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 364c0e417..f3db532e9 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -701,7 +701,6 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi UINT8 colorbrightnesses[17]; UINT8 color_match_lookup[256]; // optimization attempt - blendcolor = palette[0]; // initialize memset(translation, 0, sizeof(translation)); memset(cutoff, 0, sizeof(cutoff)); @@ -902,25 +901,7 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi continue; } - firsti = 0; - mul = 0; - mulmax = 1; - - /*for (i = 0; i < translen; i++) - { - if (brightness > colorbrightnesses[i]) // don't allow greater matches (because calculating a makeshift gradient for this is already a huge mess as is) - continue; - - compare = abs((INT16)(colorbrightnesses[i]) - (INT16)(brightness)); - - if (compare < brightdif) - { - brightdif = (UINT16)compare; - firsti = i; // best matching color that's equal brightness or darker - } - }*/ firsti = color_match_lookup[brightness]; - secondi = firsti+1; // next color in line m = (INT16)brightness - (INT16)colorbrightnesses[secondi]; @@ -985,7 +966,7 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi UINT32 tempcolor; UINT16 colorbright; - SETBRIGHTNESS(colorbright,blendcolor.s.red,blendcolor.s.green,blendcolor.s.blue); + SETBRIGHTNESS(colorbright, blendcolor.s.red, blendcolor.s.green, blendcolor.s.blue); if (colorbright == 0) colorbright = 1; // no dividing by 0 please @@ -1126,10 +1107,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) FTransform p; FSurfaceInfo Surf; - if (!cv_glmdls.value) - return; - - if (spr->precip) + if (!cv_glmdls.value || spr->precip) return; memset(&p, 0x00, sizeof(FTransform)); diff --git a/src/http-mserv.c b/src/http-mserv.c index 61d09bfb5..f81ace445 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -218,6 +218,7 @@ HMS_connect (const char *format, ...) buffer->errbuf[0] = 0x00; cc = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, buffer->errbuf); + if (cc != CURLE_OK) I_OutputMsg("libcurl: %s\n", buffer->errbuf); if (cv_masterserver_debug.value == 2) { diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 2f9171a9f..d2dee5086 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1002,7 +1002,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) || target == 0 // To everyone || consoleplayer == target-1) // To you { - const char *prefix = "", *cstart = "", *cend = "", *adminchar = "\x82~\x83", *remotechar = "\x82@\x83", *fmt2, *textcolor = "\x80"; + const char *prefix, *cstart, *adminchar = "\x82~\x83", *remotechar = "\x82@\x83", *fmt2, *textcolor = "\x80"; char *tempchar = NULL; // player is a spectator? @@ -1026,9 +1026,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) } else { - const UINT8 color = players[playernum].skincolor; - - cstart = HU_SkinColorToConsoleColor(color); + cstart = HU_SkinColorToConsoleColor(players[playernum].skincolor); } prefix = cstart; @@ -1054,13 +1052,13 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) // name, color end, and the message itself. // '\4' makes the message yellow and beeps; '\3' just beeps. if (action) - fmt2 = "* %s%s%s%s \x82%s%s"; + fmt2 = "* %s%s%s %s%s"; else if (target-1 == consoleplayer) // To you { prefix = "\x82[PM]"; cstart = "\x82"; textcolor = "\x82"; - fmt2 = "%s<%s%s>%s\x80 %s%s"; + fmt2 = "%s<%s%s> %s%s"; } else if (target > 0) // By you, to another player { @@ -1068,13 +1066,13 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) dispname = player_names[target-1]; prefix = "\x82[TO]"; cstart = "\x82"; - fmt2 = "%s<%s%s>%s\x80 %s%s"; + fmt2 = "%s<%s%s> %s%s"; } else // To everyone or sayteam, it doesn't change anything. - fmt2 = "%s<%s%s%s>\x80 %s%s"; + fmt2 = "%s<%s%s> %s%s"; - HU_AddChatText(va(fmt2, prefix, cstart, dispname, cend, textcolor, msg), cv_chatnotifications.value); // add to chat + HU_AddChatText(va(fmt2, prefix, cstart, dispname, textcolor, msg), cv_chatnotifications.value); // add to chat if (tempchar) Z_Free(tempchar); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 5af1a79b0..c6b87193c 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1901,7 +1901,6 @@ static int lib_sChangeMusic(lua_State *L) music_compat_name[0] = 0; // becomes empty string music_compat_name[6] = 0; music_name = (const char *)&music_compat_name; - music_flags = 0; } else { @@ -2088,7 +2087,6 @@ static int lib_sMusicExists(lua_State *L) } else { - music_num = 0; music_name = luaL_checkstring(L, 1); } #else diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 28055ffeb..6d04b6154 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -825,7 +825,7 @@ static void res_botai(Hook_State *hook) { BotAI_State *botai = hook->userdata; - int k[8]; + int k[8] = { 0 }; int fields = 0; diff --git a/src/m_aatree.c b/src/m_aatree.c index e67ab69c0..34e8e1d87 100644 --- a/src/m_aatree.c +++ b/src/m_aatree.c @@ -66,6 +66,7 @@ void M_AATreeFree(aatree_t *aatree) static aatree_node_t *M_AATreeRotateRight(aatree_node_t *node) { + I_Assert(node->left != NULL); aatree_node_t *newnode = node->left; aatree_node_t *tmp = newnode->right; newnode->right = node; @@ -75,6 +76,7 @@ static aatree_node_t *M_AATreeRotateRight(aatree_node_t *node) static aatree_node_t *M_AATreeRotateLeft(aatree_node_t *node) { + I_Assert(node->right != NULL); aatree_node_t *newnode = node->right; aatree_node_t *tmp = newnode->left; newnode->left = node; diff --git a/src/m_fixed.c b/src/m_fixed.c index bdb9506c2..c1bb0cf05 100644 --- a/src/m_fixed.c +++ b/src/m_fixed.c @@ -518,12 +518,12 @@ fixed_t FV3_Normal(const vector3_t *a_triangle, vector3_t *a_normal) fixed_t FV3_Strength(const vector3_t *a_1, const vector3_t *dir) { vector3_t normal; - fixed_t dist = FV3_NormalizeEx(a_1, &normal); + FV3_NormalizeEx(a_1, &normal); fixed_t dot = FV3_Dot(&normal, dir); FV3_ClosestPointOnVector(dir, a_1, &normal); - dist = FV3_Magnitude(&normal); + fixed_t dist = FV3_Magnitude(&normal); if (dot < 0) // Not facing same direction, so negate result. dist = -dist; diff --git a/src/m_menu.c b/src/m_menu.c index c07d0f270..7f0453bdf 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2251,7 +2251,7 @@ static void M_DrawGenericMenu(void) /* FALLTHRU */ case IT_NOTHING: case IT_DYBIGSPACE: - y = currentMenu->y+currentMenu->menuitems[i].alphaKey;//+= LINEHEIGHT; + y = currentMenu->y+currentMenu->menuitems[i].alphaKey; break; case IT_BIGSLIDER: M_DrawThermo(x, y, (consvar_t *)currentMenu->menuitems[i].itemaction); @@ -2382,17 +2382,17 @@ static void M_DrawGenericScrollMenu(void) y = currentMenu->y; if (currentMenu->menuitems[currentMenu->numitems-1].alphaKey < scrollareaheight) - tempcentery = currentMenu->y; // Not tall enough to scroll, but this thinker is used in case it becomes so + tempcentery = y; // Not tall enough to scroll, but this thinker is used in case it becomes so else if ((currentMenu->menuitems[itemOn].alphaKey*2 - currentMenu->menuitems[0].alphaKey*2) <= scrollareaheight) - tempcentery = currentMenu->y - currentMenu->menuitems[0].alphaKey*2; + tempcentery = y - currentMenu->menuitems[0].alphaKey*2; else if ((currentMenu->menuitems[currentMenu->numitems-1].alphaKey*2 - currentMenu->menuitems[itemOn].alphaKey*2) <= scrollareaheight) - tempcentery = currentMenu->y - currentMenu->menuitems[currentMenu->numitems-1].alphaKey*2 + 2*scrollareaheight; + tempcentery = y - currentMenu->menuitems[currentMenu->numitems-1].alphaKey*2 + 2*scrollareaheight; else - tempcentery = currentMenu->y - currentMenu->menuitems[itemOn].alphaKey*2 + scrollareaheight; + tempcentery = y - currentMenu->menuitems[itemOn].alphaKey*2 + scrollareaheight; for (i = 0; i < currentMenu->numitems; i++) { - if (currentMenu->menuitems[i].status != IT_DISABLED && currentMenu->menuitems[i].alphaKey*2 + tempcentery >= currentMenu->y) + if (currentMenu->menuitems[i].status != IT_DISABLED && currentMenu->menuitems[i].alphaKey*2 + tempcentery >= y) break; } @@ -2404,14 +2404,14 @@ static void M_DrawGenericScrollMenu(void) for (max = bottom; max > 0; max--) { - if (currentMenu->menuitems[max-1].status != IT_DISABLED && currentMenu->menuitems[max-1].alphaKey*2 + tempcentery <= (currentMenu->y + 2*scrollareaheight)) + if (currentMenu->menuitems[max-1].status != IT_DISABLED && currentMenu->menuitems[max-1].alphaKey*2 + tempcentery <= (y + 2*scrollareaheight)) break; } if (i) - V_DrawString(currentMenu->x - 20, currentMenu->y - (skullAnimCounter/5), highlightflags, "\x1A"); // up arrow + V_DrawString(x - 20, y - (skullAnimCounter/5), highlightflags, "\x1A"); // up arrow if (max != bottom) - V_DrawString(currentMenu->x - 20, currentMenu->y + 2*scrollareaheight + (skullAnimCounter/5), highlightflags, "\x1B"); // down arrow + V_DrawString(x - 20, y + 2*scrollareaheight + (skullAnimCounter/5), highlightflags, "\x1B"); // down arrow // draw title (or big pic) M_DrawMenuTitle(); @@ -2449,7 +2449,7 @@ static void M_DrawGenericScrollMenu(void) case IT_CV_INVISSLIDER: // monitor toggles use this break; case IT_CV_STRING: - if (y + 12 > (currentMenu->y + 2*scrollareaheight)) + if (y + 12 > (y + 2*scrollareaheight)) break; M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); @@ -2487,8 +2487,7 @@ static void M_DrawGenericScrollMenu(void) } // DRAW THE SKULL CURSOR - V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, - (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); + V_DrawScaledPatch(x - 24, cursory, 0, (patch_t *)W_CachePatchName("M_CURSOR", PU_PATCH)); // dumb hack // tooltips @@ -6154,8 +6153,7 @@ static boolean M_QuitTimeAttackMenu(void) // Player has selected the "START" from the time attack screen static void M_ChooseTimeAttack(INT32 choice) { - char *gpath; - const size_t glen = strlen("replay")+1+strlen(timeattackfolder)+1+strlen("MAPXX")+1; + const char *mapname = G_BuildMapName(cv_nextmap.value); char nameofdemo[256]; (void)choice; emeralds = 0; @@ -6165,20 +6163,14 @@ static void M_ChooseTimeAttack(INT32 choice) I_mkdir(va("%s"PATHSEP"replay", srb2home), 0755); I_mkdir(va("%s"PATHSEP"replay"PATHSEP"%s", srb2home, timeattackfolder), 0755); - if ((gpath = malloc(glen)) == NULL) - I_Error("Out of memory for replay filepath\n"); - - sprintf(gpath,"replay"PATHSEP"%s"PATHSEP"%s", timeattackfolder, G_BuildMapName(cv_nextmap.value)); - snprintf(nameofdemo, sizeof nameofdemo, "%s-%s-last", gpath, cv_chooseskin.string); + snprintf(nameofdemo, sizeof nameofdemo, "replay"PATHSEP"%s"PATHSEP"%s-%s-last", timeattackfolder, mapname, cv_chooseskin.string); if (!cv_autorecord.value) remove(va("%s"PATHSEP"%s.lmp", srb2home, nameofdemo)); else G_RecordDemo(nameofdemo); - G_DeferedInitNew(false, G_BuildMapName(cv_nextmap.value), (UINT8)(cv_chooseskin.value-1), 0, false); - - free(gpath); + G_DeferedInitNew(false, mapname, (UINT8)(cv_chooseskin.value-1), 0, false); } static void M_HandleStaffReplay(INT32 choice) @@ -6398,9 +6390,7 @@ void M_SetWaitingMode(int mode) #ifdef HAVE_THREADS I_lock_mutex(&m_menu_mutex); #endif - { - m_waiting_mode = mode; - } + m_waiting_mode = mode; #ifdef HAVE_THREADS I_unlock_mutex(m_menu_mutex); #endif @@ -6413,9 +6403,7 @@ int M_GetWaitingMode(void) #ifdef HAVE_THREADS I_lock_mutex(&m_menu_mutex); #endif - { - mode = m_waiting_mode; - } + mode = m_waiting_mode; #ifdef HAVE_THREADS I_unlock_mutex(m_menu_mutex); #endif @@ -6430,9 +6418,7 @@ static void Spawn_masterserver_thread(const char *name, void (*thread)(int*)) int *id = malloc(sizeof *id); I_lock_mutex(&ms_QueryId_mutex); - { - *id = ms_QueryId; - } + *id = ms_QueryId; I_unlock_mutex(ms_QueryId_mutex); I_spawn_thread(name, (I_thread_fn)thread, id); @@ -6443,9 +6429,7 @@ static int Same_instance(int id) int okay; I_lock_mutex(&ms_QueryId_mutex); - { - okay = ( id == ms_QueryId ); - } + okay = ( id == ms_QueryId ); I_unlock_mutex(ms_QueryId_mutex); return okay; @@ -6476,9 +6460,7 @@ static void Fetch_servers_thread(int *id) #ifdef HAVE_THREADS I_lock_mutex(&ms_ServerList_mutex); - { - ms_ServerList = server_list; - } + ms_ServerList = server_list; I_unlock_mutex(ms_ServerList_mutex); #else CL_QueryServerList(server_list); @@ -9848,7 +9830,6 @@ static void M_DrawColorMenu(void) else V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); - y += 16; break; default: V_DrawRightAlignedString(BASEVIDWIDTH - x, y, diff --git a/src/m_misc.c b/src/m_misc.c index 9d88a1894..4a0a163aa 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1197,6 +1197,10 @@ void M_DoScreenShot(void) palette = NULL; } #endif + else + { + I_Error("rendermode %d is not valid", rendermode); + } #ifdef USE_PNG ret = M_SavePNG(va(pandf,pathname,freename), linear, vid.width, vid.height, palette); diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 5a30a6cf7..7384a6086 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -324,9 +324,17 @@ static boolean PS_IsRowVisible(perfstatrow_t *row) (row->flags & PS_HIDE_ZERO && value_is_zero)); } +typedef union +{ + char *c; + UINT32 *i; + precise_t *p; +} history_read_pos_t; + static INT32 PS_GetMetricAverage(ps_metric_t *metric, boolean time_metric) { - char* history_read_pos = metric->history; // char* used for pointer arithmetic + history_read_pos_t history_read_pos; + history_read_pos.c = metric->history; // char* used for pointer arithmetic INT64 sum = 0; int i; int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); @@ -334,10 +342,10 @@ static INT32 PS_GetMetricAverage(ps_metric_t *metric, boolean time_metric) for (i = 0; i < cv_ps_samplesize.value; i++) { if (time_metric) - sum += (*((precise_t*)history_read_pos)) / (I_GetPrecisePrecision() / 1000000); + sum += *history_read_pos.p / (I_GetPrecisePrecision() / 1000000); else - sum += *((INT32*)history_read_pos); - history_read_pos += value_size; + sum += *history_read_pos.i; + history_read_pos.c += value_size; } return sum / cv_ps_samplesize.value; @@ -345,7 +353,8 @@ static INT32 PS_GetMetricAverage(ps_metric_t *metric, boolean time_metric) static INT32 PS_GetMetricMinOrMax(ps_metric_t *metric, boolean time_metric, boolean get_max) { - char* history_read_pos = metric->history; // char* used for pointer arithmetic + history_read_pos_t history_read_pos; + history_read_pos.c = metric->history; // char* used for pointer arithmetic INT32 found_value = get_max ? INT32_MIN : INT32_MAX; int i; int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); @@ -355,9 +364,9 @@ static INT32 PS_GetMetricMinOrMax(ps_metric_t *metric, boolean time_metric, bool INT32 value; if (time_metric) - value = (*((precise_t*)history_read_pos)) / (I_GetPrecisePrecision() / 1000000); + value = *history_read_pos.p / (I_GetPrecisePrecision() / 1000000); else - value = *((INT32*)history_read_pos); + value = *history_read_pos.i; if ((get_max && value > found_value) || (!get_max && value < found_value)) @@ -365,7 +374,7 @@ static INT32 PS_GetMetricMinOrMax(ps_metric_t *metric, boolean time_metric, bool found_value = value; } - history_read_pos += value_size; + history_read_pos.c += value_size; } return found_value; @@ -374,7 +383,8 @@ static INT32 PS_GetMetricMinOrMax(ps_metric_t *metric, boolean time_metric, bool // Calculates the standard deviation for metric. static INT32 PS_GetMetricSD(ps_metric_t *metric, boolean time_metric) { - char* history_read_pos = metric->history; // char* used for pointer arithmetic + history_read_pos_t history_read_pos; + history_read_pos.c = metric->history; // char* used for pointer arithmetic INT64 sum = 0; int i; int value_size = time_metric ? sizeof(precise_t) : sizeof(INT32); @@ -385,17 +395,17 @@ static INT32 PS_GetMetricSD(ps_metric_t *metric, boolean time_metric) INT64 value; if (time_metric) - value = (*((precise_t*)history_read_pos)) / (I_GetPrecisePrecision() / 1000000); + value = *history_read_pos.p / (I_GetPrecisePrecision() / 1000000); else - value = *((INT32*)history_read_pos); + value = *history_read_pos.i; value -= avg; sum += value * value; - history_read_pos += value_size; + history_read_pos.c += value_size; } - return round(sqrt(sum / cv_ps_samplesize.value)); + return round(sqrt((double)sum / (double)cv_ps_samplesize.value)); } // Returns the value to show on screen for metric. @@ -909,7 +919,6 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) if (strcmp(".lua", str + len - 4) == 0) { str[len-4] = '\0'; // remove .lua at end - len -= 4; } // Print wad name first. diff --git a/src/p_enemy.c b/src/p_enemy.c index dbff7842b..6fd3f3844 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -6747,10 +6747,11 @@ void A_Boss3Path(void *thing) actor->momx = 0; actor->momy = 0; actor->momz = 0; - P_SetTarget(&actor->target, actor->tracer->target); + if (actor->tracer) + P_SetTarget(&actor->target, actor->tracer->target); var1 = 0, var2 = 0; A_FaceTarget(actor); - if (actor->tracer->state == &states[actor->tracer->info->missilestate]) + if (actor && actor->tracer && actor->tracer->state == &states[actor->tracer->info->missilestate]) P_SetMobjState(actor, actor->info->missilestate); return; } @@ -9787,7 +9788,7 @@ void A_SetCustomValue(void *thing) if (cv_debug) CONS_Printf("Init custom value is %d\n", actor->cusval); - if (locvar1 == 0 && locvar2 == 4) + if (locvar1 == 0 && (locvar2 == 3 || locvar2 == 4)) return; // DON'T DIVIDE BY ZERO // no need for a "temp" value here, just modify the cusval directly @@ -9856,7 +9857,7 @@ void A_UseCusValMemo(void *thing) tempM = actor->cvmem; } - if (tempM == 0 && locvar2 == 4) + if (locvar1 == 0 && (locvar2 == 3 || locvar2 == 4)) return; // DON'T DIVIDE BY ZERO // now get new value for cusval/cvmem using the other @@ -9933,7 +9934,7 @@ void A_RelayCustomValue(void *thing) else // tracer's custom value tempT = actor->tracer->cusval; - if (temp == 0 && locvar2 == 4) + if (locvar1 == 0 && (locvar2 == 3 || locvar2 == 4)) return; // DON'T DIVIDE BY ZERO // now get new cusval using target's and the reference diff --git a/src/p_inter.c b/src/p_inter.c index 6eb6779a0..0005f5458 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2043,12 +2043,17 @@ static inline boolean P_TagDamage(mobj_t *target, mobj_t *inflictor, mobj_t *sou // Don't allow players on the same team to hurt one another, // unless cv_friendlyfire is on. - if (!cv_friendlyfire.value && (player->pflags & PF_TAGIT) == (source->player->pflags & PF_TAGIT)) + if (!cv_friendlyfire.value + && (player->pflags & PF_TAGIT) == (source->player->pflags & PF_TAGIT)) { - if (!(inflictor->flags & MF_FIRE)) - P_GivePlayerRings(player, 1); - if (inflictor->flags2 & MF2_BOUNCERING) - inflictor->fuse = 0; // bounce ring disappears at -1 not 0 + if (inflictor) + { + if (!(inflictor->flags & MF_FIRE)) + P_GivePlayerRings(player, 1); + if (inflictor->flags2 & MF2_BOUNCERING) + inflictor->fuse = 0; // bounce ring disappears at -1 not 0 + } + return false; } @@ -2097,12 +2102,16 @@ static inline boolean P_PlayerHitsPlayer(mobj_t *target, mobj_t *inflictor, mobj { // Don't allow players on the same team to hurt one another, // unless cv_friendlyfire is on. - if (!cv_friendlyfire.value && target->player->ctfteam == source->player->ctfteam) + if (!cv_friendlyfire.value + && target->player->ctfteam == source->player->ctfteam) { - if (!(inflictor->flags & MF_FIRE)) - P_GivePlayerRings(target->player, 1); - if (inflictor->flags2 & MF2_BOUNCERING) - inflictor->fuse = 0; // bounce ring disappears at -1 not 0 + if (inflictor) + { + if (!(inflictor->flags & MF_FIRE)) + P_GivePlayerRings(target->player, 1); + if (inflictor->flags2 & MF2_BOUNCERING) + inflictor->fuse = 0; // bounce ring disappears at -1 not 0 + } return false; } diff --git a/src/p_map.c b/src/p_map.c index 52d43d649..d3d23cb2e 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2834,15 +2834,12 @@ static void P_HitBounceLine(line_t *ld) moveangle = R_PointToAngle2(0, 0, tmxmove, tmymove); deltaangle = moveangle + 2*(lineangle - moveangle); - lineangle >>= ANGLETOFINESHIFT; deltaangle >>= ANGLETOFINESHIFT; movelen = P_AproxDistance(tmxmove, tmymove); tmxmove = FixedMul(movelen, FINECOSINE(deltaangle)); tmymove = FixedMul(movelen, FINESINE(deltaangle)); - - deltaangle = R_PointToAngle2(0, 0, tmxmove, tmymove); } // @@ -3050,7 +3047,8 @@ stairstep: tmxmove = FixedMul(thiscam->momx, bestslidefrac); tmymove = FixedMul(thiscam->momy, bestslidefrac); - P_HitCameraSlideLine(bestslideline, thiscam); // clip the moves + if (bestslideline != NULL) + P_HitCameraSlideLine(bestslideline, thiscam); // clip the moves thiscam->momx = tmxmove; thiscam->momy = tmymove; @@ -3189,7 +3187,8 @@ stairstep: tmxmove = FixedMul(mo->momx, bestslidefrac); tmymove = FixedMul(mo->momy, bestslidefrac); - P_HitSlideLine(bestslideline); // clip the moves + if (bestslideline != NULL) + P_HitSlideLine(bestslideline); // clip the moves if (UNLIKELY((twodlevel || (mo->flags2 & MF2_TWOD)) && mo->player)) { @@ -3460,7 +3459,8 @@ bounceback: tmymove = FixedMul(mmomy, (FRACUNIT - (FRACUNIT>>2) - (FRACUNIT>>3))); } - P_HitBounceLine(bestslideline); // clip the moves + if (bestslideline != NULL) + P_HitBounceLine(bestslideline); // clip the moves mo->momx = tmxmove; mo->momy = tmymove; diff --git a/src/p_mobj.c b/src/p_mobj.c index ee12f6b2b..a42d7bcef 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1454,7 +1454,6 @@ void P_XYMovement(mobj_t *mo) else if (mo->flags & MF_BOUNCE) { P_BounceMove(mo); - xmove = ymove = 0; S_StartSound(mo, mo->info->activesound); //{ SRB2kart - Orbinaut, Ballhog @@ -1485,7 +1484,7 @@ void P_XYMovement(mobj_t *mo) P_KillMobj(mo, NULL, NULL); P_SetObjectMomZ(mo, 8*FRACUNIT, false); - P_InstaThrust(mo, R_PointToAngle2(mo->x, mo->y, mo->x + xmove, mo->y + ymove)+ANGLE_90, 16*FRACUNIT); + P_InstaThrust(mo, R_PointToAngle2(mo->x, mo->y, mo->x, mo->y)+ANGLE_90, 16*FRACUNIT); } } //} @@ -1534,7 +1533,6 @@ void P_XYMovement(mobj_t *mo) else if (player || mo->flags & (MF_SLIDEME|MF_PUSHABLE)) // try to slide along it { P_SlideMove(mo, false); - xmove = ymove = 0; } else if (mo->type == MT_SPINFIRE) { @@ -4991,7 +4989,7 @@ static void P_Boss9Thinker(mobj_t *mobj) { mobj_t *spawner; fixed_t dist = 0; - angle = 0x06000000*leveltime; + angle = ANGLE_135*leveltime; // Alter your energy bubble's size/position if (mobj->health > 3) @@ -12284,7 +12282,7 @@ mobj_t *P_SPMAngle(mobj_t *source, mobjtype_t type, angle_t angle, UINT8 allowai // angle at which you fire, is player angle an = angle; - if (allowaim) // aiming allowed? + if (source->player && allowaim) // aiming allowed? slope = AIMINGTOSLOPE(source->player->aiming); x = source->x; @@ -12315,7 +12313,7 @@ mobj_t *P_SPMAngle(mobj_t *source, mobjtype_t type, angle_t angle, UINT8 allowai th->momx = FixedMul(th->info->speed, FINECOSINE(an>>ANGLETOFINESHIFT)); th->momy = FixedMul(th->info->speed, FINESINE(an>>ANGLETOFINESHIFT)); - if (allowaim) + if (source->player && allowaim) { th->momx = FixedMul(th->momx,FINECOSINE(source->player->aiming>>ANGLETOFINESHIFT)); th->momy = FixedMul(th->momy,FINECOSINE(source->player->aiming>>ANGLETOFINESHIFT)); diff --git a/src/p_pspr.h b/src/p_pspr.h index 89f6c1108..fab0a610d 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -94,7 +94,8 @@ */ typedef enum { - tr_trans10 = 1, + tr_trans0 = 0, + tr_trans10, tr_trans20, tr_trans30, tr_trans40, diff --git a/src/p_saveg.c b/src/p_saveg.c index cb6d46062..a4b343554 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2892,7 +2892,6 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) CalculateDoomednumToMobjtype(); // remove all the current thinkers - currentthinker = thinkercap.next; for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = next) { next = currentthinker->next; diff --git a/src/p_spec.c b/src/p_spec.c index 055a708fe..7b4b45358 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -6478,7 +6478,6 @@ void T_Scroll(scroll_t *s) case sc_carry: sec = sectors + s->affectee; - height = sec->floorheight; // sec is the control sector, find the real sector(s) to use for (i = 0; i < sec->linecount; i++) @@ -6555,7 +6554,6 @@ void T_Scroll(scroll_t *s) case sc_carry_ceiling: // carry on ceiling (FOF scrolling) sec = sectors + s->affectee; - height = sec->ceilingheight; // sec is the control sector, find the real sector(s) to use for (i = 0; i < sec->linecount; i++) diff --git a/src/p_user.c b/src/p_user.c index 392878054..a5c01152a 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -340,23 +340,23 @@ void P_DoPlayerPain(player_t *player, mobj_t *source, mobj_t *inflictor) angle_t ang; fixed_t fallbackspeed; - if (inflictor && (inflictor->type != MT_PLAYER && inflictor->type != MT_ORBINAUT && inflictor->type != MT_ORBINAUT_SHIELD - && inflictor->type != MT_JAWZ && inflictor->type != MT_JAWZ_DUD && inflictor->type != MT_JAWZ_SHIELD - && inflictor->type != MT_SMK_THWOMP)) - { - if (player->mo->eflags & MFE_VERTICALFLIP) - player->mo->z--; - else - player->mo->z++; - - if (player->mo->eflags & MFE_UNDERWATER) - P_SetObjectMomZ(player->mo, FixedDiv(10511*FRACUNIT,2600*FRACUNIT), false); - else - P_SetObjectMomZ(player->mo, FixedDiv(69*FRACUNIT,10*FRACUNIT), false); - } - if (inflictor) { + if (inflictor->type != MT_PLAYER && inflictor->type != MT_ORBINAUT && inflictor->type != MT_ORBINAUT_SHIELD + && inflictor->type != MT_JAWZ && inflictor->type != MT_JAWZ_DUD && inflictor->type != MT_JAWZ_SHIELD + && inflictor->type != MT_SMK_THWOMP) + { + if (player->mo->eflags & MFE_VERTICALFLIP) + player->mo->z--; + else + player->mo->z++; + + if (player->mo->eflags & MFE_UNDERWATER) + P_SetObjectMomZ(player->mo, FixedDiv(10511*FRACUNIT,2600*FRACUNIT), false); + else + P_SetObjectMomZ(player->mo, FixedDiv(69*FRACUNIT,10*FRACUNIT), false); + } + ang = R_PointToAngle2(inflictor->x, inflictor->y, player->mo->x, player->mo->y); // SRB2kart // explosion and rail rings send you farther back, making it more difficult diff --git a/src/r_skins.c b/src/r_skins.c index c19e34a74..f0fbfcfd1 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -530,8 +530,9 @@ void R_AddSkins(UINT16 wadnum, boolean local) if ((stoken[0] == '/' && stoken[1] == '/') || (stoken[0] == '#'))// skip comments { - stoken = strtok(NULL, "\r\n"); // skip end of line - goto next_token; // find the real next token + strtok(NULL, "\r\n"); // skip end of line + stoken = strtok(NULL, "\r\n= "); + continue; // find the real next token } value = strtok(NULL, "\r\n= "); @@ -575,6 +576,7 @@ void R_AddSkins(UINT16 wadnum, boolean local) for (value = skin->realname; *value; value++) if (*value == '_') *value = ' '; // turn _ into spaces. } + if (!hudname) { STRBUFCPY(skin->hudname, skin->name); @@ -625,27 +627,29 @@ void R_AddSkins(UINT16 wadnum, boolean local) strncpy(skin->facemmap, value, sizeof(skin->facemmap)-1); skin->facemmap[sizeof(skin->facemmap)-1] = '\0'; } - -#define FULLPROCESS(field) else if (!stricmp(stoken, #field)) skin->field = get_number(value); - // character type identification - FULLPROCESS(flags) -#undef FULLPROCESS - -#define GETKARTSTAT(field) \ - else if (!stricmp(stoken, #field)) \ - { \ - skin->field = atoi(value); \ - if (skin->field < 1) skin->field = 1; \ - if (skin->field > 9) skin->field = 9; \ - } - GETKARTSTAT(kartspeed) - GETKARTSTAT(kartweight) -#undef GETKARTSTAT - + else if (!stricmp(stoken, "flags")) // character type identification + { + skin->flags = get_number(value); + } + else if (!stricmp(stoken, "kartspeed")) + { + skin->kartspeed = atoi(value); + if (skin->kartspeed < 1) + skin->kartspeed = 1; + if (skin->kartspeed > 9) + skin->kartspeed = 9; + } + else if (!stricmp(stoken, "kartweight")) + { + skin->kartweight = atoi(value); + if (skin->kartweight < 1) + skin->kartweight = 1; + if (skin->kartweight > 9) + skin->kartweight = 9; + } // custom translation table else if (!stricmp(stoken, "startcolor")) skin->starttranscolor = atoi(value); - else if (!stricmp(stoken, "prefcolor")) skin->prefcolor = K_GetKartColorByName(value); else if (!stricmp(stoken, "highresscale")) @@ -672,7 +676,7 @@ void R_AddSkins(UINT16 wadnum, boolean local) if (!found) CONS_Debug(DBG_SETUP, "R_AddSkins: Unknown keyword '%s' in S_SKIN lump# %d (WAD %s)\n", stoken, lump, wadfiles[wadnum]->filename); } -next_token: + stoken = strtok(NULL, "\r\n= "); } free(buf2); diff --git a/src/r_things.cpp b/src/r_things.cpp index 72786bc9e..1b99b64a3 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -2211,6 +2211,9 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps fixed_t scale = 0; const INT32 vidheight = vid.height; + if (mask->drawsegs[0] == mask->drawsegs[1]) + return; + // Add the 3D floors, thicksides, and masked textures... for (ds = drawsegs + mask->drawsegs[1]; ds-- > drawsegs + mask->drawsegs[0];) { @@ -2372,9 +2375,7 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps continue; } - entry = R_CreateDrawNode(NULL); - (entry->prev = r2->prev)->next = entry; - (entry->next = r2)->prev = entry; + entry = R_CreateDrawNode(r2); entry->sprite = rover; break; } @@ -2408,9 +2409,7 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps (botplanecameraz > viewz && rover->gz > botplaneobjectz)) #endif { - entry = R_CreateDrawNode(NULL); - (entry->prev = r2->prev)->next = entry; - (entry->next = r2)->prev = entry; + entry = R_CreateDrawNode(r2); entry->sprite = rover; break; } @@ -2427,9 +2426,7 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps if (rover->sortscale < scale) { - entry = R_CreateDrawNode(NULL); - (entry->prev = r2->prev)->next = entry; - (entry->next = r2)->prev = entry; + entry = R_CreateDrawNode(r2); entry->sprite = rover; break; } @@ -2444,9 +2441,7 @@ static void R_CreateDrawNodes(maskcount_t* mask, drawnode_t* head, boolean temps if (r2->sprite->sortscale > rover->sortscale || (r2->sprite->sortscale == rover->sortscale && r2->sprite->dispoffset > rover->dispoffset)) { - entry = R_CreateDrawNode(NULL); - (entry->prev = r2->prev)->next = entry; - (entry->next = r2)->prev = entry; + entry = R_CreateDrawNode(r2); entry->sprite = rover; break; } diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 3045380d4..b2f4143e1 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -2542,7 +2542,7 @@ const char *I_LocateWad(void) SetCurrentDirectoryA(waddir); #else waddir = realpath(waddir, NULL); - if (chdir(waddir) == -1) + if (waddir == NULL || chdir(waddir) == -1) I_OutputMsg("Couldn't change working directory\n"); #endif } diff --git a/src/tables.c b/src/tables.c index 98a2c8a17..e748cec8c 100644 --- a/src/tables.c +++ b/src/tables.c @@ -24,6 +24,7 @@ // fixed_t tantoangle[2049] - ArcTan LUT, // Maps tan(angle) to angle fast. Gotta search. +#include "doomdef.h" #include "tables.h" unsigned SlopeDiv(unsigned num, unsigned den) @@ -66,9 +67,9 @@ fixed_t AngleFixed(angle_t af) return rf; } -static FUNCMATH angle_t AngleAdj(const fixed_t fa, const fixed_t wf, - angle_t ra) +static FUNCMATH angle_t AngleAdj(const fixed_t fa, const fixed_t wf, angle_t ra) { + I_Assert(wf > 0); const angle_t adj = 0x77; const boolean fan = fa < 0; const fixed_t sl = FixedDiv(fa, wf*2); diff --git a/src/v_video.c b/src/v_video.c index 5ee222988..ab3d05b91 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -612,7 +612,7 @@ static void CV_constextsize_OnChange(void) // -------------------------------------------------------------------------- // Copy a rectangular area from one bitmap to another (8bpp) // -------------------------------------------------------------------------- -void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT32 height, size_t srcrowbytes, size_t destrowbytes) +void VID_BlitLinearScreen(const UINT8 *restrict srcptr, UINT8 *restrict destptr, INT32 width, INT32 height, size_t srcrowbytes, size_t destrowbytes) { if (srcrowbytes == destrowbytes && srcrowbytes == (size_t)width) { @@ -621,7 +621,7 @@ void VID_BlitLinearScreen(const UINT8 *srcptr, UINT8 *destptr, INT32 width, INT3 while (i >= 16) { // TODO: find where the buffer is misaligned at times and align it - _mm_storeu_ps((float *)destptr, _mm_loadu_ps((const float *)srcptr)); + _mm_storeu_ps((void *)destptr, _mm_loadu_ps((const void *)srcptr)); srcptr += 16; destptr += 16; i -= 16; From 423ca0eca02f226c0efb041810342b294f969d9d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Sep 2025 06:31:28 +0200 Subject: [PATCH 19/39] redo native keyboard handling instead of like, constantly checking stuff each frame Now we check whenever we change the menu entry or open/close the chat or console instead and set sdl textinput mode directly and accordingly no more weird hacking around this is similar to how srb2classic handles it, just a bit simplified (i dont wanna touch anything menu related if it can be avoided lmao) this hopefully should resolve any weird remaining issues (lets hope i didnt miss some wonky edge case ugghhh) TODO: update sdl2 lib on windows to fix issues on sdl side with certain layouts --- src/console.c | 10 +++++ src/hu_stuff.c | 5 +++ src/i_video.h | 5 +-- src/m_menu.c | 34 +++++++++++---- src/m_menu.h | 2 - src/sdl/i_video.c | 106 +++++++++++++++++++++++----------------------- 6 files changed, 97 insertions(+), 65 deletions(-) diff --git a/src/console.c b/src/console.c index e018e1a1c..a01c72062 100644 --- a/src/console.c +++ b/src/console.c @@ -729,6 +729,8 @@ void CON_ToggleOff(void) con_forcepic = 0; con_clipviewtop = -1; // remove console clipping of view + I_SetTextInput(false); + Unlock_state(); } @@ -768,9 +770,13 @@ void CON_Ticker(void) { con_destlines = 0; CON_ClearHUD(); + I_SetTextInput(false); } else + { CON_ChangeHeight(); + I_SetTextInput(true); + } } // clip the view, so that the part under the console is not drawn @@ -787,9 +793,13 @@ void CON_Ticker(void) // check if console ready for prompt if (con_destlines >= minheight) + { consoleready = true; + } else + { consoleready = false; + } // make overlay messages disappear after a while for (i = 0; i < con_hudlines; i++) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index d2dee5086..0eaa38e8e 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1305,6 +1305,7 @@ void HU_clearChatChars(void) { M_TextInputClear(&w_chat); chat_on = false; + I_SetTextInput(false); } #ifndef NONET @@ -1357,6 +1358,7 @@ boolean HU_Responder(event_t *ev) teamtalk = false; chat_scrollmedown = true; typelines = 1; + I_SetTextInput(true); return true; } if ((ev->data1 == gamecontrol[0][gc_teamkey][0] || ev->data1 == gamecontrol[0][gc_teamkey][1]) @@ -1368,6 +1370,7 @@ boolean HU_Responder(event_t *ev) teamtalk = G_GametypeHasTeams(); // Don't teamtalk if we don't have teams. chat_scrollmedown = true; typelines = 1; + I_SetTextInput(true); return true; } } @@ -1395,6 +1398,7 @@ boolean HU_Responder(event_t *ev) { chat_on = false; chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :) + I_SetTextInput(false); HU_SendChatMessage(); } else if (c == KEY_ESCAPE @@ -1403,6 +1407,7 @@ boolean HU_Responder(event_t *ev) && c >= KEY_MOUSE1)) // If it's not a keyboard key, then the chat button is used as a toggle. { chat_on = false; + I_SetTextInput(false); } else if ((c == KEY_UPARROW || c == KEY_MOUSEWHEELUP) && chat_scroll > 0 && !OLDCHAT) // CHAT SCROLLING YAYS! { diff --git a/src/i_video.h b/src/i_video.h index 0bf6c3af0..822a1bada 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -24,7 +24,8 @@ extern "C" { #pragma interface #endif -void I_SetTextInput(void); +boolean I_UseNativeKeyboard(void); +void I_SetTextInput(boolean enable); typedef enum { @@ -138,8 +139,6 @@ void I_EndRead(void); UINT32 I_GetRefreshRate(void); -boolean I_UseNativeKeyboard(void); - boolean I_CheckNativeRes(void); void I_SetBorderlessWindow(void); diff --git a/src/m_menu.c b/src/m_menu.c index 7f0453bdf..54c57aaa9 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -157,8 +157,6 @@ boolean browselocalskins = false; boolean menuactive = false; boolean fromlevelselect = false; -boolean menu_text_input = false; - char menu_text_input_buf[MAXSTRINGLENGTH]; static textinput_t menuinput; @@ -684,9 +682,28 @@ static void M_ResetCvars(void) } // This is not a particular elegant solution, but it seems to make do for our purposes -static boolean M_CheckTextInput(void) +static void M_SetTextInput(void) { - return (menuactive && currentMenu && (itemOn < currentMenu->numitems) && (((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING) || (currentMenu->menuitems[itemOn].status == IT_MSGHANDLER && currentMenu->menuitems[itemOn].alphaKey != MM_EVENTHANDLER) || ((currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_KEYHANDLER))); + // dont reset our native input state when console is open + if (CON_Ready()) + return; + + I_SetTextInput(false); + + if (!menuactive || !currentMenu) + { + return; + } + + // check if the current entry requieres some kind of keyboard input from us + // except for MM_EVENTHANDLER since thats to be used for the control setup + const UINT16 status = currentMenu->menuitems[itemOn].status; + if ((itemOn < currentMenu->numitems) + && (((status & IT_CVARTYPE) == IT_CV_STRING) || ((status & IT_TYPE) == IT_KEYHANDLER) + || (status == IT_MSGHANDLER && currentMenu->menuitems[itemOn].alphaKey != MM_EVENTHANDLER))) + { + I_SetTextInput(true); + } } // If current menu item is IT_CV_STRING, setup menuinput @@ -717,6 +734,7 @@ static void M_NextOpt(void) } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); M_CheckStringItem(); + M_SetTextInput(); } static void M_PrevOpt(void) @@ -732,6 +750,7 @@ static void M_PrevOpt(void) } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); M_CheckStringItem(); + M_SetTextInput(); } // lock out further input in a tic when important buttons are pressed @@ -1653,6 +1672,8 @@ void M_EndModeAttackRun(void) // void M_ClearMenus(boolean callexitmenufunc) { + M_SetTextInput(); + if (!menuactive) return; @@ -1702,6 +1723,7 @@ void M_SetupNextMenu(menu_t *menudef) } M_CheckStringItem(); + M_SetTextInput(); } // @@ -1731,10 +1753,6 @@ void M_Ticker(void) interpTimerHackAllow = true; - menu_text_input = M_CheckTextInput(); - - I_SetTextInput(); - //added : 30-01-98 : test mode for five seconds if (vidm_testingmode > 0) { diff --git a/src/m_menu.h b/src/m_menu.h index 024fd62a0..de4f3b983 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -116,8 +116,6 @@ void M_QuitResponse(INT32 ch); // Determines whether to show a level in the list boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt); -extern boolean menu_text_input; - // flags for items in the menu // menu handle (what we do when key is pressed #define IT_TYPE 14 // (2+4+8) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 1a5ea118d..9ce860cb4 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -111,11 +111,6 @@ static void KeyboardLayout_OnChange(void) HU_Shiftform(); } -boolean I_UseNativeKeyboard(void) -{ - return (cv_keyboardlayout.value == 2) && (chat_on || CON_Ready() || (menu_text_input && menuactive)); -} - static CV_PossibleValue_t keyboardlayout_cons_t[] = {{1,"Default US"}, {2, "Native"}, {3, "AZERTY"}, {0, NULL}}; consvar_t cv_keyboardlayout = {"keyboardlayout", "Default US", CV_SAVE|CV_CALL, keyboardlayout_cons_t, KeyboardLayout_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -205,23 +200,6 @@ static void Impl_SetWindowIcon(void); boolean downsample = false; #endif -void I_SetTextInput(void) -{ - static boolean input_active = false; - boolean use_native = I_UseNativeKeyboard(); - - if (use_native && !input_active) - { - SDL_StartTextInput(); - input_active = true; - } - else if (!use_native && input_active) - { - SDL_StopTextInput(); - input_active = false; - } -} - static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) { if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) @@ -315,36 +293,6 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) return 0; } -// Get the equivalent ASCII (Unicode?) character for a keypress. -static INT32 GetTypedChar(SDL_Keysym keysym) -{ - SDL_Event next_event; - SDL_Keycode keycode = keysym.sym; - SDL_Scancode scancode = keysym.scancode; - - if (I_UseNativeKeyboard()) // only use this this if on chat or console or the current menu wants inputs from us (except if its the control setup menu ig) - { - // Special cases, where we always return a fixed value. - switch (keycode) - { - case SDLK_BACKSPACE: return KEY_BACKSPACE; - case SDLK_RETURN: return KEY_ENTER; - default: - break; - } - - if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 && next_event.type == SDL_TEXTINPUT) - { - if (next_event.text.text[1] == '\0') // limit to ASCII - { - return next_event.text.text[0]; - } - } - } - - return Impl_SDL_Scancode_To_Keycode(scancode); // fallback to scancodes -} - static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) { SDL_Keycode keycode = keysym.sym; @@ -423,6 +371,60 @@ static INT32 Impl_SDL_Keysym_To_Keycode(SDL_Keysym keysym) return Impl_SDL_Scancode_To_Keycode(scancode); } +static boolean native_input_active = false; + +// used to supress the games shift/alt handling +boolean I_UseNativeKeyboard(void) +{ + return (cv_keyboardlayout.value == 2 && native_input_active); +} + +void I_SetTextInput(boolean enable) +{ + if (enable && !native_input_active) + { + SDL_StartTextInput(); + native_input_active = true; + } + else if (!enable && native_input_active) + { + SDL_StopTextInput(); + native_input_active = false; + } +} + +// Get the equivalent ASCII (Unicode?) character for a keypress. +static INT32 GetTypedChar(SDL_Keysym keysym) +{ + SDL_Event next_event; + SDL_Keycode keycode = keysym.sym; + SDL_Scancode scancode = keysym.scancode; + + // only use this this if on chat or console or the current menu wants inputs from us (except if its the control setup menu ig) + if (native_input_active) + { + // Special cases, where we always return a fixed value. + switch (keycode) + { + case SDLK_BACKSPACE: return KEY_BACKSPACE; + case SDLK_RETURN: return KEY_ENTER; + default: + break; + } + + if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 && next_event.type == SDL_TEXTINPUT) + { + if (next_event.text.text[1] == '\0') // limit to ASCII + { + return next_event.text.text[0]; + } + } + } + + // otherwise fallback to scancodes + return Impl_SDL_Scancode_To_Keycode(scancode); +} + static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) { // -32768 to 32767 From 7e5019bd36d7a7de46579315ffc03ab76f26f160 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Sep 2025 16:23:30 +0200 Subject: [PATCH 20/39] handle D_AutoloadFile better only malloc stuff if we need it mallocd --- src/d_main.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index b9cfbcd06..bc826acdb 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1103,26 +1103,28 @@ static void D_AutoloadFile(const char *file, char **filearray) char *newfile; INT32 fileType = D_DetectFileType(file); - for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++) - ; - - newfile = malloc(strlen(file) + 1); - if (!newfile) - I_Error("No more free memory to AutoloadFile %s",file); - if (!fileType) { CONS_Printf("D_AutoloadFile: File %s is unknown or invalid\n", file); - free(newfile); return; } - strcpy(newfile, file); + for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++) + ; if (fileType <= 6) + { + newfile = malloc(strlen(file) + 1); + if (!newfile) + I_Error("No more free memory to AutoloadFile %s",file); + + strcpy(newfile, file); filearray[pnumwadfiles] = newfile; + } else - COM_BufAddText(va("exec %s\n", newfile)); + { + COM_BufAddText(va("exec %s\n", file)); + } } static char *strremove(char *str, const char *sub) From ab13b2810669a77e6e1c5f06189a93c71b8448ec Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Thu, 18 Sep 2025 21:19:06 +0200 Subject: [PATCH 21/39] Fix ghost hitlist causing zone errors (closes #118) Beware the wrath of PU_LEVEL --- src/g_demo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_demo.c b/src/g_demo.c index 20d40d5bf..87ae0b61f 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -630,7 +630,7 @@ void G_GhostAddHit(INT32 playernum, mobj_t *victim) ghostext[playernum].flags |= EZT_HIT; ghostext[playernum].hits++; - ghostext[playernum].hitlist = Z_Realloc(ghostext[playernum].hitlist, ghostext[playernum].hits * sizeof(mobj_t *), PU_LEVEL, &ghostext[playernum].hitlist); + Z_Realloc(ghostext[playernum].hitlist, ghostext[playernum].hits * sizeof(mobj_t *), PU_STATIC, &ghostext[playernum].hitlist); P_SetTarget(ghostext[playernum].hitlist + (ghostext[playernum].hits-1), victim); } From 34f8181e569a7f7ba22c0f130cfe3a469e3d9554 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Sep 2025 21:38:23 +0200 Subject: [PATCH 22/39] dont draw the leveltitle card for each splitscreen player they just overlap since they draw in the very same place --- src/st_stuff.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 5d0b75b9e..f5634423c 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -606,17 +606,21 @@ static void ST_overlayDrawer(void) } } - if ((!(netgame || multiplayer) || !hu_showscores) && !forceshowhud) + // dont draw those if we force the hud to show in the saturn options + if (!forceshowhud) { - if (renderisnewtic) + if (!(netgame || multiplayer) || !hu_showscores) { - LUA_HUDHOOK(game, luahuddrawlist_game[stplyrnum]); + if (renderisnewtic) + { + LUA_HUDHOOK(game, luahuddrawlist_game[stplyrnum]); + } } - } - // draw level title Tails - if (!(hu_showscores && (netgame || multiplayer) && !mapreset) && LUA_HudEnabled(hud_stagetitle) && !forceshowhud) - ST_drawLevelTitle(); + // draw level title Tails + if (stplyrnum == 0 && !(hu_showscores && (netgame || multiplayer) && !mapreset) && LUA_HudEnabled(hud_stagetitle)) + ST_drawLevelTitle(); + } if (!hu_showscores && netgame && !mapreset) { From 2ea1ac93316106d3d55c047524b87f8bf27e0315 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 28 Sep 2025 22:51:25 +0200 Subject: [PATCH 23/39] qs22j: handle cases with (0 or 1) elements to sort avoid undefined behaviour and return early if we only have 1 element we can skip all the crap since we dont need to sort anyways --- src/hardware/hw_main.cpp | 2 +- src/qs22j.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 04726315a..0c9d4bcf4 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -4191,7 +4191,7 @@ static int CompareVisSprites(const void *p1, const void *p2) fdiff = spr2->tz - spr1->tz; // this order seems correct when checking with apitrace. Back to front. if (fabsf(fdiff) < 1.0E-36f) - return spr1->dispoffset - spr2->dispoffset;// smallest dispoffset first if sprites are at (almost) same location. + return spr1->dispoffset - spr2->dispoffset; // smallest dispoffset first if sprites are at (almost) same location. else if (fdiff > 0) return 1; else diff --git a/src/qs22j.c b/src/qs22j.c index c610bde4d..bc94d6648 100644 --- a/src/qs22j.c +++ b/src/qs22j.c @@ -18,6 +18,7 @@ #include #include "qs22j.h" +#include "doomdef.h" #define INSORTTHRESH 5 // if n < this use insertion sort // MUST be >= 2 @@ -85,9 +86,14 @@ static inline char *med3(char *a, char *b, char *c, int (*compar)(const void *, (COMP(b, c) > 0 ? b : COMP(a, c) > 0 ? c : a); } -void qs22j(void *base, size_t nmemb, size_t size, - int (*compar)(const void *, const void *)) +void qs22j(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) { + // we have nothing to sort + if (UNLIKELY(nmemb <= 1)) + { + return; + } + char *stack[2*8*sizeof(size_t)], **sp = stack; // stack and stack pointer char *left = base; // set up char * base pointer char *limit = left + nmemb * size; // pointer past end of array @@ -114,7 +120,7 @@ void qs22j(void *base, size_t nmemb, size_t size, vecswapf = swapwords; if (size == sizeof(pref_typ)) swap_type = 0; - } + } else if ((size % sizeof(DWORD)) == 0) { swapf = vecswapf = swapdwords; @@ -123,6 +129,7 @@ void qs22j(void *base, size_t nmemb, size_t size, { swapf = vecswapf = swapwords; } + for (;;) { nmemb = (limit - left) / size; @@ -133,7 +140,7 @@ void qs22j(void *base, size_t nmemb, size_t size, goto pop; if (nmemb >= INSORTTHRESH) // otherwise use insertion sort - { + { char *right = limit - size; // best so far? fewer compares, a few more swaps char *p = left + (nmemb / 2) * size; From 394beb75335733b74c0d258d2cff0de69f478840 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Sep 2025 13:43:19 +0200 Subject: [PATCH 24/39] rename this --- src/hardware/hw_main.cpp | 2 +- src/p_mobj.c | 14 +++++++------- src/r_bsp.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 0c9d4bcf4..443ced9aa 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -2983,7 +2983,7 @@ static void HWR_Subsector(size_t num) const sector_t *controlSec = §ors[rover->secnum]; - if (!controlSec->moved) + if (controlSec->moved != true) continue; anyMoved = true; diff --git a/src/p_mobj.c b/src/p_mobj.c index a42d7bcef..7ff994b98 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3554,28 +3554,28 @@ animonly: static void P_CalculatePrecipFloor(precipmobj_t *mobj, boolean spawn) { // recalculate floorz each time - const sector_t *mobjsecsubsec; + const sector_t *sec; if (mobj && mobj->subsector && mobj->subsector->sector) - mobjsecsubsec = mobj->subsector->sector; + sec = mobj->subsector->sector; else return; // no need to recalc anything if not moved - if (!spawn && !mobjsecsubsec->moved) + if (!spawn && !sec->moved) return; - mobj->floorz = P_GetSectorFloorZAt(mobjsecsubsec, mobj->x, mobj->y); + mobj->floorz = P_GetSectorFloorZAt(sec, mobj->x, mobj->y); - if (mobjsecsubsec->ffloors) + if (sec->ffloors) { ffloor_t *rover; fixed_t topheight; - for (rover = mobjsecsubsec->ffloors; rover; rover = rover->next) + for (rover = sec->ffloors; rover; rover = rover->next) { // If it exists, it'll get rained on. - if (!(rover->flags & FF_EXISTS)) + if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES)) continue; if (!(rover->flags & FF_BLOCKOTHERS) && !(rover->flags & FF_SWIMMABLE)) diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index fa66ac2ac..6ef63739f 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -783,7 +783,7 @@ static void R_Subsector(size_t num) if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES)) continue; - sector_t *controlSec = §ors[rover->secnum]; + const sector_t *controlSec = §ors[rover->secnum]; if (controlSec->moved != true) continue; From f381239825df30b9a9181cb7c770e35e03ee3706 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Sep 2025 11:51:42 +0200 Subject: [PATCH 25/39] smol changes R_ProjectSprite - remove oldthing (idk what that was even for) - properly account for localskins - save a few FixedMuls during clipping --- src/hardware/hw_main.cpp | 8 ++-- src/r_things.cpp | 86 +++++++++++++++++++++------------------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 443ced9aa..026527f99 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -4750,11 +4750,11 @@ static void HWR_ProjectSprite(mobj_t *thing) rot = (thing->frame & FF_FRAMEMASK); - //Fab : 02-08-98: 'skin' override spritedef currently used for skin - if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) - { - sprskin = K_GetMobjSkin(thing); + sprskin = K_GetMobjSkin(thing); + //Fab : 02-08-98: 'skin' override spritedef currently used for skin + if (sprskin && thing->sprite == SPR_PLAY) + { sprdef = &sprskin->spritedef; #ifdef ROTSPRITE sprinfo = &sprskin->sprinfo; diff --git a/src/r_things.cpp b/src/r_things.cpp index 1b99b64a3..7f1d5af54 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1190,6 +1190,7 @@ static void R_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE spriteinfo_t *sprinfo; #endif + skin_t *sprskin = NULL; size_t lump; size_t rot; @@ -1231,24 +1232,22 @@ static void R_ProjectSprite(mobj_t *thing) if (!thing || thing->subsector == NULL) return; - mobj_t *oldthing = thing; - - const boolean mirrored = thing->mirrored; - const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); - const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); - const boolean papersprite = (thing->frame & FF_PAPERSPRITE); - // uncapped/interpolation interpmobjstate_t interp = {}; // do interpolation - R_InterpolateMobjState(oldthing, R_GetMobjTimeFrac(oldthing), &interp); + R_InterpolateMobjState(thing, R_GetMobjTimeFrac(thing), &interp); this_scale = interp.scale; if (this_scale < 1) return; + const boolean mirrored = thing->mirrored; + const boolean vflip = (thing->eflags & MFE_VERTICALFLIP); + const boolean hflip = (!(thing->frame & FF_HORIZONTALFLIP) != !mirrored); + const boolean papersprite = (thing->frame & FF_PAPERSPRITE); + // transform the origin point tr_x = interp.x - viewx; tr_y = interp.y - viewy; @@ -1283,12 +1282,14 @@ static void R_ProjectSprite(mobj_t *thing) const boolean shouldrotate = (interp.sloperoll || interp.slopepitch || interp.roll || interp.pitch || thing->rollangle || sliprollrotate); #endif + sprskin = K_GetMobjSkin(thing); + //Fab : 02-08-98: 'skin' override spritedef currently used for skin - if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) + if (sprskin && thing->sprite == SPR_PLAY) { - sprdef = &K_GetMobjSkin(thing)->spritedef; + sprdef = &sprskin->spritedef; #ifdef ROTSPRITE - sprinfo = &K_GetMobjSkin(thing)->sprinfo; + sprinfo = &sprskin->sprinfo; #endif if (rot >= sprdef->numframes) @@ -1313,7 +1314,8 @@ static void R_ProjectSprite(mobj_t *thing) sprinfo = &spriteinfo[thing->sprite]; #endif rot = (thing->frame & FF_FRAMEMASK); - if (!thing->skin) + + if (!sprskin) { thing->state->sprite = thing->sprite; thing->state->frame = thing->frame; @@ -1431,9 +1433,9 @@ static void R_ProjectSprite(mobj_t *thing) spritexscale = interp.spritexscale; spriteyscale = interp.spriteyscale; - if ((thing->skin || thing->localskin) && K_GetMobjSkin(thing)->flags & SF_HIRES) + if (sprskin && sprskin->flags & SF_HIRES) { - fixed_t highresscale = ((skin_t *)thing->skin)->highresscale; + fixed_t highresscale = sprskin->highresscale; spritexscale = FixedMul(spritexscale, highresscale); spriteyscale = FixedMul(spriteyscale, highresscale); } @@ -1475,34 +1477,38 @@ static void R_ProjectSprite(mobj_t *thing) // Get paperoffset (offset) and paperoffset (distance) paperoffset = -FixedMul(tr_x, cosmul) - FixedMul(tr_y, sinmul); paperdistance = -FixedMul(tr_x, sinmul) + FixedMul(tr_y, cosmul); + if (paperdistance < 0) { paperoffset = -paperoffset; paperdistance = -paperdistance; } + centerangle = viewangle - interp.angle; tr_x += FixedMul(offset2, cosmul); tr_y += FixedMul(offset2, sinmul); - tz2 = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin); + tz2 = FixedMul(tr_x, viewcos) + FixedMul(tr_y, viewsin); tx2 = FixedMul(tr_x, viewsin) - FixedMul(tr_y, viewcos); - if (std::max(tz, tz2) < FixedMul(MINZ, this_scale)) // non-papersprite clipping is handled earlier + const fixed_t minz_scale = FixedMul(MINZ, this_scale); + + if (std::max(tz, tz2) < minz_scale) // non-papersprite clipping is handled earlier return; // Needs partially clipped - if (tz < FixedMul(MINZ, this_scale)) + if (tz < minz_scale) { - fixed_t div = FixedDiv(tz2-tz, FixedMul(MINZ, this_scale)-tz); + fixed_t div = FixedDiv(tz2-tz, minz_scale-tz); tx += FixedDiv(tx2-tx, div); - tz = FixedMul(MINZ, this_scale); + tz = minz_scale; } - else if (tz2 < FixedMul(MINZ, this_scale)) + else if (tz2 < minz_scale) { - fixed_t div = FixedDiv(tz-tz2, FixedMul(MINZ, this_scale)-tz2); + fixed_t div = FixedDiv(tz-tz2, minz_scale-tz2); tx2 += FixedDiv(tx-tx2, div); - tz2 = FixedMul(MINZ, this_scale); + tz2 = minz_scale; } if ((tx2 / 4) < -(FixedMul(tz2, fovtan)) || (tx / 4) > FixedMul(tz, fovtan)) // too far off the side? @@ -1511,7 +1517,7 @@ static void R_ProjectSprite(mobj_t *thing) yscale = FixedDiv(projectiony, tz); xscale = FixedDiv(projection, tz); - x1 = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; + x1 = (centerxfrac + FixedMul(tx, xscale))>>FRACBITS; // off the right side? if (x1 > viewwidth) @@ -1520,7 +1526,7 @@ static void R_ProjectSprite(mobj_t *thing) yscale2 = FixedDiv(projectiony, tz2); xscale2 = FixedDiv(projection, tz2); - x2 = (centerxfrac + FixedMul(tx2,xscale2))>>FRACBITS; + x2 = (centerxfrac + FixedMul(tx2, xscale2))>>FRACBITS; // off the left side if (x2 < 0) @@ -1555,14 +1561,14 @@ static void R_ProjectSprite(mobj_t *thing) scalestep = 0; yscale = sortscale; tx += offset; - x1 = centerx + (FixedMul(tx,xscale) / FRACUNIT); + x1 = centerx + (FixedMul(tx, xscale) / FRACUNIT); // off the right side? if (x1 > viewwidth) return; tx += offset2; - x2 = (centerx + (FixedMul(tx,xscale) / FRACUNIT)) - 1; + x2 = (centerx + (FixedMul(tx, xscale) / FRACUNIT)) - 1; // off the left side if (x2 < 0) @@ -1581,24 +1587,24 @@ static void R_ProjectSprite(mobj_t *thing) // Determine the blendmode and translucency value INT32 blendmode; - if (oldthing->frame & FF_BLENDMASK) - blendmode = ((oldthing->frame & FF_BLENDMASK) >> FF_BLENDSHIFT) + 1; + if (thing->frame & FF_BLENDMASK) + blendmode = ((thing->frame & FF_BLENDMASK) >> FF_BLENDSHIFT) + 1; else - blendmode = oldthing->blendmode; + blendmode = thing->blendmode; - if (oldthing->flags2 & MF2_SHADOW || thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) + if (thing->flags2 & MF2_SHADOW || thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) trans = tr_trans80; // because now the translucency is set through FF_TRANSMASK - else if (oldthing->frame & FF_TRANSMASK) + else if (thing->frame & FF_TRANSMASK) { - trans = (oldthing->frame & FF_TRANSMASK) >> FF_TRANSSHIFT; + trans = (thing->frame & FF_TRANSMASK) >> FF_TRANSSHIFT; if (!R_BlendLevelVisible(blendmode, trans)) return; } else trans = 0; - if (cv_playerfade.value && oldthing->player) - trans = static_cast(R_GetThingTransTable(R_DoPlayerFade(oldthing), static_cast(trans))); + if (cv_playerfade.value && thing->player) + trans = static_cast(R_GetThingTransTable(R_DoPlayerFade(thing), static_cast(trans))); //SoM: 3/17/2000: Disregard sprites that are out of view.. if (vflip) @@ -1606,7 +1612,7 @@ static void R_ProjectSprite(mobj_t *thing) // When vertical flipped, draw sprites from the top down, at least as far as offsets are concerned. // sprite height - sprite topoffset is the proper inverse of the vertical offset, of course. // remember gz and gzt should be seperated by sprite height, not thing height - thing height can be shorter than the sprite itself sometimes! - gz = interp.z + oldthing->height - FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale)); + gz = interp.z + thing->height - FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale)); gzt = gz + FixedMul(spr_height, FixedMul(spriteyscale, this_scale)); } else @@ -1621,9 +1627,9 @@ static void R_ProjectSprite(mobj_t *thing) return; } - if (oldthing->frame & FF_ABSOLUTELIGHTLEVEL) + if (thing->frame & FF_ABSOLUTELIGHTLEVEL) { - const UINT8 n = R_ThingLightLevel(oldthing); + const UINT8 n = R_ThingLightLevel(thing); // n = uint8 aka 0 - 255, so the shift will always be 0 - LIGHTLEVELS - 1 lights_array = scalelight[n >> LIGHTSEGSHIFT]; } @@ -1784,11 +1790,11 @@ static void R_ProjectSprite(mobj_t *thing) else vis->transmap = NULL; - if (R_ThingIsFullBright(oldthing) || oldthing->flags2 & MF2_SHADOW || thing->flags2 & MF2_SHADOW) + if (R_ThingIsFullBright(thing) || thing->flags2 & MF2_SHADOW) vis->cut = static_cast(vis->cut | SC_FULLBRIGHT); - else if (R_ThingIsSemiBright(oldthing)) + else if (R_ThingIsSemiBright(thing)) vis->cut = static_cast(vis->cut | SC_SEMIBRIGHT); - else if (R_ThingIsFullDark(oldthing)) + else if (R_ThingIsFullDark(thing)) vis->cut = static_cast(vis->cut | SC_FULLDARK); // From c7d78fe9487272cbd295e4af3331ac95fc6e7187 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Sep 2025 14:11:25 +0200 Subject: [PATCH 26/39] only recalc precipfloor twice a second --- src/p_mobj.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 7ff994b98..1e554c53f 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3655,7 +3655,8 @@ boolean P_PrecipThinker(precipmobj_t *mobj) if (mobj->precipflags & PCF_SPLASH) return true; - if (renderisnewtic) + // only recalc this twice a second (doubt anyone will notice this lulul) + if ((leveltime % 17) == 0) P_CalculatePrecipFloor(mobj, false); // adjust height From 202e24c69cdb4c06639ea33da358833cf9d868b3 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 29 Sep 2025 14:13:15 +0200 Subject: [PATCH 27/39] fix precip not propely accounting for moving fofs (again) was fixed a while ago, then i broke it again due to performance concerns now we only update this twice a seconds, and its only for the currently rendered precipmobjs lets see how it performs --- src/p_mobj.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 1e554c53f..c16d5ce4c 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3551,7 +3551,7 @@ animonly: } } -static void P_CalculatePrecipFloor(precipmobj_t *mobj, boolean spawn) +static void P_CalculatePrecipFloor(precipmobj_t *mobj) { // recalculate floorz each time const sector_t *sec; @@ -3561,10 +3561,6 @@ static void P_CalculatePrecipFloor(precipmobj_t *mobj, boolean spawn) else return; - // no need to recalc anything if not moved - if (!spawn && !sec->moved) - return; - mobj->floorz = P_GetSectorFloorZAt(sec, mobj->x, mobj->y); if (sec->ffloors) @@ -3657,7 +3653,7 @@ boolean P_PrecipThinker(precipmobj_t *mobj) // only recalc this twice a second (doubt anyone will notice this lulul) if ((leveltime % 17) == 0) - P_CalculatePrecipFloor(mobj, false); + P_CalculatePrecipFloor(mobj); // adjust height if ((mobj->z += mobj->momz) <= mobj->floorz) @@ -10043,7 +10039,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype mobj->thinker.function = (actionf_p1)P_NullPrecipThinker; P_AddPrecipThinker(&mobj->thinker); - P_CalculatePrecipFloor(mobj, true); + P_CalculatePrecipFloor(mobj); if (mobj->floorz != starting_floorz) mobj->precipflags |= PCF_FOF; From 2656a87e46d4a38a8f9825f04687f0f71f811117 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Sep 2025 17:26:26 +0200 Subject: [PATCH 28/39] Signal handler improvements - Move the backtrace and signal stuff into one "block" in both i_system files - print the current platform into the crashlog - dedupe code a little - make crash messages slightly more understandable - handle more signals (if they exist) mostly taken from https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2732 --- src/d_netcmd.c | 13 +- src/d_netfil.c | 4 +- src/dedicated/i_main.c | 9 +- src/dedicated/i_system.c | 697 ++++++++++++++++++----------------- src/doomdef.h | 14 + src/i_system.h | 4 + src/sdl/i_main.c | 21 +- src/sdl/i_system.cpp | 775 +++++++++++++++++++-------------------- src/win32/win_dbg.c | 19 +- src/win32/win_dbg.h | 6 +- 10 files changed, 781 insertions(+), 781 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 71a807652..7d2e0c6d0 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4882,18 +4882,7 @@ static void Command_Version_f(void) #endif // OS - // Would be nice to use SDL_GetPlatform for this -#if defined (_WIN32) || defined (_WIN64) - CONS_Printf("Windows "); -#elif defined(__linux__) - CONS_Printf("Linux "); -#elif defined(MACOSX) - CONS_Printf("macOS "); -#elif defined(UNIXCOMMON) - CONS_Printf("Unix (Common) "); -#else - CONS_Printf("Other OS "); -#endif + CONS_Printf("%s ", I_GetSysName()); // Bitness if (sizeof(void*) == 4) diff --git a/src/d_netfil.c b/src/d_netfil.c index 8724fab6d..5df28a9b4 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -579,9 +579,6 @@ boolean CL_LoadServerFiles(void) { INT32 i; -// if (M_CheckParm("-nofiles")) -// return; - for (i = 0; i < fileneedednum; i++) { if (fileneeded[i].status == FS_OPEN) @@ -617,6 +614,7 @@ boolean CL_LoadServerFiles(void) fileneeded[i].status, s); } } + return true; } diff --git a/src/dedicated/i_main.c b/src/dedicated/i_main.c index 911e356d0..055b14882 100644 --- a/src/dedicated/i_main.c +++ b/src/dedicated/i_main.c @@ -213,12 +213,9 @@ int main(int argc, char **argv) //I_OutputMsg("I_StartupSystem() ...\n"); I_StartupSystem(); -#if defined (_WIN32) - { -#ifdef DRMINGW - ExcHndlInit(); -#endif - } + +#ifdef HAVE_DRMINGW + InitDrMingw(); #endif // startup SRB2 diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 585c82de8..29e80b843 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -174,293 +174,10 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif -#ifdef HAVE_LIBBACKTRACE -#include -// TODO - move this to some header file instead -extern struct backtrace_state *bt_state; - -typedef struct bt_crash_reason_s { - enum { - BTCRASH_SIGNAL, - BTCRASH_ERRORMSG, - } type; - - union { - INT32 signal; - const char *errormsg; - } value; -} bt_crash_reason_t; - -#define BT_CRASH_REASON_SIGNAL(num) (bt_crash_reason_t){ .type = BTCRASH_SIGNAL, .value = { .signal = num } } -#define BT_CRASH_REASON_ERRORMSG(msg) (bt_crash_reason_t){ .type = BTCRASH_ERRORMSG, .value = { .errormsg = msg } } - -static void printsignal(FILE *fp, INT32 num) -{ - switch (num) - { - case SIGILL: - fprintf(fp, "SIGILL - illegal instruction - invalid function image"); - break; - case SIGFPE: - fprintf(fp, "SIGFPE - mathematical exception"); - break; - case SIGSEGV: - fprintf(fp, "SIGSEGV - segment violation"); - break; - case SIGABRT: - fprintf(fp, "SIGABRT - abnormal termination triggered by abort call"); - break; - default: - fprintf(fp, "Signal number %d", num); - } -} - -typedef struct bt_out_buf_s { - boolean error; - char *pos; - size_t size; -} bt_out_buf_t; - -static void bt_syminfo_cb(void *data, uintptr_t pc, const char *symname, uintptr_t symval, uintptr_t symsize) -{ - (void)symval; - (void)symsize; - - bt_out_buf_t *buf = (bt_out_buf_t*)data; - - if (!symname) - symname = "???"; - - int n = snprintf(buf->pos, buf->size, "%p %s\n", (void*)pc, symname); - - if (n <= 0) - { - buf->size = 0; - return; - } - - buf->pos += n; - buf->size -= n; -} - -static int bt_simple_cb(void *data, uintptr_t pc) -{ - bt_out_buf_t *buf = (bt_out_buf_t*)data; - - backtrace_syminfo(bt_state, pc, bt_syminfo_cb, NULL, data); - - if (!buf->size) return 1; - - return 0; -} - -static int bt_full_cb(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) -{ - bt_out_buf_t *buf = (bt_out_buf_t*)data; - - if (!filename) filename = "???"; - if (!function) function = "???"; - - int n = snprintf(buf->pos, buf->size, "%p %s\n\t%s:%d\n", (void*)pc, function, filename, lineno); - - if (n <= 0) return 1; - - buf->pos += n; - buf->size -= n; - - if (!buf->size) return 1; - - return 0; -} - -static void bt_error_cb(void *data, const char *msg, int errnum) -{ - (void)msg; // We don't need this - - bt_out_buf_t *buf = (bt_out_buf_t*)data; - - // No debug info - if (errnum == -1) - buf->error = true; -} - -static void write_backtrace(bt_crash_reason_t reason) -{ - FILE *out = fopen(va("%s" PATHSEP "%s", srb2home, "srb2kart-crash-log.txt"), "a"); - - time_t rawtime; - struct tm *timeinfo; - - const size_t BUFSIZE = 8192; - char backtrace[BUFSIZE]; - - bt_out_buf_t buf; - buf.error = false; - buf.pos = backtrace; - buf.size = BUFSIZE; - - - if (!out) - { - fprintf(stderr, "\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n"); - out = stderr; - } - - // Get the current time as a string. - time(&rawtime); - timeinfo = localtime(&rawtime); - - fprintf(out, "------------------------\n\n"); - - fprintf(out, "Program name: %s %s\n", SRB2APPLICATION, VERSIONSTRING); - - if (compdate && comptime && comprevision && compbranch) - fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); - - if (gamestate == GS_LEVEL) - { - char *title = G_BuildMapTitle(gamemap); - - if (title) - { - fprintf(out, "Game map: %s (%s)\n", title, G_BuildMapName(gamemap)); - Z_Free(title); - } - else - fprintf(out, "Game map: %s\n", G_BuildMapName(gamemap)); - } - - fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); - - fprintf(out, "Caused by: "); - - switch (reason.type) - { - case BTCRASH_SIGNAL: - printsignal(out, reason.value.signal); - break; - - case BTCRASH_ERRORMSG: - fprintf(out, "%s", reason.value.errormsg); - break; - } - - fprintf(out, "\nBacktrace:\n"); - - // Try to get full backtrace, it will print files and line numbers - backtrace_full(bt_state, 2, bt_full_cb, bt_error_cb, (void*)&buf); - - if (buf.error) - { - // Fall back to simple backtrace, only prints function names - backtrace_simple(bt_state, 2, bt_simple_cb, NULL, (void*)&buf); - } - - fputs(backtrace, out); - - if (out != stderr) - { - fclose(out); - fprintf(stderr, "Crash report created, find srb2kart-crash-log.txt in your SRB2Kart directory\n"); - } -} - -#endif - boolean consolevent = false; boolean framebuffer = false; - -boolean g_in_exiting_signal_handler = false; - UINT8 keyboard_started = false; -static void I_ReportSignal(int num, int coredumped) -{ - //static char msg[] = "oh no! back to reality!\r\n"; - const char * sigmsg; - char msg[256]; - - switch (num) - { -// case SIGINT: -// sigmsg = "SIGINT - interrupted"; -// break; - case SIGILL: - sigmsg = "SIGILL - illegal instruction - invalid function image"; - break; - case SIGFPE: - sigmsg = "SIGFPE - mathematical exception"; - break; - case SIGSEGV: - sigmsg = "SIGSEGV - segment violation"; - break; -// case SIGTERM: -// sigmsg = "SIGTERM - Software termination signal from kill"; -// break; -// case SIGBREAK: -// sigmsg = "SIGBREAK - Ctrl-Break sequence"; -// break; - case SIGABRT: - sigmsg = "SIGABRT - abnormal termination triggered by abort call"; - break; - default: - sprintf(msg,"signal number %d", num); - if (coredumped) - sigmsg = 0; - else - sigmsg = msg; - } - - if (coredumped) - { - if (sigmsg) - sprintf(msg, "%s (core dumped)", sigmsg); - else - strcat(msg, " (core dumped)"); - } - else - { - sprintf(msg, "%s", sigmsg); - } - -#ifdef HAVE_LIBBACKTRACE - strncat(msg, "\n\nCrash report has been saved into srb2kart-crash-log.txt", 255); -#elif defined(_WIN32) && !defined(__MINGW64__) - strncat(msg, "\n\nCrash report has been saved into srb2kart.rpt", 255); -#endif - - I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); -} - -#ifndef NEWSIGNALHANDLER -FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) -{ - g_in_exiting_signal_handler = true; - - D_QuitNetGame(); // Fix server freezes - -#ifdef HAVE_LIBBACKTRACE - write_backtrace(BT_CRASH_REASON_SIGNAL(num)); -#endif - - if (demo.recording) - G_SaveDemo(); - - I_ReportSignal(num, 0); - I_ShutdownSystem(); - signal(num, SIG_DFL); //default signal action - raise(num); - I_Quit(); -} -#endif - -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) -{ - signal(num, SIG_DFL); //default signal action - raise(num); - I_Quit(); -} - #ifdef HAVE_TERMIOS // TERMIOS console code from Quake3: thank you! boolean stdin_active = true; @@ -489,16 +206,6 @@ static struct termios tty_tc; // so we provide tty_Clear and tty_Show to be called before and after a stdout or stderr output // ============================================================= -// flush stdin, I suspect some terminals are sending a LOT of garbage -// FIXME TTimo relevant? -#if 0 -static inline void tty_FlushIn(void) -{ - char key; - while (read(STDIN_FILENO, &key, 1)!=-1); -} -#endif - // do a backspace // TTimo NOTE: it seems on some terminals just sending '\b' is not enough // so for now, in any case we send "\b \b" .. yeah well .. @@ -793,55 +500,6 @@ static inline void I_StartupConsole(void) static inline void I_ShutdownConsole(void){} #endif -// -// StartupKeyboard -// -static void I_RegisterSignals (void) -{ -#ifdef SIGINT - signal(SIGINT , quit_handler); -#endif -#ifdef SIGBREAK - signal(SIGBREAK , quit_handler); -#endif -#ifdef SIGTERM - signal(SIGTERM , quit_handler); -#endif - - // If these defines don't exist, - // then compilation would have failed above us... -#ifndef NEWSIGNALHANDLER - signal(SIGILL , signal_handler); - signal(SIGSEGV , signal_handler); - signal(SIGABRT , signal_handler); - signal(SIGFPE , signal_handler); -#endif -} - -#ifdef NEWSIGNALHANDLER -static void signal_handler_child(INT32 num) -{ -#ifdef HAVE_LIBBACKTRACE - write_backtrace(BT_CRASH_REASON_SIGNAL(num)); -#endif - - if (demo.recording) - G_SaveDemo(); - - signal(num, SIG_DFL); //default signal action - raise(num); -} - -static void I_RegisterChildSignals(void) -{ - // If these defines don't exist, - // then compilation would have failed above us... - signal(SIGILL , signal_handler_child); - signal(SIGSEGV , signal_handler_child); - signal(SIGABRT , signal_handler_child); - signal(SIGFPE , signal_handler_child); -} -#endif // //I_OutputMsg @@ -1312,6 +970,317 @@ void I_SleepDuration(precise_t duration) #endif } +boolean g_in_exiting_signal_handler = false; + +static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg) +{ + const char *sigmsg; + + switch (signal_num) + { +#ifdef SIGINT + case SIGINT: + sigmsg = ("SIGINT - SRB2Kart-Saturn was interrupted prematurely by the user."); + break; +#endif + case SIGILL: // illegal instruction - invalid function image + sigmsg = ("SIGILL - SRB2Kart-Saturn has attempted to execute an illegal instruction and needs to close."); + break; + case SIGFPE: // mathematical exception + sigmsg = ("SIGFPE - SRB2Kart-Saturn has encountered a mathematical exception and needs to close."); + break; + case SIGSEGV: // segment violation + sigmsg = ("SIGSEGV - SRB2Kart-Saturn has attempted to access a memory location that it shouldn't and needs to close."); + break; +#ifdef SIGTERM + case SIGTERM: // Software termination signal from kill + sigmsg = ("SIGTERM - SRB2Kart-Saturn was terminated by a kill signal."); + break; +#endif +#ifdef SIGBREAK + case SIGBREAK: // Ctrl-Break sequence + sigmsg =("SIGBREAK - SRB2Kart-Saturn was terminated by a Ctrl-Break sequence.") + break; +#endif + case SIGABRT: // abnormal termination triggered by abort call + sigmsg = ("SIGABRT - SRB2Kart-Saturn was terminated by an abort signal."); + break; + default: + sprintf(signal_msg, "Signal number %d", signal_num); + sigmsg = (core_dumped ? "Unknown signal" : signal_msg); + break; + } + + if (core_dumped) + { + if (sigmsg) + sprintf(signal_msg, "%s (core dumped)", sigmsg); + else + strcat(signal_msg, " (core dumped)"); + } + else + { + sprintf(signal_msg, "%s", sigmsg); + } +} + +static void I_ReportSignal(int num, int coredumped) +{ + char sigmsg[512]; + + I_PrintSignal(num, coredumped, sigmsg); + 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); +} + +#ifndef NEWSIGNALHANDLER +FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) +{ + g_in_exiting_signal_handler = true; + + D_QuitNetGame(); // Fix server freezes + +#ifdef HAVE_LIBBACKTRACE + write_backtrace(BT_CRASH_REASON_SIGNAL(num)); +#endif + + I_ReportSignal(num, 0); + I_ShutdownSystem(); + signal(num, SIG_DFL); //default signal action + raise(num); + I_Quit(); +} +#endif + +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) +{ + signal(num, SIG_DFL); //default signal action + raise(num); + I_Quit(); +} + +#ifdef HAVE_LIBBACKTRACE +#include +// TODO - move this to some header file instead +extern struct backtrace_state *bt_state; + +typedef struct bt_crash_reason_s { + enum { + BTCRASH_SIGNAL, + BTCRASH_ERRORMSG, + } type; + + union { + INT32 signal; + const char *errormsg; + } value; +} bt_crash_reason_t; + +#define BT_CRASH_REASON_SIGNAL(num) (bt_crash_reason_t){ .type = BTCRASH_SIGNAL, .value = { .signal = num } } +#define BT_CRASH_REASON_ERRORMSG(msg) (bt_crash_reason_t){ .type = BTCRASH_ERRORMSG, .value = { .errormsg = msg } } + +typedef struct bt_out_buf_s { + boolean error; + char *pos; + size_t size; +} bt_out_buf_t; + +static void bt_syminfo_cb(void *data, uintptr_t pc, const char *symname, uintptr_t symval, uintptr_t symsize) +{ + (void)symval; + (void)symsize; + + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + if (!symname) + symname = "???"; + + int n = snprintf(buf->pos, buf->size, "%p %s\n", (void*)pc, symname); + + if (n <= 0) + { + buf->size = 0; + return; + } + + buf->pos += n; + buf->size -= n; +} + +static int bt_simple_cb(void *data, uintptr_t pc) +{ + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + backtrace_syminfo(bt_state, pc, bt_syminfo_cb, NULL, data); + + if (!buf->size) return 1; + + return 0; +} + +static int bt_full_cb(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) +{ + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + if (!filename) filename = "???"; + if (!function) function = "???"; + + int n = snprintf(buf->pos, buf->size, "%p %s\n\t%s:%d\n", (void*)pc, function, filename, lineno); + + if (n <= 0) return 1; + + buf->pos += n; + buf->size -= n; + + if (!buf->size) return 1; + + return 0; +} + +static void bt_error_cb(void *data, const char *msg, int errnum) +{ + (void)msg; // We don't need this + + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + // No debug info + if (errnum == -1) + buf->error = true; +} + +static void write_backtrace(bt_crash_reason_t reason) +{ + char sig_msg[512]; + const char *filename = va("%s" PATHSEP CRASH_LOGFILE_NAME, srb2home); + FILE *out = fopen(filename, "a+"); + + time_t rawtime; + struct tm *timeinfo; + + const size_t BUFSIZE = 8192; + char backtrace[BUFSIZE]; + + bt_out_buf_t buf; + buf.error = false; + buf.pos = backtrace; + buf.size = BUFSIZE; + + if (!out) + { + fprintf(stderr, "\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n"); + out = stderr; + } + + // Get the current time as a string. + time(&rawtime); + timeinfo = localtime(&rawtime); + + fprintf(out, "------------------------\n\n"); + + fprintf(out, "Program name: %s %s\n", SRB2APPLICATION, VERSIONSTRING); + + fprintf(out, "Dedicated build\n"); + fprintf(out, "Platform: %s\n", I_GetSysName()); + + if (compdate && comptime && comprevision && compbranch) + fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); + + if (gamestate == GS_LEVEL && gamemap) + { + char *title = G_BuildMapTitle(gamemap); + + if (title) + { + fprintf(out, "Game map: %s (%s)\n", title, G_BuildMapName(gamemap)); + Z_Free(title); + } + else + fprintf(out, "Game map: %s\n", G_BuildMapName(gamemap)); + } + + fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); + + fprintf(out, "Caused by: "); + + switch (reason.type) + { + case BTCRASH_SIGNAL: + I_PrintSignal(reason.value.signal, false, sig_msg); + fprintf(out, "%s", sig_msg); + break; + + case BTCRASH_ERRORMSG: + fprintf(out, "%s", reason.value.errormsg); + break; + } + + fprintf(out, "\nBacktrace:\n"); + + // Try to get full backtrace, it will print files and line numbers + backtrace_full(bt_state, 2, bt_full_cb, bt_error_cb, (void*)&buf); + + if (buf.error) + { + // Fall back to simple backtrace, only prints function names + backtrace_simple(bt_state, 2, bt_simple_cb, NULL, (void*)&buf); + } + + fputs(backtrace, out); + + if (out != stderr) + { + fclose(out); + fprintf(stderr, "Crash report created, find %s in your SRB2Kart directory\n", CRASH_LOGFILE_NAME); + } +} +#endif + +static void I_RegisterSignals(void) +{ +#ifdef SIGINT + signal(SIGINT, quit_handler); +#endif +#ifdef SIGBREAK + signal(SIGBREAK, quit_handler); +#endif +#ifdef SIGTERM + signal(SIGTERM, quit_handler); +#endif +#ifndef NEWSIGNALHANDLER + // If these defines don't exist, + // then compilation would have failed above us... + signal(SIGILL, signal_handler); + signal(SIGSEGV, signal_handler); + signal(SIGABRT, signal_handler); + signal(SIGFPE, signal_handler); +#endif +} + +#ifdef NEWSIGNALHANDLER +static void signal_handler_child(INT32 num) +{ + g_in_exiting_signal_handler = true; + +#ifdef HAVE_LIBBACKTRACE + write_backtrace(BT_CRASH_REASON_SIGNAL(num)); +#endif + + signal(num, SIG_DFL); // default signal action + raise(num); +} + +static void I_RegisterChildSignals(void) +{ + // If these defines don't exist, + // then compilation would have failed above us... + signal(SIGILL, signal_handler_child); + signal(SIGSEGV, signal_handler_child); + signal(SIGABRT, signal_handler_child); + signal(SIGFPE, signal_handler_child); +} +#endif + #ifdef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void newsignalhandler_Warn(const char *pr) { @@ -2165,6 +2134,50 @@ size_t I_GetFreeMem(size_t *total) // note CPUAFFINITY code used to reside here void I_RegisterSysCommands(void) {} +const char *I_GetSysName(void) +{ + // reference: https://sourceforge.net/p/predef/wiki/OperatingSystems/ +#if defined(_WIN32) || defined(__CYGWIN__) + return "Windows"; +#elif defined(__APPLE__) + return "Mac OS"; +#elif defined(__linux__) + return "Linux"; +#elif defined(__FreeBSD__) + return "FreeBSD"; +#elif defined(__OpenBSD__) + return "OpenBSD"; +#elif defined(__NetBSD__) + return "NetBSD"; +#elif defined(__DragonFly__) + return "DragonFly BSD"; +#elif defined(__gnu_hurd__) + return "GNU Hurd"; // for anyone mental enough to set up an SRB2 server on GNU Hurd +#elif defined(__hpux) + return "HP-UX"; +#elif defined(EPLAN9) + return "Plan 9"; +#elif defined(__HAIKU__) + return "Haiku"; +#elif defined(__BEOS__) + return "BeOS"; +#elif defined(__minix) + return "Minix"; +#elif defined(__sun) +#if defined(__SVR4) || defined(__srv4__) + return "Solaris"; // this would be so cursed... +#else + return "SunOS"; +#endif +#elif defined(_AIX) + return "AIX"; +#elif defined(__SYLLABLE__) + return "SyllableOS"; // RIP SyllableOS, i still miss you ;-; +#else + return "Unknown"; +#endif +} + boolean I_InitNetwork(void) { // this must exist, but this is actually handled in i_tcp.c diff --git a/src/doomdef.h b/src/doomdef.h index 80ae6e170..ba7a04bfb 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -90,6 +90,20 @@ extern FILE *logstream; extern char logfilename[1024]; #endif +// not sure if this belongs here lul +// TODO: figure out whats preventing 32bit windows from working with libbacktrace +#if defined(_WIN32) && !defined(MINGW64) +#define HAVE_DRMINGW +#endif + +#if defined (HAVE_LIBBACKTRACE) +#define CRASH_LOGFILE_NAME "srb2kart-crash-log.txt" +#elif defined (HAVE_DRMINGW) +#define CRASH_LOGFILE_NAME "srb2kart-crash-log.RPT" +#else +#define CRASH_LOGFILE_NAME "(unknown crash log)" +#endif + /* A mod name to further distinguish versions. */ #define SRB2APPLICATION "SRB2Kart" diff --git a/src/i_system.h b/src/i_system.h index bef997acf..024d491c7 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -239,6 +239,10 @@ const char *I_ClipboardPaste(void); void I_RegisterSysCommands(void); +/** \brief Returns the system name. + */ +const char *I_GetSysName(void); + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index 9c14f7ed6..6955d0b4c 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -40,13 +40,8 @@ #include "i_ttf.h" #endif -#if defined (_WIN32) && !defined (main) -//#define SDLMAIN -#endif - #ifdef HAVE_LIBBACKTRACE #include - struct backtrace_state *bt_state = NULL; #endif @@ -71,13 +66,6 @@ char logfilename[1024]; #endif #endif -#ifdef _WIN32 -#ifndef _AMD64_ -#include "exchndl.h" -#define DRMINGW -#endif -#endif - #if defined (_WIN32) #include "../win32/win_dbg.h" typedef BOOL (WINAPI *p_IsDebuggerPresent)(VOID); @@ -236,12 +224,9 @@ int main(int argc, char **argv) //I_OutputMsg("I_StartupSystem() ...\n"); I_StartupSystem(); -#if defined (_WIN32) - { -#ifdef DRMINGW - ExcHndlInit(); -#endif - } + +#ifdef HAVE_DRMINGW + InitDrMingw(); #endif // startup SRB2 diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index b2f4143e1..7987ea543 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -213,346 +213,9 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif -#ifdef HAVE_THREADS -#include "../core/thread_pool.h" -static std::thread::id g_main_thread_id; -#endif - -INT32 numcontrollers = 0; - -#ifdef HAVE_LIBBACKTRACE -#include -// TODO - move this to some header file instead -extern struct backtrace_state *bt_state; - -typedef enum { - BTCRASH_SIGNAL, - BTCRASH_ERRORMSG, -} bt_crash_type_t; - -typedef struct bt_crash_reason_s { - bt_crash_type_t type; - - union { - INT32 signal; - const char *errormsg; - } value; -} bt_crash_reason_t; - -#define BT_CRASH_REASON_SIGNAL(num) (bt_crash_reason_t){ .type = BTCRASH_SIGNAL, .value = { .signal = num } } -#define BT_CRASH_REASON_ERRORMSG(msg) (bt_crash_reason_t){ .type = BTCRASH_ERRORMSG, .value = { .errormsg = msg } } - -static void printsignal(FILE *fp, INT32 num) -{ - switch (num) - { - case SIGILL: - fprintf(fp, "SIGILL - illegal instruction - invalid function image"); - break; - case SIGFPE: - fprintf(fp, "SIGFPE - mathematical exception"); - break; - case SIGSEGV: - fprintf(fp, "SIGSEGV - segment violation"); - break; - case SIGABRT: - fprintf(fp, "SIGABRT - abnormal termination triggered by abort call"); - break; - default: - fprintf(fp, "Signal number %d", num); - } -} - -typedef struct bt_out_buf_s { - boolean error; - char *pos; - size_t size; -} bt_out_buf_t; - -static void bt_syminfo_cb(void *data, uintptr_t pc, const char *symname, uintptr_t symval, uintptr_t symsize) -{ - (void)symval; - (void)symsize; - - bt_out_buf_t *buf = (bt_out_buf_t*)data; - - if (!symname) - symname = "???"; - - int n = snprintf(buf->pos, buf->size, "%p %s\n", (void*)pc, symname); - - if (n <= 0) - { - buf->size = 0; - return; - } - - buf->pos += n; - buf->size -= n; -} - -static int bt_simple_cb(void *data, uintptr_t pc) -{ - bt_out_buf_t *buf = (bt_out_buf_t*)data; - - backtrace_syminfo(bt_state, pc, bt_syminfo_cb, NULL, data); - - if (!buf->size) return 1; - - return 0; -} - -static int bt_full_cb(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) -{ - bt_out_buf_t *buf = (bt_out_buf_t*)data; - - if (!filename) filename = "???"; - if (!function) function = "???"; - - int n = snprintf(buf->pos, buf->size, "%p %s\n\t%s:%d\n", (void*)pc, function, filename, lineno); - - if (n <= 0) return 1; - - buf->pos += n; - buf->size -= n; - - if (!buf->size) return 1; - - return 0; -} - -static void bt_error_cb(void *data, const char *msg, int errnum) -{ - (void)msg; // We don't need this - - bt_out_buf_t *buf = (bt_out_buf_t*)data; - - // No debug info - if (errnum == -1) - buf->error = true; -} - -static void write_backtrace(bt_crash_reason_t reason) -{ - FILE *out = fopen(va("%s" PATHSEP "%s", srb2home, "srb2kart-crash-log.txt"), "a"); - - time_t rawtime; - struct tm *timeinfo; - - const size_t BUFSIZE = 8192; - char backtrace[BUFSIZE]; - - bt_out_buf_t buf; - buf.error = false; - buf.pos = backtrace; - buf.size = BUFSIZE; - - if (!out) - { - fprintf(stderr, "\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n"); - out = stderr; - } - - // Get the current time as a string. - time(&rawtime); - timeinfo = localtime(&rawtime); - - fprintf(out, "------------------------\n\n"); - - fprintf(out, "Program name: %s %s\n", SRB2APPLICATION, VERSIONSTRING); - - if (compdate && comptime && comprevision && compbranch) - fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); - - if (gamestate == GS_LEVEL) - { - char *title = G_BuildMapTitle(gamemap); - - if (title) - { - fprintf(out, "Game map: %s (%s)\n", title, G_BuildMapName(gamemap)); - Z_Free(title); - } - else - fprintf(out, "Game map: %s\n", G_BuildMapName(gamemap)); - } - - fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); - - fprintf(out, "Caused by: "); - - switch (reason.type) - { - case BTCRASH_SIGNAL: - printsignal(out, reason.value.signal); - break; - - case BTCRASH_ERRORMSG: - fprintf(out, "%s", reason.value.errormsg); - break; - } - - fprintf(out, "\nBacktrace:\n"); - - // Try to get full backtrace, it will print files and line numbers - backtrace_full(bt_state, 2, bt_full_cb, bt_error_cb, (void*)&buf); - - if (buf.error) - { - // Fall back to simple backtrace, only prints function names - backtrace_simple(bt_state, 2, bt_simple_cb, NULL, (void*)&buf); - } - - fputs(backtrace, out); - - if (out != stderr) - { - fclose(out); - fprintf(stderr, "Crash report created, find srb2kart-crash-log.txt in your SRB2Kart directory\n"); - } -} - -#endif - -/** \brief The JoyReset function - - \param JoySet Joystick info to reset - - \return void -*/ -static void JoyReset(SDLJoyInfo_t *JoySet) -{ - if (JoySet->dev) - { - SDL_GameControllerClose(JoySet->dev); - } - JoySet->dev = NULL; - JoySet->oldjoy = -1; - JoySet->axises = JoySet->buttons = JoySet->hats = JoySet->balls = 0; - //JoySet->scale -} - -/** \brief joystick up and running -*/ -static INT32 joystick_started[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; - -/** \brief SDL info about joystick -*/ -SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS]; - SDL_bool consolevent = SDL_FALSE; SDL_bool framebuffer = SDL_FALSE; - UINT8 keyboard_started = false; -boolean g_in_exiting_signal_handler = false; - -static void I_ReportSignal(int num, int coredumped) -{ - //static char msg[] = "oh no! back to reality!\r\n"; - const char * sigmsg; - char msg[256]; - - switch (num) - { -// case SIGINT: -// sigmsg = "SIGINT - interrupted"; -// break; - case SIGILL: - sigmsg = "SIGILL - illegal instruction - invalid function image"; - break; - case SIGFPE: - sigmsg = "SIGFPE - mathematical exception"; - break; - case SIGSEGV: - sigmsg = "SIGSEGV - segment violation"; - break; -// case SIGTERM: -// sigmsg = "SIGTERM - Software termination signal from kill"; -// break; -// case SIGBREAK: -// sigmsg = "SIGBREAK - Ctrl-Break sequence"; -// break; - case SIGABRT: - sigmsg = "SIGABRT - abnormal termination triggered by abort call"; - break; - default: - sprintf(msg,"signal number %d", num); - if (coredumped) - sigmsg = 0; - else - sigmsg = msg; - } - - if (coredumped) - { - if (sigmsg) - sprintf(msg, "%s (core dumped)", sigmsg); - else - strcat(msg, " (core dumped)"); - } - else - { - sprintf(msg, "%s", sigmsg); - } - -#ifdef HAVE_LIBBACKTRACE - strncat(msg, "\n\nCrash report has been saved into srb2kart-crash-log.txt", 255); -#elif defined(_WIN32) && !defined(__MINGW64__) - strncat(msg, "\n\nCrash report has been saved into srb2kart.rpt", 255); -#endif - - I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); - - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Process killed by signal", - msg, NULL); -} - -#ifndef NEWSIGNALHANDLER -FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) -{ - g_in_exiting_signal_handler = true; - -#ifdef HAVE_THREADS - if (g_main_thread_id != std::this_thread::get_id()) - { - // Do not attempt any sort of recovery if this signal triggers off the main thread - signal(num, SIG_DFL); - raise(num); - exit(-2); - } -#endif - - D_QuitNetGame(); // Fix server freezes - -#ifdef HAVE_LIBBACKTRACE - write_backtrace(BT_CRASH_REASON_SIGNAL(num)); -#endif - - I_ReportSignal(num, 0); - I_ShutdownSystem(); - signal(num, SIG_DFL); //default signal action - raise(num); - I_Quit(); -} -#endif - -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) -{ -#ifdef HAVE_THREADS - if (g_main_thread_id != std::this_thread::get_id()) - { - // Do not attempt any sort of recovery if this signal triggers off the main thread - signal(num, SIG_DFL); - raise(num); - exit(-2); - } -#endif - - signal(num, SIG_DFL); //default signal action - raise(num); - I_Quit(); -} #ifdef HAVE_TERMIOS // TERMIOS console code from Quake3: thank you! @@ -582,16 +245,6 @@ static struct termios tty_tc; // so we provide tty_Clear and tty_Show to be called before and after a stdout or stderr output // ============================================================= -// flush stdin, I suspect some terminals are sending a LOT of garbage -// FIXME TTimo relevant? -#if 0 -static inline void tty_FlushIn(void) -{ - char key; - while (read(STDIN_FILENO, &key, 1)!=-1); -} -#endif - // do a backspace // TTimo NOTE: it seems on some terminals just sending '\b' is not enough // so for now, in any case we send "\b \b" .. yeah well .. @@ -787,6 +440,7 @@ static void Impl_HandleKeyboardConsoleEvent(KEY_EVENT_RECORD evt, HANDLE co) //event.data1 = MapVirtualKey(evt.wVirtualKeyCode,2); // convert in to char event.data1 = evt.uChar.AsciiChar; } + if (co != INVALID_HANDLE_VALUE && GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &t)) { if (event.data1 && event.data1 != KEY_LSHIFT && event.data1 != KEY_RSHIFT) @@ -804,6 +458,7 @@ static void Impl_HandleKeyboardConsoleEvent(KEY_EVENT_RECORD evt, HANDLE co) } } } + if (event.data1) D_PostEvent(&event); } @@ -888,56 +543,6 @@ static inline void I_StartupConsole(void) static inline void I_ShutdownConsole(void){} #endif -// -// StartupKeyboard -// -static void I_RegisterSignals (void) -{ -#ifdef HAVE_THREADS - g_main_thread_id = std::this_thread::get_id(); -#endif - -#ifdef SIGINT - signal(SIGINT , quit_handler); -#endif -#ifdef SIGBREAK - signal(SIGBREAK , quit_handler); -#endif -#ifdef SIGTERM - signal(SIGTERM , quit_handler); -#endif - - // If these defines don't exist, - // then compilation would have failed above us... -#ifndef NEWSIGNALHANDLER - signal(SIGILL , signal_handler); - signal(SIGSEGV , signal_handler); - signal(SIGABRT , signal_handler); - signal(SIGFPE , signal_handler); -#endif -} - -#ifdef NEWSIGNALHANDLER -static void signal_handler_child(INT32 num) -{ -#ifdef HAVE_LIBBACKTRACE - write_backtrace(BT_CRASH_REASON_SIGNAL(num)); -#endif - - signal(num, SIG_DFL); //default signal action - raise(num); -} - -static void I_RegisterChildSignals(void) -{ - // If these defines don't exist, - // then compilation would have failed above us... - signal(SIGILL , signal_handler_child); - signal(SIGSEGV , signal_handler_child); - signal(SIGABRT , signal_handler_child); - signal(SIGFPE , signal_handler_child); -} -#endif // //I_OutputMsg @@ -1095,6 +700,33 @@ INT32 I_GetKey (void) return rc; } +/** \brief The JoyReset function + + \param JoySet Joystick info to reset + + \return void +*/ +static void JoyReset(SDLJoyInfo_t *JoySet) +{ + if (JoySet->dev) + { + SDL_GameControllerClose(JoySet->dev); + } + JoySet->dev = NULL; + JoySet->oldjoy = -1; + JoySet->axises = JoySet->buttons = JoySet->hats = JoySet->balls = 0; + //JoySet->scale +} + +/** \brief joystick up and running +*/ +static INT32 joystick_started[MAXSPLITSCREENPLAYERS] = {0, 0, 0, 0}; + +/** \brief SDL info about joystick +*/ +SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS]; +INT32 numcontrollers = 0; + // // I_JoyScale // @@ -1821,6 +1453,350 @@ void I_SleepDuration(precise_t duration) #endif } +#ifdef HAVE_THREADS +#include "../core/thread_pool.h" +static std::thread::id g_main_thread_id; +#endif + +boolean g_in_exiting_signal_handler = false; + +static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg) +{ + const char *sigmsg; + + switch (signal_num) + { +#ifdef SIGINT + case SIGINT: + sigmsg = ("SIGINT - SRB2Kart-Saturn was interrupted prematurely by the user."); + break; +#endif + case SIGILL: // illegal instruction - invalid function image + sigmsg = ("SIGILL - SRB2Kart-Saturn has attempted to execute an illegal instruction and needs to close."); + break; + case SIGFPE: // mathematical exception + sigmsg = ("SIGFPE - SRB2Kart-Saturn has encountered a mathematical exception and needs to close."); + break; + case SIGSEGV: // segment violation + sigmsg = ("SIGSEGV - SRB2Kart-Saturn has attempted to access a memory location that it shouldn't and needs to close."); + break; +#ifdef SIGTERM + case SIGTERM: // Software termination signal from kill + sigmsg = ("SIGTERM - SRB2Kart-Saturn was terminated by a kill signal."); + break; +#endif +#ifdef SIGBREAK + case SIGBREAK: // Ctrl-Break sequence + sigmsg =("SIGBREAK - SRB2Kart-Saturn was terminated by a Ctrl-Break sequence.") + break; +#endif + case SIGABRT: // abnormal termination triggered by abort call + sigmsg = ("SIGABRT - SRB2Kart-Saturn was terminated by an abort signal."); + break; + default: + sprintf(signal_msg, "Signal number %d", signal_num); + sigmsg = (core_dumped ? "Unknown signal" : signal_msg); + break; + } + + if (core_dumped) + { + if (sigmsg) + sprintf(signal_msg, "%s (core dumped)", sigmsg); + else + strcat(signal_msg, " (core dumped)"); + } + else + { + sprintf(signal_msg, "%s", sigmsg); + } +} + +static void I_ReportSignal(int num, int coredumped) +{ + char sigmsg[512]; + + I_PrintSignal(num, coredumped, sigmsg); + + 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); +} + +#ifndef NEWSIGNALHANDLER +FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) +{ + g_in_exiting_signal_handler = true; + +#ifdef HAVE_THREADS + if (g_main_thread_id != std::this_thread::get_id()) + { + // Do not attempt any sort of recovery if this signal triggers off the main thread + signal(num, SIG_DFL); + raise(num); + exit(-2); + } +#endif + + D_QuitNetGame(); // Fix server freezes + +#ifdef HAVE_LIBBACKTRACE + write_backtrace(BT_CRASH_REASON_SIGNAL(num)); +#endif + + I_ReportSignal(num, 0); + I_ShutdownSystem(); + signal(num, SIG_DFL); //default signal action + raise(num); + I_Quit(); +} +#endif + +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) +{ +#ifdef HAVE_THREADS + if (g_main_thread_id != std::this_thread::get_id()) + { + // Do not attempt any sort of recovery if this signal triggers off the main thread + signal(num, SIG_DFL); + raise(num); + exit(-2); + } +#endif + + signal(num, SIG_DFL); //default signal action + raise(num); + I_Quit(); +} + +#ifdef HAVE_LIBBACKTRACE +#include +// TODO - move this to some header file instead +extern struct backtrace_state *bt_state; + +typedef enum { + BTCRASH_SIGNAL, + BTCRASH_ERRORMSG, +} bt_crash_type_t; + +typedef struct bt_crash_reason_s { + bt_crash_type_t type; + + union { + INT32 signal; + const char *errormsg; + } value; +} bt_crash_reason_t; + +#define BT_CRASH_REASON_SIGNAL(num) (bt_crash_reason_t){ .type = BTCRASH_SIGNAL, .value = { .signal = num } } +#define BT_CRASH_REASON_ERRORMSG(msg) (bt_crash_reason_t){ .type = BTCRASH_ERRORMSG, .value = { .errormsg = msg } } + +typedef struct bt_out_buf_s { + boolean error; + char *pos; + size_t size; +} bt_out_buf_t; + +static void bt_syminfo_cb(void *data, uintptr_t pc, const char *symname, uintptr_t symval, uintptr_t symsize) +{ + (void)symval; + (void)symsize; + + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + if (!symname) + symname = "???"; + + int n = snprintf(buf->pos, buf->size, "%p %s\n", (void*)pc, symname); + + if (n <= 0) + { + buf->size = 0; + return; + } + + buf->pos += n; + buf->size -= n; +} + +static int bt_simple_cb(void *data, uintptr_t pc) +{ + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + backtrace_syminfo(bt_state, pc, bt_syminfo_cb, NULL, data); + + if (!buf->size) return 1; + + return 0; +} + +static int bt_full_cb(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) +{ + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + if (!filename) filename = "???"; + if (!function) function = "???"; + + int n = snprintf(buf->pos, buf->size, "%p %s\n\t%s:%d\n", (void*)pc, function, filename, lineno); + + if (n <= 0) return 1; + + buf->pos += n; + buf->size -= n; + + if (!buf->size) return 1; + + return 0; +} + +static void bt_error_cb(void *data, const char *msg, int errnum) +{ + (void)msg; // We don't need this + + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + // No debug info + if (errnum == -1) + buf->error = true; +} + +static void write_backtrace(bt_crash_reason_t reason) +{ + char sig_msg[512]; + const char *filename = va("%s" PATHSEP CRASH_LOGFILE_NAME, srb2home); + FILE *out = fopen(filename, "a+"); + + time_t rawtime; + struct tm *timeinfo; + + const size_t BUFSIZE = 8192; + char backtrace[BUFSIZE]; + + bt_out_buf_t buf; + buf.error = false; + buf.pos = backtrace; + buf.size = BUFSIZE; + + if (!out) + { + fprintf(stderr, "\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n"); + out = stderr; + } + + // Get the current time as a string. + time(&rawtime); + timeinfo = localtime(&rawtime); + + fprintf(out, "------------------------\n\n"); + + fprintf(out, "Program name: %s %s\n", SRB2APPLICATION, VERSIONSTRING); + + fprintf(out, "Platform: %s\n", I_GetSysName()); + + if (compdate && comptime && comprevision && compbranch) + fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); + + if (gamestate == GS_LEVEL && gamemap) + { + char *map_title = G_BuildMapTitle(gamemap); + const char *map_name = G_BuildMapName(gamemap); + + if (map_title && map_name) + { + fprintf(out, "Game map: %s (%s)\n", map_title, map_name); + Z_Free(map_title); + } + else if (map_name) + { + fprintf(out, "Game map: %s\n", map_name); + } + } + + fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); + + fprintf(out, "Caused by: "); + + switch (reason.type) + { + case BTCRASH_SIGNAL: + I_PrintSignal(reason.value.signal, false, sig_msg); + fprintf(out, "%s", sig_msg); + break; + + case BTCRASH_ERRORMSG: + fprintf(out, "%s", reason.value.errormsg); + break; + } + + fprintf(out, "\nBacktrace:\n"); + + // Try to get full backtrace, it will print files and line numbers + backtrace_full(bt_state, 2, bt_full_cb, bt_error_cb, (void*)&buf); + + if (buf.error) + { + // Fall back to simple backtrace, only prints function names + backtrace_simple(bt_state, 2, bt_simple_cb, NULL, (void*)&buf); + } + + fputs(backtrace, out); + + if (out != stderr) + { + fclose(out); + fprintf(stderr, "Crash report created, find %s in your SRB2Kart directory\n", CRASH_LOGFILE_NAME); + } +} +#endif + +static void I_RegisterSignals(void) +{ +#ifdef HAVE_THREADS + g_main_thread_id = std::this_thread::get_id(); +#endif + +#ifdef SIGINT + signal(SIGINT, quit_handler); +#endif +#ifdef SIGBREAK + signal(SIGBREAK, quit_handler); +#endif +#ifdef SIGTERM + signal(SIGTERM, quit_handler); +#endif +#ifndef NEWSIGNALHANDLER + // If these defines don't exist, + // then compilation would have failed above us... + signal(SIGILL, signal_handler); + signal(SIGSEGV, signal_handler); + signal(SIGABRT, signal_handler); + signal(SIGFPE, signal_handler); +#endif +} + +#ifdef NEWSIGNALHANDLER +static void signal_handler_child(INT32 num) +{ + g_in_exiting_signal_handler = true; +#ifdef HAVE_LIBBACKTRACE + write_backtrace(BT_CRASH_REASON_SIGNAL(num)); +#endif + signal(num, SIG_DFL); // default signal action + raise(num); +} + +static void I_RegisterChildSignals(void) +{ + // If these defines don't exist, + // then compilation would have failed above us... + signal(SIGILL, signal_handler_child); + signal(SIGSEGV, signal_handler_child); + signal(SIGABRT, signal_handler_child); + signal(SIGFPE, signal_handler_child); +} +#endif + #ifdef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void newsignalhandler_Warn(const char *pr) { @@ -2698,6 +2674,11 @@ size_t I_GetFreeMem(size_t *total) #endif } +const char *I_GetSysName(void) +{ + return SDL_GetPlatform(); +} + // note CPUAFFINITY code used to reside here void I_RegisterSysCommands(void) {} #endif diff --git a/src/win32/win_dbg.c b/src/win32/win_dbg.c index 6edf260b3..5576b1dc5 100644 --- a/src/win32/win_dbg.c +++ b/src/win32/win_dbg.c @@ -21,14 +21,31 @@ #include +#ifdef HAVE_DRMINGW +#include "exchndl.h" +#endif + #include "../doomdef.h" //just for VERSION #include "win_dbg.h" #include "../m_argv.h" //print the parameter in the log LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter = NULL; -#ifdef BUGTRAP +// -------------------------------------------------------------------------- +// Initialises the DrMingw exception-handling library. Returns true if +// successful. +// -------------------------------------------------------------------------- +#ifdef HAVE_DRMINGW +BOOL InitDrMingw(void) +{ + CONS_Printf("Setting up DrMingw debugger...\n"); + ExcHndlInit(); + ExcHndlSetLogFileNameA(CRASH_LOGFILE_NAME); + return TRUE; +} +#endif +#ifdef BUGTRAP typedef void (APIENTRY *BT_SETSUPPORTURL)(LPCTSTR pszSupportURL); typedef void (APIENTRY *BT_SETFLAGS)(DWORD dwFlags); diff --git a/src/win32/win_dbg.h b/src/win32/win_dbg.h index 8f1692ea6..1c696ae5c 100644 --- a/src/win32/win_dbg.h +++ b/src/win32/win_dbg.h @@ -20,12 +20,14 @@ #define RPC_NO_WINDOWS_H #include -#ifdef BUGTRAP +#ifdef HAVE_DRMINGW +BOOL InitDrMingw(void); +#endif +#ifdef BUGTRAP BOOL InitBugTrap(void); void ShutdownBugTrap(void); BOOL IsBugTrapLoaded(void); - #endif // called in the exception filter of the __try block, writes all useful debugging information From 7400eeac2a26f71ebb61ad9c7463e0ad9ee1892e Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Sep 2025 17:26:03 +0200 Subject: [PATCH 29/39] fix dedicated build compile --- src/dedicated/i_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dedicated/i_video.c b/src/dedicated/i_video.c index c67d8cefd..51bc2c45a 100644 --- a/src/dedicated/i_video.c +++ b/src/dedicated/i_video.c @@ -145,8 +145,9 @@ UINT32 I_GetRefreshRate(void) return 0; } -void I_SetTextInput(void) +void I_SetTextInput(boolean enable) { + (void)enable; } boolean I_UseNativeKeyboard(void) From e6af82f450ddfe50ad561fa7a65f3cc903b089ad Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Sep 2025 19:12:56 +0200 Subject: [PATCH 30/39] delet JOININGAME --- src/d_clisrv.c | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 237d7c130..4723ae415 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1104,10 +1104,6 @@ static void SV_AcknowledgeResynchAck(INT32 node, UINT8 rsg) static INT16 Consistancy(void); -#ifndef NONET -#define JOININGAME -#endif - typedef enum { CL_SEARCHING, @@ -1117,9 +1113,7 @@ typedef enum CL_LOADFILES, CL_SETUPFILES, CL_WAITJOINRESPONSE, -#ifdef JOININGAME CL_DOWNLOADSAVEGAME, -#endif CL_CONNECTED, CL_ABORTED, CL_VIEWSERVER, @@ -1210,7 +1204,6 @@ static inline void CL_DrawConnectionStatus(void) switch (cl_mode) { -#ifdef JOININGAME case CL_DOWNLOADSAVEGAME: if (filedownload.current != -1) { @@ -1236,7 +1229,6 @@ static inline void CL_DrawConnectionStatus(void) else cltext = M_GetText("Waiting to download game state..."); break; -#endif case CL_ASKFULLFILELIST: case CL_CONFIRMCONNECT: case CL_LEGACYREQUESTFAILED: @@ -1877,7 +1869,6 @@ static boolean SV_SendServerConfig(INT32 node) return waspacketsent; } -#ifdef JOININGAME #define SAVEGAMESIZE (768*1024) #ifdef SATURNPAK @@ -2111,7 +2102,6 @@ static void CL_ReloadReceivedSavegame(void) CONS_Printf(M_GetText("Game state reloaded\n")); } #endif -#endif #ifndef NONET static void SendAskInfo(INT32 node) @@ -2715,12 +2705,12 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic ), NULL, MM_NOTHING); return false; } -#ifdef JOININGAME + // prepare structures to save the file // WARNING: this can be useless in case of server not in GS_LEVEL // but since the network layer doesn't provide ordered packets... CL_PrepareDownloadSaveGame(tmpsave); -#endif + if (I_GetTime() >= *asksent && CL_SendJoin()) { *asksent = I_GetTime() + NEWTICRATE*3; @@ -2733,7 +2723,6 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic cl_mode = CL_ASKJOIN; } break; -#ifdef JOININGAME case CL_DOWNLOADSAVEGAME: // At this state, the first (and only) needed file is the gamestate if (fileneeded[0].status == FS_FOUND) @@ -2745,7 +2734,6 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic } // don't break case continue to CL_CONNECTED else break; -#endif case CL_CONNECTED: case CL_CONFIRMCONNECT: //logic is handled by M_ConfirmConnect default: @@ -2851,11 +2839,9 @@ static void CL_ConnectToServer(void) #ifndef NONET tic_t asksent; #endif -#ifdef JOININGAME char tmpsave[264]; sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); -#endif #ifdef CLIENT_LOADINGSCREEN filedownload.current = -1; @@ -2863,11 +2849,9 @@ static void CL_ConnectToServer(void) cl_mode = CL_SEARCHING; -#ifdef JOININGAME // Don't get a corrupt savegame error because tmpsave already exists if (FIL_FileExists(tmpsave) && unlink(tmpsave) == -1) I_Error("Can't delete %s\n", tmpsave); -#endif if (netgame) { @@ -4924,7 +4908,6 @@ static void HandleConnect(SINT8 node) DEBFILE("new node joined\n"); } -#ifdef JOININGAME if (nodewaiting[node]) { if (node && newnode) @@ -4935,12 +4918,6 @@ static void HandleConnect(SINT8 node) SV_AddWaitingPlayers(); } -#else -#ifndef NONET - // I guess we have no use for this if we aren't doing mid-level joins? - (void)newnode; -#endif -#endif } } @@ -5281,11 +5258,8 @@ static void PT_ServerCFG(SINT8 node) playernode[(UINT8)serverplayer] = servernode; if (netgame) -#ifdef JOININGAME CONS_Printf(M_GetText("Join accepted, waiting for complete game state...\n")); -#else - CONS_Printf(M_GetText("Join accepted, waiting for next level change...\n")); -#endif + DEBFILE(va("Server accept join gametic=%u mynode=%d\n", gametic, mynode)); #ifdef SATURNPAK @@ -5308,16 +5282,13 @@ static void PT_ServerCFG(SINT8 node) scp = netbuffer->u.servercfg.varlengthinputs; CV_LoadPlayerNames(&scp); CV_LoadNetVars(&scp); -#ifdef JOININGAME + /// \note Wait. What if a Lua script uses some global custom variables synched with the NetVars hook? /// Shouldn't them be downloaded even at intermission time? /// Also, according to HandleConnect, the server will send the savegame even during intermission... /// Sryder 2018-07-05: If we don't want to send the player config another way we need to send the gamestate /// At almost any gamestate there could be joiners... So just always send gamestate? cl_mode = ((server) ? CL_CONNECTED : CL_DOWNLOADSAVEGAME); -#else - cl_mode = CL_CONNECTED; -#endif } static void PT_FileFragmentFromAwayNode(SINT8 node) From 9cb150b8eb748cb7480688da5d9b86038d8709eb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Sep 2025 19:32:08 +0200 Subject: [PATCH 31/39] delet NONET --- src/Makefile.d/features.mk | 2 - src/Makefile.d/haiku.mk | 2 - src/d_clisrv.c | 61 +++----------------- src/d_clisrv.h | 8 --- src/d_net.c | 51 +---------------- src/d_net.h | 2 - src/d_netcmd.c | 4 -- src/d_netfil.c | 8 +-- src/dedicated/i_system.c | 7 +-- src/doomdef.h | 8 +-- src/g_game.h | 2 - src/hu_stuff.c | 28 ---------- src/i_tcp.c | 112 ++++++------------------------------- src/m_menu.c | 38 +------------ src/m_menudefs.c | 35 +----------- src/mserv.c | 22 +------- src/sdl/i_system.cpp | 8 +-- 17 files changed, 41 insertions(+), 357 deletions(-) diff --git a/src/Makefile.d/features.mk b/src/Makefile.d/features.mk index ab02efc4b..fc1e8b69f 100644 --- a/src/Makefile.d/features.mk +++ b/src/Makefile.d/features.mk @@ -30,14 +30,12 @@ ifndef NOMD5 sources+=md5.c endif -ifndef NONET ifndef NOSATURNJOIN opts+=-DDOSATURNJOIN endif ifndef NOSATURNPAK opts+=-DDOSATURNPAK endif -endif ifndef NOZLIB ifndef NOPNG diff --git a/src/Makefile.d/haiku.mk b/src/Makefile.d/haiku.mk index 6742ec75b..d702a0623 100644 --- a/src/Makefile.d/haiku.mk +++ b/src/Makefile.d/haiku.mk @@ -19,9 +19,7 @@ else ifeq (${DEDICATED},1) EXENAME?=srb2haikud endif -ifndef NONET libs+=-lnetwork -endif define _set = $(1)_CFLAGS?=$($(1)_opts) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 4723ae415..8f657e342 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2103,7 +2103,6 @@ static void CL_ReloadReceivedSavegame(void) } #endif -#ifndef NONET static void SendAskInfo(INT32 node) { tic_t asktime; @@ -2277,7 +2276,6 @@ void CL_TimeoutServerList(void) } } } -#endif // ifndef NONET static void CL_ConfirmConnect(void) { @@ -2308,7 +2306,6 @@ static void CL_ConfirmConnect(void) static void M_ConfirmConnect(event_t *ev) { -#ifndef NONET if (ev->type == ev_keydown) { if (ev->data1 == ' ' || ev->data1 == 'y' || ev->data1 == KEY_ENTER || ev->data1 == gamecontrol[0][gc_accelerate][0] || ev->data1 == gamecontrol[0][gc_accelerate][1]) @@ -2323,9 +2320,6 @@ static void M_ConfirmConnect(event_t *ev) M_ClearMenus(true); } } -#else - (void)ev; -#endif } void CL_AbortConnection(void) @@ -2420,29 +2414,25 @@ static boolean CL_FinishedFileList(void) if (!filedownload.http_failed) #endif { -#ifndef NONET filedownload.completednum = 0; filedownload.completedsize = 0; filedownload.totalnum = 0; filedownload.totalsize = 0; -#endif for (i = 0; i < fileneedednum; i++) + { if (fileneeded[i].status == FS_NOTFOUND || fileneeded[i].status == FS_MD5SUMBAD) { -#ifndef NONET filedownload.totalnum++; filedownload.totalsize += fileneeded[i].totalsize; -#endif } + } -#ifndef NONET if (filedownload.totalsize>>20 >= 10) downloadsize = Z_StrDup(va("%uM",filedownload.totalsize>>20)); else downloadsize = Z_StrDup(va("%uK",filedownload.totalsize>>10)); -#endif if (cv_showdownloadprompt.value) { @@ -2496,7 +2486,6 @@ static boolean CL_FinishedFileList(void) */ static boolean CL_ServerConnectionSearchTicker(tic_t *asksent) { -#ifndef NONET INT32 i; // serverlist is updated by GetPacket function @@ -2515,6 +2504,7 @@ static boolean CL_ServerConnectionSearchTicker(tic_t *asksent) if (i < 0) return true; } + joinnode = i; // Quit here rather than downloading files and being refused later. @@ -2535,6 +2525,7 @@ static boolean CL_ServerConnectionSearchTicker(tic_t *asksent) CONS_Printf("We received a http url from the server, however it will not be used as this build lacks curl support (%s)\n", serverlist[i].info.httpsource); #endif D_ParseFileneeded(serverlist[i].info.fileneedednum, serverlist[i].info.fileneeded, 0); + if (serverlist[i].info.kartvars & SV_LOTSOFADDONS) { cl_mode = CL_ASKFULLFILELIST; @@ -2559,11 +2550,6 @@ static boolean CL_ServerConnectionSearchTicker(tic_t *asksent) SendAskInfo(servernode); *asksent = I_GetTime() + NEWTICRATE; } -#else - (void)asksent; - // No netgames, so we skip this state. - cl_mode = CL_ASKJOIN; -#endif // ifndef NONET/else return true; } @@ -2583,10 +2569,6 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic boolean waitmore; INT32 i; -#ifdef NONET - (void)tmpsave; -#endif - switch (cl_mode) { case CL_SEARCHING: @@ -2836,9 +2818,7 @@ static void CL_ConnectToServer(void) { INT32 pnumnodes, nodewaited = doomcom->numnodes, i; tic_t oldtic; -#ifndef NONET tic_t asksent; -#endif char tmpsave[264]; sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); @@ -2873,7 +2853,6 @@ static void CL_ConnectToServer(void) ClearAdminPlayers(); pnumnodes = 1; oldtic = 0; -#ifndef NONET asksent = 0; firstconnectattempttime = I_GetTime(); @@ -2906,16 +2885,11 @@ static void CL_ConnectToServer(void) map_icon_read = 0; map_icon_missing = 0xffffffff; map_icon_last_request = I_GetTime(); -#endif do { // If the connection was aborted for some reason, leave -#ifndef NONET if (!CL_ServerConnectionTicker(tmpsave, &oldtic, &asksent)) -#else - if (!CL_ServerConnectionTicker((char*)NULL, &oldtic, (tic_t *)NULL)) -#endif { if (P_PartialAddGetStage() >= 0) P_MultiSetupWadFiles(true); // in case any partial adds were done @@ -2932,16 +2906,14 @@ static void CL_ConnectToServer(void) } while (!(cl_mode == CL_CONNECTED && (client || (server && nodewaited <= pnumnodes)))); -#ifndef NONET if (netgame) F_StartWaitingPlayers(); -#endif + DEBFILE(va("Synchronisation Finished\n")); displayplayers[0] = consoleplayer; } -#ifndef NONET static void Command_ShowBan(void) //Print out ban list { size_t i; @@ -3327,8 +3299,6 @@ static void Command_Packetstat(void) } } -#endif - static void ResetNode(INT32 node); // @@ -3460,10 +3430,8 @@ void CL_Reset(void) memset(fileneeded, 0, sizeof(fileneeded)); memset(packetstat, 0, sizeof(packetstat)); -#ifndef NONET filedownload.totalnum = 0; filedownload.totalsize = 0; -#endif firstconnectattempttime = 0; serverisfull = false; connectiontimeout = (tic_t)cv_nettimeout.value; //reset this temporary hack @@ -3481,7 +3449,6 @@ void CL_Reset(void) // D_StartTitle should get done now, but the calling function will handle it } -#ifndef NONET static void Command_GetPlayerNum(void) { INT32 i; @@ -3808,7 +3775,6 @@ static void Command_Kick(void) else CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); } -#endif static void Got_KickCmd(UINT8 **p, INT32 playernum) { @@ -4236,7 +4202,6 @@ void D_ClientServerInit(void) DEBFILE(va("- - -== SRB2Kart v%d.%d "VERSIONSTRING" debugfile ==- - -\n", VERSION, SUBVERSION)); -#ifndef NONET COM_AddCommand("getplayernum", Command_GetPlayerNum); COM_AddCommand("kick", Command_Kick); COM_AddCommand("ban", Command_Ban); @@ -4262,17 +4227,13 @@ void D_ClientServerInit(void) #ifdef _DEBUG COM_AddCommand("numnodes", Command_Numnodes); #endif -#endif - RegisterNetXCmd(XD_KICK, Got_KickCmd); RegisterNetXCmd(XD_ADDPLAYER, Got_AddPlayer); RegisterNetXCmd(XD_REMOVEPLAYER, Got_RemovePlayer); -#ifndef NONET #ifdef DUMPCONSISTENCY CV_RegisterVar(&cv_dumpconsistency); #endif D_LoadBan(false); -#endif gametic = 0; localgametic = 0; @@ -4867,18 +4828,17 @@ static void HandleConnect(SINT8 node) } else { -#ifndef NONET boolean newnode = false; -#endif + // client authorised to join nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]); if (!nodeingame[node]) { gamestate_t backupstate = gamestate; -#ifndef NONET + newnode = true; -#endif + SV_AddNode(node); /// \note Wait what??? @@ -4949,7 +4909,6 @@ static void HandleTimeout(SINT8 node) M_StartMessage(M_GetText("Server Timeout\n\nPress Esc\n"), NULL, MM_NOTHING); } -#ifndef NONET /** Called when a PT_SERVERINFO packet is received * * \param node The packet sender @@ -5316,8 +5275,6 @@ static void PT_RequestFile(SINT8 node) Net_CloseConnection(node); // nope } -#endif - #ifdef SATURNPAK static void PT_WillResendGamestate(void) { @@ -6046,13 +6003,11 @@ static void GetPackets(void) } } -#ifndef NONET if (netbuffer->packettype == PT_SERVERINFO) { HandleServerInfo(node); continue; } -#endif /*if (netbuffer->packettype == PT_PLAYERINFO) continue; // We do nothing with PLAYERINFO, that's for the MS browser. Not quite true anymore :p*/ diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 6c1bf7bd2..8bfead8d7 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -642,16 +642,9 @@ void D_QuitNetGame(void); //? How many ticks to run? boolean TryRunTics(tic_t realtic); -// extra data for lmps -// these functions scare me. they contain magic. -/*boolean AddLmpExtradata(UINT8 **demo_p, INT32 playernum); -void ReadLmpExtraData(UINT8 **demo_pointer, INT32 playernum);*/ - -#ifndef NONET // translate a playername in a player number return -1 if not found and // print a error message in the console SINT8 nametonum(const char *name); -#endif extern char motd[254], server_context[8]; extern UINT8 playernode[MAXPLAYERS]; @@ -663,7 +656,6 @@ INT32 D_NumPlayers(void); void D_ResetTiccmds(void); tic_t GetLag(INT32 node); -//UINT8 GetFreeXCmdSize(UINT8 playerid); extern UINT8 hu_resynching; #ifdef SATURNPAK diff --git a/src/d_net.c b/src/d_net.c index b2500e3e5..05df1320c 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -145,7 +145,6 @@ boolean Net_GetNetStat(void) #define URGENTFREESLOTNUM 10 #define ACKTOSENDTIMEOUT (TICRATE/11) -#ifndef NONET typedef struct { UINT8 acknum; @@ -159,7 +158,6 @@ typedef struct doomdata_t data; } pak; } ackpak_t; -#endif typedef enum { @@ -167,10 +165,8 @@ typedef enum NF_TIMEOUT = 2, // Flag is set when the node got a timeout } node_flags_t; -#ifndef NONET // Table of packets that were not acknowleged can be resent (the sender window) static ackpak_t ackpak[MAXACKPACKETS]; -#endif typedef struct { @@ -198,7 +194,6 @@ typedef struct static node_t nodes[MAXNETNODES]; #define NODETIMEOUT 14 -#ifndef NONET // return <0 if a < b (mod 256) // 0 if a = n (mod 256) // >0 if a > b (mod 256) @@ -411,22 +406,16 @@ static boolean Processackpak(void) } return goodpacket; } -#endif // send special packet with only ack on it void Net_SendAcks(INT32 node) { -#ifdef NONET - (void)node; -#else doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); netbuffer->packettype = PT_NOTHING; M_Memcpy(netbuffer->u.textcmd, nodes[node].acktosend, MAXACKTOSEND); HSendPacket(node, false, 0, MAXACKTOSEND); -#endif } -#ifndef NONET static void GotAcks(void) { INT32 i, j; @@ -457,7 +446,6 @@ static void GotAcks(void) } } } -#endif void Net_ConnectionTimeout(INT32 node) { @@ -484,7 +472,6 @@ void Net_ConnectionTimeout(INT32 node) // Resend the data if needed void Net_AckTicker(void) { -#ifndef NONET INT32 i; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); @@ -534,16 +521,12 @@ void Net_AckTicker(void) } } } -#endif } // Remove last packet received ack before resending the ackreturn // (the higher layer doesn't have room, or something else ....) void Net_UnAcknowledgePacket(INT32 node) { -#ifdef NONET - (void)node; -#else INT32 hm1 = (nodes[node].acktosend_head-1+MAXACKTOSEND) % MAXACKTOSEND; DEBFILE(va("UnAcknowledge node %d\n", node)); @@ -580,10 +563,8 @@ void Net_UnAcknowledgePacket(INT32 node) if (!nodes[node].firstacktosend) nodes[node].firstacktosend = 1; } -#endif } -#ifndef NONET /** Checks if all acks have been received * * \return True if all acks have been received @@ -601,7 +582,6 @@ static boolean Net_AllAcksReceived(void) return true; } -#endif /** Waits for all ackreturns * @@ -610,9 +590,6 @@ static boolean Net_AllAcksReceived(void) */ void Net_WaitAllAckReceived(UINT32 timeout) { -#ifdef NONET - (void)timeout; -#else tic_t tictac = I_GetTime(); timeout = tictac + timeout*NEWTICRATE; @@ -630,7 +607,6 @@ void Net_WaitAllAckReceived(UINT32 timeout) HGetPacket(); Net_AckTicker(); } -#endif } static void InitNode(node_t *node) @@ -647,10 +623,8 @@ static void InitAck(void) { INT32 i; -#ifndef NONET for (i = 0; i < MAXACKPACKETS; i++) ackpak[i].acknum = 0; -#endif for (i = 0; i < MAXNETNODES; i++) InitNode(&nodes[i]); @@ -663,9 +637,6 @@ static void InitAck(void) */ void Net_AbortPacketType(UINT8 packettype) { -#ifdef NONET - (void)packettype; -#else for (INT32 i = 0; i < MAXACKPACKETS; i++) { if (ackpak[i].acknum && (ackpak[i].pak.data.packettype == packettype @@ -674,7 +645,6 @@ void Net_AbortPacketType(UINT8 packettype) ackpak[i].acknum = 0; } } -#endif } // ----------------------------------------------------------------- @@ -684,9 +654,6 @@ void Net_AbortPacketType(UINT8 packettype) // remove a node, clear all ack from this node and reset askret void Net_CloseConnection(INT32 node) { -#ifdef NONET - (void)node; -#else INT32 i; if (node == -1) @@ -738,10 +705,8 @@ void Net_CloseConnection(INT32 node) InitNode(&nodes[node]); SV_AbortSendFiles(node); I_NetFreeNodenum(node); -#endif } -#ifndef NONET // // Checksum // @@ -757,10 +722,8 @@ static UINT32 NetbufferChecksum(void) return LONG(c); } -#endif #ifdef DEBUGFILE - static void fprintfstring(char *s, size_t len) { INT32 mode = 0; @@ -1032,7 +995,6 @@ void Command_Droprate(void) packetdroprate = droprate; } -#ifndef NONET static boolean ShouldDropPacket(void) { doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); @@ -1040,7 +1002,6 @@ static boolean ShouldDropPacket(void) || (packetdroprate != 0 && rand() < (((double)RAND_MAX) * (packetdroprate / 100.f))) || packetdroprate == 100; } #endif -#endif // // HSendPacket @@ -1077,11 +1038,6 @@ boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum, size_t packetlen if (!netgame) I_Error("Tried to transmit to another node"); -#ifdef NONET - (void)node; - (void)reliable; - (void)acknum; -#else // do this before GetFreeAcknum because this function backups // the current packet doomcom->remotenode = (INT16)node; @@ -1136,8 +1092,6 @@ boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum, size_t packetlen } #endif -#endif // ndef NONET - return true; } @@ -1171,9 +1125,7 @@ boolean HGetPacket(void) if (!netgame) return false; -#ifndef NONET - - while(true) + while (true) { I_NetGet(); @@ -1216,7 +1168,6 @@ boolean HGetPacket(void) doomcom->datalength -= BASEPACKETSIZE; break; } -#endif // ifndef NONET return true; } diff --git a/src/d_net.h b/src/d_net.h index caeb3c83f..f170cdf05 100644 --- a/src/d_net.h +++ b/src/d_net.h @@ -53,10 +53,8 @@ void Net_AckTicker(void); boolean HSendPacket(INT32 node, boolean reliable, UINT8 acknum, size_t packetlength); boolean HGetPacket(void); void D_SetDoomcom(void); -#ifndef NONET void D_SaveBan(void); void D_LoadBan(boolean warning); -#endif boolean D_CheckNetGame(void); void D_CloseConnection(void); void Net_UnAcknowledgePacket(INT32 node); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 7d2e0c6d0..982c63f07 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -721,10 +721,8 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_killingdead); // d_clisrv -#ifndef NONET #ifdef SATURNJOIN CV_RegisterVar(&cv_allownewsaturnplayer); // need to register it before cv_maxplayers && cv_allownewplayer -#endif #endif CV_RegisterVar(&cv_maxplayers); CV_RegisterVar(&cv_resynchattempts); @@ -737,7 +735,6 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_downloadspeed); CV_RegisterVar(&cv_connectawaittime); CV_RegisterVar(&cv_httpsource); -#ifndef NONET CV_RegisterVar(&cv_allownewplayer); CV_RegisterVar(&cv_joinrefusemessage); @@ -748,7 +745,6 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_showjoinaddress); CV_RegisterVar(&cv_shownodeip); CV_RegisterVar(&cv_blamecfail); -#endif COM_AddCommand("ping", Command_Ping_f); CV_RegisterVar(&cv_nettimeout); diff --git a/src/d_netfil.c b/src/d_netfil.c index 5df28a9b4..a816ca78e 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1006,17 +1006,16 @@ void Got_Filetxpak(void) file->file = NULL; file->status = FS_FOUND; file->justdownloaded = true; - CONS_Printf(M_GetText("Downloading %s...(done)\n"), - filename); -#ifndef NONET + CONS_Printf(M_GetText("Downloading %s...(done)\n"), filename); + filedownload.completednum++; filedownload.completedsize += file->totalsize; -#endif } } else if (!file->justdownloaded) { const char *s; + switch(file->status) { case FS_NOTFOUND: @@ -1035,6 +1034,7 @@ void Got_Filetxpak(void) s = "unknown"; break; } + I_Error("Received a file not requested (file id: %d, file status: %s)\n", filenum, s); } diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 29e80b843..d0914be56 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1385,13 +1385,12 @@ void I_Quit(void) static boolean quiting = false; /* prevent recursive I_Quit() */ - if (quiting) goto death; + if (quiting) + goto death; quiting = false; I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. -#ifndef NONET D_SaveBan(); // save the ban list -#endif G_SaveGameData(false); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. @@ -1495,9 +1494,7 @@ void I_Error(const char *error, ...) I_ShutdownConsole(); M_SaveConfig(NULL); // save game config, cvars.. -#ifndef NONET D_SaveBan(); // save the ban list -#endif G_SaveGameData(false); // Tails 12-08-2002 // Shutdown. Here might be other errors. diff --git a/src/doomdef.h b/src/doomdef.h index ba7a04bfb..ebf794365 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -597,7 +597,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; // None of these that are disabled in the normal build are guaranteed to work perfectly // Compile them at your own risk! -#ifndef NONET //-- SATURN __ /// Detect if a client is on Saturn in the clientconfig. /// To seperately allow them to join or block joining from vanilla clients. @@ -612,7 +611,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; #define SATURNPAK #endif //-- <( ̄︶ ̄)> __ -#endif /// Undefine to use the new method of Gamma correction see colour cube in v_video.c #define BACKWARDSCOMPATCORRECTION @@ -634,10 +632,8 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Most modifications should probably enable this. //#define SAVEGAME_OTHERVERSIONS -#ifndef NONET -/// Display a connection screen on join attempts. +/// Display a connection screen on join attempts. #define CLIENT_LOADINGSCREEN -#endif /// Backwards compatibility with musicslots. /// \note You should leave this enabled unless you're working with a future SRB2 version. @@ -659,7 +655,7 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; #define ROTANGLES 72 // Needs to be a divisor of 360 (45, 60, 90, 120...) #define ROTANGDIFF (360 / ROTANGLES) -#if defined (HAVE_CURL) && ! defined (NONET) +#if defined (HAVE_CURL) #define MASTERSERVER #define HOLEPUNCH #else diff --git a/src/g_game.h b/src/g_game.h index 43d9d14b2..4812a2c1f 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -129,9 +129,7 @@ extern consvar_t cv_playerblendeffects; extern consvar_t cv_cechotoggle; -#ifndef NONET extern consvar_t cv_chatlogsize; -#endif typedef enum { diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 0eaa38e8e..0132659e4 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -275,14 +275,12 @@ static INT32 cechoflags = 0; static tic_t resynch_ticker = 0; -#ifndef NONET // just after static void Command_Say_f(void); static void Command_Sayto_f(void); static void Command_Sayteam_f(void); static void Command_CSay_f(void); static void Got_Saycmd(UINT8 **p, INT32 playernum); -#endif void HU_LoadGraphics(void) { @@ -399,13 +397,11 @@ void HU_LoadGraphics(void) // void HU_Init(void) { -#ifndef NONET COM_AddCommand("say", Command_Say_f); COM_AddCommand("sayto", Command_Sayto_f); COM_AddCommand("sayteam", Command_Sayteam_f); COM_AddCommand("csay", Command_CSay_f); RegisterNetXCmd(XD_SAY, Got_Saycmd); -#endif // set shift translation table shiftxform = english_shiftxform; @@ -442,8 +438,6 @@ void HU_Shiftform(void) // EXECUTION //====================================================================== -#ifndef NONET - // EVERY CHANGE IN THIS SCRIPT IS LOL XD! BY VINCYTM static void Chatlogsize_OnChange(void); @@ -522,11 +516,9 @@ static void Chatlogsize_OnChange(void) #undef reallocarray chat_nummsg_log = min(chat_nummsg_log, (UINT32)cv_chatlogsize.value); } -#endif void HU_AddChatText(const char *text, boolean playsound) { -#ifndef NONET if (playsound && cv_consolechat.value != 2) // Don't play the sound if we're using hidden chat. S_StartSound(NULL, sfx_radio); // reguardless of our preferences, put all of this in the chat buffer in case we decide to change from oldchat mid-game. @@ -559,14 +551,8 @@ void HU_AddChatText(const char *text, boolean playsound) CON_LogMessage(text); CON_LogMessage("\n"); // Add newline. Don't use va for that, since `text` might be refering to va's buffer itself } -#else - (void)playsound; - CONS_Printf("%s\n", text); -#endif } -#ifndef NONET - /** Runs a say command, sending an ::XD_SAY message. * A say command consists of a signed 8-bit integer for the target, an * unsigned 8-bit flag variable, and then the message itself. @@ -1087,8 +1073,6 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) #endif } -#endif - // // void HU_Ticker(void) @@ -1146,8 +1130,6 @@ void HU_Ticker(void) HU_TickSongCredits(); } -#ifndef NONET - static boolean teamtalk = false; /*static char chatchars[QUEUESIZE]; static INT32 head = 0, tail = 0;*/ @@ -1299,7 +1281,6 @@ static void HU_SendChatMessage(void) SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } } -#endif void HU_clearChatChars(void) { @@ -1308,12 +1289,10 @@ void HU_clearChatChars(void) I_SetTextInput(false); } -#ifndef NONET static boolean justscrolleddown; static boolean justscrolledup; static INT16 typelines = 1; // number of drawfill lines we need when drawing the chat. it's some weird hack and might be one frame off but I'm lazy to make another loop. // It's up here since it has to be reset when we open the chat. -#endif // // Returns true if key eaten @@ -1345,7 +1324,6 @@ boolean HU_Responder(event_t *ev) return false; } -#ifndef NONET if (!chat_on) { // enter chat mode @@ -1423,7 +1401,6 @@ boolean HU_Responder(event_t *ev) } return true; } -#endif return false; } @@ -1432,8 +1409,6 @@ boolean HU_Responder(event_t *ev) // HEADS UP DRAWING //====================================================================== -#ifndef NONET - #define HU_DrawEmote(x, y, emote, flags) M_DrawEmote((x), (y), (emote), hu_emoteanim, (flags)) // Precompile a wordwrapped string to any given width. @@ -2115,7 +2090,6 @@ static void HU_DrawChat_Old(void) } } } -#endif static void HU_DrawCEcho(void) { @@ -2342,7 +2316,6 @@ void HU_Drawer(void) if (cv_vhseffect.value && ((paused && !camera[R_GetViewNumber()].freecam) || (demo.playback && cv_playbackspeed.value > 1))) V_DrawVhsEffect(demo.rewinding); -#ifndef NONET // draw chat string plus cursor if (chat_on) { @@ -2359,7 +2332,6 @@ void HU_Drawer(void) if (!OLDCHAT && cv_consolechat.value < 2 && netgame) // Don't display minimized chat if you set the mode to Window (Hidden) HU_drawMiniChat(); // draw messages in a cool fashion. } -#endif if (cechotimer) HU_DrawCEcho(); diff --git a/src/i_tcp.c b/src/i_tcp.c index 299a4b5c1..f6152e3cd 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -42,13 +42,6 @@ #include "doomdef.h" -#if defined (NOMD5) && !defined (NONET) -//#define NONET -#endif - -#ifdef NONET -#undef HAVE_MINIUPNPC -#else #include #ifdef USE_WINSOCK1 #include @@ -71,7 +64,7 @@ #if defined (__unix__) || defined (__APPLE__) || defined (UNIXCOMMON) #include #endif // UNIXCOMMON -#endif // !NONET +#endif #ifdef USE_WINSOCK // some undefined under win32 @@ -139,8 +132,6 @@ typedef union static UINT8 UPNP_support = TRUE; #endif -#endif // !NONET - #include "i_system.h" #include "i_time.h" #include "i_net.h" @@ -164,7 +155,7 @@ static UINT8 UPNP_support = TRUE; #include "i_addrinfo.h" #define DEFAULTPORT "5029" -#if defined (USE_WINSOCK) && !defined (NONET) +#if defined (USE_WINSOCK) typedef SOCKET SOCKET_TYPE; #define ERRSOCKET (SOCKET_ERROR) #else @@ -182,8 +173,6 @@ typedef unsigned long SOCKET_TYPE; typedef int socklen_t; #endif -#ifndef NONET - typedef struct { mysockaddr_t address; @@ -206,7 +195,6 @@ static banned_t *banned; #ifdef HOLEPUNCH static const INT32 hole_punch_magic = MSBF_LONG (0x52eb11); #endif -#endif static size_t numbans = 0; static size_t banned_size = 0; @@ -217,8 +205,6 @@ static boolean init_tcp_driver = false; static const char *serverport_name = DEFAULTPORT; static const char *clientport_name;/* any port */ -#ifndef NONET - #ifdef USE_WINSOCK // stupid microsoft makes things complicated static char *get_WSAErrorStr(int e) @@ -423,83 +409,62 @@ static const char *SOCK_AddrToStr(mysockaddr_t *sk) #endif return s; } -#endif static const char *SOCK_GetNodeAddress(INT32 node) { if (node == 0) return "self"; -#ifdef NONET - return NULL; -#else + if (!nodeconnected[node]) return NULL; + return SOCK_AddrToStr(&clientaddress[node]); -#endif } static const char *SOCK_GetBanAddress(size_t ban) { if (ban >= numbans) return NULL; -#ifdef NONET - return NULL; -#else + return SOCK_AddrToStr(&banned[ban].address); -#endif } static const char *SOCK_GetBanMask(size_t ban) { -#ifdef NONET - (void)ban; -#else static char s[16]; //255.255.255.255 netmask? no, just CDIR for only + if (ban >= numbans) return NULL; + if (sprintf(s,"%d",banned[ban].mask) > 0) return s; -#endif + return NULL; } static const char *SOCK_GetBanUsername(size_t ban) { -#ifdef NONET - (void)ban; - return NULL; -#else if (ban >= numbans) return NULL; + return banned[ban].username; -#endif } static const char *SOCK_GetBanReason(size_t ban) { -#ifdef NONET - (void)ban; - return NULL; -#else if (ban >= numbans) return NULL; + return banned[ban].reason; -#endif } static time_t SOCK_GetUnbanTime(size_t ban) { -#ifdef NONET - (void)ban; - return NO_BAN_TIME; -#else if (ban >= numbans) return NO_BAN_TIME; - return banned[ban].timestamp; -#endif -} -#ifndef NONET + return banned[ban].timestamp; +} #ifdef HAVE_IPV6 static boolean SOCK_cmpipv6(mysockaddr_t *a, mysockaddr_t *b, UINT8 mask) @@ -624,9 +589,7 @@ void Command_Numnodes(void) connected, ingame); } #endif -#endif -#ifndef NONET #ifdef HOLEPUNCH /* not one of the reserved "local" addresses */ static boolean @@ -783,9 +746,7 @@ static boolean SOCK_Get(void) doomcom->remotenode = -1; // no packet return false; } -#endif -#ifndef NONET static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr) { socklen_t d4 = (socklen_t)sizeof(struct sockaddr_in); @@ -869,9 +830,7 @@ static void SOCK_Send(void) } } #undef ALLOWEDERROR -#endif //NONET -#ifndef NONET static void SOCK_FreeNodenum(INT32 numnode) { // can't disconnect from self :) @@ -886,13 +845,10 @@ static void SOCK_FreeNodenum(INT32 numnode) // put invalid address memset(&clientaddress[numnode], 0, sizeof (clientaddress[numnode])); } -#endif // // UDPsocket // -#ifndef NONET - // allocate a socket static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen) { @@ -1252,12 +1208,11 @@ static boolean UDP_Socket(void) return true; } -#endif boolean I_InitTcpDriver(void) { boolean tcp_was_up = init_tcp_driver; -#ifndef NONET + if (!init_tcp_driver) { #ifdef USE_WINSOCK @@ -1312,7 +1267,7 @@ boolean I_InitTcpDriver(void) #endif init_tcp_driver = true; } -#endif + if (!tcp_was_up && init_tcp_driver) { I_AddExitFunc(I_ShutdownTcpDriver); @@ -1326,7 +1281,6 @@ boolean I_InitTcpDriver(void) return init_tcp_driver; } -#ifndef NONET static void SOCK_CloseSocket(void) { size_t i; @@ -1340,11 +1294,9 @@ static void SOCK_CloseSocket(void) mysocketses = 0; } -#endif void I_ShutdownTcpDriver(void) { -#ifndef NONET SOCK_CloseSocket(); CONS_Printf("I_ShutdownTcpDriver: "); @@ -1354,10 +1306,8 @@ void I_ShutdownTcpDriver(void) #endif CONS_Printf("shut down\n"); init_tcp_driver = false; -#endif } -#ifndef NONET static boolean SOCK_GetAddr(struct sockaddr_in *sin, const char *address, const char *port, boolean test) { struct my_addrinfo *ai = NULL, *runp, hints; @@ -1486,11 +1436,9 @@ static void SOCK_RegisterHolePunch(void) rendezvous(4); } #endif -#endif static boolean SOCK_OpenSocket(void) { -#ifndef NONET size_t i; memset(clientaddress, 0, sizeof (clientaddress)); @@ -1513,9 +1461,6 @@ static boolean SOCK_OpenSocket(void) // build the socket but close it first SOCK_CloseSocket(); return UDP_Socket(); -#else - return false; -#endif } static void AddBannedIndex(void) @@ -1544,11 +1489,6 @@ static boolean SOCK_Ban(INT32 node) if (node > MAXNETNODES) return false; -#ifdef NONET - (void)ban; - return false; -#else - ban = numbans; AddBannedIndex(); @@ -1568,15 +1508,10 @@ static boolean SOCK_Ban(INT32 node) #endif return true; -#endif } static boolean SOCK_SetBanUsername(const char *username) { -#ifdef NONET - (void)username; - return false; -#else if (username == NULL || strlen(username) == 0) { username = "Direct IP ban"; @@ -1589,16 +1524,12 @@ static boolean SOCK_SetBanUsername(const char *username) } banned[numbans - 1].username = Z_StrDup(username); + return true; -#endif } static boolean SOCK_SetBanReason(const char *reason) { -#ifdef NONET - (void)reason; - return false; -#else if (reason == NULL || strlen(reason) == 0) { reason = "No reason given"; @@ -1611,28 +1542,18 @@ static boolean SOCK_SetBanReason(const char *reason) } banned[numbans - 1].reason = Z_StrDup(reason); + return true; -#endif } static boolean SOCK_SetUnbanTime(time_t timestamp) { -#ifdef NONET - (void)reason; - return false; -#else banned[numbans - 1].timestamp = timestamp; return true; -#endif } static boolean SOCK_SetBanAddress(const char *address, const char *mask) { -#ifdef NONET - (void)address; - (void)mask; - return false; -#else struct my_addrinfo *ai, *runp, hints; int gaie; @@ -1693,7 +1614,6 @@ static boolean SOCK_SetBanAddress(const char *address, const char *mask) I_freeaddrinfo(ai); return true; -#endif } static void SOCK_ClearBans(void) diff --git a/src/m_menu.c b/src/m_menu.c index 54c57aaa9..0248ffc85 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -174,13 +174,12 @@ levellist_mode_t levellistmode = LLM_CREATESERVER; UINT8 maplistoption = 0; static char joystickInfo[8][29]; -#ifndef NONET + static UINT32 serverlistpage; static UINT32 oldserverlistpage; static float serverlistslidex; static INT32 serverlistsearched[MAXSERVERLIST] = {0}; static UINT32 serverlistsearchedcount = 0; -#endif //static saveinfo_t savegameinfo[MAXSAVEGAMES]; // Extra info about the save games. @@ -206,11 +205,9 @@ static INT32 vidm_column_size; static void M_StopMessage(INT32 choice); -#ifndef NONET static void M_HandleServerPage(INT32 choice); static void M_HandleServerSearch(INT32 choice); static void M_SearchServerList(void); -#endif // Prototyping is fun, innit? // ========================================================================== @@ -262,7 +259,6 @@ static void M_ModeAttackEndGame(INT32 choice); static void M_SetGuestReplay(INT32 choice); // Multiplayer -#ifndef NONET static void M_PreStartServerMenu(INT32 choice); #ifdef MASTERSERVER static void M_PreStartServerMenuChoice(event_t *ev); @@ -276,7 +272,6 @@ static void M_ConnectMenuModChecks(INT32 choice); #endif static void M_Refresh(INT32 choice); static void M_Connect(INT32 choice); -#endif static void M_StartOfflineServerMenu(INT32 choice); static void M_StartServer(INT32 choice); static void M_SetupMultiPlayer(void); @@ -359,28 +354,21 @@ static void M_DrawVideoMode(void); static void M_DrawColorMenu(void); static void M_DrawMonitorToggles(void); static void M_DrawMPMainMenu(void); -#ifndef NONET static void M_DrawConnectMenu(void); -#endif static void M_DrawJoystick(void); static void M_DrawSetupMultiPlayerMenu(void); static void M_DrawLocalSkinMenu(void); // Handling functions -#ifndef NONET static boolean M_CancelConnect(void); -#endif static boolean M_QuitMultiPlayerMenu(void); static void M_HandleAddons(INT32 choice); static void M_HandleSoundTest(INT32 choice); static void M_HandleMusicTest(INT32 choice); static void M_HandleImageDef(INT32 choice); -//static void M_HandleLoadSave(INT32 choice); static void M_HandleLevelStats(INT32 choice); -#ifndef NONET static void M_HandleConnectIP(INT32 choice); static void M_ConnectLastServer(INT32 choice); -#endif static void M_HandleSetupMultiPlayer(INT32 choice); static void M_HandleVideoMode(INT32 choice); static void M_ResetCvars(void); @@ -642,12 +630,11 @@ static void M_ChangeCvar(INT32 choice) } else { -#ifndef NONET if (cv == &cv_nettimeout || cv == &cv_jointimeout) choice *= (TICRATE/7); else if (cv == &cv_maxsend) choice *= 512; -#endif + CV_AddValue(cv,choice); } } @@ -1884,9 +1871,7 @@ void M_Init(void) if (!minidoticon && !minilighticon) OP_SaturnHudMenu[sh_minidot].status = IT_GRAYEDOUT; -#ifndef NONET CV_RegisterVar(&cv_serversort); -#endif //todo put this somewhere better... CV_RegisterVar(&cv_allcaps); @@ -6504,7 +6489,6 @@ static void Fetch_servers_thread(int *id) #define S_LINEY(n) currentMenu->y + SERVERHEADERHEIGHT + (n * SERVERLINEHEIGHT) -#ifndef NONET static UINT32 localservercount; static void M_SearchServerList(void) @@ -6840,11 +6824,9 @@ static int ServerListEntryComparator_modified(const void *entry1, const void *en // Default to strcmp. return strcmp(sa->info.servername, sb->info.servername); } -#endif void M_SortServerList(void) { -#ifndef NONET switch(cv_serversort.value) { case 0: // Ping. @@ -6866,11 +6848,10 @@ void M_SortServerList(void) qs22j(serverlist, serverlistcount, sizeof(serverelem_t), ServerListEntryComparator_gametype); break; } + M_SearchServerList(); -#endif } -#ifndef NONET #ifdef UPDATE_ALERT #ifdef MASTERSERVER static void M_CheckMODVersion(int id) @@ -7054,7 +7035,6 @@ static void M_PreConnectMenuChoice(event_t *ev) M_ConnectMenuModChecks(-1); } #endif -#endif //NONET //=========================================================================== // Start Server Menu @@ -7341,7 +7321,6 @@ static void M_StartOfflineServerMenu(INT32 choice) M_SetupNextMenu(&MP_OfflineServerDef); } -#ifndef NONET static void M_StartServerMenu(INT32 choice) { (void)choice; @@ -7361,15 +7340,12 @@ static void M_StartServerMenu(INT32 choice) #define SETUPM_IP_MAXSIZE ((28-1)*8) static char setupm_ip[64]; static textinput_t setupm_input_ip; -#endif void M_Multiplayer(INT32 choice) { (void)choice; -#ifndef NONET memset(setupm_ip, 0, sizeof(setupm_ip)); M_TextInputInit(&setupm_input_ip, setupm_ip, sizeof(setupm_ip)); -#endif M_SetupNextMenu(&MP_MainDef); } @@ -7385,20 +7361,17 @@ static void M_DrawMPMainMenu(void) // use generic drawer for cursor, items and title M_DrawGenericMenu(); -#ifndef NONET #if MAXPLAYERS != 16 Update the maxplayers label... #endif V_DrawRightAlignedString(BASEVIDWIDTH-x, y+MP_MainMenu[4].alphaKey, ((itemOn == 4) ? highlightflags : 0)|MENUCAPS, "(2-16 Players)"); -#endif V_DrawRightAlignedString(BASEVIDWIDTH-x, y+MP_MainMenu[5].alphaKey, ((itemOn == 5) ? highlightflags : 0)|MENUCAPS, "(2-4 players)" ); -#ifndef NONET y += MP_MainMenu[9].alphaKey; V_DrawFill(x+5, y+4+5, /*16*8 + 6,*/ BASEVIDWIDTH - 2*(x+5), 8+6, 239); @@ -7408,7 +7381,6 @@ Update the maxplayers label... V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip); else M_DrawTextInputScroll(x+8, y+12, &setupm_input_ip, 0, SETUPM_IP_MAXSIZE); -#endif // character bar, ripped off the color bar :V { @@ -7550,8 +7522,6 @@ static void M_SetupMultiHandler(INT32 choice) } } -#ifndef NONET - // Tails 11-19-2002 static void M_ConnectIP(INT32 choice) { @@ -7576,7 +7546,6 @@ static void M_ConnectIP(INT32 choice) I_FinishUpdate(); // page flip or blit buffer } - //Join Last server static void M_ConnectLastServer(INT32 choice) { @@ -7647,7 +7616,6 @@ static void M_HandleConnectIP(INT32 choice) M_ClearMenus(true); } } -#endif //!NONET // ======================== // MULTIPLAYER PLAYER SETUP diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 7e0dd10d8..34e81193f 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -62,9 +62,7 @@ menu_t OP_DiscordOptionsDef; #endif menu_t OP_HUDOptionsDef, OP_ChatOptionsDef; menu_t OP_GameOptionsDef, OP_ServerOptionsDef; -#ifndef NONET menu_t OP_AdvServerOptionsDef; -#endif menu_t OP_MonitorToggleDef; menu_t OP_AccessibilityDef; @@ -516,15 +514,10 @@ static menuitem_t MP_MainMenu[] = {IT_STRING|IT_KEYHANDLER,NULL, "Player setup...", M_SetupMultiHandler, 18}, {IT_HEADER, NULL, "Host a game", NULL, 100-24}, -#ifndef NONET {IT_STRING|IT_CALL, NULL, "Internet/LAN...", M_PreStartServerMenu, 110-24}, -#else - {IT_GRAYEDOUT, NULL, "Internet/LAN...", NULL, 110-24}, -#endif {IT_STRING|IT_CALL, NULL, "Offline...", M_StartOfflineServerMenu, 118-24}, {IT_HEADER, NULL, "Join a game", NULL, 132-24}, -#ifndef NONET #ifndef MASTERSERVER {IT_GRAYEDOUT, NULL, "Internet server browser...",NULL, 142-24}, #else @@ -532,14 +525,8 @@ static menuitem_t MP_MainMenu[] = #endif {IT_STRING|IT_CALL, NULL, "Join last server", M_ConnectLastServer, 150-24}, {IT_STRING|IT_KEYHANDLER, NULL, "Specify IPv4 address:", M_HandleConnectIP, 158-24}, -#else - {IT_GRAYEDOUT, NULL, "Internet server browser...",NULL, 142-24}, - {IT_GRAYEDOUT, NULL, "Join last server", NULL, 150-24}, - {IT_GRAYEDOUT, NULL, "Specify IPv4 address:", NULL, 158-24}, -#endif }; -#ifndef NONET static menuitem_t MP_ServerMenu[] = { {IT_STRING|IT_CVAR, NULL, "Max. Player Count", &cv_maxplayers, 10}, @@ -555,7 +542,6 @@ static menuitem_t MP_ServerMenu[] = {IT_WHITESTRING|IT_CALL, NULL, "Start", M_StartServer, 130}, }; -#endif // Separated offline and normal servers. static menuitem_t MP_OfflineServerMenu[] = @@ -573,7 +559,6 @@ static menuitem_t MP_PlayerSetupMenu[] = {IT_KEYHANDLER | IT_STRING, NULL, "Color", M_HandleSetupMultiPlayer, 152}, }; -#ifndef NONET static menuitem_t MP_ConnectMenu[] = { {IT_STRING | IT_CVAR, NULL, "Sort By", &cv_serversort, 0}, @@ -601,7 +586,6 @@ enum mp_connect_search, FIRSTSERVERLINE }; -#endif // ------------------------------------ // Options and most (?) of its submenus @@ -1473,16 +1457,13 @@ static const char* OP_GameTooltips[] = static menuitem_t OP_ServerOptionsMenu[] = { -#ifndef NONET {IT_STRING | IT_CVAR | IT_CV_STRING, NULL, "Server Name", &cv_servername, 10}, -#endif {IT_STRING | IT_CVAR, NULL, "Intermission Timer", &cv_inttime, 40}, {IT_STRING | IT_CVAR, NULL, "Map Progression", &cv_advancemap, 50}, {IT_STRING | IT_CVAR, NULL, "Voting Timer", &cv_votetime, 60}, {IT_STRING | IT_CVAR, NULL, "Voting Rule Changes", &cv_kartvoterulechanges, 70}, -#ifndef NONET {IT_STRING | IT_CVAR, NULL, "Max. Player Count", &cv_maxplayers, 90}, {IT_STRING | IT_CVAR, NULL, "Allow Players to Join", &cv_allownewplayer, 100}, {IT_STRING | IT_CVAR, NULL, "Allow Addon Downloading", &cv_downloading, 110}, @@ -1490,29 +1471,23 @@ static menuitem_t OP_ServerOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Mute All Chat", &cv_mute, 130}, {IT_SUBMENU|IT_STRING, NULL, "Advanced Options...", &OP_AdvServerOptionsDef,150}, -#endif }; static const char* OP_ServerOptionsTooltips[] = { -#ifndef NONET "Name of server.", -#endif "Length of intermission after races.", "How the next map to be played is choosen.", "How long map voting is.", "How often should other gamemodes appear.", -#ifndef NONET "Max amount of players allowed in this server.", "Allow players to join this server.", "Allow players to download addons.", "Who has permission to pause the server?", "Completely mute in game chat.", "Options for advanced server settings.", -#endif }; -#ifndef NONET static menuitem_t OP_AdvServerOptionsMenu[] = { #ifndef MASTERSERVER @@ -1570,7 +1545,6 @@ static const char* OP_AdvServerOptionsTooltips[] = "Log player resync attempts.", "Log player file transfers.", }; -#endif #define ITEMTOGGLEBOTTOMRIGHT @@ -2398,17 +2372,12 @@ menu_t MP_MainDef = M_DrawMPMainMenu, 42, 30, 0, -#ifndef NONET M_CancelConnect, -#else - NULL, -#endif NULL }; menu_t MP_OfflineServerDef = MAPICONMENUSTYLE("M_MULTI", MP_OfflineServerMenu, &MP_MainDef); -#ifndef NONET menu_t MP_ServerDef = MAPICONMENUSTYLE("M_MULTI", MP_ServerMenu, &MP_MainDef); menu_t MP_ConnectDef = @@ -2423,7 +2392,7 @@ menu_t MP_ConnectDef = M_CancelConnect, NULL }; -#endif + menu_t MP_PlayerSetupDef = { NULL, //"M_SPLAYR" @@ -2553,9 +2522,7 @@ menu_t OP_FocusOptionsDef = DEFAULTMENUSTYLE(NULL, OP_FocusOptionsMenu, &OP_Main menu_t OP_GameOptionsDef = DEFAULTMENUSTYLE("M_GAME", OP_GameOptionsMenu, &OP_MainDef, 30, 20, OP_GameTooltips); menu_t OP_ServerOptionsDef = DEFAULTMENUSTYLE("M_SERVER", OP_ServerOptionsMenu, &OP_MainDef, 24, 20, OP_ServerOptionsTooltips); -#ifndef NONET menu_t OP_AdvServerOptionsDef = DEFAULTSCROLLSTYLE("M_SERVER", OP_AdvServerOptionsMenu, &OP_ServerOptionsDef, 24, 30, OP_AdvServerOptionsTooltips); -#endif menu_t OP_MonitorToggleDef = { diff --git a/src/mserv.c b/src/mserv.c index 2f172d27d..c7eb50442 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -29,7 +29,6 @@ #endif #ifdef MASTERSERVER - static int MSId; static int MSRegisteredId = -1; @@ -52,18 +51,12 @@ static I_cond MSCond; # define Unlock_state() #endif/*HAVE_THREADS*/ -#ifndef NONET static void Command_Listserv_f(void); -#endif - #endif/*MASTERSERVER*/ - - -static void Update_parameters (void); +static void Update_parameters(void); #ifdef MASTERSERVER - static void MasterServer_OnChange(void); static void Advertise_OnChange(void); @@ -112,7 +105,6 @@ UINT16 current_port = 0; */ void AddMServCommands(void) { -#ifndef NONET #ifdef MASTERSERVER CV_RegisterVar(&cv_masterserver); CV_RegisterVar(&cv_masterserver_update_rate); @@ -125,13 +117,11 @@ void AddMServCommands(void) #ifdef HOLEPUNCH CV_RegisterVar(&cv_rendezvousserver); #endif - CV_RegisterVar(&cv_servername); CV_RegisterVar(&cv_server_contact); #ifdef MASTERSERVER COM_AddCommand("listserv", Command_Listserv_f); #endif -#endif } #ifdef MASTERSERVER @@ -200,23 +190,17 @@ char *GetMODVersion(int id) } #endif -#ifndef NONET /** Gets a list of game servers. Called from console. */ static void Command_Listserv_f(void) { CONS_Printf(M_GetText("Retrieving server list...\n")); - - { - HMS_list_servers(); - } + HMS_list_servers(); } -#endif static boolean firstmsrules = false; -static void -Get_masterserver_rules (boolean checkfirst) +static void Get_masterserver_rules(boolean checkfirst) { char rules[256]; diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 7987ea543..af730ced6 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1927,9 +1927,7 @@ void I_Quit(void) quiting = SDL_FALSE; I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. -#ifndef NONET D_SaveBan(); // save the ban list -#endif G_SaveGameData(false); // Tails 12-08-2002 //added:16-02-98: when recording a demo, should exit using 'q' key, // but sometimes we forget and use 'F10'.. so save here too. @@ -2052,9 +2050,7 @@ void I_Error(const char *error, ...) I_ShutdownConsole(); M_SaveConfig(NULL); // save game config, cvars.. -#ifndef NONET D_SaveBan(); // save the ban list -#endif G_SaveGameData(false); // Tails 12-08-2002 // Shutdown. Here might be other errors. @@ -2073,9 +2069,7 @@ void I_Error(const char *error, ...) // 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); + 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 From ccdb73f8611b2261dfd7d4f020cde7327a0ad511 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Sep 2025 19:33:13 +0200 Subject: [PATCH 32/39] delet VANILLAJOINNEXTROUND --- src/d_clisrv.c | 8 -------- src/d_clisrv.h | 3 --- src/d_netcmd.c | 5 ++--- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8f657e342..6492b9943 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4132,10 +4132,6 @@ consvar_t cv_allownewplayer = {"allowjoin", "On", CV_SAVE|CV_CALL, CV_OnOff, Joi consvar_t cv_allownewsaturnplayer = {"allowsaturnjoin", "On", CV_HIDEN, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif -#ifdef VANILLAJOINNEXTROUND -consvar_t cv_joinnextround = {"joinnextround", "Off", CV_SAVE|CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done -#endif - static CV_PossibleValue_t maxplayers_cons_t[] = {{2, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}}; consvar_t cv_maxplayers = {"maxplayers", "8", CV_SAVE|CV_CALL, maxplayers_cons_t, Joinable_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -4847,10 +4843,6 @@ static void HandleConnect(SINT8 node) // you get a free second before desynch checks. use it wisely. SV_InitResynchVars(node); -#ifdef VANILLAJOINNEXTROUND - if (cv_joinnextround.value && gameaction == ga_nothing) - G_SetGamestate(GS_WAITINGPLAYERS); -#endif if (!SV_SendServerConfig(node)) { G_SetGamestate(backupstate); diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 8bfead8d7..2de1271fb 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -583,9 +583,6 @@ extern tic_t lowest_lag; extern consvar_t cv_mindelay, cv_gentlemens; extern consvar_t -#ifdef VANILLAJOINNEXTROUND - cv_joinnextround, -#endif cv_netticbuffer, cv_allownewplayer, #ifdef SATURNJOIN cv_allownewsaturnplayer, diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 982c63f07..3432b55ab 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -738,10 +738,9 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_allownewplayer); CV_RegisterVar(&cv_joinrefusemessage); + CV_RegisterVar(&cv_chatlogsize); -#ifdef VANILLAJOINNEXTROUND - CV_RegisterVar(&cv_joinnextround); -#endif + CV_RegisterVar(&cv_showjoinaddress); CV_RegisterVar(&cv_shownodeip); CV_RegisterVar(&cv_blamecfail); From 98b105c02a0698a7152da6e3fbe4c1d50df39cec Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Sep 2025 19:35:01 +0200 Subject: [PATCH 33/39] delet CLIENT_LOADINGSCREEN --- src/d_clisrv.c | 13 ------------- src/d_netfil.c | 4 ---- src/d_netfil.h | 5 ----- src/doomdef.h | 3 --- 4 files changed, 25 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 6492b9943..64fcd12ba 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -54,11 +54,9 @@ #include "d_main.h" #include "r_fps.h" -#ifdef CLIENT_LOADINGSCREEN // cl loading screen #include "v_video.h" #include "f_finale.h" -#endif #ifdef HAVE_DISCORDRPC #include "discord.h" @@ -1165,8 +1163,6 @@ static void CV_LoadPlayerNames(UINT8 **p) } } -#ifdef CLIENT_LOADINGSCREEN - // // CL_DrawConnectionStatus // @@ -1501,7 +1497,6 @@ static inline void CL_DrawConnectionStatus(void) } } } -#endif static boolean CL_AskFileList(INT32 firstfile) { @@ -2778,7 +2773,6 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic } *oldtic = I_GetTime(); -#ifdef CLIENT_LOADINGSCREEN if (client && cl_mode != CL_CONNECTED && cl_mode != CL_ABORTED) { F_TitleScreenTicker(true); @@ -2795,10 +2789,6 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic if (moviemode) M_SaveFrame(); } -#else - CON_Drawer(); - I_UpdateNoVsync(); -#endif } else { @@ -2823,10 +2813,7 @@ static void CL_ConnectToServer(void) sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); -#ifdef CLIENT_LOADINGSCREEN filedownload.current = -1; -#endif - cl_mode = CL_SEARCHING; // Don't get a corrupt savegame error because tmpsave already exists diff --git a/src/d_netfil.c b/src/d_netfil.c index a816ca78e..239f961a4 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -230,9 +230,7 @@ void D_ParseFileneeded(INT32 fileneedednum_parm, UINT8 *fileneededstr, UINT16 fi void CL_PrepareDownloadSaveGame(const char *tmpsave) { -#ifdef CLIENT_LOADINGSCREEN filedownload.current = -1; -#endif fileneedednum = 1; fileneeded[0].status = FS_REQUESTED; fileneeded[0].justdownloaded = false; @@ -1045,9 +1043,7 @@ void Got_Filetxpak(void) filetime = 0; } -#ifdef CLIENT_LOADINGSCREEN filedownload.current = filenum; -#endif } /** \brief Checks if a node is downloading a file diff --git a/src/d_netfil.h b/src/d_netfil.h index b84c83391..3c7502451 100644 --- a/src/d_netfil.h +++ b/src/d_netfil.h @@ -59,19 +59,15 @@ extern char downloaddir[512]; typedef struct { -#ifdef CLIENT_LOADINGSCREEN INT32 current; INT32 completednum; UINT32 completedsize; INT32 totalnum; UINT32 totalsize; -#endif - #ifdef HAVE_CURL INT32 remaining; boolean http_failed; boolean http_running; - char http_source[MAX_MIRROR_LENGTH+1]; #endif } file_download_t; @@ -79,7 +75,6 @@ typedef struct extern file_download_t filedownload; #ifdef HAVE_CURL - typedef struct HTTP_login HTTP_login; extern struct HTTP_login diff --git a/src/doomdef.h b/src/doomdef.h index ebf794365..4c3bed72f 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -632,9 +632,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Most modifications should probably enable this. //#define SAVEGAME_OTHERVERSIONS -/// Display a connection screen on join attempts. -#define CLIENT_LOADINGSCREEN - /// Backwards compatibility with musicslots. /// \note You should leave this enabled unless you're working with a future SRB2 version. #define MUSICSLOT_COMPATIBILITY From 8e8ef048606249d5a8bfceedc0c07dd9fffa7e55 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Sep 2025 19:40:15 +0200 Subject: [PATCH 34/39] delet BUGTRAP psure this never worked anyways --- src/dedicated/i_main.c | 15 ++------ src/sdl/i_main.c | 5 --- src/win32/win_dbg.c | 78 ------------------------------------------ src/win32/win_dbg.h | 6 ---- 4 files changed, 3 insertions(+), 101 deletions(-) diff --git a/src/dedicated/i_main.c b/src/dedicated/i_main.c index 055b14882..93af6b14b 100644 --- a/src/dedicated/i_main.c +++ b/src/dedicated/i_main.c @@ -138,8 +138,7 @@ static void InitLogging(void) if (M_IsPathAbsolute(reldir)) { - left = snprintf(logfilename, sizeof logfilename, - "%s"PATHSEP, reldir); + left = snprintf(logfilename, sizeof logfilename, "%s"PATHSEP, reldir); } else #ifdef DEFAULTDIR @@ -155,13 +154,10 @@ static void InitLogging(void) "."PATHSEP"%s"PATHSEP, reldir); } - strftime(&logfilename[left], sizeof logfilename - left, - format, timeinfo); + strftime(&logfilename[left], sizeof logfilename - left, format, timeinfo); } - M_MkdirEachUntil(logfilename, - M_PathParts(logdir) - 1, - M_PathParts(logfilename) - 1, 0755); + M_MkdirEachUntil(logfilename, M_PathParts(logdir) - 1, M_PathParts(logfilename) - 1, 0755); #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) logstream = fopen(logfilename, "w"); @@ -225,11 +221,6 @@ int main(int argc, char **argv) // never return D_SRB2Loop(); -#ifdef BUGTRAP - // This is safe even if BT didn't start. - ShutdownBugTrap(); -#endif - // return to OS return 0; } diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index 6955d0b4c..b2ab7777f 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -236,11 +236,6 @@ int main(int argc, char **argv) // never return D_SRB2Loop(); -#ifdef BUGTRAP - // This is safe even if BT didn't start. - ShutdownBugTrap(); -#endif - // return to OS return 0; } diff --git a/src/win32/win_dbg.c b/src/win32/win_dbg.c index 5576b1dc5..290227b09 100644 --- a/src/win32/win_dbg.c +++ b/src/win32/win_dbg.c @@ -45,84 +45,6 @@ BOOL InitDrMingw(void) } #endif -#ifdef BUGTRAP - -typedef void (APIENTRY *BT_SETSUPPORTURL)(LPCTSTR pszSupportURL); -typedef void (APIENTRY *BT_SETFLAGS)(DWORD dwFlags); -typedef void (APIENTRY *BT_SETAPPNAME)(LPCTSTR pszAppName); -typedef void (APIENTRY *BT_SETAPPVERSION)(LPCTSTR pszAppVersion); -typedef void (APIENTRY *BT_SETSUPPORTSERVER)(LPCTSTR pszSupportHost, SHORT nSupportPort); - -// BT constant definitions that we use, as given in the docs. -#define BTF_DETAILEDMODE 0x01 -#define BTF_ATTACHREPORT 0x04 - - -static HMODULE g_hmodBugTrap; - - -// -------------------------------------------------------------------------- -// Initialises the Bug Trap exception-handling library. Returns true iff -// successful. -// -------------------------------------------------------------------------- -BOOL InitBugTrap(void) -{ - BT_SETFLAGS lpfnBT_SetFlags; - BT_SETSUPPORTURL lpfnBT_SetSupportURL; - BT_SETAPPNAME lpfnBT_SetAppName; - BT_SETAPPVERSION lpfnBT_SetAppVersion; - BT_SETSUPPORTSERVER lpfnBT_SetSupportServer; - - // Loading the library installs the exception handler. -#ifdef UNICODE - g_hmodBugTrap = LoadLibrary(L"BugTrapU.dll"); -#else - g_hmodBugTrap = LoadLibrary("BugTrap.dll"); -#endif - - // Get the functions. - lpfnBT_SetFlags = (BT_SETFLAGS)GetProcAddress(g_hmodBugTrap, "BT_SetFlags"); - lpfnBT_SetSupportURL = (BT_SETSUPPORTURL)GetProcAddress(g_hmodBugTrap, "BT_SetSupportURL"); - lpfnBT_SetAppName = (BT_SETAPPNAME)GetProcAddress(g_hmodBugTrap, "BT_SetAppName"); - lpfnBT_SetAppVersion = (BT_SETAPPVERSION)GetProcAddress(g_hmodBugTrap, "BT_SetAppVersion"); - lpfnBT_SetSupportServer = (BT_SETSUPPORTSERVER)GetProcAddress(g_hmodBugTrap, "BT_SetSupportServer"); - - if (g_hmodBugTrap) - { - lpfnBT_SetAppName(TEXT("Sonic Robo Blast 2")); - lpfnBT_SetAppVersion(TEXT(VERSIONSTRING)); - lpfnBT_SetFlags(BTF_DETAILEDMODE | BTF_ATTACHREPORT); - lpfnBT_SetSupportURL(TEXT("http://www.srb2.org/")); - lpfnBT_SetSupportServer(TEXT("srb2.org"), 9999); - - return TRUE; - } - - return FALSE; -} - - -// -------------------------------------------------------------------------- -// Removes the BugTrap exception handler. Safe to call even if BT was never -// initialized. -// -------------------------------------------------------------------------- -void ShutdownBugTrap(void) -{ - if (g_hmodBugTrap) FreeLibrary(g_hmodBugTrap); -} - -// -------------------------------------------------------------------------- -// Simple test to check whether BugTrap is loaded without exposing its -// handle. -// -------------------------------------------------------------------------- -BOOL IsBugTrapLoaded(void) -{ - return !!g_hmodBugTrap; -} - -#endif // (defined BUGTRAP) - - #define NumCodeBytes 16 // Number of code bytes to record. #define MaxStackDump 2048 // Maximum number of DWORDS in stack dumps. #define StackColumns 8 // Number of columns in stack dump. diff --git a/src/win32/win_dbg.h b/src/win32/win_dbg.h index 1c696ae5c..414ffc2d9 100644 --- a/src/win32/win_dbg.h +++ b/src/win32/win_dbg.h @@ -24,12 +24,6 @@ BOOL InitDrMingw(void); #endif -#ifdef BUGTRAP -BOOL InitBugTrap(void); -void ShutdownBugTrap(void); -BOOL IsBugTrapLoaded(void); -#endif - // called in the exception filter of the __try block, writes all useful debugging information // to a file, using only win32 functions in case the C runtime is in a bad state. LONG WINAPI RecordExceptionInfo(PEXCEPTION_POINTERS data/*, LPCSTR Message, LPSTR lpCmdLine*/); From f3bbb5af56270fa3be8fe6b2a38569765924dcbb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 30 Sep 2025 22:07:21 +0200 Subject: [PATCH 35/39] ensure ALL savebuffers use Zone memory fixes a crash when sending an uncompressed save to clients --- src/d_clisrv.c | 62 ++++++++++++++++++++++++++------------------------ src/d_clisrv.h | 3 ++- src/g_game.c | 10 ++++---- src/p_setup.c | 4 ++-- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 64fcd12ba..9c9d95322 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -338,7 +338,7 @@ static void WriteNetXCmd(UINT8 *cmd, netxcmd_t id, const void *param, size_t npa void SendNetXCmdForPlayer(UINT8 playerid, netxcmd_t id, const void *param, size_t nparam) { - if (localtextcmd[playerid][0]+2+nparam > MAXTEXTCMD) + if (textcmdbuf[playerid] != NULL || localtextcmd[playerid][0]+2+nparam > MAXTEXTCMD) { textcmdbuf_t *buf = textcmdbuf[playerid]; @@ -373,17 +373,13 @@ void SendNetXCmdForPlayer(UINT8 playerid, netxcmd_t id, const void *param, size_ { WriteNetXCmd(buf->cmd, id, param, nparam); } + return; } + WriteNetXCmd(localtextcmd[playerid], id, param, nparam); } -/*UINT8 GetFreeXCmdSize(UINT8 playerid) -{ - // -1 for the size and another -1 for the ID. - return (UINT8)(localtextcmd[playerid][0] - 2); -}*/ - // Frees all textcmd memory for the specified tic static void D_FreeTextcmd(tic_t tic) { @@ -422,7 +418,8 @@ static UINT8* D_GetExistingTextcmd(tic_t tic, INT32 playernum) if (textcmdtic) { UINT8 *cmd = textcmdtic->playercmds[playernum]; - if (cmd) return cmd; + if (cmd) + return cmd; } return NULL; @@ -460,6 +457,7 @@ static void ExtraDataTicker(void) INT32 i; for (i = 0; i < MAXPLAYERS; i++) + { if (playeringame[i] || i == 0) { UINT8 *bufferstart = D_GetExistingTextcmd(gametic, i); @@ -474,8 +472,7 @@ static void ExtraDataTicker(void) { if (*curpos < MAXNETXCMD && listnetxcmd[*curpos]) { - const UINT8 id = *curpos; - curpos++; + const UINT8 id = *curpos++; DEBFILE(va("executing x_cmd %s ply %u ", netxcmdnames[id - 1], i)); (listnetxcmd[id])(&curpos, i); DEBFILE("done\n"); @@ -487,12 +484,14 @@ static void ExtraDataTicker(void) SendKick(i, KICK_MSG_CON_FAIL); DEBFILE(va("player %d kicked [gametic=%u] reason as follows:\n", i, gametic)); } + CONS_Alert(CONS_WARNING, M_GetText("Got unknown net command [%s]=%d (max %d)\n"), sizeu1(curpos - bufferstart), *curpos, bufferstart[0]); break; } } } } + } // If you are a client, you can safely forget the net commands for this tic // If you are the server, you need to remember them until every client has been aknowledged, @@ -1504,7 +1503,7 @@ static boolean CL_AskFileList(INT32 firstfile) netbuffer->packettype = PT_TELLFILESNEEDED; netbuffer->u.filesneedednum = firstfile; - return HSendPacket(servernode, false, 0, sizeof (INT32)); + return HSendPacket(servernode, false, 0, sizeof(INT32)); } /** Sends a special packet to declare how many players in local @@ -1886,7 +1885,7 @@ static void SV_SendSaveGame(INT32 node, boolean resending) UINT8 *buffertosend; // first save it in a malloced buffer - save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + save.buffer = (UINT8 *)Z_Malloc(SAVEGAMESIZE, PU_STATIC, NULL); if (!save.buffer) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); @@ -1901,7 +1900,7 @@ static void SV_SendSaveGame(INT32 node, boolean resending) length = save.p - save.buffer; if (length > SAVEGAMESIZE) { - free(save.buffer); + Z_Free(save.buffer); save.p = NULL; I_Error("Savegame buffer overrun"); } @@ -1919,8 +1918,7 @@ static void SV_SendSaveGame(INT32 node, boolean resending) if ((compressedlen = lzf_compress(save.buffer + sizeof(UINT32), length - sizeof(UINT32), compressedsave + sizeof(UINT32), length - sizeof(UINT32) - 1))) { // Compressing succeeded; send compressed data - - free(save.buffer); + Z_Free(save.buffer); // State that we're compressed. buffertosend = compressedsave; @@ -1961,7 +1959,7 @@ static void SV_SavedGame(void) sprintf(tmpsave, "%s" PATHSEP TMPSAVENAME, srb2home); // first save it in a malloced buffer - save.p = save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + save.p = save.buffer = (UINT8 *)Z_Malloc(SAVEGAMESIZE, PU_STATIC, NULL); if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for savegame\n")); @@ -1973,7 +1971,7 @@ static void SV_SavedGame(void) length = save.p - save.buffer; if (length > SAVEGAMESIZE) { - free(save.buffer); + Z_Free(save.buffer); save.p = NULL; I_Error("Savegame buffer overrun"); } @@ -1982,7 +1980,7 @@ static void SV_SavedGame(void) if (!FIL_WriteFile(tmpsave, save.buffer, length)) CONS_Printf(M_GetText("Didn't save %s for netgame"), tmpsave); - free(save.buffer); + Z_Free(save.buffer); save.p = NULL; } @@ -5391,11 +5389,8 @@ static void PT_ClientCmd(INT32 netconsole, SINT8 node) { tic_t realend, realstart; - if (client) - return; - // Ignore tics from those not synched - if (resynch_inprogress[node]) + if (client || resynch_inprogress[node]) return; doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); @@ -5551,7 +5546,8 @@ static void PT_ClientCmd(INT32 netconsole, SINT8 node) --resynch_score[node]; #else // Check player consistancy during the level - if (realstart <= gametic && realstart > gametic - BACKUPTICS+1 && gamestate == GS_LEVEL + if (gamestate == GS_LEVEL + && (realstart <= gametic && realstart + BACKUPTICS - 1 > gametic) && consistancy[realstart%BACKUPTICS] != SHORT(netbuffer->u.clientpak.consistancy)) { SV_RequireResynch(node); @@ -5559,10 +5555,13 @@ static void PT_ClientCmd(INT32 netconsole, SINT8 node) if (cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) { if (cv_blamecfail.value) + { CONS_Printf(M_GetText("Synch failure for player %d (%s); expected %hd, got %hd\n"), netconsole+1, player_names[netconsole], consistancy[realstart%BACKUPTICS], SHORT(netbuffer->u.clientpak.consistancy)); + } + DEBFILE(va("Restoring player %d (synch failure) [%update] %d!=%d\n", netconsole, realstart, consistancy[realstart%BACKUPTICS], SHORT(netbuffer->u.clientpak.consistancy))); @@ -5959,16 +5958,17 @@ static void GetPackets(void) { node = (SINT8)doomcom->remotenode; - if (netbuffer->packettype == PT_CLIENTJOIN && server) + if (server && netbuffer->packettype == PT_CLIENTJOIN) { if (!levelloading) // Otherwise just ignore { HandleConnect(node); } + continue; } - if (node == servernode && client && cl_mode != CL_SEARCHING) + if (client && node == servernode && cl_mode != CL_SEARCHING) { if (netbuffer->packettype == PT_SERVERSHUTDOWN) { @@ -6027,7 +6027,8 @@ static INT16 Consistancy(void) { if (!playeringame[i]) ret ^= 0xCCCC; - else if (!players[i].mo || gamestate != GS_LEVEL); + else if (!players[i].mo || gamestate != GS_LEVEL) + ; else { ret += players[i].mo->x; @@ -6036,6 +6037,7 @@ static INT16 Consistancy(void) ret *= i+1; } } + // I give up // Coop desynching enemies is painful if (gamestate == GS_LEVEL) @@ -6876,7 +6878,7 @@ void NetKeepAlive(void) UpdatePingTable(); -// Sryder: What is FILESTAMP??? << lmao + // Sryder: What is FILESTAMP??? << lmao GetPackets(); @@ -7146,7 +7148,7 @@ void CL_ClearRewinds(void) while ((head = rewindhead)) { rewindhead = rewindhead->next; - free(head); + Z_Free(head); } } @@ -7158,7 +7160,7 @@ rewind_t *CL_SaveRewindPoint(size_t demopos) if (rewindhead && rewindhead->leveltime + REWIND_POINT_INTERVAL > leveltime) return NULL; - rewind = (rewind_t *)malloc(sizeof (rewind_t)); + rewind = (rewind_t *)Z_Malloc(sizeof(rewind_t), PU_STATIC, NULL); if (!rewind) return NULL; @@ -7181,7 +7183,7 @@ rewind_t *CL_RewindToTime(tic_t time) while (rewindhead && rewindhead->leveltime > time) { rewind = rewindhead->next; - free(rewindhead); + Z_Free(rewindhead); rewindhead = rewind; } diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 2de1271fb..74bed4cdb 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -660,7 +660,8 @@ extern UINT8 hu_redownloadinggamestate; #endif extern boolean hu_stopped; // kart, true when the game is stopped for players due to a disconnecting or connecting player -typedef struct rewind_s { +typedef struct rewind_s +{ UINT8 savebuffer[(768*1024)]; tic_t leveltime; size_t demopos; diff --git a/src/g_game.c b/src/g_game.c index 23b291c74..7470f3fc9 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3564,7 +3564,7 @@ void G_SaveGameData(boolean force) if (!gamedataloaded) return; // If never loaded (-nodata), don't save - save.p = save.buffer = (UINT8 *)malloc(GAMEDATASIZE); + save.p = save.buffer = (UINT8 *)Z_Malloc(GAMEDATASIZE, PU_STATIC, NULL); if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); @@ -3584,7 +3584,7 @@ void G_SaveGameData(boolean force) if (!FIL_CopyFile(gamedatafilename, backupfile)) { CONS_Alert(CONS_WARNING,"Failed to create a backup of save data. Will not attempt to write to save data\n"); - free(save.buffer); + Z_Free(save.buffer); save.p = save.buffer = NULL; return; } @@ -3657,7 +3657,7 @@ void G_SaveGameData(boolean force) length = save.p - save.buffer; FIL_WriteFile(va(pandf, srb2home, gamedatafilename), save.buffer, length); - free(save.buffer); + Z_Free(save.buffer); save.p = save.buffer = NULL; } @@ -3827,7 +3827,7 @@ void G_SaveGame(UINT32 savegameslot) char name[VERSIONSIZE]; size_t length; - save.p = save.buffer = (UINT8 *)malloc(SAVEGAMESIZE); + save.p = save.buffer = (UINT8 *)Z_Malloc(SAVEGAMESIZE, PU_STATIC, NULL); if (!save.p) { CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n")); @@ -3842,7 +3842,7 @@ void G_SaveGame(UINT32 savegameslot) length = save.p - save.buffer; saved = FIL_WriteFile(backup, save.buffer, length); - free(save.buffer); + Z_Free(save.buffer); save.p = save.buffer = NULL; } diff --git a/src/p_setup.c b/src/p_setup.c index acadcd194..2ccbd1821 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1015,7 +1015,7 @@ void P_WriteThings(lumpnum_t lumpnum) data = W_CacheLumpNum(lumpnum, PU_LEVEL); - save.p = save.buffer = (UINT8 *)malloc(nummapthings * sizeof (mapthing_t)); + save.p = save.buffer = (UINT8 *)Z_Malloc(nummapthings * sizeof(mapthing_t), PU_STATIC, NULL); if (!save.p) { @@ -1040,7 +1040,7 @@ void P_WriteThings(lumpnum_t lumpnum) length = save.p - save.buffer; FIL_WriteFile(va("newthings%d.lmp", gamemap), save.buffer, length); - free(save.buffer); + Z_Free(save.buffer); save.p = NULL; CONS_Printf(M_GetText("newthings%d.lmp saved.\n"), gamemap); From 7d2bcbd1eed72050e3598a6062765b55aeb013bf Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Oct 2025 14:19:48 +0200 Subject: [PATCH 36/39] cleanup some stuff w_wad & filesrch mostly delet some "dead" code use pathisdirectory for filebrowser to declutter code properly declare FUNCNORETURN and ATTRNORETURN for some quit functions --- src/doomdef.h | 2 +- src/filesrch.c | 37 ++++++++-------------------- src/i_system.h | 2 +- src/sdl/i_system.cpp | 4 +-- src/w_wad.c | 58 ++++++++++++++++++++------------------------ 5 files changed, 40 insertions(+), 63 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 4c3bed72f..677554b78 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -418,7 +418,7 @@ enum { */ -void I_Error(const char *error, ...) FUNCIERROR; +FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...); /** \brief write a message to stderr (use before I_Quit) for when you need to quit with a msg, but need the return code 0 of I_Quit(); diff --git a/src/filesrch.c b/src/filesrch.c index 27b519edf..088911e54 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -205,6 +205,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want } } + // This folder is excluded if (skipfolder) { continue; @@ -420,9 +421,6 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) { DIR *dirhandle; struct dirent *dent; -#ifndef _WIN32 - struct stat fsstat; -#endif size_t pos = 0, folderpos = 0, numfolders = 0; char *tempname = NULL; @@ -468,23 +466,16 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) strcpy(&menupath[menupathindex[menudepthleft]],dent->d_name); -#ifndef _WIN32 - if (stat(menupath, &fsstat) < 0) -#else - // if we wanna follow symlinks we can check with FILE_ATTRIBUTE_REPARSE_POINT - DWORD fileattr = GetFileAttributes(menupath); - if (fileattr == INVALID_FILE_ATTRIBUTES) -#endif + INT32 isdir = pathisdirectory(menupath); + + if (isdir == -1) ; // was the file (re)moved? can't stat it else // is a file or directory { -#ifndef _WIN32 - if (!S_ISDIR(fsstat.st_mode)) // file -#else - if (!(fileattr & FILE_ATTRIBUTE_DIRECTORY)) -#endif + if (isdir == 0) // file { size_t len = strlen(dent->d_name)+1; + if (replayhut) { if (strcasecmp(".lmp", dent->d_name+len-5)) @@ -550,13 +541,9 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) strcpy(&menupath[menupathindex[menudepthleft]],dent->d_name); -#ifndef _WIN32 - if (stat(menupath, &fsstat) < 0) -#else - // if we wanna follow symlinks we can check with FILE_ATTRIBUTE_REPARSE_POINT - DWORD fileattr = GetFileAttributes(menupath); - if (fileattr == INVALID_FILE_ATTRIBUTES) -#endif + INT32 isdir = pathisdirectory(menupath); + + if (isdir == -1) ; // was the file (re)moved? can't stat it else // is a file or directory { @@ -565,11 +552,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) UINT8 ext = EXT_FOLDER; UINT8 folder; -#ifndef _WIN32 - if (!S_ISDIR(fsstat.st_mode)) // file -#else - if (!(fileattr & FILE_ATTRIBUTE_DIRECTORY)) -#endif + if (isdir == 0) // file { if (!((numfolders+pos) < sizecoredirmenu)) continue; // crash prevention diff --git a/src/i_system.h b/src/i_system.h index 024d491c7..f5187e037 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -93,7 +93,7 @@ void I_OsPolling(void); /** \brief Called by M_Responder when quit is selected, return exit code 0 */ -void I_Quit(void) FUNCNORETURN; +FUNCNORETURN void ATTRNORETURN I_Quit(void); /** \brief to set up the first joystick scale diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index af730ced6..97d9b27b4 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1917,7 +1917,7 @@ INT32 I_StartupSystem(void) // // I_Quit // -void I_Quit(void) +FUNCNORETURN void ATTRNORETURN I_Quit(void) { static SDL_bool quiting = SDL_FALSE; @@ -1981,7 +1981,7 @@ static INT32 errorcount = 0; */ static boolean shutdowning = false; -void I_Error(const char *error, ...) +FUNCIERROR void ATTRNORETURN I_Error(const char *error, ...) { va_list argptr; char buffer[8192]; diff --git a/src/w_wad.c b/src/w_wad.c index 623efe118..4a993a7f4 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -353,7 +353,7 @@ static inline INT32 W_MakeFileMD5(const char *filename, void *resblock) // Invalidates the cache of lump numbers. Call this whenever a wad is added. static void W_InvalidateLumpnumCache(void) { - memset(lumpnumcache, 0, sizeof (lumpnumcache)); + memset(lumpnumcache, 0, sizeof(lumpnumcache)); } UINT32 W_HashLumpName(const char *name) @@ -383,12 +383,10 @@ static restype_t ResourceFileDetect(const char* filename) static lumpinfo_t* ResGetLumpsStandalone(FILE* handle, UINT16* numlumps, const char* lumpname) { lumpinfo_t* lumpinfo = Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL); - lumpinfo->position = 0; fseek(handle, 0, SEEK_END); lumpinfo->size = ftell(handle); fseek(handle, 0, SEEK_SET); - strlcpy(lumpinfo->name, lumpname, sizeof(lumpinfo->name)); lumpinfo->namelength = strlen(lumpinfo->name); lumpinfo->hash.name = W_HashLumpName(lumpname); @@ -863,7 +861,9 @@ UINT16 W_InitFile(const char *filename, boolean local, boolean startup) } #endif - switch(type = ResourceFileDetect(filename)) + type = ResourceFileDetect(filename); + + switch (type) { case RET_SOC: lumpinfo = ResGetLumpsStandalone(handle, &numlumps, "OBJCTCFG"); @@ -950,9 +950,10 @@ UINT16 W_InitFile(const char *filename, boolean local, boolean startup) if (refreshdirmenu & REFRESHDIR_GAMEDATA) G_LoadGameData(); - DEH_UpdateMaxFreeslots(); + DEH_UpdateMaxFreeslots(); W_InvalidateLumpnumCache(); + return wadfile->numlumps; } @@ -1059,14 +1060,14 @@ const char *W_CheckNameForNum(lumpnum_t lumpnum) UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) { UINT16 i; - static char uname[9]; + static char uname[8 + 1]; UINT32 hash; size_t namelen; if (!TestValidLump(wad, 0)) return INT16_MAX; - memset(uname, 0, sizeof uname); + memset(uname, 0, sizeof(uname)); strncpy(uname, name, sizeof(uname)-1); strupr(uname); namelen = strlen(uname); @@ -1134,7 +1135,7 @@ UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump) return INT16_MAX; } -UINT16 W_CheckNumForMarkerStartPwad (const char *name, UINT16 wad, UINT16 startlump) +UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump) { UINT16 marker; marker = W_CheckNumForNamePwad(name, wad, startlump); @@ -1305,7 +1306,7 @@ lumpnum_t W_CheckNumForName(const char *name) else { // Update the cache. - lumpnum_t lumpnum = (i << 16) + check; + lumpnum_t lumpnum = (i << 16) | check; AddLumpToCache(lumpnum, name, false); return lumpnum; @@ -1331,16 +1332,13 @@ lumpnum_t W_CheckNumForLongName(const char *name) if (cachenum != LUMPERROR) return cachenum; - if (check == INT16_MAX) + // scan wad files backwards so patch lump files take precedence + for (i = numwadfiles - 1; i >= 0; i--) { - // scan wad files backwards so patch lump files take precedence - for (i = numwadfiles - 1; i >= 0; i--) - { - check = W_CheckNumForLongNamePwad(name, (UINT16)i, 0); + check = W_CheckNumForLongNamePwad(name, (UINT16)i, 0); - if (check != INT16_MAX) - break; //found it - } + if (check != INT16_MAX) + break; //found it } if (check == INT16_MAX) @@ -1350,7 +1348,7 @@ lumpnum_t W_CheckNumForLongName(const char *name) else { // Update the cache. - lumpnum_t lumpnum = (i << 16) + check; + lumpnum_t lumpnum = (i << 16) | check; AddLumpToCache(lumpnum, name, true); return lumpnum; @@ -1878,16 +1876,15 @@ void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) if (!lumpcache[lump]) { size_t len = W_LumpLengthPwad(wad, lump); - void *ptr, *dest, *lumpdata = Z_Malloc(len, PU_STATIC, NULL); + void *dest, *lumpdata = Z_Malloc(len, PU_STATIC, NULL); // read the lump in full W_ReadLumpHeaderPwad(wad, lump, lumpdata, 0, 0); - ptr = lumpdata; dest = Z_Calloc(sizeof(patch_t), tag, &lumpcache[lump]); - Patch_Create((softwarepatch_t*)(ptr), len, dest); + Patch_Create((softwarepatch_t*)lumpdata, len, dest); - Z_Free(ptr); + Z_Free(lumpdata); } else Z_ChangeTag(lumpcache[lump], tag); @@ -1909,9 +1906,12 @@ void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) patch = (patch_t *)W_CacheSoftwarePatchNumPwad(wad, lump, tag); + if (patch == NULL) + return NULL; + #ifdef HWRENDER // Software-only compile cache the data without conversion - if (patch != NULL && rendermode == render_opengl) + if (rendermode == render_opengl) Patch_CreateGL(patch); #endif @@ -2093,8 +2093,7 @@ void W_VerifyFileMD5(UINT16 wadfilenum, const char *matchmd5) // formats. checklist assumed to be valid. static int W_VerifyName(const char *name, lumpchecklist_t *checklist, boolean status) { - size_t j; - for (j = 0; checklist[j].len && checklist[j].name; ++j) + for (size_t j = 0; checklist[j].len && checklist[j].name; ++j) { if ((strncasecmp(name, checklist[j].name, checklist[j].len) != false) == status) @@ -2102,6 +2101,7 @@ static int W_VerifyName(const char *name, lumpchecklist_t *checklist, boolean st return true; } } + return false; } @@ -2363,13 +2363,7 @@ int W_VerifyNMUSlumps(const char *filename, FILE *handle, boolean exit_on_error) static int W_NameStartsWith(const char *name, lumpchecklist_t *checklist) { - size_t j; - for (j = 0; checklist[j].len && checklist[j].name; ++j) - { - if (strncasecmp(name, checklist[j].name, checklist[j].len) == 0) - return true; - } - return false; + return W_VerifyName(name, checklist, false); } // Checks if file contains at least one lump which name starts with one of strings in checklist From fac4d3c2c02180fad663d28ec9d9612bc7089757 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Oct 2025 14:20:21 +0200 Subject: [PATCH 37/39] add toggle for frameskip just in case someone wants to toggle that off for some reason --- src/d_main.c | 11 +++++++++-- src/d_netcmd.c | 1 + src/m_menudefs.c | 18 +++++++++++------- src/screen.c | 3 +++ src/screen.h | 2 +- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index bc826acdb..39951f70c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -931,9 +931,16 @@ void D_SRB2Loop(void) // // Wipes run an inner loop and artificially increase // the measured time. - if (!ranwipe && (frameskip < 3) && (deltatics > 1.0)) + if (cv_frameskip.value) { - frameskip++; + if (!ranwipe && (frameskip < 3) && (deltatics > 1.0)) + { + frameskip++; + } + else + { + frameskip = 0; + } } else { diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3432b55ab..6f97cb819 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1016,6 +1016,7 @@ void D_RegisterClientCommands(void) // screen.c CV_RegisterVar(&cv_fullscreen); CV_RegisterVar(&cv_renderview); + CV_RegisterVar(&cv_frameskip); CV_RegisterVar(&cv_vhseffect); CV_RegisterVar(&cv_shittyscreen); CV_RegisterVar(&cv_scr_width); diff --git a/src/m_menudefs.c b/src/m_menudefs.c index 34e81193f..74ee714dd 100644 --- a/src/m_menudefs.c +++ b/src/m_menudefs.c @@ -928,17 +928,19 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "FPS counter sampling", &cv_accuratefps, 50}, - {IT_STRING | IT_CVAR, NULL, "Votescreen Scaling", &cv_votebgscaling, 60}, + {IT_STRING | IT_CVAR, NULL, "Frameskip", &cv_frameskip, 60}, + + {IT_STRING | IT_CVAR, NULL, "Votescreen Scaling", &cv_votebgscaling, 70}, #ifdef HWRENDER - {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_glscreentextures, 70}, + {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_glscreentextures, 80}, #ifdef USE_FBO_OGL - {IT_STRING | IT_CVAR, NULL, "FBO Downsampling support", &cv_glframebuffer, 75}, - {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_glpalettedepth, 85}, - {IT_DISABLED, NULL, "", NULL, 95}, // dummy text + {IT_STRING | IT_CVAR, NULL, "FBO Downsampling support", &cv_glframebuffer, 85}, + {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_glpalettedepth, 95}, + {IT_DISABLED, NULL, "", NULL, 105}, // dummy text #else - {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_glpalettedepth, 80}, - {IT_DISABLED, NULL, "", NULL, 90}, // dummy text + {IT_STRING | IT_CVAR, NULL, "Palette Depth", &cv_glpalettedepth, 90}, + {IT_DISABLED, NULL, "", NULL, 100}, // dummy text #endif #endif }; @@ -952,6 +954,7 @@ static const char* OP_ExpTooltips[] = //"Should the directional lightning be randomized each map?\nTakes effect on next map load.", "Toggle being able to see the sky.", "Change the FPS counter sampling method\nInaccurate updates slower and might miss frame drops and such\nAccurate updates faster and is more accurate, but might be less readable", // how to ingles?? + "Skips rendering frames if game logic takes too long preventing issues during performance drops." // idk im shit as describing things "Different methods of scaling the votescreen backgrounds.", #ifdef HWRENDER "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", @@ -971,6 +974,7 @@ enum //op_exp_dirlight, op_exp_skybox, op_exp_accuratefps, + op_exp_frameskip, op_exp_votescrn, #ifdef HWRENDER op_exp_glscrtx, diff --git a/src/screen.c b/src/screen.c index d7747d039..21ec0ed52 100644 --- a/src/screen.c +++ b/src/screen.c @@ -45,6 +45,9 @@ static CV_PossibleValue_t shittyscreen_cons_t[] = {{0, "Okay"}, {1, "Shitty"}, { consvar_t cv_scr_width = {"scr_width", "1280", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_scr_height = {"scr_height", "800", CV_SAVE, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_renderview = {"renderview", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_frameskip = {"frameskip", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_vhseffect = {"vhspause", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_shittyscreen = {"televisionsignal", "Okay", CV_NOSHOWHELP, shittyscreen_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/screen.h b/src/screen.h index df5baee18..ecad24a64 100644 --- a/src/screen.h +++ b/src/screen.h @@ -86,7 +86,7 @@ extern INT32 setmodeneeded; // mode number to set if needed, or 0 extern UINT8 *scr_borderpatch; // patch used to fill the view borders -extern consvar_t cv_scr_width, cv_scr_height, cv_renderview, cv_fullscreen, cv_vhseffect, cv_shittyscreen; +extern consvar_t cv_scr_width, cv_scr_height, cv_renderview, cv_frameskip, cv_fullscreen, cv_vhseffect, cv_shittyscreen; extern consvar_t cv_parallelsoftware; extern consvar_t cv_paralleldrawmasked; From e550edb93e8acdbbf9204715250798b74d205b5e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 2 Oct 2025 15:00:08 +0200 Subject: [PATCH 38/39] smol micro optimizations hw_main - dont check for polyflags (rendersides) inside HWR_Addline, move to HWR_AddPolyObjectSegs - save some sector checks by assigning pointer HWR_RenderPlane - check for numpolys instead of numPolyObjects in HWR_Subsector (will only be "true" if theres polyobjs in currently traversed subsector instead of when polyobjs are generally on the map) --- src/hardware/hw_main.cpp | 74 ++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 026527f99..096b45982 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -575,21 +575,13 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool if (nrPlaneVerts < 3) //not even a triangle ? return; + const sector_t *sec = FOFsector ? FOFsector : gl_frontsector; + // Get the slope pointer to simplify future code - if (FOFsector) - { - if (FOFsector->f_slope && !isceiling) - slope = FOFsector->f_slope; - else if (FOFsector->c_slope && isceiling) - slope = FOFsector->c_slope; - } - else - { - if (gl_frontsector->f_slope && !isceiling) - slope = gl_frontsector->f_slope; - else if (gl_frontsector->c_slope && isceiling) - slope = gl_frontsector->c_slope; - } + if (sec->f_slope && !isceiling) + slope = sec->f_slope; + else if (sec->c_slope && isceiling) + slope = sec->c_slope; // Set fixedheight to the slope's height from our viewpoint, if we have a slope if (slope) @@ -645,42 +637,24 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool flatxref = (float)(((fixed_t)pv->x & (~flatflag)) / fflatsize); flatyref = (float)(((fixed_t)pv->y & (~flatflag)) / fflatsize); - if (FOFsector != NULL) + if (!isceiling) // it's a floor { - if (!isceiling) // it's a floor - { - scrollx = FixedToFloat(FOFsector->floor_xoffs)/fflatsize; - scrolly = FixedToFloat(FOFsector->floor_yoffs)/fflatsize; - angle = FOFsector->floorpic_angle; - } - else // it's a ceiling - { - scrollx = FixedToFloat(FOFsector->ceiling_xoffs)/fflatsize; - scrolly = FixedToFloat(FOFsector->ceiling_yoffs)/fflatsize; - angle = FOFsector->ceilingpic_angle; - } + scrollx = FixedToFloat(sec->floor_xoffs)/fflatsize; + scrolly = FixedToFloat(sec->floor_yoffs)/fflatsize; + angle = sec->floorpic_angle; } - else if (gl_frontsector) + else // it's a ceiling { - if (!isceiling) // it's a floor - { - scrollx = FixedToFloat(gl_frontsector->floor_xoffs)/fflatsize; - scrolly = FixedToFloat(gl_frontsector->floor_yoffs)/fflatsize; - angle = gl_frontsector->floorpic_angle; - } - else // it's a ceiling - { - scrollx = FixedToFloat(gl_frontsector->ceiling_xoffs)/fflatsize; - scrolly = FixedToFloat(gl_frontsector->ceiling_yoffs)/fflatsize; - angle = gl_frontsector->ceilingpic_angle; - } + scrollx = FixedToFloat(sec->ceiling_xoffs)/fflatsize; + scrolly = FixedToFloat(sec->ceiling_yoffs)/fflatsize; + angle = sec->ceilingpic_angle; } if (angle) // Only needs to be done if there's an altered angle { tempxsow = flatxref; tempytow = flatyref; - anglef = ANG2RAD(InvAngle(angle)); + anglef = ANG2RAD(InvAngle(angle)); flatxref = (tempxsow * cosf(anglef)) - (tempytow * sinf(anglef)); flatyref = (tempxsow * sinf(anglef)) + (tempytow * cosf(anglef)); } @@ -755,14 +729,16 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool for (i = 0; i < subsector->numlines; i++, line++) { + line_t* ld = line->linedef; + // this check sucks and is a hotspot lel - if (LIKELY(line->linedef->special != HORIZONSPECIAL)) + if (LIKELY(ld->special != HORIZONSPECIAL)) continue; if (R_PointOnSegSide(viewx, viewy, line) != 0) continue; - P_ClosestPointOnLine(viewx, viewy, line->linedef, &v); + P_ClosestPointOnLine(viewx, viewy, ld, &v); dist = FixedToFloat(R_PointToDist(v.x, v.y)); if (line->pv1) @@ -2449,9 +2425,6 @@ static void HWR_AddLine(seg_t *line) fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t - if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) - return; - gl_curline = line; if (LIKELY(gl_curline->pv1)) @@ -2614,7 +2587,12 @@ static inline void HWR_AddPolyObjectSegs(void) // Render the polyobject's lines for (j = 0; j < po_ptrs[i]->segCount; ++j) { - HWR_AddLine(po_ptrs[i]->segs[j]); + seg_t *seg = po_ptrs[i]->segs[j]; + + if (!(seg->polyseg->flags & POF_RENDERSIDES)) + continue; + + HWR_AddLine(seg); } } } @@ -3215,7 +3193,7 @@ doaddline: // without talking about the overdraw of course. sub->sector->validcount = validcount;/// \todo fix that in a better way - if (UNLIKELY(numPolyObjects)) + if (UNLIKELY(numpolys)) { while (count--) { From 20c570c97ca40ba14cc45892994c465f2e730a81 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 2 Oct 2025 16:48:58 +0300 Subject: [PATCH 39/39] Fix sector sound origin not working (mobj_t wasn't consistent with degenmobj_t) --- src/p_mobj.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/p_mobj.h b/src/p_mobj.h index 1123faf5b..781b86390 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -282,15 +282,15 @@ typedef struct mobj_s // List: thinker links. thinker_t thinker; - // More list: links in sector (if needed) - struct mobj_s *bnext; - struct mobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr - // Info for drawing: position. fixed_t x, y, z; fixed_t old_x, old_y, old_z; // position interpolation fixed_t old_x2, old_y2, old_z2; + // More list: links in sector (if needed) + struct mobj_s *bnext; + struct mobj_s **bprev; // killough 8/11/98: change to ptr-to-ptr + mobjtype_t type; const mobjinfo_t *info; // &mobjinfo[mobj->type]