From 43ed6ea083a5506c9cfef934fa79d64d61f2e9a7 Mon Sep 17 00:00:00 2001 From: auria Date: Tue, 31 Mar 2009 20:33:44 +0000 Subject: [PATCH] fixed bug related to axes vs buttons git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3331 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/input/device_manager.cpp | 2 +- src/input/input_device.cpp | 116 ++++++++++++++++++++--------------- src/input/input_device.hpp | 2 +- 3 files changed, 68 insertions(+), 52 deletions(-) diff --git a/src/input/device_manager.cpp b/src/input/device_manager.cpp index b86b642b5..3801dd57d 100644 --- a/src/input/device_manager.cpp +++ b/src/input/device_manager.cpp @@ -50,7 +50,7 @@ bool DeviceManager::mapInputToPlayerAndAction( Input::InputType type, int id0, i // std::cout << "stick motion, ID=" < 0 && m_prevAxisDirections[axis] == Input::AD_NEGATIVE) - { - // set negative axis to 0 - resetAxisDirection(axis, Input::AD_NEGATIVE, player); - } - - if(value > 0) m_prevAxisDirections[axis] = Input::AD_POSITIVE; - else if(value < 0) m_prevAxisDirections[axis] = Input::AD_NEGATIVE; - - // check if within deadzone - if(value > -m_deadzone && value < m_deadzone) - { - // Axis stands still: This is reported once for digital axes and - // can be called multipled times for analog ones. Uses the - // previous direction in which the axis was triggered to - // determine which one has to be brought into the released - // state. This allows us to regard two directions of an axis - // as completely independent input variants (as if they where - // two buttons). - - if(m_prevAxisDirections[axis] == Input::AD_NEGATIVE) + // going to negative from positive + if (value < 0 && m_prevAxisDirections[id] == Input::AD_POSITIVE) { - // set negative axis to 0 - resetAxisDirection(axis, Input::AD_NEGATIVE, player); + // set positive id to 0 + resetAxisDirection(id, Input::AD_POSITIVE, player); + } - else if(m_prevAxisDirections[axis] == Input::AD_POSITIVE) + // going to positive from negative + else if (value > 0 && m_prevAxisDirections[id] == Input::AD_NEGATIVE) { - // set positive axis to 0 - resetAxisDirection(axis, Input::AD_POSITIVE, player); + // set negative id to 0 + resetAxisDirection(id, Input::AD_NEGATIVE, player); } - m_prevAxisDirections[axis] = Input::AD_NEUTRAL; - return false; - } - - // find corresponding action and return it - for(int n=0; n 0) m_prevAxisDirections[id] = Input::AD_POSITIVE; + else if(value < 0) m_prevAxisDirections[id] = Input::AD_NEGATIVE; + + // check if within deadzone + if(value > -m_deadzone && value < m_deadzone) { - if(m_bindings[n].dir == Input::AD_NEGATIVE && value < 0) + // Axis stands still: This is reported once for digital axes and + // can be called multipled times for analog ones. Uses the + // previous direction in which the id was triggered to + // determine which one has to be brought into the released + // state. This allows us to regard two directions of an id + // as completely independent input variants (as if they where + // two buttons). + + if(m_prevAxisDirections[id] == Input::AD_NEGATIVE) + { + // set negative id to 0 + resetAxisDirection(id, Input::AD_NEGATIVE, player); + } + else if(m_prevAxisDirections[id] == Input::AD_POSITIVE) + { + // set positive id to 0 + resetAxisDirection(id, Input::AD_POSITIVE, player); + } + m_prevAxisDirections[id] = Input::AD_NEUTRAL; + + return false; + } + + // find corresponding action and return it + for(int n=0; n 0) + { + *action = (PlayerAction)n; + return true; + } + } + }// next device + } + else if(type == Input::IT_STICKBUTTON) + { + // find corresponding action and return it + for(int n=0; n 0) - { - *action = (PlayerAction)n; - return true; - } - } - }// next device + }// next device + } return false; } diff --git a/src/input/input_device.hpp b/src/input/input_device.hpp index ba52549cd..fa1e3949c 100644 --- a/src/input/input_device.hpp +++ b/src/input/input_device.hpp @@ -66,7 +66,7 @@ public: /** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false. The 'player' id passed is simply to know where to send 'axis reset's when necessary*/ - bool hasBinding(const int axis, const int value, const int player, PlayerAction* action /* out */); + bool hasBinding(Input::InputType type, const int id, const int value, const int player, PlayerAction* action /* out */); void open(const int sdl_id);