Skip to content

Refactor 4/6: the frame loop in phases, menu pages own their state - #99

Merged
seaweeduk merged 1 commit into
masterfrom
refactor/wave-3
Nov 22, 2026
Merged

seaweeduk merged 1 commit into
masterfrom
refactor/wave-3

Conversation

@seaweeduk

Copy link
Copy Markdown
Owner

Fourth layer of the structural refactor: the rest of run()'s features get owners, the frame loop becomes named phases, and the menu's page state moves out of Menu into each page's struct. Nothing changes for users.

Steps in this layer: A8, A9, A10, A11, A12, M4, M5, M6, plus review fixes for waves 0 to 3.

Owners. Each takes its collaborators by reference when it's built; run() calls it at the same points in the frame as before.

Step New owner What it took out of run()
A8 Quality eye resolution, foveation, frame reuse, refresh rate, presets and their deferred applies
A9 PanelFades, Notices panel fades, the laser, and which notice shows when several want to
A10 PlaybackSession opening, closing and stepping videos, slideshows, resume; one place resets per-video state on a video change
A11 StashCommands and every owner's handle() / fill(view) execute's cases and the MenuView build

A11: commands and the view go to their owners. execute tries applySettingCommand, then each owner's handle(). Each command still has exactly one handler. The switch left in execute has no default: and lists the commands owners handle as labels, so -Wswitch again flags a command nobody handles.

auto execute = [&](const MenuCommand& c) {
  if (c.type == MenuCommand::None) return;
  if (applySettingCommand(c, settings) || quality.handle(c, player) || session.handle(c) ||
      running.handle(c, passthrough) || passthrough.handle(c) || stashCommands.handle(c))
    return;
  switch (c.type) { /* what only run() can do: setup, key pick, Quit, Paste, ... */ }
};

A12: the frame loop in named phases. The loop body is 35 lines of phase calls. The phases are lambdas defined once before the loop, so nothing is built per frame. What one phase works out for later ones is declared with them. The XR submit core stays in one phase, unchanged.

flowchart LR
  poll --> startFrame --> choosePicture --> trackHead --> readControllers --> runJobs --> handInput --> stickInput --> pointAtMenu --> findFocus --> menuDialogs --> updateMenu --> c2["choosePicture"] --> showHints --> buildScene --> submitFrame
Loading

M4 to M6: the menu.

  • M4: page state moves out of Menu into one struct per page (Files, Library, Network, Downloads, settings, strip, keyboard, navigation column). The Stash and setup pages are nested in Menu instead of being its friends: a narrow host interface would have needed about 80 forwarding calls. One ListViewport holds the list's scroll position.
  • M5: Stash browsing moves into a model, StashBrowse, that never sees Menu. The Scene tab's layout is one function per section.
  • M6: the controls naming and editor rules move beside the controls model, in control_rules. layoutControls and layoutGestureEditor are split into their parts.

Review fixes from earlier layers.

  • Wave 0: a canvas without a GPU reports no texture. Drawing setup's panel needs setup running.
  • Wave 2: the room light and video check workers are built where they were before A4, so the library's last writes come before their threads are joined at quit. Stick seek reads the head pose in place instead of copying it every frame.
  • Wave 3: the first preset listing starts where it did before A8. The focus input is built fresh each frame again. Idle frames no longer send an empty command through every owner.
Before After
main.cpp lines 3,990 2,755
run() lines, phases included 3,485 2,278
Menu data members 213 128
Functions of 500+ lines 11 9
layoutSceneDetails lines 917 38
layoutControls lines 502 91

Known and left as is

  • PanelFades::Frame copies three Vec3 values, nine floats in all. They don't allocate.
  • The preset listing future comes from a std::promise. Destroying it doesn't join the config worker.

Important

AI disclosure

Model Variant Role
anthropic/claude-opus-5-5 high Implementation, orchestration
openai/gpt-6.2-astra high Independent review

Agent harness OpenCode 2.3.2

@seaweeduk seaweeduk added the skip-changelog Left out of release notes label Nov 22, 2026
@opencode-agent

Copy link
Copy Markdown

LGTM 👍

The frame phases preserve the ordering that matters: menu commands can stop or replace the video before the picture is selected again, and GL work is published before Vulkan submits the frame. The extracted playback and quality owners retain their deferred work, while the menu pages preserve their navigation state and share only the active list viewport.

github run

@seaweeduk
seaweeduk changed the base branch from refactor/wave-2 to master November 22, 2026 20:59
@seaweeduk
seaweeduk merged commit 5edd372 into master Nov 22, 2026
@seaweeduk
seaweeduk deleted the refactor/wave-3 branch November 22, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Left out of release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant