diff --git a/CONTRACT.md b/CONTRACT.md index 2e8e6eb..7c2423d 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -50,7 +50,7 @@ concatenates them in order and the headless harness `require`s them through a sh | `src/render_canvas.js` | `CC.Canvas` | glyph atlas, `drawImage` per cell, bloom. **Only DOM-touching module** | | `src/main.js` | `CC.Main` | loop, resize, fullscreen, seed in hash, prefers-reduced-motion | -## The palette — 20 swatches, two ladder entries each +## The palette — 21 swatches, two ladder entries each `PALETTE` in `core.js` is **append-only**. Slots 0-11 are frozen because a swatch index in this tree is a literal in other files — `surfaces.js`'s `L_LOW`/`L_LIT`/`L_HOT`, `ads.js`'s `PEAK`, @@ -67,6 +67,24 @@ Rules for the palette: through the whole of dawn, so the wall goes bright only after the sky already has. - The LUT's stride is read off `PALETTE.length`. It was a literal `12` once and that is exactly the failure above. +- APPENDING IS THE SUPPORTED GROWTH PATH AND IT HAS NOW BEEN EXERCISED, which is worth recording + because the section above is otherwise all warnings. Slot 20 `blossom` was added for the cherry: + one `PALETTE` row, one entry in each ladder, one name in the `P` map, one name in `metrics.py`'s + `NAMES`. Nothing else needed an edit — `ladder()` sorts an unlisted swatch onto the sky curve, + which is the right answer for a surface; the LUT stride and `render_canvas.js`'s atlas both read + `PALETTE.length`; and `surfaces.js` fills its per-slot tables to `PALETTE.length` with a neutral. + The 27-fixture byte-compare came back identical, so a swatch no other world writes costs those + worlds nothing. The check that matters is the parallel list in `metrics.py`, which WRAPS rather + than raising: a census taken with a short `NAMES` misattributes the new swatch to slot 0 and reads + as amber appearing in a world that has none. +- A NEW SWATCH IS FOR A MATERIAL THE TABLE CANNOT SPELL, not for a hue it already has. `blossom` and + `rose` are both pink and they are different objects: rose is a TUBE, at 57% saturation with the + lowest gain pair in either ladder specifically so a large area of it can never clear the hot line + and take the bloom with it. That bound is correct and it is why a cherry could not be painted in + rose — the crown is a SURFACE, lit by the sky, covering three hundred cells. The test to apply + before appending is whether the existing swatch's constraints are wrong for the new use or merely + inconvenient; here they were wrong, and desaturating to 30% is what makes the new one safe where + the old one is not. - Any painter that maps a hue to a material must be indexed **by palette slot with every slot filled**, not by a whitelist. `surf_west.js` carried `hue === P.warm || hue === P.white || hue === P.ember ? hue : P.amber` and every material the map learned to name after it was written @@ -208,6 +226,8 @@ what each world actually measures at each hour. The gates, in the order they are worth running: `node build.js`, `node tools/domshim.cjs`, `node tools/flicker-rate.cjs`, `node tools/lightning-rate.cjs`, `node tools/west-flicker.cjs 4`, +`node tools/canal-flicker.cjs`, `node tools/sakura-flicker.cjs 10`, +`node tools/sakura-flicker.cjs 10 jp-blossom --cells=4`, the census, and a determinism check (the same seed, frame, world and hour rendered twice must be byte-identical). @@ -219,6 +239,40 @@ feature lives somewhere the pinned camera never stands, measure it where it live `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. +THE SAME RULE CAUGHT THE CHERRY, which is the second feature to fall through the same hole and is +why this is written as a pattern rather than as one file's story. On the tree the cherry work started +from, `west-flicker.cjs` rendered 20 sakura cells of 4,800 from its pinned pose at seed 3 and 15 at +seed 42 — of which ZERO printed above the black line — and its japan rows came back BYTE-IDENTICAL +whether the crown was drawing zero visible cells a frame or eighty. It passed the tree in both states +without ever measuring it. + +THAT NUMBER IS A MOVING TARGET AND THE FIRST VERSION OF THIS PARAGRAPH SHIPPED IT AS A CONSTANT. +Raising the cherry's accept rate put a crown at the map's start pose, so the same gate now renders 80 +cells there, 45 of them printing — which quietly turned the new probe into a second copy of +west-flicker, because it pinned as soon as its threshold was met and its threshold was met at frame +zero. Two lessons, and the second is the general one: a pinned gate's blindness is a property of the +CONTENT as much as of the camera, so it cannot be written down once; and a walking probe must +threshold on what PRINTS, not on what the element owns, or it will stop on invisible occluding mass +and report a pose the viewer never sees. `tools/sakura-flicker.cjs` is the probe: it WALKS the autopilot until a stated +number of that element's cells PRINT, then pins there, and it scores only the cells that element +itself wrote, attributed by wrapping `CC.put` BEFORE `src/proj.js` is required — `proj.js` caches +`var put = CC.put` at module scope, so a wrapper installed after that require is never called by any +world-space element and the probe would measure an empty set while printing a confident PASS. Two +BOTH INVOCATIONS ARE IN THE GATE LIST ABOVE, and that is not tidiness. The default run measures the +TREE; the petal drift is a different element, needs `--cells=4` to be found at all, and returns +NOT_MEASURED at the default threshold. A maintainer who runs only the named default ships a petal +change having measured only the crown, which is this section's own rule failing one level down. + +Three further things that cost a measurement each and are now in that file's header: an element that is +SIMULATED rather than drawn from the map cannot be found by a search loop that does not call +`update()` on every frame (the first cut reported "no crown reached" for a drift the pinned run in +the same process measured at 41 cells), and the window is an ARGUMENT rather than a constant because +a rate is quantised by it — at four seconds a rate is a multiple of 0.25/s, which is too coarse to +judge against a 1.00/s limit. Quote the window with the number. + +Both of these probes take a pose the shipped gates cannot reach, and both of them found something +there. Assume the next feature that lives off the start pose needs a third. + `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 diff --git a/README.md b/README.md index d5abe99..d8c1ea4 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,8 @@ 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 | +| **Edo** seed 42 | 36.3 / 0.70 | 43.8 / 3.08 | 51.6 / 3.23 | +| **Edo** seed 7 | 29.5 / 0.03 | 34.9 / 2.23 | 44.7 / 1.17 | Four things in that table are worth saying out loud rather than leaving for someone to notice. @@ -113,8 +113,8 @@ tail is 0.41% at dusk against 7.27% at night — and that is not a bug to be tun 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 +Edo is the only world whose hot tail goes the *other* way — well under a per cent at night against +three 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 @@ -539,6 +539,7 @@ Everything here runs without a browser, which is how the thing gets verified at | `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/sakura-flicker.cjs` | the same, for the cherry — **walks** until the element's own cells PRINT in the frame, then pins, and scores only those cells. `[seconds] [element] [--cells=n] [--time=]`, and a verdict is only taken at the 10 s reference window. Run it twice: `10` for the crown and `10 jp-blossom --cells=4` for the drift | | `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 84b7157..3a8a41a 100644 --- a/build.js +++ b/build.js @@ -384,6 +384,17 @@ console.log('index.html ' + bytes + ' bytes (' + (bytes / 1024).toFixed(1) + ' * is not about the number: it is that a budget set against a half-finished tree is a guess with a * decimal point on it, and the right moment to set one is after the last file lands. * + + * THE CHERRY PASS COST 755 BYTES and made NONE of the three moves this essay asks for, which is + * recorded here because the contract asks each pass to say which one it did. It cut nothing, moved + * no line, and added content: 606,893 -> 607,648, leaving 6,752 bytes. Most of it is one function — + * the petal drift reading the crown anchors src/elements/jp_flora.js had been publishing to nobody + * since it landed — and the rest is a constant and a glyph. Four of the pass's ten edits were zero + * bytes or negative, which is the only reason a change that rewrote three files fits in a tenth of + * the headroom at all. + * + * So the finding below stands untouched for the fourth pass running, and the margin is now a tenth + * smaller than when it was written. The next feature of any size cannot be paid for out of this. * THE MOON COST 55 KB stripped — 11.5 for the painter, 43.4 for eleven elements — against the * frontier's 65. Neither is bloated; a world in this engine is simply about that big. * diff --git a/index.html b/index.html index 9035712..dac59e0 100644 --- a/index.html +++ b/index.html @@ -67,12 +67,15 @@ var CC = (function () { [ 92, 126, 74], - [ 58, 70, 142] + [ 58, 70, 142], + + [240, 168, 196] ]; var P = { amber:0, azure:1, ember:2, spring:3, violet:4, white:5, red:6, slate:7, warm:8, ice:9, pure:10, shadow:11, - stone:12, timber:13, sand:14, jade:15, rose:16, gold:17, moss:18, indigo:19 }; + stone:12, timber:13, sand:14, jade:15, rose:16, gold:17, moss:18, indigo:19, + blossom:20 }; var GLYPHS = " .,:;'\"`^~-_=+*|/\\()[]{}<>!?#%&$@8OoQ0XZWMNHUVAKY".split(''); var GI = {}; @@ -176,7 +179,9 @@ var CC = (function () { 0.46, - 0.56 + 0.56, + + 0.28 ]; @@ -219,7 +224,9 @@ var CC = (function () { 0.74, - 0.62 + 0.62, + + 0.86 ]; var GAMMA_DAY = 0.62, KNEE_DAY = 0.030; @@ -2827,6 +2834,7 @@ var CC = (function () { var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_QUOTE = g("'"), G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_TILDE = g('~'), G_PIPE = g('|'), G_PLUS = g('+'), G_8 = g('8'), G_o = g('o'), G_X = g('X'), G_STAR = g('*'), + G_HASH = g('#'), G_DQ = g('"'); function cfg() { return CC.Surf ? CC.Surf.cfg : null; } @@ -2862,7 +2870,7 @@ var CC = (function () { var SKY_UP = 1.00, SKY_SIDE = 0.52; function sunOf(cell) { - var dome = SKY_SIDE * (0.16 + 0.84 * dSky); + var dome = SKY_SIDE * (0.16 + 0.84 * dSky) + 0.33 * dFill; var op = openSky(); if (!cell || cell.faceX === undefined) return dome + 0.18 * dSun * op; @@ -3063,18 +3071,21 @@ var CC = (function () { if (glow > 0.02) { var flick = CC.reducedMotion ? 1 : 0.90 + 0.10 * vnoise(t * 0.9 + bay * 7.3 + sd * 0.01, 0x2D); - var base = (168 + 62 * hash2(bay, storey, sd ^ 0x11)) * glow * flick; + + var gh = hash2(bay, storey, sd ^ 0x11); + var gPan = gh > 0.5 ? G_HASH : G_8; + var base = (168 + 62 * gh) * glow * flick; if (wRain > 0.25 && lod === 2 && !CC.reducedMotion && hash2(Math.floor(u * 9), Math.floor(v * 5 - t * 0.7), sd ^ 0x4C7) < 0.06 * wRain) return fset(G_PIPE, P.stone, base * 0.68); - if (lod < 2) return fset(G_8, P.warm, base * 0.86); + if (lod < 2) return fset(gPan, P.warm, base * 0.86); if (fpu < 0.16 || fpv < 0.13) return fset(fpv < 0.13 ? G_DASH : G_PIPE, P.timber, base * 0.30); if (storey === 0 && v < st.gnd * 0.34) return fset(G_EQ, P.timber, (24 + 60 * sun) * gr); - return fset(G_8, P.warm, base); + return fset(gPan, P.warm, base); } if (st.vert) { @@ -6422,7 +6433,7 @@ var CC = (function () { G_STAR = CC.g('*'), G_AT = CC.g('@'), G_8 = CC.g('8'), G_o = CC.g('o'), G_SLASH = CC.g('/'), G_BSL = CC.g('\\'), G_Y = CC.g('Y'); - var CITY = null, BASE = 0, JP = null; + var CITY = null, BASE = 0, JP = null, LAT = 3.93; function boot(city) { CITY = (city && city.aveX && city.world === 'japan') ? city : null; BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 6) & 0x3fffff) : 0; @@ -6440,6 +6451,8 @@ var CC = (function () { DAYF = (JP && JP.dayFill !== undefined) ? JP.dayFill : 0; LAMP = CC.Daylight ? CC.Daylight.P.lamp : 1; + + LAT = RAD_F * CR_MAX + OFF_F * CR_MAX * Math.sqrt(1 + V.hp * V.hp); } function wxOf(axis, along, cross) { return axis ? along : cross; } @@ -6463,7 +6476,13 @@ var CC = (function () { }; CC.JPFlora = FL; - var TREE_PITCH = 12.0, TREE_R = 42, TREE_ACCEPT = 0.19; + var TREE_PITCH = 12.0, TREE_R = 42, TREE_ACCEPT = 0.32, CR_MAX = 3.4; + + var CBX = new Float64Array(3), CBY = new Float64Array(3), CBZ = new Float64Array(3); + + var RAD_F = 0.76, RY_F = 0.60; + var OFF_F = 0.50, OFF_MID = 0.16; + var MOUND = [0.60, 0.42, 0.42]; var TREE_OK = { garden: 1, temple: 1, machiya: 1, market: 1 }; var CAN_NEAR = 9.5; @@ -6474,6 +6493,8 @@ var CC = (function () { var T_RIM = 0.22, T_MID = 0.07; + var T_LOB = 0.10; + var SH_LO = 0.34, SH_W = 0.18; var SH_FAR = 0.12, SH_D0 = 18, SH_DK = 1 / 26, SH_LEAF = 0.16; @@ -6524,7 +6545,9 @@ var CC = (function () { var nf = fu * 0.46 + fv * 0.54; var tier = q > Q_MID ? 2 : (q > Q_CORE ? 1 : 0); - var shF = (nf - shLo - (tier === 2 ? T_RIM : (tier === 1 ? T_MID : 0))) * shK; + var lob = vy < 0 ? T_LOB * vy : T_LOB * 0.30 * vy; + var rimT = tier === 2 ? T_RIM + lob : (tier === 1 ? T_MID + 0.45 * lob : 0); + var shF = (nf - shLo - rimT) * shK; if (shF < 0) shF = 0; else if (shF > 1) shF = 1; var d = dc - rad * 0.86 * Math.sqrt(1 - q); @@ -6549,12 +6572,34 @@ var CC = (function () { tier === 2 ? (fw > 0.5 ? G_QUOTE : G_TICK) : (tier === 1 ? (fw > 0.5 ? G_STAR : G_o) : (nf > 0.52 ? G_AT : G_8)), - tier === 1 ? (fw > 0.5 ? cB : cA) : cA, + + tier === 1 ? (fw > 0.72 ? cB : cA) : cA, lum, d); } } } + function leader(f, x0, y0, z0, x1, y1, z1, u0, w, bias, col, lum) { + var dh = Math.sqrt((x1 - x0) * (x1 - x0) + (z1 - z0) * (z1 - z0)); + + var ns = Math.ceil((Math.abs(y1 - y0) * V.scale + 1.4 * dh * V.colK) / w) + 4; + if (ns > 30) ns = 30; + var lx = -1, ly = -1, i; + for (i = 0; i <= ns; i++) { + var u = u0 + (1 - u0) * (i / ns); + var hu = Math.pow(u, 0.55), vu = Math.pow(u, 1.6); + if (!project(x0 + (x1 - x0) * hu, y0 + (y1 - y0) * vu, z0 + (z1 - z0) * hu)) { lx = -1; continue; } + var xx = Math.floor(PJ.x), yy = Math.floor(PJ.y), g = G_PIPE; + if (lx >= 0) { + var ddx = xx - lx, ddy = yy - ly; + + if (Math.abs(ddx) * 1.6 > Math.abs(ddy)) g = (ddx > 0) === (ddy > 0) ? G_BSL : G_SLASH; + } + emit(f, xx, yy, g, col, lum, bias > 0 ? Math.max(0.6, PJ.d - bias) : PJ.d); + lx = xx; ly = yy; + } + } + function drawTrees(f, axis, idx) { var here = alongOf(axis); var lo = Math.floor((here - TREE_R) / TREE_PITCH), hi = Math.floor((here + TREE_R) / TREE_PITCH); @@ -6587,38 +6632,66 @@ var CC = (function () { var rx = px - V.ox, rz = pz - V.oz; var w = rx * V.fwx + rz * V.fwz; if (w < 1.0 || w > TREE_R) continue; - var sp = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; + var sp = rx * V.rgx + rz * V.rgz, lim = w * V.hp + LAT; if (sp < -lim || sp > lim) continue; var rr = hash2(k, side, BASE + 0x63); var th = 3.0 + rr * 1.9, cr = 1.9 + rr * 1.5; - column(f, px, pz, 0, th + 0.16, G_PIPE, tcol, tlum, w < 20 ? 1 : 0); + var crossAng = axis ? 1.5708 : 0; + var bi; + for (bi = 0; bi < 3; bi++) { + var bang = bi === 0 + ? hash2(k, side + 5, BASE + 0x65) * 6.2832 + : crossAng + (bi === 1 ? 0 : 3.1416) + (hash2(k, side + bi * 5, BASE + 0x65) - 0.5) * 1.2; + + var boff = cr * (bi === 0 ? OFF_MID : OFF_F); + CBX[bi] = px + Math.cos(bang) * boff; + CBZ[bi] = pz + Math.sin(bang) * boff; + CBY[bi] = th + cr * (MOUND[bi] + 0.18 * hash2(k, side + bi * 11, BASE + 0x66)); + } + + var fh = 0.40 * (th + cr * 1.24); + column(f, px, pz, 0, fh + 0.10, G_PIPE, tcol, tlum, 0); + + var hb = 0.16; + + var hbc = Math.ceil(hb * V.colK / w); + if (hbc < 1) hbc = 1; else if (hbc > 4) hbc = 4; + var q, qo; + for (q = 1; q <= hbc; q++) { + qo = hb * (q / hbc); + + var qh = fh * (0.82 - 0.10 * (q / hbc)); + column(f, wxOf(axis, along, cross + qo), wzOf(axis, along, cross + qo), + 0, qh, G_PIPE, tcol, tlum, 0); + column(f, wxOf(axis, along, cross - qo), wzOf(axis, along, cross - qo), + 0, qh, G_PIPE, tcol, tlum, 0); + } + if (w < 15) { + + leader(f, px, 0.34, pz, wxOf(axis, along, cross + 0.36), 0.02, + wzOf(axis, along, cross + 0.36), 0, w, 0, tcol, tlum); + leader(f, px, 0.34, pz, wxOf(axis, along, cross - 0.36), 0.02, + wzOf(axis, along, cross - 0.36), 0, w, 0, tcol, tlum); + } if (w < 30) { - var ns = Math.ceil(cr * 0.9 * V.colK / w) + 3; - if (ns > 14) ns = 14; - var b, s2i; - for (b = -1; b <= 1; b++) { + leader(f, px, fh, pz, CBX[1], CBY[1], CBZ[1], 0, w, 0, tcol, tlum); + leader(f, px, fh, pz, CBX[2], CBY[2], CBZ[2], 0, w, 0, tcol, tlum); - var lx = px + b * 0.62, lz = pz + b * 0.34; - var lh = th + cr * (0.50 - 0.10 * (b * b)); - for (s2i = 1; s2i <= ns; s2i++) { - var u2 = s2i / ns; - if (!project(px + (lx - px) * u2, th - 0.22 + (lh - th + 0.22) * u2, - pz + (lz - pz) * u2)) continue; - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), - b < 0 ? G_SLASH : (b > 0 ? G_BSL : G_PIPE), tcol, tlum * 0.94, PJ.d); - } - } + var mhu = Math.pow(0.45, 0.55), mvu = Math.pow(0.45, 1.6); + var mx = px + (CBX[1] - px) * mhu, mz = pz + (CBZ[1] - pz) * mhu; + var my = fh + (CBY[1] - fh) * mvu; + leader(f, mx, my, mz, CBX[0], CBY[0], CBZ[0], 0, w, 0, tcol, tlum); - if (project(px, th + 0.12, pz)) + if (project(px, fh + 0.06, pz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_Y, tcol, tlum, PJ.d); if (w < 15) { - if (project(px, th * 0.42, pz)) + if (project(px, fh * 0.42, pz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, tcol, tlum, PJ.d); - if (project(px, th * 0.68, pz)) + if (project(px, fh * 0.72, pz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, tcol, tlum, PJ.d); } } @@ -6627,30 +6700,35 @@ var CC = (function () { var bloom = hash2(k, side * 3, BASE + 0x64) < 0.82; - var bi; for (bi = 0; bi < 3; bi++) { - var ang = bi * 2.0944 + hash2(k, side + bi * 5, BASE + 0x65) * 1.5; - var off = cr * 0.40; - var cbx = px + Math.cos(ang) * off, cbz = pz + Math.sin(ang) * off; - var cby = th + cr * (0.44 + 0.36 * hash2(k, side + bi * 11, BASE + 0x66)); + var cbx = CBX[bi], cby = CBY[bi], cbz = CBZ[bi]; - var lowY = cby - cr * 0.528; + var lowY = cby - cr * RAD_F * RY_F; var lf = lowY >= 4.2 ? 0 : (lowY <= 2.0 ? 1 : (4.2 - lowY) * 0.4545); var lampT = (kerb && LAMP > 0.02 && lf > 0) ? 148 * LAMP * lf * lf * (3 - 2 * lf) : 0; var cb = (12 + 168 * (1 - NIGHT) + 66 * DAYF) * (bloom ? 1 : 0.62); var warmLit = lampT > 18 && NIGHT > 0.5; - var cA = warmLit ? P.warm : (bloom ? P.white : P.moss); - var cB = warmLit ? P.warm : (bloom ? P.sand : P.moss); + var cA = bloom ? P.blossom : P.moss; + var cB = warmLit ? P.warm : (bloom ? P.white : P.moss); var far = (w - SH_D0) * SH_DK; if (far < 0) far = 0; else if (far > 1) far = 1; - billow(f, cbx, cby, cbz, cr * 0.66, cr * 0.66 * 0.80, + billow(f, cbx, cby, cbz, cr * RAD_F, cr * RAD_F * RY_F, BASE + 0x67 + bi, cb, lampT * (bloom ? 1 : 0.62), cA, cB, SH_LO + SH_FAR * far + (bloom ? 0 : SH_LEAF), 1 / SH_W, far * 0.85); } + if (w < 26) { + var BR_D = cr * (OFF_F + 0.86 * RAD_F + 0.04); + leader(f, px, fh, pz, CBX[1], CBY[1], CBZ[1], 0.45, w, BR_D, tcol, tlum); + leader(f, px, fh, pz, CBX[2], CBY[2], CBZ[2], 0.45, w, BR_D, tcol, tlum); + var thu = Math.pow(0.45, 0.55), tvu = Math.pow(0.45, 1.6); + leader(f, px + (CBX[1] - px) * thu, fh + (CBY[1] - fh) * tvu, pz + (CBZ[1] - pz) * thu, + CBX[0], CBY[0], CBZ[0], 0.30, w, BR_D, tcol, tlum); + } + if (FL.n < ANC_N && w > 13) { FL.x[FL.n] = px; FL.y[FL.n] = th + cr * 1.05; FL.z[FL.n] = pz; FL.r[FL.n] = cr * 1.2; @@ -6976,6 +7054,24 @@ var CC = (function () { function respawn(i, r) { var a = r * 6.2832; + var FL = CC.JPFlora; + if (FL && FL.n > 0) { + var j = (hash2(i, 7, BASE + 0x53) * FL.n) | 0; + if (j >= FL.n) j = FL.n - 1; + + var adx = FL.x[j] - V.ox, adz = FL.z[j] - V.oz, ad2 = adx * adx + adz * adz; + if (ad2 > 400 && ad2 < 1444) { + var q = Math.sqrt(hash2(i * 13 + 5, (r * 4096) | 0, BASE + 0x54)); + pX[i] = FL.x[j] + Math.cos(a) * FL.r[j] * q; + pZ[i] = FL.z[j] + Math.sin(a) * FL.r[j] * q; + pY[i] = FL.y[j] - q * 0.9; + pPh[i] = r * 6.2832; + pVy[i] = 0.32 + r * 0.36; + pSp[i] = 0.7 + r * 1.1; + pLife[i] = 7 + r * 9; + return; + } + } pX[i] = V.ox + Math.cos(a) * (4 + r * 20); pZ[i] = V.oz + Math.sin(a) * (4 + r * 20); @@ -7077,7 +7173,8 @@ var CC = (function () { var warm = hash2(i, 0, BASE + 0x52) < 0.34; emit(f, Math.floor(PJ.x), Math.floor(PJ.y), - flat ? G_o : G_TICK, warm ? P.sand : P.white, + + flat ? G_o : G_TICK, warm ? P.sand : P.blossom, (flat ? 96 : 62) * fade * near * (0.42 + 0.58 * (1 - 0.6 * NIGHT)), PJ.d); } } diff --git a/src/core.js b/src/core.js index 7802365..d6ad9ae 100644 --- a/src/core.js +++ b/src/core.js @@ -65,13 +65,38 @@ var CC = (function () { [ 92, 126, 74], // 18 moss — dull green: planting, algae on concrete, sage, canvas. The // darkest pigment in the table after shadow, which is what a // leaf in ordinary light actually is - [ 58, 70, 142] // 19 indigo — deep blue: night glass, shade with sky in it, dusk haze. The + [ 58, 70, 142], // 19 indigo — deep blue: night glass, shade with sky in it, dusk haze. The // shade swatch for a world that has a sky in it, where `shadow` // is the shade swatch for a world that has none + /* ---- and one more, for the same reason the eight above exist ----------------------------- + * A swatch the first twenty could not spell: PALE PINK AS A SURFACE. The palette already has a + * pink — `rose` at slot 16 — and it is the wrong object. rose is a TUBE: hue 337 at 57% + * saturation, gain-bounded to 0.20/0.18 (the lowest pair in either table) precisely so a large + * area of it can never clear the hot line and take the bloom with it, because that is the + * failure that walked `violet` off magenta. Every one of those constraints is correct for + * signage and every one of them is wrong for a cherry in blossom, which is not a light source, + * is lit by the sky like any other surface, and covers three hundred cells of a frame. + * + * THE PIGMENT IS DESATURATED ON PURPOSE, and that is what makes it safe where rose is not. + * 240,168,196 is 30% saturation against rose's 57%: under this build's bloom it bleeds toward + * WHITE-pink, not toward magenta, so it does not reopen the failure the rose bound exists to + * close. It is also the more honest flower — someiyoshino photographs as a pale pink mass with + * white in it, which is why the previous pass's white+sand crown was a defensible reading of + * it even though it was not the one asked for. + * + * It blends on the SKY curve and not the sun, without an edit to ladder(), because the source + * test there is a membership list of things that EMIT and this does not emit. That is the right + * answer as well as the free one: blossom is lit by the whole hemisphere from first light, like + * stone, timber, sand, moss and indigo, and putting it on the sun curve would hold its night + * gain through the whole of dawn. */ + [240, 168, 196] // 20 blossom — pale pink SURFACE: sakura, and the first pink in this table + // that is allowed to cover area. See the note above for why it + // is not `rose` and must never be swapped for it ]; var P = { amber:0, azure:1, ember:2, spring:3, violet:4, white:5, red:6, slate:7, warm:8, ice:9, pure:10, shadow:11, - stone:12, timber:13, sand:14, jade:15, rose:16, gold:17, moss:18, indigo:19 }; + stone:12, timber:13, sand:14, jade:15, rose:16, gold:17, moss:18, indigo:19, + blossom:20 }; // Glyph table. Index 0 must stay blank — the frame is cleared to it. var GLYPHS = " .,:;'\"`^~-_=+*|/\\()[]{}<>!?#%&$@8OoQ0XZWMNHUVAKY".split(''); @@ -503,7 +528,7 @@ var CC = (function () { // the swatch would print DARKER at noon than at midnight. 94 is also the // honest reading: a hedge at night is darker than the concrete beside it, // and moss is 20 points under slate - 0.56 // 19 indigo — STRUCTURE, ceiling 115, which is slate's 114 to within a unit and is + 0.56, // 19 indigo — STRUCTURE, ceiling 115, which is slate's 114 to within a unit and is // meant to be. indigo is the shade swatch for a world with a sky in it // and slate is the far-haze swatch for the same world; they are two // readings of the same cold structure and they print at the same height, @@ -511,6 +536,17 @@ var CC = (function () { // changes HUE and not brightness. Rejected 0.70 (ceiling 124): night // glass that outprints the concrete around it reads as a lit window, // which is azure's job and comes with azure's gain + 0.28 // 20 blossom — STRUCTURE, and it takes a shade UNDER white's own gain for the reason + // sand takes exactly white's: this is the brightest pigment in the table + // (max channel 240, above white's 236), so an equal gain would make a + // blossom mass the brightest broad surface in a night frame — the exact + // fault white itself was brought down from 1.15 to fix. At 0.28 it lands + // between sand and white, which is where a pale petal seen by lamplight + // belongs: brighter than dust, dimmer than render. + // Rejected 0.20, rose's own bound: that gain exists to CRUSH, and its + // knee takes every cell under lum 96 to black — correct for a small + // signage cell written near full scale, and it would delete two thirds of + // a canopy. The bound is right for the tube and has nothing to say here ]; /* GAMMA and KNEE are held at the values the previous round fitted, and that is a measurement * rather than an omission: re-swept over the 128 frames with the new EXPOSURE in place, GAMMA @@ -668,12 +704,17 @@ var CC = (function () { // night ceiling (94) rather than falling under it — see the night entry // for the whole of why this swatch is fitted from the day side backwards. // Sage and canvas in sun. Rejected 0.60 (ceiling 91), below night again - 0.62 // 19 indigo — shade with the sky in it, ceiling 104, and MID is the entire brief: it + 0.62, // 19 indigo — shade with the sky in it, ceiling 104, and MID is the entire brief: it // is the swatch for the part of a daylight frame that is neither lit nor // black, which is what stops a noon picture reading as a lit object cut // out of paper — the same job the shadow entry above describes, one tier // up and with an actual sky in it. Rejected 0.78 (slate's gain, ceiling // 118), which puts shade level with the sunlit concrete casting it + 0.86 // 20 blossom — sunlit blossom, and it must be able to cross the hot line, because the + // crown is the only day-hot surface EDO owns and the census tail depends + // on it. A step under white's 0.92 and a step over sand's 0.90 in effect, + // since the pigment is brighter than both. Rejected white's own 0.92: a + // petal is not render and should not print level with it ]; var GAMMA_DAY = 0.62, KNEE_DAY = 0.030; diff --git a/src/elements/jp_flora.js b/src/elements/jp_flora.js index c4fd076..c10a420 100644 --- a/src/elements/jp_flora.js +++ b/src/elements/jp_flora.js @@ -74,7 +74,7 @@ * those are two different answers and this file has to agree with the map it is standing on. * BASE goes through the same imul-and-shift spread city.js:14-34 argues for — a raw adjacent salt * is how two "independent" streams end up drawing the same numbers. */ - var CITY = null, BASE = 0, JP = null; + var CITY = null, BASE = 0, JP = null, LAT = 3.93; function boot(city) { CITY = (city && city.aveX && city.world === 'japan') ? city : null; BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 6) & 0x3fffff) : 0; @@ -106,6 +106,9 @@ * already carries the hysteresis, and a second night crossfade over the top of it put the whole * town out an hour before dusk. */ LAMP = CC.Daylight ? CC.Daylight.P.lamp : 1; + /* The lateral cull's slack, once a frame, because it is a function of the LIVE fov and the + * viewer can change that. See the derivation above the cull itself. */ + LAT = RAD_F * CR_MAX + OFF_F * CR_MAX * Math.sqrt(1 + V.hp * V.hp); } /* The street-lattice helpers, in the same shape jp_town.js and west_range.js use them. They are @@ -195,8 +198,69 @@ * structure collapses into the muddy band faster than the gap threshold's distance walk can * rescue it. Measured, extending the reach from 42 to 54 m added 6% more cells and moved neither * the census nor the picture. It is also 12 m inside the projection's own cull at - * CC.Surf.FOG_END = 125, so nothing here is ever fighting the far plane. */ - var TREE_PITCH = 12.0, TREE_R = 42, TREE_ACCEPT = 0.19; + * CC.Surf.FOG_END = 125, so nothing here is ever fighting the far plane. + * + * THE ACCEPT RATE WAS RAISED 0.19 -> 0.32, AND THIS MOVES THE EDO NIGHT, DAWN AND DUSK FRAMES. + * All three, said plainly: the contract gives a declared signature hour the same protection as + * night, EDO's dawn and dusk differ from the previous tree at five of six seeds, and the only + * other place in this pass that discusses those two stops is surf_japan.js's note arguing that + * its daylight FILL leaves them byte-identical. That argument is true and it is about a different + * term; what moves the golden hours is this constant and the two edits below it. Said here because + * CONTRACT.md's rule is that a MATERIAL change may move the night frame provided the source + * declares it; this one is material (there is more tree) and is not read off the clock, so it is + * not the scale case that rule forbids. + * + * WHAT IT BUYS AT NOON, WHICH IS THE HALF THAT GENERALISES. The sunlit crown is this world's only + * day-hot surface and there is now reliably one in shot: at seed 42 the visible crown roughly + * quadruples (measured 29.4 -> 133.7 cells a frame over a 601-frame walk at 200x60) and the same + * holds at every seed looked at, including seed 512 where it goes from a few cells to nearly two + * hundred. Census at 200x60 f300 seed 42 noon: muddy 49.6 -> 48.5, hot 2.67 -> 3.40, lit p90 + * 117 -> 139. + * + * WHAT IT BUYS AT NIGHT IS ONE SEED, AND THE FIRST VERSION OF THIS NOTE PRESENTED THAT AS THE + * GENERAL RESULT. It is not. At seed 42 — the seed in every fixture and every README table — the + * night crown goes from ZERO cells above the v = 9 black line (330.7 owned cells a frame, max + * printed value 4: a hole in the frontage, not a tree) to a legible cherry in 82.2% of frames at + * max printed v 91, because the lamp exception below finally has a kerb trunk near enough to fire + * on. At seeds 7, 1337, 512 and 3 the night crown is STILL exactly zero cells above the black + * line. The tree got bigger at four of six seeds and stayed invisible at four of six. + * + * AND AT ONE SEED THAT COSTS THE PICTURE. At seed 512, frame 300, night, the change is a pure + * subtraction: 428 cells darker by more than 8, ZERO cells brighter, all of it one crown-shaped + * bite taken out of the lit frontage by a canopy that prints nothing. The night census reads + * better for it (muddy 36.4 -> 32.9) because deleting dim texture always does, which is a good + * demonstration that the census cannot see this class of defect at all. The honest lever for the + * night image is not this constant — it is the lamp exception's REACH, which is where a later + * pass should go; the accept rate is kept because the noon result above stands on its own. + * + * The density argument above is unchanged in kind — 0.79 trees per side per street index becomes + * 1.33, which is still a town with cherries in it and not an avenue of them. The pitch was + * deliberately NOT touched; the boulevard argument above still holds. */ + var TREE_PITCH = 12.0, TREE_R = 42, TREE_ACCEPT = 0.32, CR_MAX = 3.4; + + /* ---- THE CROWN'S PROPORTIONS, named because FOUR places read them and two of them used to + * carry their own copy of the number. The lateral cull's slack (LAT) and the night lamp + * exception's underside (lowY) are both functions of this shape, and when the factors lived + * as literals at the billow call the cull deleted crowns that were still on screen and the + * lamp fired against an underside the crown no longer had. + * + * A SOMEIYOSHINO IS MUCH WIDER THAN IT IS TALL AND IT IS MOUNDED. The first cut of this file + * put three equal billows on a 120-degree ring at a flat random height, which unions to + * 1.42:1 — near enough a ball, and a ball on a post is a lollipop whatever the trunk does. + * The reference read is 1.6-2.0:1 with the mass high in the middle and sweeping down and out + * to thin ragged edges, so: one billow pulled IN to the axis and raised (MOUND[0], OFF_MID) + * and two pushed OUT and dropped. RAD_F and RY_F are chosen to hold rad*ry constant against + * the old 0.66/0.528 pair — 0.76*0.456 = 0.347 against 0.348 — so the billow's own cell count + * and therefore its census contribution is unchanged; only the SHAPE moves. */ + /* The three centres, hoisted to module scope and filled once per tree. They are computed + * BEFORE anything is drawn because the leaders have to aim at them, and they are module-level + * typed arrays rather than a per-tree literal because this file allocates nothing inside + * view() — the same rule the anchor block and the billow walk already keep. */ + var CBX = new Float64Array(3), CBY = new Float64Array(3), CBZ = new Float64Array(3); + + var RAD_F = 0.76, RY_F = 0.60; // horizontal radius, and vertical as a fraction of it + var OFF_F = 0.50, OFF_MID = 0.16; // ring offset for the outer billows, and for the peak + var MOUND = [0.60, 0.42, 0.42]; // billow 0 is the peak; 1 and 2 are the shoulders var TREE_OK = { garden: 1, temple: 1, machiya: 1, market: 1 }; /* THE NEAR CUT, and it is the single most load-bearing constant in this file. Inside CAN_NEAR the @@ -289,6 +353,28 @@ * reads flat; they are a shading nudge now rather than the tier's whole identity, and * 0.60 * 0.88 = 0.53 of base is raw lum 130 at noon, comfortably the first clean rung. */ var T_RIM = 0.22, T_MID = 0.07; + /* THE UNDERSIDE IS NOT THE TOP EDGE, and until this the rim thinned identically all the way + * round because the tier is a function of q — normalised radius — alone. A cherry's top is a + * clean mound and its bottom is ragged: clumps of blossom hanging BELOW the mass with gaps + * where the branches show through. Tilting the RIM THRESHOLD with the cell's own normalised + * world height buys exactly that, and it costs nothing to key: vy is already computed for q. + * It is asymmetric on purpose — the underside gets the full tilt and the top three tenths of + * it — so the mound's upper edge stays clean and almost no hot core cells are lost. + * SCALLOPS RATHER THAN A FRINGE, because nf is a CLUSTERED field: lowering the threshold + * under a clustered field lets whole clumps survive where a uniform one would grow an even + * fuzz. The ramp width SH_W is deliberately untouched — this shifts the threshold, it does + * not widen the transition, so no cell's ramp gets faster and no rate can move. + * + * WHAT IT COSTS, MEASURED AND NOT ARGUED, because lowering a threshold under a clustered + * field lands cells anywhere on the ramp and the rim is painted in `blossom`, not white — + * so the cells this buys arrive at raw lum 0..73, which is squarely inside the muddy band. + * At 200x60 frame 300: seed 42 moves muddy 51.2 -> 51.5 at noon and 43.6 -> 43.8 at dusk, + * hot 3.28 -> 3.23, and night is unchanged because the crown is black there anyway; seed 7 + * does not move at any hour. That is 0.3 points of mud for the one feature that separates + * a cherry's silhouette from a shrub's, and it is spent knowingly. If a later pass needs + * the budget back, damp T_LOB rather than widening SH_W — the ramp width is load-bearing + * for the rate gate and the threshold is not. */ + var T_LOB = 0.10; /* THE CLUSTER FIELD'S RAMP. `nf` below is a smooth world-space value-noise field in 0..1; cells * under SH_LO are the gaps between clusters and are written as BLACK OCCLUDING MASS, cells over @@ -523,7 +609,9 @@ /* The tier the cell is in, decided in world units on both axes, and it shifts the gap * threshold rather than scaling the luminance — see the T_RIM note above. */ var tier = q > Q_MID ? 2 : (q > Q_CORE ? 1 : 0); - var shF = (nf - shLo - (tier === 2 ? T_RIM : (tier === 1 ? T_MID : 0))) * shK; + var lob = vy < 0 ? T_LOB * vy : T_LOB * 0.30 * vy; + var rimT = tier === 2 ? T_RIM + lob : (tier === 1 ? T_MID + 0.45 * lob : 0); + var shF = (nf - shLo - rimT) * shK; if (shF < 0) shF = 0; else if (shF > 1) shF = 1; /* Convex depth: this cell is on the NEAR surface of the ellipsoid, so it sits up to `rad` @@ -567,14 +655,21 @@ var lum = (base * upF + lampB * (1 - 0.78 * up)) * tierF * shF * (0.90 + 0.20 * fw); /* Colour and glyph, both off the smooth fields and the tier — no per-cell hash. The mid - * tier picks between the two swatches on `fw`, which for a blossom tree is white against - * sand: jp_town.js's drift already uses that pair as "a petal with the light behind it" - * (line 400-402) and the canopy uses it for the same reason. */ + * tier flecks the pink mass with its highlight swatch on `fw`. */ emit(f, x, r, tier === 2 ? (fw > 0.5 ? G_QUOTE : G_TICK) : (tier === 1 ? (fw > 0.5 ? G_STAR : G_o) : (nf > 0.52 ? G_AT : G_8)), - tier === 1 ? (fw > 0.5 ? cB : cA) : cA, + /* 0.72 AND NOT 0.5: the highlight is a FLECK, so it gets under a third of the mid + * tier and the pink keeps the rest. At 0.5 the crown read as two interleaved bands of + * equal weight rather than as a pink mass with light coming through it. The glyph + * split above stays at 0.5 deliberately — mark and hue changing on different isolines + * of `fw` is what stops the canopy banding, since a cell that changed shape AND colour + * together drew the two fields as one edge. + * THIS MOVES THE EDO NIGHT, DAWN AND DUSK FRAMES, declared as the contract requires; + * `fw` is spatial noise on world height and not a clock quantity, so it is the + * material case and not the forbidden scale one. */ + tier === 1 ? (fw > 0.72 ? cB : cA) : cA, lum, d); } } @@ -615,6 +710,53 @@ * and TH_JAPAN is setbackMode 'podium' with lots 5-9 m deep, so "outer ring clear" and * "trunk cell clear" are genuinely different questions. */ + /* ================================================================================ A LEADER === + * One woody stroke from (x0,y0,z0) to (x1,y1,z1), sampled in WORLD space and projected per + * sample, which is what the three straight stubs this replaced could not be: column() takes + * one ground position and two heights, so three of them at offset bases draw three parallel + * vertical bars beside the trunk and the object stays a lollipop. Same method as + * west_range.js's catenary and jp_town.js's kasagi curve, and it takes the perspective free. + * + * THE CURVE IS TWO SEPARATED EXPONENTS AND THAT IS THE WHOLE OF THE S. A cherry leader leaves + * the fork close to horizontal and arrives at the crown close to vertical; interpolating both + * axes linearly gives a straight ray, which is a fan, not a tree. Advancing the horizontal on + * u^0.55 and the vertical on u^1.6 spends the early samples going OUT and the late ones going + * UP, so the stroke leaves the bole shallow and stands up under the mass it carries. + * + * u0 lets the caller re-walk only the upper section — see the through-crown pass, which draws + * the same world line a second time with a depth bias so it prints INSIDE the blossom. + * + * THE GLYPH COMES OFF THE PROJECTED STEP, which is the one place in this file that reads a + * screen delta, and it is allowed here for a reason the crown could never claim: tlum is a + * constant across all three glyphs, so a glyph that changes as the camera walks carries NO + * luminance step with it. The header's world-keying rule exists to stop a cell's BRIGHTNESS + * crawling; a '/' becoming a '|' at the same value cannot register on a rate gate. */ + function leader(f, x0, y0, z0, x1, y1, z1, u0, w, bias, col, lum) { + var dh = Math.sqrt((x1 - x0) * (x1 - x0) + (z1 - z0) * (z1 - z0)); + /* Sample off the PROJECTED span, and the vertical dominates it: 3.5 m of rise at 14 m with + * V.scale 77.4 is 19 rows, which the eight-to-fourteen samples the stubs used could not + * cover without dashing the stroke. */ + var ns = Math.ceil((Math.abs(y1 - y0) * V.scale + 1.4 * dh * V.colK) / w) + 4; + if (ns > 30) ns = 30; + var lx = -1, ly = -1, i; + for (i = 0; i <= ns; i++) { + var u = u0 + (1 - u0) * (i / ns); + var hu = Math.pow(u, 0.55), vu = Math.pow(u, 1.6); + if (!project(x0 + (x1 - x0) * hu, y0 + (y1 - y0) * vu, z0 + (z1 - z0) * hu)) { lx = -1; continue; } + var xx = Math.floor(PJ.x), yy = Math.floor(PJ.y), g = G_PIPE; + if (lx >= 0) { + var ddx = xx - lx, ddy = yy - ly; + /* The lean is the SIGN PAIR, not the sign of ddx: '\\' runs top-left to bottom-right, so a + * stroke leans that way whenever x and y move together on screen. Keying on ddx alone was + * right for the leaders, which always rise, and inverted for the root flare, which does + * not — the buttresses came out leaning into the trunk instead of away from it. */ + if (Math.abs(ddx) * 1.6 > Math.abs(ddy)) g = (ddx > 0) === (ddy > 0) ? G_BSL : G_SLASH; + } + emit(f, xx, yy, g, col, lum, bias > 0 ? Math.max(0.6, PJ.d - bias) : PJ.d); + lx = xx; ly = yy; + } + } + function drawTrees(f, axis, idx) { var here = alongOf(axis); var lo = Math.floor((here - TREE_R) / TREE_PITCH), hi = Math.floor((here + TREE_R) / TREE_PITCH); @@ -666,13 +808,53 @@ /* Is it worth any work at all? The same three tests moon_craft.js's seeAt() makes: in front * of the eye plane, inside the walk's own reach, and not so far off to the side that - * nothing it owns can land in the frame. The +14 on the lateral limit is a crown's own - * half-width in columns at close range — a tree whose trunk is off the edge can still have - * half its canopy in shot. */ + * nothing it owns can land in the frame. + * + * THE SLACK IS ADDITIVE AND IT IS SIZED IN METRES OFF THE OBJECT, which is the correction + * a proportional version taught. The exact frustum edge is |sp| = w * V.hp. + * + * THE DERIVATION, and the first version of this note got it wrong twice. It said the reach + * was 0.40*cr of billow offset plus 0.66*cr of billow radius = 1.06*cr = 3.60 m at the cr + * ceiling, and shipped 3.6 — which is under even its own figure of 3.604, and the figure + * itself was wrong. The billow offset points in an ARBITRARY world direction, not a lateral + * one, so a billow pushed partly away from the eye sits at a larger w and is judged against + * a WIDER frustum. A sample is visible while |sp + off*cS + uu| < hp*(w + off*cF) with + * cF^2 + cS^2 = 1 and |uu| <= 0.66*cr, and the worst case over that circle is + * 0.66*cr + 0.40*cr*sqrt(1 + hp^2) = 1.1544*cr at the default fov = 3.93 m at cr 3.4. + * That is why LAT is computed in view() from the LIVE V.hp rather than frozen: the viewer + * can change fov, and a slack fitted to one fov is wrong at the others. + * + * The 0.33 m that 3.6 was short cost four poses out of 46,128 scanned per seed, one cell + * each, every one of them fogged to lum 0 — measured, not assumed. It is corrected anyway + * because a note that states a bound as proven should state the right one. + * + * The version this replaced, `w * (V.hp + 0.10)`, was written as a tightening of a slack + * that said 14 metres where the line above it said "a crown's own half-width", and it is + * recorded here because it looked equivalent and was not. 0.10*w only reaches 3.6 m at + * w = 36 m, so across almost the whole operating range (CAN_NEAR 9.5 m to TREE_R 42 m) a + * tree whose trunk was just outside the frustum but whose canopy was inside it was culled + * ENTIRELY — and this cull is per-tree and all-or-nothing, so the canopy did not fade at + * the frame edge, it vanished between two frames. Measured at seed 42 over 1201 frames, + * 16 frames differed and the worst lost 316 cells at once across 33 columns; on the cells + * the tree owned the frame before, that pop is a step of 153/255 with 61 cells over + * west-flicker's own 85/255 big-step line, at noon. A cull that is invisible to both pinned + * gates is exactly where a rate defect hides. At this slack the tree draws the same cells as + * the old +14 rule on every one of 1201 frames at seeds 42, 7 and 404, and still culls far + * earlier than 14 m of slack ever did. + * + * THIS CULL IS NOW LOAD-BEARING FOR SOMETHING ELSE, and that is worth knowing before anyone + * tunes it again. The anchor publish at the foot of this loop sits BELOW this `continue`, so + * jp_town.js's petal drift can only shed from crowns that survive this test: a drawing + * optimisation is now simulation input, and a change here moves the frame through the + * petals even where it moves no canopy. Measured: +3.6 and +14 give byte-identical EDO + * frames at f300 and f600 and differ at f900, f1200, f1500 and f1800, and the differing + * cells are mostly kind 3 while the tree's own owned-cell set is identical at all but 7 of + * 184,512 scanned poses. If that coupling is ever unwanted, publish the anchor above this + * line rather than below it. */ var rx = px - V.ox, rz = pz - V.oz; var w = rx * V.fwx + rz * V.fwz; if (w < 1.0 || w > TREE_R) continue; - var sp = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; + var sp = rx * V.rgx + rz * V.rgz, lim = w * V.hp + LAT; if (sp < -lim || sp > lim) continue; /* HEIGHT AND CROWN RADIUS SHARE ONE HASH, which saves a draw and is physically right: a @@ -684,55 +866,132 @@ * the read. Crown top is th + cr*1.3 = 5.5-9.3 m, above garden's hMax of 5.0 so the setback * tree clears its own quarter's wall. */ var rr = hash2(k, side, BASE + 0x63); - var th = 3.0 + rr * 1.9, cr = 1.9 + rr * 1.5; + var th = 3.0 + rr * 1.9, cr = 1.9 + rr * 1.5; // CR_MAX below is this line's ceiling - /* ---- the trunk, the bark, the limbs and the fork --------------------------------------- - * The trunk goes through column(), which projects the two ENDS and fills between them — - * the only way a vertical stays one cell wide and does not shear as the camera pans. Two - * cells wide inside 20 m, where a 0.35 m trunk genuinely is two columns. */ - column(f, px, pz, 0, th + 0.16, G_PIPE, tcol, tlum, w < 20 ? 1 : 0); + /* ---- WHERE THE THREE BILLOWS ARE, computed before anything is drawn ------------------ + * The leaders aim at the crown, so the crown's centres have to exist first. This is the + * same arithmetic the billow loop used to do inline; it moved up here and the loop below + * now reads the arrays rather than re-deriving them, so there is exactly one definition of + * where a billow sits and the woody structure cannot drift away from the mass it carries. */ + /* THE SHOULDERS SPREAD ACROSS THE LANE, NOT ON A FREE RING, and this is what makes the + * fork legible rather than merely present. On a uniform 120-degree ring the two shoulders + * take a random world bearing, so about as often as not a leader points along the street — + * which is the view direction for a camera walking it — and a leader that runs into DEPTH + * projects to no screen spread at all. Measured on the free-ring version: the leaders came + * out as near-vertical parallel bars, i.e. the fan-seen-edge-on failure the old three-stub + * comment worried about, reproduced by a different route. + * Anchoring the two shoulders to the CROSS-street axis is also the truer shape — a lane + * cherry spreads over the road and into the frontage, not along the kerb — and it is still + * world-keyed: crossAng is a property of the street, and the jitter is the tree's own hash. + * The peak keeps a free bearing because at OFF_MID it barely leaves the axis anyway. */ + var crossAng = axis ? 1.5708 : 0; + var bi; + for (bi = 0; bi < 3; bi++) { + var bang = bi === 0 + ? hash2(k, side + 5, BASE + 0x65) * 6.2832 + : crossAng + (bi === 1 ? 0 : 3.1416) + (hash2(k, side + bi * 5, BASE + 0x65) - 0.5) * 1.2; + /* The peak sits close to the axis; the shoulders swing out. The jitter is halved from the + * old 0.36 because it is now a jitter ON a profile rather than the profile itself — at + * 0.36 a shoulder still out-topped the peak on a third of the rolls. */ + var boff = cr * (bi === 0 ? OFF_MID : OFF_F); + CBX[bi] = px + Math.cos(bang) * boff; + CBZ[bi] = pz + Math.sin(bang) * boff; + CBY[bi] = th + cr * (MOUND[bi] + 0.18 * hash2(k, side + bi * 11, BASE + 0x66)); + } - /* THE LIMBS ARE NOT column() CALLS. column() takes ONE ground position and two heights, so - * three of them at offset bases would draw three PARALLEL VERTICAL BARS beside the trunk, - * not a splay — the object would still be a lollipop. A slanted limb needs a line in screen - * space, so each limb is sampled in WORLD space and projected per sample, which is the same - * thing west_range.js's catenary and this world's own kasagi curve do (jp_town.js:322-332) - * and it takes the perspective for free. Sample count off the projected length so it never - * dashes: the limbs are short, so eight to twelve samples covers them at any range that - * still draws them at all. + /* ---- the bole, the fork, the leaders, the flare and the bark ------------------------- + * THE BOLE STOPS AT THE FORK AND THE FORK IS LOW. What this replaced ran one unbroken + * vertical from the ground to the crown's own underside and then splayed three 0.62 m stubs + * off the top of it — a post with a ball on it, which is the lollipop read exactly, and the + * stubs were six screen columns at 14 m inside a crown fifty columns wide. A cherry divides + * its bole at a third to a half of its height into TWO heavy leaders that carry the rest, + * and everything the eye uses to name the tree is in that division. * - * They stop at 30 m. Inside that a limb is 4-8 cells of real structure between the trunk - * and the mass; beyond it, it is one or two cells buried inside a canopy that is already + * fh is 0.40 of the whole tree — bole to crown top is th + cr*1.24 with the mound above — + * so the fork lands at 2.2-3.7 m, below the crown's underside at th - 0.036cr, which is + * what puts a visibly FORKED silhouette in the gap between the street and the mass. */ + var fh = 0.40 * (th + cr * 1.24); + column(f, px, pz, 0, fh + 0.10, G_PIPE, tcol, tlum, 0); + + /* THE FLARE, and the bole's real width, both in WORLD metres on the CROSS-street axis. + * The `wide` flag column() carries is a step function in apparent thickness — two cells at + * 19.9 m and one at 20.1 — where a bole is a continuous taper, and at 6 m a 0.35 m trunk + * genuinely subtends eight columns and was drawn as two. Two short columns straddling the + * bole give it width that shrinks with distance for free, and they stop at 0.80 of the fork + * so the bole is three cells at the foot and one at the fork: a taper, not a slab. They + * REPLACE column()'s `wide` flag rather than adding to it — carrying both made the foot four + * cells across, which is a pillar. + * + * THE AXIS IS THE CROSS-STREET ONE AND THAT IS NOT A DETAIL. Along-street is the view + * direction for a camera walking the lane, so an along-street offset differs almost purely + * in DEPTH and lands in the same screen column, widening nothing. They are drawn + * unconditionally rather than under a distance gate, because a gate only relocates the step + * it was meant to remove — past a few tens of metres their separation falls under a column + * and the depth test dedupes them at no cost. */ + var hb = 0.16; + /* HOW MANY COLUMNS THE HALF-WIDTH IS WORTH, rather than two fixed world offsets. A bole is + * a solid, so its width has to be FILLED in screen terms: at 0.16 m and colK 137.6 the two + * offsets are one column apart only near 22 m, and closer in they separate — the first cut + * of this drew three posts with gaps between them at every near tree, which is worse than + * the slab it replaced. Stepping the offsets so their projections land about a column apart + * fills it at any range, and the count collapses to one pair far out, where the depth test + * dedupes them for free. Capped at four pairs: nine cells is the widest a 0.35 m bole is + * ever worth, and the cap is what stops a degenerate near camera asking for hundreds. */ + var hbc = Math.ceil(hb * V.colK / w); + if (hbc < 1) hbc = 1; else if (hbc > 4) hbc = 4; + var q, qo; + for (q = 1; q <= hbc; q++) { + qo = hb * (q / hbc); + /* The outer pairs stop shorter, so the bole narrows as it rises instead of ending in a + * flat shoulder — the taper is in the silhouette, not only in the count. */ + var qh = fh * (0.82 - 0.10 * (q / hbc)); + column(f, wxOf(axis, along, cross + qo), wzOf(axis, along, cross + qo), + 0, qh, G_PIPE, tcol, tlum, 0); + column(f, wxOf(axis, along, cross - qo), wzOf(axis, along, cross - qo), + 0, qh, G_PIPE, tcol, tlum, 0); + } + if (w < 15) { + /* The root flare, as two short leaders rather than two columns of '/': column() with a + * diagonal glyph draws a vertical stack of them, which reads as a dashed post and not as + * a buttress leaning out of the foot. Sampled in world space, so they lean. */ + leader(f, px, 0.34, pz, wxOf(axis, along, cross + 0.36), 0.02, + wzOf(axis, along, cross + 0.36), 0, w, 0, tcol, tlum); + leader(f, px, 0.34, pz, wxOf(axis, along, cross - 0.36), 0.02, + wzOf(axis, along, cross - 0.36), 0, w, 0, tcol, tlum); + } + + /* THE LEADERS. Two off the fork to the two shoulder billows, and one tertiary off the first + * leader's midpoint to the peak — so the bole divides in two, which is what the eye reads, + * and the middle of the crown is carried by a branch rather than by a third ray from the + * same point. Three rays from one point is the fan this file started with. + * + * They stop at 30 m, where a leader is one or two cells inside a canopy that is already * writing every one of them. */ if (w < 30) { - var ns = Math.ceil(cr * 0.9 * V.colK / w) + 3; - if (ns > 14) ns = 14; - var b, s2i; - for (b = -1; b <= 1; b++) { - /* Out in the cross-street direction AND in the along-street direction, so the three - * read as a splay in both axes rather than as a fan seen edge-on from one bearing. */ - var lx = px + b * 0.62, lz = pz + b * 0.34; - var lh = th + cr * (0.50 - 0.10 * (b * b)); - for (s2i = 1; s2i <= ns; s2i++) { - var u2 = s2i / ns; - if (!project(px + (lx - px) * u2, th - 0.22 + (lh - th + 0.22) * u2, - pz + (lz - pz) * u2)) continue; - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), - b < 0 ? G_SLASH : (b > 0 ? G_BSL : G_PIPE), tcol, tlum * 0.94, PJ.d); - } - } + leader(f, px, fh, pz, CBX[1], CBY[1], CBZ[1], 0, w, 0, tcol, tlum); + leader(f, px, fh, pz, CBX[2], CBY[2], CBZ[2], 0, w, 0, tcol, tlum); + /* The tertiary leaves leader 1 at its u = 0.45 point, evaluated on the same two exponents + * so it starts ON the curve it branches from and not beside it. */ + var mhu = Math.pow(0.45, 0.55), mvu = Math.pow(0.45, 1.6); + var mx = px + (CBX[1] - px) * mhu, mz = pz + (CBZ[1] - pz) * mhu; + var my = fh + (CBY[1] - fh) * mvu; + leader(f, mx, my, mz, CBX[0], CBY[0], CBZ[0], 0, w, 0, tcol, tlum); + /* One cell at the crotch. 'Y' is the last glyph in GLYPHS and it is literally a fork. */ - if (project(px, th + 0.12, pz)) + if (project(px, fh + 0.06, pz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_Y, tcol, tlum, PJ.d); + /* THE BARK, inside 15 m, and it is what names the species. Sakura is horizontally * lenticelled where cryptomeria is vertically fibred, so two rows of '-' across the near - * trunk is the difference between a cherry and a cedar at a glance. Placed at FIXED WORLD + * bole is the difference between a cherry and a cedar at a glance. Placed at FIXED WORLD * HEIGHTS rather than on a screen-row parity, so the banding cannot crawl up the trunk as - * the camera walks — the same world-keying rule the canopy is built on, for two cells. */ + * the camera walks — the same world-keying rule the canopy is built on, for two cells. + * Keyed to fh and not to th now that the bole ends at the fork, or both dashes would land + * above the wood they are meant to be on. */ if (w < 15) { - if (project(px, th * 0.42, pz)) + if (project(px, fh * 0.42, pz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, tcol, tlum, PJ.d); - if (project(px, th * 0.68, pz)) + if (project(px, fh * 0.72, pz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, tcol, tlum, PJ.d); } } @@ -758,7 +1017,7 @@ * that and was the single largest muddy source in the element. * * WHAT THAT COST BUYS IS REAL. Measured night energy at seed 42 has - * jade at 0.4% and gold, moss, rose, spring and red all at 0.0%, so six of twenty swatches + * jade at 0.4% and gold, moss, rose, spring and red all at 0.0%, so six of the then-twenty * are absent from this world, and a leaf tree is the only large legitimate moss surface EDO * has. core.js calls moss "the darkest pigment in the table after shadow, which is what a * leaf in ordinary light actually is" — a green tree in this frame IS a dark object. @@ -769,17 +1028,13 @@ * white anyway, which jp_town.js:397-402 already argues. */ var bloom = hash2(k, side * 3, BASE + 0x64) < 0.82; - /* Three billows on radiating limbs, offset 0.40*cr from the trunk and staggered in height. - * rad 0.66*cr each, so the union is very close to a crown of radius cr with about 15% of - * overdraw — and overdraw is nearly free here because CC.put depth-rejects the second write. - * The vertical radius is 0.80 of the horizontal: a someiyoshino crown is about 1.3:1 wider - * than tall, and this gets that from a single radius parameter. */ - var bi; + /* Three billows, at the centres the leader pass already fixed — the peak pulled in to + * OFF_MID and raised, the two shoulders pushed out to OFF_F and dropped. rad RAD_F*cr each, + * so the union is close to a crown of radius cr with some overdraw, and overdraw is nearly + * free here because CC.put depth-rejects the second write. See the constants' own note for + * why the union is mounded and much wider than tall rather than the ball it was. */ for (bi = 0; bi < 3; bi++) { - var ang = bi * 2.0944 + hash2(k, side + bi * 5, BASE + 0x65) * 1.5; - var off = cr * 0.40; - var cbx = px + Math.cos(ang) * off, cbz = pz + Math.sin(ang) * off; - var cby = th + cr * (0.44 + 0.36 * hash2(k, side + bi * 11, BASE + 0x66)); + var cbx = CBX[bi], cby = CBY[bi], cbz = CBZ[bi]; /* ---- THE CANOPY'S LUMINANCE ACROSS THE DAY ---------------------------------------- * The only time dependence in this whole element is NIGHT, DAYF and LAMP, which are the @@ -804,6 +1059,21 @@ * zero above 3.6 m, and a crown sits at 3.0-9.3 m, so the lamp wash does not reach it * at all. A cherry tree in an unlit lane at night IS a silhouette, and it reads where * it crosses the lit paper frontage. + * WHAT THAT COSTS THE VIEWER, WRITTEN DOWN because the line above states the design + * and not the price. The canopy base is 12 + 168*(1-NIGHT) + 66*DAYF, which is exactly + * 12 for the whole night half of a 420 s cycle — 43% of the clock — and the landing + * phase is seeded per city, so a large share of first loads open inside it. At the + * shipped accept rate this was not a silhouette, it was nothing: seed 42 — the seed in + * every fixture and every README table — drew 330.7 crown cells a frame at night with + * ZERO of them above the v = 9 black line, max printed value 4, over 1801 frames. + * The fix is NOT a night term on this base. NIGHT is read straight off the director's + * clock, so `+ 190 * NIGHT` is precisely the scale CONTRACT.md forbids; it was built + * and it also makes the crown brighter at night (202) than at dusk (180), the hour + * this note calls the element's worst, and takes seed 404's night muddy from 25.6 to + * 30.8, across the target. The legal version of the same image is to give the LAMP + * EXCEPTION below a kerb tree near enough to fire on, which is what raising the accept + * rate to 0.32 does: at seed 42 that exception fired zero times in 601 frames on the + * shipped tree, and now yields 81.4 visible warm cells a frame. * * THE ONE EXCEPTION, and it is the one image this element exists for after dark: a lantern * lighting the underside of a branch hanging over the street. The low billow of a KERB @@ -828,26 +1098,76 @@ * 0.3-0.7% of a night frame. The frame's muddy share still moves DOWN, -0.34 points at * seed 7 and -1.06 at seed 42, because the crown's own black mass more than pays for it. * That was the brief's own budget for this exception and it is met. */ - var lowY = cby - cr * 0.528; + var lowY = cby - cr * RAD_F * RY_F; var lf = lowY >= 4.2 ? 0 : (lowY <= 2.0 ? 1 : (4.2 - lowY) * 0.4545); var lampT = (kerb && LAMP > 0.02 && lf > 0) ? 148 * LAMP * lf * lf * (3 - 2 * lf) : 0; var cb = (12 + 168 * (1 - NIGHT) + 66 * DAYF) * (bloom ? 1 : 0.62); - /* When the lamp term is what is actually lighting this billow, the swatch follows the - * light rather than the flower: warm paper light on white blossom is warm. */ + /* THE CROWN IS PINK, in `blossom` — core.js slot 20, the pale-pink SURFACE swatch that + * was appended for exactly this and is the first pink in the table allowed to cover area. + * It is NOT `rose`: rose is a neon tube, gain-bounded to 0.20/0.18 so it can never clear + * the hot line, and it prints 85 at noon against blossom's 221 — a rose crown is 100% + * muddy by construction. Measured through the shipped LUT at dist 6, printed ceilings: + * blossom 159 night / 203 dawn and dusk / 221 noon, against white's 163/209/226 and + * sand's 163/207/224. So the pink sits a shade under the white it is stippled with at + * every hour, which is the right way round, and it still crosses the census hot line of + * 170 by day — the crown stays EDO's only day-hot surface, which is the whole reason the + * previous white version was defensible. + * + * WHITE IS THE MINORITY AND IT IS THE HIGHLIGHT. A someiyoshino mass is not flat: it is + * pink with pale flecks where the light comes through, which is what the reference pixel + * art draws and what the fw split below produces. cA carries the core and the rim, cB + * flecks the mid tier only. + * + * When the lamp term is what is actually lighting this billow the light does start to own + * the hue — warm paper light on a pale flower is warm — but the whole crown going `warm` + * turned a cherry into a yellow ball hanging over the street. So the lamp case keeps the + * pink in the mass and spends `warm` on the flecks instead: a pink tree with a lantern + * under it, rather than a lantern-coloured tree. */ var warmLit = lampT > 18 && NIGHT > 0.5; - var cA = warmLit ? P.warm : (bloom ? P.white : P.moss); - var cB = warmLit ? P.warm : (bloom ? P.sand : P.moss); + var cA = bloom ? P.blossom : P.moss; + var cB = warmLit ? P.warm : (bloom ? P.white : P.moss); /* The gap threshold for this billow, walked out with its own depth — see SH_FAR. shK is * the reciprocal of the ramp width, hoisted here so the inner loop is one multiply. */ var far = (w - SH_D0) * SH_DK; if (far < 0) far = 0; else if (far > 1) far = 1; - billow(f, cbx, cby, cbz, cr * 0.66, cr * 0.66 * 0.80, + billow(f, cbx, cby, cbz, cr * RAD_F, cr * RAD_F * RY_F, BASE + 0x67 + bi, cb, lampT * (bloom ? 1 : 0.62), cA, cB, SH_LO + SH_FAR * far + (bloom ? 0 : SH_LEAF), 1 / SH_W, far * 0.85); } + /* ---- the branches SEEN THROUGH the blossom --------------------------------------------- + * THE MOST DISTINCTIVE THING ABOUT THE REFERENCE IS STRUCTURE VISIBLE INSIDE THE MASS — + * dark strokes crossing the pink, heaviest in the upper middle — and until this pass it was + * not merely absent but structurally impossible. The leaders are drawn at the trunk's own + * depth, while every billow cell is pushed toward the camera by up to off + rad*0.86; CC.put + * tests strict `dist < f.dist[i]`, so the canopy overwrote the whole splay wherever it + * covered it, which was everywhere. Measured on the tree this replaced, over 1200 autopilot + * frames: 82.6% of the limb cells the element wrote never reached the frame at seed 404, and + * the `Y` the old comment called "the difference between a lollipop and a tree" landed in + * 5.3% of its attempts — 0.07 cells a frame. + * + * So the upper half of each leader is walked a SECOND time with a depth bias, and the bias + * is derived rather than picked: it must exceed the furthest forward any billow cell can be + * pushed (off + rad*0.86) so the stroke wins inside the mass, and exceed it by only a few + * centimetres of cr so the stroke stays within the tree's own volume and cannot print in + * front of something standing between the camera and the crown. At cr*1.19 it lands about + * 4 cm of cr ahead of the crown's own frontmost cell, which the crown already occludes — + * nothing new is punched through the picture. + * + * Only from u = 0.45, because below that the leader is already in clear air and drawn; only + * inside 26 m, beyond which it is one or two cells inside a mass that is writing them + * anyway; and one cell wide, never `wide`. */ + if (w < 26) { + var BR_D = cr * (OFF_F + 0.86 * RAD_F + 0.04); + leader(f, px, fh, pz, CBX[1], CBY[1], CBZ[1], 0.45, w, BR_D, tcol, tlum); + leader(f, px, fh, pz, CBX[2], CBY[2], CBZ[2], 0.45, w, BR_D, tcol, tlum); + var thu = Math.pow(0.45, 0.55), tvu = Math.pow(0.45, 1.6); + leader(f, px + (CBX[1] - px) * thu, fh + (CBY[1] - fh) * tvu, pz + (CBZ[1] - pz) * thu, + CBX[0], CBY[0], CBZ[0], 0.30, w, BR_D, tcol, tlum); + } + /* ---- publish the anchor ---------------------------------------------------------------- * Recorded AFTER the draw, only beyond 13 m, and only while there is room. See the anchor * block above for why 13 and not 0. aY is the crown top and aR is 1.2*cr so a consumer that diff --git a/src/elements/jp_town.js b/src/elements/jp_town.js index dc8aea8..b264f99 100644 --- a/src/elements/jp_town.js +++ b/src/elements/jp_town.js @@ -509,12 +509,22 @@ * a petal drawn through would only muddle. So the pool fades out above `rain` 0.35 and the frame * gets its motion from the weather instead. * - * WHITE AND SAND, NEVER ROSE. core.js's palette note puts a prohibition on rose — "SIGNAGE AND - * SCREENS ONLY", because hue 337 under this build's bloom is the failure that walked violet off - * magenta — and a drift of pink petals is exactly the large-area use it forbids. It is also - * wrong about the flower: someiyoshino is white with a blush at the base and reads as white at - * any distance. So the drift is `white` with a share of `sand` in it, which is a petal with the - * light behind it, and the setting loses nothing. + * PINK, AND NEVER `rose` — WHICH ARE TWO DIFFERENT STATEMENTS AND THE FIRST VERSION OF THIS NOTE + * CONFLATED THEM. The prohibition in core.js is on the ROSE SWATCH: "SIGNAGE AND SCREENS ONLY", + * because hue 337 at 57% saturation under this build's bloom is the failure that walked violet + * off magenta, and rose's gain is bounded at 0.20/0.18 so that a large area of it can never clear + * the hot line. All of that is still true and rose is still forbidden here. What did not follow — + * and what this note used to claim — is that the drift therefore had to be white. + * + * It had to be white only because the palette could not spell a pale pink SURFACE, and that was a + * gap in the table rather than a fact about cherry blossom. core.js slot 20 `blossom` now fills + * it: 240,168,196 at 30% saturation, which blooms toward white-pink instead of magenta, on the + * SKY curve like every other surface, printing 159 at night and 221 at noon against rose's 140 + * and 85. So the drift is pink because the flower is pink, and the swatch that carries it is a + * surface rather than a tube. + * + * The `sand` half survives, for the lantern case only: a petal crossing a lantern's light takes + * the light's colour and not its own, which is the one time a viewer does not see the flower. * * DETERMINISTIC FROM t. The state is a small pool integrated in update(), the same shape the * tumbleweed uses, and every respawn draws from hash2 on (index, quantised t) rather than from @@ -522,11 +532,94 @@ var NPET = 30; var pX = null, pY = null, pZ = null, pPh = null, pVy = null, pSp = null, pLife = null; + /* THE DRIFT COMES OFF THE CROWNS, and until now it did not. src/elements/jp_flora.js publishes + * CC.JPFlora — up to eight live crown anchors, refilled every frame, with a centre, a top and a + * radius — and its own note says a consumer must tolerate n = 0 because the walk is often between + * eligible quarters. That consumer was never written: grep for JPFlora across src/ and the built + * bundle returned only the two lines that WRITE it. So the world drew cherries in one place and + * petals in another, on a ring round the camera, which is the one arrangement that guarantees the + * two are never seen in the same shot. + * + * A SECOND HASH, NOT A SECOND rng() CALL, and this is the constraint that shapes the code. init() + * seeds the pool from the SHARED element rng and nine EDO elements initialise after this one at + * layer 22; one extra draw here shifts every one of their noise streams, which is the failure + * CONTRACT.md records about elements drawing from one rng in layer order. hash2 is a pure + * function and costs the stream nothing. + * + * IT ALSO DECORRELATES RADIUS FROM BEARING, which was a real defect in its own right. Every one + * of the seven state fields below was derived from the single scalar `r`, so bearing (r * 6.2832) + * and radius (4 + r * 20) were welded together: a petal's distance from the camera DETERMINED its + * direction. Once the 11 m near cut below removes everything with r under about 0.35, what is + * left is a fixed 234-degree arc of world bearings — the drift had a hole in it in the same + * compass direction on every seed and at every hour. `q` is a second HASH, decorrelated from the + * bearing rather than independent of it — its varying input is a 1/4096 quantisation of the same + * r, so two petals inside one bucket share a radius. That is enough to break the weld and nothing + * observable follows from the residue; it is written down because the paragraph above argues from + * decorrelation and should not be read as claiming a second random draw. It is sqrt-distributed + * so petals spread evenly over the disc of the crown rather than bunching at its centre. + * + * BE HONEST ABOUT WHAT THIS BUYS, AND IT IS LESS THAN IT SOUNDS. Under the 11 m cut, a pool of 30 + * and the frustum, the drift is structurally incapable of more than a few cells a frame — raising + * NPET to 96 with this coupling in place moved seed 42 from 0.09 to 0.09 visible cells a frame, + * so the pool size is not the constraint and never was. Measured after this change over 601-frame + * walks at 200x60, petal cells printing above the black line run 0.1 a frame at seed 42 and 0.0 at + * seeds 512 and 3 — the drift is still BELOW THE VISIBILITY FLOOR of the shipped picture, exactly + * as the camera-ring version was. Written down so a later pass does not re-derive it: the blossom + * MASS in this world is the crown, at 300-425 cells a frame. This makes the drift correct and + * located, not visible. + * + * ITS RATE MOVED AND THE NUMBER IS HERE. Petals born on a crown 13-42 m out cross cells at + * different speeds than petals born on a ring 4-24 m round the camera, and this element has + * tripped the photosensitivity rule before. Measured with tools/sakura-flicker.cjs at its 10 s + * reference window, worst over seeds 42/3/404 x kiri/clear/tsuyu: the drift's own cells go from + * 0.20 to 0.60 big steps a second, and 1.04% to 0.97% in the 3-20 Hz band. The band — which is the + * project's actual rule — improved; the step rate tripled and is still well under the 1.00/s the + * probe holds a non-default world to and an order under west-flicker's 8.0/s backstop. */ function respawn(i, r) { var a = r * 6.2832; + var FL = CC.JPFlora; + if (FL && FL.n > 0) { + var j = (hash2(i, 7, BASE + 0x53) * FL.n) | 0; + if (j >= FL.n) j = FL.n - 1; + /* THE ANCHOR HAS TO BE INSIDE THIS ELEMENT'S OWN RECYCLE RADIUS or the spawn is thrown away + * on the next tick. update() below retires a petal at dx*dx + dz*dz > 1600, i.e. 40 m, while + * the publisher accepts a tree at a FORWARD distance of up to 42 m — and forward is not + * radial, so an accepted anchor reaches about 1.30 * w, near 54 m off to the side. Measured + * before this guard: at seed 42, 75 of 135 crown spawns in one window landed outside the + * recycle radius, against zero for the camera ring the old path used (its own 4-24 m ring + * could not reach it). Worse than the waste, the respawn draw is quantised at 2 Hz, so a + * petal born outside is re-placed on the same dead point for up to half a second before it + * moves at all. 1444 is 38 m squared — inside 40 with a margin for the crown radius the + * spawn then adds. Out-of-range anchors fall through to the ring, which is the same + * behaviour the publisher's own note asks for when there is no usable crown. + * + * THE NEAR BOUND IS A RATE BOUND AND IT WAS ADDED BECAUSE THE FAR ONE ALONE FAILED THE GATE. + * With only `< 1444` the drift concentrated on whichever crown was nearest, and at seed 3 + * under tsuyu that doubled the drift's own cell count (118 -> 234) and took it to 2.03% in + * the 3-20 Hz band, over the project's 2% rule — a photosensitivity regression introduced by + * a change whose only stated purpose was to stop wasting petals. How fast a petal crosses a + * cell is a function of how near it is, which is the whole argument behind the 11 m cut + * further down; birthing the pool nearer is the same defect arriving by a different route. + * 400 is 20 m squared, and it puts the drift back at 0.97% in band and 0.60 big steps a + * second. Both ends of this bound are measured, and neither is a look. */ + var adx = FL.x[j] - V.ox, adz = FL.z[j] - V.oz, ad2 = adx * adx + adz * adz; + if (ad2 > 400 && ad2 < 1444) { + var q = Math.sqrt(hash2(i * 13 + 5, (r * 4096) | 0, BASE + 0x54)); + pX[i] = FL.x[j] + Math.cos(a) * FL.r[j] * q; + pZ[i] = FL.z[j] + Math.sin(a) * FL.r[j] * q; + pY[i] = FL.y[j] - q * 0.9; + pPh[i] = r * 6.2832; + pVy[i] = 0.32 + r * 0.36; + pSp[i] = 0.7 + r * 1.1; + pLife[i] = 7 + r * 9; + return; + } + } /* 4-24 m, not 6-32. A petal at thirty metres is a sub-cell object that projects to one dim * mark and is then culled by whatever is in front of it: measured at four seeds the wider ring - * put 0-8 of forty-six petals on screen, which is not a drift, it is a speck. */ + * put 0-8 of forty-six petals on screen, which is not a drift, it is a speck. + * This is the fallback the publisher requires: no crown in shot, so the ring round the camera + * is still what a viewer sees, exactly as it was before. */ pX[i] = V.ox + Math.cos(a) * (4 + r * 20); pZ[i] = V.oz + Math.sin(a) * (4 + r * 20); pY[i] = 3.4 + r * 4.2; @@ -679,7 +772,13 @@ * pool size, and that is where the cut was taken instead. Written down because the reasoning * for the streak is sound and the next person will have it too. */ emit(f, Math.floor(PJ.x), Math.floor(PJ.y), - flat ? G_o : G_TICK, warm ? P.sand : P.white, + /* PINK, in core.js's `blossom` (slot 20) — the drift is the same flower as the crown + * and has to be the same swatch or the petals read as ash coming off a cherry. The + * warm case keeps `sand`: a petal passing through a lantern's own light takes that + * light's colour, which is the one place the flower's own hue is not what a viewer + * sees. The prohibition this replaces was on `rose`, and it still stands — see the + * note by the swatch in core.js for why a tube and a petal are different objects. */ + flat ? G_o : G_TICK, warm ? P.sand : P.blossom, (flat ? 96 : 62) * fade * near * (0.42 + 0.58 * (1 - 0.6 * NIGHT)), PJ.d); } } diff --git a/src/surf_japan.js b/src/surf_japan.js index cd3e6ae..bca78c4 100644 --- a/src/surf_japan.js +++ b/src/surf_japan.js @@ -92,6 +92,7 @@ var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_QUOTE = g("'"), G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_TILDE = g('~'), G_PIPE = g('|'), G_PLUS = g('+'), G_8 = g('8'), G_o = g('o'), G_X = g('X'), G_STAR = g('*'), + G_HASH = g('#'), G_DQ = g('"'); /* The one thing this file and surfaces.js MUST agree on, because raycast.js configures only one @@ -188,9 +189,54 @@ * bottom of the ladder in exactly the weather it is supposed to be seen in. So the floor here is * the DOME, which is a real quantity, and the contrast the frame needs is bought back in the * glyphs instead — see the header's note on lines. */ + /* THE DAYLIGHT FILL, AND WHY A WALL IN THIS WORLD NEEDED ONE. EDO shipped as the only world in + * the tree whose NOON frame was DARKER than its night frame — lit 24.3% against 41.0% at seed 42, + * and the reversal held on every seed measured. The cause is arithmetic and it is all in this + * function. The lamp wash below is worth 0.86, while the ENTIRE daylight budget of a vertical + * face was SKY_SIDE = 0.52, and the one term that could have exceeded it, `direct`, is multiplied + * by openSky(), which under this world's own live weather (kiri, cloud 0.760) is 0.029. facade() + * then cubes what is left. Walls are 51.8% of the frame, so the whole picture inverted: the town + * was lit from its lanterns at midday. + * + * dFill AND NOT dSky IS THE WHOLE OF THE SAFETY ARGUMENT, and it is structural rather than tuned. + * dFill is smooth(clamp((dSky - 0.70) / 0.30)) — it is exactly 0 at night, and it is exactly 0 at + * BOTH signature hours, because the clock reports sky 0.657 at dawn and at dusk, under the 0.70 + * knee. So this term is the identity at night as CONTRACT.md requires of anything read off the + * clock, and it leaves the two golden-hour frames byte-identical rather than nearly so. Measured: + * EDO night, dawn and dusk are byte-identical at seeds 42, 7 and 1337 with this term in, and + * independently at six seeds x three frames on a tree with only this term reverted. + * + * IT NARROWS THE INVERSION, IT DOES NOT CLOSE IT EVERYWHERE. Over a 6-seed x 5-frame grid, noon + * lit still sits below night lit at 4 of 30 points, and one of them is seed 42 frame 300 — the + * fixture in every README table — where noon reads 40.3 against night's 40.9. The gap there was + * 16.6 points and is now 0.6. Noon also remains the dimmest of the three daylight stops at every + * seed measured, because the two other inversions named at the foot of this note are still in + * place. Said plainly so the next reader does not have to rediscover that "fixed" meant 26 of 30. + * + * K = 0.33 WAS SWEPT, AND THE FIRST SWEEP WAS TOO NARROW TO SUPPORT WHAT IT CLAIMED. It ran + * seeds 42/7/1337/512 at f300 only and concluded 0.33 was "the only value with every seed inside + * the 3.5-5 hot band". Widened to seeds 404 and 3 that is simply false: at 0.33 the noon hot tail + * reaches 8.01% at seed 404 f300 and 7.46% at seed 3 f300, and lowering K does not rescue it + * cheaply either — at K 0.20 seed 404 is still 5.01% while seed 42's noon lit falls from 40.3 to + * 35.4 and the inversion this term exists to fix comes back. + * + * The number is kept at 0.33 anyway, and the reason is that 3.5-5 is a NIGHT target and the other + * worlds do not meet it by day either. Measured at 200x60 f300 noon on this tree: the frontier + * runs 5.31% hot at seed 42, 7.68% at 404 and 6.51% at 3; the city runs 3.46/3.15/4.05; the Moon + * 2.85/2.41/3.06. EDO with this term lands at 3.17/8.01/7.46 — inside the family the frontier + * already occupies at midday, where before it was a world with almost no daylight at all. What + * would be wrong is quoting the narrow sweep as proof. The honest statement is that EDO's noon hot + * tail now varies 1.2-8.0% across seeds, which is the spread a sunlit world in this print has. + * Muddy rises, which is expected and permitted — a daylight frame is not held to the muddy + * target. + * + * TWO RELATED INVERSIONS ARE DELIBERATELY NOT FIXED HERE. The floor at the foot of this file + * inverts the same way, though its `0.55 + 0.45 * openSky()` is already the right shape — the + * wall is the term that lost it — and EDO's noon sky still prints about 65% P.shadow. Both are + * their own change with their own census; folding them in here would make this one unmeasurable. */ var SKY_UP = 1.00, SKY_SIDE = 0.52; function sunOf(cell) { - var dome = SKY_SIDE * (0.16 + 0.84 * dSky); + var dome = SKY_SIDE * (0.16 + 0.84 * dSky) + 0.33 * dFill; var op = openSky(); if (!cell || cell.faceX === undefined) return dome + 0.18 * dSun * op; /* The face crossed by a ray stepping +side has its outward normal pointing -side. */ @@ -610,7 +656,45 @@ if (glow > 0.02) { var flick = CC.reducedMotion ? 1 : 0.90 + 0.10 * vnoise(t * 0.9 + bay * 7.3 + sd * 0.01, 0x2D); - var base = (168 + 62 * hash2(bay, storey, sd ^ 0x11)) * glow * flick; + /* THE PANEL GLYPH ALTERNATES PER BAY, and it is the cheapest thing in this file that changes + * the picture. Measured at 200x60 f300 seed 42 night: '8' was 29.0% of every LIT cell in EDO + * and the world drew from 20 distinct glyphs against the city's 33, whose own top glyph is + * '_' at 13.7%. Rendered, that is fifteen unbroken rows of 8888 down the left third of the + * frame — this is the largest untextured surface in the project, at 17.5-25.5% of a night + * frame. Splitting it on the hash that is ALREADY being drawn for `base` takes '8' to 23.5% + * and the distinct count to 21, for one variable and no new noise stream. + * + * BE PRECISE ABOUT WHAT THAT BUYS, because a glyph histogram is not a texture measurement and + * this note first read as though it were. The hash is per (bay, storey), so a whole bay flips + * together: the structural measure — the share of panel ink sitting inside a horizontal run of + * six or more identical glyphs — is 35.9% before and 35.9% after at seed 42 f300, and at one + * frame the entire long-run mass simply migrated from '8' to '#'. So this is a LIGHTER PANEL + * GLYPH ON HALF THE BAYS, which is worth having on a frontage that was one repeated character + * across the whole lit third of the frame, and it is NOT a break-up of the runs. Breaking the + * runs needs a term that varies WITHIN a bay; the panel's own pu/pv module is computed two + * lines above and would cost nothing. That is the obvious next thing to try and it is not + * what this line does. + * + * `gh` HAS NO TIME TERM IN IT, deliberately: it is a pure function of (bay, storey, seed), so + * a cell's glyph cannot change while the camera is still. That matters more here than + * anywhere else in the file — the note below records that an 11 Hz hash on THIS panel is one + * of the five things that tripped the photosensitivity gate when EDO landed. The glyph does + * flip as a bay boundary sweeps a column during the walk, which is a per-cell step and is why + * this change was measured with a walking probe and not only with the pinned one. + * + * The obvious cheaper version — changing the temple row of the style table away from '8' — + * was built and measured NO effect: '8' stayed at 29.0%, because the frame's '8' is machiya + * frontage coming through this path, not temple lots. */ + /* NAMED gh, AFTER TWO NAMES THAT WERE ALREADY TAKEN. `var` is function-scoped, and facade() + * is long: it already owns `bh` ("this bay's identity, stable forever") and, inside the + * `st.flat` kura branch, `ph`. A second `var` under either name is the SAME binding, silently + * reassigned for the rest of the call. Both were benign for the same reason — every read of + * the outer one lies on a path that returns before this line — and no byte compare could ever + * have shown it. That is exactly why it is worth naming carefully rather than checking + * reachability: the next person to move a read downward gets no warning at all. */ + var gh = hash2(bay, storey, sd ^ 0x11); + var gPan = gh > 0.5 ? G_HASH : G_8; + var base = (168 + 62 * gh) * glow * flick; /* Rain across a lit panel: the water on the OUTSIDE of the paper, which is the detail that * puts the weather in front of the light instead of behind it. * @@ -634,14 +718,14 @@ if (wRain > 0.25 && lod === 2 && !CC.reducedMotion && hash2(Math.floor(u * 9), Math.floor(v * 5 - t * 0.7), sd ^ 0x4C7) < 0.06 * wRain) return fset(G_PIPE, P.stone, base * 0.68); - if (lod < 2) return fset(G_8, P.warm, base * 0.86); + if (lod < 2) return fset(gPan, P.warm, base * 0.86); if (fpu < 0.16 || fpv < 0.13) return fset(fpv < 0.13 ? G_DASH : G_PIPE, P.timber, base * 0.30); /* The lower quarter of a shopfront panel is the noren or the shutter board — solid, so the * light is cut off at knee height. It is what stops a lit frontage reading as a hole. */ if (storey === 0 && v < st.gnd * 0.34) return fset(G_EQ, P.timber, (24 + 60 * sun) * gr); - return fset(G_8, P.warm, base); + return fset(gPan, P.warm, base); } /* ---- and unlit, it is a LATTICE ------------------------------------------------------------ diff --git a/tools/canal-flicker.cjs b/tools/canal-flicker.cjs index 4ff7b2b..2aaaf8b 100644 --- a/tools/canal-flicker.cjs +++ b/tools/canal-flicker.cjs @@ -1,6 +1,6 @@ /* west-flicker's method, but with the camera PINNED ON THE CANAL — which is the one place the shipped gate can never look, because it pins at the map's start and the channel is 100+ m away. */ -const R='/Users/eden/Github/CyberCity/',fs=require('fs'); +const R=require('path').join(__dirname,'..')+'/',fs=require('fs'); global.CC=require(R+'src/core.js');global.window=undefined; ['world','proj','daylight','weather_state','city','surfaces','raycast','control'].forEach(m=>require(R+'src/'+m+'.js')); fs.readdirSync(R+'src').sort().forEach(p=>{if(/^surf_.*\.js$/.test(p))require(R+'src/'+p)}); @@ -49,9 +49,35 @@ function run(preset,seed,reduced,dOff){ for(const fq of PROBES){const a=goertzel(x,fq);if(a>band)band=a;}} return {water,worst:(100*worst/255).toFixed(1),big:big.toFixed(2),band:(100*band/255).toFixed(2)}; } +/* One sweep, collected as it prints. The verdict below reads THIS array — an earlier cut ran the + same eight configurations a second time to score them, which doubled a 13-second gate's runtime + for numbers it had already computed and left two config lists to keep in step. */ +const ROWS_ALL=[]; for(const [seed,dOff] of [[42,2],[42,8],[3,2],[3,8]]) for(const p of ['kiri','typhoon']) - { const r=run(p,seed,false,dOff); + { const r=run(p,seed,false,dOff); ROWS_ALL.push(r); console.log('seed',seed,'dist-to-channel',dOff+'m',p.padEnd(8),r?`waterCells ${String(r.water).padStart(4)} worstStep ${r.worst}% bigSteps ${r.big}/s 3-20Hz ${r.band}%`:'(never reached)'); } const rm=run('typhoon',42,true,2); console.log('reduced-motion @2m typhoon:', rm?`waterCells ${rm.water} worstStep ${rm.worst}% bigSteps ${rm.big}/s 3-20Hz ${rm.band}%`:'n/a'); + +/* THE VERDICT, which this file shipped without — CONTRACT.md names it the pattern to copy and a + probe with no PASS/FAIL is a print-out, not a gate. Four codes rather than two, following + tools/flicker-rate.cjs: 1 is a MEASURED violation, 3 is "the walk never reached the water", and + those are not the same answer. The 2% rule is the project's, and the big-step cap is the one + tools/west-flicker.cjs applies to a world that is not the default. */ +const measured = ROWS_ALL.filter(Boolean); +if (!measured.length || measured.every(r => r.water === 0)) { + console.log('RESULT: NOT_MEASURED — the walk never stood on the channel, or it rendered no water'); + process.exit(3); +} +const worstBand = Math.max(...measured.map(r => parseFloat(r.band))); +const worstBig = Math.max(...measured.map(r => parseFloat(r.big))); +const bad = (worstBand > 2.0 ? ` 3-20Hz ${worstBand}% over 2%` : '') + + (worstBig > 8.0 ? ` big steps ${worstBig}/s over 8/s` : '') + + /* The reduced-motion row was printed and not judged, which is half a gate: the flag's + rule is stricter than the live one — with it on, everything that modulates must be + frozen or slow enough that the band is empty. */ + (rm && (parseFloat(rm.big) > 0 || parseFloat(rm.band) > 0.5) + ? ` reduced motion is not still (${rm.big}/s, ${rm.band}%)` : ''); +console.log(`RESULT: ${bad ? 'FAIL' + bad : 'PASS'} (worst 3-20Hz ${worstBand}%, worst big steps ${worstBig}/s)`); +process.exit(bad ? 1 : 0); diff --git a/tools/metrics.py b/tools/metrics.py index f40cbf9..277d8ec 100644 --- a/tools/metrics.py +++ b/tools/metrics.py @@ -21,7 +21,7 @@ import sys, json # Eight swatches were appended to the palette (12..19) and this line is the whole of what that # cost the census. NAMES = ['amber','azure','ember','spring','violet','white','red','slate','warm','ice','pure','shadow', - 'stone','timber','sand','jade','rose','gold','moss','indigo'] + 'stone','timber','sand','jade','rose','gold','moss','indigo','blossom'] KINDS = ['sky', 'facade', 'floor', 'element'] def load(src): diff --git a/tools/sakura-flicker.cjs b/tools/sakura-flicker.cjs new file mode 100644 index 0000000..05d52ed --- /dev/null +++ b/tools/sakura-flicker.cjs @@ -0,0 +1,348 @@ +/* THE SAKURA RATE PROBE — tools/canal-flicker.cjs's method, aimed at the cherry. + * + * WHY THIS FILE EXISTS. CONTRACT.md's newest rule is that A GATE THAT CANNOT SEE THE FEATURE IS NOT + * A GATE, and the sakura is the second feature in this world to fall through that hole. Measured on + * the tree this file was written against: `node tools/west-flicker.cjs 4` pins the camera at + * city.startX/startZ and rendered 20 sakura cells of 4,800 at seed 3 and 15 at seed 42, none of + * which printed above the black line — its japan rows came back BYTE-IDENTICAL whether the crown + * was drawing 0 visible cells a frame or 81. Quoting that PASS for a change to the tree is exactly + * the failure the contract forbids, so this probe walks the autopilot until the element's own cells + * are actually IN the frame, pins there, and scores only the cells that element owns. + * + * THOSE NUMBERS ARE NOT CONSTANTS, and this file learned it the embarrassing way. The very pass + * that added this probe raised the cherry's accept rate, which put a crown at the map's start pose + * and took west-flicker's blind spot from 15 cells to 80, 45 of them printing. Because the search + * below stopped as soon as the target owned `--cells`, the threshold was met at frame 0 and this + * tool silently became a second copy of the gate it exists to complement, on six of nine rows, + * while its own header claimed otherwise. Hence two rules now enforced in the code: the pin + * threshold counts cells that PRINT, never cells merely owned (proj.js emits fogged-to-zero cells + * as real occluding mass, and about half a crown is those), and every row REPORTS ITS PIN FRAME so + * a reader can see whether the walk walked. A gate's blindness is a property of the content as much + * as of the camera; it has to be re-measured, not quoted. + * + * ATTRIBUTION IS BY WRAPPING CC.put BEFORE src/proj.js IS REQUIRED, and the order is load-bearing: + * proj.js caches `var put = CC.put` at module scope, so a wrapper installed after that require is + * never called by any world-space element and this probe would measure an empty set while printing + * a confident PASS. The wrapper records which cells the named element wrote; every other element in + * the world still draws, because a petal is only a hazard against what is behind it. + * + * THE MEASURED SET IS THE TREE'S OWN CELLS, not the frame. A crown is 1-3% of a frame and a whole- + * frame worst-cell figure is dominated by the street behind it — which west-flicker already gates. + * + * EXIT CODES, four rather than two, following tools/flicker-rate.cjs rather than west-flicker: + * 0 PASS 1 a MEASURED violation 2 usage 3 NOTHING WAS JUDGED. + * 3 has TWO causes and both are "this run reached no verdict", which is why they share a code: + * the walk never found the element, OR the window is not REF_WINDOW so the figures were printed + * without being judged. Neither is a pass and neither is a failure of the tree; a silent 0 on an + * unjudged run is the defect this scheme exists to prevent. The RESULT line always says which. + * + * usage: node tools/sakura-flicker.cjs [seconds] [element] [--time=] [--cells=] + * --cells is how many cells of the target must PRINT (v >= 9) before the walk pins. It counts + * what prints and NOT what the element owns — see the note above the search loop — and it is a + * REQUIRED knob rather than a constant because the two things this probe is aimed at differ by + * two orders of magnitude: a crown prints 60-140 cells and a thirty-petal drift single figures. + * A threshold + * tuned for the crown reports NOT_MEASURED on the drift, which is the correct answer for that + * threshold and a useless one for the question. + * The window is an ARGUMENT because the rate figure is quantised by it: at 4 s a rate is a multiple + * of 0.25/s, which is too coarse to ship a judgement on when the limit is 1.00/s. It is printed in + * the RESULT line so a quoted number always carries the window it was measured over. + */ +'use strict'; +const fs = require('fs'), path = require('path'); +const R = path.join(__dirname, '..') + '/'; + +const argv = process.argv.slice(2); +const flags = argv.filter(a => a.slice(0, 2) === '--'); +const pos = argv.filter(a => a.slice(0, 2) !== '--'); +const SECONDS = parseFloat(pos[0] || '10'); +const TARGET = pos[1] || 'jp-sakura'; +const HOUR_RAW = (flags.find(f => f.startsWith('--time=')) || '').slice(7); +/* COERCED, because Daylight.set branches on `typeof === 'number'` and matches STOPS by name + otherwise: a raw '0.25' matches no stop, returns false, and the clock free-runs while the + header still prints the hour that was asked for. tools/headless.cjs normalises on its own + line 155 for the same reason. Guards below test `!== ''` and not truthiness, so --time=0 + survives the coercion. */ +const HOUR = HOUR_RAW !== '' && /^[0-9]*\.?[0-9]+$/.test(HOUR_RAW) ? parseFloat(HOUR_RAW) : HOUR_RAW; +const NEED = parseInt((flags.find(f => f.startsWith('--cells=')) || '--cells=60').slice(8), 10); +if (!(SECONDS > 0)) { + console.error('usage: node tools/sakura-flicker.cjs [seconds] [element] [--time=hour]'); + process.exit(2); +} +if (SECONDS < 4) console.error('sakura-flicker: WARNING — under 4 s the 3-20 Hz figure is noise.'); + +global.CC = require(R + 'src/core.js'); +global.window = undefined; + +/* ---- the wrapper, installed before ANY consumer caches it ---------------------------------- */ +let TAG = null, OWNED = null, COLS = 120, ROWS = 40; +const rawPut = CC.put; +/* ATTRIBUTION IS CC.put's OWN RETURN VALUE and nothing else. put depth-tests, and it already tells + * the caller whether the write landed, so "did this element end up owning this cell" is answered + * exactly rather than inferred. + * + * THE FIRST CUT INFERRED IT, and it is written down because the numbers looked entirely plausible. + * It tested `f.dist[i] === d || (before && f.lum[i] === l)` where `before` was `f.lum` — an ALIAS of + * the live array, not a copy, so the second clause read the state AFTER the write and the first + * compared a double against a Float32Array slot that holds Math.fround of it. Measured on the runs + * this tool was shipping: the dist clause was true 0 times in 497,490 emits, and of the 197,312 + * emits the heuristic did accept, 93,545 had LOST the depth test. Cell counts came out 92 where the + * tree owned 13 (seed 3), 394 where it owned 103 (seed 404); for the petal drift it ran the other + * way too, dropping 61 of 129 real cells because put stores `lum | 0` and a fractional l never + * matched. The verdicts happened not to change, which is the whole hazard: a photosensitivity mask + * that silently drops half an element's cells can drop the hot one and still print PASS. + * + * The kind argument is forwarded. Nothing this tool draws passes one today, but every put in + * src/optics.js, moon_ground.js, moon_craft.js, structure.js and market.js does, and defaulting it + * to 3 in a file the contract names as a pattern to copy is a trap for whoever copies it. */ +CC.put = function (f, x, y, g, c, l, d, k) { + const ix = x | 0, iy = y | 0; + const ok = rawPut(f, x, y, g, c, l, d, k); + if (ok && TAG && ix >= 0 && iy >= 0 && ix < COLS && iy < ROWS) OWNED[iy * COLS + ix] = 1; + return ok; +}; + +['world', 'proj', 'daylight', 'weather_state', 'city', 'surfaces', 'raycast', 'control'] + .forEach(m => require(R + 'src/' + m + '.js')); +fs.readdirSync(R + 'src').sort().forEach(p => { if (/^surf_.*\.js$/.test(p)) require(R + 'src/' + p); }); +fs.readdirSync(R + 'src/elements').sort().forEach(p => require(R + 'src/elements/' + p)); + +/* An unknown stop is a USAGE error, not a NOT_MEASURED: the run would silently free-run its + clock and report an hour it never held. Checked against STOPS rather than by calling + Daylight.set once, because set() moves a module-level offset that deliberately survives + Daylight.init (src/daylight.js:263-272) and a validation call would leave residue on every + row that follows. */ +if (typeof HOUR === 'string' && HOUR !== '' && + !CC.Daylight.STOPS.some(st => st.name === HOUR)) { + console.error(`sakura-flicker: unknown --time=${HOUR_RAW} — expected a phase 0..1 or one of ` + + CC.Daylight.STOPS.map(st => st.name).join(', ')); + process.exit(2); +} + +const WARM = 360, NF = WARM + Math.round(SECONDS * 60), PROBES = [3.5, 5, 7, 9, 12, 15, 19]; +const BIG = 255 / 3; // west-flicker's own definition of a big step +/* BAND_CAP IS THE PROJECT'S RULE — nothing above 2% of full scale between 3 and 20 Hz. RATE_CAP IS + NOT: it is a house limit chosen for this probe, and it is an eighth of the 8.0/s absolute backstop + tools/west-flicker.cjs applies. It is set here because a rate is the half of this measurement a + still frame and a census both miss, and because the drift under test has tripped the band rule + before by moving faster rather than by getting brighter. Anything failing on RATE_CAP alone is + inside the project's stated rule and over this file's stricter one; say which when quoting it. + + NOTHING IS JUDGED EXCEPT AT ONE WINDOW, which is the rule tools/flicker-rate.cjs already states + and this file twice failed to apply. A Goertzel amplitude on a broadband signal falls as one over + the square root of the window, so the same unchanged tree measured 2.62% in band at 4 s, 1.82% at + 6 s, 0.97% at 10 s and 0.85% at 20 s — a verdict that flips with an argument is not a verdict. + That much was fixed first, and the RATE was then exempted on the argument that it "has no bin + width in it and is honest at any window". It is not. `big` is a MAXIMUM over cells of a big-step + COUNT divided by the window, and the maximum of a small bursty count is biased upward as the + window shrinks: the same six events on the same tree read 1.50/s at 4 s and 0.60/s at 10 s, and + the 4 s run exits 1 — which this file's own table defines as a MEASURED VIOLATION, an accusation + against the tree — for a difference that is entirely the divisor. So REF_WINDOW governs both, and + at any other window both figures are PRINTED WITHOUT BEING JUDGED. */ +const RATE_CAP = 1.00, BAND_CAP = 2.00, REF_WINDOW = 10; + +function goertzel(x, f) { + const n = x.length, w = 2 * Math.PI * f / 60, c = 2 * Math.cos(w); + let s1 = 0, s2 = 0, m = 0; + for (let i = 0; i < n; i++) m += x[i]; + m /= n; + for (let i = 0; i < n; i++) { + const v = (x[i] - m) * (0.5 - 0.5 * Math.cos(2 * Math.PI * i / (n - 1))); + const s0 = v + c * s1 - s2; s2 = s1; s1 = s0; + } + return 2 * Math.sqrt(s1 * s1 + s2 * s2 - c * s1 * s2) / n; +} + +function run(preset, seed, reduced, pinned) { + CC.World.force('japan'); + CC.reducedMotion = !!reduced; + const city = CC.City.make(seed); + CC.Daylight.init(city); + /* --time IS RE-PINNED EVERY TICK, not stamped once. Daylight.set moves an OFFSET against a t it + defaults to 0, so a single call at init holds the requested stop only until the first + Daylight.update — after which the clock runs on its 420 s cycle straight through a search that + may last 40,000 frames (eleven minutes of clock, 1.6 full days) and out the far side into the + measured window, while the header still prints the hour that was asked for. tools/headless.cjs + re-pins inside its own loop for exactly this reason. Both loops below do the same. */ + if (HOUR !== '' && CC.Daylight.set) CC.Daylight.set(HOUR, 0); + CC.Weather.init(city); CC.Control.reset(); + const live = CC.ELEMENTS.filter(e => CC.inWorld(e, 'japan')).sort((a, b) => (a.layer | 0) - (b.layer | 0)); + const rng = CC.mulberry(seed ^ 0x9e3779b9); + for (const el of live) if (el.init) el.init(city, rng, { cols: COLS, rows: ROWS }); + /* Scoped as west-flicker and canal-flicker scope it: only elements EXCLUSIVE to this world. */ + const drawn = live.filter(e => e.world && CC.inWorld(e, 'japan') && !CC.inWorld(e, 'cyber')); + const tgt = drawn.filter(e => e.name === TARGET); + const rest = drawn.filter(e => e.name !== TARGET); + + const N = COLS * ROWS; + const f = CC.makeFrame(COLS, ROWS); + OWNED = new Uint8Array(N); + const cam = { x: city.startX, z: city.startZ, yaw: 0, eyeY: 1.7, fov: 1.25, + horizon: ROWS * 0.56, cellAspect: 0.5625, rows: ROWS, t: 0 }; + + /* ---- WALK UNTIL THE TREE IS ACTUALLY IN SHOT, then pin. This is the whole point of the file. + THE PIN FRAME IS REPORTED, because a walk that pins at frame 0 has not walked and is measuring + the same pose the shipped pinned gates already measure. That is not hypothetical: with the + over-counting attribution this file first shipped, every crown row met its threshold at k = 0 + and the tool was quietly a second copy of west-flicker while claiming to be its complement. */ + let best = 0, pinFrame = 0; + if (!pinned) { + let found = false; + /* EVERY ELEMENT IS UPDATED ON EVERY FRAME OF THE SEARCH, not only on the frames that are + sampled. A draw-only element like the crown does not notice; a SIMULATED one does, and this + is where the first cut of this probe was wrong: with update() left out of the search loop, + jp-blossom's pool never integrated, so the walk reported "no crown reached — best 0 cells" + for a drift that the pinned run in the same process measured at 41 cells. An element that + moves cannot be found by a search that does not let it move. */ + for (let k = 0; k < 40000 && !found; k++) { + const t = k / 60; + if (HOUR !== '' && CC.Daylight.set) CC.Daylight.set(HOUR, t); + /* THE SEARCH WALKS IN THE WEATHER THE ROW IS ABOUT TO BE SCORED IN. Without this the + search ran on the free-running schedule, so all three presets of a seed walked a + byte-identical search and pinned at the same frame — and Surf.fog is exactly what + decides whether a crown cell prints, so the '>=NEED cells print here' guarantee was + being asserted in weather that was not the weather under test. tsuyu was the row that + showed it: the same pose, a quarter of the lit cells of clear. */ + if (!CC.Weather.P.forced) CC.Weather.set(preset, t); + CC.Daylight.update(1 / 60, t); CC.Weather.update(1 / 60, t); + CC.Control.update(1 / 60, t, cam, city); + for (const el of live) if (el.update) el.update(1 / 60, t, cam); + if (k % 10) continue; + cam.t = t; CC.clearFrame(f); CC.Cast.render(f, cam, city); + for (const el of rest) if (el.draw) el.draw(f, cam, t); + OWNED.fill(0); TAG = TARGET; + for (const el of tgt) if (el.draw) el.draw(f, cam, t); + TAG = null; + /* THE THRESHOLD COUNTS CELLS THAT PRINT, not cells that are owned, and the print is what + Compose.post decides — so it is run here exactly as it is in the measured loop. Counting + owned cells let the search stop on invisible mass: at seed 3 the crown reached 64 owned + cells of which ZERO printed above the v = 9 black line, and the probe pinned there and + called it a measurement. A gate that pins on something the viewer cannot see is the same + defect as a gate that never reaches the feature at all. */ + if (CC.Compose && CC.Compose.post) CC.Compose.post(f, cam, t); + let n = 0; for (let i = 0; i < N; i++) if (OWNED[i] && f.lum[i] >= 9) n++; + if (n > best) best = n; + if (n >= NEED) found = true; + if (found) pinFrame = k; + } + if (!found) return { cells: best, notFound: true }; + } + + /* THE MEASURED WINDOW CONTINUES THE SEARCH'S CLOCK, IT DOES NOT REWIND IT, and this is the + defect that made the walk decorative. The search stops at the first frame where >=NEED of + the element's cells PRINT, which is a statement about one instant of a 420 s daylight + cycle; restarting t at 0 for the measured window then scored a different hour entirely. + Measured on the tree this landed against: seed 3 pinned at f8000 (t = 133 s) with 63 + printing cells and was then scored at t = 0-10 s, where the same crown printed 9 cells on + kiri and 2 on tsuyu — a black crown, contributing 0.00/s and 0.00% to a PASS. Carrying the + clock over takes those rows to 68 and 64 lit and surfaces real signal that was invisible + before (seed 3 clear reads 0.20/s and 0.56% in band where it read 0.00). + The file already knew this failure mode — the --time note above re-pins the hour every tick + for exactly this reason — but that guard only fires when an hour was ASKED for, and the two + invocations CONTRACT.md gates on pass no --time at all. + Nothing else moves: Control.update is not called in this loop, so the camera stays pinned; + `keep`, `WARM` and the sampling index are untouched; and the pinned baseline run has + pinFrame = 0, so its numbers are byte-identical to before. */ + const keep = NF - WARM, s = new Uint8Array(N * keep), mask = new Uint8Array(N); + for (let k = 0; k < NF; k++) { + const t = (pinFrame + k) / 60; + if (!CC.Weather.P.forced) CC.Weather.set(preset, t); + if (HOUR !== '' && CC.Daylight.set) CC.Daylight.set(HOUR, t); + CC.Daylight.update(1 / 60, t); CC.Weather.update(1 / 60, t); + for (const el of live) if (el.update) el.update(1 / 60, t, cam); + cam.t = t; CC.clearFrame(f); CC.Cast.render(f, cam, city); + for (const el of rest) if (el.draw) el.draw(f, cam, t); + OWNED.fill(0); TAG = TARGET; + for (const el of tgt) if (el.draw) el.draw(f, cam, t); + TAG = null; + /* A cell counts if the tree owned it at ANY point in the window: a petal that arrives and + leaves is precisely the transient this gate is for, and a per-frame mask would drop it. */ + for (let i = 0; i < N; i++) if (OWNED[i]) mask[i] = 1; + if (CC.Compose && CC.Compose.post) CC.Compose.post(f, cam, t); + if (k >= WARM) { const b = (k - WARM) * N; for (let i = 0; i < N; i++) s[b + i] = f.lum[i]; } + } + + let cells = 0, lit = 0, big = 0, band = 0, worst = 0; + const x = new Float64Array(keep); + for (let i = 0; i < N; i++) { + if (!mask[i]) continue; + cells++; + /* OWNED IS NOT THE SAME AS SEEN, WHICH IS WHY THE PIN THRESHOLD COUNTS PRINTING CELLS AND + NOT OWNED ONES (see the search loop). proj.js's + emit() calls put for a cell fogged to lum 0 — real occluding mass that the element does own — + so about half a crown's owned cells print nothing, and a threshold met on those is met on + something invisible. Both counts are printed so the row cannot overstate what is on screen. */ + for (let k = 0; k < keep; k++) if (s[k * N + i] >= 9) { lit++; break; } + let b = 0, mx = 0, prev = s[i]; + for (let k = 1; k < keep; k++) { + const v = s[k * N + i], d = Math.abs(v - prev); + if (d > mx) mx = d; + if (d > BIG) b++; + prev = v; x[k] = v; + } + x[0] = s[i]; + const rate = b / (keep / 60); + if (rate > big) big = rate; + if (mx > worst) worst = mx; + for (const fq of PROBES) { const a = goertzel(x, fq); if (a > band) band = a; } + } + return { cells, lit, worst: 100 * worst / 255, big, band: 100 * band / 255, pinFrame }; +} + +console.log(`sakura rate gate — ${TARGET}, ${COLS}x${ROWS}, ${SECONDS}s measured of ${NF} frames, ` + + `${WARM} discarded, pin at >=${NEED} PRINTING cells (v>=9)` + + `${HOUR !== '' ? ', hour ' + HOUR : ''}\n`); +const rows = []; +for (const seed of [42, 3, 404]) + for (const p of ['kiri', 'clear', 'tsuyu']) { + const r = run(p, seed, false, false); + rows.push(r); + console.log(` seed ${String(seed).padStart(4)} ${p.padEnd(7)}` + + (r.notFound + ? `(no crown reached — best ${r.cells} cells)` + : `cells ${String(r.cells).padStart(4)}(${String(r.lit).padStart(3)} lit) worst step ${r.worst.toFixed(1).padStart(5)}% ` + + `big steps ${r.big.toFixed(2).padStart(5)}/s 3-20Hz ${r.band.toFixed(2).padStart(5)}% ` + + `pinned f${String(r.pinFrame).padStart(5)}${r.pinFrame === 0 ? ' (DID NOT WALK)' : ''}`)); + } +const pin = run('kiri', 42, false, true); +console.log(`\n pinned at start (what west-flicker sees): cells ${pin.cells}`); +const rm = run('tsuyu', 42, true, false); +console.log(` reduced motion: ` + (rm.notFound ? '(no crown)' : + `cells ${rm.cells} big steps ${rm.big.toFixed(2)}/s 3-20Hz ${rm.band.toFixed(2)}%`)); + +/* A ROW IS A MEASUREMENT ONLY IF SOMETHING PRINTED IN IT. `cells` is the sticky OWNED mask and + owned includes cells proj.js fogged to lum 0, so gating on it let a row that printed nothing + at all across the whole window contribute 0.00/s and 0.00% to the maxima and carry the run to + PASS — this tool's own defect, one level below the one it was written to close. THIN is the + same argument short of zero: a handful of lit cells cannot clear or fail a rate gate, and a + verdict taken on them is a verdict taken on nothing. Both are NOT_MEASURED and exit 3, which + the header defines as 'this run reached no verdict' — not as a failure of the tree. */ +const THIN = Math.max(4, NEED >> 2); +const seen = rows.filter(r => !r.notFound && r.lit > 0); +const thin = seen.filter(r => r.lit < THIN); +if (!seen.length) { + console.log('\nRESULT: NOT_MEASURED — no walk reached a crown that PRINTS; this is the probe failing, not a PASS'); + process.exit(3); +} +if (thin.length) { + console.log(`\nRESULT: NOT_MEASURED — ${thin.length} row(s) pinned on a crown printing under ` + + `${THIN} cells (worst ${Math.min(...thin.map(r => r.lit))}); this is the probe failing, not a PASS`); + process.exit(3); +} +const wBig = Math.max(...seen.map(r => r.big)), wBand = Math.max(...seen.map(r => r.band)); +const rmBad = !rm.notFound && (rm.big > 0 || rm.band > 0.5); +const judging = SECONDS === REF_WINDOW; +const bad = judging + ? ((wBig > RATE_CAP ? ` big steps ${wBig.toFixed(2)}/s over ${RATE_CAP.toFixed(2)}/s` : '') + + (wBand > BAND_CAP ? ` 3-20Hz ${wBand.toFixed(2)}% over ${BAND_CAP.toFixed(2)}%` : '') + + (rmBad ? ' reduced motion is not still' : '')) + : ''; +const walked = seen.filter(r => r.pinFrame > 0).length; +const wLit = Math.min(...seen.map(r => r.lit)); // the thinnest row a verdict was taken on +console.log(`\nRESULT: ${!judging ? 'NOT_JUDGED' : bad ? 'FAIL' + bad : 'PASS'} ` + + `(worst big steps ${wBig.toFixed(2)}/s, worst 3-20Hz ${wBand.toFixed(2)}%` + + `${judging ? '' : `; both PRINTED NOT JUDGED — a verdict is only taken at the ${REF_WINDOW}s reference window`}` + + `, over a ${SECONDS}s window; thinnest row ${wLit} lit cells; ${walked}/${seen.length} rows walked off the start pose` + + `${rm.notFound ? '; reduced-motion row found nothing — frozen by design, NOT a measured pass' : ''})`); +if (!judging) process.exit(3); +process.exit(bad ? 1 : 0);