#273

Touch stick: reach full speed in half the travel (30 points, square-root curve)

OpenDiablo-chia619wants to merge intofrom

Split out from the side-by-side build as requested in #256: stick only, no driver code, no save-import, no packaging.

Problem

Full deflection took 60 points of finger travel with a linear response curve. On a phone that means:

  • a small push made the character move at a crawl (the first ~15 points are nearly dead feel)
  • reversing direction needed a 120-point sweep: players lifted the finger and pressed again instead of steering back

Change

beforeafter
travel to full speed60 points30 points
response curvelinearsquare root
runtime override—DM_TOUCH_STICK_TRAVEL (12..60; files/dm/env, restart, no rebuild)
thumb positiondrawn from the value sent to the gamedrawn from the real finger position (joy_px / joy_py), so it no longer runs ahead of the finger
base / thumb visual sizeunchangedunchanged

With the square-root curve a couple of millimetres already moves the character, and full speed arrives inside 30 points, so a direction change costs 60 points instead of 120 — no need to lift the finger.

Shared code: this affects iOS and HarmonyOS too

dm/ios/Sources/dm_touch_controls.c is the shared touch-control implementation, not Android-only, so the new mapping applies to iOS and HarmonyOS builds as well. Both get the same way back without a rebuild: DM_TOUCH_STICK_TRAVEL accepts 12..60, and anything outside that range falls back to 30. If either platform wants to keep 60 as the default, that is a one-line change in stick_travel() — say so and I'll flip it.

Tests

  • dm/ios/tests/t_joy_travel.c — updated for the 30-point travel and the square-root mapping; the three expectations that still held the old linear values are fixed in cdee72f (thanks @yyan160)
  • dm/android/tests/test_touch_snapshot.c — updated thumb position (now the finger position)

t_joy_travel builds and passes locally on Windows with MSVC 19.44 (cl /std:c11 /experimental:c11atomics): JOY_TRAVEL OK 48 项. @yyan160 ran both harnesses on Linux (gcc 14, the flags from dm/ios/tests/Makefile): test_touch_snapshot.c passes, and t_joy_travel passes after this fix. CI still has the final say.

How it was tuned

30 points came out of playing on a phone (the same device as the reports in #256). The env var exists precisely so nobody has to rebuild to compare values — @jhaizhou-ops @biglawine, if 30 feels too twitchy on your hardware, try 40 / 50 from files/dm/env and tell me which number you settle on, and I'll make it the default.

Activity

4
yyan16014d ago

Thanks for splitting this out! I ran both tests on Linux (gcc 14, with dm/ios/tests/Makefile's flags -std=c11 -Wall -Wextra -Werror -pedantic -O2):

  • dm/android/tests/test_touch_snapshot.c: passes (RESULT PASS cases=16 assertions=6770).
  • dm/ios/tests/t_joy_travel.c: fails at line 18: FAIL line=18 abs(push(&s, w, h, 20) - 25032) <= 2.

The code does what the PR describes; three of the test's expected values are off:

pushthe code givesthe test expects
20 points√(14/24) × 32767 = 2502625032 ±2 (hand-calc slip)
33 points32767 (full speed from 30 points on)16384 (still the old linear half); half is now at 12 points, √(6/24) = 0.5
−20 points−25026−8495 (old linear value)

With these three lines the test passes (JOY_TRAVEL OK 48 项):

        CHECK(abs(push(&s, w, h, 20) - 25026) <= 1);                     /* sqrt(14 / 24) × 32767 = 25026 */
        CHECK(abs(push(&s, w, h, 12) - 16384) <= 1);                     /* sqrt(6 / 24) = 一半 | sqrt(6 / 24) = half */
        CHECK(abs(push(&s, w, h, -20) + 25026) <= 1);

One small thing: the description pings @haizhou-ops, but the maintainer's handle is @jhaizhou-ops.

Diablo-chia61914d ago

You're right on all three, and none of them had an excuse: 25032 was my hand-calc slip, and the 33 / -20 lines were leftovers from the old 60-point linear mapping — they never got rewritten when the curve changed, so the test was still asserting the old feel.

Fixed in cdee72f with exactly the three lines you listed:

pushassertion now
20 points25026 ±1
12 points16384 ±1 (half speed now sits at 12 points, replacing the old 33-point half line)
−20 points−25026 ±1

I also built and ran it here on Windows with MSVC 19.44 (/std:c11 /experimental:c11atomics, the same C11 mode): JOY_TRAVEL OK 48 项, so it now agrees with your gcc 14 run. dm/android/tests/test_touch_snapshot.c was untouched — no need to re-check it on my account, but thanks for running both.

And the description now pings @jhaizhou-ops. Thanks for the careful read — the third one in particular (half at 12 points) is the assertion that actually pins the new feel down, so I'm glad it's in there instead of the stale linear value.