📚 Encyclopedia

Games & Graphics · updated 2026-10-13

Road-graph map pipeline (author roads, generate the rest)

level-designprocedural-generationmap-editortilemapjsondata-format

A city map for a top-down driving game can be authored as a small road graph and "baked" at load time into everything the game needs. This keeps the authored file tiny and diffable, and makes the road graph the single source of truth. This is the design used by Spacebar's campaign mode (vanilla JS, 2026-08).

Authored truth: the road graph JSON

Bake at load, never stored

About 11 ms for a 512 x 512 map. It emits three artifacts: 1. A tile grid (Uint8Array). 2. Merged collision rectangles plus a per-tile index (Tile collision with merged rectangles). 3. A routing graph (Float64Array x/y plus neighbor lists) for traffic AI (Traffic AI path following on a road graph).

Filler is position-hashed, never drawn from a sequential RNG stream. With a sequential stream, any edit shifts every later random draw and reshuffles the whole city; hashing by position keeps edits local.

Validation that hard-errors

Wrong format version, unsupported z/oneway, diagonal segments, nodes off the map, and road width below a minimum (2 tiles: a 38 px garbage truck cannot fit a 32 px tile). An editor should draw these problems on the map: orphan nodes, nodes unreachable from spawn (flood fill), dangling or narrow segments, missing spawn.

Stamping roads of width w

Use lo = (w - 1) >> 1 and hi = w - 1 - lo on either side of the centerline. Using w >> 1 on both sides makes every road odd-width.

In-game editor lessons

Curves via stair-step barriers (approved design)

Segments gain curve: 1|2 (quadratic Bezier, control point at the derived elbow so it is tangent to the axes). The bake disc-stamps tiles along samples, so the barrier becomes a staircase and collision and rendering need no changes, while virtual nodes every ~3 tiles go into the routing graph so traffic follows a smooth path with zero code changes. Minimum curve radius 4 tiles, plus a post-stamp clearance check.

Generated seed district tips

Irregular block gaps of 16 to 22 tiles (about half a screen) read as a city; 34-tile spacing read as corridors. Order the palette by brightness: buildings darkest, road middle, sidewalk lightest.

See also

Linked from

Sources: spacebar memory (project_map_pipeline, project_js_rebuild), tldr post #1599