1
0
mirror of https://github.com/Lime3DS/Lime3DS.git synced 2025-03-15 02:02:30 +01:00

[WIP] Add fast forward toggle hotkey

This commit is contained in:
kleidis 2024-09-21 22:02:36 +02:00 committed by OpenSauce04
parent 4e27eb5488
commit 4a761147d1
5 changed files with 66 additions and 24 deletions

@ -786,32 +786,18 @@ void GMainWindow::InitializeHotkeys() {
[&] { Settings::values.dump_textures = !Settings::values.dump_textures; });
connect_shortcut(QStringLiteral("Toggle Custom Textures"),
[&] { Settings::values.custom_textures = !Settings::values.custom_textures; });
// We use "static" here in order to avoid capturing by lambda due to a MSVC bug, which makes
// the variable hold a garbage value after this function exits
static constexpr u16 SPEED_LIMIT_STEP = 5;
connect_shortcut(QStringLiteral("Toggle Custom Emulation Speed"), &GMainWindow::ToggleEmulationSpeed);
connect_shortcut(QStringLiteral("Increase Speed Limit"), [&] {
if (Settings::values.frame_limit.GetValue() == 0) {
return;
}
if (Settings::values.frame_limit.GetValue() < 995 - SPEED_LIMIT_STEP) {
Settings::values.frame_limit.SetValue(Settings::values.frame_limit.GetValue() +
SPEED_LIMIT_STEP);
} else {
Settings::values.frame_limit = 0;
}
UpdateStatusBar();
AdjustSpeedLimit(true);
});
connect_shortcut(QStringLiteral("Decrease Speed Limit"), [&] {
if (Settings::values.frame_limit.GetValue() == 0) {
Settings::values.frame_limit = 995;
} else if (Settings::values.frame_limit.GetValue() > SPEED_LIMIT_STEP) {
Settings::values.frame_limit.SetValue(Settings::values.frame_limit.GetValue() -
SPEED_LIMIT_STEP);
UpdateStatusBar();
}
UpdateStatusBar();
AdjustSpeedLimit(false);
});
connect_shortcut(QStringLiteral("Audio Mute/Unmute"), &GMainWindow::OnMute);
connect_shortcut(QStringLiteral("Audio Volume Down"), &GMainWindow::OnDecreaseVolume);
connect_shortcut(QStringLiteral("Audio Volume Up"), &GMainWindow::OnIncreaseVolume);
@ -2557,6 +2543,56 @@ void GMainWindow::ChangeSmallScreenPosition() {
UpdateSecondaryWindowVisibility();
}
void GMainWindow::ToggleEmulationSpeed() {
static bool key_pressed = false; // Prevent spam on hold
static int initial_frame_limit = Settings::values.frame_limit.GetValue(); // Store original frame limit
if (!key_pressed) {
key_pressed = true;
turbo_mode_active = !turbo_mode_active;
if (turbo_mode_active) {
initial_frame_limit = Settings::values.frame_limit.GetValue();
Settings::values.frame_limit.SetValue(UISettings::values.turbo_speed_slider.GetValue());
} else {
Settings::values.frame_limit.SetValue(initial_frame_limit);
}
UpdateStatusBar();
QTimer::singleShot(200, [] { key_pressed = false; });
}
}
void GMainWindow::AdjustSpeedLimit(bool increase) {
const int SPEED_LIMIT_STEP = 5;
if (turbo_mode_active) {
int turbo_speed = UISettings::values.turbo_speed_slider.GetValue();
if (increase) {
if (turbo_speed < 995) {
UISettings::values.turbo_speed_slider.SetValue(turbo_speed + SPEED_LIMIT_STEP);
}
} else {
if (turbo_speed > SPEED_LIMIT_STEP) {
UISettings::values.turbo_speed_slider.SetValue(turbo_speed - SPEED_LIMIT_STEP);
}
}
Settings::values.frame_limit.SetValue(UISettings::values.turbo_speed_slider.GetValue());
} else {
int current_frame_limit = Settings::values.frame_limit.GetValue();
if (increase) {
if (current_frame_limit < 995) {
Settings::values.frame_limit.SetValue(current_frame_limit + SPEED_LIMIT_STEP);
}
} else {
if (current_frame_limit > SPEED_LIMIT_STEP) {
Settings::values.frame_limit.SetValue(current_frame_limit - SPEED_LIMIT_STEP);
}
}
}
UpdateStatusBar();
}
void GMainWindow::ToggleScreenLayout() {
const Settings::LayoutOption new_layout = []() {
switch (Settings::values.layout_option.GetValue()) {

@ -264,6 +264,8 @@ private slots:
void ToggleSecondaryFullscreen();
void ChangeScreenLayout();
void ChangeSmallScreenPosition();
void ToggleEmulationSpeed();
void AdjustSpeedLimit(bool increase);
void UpdateSecondaryWindowVisibility();
void ToggleScreenLayout();
void OnSwapScreens();
@ -351,6 +353,9 @@ private:
MultiplayerState* multiplayer_state = nullptr;
std::unique_ptr<QtConfig> config;
// Hotkeys
bool turbo_mode_active = false;
// Whether emulation is currently running in Citra.
bool emulation_running = false;
std::unique_ptr<EmuThread> emu_thread;

@ -54,7 +54,7 @@ const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> QtConfi
// This must be in alphabetical order according to action name as it must have the same order as
// UISetting::values.shortcuts, which is alphabetically ordered.
// clang-format off
const std::array<UISettings::Shortcut, 35> QtConfig::default_hotkeys {{
const std::array<UISettings::Shortcut, 36> QtConfig::default_hotkeys {{
{QStringLiteral("Advance Frame"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::ApplicationShortcut}},
{QStringLiteral("Audio Mute/Unmute"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}},
{QStringLiteral("Audio Volume Down"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::WindowShortcut}},
@ -83,6 +83,7 @@ const std::array<UISettings::Shortcut, 35> QtConfig::default_hotkeys {{
{QStringLiteral("Stop Emulation"), QStringLiteral("Main Window"), {QStringLiteral("F5"), Qt::WindowShortcut}},
{QStringLiteral("Swap Screens"), QStringLiteral("Main Window"), {QStringLiteral("F9"), Qt::WindowShortcut}},
{QStringLiteral("Toggle 3D"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+3"), Qt::ApplicationShortcut}},
{QStringLiteral("Toggle Custom Emulation Speed"), QStringLiteral("Main Window"), {QStringLiteral("+"), Qt::ApplicationShortcut}},
{QStringLiteral("Toggle Custom Textures"), QStringLiteral("Main Window"), {QStringLiteral("F7"), Qt::ApplicationShortcut}},
{QStringLiteral("Toggle Filter Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+F"), Qt::WindowShortcut}},
{QStringLiteral("Toggle Frame Advancing"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+A"), Qt::ApplicationShortcut}},

@ -26,7 +26,7 @@ public:
static const std::array<int, Settings::NativeButton::NumButtons> default_buttons;
static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs;
static const std::array<UISettings::Shortcut, 35> default_hotkeys;
static const std::array<UISettings::Shortcut, 36> default_hotkeys;
private:
void Initialize(const std::string& config_name);

@ -76,7 +76,7 @@ struct Values {
Settings::Setting<bool> show_filter_bar{true, "showFilterBar"};
Settings::Setting<bool> show_status_bar{true, "showStatusBar"};
Settings::Setting<int> turbo_speed_slider{69, "turboSpeedSlider"};
Settings::Setting<int> turbo_speed_slider{100, "turboSpeedSlider"};
Settings::Setting<bool> confirm_before_closing{true, "confirmClose"};
Settings::Setting<bool> save_state_warning{true, "saveStateWarning"};
Settings::Setting<bool> first_start{true, "firstStart"};