2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on the
13 #include "osregistry.h"
18 static int Joy_ff_enabled = 0;
19 static SDL_Haptic *haptic = NULL;
20 static int joy_ff_handling_scaler = 0;
21 static int Joy_ff_directional_hit_effect_enabled = 1;
22 static int Joy_rumble = 0;
30 static haptic_effect_t pHitEffect1;
31 static haptic_effect_t pHitEffect2;
32 static haptic_effect_t pAfterburn1;
33 static haptic_effect_t pAfterburn2;
34 static haptic_effect_t pShootEffect;
35 static haptic_effect_t pSecShootEffect;
36 static haptic_effect_t pSpring;
37 static haptic_effect_t pDock;
38 //static haptic_effect_t pDeathroll1;
39 //static haptic_effect_t pDeathroll2;
40 //static haptic_effect_t pExplode;
42 static void joy_ff_create_effects();
43 static int joy_ff_effect_playing(haptic_effect_t *eff);
44 static void joy_ff_start_effect(haptic_effect_t *eff, const char *name);
46 extern SDL_Joystick *sdljoy;
53 ff_enabled = os_config_read_uint(NULL, "EnableJoystickFF", 1);
59 // mprintf(("Initializing Haptic...\n"));
61 if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) {
65 if ( !SDL_JoystickIsHaptic(sdljoy) ) {
66 SDL_QuitSubSystem(SDL_INIT_HAPTIC);
70 haptic = SDL_HapticOpenFromJoystick(sdljoy);
73 mprintf(("ERROR: Unable to open haptic joystick\n"));
74 SDL_QuitSubSystem(SDL_INIT_HAPTIC);
78 if ( SDL_HapticRumbleSupported(haptic) ) {
79 SDL_HapticRumbleInit(haptic);
83 mprintf(("Haptic device:\n"));
84 mprintf((" Rumble: %s\n", Joy_rumble ? "Yes" : "No"));
85 mprintf((" Axes: %d\n", SDL_HapticNumAxes(haptic)));
86 mprintf((" Max effects: %d\n", SDL_HapticNumEffects(haptic)));
87 mprintf((" Simultaneous effects: %d\n", SDL_HapticNumEffectsPlaying(haptic)));
89 joy_ff_create_effects();
95 Joy_ff_directional_hit_effect_enabled = os_config_read_uint(NULL, "EnableHitEffect", 1);
100 void joy_ff_shutdown()
102 if ( !Joy_ff_enabled ) {
108 SDL_HapticClose(haptic);
111 SDL_QuitSubSystem(SDL_INIT_HAPTIC);
116 static void joy_ff_create_effects()
118 // clear all SDL errors
121 unsigned int supported = 0;
123 supported = SDL_HapticQuery(haptic);
125 if ( !(supported & SDL_HAPTIC_CONSTANT) ) {
126 mprintf((" Constant Force: not supported\n"));
129 if ( !(supported & SDL_HAPTIC_SINE) ) {
130 mprintf((" Sine Wave: not supported\n"));
131 Warning(LOCATION, "Sine Wave: not supported");
134 if ( !(supported & SDL_HAPTIC_SAWTOOTHDOWN) ) {
135 mprintf((" Sawtooth Down: not supported\n"));
138 if ( !(supported & SDL_HAPTIC_SPRING) ) {
139 mprintf((" Spring: not supported\n"));
140 // Error(LOCATION, "Spring: not supported");
143 if ( !(supported & SDL_HAPTIC_SQUARE) ) {
144 mprintf((" Square: not supported\n"));
147 if ( !(supported & SDL_HAPTIC_TRIANGLE) ) {
148 mprintf((" Triangle: not supported\n"));
152 if (supported & SDL_HAPTIC_CONSTANT) {
154 memset(&pHitEffect1, 0, sizeof(haptic_effect_t));
156 pHitEffect1.eff.type = SDL_HAPTIC_CONSTANT;
157 pHitEffect1.eff.constant.direction.type = SDL_HAPTIC_POLAR;
158 pHitEffect1.eff.constant.direction.dir[0] = 0;
159 pHitEffect1.eff.constant.length = 300;
160 pHitEffect1.eff.constant.level = 0x7FFF;
161 pHitEffect1.eff.constant.attack_length = 0;
162 pHitEffect1.eff.constant.attack_level = 0x7FFF;
163 pHitEffect1.eff.constant.fade_length = 120;
164 pHitEffect1.eff.constant.fade_level = 1;
166 pHitEffect1.id = SDL_HapticNewEffect(haptic, &pHitEffect1.eff);
168 if (pHitEffect1.id < 0) {
169 mprintf((" Hit effect 1 failed to load:\n %s\n", SDL_GetError()));
171 pHitEffect1.loaded = 1;
175 if (supported & SDL_HAPTIC_SINE) {
177 memset(&pHitEffect2, 0, sizeof(haptic_effect_t));
179 pHitEffect2.eff.type = SDL_HAPTIC_SINE;
180 pHitEffect2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
181 pHitEffect2.eff.periodic.direction.dir[0] = 9000;
182 pHitEffect2.eff.periodic.length = 300;
183 pHitEffect2.eff.periodic.period = 100;
184 pHitEffect2.eff.periodic.magnitude = 0x7FFF;
185 pHitEffect2.eff.periodic.attack_length = 100;
186 pHitEffect2.eff.periodic.fade_length = 100;
188 pHitEffect2.id = SDL_HapticNewEffect(haptic, &pHitEffect2.eff);
190 if (pHitEffect2.id < 0) {
191 mprintf((" Hit effect 2 failed to load:\n %s\n", SDL_GetError()));
193 pHitEffect2.loaded = 1;
197 if (supported & SDL_HAPTIC_SAWTOOTHDOWN) {
199 memset(&pShootEffect, 0, sizeof(haptic_effect_t));
201 pShootEffect.eff.type = SDL_HAPTIC_SAWTOOTHDOWN;
202 pShootEffect.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
203 pShootEffect.eff.periodic.direction.dir[0] = 0;
204 pShootEffect.eff.periodic.length = 160;
205 pShootEffect.eff.periodic.period = 20;
206 pShootEffect.eff.periodic.magnitude = 0x7FFF;
207 pShootEffect.eff.periodic.fade_length = 120;
209 pShootEffect.id = SDL_HapticNewEffect(haptic, &pShootEffect.eff);
211 if (pShootEffect.id < 0) {
212 mprintf((" Fire primary effect failed to load:\n %s\n", SDL_GetError()));
214 pShootEffect.loaded = 1;
218 if (supported & SDL_HAPTIC_CONSTANT) {
220 memset(&pSecShootEffect, 0, sizeof(haptic_effect_t));
222 pSecShootEffect.eff.type = SDL_HAPTIC_CONSTANT;
223 pSecShootEffect.eff.constant.direction.type = SDL_HAPTIC_POLAR;
224 pSecShootEffect.eff.constant.direction.dir[0] = 0;
225 pSecShootEffect.eff.constant.length = 200;
226 pSecShootEffect.eff.constant.level = 0x7FFF;
227 pSecShootEffect.eff.constant.attack_length = 50;
228 pSecShootEffect.eff.constant.attack_level = 0x7FFF;
229 pSecShootEffect.eff.constant.fade_length = 100;
230 pSecShootEffect.eff.constant.fade_level = 1;
232 pSecShootEffect.id = SDL_HapticNewEffect(haptic, &pSecShootEffect.eff);
234 if (pSecShootEffect.id < 0) {
235 mprintf((" Fire secondary effect failed to load:\n %s\n", SDL_GetError()));
237 pSecShootEffect.loaded = 1;
241 if (supported & SDL_HAPTIC_SPRING) {
243 memset(&pSpring, 0, sizeof(haptic_effect_t));
245 pSpring.eff.type = SDL_HAPTIC_SPRING;
246 pSpring.eff.condition.length = SDL_HAPTIC_INFINITY;
248 for (int i = 0; i < SDL_HapticNumAxes(haptic); i++) {
249 pSpring.eff.condition.right_sat[i] = 0x7FFF;
250 pSpring.eff.condition.left_sat[i] = 0x7FFF;
251 pSpring.eff.condition.right_coeff[i] = 0x147;
252 pSpring.eff.condition.left_coeff[i] = 0x147;
255 pSpring.id = SDL_HapticNewEffect(haptic, &pSpring.eff);
257 if (pSpring.id < 0) {
258 mprintf((" Spring effect failed to load:\n %s\n", SDL_GetError()));
261 joy_ff_start_effect(&pSpring, "Spring");
265 if (supported & SDL_HAPTIC_SINE) {
267 memset(&pAfterburn1, 0, sizeof(haptic_effect_t));
269 pAfterburn1.eff.type = SDL_HAPTIC_SINE;
270 pAfterburn1.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
271 pAfterburn1.eff.periodic.direction.dir[0] = 0;
272 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
273 pAfterburn1.eff.periodic.period = 20;
274 pAfterburn1.eff.periodic.magnitude = 0x6665;
276 pAfterburn1.id = SDL_HapticNewEffect(haptic, &pAfterburn1.eff);
278 if (pAfterburn1.id < 0) {
279 mprintf((" Afterburn effect 1 failed to load:\n %s\n", SDL_GetError()));
281 pAfterburn1.loaded = 1;
285 memset(&pAfterburn2, 0, sizeof(haptic_effect_t));
287 pAfterburn2.eff.type = SDL_HAPTIC_SINE;
288 pAfterburn2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
289 pAfterburn2.eff.periodic.direction.dir[0] = 9000;
290 pAfterburn2.eff.periodic.length = 125;
291 pAfterburn2.eff.periodic.period = 100;
292 pAfterburn2.eff.periodic.magnitude = 0x3332;
294 pAfterburn2.id = SDL_HapticNewEffect(haptic, &pAfterburn2.eff);
296 if (pAfterburn2.id < 0) {
297 mprintf((" Afterburn effect 2 failed to load:\n %s\n", SDL_GetError()));
299 pAfterburn2.loaded = 1;
304 // if (supported & SDL_HAPTIC_SQUARE) {
305 if (supported & SDL_HAPTIC_TRIANGLE) {
307 memset(&pDock, 0, sizeof(haptic_effect_t));
309 // pDock.eff.type = SDL_HAPTIC_SQUARE;
310 pDock.eff.type = SDL_HAPTIC_TRIANGLE;
311 pDock.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
312 pDock.eff.periodic.direction.dir[0] = 9000;
313 pDock.eff.periodic.length = 125;
314 pDock.eff.periodic.period = 100;
315 pDock.eff.periodic.magnitude = 0x3332;
317 pDock.id = SDL_HapticNewEffect(haptic, &pDock.eff);
320 mprintf((" Dock effect failed to load:\n %s\n", SDL_GetError()));
327 if (supported & SDL_HAPTIC_SAWTOOTHDOWN) {
329 memset(&pExplode, 0, sizeof(haptic_effect_t));
331 pExplode.eff.type = SDL_HAPTIC_SAWTOOTHDOWN;
332 pExplode.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
333 pExplode.eff.periodic.direction.dir[0] = 9000;
334 pExplode.eff.periodic.length = 500;
335 pExplode.eff.periodic.period = 20;
336 pExplode.eff.periodic.magnitude = 0x7FFF;
337 pExplode.eff.periodic.attack_length = 0;
338 pExplode.eff.periodic.fade_length = 500;
340 pExplode.id = SDL_HapticNewEffect(haptic, &pExplode.eff);
342 if (pExplode.id < 0) {
343 mprintf((" Explosion effect failed to load:\n %s\n", SDL_GetError()));
349 if (supported & SDL_HAPTIC_SINE) {
351 memset(&pDeathroll1, 0, sizeof(haptic_effect_t));
353 pDeathroll1.eff.type = SDL_HAPTIC_SINE;
354 pDeathroll1.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
355 pDeathroll1.eff.periodic.direction.dir[0] = 0;
356 pDeathroll1.eff.periodic.length = SDL_HAPTIC_INFINITY;
357 pDeathroll1.eff.periodic.period = 200;
358 pDeathroll1.eff.periodic.magnitude = 0x7FFF;
359 pDeathroll1.eff.periodic.attack_length = 200;
361 pDeathroll1.id = SDL_HapticNewEffect(haptic, &pDeathroll1.eff);
363 if (pDeathroll1.id < 0) {
364 mprintf((" Deathroll effect 1 failed to load:\n %s\n", SDL_GetError()));
366 pDeathroll1.loaded = 1;
370 memset(&pDeathroll2, 0, sizeof(haptic_effect_t));
372 pDeathroll2.eff.type = SDL_HAPTIC_SINE;
373 pDeathroll2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
374 pDeathroll2.eff.periodic.direction.dir[0] = 9000;
375 pDeathroll2.eff.periodic.length = SDL_HAPTIC_INFINITY;
376 pDeathroll2.eff.periodic.period = 200;
377 pDeathroll2.eff.periodic.magnitude = 0x7FFF;
378 pDeathroll2.eff.periodic.attack_length = 200;
380 pDeathroll2.id = SDL_HapticNewEffect(haptic, &pDeathroll2.eff);
382 if (pDeathroll2.id < 0) {
383 mprintf((" Deathroll effect 2 failed to load:\n %s\n", SDL_GetError()));
385 pDeathroll2.loaded = 1;
391 static void joy_ff_start_effect(haptic_effect_t *eff, const char *name)
393 if ( !eff->loaded ) {
397 // nprintf(("Joystick", "FF: Starting effect %s\n", name));
399 if ( SDL_HapticRunEffect(haptic, eff->id, 1) ) {
400 mprintf(("HapticERROR: Unable to run %s:\n %s\n", name, SDL_GetError()));
404 void joy_ff_stop_effects()
406 SDL_HapticStopAll(haptic);
409 void joy_ff_mission_init(vector v)
413 joy_ff_handling_scaler = (int) ((vm_vec_mag(&v) + 1.3f) * 5.0f);
416 void joy_reacquire_ff()
420 void joy_unacquire_ff()
424 void joy_ff_play_vector_effect(vector *v, float scaler)
429 // nprintf(("Joystick", "FF: vec = { %f, %f, %f } s = %f\n", v->xyz.x, v->xyz.y, v->xyz.z, scaler));
430 vm_vec_copy_scale(&vf, v, scaler);
434 if (vf.xyz.y + vf.xyz.z < 0.0f) {
435 y = -vm_vec_mag(&vf);
440 joy_ff_play_dir_effect(-x, -y);
443 void joy_ff_play_dir_effect(float x, float y)
448 if ( !Joy_ff_enabled ) {
452 // allow for at least one of the effects to work
453 if ( !pHitEffect1.loaded && !pHitEffect2.loaded ) {
457 if (joy_ff_effect_playing(&pHitEffect1) || joy_ff_effect_playing(&pHitEffect2)) {
458 nprintf(("Joystick", "FF: HitEffect already playing. Skipping\n"));
462 if (Joy_ff_directional_hit_effect_enabled) {
465 } else if (x < -8000.0f) {
471 } else if (y < -8000.0f) {
475 imag = (int) fl_sqrt(x * x + y * y);
480 degs = (float)atan2(x, y);
481 idegs = (int) (degs * 18000.0f / PI) + 90;
486 while (idegs >= 36000) {
490 if (pHitEffect1.loaded) {
491 pHitEffect1.eff.constant.direction.dir[0] = idegs;
492 pHitEffect1.eff.constant.level = fl2i(0x7FFF * (imag / 10000.0f));
494 if ( SDL_HapticUpdateEffect(haptic, pHitEffect1.id, &pHitEffect1.eff) < 0 ) {
495 mprintf(("HapticERROR: Unable to update pHitEffect1:\n %s\n", SDL_GetError()));
503 if (pHitEffect2.loaded) {
504 pHitEffect2.eff.periodic.direction.dir[0] = idegs;
505 pHitEffect2.eff.periodic.magnitude = fl2i(0x7FFF * (imag / 10000.0f));
507 if ( SDL_HapticUpdateEffect(haptic, pHitEffect2.id, &pHitEffect2.eff) < 0 ) {
508 mprintf(("HapticERROR: Unable to update pHitEffect2:\n %s\n", SDL_GetError()));
513 joy_ff_start_effect(&pHitEffect1, "HitEffect1");
514 joy_ff_start_effect(&pHitEffect2, "HitEffect2");
517 static int primary_ff_level = 10000;
519 void joy_ff_play_primary_shoot(int gain)
521 if ( !Joy_ff_enabled ) {
525 if ( !pShootEffect.loaded && !Joy_rumble ) {
531 } else if (gain > 10000) {
535 if (pShootEffect.loaded) {
536 SDL_HapticStopEffect(haptic, pShootEffect.id);
538 if (gain != primary_ff_level) {
539 pShootEffect.eff.periodic.direction.dir[0] = 0;
540 pShootEffect.eff.periodic.length = 160;
541 pShootEffect.eff.periodic.magnitude = fl2i(0x7FFF * (gain / 10000.0f));
542 pShootEffect.eff.periodic.fade_length = 120;
544 if ( SDL_HapticUpdateEffect(haptic, pShootEffect.id, &pShootEffect.eff) < 0 ) {
545 mprintf(("HapticERROR: Unable to update pShootEffect:\n %s\n", SDL_GetError()));
548 primary_ff_level = gain;
551 joy_ff_start_effect(&pShootEffect, "ShootEffect");
552 } else if (Joy_rumble) {
553 SDL_HapticRumblePlay(haptic, (gain / 10000.0f) * 0.5f, 100);
557 static int secondary_ff_level = 10000;
559 void joy_ff_play_secondary_shoot(int gain)
561 if ( !Joy_ff_enabled ) {
565 if ( !pSecShootEffect.loaded && !Joy_rumble ) {
569 gain = gain * 100 + 2500;
573 } else if (gain > 10000) {
577 if (pSecShootEffect.loaded) {
578 SDL_HapticStopEffect(haptic, pSecShootEffect.id);
580 if (gain != secondary_ff_level) {
581 pSecShootEffect.eff.constant.level = fl2i(0x7FFF * (gain / 10000.0f));
582 pSecShootEffect.eff.constant.length = (150000 + gain * 25) / 1000;
584 if ( SDL_HapticUpdateEffect(haptic, pSecShootEffect.id, &pSecShootEffect.eff) < 0 ) {
585 mprintf(("HapticERROR: Unable to update pSecShootEffect:\n %s\n", SDL_GetError()));
588 secondary_ff_level = gain;
589 nprintf(("Joystick", "FF: Secondary force = 0x%04x\n", pSecShootEffect.eff.constant.level));
592 joy_ff_start_effect(&pSecShootEffect, "SecShootEffect");
593 } else if (Joy_rumble) {
594 SDL_HapticRumblePlay(haptic, (gain / 10000.0f) * 0.5f, (150000 + gain * 25) / 1000);
598 void joy_ff_adjust_handling(int speed)
603 if ( !Joy_ff_enabled ) {
607 if ( !pSpring.loaded ) {
611 v = speed * joy_ff_handling_scaler * 2 / 3;
612 // v += joy_ff_handling_scaler * joy_ff_handling_scaler * 6 / 7 + 250;
613 v += joy_ff_handling_scaler * 45 - 500;
617 } else if (v > 10000) {
621 coeff = fl2i(0x7FFF * (v / 10000.0f));
623 for (int i = 0; i < SDL_HapticNumAxes(haptic); i++) {
624 pSpring.eff.condition.right_coeff[i] = coeff;
625 pSpring.eff.condition.left_coeff[i] = coeff;
628 // nprintf(("Joystick", "FF: New handling force = 0x%04x\n", coeff));
630 SDL_HapticUpdateEffect(haptic, pSpring.id, &pSpring.eff);
633 static int joy_ff_effect_playing(haptic_effect_t *eff)
635 if ( !eff->loaded ) {
638 return (SDL_HapticGetEffectStatus(haptic, eff->id) > 0);
644 if ( !Joy_ff_enabled ) {
648 if ( !pDock.loaded ) {
652 SDL_HapticStopEffect(haptic, pDock.id);
654 pDock.eff.periodic.magnitude = 0x7fff;
656 if ( SDL_HapticUpdateEffect(haptic, pDock.id, &pDock.eff) < 0 ) {
657 mprintf(("HapticERROR: Unable to update pDock:\n %s\n", SDL_GetError()));
660 joy_ff_start_effect(&pDock, "Dock");
663 void joy_ff_play_reload_effect()
665 if ( !Joy_ff_enabled ) {
669 if ( !pDock.loaded ) {
673 SDL_HapticStopEffect(haptic, pDock.id);
675 pDock.eff.periodic.magnitude = 0x3fff;
677 if ( SDL_HapticUpdateEffect(haptic, pDock.id, &pDock.eff) < 0 ) {
678 mprintf(("HapticERROR: Unable to update pDock:\n %s\n", SDL_GetError()));
681 joy_ff_start_effect(&pDock, "Dock (Reload)");
684 static int Joy_ff_afterburning = 0;
686 void joy_ff_afterburn_on()
688 if ( !Joy_ff_enabled ) {
692 if (Joy_ff_afterburning) {
696 if ( !(pAfterburn1.loaded && pAfterburn2.loaded) ) {
700 SDL_HapticStopEffect(haptic, pAfterburn1.id);
702 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
703 pAfterburn1.eff.periodic.period = 20;
704 pAfterburn1.eff.periodic.magnitude = 0x3fff;
705 pAfterburn1.eff.periodic.attack_length = 0;
707 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
708 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
711 SDL_HapticStopEffect(haptic, pAfterburn2.id);
713 pAfterburn2.eff.periodic.length = SDL_HAPTIC_INFINITY;
714 pAfterburn2.eff.periodic.period = 100;
715 pAfterburn2.eff.periodic.magnitude = 0x3fff;
716 pAfterburn2.eff.periodic.attack_length = 0;
718 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
719 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
722 joy_ff_start_effect(&pAfterburn1, "Afterburn1");
723 joy_ff_start_effect(&pAfterburn2, "Afterburn2");
725 // nprintf(("Joystick", "FF: Afterburn started\n"));
727 Joy_ff_afterburning = 1;
730 void joy_ff_afterburn_off()
732 if ( !Joy_ff_enabled ) {
736 if ( !Joy_ff_afterburning ) {
740 if (pAfterburn1.loaded) {
741 SDL_HapticStopEffect(haptic, pAfterburn1.id);
744 if (pAfterburn2.loaded) {
745 SDL_HapticStopEffect(haptic, pAfterburn2.id);
748 Joy_ff_afterburning = 0;
750 // nprintf(("Joystick", "FF: Afterburn stopped\n"));
753 void joy_ff_explode()
755 if ( !Joy_ff_enabled ) {
759 if (pDeathroll1.loaded) {
760 SDL_HapticStopEffect(haptic, pDeathroll1.id);
763 if (pDeathroll2.loaded) {
764 SDL_HapticStopEffect(haptic, pDeathroll2.id);
767 if (pExplode.loaded) {
768 SDL_HapticStopEffect(haptic, pExplode.id);
771 joy_ff_start_effect(&pExplode, "Explode");
774 if (pAfterburn1.loaded) {
775 SDL_HapticStopEffect(haptic, pAfterburn1.id);
778 if (pAfterburn2.loaded) {
779 SDL_HapticStopEffect(haptic, pAfterburn2.id);
782 if (pShootEffect.loaded) {
783 SDL_HapticStopEffect(haptic, pShootEffect.id);
785 pShootEffect.eff.periodic.direction.dir[0] = 9000;
786 pShootEffect.eff.periodic.length = 500;
787 pShootEffect.eff.periodic.magnitude = 0x7FFF;
788 pShootEffect.eff.periodic.fade_length = 500;
790 if ( SDL_HapticUpdateEffect(haptic, pShootEffect.id, &pShootEffect.eff) < 0 ) {
791 mprintf(("HapticERROR: Unable to update pShootEffect:\n %s\n", SDL_GetError()));
794 joy_ff_start_effect(&pShootEffect, "ShootEffect (Explode)");
797 Joy_ff_afterburning = 0;
800 void joy_ff_fly_by(int mag)
804 if ( !Joy_ff_enabled ) {
808 if (Joy_ff_afterburning) {
812 if ( !(pAfterburn1.loaded && pAfterburn2.loaded) ) {
816 gain = mag * 120 + 4000;
820 } else if (gain > 10000) {
824 SDL_HapticStopEffect(haptic, pAfterburn1.id);
826 pAfterburn1.eff.periodic.length = (6000 * mag + 400000) / 1000;
827 pAfterburn1.eff.periodic.period = 20;
828 pAfterburn1.eff.periodic.magnitude = fl2i(0x7FFF * (gain / 10000.0f));
829 pAfterburn1.eff.periodic.attack_length = 0;
831 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
832 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
836 SDL_HapticStopEffect(haptic, pAfterburn2.id);
838 pAfterburn2.eff.periodic.length = (6000 * mag + 400000) / 1000;
839 pAfterburn2.eff.periodic.period = 100;
840 pAfterburn2.eff.periodic.magnitude = fl2i(0x7FFF * (gain / 10000.0f));
841 pAfterburn2.eff.periodic.attack_length = 0;
843 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
844 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
847 joy_ff_start_effect(&pAfterburn1, "Afterburn1 (Fly by)");
848 joy_ff_start_effect(&pAfterburn2, "Afterburn2 (Fly by)");
851 void joy_ff_deathroll()
853 if ( !Joy_ff_enabled ) {
857 if (pDeathroll1.loaded) {
858 SDL_HapticStopEffect(haptic, pDeathroll1.id);
861 if (pDeathroll2.loaded) {
862 SDL_HapticStopEffect(haptic, pDeathroll2.id);
865 joy_ff_start_effect(&pDeathroll1, "Deathroll1");
866 joy_ff_start_effect(&pDeathroll2, "Deathroll2");
869 if (pAfterburn1.loaded && pAfterburn2.loaded) {
870 SDL_HapticStopEffect(haptic, pAfterburn1.id);
872 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
873 pAfterburn1.eff.periodic.period = 200;
874 pAfterburn1.eff.periodic.magnitude = 0x7FFF;
875 pAfterburn1.eff.periodic.attack_length = 200;
877 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
878 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
881 SDL_HapticStopEffect(haptic, pAfterburn2.id);
883 pAfterburn2.eff.periodic.length = SDL_HAPTIC_INFINITY;
884 pAfterburn2.eff.periodic.period = 200;
885 pAfterburn2.eff.periodic.magnitude = 0x7FFF;
886 pAfterburn2.eff.periodic.attack_length = 200;
888 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
889 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
892 joy_ff_start_effect(&pAfterburn1, "Afterburn1 (Death Roll)");
893 joy_ff_start_effect(&pAfterburn2, "Afterburn2 (Death Roll)");
895 Joy_ff_afterburning = 1;