sdl (master post 3.1 preview) Merge commit 'e4f454091a943345938608570b104400f62fd625'

This commit is contained in:
2024-03-28 16:27:42 +01:00
862 changed files with 204894 additions and 45662 deletions

View File

@@ -20,6 +20,8 @@
int main(int argc, char *argv[])
{
int num_keyboards = 0;
int num_mice = 0;
int num_joysticks = 0;
SDL_Joystick *joystick = NULL;
SDL_Haptic *haptic = NULL;
@@ -78,10 +80,19 @@ int main(int argc, char *argv[])
//SDL_CreateWindow("Dummy", 128, 128, 0);
*/
SDL_free(SDL_GetKeyboards(&num_keyboards));
SDL_Log("There are %d keyboards at startup\n", num_keyboards);
SDL_free(SDL_GetMice(&num_mice));
SDL_Log("There are %d mice at startup\n", num_mice);
SDL_free(SDL_GetJoysticks(&num_joysticks));
SDL_Log("There are %d joysticks at startup\n", num_joysticks);
if (enable_haptic) {
SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics());
int num_haptics;
SDL_free(SDL_GetHaptics(&num_haptics));
SDL_Log("There are %d haptic devices at startup\n", num_haptics);
}
while (keepGoing) {
@@ -91,6 +102,18 @@ int main(int argc, char *argv[])
case SDL_EVENT_QUIT:
keepGoing = SDL_FALSE;
break;
case SDL_EVENT_KEYBOARD_ADDED:
SDL_Log("Keyboard '%s' added : %" SDL_PRIu32 "\n", SDL_GetKeyboardInstanceName(event.kdevice.which), event.kdevice.which);
break;
case SDL_EVENT_KEYBOARD_REMOVED:
SDL_Log("Keyboard removed: %" SDL_PRIu32 "\n", event.kdevice.which);
break;
case SDL_EVENT_MOUSE_ADDED:
SDL_Log("Mouse '%s' added : %" SDL_PRIu32 "\n", SDL_GetMouseInstanceName(event.mdevice.which), event.mdevice.which);
break;
case SDL_EVENT_MOUSE_REMOVED:
SDL_Log("Mouse removed: %" SDL_PRIu32 "\n", event.mdevice.which);
break;
case SDL_EVENT_JOYSTICK_ADDED:
if (joystick) {
SDL_Log("Only one joystick supported by this test\n");
@@ -99,13 +122,13 @@ int main(int argc, char *argv[])
instance = event.jdevice.which;
SDL_Log("Joy Added : %" SDL_PRIu32 " : %s\n", event.jdevice.which, SDL_GetJoystickName(joystick));
if (enable_haptic) {
if (SDL_JoystickIsHaptic(joystick)) {
haptic = SDL_HapticOpenFromJoystick(joystick);
if (SDL_IsJoystickHaptic(joystick)) {
haptic = SDL_OpenHapticFromJoystick(joystick);
if (haptic) {
SDL_Log("Joy Haptic Opened\n");
if (SDL_HapticRumbleInit(haptic) != 0) {
if (SDL_InitHapticRumble(haptic) != 0) {
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
SDL_HapticClose(haptic);
SDL_CloseHaptic(haptic);
haptic = NULL;
}
} else {
@@ -122,7 +145,7 @@ int main(int argc, char *argv[])
SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which);
instance = 0;
if (enable_haptic && haptic) {
SDL_HapticClose(haptic);
SDL_CloseHaptic(haptic);
haptic = NULL;
}
SDL_CloseJoystick(joystick);
@@ -136,13 +159,13 @@ int main(int argc, char *argv[])
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
*/
if (enable_haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
SDL_PlayHapticRumble(haptic, 0.25, 250);
}
break;
case SDL_EVENT_JOYSTICK_BUTTON_DOWN:
SDL_Log("Button Press: %d\n", event.jbutton.button);
if (enable_haptic && haptic) {
SDL_HapticRumblePlay(haptic, 0.25, 250);
SDL_PlayHapticRumble(haptic, 0.25, 250);
}
if (event.jbutton.button == 0) {
SDL_Log("Exiting due to button press of button 0\n");
@@ -152,6 +175,8 @@ int main(int argc, char *argv[])
case SDL_EVENT_JOYSTICK_BUTTON_UP:
SDL_Log("Button Release: %d\n", event.jbutton.button);
break;
default:
break;
}
}
}