From 529ed102fca5af50c690b81117078c8dc31376ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomasz=20Paku=C5=82a?= <[EMAIL REDACTED]>
Date: Mon, 20 Jan 2025 23:05:54 +0100
Subject: [PATCH] Translate conditional effect direction instead of hardcoding
it to 0
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.
---
include/SDL_haptic.h | 2 +-
src/haptic/linux/SDL_syshaptic.c | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h
index 61c62a5274306..f679c5734ecb5 100644
--- a/include/SDL_haptic.h
+++ b/include/SDL_haptic.h
@@ -624,7 +624,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. */
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index 548bb2d211d4c..2eef24137ad00 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -812,7 +812,9 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, SDL_HapticEffect *src)
dest->type = FF_FRICTION;
}
- dest->direction = 0; /* Handled by the condition-specifics. */
+ if (SDL_SYS_ToDirection(&dest->direction, &condition->direction) == -1) {
+ return -1;
+ }
/* Replay */
dest->replay.length = (condition->length == SDL_HAPTIC_INFINITY) ? 0 : CLAMP(condition->length);