From e2d0ffcdcfeb91fa04e1cfbf104198bab1cc240b Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 08:36:55 +0000 Subject: [PATCH] Fixed the number of supported joysticks in sf::Input git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1327 4e206d99-4929-0410-ac5d-dfc041789085 --- build/vc2008/sfml-window.vcproj | 12 +++---- include/SFML/Window/Input.hpp | 27 +++++++++++---- src/SFML/Window/Input.cpp | 59 ++++++++++++++++----------------- 3 files changed, 56 insertions(+), 42 deletions(-) diff --git a/build/vc2008/sfml-window.vcproj b/build/vc2008/sfml-window.vcproj index 81225ab9b..3082eb7aa 100644 --- a/build/vc2008/sfml-window.vcproj +++ b/build/vc2008/sfml-window.vcproj @@ -420,7 +420,7 @@ > diff --git a/include/SFML/Window/Input.hpp b/include/SFML/Window/Input.hpp index fbac66a4e..3485b80a2 100644 --- a/include/SFML/Window/Input.hpp +++ b/include/SFML/Window/Input.hpp @@ -117,15 +117,30 @@ private : //////////////////////////////////////////////////////////// virtual void OnEvent(const Event& EventReceived); + //////////////////////////////////////////////////////////// + /// Reset all the states + /// + //////////////////////////////////////////////////////////// + void ResetStates(); + + //////////////////////////////////////////////////////////// + // Joystick limits + //////////////////////////////////////////////////////////// + enum + { + NbJoysticks = 4, + NbJoystickButtons = 32 + }; + //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys - bool myMouseButtons[Mouse::Count]; ///< Array containing the state of all mouse buttons - bool myJoystickButtons[2][16]; ///< Array containing the state of all joysticks buttons - int myMouseX; ///< Mouse position on X - int myMouseY; ///< Mouse position on Y - float myJoystickAxis[2][Joy::Count]; ///< Joysticks position on each axis + bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys + bool myMouseButtons[Mouse::Count]; ///< Array containing the state of all mouse buttons + int myMouseX; ///< Mouse position on X + int myMouseY; ///< Mouse position on Y + bool myJoystickButtons[NbJoysticks][NbJoystickButtons]; ///< Array containing the state of all joysticks buttons + float myJoystickAxis[NbJoysticks][Joy::Count]; ///< Joysticks position on each axis }; } // namespace sf diff --git a/src/SFML/Window/Input.cpp b/src/SFML/Window/Input.cpp index 7b10270d2..06397d443 100644 --- a/src/SFML/Window/Input.cpp +++ b/src/SFML/Window/Input.cpp @@ -37,23 +37,7 @@ Input::Input() : myMouseX(0), myMouseY(0) { - for (int i = 0; i < Key::Count; ++i) - myKeys[i] = false; - - for (int i = 0; i < Mouse::Count; ++i) - myMouseButtons[i] = false; - - for (int i = 0; i < 16; ++i) - { - myJoystickButtons[0][i] = false; - myJoystickButtons[1][i] = false; - } - - for (int i = 0; i < Joy::Count; ++i) - { - myJoystickAxis[0][i] = 0.f; - myJoystickAxis[1][i] = 0.f; - } + ResetStates(); } @@ -80,7 +64,7 @@ bool Input::IsMouseButtonDown(Mouse::Button Button) const //////////////////////////////////////////////////////////// bool Input::IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const { - if ((JoyId < 2) && (Button < 16)) + if ((JoyId < NbJoysticks) && (Button < NbJoystickButtons)) return myJoystickButtons[JoyId][Button]; else return false; @@ -110,7 +94,10 @@ int Input::GetMouseY() const //////////////////////////////////////////////////////////// float Input::GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const { - return myJoystickAxis[JoyId][Axis]; + if (JoyId < NbJoysticks) + return myJoystickAxis[JoyId][Axis]; + else + return 0.f; } @@ -147,17 +134,7 @@ void Input::OnEvent(const Event& EventReceived) // Lost focus event : we must reset all persistent states case Event::LostFocus : { - for (int i = 0; i < Key::Count; ++i) - myKeys[i] = false; - - for (int i = 0; i < Mouse::Count; ++i) - myMouseButtons[i] = false; - - for (int i = 0; i < 16; ++i) - { - myJoystickButtons[0][i] = false; - myJoystickButtons[1][i] = false; - } + ResetStates(); break; } @@ -166,4 +143,26 @@ void Input::OnEvent(const Event& EventReceived) } } + +//////////////////////////////////////////////////////////// +/// Reset all the states +//////////////////////////////////////////////////////////// +void Input::ResetStates() +{ + for (int i = 0; i < Key::Count; ++i) + myKeys[i] = false; + + for (int i = 0; i < Mouse::Count; ++i) + myMouseButtons[i] = false; + + for (int i = 0; i < NbJoysticks; ++i) + { + for (int j = 0; j < NbJoystickButtons; ++j) + myJoystickButtons[i][j] = false; + + for (int j = 0; j < Joy::Count; ++j) + myJoystickAxis[i][j] = 0.f; + } +} + } // namespace sf