Skip to content

Build the sandbox ground grid on first Walk or Drive (BUILD-3951) - #9706

Closed
tcurtsinger wants to merge 2 commits into
ProjectLeonida:mainfrom
tcurtsinger:fix/sandbox-lazy-ground-grid
Closed

tcurtsinger wants to merge 2 commits into
ProjectLeonida:mainfrom
tcurtsinger:fix/sandbox-lazy-ground-grid

Conversation

@tcurtsinger

Copy link
Copy Markdown
Contributor

Claimed as BUILD-3951. Coordination claim

What and why

The windowed sandbox starts in Fly and builds the ground-collision grid before rendering its first frame. Only Walk and Drive query the grid. This patch constructs it on the first grounded frame and keeps it across mode switches, including when the scene yields an empty grid. The movement timer restarts after construction so the build time does not become camera movement.

On three local scenes, the grid build alone took 93–174 ms (median of three optimized runs per scene). Its vectors retained 64.5–150.5 MiB. A Fly-only session now skips that work and storage.

Tested

Windows x64, MSVC 19.44, NVIDIA GeForce RTX 4080, driver 621.01. Built the full runtime with CMake in RelWithDebInfo.

  • Compared the production binary against main at 5d74c2723 on a synthetic floor and three local scenes. Headless, default Fly, Walk and Drive produced 16 byte-identical frame comparisons. All windowed camera positions matched. On the floor, Walk and Drive placed the camera at 1.70 m and 1.20 m respectively.
  • Counted grid constructions in a temporary instrumented build. Default and explicit Fly built zero. Starting in Walk or Drive built one on the first frame. Sending the mode-key sequence 1 1 2 3 1 3 2 through the frame loop built one on the first 2, including with a mesh containing no complete triangles.
  • All 25 sandbox Python tests passed. The runtime suite reported 225 passes, 12 skips, one disabled test, and two failures (d3d12_vulkan_device and d3d12_depth_resolve). Both failures reproduced in a clean build of main.
  • The shader translator suite ran 5,957 tests across 447 files. The failing cases in test_image_atomics_guard and test_image_store_d16 produced the same 48 assertion failures on clean main.

AI-assisted with OpenAI Codex.

Checklist

  • The PR contains only the sandbox C++ source change. scripts/check_no_game_data.py passed on the changed file.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Follow-up for the ground grid. A sheet that the builder skips can still move the grid bounds and remove the floor from collision queries. I reproduced this in the Ground class on Windows at 72e90d8 and on its parent. The deferred construction change preserves the existing behavior.

  1. Use one mesh and one draw with the identity transform. Add a floor triangle at (0,0,0), (2,0,0), (0,2,0). Use sequential indices.
  2. Build Ground. Call height(0.5f, 0.5f, 1.0f, z). It returns true with z = 0. The grid has one cell.
  3. Append a second triangle at (-20000,0,0), (0,0,0), (0,128,0) and include its indices in the mesh. Rebuild and repeat the query. It returns false. The grid now has 135168 cells. The outer vector alone occupies 3244032 bytes on this x64 build.

The second triangle exceeds the 64 m sheet limit. The bounds pass includes it before the insertion pass skips it. Its minimum X moves the floor beyond the 4096-cell limit. Please exclude skipped sheets when computing the bounds in a follow-up. The original floor should still return z = 0 with the same one-cell grid.

AI-assisted.

@douglas-dh

Copy link
Copy Markdown
Contributor

Code read + Linux CMake/Ninja build check of 72e90d8ce (clean git merge-tree against main 5d74c2723) on Linux (Ubuntu 24.04 devcontainer, GCC 13.3.0, Ninja, Vulkan headers/loader; build + code read only, no live GPU/window run, no game files): pass.

What ran:

  • cmake -S runtime -B /tmp/pr9706-build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON && cmake --build /tmp/pr9706-build --target vk_sandbox --parallel -> compiled and linked cleanly (vk_sandbox).
  • python3 -I scripts/check_no_game_data.py -> clean (exit 0).

Code read: std::optional<Ground> ground defers ground.emplace(scene) until the first Walk/Drive frame and resets last = std::chrono::steady_clock::now() so grid construction time is excluded from dt.

AI-assisted review.

@Grimkaaah Grimkaaah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review (Linux CPU) — PASS (code-only; vk_sandbox not run)

Checked

  • Lazily builds the sandbox ground grid on first Walk/Drive via std::optional<Ground> so construction is excluded from the first movement timing.
  • Small, focused change; looks correct.

Not executed here: vk_sandbox interactive/GPU path.

No game files. Reviewer: Grimkeh (AI-assisted Cursor / Composer).

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.

5 participants