From 230e06dec73eb1bac45e19327c976b9e540d6a2f Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 28 Jun 2020 13:03:47 +0400 Subject: [PATCH] Make joysticks dead zone configurable (bug #5502) --- CHANGELOG.md | 1 + apps/openmw/mwinput/bindingsmanager.cpp | 5 +++++ apps/openmw/mwinput/bindingsmanager.hpp | 2 ++ apps/openmw/mwinput/controllermanager.cpp | 4 ++++ docs/source/reference/modding/settings/input.rst | 12 ++++++++++++ extern/oics/ICSInputControlSystem.cpp | 1 + extern/oics/ICSInputControlSystem.h | 4 ++++ extern/oics/ICSInputControlSystem_joystick.cpp | 11 +++++------ files/settings-default.cfg | 3 +++ 9 files changed, 37 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce2966cbfa..ab1b61a7c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ Bug #5485: Intimidate doesn't increase disposition on marginal wins Bug #5490: Hits to carried left slot aren't redistributed if there's no shield equipped Bug #5499: Faction advance is available when requirements not met + Bug #5502: Dead zone for analogue stick movement is too small Feature #390: 3rd person look "over the shoulder" Feature #2386: Distant Statics in the form of Object Paging Feature #5297: Add a search function to the "Datafiles" tab of the OpenMW launcher diff --git a/apps/openmw/mwinput/bindingsmanager.cpp b/apps/openmw/mwinput/bindingsmanager.cpp index 11f714205d..9d77ec99cf 100644 --- a/apps/openmw/mwinput/bindingsmanager.cpp +++ b/apps/openmw/mwinput/bindingsmanager.cpp @@ -226,6 +226,11 @@ namespace MWInput } } + void BindingsManager::setJoystickDeadZone(float deadZone) + { + mInputBinder->setJoystickDeadZone(deadZone); + } + float BindingsManager::getActionValue (int id) const { return mInputBinder->getChannel(id)->getValue(); diff --git a/apps/openmw/mwinput/bindingsmanager.hpp b/apps/openmw/mwinput/bindingsmanager.hpp index 35b26c877c..7a44a1a335 100644 --- a/apps/openmw/mwinput/bindingsmanager.hpp +++ b/apps/openmw/mwinput/bindingsmanager.hpp @@ -36,6 +36,8 @@ namespace MWInput void setPlayerControlsEnabled(bool enabled); + void setJoystickDeadZone(float deadZone); + bool isLeftOrRightButton(int action, bool joystick) const; bool actionIsActive(int id) const; diff --git a/apps/openmw/mwinput/controllermanager.cpp b/apps/openmw/mwinput/controllermanager.cpp index 3b1f587ce7..11e1c6350d 100644 --- a/apps/openmw/mwinput/controllermanager.cpp +++ b/apps/openmw/mwinput/controllermanager.cpp @@ -72,6 +72,10 @@ namespace MWInput float uiScale = Settings::Manager::getFloat("scaling factor", "GUI"); if (uiScale != 0.f) mInvUiScalingFactor = 1.f / uiScale; + + float deadZoneRadius = Settings::Manager::getFloat("joystick dead zone", "Input"); + deadZoneRadius = std::min(std::max(deadZoneRadius, 0.0f), 0.5f); + mBindingsManager->setJoystickDeadZone(deadZoneRadius); } void ControllerManager::processChangedSettings(const Settings::CategorySettingVector& changed) diff --git a/docs/source/reference/modding/settings/input.rst b/docs/source/reference/modding/settings/input.rst index 090b279582..8a95686cfc 100644 --- a/docs/source/reference/modding/settings/input.rst +++ b/docs/source/reference/modding/settings/input.rst @@ -135,6 +135,18 @@ camera sensitivity setting. This setting can only be configured by editing the settings configuration file. +joystick dead zone +------------------ + +:Type: floating point +:Range: 0.0 to 0.5 +:Default: 0.1 + +This setting controls the radius of dead zone (where an input is discarded) for joystick axes. +Note that third-party software can provide its own dead zones. In this case OpenmW-specific setting dead zone can be disabled (0.0). + +This setting can only be configured by editing the settings configuration file. + enable gyroscope ---------------- diff --git a/extern/oics/ICSInputControlSystem.cpp b/extern/oics/ICSInputControlSystem.cpp index ccd09a04e7..c03c039a40 100644 --- a/extern/oics/ICSInputControlSystem.cpp +++ b/extern/oics/ICSInputControlSystem.cpp @@ -34,6 +34,7 @@ namespace ICS , DetectingBindingListener* detectingBindingListener , InputControlSystemLog* log, size_t channelCount) : mFileName(file) + , mDeadZone(0.1f) , mLog(log) , mDetectingBindingListener(detectingBindingListener) , mDetectingBindingControl(NULL) diff --git a/extern/oics/ICSInputControlSystem.h b/extern/oics/ICSInputControlSystem.h index 43e659d0a0..c49224dc2b 100644 --- a/extern/oics/ICSInputControlSystem.h +++ b/extern/oics/ICSInputControlSystem.h @@ -79,6 +79,8 @@ namespace ICS void setDetectingBindingListener(DetectingBindingListener* detectingBindingListener){ mDetectingBindingListener = detectingBindingListener; }; DetectingBindingListener* getDetectingBindingListener(){ return mDetectingBindingListener; }; + void setJoystickDeadZone(float deadZone){ mDeadZone = deadZone; }; + // in seconds void update(float timeSinceLastFrame); @@ -180,6 +182,8 @@ namespace ICS std::string mFileName; + float mDeadZone; + typedef std::map ControlsKeyBinderMapType; // typedef std::map ControlsAxisBinderMapType; // typedef std::map ControlsButtonBinderMapType; // diff --git a/extern/oics/ICSInputControlSystem_joystick.cpp b/extern/oics/ICSInputControlSystem_joystick.cpp index ed6e2f6647..38199436ba 100644 --- a/extern/oics/ICSInputControlSystem_joystick.cpp +++ b/extern/oics/ICSInputControlSystem_joystick.cpp @@ -27,8 +27,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "ICSInputControlSystem.h" #define SDL_JOY_AXIS_MIN -32768 -#define SDL_JOY_AXIS_MAX 32767 -#define DEADZONE 0.1f +#define SDL_JOY_AXIS_MAX 32767 namespace ICS { @@ -263,13 +262,13 @@ namespace ICS float axisRange = SDL_JOY_AXIS_MAX - SDL_JOY_AXIS_MIN; float valDisplaced = (float)(evt.value - SDL_JOY_AXIS_MIN); - float percent = valDisplaced / axisRange * (1+DEADZONE*2) - DEADZONE; //Assures all values, 0 through 1, are seen - if(percent > .5-DEADZONE && percent < .5+DEADZONE) //close enough to center + float percent = valDisplaced / axisRange * (1+mDeadZone*2) - mDeadZone; //Assures all values, 0 through 1, are seen + if(percent > .5-mDeadZone && percent < .5+mDeadZone) //close enough to center percent = .5; else if(percent > .5) - percent -= DEADZONE; + percent -= mDeadZone; else - percent += DEADZONE; + percent += mDeadZone; if(joystickBinderItem.direction == Control::INCREASE) { diff --git a/files/settings-default.cfg b/files/settings-default.cfg index c48c8baf47..72accf9c99 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -421,6 +421,9 @@ enable controller = true # Emulated gamepad cursor sensitivity. gamepad cursor speed = 1.0 +# Set dead zone for joysticks (gamepad or on-screen ones) +joystick dead zone = 0.1 + # Enable gyroscope support. enable gyroscope = false