mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
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:
parent
953c73c5a6
commit
b5a17a832f
@ -42,9 +42,10 @@ namespace priv
|
|||||||
void Joystick::Initialize(unsigned int Index)
|
void Joystick::Initialize(unsigned int Index)
|
||||||
{
|
{
|
||||||
// Reset state
|
// Reset state
|
||||||
myIndex = JOYSTICKID1;
|
myIndex = JOYSTICKID1;
|
||||||
myNbAxes = 0;
|
myNbAxes = 0;
|
||||||
myNbButtons = 0;
|
myNbButtons = 0;
|
||||||
|
myIsConnected = false;
|
||||||
|
|
||||||
// Get the Index-th connected joystick
|
// Get the Index-th connected joystick
|
||||||
MMRESULT Error;
|
MMRESULT Error;
|
||||||
@ -60,6 +61,7 @@ void Joystick::Initialize(unsigned int Index)
|
|||||||
if (NbFound == Index)
|
if (NbFound == Index)
|
||||||
{
|
{
|
||||||
// Ok : store its parameters and return
|
// Ok : store its parameters and return
|
||||||
|
myIsConnected = true;
|
||||||
JOYCAPS Caps;
|
JOYCAPS Caps;
|
||||||
joyGetDevCaps(myIndex, &Caps, sizeof(Caps));
|
joyGetDevCaps(myIndex, &Caps, sizeof(Caps));
|
||||||
myNbAxes = Caps.wNumAxes;
|
myNbAxes = Caps.wNumAxes;
|
||||||
@ -84,30 +86,33 @@ JoystickState Joystick::UpdateState()
|
|||||||
{
|
{
|
||||||
JoystickState State = {0};
|
JoystickState State = {0};
|
||||||
|
|
||||||
// Get the joystick caps (for range conversions)
|
if (myIsConnected)
|
||||||
JOYCAPS Caps;
|
|
||||||
if (joyGetDevCaps(myIndex, &Caps, sizeof(Caps)) == JOYERR_NOERROR)
|
|
||||||
{
|
{
|
||||||
// Get the current joystick state
|
// Get the joystick caps (for range conversions)
|
||||||
JOYINFOEX Pos;
|
JOYCAPS Caps;
|
||||||
Pos.dwFlags = JOY_RETURNALL;
|
if (joyGetDevCaps(myIndex, &Caps, sizeof(Caps)) == JOYERR_NOERROR)
|
||||||
Pos.dwSize = sizeof(JOYINFOEX);
|
|
||||||
if (joyGetPosEx(myIndex, &Pos) == JOYERR_NOERROR)
|
|
||||||
{
|
{
|
||||||
// Axes
|
// Get the current joystick state
|
||||||
State.Axis[Joy::AxisX] = (Pos.dwXpos - (Caps.wXmax + Caps.wXmin) / 2.f) * 200.f / (Caps.wXmax - Caps.wXmin);
|
JOYINFOEX Pos;
|
||||||
State.Axis[Joy::AxisY] = (Pos.dwYpos - (Caps.wYmax + Caps.wYmin) / 2.f) * 200.f / (Caps.wYmax - Caps.wYmin);
|
Pos.dwFlags = JOY_RETURNALL;
|
||||||
State.Axis[Joy::AxisZ] = (Pos.dwZpos - (Caps.wZmax + Caps.wZmin) / 2.f) * 200.f / (Caps.wZmax - Caps.wZmin);
|
Pos.dwSize = sizeof(JOYINFOEX);
|
||||||
State.Axis[Joy::AxisR] = (Pos.dwRpos - (Caps.wRmax + Caps.wRmin) / 2.f) * 200.f / (Caps.wRmax - Caps.wRmin);
|
if (joyGetPosEx(myIndex, &Pos) == JOYERR_NOERROR)
|
||||||
State.Axis[Joy::AxisU] = (Pos.dwUpos - (Caps.wUmax + Caps.wUmin) / 2.f) * 200.f / (Caps.wUmax - Caps.wUmin);
|
{
|
||||||
State.Axis[Joy::AxisV] = (Pos.dwVpos - (Caps.wVmax + Caps.wVmin) / 2.f) * 200.f / (Caps.wVmax - Caps.wVmin);
|
// Axes
|
||||||
|
State.Axis[Joy::AxisX] = (Pos.dwXpos - (Caps.wXmax + Caps.wXmin) / 2.f) * 200.f / (Caps.wXmax - Caps.wXmin);
|
||||||
|
State.Axis[Joy::AxisY] = (Pos.dwYpos - (Caps.wYmax + Caps.wYmin) / 2.f) * 200.f / (Caps.wYmax - Caps.wYmin);
|
||||||
|
State.Axis[Joy::AxisZ] = (Pos.dwZpos - (Caps.wZmax + Caps.wZmin) / 2.f) * 200.f / (Caps.wZmax - Caps.wZmin);
|
||||||
|
State.Axis[Joy::AxisR] = (Pos.dwRpos - (Caps.wRmax + Caps.wRmin) / 2.f) * 200.f / (Caps.wRmax - Caps.wRmin);
|
||||||
|
State.Axis[Joy::AxisU] = (Pos.dwUpos - (Caps.wUmax + Caps.wUmin) / 2.f) * 200.f / (Caps.wUmax - Caps.wUmin);
|
||||||
|
State.Axis[Joy::AxisV] = (Pos.dwVpos - (Caps.wVmax + Caps.wVmin) / 2.f) * 200.f / (Caps.wVmax - Caps.wVmin);
|
||||||
|
|
||||||
// POV
|
// POV
|
||||||
State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f;
|
State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f;
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
for (unsigned int i = 0; i < GetButtonsCount(); ++i)
|
for (unsigned int i = 0; i < GetButtonsCount(); ++i)
|
||||||
State.Buttons[i] = (Pos.dwButtons & (1 << i)) != 0;
|
State.Buttons[i] = (Pos.dwButtons & (1 << i)) != 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +78,10 @@ private :
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Member data
|
// Member data
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
unsigned int myIndex; ///< Windows ID of the joystick
|
bool myIsConnected; ///< Is there a joystick connected?
|
||||||
unsigned int myNbAxes; ///< Number of axis supported by the joystick
|
unsigned int myIndex; ///< Windows ID of the joystick
|
||||||
unsigned int myNbButtons; ///< Number of buttons supported by the joystick
|
unsigned int myNbAxes; ///< Number of axis supported by the joystick
|
||||||
|
unsigned int myNbButtons; ///< Number of buttons supported by the joystick
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
Loading…
Reference in New Issue
Block a user