Skip to content

Switch HD vibration on iOS: nn::hid's rumble goes to Core Haptics - #86

Closed
4202217 wants to merge 1 commit into
seedds:mainfrom
4202217:feature/haptics-and-reclaim
Closed

4202217 wants to merge 1 commit into
seedds:mainfrom
4202217:feature/haptics-and-reclaim

Conversation

@4202217

@4202217 4202217 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

nn::hid's six vibration entry points were all "not provided" stubs (IsVibrationPermitted → 0, GetVibrationDeviceHandles → 0 devices, the rest no-ops), so a game's rumble never reached anything on iOS or on a connected controller. They now carry the game's NVNvibrationValue pairs to a host-side mixer and feed a sink.

Split out of #86 on the reviewer's advice: the device result covers this work only, and the two memory features now live in their own PR.

What moves where

  • dm/host/hle_haptics.c / .h — the mixer. The game writes the two motors (low and high band) microseconds apart with the same value; the mixer adds both motors' energy and samples a settled pair, so a level neither motor was ever at can never be produced. It follows the hardware's amplitude / frequency band mapping, and applies GeneralRumbleMultiplier the way the game does (measured 0.030 / 0.060 / 0.119 at 50 / 100 / 200% in the save's Profile<N>.sjson) — the host deliberately does not cancel it, so the in-game slider is what the player feels.
  • dm/ios/Sources/Haptics.m — the iOS sink: Core Haptics engines, one per motor channel, created from dm_haptics_ios_init() in startGame before front_ios_boot(), so the guest sees the devices when it initializes nn::hid. Focus loss, route changes and interruptions clear the state; a resume needs a new game signal.
  • dm/host/hle_hid.c — the six entry points. Handles are (npad << 8) | motor, two per controller; GetVibrationDeviceInfo describes a linear resonant actuator with position 1 = left, 2 = right; GetActualVibrationValue returns the last value the sink accepted.
  • dm/host/Makefile — -framework CoreHaptics. The iOS project takes its frameworks from this line through dm/ios/tools/gen_build.py, so no Xcode project file changes.
  • dm/host/tests/t_haptic_mixer.c — the mixer on its own, no device needed.

No sink, no change. On the Mac host without DM_HAPTIC_FAKE=1 the sink pointer stays null: IsVibrationPermitted answers 0 and GetVibrationDeviceHandles answers 0 devices, which is exactly what every game saw before. t_hid builds against the sink so the hid take-overs are still tested.

Tuning knobs: DM_HAPTIC_OFF=1 disables output, DM_HAPTIC_GAIN=<float> sets the output gain (default 3.0, range 0-10; 0 = raw mapping), DM_HAPTIC_FAKE=1 logs the mixed values with no sink installed, DM_HAPTIC_TRACE=<path> writes a TSV of every value the game sends (the guest thread only copies into a ring; a writer thread does the file I/O).

Verification

  • make -C dm/host/tests GAME=0100A00019DE0000 run — passes, including t_haptic_mixer (one motor at 0.119 → 0.505, both at 0.105 → 0.630, both at 0.119 → 0.714, suspend silences, resume does not fire a phantom rumble) and t_hid (44 checks).
  • Mac, Hades II (base game): boot → title → save, scripted input; DM_HAPTIC_FAKE=1 logs the game's request vibration value #1 frame 1002 0.119/160Hz 0.119/320Hz (gain 3.0, game multiplier 2.00) and the mixed output I=0.505 S=0.625. The title → save A presses alone produce no vibration — the swings and hits after them do.
  • iOS: Haptics.m compiles clean against the iphoneos SDK with ARC.

Not verified here: the Core Haptics feel on a real device. Core Haptics intensity / sharpness is an adaptation of the game's two-motor bands to a phone's single actuator; I have not checked how the Taptic Engine renders these values, and I have not confirmed left/right localities on physical Joy-Con or equivalence to two motors. A contributor reported game-driven rumble on an iPhone for an LM3 build of this boundary (see the comment below) — that was their own local adaptation, not this branch, and it covers the game-rumble path only.

🤖 Generated with Claude Code

@Jpkovas

Jpkovas commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Physical-device feedback for the vibration work: the player confirmed game-driven rumble on an iPhone while running LM3 1.4.0. Touch-control feedback was also felt, through a separate UIKit press-edge implementation.

Important scope: this was a local haptics-only adaptation of the boundary proposed here, not your unmodified PR head 9f5c1ecc3117e0123f3e29259378ca3d771af61c. It did not include pool_renew or tex_reclaim, so it provides no validation of either memory feature.

The local integration exposes the active player-1 vibration channels, retains sanitized last values, and forwards snapshots to a coalescing serial queue. Focus loss, route changes and interruptions clear prior state; resume requires a new game signal. We kept touch feedback and game rumble as independent launcher settings. Standalone mixer tests and HID tests passed; the platform sink logged a phone route and the player confirmed the physical result.

Core Haptics intensity/sharpness is an adaptation of the game's bands to the phone's single actuator. We have not confirmed left/right controller localities on physical hardware or equivalence to two Joy-Con motors, and we have not independently verified the tactile result in ACNH.

Keeping the vibration work separate from the two memory features would make the device result easier to review and merge. Our LM3 investigation instead points to numerous private render-target variants over shared NVN storage; it is not evidence that the packaged-source reclaim measured for Hades II will fix that workload. No game files, audio, saves, screenshots or raw device logs are attached.

The host answered nn::hid's seven vibration calls with "no devices", so every
game saw no rumble at all. Now the two Switch motors are mixed on the host and
played by the Taptic Engine or a connected controller.

- hle_haptics.c mixes a device's low / high band pair into the one intensity and
  sharpness pair Core Haptics takes: the bands' energies add (a two-motor rumble
  is not just its stronger motor), sharpness follows the amplitude-weighted
  frequency, and a dynamic attack / release keeps a held rumble from stuttering
  at the value changes. A rumble ends on the game's own zero; the silence
  watchdog only backstops a game that stops writing, and its 120 ms floor
  applies only to rumbles that really were shorter than that.
