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: none
TL;DR
A controller that ran out of battery just stopped answering, and nothing on screen said why. Longshot now shows a short
notice when a controller's battery is low, when it is very low, when a controller disconnects and when one connects,
and the pause menu's System page names the controller with its battery percentage. Checked in the game on Windows with
a DualSense, with new game-free tests, and against main: no frame-rate cost measured (about 80 fps in play and 220 on
the pause page, with and without it).
Breakdown
HOS_PAD_NOTICE=0turns all of it off.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_VERSION34);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.pyandtest_hold_toggle.pyupdated for the changed functions.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: standing still with no notice, main 80.2 / 80.0 fps, this PR 80.5 / 80.6, this PR with the notices off 80.9 / 80.75; on the pause menu's System page, where the controller's line is drawn, main 219.4 / 221.05 fps, this PR 220.9 / 221.5. 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). The System page: the pause menu opened on it, 60 s from 6 s after, main and this PR in turn, twice, after a warm-up of eachHow 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: the standing-still and reconnect rows and the sheets are from
9f0dd23, this PR's code commit as it was on main544229a(its builds named themselves 3938f4c). Rebased since: the two interface members now follow main's newer ones, so the version is 34, not 30; nothing else in the change differs, so those were not taken again. The System page row, the checks and the builds are from that rebase on mainef6038a(its builds named themselves ad35f3b). The head now (a1a3ff6, codebc175f4) is the same change on main413d63e, one commit further, which touches only the opt-in Tracy profiler build544229a9f0dd239f0dd23ef6038a, this PR @ ad35f3b)HOS_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: 639 passed, 37 failed, 96 skipped (on ad35f3b: this PR on mainef6038a, one main commit before its head now; thechecks this PR adds or changes ran again on the head and pass). main
ef6038aonthat PC: 637 passed and the same 37 failed (
test_bug_report,test_bug_report_defaults,test_compute_warm_apart,test_cpu_report,test_crash_groups,test_crt_options,test_damage_debug_menu,test_dev_packs,test_display_startup_failure,test_dlss_feature_size,test_failed_compile_keeps_objects,test_guest_imported,test_hardware_report,test_hud_layout_row,test_invalidate_quick,test_invalidate_vcore,test_libc_hooks,test_linux_preflight,test_linux_pressure,test_linux_update,test_log_open_failure,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_psychov35_fsr3_fg,test_readback_timeout_source,test_run_all_changed,test_slow_frames,test_switch_table,test_target_image_pool,test_upscaler_rows,test_vcore_escape,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.same presses, the log saying the System page in front and no longer in front at each step, and the page as the game
itself writes it (headless,
RX_VK_SHOTSwithRX_VK_SHOT_MENU=1): the line with its bolt, the controller then onits charger at 100% (third picture below).
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.
battery there, the code gives the connected and disconnected notices alone, by the game-free test. Also the pause menu's line on a screen that is not
16:9, and in the game's other languages (the line itself is a name and a number).
Must be tested: None. No further run is asked for before merge; what was not run is listed under Not tested.
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. The third picture is the rebased build's (ad35f3b), written by the game itself at 1920x1080 with the screen off.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.
Cost: none measured. In play a frame asks the host once more (two reads). On the System page the line's reads and
drawing are there every frame: 220.9 / 221.5 fps against main's 219.4 / 221.05 on that page (within the spread between runs).
Turning it off:
HOS_PAD_NOTICE=0.Compatibility:
MKWVK_API_VERSIONis 34: 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. (The pause menu's System page is measured now: Measurements' table and Risks' Cost.)
main. (main @413d63e)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).
feat(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 for two things: the rebase onto current main (the interface is at 33 there, so this becomes 34), and a measurement of the pause menu's System page with and without the controller's line, for the open checklist box. The stale Test Farm request will be asked again on the rebased commit.
974550ed92a1a3ff6707Rebased onto main
413d63e(bc175f4,a1a3ff6). The interface is at 33 on main now, so this change's two members follow as 34; whichever of the pull requests that take a version lands later renumbers, as the review says. The notice strings are kept beside main's new ones.The open checklist box: the pause menu's System page is measured now, where the controller's line reads the game's menu and is drawn every frame. Main
ef6038a219.4 / 221.05 fps, this PR (built as ad35f3b) 220.9 / 221.5, two runs a side in turn after a warm-up of each: within the spread. It is in Measurements' table and in Risks' Cost, with four new files under docs/tested/, and the box is ticked.Also in the description: the TL;DR and Breakdown the template has now, and a third picture, the System page on the rebased build with the controller on its charger (the bolt before the battery), which had not been seen on that page. The standing-still numbers and the two sheets are from before this rebase (main
544229aagainst9f0dd23): the change itself differs only in the version number. Checks on ad35f3b: 639 passed, the same 37 failed as main ef6038a's 637. 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 connects@Beanstalk on Linux: build this PR and start the game, with a controller connected if one is at hand; play a minute, then open the pause menu and go to its System page. 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 pause menu's System page, please: the controller's name should be under the controller picture.@Beanstalk on the Steam Deck: start the game and play a minute with the Deck's own controls, then open the pause menu's System page. 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 System page, please.@lg only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.The two Test Farm requests above are withdrawn: no run on Linux or the Steam Deck is asked for, and none should be started for this pull request. The description's Must be tested is None now: no further run is asked for before merge, and what was not run (a real Xbox or Switch controller, Linux, the Steam Deck) is listed under Not tested, with what stands in for it. From the author's side this is ready to merge.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.