mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-06 18:06:26 +00:00
Convert ticks to 64-bit, added nanosecond precision to the API
Fixes https://github.com/libsdl-org/SDL/issues/5512 Fixes https://github.com/libsdl-org/SDL/issues/6731
This commit is contained in:
@@ -42,15 +42,8 @@ static int numhaptics = 0;
|
||||
|
||||
int SDL_SYS_HapticInit(void)
|
||||
{
|
||||
/* Support for device connect/disconnect is API >= 16 only,
|
||||
* so we poll every three seconds
|
||||
* Ref: http://developer.android.com/reference/android/hardware/input/InputManager.InputDeviceListener.html
|
||||
*/
|
||||
static Uint32 timeout = 0;
|
||||
if (SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
|
||||
timeout = SDL_GetTicks() + 3000;
|
||||
Android_JNI_PollHapticDevices();
|
||||
}
|
||||
Android_JNI_PollHapticDevices();
|
||||
|
||||
return numhaptics;
|
||||
}
|
||||
|
||||
|
@@ -46,7 +46,7 @@ struct haptic_hwdata
|
||||
Uint8 userid; /* XInput userid index for this joystick */
|
||||
SDL_Thread *thread;
|
||||
SDL_mutex *mutex;
|
||||
Uint32 stopTicks;
|
||||
Uint64 stopTicks;
|
||||
SDL_atomic_t stopThread;
|
||||
};
|
||||
|
||||
|
@@ -147,7 +147,7 @@ static int SDLCALL SDL_RunXInputHaptic(void *arg)
|
||||
SDL_LockMutex(hwdata->mutex);
|
||||
/* If we're currently running and need to stop... */
|
||||
if (hwdata->stopTicks) {
|
||||
if ((hwdata->stopTicks != SDL_HAPTIC_INFINITY) && SDL_TICKS_PASSED(SDL_GetTicks(), hwdata->stopTicks)) {
|
||||
if ((hwdata->stopTicks != SDL_HAPTIC_INFINITY) && SDL_GetTicks() >= hwdata->stopTicks) {
|
||||
XINPUT_VIBRATION vibration = { 0, 0 };
|
||||
hwdata->stopTicks = 0;
|
||||
XINPUTSETSTATE(hwdata->userid, &vibration);
|
||||
@@ -287,9 +287,6 @@ int SDL_XINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect,
|
||||
/* do nothing. Effect runs for zero milliseconds. */
|
||||
} else {
|
||||
haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations);
|
||||
if ((haptic->hwdata->stopTicks == SDL_HAPTIC_INFINITY) || (haptic->hwdata->stopTicks == 0)) {
|
||||
haptic->hwdata->stopTicks = 1; /* fix edge cases. */
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(haptic->hwdata->mutex);
|
||||
return (XINPUTSETSTATE(haptic->hwdata->userid, vib) == ERROR_SUCCESS) ? 0 : -1;
|
||||
|
Reference in New Issue
Block a user