Skip to content

Commit

Permalink
Allow overriding g_TickRateDiv at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenithMDC committed Dec 1, 2024
1 parent d3d6787 commit affea8b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 2 additions & 0 deletions port/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
69 changes: 68 additions & 1 deletion port/src/optionsmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit affea8b

Please sign in to comment.