aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett Brown <themagnificentmrb@gmail.com>2016-11-23 07:39:08 -0800
committerGarrett Brown <themagnificentmrb@gmail.com>2016-11-23 09:00:47 -0800
commit8426462febfd694fbfa809bd738181e2fcfe66eb (patch)
tree682f320699ce22d5f246376cef4b89fdc8f03724
parent083b4853c53a5e778ad2cd945053607a3514778e (diff)
[joysticks] Avoid sending 0.0 value actions every frame
-rw-r--r--xbmc/input/joysticks/DefaultJoystick.cpp31
-rw-r--r--xbmc/input/joysticks/DefaultJoystick.h1
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<unsigned int, unsigned int> m_holdStartTimes; // Key ID -> hold start time (ms)
+ std::map<FeatureName, ANALOG_STICK_DIRECTION> m_currentDirections; // Analog stick name -> direction
// Rumble functionality
CRumbleGenerator m_rumbleGenerator;