From 49aaa2525502d9f9cbd6b17da0962b48d7fd2115 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Thu, 16 Nov 2023 22:52:56 -0500 Subject: [PATCH 1/9] Mouse Controls for saturn --- src/d_netcmd.c | 2 ++ src/d_netcmd.h | 2 ++ src/g_game.c | 4 ++-- src/k_kart.c | 3 +++ src/m_menu.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index eb246a199..e483d846d 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -301,6 +301,8 @@ INT32 cv_debug; consvar_t cv_usemouse = {"use_mouse", "Off", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usemouse2 = {"use_mouse2", "Off", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse2, 0, NULL, NULL, 0, 0, NULL}; +//WTF +consvar_t cv_mouseturn = {"mouseturn", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; #if defined(HAVE_SDL) || defined(_WINDOWS) //joystick 1 and 2 consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 9b6d99b25..e21fdbb6f 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -41,6 +41,8 @@ extern consvar_t cv_splitplayers; extern consvar_t cv_seenames, cv_allowseenames; #endif extern consvar_t cv_usemouse; +//WTF +extern consvar_t cv_mouseturn; extern consvar_t cv_usejoystick; extern consvar_t cv_usejoystick2; extern consvar_t cv_usejoystick3; diff --git a/src/g_game.c b/src/g_game.c index b4dfbf074..2a482bfaa 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1427,9 +1427,9 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer) side += ((axis * sidemove[0]) >> 10); } - // Specator mouse turning - if (player->spectator) + if (player->spectator || cv_mouseturn.value) { + //THIS WORKS WTF???????? cmd->angleturn = (INT16)(cmd->angleturn - ((mousex*(encoremode ? -1 : 1)*8))); cmd->driftturn = (INT16)(cmd->driftturn - ((mousex*(encoremode ? -1 : 1)*8))); } diff --git a/src/k_kart.c b/src/k_kart.c index 98e4e8e27..387979682 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -720,6 +720,9 @@ void K_RegisterKartStuff(void) CV_RegisterVar(&cv_stagetitle); CV_RegisterVar(&cv_lessflicker); + + CV_RegisterVar(&cv_mouseturn); + } //} diff --git a/src/m_menu.c b/src/m_menu.c index c5c3249f9..8b5597dad 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1166,9 +1166,11 @@ static menuitem_t OP_ControlsMenu[] = {IT_CALL | IT_STRING, NULL, "Player 3 Controls...", &M_Setup3PControlsMenu, 30}, {IT_CALL | IT_STRING, NULL, "Player 4 Controls...", &M_Setup4PControlsMenu, 40}, + + {IT_SUBMENU | IT_STRING, NULL, "Mouse Options...", &OP_MouseOptionsDef, 60}, - {IT_STRING | IT_CVAR, NULL, "Controls per key", &cv_controlperkey, 60}, - {IT_STRING | IT_CVAR, NULL, "Digital turn easing", &cv_turnsmooth, 70}, + {IT_STRING | IT_CVAR, NULL, "Controls per key", &cv_controlperkey, 80}, + {IT_STRING | IT_CVAR, NULL, "Digital turn easing", &cv_turnsmooth, 90}, }; static const char* OP_ControlsTooltips[] = @@ -1179,6 +1181,9 @@ static const char* OP_ControlsTooltips[] = "Setup player 3 controls.", "Setup player 4 controls.", + "Options for mouse control.", + + "Allowed amount of controls per key.", "Turn smoothing for non-analog turning.", @@ -1298,22 +1303,34 @@ static menuitem_t OP_JoystickSetMenu[] = {IT_CALL | IT_NOTHING, "", NULL, M_AssignJoystick, (LINEHEIGHT*8)+5}, }; -/*static menuitem_t OP_MouseOptionsMenu[] = +//WTF +static menuitem_t OP_MouseOptionsMenu[] = { {IT_STRING | IT_CVAR, NULL, "Use Mouse", &cv_usemouse, 10}, - {IT_STRING | IT_CVAR, NULL, "First-Person MouseLook", &cv_alwaysfreelook, 30}, - {IT_STRING | IT_CVAR, NULL, "Third-Person MouseLook", &cv_chasefreelook, 40}, - {IT_STRING | IT_CVAR, NULL, "Mouse Move", &cv_mousemove, 50}, - {IT_STRING | IT_CVAR, NULL, "Invert Mouse", &cv_invertmouse, 60}, + //{IT_STRING | IT_CVAR, NULL, "First-Person MouseLook", &cv_alwaysfreelook, 30}, + //{IT_STRING | IT_CVAR, NULL, "Third-Person MouseLook", &cv_chasefreelook, 40}, + {IT_STRING | IT_CVAR, NULL, "Mouse Turning", &cv_mouseturn, 20}, + {IT_STRING | IT_CVAR, NULL, "Invert Mouse", &cv_invertmouse, 30}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, - NULL, "Mouse X Speed", &cv_mousesens, 70}, + NULL, "Mouse X Speed", &cv_mousesens, 40}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, - NULL, "Mouse Y Speed", &cv_mouseysens, 80}, + NULL, "Mouse Y Speed", &cv_mouseysens, 50}, }; -static menuitem_t OP_Mouse2OptionsMenu[] = +static const char* OP_MouseTooltips[] = +{ + + "Enable the use of the mouse.", + "Turn using the mouse.", + "Invert mouse movements.", + "Mouse horizontal sensitivity.", + "Mouse vertical sensitivity.", + +}; + +/*static menuitem_t OP_Mouse2OptionsMenu[] = { {IT_STRING | IT_CVAR, NULL, "Use Mouse 2", &cv_usemouse2, 10}, {IT_STRING | IT_CVAR, NULL, "Second Mouse Serial Port", @@ -2648,6 +2665,8 @@ menu_t OP_MainDef = }; menu_t OP_ControlsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_ControlsMenu, &OP_MainDef, 60, 30); +//WTF +menu_t OP_MouseOptionsDef = DEFAULTMENUSTYLE("M_CONTRO", OP_MouseOptionsMenu, &OP_ControlsDef, 60, 30); menu_t OP_AllControlsDef = CONTROLMENUSTYLE(OP_AllControlsMenu, &OP_ControlsDef); menu_t OP_Joystick1Def = DEFAULTMENUSTYLE("M_CONTRO", OP_Joystick1Menu, &OP_AllControlsDef, 60, 30); menu_t OP_Joystick2Def = DEFAULTMENUSTYLE("M_CONTRO", OP_Joystick2Menu, &OP_AllControlsDef, 60, 30); @@ -4866,6 +4885,15 @@ static void M_DrawGenericMenu(void) } } + if (currentMenu == &OP_MouseOptionsDef) + { + if (!(OP_MouseTooltips[itemOn] == NULL)) + { + M_DrawSplitText(BASEVIDWIDTH / 2, BASEVIDHEIGHT-50, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, OP_MouseTooltips[itemOn], 30, coolalphatimer); + if (coolalphatimer > 0 && interpTimerHackAllow) + coolalphatimer--; + } + } if (currentMenu == &OP_VideoOptionsDef) { From 10953dbb3ad065fe6018fe4c14a83d665302b036 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Fri, 17 Nov 2023 20:29:07 +0100 Subject: [PATCH 2/9] add toggle to hide player ip addresses in nodes or listplayers command also add "listplayers" command, which is pretty much the same as "nodes" but with colors and it looks better tho kept "nodes" command just in case its needed for smth --- src/d_clisrv.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++- src/d_clisrv.h | 2 ++ src/d_netcmd.c | 1 + src/m_menu.c | 7 ++-- 4 files changed, 100 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 18f914200..c3dba1690 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -171,6 +171,8 @@ static textcmdtic_t *textcmds[TEXTCMD_HASH_SIZE] = {NULL}; consvar_t cv_showjoinaddress = {"showjoinaddress", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_shownodeip = {"showipinnodelist", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t playbackspeed_cons_t[] = {{1, "MIN"}, {10, "MAX"}, {0, NULL}}; consvar_t cv_playbackspeed = {"playbackspeed", "1", 0, playbackspeed_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -3346,7 +3348,7 @@ static void Command_Nodes(void) { CONS_Printf("%.2u: %*s", i, (int)maxlen, player_names[i]); CONS_Printf(" - %.2d", playernode[i]); - if (I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL) + if ((I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL) && (cv_shownodeip.value)) CONS_Printf(" - %s", address); if (IsPlayerAdmin(i)) @@ -3360,6 +3362,94 @@ static void Command_Nodes(void) } } +//Screw the base game nodes lets replace with listplayers instead. +static void Command_Listplayers(void) +{ + const char *address; + int width = 0; + + boolean admin; + boolean spectator; + + /* + Mode of player status for an individual player (admin, spectator). + 1 for admin + 2 for spectator + 4 for both + */ + int mode = 0; + + INT32 totalplayers = 0; + + const char *cc; + const char *pcc; + + INT32 i; + int n; + + for (i = 0; i < MAXPLAYERS; ++i) + if (playeringame[i]) + { + n = strlen(player_names[i]); + if (n > width) + width = n; + + if (mode != 7) + { + admin = IsPlayerAdmin(i); + spectator = players[i].spectator; + + if (admin) + mode |= 1; + if (spectator) + mode |= 2; + if (admin && spectator) + mode |= 4; + } + } + + for (i = 0; i < MAXPLAYERS; ++i) + if (playeringame[i]) + { + admin = IsPlayerAdmin(i); + spectator = players[i].spectator; + + if (admin) + cc = "\x85";/* red */ + else if (spectator) + cc = "\x86";/* gray */ + else + cc = ""; + + pcc = HU_SkinColorToConsoleColor(players[i].skincolor); + + CONS_Printf("%.2d: ""%s""%-*s""\x80", i, pcc,width, player_names[i]); + + if ((I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL) && (cv_shownodeip.value)) + CONS_Printf(" -- %s", address); + else/* print spacer */ + { + /* ...but not if there's a crammed status and were admin */ + if (mode != 7 || !admin) + CONS_Printf(" -- ");/* -- self */ + } + + if (admin) + CONS_Printf(M_GetText("%s"" (admin)"),cc); + if (spectator) + CONS_Printf(M_GetText("%s"" (spectator)"),cc); + + CONS_Printf("\n"); + + totalplayers++; + } + + if (totalplayers == 1) + CONS_Printf("\nThere is 1 player in the game.\n"); + else + CONS_Printf("\nThere are %d players in the game.\n", totalplayers); +} + static void Command_Ban(void) { if (COM_Argc() < 2) @@ -3925,6 +4015,7 @@ void D_ClientServerInit(void) COM_AddCommand("reloadbans", Command_ReloadBan); COM_AddCommand("connect", Command_connect); COM_AddCommand("nodes", Command_Nodes); + COM_AddCommand("listplayers", Command_Listplayers); #ifdef HAVE_CURL COM_AddCommand("set_http_login", Command_set_http_login); COM_AddCommand("list_http_logins", Command_list_http_logins); diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 65fd3c9a9..b1bc9ffcc 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -515,6 +515,8 @@ extern consvar_t cv_kicktime; extern consvar_t cv_showjoinaddress; extern consvar_t cv_playbackspeed; +extern consvar_t cv_shownodeip; + #define BASEPACKETSIZE offsetof(doomdata_t, u) #define FILETXHEADER offsetof(filetx_pak, data) #define BASESERVERTICSSIZE offsetof(doomdata_t, u.serverpak.cmds[0]) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index e483d846d..389c91a60 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -776,6 +776,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_joinnextround); #endif CV_RegisterVar(&cv_showjoinaddress); + CV_RegisterVar(&cv_shownodeip); CV_RegisterVar(&cv_blamecfail); #endif diff --git a/src/m_menu.c b/src/m_menu.c index 8b5597dad..ebd6b8971 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1749,8 +1749,10 @@ static menuitem_t OP_ChatOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Max Chat Messages", &cv_chatlogsize, 80}, {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 100}, // shows ping next to framerate if we want to. - {IT_STRING | IT_CVAR, NULL, "Ping measurement", &cv_pingmeasurement, 110}, - {IT_STRING | IT_CVAR, NULL, "Ping icon", &cv_pingicon, 120}, + {IT_STRING | IT_CVAR, NULL, "Ping measurement", &cv_pingmeasurement, 110}, + {IT_STRING | IT_CVAR, NULL, "Ping icon", &cv_pingicon, 120}, + + {IT_STRING | IT_CVAR, NULL, "Show IP addresses in playerlist", &cv_shownodeip, 140}, }; static const char* OP_ChatOptionsTooltips[] = @@ -1765,6 +1767,7 @@ static const char* OP_ChatOptionsTooltips[] = "Show player ping.", "Measurement used for ping.", "Visibility of ping icon.", + "Should Player IP addresses be printed when using\nthe nodes or listplayers command?", }; static menuitem_t OP_GameOptionsMenu[] = From 16f8299c4a814d4ecc78194b25694ee2d3fb5139 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 17 Nov 2023 20:48:27 +0100 Subject: [PATCH 3/9] fix admin menu stuff uuuuhhh --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index ebd6b8971..edc6460a0 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -4064,7 +4064,7 @@ void M_StartControlPanel(void) Dummymenuplayer_OnChange(); - if (server) + if ((server || IsPlayerAdmin(consoleplayer))) { MPauseMenu[mpause_switchmap].status = IT_STRING | IT_CALL; MPauseMenu[mpause_addons].status = IT_STRING | IT_CALL; From cc408cc859b3d8044ff3bf330327efa6df38da1c Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 17 Nov 2023 23:28:53 +0100 Subject: [PATCH 4/9] fix not being able to close warning screen when a mod spams warnings lmao --- src/m_menu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index edc6460a0..8fc8b91d1 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6155,6 +6155,8 @@ static void M_AddonsClearName(INT32 choice) M_StopMessage(choice); } +int errorshitspam = 0; // prevent the warning screen from crapping itself when errors get spammed lmao + // returns whether to do message draw static boolean M_AddonsRefresh(void) { @@ -6183,10 +6185,11 @@ static boolean M_AddonsRefresh(void) else message = va("%c%s\x80\nA file was not loaded.\nCheck the console log for more information.\n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), refreshdirname); } - else if (refreshdirmenu & (REFRESHDIR_WARNING|REFRESHDIR_ERROR)) + else if ((refreshdirmenu & (REFRESHDIR_WARNING | REFRESHDIR_ERROR)) && !errorshitspam) { S_StartSound(NULL, sfx_s224); message = va("%c%s\x80\nA file was loaded with %s.\nCheck the console log for more information.\n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), refreshdirname, ((refreshdirmenu & REFRESHDIR_ERROR) ? "errors" : "warnings")); + errorshitspam = 1; // you already said that shit } else if (majormods && !prevmajormods) { @@ -6529,12 +6532,16 @@ static void M_HandleAddons(INT32 choice) if (DumbStartsWith("KC_", dirmenu[dir_on[menudepthleft]]+DIR_STRING) || DumbStartsWith("kc_", dirmenu[dir_on[menudepthleft]]+DIR_STRING)) { M_StartMessage(va("%c%s\x80\nYou are loading a local skin.\nLocal skins will not be usable\nafter going back from\nthe title screen.\n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), dirmenu[dir_on[menudepthleft]]+DIR_STRING),NULL,MM_NOTHING); COM_BufAddText(va("addskins \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); + errorshitspam = 0; // reset it so it can show the warning screen again lmao } else S_StartSound(NULL, sfx_s26d); } else + { COM_BufAddText(va("addfile \"%s%s\"", menupath, dirmenu[dir_on[menudepthleft]]+DIR_STRING)); + errorshitspam = 0; // reset it so it can show the warning screen again lmao + } break; default: S_StartSound(NULL, sfx_s26d); From ec1123251fdebf003d1cc93af0ec55efbe86d8ef Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 17 Nov 2023 23:45:17 +0100 Subject: [PATCH 5/9] fix sliptide toggle for 3d models --- src/hardware/hw_md2.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 140c42c1f..ab015d862 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1366,15 +1366,19 @@ void HWR_DrawMD2(gr_vissprite_t *spr) angle_t sliptideroll = 0; if (spr->mobj->player) - sliptideroll = ((cv_sloperoll.value) ? spr->mobj->player->sliproll : 0); + sliptideroll = ((cv_sloperoll.value && cv_sliptideroll.value) ? spr->mobj->player->sliproll : 0); - if ((spr->mobj->rollangle)||sliptideroll) + if ((spr->mobj->rollangle)||(sliptideroll && cv_sliptideroll.value)) { angle_t rollang = 0; rollfactor = ((spr->mobj->rollmodel == true) ? 1 : 0); - if (spr->mobj->player) - rollang = (spr->mobj->rollangle*rollfactor) + (sliptideroll*spr->mobj->player->sliptidemem); + if (spr->mobj->player){ + if (sliptideroll && cv_sliptideroll.value) + rollang = (spr->mobj->rollangle*rollfactor) + (sliptideroll*spr->mobj->player->sliptidemem); + else + rollang = (spr->mobj->rollangle*rollfactor); + } else rollang = (spr->mobj->rollangle*rollfactor); @@ -1423,7 +1427,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) HWD.pfnSetShader(4); // model shader { - float this_scale = FIXED_TO_FLOAT(interp.scale); + float this_scale = FIXED_TO_FLOAT(interp.scale); float xs = this_scale * FIXED_TO_FLOAT(interp.spritexscale); float ys = this_scale * FIXED_TO_FLOAT(interp.spriteyscale); From 7a2f925078affc7e983f0aa5a66764977d06e425 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Sat, 18 Nov 2023 05:09:45 +0100 Subject: [PATCH 6/9] Make module music volume more accurate from https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2215 --- src/sdl/mixer_sound.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 57072ee3c..ad894895f 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -696,8 +696,8 @@ static void mix_gme(void *udata, Uint8 *stream, int len) music_volume = 18; // apply volume to stream - for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * (music_volume*internal_volume/100)*2 / 40; + for (i = 0, p = (short *)stream; i < len / 2; i++, p++) + *p = ((INT32)*p) * music_volume * internal_volume / 100 / 20; } #endif @@ -721,8 +721,8 @@ static void mix_openmpt(void *udata, Uint8 *stream, int len) music_volume = 18; // apply volume to stream - for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * (music_volume*internal_volume/100)*2 / 40; + for (i = 0, p = (short *)stream; i < len / 2; i++, p++) + *p = ((INT32)*p) * music_volume * internal_volume / 100 / 20; } #endif From 78018e1f78f39bbc0bd32ed3c25559c5b5231eed Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Sat, 18 Nov 2023 05:13:04 +0100 Subject: [PATCH 7/9] I_SetSongTrack(int) should be I_SetSongTrack(INT32) https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2213 --- src/dummy/i_sound.c | 2 +- src/sdl/mixer_sound.c | 2 +- src/sdl/sdl_sound.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index f09158e01..ff01bdff0 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -169,7 +169,7 @@ void I_SetMusicVolume(UINT8 volume) (void)volume; } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { (void)track; return false; diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index ad894895f..ce9a8b12f 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -1375,7 +1375,7 @@ void I_SetMusicVolume(UINT8 volume) Mix_VolumeMusic(get_real_volume(music_volume)); } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { #ifdef HAVE_LIBGME diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 5c93642bd..2f8fa7b5d 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1476,7 +1476,7 @@ void I_SetMusicVolume(UINT8 volume) (void)volume; } -boolean I_SetSongTrack(int track) +boolean I_SetSongTrack(INT32 track) { (void)track; return false; From 0b4e70faf367127af32a236abac59130c3e21d57 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Fri, 17 Nov 2023 23:48:04 -0500 Subject: [PATCH 8/9] perfstats for PreThinkFrame and PostThinkFrame plus small rewrite --- src/d_netcmd.c | 2 +- src/lua_hooklib.c | 75 ++++++++++++------ src/m_perfstats.c | 196 ++++++++++++++++++++++++++++++++++++++++------ src/m_perfstats.h | 5 ++ src/p_tick.c | 7 ++ 5 files changed, 236 insertions(+), 49 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 389c91a60..ec2b71271 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -511,7 +511,7 @@ static CV_PossibleValue_t skinselectspin_cons_t[] = { consvar_t cv_skinselectspin = {"skinselectspin", "5", CV_SAVE, skinselectspin_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t perfstats_cons_t[] = { - {0, "Off"}, {1, "Rendering"}, {2, "Logic"}, {3, "ThinkFrame"}, {0, NULL}}; + {0, "Off"}, {1, "Rendering"}, {2, "Logic"}, {3, "ThinkFrame"}, {4, "PreThinkFrame"}, {5, "PostThinkFrame"}, {0, NULL}}; consvar_t cv_perfstats = {"perfstats", "Off", CV_CALL, perfstats_cons_t, PS_PerfStats_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_ps_thinkframe_page = {"ps_thinkframe_page", "1", CV_CALL, CV_Natural, PS_ThinkFrame_Page_OnChange, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index d9344f65f..1e6a5cb29 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -430,6 +430,9 @@ void LUAh_PlayerJoin(int playernum) void LUAh_PreThinkFrame(void) { hook_p hookp; + // variables used by perf stats + int hook_index = 0; + precise_t time_taken = 0; if (!gL || !(hooksAvailable[hook_PreThinkFrame/8] & (1<<(hook_PreThinkFrame%8)))) return; @@ -437,19 +440,32 @@ void LUAh_PreThinkFrame(void) for (hookp = roothook; hookp; hookp = hookp->next) { - if (hookp->type != hook_PreThinkFrame) - continue; - - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); - if (lua_pcall(gL, 0, 0, 1)) { - if (!hookp->error || cv_debug & DBG_LUA) - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); - hookp->error = true; + if (hookp->type == hook_PreThinkFrame) + { + if (cv_perfstats.value == 4) + time_taken = I_GetPreciseTime(); + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + if (lua_pcall(gL, 0, 0, 1)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + } + if (cv_perfstats.value == 4) + { + lua_Debug ar; + time_taken = I_GetPreciseTime() - time_taken; + // we need the function, let's just retrieve it again + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_getinfo(gL, ">S", &ar); + PS_SetPreThinkFrameHookInfo(hook_index, time_taken, ar.short_src); + hook_index++; + } } - } + } lua_pop(gL, 1); // Pop error handler } @@ -498,6 +514,9 @@ void LUAh_ThinkFrame(void) void LUAh_PostThinkFrame(void) { hook_p hookp; + // variables used by perf stats + int hook_index = 0; + precise_t time_taken = 0; if (!gL || !(hooksAvailable[hook_PostThinkFrame/8] & (1<<(hook_PostThinkFrame%8)))) return; @@ -505,19 +524,31 @@ void LUAh_PostThinkFrame(void) for (hookp = roothook; hookp; hookp = hookp->next) { - if (hookp->type != hook_PostThinkFrame) - continue; - - lua_pushfstring(gL, FMT_HOOKID, hookp->id); - lua_gettable(gL, LUA_REGISTRYINDEX); - if (lua_pcall(gL, 0, 0, 1)) { - if (!hookp->error || cv_debug & DBG_LUA) - CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); - lua_pop(gL, 1); - hookp->error = true; + if (hookp->type == hook_PostThinkFrame) + { + if (cv_perfstats.value == 5) + time_taken = I_GetPreciseTime(); + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + if (lua_pcall(gL, 0, 0, 1)) { + if (!hookp->error || cv_debug & DBG_LUA) + CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); + lua_pop(gL, 1); + hookp->error = true; + } + if (cv_perfstats.value == 5) + { + lua_Debug ar; + time_taken = I_GetPreciseTime() - time_taken; + // we need the function, let's just retrieve it again + lua_pushfstring(gL, FMT_HOOKID, hookp->id); + lua_gettable(gL, LUA_REGISTRYINDEX); + lua_getinfo(gL, ">S", &ar); + PS_SetPostThinkFrameHookInfo(hook_index, time_taken, ar.short_src); + hook_index++; + } } } - lua_pop(gL, 1); // Pop error handler } diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 11c0414b0..937635536 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -63,7 +63,10 @@ static ps_metric_t ps_removecount = {0}; ps_metric_t ps_checkposition_calls = {0}; +ps_metric_t ps_lua_prethinkframe_time = {0}; ps_metric_t ps_lua_thinkframe_time = {0}; +ps_metric_t ps_lua_postthinkframe_time = {0}; + ps_metric_t ps_lua_mobjhooks = {0}; ps_metric_t ps_otherlogictime = {0}; @@ -156,7 +159,9 @@ perfstatrow_t gamelogic_rows[] = { {" mobjs ", " Mobjs: ", &ps_thlist_times[THINK_MOBJ], PS_TIME|PS_LEVEL}, {" dynslop", " Dynamic slopes: ", &ps_thlist_times[THINK_DYNSLOPE], PS_TIME|PS_LEVEL}, {" precip ", " Precipitation: ", &ps_thlist_times[THINK_PRECIP], PS_TIME|PS_LEVEL},*/ + {" lprethinkf", " LUAh_PreThinkFrame:", &ps_lua_prethinkframe_time, PS_TIME|PS_LEVEL}, {" lthinkf", " LUAh_ThinkFrame:", &ps_lua_thinkframe_time, PS_TIME|PS_LEVEL}, + {" lpostthinkf", " LUAh_PostThinkFrame:", &ps_lua_postthinkframe_time, PS_TIME|PS_LEVEL}, {" other ", " Other: ", &ps_otherlogictime, PS_TIME|PS_LEVEL}, {0} }; @@ -189,10 +194,43 @@ int ps_frame_index = 0; int ps_tick_index = 0; // dynamically allocated resizeable array for thinkframe hook stats +ps_hookinfo_t *prethinkframe_hooks = NULL; +int prethinkframe_hooks_length = 0; +int prethinkframe_hooks_capacity = 16; + ps_hookinfo_t *thinkframe_hooks = NULL; int thinkframe_hooks_length = 0; int thinkframe_hooks_capacity = 16; +ps_hookinfo_t *postthinkframe_hooks = NULL; +int postthinkframe_hooks_length = 0; +int postthinkframe_hooks_capacity = 16; + +void PS_SetPreThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) +{ + if (!prethinkframe_hooks) + { + // array needs to be initialized + prethinkframe_hooks = Z_Calloc(sizeof(ps_hookinfo_t) * prethinkframe_hooks_capacity, PU_STATIC, NULL); + } + if (index >= prethinkframe_hooks_capacity) + { + // array needs more space, realloc with double size + int new_capacity = prethinkframe_hooks_capacity * 2; + prethinkframe_hooks = Z_Realloc(prethinkframe_hooks, + sizeof(ps_hookinfo_t) * new_capacity, PU_STATIC, NULL); + // initialize new memory with zeros so the pointers in the structs are null + memset(&prethinkframe_hooks[prethinkframe_hooks_capacity], 0, + sizeof(ps_hookinfo_t) * prethinkframe_hooks_capacity); + prethinkframe_hooks_capacity = new_capacity; + } + prethinkframe_hooks[index].time_taken.value.p = time_taken; + memcpy(prethinkframe_hooks[index].short_src, short_src, LUA_IDSIZE * sizeof(char)); + // since the values are set sequentially from begin to end, the last call should leave + // the correct value to this variable + prethinkframe_hooks_length = index + 1; +} + void PS_SetThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) { if (!thinkframe_hooks) @@ -218,6 +256,33 @@ void PS_SetThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) thinkframe_hooks_length = index + 1; } +void PS_SetPostThinkFrameHookInfo(int index, precise_t time_taken, char* short_src) +{ + if (!postthinkframe_hooks) + { + // array needs to be initialized + postthinkframe_hooks = Z_Calloc(sizeof(ps_hookinfo_t) * postthinkframe_hooks_capacity, PU_STATIC, NULL); + } + if (index >= postthinkframe_hooks_capacity) + { + // array needs more space, realloc with double size + int new_capacity = postthinkframe_hooks_capacity * 2; + postthinkframe_hooks = Z_Realloc(postthinkframe_hooks, + sizeof(ps_hookinfo_t) * new_capacity, PU_STATIC, NULL); + // initialize new memory with zeros so the pointers in the structs are null + memset(&postthinkframe_hooks[postthinkframe_hooks_capacity], 0, + sizeof(ps_hookinfo_t) * postthinkframe_hooks_capacity); + postthinkframe_hooks_capacity = new_capacity; + } + postthinkframe_hooks[index].time_taken.value.p = time_taken; + memcpy(postthinkframe_hooks[index].short_src, short_src, LUA_IDSIZE * sizeof(char)); + // since the values are set sequentially from begin to end, the last call should leave + // the correct value to this variable + postthinkframe_hooks_length = index + 1; +} + + + static boolean PS_HighResolution(void) { return (vid.width >= 640 && vid.height >= 400); @@ -578,7 +643,11 @@ void PS_UpdateTickStats(void) ps_tictime.value.p - ps_playerthink_time.value.p - ps_thinkertime.value.p - - ps_lua_thinkframe_time.value.p; + ps_lua_prethinkframe_time.value.p - + ps_lua_thinkframe_time.value.p - + ps_lua_postthinkframe_time.value.p; + + PS_CountThinkers(); } @@ -590,21 +659,37 @@ void PS_UpdateTickStats(void) PS_UpdateRowHistories(misc_calls_rows, false); } } - if (cv_perfstats.value == 3 && cv_ps_samplesize.value > 1 && PS_IsLevelActive()) + if (cv_ps_samplesize.value > 1) { - int i; - for (i = 0; i < thinkframe_hooks_length; i++) + if(cv_perfstats.value >= 3 && PS_IsLevelActive()) { - PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false, false); + int i; + if (cv_perfstats.value == 3) + { + for (i = 0; i < thinkframe_hooks_length; i++) + PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false, false); + } + else if (cv_perfstats.value == 4) + { + for (i = 0; i < prethinkframe_hooks_length; i++) + PS_UpdateMetricHistory(&prethinkframe_hooks[i].time_taken, true, false, false); + } + else if (cv_perfstats.value == 5) + { + for (i = 0; i < postthinkframe_hooks_length; i++) + PS_UpdateMetricHistory(&postthinkframe_hooks[i].time_taken, true, false, false); + } } - } - if (cv_perfstats.value && cv_ps_samplesize.value > 1) - { - ps_tick_index++; - if (ps_tick_index >= cv_ps_samplesize.value) - ps_tick_index = 0; - if (ps_tick_samples_left) - ps_tick_samples_left--; + if (cv_perfstats.value) + { + ps_tick_index++; + if (ps_tick_index >= cv_ps_samplesize.value) + ps_tick_index = 0; + if (ps_tick_samples_left) + ps_tick_samples_left--; + + } + } } @@ -624,7 +709,7 @@ static void PS_DrawDescriptorHeader(void) int samples_left = max(ps_frame_samples_left, ps_tick_samples_left); int x, y; - if (cv_perfstats.value == 3) + if (cv_perfstats.value >= 3) { x = 2; y = 0; @@ -717,21 +802,20 @@ static void PS_DrawGameLogicStats(void) #define WIDTH 106 #define HEIGHT 4 #define MAX_X 214 -#define MAX_Y 192 +#define MAX_Y 182 #define START_X 2 #define START_Y 4 #define PAGE_ENTRIES ((MAX_Y - START_Y) / HEIGHT) -static void PS_DrawThinkFrameStats(void) +static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) { char s[100]; int i; - int maxpage = thinkframe_hooks_length/PAGE_ENTRIES + 1; + int maxpage = 0; int page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); - - int pagestart = min((page - 1)*PAGE_ENTRIES, thinkframe_hooks_length); - int pageend = min(pagestart + PAGE_ENTRIES, thinkframe_hooks_length); + int pagestart = 0; + int pageend = 0; // text writing position int x = START_X; int y = START_Y; @@ -741,19 +825,41 @@ static void PS_DrawThinkFrameStats(void) last_mod_name[0] = '\0'; INT32 total = 0; + //Decide page length based and drawn text on choosen thinker type + if (cv_perfstats.value == 3){ + maxpage = thinkframe_hooks_length/PAGE_ENTRIES + 1; + pagestart = min((page - 1)*PAGE_ENTRIES, thinkframe_hooks_length); + pageend = min(pagestart + PAGE_ENTRIES, thinkframe_hooks_length); + + V_DrawSmallString(MAX_X-50, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "ThinkFrame"); + } + else if (cv_perfstats.value == 4){ + maxpage = prethinkframe_hooks_length/PAGE_ENTRIES + 1; + pagestart = min((page - 1)*PAGE_ENTRIES, prethinkframe_hooks_length); + pageend = min(pagestart + PAGE_ENTRIES, prethinkframe_hooks_length); + V_DrawSmallString(MAX_X-60, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "PreThinkFrame"); + } + else if (cv_perfstats.value == 5){ + maxpage = postthinkframe_hooks_length/PAGE_ENTRIES + 1; + pagestart = min((page - 1)*PAGE_ENTRIES, postthinkframe_hooks_length); + pageend = min(pagestart + PAGE_ENTRIES, postthinkframe_hooks_length); + V_DrawSmallString(MAX_X-65, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "PostThinkFrame"); + + } + PS_DrawDescriptorHeader(); - for (i = 0; i < thinkframe_hooks_length; i++) + for (i = 0; i < hook_length; i++) { #define NEXT_ROW() y += HEIGHT; - INT32 value = PS_GetMetricScreenValue(&thinkframe_hooks[i].time_taken, true); + INT32 value = PS_GetMetricScreenValue(&hook[i].time_taken, true); total += value; if (i < pagestart || i >= pageend) continue; - char* str = thinkframe_hooks[i].short_src; + char* str = hook[i].short_src; char* tempstr = tempbuffer; int len = (int)strlen(str); char* str_ptr; @@ -808,6 +914,8 @@ static void PS_DrawThinkFrameStats(void) snprintf(s, sizeof s - 1, "PAGE %d", page); V_DrawSmallString(START_X, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, s); } + + } void PS_ThinkFrame_Page_OnChange(void) @@ -828,6 +936,24 @@ void PS_ThinkFrame_Page_OnChange(void) #undef PAGE_ENTRIES + + +static void PS_DrawPreThinkFrameStats(void) +{ + draw_think_frame_stats(prethinkframe_hooks_length, prethinkframe_hooks); +} + +static void PS_DrawThinkFrameStats(void) +{ + draw_think_frame_stats(thinkframe_hooks_length, thinkframe_hooks); +} + +static void PS_DrawPostThinkFrameStats(void) +{ + draw_think_frame_stats(postthinkframe_hooks_length, postthinkframe_hooks); +} + + void M_DrawPerfStats(void) { if (cv_perfstats.value == 1) // rendering @@ -841,7 +967,7 @@ void M_DrawPerfStats(void) // tics when frame skips happen PS_DrawGameLogicStats(); } - else if (cv_perfstats.value == 3) // lua thinkframe + else if (cv_perfstats.value >= 3) // lua thinkframe { if (!PS_IsLevelActive()) return; @@ -850,13 +976,23 @@ void M_DrawPerfStats(void) // Low resolutions can't really use V_DrawSmallString that is used by thinkframe stats. // A low-res version using V_DrawThinString could be implemented, // but it would have much less space for information. - V_DrawThinString(80, 92, V_MONOSPACE | V_ALLOWLOWERCASE | V_YELLOWMAP, "Perfstats 3 is not available"); + V_DrawThinString(80, 92, V_MONOSPACE | V_ALLOWLOWERCASE | V_YELLOWMAP, "Lua Perfstats is not available"); V_DrawThinString(80, 100, V_MONOSPACE | V_ALLOWLOWERCASE | V_YELLOWMAP, "for resolutions below 640x400."); + return; } - else + if (cv_perfstats.value == 3) { PS_DrawThinkFrameStats(); } + else if (cv_perfstats.value == 4) + { + PS_DrawPreThinkFrameStats(); + } + else if (cv_perfstats.value == 5) + { + PS_DrawPostThinkFrameStats(); + } + } } @@ -867,10 +1003,18 @@ static void PS_ClearHistory(void) Z_FreeTags(PU_PERFSTATS, PU_PERFSTATS); // thinkframe hook metric history pointers need to be cleared manually + for (i = 0; i < prethinkframe_hooks_length; i++) + { + prethinkframe_hooks[i].time_taken.history = NULL; + } for (i = 0; i < thinkframe_hooks_length; i++) { thinkframe_hooks[i].time_taken.history = NULL; } + for (i = 0; i < postthinkframe_hooks_length; i++) + { + postthinkframe_hooks[i].time_taken.history = NULL; + } ps_frame_index = ps_tick_index = 0; // PS_UpdateMetricHistory will set these correctly when it runs diff --git a/src/m_perfstats.h b/src/m_perfstats.h index d9ce6d171..ade7efd33 100644 --- a/src/m_perfstats.h +++ b/src/m_perfstats.h @@ -44,12 +44,17 @@ extern ps_metric_t ps_thlist_times[]; extern ps_metric_t ps_checkposition_calls; +extern ps_metric_t ps_lua_prethinkframe_time; extern ps_metric_t ps_lua_thinkframe_time; +extern ps_metric_t ps_lua_postthinkframe_time; extern ps_metric_t ps_lua_mobjhooks; extern ps_metric_t ps_otherlogictime; +void PS_SetPreThinkFrameHookInfo(int index, precise_t time_taken, char* short_src); void PS_SetThinkFrameHookInfo(int index, precise_t time_taken, char* short_src); +void PS_SetPostThinkFrameHookInfo(int index, precise_t time_taken, char* short_src); + void PS_UpdateTickStats(void); diff --git a/src/p_tick.c b/src/p_tick.c index c3d12e77b..6bad0f856 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -662,7 +662,10 @@ void P_Ticker(boolean run) ps_checkposition_calls.value.i = 0; #ifdef HAVE_BLUA + PS_START_TIMING(ps_lua_prethinkframe_time); LUAh_PreThinkFrame(); + PS_STOP_TIMING(ps_lua_prethinkframe_time); + #endif PS_START_TIMING(ps_playerthink_time); @@ -823,7 +826,11 @@ void P_Ticker(boolean run) D_MapChange(gamemap, gametype, encoremode, true, 0, false, false); #ifdef HAVE_BLUA + + PS_START_TIMING(ps_lua_postthinkframe_time); LUAh_PostThinkFrame(); + PS_STOP_TIMING(ps_lua_postthinkframe_time); + #endif } From 84cc8d10a73213617580bc4a287b0e9e8d0a61fd Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sat, 18 Nov 2023 00:16:47 -0500 Subject: [PATCH 9/9] Quick bug fix for pages --- src/m_perfstats.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 937635536..04e51a657 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -813,7 +813,7 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) char s[100]; int i; int maxpage = 0; - int page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); + int page = 0; int pagestart = 0; int pageend = 0; // text writing position @@ -828,6 +828,7 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) //Decide page length based and drawn text on choosen thinker type if (cv_perfstats.value == 3){ maxpage = thinkframe_hooks_length/PAGE_ENTRIES + 1; + page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); pagestart = min((page - 1)*PAGE_ENTRIES, thinkframe_hooks_length); pageend = min(pagestart + PAGE_ENTRIES, thinkframe_hooks_length); @@ -835,12 +836,14 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) } else if (cv_perfstats.value == 4){ maxpage = prethinkframe_hooks_length/PAGE_ENTRIES + 1; + page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); pagestart = min((page - 1)*PAGE_ENTRIES, prethinkframe_hooks_length); pageend = min(pagestart + PAGE_ENTRIES, prethinkframe_hooks_length); V_DrawSmallString(MAX_X-60, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "PreThinkFrame"); } else if (cv_perfstats.value == 5){ maxpage = postthinkframe_hooks_length/PAGE_ENTRIES + 1; + page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); pagestart = min((page - 1)*PAGE_ENTRIES, postthinkframe_hooks_length); pageend = min(pagestart + PAGE_ENTRIES, postthinkframe_hooks_length); V_DrawSmallString(MAX_X-65, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "PostThinkFrame");