File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -1361,9 +1361,35 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id)
1361
1361
1362
1362
// If this joystick is known to have all zero centered axes, skip the auto-centering code
1363
1363
if (SDL_JoystickAxesCenteredAtZero (joystick )) {
1364
- int i ;
1364
+ for (int i = 0 ; i < joystick -> naxes ; ++ i ) {
1365
+ joystick -> axes [i ].has_initial_value = true;
1366
+ }
1367
+ }
1365
1368
1366
- for (i = 0 ; i < joystick -> naxes ; ++ i ) {
1369
+ // We know the initial values for HIDAPI and XInput joysticks
1370
+ if ((SDL_IsJoystickHIDAPI (joystick -> guid ) ||
1371
+ SDL_IsJoystickXInput (joystick -> guid ) ||
1372
+ SDL_IsJoystickRAWINPUT (joystick -> guid ) ||
1373
+ SDL_IsJoystickWGI (joystick -> guid )) &&
1374
+ joystick -> naxes >= SDL_GAMEPAD_AXIS_COUNT ) {
1375
+ int left_trigger , right_trigger ;
1376
+ if (SDL_IsJoystickXInput (joystick -> guid )) {
1377
+ left_trigger = 2 ;
1378
+ right_trigger = 5 ;
1379
+ } else {
1380
+ left_trigger = SDL_GAMEPAD_AXIS_LEFT_TRIGGER ;
1381
+ right_trigger = SDL_GAMEPAD_AXIS_RIGHT_TRIGGER ;
1382
+ }
1383
+ for (int i = 0 ; i < SDL_GAMEPAD_AXIS_COUNT ; ++ i ) {
1384
+ int initial_value ;
1385
+ if (i == left_trigger || i == right_trigger ) {
1386
+ initial_value = SDL_MIN_SINT16 ;
1387
+ } else {
1388
+ initial_value = 0 ;
1389
+ }
1390
+ joystick -> axes [i ].value = initial_value ;
1391
+ joystick -> axes [i ].zero = initial_value ;
1392
+ joystick -> axes [i ].initial_value = initial_value ;
1367
1393
joystick -> axes [i ].has_initial_value = true;
1368
1394
}
1369
1395
}
You can’t perform that action at this time.
0 commit comments