diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2022-10-22 16:13:35 -0500 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2022-11-01 21:59:08 -0500 |
| commit | 44a4573303917496ee9b4107fbe41a5cad142e2d (patch) | |
| tree | 0108e4ad0e8eeb3605e4fca99ae2a124e68d4127 /Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | |
| parent | dc046a247014f045c9ba52b0d4110d7a64f321bc (diff) | |
ControllerInterface: Add InputBackend interface and SDL implementation.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index 442e5502fa..d1ee02370a 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -64,7 +64,7 @@ void ControllerInterface::Initialize(const WindowSystemInfo& wsi) // nothing needed for OSX and Quartz #endif #ifdef CIFACE_USE_SDL - ciface::SDL::Init(); + m_input_backends.emplace_back(ciface::SDL::CreateInputBackend(this)); #endif #ifdef CIFACE_USE_ANDROID // nothing needed @@ -181,9 +181,6 @@ void ControllerInterface::RefreshDevices(RefreshReason reason) ciface::Quartz::PopulateDevices(m_wsi.render_window); } #endif -#ifdef CIFACE_USE_SDL - ciface::SDL::PopulateDevices(); -#endif #ifdef CIFACE_USE_ANDROID ciface::Android::PopulateDevices(); #endif @@ -197,6 +194,9 @@ void ControllerInterface::RefreshDevices(RefreshReason reason) ciface::DualShockUDPClient::PopulateDevices(); #endif + for (auto& backend : m_input_backends) + backend->PopulateDevices(); + WiimoteReal::PopulateDevices(); if (m_populating_devices_counter.fetch_sub(1) == 1) @@ -242,9 +242,6 @@ void ControllerInterface::Shutdown() ciface::OSX::DeInit(); ciface::Quartz::DeInit(); #endif -#ifdef CIFACE_USE_SDL - ciface::SDL::DeInit(); -#endif #ifdef CIFACE_USE_ANDROID // nothing needed #endif @@ -255,6 +252,8 @@ void ControllerInterface::Shutdown() ciface::DualShockUDPClient::DeInit(); #endif + m_input_backends.clear(); + // Make sure no devices had been added within Shutdown() in the time // between checking they checked atomic m_is_init bool and we changed it. // We couldn't have locked m_devices_population_mutex for the whole Shutdown() @@ -384,15 +383,19 @@ void ControllerInterface::UpdateInput() // TODO: if we are an emulation input channel, we should probably always lock // Prefer outdated values over blocking UI or CPU thread (avoids short but noticeable frame drop) - if (m_devices_mutex.try_lock()) + if (!m_devices_mutex.try_lock()) + return; + + std::lock_guard lk(m_devices_mutex, std::adopt_lock); + + for (auto& backend : m_input_backends) + backend->UpdateInput(); + + for (const auto& d : m_devices) { - std::lock_guard lk(m_devices_mutex, std::adopt_lock); - for (const auto& d : m_devices) - { - // Theoretically we could avoid updating input on devices that don't have any references to - // them, but in practice a few devices types could break in different ways, so we don't - d->UpdateInput(); - } + // Theoretically we could avoid updating input on devices that don't have any references to + // them, but in practice a few devices types could break in different ways, so we don't + d->UpdateInput(); } } |
