From 3eac1fc28494709dc7cbfaae81cf0b1f42f12e17 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 4 Mar 2023 12:24:31 +0100 Subject: 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. --- Source/Core/DolphinQt/TAS/TASCheckBox.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'Source/Core/DolphinQt/TAS/TASCheckBox.cpp') 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 #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(m_state.GetValue()); + + if (check_state == Qt::PartiallyChecked) { const u64 frames_elapsed = Movie::GetCurrentFrame() - m_frame_turbo_started; return static_cast(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(new_value)); +} + +void TASCheckBox::ApplyControllerValueChange() +{ + const QSignalBlocker blocker(this); + setCheckState(static_cast(m_state.ApplyControllerValueChange())); +} -- cgit v1.2.3