Files
gabrielvidalandClaude Opus 5.5 75555e73de
Deploy demo to GitHub Pages / build (push) Canceled after 0s
Deploy demo to GitHub Pages / deploy (push) Canceled after 0s
feat(world): platforms.cull — scan only near the bounds
A long page (a chat transcript) has its visible part far past the scan's
2500-node budget, and every rescan ran getComputedStyle on all of it. With
cull > 0 the walk rejects subtrees that far outside the bounds and scrolling
triggers a debounced rescan. The limit now counts candidates, as documented,
and computeSurfaces drops boxes outside the bounds before its pairwise pass
(same result: neither a surface nor an occluder can come from there).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 23:27:08 +01:00

1.6 KiB

World

world/World.ts turns the DOM into walkable segments.

Scan (world/scanner.ts)

TreeWalker over root, at most 2500 candidates.

With platforms.cull > 0 (body lengths, off by default), the walk skips every subtree whose box lies that far outside the bounds. Scrolling then triggers a debounced rescan, so a page much taller than the screen (a long chat transcript) only pays for what is near the pet. An element is a candidate when it matches platforms.selector ([data-pet-platform]) or, with platforms.auto, looks solid: solid tags (button, input, img, …) or a visible background, border or box-shadow. platforms.ignore subtrees and the pet layer are skipped. Rescan is debounced (0.35 s) after DOM mutations (style attribute changes are ignored).

Segments (world/segments.ts)

Each frame window (0.25 s or on scroll/resize) re-measures rects and builds surfaces: the floor (bottom of bounds) first, then each box top inside bounds, wider than platforms.minWidth u, minus the parts covered by non-ancestor elements within the headroom band (0.85 u). Huge wrappers are skipped. Surface ids are stable per element (id:k), so the body can follow moving elements.

Planner (world/planner.ts)

  • edgeBetween(a, b, caps): can the pet hop from surface a to b (gaps, higher overlapping → take off beside, lower → step off the edge)? Caps come from jumpHeight / jumpReach.
  • planPath: Dijkstra over those edges.
  • ballistic(dx, dy, g, clearance): launch velocity and flight time.

Tests: world/planner.test.ts (yarn test).