From 8426462febfd694fbfa809bd738181e2fcfe66eb Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 23 Nov 2016 07:39:08 -0800 Subject: [joysticks] Avoid sending 0.0 value actions every frame --- xbmc/input/joysticks/DefaultJoystick.cpp | 31 ++++++++++++++++++++----------- xbmc/input/joysticks/DefaultJoystick.h | 1 + 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/xbmc/input/joysticks/DefaultJoystick.cpp b/xbmc/input/joysticks/DefaultJoystick.cpp index 2efa73f900..0f573982f0 100644 --- a/xbmc/input/joysticks/DefaultJoystick.cpp +++ b/xbmc/input/joysticks/DefaultJoystick.cpp @@ -123,7 +123,8 @@ bool CDefaultJoystick::OnAnalogStickMotion(const FeatureName& feature, float x, } // Now activate direction the analog stick is pointing - bHandled = ActivateDirection(feature, magnitude, analogStickDir, motionTimeMs); + if (magnitude != 0.0f) + bHandled = ActivateDirection(feature, magnitude, analogStickDir, motionTimeMs); return bHandled; } @@ -178,22 +179,30 @@ bool CDefaultJoystick::ActivateDirection(const FeatureName& feature, float magni bHandled = true; } + if (bHandled) + m_currentDirections[feature] = dir; + return bHandled; } void CDefaultJoystick::DeactivateDirection(const FeatureName& feature, ANALOG_STICK_DIRECTION dir) { - // Calculate the button key ID and input type for this direction - const unsigned int keyId = GetKeyID(feature, dir); - const INPUT_TYPE inputType = m_handler->GetInputType(keyId); - - if (inputType == INPUT_TYPE::DIGITAL) - { - m_handler->OnDigitalKey(keyId, false); - } - else if (inputType == INPUT_TYPE::ANALOG) + if (m_currentDirections[feature] == dir) { - m_handler->OnAnalogKey(keyId, 0.0f); + // Calculate the button key ID and input type for this direction + const unsigned int keyId = GetKeyID(feature, dir); + const INPUT_TYPE inputType = m_handler->GetInputType(keyId); + + if (inputType == INPUT_TYPE::DIGITAL) + { + m_handler->OnDigitalKey(keyId, false); + } + else if (inputType == INPUT_TYPE::ANALOG) + { + m_handler->OnAnalogKey(keyId, 0.0f); + } + + m_currentDirections[feature] = ANALOG_STICK_DIRECTION::UNKNOWN; } } diff --git a/xbmc/input/joysticks/DefaultJoystick.h b/xbmc/input/joysticks/DefaultJoystick.h index cdb8bcc37a..548b9e116e 100644 --- a/xbmc/input/joysticks/DefaultJoystick.h +++ b/xbmc/input/joysticks/DefaultJoystick.h @@ -95,6 +95,7 @@ namespace JOYSTICK // State variables used to process joystick input std::map m_holdStartTimes; // Key ID -> hold start time (ms) + std::map m_currentDirections; // Analog stick name -> direction // Rumble functionality CRumbleGenerator m_rumbleGenerator; -- cgit v1.2.3