Skip to content

perf(fp): seat IK in occupants.sync re-runs only when the vehicle's basis moves - #126

Merged
KunalSiyag merged 1 commit into
mainfrom
droid/r4-occupant-ik
Oct 28, 2026
Merged

KunalSiyag merged 1 commit into
mainfrom
droid/r4-occupant-ik

Conversation

@KunalSiyag

Copy link
Copy Markdown
Owner

What

occupants.sync re-ran the seat IK every frame for every seated driver and rider in range, on poses that cannot change: a car driver's sit pose is a pure function of the car's basis (the body rides the car rigidly and the pedal/wheel markers are car-space), and a rider's legs are a pure function of the crank angle, their arms of the basis alone.

The seat points, driver markers and limb bone chains were already cached; this memoizes the IK itself:

  • Car drivers re-run _driver_limbs once at seating and then only when the car's global_transform.basis changes (a grade, or a turn while vis_yaw catches up).
  • Riders re-run the leg IK only when the crank angle or the bike's basis changes, the arm reach only on a basis change, and the clip seek only when the legs re-ran. A stationary crank now early-outs after the memo update (arms at rest are the correct final pose; previously the early-out preceded the memo write, leaving the memo key stale).

Pin

New public counter ik_runs (test-only read). fp_traffic_test._check_driver_ik_memo asserts a held car adds no runs across repeat syncs and a turned car adds exactly the re-run — the two properties a regression of either memo would break.

Two bugs the suite caught in the first cut (fixed here)

  • The rider memo lives at entry slot 5, which _place read as the car-only sink float: float(Dictionary) errored every frame and rider roots froze off their seats. The sink read is now gated to car drivers.
  • The check itself leaked state: _look_at_car leaves the hero beside a moving car, which deterministically slowed the later resident-driver check by 23 s of sim time (traffic yielding to the hero). It now restores the hero position and the rotated car on exit.

Validation

  • fp_traffic_test PASS (incl. the three new ik-memo pins; resident driver 27.2 s vs main's 26.8 s).
  • tools/gate.sh quick: 180/181 steps PASS; the single FAIL was fp_car_doors_test on the Male_Adult_12_head.tres "possible cyclic resource inclusion" engine ERROR — a load-race flake also seen on other branches' gate runs this week; the suite's own verdict in that run was PASS and a standalone re-run is PASS with zero such errors.
  • pre-commit (gdlint/gdformat/complexity/repo-checks) green; api docs regenerated (ik_runs).

…asis moves

A seated driver's limb pose is a pure function of the vehicle's basis: the sit
pose is static, the contact markers are model-space, and the body rides the
vehicle rigidly. occupants.sync still re-ran _driver_limbs (and the rider's
arm reaches) every frame for every seated vehicle. Memoize per seating: car
and scooter drivers re-bend once at seating and when the car's basis changes
(a grade, a turn while vis_yaw catches up); bicycle legs follow the cranks,
arms only the basis; a rider held at a light with still cranks re-runs
nothing. Pinned by an ik_runs counter assert in fp_traffic_test.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Automated review

No new findings on the 3 changed files (gdlint, complexity, TODO policy, dead code).

Run python3 tools/checks/run_all.py locally for the full set of checks.

@KunalSiyag
KunalSiyag merged commit a047b13 into main Oct 28, 2026
6 checks passed
KunalSiyag added a commit that referenced this pull request Oct 30, 2026
…al (#131)

The #99 entry was pinned to Male_Adult_15_head.tres, but the threaded
body load races whichever shared head material is in flight: gate logs
show Male_Adult_12/15/18, Wood_Male_01 and Business_Male_07. Match the
mat/ prefix instead of one variant (fp_car_doors flaked on _12 in #126's
gate).

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
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