Skip to content

Add turbo hotkey #1925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/gui/gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,11 @@ void PCSX::GUI::startFrame() {
g_system->softReset();
}
}

if (ImGui::IsKeyPressed(ImGuiKey_Tab)) {
m_turboEnabled = !m_turboEnabled;
g_emulator->settings.get<Emulator::SettingScaler>() = m_turboEnabled ? 200 : 100;
}
Comment on lines +1063 to +1066
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Turbo hotkey implementation needs improvement for maintainability.

While the implementation works, the turbo speed (200%) and the hotkey (Tab) are hardcoded. This would be better implemented as configurable settings, especially since the PR mentions this is tentative and there's a known issue where setting the speed back to 100% can occasionally cause the emulator to hang.

Consider refactoring this to use configurable settings for both the hotkey and speed value:

-    if (ImGui::IsKeyPressed(ImGuiKey_Tab)) {
-        m_turboEnabled = !m_turboEnabled;
-        g_emulator->settings.get<Emulator::SettingScaler>() = m_turboEnabled ? 200 : 100;
+    // Check for turbo hotkey
+    if (ImGui::IsKeyPressed(g_emulator->settings.get<Emulator::SettingTurboHotkey>().value)) {
+        m_turboEnabled = !m_turboEnabled;
+        g_emulator->settings.get<Emulator::SettingScaler>() = 
+            m_turboEnabled ? g_emulator->settings.get<Emulator::SettingTurboSpeed>().value : 100;
+    }

This would require adding two new settings in the emulator settings class.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (ImGui::IsKeyPressed(ImGuiKey_Tab)) {
m_turboEnabled = !m_turboEnabled;
g_emulator->settings.get<Emulator::SettingScaler>() = m_turboEnabled ? 200 : 100;
}
// Check for turbo hotkey
if (ImGui::IsKeyPressed(g_emulator->settings.get<Emulator::SettingTurboHotkey>().value)) {
m_turboEnabled = !m_turboEnabled;
g_emulator->settings.get<Emulator::SettingScaler>() =
m_turboEnabled ? g_emulator->settings.get<Emulator::SettingTurboSpeed>().value : 100;
}

}

void PCSX::GUI::setViewport() { glViewport(0, 0, m_renderSize.x, m_renderSize.y); }
Expand Down Expand Up @@ -1504,6 +1509,10 @@ in Configuration->Emulation, restart PCSX-Redux, then try again.)"));
} else {
ImGui::TextUnformatted(_("Idle"));
}
if (m_turboEnabled) {
ImGui::Separator();
ImGui::TextUnformatted(_("Turbo"));
}

ImGui::EndMainMenuBar();
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class GUI final : public UI {
bool m_showHandles = false;
bool m_showAbout = false;
bool m_showInterruptsScaler = false;
bool m_turboEnabled = false;
Widgets::Log m_log = {settings.get<ShowLog>().value};
struct MemoryEditorWrapper {
MemoryEditorWrapper(GUI *gui, bool &show, size_t &offsetAddr, size_t baseAddr = 0x0000)
Expand Down
Loading