when this shape stops fitting

distinguished grug (level 6 of 6)explanationclass: architectural-interpretationteaches: adr-cause, adr-tradeoffneeds: adr-cause, adr-tradeoff, adr-boundary, accumulator-cap, adr-pass-order, adr-corner-tradeoff

alreadyYou can predict what a cap and a pass order change, and you know which module owns each write.

hereWhen the single-state, single-clock loop stops fitting and which shape fits the next problem.

Page: when this shape stops fitting

Job: explanation

Level: distinguished grug (level 6 of 6)

Source lines:

why grug give these 3 tool notes why grug give the proof why grug give the grill why grug give the why under an answer
explanation

this page says why the code has this shape and what a reader must be careful of.

A timber crate named Game with its lid lifted; two paddle slabs, a ball, a clock and a small flag float above it, each tied to the crate mouth by a dashed lift line
The shape this judgment weighs: one crate, one clock, one writer.

This page teaches the highest rung: decide when the architecture itself is the wrong tool, and name the source facts the decision rests on.

why

The architecture is three facts from source. state.ts:6#aggregate holds the whole round in one value that every module receives. main.ts:9#clock lets the caller supply elapsed time, so one frame loop drives the simulation. update.ts:11#advance is the single writer of the accumulator and the scores, and draw.ts:9#draw_game returns commands from a read of that value.

Those facts fit one machine with one clock and a small round. They give a reader one place to look for the round and one path from input to pixels. adr-cause names the monitor independence the fixed step buys. adr-tradeoff names the accumulator and catch-up loop paid for it. At this size the price is worth paying.

The same facts mark the edge. Two machines running main.ts:9#clock each supply their own elapsed time, so the two simulations no longer share a tick and each treats its own ball position as the truth. A game with many independent objects puts them all in the one value at state.ts:6#aggregate, so a change to one object touches the type every module reads. A renderer on another thread reads a value that update.ts:11#advance writes, and that read needs a rule for when the write is finished.

Past the edge the fitting shape is an authoritative tick on the machine that owns the simulation, which sends snapshots to clients that interpolate between them for display. State splits into components with named owners when the object count grows. The fixed step keeps its role; its home moves out of the browser frame loop. That is a judgment about the problem, held to the three source facts above.

Two timber benches face a shared paper slab named Game: at the left bench a grug writes on the slab along a heavy amber arrow fed by the Input slip; at the right bench a grug reads through a magnifier along a thin dashed arrow, and a fire arrow from his bench is crossed out and labelled no write
One bench writes, one reads, and the slab between them is the boundary this page weighs.

what breaks

Keeping the client clock as the authority in a networked game gives each machine a different score for the same rally. Putting hundreds of objects into the one Game value makes every module recompile and reread a type that grows with the object count.

Reading the live state from a second thread while advance writes it gives the renderer a torn picture of the ball. A snapshot rule settles which write the read sees.

where it fits

who owns what names the owners of this architecture. change one rule, follow the result changes one rule inside it. This page stands on both and asks whether the arrangement should exist for a different problem.

try it

Before you propose a rewrite, print the three definitions the judgment rests on:

source anchor: this line is in the file

run grep -n -E 'export function advance|export function frame|export type Game' update.ts main.ts state.ts

It prints:

update.ts:11:export function advance(game: Game, input: Input, frame_time: number): void {
main.ts:7:export function frame(game: state.Game, keys: io.KeyReader, frame_time: number): screen.DrawCommand[] {
state.ts:6:export type Game = { // aggregate: one value holds the whole round

The cited files update.ts, main.ts, state.ts ship with this site at the same path. Run the command from the school folder, or open update.ts, open main.ts, open state.ts.

reference: what carries over and what moves

FIXED_STEP at update.ts:6#120 stays useful when the clock moves to a server, because the simulation still wants equal slices. The caller named at main.ts:9#clock changes from a browser frame to the owning machine's tick. draw.ts:9#draw_game keeps returning commands, and the renderer consumes snapshots rather than the live object.

reference: every connection to this page
where this fits

This is reference. The next page in the reading order is at the bottom of the page.

learn first: why the loop pays for a fixed step, why the state is one plain object, time arrives in equal slices, why collision keeps two passes

flowchart LR
  A0["why the loop pays for a fixed step"]
  A1["why the state is one plain object"]
  A2["time arrives in equal slices"]
  A3["why collision keeps two passes"]
  H["you are here: when this shape stops fitting"]
  A0 --> H
  A1 --> H
  A2 --> H
  A3 --> H

this badge records quiz answers with a difficulty from 1 to 6. it does not measure independence or responsibility.

Useful Resources

Outside material, checked when this school was built.

grill: check what you know

Grug asks. Say the answer out loud, then tap. Grug remembers what you miss and asks again in the pop quiz.

the number is a question's difficulty from 1 to 6. a coloured chip marks a question that asks for a change, an effect or a judgment, declared in the quiz row. the rung badge records quiz answers: two right at a level and the levels below it, with a declared transfer question at level 5 or 6. it does not certify independence or responsibility. the questions are level 1 of 6 recall a fact; level 2 of 6 recall a detail; level 3 of 6 trace a path; level 4 of 6 trace a longer path; level 5 of 6 predict or judge; level 6 of 6 judge a transfer.

level 6 of 6Q1 · Two machines run main.ts with their own elapsed time. What breaks first?

try first, then show answer

3. Each machine advances its own ball with its own clock, so the two rounds disagree

why

main.ts:9#clock takes elapsed time from its caller. Two callers supply two clocks, and advance at update.ts:11#advance spends each caller's time on its own ball. The score at scoring.ts:4#goalcheck then follows two different rounds.

level 4 of 6Q2 · The game grows to hundreds of independent objects. What does the one Game value cost?

try first, then show answer

3. Every module reads a type that grew with every new object

why

state.ts:6#aggregate lists the round's fields in one type. Every module that receives that type recompiles when the list grows. A component layout gives each new object a named owner, which keeps the change local.

level 5 of 6Q3 · Drawing moves to a second thread that reads the live Game value. What rule is now needed?

try first, then show answer

3. The read needs a rule for when the writer's change is finished

why

update.ts:11#advance writes the shared value while draw.ts:9#draw_game reads it. A second thread needs a rule about which write a read sees. A snapshot held at a tick boundary gives that rule.

level 4 of 6Q4 · A move to a server tick changes which part of this architecture?

try first, then show answer

3. The place the clock is supplied, while the equal step stays

why

main.ts:9#clock shows where the elapsed time comes from. Moving the simulation to an owning machine changes that caller. FIXED_STEP at update.ts:6#120 still sets the slice length, so the equal step stays.

level 4 of 6Q5 · What makes this architecture a good fit for Pong?

try first, then show answer

1. One clock, one machine and a small round held in one value

why

state.ts:6#aggregate keeps the round in one place, and main.ts:9#clock gives the loop a single source of time. One machine with a small round pays little for that arrangement. A network of machines splits the clock.

level 4 of 6Q6 · Which shape fits network play while keeping the fixed step?

try first, then show answer

2. One authoritative tick sends snapshots and each client interpolates them for display

why

An owning machine can keep advance at update.ts:11#advance on its fixed tick and publish the result. Clients draw from the published state instead of their own copy of Game. The draw commands from draw.ts:9#draw_game still describe the frame.

level 2 of 6Q7 · One value holds the paddles, the ball, the accumulator and the serve flag in this game. Name it.

try first, then show answer

Game

why

state.ts:6#aggregate declares the one value that carries both paddles, the ball, the accumulator and the serve flag. state.ts:23#init_game builds it and returns it. Every module receives that value.