Skip to content

Mac: a Controls panel lists every key and its Switch control (Window > Show Controls, ⌘K) - #2

Merged
khalilgharbaoui merged 1 commit into
mainfrom
controls-overlay
Nov 11, 2026
Merged

khalilgharbaoui merged 1 commit into
mainfrom
controls-overlay

Conversation

@khalilgharbaoui

Copy link
Copy Markdown
Owner

What and why

Playing on the keyboard, the game's prompts name Switch buttons (A, B, ZL...) and there was no way to see which key is which while playing: the map lived in a switch in on_key and a comment at the top of front_mac.m.

  • One key map. dm/host/keymap_mac.h is a table of every key: its virtual key code, the Switch button or stick direction it drives, its group and the names the panel shows. on_key now presses the buttons and moves the sticks from it (km_button, km_stick_dir), so the panel and the key handling read the same source and cannot drift.
  • The Controls panel. dm/host/controls_mac.h builds it from that table, grouped: sticks and D-pad, face buttons, shoulders and triggers, + and −, stick presses, shake; then the touchscreen (left mouse button), the menu bar's shortcuts read from the menu itself (so a shortcut added there shows up), and one line on controllers (a Nintendo pad by its labels, any other by position).
  • Toggle. Window > Show Controls, ⌘K (a plain letter is a game key; ⌘Q, ⌘R, ⌘⇧C and ⌃⌘F are taken). Off by default. The choice is remembered across launches (user default DmControlsPanel.shown, written only when the player shows or hides it). DM_SHOW_CONTROLS=1 shows it at launch, 0 keeps it hidden (documented in docs/env_switches.tsv).
  • Never takes focus. An NSPanel subclass whose canBecomeKeyWindow and canBecomeMainWindow return NO, shown with orderFront (the Cheats panel's pattern, stricter: the Cheats panel may become key for its search field, this one never does). A click, a drag or its close button leaves the keyboard and the controllers with the game. Its labels are plain labels that never become first responder (the test checks both).
  • Doesn't cover the picture. A separate floating HUD panel rather than a view inside the game window, so it can sit beside the picture instead of over it: dark and see-through, about 290 x 550 points, at the game window's left the first time (the Cheats panel opens at its right), over its top right corner only when neither side has room on the screen. The player can drag it anywhere and its place is kept (frame autosave DmControlsPanel). It hides while another app is active and can show over the fullscreen game.
  • Mac only. Both headers carry the _mac suffix, which keeps them out of the iOS build; iOS is untouched.

The key handling is unchanged in behaviour: dm/host/tests/t_controls_mac.m pins every key code to the button or stick direction it pressed before the table. It also checks that every Switch button and stick direction has exactly one key and no key means two things, that the panel lists every key under its control and group, that it shows the menu's shortcuts the way the menu shows them, and that the panel never becomes key. DM_CONTROLS_CAPTURE=<folder> makes the test draw the panel into controls-panel.png.

Checked

  • Tests (exit codes):
    • make -C dm/host/tests GAME=0400486024DEC000 -j4 run: 0 (t_controls_mac: 461 checks, 0 failed)
    • t_controls_mac built with SAN="-fsanitize=address,undefined": 0
    • make -C dm/host GAME=0400486024DEC000 dmhost: 0, no new warning (the one in front_mac.m, activity set but not used, is already on main)
    • python -m unittest dm/tools/tests/{test_env_switches,test_docs,test_launcher_settings,test_settings,test_player_env,test_usage}.py: 0 each
    • dm/tools/env_switches.py --check: 0
  • Games run: The Legend of Zelda: Ocarina of Time (0400486024DEC000, the modules and shaders of the current Ocarina of Time (ultimate) app) through scripts/bench.py, route kokiri-deck, one run with DM_SHOW_CONTROLS=1, the new host, an empty pipeline folder. It reached its frames with 0 [RED] lines and logged front end: controls panel shown. The panel's saved frame put it at the game window's left at 364 points wide; the Quit item's full game name made it that wide, so that column is now capped at 160 points and the name is cut (the test uses the real name: 286 points). Frame times were not a measurement (load average about 25 from other work).
  • Devices and OS: Apple M5 Pro, macOS 27.2.
  • scripts/regress.py impact main..HEAD: Hades, Breath of the Wild, Pokémon Scarlet and Tears of the Kingdom, through the HID and present rules for front_mac.m and keymap_mac.h (this PR adds the keymap_mac.h rule to dm/tools/impact_map.tsv); 153 profiles unknown. regress.py check was not run: those games have no Mac build here, and the change sends the game exactly the button and stick values it sent before (pinned by the test). It only adds an AppKit panel that is off unless asked for.
  • Not checked:
    • The panel on screen by eye. The DM_CTL shot captures only the game's Metal picture, and screencapture would ask for Screen Recording permission. The test's offscreen drawing is the screenshot.
    • The panel following the game into fullscreen.
    • lint_c.py tidy: no LLVM clang-tidy on this Mac.
    • The iOS build (untouched).

Docs

  • docs/development.md: the Mac input text names the key map table and the Controls panel.
  • docs/env_switches.tsv: DM_SHOW_CONTROLS (switch) and DM_CONTROLS_CAPTURE (test).
  • No game files, keys or data extracted from a game in the change or the attachments

…> Show Controls, ⌘K)

