From 7b71bd319c72300764d8d6acf7ce1ec9ed093e28 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Mon, 30 Oct 2023 18:28:29 +0100 Subject: [PATCH] Android and iOS support. Change dead zone to integer % value in UI UI: dead zone changes from 0 to 100%. Add % for Rumble too. Support Android and iOS gamepads. Assume legacy gamepads have an analog stick (evdev, xinput) --- core/linux-dist/evdev_gamepad.h | 1 + core/rend/gui.cpp | 8 ++++---- core/windows/xinput_gamepad.h | 1 + .../flycast/src/main/jni/src/android_gamepad.h | 2 ++ shell/apple/emulator-ios/emulator/ios_gamepad.h | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/linux-dist/evdev_gamepad.h b/core/linux-dist/evdev_gamepad.h index ae40832e8..cfbe27355 100644 --- a/core/linux-dist/evdev_gamepad.h +++ b/core/linux-dist/evdev_gamepad.h @@ -65,6 +65,7 @@ public: } else INFO_LOG(INPUT, "using custom mapping '%s'", input_mapper->name.c_str()); + hasAnalogStick = true; } ~EvdevGamepadDevice() override { diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index deffbbbf6..fa2353ab7 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -1682,16 +1682,16 @@ static void gui_display_settings() ImGui::SameLine(0, 16 * settings.display.uiScale); int power = gamepad->get_rumble_power(); ImGui::SetNextItemWidth(150 * settings.display.uiScale); - if (ImGui::SliderInt("Rumble", &power, 0, 100)) + if (ImGui::SliderInt("Rumble", &power, 0, 100, "%d%%")) gamepad->set_rumble_power(power); } if (gamepad->has_analog_stick()) { ImGui::SameLine(0, 16 * settings.display.uiScale); - float deadzone = gamepad->get_dead_zone(); + int deadzone = std::round(gamepad->get_dead_zone() * 100.f); ImGui::SetNextItemWidth(150 * settings.display.uiScale); - if (ImGui::SliderFloat("Deadzone", &deadzone, 0.0f, 1.0f)) - gamepad->set_dead_zone(deadzone); + if (ImGui::SliderInt("Dead zone", &deadzone, 0, 100, "%d%%")) + gamepad->set_dead_zone(deadzone / 100.f); } ImGui::NextColumn(); ImGui::PopID(); diff --git a/core/windows/xinput_gamepad.h b/core/windows/xinput_gamepad.h index 873fc17d7..a6243e8fe 100644 --- a/core/windows/xinput_gamepad.h +++ b/core/windows/xinput_gamepad.h @@ -45,6 +45,7 @@ public: char buf[32]; sprintf(buf, "xinput-%d", xinput_port + 1); _unique_id = buf; + hasAnalogStick = true; } std::shared_ptr getDefaultMapping() override { diff --git a/shell/android-studio/flycast/src/main/jni/src/android_gamepad.h b/shell/android-studio/flycast/src/main/jni/src/android_gamepad.h index 159bf0b6b..c95b62057 100644 --- a/shell/android-studio/flycast/src/main/jni/src/android_gamepad.h +++ b/shell/android-studio/flycast/src/main/jni/src/android_gamepad.h @@ -107,11 +107,13 @@ public: { input_mapper = std::make_shared(); rumbleEnabled = true; + // hasAnalogStick = true; // TODO has an analog stick but input mapping isn't persisted } else { loadMapping(); save_mapping(); + hasAnalogStick = !fullAxes.empty(); } } ~AndroidGamepadDevice() override diff --git a/shell/apple/emulator-ios/emulator/ios_gamepad.h b/shell/apple/emulator-ios/emulator/ios_gamepad.h index 5e4a4abd1..5b4b33317 100644 --- a/shell/apple/emulator-ios/emulator/ios_gamepad.h +++ b/shell/apple/emulator-ios/emulator/ios_gamepad.h @@ -229,7 +229,7 @@ public: [gcController.extendedGamepad.rightThumbstick.yAxis setValueChangedHandler:^(GCControllerAxisInput *axis, float value) { gamepad_axis_input(IOS_AXIS_RY, (int)std::roundf(-32767.f * value)); }]; - + hasAnalogStick = true; } else { @@ -491,6 +491,7 @@ public: _name = "Virtual Gamepad"; _unique_id = "ios-virtual-gamepad"; input_mapper = getDefaultMapping(); + //hasAnalogStick = true; // TODO has an analog stick but input mapping isn't persisted } bool is_virtual_gamepad() override { return true; }