mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-27 08:05:41 +00:00
ControllerInterface: Make axis-to-button deadzone customizable
This commit is contained in:
parent
6b7c068f83
commit
293c2f50cd
|
@ -1033,6 +1033,9 @@ void CommonHostInterface::UpdateControllerInputMap(SettingsInterface& si)
|
||||||
|
|
||||||
const float axis_scale = si.GetFloatValue(category, "AxisScale", 1.00f);
|
const float axis_scale = si.GetFloatValue(category, "AxisScale", 1.00f);
|
||||||
m_controller_interface->SetControllerAxisScale(controller_index, axis_scale);
|
m_controller_interface->SetControllerAxisScale(controller_index, axis_scale);
|
||||||
|
|
||||||
|
const float deadzone_size = si.GetFloatValue(category, "Deadzone", 0.25f);
|
||||||
|
m_controller_interface->SetControllerDeadzone(controller_index, deadzone_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,9 @@ public:
|
||||||
// Set scaling that will be applied on axis-to-axis mappings
|
// Set scaling that will be applied on axis-to-axis mappings
|
||||||
virtual bool SetControllerAxisScale(int controller_index, float scale) = 0;
|
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;
|
||||||
|
|
||||||
// Input monitoring for external access.
|
// Input monitoring for external access.
|
||||||
struct Hook
|
struct Hook
|
||||||
{
|
{
|
||||||
|
|
|
@ -273,9 +273,6 @@ bool SDLControllerInterface::BindControllerAxisToButton(int controller_index, in
|
||||||
|
|
||||||
bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_Event* ev)
|
bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_Event* ev)
|
||||||
{
|
{
|
||||||
// TODO: Make deadzone customizable.
|
|
||||||
static constexpr float deadzone = 8192.0f / 32768.0f;
|
|
||||||
|
|
||||||
const float value = static_cast<float>(ev->caxis.value) / (ev->caxis.value < 0 ? 32768.0f : 32767.0f);
|
const float value = static_cast<float>(ev->caxis.value) / (ev->caxis.value < 0 ? 32768.0f : 32767.0f);
|
||||||
Log_DebugPrintf("controller %d axis %d %d %f", ev->caxis.which, ev->caxis.axis, ev->caxis.value, value);
|
Log_DebugPrintf("controller %d axis %d %d %f", ev->caxis.which, ev->caxis.axis, ev->caxis.value, value);
|
||||||
|
|
||||||
|
@ -295,7 +292,7 @@ bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_Event* ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the other direction to false so large movements don't leave the opposite on
|
// set the other direction to false so large movements don't leave the opposite on
|
||||||
const bool outside_deadzone = (std::abs(value) >= deadzone);
|
const bool outside_deadzone = (std::abs(value) >= it->deadzone);
|
||||||
const bool positive = (value >= 0.0f);
|
const bool positive = (value >= 0.0f);
|
||||||
const ButtonCallback& other_button_cb = it->axis_button_mapping[ev->caxis.axis][BoolToUInt8(!positive)];
|
const ButtonCallback& other_button_cb = it->axis_button_mapping[ev->caxis.axis][BoolToUInt8(!positive)];
|
||||||
const ButtonCallback& button_cb = it->axis_button_mapping[ev->caxis.axis][BoolToUInt8(positive)];
|
const ButtonCallback& button_cb = it->axis_button_mapping[ev->caxis.axis][BoolToUInt8(positive)];
|
||||||
|
@ -398,3 +395,14 @@ bool SDLControllerInterface::SetControllerAxisScale(int controller_index, float
|
||||||
Log_InfoPrintf("Controller %d axis scale set to %f", controller_index, it->axis_scale);
|
Log_InfoPrintf("Controller %d axis scale set to %f", controller_index, it->axis_scale);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SDLControllerInterface::SetControllerDeadzone(int controller_index, float size /* = 0.25f */)
|
||||||
|
{
|
||||||
|
auto it = GetControllerDataForPlayerId(controller_index);
|
||||||
|
if (it == m_controllers.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
it->deadzone = std::clamp(std::abs(size), 0.01f, 0.99f);
|
||||||
|
Log_InfoPrintf("Controller %d deadzone size set to %f", controller_index, it->deadzone);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ public:
|
||||||
// Set scaling that will be applied on axis-to-axis mappings
|
// Set scaling that will be applied on axis-to-axis mappings
|
||||||
bool SetControllerAxisScale(int controller_index, float scale = 1.00f) override;
|
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;
|
||||||
|
|
||||||
void PollEvents() override;
|
void PollEvents() override;
|
||||||
|
|
||||||
bool ProcessSDLEvent(const SDL_Event* event);
|
bool ProcessSDLEvent(const SDL_Event* event);
|
||||||
|
@ -47,6 +50,7 @@ private:
|
||||||
|
|
||||||
// Scaling value of 1.30f to 1.40f recommended when using recent controllers
|
// Scaling value of 1.30f to 1.40f recommended when using recent controllers
|
||||||
float axis_scale = 1.00f;
|
float axis_scale = 1.00f;
|
||||||
|
float deadzone = 0.25f;
|
||||||
|
|
||||||
std::array<AxisCallback, MAX_NUM_AXISES> axis_mapping;
|
std::array<AxisCallback, MAX_NUM_AXISES> axis_mapping;
|
||||||
std::array<ButtonCallback, MAX_NUM_BUTTONS> button_mapping;
|
std::array<ButtonCallback, MAX_NUM_BUTTONS> button_mapping;
|
||||||
|
|
Loading…
Reference in a new issue