native_audio 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/assets/include/GL/glew.h +26427 -26427
  3. data/assets/include/GLES2/gl2.h +656 -656
  4. data/assets/include/GLES2/gl2ext.h +3949 -3949
  5. data/assets/include/GLES2/gl2ext_angle.h +701 -701
  6. data/assets/include/GLES2/gl2platform.h +27 -27
  7. data/assets/include/GLES3/gl3.h +1192 -1192
  8. data/assets/include/GLES3/gl31.h +1507 -1507
  9. data/assets/include/GLES3/gl32.h +1808 -1808
  10. data/assets/include/GLES3/gl3platform.h +27 -27
  11. data/assets/include/KHR/khrplatform.h +290 -290
  12. data/assets/include/SDL2/SDL.h +233 -233
  13. data/assets/include/SDL2/SDL_assert.h +326 -326
  14. data/assets/include/SDL2/SDL_atomic.h +415 -415
  15. data/assets/include/SDL2/SDL_audio.h +1500 -1500
  16. data/assets/include/SDL2/SDL_bits.h +126 -126
  17. data/assets/include/SDL2/SDL_blendmode.h +198 -198
  18. data/assets/include/SDL2/SDL_clipboard.h +141 -141
  19. data/assets/include/SDL2/SDL_config.h +61 -61
  20. data/assets/include/SDL2/SDL_config_android.h +194 -194
  21. data/assets/include/SDL2/SDL_config_emscripten.h +218 -218
  22. data/assets/include/SDL2/SDL_config_iphoneos.h +217 -217
  23. data/assets/include/SDL2/SDL_config_macosx.h +277 -277
  24. data/assets/include/SDL2/SDL_config_minimal.h +95 -95
  25. data/assets/include/SDL2/SDL_config_ngage.h +89 -89
  26. data/assets/include/SDL2/SDL_config_os2.h +207 -207
  27. data/assets/include/SDL2/SDL_config_pandora.h +141 -141
  28. data/assets/include/SDL2/SDL_config_windows.h +331 -331
  29. data/assets/include/SDL2/SDL_config_wingdk.h +253 -253
  30. data/assets/include/SDL2/SDL_config_winrt.h +220 -220
  31. data/assets/include/SDL2/SDL_config_xbox.h +235 -235
  32. data/assets/include/SDL2/SDL_copying.h +20 -20
  33. data/assets/include/SDL2/SDL_cpuinfo.h +594 -594
  34. data/assets/include/SDL2/SDL_egl.h +2352 -2352
  35. data/assets/include/SDL2/SDL_endian.h +348 -348
  36. data/assets/include/SDL2/SDL_error.h +163 -163
  37. data/assets/include/SDL2/SDL_events.h +1166 -1166
  38. data/assets/include/SDL2/SDL_filesystem.h +149 -149
  39. data/assets/include/SDL2/SDL_gamecontroller.h +1074 -1074
  40. data/assets/include/SDL2/SDL_gesture.h +117 -117
  41. data/assets/include/SDL2/SDL_guid.h +100 -100
  42. data/assets/include/SDL2/SDL_haptic.h +1341 -1341
  43. data/assets/include/SDL2/SDL_hidapi.h +451 -451
  44. data/assets/include/SDL2/SDL_hints.h +2569 -2569
  45. data/assets/include/SDL2/SDL_image.h +2173 -2173
  46. data/assets/include/SDL2/SDL_joystick.h +1066 -1066
  47. data/assets/include/SDL2/SDL_keyboard.h +353 -353
  48. data/assets/include/SDL2/SDL_keycode.h +358 -358
  49. data/assets/include/SDL2/SDL_loadso.h +115 -115
  50. data/assets/include/SDL2/SDL_locale.h +103 -103
  51. data/assets/include/SDL2/SDL_log.h +404 -404
  52. data/assets/include/SDL2/SDL_main.h +275 -275
  53. data/assets/include/SDL2/SDL_messagebox.h +193 -193
  54. data/assets/include/SDL2/SDL_metal.h +113 -113
  55. data/assets/include/SDL2/SDL_misc.h +79 -79
  56. data/assets/include/SDL2/SDL_mixer.h +2784 -2784
  57. data/assets/include/SDL2/SDL_mouse.h +465 -465
  58. data/assets/include/SDL2/SDL_mutex.h +471 -471
  59. data/assets/include/SDL2/SDL_name.h +33 -33
  60. data/assets/include/SDL2/SDL_opengl.h +2132 -2132
  61. data/assets/include/SDL2/SDL_opengl_glext.h +13209 -13209
  62. data/assets/include/SDL2/SDL_opengles.h +39 -39
  63. data/assets/include/SDL2/SDL_opengles2.h +52 -52
  64. data/assets/include/SDL2/SDL_opengles2_gl2.h +656 -656
  65. data/assets/include/SDL2/SDL_opengles2_gl2ext.h +4033 -4033
  66. data/assets/include/SDL2/SDL_opengles2_gl2platform.h +27 -27
  67. data/assets/include/SDL2/SDL_opengles2_khrplatform.h +311 -311
  68. data/assets/include/SDL2/SDL_pixels.h +644 -644
  69. data/assets/include/SDL2/SDL_platform.h +261 -261
  70. data/assets/include/SDL2/SDL_power.h +88 -88
  71. data/assets/include/SDL2/SDL_quit.h +58 -58
  72. data/assets/include/SDL2/SDL_rect.h +376 -376
  73. data/assets/include/SDL2/SDL_render.h +1919 -1919
  74. data/assets/include/SDL2/SDL_revision.h +6 -6
  75. data/assets/include/SDL2/SDL_rwops.h +841 -841
  76. data/assets/include/SDL2/SDL_scancode.h +438 -438
  77. data/assets/include/SDL2/SDL_sensor.h +322 -322
  78. data/assets/include/SDL2/SDL_shape.h +155 -155
  79. data/assets/include/SDL2/SDL_stdinc.h +830 -830
  80. data/assets/include/SDL2/SDL_surface.h +997 -997
  81. data/assets/include/SDL2/SDL_system.h +623 -623
  82. data/assets/include/SDL2/SDL_syswm.h +386 -386
  83. data/assets/include/SDL2/SDL_test.h +69 -69
  84. data/assets/include/SDL2/SDL_test_assert.h +105 -105
  85. data/assets/include/SDL2/SDL_test_common.h +236 -236
  86. data/assets/include/SDL2/SDL_test_compare.h +69 -69
  87. data/assets/include/SDL2/SDL_test_crc32.h +124 -124
  88. data/assets/include/SDL2/SDL_test_font.h +168 -168
  89. data/assets/include/SDL2/SDL_test_fuzzer.h +386 -386
  90. data/assets/include/SDL2/SDL_test_harness.h +134 -134
  91. data/assets/include/SDL2/SDL_test_images.h +78 -78
  92. data/assets/include/SDL2/SDL_test_log.h +67 -67
  93. data/assets/include/SDL2/SDL_test_md5.h +129 -129
  94. data/assets/include/SDL2/SDL_test_memory.h +63 -63
  95. data/assets/include/SDL2/SDL_test_random.h +115 -115
  96. data/assets/include/SDL2/SDL_thread.h +464 -464
  97. data/assets/include/SDL2/SDL_timer.h +222 -222
  98. data/assets/include/SDL2/SDL_touch.h +150 -150
  99. data/assets/include/SDL2/SDL_ttf.h +2316 -2316
  100. data/assets/include/SDL2/SDL_types.h +29 -29
  101. data/assets/include/SDL2/SDL_version.h +204 -204
  102. data/assets/include/SDL2/SDL_video.h +2150 -2150
  103. data/assets/include/SDL2/SDL_vulkan.h +215 -215
  104. data/assets/include/SDL2/begin_code.h +187 -187
  105. data/assets/include/SDL2/close_code.h +40 -40
  106. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libFLAC.a +0 -0
  107. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2.a +0 -0
  108. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libSDL2_mixer.a +0 -0
  109. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libglew32.a +0 -0
  110. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmodplug.a +0 -0
  111. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libmpg123.a +0 -0
  112. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libogg.a +0 -0
  113. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopus.a +0 -0
  114. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libopusfile.a +0 -0
  115. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libsndfile.a +0 -0
  116. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libssp.a +1 -1
  117. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libstdc++.a +0 -0
  118. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbis.a +0 -0
  119. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libvorbisfile.a +0 -0
  120. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libz.a +0 -0
  121. data/assets/windows/mingw-w64-ucrt-x86_64/lib/libzstd.a +0 -0
  122. data/assets/windows/mingw-w64-x86_64/lib/libFLAC.a +0 -0
  123. data/assets/windows/mingw-w64-x86_64/lib/libSDL2.a +0 -0
  124. data/assets/windows/mingw-w64-x86_64/lib/libSDL2_mixer.a +0 -0
  125. data/assets/windows/mingw-w64-x86_64/lib/libglew32.a +0 -0
  126. data/assets/windows/mingw-w64-x86_64/lib/libmodplug.a +0 -0
  127. data/assets/windows/mingw-w64-x86_64/lib/libmpg123.a +0 -0
  128. data/assets/windows/mingw-w64-x86_64/lib/libogg.a +0 -0
  129. data/assets/windows/mingw-w64-x86_64/lib/libopus.a +0 -0
  130. data/assets/windows/mingw-w64-x86_64/lib/libopusfile.a +0 -0
  131. data/assets/windows/mingw-w64-x86_64/lib/libsndfile.a +0 -0
  132. data/assets/windows/mingw-w64-x86_64/lib/libssp.a +1 -1
  133. data/assets/windows/mingw-w64-x86_64/lib/libstdc++.a +0 -0
  134. data/assets/windows/mingw-w64-x86_64/lib/libvorbis.a +0 -0
  135. data/assets/windows/mingw-w64-x86_64/lib/libvorbisfile.a +0 -0
  136. data/assets/windows/mingw-w64-x86_64/lib/libz.a +0 -0
  137. data/assets/windows/mingw-w64-x86_64/lib/libzstd.a +0 -0
  138. data/ext/audio.c +80 -80
  139. data/ext/extconf.h +3 -3
  140. data/ext/extconf.rb +173 -177
  141. data/lib/audio.bundle +0 -0
  142. data/lib/audio.so +0 -0
  143. data/lib/native_audio.rb +50 -50
  144. metadata +4 -9
  145. data/ext/Makefile +0 -270
  146. data/ext/audio.o +0 -0
  147. data/ext/mkmf.log +0 -7
