From 746a2d4b05e02a0700d37ae40d2882086df4ad3a Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 2 Aug 2023 12:52:56 +0300 Subject: [PATCH 1/3] Make amount of messages saved in log configurable via cvar --- src/d_netcmd.c | 1 + src/g_game.h | 4 ++++ src/hu_stuff.c | 43 +++++++++++++++++++++++++++++++++++-------- src/hu_stuff.h | 3 ++- src/m_menu.c | 3 ++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 45055276e..9866de479 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -743,6 +743,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_httpsource); #ifndef NONET CV_RegisterVar(&cv_allownewplayer); + CV_RegisterVar(&cv_chatlogsize); #ifdef VANILLAJOINNEXTROUND CV_RegisterVar(&cv_joinnextround); #endif diff --git a/src/g_game.h b/src/g_game.h index 688ce3d5b..0f55724c0 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -163,6 +163,10 @@ extern consvar_t cv_resetspecialmusic; extern consvar_t cv_resume; extern consvar_t cv_fading; +#ifndef NONET +extern consvar_t cv_chatlogsize; +#endif + typedef enum { AXISNONE = 0, diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 60b1d14da..97ac3c3a0 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -378,6 +378,11 @@ void HU_Start(void) // EVERY CHANGE IN THIS SCRIPT IS LOL XD! BY VINCYTM +static void Chatlogsize_OnChange(void); + +static CV_PossibleValue_t chatlogsize_cons_t[] = {{8, "MIN"}, {MAX_CHAT_BUFSIZE, "MAX"}, {0, NULL}}; +consvar_t cv_chatlogsize = {"chatlogsize", "64", CV_CALL|CV_SAVE, chatlogsize_cons_t, Chatlogsize_OnChange, 0, NULL, NULL, 0, 0, NULL}; + static UINT32 chat_nummsg_log = 0; static UINT32 chat_nummsg_min = 0; static UINT32 chat_scroll = 0; @@ -385,10 +390,7 @@ static tic_t chat_scrolltime = 0; static UINT32 chat_maxscroll = 0; // how far can we scroll? -//static chatmsg_t chat_mini[CHAT_BUFSIZE]; // Display the last few messages sent. -//static chatmsg_t chat_log[CHAT_BUFSIZE]; // Keep every message sent to us in memory so we can scroll n shit, it's cool. - -static char chat_log[CHAT_BUFSIZE][255]; // hold the last 48 or so messages in that log. +static char **chat_log = NULL; static char chat_mini[8][255]; // display up to 8 messages that will fade away / get overwritten static tic_t chat_timers[8]; @@ -416,13 +418,30 @@ static void HU_removeChatText_Mini(void) // same but w the log. TODO: optimize this and maybe merge in a single func? im bad at C. static void HU_removeChatText_Log(void) { - // MPC: Don't create new arrays, just iterate through an existing one + // We don't have any messages, idiot! + if (!chat_nummsg_log) + return; + + free(chat_log[0]); size_t i; for(i=0;i (UINT32)cv_chatlogsize.value) + { + HU_removeChatText_Log(); + } + + // TODO - use z_zone allocators? + chat_log = reallocarray(chat_log, cv_chatlogsize.value, sizeof(char*)); + chat_nummsg_log = min(chat_nummsg_log, (UINT32)cv_chatlogsize.value); +} #endif void HU_AddChatText(const char *text, boolean playsound) @@ -432,11 +451,19 @@ void HU_AddChatText(const char *text, boolean playsound) 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. - if (chat_nummsg_log >= CHAT_BUFSIZE) // too many messages! + // Uuuh dunno how that can happen but a bit of paranoia is never too bad + if (!chat_log) + { + //I_Error("Chat log is not allocated what the fuck"); // uwu + Chatlogsize_OnChange(); // Lets hope that will surely allocate some memory for us + } + + if (chat_nummsg_log >= (UINT32)cv_chatlogsize.value) // too many messages! HU_removeChatText_Log(); + chat_log[chat_nummsg_log] = malloc(HU_MSGBUFSIZE); strcpy(chat_log[chat_nummsg_log], text); - chat_nummsg_log++; + ++chat_nummsg_log; if (chat_nummsg_min >= 8) HU_removeChatText_Mini(); diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 6842a17aa..f0ef731b6 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -62,7 +62,8 @@ typedef struct // chat stuff //------------------------------------ #define HU_MAXMSGLEN 223 -#define CHAT_BUFSIZE 64 // that's enough messages, right? We'll delete the older ones when that gets out of hand. +#define HU_MSGBUFSIZE 255 +#define MAX_CHAT_BUFSIZE 256 // that's enough messages, right? We'll delete the older ones when that gets out of hand. #define NETSPLITSCREEN // why the hell WOULDN'T we want this? #ifdef NETSPLITSCREEN #define OLDCHAT (cv_consolechat.value == 1 || dedicated || vid.width < 640) diff --git a/src/m_menu.c b/src/m_menu.c index bb19230c0..ac3bc3d41 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1533,8 +1533,9 @@ static menuitem_t OP_ChatOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Chat Background Tint", &cv_chatbacktint, 50}, {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 60}, {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 70}, + {IT_STRING | IT_CVAR, NULL, "Max Chat Messages", &cv_chatlogsize, 80}, - {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 90}, // shows ping next to framerate if we want to. + {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 100}, // shows ping next to framerate if we want to. }; static menuitem_t OP_GameOptionsMenu[] = -- 2.54.0 From a9c1e50cf88abd1792eb22299d4af8fcf153b654 Mon Sep 17 00:00:00 2001 From: xyzzy Date: Wed, 2 Aug 2023 15:12:53 +0300 Subject: [PATCH 2/3] Add missing files to .gitignore --- .gitignore | 4 +++- assets/.gitignore | 1 + src/CMakeLists.txt | 8 ++++++++ src/sdl/CMakeLists.txt | 20 ++++++++++---------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 797ea03df..8b73f04f5 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ Win32_LIB_ASM_Release /assets/debian compile.sh *.gz -.vscode/ \ No newline at end of file +.vscode/ +out +build diff --git a/assets/.gitignore b/assets/.gitignore index b9dc7c70d..52c1d72f4 100644 --- a/assets/.gitignore +++ b/assets/.gitignore @@ -10,3 +10,4 @@ !LICENSE-3RD-PARTY.txt !CMakeLists.txt !debian-template/* +installer diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index db19cbe81..e4eb9f134 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,7 @@ set(SRB2_CORE_SOURCES d_net.c d_netcmd.c d_netfil.c + d_protocol.c dehacked.c f_finale.c f_wipe.c @@ -31,6 +32,7 @@ set(SRB2_CORE_SOURCES m_fixed.c m_menu.c m_misc.c + m_perfstats.c m_queue.c m_random.c md5.c @@ -61,6 +63,7 @@ set(SRB2_CORE_HEADERS d_netcmd.h d_netfil.h d_player.h + d_protocol.h d_think.h d_ticcmd.h dehacked.h @@ -97,6 +100,7 @@ set(SRB2_CORE_HEADERS m_menu.h m_misc.h m_queue.h + m_perfstats.h m_random.h m_swap.h md5.h @@ -121,6 +125,7 @@ set(SRB2_CORE_RENDER_SOURCES r_draw.c r_fps.c r_main.c + r_patch.c r_plane.c r_segs.c r_sky.c @@ -134,6 +139,7 @@ set(SRB2_CORE_RENDER_SOURCES r_fps.h r_local.h r_main.h + r_patch r_plane.h r_segs.h r_sky.h @@ -261,6 +267,7 @@ if(${SRB2_CONFIG_HAVE_BLUA}) lua_script.c lua_skinlib.c lua_thinkerlib.c + lua_udatalib.c ) set(SRB2_LUA_HEADERS lua_hook.h @@ -268,6 +275,7 @@ if(${SRB2_CONFIG_HAVE_BLUA}) lua_hudlib_drawlist.h lua_libs.h lua_script.h + lua_udatalib.h ) prepend_sources(SRB2_LUA_SOURCES) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index b20adb096..67df4a646 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -274,16 +274,16 @@ if(${SDL2_FOUND}) ) ## strip debug symbols into separate file when using gcc - if(CMAKE_COMPILER_IS_GNUCC) - if(${CMAKE_BUILD_TYPE} MATCHES Debug) - message(STATUS "Will make separate debug symbols in *.debug") - add_custom_command(TARGET SRB2SDL2 POST_BUILD - COMMAND ${OBJCOPY} --only-keep-debug $ $.debug - COMMAND ${OBJCOPY} --strip-debug $ - COMMAND ${OBJCOPY} --add-gnu-debuglink=$.debug $ - ) - endif() - endif() + # if(CMAKE_COMPILER_IS_GNUCC) + # if(${CMAKE_BUILD_TYPE} MATCHES Debug) + # message(STATUS "Will make separate debug symbols in *.debug") + # add_custom_command(TARGET SRB2SDL2 POST_BUILD + # COMMAND ${OBJCOPY} --only-keep-debug $ $.debug + # COMMAND ${OBJCOPY} --strip-debug $ + # COMMAND ${OBJCOPY} --add-gnu-debuglink=$.debug $ + # ) + # endif() + # endif() #### Installation #### if(${CMAKE_SYSTEM} MATCHES Darwin) -- 2.54.0 From cf9ac98ffde28466b254d2e04f36014b0bcaec50 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 3 Aug 2023 11:17:04 +0300 Subject: [PATCH 3/3] Use realloc because reallocarray doesn't exist for some versions of C ;-; --- src/hu_stuff.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 97ac3c3a0..effb24837 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -438,8 +438,13 @@ static void Chatlogsize_OnChange(void) HU_removeChatText_Log(); } +// Some versons of C don't have reallocarray sadly +#define reallocarray(ptr, nmemb, size) realloc(ptr, (nmemb)*(size)) + // TODO - use z_zone allocators? chat_log = reallocarray(chat_log, cv_chatlogsize.value, sizeof(char*)); + +#undef reallocarray chat_nummsg_log = min(chat_nummsg_log, (UINT32)cv_chatlogsize.value); } #endif -- 2.54.0