XR session setup: StartXR, pause on focus loss, XR shaders #15
Loading…
Reference in a new issue
No description provided.
Delete branch "hiccup444/da-game-hiccup:xr-session-setup"
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?
Summary
Game._init_xr()only switched the viewport to XR. It did none of the session setup that Godot's XR docs treat as required:_physics_process, so at 90 Hz only two of every three rendered frames see the origin move. Smooth locomotion and smooth turning judder.xr/shaders/enabledwas off, though Godot's XR setup guide lists it as a required step.The vendored XR Tools already ships the fix,
XRToolsStartXR, and this PR uses it.Changes
scenes/game.tscn:res://addons/godot-xr-tools/xr/start_xr.tscnis added as the first child ofGame, with default settings._readyruns beforeGame._ready(checked on 4.6.3)._ready, once the OpenXR interface is up, StartXR turns V-Sync off.session_begunit setsEngine.physics_ticks_per_secondfrom the runtime's refresh rate.src/core/game.gd: adds an@onreadyreference to StartXR. A new_on_xr_focus_lost()handles itsxr_endedsignal by callingopen_pause().open_pause()already ignores MENU and an open pause. So focus loss pauses GAME and SANDBOX, and it never toggles the panel shut the way the pause button does.xr_started. Controllers and hand tracking come back all at once when focus returns, so the player resumes from the panel instead of landing mid-action.xr_endedafter it has seen the focused state. So the visible state the session passes through at startup does not pause anything._init_xr()stays as the switch between XR and flat mode.project.godot: setsxr/shaders/enabled=trueand removes the twodriver/driver_name.*="vulkan"lines under[rendering].14dc157added that pin to keep Forward+ off D3D12, where OpenXR could not create a session.gl_compatibilitysincef4ab9fb, and Godot 4.6.3 does not register arendering/driver/driver_namesetting (checked in a clean project, where no such key exists).rendering/rendering_device/driver.windows. Its engine default on 4.6.3 isvulkan.docs/orREADME.mddescribes XR init, the physics rate, V-Sync or the Vulkan pin.Left out on purpose, as a design question for you: should quitting from the runtime save the run the way Return to Menu does? That would mean OpenXR
session_stopping, plusNOTIFICATION_WM_CLOSE_REQUESTon desktop. The answer depends on the save design:save_blockedin the traversal region;Tests
New checks:
smoke_menu:xr/shaders/enabledis true.Gamehas aStartXRchild that is anXRToolsStartXR.pause_check, using a guard that StartXR is in the game scene:xr_endedin GAME opens the pause menu with the panel visible.xr_endedleaves it paused.xr_startedafter that does not resume.xr_endeddoes nothing.xr_endedopens the pause menu with the panel visible.Each new check fails on
mainor under a targeted break:main(no StartXR, setting off): "XR shaders enabled", "game scene has StartXR" and the StartXR guard fail. The focus checks sit behind the guard.xr_endedconnection removed: the GAME, still paused, focus return and SANDBOX checks fail.xr_started: "focus return does not resume" fails.open_pause(): "focus loss in MENU does nothing" fails.Full suites: smoke_menu, arms_check, addon_check, save_check, rig_motion_check, pause_check and input_check all PASS. That run was local, on Windows, with
--headless --xr-mode off. CI covers Linux, where OpenXR is enabled but has no runtime.New in the logs:
game.tscnnow prints oneERROR: OpenXR: Failed to initializefrom StartXR, with its GDScript backtrace. Any desktop run without a headset prints it too. It is expected (see the corrections below). It has no uppercase FAIL in it, so the CI grep is unaffected.set_anchoredcall in the new steps.Corrections to the review
What StartXR does without a runtime. The review said StartXR "only logs that no XR interface was found". In fact the OpenXR interface is registered even when OpenXR did not start; it is just uninitialized. StartXR then:
OpenXR: Configuring interfaceandOpenXR: Initializing interface;initialize(), which returns false without an engine message;ERROR: OpenXR: Failed to initializeand emitsxr_failed_to_initialize.On that path V-Sync and the physics rate are left alone, and the game falls back to flat mode as before. This was observed on 4.6.3 with
--xr-mode off. Judging from the engine source, CI (Linux,xr/openxr/enabled=true, no runtime) takes the same path:OpenXRInterface::initialize()returns false when there is no API.Who initializes the interface. The review said
_init_xr()can stay because StartXR "has initialized the interface by the time it runs". In practice the engine already initializes the interface at startup whenever OpenXR started. StartXR's owninitialize()only runs when OpenXR is off or failed, and then it fails. What StartXR adds is the session setup (V-Sync, physics rate) and the focus signals, which is what this PR uses it for._init_xr()stays as the flat-mode switch, as proposed.Left for in-headset checking
StartXR: Setting physics rate to N(the headset's rate).Overlap with open PRs
src/core/game.gdandscenes/game.tscn. Here StartXR goes in as the first child, and the@onreadyline sits above_slot. The new sentence in the pause header comment stays clear of #11's_active_world()hunk. So this merges with #11 as it stands, without conflicts.open_pause()supports pausing mid-traversal. Focus loss goes throughopen_pause(), so it covers the traversal region once both land.Sibling PRs from the same review: #16, #17, #18 and #19. Their source changes merge cleanly with each other. Several of them add checks at the same spot in
tests/pause_check.gd(and two intests/save_check.gd), so whichever merges second may need a small rebase that keeps both blocks.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.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.