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