diff options
| author | Léo Lam <leo@leolam.fr> | 2021-06-07 12:15:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-07 12:15:15 +0200 |
| commit | 8ca6ffd908aa95ffb5c7665083463c4ea1139b0d (patch) | |
| tree | 5a058d8aa001d2577f7e65d5aa44ec86737c3386 /Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp | |
| parent | ebe3fbe04c329f9bc100ded4dcf22720f375e2f4 (diff) | |
| parent | 83ea16f40238fa82981221ba65061a7094b2a64b (diff) | |
Merge pull request #9702 from Filoppi/controller_interface_fixes
Controller Interface refactor
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp index eaa56ef449..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<false>; class Motor final : public Core::Device::Output { public: - Motor(ControlState* value) : m_value(*value) {} + Motor(std::atomic<ControlState>* 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<ControlState>& m_value; }; template <typename T> @@ -128,13 +128,17 @@ void ReleaseDevices(std::optional<u32> 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<WiimoteReal::Wiimote> wiimote) : m_wiimote(std::move(wiimote)) @@ -317,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()) @@ -1367,7 +1377,8 @@ void Device::UpdateRumble() { static constexpr auto rumble_period = std::chrono::milliseconds(100); - const auto on_time = std::chrono::duration_cast<Clock::duration>(rumble_period * m_rumble_level); + const auto on_time = + std::chrono::duration_cast<Clock::duration>(rumble_period * m_rumble_level.load()); const auto off_time = rumble_period - on_time; const auto now = Clock::now(); |
