diff options
| author | JosJuice <josjuice@gmail.com> | 2023-03-04 12:24:31 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2023-03-08 17:49:02 +0100 |
| commit | 3eac1fc28494709dc7cbfaae81cf0b1f42f12e17 (patch) | |
| tree | 402a35fc275cc7c9c31bc5dd2270e13edb6a6b32 /Source/Core/DolphinQt/TAS/TASCheckBox.cpp | |
| parent | 95ce41ac56f2774a1b18a1a1dafd2dadee248616 (diff) | |
DolphinQt: Rework TAS input threading, part 1 (buttons)
This gets rid of a blocking operation, improving performance and fixing
https://bugs.dolphin-emu.org/issues/12893.
This also makes us no longer directly access the state of certain UI
elements from the CPU thread, which probably wasn't thread-safe but
doesn't seem to have caused any observable issues so far.
Diffstat (limited to 'Source/Core/DolphinQt/TAS/TASCheckBox.cpp')
| -rw-r--r-- | Source/Core/DolphinQt/TAS/TASCheckBox.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Source/Core/DolphinQt/TAS/TASCheckBox.cpp b/Source/Core/DolphinQt/TAS/TASCheckBox.cpp index 29a7171f47..32d1b3b0b0 100644 --- a/Source/Core/DolphinQt/TAS/TASCheckBox.cpp +++ b/Source/Core/DolphinQt/TAS/TASCheckBox.cpp @@ -6,23 +6,34 @@ #include <QMouseEvent> #include "Core/Movie.h" +#include "DolphinQt/QtUtils/QueueOnObject.h" #include "DolphinQt/TAS/TASInputWindow.h" TASCheckBox::TASCheckBox(const QString& text, TASInputWindow* parent) : QCheckBox(text, parent), m_parent(parent) { setTristate(true); + + connect(this, &TASCheckBox::stateChanged, this, &TASCheckBox::OnUIValueChanged); } bool TASCheckBox::GetValue() const { - if (checkState() == Qt::PartiallyChecked) + Qt::CheckState check_state = static_cast<Qt::CheckState>(m_state.GetValue()); + + if (check_state == Qt::PartiallyChecked) { const u64 frames_elapsed = Movie::GetCurrentFrame() - m_frame_turbo_started; return static_cast<int>(frames_elapsed % m_turbo_total_frames) < m_turbo_press_frames; } - return isChecked(); + return check_state != Qt::Unchecked; +} + +void TASCheckBox::OnControllerValueChanged(bool new_value) +{ + if (m_state.OnControllerValueChanged(new_value ? Qt::Checked : Qt::Unchecked)) + QueueOnObject(this, &TASCheckBox::ApplyControllerValueChange); } void TASCheckBox::mousePressEvent(QMouseEvent* event) @@ -44,3 +55,14 @@ void TASCheckBox::mousePressEvent(QMouseEvent* event) m_turbo_total_frames = m_turbo_press_frames + m_parent->GetTurboReleaseFrames(); setCheckState(Qt::PartiallyChecked); } + +void TASCheckBox::OnUIValueChanged(int new_value) +{ + m_state.OnUIValueChanged(static_cast<u16>(new_value)); +} + +void TASCheckBox::ApplyControllerValueChange() +{ + const QSignalBlocker blocker(this); + setCheckState(static_cast<Qt::CheckState>(m_state.ApplyControllerValueChange())); +} |
