From 1d816f8f267ff468478a4b8ff423b2dd0c734654 Mon Sep 17 00:00:00 2001 From: Filoppi Date: Sat, 15 May 2021 12:10:00 +0300 Subject: ControllerInterface: make real Wiimote use PlatformPopulateDevices() --- .../ControllerInterface/Wiimote/WiimoteController.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp index eaa56ef449..dfd329f5e0 100644 --- a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp @@ -128,13 +128,17 @@ void ReleaseDevices(std::optional count) // Remove up to "count" remotes (or all of them if nullopt). // Real wiimotes will be added to the pool. - g_controller_interface.RemoveDevice([&](const Core::Device* device) { - if (device->GetSource() != SOURCE_NAME || count == removed_devices) - return false; - - ++removed_devices; - return true; - }); + // Make sure to force the device removal immediately (as they are shared ptrs and + // they could be kept alive, preventing us from re-creating the device) + g_controller_interface.RemoveDevice( + [&](const Core::Device* device) { + if (device->GetSource() != SOURCE_NAME || count == removed_devices) + return false; + + ++removed_devices; + return true; + }, + true); } Device::Device(std::unique_ptr wiimote) : m_wiimote(std::move(wiimote)) -- cgit v1.2.3 From dcc345400e38e54ac84819e5cbcdf65c9cd95f96 Mon Sep 17 00:00:00 2001 From: Filoppi Date: Sat, 15 May 2021 12:14:11 +0300 Subject: ControllerInterface: devices population is now async so implement devices sorting priority This helps us keeping the most important devices (e.g. Mouse and Keyboard) on the top of the list of devices (they still are on all OSes supported by dolphin and to make hotplug devices like DSU appear at the bottom. --- .../InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp index dfd329f5e0..d68b0441a6 100644 --- a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp @@ -321,6 +321,12 @@ std::string Device::GetSource() const return SOURCE_NAME; } +// Always add these at the end, given their hotplug nature +int Device::GetSortPriority() const +{ + return -1; +} + void Device::RunTasks() { if (IsPerformingTask()) -- cgit v1.2.3 From a77e3b4a9bc557ac00b63c13abdb4074069e9a7d Mon Sep 17 00:00:00 2001 From: Filoppi Date: Mon, 10 May 2021 22:44:17 +0300 Subject: InputCommon: Make Wiimote rumble variable thread safe --- .../InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp index d68b0441a6..82e2cfedda 100644 --- a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp @@ -82,14 +82,14 @@ using UndetectableSignedAnalogInput = SignedInput; class Motor final : public Core::Device::Output { public: - Motor(ControlState* value) : m_value(*value) {} + Motor(std::atomic* value) : m_value(*value) {} std::string GetName() const override { return "Motor"; } void SetState(ControlState state) override { m_value = state; } private: - ControlState& m_value; + std::atomic& m_value; }; template @@ -1377,7 +1377,8 @@ void Device::UpdateRumble() { static constexpr auto rumble_period = std::chrono::milliseconds(100); - const auto on_time = std::chrono::duration_cast(rumble_period * m_rumble_level); + const auto on_time = + std::chrono::duration_cast(rumble_period * m_rumble_level.load()); const auto off_time = rumble_period - on_time; const auto now = Clock::now(); -- cgit v1.2.3