Skip to content

Commit 85fd0b0

Browse files
committed
Restart spring effect after stopping all FF effects
SDL_HapticStopAll stops all effects, including the spring effect so the joystick goes limp after one mission (joy_ff_stop_effects gets called at the end of each mission). This restarts the spring effect which should fix that issue. This fixes #1417.
1 parent 5d3e678 commit 85fd0b0

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

code/io/joy_ff-sdl.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,34 @@ static int joy_ff_has_valid_effects();
5252
static int joy_ff_effect_playing(haptic_effect_t *eff);
5353
static void joy_ff_start_effect(haptic_effect_t *eff, const char *name);
5454

55+
static void check_and_print_haptic_feature(uint32_t flags, uint32_t check_flag, const char* description) {
56+
auto has_flag = (flags & check_flag) == check_flag;
57+
58+
mprintf((" Supports %s: %s\n", description, has_flag ? "true" : "false"));
59+
}
60+
61+
static void print_haptic_support() {
62+
mprintf((" Haptic feature support:\n"));
63+
64+
auto supported = SDL_HapticQuery(haptic);
65+
check_and_print_haptic_feature(supported, SDL_HAPTIC_CONSTANT, "Constant effect");
66+
check_and_print_haptic_feature(supported, SDL_HAPTIC_SINE, "Sine effect");
67+
check_and_print_haptic_feature(supported, SDL_HAPTIC_LEFTRIGHT, "Left right effect");
68+
check_and_print_haptic_feature(supported, SDL_HAPTIC_TRIANGLE, "Triangle effect");
69+
check_and_print_haptic_feature(supported, SDL_HAPTIC_SAWTOOTHUP, "Sawtooth up effect");
70+
check_and_print_haptic_feature(supported, SDL_HAPTIC_SAWTOOTHDOWN, "Sawtooth down effect");
71+
check_and_print_haptic_feature(supported, SDL_HAPTIC_RAMP, "Ramp effect");
72+
check_and_print_haptic_feature(supported, SDL_HAPTIC_SPRING, "Spring effect");
73+
check_and_print_haptic_feature(supported, SDL_HAPTIC_DAMPER, "Damper effect");
74+
check_and_print_haptic_feature(supported, SDL_HAPTIC_INERTIA, "Inertia effect");
75+
check_and_print_haptic_feature(supported, SDL_HAPTIC_FRICTION, "Friction effect");
76+
check_and_print_haptic_feature(supported, SDL_HAPTIC_CUSTOM, "Custom effect");
77+
check_and_print_haptic_feature(supported, SDL_HAPTIC_GAIN, "global gain");
78+
check_and_print_haptic_feature(supported, SDL_HAPTIC_AUTOCENTER, "Autocenter");
79+
check_and_print_haptic_feature(supported, SDL_HAPTIC_STATUS, "Status query");
80+
check_and_print_haptic_feature(supported, SDL_HAPTIC_PAUSE, "Pause effects");
81+
}
82+
5583
int joy_ff_init()
5684
{
5785
int ff_enabled = 0;
@@ -118,6 +146,7 @@ int joy_ff_init()
118146
mprintf((" Number of haptic axes: %d\n", SDL_HapticNumAxes(haptic)));
119147
mprintf((" Number of effects supported: %d\n", SDL_HapticNumEffects(haptic)));
120148
mprintf((" Number of simultaneous effects: %d\n", SDL_HapticNumEffectsPlaying(haptic)));
149+
print_haptic_support();
121150

122151
mprintf((" ... Haptic successfully initialized!\n"));
123152

@@ -130,6 +159,11 @@ void joy_ff_shutdown()
130159
return;
131160
}
132161

162+
if (pSpring.loaded) {
163+
SDL_HapticStopEffect(haptic, pSpring.id);
164+
}
165+
joy_ff_stop_effects();
166+
133167
SDL_HapticClose(haptic);
134168
haptic = NULL;
135169

@@ -416,7 +450,15 @@ void joy_ff_stop_effects()
416450
return;
417451
}
418452

419-
SDL_HapticStopAll(haptic);
453+
joy_ff_afterburn_off();
454+
455+
if (pDeathroll1.loaded) {
456+
SDL_HapticStopEffect(haptic, pDeathroll1.id);
457+
}
458+
459+
if (pDeathroll2.loaded) {
460+
SDL_HapticStopEffect(haptic, pDeathroll2.id);
461+
}
420462
}
421463

422464
void joy_ff_mission_init(vec3d v)

0 commit comments

Comments
 (0)