Skip to content

M1: units you can see (entities, walking villagers, zoom-gated pixel sprites) - #39

Merged
CodeByBryant merged 9 commits into
claude/kind-edison-2locd1-unitsfrom
claude/kind-edison-2locd1-m1-entities
Nov 24, 2026
Merged

CodeByBryant merged 9 commits into
claude/kind-edison-2locd1-unitsfrom
claude/kind-edison-2locd1-m1-entities

Conversation

@CodeByBryant

Copy link
Copy Markdown
Owner

Summary

Milestone M1 of the units plan (ADR 0008). Stacked on #38 (M0): the base is the M0 branch, so this diff is M1 only. Retarget to main once #38 merges.

The world now has simulated villagers that walk, and you can see them: zoom in and resource objects, roads, a hall at each capital and tinted villagers are drawn as pixel sprites. They only wander so far; gathering, building and settling are M2 onward.

Changes

  • Entities: EntityStore (struct-of-arrays, lowest-free-id allocation, saved and hashed), A* Pathfinder and a shared RouteCache over the 4-tile cost grid, counter-based randomness for unit behaviour, and a timer-wheel WanderSystem (event-driven, positions derived lazily from route and leg progress, arrival on a per-cell land anchor tile).
  • World: units spawn at the capitals and step after expansion; unitPositions() snapshot; hash schema 5, save format 6, web IndexedDB version 7. Config gained a units section.
  • Renderer: a procedural pixel-art atlas (22 resources in three states, tintable villager with two frames, banner, house, hall, 16 road pieces), pure view culling and zoom gating, roads from the route network, a main-thread UnitInterpolator, and pooled SpriteLayers (visible tiles only).
  • App: unit positions travel with every ticked message and a road byte per tile with ready; the canvas publishes sprite counts as data attributes; new e2e:units.
  • Docs: determinism (hash version 5 and new vectors), save format 6, roadmap, development, ADR 0008 (what M1 built and did not).

Why the goldens moved

Every world now carries villagers, so every golden hash changes (hash schema 4 to 5). They are regenerated in their own commit (2e371c5). The vectors were recomputed with the independent Python reference, and all 20 golden values (and their save round trips) match on Node 22, Chromium 157 and QuickJS.

Verification

  • pnpm typecheck, pnpm lint, prettier --check, pnpm test (all packages) and test:determinism pass.
  • Mutation checks on the pure logic (entity store, pathing, counter hash, wander, save, sprite state, roads, culling, interpolator); survivors were either equivalent (removed) or got a test.
  • e2e:units passes and the screenshots were checked by eye: sprites off when zoomed out, on when zoomed in, villagers move while time runs.

Limits

  • Software-GL e2e cannot judge frame rate; a real-hardware check is still needed for thousands of sprites.
  • Resource sprites are still drawn from the tile slot arrays; nodes-as-rows comes in M2.
  • Villagers do not interact yet (the wheel sorts by id as insurance for when they do).

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change): every world, hash and save changes (pre-1.0)

Checklist

  • Builds (pnpm build)
  • Linting and the dependency rules pass (pnpm lint)
  • Type checking passes (pnpm typecheck)
  • Tests pass (pnpm test; and pnpm test:determinism since the engine changed)
  • Tested locally in the web app
  • Golden hashes regenerated in their own commit, reason above
  • Updated documentation / JSDoc where applicable

Generated by Claude Code

Struct-of-arrays (kind, tile, owner, state, home, target, wake, leg start and end). The lowest free id is always
the next one handed out, whatever order rows were freed in, so allocation depends only on which rows are alive
and a restored world allocates as the original would. Rows are visited in id order. EntityKind in contracts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…between walkers

Pathfinder is A* over 8 neighbours on the deterministic heap; a step costs the mean of the two cells so a route
costs the same either way and its reverse is exact. RouteCache keeps each route found for the way there and
the way back (a memo only: a route is a pure function of the grid). routePosition says where a walker is part
of the way along, by cost. Checked against a plain Dijkstra on random grids as well as drawn ones, and
mutation checked. A probe measured pathfinding as the whole cost of a crowd, which is why routes are shared.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…rld (hash 5, save 6)

Villagers are entity rows that walk shared A* routes between settlements; a timer wheel wakes
them, positions are derived lazily from route and leg progress, and arrival lands on a per-cell
land anchor tile. Entities are hashed (schema 5) and saved (format 6); derived state is rebuilt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Every world now carries villagers, so every golden hash changes; the depletion golden too.
The ten entries cover walking units (192 villagers, 191 moved after 100 ticks on the small world).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
22 resources in three states (full, low, empty), a tintable villager with two walking frames,
a banner, house, hall and 16 road pieces that join by mask. Packed into one RGBA atlas with a
frame table; pure (no DOM, no PixiJS) and pinned by checksum so the art cannot drift unseen.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…nit interpolator

Pure and tested (with mutation checks): which tiles the camera sees, when sprites replace overlays,
a road byte per tile from the route network that joins neighbours by side, and a main-thread
interpolator that glides units between world snapshots without a map (merge by id).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…ted sprites

The world sends unit positions with every run and a road byte per tile once; the renderer pools
sprites for the visible tiles only (resources from the slot arrays, roads from the route network,
a hall and banner at each capital, tinted villagers glided between snapshots). Sprites appear when
a tile is 10 screen pixels wide. The canvas publishes sprite counts as data attributes for tests.
IndexedDB version 7 for save format 6; adds the units e2e.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
The overlays are added after the sprite container, so they covered it; the container now sorts on top.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
…cts inset so neighbours do not touch

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
Copilot AI balanced review requested due to automatic review settings November 24, 2026 20:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@CodeByBryant
CodeByBryant added this pull request to stack #40 November 24, 2026 23:49
@CodeByBryant
CodeByBryant merged commit fcb43f6 into main Nov 24, 2026
14 checks passed
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.

3 participants