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.
This commit is contained in:
JosJuice 2023-03-04 12:24:31 +01:00
parent 95ce41ac56
commit 3eac1fc284
8 changed files with 140 additions and 15 deletions

View file

@ -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()));
}