Skip to content

Commit

Permalink
Translate conditional effect direction instead of hardcoding it to 0
Browse files Browse the repository at this point in the history
Provious code wrongly assumed that direction is not an important part
of conditional effect. Moreover, if there's need to hardcode polar
direction, the default should be 0x4000 (north).

For one axis affects, a direction of 0 means complete lack of force, if
a FFB-enabled device takes direction into force calculation. A sine function
graph can be used to represent the resulting forces where X is the input
direction and Y is the force multiplier (360 degrees equals to 1).

This fixes conditional effect playback on Moza Racing devices, which do
not ignore direction field.
  • Loading branch information
Lawstorant committed Jan 20, 2025
1 parent 819628c commit 5422454
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/SDL3/SDL_haptic.h
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ typedef struct SDL_HapticCondition
/* Header */
Uint16 type; /**< SDL_HAPTIC_SPRING, SDL_HAPTIC_DAMPER,
SDL_HAPTIC_INERTIA or SDL_HAPTIC_FRICTION */
SDL_HapticDirection direction; /**< Direction of the effect - Not used ATM. */
SDL_HapticDirection direction; /**< Direction of the effect. */

/* Replay */
Uint32 length; /**< Duration of the effect. */
Expand Down
4 changes: 3 additions & 1 deletion src/haptic/linux/SDL_syshaptic.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,9 @@ static bool SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *s
dest->type = FF_FRICTION;
}

dest->direction = 0; // Handled by the condition-specifics.
if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1) {
return -1;
}

// Replay
dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(condition->length);
Expand Down

0 comments on commit 5422454

Please sign in to comment.