From cf5f9dbb6565b739ad91eba2b5d61b6163d3ca2b 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 | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index f85e7a23d2..4800c3150e 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -35,6 +35,8 @@ using namespace ciface::ExpressionParser; +extern bool g_needInputForFrame; // from EXI_DeviceSlippi.cpp + namespace { const ControlState INPUT_DETECT_THRESHOLD = 0.55; @@ -212,6 +214,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 980808880e..bcf7687d74 100644 --- a/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Pipes/Pipes.cpp @@ -163,8 +163,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); @@ -198,7 +199,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) @@ -230,7 +231,9 @@ bool PipeDevice::ParseCommand(const std::string& command) { if(command == "FLUSH") { - g_needInputForFrame = false; + // Let ControllerInterface.cpp clear the flag after all PipeDevices + // have been queried. + // g_needInputForFrame = false; return true; } std::vector tokens;