diff options
| author | 2022-12-17 17:16:13 -0800 | |
|---|---|---|
| committer | 2022-12-17 17:16:13 -0800 | |
| commit | 48108a8c9b28e08f86aab5c2ad41414e455f4706 (patch) | |
| tree | 2dc3ff390a17ebdee32958eac619632cef424fe4 /src/input_common/drivers/virtual_gamepad.cpp | |
| parent | Merge pull request #7450 from FernandoS27/ndc-vulkan (diff) | |
| parent | input_common: Add virtual gamepad (diff) | |
| download | yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.gz yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.tar.xz yuzu-48108a8c9b28e08f86aab5c2ad41414e455f4706.zip | |
Merge pull request #9456 from german77/virtual_gamepad
input_common: Add virtual gamepad
Diffstat (limited to 'src/input_common/drivers/virtual_gamepad.cpp')
| -rw-r--r-- | src/input_common/drivers/virtual_gamepad.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/input_common/drivers/virtual_gamepad.cpp b/src/input_common/drivers/virtual_gamepad.cpp new file mode 100644 index 000000000..7db945aa6 --- /dev/null +++ b/src/input_common/drivers/virtual_gamepad.cpp | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "input_common/drivers/virtual_gamepad.h" | ||
| 5 | |||
| 6 | namespace InputCommon { | ||
| 7 | constexpr std::size_t PlayerIndexCount = 10; | ||
| 8 | |||
| 9 | VirtualGamepad::VirtualGamepad(std::string input_engine_) : InputEngine(std::move(input_engine_)) { | ||
| 10 | for (std::size_t i = 0; i < PlayerIndexCount; i++) { | ||
| 11 | PreSetController(GetIdentifier(i)); | ||
| 12 | } | ||
| 13 | } | ||
| 14 | |||
| 15 | void VirtualGamepad::SetButtonState(std::size_t player_index, int button_id, bool value) { | ||
| 16 | if (player_index > PlayerIndexCount) { | ||
| 17 | return; | ||
| 18 | } | ||
| 19 | const auto identifier = GetIdentifier(player_index); | ||
| 20 | SetButton(identifier, button_id, value); | ||
| 21 | } | ||
| 22 | |||
| 23 | void VirtualGamepad::SetButtonState(std::size_t player_index, VirtualButton button_id, bool value) { | ||
| 24 | SetButtonState(player_index, static_cast<int>(button_id), value); | ||
| 25 | } | ||
| 26 | |||
| 27 | void VirtualGamepad::SetStickPosition(std::size_t player_index, int axis_id, float x_value, | ||
| 28 | float y_value) { | ||
| 29 | if (player_index > PlayerIndexCount) { | ||
| 30 | return; | ||
| 31 | } | ||
| 32 | const auto identifier = GetIdentifier(player_index); | ||
| 33 | SetAxis(identifier, axis_id * 2, x_value); | ||
| 34 | SetAxis(identifier, (axis_id * 2) + 1, y_value); | ||
| 35 | } | ||
| 36 | |||
| 37 | void VirtualGamepad::SetStickPosition(std::size_t player_index, VirtualStick axis_id, float x_value, | ||
| 38 | float y_value) { | ||
| 39 | SetStickPosition(player_index, static_cast<int>(axis_id), x_value, y_value); | ||
| 40 | } | ||
| 41 | |||
| 42 | void VirtualGamepad::ResetControllers() { | ||
| 43 | for (std::size_t i = 0; i < PlayerIndexCount; i++) { | ||
| 44 | SetStickPosition(i, VirtualStick::Left, 0.0f, 0.0f); | ||
| 45 | SetStickPosition(i, VirtualStick::Right, 0.0f, 0.0f); | ||
| 46 | |||
| 47 | SetButtonState(i, VirtualButton::ButtonA, false); | ||
| 48 | SetButtonState(i, VirtualButton::ButtonB, false); | ||
| 49 | SetButtonState(i, VirtualButton::ButtonX, false); | ||
| 50 | SetButtonState(i, VirtualButton::ButtonY, false); | ||
| 51 | SetButtonState(i, VirtualButton::StickL, false); | ||
| 52 | SetButtonState(i, VirtualButton::StickR, false); | ||
| 53 | SetButtonState(i, VirtualButton::TriggerL, false); | ||
| 54 | SetButtonState(i, VirtualButton::TriggerR, false); | ||
| 55 | SetButtonState(i, VirtualButton::TriggerZL, false); | ||
| 56 | SetButtonState(i, VirtualButton::TriggerZR, false); | ||
| 57 | SetButtonState(i, VirtualButton::ButtonPlus, false); | ||
| 58 | SetButtonState(i, VirtualButton::ButtonMinus, false); | ||
| 59 | SetButtonState(i, VirtualButton::ButtonLeft, false); | ||
| 60 | SetButtonState(i, VirtualButton::ButtonUp, false); | ||
| 61 | SetButtonState(i, VirtualButton::ButtonRight, false); | ||
| 62 | SetButtonState(i, VirtualButton::ButtonDown, false); | ||
| 63 | SetButtonState(i, VirtualButton::ButtonSL, false); | ||
| 64 | SetButtonState(i, VirtualButton::ButtonSR, false); | ||
| 65 | SetButtonState(i, VirtualButton::ButtonHome, false); | ||
| 66 | SetButtonState(i, VirtualButton::ButtonCapture, false); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | PadIdentifier VirtualGamepad::GetIdentifier(std::size_t player_index) const { | ||
| 71 | return { | ||
| 72 | .guid = Common::UUID{}, | ||
| 73 | .port = player_index, | ||
| 74 | .pad = 0, | ||
| 75 | }; | ||
| 76 | } | ||
| 77 | |||
| 78 | } // namespace InputCommon | ||