From 49d611ee695f98390e38bf65436844086e3afefd Mon Sep 17 00:00:00 2001 From: Mario Liebisch Date: Thu, 28 Dec 2017 09:55:57 +0100 Subject: [PATCH] Fixed small joystick movement getting lost due to the set axes threshold. This fixes issue #1329. --- src/SFML/Window/WindowImpl.cpp | 11 ++++++++++- src/SFML/Window/WindowImpl.hpp | 9 +++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/SFML/Window/WindowImpl.cpp b/src/SFML/Window/WindowImpl.cpp index 27d4ab40f..bd87474b9 100644 --- a/src/SFML/Window/WindowImpl.cpp +++ b/src/SFML/Window/WindowImpl.cpp @@ -86,7 +86,10 @@ m_joystickThreshold(0.1f) // Get the initial joystick states JoystickManager::getInstance().update(); for (unsigned int i = 0; i < Joystick::Count; ++i) + { m_joystickStates[i] = JoystickManager::getInstance().getState(i); + std::fill_n(m_previousAxes[i], static_cast(Joystick::AxisCount), 0.f); + } // Get the initial sensor states for (unsigned int i = 0; i < Sensor::Count; ++i) @@ -176,6 +179,10 @@ void WindowImpl::processJoystickEvents() event.type = connected ? Event::JoystickConnected : Event::JoystickDisconnected; event.joystickButton.joystickId = i; pushEvent(event); + + // Clear previous axes positions + if (connected) + std::fill_n(m_previousAxes[i], static_cast(Joystick::AxisCount), 0.f); } if (connected) @@ -186,7 +193,7 @@ void WindowImpl::processJoystickEvents() if (caps.axes[j]) { Joystick::Axis axis = static_cast(j); - float prevPos = previousState.axes[axis]; + float prevPos = m_previousAxes[i][axis]; float currPos = m_joystickStates[i].axes[axis]; if (fabs(currPos - prevPos) >= m_joystickThreshold) { @@ -196,6 +203,8 @@ void WindowImpl::processJoystickEvents() event.joystickMove.axis = axis; event.joystickMove.position = currPos; pushEvent(event); + + m_previousAxes[i][axis] = currPos; } } } diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 355ee69da..a360a0184 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -270,10 +270,11 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - std::queue m_events; ///< Queue of available events - JoystickState m_joystickStates[Joystick::Count]; ///< Previous state of the joysticks - Vector3f m_sensorValue[Sensor::Count]; ///< Previous value of the sensors - float m_joystickThreshold; ///< Joystick threshold (minimum motion for "move" event to be generated) + std::queue m_events; ///< Queue of available events + JoystickState m_joystickStates[Joystick::Count]; ///< Previous state of the joysticks + Vector3f m_sensorValue[Sensor::Count]; ///< Previous value of the sensors + float m_joystickThreshold; ///< Joystick threshold (minimum motion for "move" event to be generated) + float m_previousAxes[Joystick::Count][Joystick::AxisCount]; ///< Position of each axis last time a move event triggered, in range [-100, 100] }; } // namespace priv