diff options
| author | 2022-11-28 13:12:08 -0500 | |
|---|---|---|
| committer | 2022-11-28 13:12:08 -0500 | |
| commit | 64ff79f919987685d5328114c4125140fece98d1 (patch) | |
| tree | 46cdffe7768f619a621aa50fe82f813d15bd517e /src/core/hid | |
| parent | Merge pull request #9336 from lioncash/themepath (diff) | |
| parent | core/hid/emulated_controller: Use ranges version of transform (diff) | |
| download | yuzu-64ff79f919987685d5328114c4125140fece98d1.tar.gz yuzu-64ff79f919987685d5328114c4125140fece98d1.tar.xz yuzu-64ff79f919987685d5328114c4125140fece98d1.zip | |
Merge pull request #9337 from lioncash/pbr
common/input: Add helper functions for constructing input and output devices
Diffstat (limited to 'src/core/hid')
| -rw-r--r-- | src/core/hid/emulated_console.cpp | 4 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 38 | ||||
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 14 |
3 files changed, 26 insertions, 30 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index fb7e5802a..b6c8cc58d 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp | |||
| @@ -68,7 +68,7 @@ void EmulatedConsole::ReloadInput() { | |||
| 68 | // If you load any device here add the equivalent to the UnloadInput() function | 68 | // If you load any device here add the equivalent to the UnloadInput() function |
| 69 | SetTouchParams(); | 69 | SetTouchParams(); |
| 70 | 70 | ||
| 71 | motion_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(motion_params); | 71 | motion_devices = Common::Input::CreateInputDevice(motion_params); |
| 72 | if (motion_devices) { | 72 | if (motion_devices) { |
| 73 | motion_devices->SetCallback({ | 73 | motion_devices->SetCallback({ |
| 74 | .on_change = | 74 | .on_change = |
| @@ -79,7 +79,7 @@ void EmulatedConsole::ReloadInput() { | |||
| 79 | // Unique index for identifying touch device source | 79 | // Unique index for identifying touch device source |
| 80 | std::size_t index = 0; | 80 | std::size_t index = 0; |
| 81 | for (auto& touch_device : touch_devices) { | 81 | for (auto& touch_device : touch_devices) { |
| 82 | touch_device = Common::Input::CreateDevice<Common::Input::InputDevice>(touch_params[index]); | 82 | touch_device = Common::Input::CreateInputDevice(touch_params[index]); |
| 83 | if (!touch_device) { | 83 | if (!touch_device) { |
| 84 | continue; | 84 | continue; |
| 85 | } | 85 | } |
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index ec1364452..c96d9eef3 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <algorithm> | ||
| 5 | |||
| 4 | #include "common/thread.h" | 6 | #include "common/thread.h" |
| 5 | #include "core/hid/emulated_controller.h" | 7 | #include "core/hid/emulated_controller.h" |
| 6 | #include "core/hid/input_converter.h" | 8 | #include "core/hid/input_converter.h" |
| @@ -144,29 +146,23 @@ void EmulatedController::LoadDevices() { | |||
| 144 | 146 | ||
| 145 | LoadTASParams(); | 147 | LoadTASParams(); |
| 146 | 148 | ||
| 147 | std::transform(button_params.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, | 149 | std::ranges::transform(button_params, button_devices.begin(), Common::Input::CreateInputDevice); |
| 148 | button_params.begin() + Settings::NativeButton::BUTTON_NS_END, | 150 | std::ranges::transform(stick_params, stick_devices.begin(), Common::Input::CreateInputDevice); |
| 149 | button_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>); | 151 | std::ranges::transform(motion_params, motion_devices.begin(), Common::Input::CreateInputDevice); |
| 150 | std::transform(stick_params.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, | 152 | std::ranges::transform(trigger_params, trigger_devices.begin(), |
| 151 | stick_params.begin() + Settings::NativeAnalog::STICK_HID_END, | 153 | Common::Input::CreateInputDevice); |
| 152 | stick_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>); | 154 | std::ranges::transform(battery_params, battery_devices.begin(), |
| 153 | std::transform(motion_params.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, | 155 | Common::Input::CreateInputDevice); |
| 154 | motion_params.begin() + Settings::NativeMotion::MOTION_HID_END, | 156 | camera_devices = Common::Input::CreateInputDevice(camera_params); |
| 155 | motion_devices.begin(), Common::Input::CreateDevice<Common::Input::InputDevice>); | 157 | nfc_devices = Common::Input::CreateInputDevice(nfc_params); |
| 156 | std::transform(trigger_params.begin(), trigger_params.end(), trigger_devices.begin(), | 158 | std::ranges::transform(output_params, output_devices.begin(), |
| 157 | Common::Input::CreateDevice<Common::Input::InputDevice>); | 159 | Common::Input::CreateOutputDevice); |
| 158 | std::transform(battery_params.begin(), battery_params.end(), battery_devices.begin(), | ||
| 159 | Common::Input::CreateDevice<Common::Input::InputDevice>); | ||
| 160 | camera_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(camera_params); | ||
| 161 | nfc_devices = Common::Input::CreateDevice<Common::Input::InputDevice>(nfc_params); | ||
| 162 | std::transform(output_params.begin(), output_params.end(), output_devices.begin(), | ||
| 163 | Common::Input::CreateDevice<Common::Input::OutputDevice>); | ||
| 164 | 160 | ||
| 165 | // Initialize TAS devices | 161 | // Initialize TAS devices |
| 166 | std::transform(tas_button_params.begin(), tas_button_params.end(), tas_button_devices.begin(), | 162 | std::ranges::transform(tas_button_params, tas_button_devices.begin(), |
| 167 | Common::Input::CreateDevice<Common::Input::InputDevice>); | 163 | Common::Input::CreateInputDevice); |
| 168 | std::transform(tas_stick_params.begin(), tas_stick_params.end(), tas_stick_devices.begin(), | 164 | std::ranges::transform(tas_stick_params, tas_stick_devices.begin(), |
| 169 | Common::Input::CreateDevice<Common::Input::InputDevice>); | 165 | Common::Input::CreateInputDevice); |
| 170 | } | 166 | } |
| 171 | 167 | ||
| 172 | void EmulatedController::LoadTASParams() { | 168 | void EmulatedController::LoadTASParams() { |
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index 658dbd318..e421828d2 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp | |||
| @@ -25,12 +25,12 @@ void EmulatedDevices::ReloadInput() { | |||
| 25 | Common::ParamPackage mouse_params; | 25 | Common::ParamPackage mouse_params; |
| 26 | mouse_params.Set("engine", "mouse"); | 26 | mouse_params.Set("engine", "mouse"); |
| 27 | mouse_params.Set("button", static_cast<int>(key_index)); | 27 | mouse_params.Set("button", static_cast<int>(key_index)); |
| 28 | mouse_device = Common::Input::CreateDevice<Common::Input::InputDevice>(mouse_params); | 28 | mouse_device = Common::Input::CreateInputDevice(mouse_params); |
| 29 | key_index++; | 29 | key_index++; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | mouse_stick_device = Common::Input::CreateDeviceFromString<Common::Input::InputDevice>( | 32 | mouse_stick_device = |
| 33 | "engine:mouse,axis_x:0,axis_y:1"); | 33 | Common::Input::CreateInputDeviceFromString("engine:mouse,axis_x:0,axis_y:1"); |
| 34 | 34 | ||
| 35 | // First two axis are reserved for mouse position | 35 | // First two axis are reserved for mouse position |
| 36 | key_index = 2; | 36 | key_index = 2; |
| @@ -38,7 +38,7 @@ void EmulatedDevices::ReloadInput() { | |||
| 38 | Common::ParamPackage mouse_params; | 38 | Common::ParamPackage mouse_params; |
| 39 | mouse_params.Set("engine", "mouse"); | 39 | mouse_params.Set("engine", "mouse"); |
| 40 | mouse_params.Set("axis", static_cast<int>(key_index)); | 40 | mouse_params.Set("axis", static_cast<int>(key_index)); |
| 41 | mouse_device = Common::Input::CreateDevice<Common::Input::InputDevice>(mouse_params); | 41 | mouse_device = Common::Input::CreateInputDevice(mouse_params); |
| 42 | key_index++; | 42 | key_index++; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| @@ -50,7 +50,7 @@ void EmulatedDevices::ReloadInput() { | |||
| 50 | keyboard_params.Set("button", static_cast<int>(key_index)); | 50 | keyboard_params.Set("button", static_cast<int>(key_index)); |
| 51 | keyboard_params.Set("port", 1); | 51 | keyboard_params.Set("port", 1); |
| 52 | keyboard_params.Set("pad", 0); | 52 | keyboard_params.Set("pad", 0); |
| 53 | keyboard_device = Common::Input::CreateDevice<Common::Input::InputDevice>(keyboard_params); | 53 | keyboard_device = Common::Input::CreateInputDevice(keyboard_params); |
| 54 | key_index++; | 54 | key_index++; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| @@ -62,11 +62,11 @@ void EmulatedDevices::ReloadInput() { | |||
| 62 | keyboard_params.Set("button", static_cast<int>(key_index)); | 62 | keyboard_params.Set("button", static_cast<int>(key_index)); |
| 63 | keyboard_params.Set("port", 1); | 63 | keyboard_params.Set("port", 1); |
| 64 | keyboard_params.Set("pad", 1); | 64 | keyboard_params.Set("pad", 1); |
| 65 | keyboard_device = Common::Input::CreateDevice<Common::Input::InputDevice>(keyboard_params); | 65 | keyboard_device = Common::Input::CreateInputDevice(keyboard_params); |
| 66 | key_index++; | 66 | key_index++; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | ring_analog_device = Common::Input::CreateDevice<Common::Input::InputDevice>(ring_params); | 69 | ring_analog_device = Common::Input::CreateInputDevice(ring_params); |
| 70 | 70 | ||
| 71 | for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { | 71 | for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { |
| 72 | if (!mouse_button_devices[index]) { | 72 | if (!mouse_button_devices[index]) { |