From 704c160c35ff617a77be852552e39b27e17a9f36 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Tue, 20 Apr 2021 16:06:34 +1000 Subject: [PATCH] CommonHostInterface: Add CPU overclock toggle hotkey --- src/frontend-common/common_host_interface.cpp | 68 ++++++++++++++----- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index cdeeb3d7d..8fc3bbfad 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -1813,17 +1813,6 @@ void CommonHostInterface::RegisterGeneralHotkeys() PauseSystem(!System::IsPaused()); }); - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleCheats"), - StaticString(TRANSLATABLE("Hotkeys", "Toggle Cheats")), [this](bool pressed) { - if (pressed && System::IsValid()) - { - if (!IsCheevosChallengeModeActive()) - DoToggleCheats(); - else - DisplayHotkeyBlockedByChallengeModeMessage(); - } - }); - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("PowerOff"), StaticString(TRANSLATABLE("Hotkeys", "Power Off System")), [this](bool pressed) { if (pressed && System::IsValid()) @@ -1849,12 +1838,7 @@ void CommonHostInterface::RegisterGeneralHotkeys() PowerOffSystem(ShouldSaveResumeState()); } }); -#else - RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("TogglePatchCodes"), - StaticString(TRANSLATABLE("Hotkeys", "Toggle Patch Codes")), [this](bool pressed) { - if (pressed && System::IsValid() && !IsCheevosChallengeModeActive()) - DoToggleCheats(); - }); + #endif RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Reset"), @@ -1880,6 +1864,7 @@ void CommonHostInterface::RegisterGeneralHotkeys() } }); +#ifndef __ANDROID__ RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FrameStep"), StaticString(TRANSLATABLE("Hotkeys", "Frame Step")), [this](bool pressed) { if (pressed && System::IsValid()) @@ -1891,7 +1876,6 @@ void CommonHostInterface::RegisterGeneralHotkeys() } }); -#ifndef __ANDROID__ RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Rewind"), StaticString(TRANSLATABLE("Hotkeys", "Rewind")), [this](bool pressed) { if (System::IsValid()) @@ -1909,7 +1893,55 @@ void CommonHostInterface::RegisterGeneralHotkeys() } } }); + + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleCheats"), + StaticString(TRANSLATABLE("Hotkeys", "Toggle Cheats")), [this](bool pressed) { + if (pressed && System::IsValid()) + { + if (!IsCheevosChallengeModeActive()) + DoToggleCheats(); + else + DisplayHotkeyBlockedByChallengeModeMessage(); + } + }); +#else + RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("TogglePatchCodes"), + StaticString(TRANSLATABLE("Hotkeys", "Toggle Patch Codes")), [this](bool pressed) { + if (pressed && System::IsValid()) + { + if (!IsCheevosChallengeModeActive()) + DoToggleCheats(); + else + DisplayHotkeyBlockedByChallengeModeMessage(); + } + }); #endif + + RegisterHotkey( + StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleOverclocking"), + StaticString(TRANSLATABLE("Hotkeys", "Toggle Clock Speed Control (Overclocking)")), [this](bool pressed) { + if (pressed && System::IsValid()) + { + g_settings.cpu_overclock_enable = !g_settings.cpu_overclock_enable; + g_settings.UpdateOverclockActive(); + System::UpdateOverclock(); + + if (g_settings.cpu_overclock_enable) + { + const u32 percent = g_settings.GetCPUOverclockPercent(); + const double clock_speed = + ((static_cast(System::MASTER_CLOCK) * static_cast(percent)) / 100.0) / 1000000.0; + AddFormattedOSDMessage(5.0f, + TranslateString("OSDMessage", "CPU clock speed control enabled (%u%% / %.3f MHz)."), + percent, clock_speed); + } + else + { + AddFormattedOSDMessage(5.0f, TranslateString("OSDMessage", "CPU clock speed control disabled (%.3f MHz)."), + static_cast(System::MASTER_CLOCK) / 1000000.0); + } + } + }); } void CommonHostInterface::RegisterGraphicsHotkeys()