From 764b5d938bfc67d7569f9ab513bfc7c91749ec80 Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Mon, 13 Jul 2026 22:24:03 +0200 Subject: [PATCH] fix(gamepad): resolve the menu diagonal tie-break horizontally on all clients (G25) The gamepad-UI navigation resolvers disagreed on which way a perfect 45-degree stick push (|x| == |y|) resolves: the SDL core picked horizontal (`ax >= ay`) while Apple (`abs(x) > abs(y)`) and Android (`abs(Y) >= abs(X)`) picked vertical. Align Apple (`>` -> `>=`) and Android (`>=` -> `>`) to the SDL core so an exact diagonal moves focus the same way on every client (horizontal wins). This is client-local menu navigation only and never reaches the wire. Completes the last deferred G25 sub-part. Verified: Apple `swift build` + full suite (124 pass); Android `:app:compileDebugKotlin`. Co-Authored-By: Claude Opus 4.8 --- .../app/src/main/kotlin/io/unom/punktfunk/GamepadNav.kt | 5 ++++- .../Sources/PunktfunkKit/Gamepad/GamepadMenuInput.swift | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clients/android/app/src/main/kotlin/io/unom/punktfunk/GamepadNav.kt b/clients/android/app/src/main/kotlin/io/unom/punktfunk/GamepadNav.kt index a9e8994b..dd98af48 100644 --- a/clients/android/app/src/main/kotlin/io/unom/punktfunk/GamepadNav.kt +++ b/clients/android/app/src/main/kotlin/io/unom/punktfunk/GamepadNav.kt @@ -241,7 +241,10 @@ private fun resolveDir(s: NavInputState): NavDir? { if (s.hatY >= 0.5f) return NavDir.DOWN if (s.hatX <= -0.5f) return NavDir.LEFT if (s.hatX >= 0.5f) return NavDir.RIGHT - return if (abs(s.stickY) >= abs(s.stickX)) { + // Horizontal wins an exact |x| == |y| diagonal tie (Y must be strictly greater to take the + // vertical branch), matching the SDL core and Apple nav so a perfect 45° push resolves the + // same on every client. + return if (abs(s.stickY) > abs(s.stickX)) { when { s.stickY <= -STICK_HIGH -> NavDir.UP s.stickY >= STICK_HIGH -> NavDir.DOWN diff --git a/clients/apple/Sources/PunktfunkKit/Gamepad/GamepadMenuInput.swift b/clients/apple/Sources/PunktfunkKit/Gamepad/GamepadMenuInput.swift index fb6d21e6..d162ebeb 100644 --- a/clients/apple/Sources/PunktfunkKit/Gamepad/GamepadMenuInput.swift +++ b/clients/apple/Sources/PunktfunkKit/Gamepad/GamepadMenuInput.swift @@ -140,7 +140,9 @@ public final class GamepadMenuInput { let stick = gamepad.leftThumbstick let x = stick.xAxis.value let y = stick.yAxis.value - if abs(x) > abs(y), abs(x) > deadzone { + // Horizontal wins an exact |x| == |y| diagonal tie (>=), matching the SDL core and Android + // nav so a perfect 45° push resolves to the same direction on every client. + if abs(x) >= abs(y), abs(x) > deadzone { return x > 0 ? .right : .left } else if abs(y) > deadzone { return y > 0 ? .up : .down