diff options
| author | Admiral H. Curtiss <pikachu025@gmail.com> | 2023-03-09 16:08:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-09 16:08:30 +0100 |
| commit | 234c5dd90e31cbbe6782b4a6c6ae5f2f578e199b (patch) | |
| tree | cdc1505c7932d8de0f129b06437d686e27445685 /Source/Core/DolphinQt/TAS/TASInputWindow.cpp | |
| parent | a6b1b2f9a50b41d491115a8fb08f33a4a5dcf586 (diff) | |
| parent | 0300b44d23b149a0b93dd0aa2e77d20a02882ddf (diff) | |
Merge pull request #11622 from JosJuice/tas-input-nonblocking
DolphinQt: Rework TAS input threading
Diffstat (limited to 'Source/Core/DolphinQt/TAS/TASInputWindow.cpp')
| -rw-r--r-- | Source/Core/DolphinQt/TAS/TASInputWindow.cpp | 87 |
1 files changed, 26 insertions, 61 deletions
diff --git a/Source/Core/DolphinQt/TAS/TASInputWindow.cpp b/Source/Core/DolphinQt/TAS/TASInputWindow.cpp index 0054043a8e..d74a84997f 100644 --- a/Source/Core/DolphinQt/TAS/TASInputWindow.cpp +++ b/Source/Core/DolphinQt/TAS/TASInputWindow.cpp @@ -23,6 +23,7 @@ #include "DolphinQt/TAS/StickWidget.h" #include "DolphinQt/TAS/TASCheckBox.h" #include "DolphinQt/TAS/TASSlider.h" +#include "DolphinQt/TAS/TASSpinBox.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerEmu/StickGate.h" @@ -93,9 +94,8 @@ TASCheckBox* TASInputWindow::CreateButton(const QString& text, std::string_view } QGroupBox* TASInputWindow::CreateStickInputs(const QString& text, std::string_view group_name, - InputOverrider* overrider, QSpinBox*& x_value, - QSpinBox*& y_value, u16 min_x, u16 min_y, u16 max_x, - u16 max_y, Qt::Key x_shortcut_key, + InputOverrider* overrider, u16 min_x, u16 min_y, + u16 max_x, u16 max_y, Qt::Key x_shortcut_key, Qt::Key y_shortcut_key) { const QKeySequence x_shortcut_key_sequence = QKeySequence(Qt::ALT | x_shortcut_key); @@ -110,11 +110,11 @@ QGroupBox* TASInputWindow::CreateStickInputs(const QString& text, std::string_vi const int y_default = static_cast<int>(std::round(max_y / 2.)); auto* x_layout = new QHBoxLayout; - x_value = CreateSliderValuePair(x_layout, x_default, max_x, x_shortcut_key_sequence, - Qt::Horizontal, box); + TASSpinBox* x_value = CreateSliderValuePair(x_layout, x_default, max_x, x_shortcut_key_sequence, + Qt::Horizontal, box); auto* y_layout = new QVBoxLayout; - y_value = + TASSpinBox* y_value = CreateSliderValuePair(y_layout, y_default, max_y, y_shortcut_key_sequence, Qt::Vertical, box); y_value->setMaximumWidth(60); @@ -153,8 +153,8 @@ QGroupBox* TASInputWindow::CreateStickInputs(const QString& text, std::string_vi QBoxLayout* TASInputWindow::CreateSliderValuePairLayout( const QString& text, std::string_view group_name, std::string_view control_name, - InputOverrider* overrider, QSpinBox*& value, u16 zero, int default_, u16 min, u16 max, - Qt::Key shortcut_key, QWidget* shortcut_widget, std::optional<ControlState> scale) + InputOverrider* overrider, u16 zero, int default_, u16 min, u16 max, Qt::Key shortcut_key, + QWidget* shortcut_widget, std::optional<ControlState> scale) { const QKeySequence shortcut_key_sequence = QKeySequence(Qt::ALT | shortcut_key); @@ -164,20 +164,20 @@ QBoxLayout* TASInputWindow::CreateSliderValuePairLayout( QBoxLayout* layout = new QHBoxLayout; layout->addWidget(label); - value = CreateSliderValuePair(group_name, control_name, overrider, layout, zero, default_, min, - max, shortcut_key_sequence, Qt::Horizontal, shortcut_widget, scale); + CreateSliderValuePair(group_name, control_name, overrider, layout, zero, default_, min, max, + shortcut_key_sequence, Qt::Horizontal, shortcut_widget, scale); return layout; } -QSpinBox* TASInputWindow::CreateSliderValuePair( +TASSpinBox* TASInputWindow::CreateSliderValuePair( std::string_view group_name, std::string_view control_name, InputOverrider* overrider, QBoxLayout* layout, u16 zero, int default_, u16 min, u16 max, QKeySequence shortcut_key_sequence, Qt::Orientation orientation, QWidget* shortcut_widget, std::optional<ControlState> scale) { - QSpinBox* value = CreateSliderValuePair(layout, default_, max, shortcut_key_sequence, orientation, - shortcut_widget); + TASSpinBox* value = CreateSliderValuePair(layout, default_, max, shortcut_key_sequence, + orientation, shortcut_widget); InputOverrider::OverrideFunction func; if (scale) @@ -200,12 +200,12 @@ QSpinBox* TASInputWindow::CreateSliderValuePair( // The shortcut_widget argument needs to specify the container widget that will be hidden/shown. // This is done to avoid ambigous shortcuts -QSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max, - QKeySequence shortcut_key_sequence, - Qt::Orientation orientation, - QWidget* shortcut_widget) +TASSpinBox* TASInputWindow::CreateSliderValuePair(QBoxLayout* layout, int default_, u16 max, + QKeySequence shortcut_key_sequence, + Qt::Orientation orientation, + QWidget* shortcut_widget) { - auto* value = new QSpinBox(); + auto* value = new TASSpinBox(); value->setRange(0, 99999); value->setValue(default_); connect(value, qOverload<int>(&QSpinBox::valueChanged), [value, max](int i) { @@ -239,67 +239,32 @@ std::optional<ControlState> TASInputWindow::GetButton(TASCheckBox* checkbox, { const bool pressed = std::llround(controller_state) > 0; if (m_use_controller->isChecked()) - { - if (pressed) - { - m_checkbox_set_by_controller[checkbox] = true; - QueueOnObjectBlocking(checkbox, [checkbox] { checkbox->setChecked(true); }); - } - else if (m_checkbox_set_by_controller.count(checkbox) && m_checkbox_set_by_controller[checkbox]) - { - m_checkbox_set_by_controller[checkbox] = false; - QueueOnObjectBlocking(checkbox, [checkbox] { checkbox->setChecked(false); }); - } - } + checkbox->OnControllerValueChanged(pressed); return checkbox->GetValue() ? 1.0 : 0.0; } -std::optional<ControlState> TASInputWindow::GetSpinBox(QSpinBox* spin, u16 zero, u16 min, u16 max, +std::optional<ControlState> TASInputWindow::GetSpinBox(TASSpinBox* spin, u16 zero, u16 min, u16 max, ControlState controller_state) { const u16 controller_value = ControllerEmu::EmulatedController::MapFloat<u16>(controller_state, zero, 0, max); if (m_use_controller->isChecked()) - { - if (!m_spinbox_most_recent_values.count(spin) || - m_spinbox_most_recent_values[spin] != controller_value) - { - QueueOnObjectBlocking(spin, [spin, controller_value] { spin->setValue(controller_value); }); - } - - m_spinbox_most_recent_values[spin] = controller_value; - } - else - { - m_spinbox_most_recent_values.clear(); - } + spin->OnControllerValueChanged(controller_value); - return ControllerEmu::EmulatedController::MapToFloat<ControlState, u16>(spin->value(), zero, min, - max); + return ControllerEmu::EmulatedController::MapToFloat<ControlState, u16>(spin->GetValue(), zero, + min, max); } -std::optional<ControlState> TASInputWindow::GetSpinBox(QSpinBox* spin, u16 zero, +std::optional<ControlState> TASInputWindow::GetSpinBox(TASSpinBox* spin, u16 zero, ControlState controller_state, ControlState scale) { const u16 controller_value = static_cast<u16>(std::llround(controller_state * scale + zero)); if (m_use_controller->isChecked()) - { - if (!m_spinbox_most_recent_values.count(spin) || - m_spinbox_most_recent_values[spin] != controller_value) - { - QueueOnObjectBlocking(spin, [spin, controller_value] { spin->setValue(controller_value); }); - } - - m_spinbox_most_recent_values[spin] = controller_value; - } - else - { - m_spinbox_most_recent_values.clear(); - } + spin->OnControllerValueChanged(controller_value); - return (spin->value() - zero) / scale; + return (spin->GetValue() - zero) / scale; } |
