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;
24 static int Joy_ff_afterburning = 0;
32 static haptic_effect_t pHitEffect1;
33 static haptic_effect_t pHitEffect2;
34 static haptic_effect_t pAfterburn1;
35 static haptic_effect_t pAfterburn2;
36 static haptic_effect_t pShootEffect;
37 static haptic_effect_t pSecShootEffect;
38 static haptic_effect_t pSpring;
39 static haptic_effect_t pDock;
40 //static haptic_effect_t pDeathroll1;
41 //static haptic_effect_t pDeathroll2;
42 //static haptic_effect_t pExplode;
44 static void joy_ff_create_effects();
45 static int joy_ff_effect_playing(haptic_effect_t *eff);
46 static void joy_ff_start_effect(haptic_effect_t *eff, const char *name);
48 extern SDL_Joystick *sdljoy;
55 ff_enabled = os_config_read_uint("Controls", "EnableJoystickFF", 0);
57 if ( !ff_enabled || !SDL_JoystickIsHaptic(sdljoy) ) {
61 if (SDL_InitSubSystem(SDL_INIT_HAPTIC) < 0) {
62 mprintf((" ERROR: Unable to initialize haptic subsystem\n"));
66 haptic = SDL_HapticOpenFromJoystick(sdljoy);
69 mprintf((" ERROR: Unable to open haptic joystick\n"));
70 SDL_QuitSubSystem(SDL_INIT_HAPTIC);
74 if ( SDL_HapticRumbleSupported(haptic) ) {
75 SDL_HapticRumbleInit(haptic);
79 mprintf((" Rumble : %s\n", Joy_rumble ? "Yes" : "No"));
80 mprintf((" Axes : %d\n", SDL_HapticNumAxes(haptic)));
81 mprintf((" Max effects : %d\n", SDL_HapticNumEffects(haptic)));
82 mprintf((" Running effects : %d\n", SDL_HapticNumEffectsPlaying(haptic)));
84 joy_ff_create_effects();
89 Joy_ff_directional_hit_effect_enabled = os_config_read_uint("Controls", "EnableHitEffect", 1);
94 void joy_ff_shutdown()
96 if ( !Joy_ff_enabled ) {
102 SDL_HapticClose(haptic);
105 SDL_QuitSubSystem(SDL_INIT_HAPTIC);
111 static void joy_ff_create_effects()
113 // clear all SDL errors
116 unsigned int supported = 0;
118 supported = SDL_HapticQuery(haptic);
120 if ( !(supported & SDL_HAPTIC_CONSTANT) ) {
121 mprintf((" Constant Force : not supported\n"));
124 if ( !(supported & SDL_HAPTIC_SINE) ) {
125 mprintf((" Sine Wave : not supported\n"));
126 Warning(LOCATION, "Sine Wave: not supported");
129 if ( !(supported & SDL_HAPTIC_SAWTOOTHDOWN) ) {
130 mprintf((" Sawtooth Down : not supported\n"));
133 if ( !(supported & SDL_HAPTIC_SPRING) ) {
134 mprintf((" Spring : not supported\n"));
135 // Error(LOCATION, "Spring: not supported");
138 if ( !(supported & SDL_HAPTIC_SQUARE) ) {
139 mprintf((" Square : not supported\n"));
142 if ( !(supported & SDL_HAPTIC_TRIANGLE) ) {
143 mprintf((" Triangle : not supported\n"));
147 if (supported & SDL_HAPTIC_CONSTANT) {
149 memset(&pHitEffect1, 0, sizeof(haptic_effect_t));
151 pHitEffect1.eff.type = SDL_HAPTIC_CONSTANT;
152 pHitEffect1.eff.constant.direction.type = SDL_HAPTIC_POLAR;
153 pHitEffect1.eff.constant.direction.dir[0] = 0;
154 pHitEffect1.eff.constant.length = 300;
155 pHitEffect1.eff.constant.level = 0x7FFF;
156 pHitEffect1.eff.constant.attack_length = 0;
157 pHitEffect1.eff.constant.attack_level = 0x7FFF;
158 pHitEffect1.eff.constant.fade_length = 120;
159 pHitEffect1.eff.constant.fade_level = 1;
161 pHitEffect1.id = SDL_HapticNewEffect(haptic, &pHitEffect1.eff);
163 if (pHitEffect1.id < 0) {
164 mprintf((" Hit effect 1 failed to load:\n %s\n", SDL_GetError()));
166 pHitEffect1.loaded = 1;
170 if (supported & SDL_HAPTIC_SINE) {
172 memset(&pHitEffect2, 0, sizeof(haptic_effect_t));
174 pHitEffect2.eff.type = SDL_HAPTIC_SINE;
175 pHitEffect2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
176 pHitEffect2.eff.periodic.direction.dir[0] = 9000;
177 pHitEffect2.eff.periodic.length = 300;
178 pHitEffect2.eff.periodic.period = 100;
179 pHitEffect2.eff.periodic.magnitude = 0x7FFF;
180 pHitEffect2.eff.periodic.attack_length = 100;
181 pHitEffect2.eff.periodic.fade_length = 100;
183 pHitEffect2.id = SDL_HapticNewEffect(haptic, &pHitEffect2.eff);
185 if (pHitEffect2.id < 0) {
186 mprintf((" Hit effect 2 failed to load:\n %s\n", SDL_GetError()));
188 pHitEffect2.loaded = 1;
192 if (supported & SDL_HAPTIC_SAWTOOTHDOWN) {
194 memset(&pShootEffect, 0, sizeof(haptic_effect_t));
196 pShootEffect.eff.type = SDL_HAPTIC_SAWTOOTHDOWN;
197 pShootEffect.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
198 pShootEffect.eff.periodic.direction.dir[0] = 0;
199 pShootEffect.eff.periodic.length = 160;
200 pShootEffect.eff.periodic.period = 20;
201 pShootEffect.eff.periodic.magnitude = 0x7FFF;
202 pShootEffect.eff.periodic.fade_length = 120;
204 pShootEffect.id = SDL_HapticNewEffect(haptic, &pShootEffect.eff);
206 if (pShootEffect.id < 0) {
207 mprintf((" Fire primary effect failed to load:\n %s\n", SDL_GetError()));
209 pShootEffect.loaded = 1;
213 if (supported & SDL_HAPTIC_CONSTANT) {
215 memset(&pSecShootEffect, 0, sizeof(haptic_effect_t));
217 pSecShootEffect.eff.type = SDL_HAPTIC_CONSTANT;
218 pSecShootEffect.eff.constant.direction.type = SDL_HAPTIC_POLAR;
219 pSecShootEffect.eff.constant.direction.dir[0] = 0;
220 pSecShootEffect.eff.constant.length = 200;
221 pSecShootEffect.eff.constant.level = 0x7FFF;
222 pSecShootEffect.eff.constant.attack_length = 50;
223 pSecShootEffect.eff.constant.attack_level = 0x7FFF;
224 pSecShootEffect.eff.constant.fade_length = 100;
225 pSecShootEffect.eff.constant.fade_level = 1;
227 pSecShootEffect.id = SDL_HapticNewEffect(haptic, &pSecShootEffect.eff);
229 if (pSecShootEffect.id < 0) {
230 mprintf((" Fire secondary effect failed to load:\n %s\n", SDL_GetError()));
232 pSecShootEffect.loaded = 1;
236 if (supported & SDL_HAPTIC_SPRING) {
238 memset(&pSpring, 0, sizeof(haptic_effect_t));
240 pSpring.eff.type = SDL_HAPTIC_SPRING;
241 pSpring.eff.condition.length = SDL_HAPTIC_INFINITY;
243 for (int i = 0; i < SDL_HapticNumAxes(haptic); i++) {
244 pSpring.eff.condition.right_sat[i] = 0x7FFF;
245 pSpring.eff.condition.left_sat[i] = 0x7FFF;
246 pSpring.eff.condition.right_coeff[i] = 0x147;
247 pSpring.eff.condition.left_coeff[i] = 0x147;
250 pSpring.id = SDL_HapticNewEffect(haptic, &pSpring.eff);
252 if (pSpring.id < 0) {
253 mprintf((" Spring effect failed to load:\n %s\n", SDL_GetError()));
256 joy_ff_start_effect(&pSpring, "Spring");
260 if (supported & SDL_HAPTIC_SINE) {
262 memset(&pAfterburn1, 0, sizeof(haptic_effect_t));
264 pAfterburn1.eff.type = SDL_HAPTIC_SINE;
265 pAfterburn1.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
266 pAfterburn1.eff.periodic.direction.dir[0] = 0;
267 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
268 pAfterburn1.eff.periodic.period = 20;
269 pAfterburn1.eff.periodic.magnitude = 0x3332;
271 pAfterburn1.id = SDL_HapticNewEffect(haptic, &pAfterburn1.eff);
273 if (pAfterburn1.id < 0) {
274 mprintf((" Afterburn effect 1 failed to load:\n %s\n", SDL_GetError()));
276 pAfterburn1.loaded = 1;
280 memset(&pAfterburn2, 0, sizeof(haptic_effect_t));
282 pAfterburn2.eff.type = SDL_HAPTIC_SINE;
283 pAfterburn2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
284 pAfterburn2.eff.periodic.direction.dir[0] = 9000;
285 pAfterburn2.eff.periodic.length = 125;
286 pAfterburn2.eff.periodic.period = 100;
287 pAfterburn2.eff.periodic.magnitude = 0x1999;
289 pAfterburn2.id = SDL_HapticNewEffect(haptic, &pAfterburn2.eff);
291 if (pAfterburn2.id < 0) {
292 mprintf((" Afterburn effect 2 failed to load:\n %s\n", SDL_GetError()));
294 pAfterburn2.loaded = 1;
299 // if (supported & SDL_HAPTIC_SQUARE) {
300 if (supported & SDL_HAPTIC_TRIANGLE) {
302 memset(&pDock, 0, sizeof(haptic_effect_t));
304 // pDock.eff.type = SDL_HAPTIC_SQUARE;
305 pDock.eff.type = SDL_HAPTIC_TRIANGLE;
306 pDock.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
307 pDock.eff.periodic.direction.dir[0] = 9000;
308 pDock.eff.periodic.length = 125;
309 pDock.eff.periodic.period = 100;
310 pDock.eff.periodic.magnitude = 0x3332;
312 pDock.id = SDL_HapticNewEffect(haptic, &pDock.eff);
315 mprintf((" Dock effect failed to load:\n %s\n", SDL_GetError()));
322 if (supported & SDL_HAPTIC_SAWTOOTHDOWN) {
324 memset(&pExplode, 0, sizeof(haptic_effect_t));
326 pExplode.eff.type = SDL_HAPTIC_SAWTOOTHDOWN;
327 pExplode.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
328 pExplode.eff.periodic.direction.dir[0] = 9000;
329 pExplode.eff.periodic.length = 500;
330 pExplode.eff.periodic.period = 20;
331 pExplode.eff.periodic.magnitude = 0x7FFF;
332 pExplode.eff.periodic.attack_length = 0;
333 pExplode.eff.periodic.fade_length = 500;
335 pExplode.id = SDL_HapticNewEffect(haptic, &pExplode.eff);
337 if (pExplode.id < 0) {
338 mprintf((" Explosion effect failed to load:\n %s\n", SDL_GetError()));
344 if (supported & SDL_HAPTIC_SINE) {
346 memset(&pDeathroll1, 0, sizeof(haptic_effect_t));
348 pDeathroll1.eff.type = SDL_HAPTIC_SINE;
349 pDeathroll1.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
350 pDeathroll1.eff.periodic.direction.dir[0] = 0;
351 pDeathroll1.eff.periodic.length = SDL_HAPTIC_INFINITY;
352 pDeathroll1.eff.periodic.period = 200;
353 pDeathroll1.eff.periodic.magnitude = 0x7FFF;
354 pDeathroll1.eff.periodic.attack_length = 200;
356 pDeathroll1.id = SDL_HapticNewEffect(haptic, &pDeathroll1.eff);
358 if (pDeathroll1.id < 0) {
359 mprintf((" Deathroll effect 1 failed to load:\n %s\n", SDL_GetError()));
361 pDeathroll1.loaded = 1;
365 memset(&pDeathroll2, 0, sizeof(haptic_effect_t));
367 pDeathroll2.eff.type = SDL_HAPTIC_SINE;
368 pDeathroll2.eff.periodic.direction.type = SDL_HAPTIC_POLAR;
369 pDeathroll2.eff.periodic.direction.dir[0] = 9000;
370 pDeathroll2.eff.periodic.length = SDL_HAPTIC_INFINITY;
371 pDeathroll2.eff.periodic.period = 200;
372 pDeathroll2.eff.periodic.magnitude = 0x7FFF;
373 pDeathroll2.eff.periodic.attack_length = 200;
375 pDeathroll2.id = SDL_HapticNewEffect(haptic, &pDeathroll2.eff);
377 if (pDeathroll2.id < 0) {
378 mprintf((" Deathroll effect 2 failed to load:\n %s\n", SDL_GetError()));
380 pDeathroll2.loaded = 1;
386 static void joy_ff_start_effect(haptic_effect_t *eff, const char *name)
388 if ( !eff->loaded ) {
392 // nprintf(("Joystick", "FF: Starting effect %s\n", name));
394 if ( SDL_HapticRunEffect(haptic, eff->id, 1) ) {
395 mprintf(("HapticERROR: Unable to run %s:\n %s\n", name, SDL_GetError()));
399 void joy_ff_stop_effects()
401 if ( !Joy_ff_enabled ) {
405 SDL_HapticStopAll(haptic);
408 void joy_ff_mission_init(vector v)
412 joy_ff_handling_scaler = (int) ((vm_vec_mag(&v) + 1.3f) * 5.0f);
414 Joy_ff_afterburning = 0;
417 void joy_reacquire_ff()
419 if ( !Joy_ff_enabled ) {
423 if (Joy_ff_acquired) {
427 joy_ff_start_effect(&pSpring, "Spring");
432 void joy_unacquire_ff()
434 if ( !Joy_ff_enabled ) {
438 if ( !Joy_ff_acquired ) {
442 joy_ff_stop_effects();
447 void joy_ff_play_vector_effect(vector *v, float scaler)
452 // nprintf(("Joystick", "FF: vec = { %f, %f, %f } s = %f\n", v->xyz.x, v->xyz.y, v->xyz.z, scaler));
453 vm_vec_copy_scale(&vf, v, scaler);
457 if (vf.xyz.y + vf.xyz.z < 0.0f) {
458 y = -vm_vec_mag(&vf);
463 joy_ff_play_dir_effect(-x, -y);
466 void joy_ff_play_dir_effect(float x, float y)
471 if ( !Joy_ff_enabled ) {
475 if ( !Joy_ff_acquired ) {
479 // allow for at least one of the effects to work
480 if ( !pHitEffect1.loaded && !pHitEffect2.loaded ) {
484 if (joy_ff_effect_playing(&pHitEffect1) || joy_ff_effect_playing(&pHitEffect2)) {
485 nprintf(("Joystick", "FF: HitEffect already playing. Skipping\n"));
489 if (Joy_ff_directional_hit_effect_enabled) {
492 } else if (x < -8000.0f) {
498 } else if (y < -8000.0f) {
502 imag = (int) fl_sqrt(x * x + y * y);
507 degs = (float)atan2(x, y);
508 idegs = (int) (degs * 18000.0f / PI) + 90;
513 while (idegs >= 36000) {
517 if (pHitEffect1.loaded) {
518 pHitEffect1.eff.constant.direction.dir[0] = idegs;
519 pHitEffect1.eff.constant.level = (Sint16)(32767.0f * (imag / 10000.0f));
521 if ( SDL_HapticUpdateEffect(haptic, pHitEffect1.id, &pHitEffect1.eff) < 0 ) {
522 mprintf(("HapticERROR: Unable to update pHitEffect1:\n %s\n", SDL_GetError()));
530 if (pHitEffect2.loaded) {
531 pHitEffect2.eff.periodic.direction.dir[0] = idegs;
532 pHitEffect2.eff.periodic.magnitude = (Sint16)(32767.0f * (imag / 10000.0f));
534 if ( SDL_HapticUpdateEffect(haptic, pHitEffect2.id, &pHitEffect2.eff) < 0 ) {
535 mprintf(("HapticERROR: Unable to update pHitEffect2:\n %s\n", SDL_GetError()));
540 joy_ff_start_effect(&pHitEffect1, "HitEffect1");
541 joy_ff_start_effect(&pHitEffect2, "HitEffect2");
544 void joy_ff_play_primary_shoot(int gain)
546 if ( !Joy_ff_enabled ) {
550 if ( !Joy_ff_acquired ) {
554 if ( !pShootEffect.loaded && !Joy_rumble ) {
560 } else if (gain > 10000) {
564 if (pShootEffect.loaded) {
565 SDL_HapticStopEffect(haptic, pShootEffect.id);
567 static int primary_ff_level = 10000;
569 if (gain != primary_ff_level) {
570 pShootEffect.eff.periodic.direction.dir[0] = 0;
571 pShootEffect.eff.periodic.length = 160;
572 pShootEffect.eff.periodic.magnitude = (Sint16)(32767.0f * (gain / 10000.0f));
573 pShootEffect.eff.periodic.fade_length = 120;
575 if ( SDL_HapticUpdateEffect(haptic, pShootEffect.id, &pShootEffect.eff) < 0 ) {
576 mprintf(("HapticERROR: Unable to update pShootEffect:\n %s\n", SDL_GetError()));
579 primary_ff_level = gain;
582 joy_ff_start_effect(&pShootEffect, "ShootEffect");
583 } else if (Joy_rumble) {
584 SDL_HapticRumblePlay(haptic, (gain / 10000.0f) * 0.5f, 100);
588 void joy_ff_play_secondary_shoot(int gain)
590 if ( !Joy_ff_enabled ) {
594 if ( !Joy_ff_acquired ) {
598 if ( !pSecShootEffect.loaded && !Joy_rumble ) {
602 gain = gain * 100 + 2500;
606 } else if (gain > 10000) {
610 if (pSecShootEffect.loaded) {
611 SDL_HapticStopEffect(haptic, pSecShootEffect.id);
613 static int secondary_ff_level = 10000;
615 if (gain != secondary_ff_level) {
616 pSecShootEffect.eff.constant.level = (Sint16)(32767.0f * (gain / 10000.0f));
617 pSecShootEffect.eff.constant.length = (150000 + gain * 25) / 1000;
619 if ( SDL_HapticUpdateEffect(haptic, pSecShootEffect.id, &pSecShootEffect.eff) < 0 ) {
620 mprintf(("HapticERROR: Unable to update pSecShootEffect:\n %s\n", SDL_GetError()));
623 secondary_ff_level = gain;
624 nprintf(("Joystick", "FF: Secondary force = 0x%04x\n", pSecShootEffect.eff.constant.level));
627 joy_ff_start_effect(&pSecShootEffect, "SecShootEffect");
628 } else if (Joy_rumble) {
629 SDL_HapticRumblePlay(haptic, (gain / 10000.0f) * 0.5f, (150000 + gain * 25) / 1000);
633 void joy_ff_adjust_handling(int speed)
638 if ( !Joy_ff_enabled ) {
642 if ( !Joy_ff_acquired ) {
646 if ( !pSpring.loaded ) {
650 static int last_speed = -1000;
652 if (speed == last_speed) {
658 v = speed * joy_ff_handling_scaler * 2 / 3;
659 // v += joy_ff_handling_scaler * joy_ff_handling_scaler * 6 / 7 + 250;
660 v += joy_ff_handling_scaler * 45 - 500;
664 } else if (v > 10000) {
668 coeff = (short)(32767.0f * (v / 10000.0f));
670 for (int i = 0; i < SDL_HapticNumAxes(haptic); i++) {
671 pSpring.eff.condition.right_coeff[i] = coeff;
672 pSpring.eff.condition.left_coeff[i] = coeff;
675 // nprintf(("Joystick", "FF: New handling force = 0x%04x\n", coeff));
677 SDL_HapticUpdateEffect(haptic, pSpring.id, &pSpring.eff);
680 static int joy_ff_effect_playing(haptic_effect_t *eff)
682 if ( !eff->loaded ) {
685 return (SDL_HapticGetEffectStatus(haptic, eff->id) > 0);
691 if ( !Joy_ff_enabled ) {
695 if ( !Joy_ff_acquired ) {
699 if ( !pDock.loaded ) {
703 SDL_HapticStopEffect(haptic, pDock.id);
705 pDock.eff.periodic.magnitude = 0x7fff;
707 if ( SDL_HapticUpdateEffect(haptic, pDock.id, &pDock.eff) < 0 ) {
708 mprintf(("HapticERROR: Unable to update pDock:\n %s\n", SDL_GetError()));
711 joy_ff_start_effect(&pDock, "Dock");
714 void joy_ff_play_reload_effect()
716 if ( !Joy_ff_enabled ) {
720 if ( !Joy_ff_acquired ) {
724 if ( !pDock.loaded ) {
728 SDL_HapticStopEffect(haptic, pDock.id);
730 pDock.eff.periodic.magnitude = 0x3fff;
732 if ( SDL_HapticUpdateEffect(haptic, pDock.id, &pDock.eff) < 0 ) {
733 mprintf(("HapticERROR: Unable to update pDock:\n %s\n", SDL_GetError()));
736 joy_ff_start_effect(&pDock, "Dock (Reload)");
739 void joy_ff_afterburn_on()
741 if ( !Joy_ff_enabled ) {
745 if ( !Joy_ff_acquired ) {
749 if (Joy_ff_afterburning) {
753 if ( !(pAfterburn1.loaded && pAfterburn2.loaded) ) {
757 SDL_HapticStopEffect(haptic, pAfterburn1.id);
759 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
760 pAfterburn1.eff.periodic.period = 20;
761 pAfterburn1.eff.periodic.magnitude = 0x3332;
762 pAfterburn1.eff.periodic.attack_length = 0;
764 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
765 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
768 SDL_HapticStopEffect(haptic, pAfterburn2.id);
770 pAfterburn2.eff.periodic.length = SDL_HAPTIC_INFINITY;
771 pAfterburn2.eff.periodic.period = 100;
772 pAfterburn2.eff.periodic.magnitude = 0x1999;
773 pAfterburn2.eff.periodic.attack_length = 0;
775 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
776 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
779 joy_ff_start_effect(&pAfterburn1, "Afterburn1");
780 joy_ff_start_effect(&pAfterburn2, "Afterburn2");
782 // nprintf(("Joystick", "FF: Afterburn started\n"));
784 Joy_ff_afterburning = 1;
787 void joy_ff_afterburn_off()
789 if ( !Joy_ff_enabled ) {
793 if ( !Joy_ff_acquired ) {
797 if ( !Joy_ff_afterburning ) {
801 if (pAfterburn1.loaded) {
802 SDL_HapticStopEffect(haptic, pAfterburn1.id);
805 if (pAfterburn2.loaded) {
806 SDL_HapticStopEffect(haptic, pAfterburn2.id);
809 Joy_ff_afterburning = 0;
811 // nprintf(("Joystick", "FF: Afterburn stopped\n"));
814 void joy_ff_explode()
816 if ( !Joy_ff_enabled ) {
820 if ( !Joy_ff_acquired ) {
824 if (pDeathroll1.loaded) {
825 SDL_HapticStopEffect(haptic, pDeathroll1.id);
828 if (pDeathroll2.loaded) {
829 SDL_HapticStopEffect(haptic, pDeathroll2.id);
832 if (pExplode.loaded) {
833 SDL_HapticStopEffect(haptic, pExplode.id);
836 joy_ff_start_effect(&pExplode, "Explode");
839 if (pAfterburn1.loaded) {
840 SDL_HapticStopEffect(haptic, pAfterburn1.id);
843 if (pAfterburn2.loaded) {
844 SDL_HapticStopEffect(haptic, pAfterburn2.id);
847 if (pShootEffect.loaded) {
848 SDL_HapticStopEffect(haptic, pShootEffect.id);
850 pShootEffect.eff.periodic.direction.dir[0] = 9000;
851 pShootEffect.eff.periodic.length = 500;
852 pShootEffect.eff.periodic.magnitude = 0x7FFF;
853 pShootEffect.eff.periodic.fade_length = 500;
855 if ( SDL_HapticUpdateEffect(haptic, pShootEffect.id, &pShootEffect.eff) < 0 ) {
856 mprintf(("HapticERROR: Unable to update pShootEffect:\n %s\n", SDL_GetError()));
859 joy_ff_start_effect(&pShootEffect, "ShootEffect (Explode)");
860 } else if (Joy_rumble) {
861 SDL_HapticRumblePlay(haptic, 0.75f, 500);
864 Joy_ff_afterburning = 0;
867 void joy_ff_fly_by(int mag)
871 if ( !Joy_ff_enabled ) {
875 if ( !Joy_ff_acquired ) {
879 if (Joy_ff_afterburning) {
883 if ( !(pAfterburn1.loaded && pAfterburn2.loaded) ) {
887 gain = mag * 120 + 4000;
891 } else if (gain > 10000) {
895 SDL_HapticStopEffect(haptic, pAfterburn1.id);
897 pAfterburn1.eff.periodic.length = (6000 * mag + 400000) / 1000;
898 pAfterburn1.eff.periodic.period = 20;
899 pAfterburn1.eff.periodic.magnitude = (Sint16)(32767.0f * (gain / 10000.0f));
900 pAfterburn1.eff.periodic.attack_length = 0;
902 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
903 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
907 SDL_HapticStopEffect(haptic, pAfterburn2.id);
909 pAfterburn2.eff.periodic.length = (6000 * mag + 400000) / 1000;
910 pAfterburn2.eff.periodic.period = 100;
911 pAfterburn2.eff.periodic.magnitude = (Sint16)(32767.0f * (gain / 10000.0f));
912 pAfterburn2.eff.periodic.attack_length = 0;
914 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
915 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
918 joy_ff_start_effect(&pAfterburn1, "Afterburn1 (Fly by)");
919 joy_ff_start_effect(&pAfterburn2, "Afterburn2 (Fly by)");
922 void joy_ff_deathroll()
924 if ( !Joy_ff_enabled ) {
928 if ( !Joy_ff_acquired ) {
932 if (pDeathroll1.loaded) {
933 SDL_HapticStopEffect(haptic, pDeathroll1.id);
936 if (pDeathroll2.loaded) {
937 SDL_HapticStopEffect(haptic, pDeathroll2.id);
940 joy_ff_start_effect(&pDeathroll1, "Deathroll1");
941 joy_ff_start_effect(&pDeathroll2, "Deathroll2");
944 if (pAfterburn1.loaded && pAfterburn2.loaded) {
945 SDL_HapticStopEffect(haptic, pAfterburn1.id);
947 pAfterburn1.eff.periodic.length = SDL_HAPTIC_INFINITY;
948 pAfterburn1.eff.periodic.period = 200;
949 pAfterburn1.eff.periodic.magnitude = 0x7FFF;
950 pAfterburn1.eff.periodic.attack_length = 200;
952 if ( SDL_HapticUpdateEffect(haptic, pAfterburn1.id, &pAfterburn1.eff) < 0 ) {
953 mprintf(("HapticERROR: Unable to update pAfterburn1:\n %s\n", SDL_GetError()));
956 SDL_HapticStopEffect(haptic, pAfterburn2.id);
958 pAfterburn2.eff.periodic.length = SDL_HAPTIC_INFINITY;
959 pAfterburn2.eff.periodic.period = 200;
960 pAfterburn2.eff.periodic.magnitude = 0x7FFF;
961 pAfterburn2.eff.periodic.attack_length = 200;
963 if ( SDL_HapticUpdateEffect(haptic, pAfterburn2.id, &pAfterburn2.eff) < 0 ) {
964 mprintf(("HapticERROR: Unable to update pAfterburn2:\n %s\n", SDL_GetError()));
967 joy_ff_start_effect(&pAfterburn1, "Afterburn1 (Death Roll)");
968 joy_ff_start_effect(&pAfterburn2, "Afterburn2 (Death Roll)");
970 Joy_ff_afterburning = 1;