mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-01 06:44:27 +08:00
Update to GameInput V3 (#15302)
This commit is contained in:
@@ -31,7 +31,9 @@
|
|||||||
#define GAMEINPUT_API_VERSION 0
|
#define GAMEINPUT_API_VERSION 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GAMEINPUT_API_VERSION == 2
|
#if GAMEINPUT_API_VERSION == 3
|
||||||
|
using namespace GameInput::v3;
|
||||||
|
#elif GAMEINPUT_API_VERSION == 2
|
||||||
using namespace GameInput::v2;
|
using namespace GameInput::v2;
|
||||||
#elif GAMEINPUT_API_VERSION == 1
|
#elif GAMEINPUT_API_VERSION == 1
|
||||||
using namespace GameInput::v1;
|
using namespace GameInput::v1;
|
||||||
|
|||||||
@@ -542,9 +542,15 @@ static bool GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
|||||||
}
|
}
|
||||||
#endif // GAMEINPUT_API_VERSION >= 1
|
#endif // GAMEINPUT_API_VERSION >= 1
|
||||||
} else {
|
} else {
|
||||||
|
#if GAMEINPUT_API_VERSION >= 3
|
||||||
|
joystick->naxes = info->controllerInfo->controllerAxisCount;
|
||||||
|
joystick->nbuttons = info->controllerInfo->controllerButtonCount;
|
||||||
|
joystick->nhats = info->controllerInfo->controllerSwitchCount;
|
||||||
|
#else
|
||||||
joystick->naxes = info->controllerAxisCount;
|
joystick->naxes = info->controllerAxisCount;
|
||||||
joystick->nbuttons = info->controllerButtonCount;
|
joystick->nbuttons = info->controllerButtonCount;
|
||||||
joystick->nhats = info->controllerSwitchCount;
|
joystick->nhats = info->controllerSwitchCount;
|
||||||
|
#endif // GAMEINPUT_API_VERSION >= 3
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->supportedRumbleMotors & (GameInputRumbleLowFrequency | GameInputRumbleHighFrequency)) {
|
if (info->supportedRumbleMotors & (GameInputRumbleLowFrequency | GameInputRumbleHighFrequency)) {
|
||||||
@@ -676,13 +682,13 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick)
|
|||||||
#undef CONVERT_TRIGGER
|
#undef CONVERT_TRIGGER
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool *button_state = SDL_stack_alloc(bool, info->controllerButtonCount);
|
bool *button_state = SDL_stack_alloc(bool, joystick->nbuttons);
|
||||||
float *axis_state = SDL_stack_alloc(float, info->controllerAxisCount);
|
float *axis_state = SDL_stack_alloc(float, joystick->naxes);
|
||||||
GameInputSwitchPosition *switch_state = SDL_stack_alloc(GameInputSwitchPosition, info->controllerSwitchCount);
|
GameInputSwitchPosition *switch_state = SDL_stack_alloc(GameInputSwitchPosition, joystick->nhats);
|
||||||
|
|
||||||
if (button_state) {
|
if (button_state) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t button_count = reading->GetControllerButtonState(info->controllerButtonCount, button_state);
|
uint32_t button_count = reading->GetControllerButtonState(joystick->nbuttons, button_state);
|
||||||
for (i = 0; i < button_count; ++i) {
|
for (i = 0; i < button_count; ++i) {
|
||||||
SDL_SendJoystickButton(timestamp, joystick, (Uint8)i, button_state[i]);
|
SDL_SendJoystickButton(timestamp, joystick, (Uint8)i, button_state[i]);
|
||||||
}
|
}
|
||||||
@@ -692,7 +698,7 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick)
|
|||||||
#define CONVERT_AXIS(v) (Sint16)((v)*65535.0f - 32768.0f)
|
#define CONVERT_AXIS(v) (Sint16)((v)*65535.0f - 32768.0f)
|
||||||
if (axis_state) {
|
if (axis_state) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t axis_count = reading->GetControllerAxisState(info->controllerAxisCount, axis_state);
|
uint32_t axis_count = reading->GetControllerAxisState(joystick->naxes, axis_state);
|
||||||
for (i = 0; i < axis_count; ++i) {
|
for (i = 0; i < axis_count; ++i) {
|
||||||
SDL_SendJoystickAxis(timestamp, joystick, (Uint8)i, CONVERT_AXIS(axis_state[i]));
|
SDL_SendJoystickAxis(timestamp, joystick, (Uint8)i, CONVERT_AXIS(axis_state[i]));
|
||||||
}
|
}
|
||||||
@@ -702,7 +708,7 @@ static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick)
|
|||||||
|
|
||||||
if (switch_state) {
|
if (switch_state) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t switch_count = reading->GetControllerSwitchState(info->controllerSwitchCount, switch_state);
|
uint32_t switch_count = reading->GetControllerSwitchState(joystick->nhats, switch_state);
|
||||||
for (i = 0; i < switch_count; ++i) {
|
for (i = 0; i < switch_count; ++i) {
|
||||||
Uint8 hat;
|
Uint8 hat;
|
||||||
switch (switch_state[i]) {
|
switch (switch_state[i]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user