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 int Joy_ff_acquired = 0;
20 static SDL_Haptic *haptic = NULL;
21 static int joy_ff_handling_scaler = 0;
22 static int Joy_ff_directional_hit_effect_enabled = 1;
23 static int Joy_rumble = 0;
31 static haptic_effect_t pHitEffect1;
32 static haptic_effect_t pHitEffect2;
33 static haptic_effect_t pAfterburn1;
34 static haptic_effect_t pAfterburn2;
35 static haptic_effect_t pShootEffect;
36 static haptic_effect_t pSecShootEffect;
37 static haptic_effect_t pSpring;
38 static haptic_effect_t pDock;
39 //static haptic_effect_t pDeathroll1;
40 //static haptic_effect_t pDeathroll2;
41 //static haptic_effect_t pExplode;
43 static void joy_ff_create_effects();
44 static int joy_ff_effect_playing(haptic_effect_t *eff);
45 static void joy_ff_start_effect(haptic_effect_t *eff, const char *name);
47 extern SDL_Joystick *sdljoy;
54 ff_enabled = os_config_read_uint("Controls", "EnableJoystickFF", 0);
56 if ( !ff_enabled || !SDL_JoystickIsHaptic(sdljoy) ) {
60 if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) {
61 mprintf((" ERROR: Unable to initialize haptic subsystem\n"));
65 haptic = SDL_HapticOpenFromJoystick(sdljoy);
68 mprintf((" ERROR: Unable to open haptic joystick\n"));
69 SDL_QuitSubSystem(SDL_INIT_HAPTIC);
73 if ( SDL_HapticRumbleSupported(haptic) ) {
74 SDL_HapticRumbleInit(haptic);
78 mprintf((" Rumble : %s\n", Joy_rumble ? "Yes" : "No"));
79 mprintf((" Axes : %d\n", SDL_HapticNumAxes(haptic)));
80 mprintf((" Max effects : %d\n", SDL_HapticNumEffects(haptic)));
81 mprintf((" Running effects : %d\n", SDL_HapticNumEffectsPlaying(haptic)));
83 joy_ff_create_effects();
88 Joy_ff_directional_hit_effect_enabled = os_config_read_uint("Controls", "EnableHitEffect", 1);
93 void joy_ff_shutdown()
95 if ( !Joy_ff_enabled ) {
101 SDL_HapticClose(haptic);
104 SDL_QuitSubSystem(SDL_INIT_HAPTIC);
110 static void joy_ff_create_effects()
112 // clear all SDL errors
115 unsigned int supported = 0;
117 supported = SDL_HapticQuery(haptic);
119 if ( !(supported & SDL_HAPTIC_CONSTANT) ) {
120 mprintf((" Constant Force : not supported\n"));
123 if ( !(supported & SDL_HAPTIC_SINE) ) {
124 mprintf((" Sine Wave : not supported\n"));
125 Warning(LOCATION, "Sine Wave: not supported");
128 if ( !(supported & SDL_HAPTIC_SAWTOOTHDOWN) ) {
129 mprintf((" Sawtooth Down : not supported\n"));
132 if ( !(supported & SDL_HAPTIC_SPRING) ) {
133 mprintf((" Spring : not supported\n"));
134 // Error(LOCATION, "Spring: not supported");
137 if ( !(supported & SDL_HAPTIC_SQUARE) ) {
138 mprintf((" Square : not supported\n"));
141 if ( !(supported & SDL_HAPTIC_TRIANGLE) ) {
142 mprintf((" Triangle : not supported\n"));
146 if (supported & SDL_HAPTIC_CONSTANT) {
148 memset(&pHitEffect1, 0, sizeof(haptic_effect_t));
150 pHitEffect1.eff.type = SDL_HAPTIC_CONSTANT;
151 pHitEffect1.eff.constant.direction.type = SDL_HAPTIC_POLAR;
152 pHitEffect1.eff.constant.direction.dir[0] = 0;
153 pHitEffect1.eff.constant.length = 300;
154 pHitEffect1.eff.constant.level = 0x7FFF;
155 pHitEffect1.eff.constant.attack_length = 0;
156 pHitEffect1.eff.constant.attack_level = 0x7FFF;
157 pHitEffect1.eff.constant.fade_length = 120;
158 pHitEffect1.eff.constant.fade_level = 1;
160 pHitEffect1.id = SDL_HapticNewEffect(haptic, &pHitEffect1.eff);
162 if (pHitEffect1.id < 0) {
163 mprintf((" Hit effect 1 failed to load:\n %s\n", SDL_GetError()));
165 pHitEffect1.loaded = 1;
169 if (supported & SDL_HAPTIC_SINE) {
171 memset(&pHitEffect2, 0, sizeof(haptic_effect_t));
173 pHitEffect2.eff.type = SDL_HAPTIC_SINE;
174 pHitEffect2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
175 pHitEffect2.eff.periodic.direction.dir[0] = 9000;
176 pHitEffect2.eff.periodic.length = 300;
177 pHitEffect2.eff.periodic.period = 100;
178 pHitEffect2.eff.periodic.magnitude = 0x7FFF;
179 pHitEffect2.eff.periodic.attack_length = 100;
180 pHitEffect2.eff.periodic.fade_length = 100;
182 pHitEffect2.id = SDL_HapticNewEffect(haptic, &pHitEffect2.eff);
184 if (pHitEffect2.id < 0) {
185 mprintf((" Hit effect 2 failed to load:\n %s\n", SDL_GetError()));
187 pHitEffect2.loaded = 1;
191 if (supported & SDL_HAPTIC_SAWTOOTHDOWN) {
193 memset(&pShootEffect, 0, sizeof(haptic_effect_t));
195 pShootEffect.eff.type = SDL_HAPTIC_SAWTOOTHDOWN;
196 pShootEffect.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
197 pShootEffect.eff.periodic.direction.dir[0] = 0;
198 pShootEffect.eff.periodic.length = 160;
199 pShootEffect.eff.periodic.period = 20;
200 pShootEffect.eff.periodic.magnitude = 0x7FFF;
201 pShootEffect.eff.periodic.fade_length = 120;
203 pShootEffect.id = SDL_HapticNewEffect(haptic, &pShootEffect.eff);
205 if (pShootEffect.id < 0) {
206 mprintf((" Fire primary effect failed to load:\n %s\n", SDL_GetError()));
208 pShootEffect.loaded = 1;
212 if (supported & SDL_HAPTIC_CONSTANT) {
214 memset(&pSecShootEffect, 0, sizeof(haptic_effect_t));
216 pSecShootEffect.eff.type = SDL_HAPTIC_CONSTANT;
217 pSecShootEffect.eff.constant.direction.type = SDL_HAPTIC_POLAR;
218 pSecShootEffect.eff.constant.direction.dir[0] = 0;
219 pSecShootEffect.eff.constant.length = 200;
220 pSecShootEffect.eff.constant.level = 0x7FFF;
221 pSecShootEffect.eff.constant.attack_length = 50;
222 pSecShootEffect.eff.constant.attack_level = 0x7FFF;
223 pSecShootEffect.eff.constant.fade_length = 100;
224 pSecShootEffect.eff.constant.fade_level = 1;
226 pSecShootEffect.id = SDL_HapticNewEffect(haptic, &pSecShootEffect.eff);
228 if (pSecShootEffect.id < 0) {
229 mprintf((" Fire secondary effect failed to load:\n %s\n", SDL_GetError()));
231 pSecShootEffect.loaded = 1;
235 if (supported & SDL_HAPTIC_SPRING) {
237 memset(&pSpring, 0, sizeof(haptic_effect_t));
239 pSpring.eff.type = SDL_HAPTIC_SPRING;
240 pSpring.eff.condition.length = SDL_HAPTIC_INFINITY;
242 for (int i = 0; i < SDL_HapticNumAxes(haptic); i++) {
243 pSpring.eff.condition.right_sat[i] = 0x7FFF;
244 pSpring.eff.condition.left_sat[i] = 0x7FFF;
245 pSpring.eff.condition.right_coeff[i] = 0x147;
246 pSpring.eff.condition.left_coeff[i] = 0x147;
249 pSpring.id = SDL_HapticNewEffect(haptic, &pSpring.eff);
251 if (pSpring.id < 0) {
252 mprintf((" Spring effect failed to load:\n %s\n", SDL_GetError()));
255 joy_ff_start_effect(&pSpring, "Spring");
259 if (supported & SDL_HAPTIC_SINE) {
261 memset(&pAfterburn1, 0, sizeof(haptic_effect_t));
263 pAfterburn1.eff.type = SDL_HAPTIC_SINE;
264 pAfterburn1.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
265 pAfterburn1.eff.periodic.direction.dir[0] = 0;
266 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
267 pAfterburn1.eff.periodic.period = 20;
268 pAfterburn1.eff.periodic.magnitude = 0x6665;
270 pAfterburn1.id = SDL_HapticNewEffect(haptic, &pAfterburn1.eff);
272 if (pAfterburn1.id < 0) {
273 mprintf((" Afterburn effect 1 failed to load:\n %s\n", SDL_GetError()));
275 pAfterburn1.loaded = 1;
279 memset(&pAfterburn2, 0, sizeof(haptic_effect_t));
281 pAfterburn2.eff.type = SDL_HAPTIC_SINE;
282 pAfterburn2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
283 pAfterburn2.eff.periodic.direction.dir[0] = 9000;
284 pAfterburn2.eff.periodic.length = 125;
285 pAfterburn2.eff.periodic.period = 100;
286 pAfterburn2.eff.periodic.magnitude = 0x3332;
288 pAfterburn2.id = SDL_HapticNewEffect(haptic, &pAfterburn2.eff);
290 if (pAfterburn2.id < 0) {
291 mprintf((" Afterburn effect 2 failed to load:\n %s\n", SDL_GetError()));
293 pAfterburn2.loaded = 1;
298 // if (supported & SDL_HAPTIC_SQUARE) {
299 if (supported & SDL_HAPTIC_TRIANGLE) {
301 memset(&pDock, 0, sizeof(haptic_effect_t));
303 // pDock.eff.type = SDL_HAPTIC_SQUARE;
304 pDock.eff.type = SDL_HAPTIC_TRIANGLE;
305 pDock.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
306 pDock.eff.periodic.direction.dir[0] = 9000;
307 pDock.eff.periodic.length = 125;
308 pDock.eff.periodic.period = 100;
309 pDock.eff.periodic.magnitude = 0x3332;
311 pDock.id = SDL_HapticNewEffect(haptic, &pDock.eff);
314 mprintf((" Dock effect failed to load:\n %s\n", SDL_GetError()));
321 if (supported & SDL_HAPTIC_SAWTOOTHDOWN) {
323 memset(&pExplode, 0, sizeof(haptic_effect_t));
325 pExplode.eff.type = SDL_HAPTIC_SAWTOOTHDOWN;
326 pExplode.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
327 pExplode.eff.periodic.direction.dir[0] = 9000;
328 pExplode.eff.periodic.length = 500;
329 pExplode.eff.periodic.period = 20;
330 pExplode.eff.periodic.magnitude = 0x7FFF;
331 pExplode.eff.periodic.attack_length = 0;
332 pExplode.eff.periodic.fade_length = 500;
334 pExplode.id = SDL_HapticNewEffect(haptic, &pExplode.eff);
336 if (pExplode.id < 0) {
337 mprintf((" Explosion effect failed to load:\n %s\n", SDL_GetError()));
343 if (supported & SDL_HAPTIC_SINE) {
345 memset(&pDeathroll1, 0, sizeof(haptic_effect_t));
347 pDeathroll1.eff.type = SDL_HAPTIC_SINE;
348 pDeathroll1.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
349 pDeathroll1.eff.periodic.direction.dir[0] = 0;
350 pDeathroll1.eff.periodic.length = SDL_HAPTIC_INFINITY;
351 pDeathroll1.eff.periodic.period = 200;
352 pDeathroll1.eff.periodic.magnitude = 0x7FFF;
353 pDeathroll1.eff.periodic.attack_length = 200;
355 pDeathroll1.id = SDL_HapticNewEffect(haptic, &pDeathroll1.eff);
357 if (pDeathroll1.id < 0) {
358 mprintf((" Deathroll effect 1 failed to load:\n %s\n", SDL_GetError()));
360 pDeathroll1.loaded = 1;
364 memset(&pDeathroll2, 0, sizeof(haptic_effect_t));
366 pDeathroll2.eff.type = SDL_HAPTIC_SINE;
367 pDeathroll2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
368 pDeathroll2.eff.periodic.direction.dir[0] = 9000;
369 pDeathroll2.eff.periodic.length = SDL_HAPTIC_INFINITY;
370 pDeathroll2.eff.periodic.period = 200;
371 pDeathroll2.eff.periodic.magnitude = 0x7FFF;
372 pDeathroll2.eff.periodic.attack_length = 200;
374 pDeathroll2.id = SDL_HapticNewEffect(haptic, &pDeathroll2.eff);
376 if (pDeathroll2.id < 0) {
377 mprintf((" Deathroll effect 2 failed to load:\n %s\n", SDL_GetError()));
379 pDeathroll2.loaded = 1;
385 static void joy_ff_start_effect(haptic_effect_t *eff, const char *name)
387 if ( !eff->loaded ) {
391 // nprintf(("Joystick", "FF: Starting effect %s\n", name));
393 if ( SDL_HapticRunEffect(haptic, eff->id, 1) ) {
394 mprintf(("HapticERROR: Unable to run %s:\n %s\n", name, SDL_GetError()));
398 void joy_ff_stop_effects()
400 if ( !Joy_ff_enabled ) {
404 SDL_HapticStopAll(haptic);
407 void joy_ff_mission_init(vector v)
411 joy_ff_handling_scaler = (int) ((vm_vec_mag(&v) + 1.3f) * 5.0f);
414 void joy_reacquire_ff()
416 if ( !Joy_ff_enabled ) {
420 if (Joy_ff_acquired) {
424 joy_ff_start_effect(&pSpring, "Spring");
429 void joy_unacquire_ff()
431 if ( !Joy_ff_enabled ) {
435 if ( !Joy_ff_acquired ) {
439 joy_ff_stop_effects();
444 void joy_ff_play_vector_effect(vector *v, float scaler)
449 // nprintf(("Joystick", "FF: vec = { %f, %f, %f } s = %f\n", v->xyz.x, v->xyz.y, v->xyz.z, scaler));
450 vm_vec_copy_scale(&vf, v, scaler);
454 if (vf.xyz.y + vf.xyz.z < 0.0f) {
455 y = -vm_vec_mag(&vf);
460 joy_ff_play_dir_effect(-x, -y);
463 void joy_ff_play_dir_effect(float x, float y)
468 if ( !Joy_ff_enabled ) {
472 if ( !Joy_ff_acquired ) {
476 // allow for at least one of the effects to work
477 if ( !pHitEffect1.loaded && !pHitEffect2.loaded ) {
481 if (joy_ff_effect_playing(&pHitEffect1) || joy_ff_effect_playing(&pHitEffect2)) {
482 nprintf(("Joystick", "FF: HitEffect already playing. Skipping\n"));
486 if (Joy_ff_directional_hit_effect_enabled) {
489 } else if (x < -8000.0f) {
495 } else if (y < -8000.0f) {
499 imag = (int) fl_sqrt(x * x + y * y);
504 degs = (float)atan2(x, y);
505 idegs = (int) (degs * 18000.0f / PI) + 90;
510 while (idegs >= 36000) {
514 if (pHitEffect1.loaded) {
515 pHitEffect1.eff.constant.direction.dir[0] = idegs;
516 pHitEffect1.eff.constant.level = (Sint16)(32767.0f * (imag / 10000.0f));
518 if ( SDL_HapticUpdateEffect(haptic, pHitEffect1.id, &pHitEffect1.eff) < 0 ) {
519 mprintf(("HapticERROR: Unable to update pHitEffect1:\n %s\n", SDL_GetError()));
527 if (pHitEffect2.loaded) {
528 pHitEffect2.eff.periodic.direction.dir[0] = idegs;
529 pHitEffect2.eff.periodic.magnitude = (Sint16)(32767.0f * (imag / 10000.0f));
531 if ( SDL_HapticUpdateEffect(haptic, pHitEffect2.id, &pHitEffect2.eff) < 0 ) {
532 mprintf(("HapticERROR: Unable to update pHitEffect2:\n %s\n", SDL_GetError()));
537 joy_ff_start_effect(&pHitEffect1, "HitEffect1");
538 joy_ff_start_effect(&pHitEffect2, "HitEffect2");
541 static int primary_ff_level = 10000;
543 void joy_ff_play_primary_shoot(int gain)
545 if ( !Joy_ff_enabled ) {
549 if ( !Joy_ff_acquired ) {
553 if ( !pShootEffect.loaded && !Joy_rumble ) {
559 } else if (gain > 10000) {
563 if (pShootEffect.loaded) {
564 SDL_HapticStopEffect(haptic, pShootEffect.id);
566 if (gain != primary_ff_level) {
567 pShootEffect.eff.periodic.direction.dir[0] = 0;
568 pShootEffect.eff.periodic.length = 160;
569 pShootEffect.eff.periodic.magnitude = (Sint16)(32767.0f * (gain / 10000.0f));
570 pShootEffect.eff.periodic.fade_length = 120;
572 if ( SDL_HapticUpdateEffect(haptic, pShootEffect.id, &pShootEffect.eff) < 0 ) {
573 mprintf(("HapticERROR: Unable to update pShootEffect:\n %s\n", SDL_GetError()));
576 primary_ff_level = gain;
579 joy_ff_start_effect(&pShootEffect, "ShootEffect");
580 } else if (Joy_rumble) {
581 SDL_HapticRumblePlay(haptic, (gain / 10000.0f) * 0.5f, 100);
585 static int secondary_ff_level = 10000;
587 void joy_ff_play_secondary_shoot(int gain)
589 if ( !Joy_ff_enabled ) {
593 if ( !Joy_ff_acquired ) {
597 if ( !pSecShootEffect.loaded && !Joy_rumble ) {
601 gain = gain * 100 + 2500;
605 } else if (gain > 10000) {
609 if (pSecShootEffect.loaded) {
610 SDL_HapticStopEffect(haptic, pSecShootEffect.id);
612 if (gain != secondary_ff_level) {
613 pSecShootEffect.eff.constant.level = (Sint16)(32767.0f * (gain / 10000.0f));
614 pSecShootEffect.eff.constant.length = (150000 + gain * 25) / 1000;
616 if ( SDL_HapticUpdateEffect(haptic, pSecShootEffect.id, &pSecShootEffect.eff) < 0 ) {
617 mprintf(("HapticERROR: Unable to update pSecShootEffect:\n %s\n", SDL_GetError()));
620 secondary_ff_level = gain;
621 nprintf(("Joystick", "FF: Secondary force = 0x%04x\n", pSecShootEffect.eff.constant.level));
624 joy_ff_start_effect(&pSecShootEffect, "SecShootEffect");
625 } else if (Joy_rumble) {
626 SDL_HapticRumblePlay(haptic, (gain / 10000.0f) * 0.5f, (150000 + gain * 25) / 1000);
630 void joy_ff_adjust_handling(int speed)
635 if ( !Joy_ff_enabled ) {
639 if ( !Joy_ff_acquired ) {
643 if ( !pSpring.loaded ) {
647 v = speed * joy_ff_handling_scaler * 2 / 3;
648 // v += joy_ff_handling_scaler * joy_ff_handling_scaler * 6 / 7 + 250;
649 v += joy_ff_handling_scaler * 45 - 500;
653 } else if (v > 10000) {
657 coeff = (short)(32767.0f * (v / 10000.0f));
659 for (int i = 0; i < SDL_HapticNumAxes(haptic); i++) {
660 pSpring.eff.condition.right_coeff[i] = coeff;
661 pSpring.eff.condition.left_coeff[i] = coeff;
664 // nprintf(("Joystick", "FF: New handling force = 0x%04x\n", coeff));
666 SDL_HapticUpdateEffect(haptic, pSpring.id, &pSpring.eff);
669 static int joy_ff_effect_playing(haptic_effect_t *eff)
671 if ( !eff->loaded ) {
674 return (SDL_HapticGetEffectStatus(haptic, eff->id) > 0);
680 if ( !Joy_ff_enabled ) {
684 if ( !Joy_ff_acquired ) {
688 if ( !pDock.loaded ) {
692 SDL_HapticStopEffect(haptic, pDock.id);
694 pDock.eff.periodic.magnitude = 0x7fff;
696 if ( SDL_HapticUpdateEffect(haptic, pDock.id, &pDock.eff) < 0 ) {
697 mprintf(("HapticERROR: Unable to update pDock:\n %s\n", SDL_GetError()));
700 joy_ff_start_effect(&pDock, "Dock");
703 void joy_ff_play_reload_effect()
705 if ( !Joy_ff_enabled ) {
709 if ( !Joy_ff_acquired ) {
713 if ( !pDock.loaded ) {
717 SDL_HapticStopEffect(haptic, pDock.id);
719 pDock.eff.periodic.magnitude = 0x3fff;
721 if ( SDL_HapticUpdateEffect(haptic, pDock.id, &pDock.eff) < 0 ) {
722 mprintf(("HapticERROR: Unable to update pDock:\n %s\n", SDL_GetError()));
725 joy_ff_start_effect(&pDock, "Dock (Reload)");
728 static int Joy_ff_afterburning = 0;
730 void joy_ff_afterburn_on()
732 if ( !Joy_ff_enabled ) {
736 if ( !Joy_ff_acquired ) {
740 if (Joy_ff_afterburning) {
744 if ( !(pAfterburn1.loaded && pAfterburn2.loaded) ) {
748 SDL_HapticStopEffect(haptic, pAfterburn1.id);
750 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
751 pAfterburn1.eff.periodic.period = 20;
752 pAfterburn1.eff.periodic.magnitude = 0x3fff;
753 pAfterburn1.eff.periodic.attack_length = 0;
755 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
756 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
759 SDL_HapticStopEffect(haptic, pAfterburn2.id);
761 pAfterburn2.eff.periodic.length = SDL_HAPTIC_INFINITY;
762 pAfterburn2.eff.periodic.period = 100;
763 pAfterburn2.eff.periodic.magnitude = 0x3fff;
764 pAfterburn2.eff.periodic.attack_length = 0;
766 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
767 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
770 joy_ff_start_effect(&pAfterburn1, "Afterburn1");
771 joy_ff_start_effect(&pAfterburn2, "Afterburn2");
773 // nprintf(("Joystick", "FF: Afterburn started\n"));
775 Joy_ff_afterburning = 1;
778 void joy_ff_afterburn_off()
780 if ( !Joy_ff_enabled ) {
784 if ( !Joy_ff_acquired ) {
788 if ( !Joy_ff_afterburning ) {
792 if (pAfterburn1.loaded) {
793 SDL_HapticStopEffect(haptic, pAfterburn1.id);
796 if (pAfterburn2.loaded) {
797 SDL_HapticStopEffect(haptic, pAfterburn2.id);
800 Joy_ff_afterburning = 0;
802 // nprintf(("Joystick", "FF: Afterburn stopped\n"));
805 void joy_ff_explode()
807 if ( !Joy_ff_enabled ) {
811 if ( !Joy_ff_acquired ) {
815 if (pDeathroll1.loaded) {
816 SDL_HapticStopEffect(haptic, pDeathroll1.id);
819 if (pDeathroll2.loaded) {
820 SDL_HapticStopEffect(haptic, pDeathroll2.id);
823 if (pExplode.loaded) {
824 SDL_HapticStopEffect(haptic, pExplode.id);
827 joy_ff_start_effect(&pExplode, "Explode");
830 if (pAfterburn1.loaded) {
831 SDL_HapticStopEffect(haptic, pAfterburn1.id);
834 if (pAfterburn2.loaded) {
835 SDL_HapticStopEffect(haptic, pAfterburn2.id);
838 if (pShootEffect.loaded) {
839 SDL_HapticStopEffect(haptic, pShootEffect.id);
841 pShootEffect.eff.periodic.direction.dir[0] = 9000;
842 pShootEffect.eff.periodic.length = 500;
843 pShootEffect.eff.periodic.magnitude = 0x7FFF;
844 pShootEffect.eff.periodic.fade_length = 500;
846 if ( SDL_HapticUpdateEffect(haptic, pShootEffect.id, &pShootEffect.eff) < 0 ) {
847 mprintf(("HapticERROR: Unable to update pShootEffect:\n %s\n", SDL_GetError()));
850 joy_ff_start_effect(&pShootEffect, "ShootEffect (Explode)");
853 Joy_ff_afterburning = 0;
856 void joy_ff_fly_by(int mag)
860 if ( !Joy_ff_enabled ) {
864 if ( !Joy_ff_acquired ) {
868 if (Joy_ff_afterburning) {
872 if ( !(pAfterburn1.loaded && pAfterburn2.loaded) ) {
876 gain = mag * 120 + 4000;
880 } else if (gain > 10000) {
884 SDL_HapticStopEffect(haptic, pAfterburn1.id);
886 pAfterburn1.eff.periodic.length = (6000 * mag + 400000) / 1000;
887 pAfterburn1.eff.periodic.period = 20;
888 pAfterburn1.eff.periodic.magnitude = (Sint16)(32767.0f * (gain / 10000.0f));
889 pAfterburn1.eff.periodic.attack_length = 0;
891 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
892 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
896 SDL_HapticStopEffect(haptic, pAfterburn2.id);
898 pAfterburn2.eff.periodic.length = (6000 * mag + 400000) / 1000;
899 pAfterburn2.eff.periodic.period = 100;
900 pAfterburn2.eff.periodic.magnitude = (Sint16)(32767.0f * (gain / 10000.0f));
901 pAfterburn2.eff.periodic.attack_length = 0;
903 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
904 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
907 joy_ff_start_effect(&pAfterburn1, "Afterburn1 (Fly by)");
908 joy_ff_start_effect(&pAfterburn2, "Afterburn2 (Fly by)");
911 void joy_ff_deathroll()
913 if ( !Joy_ff_enabled ) {
917 if ( !Joy_ff_acquired ) {
921 if (pDeathroll1.loaded) {
922 SDL_HapticStopEffect(haptic, pDeathroll1.id);
925 if (pDeathroll2.loaded) {
926 SDL_HapticStopEffect(haptic, pDeathroll2.id);
929 joy_ff_start_effect(&pDeathroll1, "Deathroll1");
930 joy_ff_start_effect(&pDeathroll2, "Deathroll2");
933 if (pAfterburn1.loaded && pAfterburn2.loaded) {
934 SDL_HapticStopEffect(haptic, pAfterburn1.id);
936 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
937 pAfterburn1.eff.periodic.period = 200;
938 pAfterburn1.eff.periodic.magnitude = 0x7FFF;
939 pAfterburn1.eff.periodic.attack_length = 200;
941 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
942 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
945 SDL_HapticStopEffect(haptic, pAfterburn2.id);
947 pAfterburn2.eff.periodic.length = SDL_HAPTIC_INFINITY;
948 pAfterburn2.eff.periodic.period = 200;
949 pAfterburn2.eff.periodic.magnitude = 0x7FFF;
950 pAfterburn2.eff.periodic.attack_length = 200;
952 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
953 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
956 joy_ff_start_effect(&pAfterburn1, "Afterburn1 (Death Roll)");
957 joy_ff_start_effect(&pAfterburn2, "Afterburn2 (Death Roll)");
959 Joy_ff_afterburning = 1;