WIP: feat(input): custom gyro aiming with per-item aim detection #699
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!699
Loading…
Reference in a new issue
No description provided.
Delete branch "kendowashere/Longshot:feat/gyro-aim"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: feat · Risk: low · Tested on: Windows 11, RTX 5070 Ti, DualSense · Needs: Linux, any GPU
Why
The game's own motion aiming has a dead zone and smoothing, and it only works where the game turns it on. Players used to mouse-like gyro (as in controller remappers) have no way to get it here, nor a choice of how the controller's turn becomes a camera turn. This adds that as an opt-in Custom Motion style. It is a port of the custom gyro in NX2navi, a static recompilation of the same game build: https://github.com/tangerineturtle1/NX2navi/pull/955. Issue #974 asks for a way to recalibrate the gyro against drift and for an adjustable gyro dead zone: the Custom style's Gyro dead zone row is the second, and a Recalibrate gyro row, added here, is the first.
What changed
The Motion page's new Motion style row is Original (the game's own motion aiming, the default) or Custom: the controller's turn goes straight into the camera, 2.0 degrees of camera per degree of controller by default, with no smoothing, at any frame rate and Camera speed. While Custom turns the camera, the game's six-axis sensor reads the pad at rest, so the two never add up.
nx2/oot_patches.pypatch_gyro_aim: two calls in the camera input update,f_8039c300.hos_gyro_aim_cameraadds the gathered turn to the processed stick (s1 x, s0 y) before its first store, so the game's inversion, idle test, camera speed and Link's aim follow it as they follow the right stick;hos_gyro_aim_activityclears the idle bit before the last flags store when the gyro moved the camera.host/gyro_aim.c,host/gyro_aim.h: the maths and the game reads. The spaces (what a gyro space is, and how the different ones turn the camera, is explained on Gyro Wiki: https://gyrowiki.jibbsmart.com/blog:player-space-gyro-and-alternatives-explained): Player space (the default), World space, Local yaw, Local roll, Local yaw + roll and Laser pointer (aims where the controller points, with no dead zone or tightening). Then the dead zone, the tightening (a turn slower than it is scaled down in proportion), and the touchpad pause. The turn is divided by the engine's frame step and the Camera speed row, so a degree of controller turns the same angle at any frame rate.hos_gyro_aim_owns_sensor,host/nn_hid.c).host/pad_sdl.c,host/hos_sdl.c: every 4 ms poll feeds the real rate with the filter's learned bias taken off, the filter's up direction, and whether a finger rests on the touchpad (hos_sdl_pad_touched, for SDL 2 and 3).gpu/vk/vk_menu.cpp,vk_menu.h,vk_replay.cpp,vk_api.h: the rows, in order: Motion style, then while it is Custom: Gyro active, Gyro space, Horizontal sensitivity, Vertical sensitivity, Gyro dead zone, Gyro tightening, Touchpad pauses gyro. Option ids 80 to 87 (no open pull request uses them).gpu/vk/menu_i18n.h: the texts in all 13 languages.host/hos_motion.h) already learns the gyroscope's resting rate whenever the pad lies still, quickly for its first 2 s of stillness (a quarter second's average), then slowly (3 s), so drift that changes later in play (a pad warming up) takes long stillness to follow. A press starts that learning over in its quick phase, from the bias it had (host/pad_sdl.c:learned_tandstill_tback to 0, the pad's saved bias dropped), and the row says what happens: Set it down, then Done once 2 s of stillness are learned again, or No motion controller. The menu counts presses inopts.gyro_recalibrate(option id 88, read by the pad thread as a change), and the pad thread says back throughrx_option_set(id 89,menu_option_set); neither is kept in the options file, and no interface struct changes. The log sayshid: motion: recalibrating "..."and... recalibrated, bias (...).row_shown). Its help says so.README.md: the option table and a paragraph.tests/gyro_aim_test.c,tests/test_gyro_aim.py: new;tests/test_damage_debug_menu.py: the row helper is listed in its stub, asis_laptop_rowis;tests/test_menu_tune.py: its pinned prompt line now has the Recalibrate gyro row's Start.Measurements
Verdict: nothing to measure: an input feature that is off by default; with Motion style on Original the two added calls return at once and the game's own motion path is unchanged.
Flags and settings
Eight new menu rows on the Motion page (ini keys
motion_style,gyro_active,gyro_space,horizontal_sensitivity,vertical_sensitivity,gyro_dead_zone,gyro_tightening,touchpad_pauses_gyro), no switch and no build flag. The README's option table lists them.motion_style, id 80)gyro_active, 82)gyro_space, 81)Testing
Tested:
tests/test_gyro_aim.pycompiles the maths with synthetic readings (each space's turn however the controller is held, dead zone, tightening, the touchpad pause, the laser pointer returning to its start, the aim gate for each item and the cases that must not count), applies the patch to a fixture of the lifted function (once, and again unchanged; I also applied it by hand to the real liftedf_8039c300of a build: one hook each, again unchanged), and checks that the rows reach the host and the defaults. It also checks the Recalibrate gyro row's wiring: the press counted, the reset after a new pad's filter is made (so the press wins over the pad's saved bias), Done when 2 s are learned, the no-pad case, and nothing in the options file (it fails with the press count removed).python -I -B tests/run_all.pyon this branch (86d954d1) onmain@e41de662: 583 passed, 24 failed, 41 skipped; a cleanmain@e41de662on this PC: 581 passed, 25 failed, 41 skipped, the same 24 andtest_mesh_args_cleanup, which passes on the branch.main@6c9edffe, before the rebase ontoe090cc48, which touches none of this branch's files. With Motion style Custom and Gyro active When the game allows, aiming the bow or slingshot and the hookshot turns the camera with the controller and the log says so (gyro: the game aims: the custom gyro turns the camera (Link's item in use 3), and... 4for the hookshot); outside an aim it reportsgyro: no aim (Link's item in use 0)and the camera is left alone. It plays well.host/gyro_aim.c,host/hos_sdl.c,host/pad_sdl.candhost/nn_hid.ccompile for a Linux target (clang-fsyntax-onlyagainst the Linux sysroot's own headers andhost/posix's compatibility layer, on a build tree with both of my branches merged). The same check passes on untouched host files and fails withouthost/posix, so it can tell. That is not a Linux build, link or run: the renderer's C++ files and the shader and game build were not compiled for Linux.Not tested: the Recalibrate gyro row in the game (built and installed with my other branches, waiting for a run); the boomerang's and the fishing rod's cast aims (the same gate, not in the log of the run above); the Gyro spaces other than Player space in the game (their maths is in the game-free test); Always; Linux; a Steam Deck; controllers other than a DualSense (Switch Pro, DualShock 4's touchpad).
Must be tested:
host/gyro_aim.cuses the same locking calls as the other host files;host/hos_sdl.c's touchpad calls name SDL 2's and SDL 3's functions) and the game starts with Motion style on Custom (asked of the Test Farm on this PR: build and start the game, open Controls > Motion and set Motion style to Custom, expecting the seven rows below it to appear and aiming the bow to turn the camera with a gyro pad).Risks
What could break: the camera input update (
f_8039c300) now calls the host twice a frame, and a pad's reading feeds the custom gyro on the polling thread. Both return at once on Original. A wrong aim gate would leave the camera still while aiming (the game's own motion aiming takes over outside the gate), never turn it without an aim under When the game allows.Turning it off: Motion style Original (the default), or revert the commit.
Compatibility: the options file gains eight lines (an older file keeps its values and reads the defaults for these). The player's next build translates the game again because the lifted camera function changes, as for any change to
nx2/oot_patches.py. The shader and pipeline caches andMKWVK_API_VERSIONare untouched (the option ids are newHOS_OPT_*numbers and no struct changed, as when the earlier options such asHOS_OPT_HOLD_TOGGLEwere added).Issues
See #974 (recalibration and a gyro dead zone; it can close once this is merged).
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks. Not ticked yet: Two per-frame host calls and the polling-thread gyro work are stated as costs, with no timing given.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.tests/that reads changed source updated in this PR, not weakened.6fb56e871be5e5de5b74e5e5de5b74f0678ba305Rebased onto
main@7bacf846: conflicts in gpu/vk/menu_i18n.h: main dropped the "VRAM budget" entries, so they are dropped here too and the per-language entry counts inkLangsrecomputed (checked against the arrays). No tests were run here; the test boxes stay yours.@Beanstalk On Linux, with a controller that has a gyroscope (DualSense, Switch Pro Controller, Joy-Con or Steam Deck): build this branch and start the game. Open Controls > Motion and set Motion style to Custom: the seven rows below it should appear. In the field, aim the bow (or slingshot, hookshot, boomerang): moving the controller should turn the camera, and the camera should stay still from motion when not aiming. Then set Motion style back to Original: the game's own motion aiming should behave as on main. Pass: it builds and starts, the rows are there, and gyro aiming works as described. Please copy any log line containing 'gyro'.
@kendowashere only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it.This request was forf0678ba, and the PR has changed since (86d954d), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.f0678ba30586d954d162theguyser referenced this pull request2026-11-16 13:51:42 +00:00
Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.