- Haptics.m runs one Core Haptics engine per target: the Taptic Engine on the
  phone, and a separate pattern player for a physical controller. It suspends on
  backgrounding and on an audio interruption, and invalidates the epoch so
  nothing queued before the pause fires afterwards.
- hle_hid.c: the seven vibration HLEs forward to the sink. With no sink (the Mac
  host without DM_HAPTIC_FAKE) they report exactly what they did before, no
  devices, so nothing changes for a game that cannot feel anything.
- The game's own strength setting is left alone: it already multiplies the
  amplitude before the call, so the in-game slider is what the player feels.
  DM_HAPTIC_GAIN (default 3) only compensates for the Taptic Engine being much
  weaker than a Joy-Con at the same amplitude; 0 = the raw mapping.
- DM_HAPTIC_FAKE, DM_HAPTIC_OFF, DM_HAPTIC_TRACE, DM_HAPTIC_TRACE_ALL and
  DM_HAPTIC_GAIN are diagnostic switches; none is needed to play.
- t_haptic_mixer.c pins the mixer's arithmetic: two motors beating one, no
  phantom level between the two amplitudes, the attack not freezing a rumble
  that stops writing, and suspend / resume not replaying an old value.

Measured on a Hades II rumble (295 ms): the right motor alone at 0.119, then both
at 0.105. The mixer's output is 0.505 and then 0.630 at gain 3.

Co-Authored-By: Claude Code <[email protected]>
@4202217
4202217 force-pushed the feature/haptics-and-reclaim branch from 9f5c1ec to 2b7e392 Compare October 24, 2026 02:14
@4202217 4202217 changed the title Haptics on iOS, and two guest-memory reclaim layers for NVN Switch HD vibration on iOS: nn::hid's rumble goes to Core Haptics Oct 24, 2026
@4202217

4202217 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Split as suggested: this PR now carries the vibration work only (one commit on top of main). The two memory features moved to #103, so the device result above stays with the work it actually covers.

Nothing in the vibration code changed in the split; the branch was rebuilt on the current main and re-checked (t_haptic_mixer and t_hid pass, a Mac run of Hades II still logs the game's request and the mixed output).

seedds added a commit that referenced this pull request Oct 24, 2026
Preserve per-player motor state and SDK vibration handles, apply batches atomically, and route Core Haptics output through existing controller assignments. Add independent launcher controls and lifecycle tests.

Supersedes #86. Physical feel and controller compatibility still require device testing.
@seedds

seedds commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Thanks for proposing the game-rumble path. This is now implemented on main in 3eb1d76, so I am closing this PR as superseded.

The implementation preserves SDK handle encoding and independent player/left-right motor state, commits vibration batches atomically, and shares Core Haptics output between iOS and Mac controllers. It uses separate controller localities when available and a combined phone output, follows existing player assignments, and adds independent Game rumble and Rumble strength launcher settings. Effects retain their requested timing, with state cleared on lifecycle and route changes.

Validation passed: the host test suite, 60 HID checks, rumble state and Apple adapter tests with fake engines, the Mac host build, iOS compilation checks, and iOS build-input/settings generation. Physical feel and controller compatibility still need device testing; the device feedback on this PR is not being claimed as validation of this implementation.

The memory-reclaim work in #103 and the LM3 memory issue #100 remain separate and open.

@seedds seedds closed this Oct 24, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Preserve per-player motor state and SDK vibration handles, apply batches atomically, and route Core Haptics output through existing controller assignments. Add independent launcher controls and lifecycle tests.

Supersedes seedds#86. Physical feel and controller compatibility still require device testing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants