mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-02-02 20:46:45 +00:00
Yellow squiggly lines begone! Done automatically on .cpp files through `run-clang-tidy`, with manual corrections to the mistakes. If an import is directly used, but is technically unnecessary since it's recursively imported by something else, it is *not* removed. The tool doesn't touch .h files, so I did some of them by hand while fixing errors due to old recursive imports. Not everything is removed, but the cleanup should be substantial enough. Because this done on Linux, code that isn't used on it is mostly untouched. (Hopefully no open PR is depending on these imports...)
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
// Copyright 2023 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "DolphinQt/TAS/TASControlState.h"
|
|
|
|
#include <atomic>
|
|
|
|
int TASControlState::GetValue() const
|
|
{
|
|
const State ui_thread_state = m_ui_thread_state.load(std::memory_order_relaxed);
|
|
const State cpu_thread_state = m_cpu_thread_state.load(std::memory_order_relaxed);
|
|
|
|
return (ui_thread_state.version != cpu_thread_state.version ? cpu_thread_state : ui_thread_state)
|
|
.value;
|
|
}
|
|
|
|
bool TASControlState::OnControllerValueChanged(int new_value)
|
|
{
|
|
const State cpu_thread_state = m_cpu_thread_state.load(std::memory_order_relaxed);
|
|
|
|
if (cpu_thread_state.value == new_value)
|
|
{
|
|
// The CPU thread state is already up to date with the controller. No need to do anything
|
|
return false;
|
|
}
|
|
|
|
const State new_state{static_cast<int>(cpu_thread_state.version + 1), new_value};
|
|
m_cpu_thread_state.store(new_state, std::memory_order_relaxed);
|
|
|
|
return true;
|
|
}
|
|
|
|
void TASControlState::OnUIValueChanged(int new_value)
|
|
{
|
|
const State ui_thread_state = m_ui_thread_state.load(std::memory_order_relaxed);
|
|
|
|
const State new_state{ui_thread_state.version, new_value};
|
|
m_ui_thread_state.store(new_state, std::memory_order_relaxed);
|
|
}
|
|
|
|
int TASControlState::ApplyControllerValueChange()
|
|
{
|
|
const State ui_thread_state = m_ui_thread_state.load(std::memory_order_relaxed);
|
|
const State cpu_thread_state = m_cpu_thread_state.load(std::memory_order_relaxed);
|
|
|
|
if (ui_thread_state.version == cpu_thread_state.version)
|
|
{
|
|
// The UI thread state is already up to date with the CPU thread. No need to do anything
|
|
return ui_thread_state.value;
|
|
}
|
|
else
|
|
{
|
|
m_ui_thread_state.store(cpu_thread_state, std::memory_order_relaxed);
|
|
return cpu_thread_state.value;
|
|
}
|
|
}
|