A player on the keyboard sees the game's prompts name Switch buttons (A, B, ZL) and had no way to see which key is which while playing: the map was a switch statement in on_key and a comment at the top of front_mac.m.

The map is now one table, dm/host/keymap_mac.h. on_key presses the buttons and moves the sticks from it, and a new Controls panel (dm/host/controls_mac.h) lists it, grouped: sticks and D-pad, face buttons, shoulders and triggers, + and −, stick presses and shake, then the touchscreen, the menu bar's shortcuts read from the menu itself, and a line on controllers (a Nintendo pad by its labels, any other by position). So the panel cannot say something the keys do not do.

The panel is a small dark see-through HUD panel that floats beside the game window: at its left the first time (the Cheats panel opens at its right), over its top right corner when neither side has room on the screen. It never becomes key or main and is shown with orderFront, so the keyboard and the controllers stay with the game whatever is clicked on it; it can be dragged anywhere and its place is kept (frame autosave DmControlsPanel). Window > Show Controls (⌘K: a plain letter is a game key, and ⌘Q, ⌘R, ⌘⇧C and ⌃⌘F are taken) toggles it, and the choice is remembered in the user default DmControlsPanel.shown. DM_SHOW_CONTROLS=1 shows it at launch and 0 keeps it hidden. Mac only: iOS is untouched (the _mac names keep both headers out of it).

The key handling does what it did: tests/t_controls_mac.m pins every key code to the button or stick direction it pressed before the table, checks that every Switch button and stick direction has exactly one key and no key means two things, that the panel lists every key under its control and group and the menu's shortcuts as the menu shows them, that its labels never take the keyboard, and that the panel never becomes key. DM_CONTROLS_CAPTURE=<folder> draws the panel into a PNG. dm/tools/impact_map.tsv maps keymap_mac.h to the games' HID use, as dm_input.h and pad_apple.h are.

