DSU joystick: add multi-server support & refactor

Refactor the DSU joystick driver to support multiple DSU servers and improve networking/lifecycle handling. Introduces a per-server DSU_ServerConnection type (DSU_MAX_SERVERS), moves per-server sockets, client IDs, threads and slots into that structure, and updates function signatures accordingly. Receiver thread now uses select() with a timeout, per-server sockets/threads are created, and sockets are closed/threads joined per-server on shutdown. Added server string parsing (address[:port]) and support for comma-separated server lists, improved timeout/detection logic to avoid SDL deadlocks by deferring SDL_PrivateJoystickAdded until DSU_JoystickDetect, and fixed rumble to send to the correct server/socket. Added sensor enable tracking, touchpad and sensor handling improvements, and a small CMake option change for DSU_JOYSTICK handling. Updated header to define new structs and fields.
This commit is contained in:
danprice142 2026-02-03 15:32:44 +00:00
parent 40855e0e52
commit db1245c613
3 changed files with 413 additions and 250 deletions

View file

@ -380,7 +380,7 @@ dep_option(SDL_HIDAPI_LIBUSB "Use libusb for low level joystick drivers" O
dep_option(SDL_HIDAPI_LIBUSB_SHARED "Dynamically load libusb support" ON "SDL_HIDAPI_LIBUSB;SDL_DEPS_SHARED" OFF)
dep_option(SDL_HIDAPI_JOYSTICK "Use HIDAPI for low level joystick drivers" ON SDL_HIDAPI OFF)
dep_option(SDL_VIRTUAL_JOYSTICK "Enable the virtual-joystick driver" ON SDL_HIDAPI OFF)
option(SDL_DSU_JOYSTICK "Enable DSU client joystick support" ON)
dep_option(SDL_DSU_JOYSTICK "Enable DSU client joystick support" ON SDL_JOYSTICK OFF)
set_option(SDL_LIBUDEV "Enable libudev support" ON)
set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF)
set_option(SDL_CCACHE "Use Ccache to speed up build" OFF)

File diff suppressed because it is too large Load diff

View file

@ -71,6 +71,7 @@ typedef struct DSU_ControllerSlot {
/* Motion data */
bool has_gyro;
bool has_accel;
bool sensors_enabled; /* Track if SDL enabled sensors */
float gyro[3]; /* Pitch, Yaw, Roll in rad/s */
float accel[3]; /* X, Y, Z in m/s² */
Uint64 motion_timestamp;
@ -87,9 +88,16 @@ typedef struct DSU_ControllerSlot {
/* Timing */
Uint64 last_packet_time;
Uint32 packet_number;
/* Back-reference to parent server connection */
struct DSU_ServerConnection *parent_conn;
} DSU_ControllerSlot;
typedef struct DSU_Context_t {
/* Maximum number of DSU servers that can be connected simultaneously */
#define DSU_MAX_SERVERS 4
/* Per-server connection state */
typedef struct DSU_ServerConnection {
/* Network */
dsu_socket_t socket;
SDL_Thread *receiver_thread;
@ -98,15 +106,29 @@ typedef struct DSU_Context_t {
/* Server configuration */
char server_address[256];
Uint16 server_port;
Uint16 client_port;
Uint32 client_id;
/* Controller slots (4 max per DSU protocol) */
/* Controller slots (4 max per DSU server) */
DSU_ControllerSlot slots[DSU_MAX_SLOTS];
SDL_Mutex *slots_mutex;
/* Timing for periodic updates */
Uint64 last_request_time;
/* Back-reference to parent context */
struct DSU_Context_t *parent;
int server_index;
} DSU_ServerConnection;
typedef struct DSU_Context_t {
/* Server connections */
DSU_ServerConnection servers[DSU_MAX_SERVERS];
int server_count;
/* Client port (shared across all servers) */
Uint16 client_port;
/* Shared mutex for all slots */
SDL_Mutex *slots_mutex;
} DSU_Context;
#endif /* SDL_JOYSTICK_DSU */