HOW WANDER IS BUILT · LAYER 3 OF 7
Sampling, seams and the worker.
Wander never builds a world; it builds the 64-column chunk you are standing in and the ones around it. A chunk is a window of the law: H[x][z] heights, C[x][z] a colour class, and then whatever stands on the ground. Two things make chunks join without cracks. First, the law is a pure function of the column and the lane, so two chunks that share an edge compute the same numbers on it. Second, every chunk also asks the law for the ring of cells just outside itself (heightOutside, kept as border.E/W/N/S) so its edge walls run only down to the neighbour's height, and a missing neighbour never shows as a cliff. The page keeps a synchronous path for the chunk it needs now; a worker opens the same world with the same options and builds the rest, posting back the chunk and its mesh buffers. Far away, tiles sample the same law at a stride of four or sixteen cells for the horizon.
const W = SIWander || WanderWorlds; // wander.js: the whole of worlds.js, in Node or the page
const inst = W.open("rulerhills", {}); // options as the link carries them: seed, g0, edits, width, walls, depth ...
const c = inst.chunk(0, 0); // 64 x 64 cells: H, C, top, border, mat, roofs, flags, signs, spans
console.log(c.NX, c.NZ, "highest", Math.max(...c.H.map(col => Math.max(...col))), "border east", Array.from(c.border.E).slice(0, 8));
const east = inst.chunk(1, 0);
console.log("seam:", c.border.E[10] === east.H[0][10] ? "exact" : "cracked"); // the ring outside equals the neighbour's first column
const tile = W.tile(inst, 4, 256, 0, 0, []); // the horizon: one sample every 4 cells, 256 cells a tile
console.log("tile", tile.nx, "x", tile.nz, "maxH", tile.maxH);
// in the page: worker.postMessage({type: "chunk", ci, cj, token, edits: inst.body(), shown}) and the worker answers {type: "chunk", parts, chunk}The chunk export of the kit's terrain engine is the same idea without Wander: SITerrain.window(world, x0, z0, w, h), drawn in three dimensions by view3d.html. In Python, sitoolz.wander.open and chunk give the same chunk, checked cell for cell by tests/test_wander.py against a fixture Node wrote from worlds.js.
← A column is a height A chunk is a mesh →
How Wander is built · by Lars Rocha · every layer stands on a law in sitoolz, written twice and checked against one fixture.