From 0db3923f1dbb481deeaa9329e00f50ea23a60e4c Mon Sep 17 00:00:00 2001 From: DarthMew Date: Sun, 17 Apr 2022 23:34:43 +0200 Subject: [PATCH] Add 'Controller NeGcon Twist Response' option & remove 'Controller NeGcon Steering Axis Deadzone' for slots 5 through 8 --- src/core/negcon.cpp | 23 +- src/core/negcon.h | 1 + src/libretro/libretro_core_options.h | 320 +++++------------------ src/libretro/libretro_host_interface.cpp | 44 ++-- 4 files changed, 119 insertions(+), 269 deletions(-) diff --git a/src/core/negcon.cpp b/src/core/negcon.cpp index 8069e20d..35fcb47a 100644 --- a/src/core/negcon.cpp +++ b/src/core/negcon.cpp @@ -67,12 +67,24 @@ void NeGcon::SetAxisState(s32 axis_code, float value) // Steering Axis: -1..1 -> 0..255 if (axis_code == static_cast(Axis::Steering)) { - const float float_value = + float float_value = (std::abs(value) < m_steering_deadzone) ? 0.0f : std::copysign((std::abs(value) - m_steering_deadzone) / (1.0f - m_steering_deadzone), value); - const u8 u8_value = static_cast(std::clamp(std::round(((float_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f)); + if (m_twist_response == "quadratic") + { + if (float_value < 0.0f) + float_value = -(float_value * float_value); + else + float_value = float_value * float_value; + } + else if (m_twist_response == "cubic") + { + float_value = float_value * float_value * float_value; + } + + const u8 u8_value = static_cast(std::clamp(std::round(((float_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value); return; @@ -293,9 +305,11 @@ u32 NeGcon::StaticGetVibrationMotorCount() Controller::SettingList NeGcon::StaticGetSettings() { - static constexpr std::array settings = { + static constexpr std::array settings = { {{SettingInfo::Type::Float, "SteeringDeadzone", TRANSLATABLE("NeGcon", "Steering Axis Deadzone"), - TRANSLATABLE("NeGcon", "Sets deadzone size for steering axis."), "0.00f", "0.00f", "0.99f", "0.01f"}}}; + TRANSLATABLE("NeGcon", "Sets deadzone size for steering axis."), "0.00f", "0.00f", "0.99f", "0.01f"}, + {SettingInfo::Type::String, "TwistResponse", TRANSLATABLE("NeGcon", "Twist Response"), + TRANSLATABLE("NeGcon", "Choose the twist response type of the left analog stick.")}}}; return SettingList(settings.begin(), settings.end()); } @@ -304,4 +318,5 @@ void NeGcon::LoadSettings(const char* section) { Controller::LoadSettings(section); m_steering_deadzone = g_host_interface->GetFloatSettingValue(section, "SteeringDeadzone", 0.10f); + m_twist_response = g_host_interface->GetStringSettingValue(section, "TwistResponse"); } diff --git a/src/core/negcon.h b/src/core/negcon.h index 8db6f160..94f56005 100644 --- a/src/core/negcon.h +++ b/src/core/negcon.h @@ -87,4 +87,5 @@ private: TransferState m_transfer_state = TransferState::Idle; float m_steering_deadzone = 0.00f; + std::string m_twist_response; }; diff --git a/src/libretro/libretro_core_options.h b/src/libretro/libretro_core_options.h index 95743c91..fa86c7d7 100644 --- a/src/libretro/libretro_core_options.h +++ b/src/libretro/libretro_core_options.h @@ -1467,6 +1467,24 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "0.10" }, + { + "duckstation_Controller1.TwistResponse", + "Controller 1 NeGcon Twist Response", + NULL, + "Sets the twist response type for the left analog stick. " + "'Quadratic' allows for greater precision than 'Linear' when making small movements, and is more suited for modern controllers, " + "While 'Cubic' further increases small movement precision, but 'exaggerates' larger movements. " + "'Linear' is generally only useful when using racing wheel peripherals.", + NULL, + "port", + { + { "linear", "Linear" }, + { "quadratic", "Quadratic" }, + { "cubic", "Cubic" }, + { NULL, NULL }, + }, + "linear" + }, { "duckstation_Controller2.ForceAnalogOnReset", "Controller 2 Force Analog Mode on Reset", @@ -1872,6 +1890,24 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "0.00" }, + { + "duckstation_Controller2.TwistResponse", + "Controller 2 NeGcon Twist Response", + NULL, + "Sets the twist response type for the left analog stick. " + "'Quadratic' allows for greater precision than 'Linear' when making small movements, and is more suited for modern controllers, " + "While 'Cubic' further increases small movement precision, but 'exaggerates' larger movements. " + "'Linear' is generally only useful when using racing wheel peripherals.", + NULL, + "port", + { + { "linear", "Linear" }, + { "quadratic", "Quadratic" }, + { "cubic", "Cubic" }, + { NULL, NULL }, + }, + "linear" + }, { "duckstation_Controller3.ForceAnalogOnReset", "Controller 3 Force Analog Mode on Reset", @@ -2166,6 +2202,24 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "0.10" }, + { + "duckstation_Controller3.TwistResponse", + "Controller 3 NeGcon Twist Response", + NULL, + "Sets the twist response type for the left analog stick. " + "'Quadratic' allows for greater precision than 'Linear' when making small movements, and is more suited for modern controllers, " + "While 'Cubic' further increases small movement precision, but 'exaggerates' larger movements. " + "'Linear' is generally only useful when using racing wheel peripherals.", + NULL, + "port", + { + { "linear", "Linear" }, + { "quadratic", "Quadratic" }, + { "cubic", "Cubic" }, + { NULL, NULL }, + }, + "linear" + }, { "duckstation_Controller4.ForceAnalogOnReset", "Controller 4 Force Analog Mode on Reset", @@ -2460,6 +2514,24 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "0.10" }, + { + "duckstation_Controller4.TwistResponse", + "Controller 4 NeGcon Twist Response", + NULL, + "Sets the twist response type for the left analog stick. " + "'Quadratic' allows for greater precision than 'Linear' when making small movements, and is more suited for modern controllers, " + "While 'Cubic' further increases small movement precision, but 'exaggerates' larger movements. " + "'Linear' is generally only useful when using racing wheel peripherals.", + NULL, + "port", + { + { "linear", "Linear" }, + { "quadratic", "Quadratic" }, + { "cubic", "Cubic" }, + { NULL, NULL }, + }, + "linear" + }, { "duckstation_Controller5.ForceAnalogOnReset", "Controller 5 Force Analog Mode on Reset", @@ -2692,68 +2764,6 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "8" }, - { - "duckstation_Controller5.SteeringDeadzone", - "Controller 5 NeGcon Steering Axis Deadzone", - NULL, - "Scales X coordinates relative to the center of the screen.", - NULL, - "port", - { - { "0.00", NULL }, - { "0.02", NULL }, - { "0.04", NULL }, - { "0.06", NULL }, - { "0.08", NULL }, - { "0.10", NULL }, - { "0.12", NULL }, - { "0.14", NULL }, - { "0.16", NULL }, - { "0.18", NULL }, - { "0.20", NULL }, - { "0.22", NULL }, - { "0.24", NULL }, - { "0.26", NULL }, - { "0.28", NULL }, - { "0.30", NULL }, - { "0.32", NULL }, - { "0.34", NULL }, - { "0.36", NULL }, - { "0.38", NULL }, - { "0.40", NULL }, - { "0.42", NULL }, - { "0.44", NULL }, - { "0.46", NULL }, - { "0.48", NULL }, - { "0.50", NULL }, - { "0.52", NULL }, - { "0.54", NULL }, - { "0.56", NULL }, - { "0.58", NULL }, - { "0.60", NULL }, - { "0.62", NULL }, - { "0.64", NULL }, - { "0.66", NULL }, - { "0.68", NULL }, - { "0.70", NULL }, - { "0.72", NULL }, - { "0.74", NULL }, - { "0.76", NULL }, - { "0.78", NULL }, - { "0.80", NULL }, - { "0.82", NULL }, - { "0.84", NULL }, - { "0.86", NULL }, - { "0.88", NULL }, - { "0.90", NULL }, - { "0.92", NULL }, - { "0.94", NULL }, - { "0.96", NULL }, - { "0.98", NULL }, - { NULL, NULL }, - }, - "0.10" - }, { "duckstation_Controller6.ForceAnalogOnReset", "Controller 6 Force Analog Mode on Reset", @@ -2986,68 +2996,6 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "8" }, - { - "duckstation_Controller6.SteeringDeadzone", - "Controller 6 NeGcon Steering Axis Deadzone", - NULL, - "Scales X coordinates relative to the center of the screen.", - NULL, - "port", - { - { "0.00", NULL }, - { "0.02", NULL }, - { "0.04", NULL }, - { "0.06", NULL }, - { "0.08", NULL }, - { "0.10", NULL }, - { "0.12", NULL }, - { "0.14", NULL }, - { "0.16", NULL }, - { "0.18", NULL }, - { "0.20", NULL }, - { "0.22", NULL }, - { "0.24", NULL }, - { "0.26", NULL }, - { "0.28", NULL }, - { "0.30", NULL }, - { "0.32", NULL }, - { "0.34", NULL }, - { "0.36", NULL }, - { "0.38", NULL }, - { "0.40", NULL }, - { "0.42", NULL }, - { "0.44", NULL }, - { "0.46", NULL }, - { "0.48", NULL }, - { "0.50", NULL }, - { "0.52", NULL }, - { "0.54", NULL }, - { "0.56", NULL }, - { "0.58", NULL }, - { "0.60", NULL }, - { "0.62", NULL }, - { "0.64", NULL }, - { "0.66", NULL }, - { "0.68", NULL }, - { "0.70", NULL }, - { "0.72", NULL }, - { "0.74", NULL }, - { "0.76", NULL }, - { "0.78", NULL }, - { "0.80", NULL }, - { "0.82", NULL }, - { "0.84", NULL }, - { "0.86", NULL }, - { "0.88", NULL }, - { "0.90", NULL }, - { "0.92", NULL }, - { "0.94", NULL }, - { "0.96", NULL }, - { "0.98", NULL }, - { NULL, NULL }, - }, - "0.10" - }, { "duckstation_Controller7.ForceAnalogOnReset", "Controller 7 Force Analog Mode on Reset", @@ -3280,68 +3228,6 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "8" }, - { - "duckstation_Controller7.SteeringDeadzone", - "Controller 7 NeGcon Steering Axis Deadzone", - NULL, - "Scales X coordinates relative to the center of the screen.", - NULL, - "port", - { - { "0.00", NULL }, - { "0.02", NULL }, - { "0.04", NULL }, - { "0.06", NULL }, - { "0.08", NULL }, - { "0.10", NULL }, - { "0.12", NULL }, - { "0.14", NULL }, - { "0.16", NULL }, - { "0.18", NULL }, - { "0.20", NULL }, - { "0.22", NULL }, - { "0.24", NULL }, - { "0.26", NULL }, - { "0.28", NULL }, - { "0.30", NULL }, - { "0.32", NULL }, - { "0.34", NULL }, - { "0.36", NULL }, - { "0.38", NULL }, - { "0.40", NULL }, - { "0.42", NULL }, - { "0.44", NULL }, - { "0.46", NULL }, - { "0.48", NULL }, - { "0.50", NULL }, - { "0.52", NULL }, - { "0.54", NULL }, - { "0.56", NULL }, - { "0.58", NULL }, - { "0.60", NULL }, - { "0.62", NULL }, - { "0.64", NULL }, - { "0.66", NULL }, - { "0.68", NULL }, - { "0.70", NULL }, - { "0.72", NULL }, - { "0.74", NULL }, - { "0.76", NULL }, - { "0.78", NULL }, - { "0.80", NULL }, - { "0.82", NULL }, - { "0.84", NULL }, - { "0.86", NULL }, - { "0.88", NULL }, - { "0.90", NULL }, - { "0.92", NULL }, - { "0.94", NULL }, - { "0.96", NULL }, - { "0.98", NULL }, - { NULL, NULL }, - }, - "0.10" - }, { "duckstation_Controller8.ForceAnalogOnReset", "Controller 8 Force Analog Mode on Reset", @@ -3574,68 +3460,6 @@ struct retro_core_option_v2_definition option_defs_us[] = { }, "8" }, - { - "duckstation_Controller8.SteeringDeadzone", - "Controller 8 NeGcon Steering Axis Deadzone", - NULL, - "Scales X coordinates relative to the center of the screen.", - NULL, - "port", - { - { "0.00", NULL }, - { "0.02", NULL }, - { "0.04", NULL }, - { "0.06", NULL }, - { "0.08", NULL }, - { "0.10", NULL }, - { "0.12", NULL }, - { "0.14", NULL }, - { "0.16", NULL }, - { "0.18", NULL }, - { "0.20", NULL }, - { "0.22", NULL }, - { "0.24", NULL }, - { "0.26", NULL }, - { "0.28", NULL }, - { "0.30", NULL }, - { "0.32", NULL }, - { "0.34", NULL }, - { "0.36", NULL }, - { "0.38", NULL }, - { "0.40", NULL }, - { "0.42", NULL }, - { "0.44", NULL }, - { "0.46", NULL }, - { "0.48", NULL }, - { "0.50", NULL }, - { "0.52", NULL }, - { "0.54", NULL }, - { "0.56", NULL }, - { "0.58", NULL }, - { "0.60", NULL }, - { "0.62", NULL }, - { "0.64", NULL }, - { "0.66", NULL }, - { "0.68", NULL }, - { "0.70", NULL }, - { "0.72", NULL }, - { "0.74", NULL }, - { "0.76", NULL }, - { "0.78", NULL }, - { "0.80", NULL }, - { "0.82", NULL }, - { "0.84", NULL }, - { "0.86", NULL }, - { "0.88", NULL }, - { "0.90", NULL }, - { "0.92", NULL }, - { "0.94", NULL }, - { "0.96", NULL }, - { "0.98", NULL }, - { NULL, NULL }, - }, - "0.10" - }, { "duckstation_Display.ShowOSDMessages", "Display OSD Messages", diff --git a/src/libretro/libretro_host_interface.cpp b/src/libretro/libretro_host_interface.cpp index 5ababef1..2a4699dd 100644 --- a/src/libretro/libretro_host_interface.cpp +++ b/src/libretro/libretro_host_interface.cpp @@ -97,33 +97,41 @@ void LibretroHostInterface::retro_set_environment() g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_UPDATE_DISPLAY_CALLBACK, &opts_update_display_cb); static const struct retro_controller_description pads[] = { - { "Digital Controller (Gamepad)", RETRO_DEVICE_JOYPAD }, - { "Analog Controller (DualShock)", RETRO_DEVICE_PS_DUALSHOCK }, - { "Analog Joystick", RETRO_DEVICE_PS_ANALOG_JOYSTICK }, - { "NeGcon", RETRO_DEVICE_PS_NEGCON }, - { "Namco GunCon", RETRO_DEVICE_PS_GUNCON }, - { "PlayStation Mouse", RETRO_DEVICE_PS_MOUSE }, + { "Digital Controller (Gamepad)", RETRO_DEVICE_JOYPAD }, + { "Analog Controller (DualShock)", RETRO_DEVICE_PS_DUALSHOCK }, + { "Analog Joystick", RETRO_DEVICE_PS_ANALOG_JOYSTICK }, + { "NeGcon", RETRO_DEVICE_PS_NEGCON }, + { "Namco GunCon", RETRO_DEVICE_PS_GUNCON }, + { "PlayStation Mouse", RETRO_DEVICE_PS_MOUSE }, { NULL, 0 }, }; static const struct retro_controller_description pads_mt[] = { - { "Digital Controller (Gamepad)", RETRO_DEVICE_JOYPAD }, - { "Analog Controller (DualShock)", RETRO_DEVICE_PS_DUALSHOCK }, - { "Analog Joystick", RETRO_DEVICE_PS_ANALOG_JOYSTICK }, - { "NeGcon", RETRO_DEVICE_PS_NEGCON }, - { "PlayStation Mouse", RETRO_DEVICE_PS_MOUSE }, + { "Digital Controller (Gamepad)", RETRO_DEVICE_JOYPAD }, + { "Analog Controller (DualShock)", RETRO_DEVICE_PS_DUALSHOCK }, + { "Analog Joystick", RETRO_DEVICE_PS_ANALOG_JOYSTICK }, + { "NeGcon", RETRO_DEVICE_PS_NEGCON }, + { "PlayStation Mouse", RETRO_DEVICE_PS_MOUSE }, + { NULL, 0 }, + }; + + static const struct retro_controller_description pads_mt2[] = { + { "Digital Controller (Gamepad)", RETRO_DEVICE_JOYPAD }, + { "Analog Controller (DualShock)", RETRO_DEVICE_PS_DUALSHOCK }, + { "Analog Joystick", RETRO_DEVICE_PS_ANALOG_JOYSTICK }, + { "PlayStation Mouse", RETRO_DEVICE_PS_MOUSE }, { NULL, 0 }, }; static const struct retro_controller_info ports[] = { - { pads, 6 }, - { pads, 6 }, - { pads_mt, 6 }, - { pads_mt, 6 }, - { pads_mt, 6 }, - { pads_mt, 6 }, + { pads, 7 }, + { pads, 7 }, { pads_mt, 6 }, { pads_mt, 6 }, + { pads_mt2, 5 }, + { pads_mt2, 5 }, + { pads_mt2, 5 }, + { pads_mt2, 5 }, { NULL, 0 }, }; @@ -877,6 +885,8 @@ bool LibretroHostInterface::UpdateCoreOptionsDisplay(bool controller) option_display.visible = negcon_active; option_display.key = (TinyString::FromFormat("duckstation_Controller%u.SteeringDeadzone", (i + 1))); g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); + option_display.key = (TinyString::FromFormat("duckstation_Controller%u.TwistResponse", (i + 1))); + g_retro_environment_callback(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display); option_display.visible = guncon_active; option_display.key = (TinyString::FromFormat("duckstation_Controller%u.XScale", (i + 1)));