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)
This commit is contained in:
Flyinghead 2023-10-30 18:28:29 +01:00
parent c0de126b2b
commit 7b71bd319c
5 changed files with 10 additions and 5 deletions

View File

@ -65,6 +65,7 @@ public:
} }
else else
INFO_LOG(INPUT, "using custom mapping '%s'", input_mapper->name.c_str()); INFO_LOG(INPUT, "using custom mapping '%s'", input_mapper->name.c_str());
hasAnalogStick = true;
} }
~EvdevGamepadDevice() override ~EvdevGamepadDevice() override
{ {

View File

@ -1682,16 +1682,16 @@ static void gui_display_settings()
ImGui::SameLine(0, 16 * settings.display.uiScale); ImGui::SameLine(0, 16 * settings.display.uiScale);
int power = gamepad->get_rumble_power(); int power = gamepad->get_rumble_power();
ImGui::SetNextItemWidth(150 * settings.display.uiScale); 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); gamepad->set_rumble_power(power);
} }
if (gamepad->has_analog_stick()) if (gamepad->has_analog_stick())
{ {
ImGui::SameLine(0, 16 * settings.display.uiScale); 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); ImGui::SetNextItemWidth(150 * settings.display.uiScale);
if (ImGui::SliderFloat("Deadzone", &deadzone, 0.0f, 1.0f)) if (ImGui::SliderInt("Dead zone", &deadzone, 0, 100, "%d%%"))
gamepad->set_dead_zone(deadzone); gamepad->set_dead_zone(deadzone / 100.f);
} }
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::PopID(); ImGui::PopID();

View File

@ -45,6 +45,7 @@ public:
char buf[32]; char buf[32];
sprintf(buf, "xinput-%d", xinput_port + 1); sprintf(buf, "xinput-%d", xinput_port + 1);
_unique_id = buf; _unique_id = buf;
hasAnalogStick = true;
} }
std::shared_ptr<InputMapping> getDefaultMapping() override { std::shared_ptr<InputMapping> getDefaultMapping() override {

View File

@ -107,11 +107,13 @@ public:
{ {
input_mapper = std::make_shared<IdentityInputMapping>(); input_mapper = std::make_shared<IdentityInputMapping>();
rumbleEnabled = true; rumbleEnabled = true;
// hasAnalogStick = true; // TODO has an analog stick but input mapping isn't persisted
} }
else else
{ {
loadMapping(); loadMapping();
save_mapping(); save_mapping();
hasAnalogStick = !fullAxes.empty();
} }
} }
~AndroidGamepadDevice() override ~AndroidGamepadDevice() override

View File

@ -229,7 +229,7 @@ public:
[gcController.extendedGamepad.rightThumbstick.yAxis setValueChangedHandler:^(GCControllerAxisInput *axis, float value) { [gcController.extendedGamepad.rightThumbstick.yAxis setValueChangedHandler:^(GCControllerAxisInput *axis, float value) {
gamepad_axis_input(IOS_AXIS_RY, (int)std::roundf(-32767.f * value)); gamepad_axis_input(IOS_AXIS_RY, (int)std::roundf(-32767.f * value));
}]; }];
hasAnalogStick = true;
} }
else else
{ {
@ -491,6 +491,7 @@ public:
_name = "Virtual Gamepad"; _name = "Virtual Gamepad";
_unique_id = "ios-virtual-gamepad"; _unique_id = "ios-virtual-gamepad";
input_mapper = getDefaultMapping(); input_mapper = getDefaultMapping();
//hasAnalogStick = true; // TODO has an analog stick but input mapping isn't persisted
} }
bool is_virtual_gamepad() override { return true; } bool is_virtual_gamepad() override { return true; }