From f10e2a0db6a3d2cd2b504774a64915092e01af60 Mon Sep 17 00:00:00 2001 From: Vlad Firoiu Date: Wed, 22 May 2024 08:57:04 -0400 Subject: [PATCH] Wait for inputs until all PipeDevices have been flushed in blocking mode. --- .../ControllerInterface/ControllerInterface.cpp | 4 ++++ .../Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index cfb1a4d6d2..c33945143f 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -40,6 +40,8 @@ using namespace ciface::ExpressionParser; +extern bool g_needInputForFrame; // from EXI_DeviceSlippi.cpp + namespace { const ControlState INPUT_DETECT_THRESHOLD = 0.55; @@ -217,6 +219,8 @@ void ControllerInterface::UpdateInput() std::lock_guard lk(m_devices_mutex, std::adopt_lock); for (const auto& d : m_devices) d->UpdateInput(); + + g_needInputForFrame = false; } } diff --git a/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp b/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp index 1e2324fe8d..e3287331f6 100644 --- a/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp @@ -164,8 +164,9 @@ s32 PipeDevice::readFromPipe(PIPE_FD file_descriptor, char *in_buffer, size_t si void PipeDevice::UpdateInput() { bool finished = false; + bool wait_for_inputs = SConfig::GetInstance().m_blockingPipes && g_needInputForFrame; #ifndef _WIN32 - if(SConfig::GetInstance().m_blockingPipes && g_needInputForFrame) + if(wait_for_inputs) { fd_set set; FD_ZERO (&set); @@ -199,7 +200,7 @@ void PipeDevice::UpdateInput() m_buf.erase(0, newline + 1); newline = m_buf.find("\n"); } - } while(!finished && g_needInputForFrame && SConfig::GetInstance().m_blockingPipes); + } while(!finished && wait_for_inputs); } void PipeDevice::AddAxis(const std::string& name, double value) @@ -264,7 +265,8 @@ bool PipeDevice::ParseCommand(const std::string& command) { if(command == "FLUSH") { - g_needInputForFrame = false; + // Let ControllerInterface::UpdateInputs clear the g_needInputForFrame + // flag after all PipeDevices have been queried. return true; } std::vector tokens;