Merge pull request #1067 from ggrtk/analog-axis-scale

ControllerInterface: Move axis scaling into AnalogController class
This commit is contained in:
Connor McLaughlin 2020-11-14 23:20:04 +10:00 committed by GitHub
commit 925bb7173f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 21 additions and 46 deletions

View File

@ -82,7 +82,8 @@ void AnalogController::SetAxisState(s32 axis_code, float value)
return;
// -1..1 -> 0..255
const u8 u8_value = static_cast<u8>(std::clamp(((value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
const float scaled_value = std::clamp(value * m_axis_scale, -1.0f, 1.0f);
const u8 u8_value = static_cast<u8>(std::clamp(((scaled_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
SetAxisState(static_cast<Axis>(axis_code), u8_value);
}
@ -567,6 +568,8 @@ void AnalogController::LoadSettings(const char* section)
Controller::LoadSettings(section);
m_auto_enable_analog = g_host_interface->GetBoolSettingValue(section, "AutoEnableAnalog", false);
m_analog_dpad_in_digital_mode = g_host_interface->GetBoolSettingValue(section, "AnalogDPadInDigitalMode", false);
m_axis_scale =
std::clamp(std::abs(g_host_interface->GetFloatSettingValue(section, "AxisScale", 1.00f)), 0.01f, 1.50f);
m_rumble_bias =
static_cast<u8>(std::min<u32>(g_host_interface->GetIntSettingValue(section, "VibrationBias", 8), 255));
}

View File

@ -137,6 +137,7 @@ private:
bool m_auto_enable_analog = false;
bool m_analog_dpad_in_digital_mode = false;
float m_axis_scale = 1.00f;
u8 m_rumble_bias = 8;
bool m_analog_mode = false;

View File

@ -19,7 +19,7 @@ PlayStationMouse::~PlayStationMouse() = default;
ControllerType PlayStationMouse::GetType() const
{
return ControllerType::NamcoGunCon;
return ControllerType::PlayStationMouse;
}
std::optional<s32> PlayStationMouse::GetAxisCodeByName(std::string_view axis_name) const

View File

@ -457,7 +457,7 @@ void LibretroHostInterface::OnSystemDestroyed()
m_using_hardware_renderer = false;
}
static std::array<retro_core_option_definition, 42> s_option_definitions = {{
static std::array<retro_core_option_definition, 44> s_option_definitions = {{
{"duckstation_Console.Region",
"Console Region",
"Determines which region/hardware to emulate. Auto-Detect will use the region of the disc inserted.",
@ -723,6 +723,12 @@ static std::array<retro_core_option_definition, 42> s_option_definitions = {{
"Allows you to use the analog sticks to control the d-pad in digital mode, as well as the buttons.",
{{"true", "Enabled"}, {"false", "Disabled"}},
"false"},
{"duckstation_Controller1.AxisScale",
"Controller 1 Analog Axis Scale",
"Sets the analog stick axis scaling factor.",
{{"1.00f", "1.00"}, {"1.40f", "1.40"}},
"1.00f"
},
{"duckstation_Controller2.Type",
"Controller 2 Type",
"Sets the type of controller for Slot 2.",
@ -743,6 +749,12 @@ static std::array<retro_core_option_definition, 42> s_option_definitions = {{
"Allows you to use the analog sticks to control the d-pad in digital mode, as well as the buttons.",
{{"true", "Enabled"}, {"false", "Disabled"}},
"false"},
{"duckstation_Controller2.AxisScale",
"Controller 2 Analog Axis Scale",
"Sets the analog stick axis scaling factor.",
{{"1.00f", "1.00"}, {"1.40f", "1.40"}},
"1.00f"
},
{"duckstation_Display.ShowOSDMessages",
"Display OSD Messages",
"Shows on-screen messages generated by the core.",

View File

@ -1145,10 +1145,6 @@ void CommonHostInterface::UpdateControllerInputMap(SettingsInterface& si)
if (m_controller_interface)
{
const float axis_scale = si.GetFloatValue(category, "AxisScale", 1.00f);
m_controller_interface->SetControllerAxisScale(controller_index,
(ctype == ControllerType::AnalogController) ? axis_scale : 1.00f);
const float deadzone_size = si.GetFloatValue(category, "Deadzone", 0.25f);
m_controller_interface->SetControllerDeadzone(controller_index, deadzone_size);
}

View File

@ -62,9 +62,6 @@ public:
virtual u32 GetControllerRumbleMotorCount(int controller_index) = 0;
virtual void SetControllerRumbleStrength(int controller_index, const float* strengths, u32 num_motors) = 0;
// Set scaling that will be applied on axis-to-axis mappings
virtual bool SetControllerAxisScale(int controller_index, float scale) = 0;
// Set deadzone that will be applied on axis-to-button mappings
virtual bool SetControllerDeadzone(int controller_index, float size) = 0;

View File

@ -320,8 +320,7 @@ bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_Event* ev)
const AxisCallback& cb = it->axis_mapping[ev->caxis.axis];
if (cb)
{
// Apply axis scaling only when controller axis is mapped to an axis
cb(std::clamp(it->axis_scale * value, -1.0f, 1.0f));
cb(value);
return true;
}
@ -427,17 +426,6 @@ void SDLControllerInterface::SetControllerRumbleStrength(int controller_index, c
}
}
bool SDLControllerInterface::SetControllerAxisScale(int controller_index, float scale /* = 1.00f */)
{
auto it = GetControllerDataForPlayerId(controller_index);
if (it == m_controllers.end())
return false;
it->axis_scale = std::clamp(std::abs(scale), 0.01f, 1.50f);
Log_InfoPrintf("Controller %d axis scale set to %f", controller_index, it->axis_scale);
return true;
}
bool SDLControllerInterface::SetControllerDeadzone(int controller_index, float size /* = 0.25f */)
{
auto it = GetControllerDataForPlayerId(controller_index);

View File

@ -35,9 +35,6 @@ public:
u32 GetControllerRumbleMotorCount(int controller_index) override;
void SetControllerRumbleStrength(int controller_index, const float* strengths, u32 num_motors) override;
// Set scaling that will be applied on axis-to-axis mappings
bool SetControllerAxisScale(int controller_index, float scale = 1.00f) override;
// Set deadzone that will be applied on axis-to-button mappings
bool SetControllerDeadzone(int controller_index, float size = 0.25f) override;
@ -54,8 +51,6 @@ private:
int joystick_id;
int player_id;
// Scaling value of 1.30f to 1.40f recommended when using recent controllers
float axis_scale = 1.00f;
float deadzone = 0.25f;
std::array<AxisCallback, MAX_NUM_AXISES> axis_mapping;

View File

@ -229,8 +229,7 @@ bool XInputControllerInterface::HandleAxisEvent(u32 index, Axis axis, s32 value)
const AxisCallback& cb = m_controllers[index].axis_mapping[static_cast<u32>(axis)];
if (cb)
{
// Apply axis scaling only when controller axis is mapped to an axis
cb(std::clamp(m_controllers[index].axis_scale * f_value, -1.0f, 1.0f));
cb(f_value);
return true;
}
@ -302,17 +301,6 @@ void XInputControllerInterface::SetControllerRumbleStrength(int controller_index
m_xinput_set_state(static_cast<u32>(controller_index), &vib);
}
bool XInputControllerInterface::SetControllerAxisScale(int controller_index, float scale /* = 1.00f */)
{
if (static_cast<u32>(controller_index) >= XUSER_MAX_COUNT || !m_controllers[controller_index].connected)
return false;
m_controllers[static_cast<u32>(controller_index)].axis_scale = std::clamp(std::abs(scale), 0.01f, 1.50f);
Log_InfoPrintf("Controller %d axis scale set to %f", controller_index,
m_controllers[static_cast<u32>(controller_index)].axis_scale);
return true;
}
bool XInputControllerInterface::SetControllerDeadzone(int controller_index, float size /* = 0.25f */)
{
if (static_cast<u32>(controller_index) >= XUSER_MAX_COUNT || !m_controllers[controller_index].connected)

View File

@ -32,9 +32,6 @@ public:
u32 GetControllerRumbleMotorCount(int controller_index) override;
void SetControllerRumbleStrength(int controller_index, const float* strengths, u32 num_motors) override;
// Set scaling that will be applied on axis-to-axis mappings
bool SetControllerAxisScale(int controller_index, float scale = 1.00f) override;
// Set deadzone that will be applied on axis-to-button mappings
bool SetControllerDeadzone(int controller_index, float size = 0.25f) override;
@ -62,8 +59,6 @@ private:
XINPUT_STATE last_state = {};
bool connected = false;
// Scaling value of 1.30f to 1.40f recommended when using recent controllers
float axis_scale = 1.00f;
float deadzone = 0.25f;
std::array<AxisCallback, MAX_NUM_AXISES> axis_mapping;