Checked: make -C dm/host/tests GAME=0400486024DEC000 run, t_controls_mac under ASan and UBSan, the host build, dm/tools/tests test_env_switches, test_docs, test_launcher_settings, test_settings, test_player_env and test_usage, scripts/regress.py impact main..HEAD, and scripts/bench.py on The Legend of Zelda: Ocarina of Time along the kokiri-deck route with DM_SHOW_CONTROLS=1 (the panel shown, 0 [RED] lines).
@khalilgharbaoui
khalilgharbaoui merged commit 31f9796 into main Nov 11, 2026
khalilgharbaoui pushed a commit that referenced this pull request Nov 14, 2026
… movie no longer falls behind its sound when frames take two vsyncs and its last scenes no longer play in silence (issue seedds#1501)

Issue seedds#1501: parts of Ocarina of Time's opening (`0400486024DEC000`, v131072) play with no sound, the renderer's mix silent for about a minute with no underrun and no red line.

**Cause.** The picture is behind the sound, and the sound ends first. The movie's sound is a stream of the game's sound engine and keeps real time. The picture comes from the game's movie player, which is limited to one picture a frame:

- once a frame the player's update (`main+0x3b5ca60`) adds the frame's time to a count of pictures due and advances that many (`main+0x3b61ea0`), but at most the limit at the player's `+0x20` (`main+0x3b5cb2c`); the rest stays in the count;
- the constructor (`main+0x3b5cec0`) sets the limit to 1, or to 2 for a last argument of 2 or more, and the queue to twice the limit; the game's one caller passes 1 (`main+0x3b5c55c`).

The console holds one vsync a frame in its movies. Here the frame step hands the game steps of two and three vsyncs, so each such frame leaves the picture one further behind for the rest of the movie. Read in play with `DM_PROBE=main:3b5cb28`, `DM_PROBE_ALL=1` (`x8` the pictures due, `x9` the limit): the limit 1, and the count at 1,350 pictures after 45 s at a 30 fps frame step.

**Change.** One function-matched cut in the profile (`MATCH_CUTS` in `dm/games/0400486024DEC000/patches.py`): the constructor takes its own value for 2 whatever its caller passes (`cinc w8, w28, ge` → `mov w8, #2`: limit 2, queue 4). A frame of two vsyncs then shows every second picture, and a movie that fell behind catches up at two pictures a frame. It is a cut of the game's code because the limit is the game's: the host's decoder gives every picture it is asked for. 09a91c5 (the decoder on its own thread) does not change this: with its host the 30 fps runs below are the "before".

Not 3, the frame step's largest hold: it is no value of the constructor's, and forced, the game stopped at the movie's start with a copy to a null pointer in `sdk` (cause not looked into). Frames held three vsyncs still lose a picture each until shorter frames catch up.

Reference entry: [A player limited to one picture a frame falls behind its sound](docs/reference/movies.md#a-player-limited-to-one-picture-a-frame-falls-behind-its-sound); the numbers are in the game note (Frame rate).

Relation to open PRs: seedds#1379 (AV1 pictures by the movie's clock) drops late pictures in the host's decoder for the same symptom; it conflicts with `main` since 09a91c5. This change needs no clock in the host. seedds#1661 (a trace of the mix) is independent.

The issue also reports item and chest jingles missing in play. Not reproduced, not looked into, and no movie plays there: this PR does not claim it.

- Tests: `python -m unittest dm/tools/tests/test_patches.py`: 23 pass; the new `test_ocarina_movie_player_takes_two_pictures_a_frame` fails without the profile change (1 error of 23). `test_docs.py`, `test_game_profile.py` pass; `docs_patches.py --check` current. The Python tests file by file (`dm/tools/tests`, `dm/ios/tests`, `dm/gfx/tests`, `DM_GAME=0400486024DEC000`): all pass but `test_tree_tar.py` (`test_packs_a_quiet_folder_and_keeps_its_attributes`), which fails the same on an unchanged tree.
- The rewriter on the game's `main` (v131072): `function patch "movie pictures a frame: …": matched at 0x3b5d084`; the patched module differs from the one without the cut in those 4 bytes only.
- Games run: The Legend of Zelda: Ocarina of Time `0400486024DEC000` v131072, headless, from an empty save through the title into the opening's first movie (`Dm_Kokiri_0000`: 9,254 pictures at 60 a second, 154.2 s), `DM_KEYS=50:A~0.2`. The host is 7867152's (the chain of the libraries on this Mac) with 09a91c5's decoder files and two log lines: one per 60 pictures given (stream time, host time) and one per 200 renderer frames (how many not silent). A second counts as silent with 4 or fewer of its 200 frames not silent.

  | run | 154.00 s of the movie took | silent seconds in the movie |
  |---|---|---|
  | 30 fps target, without the cut, 3 runs | 307.97, 307.95, 307.95 s (0.500) | 153, 153, 153 |
  | 30 fps target, with the cut, 3 runs | 154.03, 153.97, 153.97 s (1.000) | 0, 0, 0 |
  | 60 fps target, 7867152 as it is, the Mac busy (hold between 1 and 2), 1 run | 216.85 s (0.710) | 59 |
  | 60 fps target, without the cut, the Mac idle, 1 run | 153.98 s | 0 |
  | 60 fps target, with the cut, the Mac idle, 1 run | 153.84 s | 0 |

  Game time was 1.000 of real time in the 30 fps runs on both sides. With the cut at the 60 fps target the title movie, 9.88 s behind after its first 36 s without it (the long frames of the start), was level with its clock, and after the opening's movie the game went on into the Great Deku Tree scene (screenshot). The red lines are the same on both sides (those of a partial shader library).
- Devices and OS: Mac, Apple M4 (10-core GPU, 24 GB), VideoToolbox AV1.
- `scripts/regress.py`: not run. The change is one profile's `patches.py`, a test and docs; no host, chain or shared tool file changes, and the rule is scoped to this profile.
- Not run: a window with sound listened to (the measurements are the renderer's counters); an iPhone or iPad; a Mac that decodes AV1 with dav1d; the opening's later movies and the game's other 24; a host built from `main`'s head (its chain's libraries are not on this Mac; the host files between 7867152 and 09a91c5 differ in the decoder, taken here, and in `hle_oe.c`, `loader.c` and `probe.c`). Lint not run (ruff, pyright and LLVM are not installed here).
- Open: frames held three vsyncs (above); whether other games of this engine have the same player.

- [x] The finding is in its game note and its `docs/reference/movies.md` entry, and `python3 dm/tools/docs_symptoms.py` was run (the symptom index); `docs/agents/game-patches.md` regenerated
- [ ] A chain tool changed: no
- [x] No game files, keys or data extracted from a game in the change or the attachments

(cherry picked from commit b7104ba)
@khalilgharbaoui
khalilgharbaoui deleted the controls-overlay branch November 16, 2026 06:06
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.

1 participant