feat(input): show a notice when a controller's battery is low, when it disconnects and when it connects #1092
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1092
Loading…
Reference in a new issue
No description provided.
Delete branch "lg/Longshot:feat/controller-notices"
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 4090 (621.24), a DualSense over Bluetooth · Needs: an Xbox and a Switch controller; a run on Linux; Steam Deck
Why
A controller that runs out of battery just stops answering, and nothing on screen says why. The game never asks for
a controller's battery: on the console the system shows the low-battery notice and the controller screen, and
Longshot had nothing in their place.
No issue asks for this (tracker searched: battery, disconnect, controller connected).
What changed
Longshot now shows a short notice at the top of the screen, in the menu's style and language, when a controller's
battery gets low, when it gets very low, when a controller disconnects (saying if its battery was low) and when one
connects during play. Each shows for 6 to 12 seconds; the game is not paused. The game's own pause menu names the
controller on its System page, under the controller picture of "Basic Controls", with its battery percentage when it
reports a measured one (a DualSense or DualShock 4) and a bolt while it is plugged in. A controller that reports no
battery gets only the connected and disconnected notices, and under Steam Input that is the case whenever the game is
given only Steam's stand-in controller.
host/pad_battery.h(pure). Low and very low follow what each controller reports through SDL: DualSense andDualShock 4 count in tenths (20% and 10%, the number shown); Xbox controllers warn at 40% and 10% and Switch
controllers at 25% and 0%, with no number shown (SDL gives them as four and five levels); SDL2 and XInput give four
steps. Each warning shows once as the battery falls. No new warning while the controller is plugged in, and one on
screen goes after five readings plugged in (about 5 s through SDL, about 25 s through XInput).
host/pad_battery.ckeeps a queue of notices: a new one replaces the same controller's earlier ones;otherwise the one on screen plays out, then the most urgent waiting one. A notice's time counts only while the
player can be looking: the game's window in front (or an overlay over it), or the controllers set to count in the
background.
pads_poll(host/pad_sdl.c, once a second, through the newhos_sdl_pad_power) and,only when SDL's controller support is not there,
pads_read(host/nn_hid.c, XInput) report controllers to it.host/oot_menu.cfinds the System page in front from the game's own menu hooks, on Windowsand Linux (one of the page's panes took the focus last, and its screen still updates);
host/hos_wide_ui.cnotes thepane that shows the page's panel as it is placed and reads where it is when asked, so the line slides in with the
page. It hides on the other pages, under a screen opened from the page (Load, Options), under the Insert menu and
when the menu closes.
MkwVkHost.pad_noticeandpad_status(MKWVK_API_VERSION30);draw_pad_noticeanddraw_pad_statusin
gpu/vk/vk_menu.cpp; the notice's five texts in each menu language (gpu/vk/menu_i18n.h).tests/test_pad_battery.pyandtests/test_pad_panel.py(new);test_fps_overlay_order.py,test_pads_after_menu.py,test_hold_toggle.pyandtest_audio_output_devices.pyupdated for the changedfunctions and the new version (the audio check pinned version 29 and the interface's last members).
docs/development.md, and the guide-image review note.Limits:
and controllers SDL reads through the plain Linux joystick driver. The log says so once.
wider screen than 16:9 its place follows the menus' fit but was not looked at.
for the seconds it shows (second sheet below).
Measurements
Verdict: it works in the game (screenshots below), and no frame-rate cost was measured while no notice shows: standing still, main 80.2 / 80.0 fps, this PR 80.5 / 80.6, this PR with the notices off 80.9 / 80.75. Through the controller going and coming back, with the disconnected and then the connected notice shown, the six 5 s readings are 79.3 to 80.6 fps on main (median 79.55) and 79.5 to 80.6 here (median 79.85): no difference beyond the noise of so few samples, and the readings cover more than the notices themselves.
Hardware: Windows 11, RTX 4090 24 GB, driver 621.24, Core i9-10900K, 32 GB
Scene: the village, by its gate, daytime, standing still where the save loads; 3840x2160, DLAA, frame generation off, no frame rate cap, V-Sync off, HDR off (read back from each run's log)
Method: the
vi:lines oflongshot_log.txt(fps over 5 s). Standing still: 60 s from 25 s after the save loaded, main, this PR and this PR with the switch in turn, twice, after a warm-up launch of each build; the median of each run's 12 lines. The controller going and coming back: its device switched off in Windows, 5 s, switched on, 6 s, main and this PR in turn, twice; the three lines that end in that time (each covers 5 s, so they reach back before the disconnect)How to reproduce: load a save standing still with a controller connected, the settings above, and read the log's
vi:lines;HOS_PAD_NOTICE=0inlongshot_env.txtfor the third columnCommits:
9f0dd23is this PR's code commit, on main544229a. The builds that ran name themselves 3938f4c (the Insert menu's banner in the second sheet too): that commit with an earlier set of run files. The head974550ediffers from it only underdocs/tested/544229a9f0dd239f0dd23HOS_PAD_BATTERY_TEST; its own reading was 85%, on its battery)DualSense Wireless Controller: 85%under the controller pictureThe log lines
Flags and settings
Two new switches, no menu row (
HOS_HEADLESS,HOS_WINDOW_NOACTIVATE,HOS_INPUT_BACKGROUNDandHOS_MENU_TRACEin the diff are existing ones, only read).HOS_PAD_NOTICE=0=0: run in the gameHOS_PAD_BATTERY_TEST=<percent>[,xbox|switch|sony][,plugged]pluggedreads it as plugged in5,15,40,xboxand0,switch: run in the game;plugged: the game-free test onlyTesting
Tested:
python -I -B tests/run_all.py: 608 passed, 37 failed, 78 skipped (on 3938f4c; the head differs only underdocs/tested/, whose check passes for this PR's files and fails on main for another's). main544229aonthat PC: 606 passed and the same 37 failed (
test_bug_report,test_bug_report_defaults,test_cpu_report,test_crash_groups,test_crt_options,test_damage_debug_menu,test_display_startup_failure,test_dlss_feature_size,test_failed_compile_keeps_objects,test_framegen_preset,test_guest_imported,test_hardware_report,test_hud_layout_row,test_invalidate_vcore,test_linux_preflight,test_linux_pressure,test_linux_update,test_mirror_budget,test_missing_nup,test_mods_size_table,test_pending_guest_import,test_pipeline_play_cache,test_present_thread,test_profiling_mode,test_readback_timeout_source,test_rumble_menu,test_run_all_changed,test_slow_frames,test_switch_table,test_target_image_pool,test_tested_configurations,test_upscaler_round_trip,test_upscaler_rows,test_vcore_escape,test_vk_occlusion_queries,test_vk_swapchain_compat,test_walk_key).RX_TARGET=windows, llvm-mingw 20261104), main and this PR.scripts/dev_build.py build --quick, Ubuntu 26.04, tools.lock's tools):longshotandlongshot_vk.socompile and link. Not run there: that PC has no GPU.9f0dd23, Windows 11, RTX 4090 (driver 621.24), one DualSense over Bluetooth on its battery, SDL 3.4.20,4K: nothing shown at launch, each notice over the game, the low and very low ones over the open Insert menu, German
at the Large menu size, an Xbox and a Switch controller simulated (
HOS_PAD_BATTERY_TEST=40,xboxand0,switch:the warning with no number), and no notice with
HOS_PAD_NOTICE=0(that the pause menu then names no controller iscovered by the game-free test only). The low and very low warnings came from
HOS_PAD_BATTERY_TEST; connecting and disconnecting from switching the controller's device off and on in Windows.opened from it and back on return; gone on the Items page and back; gone under the Insert menu; gone with the
controller disconnected and back with it; gone with the menu closed and there when it opens again on that page;
15%and an Xbox controller's name alone fromHOS_PAD_BATTERY_TEST. The presses were sent withHOS_INPUT_LIVE.plugged in, its battery at 100%), several notices one after another, and a notice that came up behind another window still there on comingback.
Not tested:
and pulled on purpose.
rules are covered by the game-free test, from SDL 3.4's source, and the Xbox and Switch notices by the simulation.
drawing showed it on the Insert menu in earlier builds).
16:9, and in the game's other languages (the line itself is a name and a number).
Must be tested:
HOS_PAD_BATTERY_TEST=40inlongshot_env.txt, expecting ahid: "(its name)": on its battery, its battery at about N%line inlongshot_log.txtthe first time and "Controller battery low" with no percentage the second (by hand: the log line and the notice)HOS_PAD_BATTERY_TEST=25, expecting the same kind of log line and "Controller battery low" with no percentage (by hand: the log line and the notice)hid: "(its name)": ...line in the log saying what was read of its battery (Test Farm: asked in a comment,@Beanstalk on Linux: ...)no battery reading from it so farin the log, or a battery line if the Deck's controls turn out to report one (Test Farm: asked in a comment,@Beanstalk on the Steam Deck: ...)Screenshots
Before: main @
544229a· After: this PR @9f0dd23. The same save, the same spot, 3840x2160. The battery levels are set withHOS_PAD_BATTERY_TEST; the Xbox and Switch controllers are simulated with it on the DualSense.Risks
What could break: a controller that misreports its battery gets a warning it should not; a virtual controller that
reconnects by itself would be announced each time; the pause menu's line reads the game's own menu objects each frame
that page shows (as the mouse in the game's menus does), so a game version they do not fit shows no line.
Turning it off:
HOS_PAD_NOTICE=0.Compatibility:
MKWVK_API_VERSIONis 30: the game and its renderer must come from the same build, as before. Saves,longshot_options.iniand the caches are not touched.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: Risks names a per-frame menu read on the pause page, but no measurement covers that page.
main. (main @544229a)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.docs/tested/for each new measured run (format indocs/tested-configurations.md).MKWVK_API_VERSIONbumped (gpu/vk/vk_api.h'sMkwVkHostorMkwVkRendererchanged).tests/that reads changed source updated in this PR, not weakened.scripts/dev_build.py build --quick. No path code changed.)🤖 Generated with Claude Code
Tested in game: RTX 4090, driver 621.24, Windows 11, one DualSense over Bluetooth, 3840x2160: the village by its gate. Each notice showed over the game (battery low, very low, disconnected, disconnected with its battery low, connected), the low and very low ones over the open menu too; the Controls tab named the controller with 100% and the charging bolt; nothing showed with HOS_PAD_NOTICE=0. The low levels and the Xbox and Switch cases were set with HOS_PAD_BATTERY_TEST; connecting and disconnecting by switching the controller's device off and on in Windows. Run on 0922406, this branch's code commit before its last rebase over commits the game does not run (the builder and scripts).
@Beanstalk on Linux: build this PR and start the game, with a controller connected if one is at hand; play a minute. Check that the build succeeds, that no controller notice shows at the start, and report the log's
hid:lines about the controller (its battery reading, or "no battery reading from it so far"). A picture of the Insert menu's Controls tab, please.@Beanstalk on the Steam Deck: start the game and play a minute with the Deck's own controls. Check that no controller notice shows over the game, and report the log's
hid:lines about the controller ("no battery reading from it so far" is expected). A picture of the game, please.@lg only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it.This request was for904aba7, and the PR has changed since (d59d240), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.904aba71fcd59d240006Rebased onto main
55e8fbd(cc194ad,d59d240). main's microphone test took interface version 25, so this change's two members now follow it and the version is 26; the two audio checks that pinned 25 and the last member are updated. The whole game now builds for Linux too (scripts/dev_build.py build --quick, Ubuntu 26.04): that box is ticked. The rebased change ran in the game again (RTX 4090, 621.24, Windows 11, a DualSense): the disconnected, connected and low notices, the Controls tab's line, and main's new Audio rows beside them. The frame-rate numbers and the two sheets are from before the rebase (main0691f81against 0922406), and were not taken again: the change itself is the same but for the version.WIP: feat(input): show a notice when a controller's battery is low, when it disconnects and when it connectsto feat(input): show a notice when a controller's battery is low, when it disconnects and when it connectsfeat(input): show a notice when a controller's battery is low, when it disconnects and when it connectsto WIP: feat(input): show a notice when a controller's battery is low, when it disconnects and when it connectsBack to work in progress. The controller's name and battery are moving from the Insert menu's Controls screens to the game's own pause menu: its System page, above the controller picture under "Basic Controls". The change is written and has game-free checks, but it has not run in the game yet, and the description, its pictures and its Testing section still describe the Insert menu's line. Ready again once it has run in the game and those are redone.
d59d240006974550ed92The controller's name and battery now show on the game's own pause menu instead of the Insert menu: on the System page, under the controller picture at the foot of the "Basic Controls" panel (it was tried under the title first: crowded). host/oot_menu.c finds that page in front from the game's menu hooks and host/hos_wide_ui.c reads where the panel is, so the line slides in with the page; it hides on the other pages, under a screen opened from the page, under the Insert menu and when the menu closes. Rebased onto main
544229a(9f0dd23,974550e); the interface version is 30 now, after main's 29. Everything was run again on these commits on the same PC (RTX 4090, 621.24, Windows 11, a DualSense): the pictures, the frame rate (main 80.2 / 80.0 fps, this PR 80.5 / 80.6, notices off 80.9 / 80.75), the reconnect comparison and the pause menu; the run files under docs/tested/ are the new runs'. It builds whole for Windows and Linux.WIP: feat(input): show a notice when a controller's battery is low, when it disconnects and when it connectsto feat(input): show a notice when a controller's battery is low, when it disconnects and when it connectsA controller's low battery, a disconnect and a connect show a short notice, and the pause menu's System page names the controller. I read head
974550ed. It applies onto current main. Unset, the notices are on.HOS_PAD_NOTICE=0reads no battery and names no controller. The page is found from the menu hooks, and a pointer outside the guest window is not followed.MKWVK_API_VERSIONgoes from 29 to 30 forpad_noticeandpad_status. #1034 and #1358 also take 30, so whichever lands second renumbers. The notice strings sit beside #1318 and #1349: keep all of them.On Windows a DualSense showed each notice, and standing still stayed at about 80 fps. An Xbox controller, a Switch controller, a Linux DualSense, and the Deck's own controls are still open. The earlier farm ask was for an older commit and never started.
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.