diff options
| author | 2024-02-21 10:43:46 -0500 | |
|---|---|---|
| committer | 2024-02-21 10:43:46 -0500 | |
| commit | 8bbc209950178ca7258bfc22a08101cb30c29a58 (patch) | |
| tree | 642d3775fa0136b84bbfcff7363441bd8f4145df /src/android | |
| parent | fs: add missing mutex header for member (#13106) (diff) | |
| parent | android: Connect controllers with supported styles (diff) | |
| download | yuzu-8bbc209950178ca7258bfc22a08101cb30c29a58.tar.gz yuzu-8bbc209950178ca7258bfc22a08101cb30c29a58.tar.xz yuzu-8bbc209950178ca7258bfc22a08101cb30c29a58.zip | |
Merge pull request #13105 from t895/connection-fix
android: Misc controller fixes
Diffstat (limited to 'src/android')
3 files changed, 52 insertions, 33 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt index d35de80c4..a84ac77a2 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt | |||
| @@ -64,17 +64,17 @@ data class PlayerInput( | |||
| 64 | fun hasMapping(): Boolean { | 64 | fun hasMapping(): Boolean { |
| 65 | var hasMapping = false | 65 | var hasMapping = false |
| 66 | buttons.forEach { | 66 | buttons.forEach { |
| 67 | if (it != "[empty]") { | 67 | if (it != "[empty]" && it.isNotEmpty()) { |
| 68 | hasMapping = true | 68 | hasMapping = true |
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| 71 | analogs.forEach { | 71 | analogs.forEach { |
| 72 | if (it != "[empty]") { | 72 | if (it != "[empty]" && it.isNotEmpty()) { |
| 73 | hasMapping = true | 73 | hasMapping = true |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | motions.forEach { | 76 | motions.forEach { |
| 77 | if (it != "[empty]") { | 77 | if (it != "[empty]" && it.isNotEmpty()) { |
| 78 | hasMapping = true | 78 | hasMapping = true |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 4ea82e217..1226219ad 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp | |||
| @@ -292,6 +292,9 @@ void EmulationSession::ShutdownEmulation() { | |||
| 292 | // Unload user input. | 292 | // Unload user input. |
| 293 | m_system.HIDCore().UnloadInputDevices(); | 293 | m_system.HIDCore().UnloadInputDevices(); |
| 294 | 294 | ||
| 295 | // Enable all controllers | ||
| 296 | m_system.HIDCore().SetSupportedStyleTag({Core::HID::NpadStyleSet::All}); | ||
| 297 | |||
| 295 | // Shutdown the main emulated process | 298 | // Shutdown the main emulated process |
| 296 | if (m_load_result == Core::SystemResultStatus::Success) { | 299 | if (m_load_result == Core::SystemResultStatus::Success) { |
| 297 | m_system.DetachDebugger(); | 300 | m_system.DetachDebugger(); |
diff --git a/src/android/app/src/main/jni/native_input.cpp b/src/android/app/src/main/jni/native_input.cpp index 37a65f2b8..4935a4607 100644 --- a/src/android/app/src/main/jni/native_input.cpp +++ b/src/android/app/src/main/jni/native_input.cpp | |||
| @@ -102,8 +102,50 @@ void ApplyControllerConfig(size_t player_index, | |||
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | std::vector<s32> GetSupportedStyles(int player_index) { | ||
| 106 | auto& hid_core = EmulationSession::GetInstance().System().HIDCore(); | ||
| 107 | const auto npad_style_set = hid_core.GetSupportedStyleTag(); | ||
| 108 | std::vector<s32> supported_indexes; | ||
| 109 | if (npad_style_set.fullkey == 1) { | ||
| 110 | supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::Fullkey)); | ||
| 111 | } | ||
| 112 | |||
| 113 | if (npad_style_set.joycon_dual == 1) { | ||
| 114 | supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::JoyconDual)); | ||
| 115 | } | ||
| 116 | |||
| 117 | if (npad_style_set.joycon_left == 1) { | ||
| 118 | supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::JoyconLeft)); | ||
| 119 | } | ||
| 120 | |||
| 121 | if (npad_style_set.joycon_right == 1) { | ||
| 122 | supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::JoyconRight)); | ||
| 123 | } | ||
| 124 | |||
| 125 | if (player_index == 0 && npad_style_set.handheld == 1) { | ||
| 126 | supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::Handheld)); | ||
| 127 | } | ||
| 128 | |||
| 129 | if (npad_style_set.gamecube == 1) { | ||
| 130 | supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::GameCube)); | ||
| 131 | } | ||
| 132 | |||
| 133 | return supported_indexes; | ||
| 134 | } | ||
| 135 | |||
| 105 | void ConnectController(size_t player_index, bool connected) { | 136 | void ConnectController(size_t player_index, bool connected) { |
| 106 | auto& hid_core = EmulationSession::GetInstance().System().HIDCore(); | 137 | auto& hid_core = EmulationSession::GetInstance().System().HIDCore(); |
| 138 | ApplyControllerConfig(player_index, [&](Core::HID::EmulatedController* controller) { | ||
| 139 | auto supported_styles = GetSupportedStyles(player_index); | ||
| 140 | auto controller_style = controller->GetNpadStyleIndex(true); | ||
| 141 | auto style = std::find(supported_styles.begin(), supported_styles.end(), | ||
| 142 | static_cast<int>(controller_style)); | ||
| 143 | if (style == supported_styles.end() && !supported_styles.empty()) { | ||
| 144 | controller->SetNpadStyleIndex( | ||
| 145 | static_cast<Core::HID::NpadStyleIndex>(supported_styles[0])); | ||
| 146 | } | ||
| 147 | }); | ||
| 148 | |||
| 107 | if (player_index == 0) { | 149 | if (player_index == 0) { |
| 108 | auto* handheld = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); | 150 | auto* handheld = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); |
| 109 | auto* player_one = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); | 151 | auto* player_one = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); |
| @@ -522,36 +564,10 @@ jint Java_org_yuzu_yuzu_1emu_features_input_NativeInput_getButtonNameImpl(JNIEnv | |||
| 522 | 564 | ||
| 523 | jintArray Java_org_yuzu_yuzu_1emu_features_input_NativeInput_getSupportedStyleTagsImpl( | 565 | jintArray Java_org_yuzu_yuzu_1emu_features_input_NativeInput_getSupportedStyleTagsImpl( |
| 524 | JNIEnv* env, jobject j_obj, jint j_player_index) { | 566 | JNIEnv* env, jobject j_obj, jint j_player_index) { |
| 525 | auto& hid_core = EmulationSession::GetInstance().System().HIDCore(); | 567 | auto supported_styles = GetSupportedStyles(j_player_index); |
| 526 | const auto npad_style_set = hid_core.GetSupportedStyleTag(); | 568 | jintArray j_supported_indexes = env->NewIntArray(supported_styles.size()); |
| 527 | std::vector<s32> supported_indexes; | 569 | env->SetIntArrayRegion(j_supported_indexes, 0, supported_styles.size(), |
| 528 | if (npad_style_set.fullkey == 1) { | 570 | supported_styles.data()); |
| 529 | supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::Fullkey)); | ||
| 530 | } | ||
| 531 | |||
| 532 | if (npad_style_set.joycon_dual == 1) { | ||
| 533 | supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::JoyconDual)); | ||
| 534 | } | ||
| 535 | |||
| 536 | if (npad_style_set.joycon_left == 1) { | ||
| 537 | supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::JoyconLeft)); | ||
| 538 | } | ||
| 539 | |||
| 540 | if (npad_style_set.joycon_right == 1) { | ||
| 541 | supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::JoyconRight)); | ||
| 542 | } | ||
| 543 | |||
| 544 | if (j_player_index == 0 && npad_style_set.handheld == 1) { | ||
| 545 | supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::Handheld)); | ||
| 546 | } | ||
| 547 | |||
| 548 | if (npad_style_set.gamecube == 1) { | ||
| 549 | supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::GameCube)); | ||
| 550 | } | ||
| 551 | |||
| 552 | jintArray j_supported_indexes = env->NewIntArray(supported_indexes.size()); | ||
| 553 | env->SetIntArrayRegion(j_supported_indexes, 0, supported_indexes.size(), | ||
| 554 | supported_indexes.data()); | ||
| 555 | return j_supported_indexes; | 571 | return j_supported_indexes; |
| 556 | } | 572 | } |
| 557 | 573 | ||