Unconnected joysticks are no longer updated (on Windows)

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1195 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2009-07-25 10:02:07 +00:00
parent 953c73c5a6
commit b5a17a832f
2 changed files with 32 additions and 26 deletions

View File

@ -45,6 +45,7 @@ void Joystick::Initialize(unsigned int Index)
myIndex = JOYSTICKID1;
myNbAxes = 0;
myNbButtons = 0;
myIsConnected = false;
// Get the Index-th connected joystick
MMRESULT Error;
@ -60,6 +61,7 @@ void Joystick::Initialize(unsigned int Index)
if (NbFound == Index)
{
// Ok : store its parameters and return
myIsConnected = true;
JOYCAPS Caps;
joyGetDevCaps(myIndex, &Caps, sizeof(Caps));
myNbAxes = Caps.wNumAxes;
@ -84,6 +86,8 @@ JoystickState Joystick::UpdateState()
{
JoystickState State = {0};
if (myIsConnected)
{
// Get the joystick caps (for range conversions)
JOYCAPS Caps;
if (joyGetDevCaps(myIndex, &Caps, sizeof(Caps)) == JOYERR_NOERROR)
@ -110,6 +114,7 @@ JoystickState Joystick::UpdateState()
State.Buttons[i] = (Pos.dwButtons & (1 << i)) != 0;
}
}
}
return State;
}

View File

@ -78,6 +78,7 @@ private :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
bool myIsConnected; ///< Is there a joystick connected?
unsigned int myIndex; ///< Windows ID of the joystick
unsigned int myNbAxes; ///< Number of axis supported by the joystick
unsigned int myNbButtons; ///< Number of buttons supported by the joystick