diff --git a/CONTRACT.md b/CONTRACT.md index 1fec028..2e8e6eb 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -40,9 +40,10 @@ concatenates them in order and the headless harness `require`s them through a sh | `src/weather_state.js` | `CC.Weather` | the weather director and one preset table per world; `rel()` is the cross-world quantity | | `src/city.js` | `CC.City` | `make(seed)` → heightmap + per-cell district/style/sign metadata, for any world | | `src/raycast.js` | `CC.Cast` | `render(frame, cam, city)` — fills every cell: façades, floor, sky | -| `src/surfaces.js` | `CC.Surf` | texture fns: `facade(u,v,cell,dist)`, `floorTex(wx,wz,dist)`, `sky(x,y,t)`; owns `configure`/`cfg`/`fog` for every world and delegates to the three painters | +| `src/surfaces.js` | `CC.Surf` | texture fns: `facade(u,v,cell,dist)`, `floorTex(wx,wz,dist)`, `sky(x,y,t)`; owns `configure`/`cfg`/`fog` for every world and delegates to the other painters through `CC.SURFACES` | | `src/surf_west.js` | `CC.SurfWest` | the frontier's `facade` / `floorTex` / `sky`, same signatures | | `src/surf_moon.js` | `CC.SurfMoon` | Moonwalk's, likewise. Painters self-register into `CC.SURFACES[id]`; `build.js` globs `src/surf_*.js` | +| `src/surf_japan.js` | `CC.SurfJapan` | EDO's. The only painter with TWO key lights — a sky dome scaled by how much cloud there is, and a lamp wash that is a function of height above the ground and nothing else | | `src/proj.js` | `CC.Proj` | the ONE copy of the element camera — `make()` hands each world-space element file its own basis and the four helpers closed over it | | `src/control.js` | `CC.Control` | the walk and the input devices; re-anchors to `city.js`'s route on a rebuild | | `src/elements/*.js` | pushes to `CC.ELEMENTS` | ambient systems, see below | @@ -78,8 +79,9 @@ CC.ELEMENTS.push({ name: 'rain', layer: 10, // lower draws first; elements draw after the world pass world: 'cyber', // OPTIONAL: an id, or an ARRAY of ids. Absent means EVERY world — - // which is a materially different promise now there are three, and is - // why the atmospheric elements had to be given ['cyber','west']. + // which is a materially different promise now there are four, and is + // why the atmospheric elements carry ['cyber','west','japan'] and the + // Moon is left out of every one of them. init(city, rng) {}, // allocate persistent state update(dt, t, cam) {}, // advance simulation; no drawing draw(frame, cam, t) {}, // use CC.put(frame, x, y, glyph, colour, lum, dist) — it depth-tests for you @@ -90,14 +92,31 @@ CC.ELEMENTS.push({ `CC.World` names the live world and calls back when it changes; `main.js` responds by tearing the map down and building a new one on the **same seed**. Everything downstream keeps its own data for -every world next to the numbers it already has — `city.js` holds three district tables (nine -quarters for the city, six for the frontier, eight for the Moon), `weather_state.js` three preset -tables, `surfaces.js` delegates to three painters — rather than reading from one central theme -object. The URL fragment is `#` for the default world and `#/` otherwise. +every world next to the numbers it already has — `city.js` holds four district tables (nine +quarters for the city, six for the frontier, eight for the Moon, seven for EDO), +`weather_state.js` four preset tables, `surfaces.js` delegates to four painters — rather than +reading from one central theme object. The URL fragment is `#` for the default world and +`#/` otherwise. + +WHAT A FOURTH WORLD COST, recorded because it is the measurement that says whether the three +registries below were worth building: 33.2 KB of stripped bundle, against the frontier's 65 and the +Moon's 55. Nothing in `raycast.js`, `main.js`, `control.js`, `render_canvas.js` or +`tools/headless.cjs` was touched at all — a world is now a `world.js` row, a `city.js` theme and +district table, a `weather_state.js` preset table, one self-registering painter, and element files +that tag themselves. If adding one turns out to need an edit to any of those five files, that edit +is the bug. Rules for worlds: - An element that belongs to one world says so with `world:` on itself, as an id or an array of - them. The test is `CC.inWorld(el, id)` and there is exactly ONE definition of it, in `world.js`, + them. A shared element that has to behave differently per world does it through a **table keyed + by world id**, never a boolean. `street.js` carried `PED_WEST = city.world === 'west'` doing two + unrelated jobs — the frontier's costume weights and "this crowd is pre-electric" — and a fourth + world needed the second and not the first. It is now two lookups, `PED_ARCH` and `PED_PRE_W`, and + a world that is in neither gets the modern default rather than whatever the last `else` was. + Whatever the gate does, the DRAW must still happen: every one of those branches takes its hash + and throws the result away rather than skipping it, so one world's crowd is not a reshuffle of + another's. +- The test is `CC.inWorld(el, id)` and there is exactly ONE definition of it, in `world.js`, shared by `main.js`, `tools/headless.cjs` and the photosensitivity gates — because those three had three copies and an offline reference frame rendered from a different element set than the browser's is not a reference frame. `main.js` filters **before** the layer sort, because every @@ -106,7 +125,9 @@ Rules for worlds: - A world is added by appending a row to `world.js`'s `LIST` (never prepending — `LIST[0]` is the URL default and every `#42` link ever shared addresses it), a theme block and district table in `city.js`'s `THEMES`, a painter file that self-registers, a weather table in `weather_state.js`, - and element files tagged with its id. Nothing in the tree switches on a world id with a ternary + and element files tagged with its id. That is the whole list; EDO was added without touching + `raycast.js`, `main.js`, `control.js` or `tools/headless.cjs`, all four of which already read the + registry rather than a set of literals. Nothing in the tree switches on a world id with a ternary any more; every one of those is a registry lookup with a documented fallback. - Nothing decides geometry by reading `CC.World` at draw time. The map resolved the world once, inside `make()`, and carries the answer on itself as `city.world`; between a keypress and the @@ -160,8 +181,15 @@ Rules for elements: ## The build -`node build.js` must exit 0. It fails over **560 KB** and that line has been raised three times and +`node build.js` must exit 0. It fails over **600 KB** and that line has been raised five times and held once; the essay in `build.js` is the record and it is addressed to whoever lands here next. +**The next pass must split the payload.** Three passes running have now ended at this line with the +same finding — the content is bigger than the headroom and every remaining cut is a rounding error +against it. The last non-content cut in the tree (the duplicated `streetSpan` / `objVisible` / +`corridor` bodies, measured at ~2,350 bytes and banked in `build.js`'s essay) is worth a tenth of a +world. +It also checks that every world's painter global is present, so a painter dropped into `src/` and +never registered fails the build instead of rendering as the city. The order is: cut something that is not content, then cut content, then move the line, and write down which one you did. The whitespace has already been spent — `decomment()` halves leading indentation, worth 42,134 bytes of a measured 84,232 — so a future pass has one fewer option than @@ -183,6 +211,32 @@ The gates, in the order they are worth running: `node build.js`, `node tools/dom the census, and a determinism check (the same seed, frame, world and hour rendered twice must be byte-identical). +A GATE THAT CANNOT SEE THE FEATURE IS NOT A GATE, and this is the newest hard-won rule here. Both +photosensitivity tools PIN THE CAMERA at the map's start, so anything the walk only reaches later is +invisible to them: EDO's canal is on a 160 m pitch, and `west-flicker.cjs` returned PASS having +rendered ZERO canal cells on a surface that was in fact running at 3.61% against a 2% rule. When a +feature lives somewhere the pinned camera never stands, measure it where it lives — +`tools/canal-flicker.cjs` is that probe for the canal and is the pattern to copy. Quoting a PASS +from a tool that rendered none of the thing under test is worse than not running it. + +`west-flicker.cjs` is named after the frontier and is NOT scoped to it: it walks `CC.World.LIST` +and gates every world that is not the default against the default's own elements, so a new world is +covered the day its row lands. It is also the only gate that can see a whole class of defect that +is invisible in a still and invisible in the census — a frame that is correct at every instant and +wrong in its RATE. Adding EDO tripped it five times: an 11 Hz hash on a lit panel, a 26 Hz re-deal +in the sky, a 4.5 Hz ripple offset, a 2.6 Hz gutter whose harmonics landed in band, and a drift of +blossom whose petals cross a cell at about 5 Hz. Note that the last of those could not be fixed by +dimming or by thinning the pool — both change the amplitude and the gate was measuring the rate; +what fixed it was refusing to draw a petal inside 11 m. + +THE OTHER STANDING CHECK, and it is not optional either: before anything ships, render the same +fixtures in every world that was ALREADY there and byte-compare them against the tree you started +from. Twenty-seven — three worlds x three hours x three seeds — is what the pass that added EDO +ran, and all twenty-seven were byte-identical. +A world addition touches shared files (element `world:` tags, a per-world table in a shared +element) and every one of those is an opportunity to move a frame in a world nobody was looking +at. + A note on window lengths, because two of those tools take one and they do not mean the same thing by it. `west-flicker.cjs` measures per-cell frame steps and rates, which have no bin width in them and are honest at four seconds. `flicker-rate.cjs`'s 3-20 Hz rule is a periodogram peak, which for diff --git a/README.md b/README.md index 3375246..d5abe99 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,60 @@ # CyberCity -Three walkable worlds drawn entirely in text characters, in one self-contained HTML file, with the +Four walkable worlds drawn entirely in text characters, in one self-contained HTML file, with the sun going round. No build step to run it, no dependencies, no network requests. Open `index.html` and you are standing on a street in the rain. Press **2** and you are on a dirt road on the frontier; press -**3** and you are on the Moon. +**3** and you are on the Moon; press **4** and you are in a castle town on a wet evening. **[cybercity.carino.systems](https://cybercity.carino.systems)** ![A street canyon at night, lit tower faces either side](docs/street.png) -## Three worlds +## Four worlds | key | world | | |---|---|---| | `1` | **CyberCity** | a rain-lit city — neon, aerial traffic, police, market stalls | | `2` | **Frontier** | an 1880s timber town — veranda posts, painted boards, telegraph, horses, open desert | | `3` | **Moonwalk** | an Apollo-era lunar surface — regolith, craters, a black sky with Earth in it | +| `4` | **Edo** | a castle town in the rain — paper screens, lanterns, tiled eaves, a canal, bridges, sakura | -They are the same engine and the same seed. `#42` is a place in all three, so pressing 1, 2 and 3 +They are the same engine and the same seed. `#42` is a place in all four, so pressing 1, 2, 3 and 4 in turn shows you the same corner of the same street lattice with a different century — or a -different world — built on it. That is the point of having three. +different world — built on it. That is the point of having four. ![A frontier main street at dusk, veranda posts and a sunset band](docs/frontier.png) ![A lunar plain at local noon, Earth hanging in a black sky](docs/moonwalk.png) +![A machi street at dusk: lit paper screens down both sides, wet earth between](docs/edo.png) + +The fourth one is the odd one out and deliberately so. The first three are all lit from a long way +off — by a sodium grid, by one low sun, by another one with no air in front of it — and **Edo** is +lit from inside the street: a paper lantern hung under the eave at 2.1 m and an oil lamp behind +every shopfront. That inverts the whole model. Sun and sky light the top of a wall and leave the +ground dark; lanterns do the opposite, so a machi street after dark is bright at the bottom and +black at the top, and which of the two lighting models the frame is under is what the clock +decides. It is also the only world *built around* an overcast sky rather than merely having one as +a weather state — under a deck there is no shadow to speak of and the two sides of a street are +within a stop of each other, so what carries the picture is not tone but +**lines**: the ridge tile, the drip edge under it, the mid-rail, the gutter, the batter of a castle +wall. A cell of that world is a line or it is nearly nothing. + +![A canal at dusk: lantern light coming back off the water, banners on the far bank](docs/edo-canal.png) + +It also has a **canal** in it — 9.2 m of water on a 160 m pitch, so the walk meets one about every +hundred seconds and crosses it on an arched taiko-bashi. Nothing is carved to make it: in this +engine a negative height renders byte-identically to zero (the march is `if (h <= 0) continue` and +the floor is painted by inverse projection against the y=0 plane, which never consults the +heightmap), so the water is a *painted plane* with a 0.45 m stone coping beside it. That coping +height is an occlusion budget rather than a wall: a parapet of height h at distance W hides all +ground out to `W*eyeY/(eyeY-h)`, so the 1.2 m a real embankment has would hide the entire canal and +the far bank behind its own kerb. At 0.45 m it costs three metres of water and the eye supplies the +drop. What sells it is the reflect pass — a puddle gives back three cells, a canal gives back a +quarter of the floor rows. + ## The day Every world runs a day/night cycle. Seven minutes is a full day; the sun climbs to 54 degrees and @@ -66,8 +94,10 @@ and it moves the other way. Both, measured at 200x60 on frame 300 at two seeds, | **frontier** seed 7 | 26.5 / 0.24 | 38.7 / 1.03 | 40.9 / 7.16 | | **Moonwalk** seed 42 | 5.5 / 1.64 | 6.6 / 2.27 | 5.0 / 2.85 | | **Moonwalk** seed 7 | 11.8 / 1.27 | 7.2 / 3.88 | 6.2 / 3.60 | +| **Edo** seed 42 | 38.6 / 0.38 | 46.8 / 2.58 | 51.9 / 0.71 | +| **Edo** seed 7 | 30.8 / 0.03 | 37.3 / 2.08 | 37.6 / 0.07 | -Three things in that table are worth saying out loud rather than leaving for someone to notice. +Four things in that table are worth saying out loud rather than leaving for someone to notice. The Moon holds the night target at every hour of its day and at both seeds, 5.0% to 11.8% against a limit of 30, because it has no air — which is the whole argument for it being the third world. @@ -78,10 +108,22 @@ under a sky that is a third of the frame and never goes to zero. The number move two seeds, which is the honest size of the seed effect out there — seed 7 draws more open range and open range is black. -Twilight in the two atmospheric worlds is the flattest hour of the three — the city's hot tail is -0.41% at dusk against 7.27% at night — and that is not a bug to be tuned out either: it is the hour -when the neon and the sky are the same brightness, which is exactly what makes it look like -twilight. +Twilight in the two older atmospheric worlds is the flattest hour of the three — the city's hot +tail is 0.41% at dusk against 7.27% at night — and that is not a bug to be tuned out either: it is +the hour when the neon and the sky are the same brightness, which is exactly what makes it look +like twilight. + +Edo is the only world whose hot tail goes the *other* way — a few hundredths of a per cent at +night against two and a half at dusk — and it is the ladder rather than the picture. After dark the print's hot line is v 170 and the only +swatches in the palette that reach it are `amber` (179), `azure` (219), `red` (206), `ice` (174) +and `pure` (234) — a sodium lamp, a screen, a signal, a rain highlight and a specular. A paper +lantern is materially `warm`, which tops out at 167: three points under the line at any luminance +whatsoever, so a town lit entirely by lanterns censuses at nothing however many of them are in +frame. That is not a fault to tune out by repainting the lantern in a swatch that lies about what +it is. Two cells' worth of `pure` are spent where they are physically right — the blown-out core of +a near lantern and the glint off the water in the gutter — and the rest of the world is honestly a +dark wet street with warm holes in it. By dusk the ladder has crossed onto the day curve, where +`warm` reaches 187 and `white` 209, and the same frame scores 2.58%. ![A dust storm coming up the road](docs/dust.png) @@ -92,8 +134,8 @@ and `.` in twenty colours. ## The palette, and why it is twenty and not twelve It was twelve: two pillars — sodium amber and screen azure — and ten narrow things around them. -Twelve is enough for a wet neon street at night and it is not enough for three worlds with a sun -over them, and the failure was specific rather than general. There was no neutral grey at all +Twelve is enough for a wet neon street at night and it is not enough for the daylight worlds, and +the failure was specific rather than general. There was no neutral grey at all (slate is deliberately blue and says so in its own comment), no brown, no green that is not an accent, and nothing warm-metal. Everything that was none of those collapsed onto amber. @@ -116,6 +158,12 @@ walked violet off magenta years ago. At 0.20 the knee crushes every rose cell un black, so rose can only exist where something wrote it near full scale — which makes "signage only, never a field" arithmetic instead of a note in a comment. +Twenty turned out to be enough for a fourth world: **Edo adds no swatch at all.** Weathered cedar +is `timber` in shade and `sand` in light, lime plaster is `white`, clay tile and a castle wall are +`stone`, the dye on every piece of cloth in the place is `indigo`, and the lamp behind the paper is +`warm`. That is the extension doing exactly what it was added for, and it is worth recording as +evidence that the palette is now the right size rather than merely a bigger one. + ## What is in it It walks itself. Leave it alone and it strolls the city forever, turning corners, passing under @@ -294,7 +342,7 @@ It plays itself, so all of this is optional. | `Tab` | take the controls / give them back | | `Esc` | give them back | | `P` | photo mode — freezes the world, you can still look and move | -| `1` `2` `3` | world: CyberCity, Frontier, Moonwalk (gamepad: `Y` / triangle cycles) | +| `1` `2` `3` `4` | world: CyberCity, Frontier, Moonwalk, Edo (gamepad: `Y` / triangle cycles) | | `T` | step the time of day (`Shift`+`T` steps back) | | `Y` | stop / restart the automatic day cycle | | `Shift`+`1`–`6` | weather | @@ -304,24 +352,30 @@ It plays itself, so all of this is optional. | `H` | show the controls | The weather presets are `clear, drizzle, rain, downpour, mist, storm` in the city, -`blazing, breeze, dust, squall, overcast, thunder` on the frontier, and on the Moon exactly one, -`vacuum`, with every parameter at zero — which is not a placeholder but the honest answer, and it -is what makes the whole weather machinery collapse to nothing there without a single special case. They moved onto `Shift` when +`blazing, breeze, dust, squall, overcast, thunder` on the frontier, `clear, haze, tsuyu, shower, +typhoon, kiri` in Edo, and on the Moon exactly one, `vacuum`, with every parameter at zero — which +is not a placeholder but the honest answer, and it is what makes the whole weather machinery +collapse to nothing there without a single special case. Edo's table is very nearly the frontier's +inverted: out there it is dry for weeks and the middle of the table is made of dust, and there it +is a maritime climate on the edge of a monsoon and the middle of the table is four grades of rain. +No row of it has `wet` under 0.20; the ground is always holding water, which is what the +reflections in the road are for. They moved onto `Shift` when the worlds took the digit row: which world you are standing in is the larger fact, and it is the one a viewer told "press 1 or 2" reaches for. On a phone or tablet the left half of the screen walks, the right half looks, and a tap goes fullscreen. There is no world gesture: every gesture on a touchscreen is already spoken for by those two halves, and a hidden two-finger something that rebuilds the world is a trap rather than -a control — so on a phone the other two worlds are reached by their URLs, `#west/42` and -`#moon/42`. +a control — so on a phone the other three worlds are reached by their URLs, `#west/42`, +`#moon/42` and `#japan/42`. Gamepads work too, and a pad is the one input device other than a keyboard that can reach the -second world: **Y** (triangle) cycles it. +other worlds: **Y** (triangle) cycles through them. -The URL carries the world and the seed — `#42` for a city, `#west/42` or `#moon/42` for the same -seed elsewhere — so a place you liked is a link you can send. The bare `#seed=42` form still works, -and so do the words people actually type: `#western/42`, `#lunar/42`, `#apollo/42`. +The URL carries the world and the seed — `#42` for a city, `#west/42`, `#moon/42` or `#japan/42` +for the same seed elsewhere — so a place you liked is a link you can send. The bare `#seed=42` form +still works, and so do the words people actually type: `#western/42`, `#lunar/42`, `#apollo/42`, +`#edo/42`, `#kyoto/42`. ![A downpour, ember quarter](docs/downpour.png) @@ -369,17 +423,61 @@ occupied and only the sway moves them. Measured now, at a four-second window wit pinned: the frontier's own elements take a big step 1.50 times a second against the city's own 1.50, and carry 2.53% of full scale in the 3-20 Hz band against the city's 2.28% — the two worlds are the same shape, which is what the gate was for. The Moon's own elements are 0.00/s and 0.00%, -because `vacuum` has every parameter at zero and there is nothing out there that modulates. With -every element in a world switched on at once, which is context rather than a gate, the big-step -rates are 4.75/s for the city, 7.25/s for the frontier and 0.25/s for the Moon. The tumbleweed's -roll rate and the cloud bars' drift were sized against the same rule in advance, with the -arithmetic written down next to the constant. +because `vacuum` has every parameter at zero and there is nothing out there that modulates. Edo's +are 0.75/s and 2.23%. With every element in a world switched on at once, which is context rather +than a gate, the big-step rates are 4.75/s for the city, 7.25/s for the frontier, 0.25/s for the +Moon and 1.50/s for Edo. The tumbleweed's roll rate and the cloud bars' drift were sized against +the same rule in advance, with the arithmetic written down next to the constant. + +The canal found a fifth kind of failure and it is the one worth reading, because **the shipped gate +returned PASS on it while rendering zero canal cells**. `west-flicker.cjs` pins the camera at the +map's start; the channel is on a 160 m pitch and is a hundred metres from there, so the tool was +measuring a frame with no water in it. Pinning the camera *on the water* instead — that probe is +kept as `tools/canal-flicker.cjs` — the first cut scored **3.61% in the 3-20 Hz band against a 2% +rule and 2.5 big steps a second against a limit of 1.0**. + +The mechanism is the interesting part, and it is the companion to the blossom's lesson rather than a +repeat of it. The ripple is a *fractional row offset* that the caster floors to pick a source row, +so what the eye sees is not the offset, it is the offset **crossing an integer** — and each crossing +swaps the reflected cell between a lantern and the black beside it, which is a near-full-scale step. +Cutting the amplitude six-fold and the mirror by a third barely moved the number, because once the +amplitude is under one row the crossing rate is no longer set by how far the offset swings; it is set +by how often the noise wanders back across one boundary, which is the noise's own frequency. At +1.1 Hz its third harmonic is 3.3 and lands inside the band. **The rate was the lever**: 0.37 Hz puts +the first three harmonics at 0.74, 1.11 and 1.48, and the measurement drops to 1.43% and 0.50/s with +reduced motion silent at 0.00%. The mirror then goes back up and the water keeps its depth. + +Edo's gate found four more before that, and it is worth saying that **none of them was visible in a +still and none of them showed up in any census** — every frame was correct at every instant and the whole +defect was in the rate. Rain running down a lit paper screen re-dealt its hash eleven times a +second, which is the middle of the danger band, over the largest lit area in the frame; a second +rain drawn into the sky dome re-dealt every sky cell it touched about every other frame, which is +not a moving streak but per-frame noise, and per-frame noise puts energy at *every* frequency; the +ripple offset on a puddle stepped the mirrored row by up to four rows at 4.5 Hz in a downpour; and +the gutter's water pattern ran at 2.6 Hz, whose second and third harmonics land at 5.2 and 7.8. The +sky rain was deleted outright — `elements/weather.js` already owns the rain in every world that has +any, and a second cruder one behind it was never worth a line — and the other three were slowed +under the band, with the streak also inverted to be *darker* than the paper behind it, which is +both the smaller step and what water on a lit screen actually looks like. + +The blossom drift is the one that had to be redesigned rather than slowed, and its note is the +useful one. A petal crosses a *cell* in about a fifth of a second at conversational distance, so it +switches that cell at roughly 5 Hz whatever it is drawn at — and dimming it (150 to 96) and +thinning the pool (64 petals to 40 to 22 to 10) left the gate reporting the identical figure at the +identical cell every single time, because the worst cell is one petal's trajectory and neither +lever touches the rate. What fixed it was distance: nothing inside 11 m is drawn, faded in over the +next five, because at 11 m a petal covers a cell for half a second and is out of the band. It is +also the better picture — a petal a metre from the eye reads as a bug on the lens. `prefers-reduced-motion` is honoured throughout. With it on, the walk slows, the rain calms, the police lightbar holds steady instead of alternating, the aerial traffic parks, the windmill's vane -stops and the tumbleweed slows to a third — but both worlds stay populated. The point is stillness, -not deletion. Measured: with the flag on, the frontier's own elements produce **no** step over a -third of full scale anywhere and an empty 3-20 Hz band, in every weather state. +stops, the tumbleweed slows to a third, and Edo's lantern flames, noren hems, gutter and sky bands +all freeze — but every world stays populated. The point is stillness, not deletion. The one thing +that is *removed* rather than damped is the blossom, and the reason is that damping it does not +make it a quieter version of itself: a drift of petals **is** the motion, and thirty petals frozen +in mid-air are not a calmer drift, they are a scatter of dots hanging in the sky. Measured: with +the flag on, every world's own elements produce **no** step over a third of full scale anywhere and +an empty 3-20 Hz band, in every weather state. ## Running it @@ -433,13 +531,14 @@ Everything here runs without a browser, which is how the thing gets verified at | | | |---|---| -| `tools/headless.cjs` | render any frame of any seed offline, as a text dump — `--west` / `--moon`, `--time=`, `--weather=`, `--yaw=` | +| `tools/headless.cjs` | render any frame of any seed offline, as a text dump — `--west` / `--moon` / `--japan`, `--time=`, `--weather=`, `--yaw=` | | `tools/topng.py` | turn that dump into a PNG, with the bloom the canvas applies | | `tools/metrics.py` | the print census — exposure bands, colour split, what each layer costs | | `tools/peds.cjs` | the crowd alone, against an empty frame, at a size you can actually see | | `tools/flicker-rate.cjs` | the photosensitivity gate, for the city's signage — run it with **no arguments**, see above | | `tools/lightning-rate.cjs` | the same, for storms | | `tools/west-flicker.cjs` | the same, for every world that is not the city — pinned camera, per cell, against the city as its baseline | +| `tools/canal-flicker.cjs` | the same, for Edo's canal — pins the camera **on the water**, which the gate above structurally cannot do | | `tools/domshim.cjs` | runs the built page against a fake DOM — boot, resize, input, worlds, tab loss | The renderer is deterministic: the same seed and frame give a byte-identical picture in a browser diff --git a/build.js b/build.js index 8a514f0..84b7157 100644 --- a/build.js +++ b/build.js @@ -204,7 +204,22 @@ const parts = files.map(p => { /* One IIFE, one `var CC`. core.js declares CC with `var`, so it is hoisted to the top of this * function and every later module's `typeof CC !== 'undefined'` guard sees it. Nothing leaks to * window, which is the point: the page has no API surface to poke at. */ -const bundle = '(function () {\n' + parts.join('\n') + '\n})();\n'; +/* ---- one 'use strict', not thirty-three ------------------------------------------------------- + * Every module in src/ opens its IIFE with `'use strict';` because every module is also `require`d + * on its own by tools/headless.cjs, where nothing else would supply it. Concatenated, that is 33 + * copies of the same 13-byte directive inside one wrapper that is itself sloppy-mode — so the + * directive is doing real work per module and cannot simply be deleted. + * + * Hoisting it is the cut. One directive on the wrapper makes the WHOLE bundle strict, which is + * exactly the union of what the 33 were doing individually, and there is no code in the bundle + * outside a module IIFE for it to newly apply to. 481 bytes, and the only non-content cut left + * after the dead-identifier sweep that does not touch a line of source. + * + * The match is deliberately narrow: a line whose ENTIRE content is the directive. A `'use strict'` + * inside a string literal or trailing another statement is left alone, because this runs after + * decomment() and has no parser to tell it apart. */ +const parts2 = parts.map(p => p.replace(/^[ \t]*(['"])use strict\1;[ \t]*$\n?/gm, '')); +const bundle = "(function () {\n'use strict';\n" + parts2.join('\n') + '\n})();\n'; /* The page must open with ZERO network requests, so nothing may reference a module loader. */ if (/\brequire\s*\(/.test(bundle)) throw new Error('build: a require() survived the strip'); @@ -217,7 +232,8 @@ if (/<\/script/i.test(bundle)) throw new Error('build: source contains a closing /* Every module named its global; if one is missing it was dropped, mis-ordered, or the comment * scanner ate something structural. Cheap, and it has caught both. */ for (const need of ['var CC', 'CC.City', 'CC.Surf', 'CC.Cast', 'CC.Canvas', 'CC.Main', - 'CC.World', 'CC.SurfWest', 'CC.Daylight', 'CC.ELEMENTS.push']) + 'CC.World', 'CC.SurfWest', 'CC.SurfMoon', 'CC.SurfJapan', + 'CC.Daylight', 'CC.ELEMENTS.push']) if (!bundle.includes(need)) throw new Error('build: bundle is missing ' + need); /* Compiles the bundle without running it. This is what makes the comment scanner safe to trust: @@ -403,8 +419,107 @@ console.log('index.html ' + bytes + ' bytes (' + (bytes / 1024).toFixed(1) + ' * WHAT THAT BUYS THE NEXT PASS, honestly: 25.5 KB is about a third of a world, so this is not a * reprieve. The next pass over the line has the same three options and one fewer of them — the * whitespace is spent now — and the two that remain are the two the essay above already refuses. - * Splitting the payload is still the escape hatch and it is still the last one. */ -if (bytes > 560 * 1024) { - console.error('build: index.html is over the 560 KB budget'); + * Splitting the payload is still the escape hatch and it is still the last one. + * + * ---- AND THE PASS AFTER THAT MOVED IT. 560 KB -> 580 KB, AT 567.5. ---- + * Fifth time at this line. The paragraph directly above says the next pass has three options and + * one fewer of them; this is the answer to that paragraph, taken in the order the note at the head + * of the file demands — cut what is not content, then cut content, then move the line, and write + * down which one you did. What was done is the third, and the first two were tried first. + * + * WHAT LANDED: a fourth world. EDO — a castle town on a wet evening — as src/surf_japan.js and + * src/elements/jp_town.js, plus a district table, a theme block, a weather table and a registry row + * inside four existing files, and thirteen shared atmospheric elements widened to include it. + * + * WHAT IT COST, and this is the number worth recording: 33.2 KB stripped, against the frontier's + * 65 and the Moon's 55. A world in this engine used to be "simply about that big" and it is now + * about half that big, and the reason is not that this one is thinner — it has a painter, five + * elements of its own, its own lighting model and its own sky. It is that the three registries the + * Moon's pass built (src/proj.js's shared element camera, CC.SURFACES's painter map and city.js's + * THEMES map) mean a fourth world writes almost no scaffolding: no projection, no view/emit/column, + * no per-world branch anywhere in raycast.js, main.js, control.js or tools/headless.cjs. The + * previous two passes paid for this one. + * + * WHAT WAS CUT FIRST, and it is honest to say it was almost nothing: 305 bytes of glyph constants + * declared and never used in the two new files. That is the whole of the non-content cut available, + * and it was looked for rather than assumed. The two candidates the essays above name are still + * the only two: + * STRIPPING INDENTATION OUTRIGHT is worth about 42 KB on top of the halving that already + * happened, and it is refused for the third time on the third file's own grounds — halving + * leaves a nested document a person can read, and stripping leaves a wall. That refusal is the + * one thing about this budget that has never moved and it should not move now. + * SPLITTING THE PAYLOAD costs the "one self-contained file" property, which is not a constraint + * on the deliverable, it IS the deliverable — the contract's first line. Spending it to avoid + * a 20 KB raise would be trading the thing the project is for a number that still describes + * one HTTP response. + * Deleting content to make a number is what the 420 essay forbids and it is still the wrong way + * round: the content is the point. + * + * SO: 580 KB, ~152 KB gzipped, still one response, still parsing in well under a frame, still a + * page source a person can open and read. Four worlds and a day cycle in 580 KB. + * + * THE HEADROOM IS DELIBERATELY SMALL and that is the whole of what this raise is willing to give. + * 12.5 KB is a third of a world and about one element file — it is not a reprieve and it is not + * meant to be. The 420 pass raised the line and left 4 KB and the note called that "not headroom"; + * this leaves three times that and says the same thing about it. The number was also set AFTER the + * last source file landed rather than while the tree was half-written, which is the one lesson the + * 560 pass wrote down about itself and then had to learn twice. + * + * WHAT THE NEXT PASS HAS. Two options, not three. The whitespace is spent, the unused-identifier + * sweep is spent, and the indentation refusal has now been reaffirmed three times, which should be + * read as settled rather than as an option still on the table. That leaves splitting the payload — + * and a fifth world is where it stops being the escape hatch and starts being the design. If you + * are here to add one: split first, then add it, and do not touch this line again. * + * ---- AND THE PASS AFTER THAT MOVED IT AGAIN. 580 KB -> 600 KB, AT 590.1. ---- + * Sixth time at this line, and the paragraph directly above it says not to do this. It is owed a + * straight answer rather than an edit, so here is the arithmetic that overruled it. + * + * WHAT LANDED: content for EDO — a CANAL in the map with a reflecting water surface, festival + * BANNERS, SAKURA trees, a castle KEEP, red-papered lanterns, a wider district accent, and dyed + * umbrellas on the crowd. Asked for by name, all of it. + * + * WHAT WAS CUT FIRST, because the procedure at the head of this file demands it and because the + * paragraph above says the sweep is spent — it was not: + * - `edgeDist()` in jp_town.js, dead on arrival one pass earlier when the stone lanterns were + * rewritten to walk the street instead of a lattice. MEASURED -416. + * - `'use strict'` hoisted from 33 module IIFEs onto the wrapper. Every module needs its own when + * `require`d alone by the harness, and concatenated they are 33 copies inside one sloppy-mode + * wrapper; one directive on the wrapper is the exact union of what they were doing. + * MEASURED -481, and all 36 four-world fixtures byte-identical. + * Both were taken. -897 total, and the pass ends up carrying more content per byte than it did. + * + * WHY THE LINE MOVED ANYWAY, AND THIS IS THE PART THAT IS NOT A DODGE. The content is 24 KB and the + * headroom was 13. THERE IS NO COMBINATION THAT FITS, and that was checked rather than assumed: + * everything, after the two cuts above ............ 604,283 (10,363 over) + * minus the castle keep (7.0 KB) .................. 597,325 (3,405 over) + * minus the keep AND the duplicated helpers ....... 594,975 (1,055 over) + * The last row is with EVERY cut this tree has left, including one that is not free (see below), + * and it is still over. So the choice was never "cut or raise" — it was "raise, or delete a third + * of what was asked for". Deleting content to make a number is what the 420 essay forbids and it + * is still the wrong way round. + * + * WHAT WAS MEASURED, BANKED AND DELIBERATELY NOT TAKEN, so the next pass does not re-derive it: + * the duplicated function bodies. `streetSpan` is byte-identical across market.js, west_town.js, + * west_stock.js and structure.js; `objVisible` across west_town.js and west_stock.js; `corridor` + * across police.js and street.js. Hoisting them into src/proj.js is worth about 2,350 bytes and it + * is the cut proj.js's own header asks for. It was NOT taken here for one reason: it does not + * change the outcome. It saves 2.3 KB against a 10.4 KB overrun, so the line moves either way — and + * it touches six files belonging to three shipped worlds, in exactly the operation this file + * already records as having cost two silent clock-cache bugs the last time it was performed. + * Risk with no benefit is not a cut, it is a coin flip. TAKE IT when it is worth something. + * + * SO WHAT DOES 600 KB MEAN? ~157 KB gzipped, one HTTP response, parsing in well under a frame, and + * a page source a person can still open and read. Four worlds, a day cycle and a canal in 600 KB. + * + * AND THE HONEST WARNING, which is the same one the paragraph above gives and it is now overdue: + * THE NEXT PASS MUST SPLIT. Not because 600 is a magic number but because the last three passes + * have each ended with the same finding — the content is bigger than the headroom and the cuts are + * rounding errors against it. The banked duplication cut above is the last non-content cut in the + * tree and it is worth two thousand bytes. A world is thirty thousand. Splitting the payload costs + * the "one self-contained file" property, which is the first line of CONTRACT.md and is a real + * loss — but it is the only remaining answer that is not "ship less", and it should be taken + * deliberately, by someone who has decided that trade, rather than discovered at this line again. */ +if (bytes > 600 * 1024) { + console.error('build: index.html is over the 600 KB budget'); process.exit(1); } diff --git a/docs/edo-canal.png b/docs/edo-canal.png new file mode 100644 index 0000000..49102b6 Binary files /dev/null and b/docs/edo-canal.png differ diff --git a/docs/edo.png b/docs/edo.png new file mode 100644 index 0000000..14298aa Binary files /dev/null and b/docs/edo.png differ diff --git a/index.html b/index.html index 8acf632..9035712 100644 --- a/index.html +++ b/index.html @@ -33,9 +33,9 @@
click for fullscreen