mirror of
https://github.com/yuzu-emu/yuzu-android
synced 2024-12-23 04:31:20 -08:00
Merge pull request #13105 from t895/connection-fix
android: Misc controller fixes
This commit is contained in:
commit
8bbc209950
@ -64,17 +64,17 @@ data class PlayerInput(
|
|||||||
fun hasMapping(): Boolean {
|
fun hasMapping(): Boolean {
|
||||||
var hasMapping = false
|
var hasMapping = false
|
||||||
buttons.forEach {
|
buttons.forEach {
|
||||||
if (it != "[empty]") {
|
if (it != "[empty]" && it.isNotEmpty()) {
|
||||||
hasMapping = true
|
hasMapping = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
analogs.forEach {
|
analogs.forEach {
|
||||||
if (it != "[empty]") {
|
if (it != "[empty]" && it.isNotEmpty()) {
|
||||||
hasMapping = true
|
hasMapping = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
motions.forEach {
|
motions.forEach {
|
||||||
if (it != "[empty]") {
|
if (it != "[empty]" && it.isNotEmpty()) {
|
||||||
hasMapping = true
|
hasMapping = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,6 +292,9 @@ void EmulationSession::ShutdownEmulation() {
|
|||||||
// Unload user input.
|
// Unload user input.
|
||||||
m_system.HIDCore().UnloadInputDevices();
|
m_system.HIDCore().UnloadInputDevices();
|
||||||
|
|
||||||
|
// Enable all controllers
|
||||||
|
m_system.HIDCore().SetSupportedStyleTag({Core::HID::NpadStyleSet::All});
|
||||||
|
|
||||||
// Shutdown the main emulated process
|
// Shutdown the main emulated process
|
||||||
if (m_load_result == Core::SystemResultStatus::Success) {
|
if (m_load_result == Core::SystemResultStatus::Success) {
|
||||||
m_system.DetachDebugger();
|
m_system.DetachDebugger();
|
||||||
|
@ -102,8 +102,50 @@ void ApplyControllerConfig(size_t player_index,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<s32> GetSupportedStyles(int player_index) {
|
||||||
|
auto& hid_core = EmulationSession::GetInstance().System().HIDCore();
|
||||||
|
const auto npad_style_set = hid_core.GetSupportedStyleTag();
|
||||||
|
std::vector<s32> supported_indexes;
|
||||||
|
if (npad_style_set.fullkey == 1) {
|
||||||
|
supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::Fullkey));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (npad_style_set.joycon_dual == 1) {
|
||||||
|
supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::JoyconDual));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (npad_style_set.joycon_left == 1) {
|
||||||
|
supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::JoyconLeft));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (npad_style_set.joycon_right == 1) {
|
||||||
|
supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::JoyconRight));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player_index == 0 && npad_style_set.handheld == 1) {
|
||||||
|
supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::Handheld));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (npad_style_set.gamecube == 1) {
|
||||||
|
supported_indexes.push_back(static_cast<s32>(Core::HID::NpadStyleIndex::GameCube));
|
||||||
|
}
|
||||||
|
|
||||||
|
return supported_indexes;
|
||||||
|
}
|
||||||
|
|
||||||
void ConnectController(size_t player_index, bool connected) {
|
void ConnectController(size_t player_index, bool connected) {
|
||||||
auto& hid_core = EmulationSession::GetInstance().System().HIDCore();
|
auto& hid_core = EmulationSession::GetInstance().System().HIDCore();
|
||||||
|
ApplyControllerConfig(player_index, [&](Core::HID::EmulatedController* controller) {
|
||||||
|
auto supported_styles = GetSupportedStyles(player_index);
|
||||||
|
auto controller_style = controller->GetNpadStyleIndex(true);
|
||||||
|
auto style = std::find(supported_styles.begin(), supported_styles.end(),
|
||||||
|
static_cast<int>(controller_style));
|
||||||
|
if (style == supported_styles.end() && !supported_styles.empty()) {
|
||||||
|
controller->SetNpadStyleIndex(
|
||||||
|
static_cast<Core::HID::NpadStyleIndex>(supported_styles[0]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (player_index == 0) {
|
if (player_index == 0) {
|
||||||
auto* handheld = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld);
|
auto* handheld = hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld);
|
||||||
auto* player_one = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1);
|
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
|
|||||||
|
|
||||||
jintArray Java_org_yuzu_yuzu_1emu_features_input_NativeInput_getSupportedStyleTagsImpl(
|
jintArray Java_org_yuzu_yuzu_1emu_features_input_NativeInput_getSupportedStyleTagsImpl(
|
||||||
JNIEnv* env, jobject j_obj, jint j_player_index) {
|
JNIEnv* env, jobject j_obj, jint j_player_index) {
|
||||||
auto& hid_core = EmulationSession::GetInstance().System().HIDCore();
|
auto supported_styles = GetSupportedStyles(j_player_index);
|
||||||
const auto npad_style_set = hid_core.GetSupportedStyleTag();
|
jintArray j_supported_indexes = env->NewIntArray(supported_styles.size());
|
||||||
std::vector<s32> supported_indexes;
|
env->SetIntArrayRegion(j_supported_indexes, 0, supported_styles.size(),
|
||||||
if (npad_style_set.fullkey == 1) {
|
supported_styles.data());
|
||||||
supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::Fullkey));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (npad_style_set.joycon_dual == 1) {
|
|
||||||
supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::JoyconDual));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (npad_style_set.joycon_left == 1) {
|
|
||||||
supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::JoyconLeft));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (npad_style_set.joycon_right == 1) {
|
|
||||||
supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::JoyconRight));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (j_player_index == 0 && npad_style_set.handheld == 1) {
|
|
||||||
supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::Handheld));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (npad_style_set.gamecube == 1) {
|
|
||||||
supported_indexes.push_back(static_cast<u32>(Core::HID::NpadStyleIndex::GameCube));
|
|
||||||
}
|
|
||||||
|
|
||||||
jintArray j_supported_indexes = env->NewIntArray(supported_indexes.size());
|
|
||||||
env->SetIntArrayRegion(j_supported_indexes, 0, supported_indexes.size(),
|
|
||||||
supported_indexes.data());
|
|
||||||
return j_supported_indexes;
|
return j_supported_indexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user