From affea8b60e61696d863a9beab25da40c5b835f0b Mon Sep 17 00:00:00 2001 From: Matthew Coppola Date: Sat, 30 Nov 2024 20:29:11 -0500 Subject: [PATCH] Allow overriding g_TickRateDiv at runtime --- port/src/main.c | 2 ++ port/src/optionsmenu.c | 69 +++++++++++++++++++++++++++++++++++++++++- src/include/data.h | 1 + 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/port/src/main.c b/port/src/main.c index f8f6af13f..c745c0efb 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -36,6 +36,7 @@ u32 g_VmNumPageReplaces = 0; u8 g_VmShowStats = 0; s32 g_TickRateDiv = 1; +s32 g_TickRateDivOverride = 0; s32 g_TickExtraSleep = true; s32 g_SkipIntro = false; @@ -165,6 +166,7 @@ PD_CONSTRUCTOR static void gameConfigInit(void) configRegisterInt("Game.MenuMouseControl", &g_MenuMouseControl, 0, 1); configRegisterFloat("Game.ScreenShakeIntensity", &g_ViShakeIntensityMult, 0.f, 10.f); configRegisterInt("Game.TickRateDivisor", &g_TickRateDiv, 0, 10); + configRegisterInt("Game.TickRateDivisorOverride", &g_TickRateDivOverride, 0, 1); configRegisterInt("Game.ExtraSleep", &g_TickExtraSleep, 0, 1); configRegisterInt("Game.SkipIntro", &g_SkipIntro, 0, 1); configRegisterInt("Game.DisableMpDeathMusic", &g_MusicDisableMpDeath, 0, 1); diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index e26c8efcd..1d03bc169 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -775,7 +775,7 @@ static MenuItemHandlerResult menuhandlerFramerateLimit(s32 operation, struct men data->slider.value = videoGetFramerateLimit(); break; case MENUOP_SET: - if (g_TickRateDiv < 2) { + if (!g_TickRateDivOverride) { g_TickRateDiv = (data->slider.value == 0 || data->slider.value > 60) ? 0 : 1; } videoSetFramerateLimit(data->slider.value); @@ -960,6 +960,49 @@ static MenuItemHandlerResult menuhandlerGeMuzzleFlashes(s32 operation, struct me return 0; } +static MenuItemHandlerResult menuhandlerTickrateDivisorOverride(s32 operation, struct menuitem *item, union handlerdata *data) +{ + s32 framerateLimit; + + switch (operation) { + case MENUOP_GET: + return g_TickRateDivOverride; + case MENUOP_SET: + g_TickRateDivOverride = data->checkbox.value; + if (!g_TickRateDivOverride) { + framerateLimit = videoGetFramerateLimit(); + g_TickRateDiv = (framerateLimit == 0 || framerateLimit > 60) ? 0 : 1; + } + } + + return 0; +} + +static MenuItemHandlerResult menuhandlerTickrateDivisor(s32 operation, struct menuitem *item, union handlerdata *data) +{ + s32 framerateLimit; + + switch (operation) { + case MENUOP_CHECKHIDDEN: + if (!g_TickRateDivOverride) { + return true; + } + break; + case MENUOP_GETSLIDER: + data->slider.value = g_TickRateDiv; + break; + case MENUOP_SET: + if (g_TickRateDivOverride) { + g_TickRateDiv = data->slider.value; + } else { + framerateLimit = videoGetFramerateLimit(); + g_TickRateDiv = (framerateLimit == 0 || framerateLimit > 60) ? 0 : 1; + } + } + + return 0; +} + static MenuItemHandlerResult menuhandlerCenterHUD(s32 operation, struct menuitem *item, union handlerdata *data) { static const char *opts[] = { @@ -1169,6 +1212,30 @@ struct menuitem g_ExtendedVideoMenuItems[] = { 0, NULL, }, + { + MENUITEMTYPE_CHECKBOX, + 0, + MENUITEMFLAG_LITERAL_TEXT, + (uintptr_t)"Override Tickrate Divisor", + 0, + menuhandlerTickrateDivisorOverride, + }, + { + MENUITEMTYPE_SLIDER, + 0, + MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE, + (uintptr_t)"Tickrate Divisor", + 10, + menuhandlerTickrateDivisor, + }, + { + MENUITEMTYPE_SEPARATOR, + 0, + 0, + 0, + 0, + NULL, + }, { MENUITEMTYPE_SELECTABLE, 0, diff --git a/src/include/data.h b/src/include/data.h index 24c106292..6a5148ca0 100644 --- a/src/include/data.h +++ b/src/include/data.h @@ -550,6 +550,7 @@ extern s32 g_BlurFb; extern s32 g_BlurFbCapTimer; extern bool g_BlurFbDirty; extern s32 g_TickRateDiv; +extern s32 g_TickRateDivOverride; extern s32 g_TickExtraSleep; extern s32 g_MusicDisableMpDeath; extern s32 g_BgunGeMuzzleFlashes;