mirror of https://github.com/encounter/SDL.git
Haptic: Deal with negative periodic magnitudes (thanks, Elias!).
A negative periodic magnitude doesn't exist in Windows' and MacOS' FF APIs The periodic magnitude parameter of the SDL Haptic API is based on the Linux FF API, so it means they are not directly compatible: 'dwMagnitude' is a 'DWORD', which is unsigned. Fixes Bugzilla #2701.
This commit is contained in:
parent
266c0023da
commit
5f9ea7edeb
|
@ -553,7 +553,7 @@ typedef struct SDL_HapticPeriodic
|
||||||
|
|
||||||
/* Periodic */
|
/* Periodic */
|
||||||
Uint16 period; /**< Period of the wave. */
|
Uint16 period; /**< Period of the wave. */
|
||||||
Sint16 magnitude; /**< Peak value. */
|
Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
|
||||||
Sint16 offset; /**< Mean value of the wave. */
|
Sint16 offset; /**< Mean value of the wave. */
|
||||||
Uint16 phase; /**< Horizontal shift given by hundredth of a degree. */
|
Uint16 phase; /**< Horizontal shift given by hundredth of a degree. */
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#ifdef SDL_HAPTIC_IOKIT
|
#ifdef SDL_HAPTIC_IOKIT
|
||||||
|
|
||||||
#include "SDL_assert.h"
|
#include "SDL_assert.h"
|
||||||
|
#include "SDL_stdinc.h"
|
||||||
#include "SDL_haptic.h"
|
#include "SDL_haptic.h"
|
||||||
#include "../SDL_syshaptic.h"
|
#include "../SDL_syshaptic.h"
|
||||||
#include "SDL_joystick.h"
|
#include "SDL_joystick.h"
|
||||||
|
@ -872,9 +873,10 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src)
|
||||||
SDL_memset(periodic, 0, sizeof(FFPERIODIC));
|
SDL_memset(periodic, 0, sizeof(FFPERIODIC));
|
||||||
|
|
||||||
/* Specifics */
|
/* Specifics */
|
||||||
periodic->dwMagnitude = CONVERT(hap_periodic->magnitude);
|
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
|
||||||
periodic->lOffset = CONVERT(hap_periodic->offset);
|
periodic->lOffset = CONVERT(hap_periodic->offset);
|
||||||
periodic->dwPhase = hap_periodic->phase;
|
periodic->dwPhase =
|
||||||
|
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
|
||||||
periodic->dwPeriod = hap_periodic->period * 1000;
|
periodic->dwPeriod = hap_periodic->period * 1000;
|
||||||
dest->cbTypeSpecificParams = sizeof(FFPERIODIC);
|
dest->cbTypeSpecificParams = sizeof(FFPERIODIC);
|
||||||
dest->lpvTypeSpecificParams = periodic;
|
dest->lpvTypeSpecificParams = periodic;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "../../SDL_internal.h"
|
#include "../../SDL_internal.h"
|
||||||
|
|
||||||
#include "SDL_error.h"
|
#include "SDL_error.h"
|
||||||
|
#include "SDL_stdinc.h"
|
||||||
#include "SDL_haptic.h"
|
#include "SDL_haptic.h"
|
||||||
#include "SDL_timer.h"
|
#include "SDL_timer.h"
|
||||||
#include "SDL_windowshaptic_c.h"
|
#include "SDL_windowshaptic_c.h"
|
||||||
|
@ -714,9 +715,10 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest,
|
||||||
SDL_memset(periodic, 0, sizeof(DIPERIODIC));
|
SDL_memset(periodic, 0, sizeof(DIPERIODIC));
|
||||||
|
|
||||||
/* Specifics */
|
/* Specifics */
|
||||||
periodic->dwMagnitude = CONVERT(hap_periodic->magnitude);
|
periodic->dwMagnitude = CONVERT(SDL_abs(hap_periodic->magnitude));
|
||||||
periodic->lOffset = CONVERT(hap_periodic->offset);
|
periodic->lOffset = CONVERT(hap_periodic->offset);
|
||||||
periodic->dwPhase = hap_periodic->phase;
|
periodic->dwPhase =
|
||||||
|
(hap_periodic->phase + (hap_periodic->magnitude < 0 ? 18000 : 0)) % 36000;
|
||||||
periodic->dwPeriod = hap_periodic->period * 1000;
|
periodic->dwPeriod = hap_periodic->period * 1000;
|
||||||
dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
|
dest->cbTypeSpecificParams = sizeof(DIPERIODIC);
|
||||||
dest->lpvTypeSpecificParams = periodic;
|
dest->lpvTypeSpecificParams = periodic;
|
||||||
|
|
|
@ -122,7 +122,8 @@ main(int argc, char **argv)
|
||||||
SDL_Log(" effect %d: Sine Wave\n", nefx);
|
SDL_Log(" effect %d: Sine Wave\n", nefx);
|
||||||
efx[nefx].type = SDL_HAPTIC_SINE;
|
efx[nefx].type = SDL_HAPTIC_SINE;
|
||||||
efx[nefx].periodic.period = 1000;
|
efx[nefx].periodic.period = 1000;
|
||||||
efx[nefx].periodic.magnitude = 0x4000;
|
efx[nefx].periodic.magnitude = -0x2000; /* Negative magnitude and ... */
|
||||||
|
efx[nefx].periodic.phase = 18000; /* ... 180 degrees phase shift => cancel eachother */
|
||||||
efx[nefx].periodic.length = 5000;
|
efx[nefx].periodic.length = 5000;
|
||||||
efx[nefx].periodic.attack_length = 1000;
|
efx[nefx].periodic.attack_length = 1000;
|
||||||
efx[nefx].periodic.fade_length = 1000;
|
efx[nefx].periodic.fade_length = 1000;
|
||||||
|
|
Loading…
Reference in New Issue