@@ -1,1341 +1,1341 @@
1
- /*
2
- Simple DirectMedia Layer
3
- Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
4
-
5
- This software is provided 'as-is', without any express or implied
6
- warranty. In no event will the authors be held liable for any damages
7
- arising from the use of this software.
8
-
9
- Permission is granted to anyone to use this software for any purpose,
10
- including commercial applications, and to alter it and redistribute it
11
- freely, subject to the following restrictions:
12
-
13
- 1. The origin of this software must not be misrepresented; you must not
14
- claim that you wrote the original software. If you use this software
15
- in a product, an acknowledgment in the product documentation would be
16
- appreciated but is not required.
17
- 2. Altered source versions must be plainly marked as such, and must not be
18
- misrepresented as being the original software.
19
- 3. This notice may not be removed or altered from any source distribution.
20
- */
21
-
22
- /**
23
- * \file SDL_haptic.h
24
- *
25
- * \brief The SDL haptic subsystem allows you to control haptic (force feedback)
26
- * devices.
27
- *
28
- * The basic usage is as follows:
29
- * - Initialize the subsystem (::SDL_INIT_HAPTIC).
30
- * - Open a haptic device.
31
- * - SDL_HapticOpen() to open from index.
32
- * - SDL_HapticOpenFromJoystick() to open from an existing joystick.
33
- * - Create an effect (::SDL_HapticEffect).
34
- * - Upload the effect with SDL_HapticNewEffect().
35
- * - Run the effect with SDL_HapticRunEffect().
36
- * - (optional) Free the effect with SDL_HapticDestroyEffect().
37
- * - Close the haptic device with SDL_HapticClose().
38
- *
39
- * \par Simple rumble example:
40
- * \code
41
- * SDL_Haptic *haptic;
42
- *
43
- * // Open the device
44
- * haptic = SDL_HapticOpen( 0 );
45
- * if (haptic == NULL)
46
- * return -1;
47
- *
48
- * // Initialize simple rumble
49
- * if (SDL_HapticRumbleInit( haptic ) != 0)
50
- * return -1;
51
- *
52
- * // Play effect at 50% strength for 2 seconds
53
- * if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0)
54
- * return -1;
55
- * SDL_Delay( 2000 );
56
- *
57
- * // Clean up
58
- * SDL_HapticClose( haptic );
59
- * \endcode
60
- *
61
- * \par Complete example:
62
- * \code
63
- * int test_haptic( SDL_Joystick * joystick ) {
64
- * SDL_Haptic *haptic;
65
- * SDL_HapticEffect effect;
66
- * int effect_id;
67
- *
68
- * // Open the device
69
- * haptic = SDL_HapticOpenFromJoystick( joystick );
70
- * if (haptic == NULL) return -1; // Most likely joystick isn't haptic
71
- *
72
- * // See if it can do sine waves
73
- * if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) {
74
- * SDL_HapticClose(haptic); // No sine effect
75
- * return -1;
76
- * }
77
- *
78
- * // Create the effect
79
- * SDL_memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default
80
- * effect.type = SDL_HAPTIC_SINE;
81
- * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
82
- * effect.periodic.direction.dir[0] = 18000; // Force comes from south
83
- * effect.periodic.period = 1000; // 1000 ms
84
- * effect.periodic.magnitude = 20000; // 20000/32767 strength
85
- * effect.periodic.length = 5000; // 5 seconds long
86
- * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
87
- * effect.periodic.fade_length = 1000; // Takes 1 second to fade away
88
- *
89
- * // Upload the effect
90
- * effect_id = SDL_HapticNewEffect( haptic, &effect );
91
- *
92
- * // Test the effect
93
- * SDL_HapticRunEffect( haptic, effect_id, 1 );
94
- * SDL_Delay( 5000); // Wait for the effect to finish
95
- *
96
- * // We destroy the effect, although closing the device also does this
97
- * SDL_HapticDestroyEffect( haptic, effect_id );
98
- *
99
- * // Close the device
100
- * SDL_HapticClose(haptic);
101
- *
102
- * return 0; // Success
103
- * }
104
- * \endcode
105
- */
106
-
107
- #ifndef SDL_haptic_h_
108
- #define SDL_haptic_h_
109
-
110
- #include "SDL_stdinc.h"
111
- #include "SDL_error.h"
112
- #include "SDL_joystick.h"
113
-
114
- #include "begin_code.h"
115
- /* Set up for C function definitions, even when using C++ */
116
- #ifdef __cplusplus
117
- extern "C" {
118
- #endif /* __cplusplus */
119
-
120
- /* FIXME: For SDL 2.1, adjust all the magnitude variables to be Uint16 (0xFFFF).
121
- *
122
- * At the moment the magnitude variables are mixed between signed/unsigned, and
123
- * it is also not made clear that ALL of those variables expect a max of 0x7FFF.
124
- *
125
- * Some platforms may have higher precision than that (Linux FF, Windows XInput)
126
- * so we should fix the inconsistency in favor of higher possible precision,
127
- * adjusting for platforms that use different scales.
128
- * -flibit
129
- */
130
-
131
- /**
132
- * \typedef SDL_Haptic
133
- *
134
- * \brief The haptic structure used to identify an SDL haptic.
135
- *
136
- * \sa SDL_HapticOpen
137
- * \sa SDL_HapticOpenFromJoystick
138
- * \sa SDL_HapticClose
139
- */
140
- struct _SDL_Haptic;
141
- typedef struct _SDL_Haptic SDL_Haptic;
142
-
143
-
144
- /**
145
- * \name Haptic features
146
- *
147
- * Different haptic features a device can have.
148
- */
149
- /* @{ */
150
-
151
- /**
152
- * \name Haptic effects
153
- */
154
- /* @{ */
155
-
156
- /**
157
- * \brief Constant effect supported.
158
- *
159
- * Constant haptic effect.
160
- *
161
- * \sa SDL_HapticCondition
162
- */
163
- #define SDL_HAPTIC_CONSTANT (1u<<0)
164
-
165
- /**
166
- * \brief Sine wave effect supported.
167
- *
168
- * Periodic haptic effect that simulates sine waves.
169
- *
170
- * \sa SDL_HapticPeriodic
171
- */
172
- #define SDL_HAPTIC_SINE (1u<<1)
173
-
174
- /**
175
- * \brief Left/Right effect supported.
176
- *
177
- * Haptic effect for direct control over high/low frequency motors.
178
- *
179
- * \sa SDL_HapticLeftRight
180
- * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
181
- * we ran out of bits, and this is important for XInput devices.
182
- */
183
- #define SDL_HAPTIC_LEFTRIGHT (1u<<2)
184
-
185
- /* !!! FIXME: put this back when we have more bits in 2.1 */
186
- /* #define SDL_HAPTIC_SQUARE (1<<2) */
187
-
188
- /**
189
- * \brief Triangle wave effect supported.
190
- *
191
- * Periodic haptic effect that simulates triangular waves.
192
- *
193
- * \sa SDL_HapticPeriodic
194
- */
195
- #define SDL_HAPTIC_TRIANGLE (1u<<3)
196
-
197
- /**
198
- * \brief Sawtoothup wave effect supported.
199
- *
200
- * Periodic haptic effect that simulates saw tooth up waves.
201
- *
202
- * \sa SDL_HapticPeriodic
203
- */
204
- #define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
205
-
206
- /**
207
- * \brief Sawtoothdown wave effect supported.
208
- *
209
- * Periodic haptic effect that simulates saw tooth down waves.
210
- *
211
- * \sa SDL_HapticPeriodic
212
- */
213
- #define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
214
-
215
- /**
216
- * \brief Ramp effect supported.
217
- *
218
- * Ramp haptic effect.
219
- *
220
- * \sa SDL_HapticRamp
221
- */
222
- #define SDL_HAPTIC_RAMP (1u<<6)
223
-
224
- /**
225
- * \brief Spring effect supported - uses axes position.
226
- *
227
- * Condition haptic effect that simulates a spring. Effect is based on the
228
- * axes position.
229
- *
230
- * \sa SDL_HapticCondition
231
- */
232
- #define SDL_HAPTIC_SPRING (1u<<7)
233
-
234
- /**
235
- * \brief Damper effect supported - uses axes velocity.
236
- *
237
- * Condition haptic effect that simulates dampening. Effect is based on the
238
- * axes velocity.
239
- *
240
- * \sa SDL_HapticCondition
241
- */
242
- #define SDL_HAPTIC_DAMPER (1u<<8)
243
-
244
- /**
245
- * \brief Inertia effect supported - uses axes acceleration.
246
- *
247
- * Condition haptic effect that simulates inertia. Effect is based on the axes
248
- * acceleration.
249
- *
250
- * \sa SDL_HapticCondition
251
- */
252
- #define SDL_HAPTIC_INERTIA (1u<<9)
253
-
254
- /**
255
- * \brief Friction effect supported - uses axes movement.
256
- *
257
- * Condition haptic effect that simulates friction. Effect is based on the
258
- * axes movement.
259
- *
260
- * \sa SDL_HapticCondition
261
- */
262
- #define SDL_HAPTIC_FRICTION (1u<<10)
263
-
264
- /**
265
- * \brief Custom effect is supported.
266
- *
267
- * User defined custom haptic effect.
268
- */
269
- #define SDL_HAPTIC_CUSTOM (1u<<11)
270
-
271
- /* @} *//* Haptic effects */
272
-
273
- /* These last few are features the device has, not effects */
274
-
275
- /**
276
- * \brief Device can set global gain.
277
- *
278
- * Device supports setting the global gain.
279
- *
280
- * \sa SDL_HapticSetGain
281
- */
282
- #define SDL_HAPTIC_GAIN (1u<<12)
283
-
284
- /**
285
- * \brief Device can set autocenter.
286
- *
287
- * Device supports setting autocenter.
288
- *
289
- * \sa SDL_HapticSetAutocenter
290
- */
291
- #define SDL_HAPTIC_AUTOCENTER (1u<<13)
292
-
293
- /**
294
- * \brief Device can be queried for effect status.
295
- *
296
- * Device supports querying effect status.
297
- *
298
- * \sa SDL_HapticGetEffectStatus
299
- */
300
- #define SDL_HAPTIC_STATUS (1u<<14)
301
-
302
- /**
303
- * \brief Device can be paused.
304
- *
305
- * Devices supports being paused.
306
- *
307
- * \sa SDL_HapticPause
308
- * \sa SDL_HapticUnpause
309
- */
310
- #define SDL_HAPTIC_PAUSE (1u<<15)
311
-
312
-
313
- /**
314
- * \name Direction encodings
315
- */
316
- /* @{ */
317
-
318
- /**
319
- * \brief Uses polar coordinates for the direction.
320
- *
321
- * \sa SDL_HapticDirection
322
- */
323
- #define SDL_HAPTIC_POLAR 0
324
-
325
- /**
326
- * \brief Uses cartesian coordinates for the direction.
327
- *
328
- * \sa SDL_HapticDirection
329
- */
330
- #define SDL_HAPTIC_CARTESIAN 1
331
-
332
- /**
333
- * \brief Uses spherical coordinates for the direction.
334
- *
335
- * \sa SDL_HapticDirection
336
- */
337
- #define SDL_HAPTIC_SPHERICAL 2
338
-
339
- /**
340
- * \brief Use this value to play an effect on the steering wheel axis. This
341
- * provides better compatibility across platforms and devices as SDL will guess
342
- * the correct axis.
343
- * \sa SDL_HapticDirection
344
- */
345
- #define SDL_HAPTIC_STEERING_AXIS 3
346
-
347
- /* @} *//* Direction encodings */
348
-
349
- /* @} *//* Haptic features */
350
-
351
- /*
352
- * Misc defines.
353
- */
354
-
355
- /**
356
- * \brief Used to play a device an infinite number of times.
357
- *
358
- * \sa SDL_HapticRunEffect
359
- */
360
- #define SDL_HAPTIC_INFINITY 4294967295U
361
-
362
-
363
- /**
364
- * \brief Structure that represents a haptic direction.
365
- *
366
- * This is the direction where the force comes from,
367
- * instead of the direction in which the force is exerted.
368
- *
369
- * Directions can be specified by:
370
- * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates.
371
- * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
372
- * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
373
- *
374
- * Cardinal directions of the haptic device are relative to the positioning
375
- * of the device. North is considered to be away from the user.
376
- *
377
- * The following diagram represents the cardinal directions:
378
- * \verbatim
379
- .--.
380
- |__| .-------.
381
- |=.| |.-----.|
382
- |--| || ||
383
- | | |'-----'|
384
- |__|~')_____('
385
- [ COMPUTER ]
386
-
387
-
388
- North (0,-1)
389
- ^
390
- |
391
- |
392
- (-1,0) West <----[ HAPTIC ]----> East (1,0)
393
- |
394
- |
395
- v
396
- South (0,1)
397
-
398
-
399
- [ USER ]
400
- \|||/
401
- (o o)
402
- ---ooO-(_)-Ooo---
403
- \endverbatim
404
- *
405
- * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a
406
- * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses
407
- * the first \c dir parameter. The cardinal directions would be:
408
- * - North: 0 (0 degrees)
409
- * - East: 9000 (90 degrees)
410
- * - South: 18000 (180 degrees)
411
- * - West: 27000 (270 degrees)
412
- *
413
- * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions
414
- * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses
415
- * the first three \c dir parameters. The cardinal directions would be:
416
- * - North: 0,-1, 0
417
- * - East: 1, 0, 0
418
- * - South: 0, 1, 0
419
- * - West: -1, 0, 0
420
- *
421
- * The Z axis represents the height of the effect if supported, otherwise
422
- * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you
423
- * can use any multiple you want, only the direction matters.
424
- *
425
- * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations.
426
- * The first two \c dir parameters are used. The \c dir parameters are as
427
- * follows (all values are in hundredths of degrees):
428
- * - Degrees from (1, 0) rotated towards (0, 1).
429
- * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
430
- *
431
- *
432
- * Example of force coming from the south with all encodings (force coming
433
- * from the south means the user will have to pull the stick to counteract):
434
- * \code
435
- * SDL_HapticDirection direction;
436
- *
437
- * // Cartesian directions
438
- * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
439
- * direction.dir[0] = 0; // X position
440
- * direction.dir[1] = 1; // Y position
441
- * // Assuming the device has 2 axes, we don't need to specify third parameter.
442
- *
443
- * // Polar directions
444
- * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
445
- * direction.dir[0] = 18000; // Polar only uses first parameter
446
- *
447
- * // Spherical coordinates
448
- * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
449
- * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
450
- * \endcode
451
- *
452
- * \sa SDL_HAPTIC_POLAR
453
- * \sa SDL_HAPTIC_CARTESIAN
454
- * \sa SDL_HAPTIC_SPHERICAL
455
- * \sa SDL_HAPTIC_STEERING_AXIS
456
- * \sa SDL_HapticEffect
457
- * \sa SDL_HapticNumAxes
458
- */
459
- typedef struct SDL_HapticDirection
460
- {
461
- Uint8 type; /**< The type of encoding. */
462
- Sint32 dir[3]; /**< The encoded direction. */
463
- } SDL_HapticDirection;
464
-
465
-
466
- /**
467
- * \brief A structure containing a template for a Constant effect.
468
- *
469
- * This struct is exclusively for the ::SDL_HAPTIC_CONSTANT effect.
470
- *
471
- * A constant effect applies a constant force in the specified direction
472
- * to the joystick.
473
- *
474
- * \sa SDL_HAPTIC_CONSTANT
475
- * \sa SDL_HapticEffect
476
- */
477
- typedef struct SDL_HapticConstant
478
- {
479
- /* Header */
480
- Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */
481
- SDL_HapticDirection direction; /**< Direction of the effect. */
482
-
483
- /* Replay */
484
- Uint32 length; /**< Duration of the effect. */
485
- Uint16 delay; /**< Delay before starting the effect. */
486
-
487
- /* Trigger */
488
- Uint16 button; /**< Button that triggers the effect. */
489
- Uint16 interval; /**< How soon it can be triggered again after button. */
490
-
491
- /* Constant */
492
- Sint16 level; /**< Strength of the constant effect. */
493
-
494
- /* Envelope */
495
- Uint16 attack_length; /**< Duration of the attack. */
496
- Uint16 attack_level; /**< Level at the start of the attack. */
497
- Uint16 fade_length; /**< Duration of the fade. */
498
- Uint16 fade_level; /**< Level at the end of the fade. */
499
- } SDL_HapticConstant;
500
-
501
- /**
502
- * \brief A structure containing a template for a Periodic effect.
503
- *
504
- * The struct handles the following effects:
505
- * - ::SDL_HAPTIC_SINE
506
- * - ::SDL_HAPTIC_LEFTRIGHT
507
- * - ::SDL_HAPTIC_TRIANGLE
508
- * - ::SDL_HAPTIC_SAWTOOTHUP
509
- * - ::SDL_HAPTIC_SAWTOOTHDOWN
510
- *
511
- * A periodic effect consists in a wave-shaped effect that repeats itself
512
- * over time. The type determines the shape of the wave and the parameters
513
- * determine the dimensions of the wave.
514
- *
515
- * Phase is given by hundredth of a degree meaning that giving the phase a value
516
- * of 9000 will displace it 25% of its period. Here are sample values:
517
- * - 0: No phase displacement.
518
- * - 9000: Displaced 25% of its period.
519
- * - 18000: Displaced 50% of its period.
520
- * - 27000: Displaced 75% of its period.
521
- * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
522
- *
523
- * Examples:
524
- * \verbatim
525
- SDL_HAPTIC_SINE
526
- __ __ __ __
527
- / \ / \ / \ /
528
- / \__/ \__/ \__/
529
-
530
- SDL_HAPTIC_SQUARE
531
- __ __ __ __ __
532
- | | | | | | | | | |
533
- | |__| |__| |__| |__| |
534
-
535
- SDL_HAPTIC_TRIANGLE
536
- /\ /\ /\ /\ /\
537
- / \ / \ / \ / \ /
538
- / \/ \/ \/ \/
539
-
540
- SDL_HAPTIC_SAWTOOTHUP
541
- /| /| /| /| /| /| /|
542
- / | / | / | / | / | / | / |
543
- / |/ |/ |/ |/ |/ |/ |
544
-
545
- SDL_HAPTIC_SAWTOOTHDOWN
546
- \ |\ |\ |\ |\ |\ |\ |
547
- \ | \ | \ | \ | \ | \ | \ |
548
- \| \| \| \| \| \| \|
549
- \endverbatim
550
- *
551
- * \sa SDL_HAPTIC_SINE
552
- * \sa SDL_HAPTIC_LEFTRIGHT
553
- * \sa SDL_HAPTIC_TRIANGLE
554
- * \sa SDL_HAPTIC_SAWTOOTHUP
555
- * \sa SDL_HAPTIC_SAWTOOTHDOWN
556
- * \sa SDL_HapticEffect
557
- */
558
- typedef struct SDL_HapticPeriodic
559
- {
560
- /* Header */
561
- Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT,
562
- ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or
563
- ::SDL_HAPTIC_SAWTOOTHDOWN */
564
- SDL_HapticDirection direction; /**< Direction of the effect. */
565
-
566
- /* Replay */
567
- Uint32 length; /**< Duration of the effect. */
568
- Uint16 delay; /**< Delay before starting the effect. */
569
-
570
- /* Trigger */
571
- Uint16 button; /**< Button that triggers the effect. */
572
- Uint16 interval; /**< How soon it can be triggered again after button. */
573
-
574
- /* Periodic */
575
- Uint16 period; /**< Period of the wave. */
576
- Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
577
- Sint16 offset; /**< Mean value of the wave. */
578
- Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
579
-
580
- /* Envelope */
581
- Uint16 attack_length; /**< Duration of the attack. */
582
- Uint16 attack_level; /**< Level at the start of the attack. */
583
- Uint16 fade_length; /**< Duration of the fade. */
584
- Uint16 fade_level; /**< Level at the end of the fade. */
585
- } SDL_HapticPeriodic;
586
-
587
- /**
588
- * \brief A structure containing a template for a Condition effect.
589
- *
590
- * The struct handles the following effects:
591
- * - ::SDL_HAPTIC_SPRING: Effect based on axes position.
592
- * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity.
593
- * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
594
- * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement.
595
- *
596
- * Direction is handled by condition internals instead of a direction member.
597
- * The condition effect specific members have three parameters. The first
598
- * refers to the X axis, the second refers to the Y axis and the third
599
- * refers to the Z axis. The right terms refer to the positive side of the
600
- * axis and the left terms refer to the negative side of the axis. Please
601
- * refer to the ::SDL_HapticDirection diagram for which side is positive and
602
- * which is negative.
603
- *
604
- * \sa SDL_HapticDirection
605
- * \sa SDL_HAPTIC_SPRING
606
- * \sa SDL_HAPTIC_DAMPER
607
- * \sa SDL_HAPTIC_INERTIA
608
- * \sa SDL_HAPTIC_FRICTION
609
- * \sa SDL_HapticEffect
610
- */
611
- typedef struct SDL_HapticCondition
612
- {
613
- /* Header */
614
- Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,
615
- ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */
616
- SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
617
-
618
- /* Replay */
619
- Uint32 length; /**< Duration of the effect. */
620
- Uint16 delay; /**< Delay before starting the effect. */
621
-
622
- /* Trigger */
623
- Uint16 button; /**< Button that triggers the effect. */
624
- Uint16 interval; /**< How soon it can be triggered again after button. */
625
-
626
- /* Condition */
627
- Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
628
- Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
629
- Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
630
- Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
631
- Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
632
- Sint16 center[3]; /**< Position of the dead zone. */
633
- } SDL_HapticCondition;
634
-
635
- /**
636
- * \brief A structure containing a template for a Ramp effect.
637
- *
638
- * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect.
639
- *
640
- * The ramp effect starts at start strength and ends at end strength.
641
- * It augments in linear fashion. If you use attack and fade with a ramp
642
- * the effects get added to the ramp effect making the effect become
643
- * quadratic instead of linear.
644
- *
645
- * \sa SDL_HAPTIC_RAMP
646
- * \sa SDL_HapticEffect
647
- */
648
- typedef struct SDL_HapticRamp
649
- {
650
- /* Header */
651
- Uint16 type; /**< ::SDL_HAPTIC_RAMP */
652
- SDL_HapticDirection direction; /**< Direction of the effect. */
653
-
654
- /* Replay */
655
- Uint32 length; /**< Duration of the effect. */
656
- Uint16 delay; /**< Delay before starting the effect. */
657
-
658
- /* Trigger */
659
- Uint16 button; /**< Button that triggers the effect. */
660
- Uint16 interval; /**< How soon it can be triggered again after button. */
661
-
662
- /* Ramp */
663
- Sint16 start; /**< Beginning strength level. */
664
- Sint16 end; /**< Ending strength level. */
665
-
666
- /* Envelope */
667
- Uint16 attack_length; /**< Duration of the attack. */
668
- Uint16 attack_level; /**< Level at the start of the attack. */
669
- Uint16 fade_length; /**< Duration of the fade. */
670
- Uint16 fade_level; /**< Level at the end of the fade. */
671
- } SDL_HapticRamp;
672
-
673
- /**
674
- * \brief A structure containing a template for a Left/Right effect.
675
- *
676
- * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect.
677
- *
678
- * The Left/Right effect is used to explicitly control the large and small
679
- * motors, commonly found in modern game controllers. The small (right) motor
680
- * is high frequency, and the large (left) motor is low frequency.
681
- *
682
- * \sa SDL_HAPTIC_LEFTRIGHT
683
- * \sa SDL_HapticEffect
684
- */
685
- typedef struct SDL_HapticLeftRight
686
- {
687
- /* Header */
688
- Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */
689
-
690
- /* Replay */
691
- Uint32 length; /**< Duration of the effect in milliseconds. */
692
-
693
- /* Rumble */
694
- Uint16 large_magnitude; /**< Control of the large controller motor. */
695
- Uint16 small_magnitude; /**< Control of the small controller motor. */
696
- } SDL_HapticLeftRight;
697
-
698
- /**
699
- * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect.
700
- *
701
- * This struct is exclusively for the ::SDL_HAPTIC_CUSTOM effect.
702
- *
703
- * A custom force feedback effect is much like a periodic effect, where the
704
- * application can define its exact shape. You will have to allocate the
705
- * data yourself. Data should consist of channels * samples Uint16 samples.
706
- *
707
- * If channels is one, the effect is rotated using the defined direction.
708
- * Otherwise it uses the samples in data for the different axes.
709
- *
710
- * \sa SDL_HAPTIC_CUSTOM
711
- * \sa SDL_HapticEffect
712
- */
713
- typedef struct SDL_HapticCustom
714
- {
715
- /* Header */
716
- Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */
717
- SDL_HapticDirection direction; /**< Direction of the effect. */
718
-
719
- /* Replay */
720
- Uint32 length; /**< Duration of the effect. */
721
- Uint16 delay; /**< Delay before starting the effect. */
722
-
723
- /* Trigger */
724
- Uint16 button; /**< Button that triggers the effect. */
725
- Uint16 interval; /**< How soon it can be triggered again after button. */
726
-
727
- /* Custom */
728
- Uint8 channels; /**< Axes to use, minimum of one. */
729
- Uint16 period; /**< Sample periods. */
730
- Uint16 samples; /**< Amount of samples. */
731
- Uint16 *data; /**< Should contain channels*samples items. */
732
-
733
- /* Envelope */
734
- Uint16 attack_length; /**< Duration of the attack. */
735
- Uint16 attack_level; /**< Level at the start of the attack. */
736
- Uint16 fade_length; /**< Duration of the fade. */
737
- Uint16 fade_level; /**< Level at the end of the fade. */
738
- } SDL_HapticCustom;
739
-
740
- /**
741
- * \brief The generic template for any haptic effect.
742
- *
743
- * All values max at 32767 (0x7FFF). Signed values also can be negative.
744
- * Time values unless specified otherwise are in milliseconds.
745
- *
746
- * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767
747
- * value. Neither delay, interval, attack_length nor fade_length support
748
- * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
749
- *
750
- * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of
751
- * ::SDL_HAPTIC_INFINITY.
752
- *
753
- * Button triggers may not be supported on all devices, it is advised to not
754
- * use them if possible. Buttons start at index 1 instead of index 0 like
755
- * the joystick.
756
- *
757
- * If both attack_length and fade_level are 0, the envelope is not used,
758
- * otherwise both values are used.
759
- *
760
- * Common parts:
761
- * \code
762
- * // Replay - All effects have this
763
- * Uint32 length; // Duration of effect (ms).
764
- * Uint16 delay; // Delay before starting effect.
765
- *
766
- * // Trigger - All effects have this
767
- * Uint16 button; // Button that triggers effect.
768
- * Uint16 interval; // How soon before effect can be triggered again.
769
- *
770
- * // Envelope - All effects except condition effects have this
771
- * Uint16 attack_length; // Duration of the attack (ms).
772
- * Uint16 attack_level; // Level at the start of the attack.
773
- * Uint16 fade_length; // Duration of the fade out (ms).
774
- * Uint16 fade_level; // Level at the end of the fade.
775
- * \endcode
776
- *
777
- *
778
- * Here we have an example of a constant effect evolution in time:
779
- * \verbatim
780
- Strength
781
- ^
782
- |
783
- | effect level --> _________________
784
- | / \
785
- | / \
786
- | / \
787
- | / \
788
- | attack_level --> | \
789
- | | | <--- fade_level
790
- |
791
- +--------------------------------------------------> Time
792
- [--] [---]
793
- attack_length fade_length
794
-
795
- [------------------][-----------------------]
796
- delay length
797
- \endverbatim
798
- *
799
- * Note either the attack_level or the fade_level may be above the actual
800
- * effect level.
801
- *
802
- * \sa SDL_HapticConstant
803
- * \sa SDL_HapticPeriodic
804
- * \sa SDL_HapticCondition
805
- * \sa SDL_HapticRamp
806
- * \sa SDL_HapticLeftRight
807
- * \sa SDL_HapticCustom
808
- */
809
- typedef union SDL_HapticEffect
810
- {
811
- /* Common for all force feedback effects */
812
- Uint16 type; /**< Effect type. */
813
- SDL_HapticConstant constant; /**< Constant effect. */
814
- SDL_HapticPeriodic periodic; /**< Periodic effect. */
815
- SDL_HapticCondition condition; /**< Condition effect. */
816
- SDL_HapticRamp ramp; /**< Ramp effect. */
817
- SDL_HapticLeftRight leftright; /**< Left/Right effect. */
818
- SDL_HapticCustom custom; /**< Custom effect. */
819
- } SDL_HapticEffect;
820
-
821
-
822
- /* Function prototypes */
823
-
824
- /**
825
- * Count the number of haptic devices attached to the system.
826
- *
827
- * \returns the number of haptic devices detected on the system or a negative
828
- * error code on failure; call SDL_GetError() for more information.
829
- *
830
- * \since This function is available since SDL 2.0.0.
831
- *
832
- * \sa SDL_HapticName
833
- */
834
- extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
835
-
836
- /**
837
- * Get the implementation dependent name of a haptic device.
838
- *
839
- * This can be called before any joysticks are opened. If no name can be
840
- * found, this function returns NULL.
841
- *
842
- * \param device_index index of the device to query.
843
- * \returns the name of the device or NULL on failure; call SDL_GetError() for
844
- * more information.
845
- *
846
- * \since This function is available since SDL 2.0.0.
847
- *
848
- * \sa SDL_NumHaptics
849
- */
850
- extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
851
-
852
- /**
853
- * Open a haptic device for use.
854
- *
855
- * The index passed as an argument refers to the N'th haptic device on this
856
- * system.
857
- *
858
- * When opening a haptic device, its gain will be set to maximum and
859
- * autocenter will be disabled. To modify these values use SDL_HapticSetGain()
860
- * and SDL_HapticSetAutocenter().
861
- *
862
- * \param device_index index of the device to open
863
- * \returns the device identifier or NULL on failure; call SDL_GetError() for
864
- * more information.
865
- *
866
- * \since This function is available since SDL 2.0.0.
867
- *
868
- * \sa SDL_HapticClose
869
- * \sa SDL_HapticIndex
870
- * \sa SDL_HapticOpenFromJoystick
871
- * \sa SDL_HapticOpenFromMouse
872
- * \sa SDL_HapticPause
873
- * \sa SDL_HapticSetAutocenter
874
- * \sa SDL_HapticSetGain
875
- * \sa SDL_HapticStopAll
876
- */
877
- extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);
878
-
879
- /**
880
- * Check if the haptic device at the designated index has been opened.
881
- *
882
- * \param device_index the index of the device to query
883
- * \returns 1 if it has been opened, 0 if it hasn't or on failure; call
884
- * SDL_GetError() for more information.
885
- *
886
- * \since This function is available since SDL 2.0.0.
887
- *
888
- * \sa SDL_HapticIndex
889
- * \sa SDL_HapticOpen
890
- */
891
- extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index);
892
-
893
- /**
894
- * Get the index of a haptic device.
895
- *
896
- * \param haptic the SDL_Haptic device to query
897
- * \returns the index of the specified haptic device or a negative error code
898
- * on failure; call SDL_GetError() for more information.
899
- *
900
- * \since This function is available since SDL 2.0.0.
901
- *
902
- * \sa SDL_HapticOpen
903
- * \sa SDL_HapticOpened
904
- */
905
- extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic);
906
-
907
- /**
908
- * Query whether or not the current mouse has haptic capabilities.
909
- *
910
- * \returns SDL_TRUE if the mouse is haptic or SDL_FALSE if it isn't.
911
- *
912
- * \since This function is available since SDL 2.0.0.
913
- *
914
- * \sa SDL_HapticOpenFromMouse
915
- */
916
- extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void);
917
-
918
- /**
919
- * Try to open a haptic device from the current mouse.
920
- *
921
- * \returns the haptic device identifier or NULL on failure; call
922
- * SDL_GetError() for more information.
923
- *
924
- * \since This function is available since SDL 2.0.0.
925
- *
926
- * \sa SDL_HapticOpen
927
- * \sa SDL_MouseIsHaptic
928
- */
929
- extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void);
930
-
931
- /**
932
- * Query if a joystick has haptic features.
933
- *
934
- * \param joystick the SDL_Joystick to test for haptic capabilities
935
- * \returns SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't, or a
936
- * negative error code on failure; call SDL_GetError() for more
937
- * information.
938
- *
939
- * \since This function is available since SDL 2.0.0.
940
- *
941
- * \sa SDL_HapticOpenFromJoystick
942
- */
943
- extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick);
944
-
945
- /**
946
- * Open a haptic device for use from a joystick device.
947
- *
948
- * You must still close the haptic device separately. It will not be closed
949
- * with the joystick.
950
- *
951
- * When opened from a joystick you should first close the haptic device before
952
- * closing the joystick device. If not, on some implementations the haptic
953
- * device will also get unallocated and you'll be unable to use force feedback
954
- * on that device.
955
- *
956
- * \param joystick the SDL_Joystick to create a haptic device from
957
- * \returns a valid haptic device identifier on success or NULL on failure;
958
- * call SDL_GetError() for more information.
959
- *
960
- * \since This function is available since SDL 2.0.0.
961
- *
962
- * \sa SDL_HapticClose
963
- * \sa SDL_HapticOpen
964
- * \sa SDL_JoystickIsHaptic
965
- */
966
- extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *
967
- joystick);
968
-
969
- /**
970
- * Close a haptic device previously opened with SDL_HapticOpen().
971
- *
972
- * \param haptic the SDL_Haptic device to close
973
- *
974
- * \since This function is available since SDL 2.0.0.
975
- *
976
- * \sa SDL_HapticOpen
977
- */
978
- extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic);
979
-
980
- /**
981
- * Get the number of effects a haptic device can store.
982
- *
983
- * On some platforms this isn't fully supported, and therefore is an
984
- * approximation. Always check to see if your created effect was actually
985
- * created and do not rely solely on SDL_HapticNumEffects().
986
- *
987
- * \param haptic the SDL_Haptic device to query
988
- * \returns the number of effects the haptic device can store or a negative
989
- * error code on failure; call SDL_GetError() for more information.
990
- *
991
- * \since This function is available since SDL 2.0.0.
992
- *
993
- * \sa SDL_HapticNumEffectsPlaying
994
- * \sa SDL_HapticQuery
995
- */
996
- extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic);
997
-
998
- /**
999
- * Get the number of effects a haptic device can play at the same time.
1000
- *
1001
- * This is not supported on all platforms, but will always return a value.
1002
- *
1003
- * \param haptic the SDL_Haptic device to query maximum playing effects
1004
- * \returns the number of effects the haptic device can play at the same time
1005
- * or a negative error code on failure; call SDL_GetError() for more
1006
- * information.
1007
- *
1008
- * \since This function is available since SDL 2.0.0.
1009
- *
1010
- * \sa SDL_HapticNumEffects
1011
- * \sa SDL_HapticQuery
1012
- */
1013
- extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic);
1014
-
1015
- /**
1016
- * Get the haptic device's supported features in bitwise manner.
1017
- *
1018
- * \param haptic the SDL_Haptic device to query
1019
- * \returns a list of supported haptic features in bitwise manner (OR'd), or 0
1020
- * on failure; call SDL_GetError() for more information.
1021
- *
1022
- * \since This function is available since SDL 2.0.0.
1023
- *
1024
- * \sa SDL_HapticEffectSupported
1025
- * \sa SDL_HapticNumEffects
1026
- */
1027
- extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic);
1028
-
1029
-
1030
- /**
1031
- * Get the number of haptic axes the device has.
1032
- *
1033
- * The number of haptic axes might be useful if working with the
1034
- * SDL_HapticDirection effect.
1035
- *
1036
- * \param haptic the SDL_Haptic device to query
1037
- * \returns the number of axes on success or a negative error code on failure;
1038
- * call SDL_GetError() for more information.
1039
- *
1040
- * \since This function is available since SDL 2.0.0.
1041
- */
1042
- extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
1043
-
1044
- /**
1045
- * Check to see if an effect is supported by a haptic device.
1046
- *
1047
- * \param haptic the SDL_Haptic device to query
1048
- * \param effect the desired effect to query
1049
- * \returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't, or a
1050
- * negative error code on failure; call SDL_GetError() for more
1051
- * information.
1052
- *
1053
- * \since This function is available since SDL 2.0.0.
1054
- *
1055
- * \sa SDL_HapticNewEffect
1056
- * \sa SDL_HapticQuery
1057
- */
1058
- extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic,
1059
- SDL_HapticEffect *
1060
- effect);
1061
-
1062
- /**
1063
- * Create a new haptic effect on a specified device.
1064
- *
1065
- * \param haptic an SDL_Haptic device to create the effect on
1066
- * \param effect an SDL_HapticEffect structure containing the properties of
1067
- * the effect to create
1068
- * \returns the ID of the effect on success or a negative error code on
1069
- * failure; call SDL_GetError() for more information.
1070
- *
1071
- * \since This function is available since SDL 2.0.0.
1072
- *
1073
- * \sa SDL_HapticDestroyEffect
1074
- * \sa SDL_HapticRunEffect
1075
- * \sa SDL_HapticUpdateEffect
1076
- */
1077
- extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic,
1078
- SDL_HapticEffect * effect);
1079
-
1080
- /**
1081
- * Update the properties of an effect.
1082
- *
1083
- * Can be used dynamically, although behavior when dynamically changing
1084
- * direction may be strange. Specifically the effect may re-upload itself and
1085
- * start playing from the start. You also cannot change the type either when
1086
- * running SDL_HapticUpdateEffect().
1087
- *
1088
- * \param haptic the SDL_Haptic device that has the effect
1089
- * \param effect the identifier of the effect to update
1090
- * \param data an SDL_HapticEffect structure containing the new effect
1091
- * properties to use
1092
- * \returns 0 on success or a negative error code on failure; call
1093
- * SDL_GetError() for more information.
1094
- *
1095
- * \since This function is available since SDL 2.0.0.
1096
- *
1097
- * \sa SDL_HapticDestroyEffect
1098
- * \sa SDL_HapticNewEffect
1099
- * \sa SDL_HapticRunEffect
1100
- */
1101
- extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic,
1102
- int effect,
1103
- SDL_HapticEffect * data);
1104
-
1105
- /**
1106
- * Run the haptic effect on its associated haptic device.
1107
- *
1108
- * To repeat the effect over and over indefinitely, set `iterations` to
1109
- * `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make
1110
- * one instance of the effect last indefinitely (so the effect does not fade),
1111
- * set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY`
1112
- * instead.
1113
- *
1114
- * \param haptic the SDL_Haptic device to run the effect on
1115
- * \param effect the ID of the haptic effect to run
1116
- * \param iterations the number of iterations to run the effect; use
1117
- * `SDL_HAPTIC_INFINITY` to repeat forever
1118
- * \returns 0 on success or a negative error code on failure; call
1119
- * SDL_GetError() for more information.
1120
- *
1121
- * \since This function is available since SDL 2.0.0.
1122
- *
1123
- * \sa SDL_HapticDestroyEffect
1124
- * \sa SDL_HapticGetEffectStatus
1125
- * \sa SDL_HapticStopEffect
1126
- */
1127
- extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic,
1128
- int effect,
1129
- Uint32 iterations);
1130
-
1131
- /**
1132
- * Stop the haptic effect on its associated haptic device.
1133
- *
1134
- * *
1135
- *
1136
- * \param haptic the SDL_Haptic device to stop the effect on
1137
- * \param effect the ID of the haptic effect to stop
1138
- * \returns 0 on success or a negative error code on failure; call
1139
- * SDL_GetError() for more information.
1140
- *
1141
- * \since This function is available since SDL 2.0.0.
1142
- *
1143
- * \sa SDL_HapticDestroyEffect
1144
- * \sa SDL_HapticRunEffect
1145
- */
1146
- extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic,
1147
- int effect);
1148
-
1149
- /**
1150
- * Destroy a haptic effect on the device.
1151
- *
1152
- * This will stop the effect if it's running. Effects are automatically
1153
- * destroyed when the device is closed.
1154
- *
1155
- * \param haptic the SDL_Haptic device to destroy the effect on
1156
- * \param effect the ID of the haptic effect to destroy
1157
- *
1158
- * \since This function is available since SDL 2.0.0.
1159
- *
1160
- * \sa SDL_HapticNewEffect
1161
- */
1162
- extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic,
1163
- int effect);
1164
-
1165
- /**
1166
- * Get the status of the current effect on the specified haptic device.
1167
- *
1168
- * Device must support the SDL_HAPTIC_STATUS feature.
1169
- *
1170
- * \param haptic the SDL_Haptic device to query for the effect status on
1171
- * \param effect the ID of the haptic effect to query its status
1172
- * \returns 0 if it isn't playing, 1 if it is playing, or a negative error
1173
- * code on failure; call SDL_GetError() for more information.
1174
- *
1175
- * \since This function is available since SDL 2.0.0.
1176
- *
1177
- * \sa SDL_HapticRunEffect
1178
- * \sa SDL_HapticStopEffect
1179
- */
1180
- extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic,
1181
- int effect);
1182
-
1183
- /**
1184
- * Set the global gain of the specified haptic device.
1185
- *
1186
- * Device must support the SDL_HAPTIC_GAIN feature.
1187
- *
1188
- * The user may specify the maximum gain by setting the environment variable
1189
- * `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to
1190
- * SDL_HapticSetGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the
1191
- * maximum.
1192
- *
1193
- * \param haptic the SDL_Haptic device to set the gain on
1194
- * \param gain value to set the gain to, should be between 0 and 100 (0 - 100)
1195
- * \returns 0 on success or a negative error code on failure; call
1196
- * SDL_GetError() for more information.
1197
- *
1198
- * \since This function is available since SDL 2.0.0.
1199
- *
1200
- * \sa SDL_HapticQuery
1201
- */
1202
- extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
1203
-
1204
- /**
1205
- * Set the global autocenter of the device.
1206
- *
1207
- * Autocenter should be between 0 and 100. Setting it to 0 will disable
1208
- * autocentering.
1209
- *
1210
- * Device must support the SDL_HAPTIC_AUTOCENTER feature.
1211
- *
1212
- * \param haptic the SDL_Haptic device to set autocentering on
1213
- * \param autocenter value to set autocenter to (0-100)
1214
- * \returns 0 on success or a negative error code on failure; call
1215
- * SDL_GetError() for more information.
1216
- *
1217
- * \since This function is available since SDL 2.0.0.
1218
- *
1219
- * \sa SDL_HapticQuery
1220
- */
1221
- extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic,
1222
- int autocenter);
1223
-
1224
- /**
1225
- * Pause a haptic device.
1226
- *
1227
- * Device must support the `SDL_HAPTIC_PAUSE` feature. Call
1228
- * SDL_HapticUnpause() to resume playback.
1229
- *
1230
- * Do not modify the effects nor add new ones while the device is paused. That
1231
- * can cause all sorts of weird errors.
1232
- *
1233
- * \param haptic the SDL_Haptic device to pause
1234
- * \returns 0 on success or a negative error code on failure; call
1235
- * SDL_GetError() for more information.
1236
- *
1237
- * \since This function is available since SDL 2.0.0.
1238
- *
1239
- * \sa SDL_HapticUnpause
1240
- */
1241
- extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
1242
-
1243
- /**
1244
- * Unpause a haptic device.
1245
- *
1246
- * Call to unpause after SDL_HapticPause().
1247
- *
1248
- * \param haptic the SDL_Haptic device to unpause
1249
- * \returns 0 on success or a negative error code on failure; call
1250
- * SDL_GetError() for more information.
1251
- *
1252
- * \since This function is available since SDL 2.0.0.
1253
- *
1254
- * \sa SDL_HapticPause
1255
- */
1256
- extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
1257
-
1258
- /**
1259
- * Stop all the currently playing effects on a haptic device.
1260
- *
1261
- * \param haptic the SDL_Haptic device to stop
1262
- * \returns 0 on success or a negative error code on failure; call
1263
- * SDL_GetError() for more information.
1264
- *
1265
- * \since This function is available since SDL 2.0.0.
1266
- */
1267
- extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
1268
-
1269
- /**
1270
- * Check whether rumble is supported on a haptic device.
1271
- *
1272
- * \param haptic haptic device to check for rumble support
1273
- * \returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't, or a
1274
- * negative error code on failure; call SDL_GetError() for more
1275
- * information.
1276
- *
1277
- * \since This function is available since SDL 2.0.0.
1278
- *
1279
- * \sa SDL_HapticRumbleInit
1280
- * \sa SDL_HapticRumblePlay
1281
- * \sa SDL_HapticRumbleStop
1282
- */
1283
- extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
1284
-
1285
- /**
1286
- * Initialize a haptic device for simple rumble playback.
1287
- *
1288
- * \param haptic the haptic device to initialize for simple rumble playback
1289
- * \returns 0 on success or a negative error code on failure; call
1290
- * SDL_GetError() for more information.
1291
- *
1292
- * \since This function is available since SDL 2.0.0.
1293
- *
1294
- * \sa SDL_HapticOpen
1295
- * \sa SDL_HapticRumblePlay
1296
- * \sa SDL_HapticRumbleStop
1297
- * \sa SDL_HapticRumbleSupported
1298
- */
1299
- extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
1300
-
1301
- /**
1302
- * Run a simple rumble effect on a haptic device.
1303
- *
1304
- * \param haptic the haptic device to play the rumble effect on
1305
- * \param strength strength of the rumble to play as a 0-1 float value
1306
- * \param length length of the rumble to play in milliseconds
1307
- * \returns 0 on success or a negative error code on failure; call
1308
- * SDL_GetError() for more information.
1309
- *
1310
- * \since This function is available since SDL 2.0.0.
1311
- *
1312
- * \sa SDL_HapticRumbleInit
1313
- * \sa SDL_HapticRumbleStop
1314
- * \sa SDL_HapticRumbleSupported
1315
- */
1316
- extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );
1317
-
1318
- /**
1319
- * Stop the simple rumble on a haptic device.
1320
- *
1321
- * \param haptic the haptic device to stop the rumble effect on
1322
- * \returns 0 on success or a negative error code on failure; call
1323
- * SDL_GetError() for more information.
1324
- *
1325
- * \since This function is available since SDL 2.0.0.
1326
- *
1327
- * \sa SDL_HapticRumbleInit
1328
- * \sa SDL_HapticRumblePlay
1329
- * \sa SDL_HapticRumbleSupported
1330
- */
1331
- extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);
1332
-
1333
- /* Ends C function definitions when using C++ */
1334
- #ifdef __cplusplus
1335
- }
1336
- #endif
1337
- #include "close_code.h"
1338
-
1339
- #endif /* SDL_haptic_h_ */
1340
-
1341
- /* vi: set ts=4 sw=4 expandtab: */
1
+ /*
2
+ Simple DirectMedia Layer
3
+ Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
4
+
5
+ This software is provided 'as-is', without any express or implied
6
+ warranty. In no event will the authors be held liable for any damages
7
+ arising from the use of this software.
8
+
9
+ Permission is granted to anyone to use this software for any purpose,
10
+ including commercial applications, and to alter it and redistribute it
11
+ freely, subject to the following restrictions:
12
+
13
+ 1. The origin of this software must not be misrepresented; you must not
14
+ claim that you wrote the original software. If you use this software
15
+ in a product, an acknowledgment in the product documentation would be
16
+ appreciated but is not required.
17
+ 2. Altered source versions must be plainly marked as such, and must not be
18
+ misrepresented as being the original software.
19
+ 3. This notice may not be removed or altered from any source distribution.
20
+ */
21
+
22
+ /**
23
+ * \file SDL_haptic.h
24
+ *
25
+ * \brief The SDL haptic subsystem allows you to control haptic (force feedback)
26
+ * devices.
27
+ *
28
+ * The basic usage is as follows:
29
+ * - Initialize the subsystem (::SDL_INIT_HAPTIC).
30
+ * - Open a haptic device.
31
+ * - SDL_HapticOpen() to open from index.
32
+ * - SDL_HapticOpenFromJoystick() to open from an existing joystick.
33
+ * - Create an effect (::SDL_HapticEffect).
34
+ * - Upload the effect with SDL_HapticNewEffect().
35
+ * - Run the effect with SDL_HapticRunEffect().
36
+ * - (optional) Free the effect with SDL_HapticDestroyEffect().
37
+ * - Close the haptic device with SDL_HapticClose().
38
+ *
39
+ * \par Simple rumble example:
40
+ * \code
41
+ * SDL_Haptic *haptic;
42
+ *
43
+ * // Open the device
44
+ * haptic = SDL_HapticOpen( 0 );
45
+ * if (haptic == NULL)
46
+ * return -1;
47
+ *
48
+ * // Initialize simple rumble
49
+ * if (SDL_HapticRumbleInit( haptic ) != 0)
50
+ * return -1;
51
+ *
52
+ * // Play effect at 50% strength for 2 seconds
53
+ * if (SDL_HapticRumblePlay( haptic, 0.5, 2000 ) != 0)
54
+ * return -1;
55
+ * SDL_Delay( 2000 );
56
+ *
57
+ * // Clean up
58
+ * SDL_HapticClose( haptic );
59
+ * \endcode
60
+ *
61
+ * \par Complete example:
62
+ * \code
63
+ * int test_haptic( SDL_Joystick * joystick ) {
64
+ * SDL_Haptic *haptic;
65
+ * SDL_HapticEffect effect;
66
+ * int effect_id;
67
+ *
68
+ * // Open the device
69
+ * haptic = SDL_HapticOpenFromJoystick( joystick );
70
+ * if (haptic == NULL) return -1; // Most likely joystick isn't haptic
71
+ *
72
+ * // See if it can do sine waves
73
+ * if ((SDL_HapticQuery(haptic) & SDL_HAPTIC_SINE)==0) {
74
+ * SDL_HapticClose(haptic); // No sine effect
75
+ * return -1;
76
+ * }
77
+ *
78
+ * // Create the effect
79
+ * SDL_memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default
80
+ * effect.type = SDL_HAPTIC_SINE;
81
+ * effect.periodic.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
82
+ * effect.periodic.direction.dir[0] = 18000; // Force comes from south
83
+ * effect.periodic.period = 1000; // 1000 ms
84
+ * effect.periodic.magnitude = 20000; // 20000/32767 strength
85
+ * effect.periodic.length = 5000; // 5 seconds long
86
+ * effect.periodic.attack_length = 1000; // Takes 1 second to get max strength
87
+ * effect.periodic.fade_length = 1000; // Takes 1 second to fade away
88
+ *
89
+ * // Upload the effect
90
+ * effect_id = SDL_HapticNewEffect( haptic, &effect );
91
+ *
92
+ * // Test the effect
93
+ * SDL_HapticRunEffect( haptic, effect_id, 1 );
94
+ * SDL_Delay( 5000); // Wait for the effect to finish
95
+ *
96
+ * // We destroy the effect, although closing the device also does this
97
+ * SDL_HapticDestroyEffect( haptic, effect_id );
98
+ *
99
+ * // Close the device
100
+ * SDL_HapticClose(haptic);
101
+ *
102
+ * return 0; // Success
103
+ * }
104
+ * \endcode
105
+ */
106
+
107
+ #ifndef SDL_haptic_h_
108
+ #define SDL_haptic_h_
109
+
110
+ #include "SDL_stdinc.h"
111
+ #include "SDL_error.h"
112
+ #include "SDL_joystick.h"
113
+
114
+ #include "begin_code.h"
115
+ /* Set up for C function definitions, even when using C++ */
116
+ #ifdef __cplusplus
117
+ extern "C" {
118
+ #endif /* __cplusplus */
119
+
120
+ /* FIXME: For SDL 2.1, adjust all the magnitude variables to be Uint16 (0xFFFF).
121
+ *
122
+ * At the moment the magnitude variables are mixed between signed/unsigned, and
123
+ * it is also not made clear that ALL of those variables expect a max of 0x7FFF.
124
+ *
125
+ * Some platforms may have higher precision than that (Linux FF, Windows XInput)
126
+ * so we should fix the inconsistency in favor of higher possible precision,
127
+ * adjusting for platforms that use different scales.
128
+ * -flibit
129
+ */
130
+
131
+ /**
132
+ * \typedef SDL_Haptic
133
+ *
134
+ * \brief The haptic structure used to identify an SDL haptic.
135
+ *
136
+ * \sa SDL_HapticOpen
137
+ * \sa SDL_HapticOpenFromJoystick
138
+ * \sa SDL_HapticClose
139
+ */
140
+ struct _SDL_Haptic;
141
+ typedef struct _SDL_Haptic SDL_Haptic;
142
+
143
+
144
+ /**
145
+ * \name Haptic features
146
+ *
147
+ * Different haptic features a device can have.
148
+ */
149
+ /* @{ */
150
+
151
+ /**
152
+ * \name Haptic effects
153
+ */
154
+ /* @{ */
155
+
156
+ /**
157
+ * \brief Constant effect supported.
158
+ *
159
+ * Constant haptic effect.
160
+ *
161
+ * \sa SDL_HapticCondition
162
+ */
163
+ #define SDL_HAPTIC_CONSTANT (1u<<0)
164
+
165
+ /**
166
+ * \brief Sine wave effect supported.
167
+ *
168
+ * Periodic haptic effect that simulates sine waves.
169
+ *
170
+ * \sa SDL_HapticPeriodic
171
+ */
172
+ #define SDL_HAPTIC_SINE (1u<<1)
173
+
174
+ /**
175
+ * \brief Left/Right effect supported.
176
+ *
177
+ * Haptic effect for direct control over high/low frequency motors.
178
+ *
179
+ * \sa SDL_HapticLeftRight
180
+ * \warning this value was SDL_HAPTIC_SQUARE right before 2.0.0 shipped. Sorry,
181
+ * we ran out of bits, and this is important for XInput devices.
182
+ */
183
+ #define SDL_HAPTIC_LEFTRIGHT (1u<<2)
184
+
185
+ /* !!! FIXME: put this back when we have more bits in 2.1 */
186
+ /* #define SDL_HAPTIC_SQUARE (1<<2) */
187
+
188
+ /**
189
+ * \brief Triangle wave effect supported.
190
+ *
191
+ * Periodic haptic effect that simulates triangular waves.
192
+ *
193
+ * \sa SDL_HapticPeriodic
194
+ */
195
+ #define SDL_HAPTIC_TRIANGLE (1u<<3)
196
+
197
+ /**
198
+ * \brief Sawtoothup wave effect supported.
199
+ *
200
+ * Periodic haptic effect that simulates saw tooth up waves.
201
+ *
202
+ * \sa SDL_HapticPeriodic
203
+ */
204
+ #define SDL_HAPTIC_SAWTOOTHUP (1u<<4)
205
+
206
+ /**
207
+ * \brief Sawtoothdown wave effect supported.
208
+ *
209
+ * Periodic haptic effect that simulates saw tooth down waves.
210
+ *
211
+ * \sa SDL_HapticPeriodic
212
+ */
213
+ #define SDL_HAPTIC_SAWTOOTHDOWN (1u<<5)
214
+
215
+ /**
216
+ * \brief Ramp effect supported.
217
+ *
218
+ * Ramp haptic effect.
219
+ *
220
+ * \sa SDL_HapticRamp
221
+ */
222
+ #define SDL_HAPTIC_RAMP (1u<<6)
223
+
224
+ /**
225
+ * \brief Spring effect supported - uses axes position.
226
+ *
227
+ * Condition haptic effect that simulates a spring. Effect is based on the
228
+ * axes position.
229
+ *
230
+ * \sa SDL_HapticCondition
231
+ */
232
+ #define SDL_HAPTIC_SPRING (1u<<7)
233
+
234
+ /**
235
+ * \brief Damper effect supported - uses axes velocity.
236
+ *
237
+ * Condition haptic effect that simulates dampening. Effect is based on the
238
+ * axes velocity.
239
+ *
240
+ * \sa SDL_HapticCondition
241
+ */
242
+ #define SDL_HAPTIC_DAMPER (1u<<8)
243
+
244
+ /**
245
+ * \brief Inertia effect supported - uses axes acceleration.
246
+ *
247
+ * Condition haptic effect that simulates inertia. Effect is based on the axes
248
+ * acceleration.
249
+ *
250
+ * \sa SDL_HapticCondition
251
+ */
252
+ #define SDL_HAPTIC_INERTIA (1u<<9)
253
+
254
+ /**
255
+ * \brief Friction effect supported - uses axes movement.
256
+ *
257
+ * Condition haptic effect that simulates friction. Effect is based on the
258
+ * axes movement.
259
+ *
260
+ * \sa SDL_HapticCondition
261
+ */
262
+ #define SDL_HAPTIC_FRICTION (1u<<10)
263
+
264
+ /**
265
+ * \brief Custom effect is supported.
266
+ *
267
+ * User defined custom haptic effect.
268
+ */
269
+ #define SDL_HAPTIC_CUSTOM (1u<<11)
270
+
271
+ /* @} *//* Haptic effects */
272
+
273
+ /* These last few are features the device has, not effects */
274
+
275
+ /**
276
+ * \brief Device can set global gain.
277
+ *
278
+ * Device supports setting the global gain.
279
+ *
280
+ * \sa SDL_HapticSetGain
281
+ */
282
+ #define SDL_HAPTIC_GAIN (1u<<12)
283
+
284
+ /**
285
+ * \brief Device can set autocenter.
286
+ *
287
+ * Device supports setting autocenter.
288
+ *
289
+ * \sa SDL_HapticSetAutocenter
290
+ */
291
+ #define SDL_HAPTIC_AUTOCENTER (1u<<13)
292
+
293
+ /**
294
+ * \brief Device can be queried for effect status.
295
+ *
296
+ * Device supports querying effect status.
297
+ *
298
+ * \sa SDL_HapticGetEffectStatus
299
+ */
300
+ #define SDL_HAPTIC_STATUS (1u<<14)
301
+
302
+ /**
303
+ * \brief Device can be paused.
304
+ *
305
+ * Devices supports being paused.
306
+ *
307
+ * \sa SDL_HapticPause
308
+ * \sa SDL_HapticUnpause
309
+ */
310
+ #define SDL_HAPTIC_PAUSE (1u<<15)
311
+
312
+
313
+ /**
314
+ * \name Direction encodings
315
+ */
316
+ /* @{ */
317
+
318
+ /**
319
+ * \brief Uses polar coordinates for the direction.
320
+ *
321
+ * \sa SDL_HapticDirection
322
+ */
323
+ #define SDL_HAPTIC_POLAR 0
324
+
325
+ /**
326
+ * \brief Uses cartesian coordinates for the direction.
327
+ *
328
+ * \sa SDL_HapticDirection
329
+ */
330
+ #define SDL_HAPTIC_CARTESIAN 1
331
+
332
+ /**
333
+ * \brief Uses spherical coordinates for the direction.
334
+ *
335
+ * \sa SDL_HapticDirection
336
+ */
337
+ #define SDL_HAPTIC_SPHERICAL 2
338
+
339
+ /**
340
+ * \brief Use this value to play an effect on the steering wheel axis. This
341
+ * provides better compatibility across platforms and devices as SDL will guess
342
+ * the correct axis.
343
+ * \sa SDL_HapticDirection
344
+ */
345
+ #define SDL_HAPTIC_STEERING_AXIS 3
346
+
347
+ /* @} *//* Direction encodings */
348
+
349
+ /* @} *//* Haptic features */
350
+
351
+ /*
352
+ * Misc defines.
353
+ */
354
+
355
+ /**
356
+ * \brief Used to play a device an infinite number of times.
357
+ *
358
+ * \sa SDL_HapticRunEffect
359
+ */
360
+ #define SDL_HAPTIC_INFINITY 4294967295U
361
+
362
+
363
+ /**
364
+ * \brief Structure that represents a haptic direction.
365
+ *
366
+ * This is the direction where the force comes from,
367
+ * instead of the direction in which the force is exerted.
368
+ *
369
+ * Directions can be specified by:
370
+ * - ::SDL_HAPTIC_POLAR : Specified by polar coordinates.
371
+ * - ::SDL_HAPTIC_CARTESIAN : Specified by cartesian coordinates.
372
+ * - ::SDL_HAPTIC_SPHERICAL : Specified by spherical coordinates.
373
+ *
374
+ * Cardinal directions of the haptic device are relative to the positioning
375
+ * of the device. North is considered to be away from the user.
376
+ *
377
+ * The following diagram represents the cardinal directions:
378
+ * \verbatim
379
+ .--.
380
+ |__| .-------.
381
+ |=.| |.-----.|
382
+ |--| || ||
383
+ | | |'-----'|
384
+ |__|~')_____('
385
+ [ COMPUTER ]
386
+
387
+
388
+ North (0,-1)
389
+ ^
390
+ |
391
+ |
392
+ (-1,0) West <----[ HAPTIC ]----> East (1,0)
393
+ |
394
+ |
395
+ v
396
+ South (0,1)
397
+
398
+
399
+ [ USER ]
400
+ \|||/
401
+ (o o)
402
+ ---ooO-(_)-Ooo---
403
+ \endverbatim
404
+ *
405
+ * If type is ::SDL_HAPTIC_POLAR, direction is encoded by hundredths of a
406
+ * degree starting north and turning clockwise. ::SDL_HAPTIC_POLAR only uses
407
+ * the first \c dir parameter. The cardinal directions would be:
408
+ * - North: 0 (0 degrees)
409
+ * - East: 9000 (90 degrees)
410
+ * - South: 18000 (180 degrees)
411
+ * - West: 27000 (270 degrees)
412
+ *
413
+ * If type is ::SDL_HAPTIC_CARTESIAN, direction is encoded by three positions
414
+ * (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses
415
+ * the first three \c dir parameters. The cardinal directions would be:
416
+ * - North: 0,-1, 0
417
+ * - East: 1, 0, 0
418
+ * - South: 0, 1, 0
419
+ * - West: -1, 0, 0
420
+ *
421
+ * The Z axis represents the height of the effect if supported, otherwise
422
+ * it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you
423
+ * can use any multiple you want, only the direction matters.
424
+ *
425
+ * If type is ::SDL_HAPTIC_SPHERICAL, direction is encoded by two rotations.
426
+ * The first two \c dir parameters are used. The \c dir parameters are as
427
+ * follows (all values are in hundredths of degrees):
428
+ * - Degrees from (1, 0) rotated towards (0, 1).
429
+ * - Degrees towards (0, 0, 1) (device needs at least 3 axes).
430
+ *
431
+ *
432
+ * Example of force coming from the south with all encodings (force coming
433
+ * from the south means the user will have to pull the stick to counteract):
434
+ * \code
435
+ * SDL_HapticDirection direction;
436
+ *
437
+ * // Cartesian directions
438
+ * direction.type = SDL_HAPTIC_CARTESIAN; // Using cartesian direction encoding.
439
+ * direction.dir[0] = 0; // X position
440
+ * direction.dir[1] = 1; // Y position
441
+ * // Assuming the device has 2 axes, we don't need to specify third parameter.
442
+ *
443
+ * // Polar directions
444
+ * direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
445
+ * direction.dir[0] = 18000; // Polar only uses first parameter
446
+ *
447
+ * // Spherical coordinates
448
+ * direction.type = SDL_HAPTIC_SPHERICAL; // Spherical encoding
449
+ * direction.dir[0] = 9000; // Since we only have two axes we don't need more parameters.
450
+ * \endcode
451
+ *
452
+ * \sa SDL_HAPTIC_POLAR
453
+ * \sa SDL_HAPTIC_CARTESIAN
454
+ * \sa SDL_HAPTIC_SPHERICAL
455
+ * \sa SDL_HAPTIC_STEERING_AXIS
456
+ * \sa SDL_HapticEffect
457
+ * \sa SDL_HapticNumAxes
458
+ */
459
+ typedef struct SDL_HapticDirection
460
+ {
461
+ Uint8 type; /**< The type of encoding. */
462
+ Sint32 dir[3]; /**< The encoded direction. */
463
+ } SDL_HapticDirection;
464
+
465
+
466
+ /**
467
+ * \brief A structure containing a template for a Constant effect.
468
+ *
469
+ * This struct is exclusively for the ::SDL_HAPTIC_CONSTANT effect.
470
+ *
471
+ * A constant effect applies a constant force in the specified direction
472
+ * to the joystick.
473
+ *
474
+ * \sa SDL_HAPTIC_CONSTANT
475
+ * \sa SDL_HapticEffect
476
+ */
477
+ typedef struct SDL_HapticConstant
478
+ {
479
+ /* Header */
480
+ Uint16 type; /**< ::SDL_HAPTIC_CONSTANT */
481
+ SDL_HapticDirection direction; /**< Direction of the effect. */
482
+
483
+ /* Replay */
484
+ Uint32 length; /**< Duration of the effect. */
485
+ Uint16 delay; /**< Delay before starting the effect. */
486
+
487
+ /* Trigger */
488
+ Uint16 button; /**< Button that triggers the effect. */
489
+ Uint16 interval; /**< How soon it can be triggered again after button. */
490
+
491
+ /* Constant */
492
+ Sint16 level; /**< Strength of the constant effect. */
493
+
494
+ /* Envelope */
495
+ Uint16 attack_length; /**< Duration of the attack. */
496
+ Uint16 attack_level; /**< Level at the start of the attack. */
497
+ Uint16 fade_length; /**< Duration of the fade. */
498
+ Uint16 fade_level; /**< Level at the end of the fade. */
499
+ } SDL_HapticConstant;
500
+
501
+ /**
502
+ * \brief A structure containing a template for a Periodic effect.
503
+ *
504
+ * The struct handles the following effects:
505
+ * - ::SDL_HAPTIC_SINE
506
+ * - ::SDL_HAPTIC_LEFTRIGHT
507
+ * - ::SDL_HAPTIC_TRIANGLE
508
+ * - ::SDL_HAPTIC_SAWTOOTHUP
509
+ * - ::SDL_HAPTIC_SAWTOOTHDOWN
510
+ *
511
+ * A periodic effect consists in a wave-shaped effect that repeats itself
512
+ * over time. The type determines the shape of the wave and the parameters
513
+ * determine the dimensions of the wave.
514
+ *
515
+ * Phase is given by hundredth of a degree meaning that giving the phase a value
516
+ * of 9000 will displace it 25% of its period. Here are sample values:
517
+ * - 0: No phase displacement.
518
+ * - 9000: Displaced 25% of its period.
519
+ * - 18000: Displaced 50% of its period.
520
+ * - 27000: Displaced 75% of its period.
521
+ * - 36000: Displaced 100% of its period, same as 0, but 0 is preferred.
522
+ *
523
+ * Examples:
524
+ * \verbatim
525
+ SDL_HAPTIC_SINE
526
+ __ __ __ __
527
+ / \ / \ / \ /
528
+ / \__/ \__/ \__/
529
+
530
+ SDL_HAPTIC_SQUARE
531
+ __ __ __ __ __
532
+ | | | | | | | | | |
533
+ | |__| |__| |__| |__| |
534
+
535
+ SDL_HAPTIC_TRIANGLE
536
+ /\ /\ /\ /\ /\
537
+ / \ / \ / \ / \ /
538
+ / \/ \/ \/ \/
539
+
540
+ SDL_HAPTIC_SAWTOOTHUP
541
+ /| /| /| /| /| /| /|
542
+ / | / | / | / | / | / | / |
543
+ / |/ |/ |/ |/ |/ |/ |
544
+
545
+ SDL_HAPTIC_SAWTOOTHDOWN
546
+ \ |\ |\ |\ |\ |\ |\ |
547
+ \ | \ | \ | \ | \ | \ | \ |
548
+ \| \| \| \| \| \| \|
549
+ \endverbatim
550
+ *
551
+ * \sa SDL_HAPTIC_SINE
552
+ * \sa SDL_HAPTIC_LEFTRIGHT
553
+ * \sa SDL_HAPTIC_TRIANGLE
554
+ * \sa SDL_HAPTIC_SAWTOOTHUP
555
+ * \sa SDL_HAPTIC_SAWTOOTHDOWN
556
+ * \sa SDL_HapticEffect
557
+ */
558
+ typedef struct SDL_HapticPeriodic
559
+ {
560
+ /* Header */
561
+ Uint16 type; /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT,
562
+ ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or
563
+ ::SDL_HAPTIC_SAWTOOTHDOWN */
564
+ SDL_HapticDirection direction; /**< Direction of the effect. */
565
+
566
+ /* Replay */
567
+ Uint32 length; /**< Duration of the effect. */
568
+ Uint16 delay; /**< Delay before starting the effect. */
569
+
570
+ /* Trigger */
571
+ Uint16 button; /**< Button that triggers the effect. */
572
+ Uint16 interval; /**< How soon it can be triggered again after button. */
573
+
574
+ /* Periodic */
575
+ Uint16 period; /**< Period of the wave. */
576
+ Sint16 magnitude; /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
577
+ Sint16 offset; /**< Mean value of the wave. */
578
+ Uint16 phase; /**< Positive phase shift given by hundredth of a degree. */
579
+
580
+ /* Envelope */
581
+ Uint16 attack_length; /**< Duration of the attack. */
582
+ Uint16 attack_level; /**< Level at the start of the attack. */
583
+ Uint16 fade_length; /**< Duration of the fade. */
584
+ Uint16 fade_level; /**< Level at the end of the fade. */
585
+ } SDL_HapticPeriodic;
586
+
587
+ /**
588
+ * \brief A structure containing a template for a Condition effect.
589
+ *
590
+ * The struct handles the following effects:
591
+ * - ::SDL_HAPTIC_SPRING: Effect based on axes position.
592
+ * - ::SDL_HAPTIC_DAMPER: Effect based on axes velocity.
593
+ * - ::SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
594
+ * - ::SDL_HAPTIC_FRICTION: Effect based on axes movement.
595
+ *
596
+ * Direction is handled by condition internals instead of a direction member.
597
+ * The condition effect specific members have three parameters. The first
598
+ * refers to the X axis, the second refers to the Y axis and the third
599
+ * refers to the Z axis. The right terms refer to the positive side of the
600
+ * axis and the left terms refer to the negative side of the axis. Please
601
+ * refer to the ::SDL_HapticDirection diagram for which side is positive and
602
+ * which is negative.
603
+ *
604
+ * \sa SDL_HapticDirection
605
+ * \sa SDL_HAPTIC_SPRING
606
+ * \sa SDL_HAPTIC_DAMPER
607
+ * \sa SDL_HAPTIC_INERTIA
608
+ * \sa SDL_HAPTIC_FRICTION
609
+ * \sa SDL_HapticEffect
610
+ */
611
+ typedef struct SDL_HapticCondition
612
+ {
613
+ /* Header */
614
+ Uint16 type; /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,
615
+ ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */
616
+ SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
617
+
618
+ /* Replay */
619
+ Uint32 length; /**< Duration of the effect. */
620
+ Uint16 delay; /**< Delay before starting the effect. */
621
+
622
+ /* Trigger */
623
+ Uint16 button; /**< Button that triggers the effect. */
624
+ Uint16 interval; /**< How soon it can be triggered again after button. */
625
+
626
+ /* Condition */
627
+ Uint16 right_sat[3]; /**< Level when joystick is to the positive side; max 0xFFFF. */
628
+ Uint16 left_sat[3]; /**< Level when joystick is to the negative side; max 0xFFFF. */
629
+ Sint16 right_coeff[3]; /**< How fast to increase the force towards the positive side. */
630
+ Sint16 left_coeff[3]; /**< How fast to increase the force towards the negative side. */
631
+ Uint16 deadband[3]; /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
632
+ Sint16 center[3]; /**< Position of the dead zone. */
633
+ } SDL_HapticCondition;
634
+
635
+ /**
636
+ * \brief A structure containing a template for a Ramp effect.
637
+ *
638
+ * This struct is exclusively for the ::SDL_HAPTIC_RAMP effect.
639
+ *
640
+ * The ramp effect starts at start strength and ends at end strength.
641
+ * It augments in linear fashion. If you use attack and fade with a ramp
642
+ * the effects get added to the ramp effect making the effect become
643
+ * quadratic instead of linear.
644
+ *
645
+ * \sa SDL_HAPTIC_RAMP
646
+ * \sa SDL_HapticEffect
647
+ */
648
+ typedef struct SDL_HapticRamp
649
+ {
650
+ /* Header */
651
+ Uint16 type; /**< ::SDL_HAPTIC_RAMP */
652
+ SDL_HapticDirection direction; /**< Direction of the effect. */
653
+
654
+ /* Replay */
655
+ Uint32 length; /**< Duration of the effect. */
656
+ Uint16 delay; /**< Delay before starting the effect. */
657
+
658
+ /* Trigger */
659
+ Uint16 button; /**< Button that triggers the effect. */
660
+ Uint16 interval; /**< How soon it can be triggered again after button. */
661
+
662
+ /* Ramp */
663
+ Sint16 start; /**< Beginning strength level. */
664
+ Sint16 end; /**< Ending strength level. */
665
+
666
+ /* Envelope */
667
+ Uint16 attack_length; /**< Duration of the attack. */
668
+ Uint16 attack_level; /**< Level at the start of the attack. */
669
+ Uint16 fade_length; /**< Duration of the fade. */
670
+ Uint16 fade_level; /**< Level at the end of the fade. */
671
+ } SDL_HapticRamp;
672
+
673
+ /**
674
+ * \brief A structure containing a template for a Left/Right effect.
675
+ *
676
+ * This struct is exclusively for the ::SDL_HAPTIC_LEFTRIGHT effect.
677
+ *
678
+ * The Left/Right effect is used to explicitly control the large and small
679
+ * motors, commonly found in modern game controllers. The small (right) motor
680
+ * is high frequency, and the large (left) motor is low frequency.
681
+ *
682
+ * \sa SDL_HAPTIC_LEFTRIGHT
683
+ * \sa SDL_HapticEffect
684
+ */
685
+ typedef struct SDL_HapticLeftRight
686
+ {
687
+ /* Header */
688
+ Uint16 type; /**< ::SDL_HAPTIC_LEFTRIGHT */
689
+
690
+ /* Replay */
691
+ Uint32 length; /**< Duration of the effect in milliseconds. */
692
+
693
+ /* Rumble */
694
+ Uint16 large_magnitude; /**< Control of the large controller motor. */
695
+ Uint16 small_magnitude; /**< Control of the small controller motor. */
696
+ } SDL_HapticLeftRight;
697
+
698
+ /**
699
+ * \brief A structure containing a template for the ::SDL_HAPTIC_CUSTOM effect.
700
+ *
701
+ * This struct is exclusively for the ::SDL_HAPTIC_CUSTOM effect.
702
+ *
703
+ * A custom force feedback effect is much like a periodic effect, where the
704
+ * application can define its exact shape. You will have to allocate the
705
+ * data yourself. Data should consist of channels * samples Uint16 samples.
706
+ *
707
+ * If channels is one, the effect is rotated using the defined direction.
708
+ * Otherwise it uses the samples in data for the different axes.
709
+ *
710
+ * \sa SDL_HAPTIC_CUSTOM
711
+ * \sa SDL_HapticEffect
712
+ */
713
+ typedef struct SDL_HapticCustom
714
+ {
715
+ /* Header */
716
+ Uint16 type; /**< ::SDL_HAPTIC_CUSTOM */
717
+ SDL_HapticDirection direction; /**< Direction of the effect. */
718
+
719
+ /* Replay */
720
+ Uint32 length; /**< Duration of the effect. */
721
+ Uint16 delay; /**< Delay before starting the effect. */
722
+
723
+ /* Trigger */
724
+ Uint16 button; /**< Button that triggers the effect. */
725
+ Uint16 interval; /**< How soon it can be triggered again after button. */
726
+
727
+ /* Custom */
728
+ Uint8 channels; /**< Axes to use, minimum of one. */
729
+ Uint16 period; /**< Sample periods. */
730
+ Uint16 samples; /**< Amount of samples. */
731
+ Uint16 *data; /**< Should contain channels*samples items. */
732
+
733
+ /* Envelope */
734
+ Uint16 attack_length; /**< Duration of the attack. */
735
+ Uint16 attack_level; /**< Level at the start of the attack. */
736
+ Uint16 fade_length; /**< Duration of the fade. */
737
+ Uint16 fade_level; /**< Level at the end of the fade. */
738
+ } SDL_HapticCustom;
739
+
740
+ /**
741
+ * \brief The generic template for any haptic effect.
742
+ *
743
+ * All values max at 32767 (0x7FFF). Signed values also can be negative.
744
+ * Time values unless specified otherwise are in milliseconds.
745
+ *
746
+ * You can also pass ::SDL_HAPTIC_INFINITY to length instead of a 0-32767
747
+ * value. Neither delay, interval, attack_length nor fade_length support
748
+ * ::SDL_HAPTIC_INFINITY. Fade will also not be used since effect never ends.
749
+ *
750
+ * Additionally, the ::SDL_HAPTIC_RAMP effect does not support a duration of
751
+ * ::SDL_HAPTIC_INFINITY.
752
+ *
753
+ * Button triggers may not be supported on all devices, it is advised to not
754
+ * use them if possible. Buttons start at index 1 instead of index 0 like
755
+ * the joystick.
756
+ *
757
+ * If both attack_length and fade_level are 0, the envelope is not used,
758
+ * otherwise both values are used.
759
+ *
760
+ * Common parts:
761
+ * \code
762
+ * // Replay - All effects have this
763
+ * Uint32 length; // Duration of effect (ms).
764
+ * Uint16 delay; // Delay before starting effect.
765
+ *
766
+ * // Trigger - All effects have this
767
+ * Uint16 button; // Button that triggers effect.
768
+ * Uint16 interval; // How soon before effect can be triggered again.
769
+ *
770
+ * // Envelope - All effects except condition effects have this
771
+ * Uint16 attack_length; // Duration of the attack (ms).
772
+ * Uint16 attack_level; // Level at the start of the attack.
773
+ * Uint16 fade_length; // Duration of the fade out (ms).
774
+ * Uint16 fade_level; // Level at the end of the fade.
775
+ * \endcode
776
+ *
777
+ *
778
+ * Here we have an example of a constant effect evolution in time:
779
+ * \verbatim
780
+ Strength
781
+ ^
782
+ |
783
+ | effect level --> _________________
784
+ | / \
785
+ | / \
786
+ | / \
787
+ | / \
788
+ | attack_level --> | \
789
+ | | | <--- fade_level
790
+ |
791
+ +--------------------------------------------------> Time
792
+ [--] [---]
793
+ attack_length fade_length
794
+
795
+ [------------------][-----------------------]
796
+ delay length
797
+ \endverbatim
798
+ *
799
+ * Note either the attack_level or the fade_level may be above the actual
800
+ * effect level.
801
+ *
802
+ * \sa SDL_HapticConstant
803
+ * \sa SDL_HapticPeriodic
804
+ * \sa SDL_HapticCondition
805
+ * \sa SDL_HapticRamp
806
+ * \sa SDL_HapticLeftRight
807
+ * \sa SDL_HapticCustom
808
+ */
809
+ typedef union SDL_HapticEffect
810
+ {
811
+ /* Common for all force feedback effects */
812
+ Uint16 type; /**< Effect type. */
813
+ SDL_HapticConstant constant; /**< Constant effect. */
814
+ SDL_HapticPeriodic periodic; /**< Periodic effect. */
815
+ SDL_HapticCondition condition; /**< Condition effect. */
816
+ SDL_HapticRamp ramp; /**< Ramp effect. */
817
+ SDL_HapticLeftRight leftright; /**< Left/Right effect. */
818
+ SDL_HapticCustom custom; /**< Custom effect. */
819
+ } SDL_HapticEffect;
820
+
821
+
822
+ /* Function prototypes */
823
+
824
+ /**
825
+ * Count the number of haptic devices attached to the system.
826
+ *
827
+ * \returns the number of haptic devices detected on the system or a negative
828
+ * error code on failure; call SDL_GetError() for more information.
829
+ *
830
+ * \since This function is available since SDL 2.0.0.
831
+ *
832
+ * \sa SDL_HapticName
833
+ */
834
+ extern DECLSPEC int SDLCALL SDL_NumHaptics(void);
835
+
836
+ /**
837
+ * Get the implementation dependent name of a haptic device.
838
+ *
839
+ * This can be called before any joysticks are opened. If no name can be
840
+ * found, this function returns NULL.
841
+ *
842
+ * \param device_index index of the device to query.
843
+ * \returns the name of the device or NULL on failure; call SDL_GetError() for
844
+ * more information.
845
+ *
846
+ * \since This function is available since SDL 2.0.0.
847
+ *
848
+ * \sa SDL_NumHaptics
849
+ */
850
+ extern DECLSPEC const char *SDLCALL SDL_HapticName(int device_index);
851
+
852
+ /**
853
+ * Open a haptic device for use.
854
+ *
855
+ * The index passed as an argument refers to the N'th haptic device on this
856
+ * system.
857
+ *
858
+ * When opening a haptic device, its gain will be set to maximum and
859
+ * autocenter will be disabled. To modify these values use SDL_HapticSetGain()
860
+ * and SDL_HapticSetAutocenter().
861
+ *
862
+ * \param device_index index of the device to open
863
+ * \returns the device identifier or NULL on failure; call SDL_GetError() for
864
+ * more information.
865
+ *
866
+ * \since This function is available since SDL 2.0.0.
867
+ *
868
+ * \sa SDL_HapticClose
869
+ * \sa SDL_HapticIndex
870
+ * \sa SDL_HapticOpenFromJoystick
871
+ * \sa SDL_HapticOpenFromMouse
872
+ * \sa SDL_HapticPause
873
+ * \sa SDL_HapticSetAutocenter
874
+ * \sa SDL_HapticSetGain
875
+ * \sa SDL_HapticStopAll
876
+ */
877
+ extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpen(int device_index);
878
+
879
+ /**
880
+ * Check if the haptic device at the designated index has been opened.
881
+ *
882
+ * \param device_index the index of the device to query
883
+ * \returns 1 if it has been opened, 0 if it hasn't or on failure; call
884
+ * SDL_GetError() for more information.
885
+ *
886
+ * \since This function is available since SDL 2.0.0.
887
+ *
888
+ * \sa SDL_HapticIndex
889
+ * \sa SDL_HapticOpen
890
+ */
891
+ extern DECLSPEC int SDLCALL SDL_HapticOpened(int device_index);
892
+
893
+ /**
894
+ * Get the index of a haptic device.
895
+ *
896
+ * \param haptic the SDL_Haptic device to query
897
+ * \returns the index of the specified haptic device or a negative error code
898
+ * on failure; call SDL_GetError() for more information.
899
+ *
900
+ * \since This function is available since SDL 2.0.0.
901
+ *
902
+ * \sa SDL_HapticOpen
903
+ * \sa SDL_HapticOpened
904
+ */
905
+ extern DECLSPEC int SDLCALL SDL_HapticIndex(SDL_Haptic * haptic);
906
+
907
+ /**
908
+ * Query whether or not the current mouse has haptic capabilities.
909
+ *
910
+ * \returns SDL_TRUE if the mouse is haptic or SDL_FALSE if it isn't.
911
+ *
912
+ * \since This function is available since SDL 2.0.0.
913
+ *
914
+ * \sa SDL_HapticOpenFromMouse
915
+ */
916
+ extern DECLSPEC int SDLCALL SDL_MouseIsHaptic(void);
917
+
918
+ /**
919
+ * Try to open a haptic device from the current mouse.
920
+ *
921
+ * \returns the haptic device identifier or NULL on failure; call
922
+ * SDL_GetError() for more information.
923
+ *
924
+ * \since This function is available since SDL 2.0.0.
925
+ *
926
+ * \sa SDL_HapticOpen
927
+ * \sa SDL_MouseIsHaptic
928
+ */
929
+ extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromMouse(void);
930
+
931
+ /**
932
+ * Query if a joystick has haptic features.
933
+ *
934
+ * \param joystick the SDL_Joystick to test for haptic capabilities
935
+ * \returns SDL_TRUE if the joystick is haptic, SDL_FALSE if it isn't, or a
936
+ * negative error code on failure; call SDL_GetError() for more
937
+ * information.
938
+ *
939
+ * \since This function is available since SDL 2.0.0.
940
+ *
941
+ * \sa SDL_HapticOpenFromJoystick
942
+ */
943
+ extern DECLSPEC int SDLCALL SDL_JoystickIsHaptic(SDL_Joystick * joystick);
944
+
945
+ /**
946
+ * Open a haptic device for use from a joystick device.
947
+ *
948
+ * You must still close the haptic device separately. It will not be closed
949
+ * with the joystick.
950
+ *
951
+ * When opened from a joystick you should first close the haptic device before
952
+ * closing the joystick device. If not, on some implementations the haptic
953
+ * device will also get unallocated and you'll be unable to use force feedback
954
+ * on that device.
955
+ *
956
+ * \param joystick the SDL_Joystick to create a haptic device from
957
+ * \returns a valid haptic device identifier on success or NULL on failure;
958
+ * call SDL_GetError() for more information.
959
+ *
960
+ * \since This function is available since SDL 2.0.0.
961
+ *
962
+ * \sa SDL_HapticClose
963
+ * \sa SDL_HapticOpen
964
+ * \sa SDL_JoystickIsHaptic
965
+ */
966
+ extern DECLSPEC SDL_Haptic *SDLCALL SDL_HapticOpenFromJoystick(SDL_Joystick *
967
+ joystick);
968
+
969
+ /**
970
+ * Close a haptic device previously opened with SDL_HapticOpen().
971
+ *
972
+ * \param haptic the SDL_Haptic device to close
973
+ *
974
+ * \since This function is available since SDL 2.0.0.
975
+ *
976
+ * \sa SDL_HapticOpen
977
+ */
978
+ extern DECLSPEC void SDLCALL SDL_HapticClose(SDL_Haptic * haptic);
979
+
980
+ /**
981
+ * Get the number of effects a haptic device can store.
982
+ *
983
+ * On some platforms this isn't fully supported, and therefore is an
984
+ * approximation. Always check to see if your created effect was actually
985
+ * created and do not rely solely on SDL_HapticNumEffects().
986
+ *
987
+ * \param haptic the SDL_Haptic device to query
988
+ * \returns the number of effects the haptic device can store or a negative
989
+ * error code on failure; call SDL_GetError() for more information.
990
+ *
991
+ * \since This function is available since SDL 2.0.0.
992
+ *
993
+ * \sa SDL_HapticNumEffectsPlaying
994
+ * \sa SDL_HapticQuery
995
+ */
996
+ extern DECLSPEC int SDLCALL SDL_HapticNumEffects(SDL_Haptic * haptic);
997
+
998
+ /**
999
+ * Get the number of effects a haptic device can play at the same time.
1000
+ *
1001
+ * This is not supported on all platforms, but will always return a value.
1002
+ *
1003
+ * \param haptic the SDL_Haptic device to query maximum playing effects
1004
+ * \returns the number of effects the haptic device can play at the same time
1005
+ * or a negative error code on failure; call SDL_GetError() for more
1006
+ * information.
1007
+ *
1008
+ * \since This function is available since SDL 2.0.0.
1009
+ *
1010
+ * \sa SDL_HapticNumEffects
1011
+ * \sa SDL_HapticQuery
1012
+ */
1013
+ extern DECLSPEC int SDLCALL SDL_HapticNumEffectsPlaying(SDL_Haptic * haptic);
1014
+
1015
+ /**
1016
+ * Get the haptic device's supported features in bitwise manner.
1017
+ *
1018
+ * \param haptic the SDL_Haptic device to query
1019
+ * \returns a list of supported haptic features in bitwise manner (OR'd), or 0
1020
+ * on failure; call SDL_GetError() for more information.
1021
+ *
1022
+ * \since This function is available since SDL 2.0.0.
1023
+ *
1024
+ * \sa SDL_HapticEffectSupported
1025
+ * \sa SDL_HapticNumEffects
1026
+ */
1027
+ extern DECLSPEC unsigned int SDLCALL SDL_HapticQuery(SDL_Haptic * haptic);
1028
+
1029
+
1030
+ /**
1031
+ * Get the number of haptic axes the device has.
1032
+ *
1033
+ * The number of haptic axes might be useful if working with the
1034
+ * SDL_HapticDirection effect.
1035
+ *
1036
+ * \param haptic the SDL_Haptic device to query
1037
+ * \returns the number of axes on success or a negative error code on failure;
1038
+ * call SDL_GetError() for more information.
1039
+ *
1040
+ * \since This function is available since SDL 2.0.0.
1041
+ */
1042
+ extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
1043
+
1044
+ /**
1045
+ * Check to see if an effect is supported by a haptic device.
1046
+ *
1047
+ * \param haptic the SDL_Haptic device to query
1048
+ * \param effect the desired effect to query
1049
+ * \returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't, or a
1050
+ * negative error code on failure; call SDL_GetError() for more
1051
+ * information.
1052
+ *
1053
+ * \since This function is available since SDL 2.0.0.
1054
+ *
1055
+ * \sa SDL_HapticNewEffect
1056
+ * \sa SDL_HapticQuery
1057
+ */
1058
+ extern DECLSPEC int SDLCALL SDL_HapticEffectSupported(SDL_Haptic * haptic,
1059
+ SDL_HapticEffect *
1060
+ effect);
1061
+
1062
+ /**
1063
+ * Create a new haptic effect on a specified device.
1064
+ *
1065
+ * \param haptic an SDL_Haptic device to create the effect on
1066
+ * \param effect an SDL_HapticEffect structure containing the properties of
1067
+ * the effect to create
1068
+ * \returns the ID of the effect on success or a negative error code on
1069
+ * failure; call SDL_GetError() for more information.
1070
+ *
1071
+ * \since This function is available since SDL 2.0.0.
1072
+ *
1073
+ * \sa SDL_HapticDestroyEffect
1074
+ * \sa SDL_HapticRunEffect
1075
+ * \sa SDL_HapticUpdateEffect
1076
+ */
1077
+ extern DECLSPEC int SDLCALL SDL_HapticNewEffect(SDL_Haptic * haptic,
1078
+ SDL_HapticEffect * effect);
1079
+
1080
+ /**
1081
+ * Update the properties of an effect.
1082
+ *
1083
+ * Can be used dynamically, although behavior when dynamically changing
1084
+ * direction may be strange. Specifically the effect may re-upload itself and
1085
+ * start playing from the start. You also cannot change the type either when
1086
+ * running SDL_HapticUpdateEffect().
1087
+ *
1088
+ * \param haptic the SDL_Haptic device that has the effect
1089
+ * \param effect the identifier of the effect to update
1090
+ * \param data an SDL_HapticEffect structure containing the new effect
1091
+ * properties to use
1092
+ * \returns 0 on success or a negative error code on failure; call
1093
+ * SDL_GetError() for more information.
1094
+ *
1095
+ * \since This function is available since SDL 2.0.0.
1096
+ *
1097
+ * \sa SDL_HapticDestroyEffect
1098
+ * \sa SDL_HapticNewEffect
1099
+ * \sa SDL_HapticRunEffect
1100
+ */
1101
+ extern DECLSPEC int SDLCALL SDL_HapticUpdateEffect(SDL_Haptic * haptic,
1102
+ int effect,
1103
+ SDL_HapticEffect * data);
1104
+
1105
+ /**
1106
+ * Run the haptic effect on its associated haptic device.
1107
+ *
1108
+ * To repeat the effect over and over indefinitely, set `iterations` to
1109
+ * `SDL_HAPTIC_INFINITY`. (Repeats the envelope - attack and fade.) To make
1110
+ * one instance of the effect last indefinitely (so the effect does not fade),
1111
+ * set the effect's `length` in its structure/union to `SDL_HAPTIC_INFINITY`
1112
+ * instead.
1113
+ *
1114
+ * \param haptic the SDL_Haptic device to run the effect on
1115
+ * \param effect the ID of the haptic effect to run
1116
+ * \param iterations the number of iterations to run the effect; use
1117
+ * `SDL_HAPTIC_INFINITY` to repeat forever
1118
+ * \returns 0 on success or a negative error code on failure; call
1119
+ * SDL_GetError() for more information.
1120
+ *
1121
+ * \since This function is available since SDL 2.0.0.
1122
+ *
1123
+ * \sa SDL_HapticDestroyEffect
1124
+ * \sa SDL_HapticGetEffectStatus
1125
+ * \sa SDL_HapticStopEffect
1126
+ */
1127
+ extern DECLSPEC int SDLCALL SDL_HapticRunEffect(SDL_Haptic * haptic,
1128
+ int effect,
1129
+ Uint32 iterations);
1130
+
1131
+ /**
1132
+ * Stop the haptic effect on its associated haptic device.
1133
+ *
1134
+ * *
1135
+ *
1136
+ * \param haptic the SDL_Haptic device to stop the effect on
1137
+ * \param effect the ID of the haptic effect to stop
1138
+ * \returns 0 on success or a negative error code on failure; call
1139
+ * SDL_GetError() for more information.
1140
+ *
1141
+ * \since This function is available since SDL 2.0.0.
1142
+ *
1143
+ * \sa SDL_HapticDestroyEffect
1144
+ * \sa SDL_HapticRunEffect
1145
+ */
1146
+ extern DECLSPEC int SDLCALL SDL_HapticStopEffect(SDL_Haptic * haptic,
1147
+ int effect);
1148
+
1149
+ /**
1150
+ * Destroy a haptic effect on the device.
1151
+ *
1152
+ * This will stop the effect if it's running. Effects are automatically
1153
+ * destroyed when the device is closed.
1154
+ *
1155
+ * \param haptic the SDL_Haptic device to destroy the effect on
1156
+ * \param effect the ID of the haptic effect to destroy
1157
+ *
1158
+ * \since This function is available since SDL 2.0.0.
1159
+ *
1160
+ * \sa SDL_HapticNewEffect
1161
+ */
1162
+ extern DECLSPEC void SDLCALL SDL_HapticDestroyEffect(SDL_Haptic * haptic,
1163
+ int effect);
1164
+
1165
+ /**
1166
+ * Get the status of the current effect on the specified haptic device.
1167
+ *
1168
+ * Device must support the SDL_HAPTIC_STATUS feature.
1169
+ *
1170
+ * \param haptic the SDL_Haptic device to query for the effect status on
1171
+ * \param effect the ID of the haptic effect to query its status
1172
+ * \returns 0 if it isn't playing, 1 if it is playing, or a negative error
1173
+ * code on failure; call SDL_GetError() for more information.
1174
+ *
1175
+ * \since This function is available since SDL 2.0.0.
1176
+ *
1177
+ * \sa SDL_HapticRunEffect
1178
+ * \sa SDL_HapticStopEffect
1179
+ */
1180
+ extern DECLSPEC int SDLCALL SDL_HapticGetEffectStatus(SDL_Haptic * haptic,
1181
+ int effect);
1182
+
1183
+ /**
1184
+ * Set the global gain of the specified haptic device.
1185
+ *
1186
+ * Device must support the SDL_HAPTIC_GAIN feature.
1187
+ *
1188
+ * The user may specify the maximum gain by setting the environment variable
1189
+ * `SDL_HAPTIC_GAIN_MAX` which should be between 0 and 100. All calls to
1190
+ * SDL_HapticSetGain() will scale linearly using `SDL_HAPTIC_GAIN_MAX` as the
1191
+ * maximum.
1192
+ *
1193
+ * \param haptic the SDL_Haptic device to set the gain on
1194
+ * \param gain value to set the gain to, should be between 0 and 100 (0 - 100)
1195
+ * \returns 0 on success or a negative error code on failure; call
1196
+ * SDL_GetError() for more information.
1197
+ *
1198
+ * \since This function is available since SDL 2.0.0.
1199
+ *
1200
+ * \sa SDL_HapticQuery
1201
+ */
1202
+ extern DECLSPEC int SDLCALL SDL_HapticSetGain(SDL_Haptic * haptic, int gain);
1203
+
1204
+ /**
1205
+ * Set the global autocenter of the device.
1206
+ *
1207
+ * Autocenter should be between 0 and 100. Setting it to 0 will disable
1208
+ * autocentering.
1209
+ *
1210
+ * Device must support the SDL_HAPTIC_AUTOCENTER feature.
1211
+ *
1212
+ * \param haptic the SDL_Haptic device to set autocentering on
1213
+ * \param autocenter value to set autocenter to (0-100)
1214
+ * \returns 0 on success or a negative error code on failure; call
1215
+ * SDL_GetError() for more information.
1216
+ *
1217
+ * \since This function is available since SDL 2.0.0.
1218
+ *
1219
+ * \sa SDL_HapticQuery
1220
+ */
1221
+ extern DECLSPEC int SDLCALL SDL_HapticSetAutocenter(SDL_Haptic * haptic,
1222
+ int autocenter);
1223
+
1224
+ /**
1225
+ * Pause a haptic device.
1226
+ *
1227
+ * Device must support the `SDL_HAPTIC_PAUSE` feature. Call
1228
+ * SDL_HapticUnpause() to resume playback.
1229
+ *
1230
+ * Do not modify the effects nor add new ones while the device is paused. That
1231
+ * can cause all sorts of weird errors.
1232
+ *
1233
+ * \param haptic the SDL_Haptic device to pause
1234
+ * \returns 0 on success or a negative error code on failure; call
1235
+ * SDL_GetError() for more information.
1236
+ *
1237
+ * \since This function is available since SDL 2.0.0.
1238
+ *
1239
+ * \sa SDL_HapticUnpause
1240
+ */
1241
+ extern DECLSPEC int SDLCALL SDL_HapticPause(SDL_Haptic * haptic);
1242
+
1243
+ /**
1244
+ * Unpause a haptic device.
1245
+ *
1246
+ * Call to unpause after SDL_HapticPause().
1247
+ *
1248
+ * \param haptic the SDL_Haptic device to unpause
1249
+ * \returns 0 on success or a negative error code on failure; call
1250
+ * SDL_GetError() for more information.
1251
+ *
1252
+ * \since This function is available since SDL 2.0.0.
1253
+ *
1254
+ * \sa SDL_HapticPause
1255
+ */
1256
+ extern DECLSPEC int SDLCALL SDL_HapticUnpause(SDL_Haptic * haptic);
1257
+
1258
+ /**
1259
+ * Stop all the currently playing effects on a haptic device.
1260
+ *
1261
+ * \param haptic the SDL_Haptic device to stop
1262
+ * \returns 0 on success or a negative error code on failure; call
1263
+ * SDL_GetError() for more information.
1264
+ *
1265
+ * \since This function is available since SDL 2.0.0.
1266
+ */
1267
+ extern DECLSPEC int SDLCALL SDL_HapticStopAll(SDL_Haptic * haptic);
1268
+
1269
+ /**
1270
+ * Check whether rumble is supported on a haptic device.
1271
+ *
1272
+ * \param haptic haptic device to check for rumble support
1273
+ * \returns SDL_TRUE if effect is supported, SDL_FALSE if it isn't, or a
1274
+ * negative error code on failure; call SDL_GetError() for more
1275
+ * information.
1276
+ *
1277
+ * \since This function is available since SDL 2.0.0.
1278
+ *
1279
+ * \sa SDL_HapticRumbleInit
1280
+ * \sa SDL_HapticRumblePlay
1281
+ * \sa SDL_HapticRumbleStop
1282
+ */
1283
+ extern DECLSPEC int SDLCALL SDL_HapticRumbleSupported(SDL_Haptic * haptic);
1284
+
1285
+ /**
1286
+ * Initialize a haptic device for simple rumble playback.
1287
+ *
1288
+ * \param haptic the haptic device to initialize for simple rumble playback
1289
+ * \returns 0 on success or a negative error code on failure; call
1290
+ * SDL_GetError() for more information.
1291
+ *
1292
+ * \since This function is available since SDL 2.0.0.
1293
+ *
1294
+ * \sa SDL_HapticOpen
1295
+ * \sa SDL_HapticRumblePlay
1296
+ * \sa SDL_HapticRumbleStop
1297
+ * \sa SDL_HapticRumbleSupported
1298
+ */
1299
+ extern DECLSPEC int SDLCALL SDL_HapticRumbleInit(SDL_Haptic * haptic);
1300
+
1301
+ /**
1302
+ * Run a simple rumble effect on a haptic device.
1303
+ *
1304
+ * \param haptic the haptic device to play the rumble effect on
1305
+ * \param strength strength of the rumble to play as a 0-1 float value
1306
+ * \param length length of the rumble to play in milliseconds
1307
+ * \returns 0 on success or a negative error code on failure; call
1308
+ * SDL_GetError() for more information.
1309
+ *
1310
+ * \since This function is available since SDL 2.0.0.
1311
+ *
1312
+ * \sa SDL_HapticRumbleInit
1313
+ * \sa SDL_HapticRumbleStop
1314
+ * \sa SDL_HapticRumbleSupported
1315
+ */
1316
+ extern DECLSPEC int SDLCALL SDL_HapticRumblePlay(SDL_Haptic * haptic, float strength, Uint32 length );
1317
+
1318
+ /**
1319
+ * Stop the simple rumble on a haptic device.
1320
+ *
1321
+ * \param haptic the haptic device to stop the rumble effect on
1322
+ * \returns 0 on success or a negative error code on failure; call
1323
+ * SDL_GetError() for more information.
1324
+ *
1325
+ * \since This function is available since SDL 2.0.0.
1326
+ *
1327
+ * \sa SDL_HapticRumbleInit
1328
+ * \sa SDL_HapticRumblePlay
1329
+ * \sa SDL_HapticRumbleSupported
1330
+ */
1331
+ extern DECLSPEC int SDLCALL SDL_HapticRumbleStop(SDL_Haptic * haptic);
1332
+
1333
+ /* Ends C function definitions when using C++ */
1334
+ #ifdef __cplusplus
1335
+ }
1336
+ #endif
1337
+ #include "close_code.h"
1338
+
1339
+ #endif /* SDL_haptic_h_ */
1340
+
1341
+ /* vi: set ts=4 sw=4 expandtab: */