A fourth world lit from inside the street, and a canal to cross on the way
Edo, on key 4: a castle town in the rain, the first world lit from within rather than from a long way off. Paper lanterns under the eaves and oil lamps behind the shopfronts invert the lighting model — bright at the bottom of a wall, black at the top — and under an overcast deck the picture is carried by lines (ridge tile, drip edge, mid-rail, gutter, the batter of a castle wall) rather than by tone. The canal is a painted plane, not carved geometry: a negative height renders byte-identically to zero, so the water sits on the y=0 floor pass with a 0.45 m stone coping beside it — an occlusion budget rather than a wall, since a real 1.2 m embankment would hide the water and the far bank behind its own kerb. The reflect pass gives back a quarter of the floor rows where a puddle gives back three cells. Same engine, same seed: #42 is the same corner of the same street lattice in all four. New: src/surf_japan.js and jp_{town,castle,banner,flora}.js; a canal-flicker harness in tools/. Readme carries the Edo brightness ladder and the two new plates.
This commit is contained in:
parent
91e13f5d8a
commit
56c1b629fc
23 changed files with 6788 additions and 139 deletions
74
CONTRACT.md
74
CONTRACT.md
|
|
@ -40,9 +40,10 @@ concatenates them in order and the headless harness `require`s them through a sh
|
|||
| `src/weather_state.js` | `CC.Weather` | the weather director and one preset table per world; `rel()` is the cross-world quantity |
|
||||
| `src/city.js` | `CC.City` | `make(seed)` → heightmap + per-cell district/style/sign metadata, for any world |
|
||||
| `src/raycast.js` | `CC.Cast` | `render(frame, cam, city)` — fills every cell: façades, floor, sky |
|
||||
| `src/surfaces.js` | `CC.Surf` | texture fns: `facade(u,v,cell,dist)`, `floorTex(wx,wz,dist)`, `sky(x,y,t)`; owns `configure`/`cfg`/`fog` for every world and delegates to the three painters |
|
||||
| `src/surfaces.js` | `CC.Surf` | texture fns: `facade(u,v,cell,dist)`, `floorTex(wx,wz,dist)`, `sky(x,y,t)`; owns `configure`/`cfg`/`fog` for every world and delegates to the other painters through `CC.SURFACES` |
|
||||
| `src/surf_west.js` | `CC.SurfWest` | the frontier's `facade` / `floorTex` / `sky`, same signatures |
|
||||
| `src/surf_moon.js` | `CC.SurfMoon` | Moonwalk's, likewise. Painters self-register into `CC.SURFACES[id]`; `build.js` globs `src/surf_*.js` |
|
||||
| `src/surf_japan.js` | `CC.SurfJapan` | EDO's. The only painter with TWO key lights — a sky dome scaled by how much cloud there is, and a lamp wash that is a function of height above the ground and nothing else |
|
||||
| `src/proj.js` | `CC.Proj` | the ONE copy of the element camera — `make()` hands each world-space element file its own basis and the four helpers closed over it |
|
||||
| `src/control.js` | `CC.Control` | the walk and the input devices; re-anchors to `city.js`'s route on a rebuild |
|
||||
| `src/elements/*.js` | pushes to `CC.ELEMENTS` | ambient systems, see below |
|
||||
|
|
@ -78,8 +79,9 @@ CC.ELEMENTS.push({
|
|||
name: 'rain',
|
||||
layer: 10, // lower draws first; elements draw after the world pass
|
||||
world: 'cyber', // OPTIONAL: an id, or an ARRAY of ids. Absent means EVERY world —
|
||||
// which is a materially different promise now there are three, and is
|
||||
// why the atmospheric elements had to be given ['cyber','west'].
|
||||
// which is a materially different promise now there are four, and is
|
||||
// why the atmospheric elements carry ['cyber','west','japan'] and the
|
||||
// Moon is left out of every one of them.
|
||||
init(city, rng) {}, // allocate persistent state
|
||||
update(dt, t, cam) {}, // advance simulation; no drawing
|
||||
draw(frame, cam, t) {}, // use CC.put(frame, x, y, glyph, colour, lum, dist) — it depth-tests for you
|
||||
|
|
@ -90,14 +92,31 @@ CC.ELEMENTS.push({
|
|||
|
||||
`CC.World` names the live world and calls back when it changes; `main.js` responds by tearing the
|
||||
map down and building a new one on the **same seed**. Everything downstream keeps its own data for
|
||||
every world next to the numbers it already has — `city.js` holds three district tables (nine
|
||||
quarters for the city, six for the frontier, eight for the Moon), `weather_state.js` three preset
|
||||
tables, `surfaces.js` delegates to three painters — rather than reading from one central theme
|
||||
object. The URL fragment is `#<seed>` for the default world and `#<world>/<seed>` otherwise.
|
||||
every world next to the numbers it already has — `city.js` holds four district tables (nine
|
||||
quarters for the city, six for the frontier, eight for the Moon, seven for EDO),
|
||||
`weather_state.js` four preset tables, `surfaces.js` delegates to four painters — rather than
|
||||
reading from one central theme object. The URL fragment is `#<seed>` for the default world and
|
||||
`#<world>/<seed>` otherwise.
|
||||
|
||||
WHAT A FOURTH WORLD COST, recorded because it is the measurement that says whether the three
|
||||
registries below were worth building: 33.2 KB of stripped bundle, against the frontier's 65 and the
|
||||
Moon's 55. Nothing in `raycast.js`, `main.js`, `control.js`, `render_canvas.js` or
|
||||
`tools/headless.cjs` was touched at all — a world is now a `world.js` row, a `city.js` theme and
|
||||
district table, a `weather_state.js` preset table, one self-registering painter, and element files
|
||||
that tag themselves. If adding one turns out to need an edit to any of those five files, that edit
|
||||
is the bug.
|
||||
|
||||
Rules for worlds:
|
||||
- An element that belongs to one world says so with `world:` on itself, as an id or an array of
|
||||
them. The test is `CC.inWorld(el, id)` and there is exactly ONE definition of it, in `world.js`,
|
||||
them. A shared element that has to behave differently per world does it through a **table keyed
|
||||
by world id**, never a boolean. `street.js` carried `PED_WEST = city.world === 'west'` doing two
|
||||
unrelated jobs — the frontier's costume weights and "this crowd is pre-electric" — and a fourth
|
||||
world needed the second and not the first. It is now two lookups, `PED_ARCH` and `PED_PRE_W`, and
|
||||
a world that is in neither gets the modern default rather than whatever the last `else` was.
|
||||
Whatever the gate does, the DRAW must still happen: every one of those branches takes its hash
|
||||
and throws the result away rather than skipping it, so one world's crowd is not a reshuffle of
|
||||
another's.
|
||||
- The test is `CC.inWorld(el, id)` and there is exactly ONE definition of it, in `world.js`,
|
||||
shared by `main.js`, `tools/headless.cjs` and the photosensitivity gates — because those three had
|
||||
three copies and an offline reference frame rendered from a different element set than the
|
||||
browser's is not a reference frame. `main.js` filters **before** the layer sort, because every
|
||||
|
|
@ -106,7 +125,9 @@ Rules for worlds:
|
|||
- A world is added by appending a row to `world.js`'s `LIST` (never prepending — `LIST[0]` is the
|
||||
URL default and every `#42` link ever shared addresses it), a theme block and district table in
|
||||
`city.js`'s `THEMES`, a painter file that self-registers, a weather table in `weather_state.js`,
|
||||
and element files tagged with its id. Nothing in the tree switches on a world id with a ternary
|
||||
and element files tagged with its id. That is the whole list; EDO was added without touching
|
||||
`raycast.js`, `main.js`, `control.js` or `tools/headless.cjs`, all four of which already read the
|
||||
registry rather than a set of literals. Nothing in the tree switches on a world id with a ternary
|
||||
any more; every one of those is a registry lookup with a documented fallback.
|
||||
- Nothing decides geometry by reading `CC.World` at draw time. The map resolved the world once,
|
||||
inside `make()`, and carries the answer on itself as `city.world`; between a keypress and the
|
||||
|
|
@ -160,8 +181,15 @@ Rules for elements:
|
|||
|
||||
## The build
|
||||
|
||||
`node build.js` must exit 0. It fails over **560 KB** and that line has been raised three times and
|
||||
`node build.js` must exit 0. It fails over **600 KB** and that line has been raised five times and
|
||||
held once; the essay in `build.js` is the record and it is addressed to whoever lands here next.
|
||||
**The next pass must split the payload.** Three passes running have now ended at this line with the
|
||||
same finding — the content is bigger than the headroom and every remaining cut is a rounding error
|
||||
against it. The last non-content cut in the tree (the duplicated `streetSpan` / `objVisible` /
|
||||
`corridor` bodies, measured at ~2,350 bytes and banked in `build.js`'s essay) is worth a tenth of a
|
||||
world.
|
||||
It also checks that every world's painter global is present, so a painter dropped into `src/` and
|
||||
never registered fails the build instead of rendering as the city.
|
||||
The order is: cut something that is not content, then cut content, then move the line, and write
|
||||
down which one you did. The whitespace has already been spent — `decomment()` halves leading
|
||||
indentation, worth 42,134 bytes of a measured 84,232 — so a future pass has one fewer option than
|
||||
|
|
@ -183,6 +211,32 @@ The gates, in the order they are worth running: `node build.js`, `node tools/dom
|
|||
the census, and a determinism check (the same seed, frame, world and hour rendered twice must be
|
||||
byte-identical).
|
||||
|
||||
A GATE THAT CANNOT SEE THE FEATURE IS NOT A GATE, and this is the newest hard-won rule here. Both
|
||||
photosensitivity tools PIN THE CAMERA at the map's start, so anything the walk only reaches later is
|
||||
invisible to them: EDO's canal is on a 160 m pitch, and `west-flicker.cjs` returned PASS having
|
||||
rendered ZERO canal cells on a surface that was in fact running at 3.61% against a 2% rule. When a
|
||||
feature lives somewhere the pinned camera never stands, measure it where it lives —
|
||||
`tools/canal-flicker.cjs` is that probe for the canal and is the pattern to copy. Quoting a PASS
|
||||
from a tool that rendered none of the thing under test is worse than not running it.
|
||||
|
||||
`west-flicker.cjs` is named after the frontier and is NOT scoped to it: it walks `CC.World.LIST`
|
||||
and gates every world that is not the default against the default's own elements, so a new world is
|
||||
covered the day its row lands. It is also the only gate that can see a whole class of defect that
|
||||
is invisible in a still and invisible in the census — a frame that is correct at every instant and
|
||||
wrong in its RATE. Adding EDO tripped it five times: an 11 Hz hash on a lit panel, a 26 Hz re-deal
|
||||
in the sky, a 4.5 Hz ripple offset, a 2.6 Hz gutter whose harmonics landed in band, and a drift of
|
||||
blossom whose petals cross a cell at about 5 Hz. Note that the last of those could not be fixed by
|
||||
dimming or by thinning the pool — both change the amplitude and the gate was measuring the rate;
|
||||
what fixed it was refusing to draw a petal inside 11 m.
|
||||
|
||||
THE OTHER STANDING CHECK, and it is not optional either: before anything ships, render the same
|
||||
fixtures in every world that was ALREADY there and byte-compare them against the tree you started
|
||||
from. Twenty-seven — three worlds x three hours x three seeds — is what the pass that added EDO
|
||||
ran, and all twenty-seven were byte-identical.
|
||||
A world addition touches shared files (element `world:` tags, a per-world table in a shared
|
||||
element) and every one of those is an opportunity to move a frame in a world nobody was looking
|
||||
at.
|
||||
|
||||
A note on window lengths, because two of those tools take one and they do not mean the same thing
|
||||
by it. `west-flicker.cjs` measures per-cell frame steps and rates, which have no bin width in them
|
||||
and are honest at four seconds. `flicker-rate.cjs`'s 3-20 Hz rule is a periodogram peak, which for
|
||||
|
|
|
|||
161
README.md
161
README.md
|
|
@ -1,32 +1,60 @@
|
|||
# CyberCity
|
||||
|
||||
Three walkable worlds drawn entirely in text characters, in one self-contained HTML file, with the
|
||||
Four walkable worlds drawn entirely in text characters, in one self-contained HTML file, with the
|
||||
sun going round.
|
||||
|
||||
No build step to run it, no dependencies, no network requests. Open `index.html` and you are
|
||||
standing on a street in the rain. Press **2** and you are on a dirt road on the frontier; press
|
||||
**3** and you are on the Moon.
|
||||
**3** and you are on the Moon; press **4** and you are in a castle town on a wet evening.
|
||||
|
||||
**[cybercity.carino.systems](https://cybercity.carino.systems)**
|
||||
|
||||

|
||||
|
||||
## Three worlds
|
||||
## Four worlds
|
||||
|
||||
| key | world | |
|
||||
|---|---|---|
|
||||
| `1` | **CyberCity** | a rain-lit city — neon, aerial traffic, police, market stalls |
|
||||
| `2` | **Frontier** | an 1880s timber town — veranda posts, painted boards, telegraph, horses, open desert |
|
||||
| `3` | **Moonwalk** | an Apollo-era lunar surface — regolith, craters, a black sky with Earth in it |
|
||||
| `4` | **Edo** | a castle town in the rain — paper screens, lanterns, tiled eaves, a canal, bridges, sakura |
|
||||
|
||||
They are the same engine and the same seed. `#42` is a place in all three, so pressing 1, 2 and 3
|
||||
They are the same engine and the same seed. `#42` is a place in all four, so pressing 1, 2, 3 and 4
|
||||
in turn shows you the same corner of the same street lattice with a different century — or a
|
||||
different world — built on it. That is the point of having three.
|
||||
different world — built on it. That is the point of having four.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
The fourth one is the odd one out and deliberately so. The first three are all lit from a long way
|
||||
off — by a sodium grid, by one low sun, by another one with no air in front of it — and **Edo** is
|
||||
lit from inside the street: a paper lantern hung under the eave at 2.1 m and an oil lamp behind
|
||||
every shopfront. That inverts the whole model. Sun and sky light the top of a wall and leave the
|
||||
ground dark; lanterns do the opposite, so a machi street after dark is bright at the bottom and
|
||||
black at the top, and which of the two lighting models the frame is under is what the clock
|
||||
decides. It is also the only world *built around* an overcast sky rather than merely having one as
|
||||
a weather state — under a deck there is no shadow to speak of and the two sides of a street are
|
||||
within a stop of each other, so what carries the picture is not tone but
|
||||
**lines**: the ridge tile, the drip edge under it, the mid-rail, the gutter, the batter of a castle
|
||||
wall. A cell of that world is a line or it is nearly nothing.
|
||||
|
||||

|
||||
|
||||
It also has a **canal** in it — 9.2 m of water on a 160 m pitch, so the walk meets one about every
|
||||
hundred seconds and crosses it on an arched taiko-bashi. Nothing is carved to make it: in this
|
||||
engine a negative height renders byte-identically to zero (the march is `if (h <= 0) continue` and
|
||||
the floor is painted by inverse projection against the y=0 plane, which never consults the
|
||||
heightmap), so the water is a *painted plane* with a 0.45 m stone coping beside it. That coping
|
||||
height is an occlusion budget rather than a wall: a parapet of height h at distance W hides all
|
||||
ground out to `W*eyeY/(eyeY-h)`, so the 1.2 m a real embankment has would hide the entire canal and
|
||||
the far bank behind its own kerb. At 0.45 m it costs three metres of water and the eye supplies the
|
||||
drop. What sells it is the reflect pass — a puddle gives back three cells, a canal gives back a
|
||||
quarter of the floor rows.
|
||||
|
||||
## The day
|
||||
|
||||
Every world runs a day/night cycle. Seven minutes is a full day; the sun climbs to 54 degrees and
|
||||
|
|
@ -66,8 +94,10 @@ and it moves the other way. Both, measured at 200x60 on frame 300 at two seeds,
|
|||
| **frontier** seed 7 | 26.5 / 0.24 | 38.7 / 1.03 | 40.9 / 7.16 |
|
||||
| **Moonwalk** seed 42 | 5.5 / 1.64 | 6.6 / 2.27 | 5.0 / 2.85 |
|
||||
| **Moonwalk** seed 7 | 11.8 / 1.27 | 7.2 / 3.88 | 6.2 / 3.60 |
|
||||
| **Edo** seed 42 | 38.6 / 0.38 | 46.8 / 2.58 | 51.9 / 0.71 |
|
||||
| **Edo** seed 7 | 30.8 / 0.03 | 37.3 / 2.08 | 37.6 / 0.07 |
|
||||
|
||||
Three things in that table are worth saying out loud rather than leaving for someone to notice.
|
||||
Four things in that table are worth saying out loud rather than leaving for someone to notice.
|
||||
|
||||
The Moon holds the night target at every hour of its day and at both seeds, 5.0% to 11.8% against
|
||||
a limit of 30, because it has no air — which is the whole argument for it being the third world.
|
||||
|
|
@ -78,10 +108,22 @@ under a sky that is a third of the frame and never goes to zero. The number move
|
|||
two seeds, which is the honest size of the seed effect out there — seed 7 draws more open range and
|
||||
open range is black.
|
||||
|
||||
Twilight in the two atmospheric worlds is the flattest hour of the three — the city's hot tail is
|
||||
0.41% at dusk against 7.27% at night — and that is not a bug to be tuned out either: it is the hour
|
||||
when the neon and the sky are the same brightness, which is exactly what makes it look like
|
||||
twilight.
|
||||
Twilight in the two older atmospheric worlds is the flattest hour of the three — the city's hot
|
||||
tail is 0.41% at dusk against 7.27% at night — and that is not a bug to be tuned out either: it is
|
||||
the hour when the neon and the sky are the same brightness, which is exactly what makes it look
|
||||
like twilight.
|
||||
|
||||
Edo is the only world whose hot tail goes the *other* way — a few hundredths of a per cent at
|
||||
night against two and a half at dusk — and it is the ladder rather than the picture. After dark the print's hot line is v 170 and the only
|
||||
swatches in the palette that reach it are `amber` (179), `azure` (219), `red` (206), `ice` (174)
|
||||
and `pure` (234) — a sodium lamp, a screen, a signal, a rain highlight and a specular. A paper
|
||||
lantern is materially `warm`, which tops out at 167: three points under the line at any luminance
|
||||
whatsoever, so a town lit entirely by lanterns censuses at nothing however many of them are in
|
||||
frame. That is not a fault to tune out by repainting the lantern in a swatch that lies about what
|
||||
it is. Two cells' worth of `pure` are spent where they are physically right — the blown-out core of
|
||||
a near lantern and the glint off the water in the gutter — and the rest of the world is honestly a
|
||||
dark wet street with warm holes in it. By dusk the ladder has crossed onto the day curve, where
|
||||
`warm` reaches 187 and `white` 209, and the same frame scores 2.58%.
|
||||
|
||||

|
||||
|
||||
|
|
@ -92,8 +134,8 @@ and `.` in twenty colours.
|
|||
## The palette, and why it is twenty and not twelve
|
||||
|
||||
It was twelve: two pillars — sodium amber and screen azure — and ten narrow things around them.
|
||||
Twelve is enough for a wet neon street at night and it is not enough for three worlds with a sun
|
||||
over them, and the failure was specific rather than general. There was no neutral grey at all
|
||||
Twelve is enough for a wet neon street at night and it is not enough for the daylight worlds, and
|
||||
the failure was specific rather than general. There was no neutral grey at all
|
||||
(slate is deliberately blue and says so in its own comment), no brown, no green that is not an
|
||||
accent, and nothing warm-metal. Everything that was none of those collapsed onto amber.
|
||||
|
||||
|
|
@ -116,6 +158,12 @@ walked violet off magenta years ago. At 0.20 the knee crushes every rose cell un
|
|||
black, so rose can only exist where something wrote it near full scale — which makes "signage
|
||||
only, never a field" arithmetic instead of a note in a comment.
|
||||
|
||||
Twenty turned out to be enough for a fourth world: **Edo adds no swatch at all.** Weathered cedar
|
||||
is `timber` in shade and `sand` in light, lime plaster is `white`, clay tile and a castle wall are
|
||||
`stone`, the dye on every piece of cloth in the place is `indigo`, and the lamp behind the paper is
|
||||
`warm`. That is the extension doing exactly what it was added for, and it is worth recording as
|
||||
evidence that the palette is now the right size rather than merely a bigger one.
|
||||
|
||||
## What is in it
|
||||
|
||||
It walks itself. Leave it alone and it strolls the city forever, turning corners, passing under
|
||||
|
|
@ -294,7 +342,7 @@ It plays itself, so all of this is optional.
|
|||
| `Tab` | take the controls / give them back |
|
||||
| `Esc` | give them back |
|
||||
| `P` | photo mode — freezes the world, you can still look and move |
|
||||
| `1` `2` `3` | world: CyberCity, Frontier, Moonwalk (gamepad: `Y` / triangle cycles) |
|
||||
| `1` `2` `3` `4` | world: CyberCity, Frontier, Moonwalk, Edo (gamepad: `Y` / triangle cycles) |
|
||||
| `T` | step the time of day (`Shift`+`T` steps back) |
|
||||
| `Y` | stop / restart the automatic day cycle |
|
||||
| `Shift`+`1`–`6` | weather |
|
||||
|
|
@ -304,24 +352,30 @@ It plays itself, so all of this is optional.
|
|||
| `H` | show the controls |
|
||||
|
||||
The weather presets are `clear, drizzle, rain, downpour, mist, storm` in the city,
|
||||
`blazing, breeze, dust, squall, overcast, thunder` on the frontier, and on the Moon exactly one,
|
||||
`vacuum`, with every parameter at zero — which is not a placeholder but the honest answer, and it
|
||||
is what makes the whole weather machinery collapse to nothing there without a single special case. They moved onto `Shift` when
|
||||
`blazing, breeze, dust, squall, overcast, thunder` on the frontier, `clear, haze, tsuyu, shower,
|
||||
typhoon, kiri` in Edo, and on the Moon exactly one, `vacuum`, with every parameter at zero — which
|
||||
is not a placeholder but the honest answer, and it is what makes the whole weather machinery
|
||||
collapse to nothing there without a single special case. Edo's table is very nearly the frontier's
|
||||
inverted: out there it is dry for weeks and the middle of the table is made of dust, and there it
|
||||
is a maritime climate on the edge of a monsoon and the middle of the table is four grades of rain.
|
||||
No row of it has `wet` under 0.20; the ground is always holding water, which is what the
|
||||
reflections in the road are for. They moved onto `Shift` when
|
||||
the worlds took the digit row: which world you are standing in is the larger fact, and it is the
|
||||
one a viewer told "press 1 or 2" reaches for.
|
||||
|
||||
On a phone or tablet the left half of the screen walks, the right half looks, and a tap goes
|
||||
fullscreen. There is no world gesture: every gesture on a touchscreen is already spoken for by
|
||||
those two halves, and a hidden two-finger something that rebuilds the world is a trap rather than
|
||||
a control — so on a phone the other two worlds are reached by their URLs, `#west/42` and
|
||||
`#moon/42`.
|
||||
a control — so on a phone the other three worlds are reached by their URLs, `#west/42`,
|
||||
`#moon/42` and `#japan/42`.
|
||||
|
||||
Gamepads work too, and a pad is the one input device other than a keyboard that can reach the
|
||||
second world: **Y** (triangle) cycles it.
|
||||
other worlds: **Y** (triangle) cycles through them.
|
||||
|
||||
The URL carries the world and the seed — `#42` for a city, `#west/42` or `#moon/42` for the same
|
||||
seed elsewhere — so a place you liked is a link you can send. The bare `#seed=42` form still works,
|
||||
and so do the words people actually type: `#western/42`, `#lunar/42`, `#apollo/42`.
|
||||
The URL carries the world and the seed — `#42` for a city, `#west/42`, `#moon/42` or `#japan/42`
|
||||
for the same seed elsewhere — so a place you liked is a link you can send. The bare `#seed=42` form
|
||||
still works, and so do the words people actually type: `#western/42`, `#lunar/42`, `#apollo/42`,
|
||||
`#edo/42`, `#kyoto/42`.
|
||||
|
||||

|
||||
|
||||
|
|
@ -369,17 +423,61 @@ occupied and only the sway moves them. Measured now, at a four-second window wit
|
|||
pinned: the frontier's own elements take a big step 1.50 times a second against the city's own
|
||||
1.50, and carry 2.53% of full scale in the 3-20 Hz band against the city's 2.28% — the two worlds
|
||||
are the same shape, which is what the gate was for. The Moon's own elements are 0.00/s and 0.00%,
|
||||
because `vacuum` has every parameter at zero and there is nothing out there that modulates. With
|
||||
every element in a world switched on at once, which is context rather than a gate, the big-step
|
||||
rates are 4.75/s for the city, 7.25/s for the frontier and 0.25/s for the Moon. The tumbleweed's
|
||||
roll rate and the cloud bars' drift were sized against the same rule in advance, with the
|
||||
arithmetic written down next to the constant.
|
||||
because `vacuum` has every parameter at zero and there is nothing out there that modulates. Edo's
|
||||
are 0.75/s and 2.23%. With every element in a world switched on at once, which is context rather
|
||||
than a gate, the big-step rates are 4.75/s for the city, 7.25/s for the frontier, 0.25/s for the
|
||||
Moon and 1.50/s for Edo. The tumbleweed's roll rate and the cloud bars' drift were sized against
|
||||
the same rule in advance, with the arithmetic written down next to the constant.
|
||||
|
||||
The canal found a fifth kind of failure and it is the one worth reading, because **the shipped gate
|
||||
returned PASS on it while rendering zero canal cells**. `west-flicker.cjs` pins the camera at the
|
||||
map's start; the channel is on a 160 m pitch and is a hundred metres from there, so the tool was
|
||||
measuring a frame with no water in it. Pinning the camera *on the water* instead — that probe is
|
||||
kept as `tools/canal-flicker.cjs` — the first cut scored **3.61% in the 3-20 Hz band against a 2%
|
||||
rule and 2.5 big steps a second against a limit of 1.0**.
|
||||
|
||||
The mechanism is the interesting part, and it is the companion to the blossom's lesson rather than a
|
||||
repeat of it. The ripple is a *fractional row offset* that the caster floors to pick a source row,
|
||||
so what the eye sees is not the offset, it is the offset **crossing an integer** — and each crossing
|
||||
swaps the reflected cell between a lantern and the black beside it, which is a near-full-scale step.
|
||||
Cutting the amplitude six-fold and the mirror by a third barely moved the number, because once the
|
||||
amplitude is under one row the crossing rate is no longer set by how far the offset swings; it is set
|
||||
by how often the noise wanders back across one boundary, which is the noise's own frequency. At
|
||||
1.1 Hz its third harmonic is 3.3 and lands inside the band. **The rate was the lever**: 0.37 Hz puts
|
||||
the first three harmonics at 0.74, 1.11 and 1.48, and the measurement drops to 1.43% and 0.50/s with
|
||||
reduced motion silent at 0.00%. The mirror then goes back up and the water keeps its depth.
|
||||
|
||||
Edo's gate found four more before that, and it is worth saying that **none of them was visible in a
|
||||
still and none of them showed up in any census** — every frame was correct at every instant and the whole
|
||||
defect was in the rate. Rain running down a lit paper screen re-dealt its hash eleven times a
|
||||
second, which is the middle of the danger band, over the largest lit area in the frame; a second
|
||||
rain drawn into the sky dome re-dealt every sky cell it touched about every other frame, which is
|
||||
not a moving streak but per-frame noise, and per-frame noise puts energy at *every* frequency; the
|
||||
ripple offset on a puddle stepped the mirrored row by up to four rows at 4.5 Hz in a downpour; and
|
||||
the gutter's water pattern ran at 2.6 Hz, whose second and third harmonics land at 5.2 and 7.8. The
|
||||
sky rain was deleted outright — `elements/weather.js` already owns the rain in every world that has
|
||||
any, and a second cruder one behind it was never worth a line — and the other three were slowed
|
||||
under the band, with the streak also inverted to be *darker* than the paper behind it, which is
|
||||
both the smaller step and what water on a lit screen actually looks like.
|
||||
|
||||
The blossom drift is the one that had to be redesigned rather than slowed, and its note is the
|
||||
useful one. A petal crosses a *cell* in about a fifth of a second at conversational distance, so it
|
||||
switches that cell at roughly 5 Hz whatever it is drawn at — and dimming it (150 to 96) and
|
||||
thinning the pool (64 petals to 40 to 22 to 10) left the gate reporting the identical figure at the
|
||||
identical cell every single time, because the worst cell is one petal's trajectory and neither
|
||||
lever touches the rate. What fixed it was distance: nothing inside 11 m is drawn, faded in over the
|
||||
next five, because at 11 m a petal covers a cell for half a second and is out of the band. It is
|
||||
also the better picture — a petal a metre from the eye reads as a bug on the lens.
|
||||
|
||||
`prefers-reduced-motion` is honoured throughout. With it on, the walk slows, the rain calms, the
|
||||
police lightbar holds steady instead of alternating, the aerial traffic parks, the windmill's vane
|
||||
stops and the tumbleweed slows to a third — but both worlds stay populated. The point is stillness,
|
||||
not deletion. Measured: with the flag on, the frontier's own elements produce **no** step over a
|
||||
third of full scale anywhere and an empty 3-20 Hz band, in every weather state.
|
||||
stops, the tumbleweed slows to a third, and Edo's lantern flames, noren hems, gutter and sky bands
|
||||
all freeze — but every world stays populated. The point is stillness, not deletion. The one thing
|
||||
that is *removed* rather than damped is the blossom, and the reason is that damping it does not
|
||||
make it a quieter version of itself: a drift of petals **is** the motion, and thirty petals frozen
|
||||
in mid-air are not a calmer drift, they are a scatter of dots hanging in the sky. Measured: with
|
||||
the flag on, every world's own elements produce **no** step over a third of full scale anywhere and
|
||||
an empty 3-20 Hz band, in every weather state.
|
||||
|
||||
## Running it
|
||||
|
||||
|
|
@ -433,13 +531,14 @@ Everything here runs without a browser, which is how the thing gets verified at
|
|||
|
||||
| | |
|
||||
|---|---|
|
||||
| `tools/headless.cjs` | render any frame of any seed offline, as a text dump — `--west` / `--moon`, `--time=`, `--weather=`, `--yaw=` |
|
||||
| `tools/headless.cjs` | render any frame of any seed offline, as a text dump — `--west` / `--moon` / `--japan`, `--time=`, `--weather=`, `--yaw=` |
|
||||
| `tools/topng.py` | turn that dump into a PNG, with the bloom the canvas applies |
|
||||
| `tools/metrics.py` | the print census — exposure bands, colour split, what each layer costs |
|
||||
| `tools/peds.cjs` | the crowd alone, against an empty frame, at a size you can actually see |
|
||||
| `tools/flicker-rate.cjs` | the photosensitivity gate, for the city's signage — run it with **no arguments**, see above |
|
||||
| `tools/lightning-rate.cjs` | the same, for storms |
|
||||
| `tools/west-flicker.cjs` | the same, for every world that is not the city — pinned camera, per cell, against the city as its baseline |
|
||||
| `tools/canal-flicker.cjs` | the same, for Edo's canal — pins the camera **on the water**, which the gate above structurally cannot do |
|
||||
| `tools/domshim.cjs` | runs the built page against a fake DOM — boot, resize, input, worlds, tab loss |
|
||||
|
||||
The renderer is deterministic: the same seed and frame give a byte-identical picture in a browser
|
||||
|
|
|
|||
125
build.js
125
build.js
|
|
@ -204,7 +204,22 @@ const parts = files.map(p => {
|
|||
/* One IIFE, one `var CC`. core.js declares CC with `var`, so it is hoisted to the top of this
|
||||
* function and every later module's `typeof CC !== 'undefined'` guard sees it. Nothing leaks to
|
||||
* window, which is the point: the page has no API surface to poke at. */
|
||||
const bundle = '(function () {\n' + parts.join('\n') + '\n})();\n';
|
||||
/* ---- one 'use strict', not thirty-three -------------------------------------------------------
|
||||
* Every module in src/ opens its IIFE with `'use strict';` because every module is also `require`d
|
||||
* on its own by tools/headless.cjs, where nothing else would supply it. Concatenated, that is 33
|
||||
* copies of the same 13-byte directive inside one wrapper that is itself sloppy-mode — so the
|
||||
* directive is doing real work per module and cannot simply be deleted.
|
||||
*
|
||||
* Hoisting it is the cut. One directive on the wrapper makes the WHOLE bundle strict, which is
|
||||
* exactly the union of what the 33 were doing individually, and there is no code in the bundle
|
||||
* outside a module IIFE for it to newly apply to. 481 bytes, and the only non-content cut left
|
||||
* after the dead-identifier sweep that does not touch a line of source.
|
||||
*
|
||||
* The match is deliberately narrow: a line whose ENTIRE content is the directive. A `'use strict'`
|
||||
* inside a string literal or trailing another statement is left alone, because this runs after
|
||||
* decomment() and has no parser to tell it apart. */
|
||||
const parts2 = parts.map(p => p.replace(/^[ \t]*(['"])use strict\1;[ \t]*$\n?/gm, ''));
|
||||
const bundle = "(function () {\n'use strict';\n" + parts2.join('\n') + '\n})();\n';
|
||||
|
||||
/* The page must open with ZERO network requests, so nothing may reference a module loader. */
|
||||
if (/\brequire\s*\(/.test(bundle)) throw new Error('build: a require() survived the strip');
|
||||
|
|
@ -217,7 +232,8 @@ if (/<\/script/i.test(bundle)) throw new Error('build: source contains a closing
|
|||
/* Every module named its global; if one is missing it was dropped, mis-ordered, or the comment
|
||||
* scanner ate something structural. Cheap, and it has caught both. */
|
||||
for (const need of ['var CC', 'CC.City', 'CC.Surf', 'CC.Cast', 'CC.Canvas', 'CC.Main',
|
||||
'CC.World', 'CC.SurfWest', 'CC.Daylight', 'CC.ELEMENTS.push'])
|
||||
'CC.World', 'CC.SurfWest', 'CC.SurfMoon', 'CC.SurfJapan',
|
||||
'CC.Daylight', 'CC.ELEMENTS.push'])
|
||||
if (!bundle.includes(need)) throw new Error('build: bundle is missing ' + need);
|
||||
|
||||
/* Compiles the bundle without running it. This is what makes the comment scanner safe to trust:
|
||||
|
|
@ -403,8 +419,107 @@ console.log('index.html ' + bytes + ' bytes (' + (bytes / 1024).toFixed(1) + '
|
|||
* WHAT THAT BUYS THE NEXT PASS, honestly: 25.5 KB is about a third of a world, so this is not a
|
||||
* reprieve. The next pass over the line has the same three options and one fewer of them — the
|
||||
* whitespace is spent now — and the two that remain are the two the essay above already refuses.
|
||||
* Splitting the payload is still the escape hatch and it is still the last one. */
|
||||
if (bytes > 560 * 1024) {
|
||||
console.error('build: index.html is over the 560 KB budget');
|
||||
* Splitting the payload is still the escape hatch and it is still the last one.
|
||||
*
|
||||
* ---- AND THE PASS AFTER THAT MOVED IT. 560 KB -> 580 KB, AT 567.5. ----
|
||||
* Fifth time at this line. The paragraph directly above says the next pass has three options and
|
||||
* one fewer of them; this is the answer to that paragraph, taken in the order the note at the head
|
||||
* of the file demands — cut what is not content, then cut content, then move the line, and write
|
||||
* down which one you did. What was done is the third, and the first two were tried first.
|
||||
*
|
||||
* WHAT LANDED: a fourth world. EDO — a castle town on a wet evening — as src/surf_japan.js and
|
||||
* src/elements/jp_town.js, plus a district table, a theme block, a weather table and a registry row
|
||||
* inside four existing files, and thirteen shared atmospheric elements widened to include it.
|
||||
*
|
||||
* WHAT IT COST, and this is the number worth recording: 33.2 KB stripped, against the frontier's
|
||||
* 65 and the Moon's 55. A world in this engine used to be "simply about that big" and it is now
|
||||
* about half that big, and the reason is not that this one is thinner — it has a painter, five
|
||||
* elements of its own, its own lighting model and its own sky. It is that the three registries the
|
||||
* Moon's pass built (src/proj.js's shared element camera, CC.SURFACES's painter map and city.js's
|
||||
* THEMES map) mean a fourth world writes almost no scaffolding: no projection, no view/emit/column,
|
||||
* no per-world branch anywhere in raycast.js, main.js, control.js or tools/headless.cjs. The
|
||||
* previous two passes paid for this one.
|
||||
*
|
||||
* WHAT WAS CUT FIRST, and it is honest to say it was almost nothing: 305 bytes of glyph constants
|
||||
* declared and never used in the two new files. That is the whole of the non-content cut available,
|
||||
* and it was looked for rather than assumed. The two candidates the essays above name are still
|
||||
* the only two:
|
||||
* STRIPPING INDENTATION OUTRIGHT is worth about 42 KB on top of the halving that already
|
||||
* happened, and it is refused for the third time on the third file's own grounds — halving
|
||||
* leaves a nested document a person can read, and stripping leaves a wall. That refusal is the
|
||||
* one thing about this budget that has never moved and it should not move now.
|
||||
* SPLITTING THE PAYLOAD costs the "one self-contained file" property, which is not a constraint
|
||||
* on the deliverable, it IS the deliverable — the contract's first line. Spending it to avoid
|
||||
* a 20 KB raise would be trading the thing the project is for a number that still describes
|
||||
* one HTTP response.
|
||||
* Deleting content to make a number is what the 420 essay forbids and it is still the wrong way
|
||||
* round: the content is the point.
|
||||
*
|
||||
* SO: 580 KB, ~152 KB gzipped, still one response, still parsing in well under a frame, still a
|
||||
* page source a person can open and read. Four worlds and a day cycle in 580 KB.
|
||||
*
|
||||
* THE HEADROOM IS DELIBERATELY SMALL and that is the whole of what this raise is willing to give.
|
||||
* 12.5 KB is a third of a world and about one element file — it is not a reprieve and it is not
|
||||
* meant to be. The 420 pass raised the line and left 4 KB and the note called that "not headroom";
|
||||
* this leaves three times that and says the same thing about it. The number was also set AFTER the
|
||||
* last source file landed rather than while the tree was half-written, which is the one lesson the
|
||||
* 560 pass wrote down about itself and then had to learn twice.
|
||||
*
|
||||
* WHAT THE NEXT PASS HAS. Two options, not three. The whitespace is spent, the unused-identifier
|
||||
* sweep is spent, and the indentation refusal has now been reaffirmed three times, which should be
|
||||
* read as settled rather than as an option still on the table. That leaves splitting the payload —
|
||||
* and a fifth world is where it stops being the escape hatch and starts being the design. If you
|
||||
* are here to add one: split first, then add it, and do not touch this line again. *
|
||||
* ---- AND THE PASS AFTER THAT MOVED IT AGAIN. 580 KB -> 600 KB, AT 590.1. ----
|
||||
* Sixth time at this line, and the paragraph directly above it says not to do this. It is owed a
|
||||
* straight answer rather than an edit, so here is the arithmetic that overruled it.
|
||||
*
|
||||
* WHAT LANDED: content for EDO — a CANAL in the map with a reflecting water surface, festival
|
||||
* BANNERS, SAKURA trees, a castle KEEP, red-papered lanterns, a wider district accent, and dyed
|
||||
* umbrellas on the crowd. Asked for by name, all of it.
|
||||
*
|
||||
* WHAT WAS CUT FIRST, because the procedure at the head of this file demands it and because the
|
||||
* paragraph above says the sweep is spent — it was not:
|
||||
* - `edgeDist()` in jp_town.js, dead on arrival one pass earlier when the stone lanterns were
|
||||
* rewritten to walk the street instead of a lattice. MEASURED -416.
|
||||
* - `'use strict'` hoisted from 33 module IIFEs onto the wrapper. Every module needs its own when
|
||||
* `require`d alone by the harness, and concatenated they are 33 copies inside one sloppy-mode
|
||||
* wrapper; one directive on the wrapper is the exact union of what they were doing.
|
||||
* MEASURED -481, and all 36 four-world fixtures byte-identical.
|
||||
* Both were taken. -897 total, and the pass ends up carrying more content per byte than it did.
|
||||
*
|
||||
* WHY THE LINE MOVED ANYWAY, AND THIS IS THE PART THAT IS NOT A DODGE. The content is 24 KB and the
|
||||
* headroom was 13. THERE IS NO COMBINATION THAT FITS, and that was checked rather than assumed:
|
||||
* everything, after the two cuts above ............ 604,283 (10,363 over)
|
||||
* minus the castle keep (7.0 KB) .................. 597,325 (3,405 over)
|
||||
* minus the keep AND the duplicated helpers ....... 594,975 (1,055 over)
|
||||
* The last row is with EVERY cut this tree has left, including one that is not free (see below),
|
||||
* and it is still over. So the choice was never "cut or raise" — it was "raise, or delete a third
|
||||
* of what was asked for". Deleting content to make a number is what the 420 essay forbids and it
|
||||
* is still the wrong way round.
|
||||
*
|
||||
* WHAT WAS MEASURED, BANKED AND DELIBERATELY NOT TAKEN, so the next pass does not re-derive it:
|
||||
* the duplicated function bodies. `streetSpan` is byte-identical across market.js, west_town.js,
|
||||
* west_stock.js and structure.js; `objVisible` across west_town.js and west_stock.js; `corridor`
|
||||
* across police.js and street.js. Hoisting them into src/proj.js is worth about 2,350 bytes and it
|
||||
* is the cut proj.js's own header asks for. It was NOT taken here for one reason: it does not
|
||||
* change the outcome. It saves 2.3 KB against a 10.4 KB overrun, so the line moves either way — and
|
||||
* it touches six files belonging to three shipped worlds, in exactly the operation this file
|
||||
* already records as having cost two silent clock-cache bugs the last time it was performed.
|
||||
* Risk with no benefit is not a cut, it is a coin flip. TAKE IT when it is worth something.
|
||||
*
|
||||
* SO WHAT DOES 600 KB MEAN? ~157 KB gzipped, one HTTP response, parsing in well under a frame, and
|
||||
* a page source a person can still open and read. Four worlds, a day cycle and a canal in 600 KB.
|
||||
*
|
||||
* AND THE HONEST WARNING, which is the same one the paragraph above gives and it is now overdue:
|
||||
* THE NEXT PASS MUST SPLIT. Not because 600 is a magic number but because the last three passes
|
||||
* have each ended with the same finding — the content is bigger than the headroom and the cuts are
|
||||
* rounding errors against it. The banked duplication cut above is the last non-content cut in the
|
||||
* tree and it is worth two thousand bytes. A world is thirty thousand. Splitting the payload costs
|
||||
* the "one self-contained file" property, which is the first line of CONTRACT.md and is a real
|
||||
* loss — but it is the only remaining answer that is not "ship less", and it should be taken
|
||||
* deliberately, by someone who has decided that trade, rather than discovered at this line again. */
|
||||
if (bytes > 600 * 1024) {
|
||||
console.error('build: index.html is over the 600 KB budget');
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
|
|||
BIN
docs/edo-canal.png
Normal file
BIN
docs/edo-canal.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 595 KiB |
BIN
docs/edo.png
Normal file
BIN
docs/edo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 775 KiB |
1859
index.html
1859
index.html
File diff suppressed because it is too large
Load diff
304
src/city.js
304
src/city.js
|
|
@ -99,9 +99,51 @@
|
|||
['.', ',', "'"] // 9 swell — open ground that happens to be higher than the ground beside it
|
||||
];
|
||||
|
||||
/* ---- EDO's six, and every one of them is a JOINT rather than a surface ------------------------
|
||||
* The world-wide style numbering continues at 10: the frontier stops at 6, the Moon at 9, and a
|
||||
* reader who sees 13 on a record can find row 13 in exactly one table. TH_JAPAN.styleBase is 10
|
||||
* and makeRec takes the offset off again.
|
||||
*
|
||||
* WHAT MAKES THE READ, and it is not colour. A frontier wall is a MASS of boards with holes
|
||||
* punched in it, so its dim glyph carries the whole facade and its lit glyph is a rarity. A
|
||||
* machiya front is the opposite object: it is a TIMBER FRAME with the gaps filled in, and the
|
||||
* thing the eye reads it by is the frame — the vertical slats of a koshi lattice, the grid of a
|
||||
* shoji screen, the posts either side of a plaster panel. So five of these six lead on a dim
|
||||
* glyph that is a LINE ('|', '+', '=') rather than a stroke, and the two that do not are the two
|
||||
* things in this world that genuinely are mass: the storehouse and the castle wall.
|
||||
*
|
||||
* '|' IS THE MOST IMPORTANT GLYPH IN THIS TABLE and it is the one the frontier could not use. Its
|
||||
* measured ink is 18.7% against '-' at 5.3 (surf_west.js's INK ramp has the census), so a wall of
|
||||
* it is four times the ink a clapboard wall is — which would have been wrong out there and is
|
||||
* right here, because a koshi lattice really is a solid rank of slats at 3 cm centres and a
|
||||
* machiya front really is darker and denser than the plaster beside it.
|
||||
*
|
||||
* AND THE LIT GLYPH IS THE PAPER, not a window. On every other world 'lit' means a hole with a
|
||||
* lamp behind it; here the screen itself is the emitter — a shoji is a sheet of paper with the
|
||||
* room's light coming through the whole of it — which is why rows 10 and 11 light in '#' and '8',
|
||||
* the two heaviest glyphs the print will take without the bloom welding cells together. */
|
||||
var STYLE_CH_JP = [
|
||||
['8', '|', 'o'], // 10 machiya — koshi lattice over a dark timber frame, the street standard
|
||||
['#', '+', ':'], // 11 shoji — a whole storey of paper screens; the wall IS the lamp
|
||||
['O', "'", ':'], // 12 kura — lime plaster storehouse, blind on three sides
|
||||
['0', 'X', ':'], // 13 namako — tile set in a diamond lattice of raised plaster joints
|
||||
['8', '=', 'o'], // 14 temple — heavy horizontal timber under an eave that eats the wall
|
||||
['%', '&', ':'] // 15 ishigaki — the battered rubble base of a castle, and nothing above it
|
||||
];
|
||||
/* A KANBAN, not a noren and not a lantern. Edo shop signage is a large carved or painted wooden
|
||||
* board hung flat on the frontage, which is the object city.js already knows how to hang — the
|
||||
* frontier's `board` — and the two soft lit things this world is actually remembered for, the
|
||||
* split noren curtain and the paper chochin, are OBJECTS rather than texture and belong to
|
||||
* src/elements/jp_town.js where they can hang in front of a wall instead of being painted on it.
|
||||
*
|
||||
* The glyphs are the ones that read as a dense block of brushed character at two cells tall.
|
||||
* There is no '/' or 'Z' in here: a kanji is built out of horizontals and verticals and reads
|
||||
* WRONG the instant a diagonal appears in it. */
|
||||
var SIGN_CH_JP = ['#', 'H', 'X', 'M', 'W', 'K', '8'];
|
||||
|
||||
// Districts are the colour masses. Weights keep the two pillars dominant and violet rare,
|
||||
// which is the reference ratio (amber ~26% of lit pixels, azure ~27%, violet a garnish).
|
||||
var DIST = null, DIST_CYBER = null, DIST_WEST = null, DIST_MOON = null;
|
||||
var DIST = null, DIST_CYBER = null, DIST_WEST = null, DIST_MOON = null, DIST_JAPAN = null;
|
||||
function buildDistricts() {
|
||||
DIST_CYBER = [
|
||||
// hMin is the floor of the canyon wall, not the average: with the squared height curve most
|
||||
|
|
@ -392,11 +434,118 @@
|
|||
vacant: 0.93, boulder: 0.14, crater: 0.05 }
|
||||
];
|
||||
|
||||
norm(DIST_CYBER); norm(DIST_WEST); norm(DIST_MOON);
|
||||
/* ---- EDO: a castle town on a wet evening, and the quarters are TRADES ---------------------
|
||||
* Read against the other three tables, the axis this one runs is neither colour (the city) nor
|
||||
* material (the frontier) nor landform (the Moon) — it is WHO LIVES ON THE BLOCK, because that
|
||||
* is what actually decided how a machi was built. A merchant street, a warehouse district, a
|
||||
* temple precinct and a castle enclosure are four different building types, four different
|
||||
* heights and four different amounts of open ground, and every other field here falls out of
|
||||
* which of them a lot belongs to.
|
||||
*
|
||||
* NOTHING LEADS ON A SATURATED HUE, and that is the discipline this table has to keep. The
|
||||
* cliche of this setting is vermilion — the torii, the temple column, the lacquer — and a
|
||||
* quarter with `hue: P.ember` in it would put sixteen-column red walls down a street where the
|
||||
* real thing is unpainted cedar going grey, lime plaster and grey clay tile. So ember appears
|
||||
* exactly once, on `temple`, at a mixP of 0.42 — i.e. under half of even that quarter's lots —
|
||||
* and it is otherwise an ACCENT, which surfaces reach through the window-accent roll and
|
||||
* signHue and nowhere else. Vermilion is a column and a gate, and columns and gates are
|
||||
* objects, so they belong to src/elements/jp_town.js.
|
||||
*
|
||||
* THE PILLAR ARITHMETIC, on the same form as the city's. Ground that leads on timber or sand —
|
||||
* the two swatches that ARE weathered cedar, in shade and in the wet light respectively —
|
||||
* is machiya 0.26 + nagaya 0.15 + market 0.11 = 0.52, and `mix` threads one or the other
|
||||
* through kura, temple, garden and castle at (1 - mixP) for another 0.09, so 61% of the town
|
||||
* is wood. white takes 0.15 (the plaster), stone 0.13 (the castle base and the walls), moss
|
||||
* 0.10 (the garden). That is a brown-grey-green town with red on the objects in it, which is
|
||||
* what the reference prints are, and it is what stops this world reading as the frontier: the
|
||||
* frontier is timber under a DRY sky at 0.30 haze minimum, and this is the same timber wet.
|
||||
*
|
||||
* `lit` IS HIGHER THAN ANY OTHER WORLD'S AND IT MEANS SOMETHING DIFFERENT HERE. On the city it
|
||||
* is the share of punched windows with a lamp behind them; on the frontier it is a third of
|
||||
* that, because a kerosene town can only afford so many. Here it is the share of BAYS whose
|
||||
* paper screen is lit — and a bay is 2.9 m of frontage lit over its whole area rather than a
|
||||
* 1 m hole in a wall, so the same number buys many times the lit surface. machiya at 0.46 is
|
||||
* roughly one shopfront in two, which is what a lit machi street after dark actually is, and it
|
||||
* is where the whole world's night look lives: measured before this table was raised, `warm`
|
||||
* was 4.6% of a night frame's lit energy against the frontier's 17.5% — this world was less
|
||||
* lamplit than the desert, which is the one thing it must never be.
|
||||
*
|
||||
* hMin/hMax ARE THE OTHER HALF OF THE SETTING. Nothing here except the castle keep and the
|
||||
* pagoda clears 9 m, because a machiya is one and a half storeys with a deep roof on it — and
|
||||
* the roof is most of the building, which is why the eave setback below (see TH_JAPAN's
|
||||
* podMin/podVar) takes a third of every lot's height back off its outer ring. The two tall
|
||||
* rows are deliberately rare and deliberately enormous against everything around them: a keep
|
||||
* at 13-25 m over a street of 6 m frontages is a five-storey building in a two-storey town,
|
||||
* seen from the end of every street in it, and it is the one vertical this world has. */
|
||||
DIST_JAPAN = [
|
||||
/* The merchant street, and the row this world is mostly made of. `styles` is machiya twice
|
||||
* and shoji once so two lots in three are lattice and one in three is paper — which is what
|
||||
* carries the lit frontage after dark without every building being a lantern. */
|
||||
{ name: 'machiya', hue: P.timber, mix: P.sand, mixP: 0.72, accent: P.warm, styles: [10, 10, 11],
|
||||
hMin: 5.4, hMax: 8.6, lit: 0.46, signP: 0.52, landmark: 0.004, w: 0.26,
|
||||
vacant: 0.08 },
|
||||
/* The back-lane tenements — nagaya, the row house. Lower, poorer, and the darkest frontage
|
||||
* in the settled half of the table; its openings are shutters rather than lattice, which is
|
||||
* why it leads on the plain machiya style with the plaster row threaded through it. */
|
||||
{ name: 'nagaya', hue: P.timber, mix: P.stone, mixP: 0.66, accent: P.sand, styles: [10, 12, 10],
|
||||
hMin: 4.2, hMax: 6.4, lit: 0.24, signP: 0.14, landmark: 0.002, w: 0.15,
|
||||
vacant: 0.14 },
|
||||
/* Kura — the fireproof storehouse, thick lime plaster over an earth core, and the only white
|
||||
* mass in town. It is blind by construction (signP 0.06, lit 0.08): a warehouse has two
|
||||
* small barred openings and a door, and at night there is nobody in it. */
|
||||
{ name: 'kura', hue: P.white, mix: P.timber, mixP: 0.70, accent: P.stone, styles: [12, 13, 12],
|
||||
hMin: 6.2, hMax: 9.4, lit: 0.08, signP: 0.06, landmark: 0.006, w: 0.15,
|
||||
vacant: 0.16 },
|
||||
/* The temple precinct. landmark 0.026 is the highest rate in this world and it is what puts
|
||||
* a pagoda up: TH_JAPAN's lmMin/lmVar hand a landmark 13-25 m, and against a 6 m street that
|
||||
* is the silhouette the whole quarter exists for. ember leads under half its lots and gold
|
||||
* is the metal on the finial and the bracket ends. */
|
||||
{ name: 'temple', hue: P.ember, mix: P.timber, mixP: 0.42, accent: P.gold, styles: [14, 14, 12],
|
||||
hMin: 6.6, hMax: 11.0, lit: 0.26, signP: 0.10, landmark: 0.026, w: 0.12,
|
||||
vacant: 0.26 },
|
||||
/* Garden — 58% open ground, and it does for this world exactly what `range` does for the
|
||||
* frontier and `mare` for the Moon: it is the row that stops the town tiling frontage to the
|
||||
* horizon. What is left standing on it is a wall, a gate and a teahouse, all low. moss leads
|
||||
* because a garden here is moss, clipped pine and wet stone rather than lawn. */
|
||||
{ name: 'garden', hue: P.moss, mix: P.stone, mixP: 0.58, accent: P.jade, styles: [12, 15, 14],
|
||||
hMin: 2.6, hMax: 5.0, lit: 0.06, signP: 0.02, landmark: 0.004, w: 0.10,
|
||||
vacant: 0.58 },
|
||||
/* The castle enclosure: a battered stone base with very little on top of it, and the tallest
|
||||
* row in the table by a factor of three. hMin 7 is the ishigaki itself — a wall you cannot
|
||||
* see over is the point of it — and landmark 0.030 is the keep. */
|
||||
{ name: 'castle', hue: P.stone, mix: P.white, mixP: 0.76, accent: P.gold, styles: [15, 15, 13],
|
||||
hMin: 7.0, hMax: 12.0, lit: 0.07, signP: 0.02, landmark: 0.030, w: 0.11,
|
||||
vacant: 0.22 },
|
||||
/* The riverside market: awnings, stalls and hanging cloth, the lowest and busiest frontage
|
||||
* in town. signP 0.62 is the highest anywhere in this project — a market IS its signage —
|
||||
* and hMax 5.6 keeps the sky slot open over the one place the walk gets crowded. */
|
||||
{ name: 'market', hue: P.sand, mix: P.timber, mixP: 0.54, accent: P.jade, styles: [10, 11, 10],
|
||||
hMin: 3.4, hMax: 5.6, lit: 0.42, signP: 0.62, landmark: 0.001, w: 0.11,
|
||||
vacant: 0.18 },
|
||||
/* ---- THE CANAL BANK, AND IT HAS WEIGHT ZERO -----------------------------------------------
|
||||
* This row is not a quarter and districtType can never roll it. `norm()` accumulates w into
|
||||
* `acc` and `total`, districtType draws `r = hash * total` and returns the first row with
|
||||
* `r < acc[i]` — so with w 0 this row's acc equals its predecessor's, r is strictly less than
|
||||
* total, and the loop always returns at or before `market`. That is arithmetic, not a
|
||||
* convention about being last: the row is unreachable by the Voronoi and reachable only by
|
||||
* computeCell's river branch, which assigns it by index.
|
||||
*
|
||||
* It exists because makeRec is called for the COPING (a coping has height, so it is a lot
|
||||
* like any other) and needs a district record to read hue/styles/lit/signP off. style 15 is
|
||||
* ishigaki, the same battered rubble the castle wall is built from, which is exactly what a
|
||||
* canal embankment is. lit and signP are 0: nobody lights a retaining wall and nobody nails a
|
||||
* shop board to one. */
|
||||
{ name: 'river', hue: P.stone, mix: P.moss, mixP: 0.72, accent: P.moss, styles: [15],
|
||||
hMin: 0.45, hMax: 0.45, lit: 0, signP: 0, landmark: 0, w: 0,
|
||||
vacant: 0 }
|
||||
];
|
||||
|
||||
norm(DIST_CYBER); norm(DIST_WEST); norm(DIST_MOON); norm(DIST_JAPAN);
|
||||
/* Hung on the themes, so make() reads TH.dist and nothing selects a table by comparing a
|
||||
* string. The three-line `west ? A : B` chain this replaced is the exact shape that made a
|
||||
* third world silently inherit the city's districts. */
|
||||
TH_CYBER.dist = DIST_CYBER; TH_WEST.dist = DIST_WEST; TH_MOON.dist = DIST_MOON;
|
||||
TH_JAPAN.dist = DIST_JAPAN;
|
||||
DIST = DIST_CYBER;
|
||||
}
|
||||
function norm(T) {
|
||||
|
|
@ -568,12 +717,79 @@
|
|||
setbackMode: 'none', signShape: 'none', signPalette: 'none'
|
||||
};
|
||||
|
||||
/* ---- EDO ---------------------------------------------------------------------------------
|
||||
* The ground plan is the narrowest in the project and the LOTS are the strangest, and both of
|
||||
* those are the setting rather than a taste.
|
||||
*
|
||||
* AVE 38 / CROSS 32 — between the city's 30 and the frontier's 52, and closer to the city,
|
||||
* because a castle town is DENSE. The block is short, the crossings come often, and that is
|
||||
* what makes the alley rate below matter.
|
||||
* aveWide/Mid/Narrow 5/4/3 — half-widths, so the streets run 6 to 10 m against the frontier's
|
||||
* 12-18 and the city's 6-12. A machi street is a street you can talk across, and at 6 m the
|
||||
* two rows of eaves nearly meet overhead, which is the whole read.
|
||||
* lotW 4 + 3, lotD 9 + 8 — THE EEL'S BED, and it is the one number in this file that is a
|
||||
* historical fact rather than a composition. Edo frontage was taxed by its width, so a
|
||||
* machiya is 4-7 m across the street and 9-17 m deep — an aspect ratio of about 1:2.5,
|
||||
* where every other world in this tree is roughly square (city 6-13 x 6-14, frontier 5-10 x
|
||||
* 6-12). What it buys the frame is that a block's STREET face is cut into many narrow
|
||||
* buildings while its flank is a few long ones, so turning a corner changes the rhythm of
|
||||
* the wall completely — which is what walking round a machi block actually does.
|
||||
* alleyP 0.58 / alleyDeepP 0.46 — the roji, and the highest alley rate in any world. A machi
|
||||
* block is threaded with them and they are how the light gets in; the frontier's 0.52 was
|
||||
* already high and this is a place that is mostly alley.
|
||||
* setbackMode 'podium' with podMin 3.2 / podVar 2.2 — THE EAVE, drawn with the city's own
|
||||
* mechanism and nothing new. The podium rule drops a lot's outer ring to `pod` when pod is
|
||||
* lower than the lot; here the lot is 5-9 m and the ring lands at 3.2-5.4, so every building
|
||||
* in town is a low skirt of roof round a taller ridge. That is a hipped tile roof seen from
|
||||
* a metre seven, and it is the single most recognisable silhouette this world has. setbackP
|
||||
* is 0.62 rather than the city's 0.42 because a machiya without its eave is a shed.
|
||||
* lmMin 13 / lmVar 12 — a pagoda or a keep, 13-25 m. crownTall 20 so only the top half of
|
||||
* that band wears a crown. Well under raycast.js's HMAX of 108.
|
||||
* DG 30 — quarters about 30 m across, tighter than the city's 26-cell Voronoi in world terms
|
||||
* because the block pitch is longer; a trade quarter in a castle town is a few blocks, not
|
||||
* a district.
|
||||
* sky 1 — there is a sky, and it rains out of it.
|
||||
*/
|
||||
var TH_JAPAN = {
|
||||
id: 'japan', AVE: 38, CROSS: 32,
|
||||
aveJit: 17, aveOff: -8, crossJit: 14, crossOff: -7,
|
||||
aveWide: 5, aveMid: 4, aveNarrow: 3, aveMidP: 0.38, aveEvery: 4,
|
||||
crossWide: 4, crossMid: 3, crossNarrow: 2, crossMidP: 0.30, crossEvery: 5,
|
||||
lotW: 4, lotWVar: 3, lotD: 9, lotDVar: 8,
|
||||
alleyMin: 8, alleyP: 0.58, alleyDeepMin: 9, alleyDeepP: 0.46,
|
||||
plazaP: 0.11, plazaBigP: 0.22, plazaR: 4, plazaRVar: 7,
|
||||
vacant: 0.10, setbackP: 0.62, podMin: 3.2, podVar: 2.2, falseFront: 0,
|
||||
lmMin: 13, lmVar: 12, crownTall: 20, DG: 30, sky: 1,
|
||||
/* ---- THE CANAL. See rivZ/rivD in make() for the meander and computeCell for the branch. -----
|
||||
* A horikawa, not the Sumida: 9.2 m of water on a 160 m pitch in z, met once every 100 s of
|
||||
* walking, which makes it the largest-scale event in the walk (a corner is 16-60 s).
|
||||
*
|
||||
* `rivCopeH` 0.45 IS THE NUMBER THE WHOLE FEATURE TURNS ON and it is an occlusion budget rather
|
||||
* than a wall height. A wall of height hh at distance W hides all ground from W out to
|
||||
* W*eyeY/(eyeY-hh); at 0.45 that is 8 -> 11.0 m and 12 -> 16.5 m, i.e. three metres of water.
|
||||
* At the 1.2 m a real embankment parapet actually is, it would be 12 -> 43.3 m — the entire
|
||||
* canal AND the far bank hidden behind its own kerb. The eye supplies the drop from a stone
|
||||
* edge with dark broken water beyond it; it does not need to be shown the drop.
|
||||
*
|
||||
* The meander is deliberately SMALL (±5.0 m). The block interior between two cross streets is
|
||||
* as narrow as 9 m once cz()'s jitter is spent, so the ±18 m a real river wants would put the
|
||||
* channel down the middle of a cross street and the walk's jog segment would run up the water.
|
||||
* Wavenumbers 0.01932 and 0.04310 rad/m are wavelengths of 325.2 and 145.8 m, which are 8.558
|
||||
* and 3.836 of AVE 38 — neither near a small rational, on exactly the argument swellLat 54
|
||||
* makes against AVE 96. The first cut used 0.04724, a clean 7/2 of AVE, and repeated its
|
||||
* features on every block. */
|
||||
rivHalf: 4.6, rivCope: 1.0, rivCopeH: 0.45, rivQuay: 2.2, rivEvery: 5,
|
||||
rivAmp: 3.6, rivAmp2: 1.4,
|
||||
styleCh: STYLE_CH_JP, signCh: SIGN_CH_JP, styleBase: 10,
|
||||
setbackMode: 'podium', signShape: 'board', signPalette: 'lacquer'
|
||||
};
|
||||
|
||||
/* ---- the theme registry ---------------------------------------------------------------------
|
||||
* A MAP, not a ternary. The line this replaced was `id === 'west' ? TH_WEST : TH_CYBER`, and its
|
||||
* failure mode with a third world was not an error: an unknown id fell through to the city and
|
||||
* built a cyberpunk heightmap under somebody else's name. A missing key still falls back — a
|
||||
* world with no theme has to build SOMETHING — but adding a world is now one row. */
|
||||
var THEMES = { cyber: TH_CYBER, west: TH_WEST, moon: TH_MOON };
|
||||
var THEMES = { cyber: TH_CYBER, west: TH_WEST, moon: TH_MOON, japan: TH_JAPAN };
|
||||
function themeOf(id) { return THEMES[id] || TH_CYBER; }
|
||||
function worldId() {
|
||||
return (C && C.World && C.World.id) ? C.World.id : 'cyber';
|
||||
|
|
@ -625,6 +841,11 @@
|
|||
var TH = themeOf(worldId());
|
||||
var AVE = TH.AVE, CROSS = TH.CROSS;
|
||||
var DIST = TH.dist;
|
||||
/* Resolved by NAME once per map rather than hardcoded as an index, because DIST_JAPAN's row
|
||||
* order is a thing a later pass will reorder without thinking about this. -1 in every world
|
||||
* that has no canal, and the branch is gated on the theme constant anyway. */
|
||||
var RIVI = -1;
|
||||
for (var ri = 0; ri < DIST.length; ri++) if (DIST[ri].name === 'river') RIVI = ri;
|
||||
var STY = TH.styles;
|
||||
var SIGNS = TH.signs;
|
||||
|
||||
|
|
@ -646,6 +867,29 @@
|
|||
: (hash(0, m, S + 202) < TH.crossMidP ? TH.crossMid : TH.crossNarrow);
|
||||
}
|
||||
|
||||
/* ---- THE CANAL ------------------------------------------------------------------------------
|
||||
* A band in z, periodic on rivEvery cross streets, meandering in x. Two sine terms so it is not
|
||||
* a regular wave; one seeded phase so a canal is a fact about the seed rather than about the
|
||||
* origin. `rivQ` goes through this file's `hash` wrapper and not raw hash2, for the reason the
|
||||
* salt-spreading essay at the top of the file gives; salt 53 is unused by anything else here.
|
||||
*
|
||||
* rivD measures the channel by |dz| rather than by true perpendicular distance. The combined
|
||||
* slope of the two terms is 3.6*0.01932 + 1.4*0.04310 = 0.130, i.e. 7.4 degrees, so the two
|
||||
* differ by cos(7.4 deg) = 0.9917 — under one per cent, on a function called twenty thousand
|
||||
* times a frame. A sqrt here would buy nothing measurable and cost the whole frame budget.
|
||||
*
|
||||
* The `round((pz - b)/period)` term is what makes it periodic without a loop: it snaps to the
|
||||
* nearest channel rather than searching, so the cost is constant however far from the origin
|
||||
* the walk has got. */
|
||||
var RIV_P = TH.rivEvery !== undefined ? TH.rivEvery * CROSS : 0;
|
||||
var rivQ = TH.rivEvery !== undefined ? hash(0, 0, S + 53) * 6.2832 : 0;
|
||||
function rivZ(px, pz) {
|
||||
var b = CROSS * 0.5 + TH.rivAmp * Math.sin(px * 0.01932 + rivQ)
|
||||
+ TH.rivAmp2 * Math.sin(px * 0.04310 - rivQ * 2.3);
|
||||
return b + Math.round((pz - b) / RIV_P) * RIV_P;
|
||||
}
|
||||
function rivD(px, pz) { var d = pz - rivZ(px, pz); return d < 0 ? -d : d; }
|
||||
|
||||
// Scratch records: computeCell is only ever called from buildChunk, never re-entrantly.
|
||||
var SX = { street: 0, k: 0, b: 0, x0: 0, x1: 0 };
|
||||
var SZ = { street: 0, m: 0, b: 0, z0: 0, z1: 0 };
|
||||
|
|
@ -762,6 +1006,33 @@
|
|||
|
||||
function computeCell(gx, gz) {
|
||||
colX(gx, SX); rowZ(gz, SZ);
|
||||
/* ---- THE CANAL COMES FIRST, AND THE TWO GUARDS ARE THE WHOLE DESIGN ------------------------
|
||||
* `!SZ.street` — THE CROSS STREET WINS. A cross street runs parallel to the channel and the
|
||||
* two overlap on a good fraction of crossings; letting the water flood it would put the
|
||||
* walk's own jog segment in the canal. Clipped by the road instead, it reads as a kashi-dori,
|
||||
* a canal-side street, which is the correct object and costs one comparison.
|
||||
* `!SX.street` on the COPING only — the avenue is cut by the water (that is where the bridge
|
||||
* goes) but must never be blocked by a wall, or the route walks into one.
|
||||
*
|
||||
* NOTHING IS CARVED. Height stays 0 on the water, because a negative height renders
|
||||
* identically to zero in this engine — raycast.js's march is `if (h <= 0) continue` and the
|
||||
* floor is painted by inverse projection against the y=0 plane with no reference to the
|
||||
* heightmap at all. A channel at -1.4 m and one at -14 m produce the same frame. So the water
|
||||
* is a PAINTED PLANE and the read comes from the coping's edge line, from the reflect pass,
|
||||
* and from the far bank standing over it.
|
||||
*
|
||||
* Gated on the theme constant exactly as the Moon's swell is, so the other three worlds take
|
||||
* one undefined comparison per cell and stay byte-identical. */
|
||||
if (TH.rivHalf !== undefined && RIVI >= 0 && !SZ.street) {
|
||||
var rr = rivD(gx + 0.5, gz + 0.5);
|
||||
if (rr < TH.rivHalf) { cH = 0; cD = RIVI; return; }
|
||||
if (rr < TH.rivHalf + TH.rivCope && !SX.street) {
|
||||
/* The lot anchor is snapped to a 4 m lattice so makeRec's per-lot hashes give the coping
|
||||
* a stone pattern that changes every four metres instead of every cell. `& 3` floors
|
||||
* correctly for negative gx, which `%` would not. */
|
||||
cH = TH.rivCopeH; cD = RIVI; cLX = gx - (gx & 3); cLZ = gz - (gz & 3); return;
|
||||
}
|
||||
}
|
||||
if (SX.street || SZ.street) { cH = 0; cD = districtAt(gx, gz); return; }
|
||||
|
||||
var x0 = SX.x0, x1 = SX.x1, z0 = SZ.z0, z1 = SZ.z1, bK = SX.b, bM = SZ.b;
|
||||
|
|
@ -888,6 +1159,29 @@
|
|||
* the palette and the only cool thing in the frame is shadow. Put one azure sign on a
|
||||
* timber front and the whole world stops being a place and starts being a filter. */
|
||||
if (TH.signPalette === 'none') return P.white; // no signs are rolled at all; see DIST_MOON
|
||||
/* ---- EDO: LACQUER AND INK, and it is a narrower palette than the frontier's ---------------
|
||||
* A kanban is a plank of cedar with characters cut into it and filled — with black ink,
|
||||
* with gold leaf if the shop is doing well, with vermilion if it is a temple's. There are
|
||||
* four colours on a street of them and none of them is blue, for exactly the reason the
|
||||
* frontier note above gives: azure and violet read as EMITTED light and everything in this
|
||||
* world is lit by an oil lamp or by a wet sky.
|
||||
*
|
||||
* WARM LEADS AT 0.30 and that is deliberate: `warm` is the lamp behind the paper, and a
|
||||
* board hung under the eave of a lit shopfront takes its colour from that lamp rather than
|
||||
* from its own paint. ember is the lacquered board (0.22), white the fresh plaster-ground
|
||||
* one (0.18), gold the gilded one (0.14) — gold's night ceiling is 157, under amber's 179,
|
||||
* so a gilded board is the brightest sign in town and still loses to the window beside it,
|
||||
* which is the same arithmetic the frontier's note relies on. timber at 0.10 is the board
|
||||
* nobody has repainted, and it is the one that reads as WOOD rather than as writing.
|
||||
* jade closes it at 0.06 — the copper on a temple board, gone green. */
|
||||
if (TH.signPalette === 'lacquer') {
|
||||
if (r < 0.30) return P.warm;
|
||||
if (r < 0.52) return P.ember;
|
||||
if (r < 0.70) return P.white;
|
||||
if (r < 0.84) return P.gold;
|
||||
if (r < 0.94) return P.timber;
|
||||
return P.jade;
|
||||
}
|
||||
if (TH.signPalette === 'painted') {
|
||||
/* gold and moss are the two additions, and they are period rather than decorative: gilt
|
||||
* lettering on a bank or a saloon board, and the dark green ground every second painted
|
||||
|
|
@ -1357,6 +1651,10 @@
|
|||
isStreet: function (gx, gz) { return height(gx, gz) <= 0; },
|
||||
// Exposed for surfaces/elements that want to reason about the corridor itself.
|
||||
aveX: ax, aveW: aw, crossZ: cz, crossW: cw,
|
||||
/* The canal, for the texture layer and for the bridges. `undefined` in a world with no
|
||||
* channel, which is what raycast.js's `city.rivD ? ... : null` reads. */
|
||||
rivD: TH.rivHalf !== undefined ? rivD : undefined,
|
||||
rivHalf: TH.rivHalf, rivCope: TH.rivCope, rivQuay: TH.rivQuay,
|
||||
AVE: AVE, CROSS: CROSS, SPEED: SPEED,
|
||||
/* WHICH WORLD THIS MAP IS, carried on the map rather than read off CC.World. An element that
|
||||
* asks the registry is asking what the viewer last pressed; an element that asks the city is
|
||||
|
|
|
|||
648
src/elements/jp_banner.js
Normal file
648
src/elements/jp_banner.js
Normal file
|
|
@ -0,0 +1,648 @@
|
|||
/* CyberCity EDO festival banners — JP-NOBORI, layer 18.
|
||||
*
|
||||
* WHY THIS IS ITS OWN FILE AND NOT PART OF jp_town.js. It is the same street and the same walk, and
|
||||
* under any other constraint it would live beside the toro and the noren. It does not, for one
|
||||
* reason worth recording: this object was designed once, implemented, censused and refuted on every
|
||||
* claim it made, and the prose that justifies each surviving number is longer than the code. Putting
|
||||
* that inside a file which is already 34 KB of argument would bury both. The cost is one more
|
||||
* CC.Proj.make() basis (one small record, once, for the life of the page) and one more copy of the
|
||||
* street-walk helpers. Everything else — the placement rule, the light model, the glyph budget — is
|
||||
* jp_town.js's, deliberately, and where the two disagree jp_town.js is right.
|
||||
*
|
||||
* WHAT A NOBORI IS. One sheet of bleached cotton about 0.6 m across and two or three metres long,
|
||||
* laced down one edge to a bamboo pole and along its top to a short crossbar, with a dyed hem and a
|
||||
* brushed device on it. They stand in a RANK at the kerb on a temple approach or down a market
|
||||
* street at a festival, all facing the same way — which is to say facing the person walking up the
|
||||
* street, not the buildings opposite. That last fact is the whole geometry of this element and it
|
||||
* is why the cloth spans ACROSS the road rather than along it (see drawNobori).
|
||||
*
|
||||
* WHY IT EXISTS, and it is the one question this file has to answer honestly. The ask was COLOUR.
|
||||
* EDO's measured lit-energy split at night, seed 42, is warm 58.8% / white 16.4% / timber 9.8%,
|
||||
* with jade at 0.4% and gold at 0.0% — six of twenty swatches absent from the world entirely. The
|
||||
* setting is the reason: sumptuary law kept colour off the buildings, so what colour there was hung
|
||||
* in the air on cloth, paper and lacquer. Cloth hung in the air is exactly what an element drawn
|
||||
* through src/proj.js can put in front of a facade, and the facade is the one thing already taken.
|
||||
*
|
||||
* WHAT IT ACTUALLY BOUGHT, measured this session at 200x60, frame 300, against the same tree with
|
||||
* this element dropped from the list — so the comparison is this object and nothing else:
|
||||
* seed 42 night ember 3.0% -> 3.5% of lit energy, white 16.4% -> 17.6%, warm 58.8% -> 57.4%
|
||||
* seed 7 night ember 0.4% -> 1.1%
|
||||
* seed 3 night ember absent -> 0.7%, GOLD absent -> 0.6% (this world measures gold at 0.0%)
|
||||
* seed 3 dusk ember absent -> 0.4%, gold absent -> 0.3%
|
||||
* and on the print census (muddy 9-119, target under 30; hot v>=170, target 3.5-5) it is positive
|
||||
* or flat at all twelve seed/hour fixtures tried — muddy down at eleven of twelve, hot up at eight
|
||||
* and never down. The largest single move is noon, where the hot tail goes 0.73% -> 2.67% at seed
|
||||
* 42 and 0.34% -> 2.69% at seed 3: bleached cotton in sun is one of the few things in this world
|
||||
* that can print in the hot tail by day, and EDO's whole census problem is that it has almost
|
||||
* nothing there.
|
||||
*
|
||||
* ==================================================================================================
|
||||
* THE FIVE THINGS THAT WENT WRONG THE FIRST TIME, all measured by independent reviews of the design
|
||||
* this file replaces, all fixed here by name. This is not caution, it is the list.
|
||||
*
|
||||
* 1. THE POLE AND THE CLOTH FOUGHT FOR ONE CELL. The design stood the pole at the exact point the
|
||||
* cloth was projected from, so the pole's column and the cloth's first column were the same
|
||||
* screen cell at the same nominal depth. CC.put's test is strict (`dist < f.dist[i]`), so the
|
||||
* winner was settled by float32 rounding and flipped from frame to frame: the cell alternated
|
||||
* between timber at lum 114 and blank at about 26 Hz — 45% of full scale in the middle of the
|
||||
* 3-20 Hz flash band — and tools/west-flicker.cjs went from 0.50 big steps/s to 31.50 against
|
||||
* an absolute cap of 8.0. FIXED TWICE OVER HERE: the pole is drawn only BELOW the cloth
|
||||
* (0 -> NOB_BOT + 0.10) so the two barely share a row at all, and the cloth is emitted at
|
||||
* d - 0.02 so that where they do meet the contest is decided by arithmetic, not by rounding.
|
||||
* 2. THE SWAY WAS A LUMINANCE FLASH, NOT A SHAPE MOVING. A 0.12 m positional wobble at 0.35 Hz
|
||||
* moves a banner about 1.3 columns, and because the design wrote every sub-threshold cell as
|
||||
* occluding black, each edge column stepped 0 <-> full scale, twenty-two cells at a time.
|
||||
* Measured 30.25 big steps/s on six of six EDO presets; deleting the one sway line took it
|
||||
* back to 0.50/s and a PASS. THERE IS NO SWAY IN THIS FILE. See the note above mk().
|
||||
* 3. THE BLANKING RULE ATE THE OBJECT. Writing a sub-threshold cell as occluding black is free in
|
||||
* metrics.py's arithmetic (lum 0 counts as blank) but it deleted 74% of the cloth after dark,
|
||||
* and it is the amplitude half of failure 2. THERE IS NO OCCLUDING BLACK HERE EITHER: a cell
|
||||
* that cannot clear the print's muddy ceiling is simply not written and what is behind it
|
||||
* shows through. That one rule is what this whole element is built on — see minLum().
|
||||
* 4. THE DEVICE WAS A FIXED CENTRE COLUMN. At the distances the placement actually delivered the
|
||||
* banner was 1-3 columns wide, so "a centre column plus two hem rows, 27% of the object" was
|
||||
* in fact 56% of it, all in swatches the noon ladder condemns. The device here is keyed on the
|
||||
* banner's OWN measured width and does not exist below nw = 3.
|
||||
* 5. THE BANNERS WERE NEVER NEAR ENOUGH TO SEE. The measured nearest banner over a 301-frame
|
||||
* replay was 23.45 m, and two seeds of three drew none at all after dark. The limiting terms
|
||||
* were the pitch, the district gate and the acceptance rate — NOT the near cut, which never
|
||||
* bound. All three are much more generous here, and the result is measured rather than argued:
|
||||
* over fourteen seeds at night, twelve draw between 4 and 130 cells, and the nearest banner is
|
||||
* between 9.0 m and 13.5 m at nine of them. Two seeds (9 and 13) still draw nothing, and that
|
||||
* is stated rather than hidden — see NOB_R.
|
||||
* ==================================================================================================
|
||||
*
|
||||
* THE PRINT IS THE DESIGN. Every threshold in minLum() was re-derived against core.js's live LUT
|
||||
* this session — by writing one cell through Surf.fog + CC.put + CC.Compose.post and reading
|
||||
* max(r,g,b)*lum/255 back out, which is metrics.py's own definition of a printed value — because
|
||||
* the table the first version was designed against was measured to be 5-10% optimistic, and that is
|
||||
* exactly the margin between a colour cell and a muddy one.
|
||||
*/
|
||||
(function (CC) {
|
||||
'use strict';
|
||||
|
||||
/* One projector per element — see src/proj.js. V and PJ are this element's own basis and scratch;
|
||||
* the three helpers are closed over them. litFace() is deliberately not used: a sheet of hanging
|
||||
* cloth has no face normal worth computing at three columns wide, and this object is lit by the
|
||||
* lamp wash and the sky fill alone, exactly as the wall behind it is. */
|
||||
var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ;
|
||||
var project = PR.project, emit = PR.emit, column = PR.column;
|
||||
|
||||
var P = CC.P, hash2 = CC.hash2, clamp = CC.clamp;
|
||||
|
||||
/* GLYPHS, all from core.js's existing set and every one chosen by an argument already written down
|
||||
* in city.js or surf_japan.js rather than by eye:
|
||||
* '=' the cloth field — the top of surf_japan.js's own INK ramp at 17% ink, which is as heavy as
|
||||
* this world lets a non-emitting surface go.
|
||||
* '|' the pole, and the luff and fly edges of the cloth. city.js records '|' as the most
|
||||
* important glyph in this world, at 18.7% measured ink against '-' at 5.3.
|
||||
* '-' the hem rows and the top lacing band. A hem is a horizontal edge caught from above, and
|
||||
* the mark that says "edge" at this resolution is one with width across the cell.
|
||||
* '8' the device. city.js reserves '#' and '8' as "the two heaviest glyphs the print will take
|
||||
* without the bloom welding cells together", and a brushed mon on cloth is exactly that kind
|
||||
* of solid mark. '#' is NOT used here: it is the shoji's lit paper and must stay unique.
|
||||
* '`' the one wet glint, the same mark the gutter glint and the lantern core already use.
|
||||
* No diagonals anywhere, for city.js's reason: a kanji is built out of horizontals and verticals
|
||||
* and reads wrong the instant an 'X' or a 'Z' appears in it. */
|
||||
var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_8 = CC.g('8'),
|
||||
G_TICK = CC.g('`');
|
||||
|
||||
/* Bound once per rebuild. `city.world`, never CC.World: between a keypress and the rebuild those
|
||||
* are two different answers and this file must agree with the map it is standing on. The salt is
|
||||
* this element's own — a different multiplier and shift from jp_town.js's — so a banner and a
|
||||
* stone lantern that happen to be walked with the same k do not roll correlated hashes. */
|
||||
var CITY = null, BASE = 0, JP = null;
|
||||
function boot(city) {
|
||||
CITY = (city && city.aveX && city.world === 'japan') ? city : null;
|
||||
BASE = CITY ? ((Math.imul(CITY.seed | 0, 52711) >>> 5) & 0x3fffff) : 0;
|
||||
JP = null;
|
||||
}
|
||||
|
||||
/* Per-frame caches. EVERY ONE OF THESE IS ASSIGNED INSIDE view(), which the contract asks for by
|
||||
* name after two frontier files were left holding their declared defaults and silently stopped
|
||||
* following the clock. There is no wind cache here and that is not an omission: nothing in this
|
||||
* element moves, so the wind has nothing to act on.
|
||||
*
|
||||
* NIGHT is surf_japan.js's dNight and DAYF its dFill, read off the painter registry rather than
|
||||
* by CC.SurfJapan's name, so an element copied into another world picks up that world's painter.
|
||||
* Probed live at all four stops: NIGHT is 1 at night and 0 at dusk AND noon; DAYF is 0 at night
|
||||
* AND dusk and 1 at noon. That pair is what lets the daylight terms in groundLum() be ADDITIVE
|
||||
* and still satisfy the contract's "every daylight scale is the identity at night".
|
||||
*
|
||||
* LAMP is CC.Daylight.P.lamp and nothing else — never multiplied by a second night crossfade of
|
||||
* this file's own. That mistake is shipped, documented three times, and put the whole town out an
|
||||
* hour before dusk; the director already owns the fade and the hysteresis. Measured: LAMP is
|
||||
* 1.000 at night, 1.000 at dusk and 0.000 at noon, which is why dusk is the brightest hour this
|
||||
* object has — lamp wash and sky fill at once. */
|
||||
var W_WET = 1, NIGHT = 1, LAMP = 1, DAYF = 0;
|
||||
function view(f, cam, t) {
|
||||
PR.view(f, cam, t);
|
||||
if (!JP) JP = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null;
|
||||
W_WET = CC.Weather ? CC.Weather.rel('wet') : 1;
|
||||
NIGHT = (JP && JP.night !== undefined) ? JP.night : 1;
|
||||
DAYF = (JP && JP.dayFill !== undefined) ? JP.dayFill : 0;
|
||||
LAMP = CC.Daylight ? CC.Daylight.P.lamp : 1;
|
||||
}
|
||||
|
||||
/* The street-walk helpers, identical in shape and in argument to jp_town.js's — see that file's
|
||||
* notes, which are the authority. The one that is easy to get wrong is alongOf: an avenue is
|
||||
* indexed by x and RUNS along z, so the index comes off V.ox and the walk range comes off V.oz,
|
||||
* one axis apart from nearIdx directly above it, and nothing in either name says so. */
|
||||
function wxOf(axis, along, cross) { return axis ? along : cross; }
|
||||
function wzOf(axis, along, cross) { return axis ? cross : along; }
|
||||
function nearIdx(axis) {
|
||||
return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE));
|
||||
}
|
||||
function centreOf(axis, idx) { return axis ? CITY.crossZ(idx) : CITY.aveX(idx); }
|
||||
function halfOf(axis, idx) { return axis ? CITY.crossW(idx) : CITY.aveW(idx); }
|
||||
function alongOf(axis) { return axis ? V.ox : V.oz; }
|
||||
/* WHERE THE WALL ACTUALLY IS, in world metres. city.js's colX() marks cells [c-hw, c+hw] as
|
||||
* corridor and a cell `g` covers world [g, g+1), so the building face on the +side is the plane
|
||||
* x = c + hw + 1 and on the -side it is x = c - hw. A tenth of a metre wrong here is not a
|
||||
* cosmetic error: the object ends up INSIDE the building and CC.put's depth test removes it
|
||||
* silently, with nothing anywhere reporting it. */
|
||||
function faceOf(axis, idx, side) {
|
||||
return centreOf(axis, idx) + 0.5 + side * (halfOf(axis, idx) + 0.5);
|
||||
}
|
||||
function heightAt(axis, along, cross) {
|
||||
return CITY.height(wxOf(axis, along, cross), wzOf(axis, along, cross));
|
||||
}
|
||||
|
||||
/* ---- THE CONSTANTS, AND THE ARITHMETIC EACH ONE CAME OUT OF -------------------------------- */
|
||||
|
||||
/* NOB_PITCH — metres between banner positions along a frontage, and the direct answer to measured
|
||||
* failure 5. The lanterns in jp_town.js are at 2.4, the noren at 5.4, the toro at 7.4; this is the
|
||||
* second tightest pitch of any object in this world and it has to be.
|
||||
*
|
||||
* THE ARITHMETIC. The banner is only drawn between 9 and 26 m (see NOB_NEAR/NOB_FAR), so the
|
||||
* window that matters is a 17 m annulus on each frontage, forward of the camera. At the original
|
||||
* design's 6.2 m pitch that annulus holds 2.7 candidate slots per side; after the frontage gate
|
||||
* (about a third of slots are vacant lot), the district gate and the acceptance rate, the expected
|
||||
* number of banners in view was well under one — which is exactly what the census of that version
|
||||
* found: 0.83 per frame at night, and none at all at two seeds of three. At 3.2 the same annulus
|
||||
* holds 5.3 slots per side, and measured over fourteen seeds twelve of them now draw. It is not a
|
||||
* picket fence: 3.2 m is a banner every shopfront bay and a half, and the distance gate removes
|
||||
* all but the two or three nearest, so what reaches the frame is a rank of two to four. The 1.2 m
|
||||
* jitter on top keeps the rank from reading as a comb — a festival street is set out by hand —
|
||||
* and is the same device, at the same fraction of the pitch, as the toro's 2.6 on 7.4. */
|
||||
var NOB_PITCH = 3.2;
|
||||
|
||||
/* NOB_BOT / NOB_TOP — the cloth's foot and head in metres, so 2.05 m of cotton.
|
||||
*
|
||||
* THE HEIGHT IS A PRINT DECISION AND NOT A PROPORTION. surf_japan.js's lamp wash is a function of
|
||||
* HEIGHT and nothing else: identity below 1.0 m, smoothstepped to zero at 3.6 m, times 0.86. So
|
||||
* after dark a cell's write luminance falls off with how high up the cloth it is, and measured
|
||||
* against the live LUT a `white` cell needs 138 at 14 m to clear the print's muddy ceiling of
|
||||
* v = 119. groundLum() reaches 223 at NOB_BOT and crosses the 159 it needs after the margin at
|
||||
* about 2.03 m, so a 2.05 m banner is very nearly exactly as much cloth as the night can print,
|
||||
* and every centimetre above it would be cloth drawn only to be discarded. The design this
|
||||
* replaces put the top at 4.05 m and then blanked the upper 72% of it in every night frame.
|
||||
*
|
||||
* NOB_BOT 1.10 keeps the foot just inside the band where the lamp wash is still at full strength,
|
||||
* which is the only band in this world where a colour cell can clear v = 120 after dark. */
|
||||
var NOB_BOT = 1.10, NOB_TOP = 3.15;
|
||||
|
||||
/* NOB_W — the cloth's width in metres, measured across the road. A real nobori is 0.55-0.70 m. At
|
||||
* V.colK 137.6 (200 columns, fov 1.25) that is 8.9 screen columns at 9 m and 3.1 at 26 m, so
|
||||
* across the whole range this object is drawn at it is 3 to 8 columns wide — enough for a device
|
||||
* column with cloth either side of it, narrow enough that three of them are not a wall. */
|
||||
var NOB_W = 0.58;
|
||||
|
||||
/* NOB_OUT — how far the pole stands out from the frontage plane. The lanterns hang at 0.45, the
|
||||
* noren at 0.14, the toro at 0.85. 1.00 puts the banner in front of every one of them so it wins
|
||||
* CC.put's strict depth test rather than fighting it, and city.js's TH_JAPAN gives the narrowest
|
||||
* corridor (crossNarrow 2) about 5 m, of which two facing banners take 1.16 m of cloth and 2 m of
|
||||
* standoff — a festival street, not a blocked one. */
|
||||
var NOB_OUT = 1.00;
|
||||
|
||||
/* NOB_NEAR / NOB_FAR — the only two distance numbers in the file, and both are print constants.
|
||||
*
|
||||
* NOB_FAR 26 IS core.js's FIRST DEPTH-BUCKET BOUNDARY. tone() quantises the print into DBUCKETS 8
|
||||
* across FOG_START 12 .. FOG_END 125, so the gamma lift retires in steps and every threshold in
|
||||
* minLum() jumps by 40-60% at d = 26.125 m: measured on the live LUT, `white` at night needs 153
|
||||
* at 25 m and 219 at 28 m. This element's maximum night write luminance is 223. So past 26 m after
|
||||
* dark there is no luminance that prints a banner at all, and the far cut is where the print puts
|
||||
* it rather than where a taste puts it. Keeping the same cut by day costs a few two-column smears
|
||||
* at 26-40 m and buys one number instead of a second threshold table for the far bucket.
|
||||
*
|
||||
* NOB_NEAR 9 is an AREA bound. At 9 m one banner is 8 columns by 18 rows before the threshold
|
||||
* takes rows off it, about 140 cells; at 6 m it would be 300, a quarter of a 200x60 frame in one
|
||||
* object. It was measured against the alternatives rather than picked: at 13 m only five of eight
|
||||
* test seeds drew a banner at all and at 11 m six did, because the nearest accepted slot usually
|
||||
* sits just inside the cut; at 9 m it is twelve of fourteen. That is the whole reason it is not a
|
||||
* rounder number.
|
||||
*
|
||||
* WHY THE NEAR CUT IS NOT ALSO A RATE BOUND HERE, which the blossom's note in jp_town.js is about
|
||||
* and which is worth being explicit on. A banner is RIGID and STATIC in world space, so as the
|
||||
* camera walks it sweeps ACROSS cells once and leaves them; it does not re-deal, oscillate or
|
||||
* dither in place, and a single pulse is not sustained energy in the 3-20 Hz band. That is the
|
||||
* difference between it and the petal, which crosses and re-crosses the same cells four times a
|
||||
* second, and between it and this design's own deleted sway. Verified rather than assumed:
|
||||
* `node tools/west-flicker.cjs 4` with this element in the tree returns japan seed 42 at
|
||||
* 0.50-0.75 big steps/s and 0.53-1.16% in the 3-20 Hz band on all six EDO presets — the same
|
||||
* numbers the tree measured before it existed — and RESULT: PASS.
|
||||
*
|
||||
* There is one thing near banners DO cost, and it is not flicker. At seed 1 a banner at 9.2 m
|
||||
* stands directly in front of a lit shoji and overwrites 33 cells that were in the print's hot
|
||||
* tail. The frame's hot percentage does not move (0.24% -> 0.24%) because the banner's own cells
|
||||
* take their place, but the trade is real and it is the argument for not going below 9 m. */
|
||||
var NOB_NEAR = 9, NOB_FAR = 26;
|
||||
|
||||
/* NOB_R — per-district acceptance rate, keyed on CITY.DISTRICTS[districtAt()].name. A TABLE and
|
||||
* not a set, because a temple approach and a back lane want opposite densities and the same
|
||||
* literal cannot give both: a rank of four banners is what a matsuri looks like and one lone
|
||||
* banner is what a shop looks like, and both have to come out of one rule.
|
||||
*
|
||||
* ALL SEVEN ROWS ARE IN IT, and that is a repair rather than a taste. The design this replaces
|
||||
* listed three (temple, market, machiya — 49% of the ground by city.js's weights) and was measured
|
||||
* drawing nothing at all at two seeds of three. Traced: the camera was standing on a street whose
|
||||
* near frontages happened to be kura and castle for the whole replay, so the closest accepted
|
||||
* banner in any frame was 28.6 m away and the near half of the picture had none. A district gate
|
||||
* that can switch the object off for a whole street is the wrong shape for something meant to be
|
||||
* characteristic of the world. The rates instead say how OFTEN each quarter flies one: a temple
|
||||
* approach nearly always, a market street usually, a merchant row often, a storehouse district and
|
||||
* a back lane occasionally, a garden rarely, and the castle enclosure least of all — a wall you
|
||||
* cannot see over gets the standards at its gate and nowhere else.
|
||||
*
|
||||
* The absolute values are high because the frontage gate, the 9-26 m annulus and the occlusion
|
||||
* behind them throw away roughly three quarters of every candidate. Measured at these rates over
|
||||
* fourteen seeds at night: twelve draw, at 4 to 130 cells; seeds 9 and 13 draw nothing, in both
|
||||
* cases because the two accepted slots inside 26 m are hidden behind a corner building. */
|
||||
var NOB_R = { temple: 0.72, market: 0.64, machiya: 0.46, kura: 0.30, nagaya: 0.26, garden: 0.20,
|
||||
castle: 0.16 };
|
||||
|
||||
/* NOB_DEV — the hem and device swatch, one roll per banner, and it is TWO swatches where the
|
||||
* design that preceded this had four.
|
||||
*
|
||||
* INDIGO WAS CUT OUTRIGHT. Measured through the live LUT, `indigo` cannot print v >= 120 at ANY
|
||||
* write luminance at ANY hour — night, dusk and noon all come back with no solution. A field of it
|
||||
* is a field of muddy cells by construction, and the census of the earlier version bore that out:
|
||||
* 15 indigo cells sitting in the muddy band at noon, from a guard whose entire purpose was to
|
||||
* prevent exactly that.
|
||||
*
|
||||
* ember IS THREE ROLLS IN FOUR AND IT IS THE LADDER'S CHOICE, NOT A TASTE. core.js's ladder()
|
||||
* splits the palette into SOURCES that blend on the sun curve and SURFACES that blend on the sky
|
||||
* curve, and the test for membership is "does it emit". A dyed cotton hem is a surface, so it is
|
||||
* `ember` (the lacquer and dyed-cloth vermilion) and not `red` (the lamp vermilion, which
|
||||
* jp_town.js's akachochin correctly spends on the paper lantern hanging next to it). Putting cloth
|
||||
* on the source curve would be the exact mistake ladder()'s own essay is written about. It is also
|
||||
* the cheapest accent to print in this world after dark: ember needs 114 at 14 m against white's
|
||||
* 138, so the dyed parts of a night banner clear before the cotton does.
|
||||
*
|
||||
* gold IS ONE ROLL IN FOUR — the gilt device of a temple banner. It is expensive (124 at night,
|
||||
* 229 at noon) and it is the swatch this world measures at 0.0% of lit energy, so one banner in
|
||||
* four carrying it is the difference between the palette having a slot and using it: at seed 3
|
||||
* night it puts gold on screen at 0.6% of lit energy, and at seed 3 dusk at 0.3%. */
|
||||
var NOB_DEV = [P.ember, P.ember, P.ember, P.gold];
|
||||
|
||||
/* ---- THE PRINT THRESHOLDS, MEASURED, AND THE ONE RULE THIS ELEMENT IS BUILT ON ---------------
|
||||
*
|
||||
* A cell is written if and only if it will print at v >= 120. Otherwise nothing is written at all
|
||||
* — not a dim cell, and NOT occluding black. That is the whole of it, and it has three
|
||||
* consequences worth stating out loud because each was a defect in the version this replaces:
|
||||
* - This element essentially cannot add a muddy cell. metrics.py's muddy band is 9 <= v < 120
|
||||
* and every cell here is aimed over 120 or dropped, so the way it moves the muddy count is
|
||||
* DOWN, by overpainting a muddy facade cell. Measured per frame at four seeds and three hours:
|
||||
* it overpaints 8 to 133 muddy cells and adds between 0 and 9 of its own. The residue is not
|
||||
* zero and the reason is honest: optics.js's per-row scanline gain and its exposure adaptation
|
||||
* are applied to f.lum AFTER this element writes and this element cannot see them, so a cell
|
||||
* aimed a point or two over the line can be pushed back under it. The 1.15 margin below is
|
||||
* sized for that and mostly wins.
|
||||
* - This element has no full-scale flash mechanism. Occluding black against a lit wall is a
|
||||
* 0 <-> 255 step every time an edge crosses a cell; a cell that is simply not written leaves
|
||||
* the wall exactly where it was and steps by nothing at all.
|
||||
* - The banner is SHORTER after dark than at noon, and nearer banners are taller than far ones.
|
||||
* That is not a defect, it is the lamp wash made visible: a cloth lit from below fades into
|
||||
* the dark above it, which is what a nobori under a lantern rank looks like.
|
||||
*
|
||||
* THE NUMBERS. Measured this session by writing one cell through Surf.fog -> CC.put ->
|
||||
* CC.Compose.post with the daylight pinned, and reading max(r,g,b)*lum/255 back out. Write
|
||||
* luminance needed for v >= 120 at 14 m:
|
||||
*
|
||||
* night dusk noon
|
||||
* white 138 106 97
|
||||
* ember 114 184 210
|
||||
* gold 124 210 229
|
||||
* sand 175 127 114
|
||||
*
|
||||
* and the same table at 25 m is 153/116/105, 126/202/230, 137/230/251, 193/139/124.
|
||||
*
|
||||
* THE FOG RAMP INSIDE ONE DEPTH BUCKET IS ONE COMMON FACTOR FOR EVERY SWATCH AT EVERY HOUR, and
|
||||
* that measurement is what makes this a four-row table instead of a twelve-row one: the ratio of
|
||||
* the 25 m figure to the 14 m figure is 1.109 for white at night, 1.105 for ember, 1.105 for gold
|
||||
* and 1.105 for sand, and 1.082/1.095/1.096/1.088 at noon. `1 + 0.0095 * (d - 14)` reproduces all
|
||||
* sixteen to within 2%.
|
||||
*
|
||||
* THE 1.15 MARGIN IS NOT SLACK, IT IS THE TWO GAINS THIS FILE CANNOT SEE. optics.js multiplies
|
||||
* f.lum by the eye's adaptation (measured between 0.937 and 1.016 across the seeds used here) and
|
||||
* by a per-row modulation whose worst row carries the scanline dip of (1 - 0.070). Their worst-case
|
||||
* product is about 0.87, and 1/0.87 is 1.15. It also absorbs the 2% the fog approximation above
|
||||
* gives away, and the fact that the table was probed at the default weather while a fixture runs
|
||||
* whatever the schedule hands it.
|
||||
*
|
||||
* THE ONE ARITHMETIC RESULT WORTH CARRYING AWAY, and it inverts the naive plan: VERMILION AND GOLD
|
||||
* ARE NIGHT COLOURS IN THIS PRINT AND WHITE IS A DAY COLOUR. ladder() blends toward EXPOSURE_DAY
|
||||
* while GAMMA goes 0.33 -> 0.62 and crushes the mid out from under them, so an ember cell that
|
||||
* clears comfortably at midnight cannot be made to clear at midday at any luminance this object
|
||||
* writes. That is why the banner's ground is white and its dye is a line — and it is why, at noon,
|
||||
* the dye is quietly demoted to cloth by the rule below and the object is a plain white cotton
|
||||
* banner. That is not a defect being hidden: it is the measurement, and the alternative was tried
|
||||
* and priced. Writing the noon ground bright enough to carry the ember device (0.62 -> 0.70 in
|
||||
* groundLum, or the margin down to 1.10) does put 22-43 ember cells per frame back into the noon
|
||||
* picture, and it costs 0.35 points of muddy and 0.37 points of hot tail averaged over the four
|
||||
* noon fixtures, because every device cell it saves is a cell that would otherwise have printed
|
||||
* white in the hot tail. Anyone who wants the noon colour more than the noon census has one
|
||||
* constant to change and the price of it is written here. */
|
||||
var NOB_TN = [138, 114, 124, 175]; // night, at 14 m: white, ember, gold, sand
|
||||
var NOB_TE = [106, 184, 210, 127]; // dusk
|
||||
var NOB_TD = [97, 210, 229, 114]; // noon
|
||||
|
||||
function minLum(si, d) {
|
||||
var th = NOB_TN[si] * NIGHT + (1 - NIGHT) * (NOB_TE[si] + (NOB_TD[si] - NOB_TE[si]) * DAYF);
|
||||
return th * (d > 14 ? 1 + 0.0095 * (d - 14) : 1) * 1.15;
|
||||
}
|
||||
|
||||
/* ---- THE LIGHT ON THE CLOTH ------------------------------------------------------------------
|
||||
* lampAt REPRODUCED BY HAND, including the 0.86 the first version of this dropped. surf_japan.js
|
||||
* exports no lamp function to call, and a banner lit by a different town than the wall behind it
|
||||
* is the most visible possible error, so the shape is copied exactly: identity below 1.0 m,
|
||||
* smoothstepped to zero at 3.6 m, scaled by 0.86.
|
||||
*
|
||||
* The whole census turns on the expression under it. BOTH daylight terms are ADDITIVE and both are
|
||||
* zero at night — NIGHT is 1 at night, DAYF is 0 at night and at dusk — so the contract's "every
|
||||
* daylight scale is the identity at night" holds by construction rather than by inspection. The
|
||||
* three stops it produces, against the threshold table above:
|
||||
* NIGHT foot 223 (white needs 159 after the margin: clears), 2.03 m 159 (the last row that
|
||||
* clears), head 45 (never written). So a night banner is its lower 45%, and the ember hem
|
||||
* and gold device — which need only 131 and 143 — are the first things on it to print.
|
||||
* Measured 43-130 cells per frame.
|
||||
* DUSK foot 255 (white needs 122 to clear and 199 to be HOT, so a near banner's foot is the
|
||||
* first non-`pure` hot cloth this world has had), 2.05 m 222, head 113, which is just
|
||||
* under and drops the top row or two. Lamp and sky at once make this the object's
|
||||
* brightest hour: measured 118-255 cells per frame, of which 21-96 print hot.
|
||||
* NOON uniform 237 (white needs 112 to clear and 192 to be HOT at 14 m, so the whole banner
|
||||
* lands in the hot tail — the one number EDO is short of, measured at 0.73% against a
|
||||
* 3.5-5% target). ember needs 242 after the margin, so the device demotes to cloth; see
|
||||
* the last paragraph of minLum() for what buying it back would cost.
|
||||
* The 30 floor and the 225 span are chosen so the night foot lands at 223 rather than at 255: a
|
||||
* banner is a lit surface and not a source, and it must not outprint the paper shopfronts this
|
||||
* world's whole lighting model is built on. */
|
||||
function lampAt(vy) {
|
||||
if (vy <= 1.0) return 0.86;
|
||||
if (vy >= 3.6) return 0;
|
||||
var k = (3.6 - vy) / 2.6;
|
||||
return 0.86 * k * k * (3 - 2 * k);
|
||||
}
|
||||
function groundLum(vy) {
|
||||
return 30 + 225 * clamp(lampAt(vy) * LAMP + (1 - NIGHT) * (0.30 + 0.62 * DAYF), 0, 1);
|
||||
}
|
||||
|
||||
/* ==================================================================================== nobori ===
|
||||
* One frontage walk, exactly drawToro's, and then per accepted slot: a pole, a sheet of cloth, and
|
||||
* at most one wet glint.
|
||||
*
|
||||
* THE CLOTH SPANS ACROSS THE ROAD, NOT ALONG IT, and this is the geometry the object lives or dies
|
||||
* by. A nobori is laced to its pole down one edge and hangs from a crossbar at the top, so its
|
||||
* face normal is perpendicular to the pole. A rank of them lines an approach FACING THE PERSON
|
||||
* WALKING UP IT, which means the face points along the street and the cloth's width runs across
|
||||
* it. Hang it the other way and every banner in the rank is seen edge-on by the only camera this
|
||||
* project has, which is a one-column smear.
|
||||
*
|
||||
* THE TWO CORNERS ARE PROJECTED, NOT COMPUTED FROM colK. The obvious implementation takes one
|
||||
* projected point and steps `NOB_W * V.colK / d` columns sideways, and it is wrong in two ways at
|
||||
* once: it assumes the cloth is perpendicular to the view direction (it is not, except dead
|
||||
* ahead), and the screen direction of "outward across the road" flips sign with the side of the
|
||||
* street and again with the camera's yaw. Projecting both bottom corners costs one extra call and
|
||||
* gets the foreshortening, the sign and the width all correct for free. It is the same argument
|
||||
* west_range.js's catenary and jp_town.js's kasagi make for sampling in world space. */
|
||||
function drawNobori(f, axis, idx) {
|
||||
var here = alongOf(axis);
|
||||
/* The walk window is the far cut plus one pitch, not a fixed 40 m: every slot outside 26 m is
|
||||
* rejected by the distance gate below anyway, and walking 90 m of frontage to throw away 65 of
|
||||
* it is the kind of cost that does not show up until four elements are all doing it. */
|
||||
var lo = Math.floor((here - NOB_FAR - NOB_PITCH) / NOB_PITCH);
|
||||
var hi = Math.floor((here + NOB_FAR + NOB_PITCH) / NOB_PITCH);
|
||||
if (hi - lo > 24) hi = lo + 24;
|
||||
|
||||
for (var side = -1; side <= 1; side += 2) {
|
||||
var wall = faceOf(axis, idx, side);
|
||||
var poleC = wall - side * NOB_OUT; // the pole, a metre out from the frontage
|
||||
var clothC = wall - side * (NOB_OUT + NOB_W); // far edge of the cloth, further into the road
|
||||
var lace = wall - side * (NOB_OUT + 0.06); // near edge: 6 cm of daylight past the pole
|
||||
var back = wall + side * 0.8; // one step into the block: the wall itself
|
||||
|
||||
for (var k = lo; k <= hi; k++) {
|
||||
var along = k * NOB_PITCH + hash2(k, side, BASE + 0x61) * 1.2;
|
||||
|
||||
/* THE FRONTAGE GATE IS h > 1.6, NOT the design's 2.6. A banner is planted at the KERB and
|
||||
* does not hang off an eave, so all it needs is a building to stand in front of — and
|
||||
* city.js's `market` row has hMin 3.4 while `garden` has 2.6, so a 2.6 m floor was quietly
|
||||
* refusing the two lowest and busiest frontages in the world. What this really tests is "is
|
||||
* this a built frontage rather than a vacant lot", and 1.6 tests that and nothing else. */
|
||||
if (heightAt(axis, along, back) < 1.6) continue;
|
||||
|
||||
/* THE DISTRICT IS PROBED AT THE WALL, not at the pole. The pole stands a metre into the
|
||||
* carriageway and the carriageway belongs to whichever district's cell happens to reach it;
|
||||
* the frontage behind it is the one that owns the shop the banner belongs to. */
|
||||
var D = CITY.DISTRICTS && CITY.DISTRICTS[CITY.districtAt(wxOf(axis, along, back),
|
||||
wzOf(axis, along, back))];
|
||||
var rate = D ? NOB_R[D.name] : 0;
|
||||
if (!rate) continue;
|
||||
if (hash2(k, side * 3 + (axis ? 7 : 0), BASE + 0x62) > rate) continue;
|
||||
|
||||
/* Nothing standing inside a building. The pole is a metre off the frontage plane, which is
|
||||
* clear of the block on any ordinary street, but a corner lot can put a wall there. */
|
||||
if (heightAt(axis, along, poleC) > 0.5) continue;
|
||||
|
||||
/* ---- the two bottom corners and the top -----------------------------------------------
|
||||
* Order matters: PJ is one shared scratch record, so every value has to be copied out
|
||||
* before the next project() overwrites it. */
|
||||
if (!project(wxOf(axis, along, lace), NOB_BOT, wzOf(axis, along, lace))) continue;
|
||||
var xa = PJ.x, rb = PJ.y, d = PJ.d;
|
||||
if (d < NOB_NEAR || d > NOB_FAR) continue;
|
||||
if (!project(wxOf(axis, along, clothC), NOB_BOT, wzOf(axis, along, clothC))) continue;
|
||||
var xb = PJ.x;
|
||||
if (!project(wxOf(axis, along, lace), NOB_TOP, wzOf(axis, along, lace))) continue;
|
||||
var rt = PJ.y;
|
||||
|
||||
var c0 = Math.floor(xa < xb ? xa : xb), c1 = Math.floor(xa < xb ? xb : xa);
|
||||
var r0 = Math.floor(rt), r1 = Math.floor(rb);
|
||||
if (r1 < r0) { var sw = r0; r0 = r1; r1 = sw; }
|
||||
/* Off the side of the frame entirely, and a defensive bound on the row span: a banner that
|
||||
* projects to more rows than the frame has is one the near cut should already have removed,
|
||||
* and looping over it would be the one path here that is not cheap. */
|
||||
if (c1 < 0 || c0 >= V.cols) continue;
|
||||
var nw = c1 - c0 + 1;
|
||||
if (nw > 8) nw = 8;
|
||||
if (r1 - r0 > V.rows) continue;
|
||||
|
||||
/* ---- the pole ------------------------------------------------------------------------
|
||||
* ONLY THE PART BELOW THE CLOTH, 0 to NOB_BOT + 0.10. That is a metre and a bit of bamboo
|
||||
* standing on the road under the banner, which is what you actually see of it, and it is the
|
||||
* first half of the fix for measured failure 1: the pole and the cloth cannot contend for a
|
||||
* cell they never share. (The second half is the -0.02 depth bias on the cloth below.)
|
||||
*
|
||||
* `sand` AND NOT `timber`, AND IT IS THE PRINT THAT DECIDES. Measured on the live LUT,
|
||||
* timber cannot reach v = 120 at any luminance at night and needs 254 at noon inside 14 m —
|
||||
* so a timber pole is a column of guaranteed muddy cells at every hour, which is exactly
|
||||
* what the census caught the first version of this doing, 17-23 of them per frame, appearing
|
||||
* nowhere in that design's own reasoning. sand is scraped bamboo, it needs 175 at night and
|
||||
* 114 at noon, and the luminance below reaches both.
|
||||
*
|
||||
* The 0.92 is the pole's own shading and it is a measured number as much as a physical one.
|
||||
* A round pole turns away from the light over most of its circumference, so it has to be
|
||||
* written under the flat sheet beside it; but bamboo is smooth and picks up a sheen down its
|
||||
* length, so it must not be written far under. At 0.80 the night pole landed at 179 against
|
||||
* sand's margined 201 and was dropped at every hour after dark, which left the banner
|
||||
* floating; at 0.92 it lands at 206 and prints inside about 14 m and not beyond, so near
|
||||
* banners stand on something and far ones do not. Measured 5-15 sand cells per frame. */
|
||||
var plum = groundLum(0.55) * 0.92;
|
||||
if (plum >= minLum(3, d))
|
||||
column(f, wxOf(axis, along, poleC), wzOf(axis, along, poleC),
|
||||
0, NOB_BOT + 0.10, G_PIPE, P.sand, plum, 0);
|
||||
|
||||
/* ---- the cloth -----------------------------------------------------------------------
|
||||
* THE DEVICE COLUMN IS KEYED ON THE BANNER'S OWN WIDTH. The design this replaces put it at a
|
||||
* fixed centre column and assumed a 7-column banner; at the distances that placement
|
||||
* actually delivered, nw was 1-3, so "the device plus two hem rows is 27% of the object"
|
||||
* came out at 56% and every one of those cells was in a swatch the noon ladder condemns.
|
||||
* Here: no device at all below nw = 3 (there is no room for one that is not the whole
|
||||
* banner) and no edge columns below nw = 4, for the same reason. Over the 9-26 m this
|
||||
* element is drawn at, nw runs 3 to 8. */
|
||||
var dev = NOB_DEV[(hash2(k, side, BASE + 0x63) * 4) | 0];
|
||||
var devI = dev === P.gold ? 2 : 1; // index into the threshold table
|
||||
var cd = nw >= 3 ? (nw >> 1) : -1; // the device column, or none
|
||||
var hemR = (r1 - r0) >= 8 ? 1 : 0; // two hem rows on a tall banner, one on a short
|
||||
var cdq = (k * 7 + side * 3) | 0; // the device's own hash lane
|
||||
var c, r;
|
||||
|
||||
for (r = r0; r <= r1; r++) {
|
||||
/* The cloth's world height for this row, which is what the lamp wash is a function of.
|
||||
* Guarded for the one-row case, where the banner is its own foot. */
|
||||
var vy = r1 > r0 ? NOB_BOT + (NOB_TOP - NOB_BOT) * (r1 - r) / (r1 - r0) : NOB_BOT;
|
||||
var gl = groundLum(vy);
|
||||
var top = r === r0, hem = r >= r1 - hemR;
|
||||
|
||||
for (c = 0; c < nw; c++) {
|
||||
var edge = nw >= 4 && (c === 0 || c === nw - 1);
|
||||
var ch, si, col, lm;
|
||||
|
||||
if (hem || top) {
|
||||
/* The hem and the top lacing band: the dyed edge, all the way across. Two rows out of
|
||||
* eighteen, or one out of eight — a LINE and not a field, which is the only form ember
|
||||
* and gold are licensed in by the table above. */
|
||||
ch = G_DASH; si = devI; col = dev; lm = gl;
|
||||
} else if (c === cd &&
|
||||
/* THE DEVICE IS A BROKEN VERTICAL RUN, AND IT IS KEYED IN WORLD SPACE. A
|
||||
* column of brushed kanji at three columns and ten rows is not a shape, it is
|
||||
* a rhythm of ink and gap — the same argument city.js makes for SIGN_CH_JP
|
||||
* having no diagonals. The hash is taken on the cloth's own HEIGHT quantised
|
||||
* into 17 cm bands, `(vy * 6) | 0`, and NOT on the screen row `r`. That
|
||||
* distinction is the entire photosensitivity story of this element: a dither
|
||||
* keyed on a screen row RE-DEALS every time the camera moves the banner up or
|
||||
* down a cell, which is a broadband per-frame flash exactly like the one that
|
||||
* has tripped this world five times; keyed on world height, a given band of
|
||||
* cloth keeps its ink for as long as it is on screen and the only thing that
|
||||
* changes is which cell it lands in. 0.62 is 62% ink, which over ten rows is
|
||||
* six marks and four gaps — a brush stroke rather than a dotted line. */
|
||||
hash2(cdq, (vy * 6) | 0, BASE + 0x64) < 0.62) {
|
||||
ch = G_8; si = devI; col = dev; lm = gl;
|
||||
} else if (edge) {
|
||||
/* The luff and the fly. A hanging sheet curls at its free edges and turns away from
|
||||
* the light, so they are the same cotton written at 0.86 — which also means they are
|
||||
* the first cells minLum drops as the banner climbs into the dark, and the object
|
||||
* narrows toward the top the way a real one does as it goes out of the lamp. */
|
||||
ch = G_PIPE; si = 0; col = P.white; lm = gl * 0.86;
|
||||
} else {
|
||||
ch = G_EQ; si = 0; col = P.white; lm = gl;
|
||||
}
|
||||
|
||||
/* THE ONE RULE. Under threshold in its own swatch, the cell falls back to cloth — a dye
|
||||
* this print cannot resolve at this hour is still a piece of cotton — and under
|
||||
* threshold as cloth it is not written at all. No dim cells and no occluding black. */
|
||||
if (lm < minLum(si, d)) {
|
||||
if (si === 0) continue;
|
||||
ch = G_EQ; col = P.white; lm = gl;
|
||||
if (lm < minLum(0, d)) continue;
|
||||
}
|
||||
/* -0.02 m of depth bias, and it is the second half of the fix for measured failure 1.
|
||||
* The pole is already drawn below the cloth so the two barely meet, but where they do —
|
||||
* the hem row sitting on the head of the pole — this makes CC.put's strict
|
||||
* `dist < f.dist[i]` a decided question instead of a float32 coin toss that lands
|
||||
* differently every frame. 2 cm is seven hundred times finer than the print's own depth
|
||||
* quantiser (DBUCKETS 8 over 113 m, i.e. 14 m to a bucket), so it changes the fog, the
|
||||
* bucket and the printed value by exactly nothing. */
|
||||
emit(f, c0 + c, r, ch, col, lm, d - 0.02);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- the one wet glint ---------------------------------------------------------------
|
||||
* `pure` is the only swatch in this palette that prints in the hot tail after dark at a
|
||||
* luminance an ordinary object can write — 101 at 14 m for v >= 170, against red's 152 — and
|
||||
* core.js's own note on it is "specular hits only, use sparingly". One cell per near banner
|
||||
* in wet air is as sparing as it is possible to be, and it is the discipline the lantern
|
||||
* core and the gutter glint already keep.
|
||||
*
|
||||
* IT IS WRITTEN AT c0 + nw, ONE COLUMN PAST THE CLOTH, AND THAT IS NOT A DETAIL. The cloth
|
||||
* loop covers c0 .. c0 + nw - 1 at depth d - 0.02, so a glint aimed inside it would be
|
||||
* rejected by CC.put's strict depth test at the same d — which is measurably what happens to
|
||||
* the existing lantern core, and why that one prints five cells in a night frame instead of
|
||||
* one per lantern. Here the target is a cell this object has not touched, and it is written
|
||||
* at d - 0.04 so it also wins against whatever is behind it. Measured 1-2 per frame at night
|
||||
* and at dusk, and each one is hot. The physical reading is a drop running off the fly edge
|
||||
* and catching the lantern the banner is standing under, which is why it is gated on the
|
||||
* lamp being lit and on the air actually being wet. */
|
||||
if (LAMP > 0.4 && W_WET > 0.5 && d < 20 && r1 > r0)
|
||||
emit(f, c0 + nw, r1 - 1, G_TICK, P.pure, 132 * LAMP, d - 0.04);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- registration ---------------------------------------------------------------------------
|
||||
* Layer 18, between jp_town.js's toro (17) and its lanterns (19), which is where a thing standing
|
||||
* a metre into the road belongs in the paint order: in front of the stone lantern against the wall
|
||||
* and behind the chochin hung out over it. Its own layer rather than folded into a neighbour's,
|
||||
* because the layer sort is what decides that order. init consumes no rng, so nothing downstream
|
||||
* of it in the shared stream moves — and because main.js filters on world BEFORE the layer sort, a
|
||||
* `world: 'japan'` element cannot touch any other world's list or stream at all. Verified rather
|
||||
* than asserted: all twenty-seven standing fixtures (cyber/west/moon x night/dusk/noon x seeds
|
||||
* 3/42/7) render byte-identical with this file present and with it absent.
|
||||
*
|
||||
* NOTHING IN THIS ELEMENT MOVES, AND THAT IS THE MOST IMPORTANT LINE IN THE FILE. There is no
|
||||
* update(), no state, no vnoise and no use of t: the banner is a pure function of (map, camera,
|
||||
* hour). The design this replaces carried a 0.12 m sway at 0.35 Hz, argued at length as "the
|
||||
* noren's shape an octave lower, no risk", and tools/west-flicker.cjs measured it at 30.25 big
|
||||
* steps per second against an absolute cap of 8.0, on six of six EDO presets, with the world's
|
||||
* 3-20 Hz band energy going 1.87% -> 4.28%. Deleting the one sway line took it back to 0.50/s and
|
||||
* a PASS. The mechanism was not the one that design analysed: it computed the amplitude as a
|
||||
* printed LUMINANCE change of a couple of percent, but the sway was POSITIONAL and the object's
|
||||
* own blanking rule wrote every sub-threshold cell at lum 0 — so a 1.3-column wobble stepped a
|
||||
* whole column of a 22-row banner between 0 and full scale, twenty-two cells at once. A sub-cell
|
||||
* position wobble on a blanked object is a full-scale luminance flash and not a shape moving, and
|
||||
* the two features that design was proudest of cancelled each other exactly.
|
||||
*
|
||||
* So: no sway, and no occluding black either, which removes both halves of it. CC.reducedMotion
|
||||
* therefore needs no branch here — the element is FROZEN by construction at every setting, which
|
||||
* satisfies the reduced-motion absolutes (band <= 0.5%, rate <= 0.05/s) trivially rather than by a
|
||||
* damping factor that would itself have to be measured; the gate reports japan at 0.00% and
|
||||
* 0.00/s under reduced motion on all six presets with this element in the tree. Any future motion
|
||||
* on this object has to be run through tools/west-flicker.cjs BEFORE it is written down as safe. */
|
||||
function mk(name, layer, fn) {
|
||||
return {
|
||||
name: name, layer: layer, world: 'japan',
|
||||
init: function (city) { boot(city); },
|
||||
draw: function (f, cam, t) {
|
||||
if (!CITY) return;
|
||||
view(f, cam, t === undefined ? (cam.t || 0) : t);
|
||||
fn(f);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CC.ELEMENTS.push(mk('jp-nobori', 18, function (f) {
|
||||
var i;
|
||||
for (i = -1; i <= 1; i++) drawNobori(f, 0, nearIdx(0) + i);
|
||||
for (i = -1; i <= 1; i++) drawNobori(f, 1, nearIdx(1) + i);
|
||||
}));
|
||||
|
||||
})(typeof CC !== 'undefined' ? CC : require('../core.js'));
|
||||
610
src/elements/jp_castle.js
Normal file
610
src/elements/jp_castle.js
Normal file
|
|
@ -0,0 +1,610 @@
|
|||
/* CyberCity EDO — THE CASTLE KEEP. One element, layer 15.
|
||||
*
|
||||
* WHAT THIS IS. A tenshu: the multi-tiered thing at the end of a street that tells you which town
|
||||
* you are in. src/city.js already builds the MASS — DIST_JAPAN's `castle` row carries
|
||||
* `landmark: 0.030`, the highest rate in the quarter, and TH_JAPAN's lmMin/lmVar turn that roll
|
||||
* into a 13-25 m lot against a 5.4-8.6 m machiya street. What the map cannot build is what makes
|
||||
* that slab a castle rather than a chimney: the STACK OF ROOFS. Each storey of a keep is capped by
|
||||
* a tiled eave that oversails the wall below it, each one narrower than the last, with the corners
|
||||
* turned up and a pair of gilt shachihoko on the top ridge. That is geometry standing OFF the wall
|
||||
* plane, which is exactly the class of object src/surf_japan.js cannot paint — it is handed (u, v)
|
||||
* on a face and has no camera, no depth and no world — and exactly what an element file is for.
|
||||
*
|
||||
* SO THIS FILE FINDS THE MAP'S OWN KEEP AND PUTS THE ROOFS ON IT. It builds nothing of its own and
|
||||
* it invents no site: it walks a world-aligned lattice, asks src/city.js for the record under each
|
||||
* sample, and accepts the lot only when the district is `castle` and the lot's interior height
|
||||
* clears 12.5 m — which, given the castle row's hMax of 12.0, is an EXACT detector for a landmark
|
||||
* roll rather than a threshold somebody guessed. src/elements/structure.js's rooftop plant and
|
||||
* masts locate the city's towers the same way and its comment says why: a lattice probe against
|
||||
* CITY.height is the only handle an element has on what the map decided.
|
||||
*
|
||||
* ============================================================================================
|
||||
* THE THREE THINGS THAT DECIDE EVERY NUMBER BELOW, all three measured rather than assumed.
|
||||
* ============================================================================================
|
||||
*
|
||||
* 1. A KEEP IS ONLY EVER FRAMED AT 40-110 m, so its detail has to be sized for that and nothing
|
||||
* else. src/raycast.js and src/proj.js share scale = cols*cellAspect/(2*tan(fov/2)) = 77.4 at
|
||||
* 200 columns, and horizon = 0.56*rows. One screen ROW therefore spans d/77.4 metres of a far
|
||||
* wall: 0.52 m at 40 m, 0.78 at 60, 1.16 at 90. Anything under a metre tall on this object is
|
||||
* sub-row and draws nothing. That is why the tier spacing here is 4.3-4.9 m on a tall keep
|
||||
* (five to six rows apart at the design range) and why every one-row detail — the soffit band,
|
||||
* the upturned corner, the gable apex — is offset in SCREEN rows rather than in metres. A
|
||||
* 0.4 m soffit and a 0.55 m corner lift are the real dimensions and both are invisible out
|
||||
* here at the sizes they really have; the row below and
|
||||
* the row above are what those dimensions MEAN at the distance this object lives at.
|
||||
* The other half of the same arithmetic: the top of an H-metre keep sits at row
|
||||
* horizon - (H-1.7)*77.4/d, so a 25 m keep has six rows of sky over it only past 65 m and its
|
||||
* ridge is off the top of the frame inside 54 — MEASURED on the seed-7 keep at 59 m, where the
|
||||
* top eave projected to row -1 and only its soffit, one row below, was on the frame at all.
|
||||
* This file does not fight that — it gates each tier separately (see 3),
|
||||
* so the tiers that are off-screen simply are not drawn.
|
||||
*
|
||||
* 2. AT NIGHT, NOTHING ON A KEEP IS LIT, AND THAT IS BY CONSTRUCTION RATHER THAN BY OVERSIGHT.
|
||||
* surf_japan.js's lampAt() is identically zero above 3.6 m — it is an envelope for lanterns
|
||||
* hung at 2.1 m and it has to be — and sunOf() collapses to its dome term, 0.083, once the sun
|
||||
* is down. So there is no light source in this world that reaches 20 m up. Measured through
|
||||
* core.js's LUT with EDO's fog (14/150/1.15) applied first, a painter writing the maximum
|
||||
* lum 255 at 60 m at night prints: white 84, sand 77, timber 68, stone 74, indigo 75, gold 89,
|
||||
* warm 95, jade 98, and PURE 159 — pure being the one swatch whose max channel is 255, so its
|
||||
* printed value IS its fogged luminance. Against a muddy ceiling of 119 and a hot line of 170,
|
||||
* exactly one swatch in the palette can be seen at all at that range after dark, and it can only
|
||||
* be HOT inside about 55 m. (The two numbers checked against the live renderer rather than
|
||||
* against the table: this element's brightest cell measures 152 at 65 m and 194 at 45 m.)
|
||||
* THE DECISION, taken explicitly because a previous pass at this object shipped 2,500 bytes of
|
||||
* eave that never printed a cell above v=119: the TIERS ARE A DAYLIGHT READ AND A SILHOUETTE AT
|
||||
* NIGHT, and the night read is bought with a handful of `pure` on the top ridge and the two
|
||||
* shachihoko — five to twelve cells, which is the whole of what this world's own palette note
|
||||
* means by "specular hits only, use sparingly". src/elements/jp_town.js spends its one `pure`
|
||||
* cell per near lantern on the same argument. EDO's night hot tail censuses 0.21% against a
|
||||
* 3.5-5% target, so those cells are also the only contribution this object can make to a number
|
||||
* that is an order of magnitude short.
|
||||
* The eave lines themselves are NOT bright and are not trying to be. An eave seen from 65 m at
|
||||
* an elevation of 17 degrees is its own UNDERSIDE: the honest mark is a dark line with a band of
|
||||
* black beneath it, drawn across a pale plaster wall. That reads by day, which is when a keep is
|
||||
* a keep, and src/elements/west_range.js's telegraph pole makes the identical argument for the
|
||||
* identical reason — some objects read by getting DARKER than what is behind them.
|
||||
*
|
||||
* 3. THIS ELEMENT HAS NO TIME TERM AT ALL, AND ITS PHOTOSENSITIVITY GATE IS THEREFORE A GATE ON
|
||||
* THE CAMERA. Nothing here reads `t`. Every cell is a pure function of (map, camera), so the
|
||||
* object cannot flash: what changes is the ROW an eave lands on, as the walk closes the
|
||||
* distance. That rate is the thing this world has failed on five times, and every one of those
|
||||
* failures was invisible in a still and invisible in the census because the defect was purely in
|
||||
* the rate. The arithmetic here is exact rather than sampled:
|
||||
* row = horizon - (y - eyeY)*scale/d => |drow/dt| = (y - eyeY)*scale*v / d^2
|
||||
* with v = CITY.SPEED = 1.6 m/s. For a 24.5 m ridge that is 3.1 Hz at 30 m, 2.3 Hz at 35 m,
|
||||
* 1.8 Hz at 40 m and 0.78 Hz at 60 m — i.e. a near keep toggles a cell squarely inside the
|
||||
* 3-20 Hz band, and no amount of dimming or thinning touches it. THE LEVER IS DISTANCE. So each
|
||||
* tier is cut at its OWN minimum distance, dMin = sqrt((y - eyeY)*scale*v/KEEP_HZ), which is the
|
||||
* inverse of that expression solved for 2 Hz: 38 m for a 24.5 m ridge, 23 m for a 10 m one.
|
||||
* A tall tier is cut further out than a low one,
|
||||
* which is also exactly where a tall tier leaves the top of the frame, so the gate and the
|
||||
* framing agree instead of fighting.
|
||||
* THE HORIZONTAL DIRECTION IS FREE AND IT IS WORTH SAYING WHY, because it looks like the bigger
|
||||
* number: the camera's sway and yaw wobble move a run of eave at up to five columns a second,
|
||||
* which sounds alarming until you notice that a HORIZONTAL RUN SLIDING HORIZONTALLY DOES NOT
|
||||
* TOGGLE ITS OWN INTERIOR CELLS — a cell that was on the line is still on the line. Only the two
|
||||
* ends move on and off, and the wobble that moves them is 0.10 Hz (control.js's sin(s*0.41)
|
||||
* term) and 0.02 Hz (its vnoise sway). The one motion that can put a whole run of cells on and
|
||||
* off together is the vertical one, and that is what dMin gates.
|
||||
* REDUCED MOTION: nothing is damped and nothing is frozen, because there is nothing here that
|
||||
* moves. Said out loud rather than left implicit, since the house rule asks for one of the two:
|
||||
* the correct answer for a static world-space object is neither, and CC.reducedMotion also
|
||||
* damps the walk itself (control.js scales the gait by 0.15), which can only lower every rate
|
||||
* above. This element is strictly safer under it than without it.
|
||||
*
|
||||
* ============================================================================================
|
||||
* WHAT IT ACTUALLY MEASURES, so the next reader does not have to take any of the above on trust.
|
||||
* Sampled every 300 frames over the first 30,000 of the walk, ten seeds (42, 3, 7, 1, 5, 11, 1234,
|
||||
* 99, 2, 17), 200x60, through the real element list with the real weather:
|
||||
* COVERAGE 121 of 1,010 sampled frames draw at least one cell — 12.0% of the walk. Nine of the
|
||||
* ten seeds draw it; seed 1 never does, because its four castle landmarks are all
|
||||
* 90-110 m out and behind a frontage every time the walk faces one. That is the rate
|
||||
* `landmark: 0.030` on an 11%-weighted district buys, and it is the right rarity: a
|
||||
* keep the walk meets every minute is not a landmark.
|
||||
* SIZE 62.7 cells a frame averaged over the frames that draw it, 7.5 averaged over every
|
||||
* sampled frame, peak 228 (seed 7 f11400) — i.e. under 2% of a 12,000-cell frame at
|
||||
* its largest, which is the 7-9% target read honestly rather than overshot.
|
||||
* PRINT At noon 4,069 of those 7,585 cells print v >= 9, 121 print hot, max printed 208.
|
||||
* At night 594 of 7,587 print v >= 9, 16 print hot, max 194 — and essentially every
|
||||
* one of the night survivors is the `pure` ridge or a shachihoko. That asymmetry IS
|
||||
* the design; see 2 above.
|
||||
* CENSUS Neutral, which is what a landmark that neither lights nor blacks out the frame
|
||||
* should be. seed 7 f10500 at noon: muddy 38.88 -> 39.18, hot 2.283 -> 2.283, black
|
||||
* 48.89 -> 48.82. At night: muddy 36.62 -> 36.33, black 56.11 -> 56.37. The largest
|
||||
* move on any measured fixture is 0.30 points of muddy.
|
||||
* RATE tools/west-flicker.cjs cannot see this object AT ALL and saying so is part of the
|
||||
* measurement: it renders the world pass with the CAMERA PINNED, and a mass with no
|
||||
* time term cannot change under a pinned camera. So the same comparison was run in
|
||||
* that tool's own form with the camera WALKING — 1,200 consecutive frames, the world
|
||||
* pass rendered twice, once alone and once with this element, per-cell printed-value
|
||||
* time series, seven Goertzel probes at 3.5/5/7/9/12/15/19 Hz:
|
||||
* seed 7 f10200-11400 noon : worst per-cell INCREASE in 3-20 Hz power 0.45% of full
|
||||
* scale, worst increase in big-step rate 0.20/s. Frame worst-cell figures
|
||||
* unchanged (3.20/s, 4.39%) with and without.
|
||||
* seed 7 f10200-11400 night: +0.53% band, +0.20/s.
|
||||
* seed 7 f11400-12600 night (the near approach, where the tier cuts fire): +0.16%
|
||||
* band, and NO cell anywhere gained a single big step.
|
||||
* seed 17 f24900-26100 night: +0.56% band, +0.30/s.
|
||||
* seed 2 f10200-11400 noon : +0.59% band, +0.25/s.
|
||||
* Against the project's gates of 2% in band and 1.0 big steps a second, the worst of
|
||||
* those is 30% of the band limit and 30% of the rate limit, and the object never moves
|
||||
* the frame's own worst cell. The walking camera by itself measures 3.2-8.5 big steps
|
||||
* a second and 4.4-5.5% in band on this world, which is the honest context: this
|
||||
* element is far below the noise floor of the camera it is seen from.
|
||||
*
|
||||
* WHAT IT DOES NOT DO. It does not touch the heightmap, it does not add a terrace, and it does not
|
||||
* flatten a bailey. A separate proposal exists for a block-scale stepped mass in src/city.js with
|
||||
* an enclosure wall round it; it is not this file's to make, it is a district-scale change rather
|
||||
* than a building, and it was measured moving 18-52% of a walk frame. What is here stands on the
|
||||
* lot the map already put up, and if that proposal ever lands this file keeps working — it reads
|
||||
* a height and a district name and nothing else.
|
||||
*/
|
||||
(function (CC) {
|
||||
'use strict';
|
||||
|
||||
/* One projector per element — see src/proj.js for why there is exactly one copy of the camera
|
||||
* basis in the tree. V and PJ are this element's own basis and scratch. */
|
||||
var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ;
|
||||
var project = PR.project, emit = PR.emit, litFace = PR.litFace;
|
||||
|
||||
var P = CC.P;
|
||||
|
||||
/* G_TICK is the one mark in GLYPHS that reads as the end of a horizontal run turning UP, which
|
||||
* is the whole recognition of a Japanese eave; G_CARET is what west_town.js:514 uses for a
|
||||
* steeple apex and does the same job on a chidori-hafu gable; G_o is the shachihoko. There is no
|
||||
* diagonal anywhere in this object on purpose — city.js's own note on SIGN_CH_JP is right that a
|
||||
* diagonal reads wrong in this world, and a roof slope at a 9x16 cell is a staircase of
|
||||
* horizontals in any case. */
|
||||
var G_EQ = CC.g('='), G_UNDER = CC.g('_'), G_TICK = CC.g('`'),
|
||||
G_CARET = CC.g('^'), G_QUOTE = CC.g("'"), G_o = CC.g('o');
|
||||
|
||||
/* Bound once per rebuild, off `city.world` and never off CC.World: between a keypress and the
|
||||
* rebuild those are two different answers, and this file has to agree with the map it is
|
||||
* measuring heights in. */
|
||||
var CITY = null, JP = null;
|
||||
function boot(city) {
|
||||
CITY = (city && city.aveX && city.world === 'japan') ? city : null;
|
||||
JP = null;
|
||||
}
|
||||
|
||||
/* Per-frame caches. EVERY ONE OF THESE IS ASSIGNED INSIDE view(). The contract names this after
|
||||
* two frontier files kept a cache with one field left on its declared default and quietly
|
||||
* stopped following the clock while the street behind them still did; nothing reported it. */
|
||||
var NIGHT = 1, DAYF = 0, WALK = 1.6;
|
||||
function view(f, cam, t) {
|
||||
PR.view(f, cam, t);
|
||||
if (!JP) JP = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null;
|
||||
/* `night` is surf_japan's own crossfade rather than the director's hard P.night flag, for the
|
||||
* reason that file states: a hard flag snaps while the painter is still halfway through its
|
||||
* handover, and this object is a large area. */
|
||||
NIGHT = (JP && JP.night !== undefined) ? JP.night : 1;
|
||||
DAYF = (JP && JP.dayFill !== undefined) ? JP.dayFill : 0;
|
||||
/* The walk speed comes off the MAP, not off a literal: city.js exports SPEED and the whole
|
||||
* photosensitivity gate below is solved for it. A copied 1.6 here would silently stop being
|
||||
* the gate the moment that constant moved. */
|
||||
WALK = (CITY && CITY.SPEED) ? CITY.SPEED : 1.6;
|
||||
}
|
||||
|
||||
/* ============================================================================== the search ===
|
||||
* A world-aligned lattice, 4 m across and 8 m along, out to just inside src/proj.js's own far
|
||||
* plane. Both steps are chosen against city.js's EDO lot size rather than for tidiness: TH_JAPAN
|
||||
* gives lotW 4 + 0..3 and lotD 9 + 0..8, so a lot is 4-6 cells wide by 9-16 deep, and a step of 4
|
||||
* in x and 8 in z therefore cannot step OVER one. That is the whole placement rule — a keep is
|
||||
* wherever the map put a castle landmark, and this lattice is guaranteed to find every one of
|
||||
* them within range.
|
||||
*
|
||||
* ALIGNED TO THE WORLD, NOT TO THE CAMERA, which is the bug that would otherwise be here. A
|
||||
* lattice keyed on floor((ox - R)/4) re-deals its sample set every time the camera moves a metre,
|
||||
* so a lot found on one frame is missed on the next and a 200-cell object strobes at walking
|
||||
* pace — the exact defect class this world's blossom note is written about. Snapping the bounds
|
||||
* to multiples of the step makes the sample set a property of the MAP.
|
||||
*
|
||||
* DEDUPE IS BY LOT ANCHOR AND IS EXACT. Several lattice points can land in one lot, and each
|
||||
* would build a second keep on top of the first. west_town.js's drawCrowns solves the same
|
||||
* problem with an `abs(cx - gx) > 4` proximity test, which is approximate; here the record hands
|
||||
* back lotX/lotZ, so the answer is just "have I already BUILT on this anchor" against a fixed
|
||||
* three-slot list.
|
||||
*
|
||||
* THE LIST HOLDS BUILT KEEPS AND NOTHING ELSE, and that distinction is the one bug this scan has
|
||||
* already had. The first cut recorded every castle lot it looked at — ordinary 7-12 m ishigaki
|
||||
* included — and used the same counter as the work cap, so the loop returned after the third
|
||||
* castle lot of any kind. In a castle quarter that is three ordinary walls, and MEASURED across
|
||||
* ten named (seed, frame) fixtures ONE drew the keep — seed 7, where a landmark happened to fall
|
||||
* in the first three castle lots the scan met — and NINE DREW ZERO CELLS. Rejecting a lot has to
|
||||
* cost nothing but the one interior height probe that rejects it.
|
||||
*
|
||||
* Three slots because that is the WORK cap and not a dedupe limit: a forward cone rarely holds
|
||||
* more than one keep, two is a corner of the castle quarter, and a fourth would be out past
|
||||
* 110 m where the fog has it anyway.
|
||||
* ============================================================================================ */
|
||||
var KEEP_R = 124; // just inside V.far (Surf.FOG_END, 125): the far cut is then
|
||||
// project()'s own, shared with every other element, rather than
|
||||
// a second edge of this file's invention.
|
||||
var STEP_X = 4, STEP_Z = 8;
|
||||
var MAX_KEEPS = 3;
|
||||
/* 12.5 m. NOT a taste threshold: DIST_JAPAN's castle row is hMin 7.0 / hMax 12.0, and the only
|
||||
* other branch that can raise a castle lot is `hash(lx,lz,S+502) < D.landmark`, which sets
|
||||
* h = TH_JAPAN.lmMin + rand*lmVar = 13-25 m. EDO declares no swellAmp so nothing adds relief on
|
||||
* top. A castle lot over 12.5 m is therefore a landmark roll and nothing else — an exact
|
||||
* detector, and it will stay exact as long as those two bands do not overlap. */
|
||||
var KEEP_MIN_H = 12.5;
|
||||
/* Allocated at load rather than in init(): the length is a literal and there is nothing
|
||||
* per-city about it, so there is no second allocation to avoid. */
|
||||
var builtX = new Int32Array(MAX_KEEPS), builtZ = new Int32Array(MAX_KEEPS), builtN = 0;
|
||||
|
||||
/* ============================================================================== the tiers ===
|
||||
* TIER_SPAN 0.58 — the roofs occupy the top 58% of the mass and the bottom 42% is the ishigaki
|
||||
* and the first storey, which is where a real tenshu's stonework stops. On a 24.5 m keep that
|
||||
* puts the lowest eave at 10.3 m and the top one at 24.5, four eaves 4.7 m apart: six rows apart
|
||||
* at 60 m and nine at 40, which is the whole reason the object reads as stacked rather than as
|
||||
* one striped slab. It is a FRACTION of the height rather than a fixed step for exactly that
|
||||
* reason: a fixed 3.9 m would put two eaves on a 13 m keep 1.5 rows apart at 90 m, which is one
|
||||
* thick line and not a tier.
|
||||
* FLY0 / FLY_D — how far each eave oversails the wall below it, 1.10 m at the top growing by
|
||||
* 0.78 m a storey downward. This is the ONLY thing that makes the silhouette a pyramid, because
|
||||
* the mass under it is a single-width slab all the way up: the eaves are what step outward. On a
|
||||
* 3 m core the base tier finishes 9.9 m across, which is a tenshu footprint (Himeji is about 20),
|
||||
* and at 60 m it stands about eight columns proud of the wall on each side. It is also what puts
|
||||
* the eave IN FRONT of its own wall in depth, which is what lets it print at all — see runEave.
|
||||
* NTIER — four storeys over 19 m, three over 15, two under. Not a look: with TIER_SPAN fixed, a
|
||||
* fourth eave on a 14 m keep lands 2.7 m from its neighbour, which is under two rows at 80 m.
|
||||
* ============================================================================================ */
|
||||
var TIER_SPAN = 0.58, FLY0 = 1.10, FLY_D = 0.78;
|
||||
|
||||
/* ===================================================================== the rate gate, again ===
|
||||
* KEEP_HZ 2.0 is the target ceiling for how fast the walk may drag a tier across a row boundary,
|
||||
* and 2.0 rather than 3.0 because 3.0 is the EDGE of the flash band and this object is 200 cells
|
||||
* wide — the gate wants headroom on the shoulder, exactly as jp_town.js's blossom takes its cut
|
||||
* at 2.1 Hz rather than at 3.0. Solved for distance: dMin = sqrt((y - eyeY)*scale*WALK/KEEP_HZ),
|
||||
* which is 38 m for a 24.5 m ridge and 23 m for a 10 m one.
|
||||
* RIDGE_HZ 1.6 is the same gate, stricter, for the `pure` cells alone. They are the only cells in
|
||||
* this object with real amplitude — pure prints exactly what its luminance says, because its max
|
||||
* channel IS 255, so a ridge cell is a 60%-of-full-scale step against a night sky — and amplitude
|
||||
* is the other axis of the rule. 1.6 Hz is half the low edge of the band and well clear of the
|
||||
* 3.5 Hz probe whose shoulder jp_town.js's blossom note had to move away from; it puts a 25 m
|
||||
* keep's ridge cut at 44 m and full brightness at 53.
|
||||
* THE WINDOW IS NARROW AND IT IS WORTH STATING EXACTLY. `pure` written at 255 prints 255*T where
|
||||
* T is EDO's fog transmittance (14/150/1.15): 190 at 44 m, 173 at 53, 150 at 65, 120 at 79, and
|
||||
* 105 at 88. So the top ridge clears the muddy ceiling of 119 only inside 79 m and can be HOT
|
||||
* (v >= 170) only inside about 55. Between the 53 m the rate gate allows and the 79 m the fog
|
||||
* allows there is a 26 m window — about sixteen seconds of walk — in which this object has cells
|
||||
* a night frame can see. That is the whole of what a keep can be after dark here, and it is
|
||||
* the reason RIDGE_FAR is 82 rather than the 110 the geometry would allow: past it a `pure`
|
||||
* cell is under the muddy ceiling and is a specular spent on nothing.
|
||||
* FADE_M 9 m is the luminance ramp above each cut, the same shape as the blossom's 11->16 m
|
||||
* fade-in, so a tier arrives over about six seconds of walk rather than on one frame. It fades
|
||||
* the LUMINANCE; the black soffit band under each eave is an occluder and cannot be faded (a
|
||||
* cell written at lum 0 still claims the cell), so the honest statement is that each tier's
|
||||
* arrival is a step of 30-60 black cells — 0.25-0.5% of a 200x60 frame — and that the
|
||||
* per-tier gating is what stops all four arriving on the same frame. They arrive at four
|
||||
* distances 6-14 m apart, i.e. four separate steps several seconds apart.
|
||||
* ============================================================================================ */
|
||||
var KEEP_HZ = 2.0, RIDGE_HZ = 1.6, RIDGE_FAR = 82, FADE_M = 9;
|
||||
/* 2.6 m of crown roof above the top eave. Set by the row size at the FAR end of the range, not
|
||||
* by the near: one row is 1.29 m at 100 m, so anything under 2.6 m puts the ridge on the same
|
||||
* screen row as the eave it is supposed to sit above — and the eave, being a metre and a half
|
||||
* further out, is NEARER, so CC.put keeps the eave and drops the ridge. The first cut used
|
||||
* 1.55 m, which is under two rows at 65 m and one row at 100, and it was raised together with the
|
||||
* ridge-axis correction below when a 65 m fixture came back with zero `pure` cells. It is also
|
||||
* the honest dimension: a tenshu's top roof stands about three metres over its top wall plate. */
|
||||
var RIDGE_H = 2.6;
|
||||
|
||||
/* ================================================================================ one eave ===
|
||||
* A horizontal run in world space, plus the two marks that make it Japanese.
|
||||
*
|
||||
* SAMPLED IN WORLD SPACE AND SIZED IN SCREEN SPACE. The ends are projected first, purely to
|
||||
* count how many samples the run needs: a 15 m eave seen at a glancing 16 degrees covers nine
|
||||
* columns, and sizing the loop off the world length would emit it thirty-three times into the
|
||||
* same nine cells. Every sample then carries its OWN depth, which is what makes the run occlude
|
||||
* correctly where it crosses in front of its own building and lose correctly where a nearer
|
||||
* frontage is in the way.
|
||||
*
|
||||
* THE SOFFIT IS DRAWN ONE SCREEN ROW BELOW, NOT 0.4 m BELOW. A real eave has about forty
|
||||
* centimetres of shadowed underside; at 60 m that is half a row and it lands on the same cell as
|
||||
* the eave itself, where CC.put's strictly-less depth test throws it away. The row below is what
|
||||
* 0.4 m MEANS at the distance this object is framed at. It is written at lum 0 in P.shadow, the
|
||||
* same true-black cap jp_town.js puts on its lanterns: it prints as nothing and it OCCLUDES,
|
||||
* which for a projecting eave is the correct and the entire contribution.
|
||||
*
|
||||
* THE UPTURNED CORNER is one G_TICK one row ABOVE each end, for the same reason — the real lift
|
||||
* is 0.55 m and is sub-row out here. It is emitted at d - 0.01 because it may land on a cell the
|
||||
* eave of the tier above already wrote at the same depth, and CC.put rejects an equal-depth
|
||||
* write; jp_town.js's chochin core draws five cells a frame for exactly that reason. */
|
||||
function runEave(f, ax, az, bx, bz, y, col, lum, soffit, tick) {
|
||||
var n, i, u, px, pz, x, yy;
|
||||
/* Both ends, only to size the loop. If either is behind the eye plane or past the far plane
|
||||
* the run is still drawn — it is sized off its world length instead and the samples that fall
|
||||
* outside are dropped one at a time by project(). */
|
||||
var okA = project(ax, y, az), sx = PJ.x, sy = PJ.y, sd = PJ.d;
|
||||
var okB = project(bx, y, bz), ex = PJ.x, ey = PJ.y, ed = PJ.d;
|
||||
if (okA && okB) {
|
||||
n = ex > sx ? ex - sx : sx - ex;
|
||||
var m = ey > sy ? ey - sy : sy - ey;
|
||||
if (m > n) n = m;
|
||||
/* AND THEN MULTIPLIED BY THE DEPTH RATIO, which is not a fudge factor. The loop steps
|
||||
* uniformly in WORLD space and the projection is not uniform: on a 15 m eave running away
|
||||
* from the camera from 58 m to 72 m, equal world steps land 24% further apart on screen at
|
||||
* the near end than at the far one, so a count sized off the screen extent alone leaves
|
||||
* single-column holes down the near half of every run, which is what the first render showed
|
||||
* on the oblique sides. Scaling by far/near oversamples the far end, where the duplicate
|
||||
* write is simply rejected by CC.put's own depth test and costs one comparison. MEASURED over
|
||||
* eight seeds x 101 sampled frames at noon it is worth +85 cells across the 114 frames that
|
||||
* draw anything, i.e. about 1% — small, because the broad face of a keep is usually close to
|
||||
* perpendicular and its depth ratio is close to 1, and it is the oblique side, the one
|
||||
* running away from the eye, that this repairs. Single-cell gaps remain where two facing
|
||||
* sides meet at a corner and the two runs round to different columns. */
|
||||
n = Math.ceil(n * (ed > sd ? ed / sd : sd / ed));
|
||||
} else {
|
||||
var dx = bx - ax, dz = bz - az;
|
||||
n = Math.ceil(Math.sqrt(dx * dx + dz * dz) * 2);
|
||||
}
|
||||
if (n < 1) n = 1;
|
||||
if (n > 96) n = 96; // a 96-cell eave is already half the width of the frame
|
||||
|
||||
for (i = 0; i <= n; i++) {
|
||||
u = i / n;
|
||||
px = ax + (bx - ax) * u; pz = az + (bz - az) * u;
|
||||
if (!project(px, y, pz)) continue;
|
||||
x = Math.floor(PJ.x); yy = Math.floor(PJ.y);
|
||||
emit(f, x, yy, G_EQ, col, lum, PJ.d);
|
||||
if (soffit) emit(f, x, yy + 1, G_UNDER, P.shadow, 0, PJ.d);
|
||||
if (tick && (i === 0 || i === n))
|
||||
emit(f, x, yy - 1, G_TICK, col, lum * 1.25, PJ.d - 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================================= one keep ===
|
||||
* Everything below is a pure function of the lot and the camera. Returns 1 if it built anything,
|
||||
* so the caller can cap the work.
|
||||
* ============================================================================================ */
|
||||
function drawKeep(f, rec) {
|
||||
var lx = rec.lotX, lz = rec.lotZ;
|
||||
|
||||
/* THE INTERIOR PROBE, and the offset is not arbitrary. A landmark lot with TH_JAPAN's podium
|
||||
* setback has its outer ring dropped to 3.2-5.4 m, so a cell on the lot boundary reports the
|
||||
* PLINTH height and not the keep's. lotW is at least 4 and lotD at least 9, so (lx+2, lz+4) is
|
||||
* inside the ring on every lot this world can produce, which makes it the one probe that is
|
||||
* always the real height. */
|
||||
var H = CITY.height(lx + 2, lz + 4);
|
||||
if (H < KEEP_MIN_H) return 0;
|
||||
|
||||
/* THE CORE FOOTPRINT, grown outward from that probe while the height holds. This is what the
|
||||
* roofs are hung on, and it has to be the CORE rather than the lot: the plinth ring is a metre
|
||||
* of 4 m stonework round the outside and an eave measured from the lot boundary would oversail
|
||||
* from a metre too far out on every side. The walk is bounded by the largest lot EDO can make
|
||||
* (6 x 16) so it cannot run away, and it costs at most 26 height lookups on a cached chunk. */
|
||||
var floorH = H - 0.6, x0 = lx + 2, x1 = lx + 2, z0 = lz + 4, z1 = lz + 4, xm;
|
||||
while (x0 > lx && CITY.height(x0 - 1, lz + 4) > floorH) x0--;
|
||||
while (x1 < lx + 5 && CITY.height(x1 + 1, lz + 4) > floorH) x1++;
|
||||
xm = (x0 + x1) >> 1;
|
||||
while (z0 > lz && CITY.height(xm, z0 - 1) > floorH) z0--;
|
||||
while (z1 < lz + 15 && CITY.height(xm, z1 + 1) > floorH) z1++;
|
||||
/* A cell `g` covers world [g, g+1), which is the same half-open convention jp_town.js's faceOf
|
||||
* is written against — an object placed on the wrong side of that plane is inside the building
|
||||
* and CC.put deletes it silently. */
|
||||
var wx0 = x0, wx1 = x1 + 1, wz0 = z0, wz1 = z1 + 1;
|
||||
|
||||
var kx = (wx0 + wx1) * 0.5, kz = (wz0 + wz1) * 0.5;
|
||||
var rx = kx - V.ox, rz = kz - V.oz;
|
||||
var d = Math.sqrt(rx * rx + rz * rz);
|
||||
if (d > KEEP_R) return 0;
|
||||
|
||||
/* Per-lot variation, from the record's own hash rather than from an rng: this file draws no
|
||||
* random numbers at all and the harness at frame 9000 has to get the browser's frame 9000. */
|
||||
var sd = rec.seed;
|
||||
var nt = H >= 19 ? 4 : (H >= 15 ? 3 : 2);
|
||||
var step = H * TIER_SPAN / (nt - 1);
|
||||
var fly0 = FLY0 + sd * 0.30;
|
||||
|
||||
/* The two lit faces, off src/proj.js's litFace, which resolves SUN_X/SUN_Z from whichever
|
||||
* painter owns the live world rather than from CC.Daylight — surf_moon.js's argument, and it
|
||||
* is the reason the roofs and the wall under them agree about where the light is. */
|
||||
var sunPX = litFace(1, 0), sunNX = litFace(-1, 0);
|
||||
var sunPZ = litFace(0, 1), sunNZ = litFace(0, -1);
|
||||
|
||||
var built = 0, i, s;
|
||||
for (i = 0; i < nt; i++) {
|
||||
var y = H - i * step;
|
||||
var fly = fly0 + i * FLY_D;
|
||||
|
||||
/* THE GATE, per tier, solved from |drow/dt| = (y - eyeY)*scale*WALK/d^2. See the header. */
|
||||
var dMin = Math.sqrt((y - V.eyeY) * V.scale * WALK / KEEP_HZ);
|
||||
if (d < dMin) continue;
|
||||
var fade = d < dMin + FADE_M ? (d - dMin) / FADE_M : 1;
|
||||
fade = fade * fade * (3 - 2 * fade); // smoothstep, so the ramp has no corner in it
|
||||
|
||||
var ex0 = wx0 - fly, ex1 = wx1 + fly, ez0 = wz0 - fly, ez1 = wz1 + fly;
|
||||
|
||||
/* Which side is the BROAD one — the face most square to the view. The gable goes on that one
|
||||
* and nowhere else: a chidori-hafu on a face seen at fifteen degrees is two cells of
|
||||
* noise. */
|
||||
var fx = V.fwx < 0 ? -V.fwx : V.fwx, fz = V.fwz < 0 ? -V.fwz : V.fwz;
|
||||
var broadIsX = fx > fz;
|
||||
|
||||
for (s = 0; s < 4; s++) {
|
||||
/* 0:+x 1:-x 2:+z 3:-z. A side is drawn only when its outward normal faces the camera. The
|
||||
* far two are hidden behind the roof in front of them — we are looking UP at this object
|
||||
* from 17 degrees below its eaves — and drawing them would scatter marks in the sky above
|
||||
* every tier, which is what the first cut did. */
|
||||
var ax, az, bx, bz, sun, isBroad;
|
||||
if (s === 0) {
|
||||
if (V.ox <= ex1) continue;
|
||||
ax = ex1; az = ez0; bx = ex1; bz = ez1; sun = sunPX; isBroad = broadIsX;
|
||||
} else if (s === 1) {
|
||||
if (V.ox >= ex0) continue;
|
||||
ax = ex0; az = ez0; bx = ex0; bz = ez1; sun = sunNX; isBroad = broadIsX;
|
||||
} else if (s === 2) {
|
||||
if (V.oz <= ez1) continue;
|
||||
ax = ex0; az = ez1; bx = ex1; bz = ez1; sun = sunPZ; isBroad = !broadIsX;
|
||||
} else {
|
||||
if (V.oz >= ez0) continue;
|
||||
ax = ex0; az = ez0; bx = ex1; bz = ez0; sun = sunNZ; isBroad = !broadIsX;
|
||||
}
|
||||
|
||||
/* ONE SWATCH, P.stone, AND THE HOUR IS CARRIED ENTIRELY IN THE LUMINANCE. The obvious
|
||||
* alternative is west_range.js's `sun > 0.6 ? A : B` swatch switch, and on a telegraph pole
|
||||
* that is right because a pole is four cells. Here the run is 20-40 cells wide on a face
|
||||
* that all changes at once, and a swatch that flips as the sun crosses an azimuth is the
|
||||
* large-area single-frame step surf_japan.js:449 names by name. MEASURED, these cells
|
||||
* print v 30-70 at 60 m by day against a frame whose lit p90 is 130 — so the eave is a DARK
|
||||
* line on a pale mass, which is what an eave seen from seventeen degrees below actually is,
|
||||
* and stone's max channel of 170 could not make it a bright one at this range even at
|
||||
* lum 255. At night it prints under 20 and the tiers go to silhouette — deliberately, and
|
||||
* see the header. */
|
||||
var lum = 18 + 120 * sun * (0.22 + 0.78 * (1 - NIGHT)) + 26 * DAYF;
|
||||
runEave(f, ax, az, bx, bz, y, P.stone, lum * fade, 1, 1);
|
||||
|
||||
/* THE CHIDORI-HAFU, on the two middle tiers of the broad face only: the dormer gable that
|
||||
* breaks a keep's roofline, and the one piece of this object that is a SHAPE rather than a
|
||||
* line. Three cells — an apex two rows up and a barge-board mark either side one row up —
|
||||
* because at 60 m a 2 m gable is two and a half rows and there is nothing else in it. */
|
||||
if (isBroad && i > 0 && i < nt - 1) {
|
||||
var mx = (ax + bx) * 0.5, mz = (az + bz) * 0.5;
|
||||
if (project(mx, y, mz)) {
|
||||
var gxp = Math.floor(PJ.x), gyp = Math.floor(PJ.y), gd = PJ.d - 0.01;
|
||||
emit(f, gxp, gyp - 2, G_CARET, P.stone, lum * fade * 1.3, gd);
|
||||
emit(f, gxp - 1, gyp - 1, G_QUOTE, P.stone, lum * fade, gd);
|
||||
emit(f, gxp + 1, gyp - 1, G_TICK, P.stone, lum * fade, gd);
|
||||
}
|
||||
}
|
||||
built = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================== the ridge and the fish ===
|
||||
* The crown roof, and the only thing on this object that a night frame can see.
|
||||
*
|
||||
* The ridge is a short horizontal run across the core, inset 12% at each end so it reads as a
|
||||
* ridge sitting on a hip roof rather than as a fifth eave — which axis it takes is decided
|
||||
* below and is a correction worth its own paragraph. `pure` at 255 prints what its luminance
|
||||
* says, because its max channel IS 255 and the printed value is therefore just the fogged
|
||||
* luminance, which is why the two numbers here are the only ones in this file set by aiming at
|
||||
* the census rather than at the light. MEASURED over ten seeds: 5-16 `pure` cells on the frames
|
||||
* that carry them, printing 128-165 in the 60-70 m band and reaching 170-194 inside 55 m, which
|
||||
* is the only hot tail a keep can contribute to a night frame censusing 0.21% against a 3.5-5%
|
||||
* target.
|
||||
*
|
||||
* The shachihoko are one cell each, one row above the ridge ends, in `pure` with a `gold` mark
|
||||
* under them at d - 0.01 — the gilt body, which is the material claim, drawn where the ridge
|
||||
* has already written the cell and would otherwise be rejected at equal depth. gold's max
|
||||
* channel is 240, so at 65 m through EDO's fog it prints around 82: inside the muddy band. It
|
||||
* is there for the day and the `pure` cell above it is there for the night, and neither is a
|
||||
* substitute for the other. */
|
||||
var dRidge = Math.sqrt((H + RIDGE_H - V.eyeY) * V.scale * WALK / RIDGE_HZ);
|
||||
if (built && d >= dRidge && d <= RIDGE_FAR) {
|
||||
var rf = d < dRidge + FADE_M ? (d - dRidge) / FADE_M : 1;
|
||||
rf = rf * rf * (3 - 2 * rf);
|
||||
/* Fades out again over the last 14 m as well: `pure` at 255 prints 120 at 79 m, so from 68 m
|
||||
* outward these cells are on their way under the muddy ceiling and a specular that cannot be
|
||||
* seen should not be spent. */
|
||||
if (d > RIDGE_FAR - 14) rf *= (RIDGE_FAR - d) / 14;
|
||||
|
||||
/* THE RIDGE RUNS ACROSS THE VIEW, NOT ALONG THE CORE'S LONGER AXIS, and that is a correction
|
||||
* rather than a preference. A tenshu's main ridge does run along its long axis, and the first
|
||||
* cut drew it that way — on the seed-7 keep, whose 3x8 m core is seen almost end-on, that put
|
||||
* the whole ridge along the line of sight, where it projected to FOUR cells stacked
|
||||
* vertically in one column, three of which lost the depth test to the top eave in front of
|
||||
* them and the fourth to a raindrop. Measured: zero `pure` cells in the frame. A ridge is
|
||||
* only ever a horizontal mark at this resolution, so it is drawn on whichever core axis is
|
||||
* more square to the camera — the irimoya gable end facing the approach, which is what a
|
||||
* keep on the far side of a bailey actually presents. */
|
||||
var ry = H + RIDGE_H;
|
||||
var rax, raz, rbx, rbz;
|
||||
var afx = V.fwx < 0 ? -V.fwx : V.fwx, afz = V.fwz < 0 ? -V.fwz : V.fwz;
|
||||
if (afz >= afx) {
|
||||
rax = wx0 + (wx1 - wx0) * 0.12; rbx = wx1 - (wx1 - wx0) * 0.12;
|
||||
raz = rbz = (wz0 + wz1) * 0.5;
|
||||
} else {
|
||||
raz = wz0 + (wz1 - wz0) * 0.12; rbz = wz1 - (wz1 - wz0) * 0.12;
|
||||
rax = rbx = (wx0 + wx1) * 0.5;
|
||||
}
|
||||
/* 214, not 255: at 60 m EDO's fog transmits about 0.62, so 214 prints ~133 — clear of the
|
||||
* muddy ceiling of 119 and deliberately UNDER the hot line, because a whole RUN of hot cells
|
||||
* on one object is not the shape a 0.21% hot tail is short of. The two fish are what go over
|
||||
* it, and only inside 55 m. */
|
||||
runEave(f, rax, raz, rbx, rbz, ry, P.pure, 214 * rf, 0, 0);
|
||||
|
||||
var q;
|
||||
for (q = 0; q < 2; q++) {
|
||||
var fxp = q ? rbx : rax, fzp = q ? rbz : raz;
|
||||
if (!project(fxp, ry + 0.55, fzp)) continue;
|
||||
var fxc = Math.floor(PJ.x), fyc = Math.floor(PJ.y), fd = PJ.d;
|
||||
emit(f, fxc, fyc, G_o, P.pure, 255 * rf, fd);
|
||||
/* The gilt body, one row down, at d - 0.01 so it beats the ridge cell already written
|
||||
* there. CC.put's depth test is strictly-less and an equal-depth write is dropped. */
|
||||
emit(f, fxc, fyc + 1, G_TICK, P.gold, (150 + 80 * DAYF) * rf, fd - 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
return built;
|
||||
}
|
||||
|
||||
/* ============================================================================ the scan pass ===
|
||||
* See the essay at `the search` above for why the lattice is world-aligned and why the two steps
|
||||
* are 4 and 8. The order of the two loops is z-then-x so the sample order is a property of the
|
||||
* map: with MAX_KEEPS capping the work, which keeps get built has to be reproducible, and a scan
|
||||
* ordered by camera position would build a different three from one frame to the next.
|
||||
* ============================================================================================ */
|
||||
function drawKeeps(f) {
|
||||
var R = KEEP_R;
|
||||
var gx0 = Math.floor((V.ox - R) / STEP_X) * STEP_X;
|
||||
var gx1 = Math.floor((V.ox + R) / STEP_X) * STEP_X;
|
||||
var gz0 = Math.floor((V.oz - R) / STEP_Z) * STEP_Z;
|
||||
var gz1 = Math.floor((V.oz + R) / STEP_Z) * STEP_Z;
|
||||
/* 1.8 half-planes of slop on the cone. The frame edge is |sp| = tan(fov/2); a keep whose CENTRE
|
||||
* is outside the frame can still have half its base tier inside it, because the eaves oversail
|
||||
* three metres and the object is twenty columns wide. */
|
||||
var cone = V.hp * 1.8;
|
||||
var gx, gz, rx, rz, w, sp, rec, k, dup;
|
||||
|
||||
builtN = 0;
|
||||
for (gz = gz0; gz <= gz1; gz += STEP_Z) {
|
||||
for (gx = gx0; gx <= gx1; gx += STEP_X) {
|
||||
rx = gx + 0.5 - V.ox; rz = gz + 0.5 - V.oz;
|
||||
w = rx * V.fwx + rz * V.fwz;
|
||||
if (w < 8) continue; // behind, or too close to be a keep at all
|
||||
sp = (rx * V.rgx + rz * V.rgz) / w;
|
||||
if (sp > cone || sp < -cone) continue;
|
||||
if (rx * rx + rz * rz > R * R) continue;
|
||||
/* The hash-free tests first and the map lookups last: height() is a chunk fetch and cell()
|
||||
* can build a record, and this loop runs a few hundred times a frame. */
|
||||
if (CITY.height(gx, gz) <= 0) continue; // street, alley, plaza or vacant: no record
|
||||
rec = CITY.cell(gx, gz);
|
||||
if (!rec || rec.district !== 'castle') continue;
|
||||
|
||||
dup = 0;
|
||||
for (k = 0; k < builtN; k++)
|
||||
if (builtX[k] === rec.lotX && builtZ[k] === rec.lotZ) { dup = 1; break; }
|
||||
if (dup) continue;
|
||||
|
||||
/* An ordinary castle lot is rejected inside drawKeep by one height probe and costs nothing
|
||||
* else; only a landmark reaches the footprint walk. That is why the reject is NOT cached —
|
||||
* caching it is what broke the scan, see the essay above. */
|
||||
if (!drawKeep(f, rec)) continue;
|
||||
builtX[builtN] = rec.lotX; builtZ[builtN] = rec.lotZ; builtN++;
|
||||
if (builtN >= MAX_KEEPS) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Registered at layer 15, which is free IN EDO — the world-filtered list has 26 elements in it
|
||||
* and none of them was on 15 (jp_town.js takes 16, 17, 19, 20 and 22; weather.js 14; street.js
|
||||
* 18 and up). west_range.js's brush and moon_ground.js's boulders are both on 15, and that is
|
||||
* fine and worth saying so nobody "fixes" it: the layer sort runs on the list AFTER CC.inWorld
|
||||
* has filtered it, so two elements in two different worlds can never be adjacent in one sort.
|
||||
* Being alone on its layer is what matters, because it means the sort cannot reorder an existing
|
||||
* pair. init() draws nothing from the shared rng either, so no downstream element's stream
|
||||
* moves: jp-blossom gets the same thirty draws it had. Checked, not assumed. */
|
||||
CC.ELEMENTS.push({
|
||||
name: 'jp-keep',
|
||||
layer: 15,
|
||||
world: 'japan',
|
||||
init: function (city) { boot(city); },
|
||||
draw: function (f, cam, t) {
|
||||
if (!CITY) return;
|
||||
view(f, cam, t === undefined ? (cam.t || 0) : t);
|
||||
drawKeeps(f);
|
||||
}
|
||||
});
|
||||
|
||||
})(typeof CC !== 'undefined' ? CC : require('../core.js'));
|
||||
911
src/elements/jp_flora.js
Normal file
911
src/elements/jp_flora.js
Normal file
|
|
@ -0,0 +1,911 @@
|
|||
/* CyberCity EDO planting — the sakura, and it is the only object in this world with VOLUME.
|
||||
* Layer 18.
|
||||
*
|
||||
* WHY A TREE AND WHY THIS TREE. src/elements/jp_town.js draws four objects and every one of them
|
||||
* is a FACE or a stick: a paper bag under an eave, a curtain across a door, four posts of a gate,
|
||||
* a stone box on the kerb. src/surf_japan.js paints the walls and the ground and by construction
|
||||
* cannot paint anything that stands off them. So the frame this world ships is a corridor of flat
|
||||
* planes with small flat things hung on it, and the one thing missing from it is a mass — an object
|
||||
* that occupies a lump of air between the camera and the frontage, that is lit differently on its
|
||||
* top and its underside, and that the street has to be seen THROUGH. A cherry over a machi lane is
|
||||
* that object, and it is also the single most recognisable thing the setting owns.
|
||||
*
|
||||
* IT IS ALSO THE ONLY DAY-HOT SURFACE THIS WORLD HAS, which is the census half of the argument and
|
||||
* is measured rather than asserted. core.js's print ladder gives `white` a day ceiling of 209 and
|
||||
* the hot line is a printed v of 170, so white needs lum >= 207 by day to print hot. Nothing else
|
||||
* in EDO is licensed anywhere near it: `warm` tops out at 187, `sand` at 190, `ember` at 136, and
|
||||
* `pure` is spent one cell at a time on the core of a near lantern (jp_town.js:199-208). EDO's noon
|
||||
* hot tail measures 0.71% at seed 42 and 0.07% at seed 7 against a project target of 3.5-5%. A
|
||||
* sunlit blossom mass in white at CB 246 prints v ~200 over a large area and is materially honest
|
||||
* about it: someiyoshino in full sun IS the brightest thing in the street.
|
||||
*
|
||||
* WHAT MAKES A TREE DANGEROUS HERE, AND WHAT WAS DONE ABOUT IT. This world has tripped the
|
||||
* photosensitivity rule — nothing above 2% of full scale between 3 and 20 Hz — five times, and
|
||||
* every trip was invisible in a still frame and invisible in the census, because the defect was
|
||||
* purely in the RATE. jp_town.js's blossom drift records the shape of it at length (lines 512-558:
|
||||
* dimming and thinning the pool moved the number not at all, and only an 11 m distance cut did),
|
||||
* and moon_craft.js records the same failure on a static object with a screen-keyed dither
|
||||
* (lines 244-250: 33 big steps a second, 6.3% in band, from a lattice that RE-DEALT as the object
|
||||
* moved a fraction of a cell). A canopy is that hazard at four hundred times the area, so this file
|
||||
* takes the fix moon_craft's quad() takes and states as a rule at its line 385: THE DITHER IS KEYED
|
||||
* IN WORLD METRES. Every luminance in the crown is a function of the world point the cell is
|
||||
* looking at — never of dx/dy from a projected centre, never of floor(PJ.x), never of iw or ih, and
|
||||
* never of t. See the block over billow() for the arithmetic, which is the most important reasoning
|
||||
* in this file.
|
||||
*
|
||||
* NOTHING IN HERE MOVES. Not the crown, not a limb, not a leaf. The arithmetic is in the sway note
|
||||
* below drawTrees(); the short version is that a crown at 14 m subtends 63 columns and a 0.6 Hz
|
||||
* sway of +/-0.12 m would put every one of its ~150 rim cells across a cell boundary at 1.2 Hz with
|
||||
* a third harmonic inside the band, at day contrast against sky. The motion in this world stays
|
||||
* where jp_town.js already gated it: the petals, cut at 11 m.
|
||||
*/
|
||||
(function (CC) {
|
||||
'use strict';
|
||||
|
||||
/* One projector per element — see src/proj.js for why there is exactly one copy of the camera and
|
||||
* why each element holds its own basis. V and PJ are this file's own; the helpers are closed over
|
||||
* them. litFace() is deliberately NOT pulled in: see the lighting note over billow(). */
|
||||
var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ;
|
||||
var project = PR.project, emit = PR.emit, column = PR.column;
|
||||
|
||||
var P = CC.P, hash2 = CC.hash2, vnoise = CC.vnoise;
|
||||
|
||||
/* THE CANOPY RAMP IS BUILT FROM MARKS WITH A HOLE IN THEM, never from block glyphs, and that is
|
||||
* the whole "blossom, not blob" argument. A blossom mass at 9x16 px per cell is a stipple of
|
||||
* small round marks with air between them; '#', '%', '&', '$', 'M' and 'W' fill the cell corner
|
||||
* to corner and turn a crown into masonry. surf_japan.js's own INK ramp stops at '=' for exactly
|
||||
* this reason. So:
|
||||
* '@' the heaviest glyph in the table that still has a HOLE in it — a dense knot of flowers
|
||||
* seen small is a knot with light in it, which is what '@' draws and '#' does not.
|
||||
* '8' two stacked lobes: two clusters on one twig. Already the chochin's body glyph.
|
||||
* '*' five arms round a centre. It is the only glyph in GLYPHS that is literally a flower.
|
||||
* 'o' one open bloom, for the mid tier.
|
||||
* '`' and "'" the feathered rim, paired so the edge alternates lean and does not comb.
|
||||
* The trunk takes '|', the limbs '/' '|' '\' so the three read as a splay rather than a post, and
|
||||
* 'Y' — the last glyph in the table and literally a fork — goes at the crotch. One cell, and it
|
||||
* is the difference between a lollipop and a tree. '-' bands the near trunk: sakura bark is
|
||||
* horizontally lenticelled where cryptomeria is vertically fibred, and two rows of it is what
|
||||
* names the species at a glance. */
|
||||
var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"),
|
||||
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');
|
||||
|
||||
/* Bound once per rebuild from the MAP, never from CC.World: between a keypress and the rebuild
|
||||
* 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;
|
||||
function boot(city) {
|
||||
CITY = (city && city.aveX && city.world === 'japan') ? city : null;
|
||||
BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 6) & 0x3fffff) : 0;
|
||||
JP = null;
|
||||
/* STALE ANCHORS ACROSS A REBUILD, and this one line is a shipped-class bug closed by hand.
|
||||
* main.js re-runs every element's init() on any seed or world change, and jp-blossom's init
|
||||
* seeds thirty petals through respawn() BEFORE this element has drawn a single frame of the new
|
||||
* city. If the anchor count survived the rebuild, those thirty petals would be seeded at tree
|
||||
* positions from a map that no longer exists — and a fresh headless process, which starts at
|
||||
* n = 0, would never see it. That is precisely the browser-diverges-from-the-harness class the
|
||||
* fixture comparison exists to catch. */
|
||||
FL.n = 0;
|
||||
}
|
||||
|
||||
/* Per-frame caches. EVERY ONE OF THESE IS ASSIGNED INSIDE view(). The contract asks for that by
|
||||
* name after two frontier files were left holding their declared defaults and silently stopped
|
||||
* following the clock; the declared values here are the NIGHT end, so a file that somehow drew
|
||||
* without a view() would draw a black tree rather than a noon-white one in the dark. */
|
||||
var NIGHT = 1, DAYF = 0, LAMP = 1;
|
||||
function view(f, cam, t) {
|
||||
PR.view(f, cam, t);
|
||||
/* Resolved off the painter registry rather than by CC.SurfJapan's name, so the getters come
|
||||
* from whichever painter actually owns the live world. Same shape as jp_town.js:64. */
|
||||
if (!JP) JP = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null;
|
||||
NIGHT = (JP && JP.night !== undefined) ? JP.night : 1;
|
||||
DAYF = (JP && JP.dayFill !== undefined) ? JP.dayFill : 0;
|
||||
/* LAMP ALONE, and never NIGHT * LAMP. That is a shipped-and-fixed bug documented three times in
|
||||
* this tree (surf_japan.js:242-249 and 580-584, jp_town.js:144-146): the director's `lamp`
|
||||
* 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 street-lattice helpers, in the same shape jp_town.js and west_range.js use them. They are
|
||||
* repeated here rather than reached for across files because an element file in this project owns
|
||||
* its own scaffolding and nothing exports these; the six of them strip to under 300 bytes.
|
||||
*
|
||||
* WHICH AXIS IS WHICH is the distinction that had every lantern in jp_town.js placed two hundred
|
||||
* metres up the wrong road, so it is restated: an avenue is INDEXED by x and RUNS along z, so
|
||||
* nearIdx reads V.ox and alongOf reads V.oz. They are one axis apart and nothing in either name
|
||||
* says so. */
|
||||
function wxOf(axis, along, cross) { return axis ? along : cross; }
|
||||
function wzOf(axis, along, cross) { return axis ? cross : along; }
|
||||
function nearIdx(axis) {
|
||||
return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE));
|
||||
}
|
||||
function centreOf(axis, idx) { return axis ? CITY.crossZ(idx) : CITY.aveX(idx); }
|
||||
function halfOf(axis, idx) { return axis ? CITY.crossW(idx) : CITY.aveW(idx); }
|
||||
function alongOf(axis) { return axis ? V.ox : V.oz; }
|
||||
/* Where the building face actually is, in world metres. city.js's colX() marks cells [c-hw, c+hw]
|
||||
* as corridor and a cell `g` covers world [g, g+1), so the frontage plane on the +side is
|
||||
* x = c + hw + 1 and on the -side x = c - hw — which is this one expression. A tenth of a metre
|
||||
* wrong here is not cosmetic: an object on the far side of that plane is INSIDE the building and
|
||||
* CC.put's depth test deletes it without a word. */
|
||||
function faceOf(axis, idx, side) {
|
||||
return centreOf(axis, idx) + 0.5 + side * (halfOf(axis, idx) + 0.5);
|
||||
}
|
||||
|
||||
/* ============================================================================= THE ANCHOR LIST ===
|
||||
* WHAT THIS IS FOR AND WHY IT LIVES IN A GLOBAL. jp_town.js's blossom drift spawns its petals on
|
||||
* a ring 4-24 m round the CAMERA (respawn(), line 410-422) — that is, from nowhere. It is the
|
||||
* shipped look and it censuses fine, but with trees in the world it is plainly wrong: the petals
|
||||
* should come off a crown. This file cannot edit jp_town.js, so instead it PUBLISHES where its
|
||||
* crowns are and a later one-line change in respawn() can read them. Nothing here breaks if that
|
||||
* change is never made — the list is written every frame and, if nobody looks, thrown away.
|
||||
*
|
||||
* WHAT A CONSUMER MUST HONOUR, and it is one rule: only trees beyond 13 m are recorded. The 11 m
|
||||
* cut in jp_town.js:532 is a measured photosensitivity gate (without the drift the world scores
|
||||
* 1.27% in band, with it and no cut 2.59%), and a petal born on a crown at 6 m would spend its
|
||||
* whole life inside that cut and be drawn never. So the nearest and best-seen tree sheds nothing.
|
||||
* That is the trade, stated plainly, and the alternative is reopening a gate that took five
|
||||
* failures to close.
|
||||
*
|
||||
* ALLOCATED ONCE, at module load, never per frame — same rule as everything else in draw(). */
|
||||
var ANC_N = 8;
|
||||
var FL = {
|
||||
n: 0, cap: ANC_N,
|
||||
x: new Float64Array(ANC_N), y: new Float64Array(ANC_N),
|
||||
z: new Float64Array(ANC_N), r: new Float64Array(ANC_N)
|
||||
};
|
||||
CC.JPFlora = FL;
|
||||
|
||||
/* =================================================================================== placement ===
|
||||
* A STREET WALK, NOT A LATTICE, and jp_town.js:341-348 already records why: two lattice cuts of
|
||||
* the stone lantern failed for two compounding reasons — this world's open ground is mostly
|
||||
* INSIDE a block, so the frontage occludes it, and the thin strip beside the road where it is not
|
||||
* is a small fraction of a lattice cell's area, so almost nothing lands in it. Walking the along-
|
||||
* street index the way the lanterns and the toro do puts the object exactly where it can be seen,
|
||||
* at a rate that is a PITCH rather than an area fraction, for less code.
|
||||
*
|
||||
* THE PITCH LADDER IN THIS WORLD ALREADY RUNS FROM lantern-per-bay TO object-per-lot — LAN_PITCH
|
||||
* 2.4, NOREN_PITCH 5.4, TORO_PITCH 7.4 — and a tree belongs at the far end of it. Below about
|
||||
* 8 m it reads as a planted boulevard, which is a park and not a castle town.
|
||||
*
|
||||
* THE ELIGIBLE QUARTERS ARE NOT ISH_OK. The stone lantern's table includes `kura`, a fireproof
|
||||
* warehouse yard, which is the one place in town nobody plants a flowering tree, and `castle`,
|
||||
* which measured out nearly inert as a placement quarter — hMin 7.0 / hMax 12.0 with vacant 0.22
|
||||
* means its frontage is a battered stone wall you cannot see over and its open lots are behind it.
|
||||
* What is left is the four quarters where a tree is both plausible and visible: `garden` (58%
|
||||
* vacant, so the setback placement fires there and the crown is seen over the wall), `temple`
|
||||
* (the approach tree), and `machiya` + `market`, which are the two dense frontages where the tree
|
||||
* goes to the KERB and overhangs the carriageway. Those four are 0.59 of quarters by district
|
||||
* weight (0.26 + 0.11 + 0.10 + 0.12), which is why the accept rate below is 0.19 and not the 0.34
|
||||
* a three-quarter table would want.
|
||||
*
|
||||
* THE DENSITY, WORKED AND THEN MEASURED. The walk covers 2*TREE_R = 84 m of frontage per street
|
||||
* index per side, which is 7 slots at a 12 m pitch; times 0.59 eligible times 0.19 accepted is
|
||||
* 0.79 trees per side per street index — call it one, which is the density the brief's own
|
||||
* arithmetic lands on once `castle` comes out and `machiya` goes in. MEASURED over 41 frames of
|
||||
* the autopilot at 200x60, counting every tree that passes the frustum test: seed 1 gives 0.51
|
||||
* trees a frame, seed 7 gives 3.22, seed 42 gives 4.12 and seed 404 gives 6.78, with a quarter to
|
||||
* a half of them inside 20 m. That spread is the map's, not the pitch's — a walk that spends its
|
||||
* time in `nagaya` and `kura` sees no trees at all and should not — and it is why the pitch was
|
||||
* not raised to flatter the poor seeds: an avenue of them is a park, and this is a town.
|
||||
*
|
||||
* TREE_R = 42 m rather than the brief's 62. A crown at 42 m is still 2.6*2*137.6/42 = 17 columns
|
||||
* and a perfectly legible shape down a street; beyond that fog has it at under 71% and the tier
|
||||
* 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;
|
||||
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
|
||||
* TRUNK is drawn and the canopy is not.
|
||||
*
|
||||
* The picture reason first, because it is the one that decides the number. At 200x60 the horizon
|
||||
* is row 33.6 and V.scale is 77.4, so a crown centred at 5.8 m of height projects to row
|
||||
* 33.6 - (5.8-1.7)*77.4/d. At d = 6 that is row -19; at d = 8, row -6; at d = 9.5, row +0.2. So
|
||||
* anywhere inside about nine metres the entire crown is off the top of a 60-row frame and all the
|
||||
* viewer gets is a wall of white sweeping the frame edge — while the billow loop is at its
|
||||
* LARGEST and emitting almost nothing. Nine and a half metres is where the crown starts to be a
|
||||
* crown rather than a ceiling.
|
||||
*
|
||||
* The rate reason second. The world-keyed field below makes a screen cell's crossing rate
|
||||
* independent of distance (see the arithmetic over billow()), so distance is no longer the lever
|
||||
* it is for the petals — but the SILHOUETTE still sweeps across the frame at speed*colK/d columns
|
||||
* per second, and at 6 m on the autopilot's 1.6 m/s that is 37 columns/s of a hard crown/sky
|
||||
* boundary passing over the near half of the frame. Nine and a half metres holds it to 23, and
|
||||
* the manual walk at 2.7 m/s to 39.
|
||||
*
|
||||
* The cost reason third, and it is the one the critique of this design was loudest about. The
|
||||
* per-billow ellipse is 400-660 cells at 20 m, 800-1,300 at 14 m, 1,500-2,400 at 10 m and would
|
||||
* be 4,000-4,900 at 6 m. The bound that actually bounds it is not this cut but the per-column row
|
||||
* clip inside billow() — an off-frame row is never iterated at all — and this cut is what stops
|
||||
* the loop paying for a shape nobody can see. */
|
||||
var CAN_NEAR = 9.5;
|
||||
|
||||
/* THE UP-FACTOR, WHICH IS THE MUDDY LEVER AND IS SHIPPED AT THE HIGHER OF THE TWO CANDIDATE
|
||||
* SETTINGS. A crown at noon lands most of its cells in the print's muddy band (9 <= v < 120)
|
||||
* whatever is done, and EDO's noon muddy is 44-52% against a project target under 30%, so this is
|
||||
* the number that decides whether the element is a census win or a census cost.
|
||||
*
|
||||
* The two candidates were 0.46 + 0.54*up and 0.60 + 0.40*up, and 0.60 is what ships. Measured
|
||||
* here, pooled over eight frames at seed 42 noon with the element rendered twice — once with, once
|
||||
* without, and the frames differenced cell by cell — 0.46 puts 4-6 more points of the element's
|
||||
* own cells in the band and takes the same off its hot tail. The cost is a flatter crown: 0.60 is
|
||||
* about 1.7:1 top-to-underside where 0.46 is 2.2:1. That is a fair reading of surf_japan.js's own
|
||||
* dome model anyway — SKY_UP 1.00 against SKY_SIDE 0.52 applied to a sphere, under an overcast
|
||||
* where the SKY is the key light and there is no sun term at all.
|
||||
*
|
||||
* IT FLATTENS FURTHER WITH DISTANCE. See the `dim` term inside billow(): fog takes a crown at 40 m
|
||||
* to 71% of its luminance, so an underside at 0.60 of base slides into the band however clean it
|
||||
* was at 14 m — and at forty metres a 5 m crown is nine columns wide, where a top-to-underside
|
||||
* gradient is not resolvable and haze has flattened it in life as well as in the ladder.
|
||||
*
|
||||
* RIM_F and MID_F are what is LEFT of the brief's rim x0.62 / mid x0.78 after the tier identity
|
||||
* moved to the gap threshold — see the T_RIM block below, which is where that 0.62 went and why. */
|
||||
var UP_FLOOR = 0.60, UP_SPAN = 0.40, RIM_F = 0.88, MID_F = 0.95;
|
||||
|
||||
/* The two tier radii, as normalised radius-squared inside the billow's silhouette disc. q 0.28
|
||||
* puts about 28% of the disc's area in the core, q 0.62 another 34% in the mid and the remaining
|
||||
* 38% in the rim. That three-way split is the same one surf_japan.js's walls already use
|
||||
* (lit / mid / shd at line 452-454) and the mapping notes name a missing third tier as the
|
||||
* highest-leverage census change available anywhere in this world. */
|
||||
var Q_CORE = 0.28, Q_MID = 0.62;
|
||||
|
||||
/* ---- WHY THE OUTER TIERS THIN OUT INSTEAD OF DIMMING DOWN, WHICH IS THIS FILE'S ONE REAL
|
||||
* DEPARTURE FROM THE BRIEF IT WAS BUILT TO, AND IT IS A MEASUREMENT AND NOT A PREFERENCE --------
|
||||
* The brief writes the three tiers as LUMINANCE factors — rim x0.62, mid x0.78, core x1.00 — on
|
||||
* top of an up-factor floor of 0.60. Multiply those out and the dimmest lit cell in the crown is
|
||||
* 0.60 * 0.62 = 0.372 of base, which at noon is raw lum 92.
|
||||
*
|
||||
* THE PRINT LADDER, MEASURED, IS WHY THAT DOES NOT WORK. Poked cell by cell through the shipped
|
||||
* exposure LUT at this world's noon exposure (which applies a GAMMA LIFT and a knee, so the naive
|
||||
* `ceiling * lum/255` is not the print and is wrong by a factor of two at the bottom):
|
||||
*
|
||||
* raw lum 8 24 60 100 140 180 220 246
|
||||
* white v 24 49 88 122 152 179 198 206
|
||||
* sand v 21 44 80 110 137 161 180 187
|
||||
* timber v 11 26 48 66 82 97 111 118
|
||||
* moss v 10 23 41 57 71 83 94 100
|
||||
*
|
||||
* So `white` clears the muddy ceiling of 120 at raw lum ~98 and reaches the hot line of 170 at
|
||||
* ~166, and it is black only under raw lum ~3. THERE IS NO SUCH THING AS A DIM CELL: everything
|
||||
* between raw 3 and raw 98 prints into the band. Raw 92 is the last rung below the line, so the
|
||||
* rim — 38% of every crown's area — was manufacturing mud by construction. Measured pooled over
|
||||
* eight frames at seed 42 noon by rendering the world twice and differencing, the multiplicative
|
||||
* version put 88.4% of the element's own cells in the band and moved the FRAME's muddy share the
|
||||
* WRONG WAY at six of the eight frames.
|
||||
*
|
||||
* So the tiers move the GAP THRESHOLD instead of the luminance. A rim cell is either full blossom
|
||||
* or black; what makes the rim a rim is that far more of it is black. That is bimodal by
|
||||
* construction, it is what a feathered edge actually looks like (clusters against sky, not a grey
|
||||
* wash), and it is the same idea the brief argues for when it says the porosity must live in the
|
||||
* mixture rather than in missing cells — carried one step further, into the luminance. With the
|
||||
* same eight frames the element measures 70.3% black / 24.6% muddy / 5.1% clean, and the frame's
|
||||
* muddy share moves -1.03 points rather than up.
|
||||
*
|
||||
* The luminance factors are kept, at 0.88 and 0.95, because a rim exactly as bright as the core
|
||||
* 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 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
|
||||
* SH_HI are full blossom, and in between the luminance ramps. Three things are being bought:
|
||||
* THE GAP IS WRITTEN, NOT SKIPPED. moon_craft.js's quad states the rule at line 385: a cell
|
||||
* that is always painted can never alternate with what is behind it. A canopy that leaves 30%
|
||||
* of its cells unwritten shows sky through them and every one of them alternates with the
|
||||
* crown as the walk moves it — the windmill failure (west_town.js:470-500) reproduced over
|
||||
* four hundred cells instead of twelve. metrics.py does not count ink; the eye does. That
|
||||
* asymmetry is the whole trick: it LOOKS porous and it is solid.
|
||||
* THE GAP IS LUM 0 AND NOT LUM 9. The brief pins the shade tier at lum 9 and calls it "the one
|
||||
* number that must not drift", on the arithmetic `ceiling * lum/255`. That is not the print:
|
||||
* the measured ladder in the T_RIM block above has timber at raw lum 8 printing v 11 and
|
||||
* `shadow` at raw 8 printing v 2, so lum 9 in any of this world's timbers is INSIDE the muddy
|
||||
* band and the tier that was meant to be the element's best census property would have been
|
||||
* its worst. Lum 0 in `shadow` is genuinely black at every hour and still occludes, because
|
||||
* CC.put writes f.dist unconditionally whatever the luminance is.
|
||||
* THE RAMP WIDTH IS A PHOTOSENSITIVITY NUMBER AND IT IS SOLVED, NOT PICKED. What the ramp buys
|
||||
* is that a cell being crossed by a gap boundary takes several FRAMES to make the transition
|
||||
* instead of one, so no single frame's step reaches the project's big-step line of a third of
|
||||
* full scale. The number of frames is
|
||||
* frames = ramp_metres * 60 / s
|
||||
* where s is the camera's lateral speed — the distance term cancels exactly, for the same
|
||||
* reason it cancels in the crossing rate over billow(). The field's gradient is about 1.25
|
||||
* per metre, so a ramp of SH_W = 0.18 in field value is 0.144 m of world, i.e. 5.4 frames at
|
||||
* the autopilot's 1.6 m/s and 3.2 frames at the manual walk's 2.7 m/s. Three frames is the
|
||||
* floor: at three, a full-swing transition is 33% of scale per frame, exactly the big-step
|
||||
* line. SH_W is set at the narrowest value that still clears it, because every hundredth
|
||||
* wider is another band of half-lit cells landing in the muddy band — the first cut ran the
|
||||
* ramp at 0.36 and measured 59.5% of the element's cells muddy against 24.6% at 0.18. */
|
||||
var SH_LO = 0.34, SH_W = 0.18;
|
||||
|
||||
/* ---- AND THE THRESHOLD WALKS OUT WITH DISTANCE, which is a census lever and a picture fix at
|
||||
* the same time and was the single largest measured improvement in this file.
|
||||
*
|
||||
* MEASURED FIRST. Fog on this world's ramp (14 m / 150 m / pow 1.5) takes a crown at 30 m to 83%
|
||||
* of its raw luminance and one at 44 m to 71%, and `white` needs raw lum 98 to clear the muddy
|
||||
* ceiling — so a crown that lands cleanly at 14 m slides bodily INTO the band at 30 and sits
|
||||
* there. Walking the gap threshold out with the billow's own depth pushes the cells that would
|
||||
* have gone dim to black instead and leaves the ones that would have stayed clean alone.
|
||||
*
|
||||
* THE PICTURE ARGUMENT IS THE SAME ARGUMENT AND IT IS west_range.js's, made about a telegraph
|
||||
* pole at line 102-107: by day the honest reading of a distant object under haze is that it gets
|
||||
* DARKER against its surroundings, not fainter. A cherry at forty metres in humid spring air is a
|
||||
* dark mass with a bright top edge, and that is what a raised gap threshold draws — the dim half
|
||||
* of the crown falls out to occluding black and what survives is the lit crown and the sunward
|
||||
* rim. What it must never do is pop, so it is a linear ramp in distance from 18 m over the next
|
||||
* 26 m: at the autopilot's 1.6 m/s the threshold moves 0.0074 per second against a field ramp
|
||||
* SH_W = 0.18 wide, so a cell's luminance changes by at most 4% of its swing per second from this
|
||||
* term. That is well over an octave below the bottom of the flash band, and it is the reason this
|
||||
* one term is allowed to be keyed on the camera at all when nothing else in the file is.
|
||||
*
|
||||
* SH_LEAF is the same lever spent on the leaf trees, and its arithmetic is in the `bloom` note
|
||||
* inside drawTrees(): `moss` prints v 100 at raw lum 246, which is UNDER the muddy ceiling of
|
||||
* 120, so no luminance of it is ever clean and every visible moss cell is a muddy cell. The only
|
||||
* thing that can be done about that is to have fewer of them, which is what a raised gap
|
||||
* threshold on a leaf crown does. */
|
||||
var SH_FAR = 0.12, SH_D0 = 18, SH_DK = 1 / 26, SH_LEAF = 0.16;
|
||||
|
||||
/* ================================================================================= ONE BILLOW ===
|
||||
* A crown is drawn as three overlapping ellipsoids and this draws one of them: centre (bx,by,bz),
|
||||
* horizontal radius `rad`, vertical radius `ry`. THREE AND NOT ONE, because a someiyoshino crown
|
||||
* is a cluster of distinct billows on radiating limbs and the union of three offset ellipses has
|
||||
* a naturally ragged outline where one ellipse never does; and because a crown spans three metres
|
||||
* of DEPTH, so at ten metres its near and far sides differ 30% in size and a single screen-space
|
||||
* ellipse is simply the wrong shape up close.
|
||||
*
|
||||
* ---- HOW IT IS WALKED, AND WHY IT IS WALKED THIS WAY -------------------------------------------
|
||||
* This is moon_craft.js's quad() generalised from a flat face to a silhouette: sample ACROSS the
|
||||
* object in world metres, one sample per screen column solved off the projected width, and for
|
||||
* each sample project the two ENDS of a vertical and fill between them. proj.js's column() gives
|
||||
* the reason — sampling a grid of world points and projecting each separately puts them in
|
||||
* different columns whenever the object is off-axis, and the object shears as the camera pans.
|
||||
*
|
||||
* The sample axis is the camera's own right vector (V.rgx, V.rgz), which is what makes the sample
|
||||
* count solvable and the fill gapless: sample i lands in screen column i, near enough. The world
|
||||
* point it names, (bx + rgx*u, wy, bz + rgz*u), is a point on the disc through the billow's
|
||||
* centre perpendicular to the view — i.e. very nearly the point the ray through that cell would
|
||||
* hit on the near surface of the ellipsoid.
|
||||
*
|
||||
* ---- AND THAT WORLD POINT IS THE KEY TO EVERY HASH IN HERE, WHICH IS THE POINT OF THE FILE -----
|
||||
* THE FAILURE THIS AVOIDS, stated exactly. The obvious way to texture a projected blob is to hash
|
||||
* the SCREEN offset from its centre cell: hash2(dx + salt, dy - salt, ...) where dx, dy are
|
||||
* offsets from floor(PJ.x) and floor(PJ.y). Every element in this tree that has done that has
|
||||
* failed the gate, because floor(PJ.x), floor(PJ.y), and the half-widths derived from the
|
||||
* projected size ALL STEP CONTINUOUSLY as the camera walks, and each step RE-DEALS the entire
|
||||
* lattice at once. For a kerb tree 3 m off the walk line at the autopilot's 1.6 m/s (control.js
|
||||
* SPEED), floor(PJ.x) steps at p*s*colK/w^2 — 10.3 Hz at 8 m, 4.6 Hz at 12 m, 2.6 Hz at 16 m —
|
||||
* and floor(PJ.y) at very nearly the same rate. At the manual WALK speed of 2.7 m/s every one of
|
||||
* those doubles. Each re-deal changes state on a large fraction of several hundred canopy cells,
|
||||
* so a given cell alternates six or seven times a second, squarely in the 3-20 Hz band, at a day
|
||||
* contrast of black-gap against white-core which is 76% of full scale. That is moon_craft.js:
|
||||
* 244-250 verbatim (33 big steps/s, 6.3% in band) on an object forty times the area.
|
||||
*
|
||||
* WHAT IS DONE INSTEAD. Every field below is sampled at the CELL'S WORLD POINT in metres. The
|
||||
* crown does not move and the world point does not move, so nothing re-deals, ever. What is left
|
||||
* is only the honest thing — as the camera translates, a fixed screen cell looks at a different
|
||||
* part of a stationary object — and its rate is a pure function of world speed and world feature
|
||||
* size, with the distance term cancelling exactly:
|
||||
*
|
||||
* cell's rate of crossing one feature = (s * colK / d) / (L * colK / d) = s / L
|
||||
*
|
||||
* where s is the camera's lateral speed and L the feature size in metres. At L = 1.6 m (the field
|
||||
* frequency below is 0.62 per metre, so a period is 1.6 m) that is 1.0 Hz on the 1.6 m/s
|
||||
* autopilot and 1.7 Hz at the 2.7 m/s manual walk. Both are BELOW the 3 Hz floor of the band, at
|
||||
* every distance, which is a property no screen-keyed lattice can have at any distance at all.
|
||||
*
|
||||
* AND THE FIELD IS SMOOTH, NOT BINARY, which is the second half of it. vnoise interpolates, so
|
||||
* adjacent cells differ by a fraction of the swing rather than by all of it, and the transition
|
||||
* from black gap to full blossom is spread over SH_W = 0.18 of field value — see that constant
|
||||
* for the frames-per-transition solve, which is the number that actually bounds the per-frame
|
||||
* step. This is west_town.js's and surf_moon.js's standing remedy — SPREAD THE CHANGE, NEVER
|
||||
* SWITCH IT — applied to a texture instead of to a terminator.
|
||||
*
|
||||
* THE ONE HIGH-FREQUENCY TERM, and its budget. `fw` is a second octave at 2.7 per metre (period
|
||||
* 0.37 m) whose whole job is to keep the crown from reading as three smooth blobs. Its crossing
|
||||
* rate is s/0.37 = 4.3 Hz on autopilot, which IS in the band, so its AMPLITUDE is what has to be
|
||||
* legal rather than its rate: it is worth +/-0.10 of the tier luminance, and because it too is
|
||||
* interpolated the change a cell sees in one frame is (its own period in frames)^-1 times that
|
||||
* swing = s/(0.37*60) * 0.20 = 1.4% of the tier value at 1.6 m/s and 2.4% at 2.7 m/s, i.e. at or
|
||||
* under 2% of full scale even where the crown is at its brightest. That is the budget and it is
|
||||
* spent deliberately; it is also why there is no third octave.
|
||||
*
|
||||
* NO PER-CELL HASH DECIDES A LUMINANCE OR A GLYPH ANYWHERE IN THIS LOOP. Both come from the two
|
||||
* smooth fields and from the cell's geometric position in the disc. That is a stronger guarantee
|
||||
* than world-keying alone and it costs nothing: two vnoise calls per cell is four hash2 calls,
|
||||
* exactly what quad() spends.
|
||||
*
|
||||
* ---- MEASURED, WITH THE CAMERA WALKING, WHICH NO TOOL IN THIS TREE DOES --------------------------
|
||||
* tools/west-flicker.cjs PINS the camera and says so at its line 156 ("the only variable left is
|
||||
* time"), and this object has no time dependence at all beyond the daylight clock — so the shipped
|
||||
* gate sees it and reports nothing: measured under that condition the element's worst cell adds
|
||||
* +0.00 big steps/s and +0.00% in band at night, +0.56% at noon (which is the daylight clock, not
|
||||
* the tree). That is a PASS the hazard would have walked straight through, so the measurement was
|
||||
* redone with west-flicker's own metric — BIG = 255/3, the same seven Goertzel probes on f.lum,
|
||||
* 180 frames — and the camera driven by CC.Control exactly as main.js drives it. Worst per-cell
|
||||
* increase attributable to this element, seed 42 noon, 200x60:
|
||||
*
|
||||
* jp-sakura step +64.7% big steps +2.00/s 3-20 Hz +3.76%
|
||||
* jp-stonelantern step +70.2% big steps +2.00/s 3-20 Hz +3.99%
|
||||
* jp-torii step +60.8% big steps +1.67/s 3-20 Hz +3.57%
|
||||
* jp-lanterns step +38.0% big steps +2.67/s 3-20 Hz +1.87%
|
||||
* jp-noren step +26.3% big steps +1.33/s 3-20 Hz +2.03%
|
||||
* jp-blossom step +0.0% big steps +0.00/s 3-20 Hz +0.00% (its 11 m cut, working)
|
||||
*
|
||||
* The whole frame with no element at all measures 5.67 big steps/s and 7.26% in band under a
|
||||
* walking camera, so every one of these is a fraction of a baseline that is a property of a
|
||||
* character grid with a camera moving across it — which is the stance flicker-rate.cjs:266-271
|
||||
* already records. What matters is that the sakura sits WITH the two shipped static objects and
|
||||
* not an order above them, which is exactly what world-keying buys and exactly what a screen-keyed
|
||||
* lattice would have destroyed: moon_craft.js measured 33 big steps/s from that mistake.
|
||||
*
|
||||
* ---- THE LIGHTING IS TOP-DOWN AND THERE IS NO SUN TERM -----------------------------------------
|
||||
* litFace() is not used and that is deliberate: a crown presents every normal at once, which is
|
||||
* west_range.js's saguaro argument (lines 243-249) about a cylinder, only more so for a sphere.
|
||||
* surf_japan.js's whole thesis is that under an overcast deck what models a surface is its angle
|
||||
* to the SKY and not to the sun — SKY_UP 1.00 against SKY_SIDE 0.52 — so the crown is lit purely
|
||||
* top-down at UP_FLOOR..1. That is also what a cherry under Japanese spring overcast looks like.
|
||||
*
|
||||
* ---- AND THE DEPTH IS CONVEX -------------------------------------------------------------------
|
||||
* The lantern sprite in jp_town.js writes every cell at the single depth of its projected centre,
|
||||
* which is invisible on a 0.3 m paper bag and would be very visible on a 4 m crown: the whole
|
||||
* billow would win or lose the depth test against a wall as one unit, so a kerb tree would read as
|
||||
* a decal pasted flat on the shopfront. Instead each cell is pushed toward the camera by the
|
||||
* ellipsoid's own bulge, rad*sqrt(1-q), so the crown occupies a real lump of depth and the
|
||||
* frontage behind it is occluded cell by cell as geometry says it should be. */
|
||||
function billow(f, bx, by, bz, rad, ry, salt, base, lampB, cA, cB, shLo, shK, dim) {
|
||||
var rx = bx - V.ox, rz = bz - V.oz;
|
||||
var w = rx * V.fwx + rz * V.fwz;
|
||||
if (w < 1.2 || w > V.far) return;
|
||||
|
||||
/* One sample per projected column, capped. The cap is not a quality knob — a billow asking for
|
||||
* more than 120 samples is wider than half a 200-column frame and is being drawn from inside
|
||||
* itself, which CAN_NEAR already refuses; it is here so a future camera with a wider fov or a
|
||||
* bigger frame cannot turn this loop into a hang. */
|
||||
var n = Math.ceil(2 * rad * V.colK / w) + 2;
|
||||
if (n < 3) n = 3; else if (n > 120) n = 120;
|
||||
|
||||
var i, r;
|
||||
for (i = 0; i <= n; i++) {
|
||||
/* uu is the lateral offset in WORLD METRES from the billow centre, along the camera's right
|
||||
* vector. Everything downstream is keyed off the world point it names. */
|
||||
var uu = ((i / n) * 2 - 1) * rad;
|
||||
var un = uu / rad;
|
||||
var s2 = 1 - un * un; if (s2 < 0) s2 = 0;
|
||||
var hv = ry * Math.sqrt(s2); // world half-height of the silhouette at this offset
|
||||
var wpx = bx + V.rgx * uu, wpz = bz + V.rgz * uu;
|
||||
|
||||
/* Project the two ENDS of this vertical, exactly as column() and quad() do. */
|
||||
if (!project(wpx, by - hv, wpz)) continue;
|
||||
var x = Math.floor(PJ.x), yb = PJ.y, dc = PJ.d;
|
||||
if (x < 0 || x >= V.cols) continue;
|
||||
if (!project(wpx, by + hv, wpz)) continue;
|
||||
var yt = PJ.y;
|
||||
if (yt > yb) { var sw = yt; yt = yb; yb = sw; }
|
||||
var span = yb - yt; if (span < 1e-4) span = 1e-4;
|
||||
|
||||
/* THE ROW CLIP IS THE REAL COST BOUND. An off-frame row is never entered, so a crown whose
|
||||
* centre is above the top of the frame costs only the columns it actually fills. Without this
|
||||
* the loop pays a q, two vnoise and an emit for every row of a shape that emit() would reject
|
||||
* on entry anyway (proj.js:82). */
|
||||
var r0 = Math.floor(yt), r1 = Math.floor(yb);
|
||||
if (r1 < 0 || r0 >= V.rows) continue;
|
||||
if (r0 < 0) r0 = 0;
|
||||
if (r1 >= V.rows) r1 = V.rows - 1;
|
||||
|
||||
/* The per-COLUMN half of the cluster field, hoisted out of the row loop: it depends only on
|
||||
* the horizontal world position, which is constant down a column. `ph` shears the vertical
|
||||
* octave by the same horizontal position so the two do not stack into a plaid — a separable
|
||||
* field a + b draws a grid, and a grid is the one thing a canopy must not be. */
|
||||
var fu = vnoise(wpx * 0.62 + wpz * 0.41, salt);
|
||||
var ph = wpx * 0.53 + wpz * 0.29;
|
||||
|
||||
for (r = r0; r <= r1; r++) {
|
||||
/* The cell's world height. The column runs from by+hv at row yt down to by-hv at row yb, so
|
||||
* this is a straight inverse-lerp on the cell CENTRE. It is a world metre, which is what
|
||||
* every field below wants. */
|
||||
var wy = by + hv * (1 - 2 * ((r + 0.5 - yt) / span));
|
||||
var vy = (wy - by) / ry;
|
||||
/* Normalised radius-squared inside the silhouette disc, in world units on both axes. At the
|
||||
* disc's edge hv is 0 and this is exactly 1, so the tiers are continuous with the outline
|
||||
* rather than approximating it. */
|
||||
var q = un * un + vy * vy;
|
||||
if (q > 1.0) q = 1.0;
|
||||
|
||||
var fv = vnoise(wy * 0.62 + ph, salt ^ 0x2B);
|
||||
var fw = vnoise(wy * 2.7 + ph * 1.9, salt ^ 0x5D);
|
||||
var nf = fu * 0.46 + fv * 0.54;
|
||||
|
||||
/* The gap ramp. Below SH_LO the cell is a hole between clusters; above SH_HI it is full
|
||||
* blossom; between them it ramps, which is the whole photosensitivity argument above. */
|
||||
/* 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;
|
||||
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`
|
||||
* closer than the disc plane the column was projected on. 0.86 rather than 1.0 keeps the
|
||||
* very front of the crown from poking through anything it is legitimately touching. */
|
||||
var d = dc - rad * 0.86 * Math.sqrt(1 - q);
|
||||
if (d < 0.6) d = 0.6;
|
||||
|
||||
if (shF <= 0.02) {
|
||||
/* THE GAP, and it is written. Glyph 0 at lum 0 in shadow: genuinely black at every hour,
|
||||
* and CC.put still stamps f.dist so it occludes the frontage behind it. */
|
||||
emit(f, x, r, 0, P.shadow, 0, d);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Top-down only. `up` is 0 at the underside of the billow and 1 at its crown, computed from
|
||||
* the world height rather than from a screen row — rows increase DOWNWARD in this renderer
|
||||
* (proj.js:73), and a design specified in screen rows inverts the gradient and puts the one
|
||||
* cell the whole feature is justified by, the hot sunlit core, on the shaded underside. */
|
||||
var up = (wy - by + ry) * (0.5 / ry);
|
||||
if (up < 0) up = 0; else if (up > 1) up = 1;
|
||||
|
||||
/* THE UP-FACTOR FLATTENS WITH DISTANCE, and that is the same measurement as the gap
|
||||
* threshold's distance walk. Fog takes a crown at 40 m to 71% of its luminance, so an
|
||||
* underside at 0.60 of base slides into the band however clean it was at 14 m — and at
|
||||
* forty metres a 5 m crown is nine columns wide, where a top-to-underside gradient is not
|
||||
* resolvable and haze has flattened it anyway. `dim` is the distance term computed by the
|
||||
* caller; at its far end the crown is lit almost uniformly, which is both what is legible
|
||||
* and what keeps the far half of the element out of the mud. */
|
||||
var upF = UP_FLOOR + UP_SPAN * up;
|
||||
upF = upF + (1 - upF) * dim;
|
||||
var tierF = tier === 2 ? RIM_F : (tier === 1 ? MID_F : 1);
|
||||
/* THE LAMP TERM RUNS THE OTHER WAY UP THE CROWN, and that is the whole reason it is a
|
||||
* separate argument rather than part of `base`. The sky is above the tree and the lantern
|
||||
* is under it, so one lights the crown and the other lights the UNDERSIDE — and multiplying
|
||||
* a lamp contribution by the same top-weighted factor as the sky, which is what the first
|
||||
* cut of this did, lit an entire small crown evenly and put a glowing ball over a night
|
||||
* street with nothing under it to explain the light. (1 - 0.78*up) puts nearly all of it on
|
||||
* the branches a lantern can actually reach and leaves the crown dark, which is both the
|
||||
* physics and the photograph. */
|
||||
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. */
|
||||
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,
|
||||
lum, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ==================================================================================== the tree ===
|
||||
* Trunk, three limbs, a fork, and three billows of canopy.
|
||||
*
|
||||
* ---- IT DOES NOT SWAY, AND THE ARITHMETIC IS WHY ----------------------------------------------
|
||||
* A crown at 14 m subtends 2*3.2*colK/d = 63 columns (colK is 137.6 at 200 columns and fov 1.25)
|
||||
* with roughly 150 cells on its rim. A gentle 0.6 Hz sway of +/-0.12 m is +/-1.2 columns at that
|
||||
* range, so every one of those rim cells would alternate crown-against-sky at 1.2 Hz — with a
|
||||
* second harmonic at 2.4 and a third at 3.6, and the third one is inside the band — at a day
|
||||
* contrast of white at printed v ~200 against sky, i.e. about 70% of full scale. That is
|
||||
* catastrophic and it is exactly the shape jp_town.js:526-535 and west_town.js's windmill note
|
||||
* already describe. The tree is static.
|
||||
*
|
||||
* CC.reducedMotion therefore needs no branch here, and the house rule "damp or freeze, and say
|
||||
* which and why" is answered: this element is FROZEN, by construction, at every setting. There is
|
||||
* nothing in it that moves for a reduced-motion viewer to be spared.
|
||||
*
|
||||
* ---- THE TWO PLACEMENTS, ON ONE PROBE ---------------------------------------------------------
|
||||
* The heightmap is probed at face + side*0.8 — the first cell of the block, which is the idiom
|
||||
* every hanging object in jp_town.js uses:
|
||||
* THERE IS A BUILDING (hB > 1.2): the tree is a KERB tree, 1.35 m out from the frontage into
|
||||
* the carriageway. The toro sits at 0.85; a tree needs another half metre because its canopy
|
||||
* has to clear the eave the toro stands under. Trunk against the wall, crown over the street.
|
||||
* It is IN FRONT of the frontage plane, so nothing can occlude it and no clearance test is
|
||||
* needed or wanted — an earlier version of this design carried one and it did nothing but
|
||||
* delete trees that would have rendered fine.
|
||||
* THERE IS NOT (hB <= 1.2): the tree stands 3.2 m BACK inside the lot and the crown is seen
|
||||
* over the wall. This is the courtyard tree and it is viable only because a crown is TALL:
|
||||
* jp_town.js:108-115's courtyard failure was a ground object at 0-1.3 m behind a frontage,
|
||||
* where a crown at 4.5-7.5 m over a garden quarter whose own hMax is 5.0 projects into cells
|
||||
* the world pass left as SKY at dist Infinity, so CC.put takes it. Same mechanism as
|
||||
* structure.js's masts. This is the case with a real line-of-sight hazard, so it gets a SECOND
|
||||
* probe at the trunk's own cell 3.2 m in — the first probe only says the outer ring is clear,
|
||||
* and TH_JAPAN is setbackMode 'podium' with lots 5-9 m deep, so "outer ring clear" and
|
||||
* "trunk cell clear" are genuinely different questions.
|
||||
*/
|
||||
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);
|
||||
/* The same defensive cap the toro and the lanterns carry: a degenerate camera position must not
|
||||
* be able to ask for ten thousand slots. 2*TREE_R/TREE_PITCH is 7, so this only ever fires on
|
||||
* a NaN or an infinity coming out of the camera. */
|
||||
if (hi - lo > 10) hi = lo + 10;
|
||||
|
||||
/* THE TRUNK IS DRAWN AS BLACK MASS AND THAT IS FORCED BY THE PRINT LADDER, not chosen. Measured
|
||||
* through the shipped LUT at this exposure, `timber` prints v 118 at raw lum 246 and `indigo`
|
||||
* 102 — both UNDER the muddy band's ceiling of 120 — so there is no luminance of either swatch,
|
||||
* at any hour, that prints clean. A trunk is therefore either black or it is mud, and at raw
|
||||
* lum 5 timber prints v 7 and indigo v 2, which is black. Everything above about lum 6 lands in
|
||||
* the band: the first cut of this file drew the trunk at 116 (v 55) and measured 113 muddy
|
||||
* cells from the trunks alone in a single frame, more than the entire canopy contributed.
|
||||
*
|
||||
* It is also the better picture, which is the usual outcome when the ladder is right.
|
||||
* west_range.js's telegraph pole makes the identical call for the identical reason at its lines
|
||||
* 102-107 — by day a creosoted pole is DARK against a bright sky, and that inversion is what
|
||||
* makes it read at midday. A cherry trunk at noon against a lit street is a black stroke; at
|
||||
* night it is a black stroke against a dark one, and the crown above it is black too, which is
|
||||
* what surf_japan.js's lampAt says a 3-9 m object must be when the wash is zero above 3.6 m.
|
||||
* The glyph and swatch are kept rather than collapsing to shadow-at-zero so that a future
|
||||
* exposure pass which lifts the bottom of the ladder gets a trunk with grain in it. */
|
||||
var tlum = 4 + 2 * (1 - NIGHT) + 1 * DAYF;
|
||||
var tcol = NIGHT > 0.5 ? P.indigo : P.timber;
|
||||
|
||||
for (var side = -1; side <= 1; side += 2) {
|
||||
var face = faceOf(axis, idx, side);
|
||||
var back = face + side * 0.8;
|
||||
for (var k = lo; k <= hi; k++) {
|
||||
/* 4.0 m of jitter on a 12 m pitch, so the row is a scatter and not a colonnade. */
|
||||
var along = k * TREE_PITCH + hash2(k, side, BASE + 0x61) * 4.0;
|
||||
/* The decorrelation term is this file's neighbours' idiom — the toro uses
|
||||
* side*3 + (axis?5:0), the noren side*5 + (axis?2:0) — so the two sides of a street and the
|
||||
* two axes are independent rolls rather than four views of the same one. */
|
||||
if (hash2(k, side * 9 + (axis ? 4 : 0), BASE + 0x62) > TREE_ACCEPT) continue;
|
||||
|
||||
var bx = wxOf(axis, along, back), bz = wzOf(axis, along, back);
|
||||
var D = CITY.DISTRICTS && CITY.DISTRICTS[CITY.districtAt(bx, bz)];
|
||||
if (!D || TREE_OK[D.name] !== 1) continue;
|
||||
|
||||
var hB = CITY.height(bx, bz);
|
||||
var kerb = hB > 1.2;
|
||||
var cross = face + side * (kerb ? -1.35 : 3.2);
|
||||
var px = wxOf(axis, along, cross), pz = wzOf(axis, along, cross);
|
||||
/* The setback tree's second probe — see the placement note above. */
|
||||
if (!kerb && CITY.height(px, pz) > 1.2) continue;
|
||||
|
||||
/* 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. */
|
||||
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;
|
||||
if (sp < -lim || sp > lim) continue;
|
||||
|
||||
/* HEIGHT AND CROWN RADIUS SHARE ONE HASH, which saves a draw and is physically right: a
|
||||
* taller tree is a wider tree. th is 3.0-4.9 m of clear trunk — the lower bound is set by
|
||||
* lampAt's 3.6 m falloff (surf_japan.js:241-254) and by the eave, because a kerb tree
|
||||
* standing 1.35 m off a 2.9-5.0 m frontage needs its crown to start where the eave ends or
|
||||
* the canopy is inside the roof and CC.put deletes it. cr is 1.9-3.4 m, i.e. a crown 3.8 to
|
||||
* 6.8 m across against a 6-11 m street: the canopy meets the eaves on the far side, which is
|
||||
* 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;
|
||||
|
||||
/* ---- 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);
|
||||
|
||||
/* 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.
|
||||
*
|
||||
* 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
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
/* 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))
|
||||
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
|
||||
* 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. */
|
||||
if (w < 15) {
|
||||
if (project(px, th * 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))
|
||||
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, tcol, tlum, PJ.d);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- the near cut ----------------------------------------------------------------------
|
||||
* Trunk only inside CAN_NEAR. See the constant's own note: inside about nine metres the
|
||||
* whole crown is off the top of a 60-row frame and the loop is at its largest. */
|
||||
if (w < CAN_NEAR) continue;
|
||||
|
||||
/* ---- SEASON BY MIXTURE, BECAUSE THIS WORLD HAS NO SEASON CLOCK -------------------------
|
||||
* 82% of trees are in blossom and 18% are in leaf. A street where every tree is white is a
|
||||
* postcard — jp_town.js's header warns about exactly that failure mode with vermilion —
|
||||
* and four white with one green is spring.
|
||||
*
|
||||
* THE LEAF TREE IS DARK ON PURPOSE AND IT IS A MINORITY BECAUSE IT HAS TO BE. Measured
|
||||
* through the shipped LUT, `moss` prints v 100 at raw lum 246 and v 93 at night — both
|
||||
* UNDER the muddy band's ceiling of 120. So there is no luminance of moss, at any hour,
|
||||
* that prints clean: every VISIBLE moss cell is a muddy cell, and the only lever available
|
||||
* is how many of them there are. Hence 18% rather than the brief's 32%, x0.62 on the base,
|
||||
* and SH_LEAF raising the gap threshold so most of a leaf crown is black mass with a green
|
||||
* tint on the lit edge rather than a green fill. Measured, a leaf crown at 14 m contributes
|
||||
* 25-40 muddy cells where the brief's 32%-at-x0.72 version contributed roughly four times
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* NOT `spring`: core.js fits it as a district accent and west_range.js has already claimed
|
||||
* it as "the one living colour in the frame" out on the frontier. NOT `rose`: core.js
|
||||
* carries an explicit prohibition on it outside signage and screens, and someiyoshino reads
|
||||
* 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;
|
||||
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));
|
||||
|
||||
/* ---- THE CANOPY'S LUMINANCE ACROSS THE DAY ----------------------------------------
|
||||
* The only time dependence in this whole element is NIGHT, DAYF and LAMP, which are the
|
||||
* daylight director's minute-scale clock, and they are split the way drawToro and
|
||||
* drawNoren split theirs — a (1-NIGHT) ramp plus a DAYF top end — so the tree comes up
|
||||
* with the town rather than on a curve of its own.
|
||||
* NOON (NIGHT 0, DAYF 1): base 246. The crown-top core prints v ~200 in white, over
|
||||
* the hot line of 170, which is the entire census argument for this element.
|
||||
* DUSK (NIGHT 0, DAYF 0): base 180. surf_japan.js:143 makes dNight a smoothstep on
|
||||
* (0.30 - dSky)/0.30 and the director reports dSky 0.657 at the dusk stop, so dNight
|
||||
* is exactly 0 there and dFill exactly 0: the canopy is 180, not the 96 a naive
|
||||
* "NIGHT = 0.5" reading would give. Read off the director at all six stops, the
|
||||
* canopy base is dawn 180 / morning 237 / noon 246 / afternoon 237 / dusk 180 /
|
||||
* night 12 — dNight is a two-state quantity over almost the whole clock and the
|
||||
* canopy is never at any intermediate value. Dusk is the hour the element is worst
|
||||
* at: measured, its hot tail is 0.0% at every seed tried because `white` reaches only
|
||||
* v 191 at raw 246 on the dusk ladder and the tiers never leave it there. What it
|
||||
* does instead is black: 43-77% of its cells, and the frame's muddy share still moves
|
||||
* -0.79 to -1.28 points. Stated rather than dodged.
|
||||
* NIGHT (NIGHT 1, DAYF 0): base 12. The crown prints v 3-7 and is pure occluding mass.
|
||||
* That is not a compromise, it is what lampAt says: it is full below 1.0 m and exactly
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
* tree takes a warm lamp term, and only that one — never a setback tree, whose crown is
|
||||
* inside a garden with no lantern in it.
|
||||
*
|
||||
* IT IS GATED ON THE BILLOW'S UNDERSIDE, NOT ITS CENTRE, and that is a bug this file had
|
||||
* for one measured round. With th at 3.0-4.9 m and the billow centres at th + 0.44..0.80
|
||||
* of cr, a CENTRE is essentially never under lampAt's 3.6 m ceiling: the exception fired
|
||||
* on nothing and the night frame measured 100.0% black element cells at both seeds. The
|
||||
* UNDERSIDE of the lowest billow is at 2.5-3.4 m, which is the branch a lantern actually
|
||||
* lights. The falloff is lampAt's own shape (surf_japan.js:241-254) — full below, smooth-
|
||||
* stepped out, zero above — carried to 4.6 m rather than lampAt's 3.6 because lampAt is
|
||||
* modelling the wash on a WALL and a branch four metres up over a lantern at 2.12 m is
|
||||
* still visibly lit. 132 rather than 96 for the same reason the number had to move at
|
||||
* all: measured, warm on the NIGHT ladder needs raw lum ~150 to clear the muddy ceiling,
|
||||
* so a term that peaks at 108 could only ever have produced mud.
|
||||
*
|
||||
* THE COST IS BUDGETED AND IT IS THE ONE PLACE THIS ELEMENT ADDS MUD ON PURPOSE. Measured
|
||||
* pooled over eight night frames: seed 42 gives 0.4% of its cells muddy (its walk has few
|
||||
* kerb trees low enough), seed 7 gives 26.6%, which is 40-80 cells on the near tree and
|
||||
* 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 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. */
|
||||
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);
|
||||
|
||||
/* 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,
|
||||
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);
|
||||
}
|
||||
|
||||
/* ---- 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
|
||||
* spawns inside that radius spreads the drift slightly wider than the crown rather than
|
||||
* dropping a column of petals down one trunk. */
|
||||
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;
|
||||
FL.n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================================ registration ===
|
||||
* LAYER 18, which is free in this world: 16 is the torii, 17 the toro and the market, 19 the
|
||||
* lanterns, 20 the noren and street.js's crowd, 21 and 22 street.js and the blossom. The only
|
||||
* other element at 18 is street.js's foodstalls, which is world 'cyber' and is filtered out
|
||||
* before the layer sort, so no tie is created and main.js:157-164's readdirSync tie-break hazard
|
||||
* is not touched.
|
||||
*
|
||||
* IT DRAWS BEFORE THE BLOSSOM (18 < 22), which is what makes the anchor list this frame's rather
|
||||
* than last frame's for anything that reads it in draw(). A consumer that reads it from update()
|
||||
* gets the PREVIOUS frame's, because main.js runs every update() before every draw() — that is
|
||||
* one frame of staleness on a static object, i.e. none, and it is already this file's neighbour's
|
||||
* pattern (jp_town.js reads the previous frame's W_WIND for the same reason).
|
||||
*
|
||||
* ITS init() CONSUMES NO rng. main.js hands one shared generator to every element's init in layer
|
||||
* order, so an element that drew from it would shift the thirty draws jp-blossom makes and change
|
||||
* every fixture in the world. boot(city) draws nothing, so registering this element is neutral by
|
||||
* construction — the shared-init-rng trap closed rather than hoped about. */
|
||||
function mk(name, layer, fn) {
|
||||
return {
|
||||
name: name, layer: layer, world: 'japan',
|
||||
init: function (city) { boot(city); },
|
||||
draw: function (f, cam, t) {
|
||||
if (!CITY) return;
|
||||
view(f, cam, t === undefined ? (cam.t || 0) : t);
|
||||
fn(f);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
CC.ELEMENTS.push(mk('jp-sakura', 18, function (f) {
|
||||
/* The anchor list is rebuilt from empty every frame. A consumer must therefore tolerate n = 0 —
|
||||
* which happens whenever the walk is between eligible quarters — by falling back to whatever it
|
||||
* did before. A drift that emptied its pool instead would blink out every time the camera left
|
||||
* a garden. */
|
||||
FL.n = 0;
|
||||
/* Three street indices either way on both axes, the same reach the toro and the lanterns walk.
|
||||
* THERE IS NO WEATHER BRANCH, deliberately. jp_town.js's drift switches off above rain 0.35
|
||||
* because a petal drawn through several hundred cells of elements/weather.js's rain only
|
||||
* muddles it; a TREE is the thing the rain falls past, and a cherry that vanished in a squall
|
||||
* would take the street's whole silhouette with it. The wet air reaches it through Surf.fog
|
||||
* inside emit(), which is where it belongs. */
|
||||
var i;
|
||||
for (i = -1; i <= 1; i++) drawTrees(f, 0, nearIdx(0) + i);
|
||||
for (i = -1; i <= 1; i++) drawTrees(f, 1, nearIdx(1) + i);
|
||||
}));
|
||||
|
||||
})(typeof CC !== 'undefined' ? CC : require('../core.js'));
|
||||
688
src/elements/jp_town.js
Normal file
688
src/elements/jp_town.js
Normal file
|
|
@ -0,0 +1,688 @@
|
|||
/* CyberCity EDO street furniture — the objects that make the fourth world a place. Layers 16-22.
|
||||
*
|
||||
* WHAT THIS FILE IS FOR, and it is the same argument west_town.js and moon_craft.js make about
|
||||
* their own worlds. src/surf_japan.js paints every wall and every square metre of ground, and when
|
||||
* it is finished the street is correct and empty: timber, plaster, tile, wet earth, and the light
|
||||
* from behind the paper. What it cannot paint is anything that stands OFF a surface, because the
|
||||
* texture layer is handed (u, v) on a plane and has no camera, no depth and no world. Everything
|
||||
* this setting is actually remembered by is exactly that kind of object —
|
||||
*
|
||||
* THE LANTERN. A chochin hung under the eave, at 2.1 m, half a metre proud of the wall. It is
|
||||
* the source of surf_japan.js's whole lamp-wash lighting model, so drawing the wash without
|
||||
* ever drawing the lamp would be a world lit by nothing visible. It is also where this world's
|
||||
* highlights come from: measured before this file existed, a night frame censused 0.00% in the
|
||||
* print's hot tail against a 3.5-5% target, because the brightest thing in it was a paper
|
||||
* screen seen through fog. A lantern is the same light with nothing in front of it.
|
||||
* THE NOREN. The split curtain over a shop door. It is the one DARK object in a lit opening
|
||||
* — indigo cloth hung across the brightest cells on the elevation — and a dark shape in front
|
||||
* of a bright one is worth more to a frame at this resolution than any amount of extra light.
|
||||
* THE TORII. Two posts and two beams, vermilion, straddling the road at a temple. It is the
|
||||
* only thing in this world that crosses the street rather than lining it, and it is the single
|
||||
* most recognisable silhouette the setting has.
|
||||
* THE PETALS. Something that moves and is not weather. The frontier has one tumbleweed for
|
||||
* this reason and says so; this has a drift of blossom, and it is off in the rain.
|
||||
*
|
||||
* WHERE THE LIGHT COMES FROM. Every one of these reads SUN_X/SUN_Z off the painter registry
|
||||
* through src/proj.js's litFace(), never off CC.Daylight, for the reason surf_moon.js states at
|
||||
* length: the ground and the objects standing on it must have got their geometry from the same
|
||||
* place. Whether a lantern is BURNING is `CC.Daylight.P.lamp` and nothing else — the same single
|
||||
* number surf_japan.js's lamp wash reads, so the light on a wall and the lamp hanging in front of
|
||||
* it come up together to the frame. (An earlier cut multiplied that by a night crossfade of its
|
||||
* own in both files and put the whole town out an hour before dusk; the director already owns the
|
||||
* fade and the hysteresis.) `CC.SurfJapan.night` is read too, but only for things that are not
|
||||
* artificial light: how far a torii has gone to silhouette, how bright a stone lantern's own
|
||||
* masonry is, how a petal reads against the sky.
|
||||
*/
|
||||
(function (CC) {
|
||||
'use strict';
|
||||
|
||||
/* One projector per element — see src/proj.js. V and PJ are this element's own basis and
|
||||
* scratch; the four helpers are closed over them. */
|
||||
var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ;
|
||||
var project = PR.project, emit = PR.emit, column = PR.column, litFace = PR.litFace;
|
||||
|
||||
var P = CC.P, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise;
|
||||
|
||||
var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_TICK = CC.g('`'), G_COLON = CC.g(':'),
|
||||
G_EQ = CC.g('='), G_8 = CC.g('8'), G_O = CC.g('O'), G_o = CC.g('o');
|
||||
|
||||
/* Bound once per rebuild. `city.world`, never CC.World: between a keypress and the rebuild those
|
||||
* are two different answers and this file must agree with the map it is standing on. */
|
||||
var CITY = null, BASE = 0, JP = null;
|
||||
function boot(city) {
|
||||
CITY = (city && city.aveX && city.world === 'japan') ? city : null;
|
||||
BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 6) & 0x3fffff) : 0;
|
||||
JP = null;
|
||||
}
|
||||
|
||||
/* Per-frame caches. EVERY ONE OF THESE IS ASSIGNED INSIDE view(), which the contract asks for by
|
||||
* name after two frontier files were left holding their declared defaults and silently stopped
|
||||
* following the clock. */
|
||||
var W_RAIN = 0, W_WIND = 1, W_WET = 1, NIGHT = 1, LAMP = 1, DAYF = 0;
|
||||
function view(f, cam, t) {
|
||||
PR.view(f, cam, t);
|
||||
if (!JP) JP = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null;
|
||||
W_RAIN = CC.Weather ? CC.Weather.P.rain : 0;
|
||||
W_WIND = CC.Weather ? CC.Weather.rel('wind') : 1;
|
||||
W_WET = CC.Weather ? CC.Weather.rel('wet') : 1;
|
||||
NIGHT = (JP && JP.night !== undefined) ? JP.night : 1;
|
||||
DAYF = (JP && JP.dayFill !== undefined) ? JP.dayFill : 0;
|
||||
LAMP = CC.Daylight ? CC.Daylight.P.lamp : 1;
|
||||
}
|
||||
|
||||
/* Which street the camera is nearest, in either axis, and the two helpers that turn an
|
||||
* (along, cross) pair into world coordinates. Identical in shape to west_range.js's, because the
|
||||
* lattice they are indexing is the same lattice. */
|
||||
function wxOf(axis, along, cross) { return axis ? along : cross; }
|
||||
function wzOf(axis, along, cross) { return axis ? cross : along; }
|
||||
function nearIdx(axis) {
|
||||
return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE));
|
||||
}
|
||||
function centreOf(axis, idx) { return axis ? CITY.crossZ(idx) : CITY.aveX(idx); }
|
||||
function halfOf(axis, idx) { return axis ? CITY.crossW(idx) : CITY.aveW(idx); }
|
||||
/* WHERE THE CAMERA IS ALONG THE STREET, which is the OTHER axis from the one nearIdx reads and
|
||||
* is the distinction that had every lantern in this file placed two hundred metres up the wrong
|
||||
* road. An avenue is indexed by x and runs along z, so the index comes off V.ox and the walk
|
||||
* range comes off V.oz; a cross street is the transpose. west_range.js gets this right and reads
|
||||
* `axis ? V.ox : V.oz` — one axis apart from `nearIdx` directly above it, and nothing in either
|
||||
* function's name says so, which is why it is named here. */
|
||||
function alongOf(axis) { return axis ? V.ox : V.oz; }
|
||||
|
||||
/* WHERE THE WALL ACTUALLY IS, in world metres, on a given side of a given street. city.js's
|
||||
* colX() marks cells [c-hw, c+hw] as corridor, and a cell `g` covers world [g, g+1) — so the
|
||||
* building face on the +side is the plane x = c + hw + 1 and on the -side it is x = c - hw,
|
||||
* which is this one expression. Getting it wrong by a tenth of a metre is not a cosmetic error:
|
||||
* an object placed on the far side of that plane is INSIDE the building, and CC.put's depth test
|
||||
* removes it silently. Every hanging thing in this file is positioned relative to `faceOf` and
|
||||
* probes the heightmap at `faceOf + 0.8*side`, which is the first cell of the block. */
|
||||
function faceOf(axis, idx, side) {
|
||||
return centreOf(axis, idx) + 0.5 + side * (halfOf(axis, idx) + 0.5);
|
||||
}
|
||||
|
||||
/* Is there a building face here, and how tall is it? A lantern hangs off a WALL, so the probe is
|
||||
* the cell one step behind the frontage line — and it returns the height, because the eave the
|
||||
* lantern hangs under is at the top of it and a lantern nailed above its own roof is worse than
|
||||
* no lantern. */
|
||||
function wallH(axis, along, cross) {
|
||||
return CITY.height(wxOf(axis, along, cross), wzOf(axis, along, cross));
|
||||
}
|
||||
|
||||
/* ================================================================================= lanterns ===
|
||||
* A chochin every 2.4 m along both frontages of whichever street the camera is on, on the lots
|
||||
* that have a shop in them — which is to say wherever the map put a sign, plus a share of the
|
||||
* rest. The pitch is the one number here worth arguing about: at 4 m the street reads as
|
||||
* occasionally lit and at 1.5 m it reads as a festival. 2.4 is a lantern per shopfront bay and a
|
||||
* bit, which is what a photograph of a lit machi street shows.
|
||||
*
|
||||
* THE SHAPE IS FOUR CELLS AND IT HAS TO BE. A chochin is a vertical ellipse of ribbed paper with
|
||||
* a dark cap and base, and at 2.1 m up and 6 m away that is about two cells wide and three tall.
|
||||
* So it is drawn as an explicit little sprite rather than through column(): a bright core, a
|
||||
* darker rib down each side, and one cell of black at each end. The black ends are what make it
|
||||
* an OBJECT — a warm blob with no cap reads as a window.
|
||||
*
|
||||
* THE FLAME. Every lit thing in this project is gated by the photosensitivity rule — nothing
|
||||
* above 2% of full scale between 3 and 20 Hz — and a flame is the obvious way to break it. This
|
||||
* one is a single vnoise sampled at 0.55 Hz with a 9% swing, so its whole spectrum sits an octave
|
||||
* and a half BELOW the danger band and its amplitude would be legal even inside it. A candle in
|
||||
* a paper box is heavily damped by the paper anyway: what you see move is the glow, not the
|
||||
* flame, and it moves slowly.
|
||||
*
|
||||
* THE HALO. Two cells of dim warm either side, in wet weather only. That is not a bloom (the
|
||||
* canvas does its own) — it is the air: rain and river mist round a lamp is the reason this
|
||||
* world's `steam` never drops below 0.44, and a lamp with no halo in a downpour reads as a hole
|
||||
* cut in the frame rather than as a light in it. */
|
||||
var LAN_PITCH = 2.4, LAN_Y = 2.12, LAN_OUT = 0.42;
|
||||
|
||||
function drawLanterns(f, axis, idx) {
|
||||
var here = alongOf(axis);
|
||||
var lo = Math.floor((here - 46) / LAN_PITCH), hi = Math.floor((here + 46) / LAN_PITCH);
|
||||
if (hi - lo > 40) hi = lo + 40;
|
||||
/* Off by day, and by DAYF rather than by a hard test on the hour: a street that puts every
|
||||
* lantern out on one frame is the large-area step the whole project's flicker rule is about.
|
||||
* A paper lantern in daylight is still THERE, so it does not vanish — it goes to the pale
|
||||
* unlit sand-coloured bag it actually is. */
|
||||
/* LAMP alone — see surf_japan.js's lampAt, which had this same bug and the same fix. The
|
||||
* director's `lamp` already has the hysteresis; a second night crossfade over the top of it
|
||||
* puts the lanterns out an hour before dusk. */
|
||||
var lampK = LAMP;
|
||||
|
||||
for (var side = -1; side <= 1; side += 2) {
|
||||
var face = faceOf(axis, idx, side);
|
||||
var cross = face - side * 0.45; // hung half a metre proud of the wall
|
||||
var back = face + side * 0.8; // one step into the block: the wall itself
|
||||
for (var k = lo; k <= hi; k++) {
|
||||
var along = k * LAN_PITCH + hash2(k, side, BASE + 0x11) * 0.7;
|
||||
var h = wallH(axis, along, back);
|
||||
if (h < 2.9) continue; // no wall, or too low to hang one under
|
||||
var r = hash2(k, side * 7 + (axis ? 3 : 0), BASE + 0x12);
|
||||
if (r > 0.52) continue;
|
||||
var px = wxOf(axis, along, cross), pz = wzOf(axis, along, cross);
|
||||
/* Hung just under the eave, but never higher than the wall it is on. */
|
||||
var y = LAN_Y + hash2(k, side, BASE + 0x13) * 0.30;
|
||||
if (y > h - 0.9) y = h - 0.9;
|
||||
if (y < 1.5) continue;
|
||||
|
||||
if (!project(px, y, pz)) continue;
|
||||
var x = Math.floor(PJ.x), yy = Math.floor(PJ.y), d = PJ.d;
|
||||
if (x < -3 || x >= V.cols + 3) continue;
|
||||
|
||||
/* Its apparent size, from the same projection the caster uses: a 0.30 m body. */
|
||||
var rw = 0.15 * V.colK / d, rh = 0.24 * V.scale / d;
|
||||
|
||||
var flick = CC.reducedMotion ? 1
|
||||
: 0.955 + 0.09 * vnoise(t0 * 0.55 + k * 3.7 + side * 1.9, BASE & 0xffff);
|
||||
/* ---- THE AKACHOCHIN, AND IT IS THE BEST THREE LINES IN THIS WORLD ------------------------
|
||||
* Three lanterns in ten are papered RED, which is the mark of a place that sells food and
|
||||
* drink and is the one piece of saturated colour an Edo street reliably had. It is also,
|
||||
* measured, the single best print trade in the tree.
|
||||
*
|
||||
* WHY `red` AND NOT `ember`, and it is core.js's ladder() rule rather than a taste. ladder()
|
||||
* splits the palette on "does it EMIT": sources — amber, azure, warm, ice, jade, rose, gold,
|
||||
* red — blend along the sun curve, surfaces blend along the sky curve. An akachochin is a
|
||||
* red LAMP (core.js's own gloss on slot 6 is "aerial lamps, stop signals"), so red is the
|
||||
* correct half of the table. A piece of dyed CLOTH in the same colour is `ember`, on the
|
||||
* other curve — which is why the banners in jp_banner.js use ember and this does not.
|
||||
*
|
||||
* AND IT IS WRITTEN DIMMER AND PRINTS HOTTER, which is the ladder doing its job rather than
|
||||
* the paint lying. Red paper over the same candle is materially dimmer than white, so the
|
||||
* luminance is scaled by 0.90 — and core.js gives red a night gain of 0.56 against warm's
|
||||
* 0.32, so the red lantern goes in at 198 against 220 and comes out of the print at v 183
|
||||
* against v 154. Measured on the seed 42 night frame: 72 of 181 lantern cells repaint, the
|
||||
* core and rib cells cross the print's hot line (v 157 -> 185, v 144 -> 173), and the census
|
||||
* moves hot 0.38% -> 0.69% and muddy 38.6% -> 38.3%. Those are the first non-`pure` hot
|
||||
* cells this world has ever had.
|
||||
*
|
||||
* THE SHARE IS CAPPED AT 0.30 ON PURPOSE. Each ten points is worth about +0.07 points of hot
|
||||
* tail, and red is the only swatch here that can outrank the paper shopfronts the world's
|
||||
* whole lighting model is built on. Past about 0.35 the lanterns start to lead the frame.
|
||||
* Rendered through topng.py at 0.30 it reads as red lanterns rather than as pink, so the
|
||||
* magenta-bloom failure that walked `violet` off hue 288 is not reproduced. */
|
||||
var red = hash2(k, side * 11 + (axis ? 1 : 0), BASE + 0x15) < 0.30;
|
||||
var warm = (196 + 44 * hash2(k, side, BASE + 0x14)) * (red ? 0.90 : 1);
|
||||
var lum = lampK > 0.02 ? warm * lampK * flick : 0;
|
||||
var col = lampK > 0.02 ? (red ? P.red : P.warm) : P.sand;
|
||||
if (lum < 6) lum = 26 + 60 * DAYF; // unlit: a pale bag under the eave
|
||||
|
||||
/* The cord and the cap. One cell of nothing above the body is what stops it floating. */
|
||||
if (project(px, y + 0.34, pz))
|
||||
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, P.timber, 22 + 40 * DAYF, PJ.d);
|
||||
|
||||
if (rw < 0.7) { emit(f, x, yy, G_o, col, lum, d); }
|
||||
else {
|
||||
var iw = rw < 1.4 ? 1 : 2, ih = rh < 1.2 ? 1 : (rh < 2.4 ? 2 : 3), dx, dy;
|
||||
for (dy = -ih; dy <= ih; dy++) for (dx = -iw; dx <= iw; dx++) {
|
||||
var uq = dx / (iw + 0.35), vq = dy / (ih + 0.35);
|
||||
if (uq * uq + vq * vq > 1.05) continue;
|
||||
/* The ribs. A chochin is a spiral of split bamboo under the paper and it prints as
|
||||
* horizontal banding, so the glyph alternates by ROW rather than being one fill. */
|
||||
var rib = ((dy + 64) & 1) === 0;
|
||||
var edge = uq * uq + vq * vq > 0.55;
|
||||
emit(f, x + dx, yy + dy, edge ? G_COLON : (rib ? G_EQ : G_8),
|
||||
col, lum * (edge ? 0.52 : (rib ? 0.86 : 1)), d);
|
||||
}
|
||||
/* Cap and base: black, always, at both ends. */
|
||||
emit(f, x, yy - ih - 1, G_DASH, P.shadow, 0, d);
|
||||
emit(f, x, yy + ih + 1, G_DASH, P.timber, 30 * (0.4 + DAYF), d);
|
||||
/* THE CORE, one cell, and it is the only `pure` in this world. surf_japan.js's header
|
||||
* carries the arithmetic: at night the print's hot line is v 170 and `warm` — the swatch
|
||||
* a paper lantern is materially made of — tops out at 167, so a town lit entirely by
|
||||
* lanterns censused 0.00% in the hot tail with two hundred cells of lantern in the frame.
|
||||
* The paper directly over a flame is blown out in every photograph of one ever taken,
|
||||
* which is what core.js's "specular hits only, use sparingly" describes, and one cell per
|
||||
* near lantern is as sparing as it is possible to be. Gated on the lamp being lit and on
|
||||
* the lantern being resolved at all, so a distant one never gets a white pixel in it. */
|
||||
if (lampK > 0.4 && rw > 0.7)
|
||||
emit(f, x, yy, G_8, P.pure, lum * 0.86, d);
|
||||
}
|
||||
|
||||
/* The halo in wet air. Two cells out, dim, and only where the frame is not already full. */
|
||||
if (lum > 40 && W_WET > 0.5) {
|
||||
var hk = clamp((W_WET - 0.5) * 0.9, 0, 0.5);
|
||||
for (var q = -2; q <= 2; q++) {
|
||||
if (q === 0) continue;
|
||||
/* `col`, not P.warm: the air scatters the lamp's own colour, so a red lantern gets a
|
||||
* red halo. Costs nothing — it is the same expression with a shorter name in it. */
|
||||
emit(f, x + q, yy, G_TICK, col, lum * hk * 0.16, d + 0.01);
|
||||
emit(f, x, yy + q, G_TICK, col, lum * hk * 0.13, d + 0.01);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ==================================================================================== noren ===
|
||||
* The split curtain hung across a shop doorway: two or three panels of indigo-dyed cloth from
|
||||
* about 1.9 m down to 1.1 m, with gaps you can see the lit interior through.
|
||||
*
|
||||
* IT IS DRAWN AS A HOLE, NOT AS A THING. The cells are written dark over whatever the wall behind
|
||||
* them is — which, at a shopfront, is surf_japan.js's paper panel at the top of the ladder — so
|
||||
* what the frame gains is a silhouette of hanging cloth against light. That is the entire object,
|
||||
* it costs about twenty cells, and it is the cheapest identity in this file.
|
||||
*
|
||||
* THE HEM MOVES. A noren hangs free at the bottom and the draught off the street lifts it, so the
|
||||
* bottom row is offset by a slow noise per panel. The rate is deliberately under 1 Hz for the
|
||||
* same photosensitivity reason the lantern's flame is, and the amplitude is a fraction of a cell
|
||||
* — this is a shape moving, not a luminance flashing, which is the distinction the gate cares
|
||||
* about. */
|
||||
var NOREN_TOP = 1.92, NOREN_BOT = 1.06, NOREN_PITCH = 5.4;
|
||||
|
||||
function drawNoren(f, axis, idx) {
|
||||
var here = alongOf(axis);
|
||||
var lo = Math.floor((here - 34) / NOREN_PITCH), hi = Math.floor((here + 34) / NOREN_PITCH);
|
||||
if (hi - lo > 16) hi = lo + 16;
|
||||
|
||||
for (var side = -1; side <= 1; side += 2) {
|
||||
var wall = faceOf(axis, idx, side);
|
||||
var face = wall - side * 0.14; // the cloth hangs against the frontage
|
||||
var back = wall + side * 0.8;
|
||||
for (var k = lo; k <= hi; k++) {
|
||||
var along = k * NOREN_PITCH + hash2(k, side, BASE + 0x21) * 2.2;
|
||||
if (wallH(axis, along, back) < 3.2) continue;
|
||||
if (hash2(k, side * 5 + (axis ? 2 : 0), BASE + 0x22) > 0.46) continue;
|
||||
|
||||
/* Three panels over 1.3 m of doorway, each 0.34 m wide with a finger of gap between. */
|
||||
var np = 3, w = 0.40;
|
||||
for (var pi = 0; pi < np; pi++) {
|
||||
var off = (pi - (np - 1) * 0.5) * w;
|
||||
var a = along + off;
|
||||
var sway = CC.reducedMotion ? 0
|
||||
: vnoise(t0 * 0.7 + k * 2.3 + pi * 0.9, BASE + 0x23) * 0.10 * (0.4 + W_WIND);
|
||||
/* A dyed cloth is the darkest thing on a lit frontage and the crest at the top is the
|
||||
* one part of it that catches the lamp inside — which is why the top row is drawn a
|
||||
* shade up and in `stone` rather than in the cloth's own indigo. */
|
||||
column(f, wxOf(axis, a, face), wzOf(axis, a, face),
|
||||
NOREN_BOT + sway, NOREN_TOP, G_PIPE, P.indigo,
|
||||
(26 + 54 * LAMP) + 40 * DAYF, 0);
|
||||
if (project(wxOf(axis, a, face), NOREN_TOP + 0.04, wzOf(axis, a, face)))
|
||||
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, P.stone,
|
||||
54 + 70 * LAMP + 60 * DAYF, PJ.d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ==================================================================================== torii ===
|
||||
* Two posts, a curved lintel, a straight tie-beam under it, and it straddles the road. Placed at
|
||||
* a cross-street mouth in a `temple` quarter and nowhere else, which is both correct and rare —
|
||||
* a torii marks an approach, and one on every corner would be wallpaper.
|
||||
*
|
||||
* THE CURVE IS THE RECOGNITION and it is four extra samples. A straight top beam is a football
|
||||
* goal; the kasagi rises toward its ends, and drawing it as a shallow arc sampled along its
|
||||
* length is what makes the silhouette read at forty metres in a frame made of characters. It is
|
||||
* sampled in WORLD space and projected per sample, exactly as west_range.js's catenary is, so it
|
||||
* takes the perspective for free.
|
||||
*
|
||||
* VERMILION IS SPENT HERE. city.js's district table holds `ember` to one quarter at a mixP of
|
||||
* 0.42 precisely so that this object can be the red thing in the frame — and it still gets a
|
||||
* lit face and a shaded face off litFace(), because a painted post in flat light is not one
|
||||
* flat colour and the whole point of the shape is that it is round. */
|
||||
var TORII_H = 4.6;
|
||||
|
||||
function drawTorii(f, axis, idx) {
|
||||
var c = centreOf(axis, idx), hw = halfOf(axis, idx);
|
||||
/* Where the cross streets cut this one — the mouths are the only places a gate can stand. */
|
||||
var oIdx = nearIdx(axis ? 0 : 1);
|
||||
for (var m = oIdx - 1; m <= oIdx + 1; m++) {
|
||||
var along = centreOf(axis ? 0 : 1, m) + 0.5;
|
||||
var px0 = wxOf(axis, along, c + 0.5), pz0 = wzOf(axis, along, c + 0.5);
|
||||
var di = CITY.districtAt(px0, pz0);
|
||||
var D = CITY.DISTRICTS && CITY.DISTRICTS[di];
|
||||
if (!D || D.name !== 'temple') continue;
|
||||
if (hash2(m, idx, BASE + 0x31) > 0.40) continue;
|
||||
|
||||
/* The posts stand at the very edge of the carriageway, not beyond it: a torii is a gate
|
||||
* across a road, and posts set back into the frontage would both be occluded by the wall and
|
||||
* stop the thing straddling anything. */
|
||||
var span = hw + 0.35;
|
||||
var lit = litFace(axis ? 1 : 0, axis ? 0 : 1);
|
||||
var shd = litFace(axis ? -1 : 0, axis ? 0 : -1);
|
||||
var base = 96 + 120 * (lit > shd ? lit : shd) * (0.35 + 0.65 * (1 - NIGHT));
|
||||
/* At night it is lit by the lanterns on the approach rather than by the sky, so it keeps a
|
||||
* floor — a black torii is a torii nobody can see, and this is the object the quarter is
|
||||
* for. */
|
||||
if (base < 84) base = 84;
|
||||
|
||||
var s;
|
||||
for (s = -1; s <= 1; s += 2) {
|
||||
var cx = c + 0.5 + s * span;
|
||||
column(f, wxOf(axis, along, cx), wzOf(axis, along, cx), 0, TORII_H,
|
||||
G_PIPE, P.ember, base, 1);
|
||||
}
|
||||
/* The nuki — the straight tie-beam, at four fifths height. */
|
||||
var i, N = 22;
|
||||
for (i = 0; i <= N; i++) {
|
||||
var q = i / N, cxx = c + 0.5 + (q * 2 - 1) * span;
|
||||
if (project(wxOf(axis, along, cxx), TORII_H * 0.80, wzOf(axis, along, cxx)))
|
||||
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, P.ember, base * 0.86, PJ.d);
|
||||
/* The kasagi: the same sweep 0.55 m higher, rising 0.42 m toward each end. */
|
||||
var ky = TORII_H + 0.42 * (2 * q - 1) * (2 * q - 1);
|
||||
if (project(wxOf(axis, along, cxx), ky, wzOf(axis, along, cxx)))
|
||||
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_EQ, P.ember, base, PJ.d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================================ stone lantern ===
|
||||
* A toro standing against the wall on a temple approach or outside a compound: a squat stone
|
||||
* pedestal, a fire box with a small warm eye in it, and a wide cap. It is the counterpart to the
|
||||
* chochin — the same light in stone rather than paper, standing on the ground rather than hung —
|
||||
* and it is what gives the quiet quarters something of their own after dark.
|
||||
*
|
||||
* IT IS PLACED ALONG THE STREET AND NOT ON A LATTICE, and that is the third and last version of
|
||||
* this placement. The first two scattered candidates on a 2D lattice the way west_range.js
|
||||
* scatters brush, which is right for open country and wrong here for two compounding reasons:
|
||||
* this world's open ground is mostly INSIDE a block (so the frontage occludes it), and the thin
|
||||
* strip where it is not is a small fraction of a lattice cell's area (so almost nothing lands in
|
||||
* it). Walking the street the way the lanterns above do puts the object exactly where it can be
|
||||
* seen, at a rate that is a pitch rather than an area fraction, for less code. */
|
||||
var TORO_PITCH = 7.4;
|
||||
var ISH_OK = { garden: 1, temple: 1, kura: 1, castle: 1 };
|
||||
|
||||
function drawToro(f, axis, idx) {
|
||||
var here = alongOf(axis);
|
||||
var lo = Math.floor((here - 40) / TORO_PITCH), hi = Math.floor((here + 40) / TORO_PITCH);
|
||||
if (hi - lo > 14) hi = lo + 14;
|
||||
var lampK = LAMP;
|
||||
|
||||
for (var side = -1; side <= 1; side += 2) {
|
||||
var face = faceOf(axis, idx, side);
|
||||
var cross = face - side * 0.85; // against the wall, inside the carriageway
|
||||
var back = face + side * 0.8;
|
||||
for (var k = lo; k <= hi; k++) {
|
||||
var along = k * TORO_PITCH + hash2(k, side, BASE + 0x41) * 2.6;
|
||||
if (hash2(k, side * 3 + (axis ? 5 : 0), BASE + 0x42) > 0.40) continue;
|
||||
var px = wxOf(axis, along, cross), pz = wzOf(axis, along, cross);
|
||||
var D = CITY.DISTRICTS && CITY.DISTRICTS[CITY.districtAt(wxOf(axis, along, back),
|
||||
wzOf(axis, along, back))];
|
||||
if (!D || ISH_OK[D.name] !== 1) continue;
|
||||
|
||||
var sun = litFace(0, 1);
|
||||
var scol = sun > 0.55 ? P.stone : P.indigo;
|
||||
var slum = (26 + 132 * sun) * (0.30 + 0.70 * (1 - NIGHT)) + 20;
|
||||
column(f, px, pz, 0, 0.70, G_O, scol, slum, 0); // the pedestal
|
||||
column(f, px, pz, 1.04, 1.32, G_EQ, scol, slum * 1.15, 1); // the cap
|
||||
/* The fire box, and the eye in it. One cell, warm, and it is the whole reason the object is
|
||||
* here — a stone lantern that is not lit is a bollard. */
|
||||
if (project(px, 0.90, pz))
|
||||
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), lampK > 0.1 ? G_o : G_COLON,
|
||||
lampK > 0.1 ? P.warm : scol,
|
||||
lampK > 0.1 ? (146 + 64 * lampK) * lampK : slum * 0.7, PJ.d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* =================================================================================== bridge ===
|
||||
* A taiko-bashi, the drum bridge, where an avenue crosses the canal. Hiroshige drew this object
|
||||
* more than any other in the setting and it is the single most recognisable silhouette it has.
|
||||
*
|
||||
* IT IS ALSO NOT DECORATION. city.js's river branch floods the avenue — deliberately, because a
|
||||
* coping across the road would be a wall the route walks into — so without this element the walk
|
||||
* crosses nine metres of open water on nothing at all. The deck is what the walk is standing on.
|
||||
*
|
||||
* THE ARCH IS THE WHOLE RECOGNITION and it is four extra samples, exactly as the torii's kasagi
|
||||
* is above. A flat deck with rails is a jetty; a deck that RISES to a crown and comes down again
|
||||
* is a drum bridge, and at character resolution the rise is the only thing carrying it. The rail
|
||||
* runs 1.25 m at the abutments to 1.80 m at the crown — ABOVE the 1.66 m eye, which is what puts
|
||||
* it on the silhouette against the far bank instead of lying flat on the water.
|
||||
*
|
||||
* THE DECK IS DRAWN BEFORE THE RAIL AND AT A SLIGHTLY NEARER DEPTH, because CC.put's depth test
|
||||
* is strict and a deck plank and a rail post that land on one cell at one distance is the
|
||||
* contention that cost the banners their flicker margin.
|
||||
*
|
||||
* NOTHING HERE MOVES. There is no t term anywhere in this element: a bridge is a static object
|
||||
* and the only reason its cells ever change is the camera walking, which no gate measures and
|
||||
* which is bounded by the walk's own 1.6 m/s. That is the cheapest possible photosensitivity
|
||||
* story and it is worth having on the one object that spans the whole frame. */
|
||||
var BR_SPAN = 5.6, BR_RISE = 0.55, BR_N = 30;
|
||||
|
||||
function drawBridge(f, axis, idx) {
|
||||
if (!CITY.rivD) return;
|
||||
var c = centreOf(axis, idx), hw = halfOf(axis, idx);
|
||||
var here = alongOf(axis);
|
||||
/* Where this street crosses the channel: march the channel's own distance function along the
|
||||
* street from the camera and take the zero. Cheaper and more robust than inverting the meander,
|
||||
* and it lands on the right crossing when several are in range. */
|
||||
var cx0 = c + 0.5, best = -1, bd = 1e9, a;
|
||||
for (a = here - 120; a < here + 120; a += 2) {
|
||||
var dd = CITY.rivD(wxOf(axis, a, cx0), wzOf(axis, a, cx0));
|
||||
if (dd < bd) { bd = dd; best = a; }
|
||||
}
|
||||
if (best < 0 || bd > 3.0) return;
|
||||
|
||||
var half = hw + 0.5; // the deck spans the carriageway, kerb to kerb
|
||||
var lit = litFace(0, 1);
|
||||
/* indigo after dark and timber by day, which is the same pair surf_japan's own SHD
|
||||
* table resolves timber to — spelled out here because that table is private to the painter. */
|
||||
var wood = NIGHT > 0.5 ? P.indigo : P.timber;
|
||||
/* THE DECK IS IN THE LAMP WASH AND MUST SAY SO. It sits at 0.30-0.85 m, which is inside the
|
||||
* band where surf_japan's lampAt() is the identity — the brightest strip in this whole world
|
||||
* after dark. Lit by the sky term alone the bridge came out at a printed luminance of 49 and
|
||||
* read as a smudge over the water; the lantern term is what makes it the thing you can see you
|
||||
* are about to walk across. Zero at noon, so the daylight scale stays the identity. */
|
||||
var base = 26 + 150 * lit * (0.35 + 0.65 * (1 - NIGHT)) + 40 * DAYF + 96 * LAMP;
|
||||
var i, q, y;
|
||||
/* The deck. Sampled across the span in the ALONG axis so the planks run across the bridge,
|
||||
* which is what carries the arch — a plank line at constant `a` converges to the same vanishing
|
||||
* point the street does. */
|
||||
for (i = 0; i <= BR_N; i++) {
|
||||
q = i / BR_N;
|
||||
y = 0.30 + BR_RISE * (1 - (2 * q - 1) * (2 * q - 1));
|
||||
var aa = best + (q * 2 - 1) * BR_SPAN;
|
||||
column(f, wxOf(axis, aa, cx0 - half), wzOf(axis, aa, cx0 - half), y - 0.22, y,
|
||||
G_EQ, wood, base, 0);
|
||||
column(f, wxOf(axis, aa, cx0 + half), wzOf(axis, aa, cx0 + half), y - 0.22, y,
|
||||
G_EQ, wood, base, 0);
|
||||
if (project(wxOf(axis, aa, cx0), y, wzOf(axis, aa, cx0)))
|
||||
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_EQ, wood, base * 0.86, PJ.d - 0.02);
|
||||
}
|
||||
/* The two rails, and the posts under them. Vermilion on a temple approach and plain timber
|
||||
* everywhere else — the same one-quarter-gets-the-lacquer rule the torii follows. */
|
||||
var D = CITY.DISTRICTS && CITY.DISTRICTS[CITY.districtAt(wxOf(axis, best, cx0),
|
||||
wzOf(axis, best, cx0))];
|
||||
var rc = (D && D.name === 'temple') ? P.ember : wood;
|
||||
var rl = (D && D.name === 'temple') ? base * 1.25 + 30 : base;
|
||||
for (i = 0; i <= BR_N; i++) {
|
||||
q = i / BR_N;
|
||||
y = 0.30 + BR_RISE * (1 - (2 * q - 1) * (2 * q - 1));
|
||||
var ab = best + (q * 2 - 1) * BR_SPAN;
|
||||
var ry = y + 0.95 + 0.55 * (1 - (2 * q - 1) * (2 * q - 1));
|
||||
for (var sd2 = -1; sd2 <= 1; sd2 += 2) {
|
||||
var rx = cx0 + sd2 * half;
|
||||
if (project(wxOf(axis, ab, rx), ry, wzOf(axis, ab, rx)))
|
||||
emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_EQ, rc, rl, PJ.d - 0.03);
|
||||
/* A post every fifth sample, from the deck to the rail. */
|
||||
if (i % 5 === 0)
|
||||
column(f, wxOf(axis, ab, rx), wzOf(axis, ab, rx), y, ry, G_PIPE, rc, rl * 0.78, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================================== blossom ===
|
||||
* A drift of petals, and it is this world's tumbleweed: the one thing in the frame that moves and
|
||||
* is not weather. west_range.js argues the case for having exactly one such object and the
|
||||
* argument holds here — a still frame of a wet street is a photograph, and a photograph is not
|
||||
* what this piece is.
|
||||
*
|
||||
* IT IS OFF IN THE RAIN, which is the whole of its weather logic and is not a dodge. Blossom
|
||||
* comes down on a still spring day and it comes down in a wind; in a squall it is on the ground
|
||||
* inside a minute, and elements/weather.js is already drawing several hundred cells of rain that
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
* an rng — so the offline harness at frame 9000 gets the browser's frame 9000. */
|
||||
var NPET = 30;
|
||||
var pX = null, pY = null, pZ = null, pPh = null, pVy = null, pSp = null, pLife = null;
|
||||
|
||||
function respawn(i, r) {
|
||||
var a = r * 6.2832;
|
||||
/* 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. */
|
||||
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;
|
||||
pPh[i] = r * 6.2832;
|
||||
pVy[i] = 0.32 + r * 0.36; // terminal velocity of a petal, near enough
|
||||
pSp[i] = 0.7 + r * 1.1;
|
||||
pLife[i] = 7 + r * 9;
|
||||
}
|
||||
|
||||
var t0 = 0;
|
||||
|
||||
function mk(name, layer, fn) {
|
||||
return {
|
||||
name: name, layer: layer, world: 'japan',
|
||||
init: function (city) { boot(city); },
|
||||
draw: function (f, cam, t) {
|
||||
if (!CITY) return;
|
||||
t0 = t === undefined ? (cam.t || 0) : t;
|
||||
view(f, cam, t0);
|
||||
fn(f);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/* Layer 14: below the torii at 16 and the keep at 15, because a bridge is the thing everything
|
||||
* else on the crossing stands in front of. */
|
||||
CC.ELEMENTS.push(mk('jp-bridge', 14, function (f) {
|
||||
var i;
|
||||
for (i = -1; i <= 1; i++) drawBridge(f, 0, nearIdx(0) + i);
|
||||
for (i = -1; i <= 1; i++) drawBridge(f, 1, nearIdx(1) + i);
|
||||
}));
|
||||
CC.ELEMENTS.push(mk('jp-torii', 16, function (f) {
|
||||
var i;
|
||||
for (i = -1; i <= 1; i++) drawTorii(f, 0, nearIdx(0) + i);
|
||||
for (i = -1; i <= 1; i++) drawTorii(f, 1, nearIdx(1) + i);
|
||||
}));
|
||||
CC.ELEMENTS.push(mk('jp-stonelantern', 17, function (f) {
|
||||
var i;
|
||||
for (i = -1; i <= 1; i++) drawToro(f, 0, nearIdx(0) + i);
|
||||
for (i = -1; i <= 1; i++) drawToro(f, 1, nearIdx(1) + i);
|
||||
}));
|
||||
CC.ELEMENTS.push(mk('jp-lanterns', 19, function (f) {
|
||||
var i;
|
||||
for (i = -1; i <= 1; i++) drawLanterns(f, 0, nearIdx(0) + i);
|
||||
for (i = -1; i <= 1; i++) drawLanterns(f, 1, nearIdx(1) + i);
|
||||
}));
|
||||
CC.ELEMENTS.push(mk('jp-noren', 20, function (f) {
|
||||
var i;
|
||||
for (i = -1; i <= 1; i++) drawNoren(f, 0, nearIdx(0) + i);
|
||||
for (i = -1; i <= 1; i++) drawNoren(f, 1, nearIdx(1) + i);
|
||||
}));
|
||||
|
||||
CC.ELEMENTS.push({
|
||||
name: 'jp-blossom',
|
||||
layer: 22,
|
||||
world: 'japan',
|
||||
init: function (city, rng) {
|
||||
boot(city);
|
||||
pX = new Float64Array(NPET); pY = new Float64Array(NPET); pZ = new Float64Array(NPET);
|
||||
pPh = new Float64Array(NPET); pVy = new Float64Array(NPET); pSp = new Float64Array(NPET);
|
||||
pLife = new Float64Array(NPET);
|
||||
/* Placed relative to the map's start rather than to the camera: init() runs before the first
|
||||
* camera update and V is still zeroed. */
|
||||
V.ox = city && city.startX !== undefined ? city.startX : 0;
|
||||
V.oz = city && city.startZ !== undefined ? city.startZ : 0;
|
||||
for (var i = 0; i < NPET; i++) respawn(i, rng());
|
||||
},
|
||||
update: function (dt, t, cam) {
|
||||
if (!CITY) return;
|
||||
V.ox = cam.x; V.oz = cam.z;
|
||||
var damp = CC.reducedMotion ? 0.3 : 1;
|
||||
var gust = 0.5 + 1.1 * W_WIND;
|
||||
for (var i = 0; i < NPET; i++) {
|
||||
pLife[i] -= dt;
|
||||
/* A petal does not fall, it SLIPS: it slides sideways, stalls, and slides the other way,
|
||||
* which is what the phase term is. The horizontal motion is the same order as the vertical
|
||||
* and that ratio is the whole read — anything that drops straight down is snow. */
|
||||
pPh[i] += dt * pSp[i] * damp;
|
||||
pY[i] -= pVy[i] * dt * damp;
|
||||
pX[i] += Math.cos(pPh[i]) * 0.42 * dt * gust * damp;
|
||||
pZ[i] += (Math.sin(pPh[i] * 0.7) * 0.30 + 0.22) * dt * gust * damp;
|
||||
var dx = pX[i] - cam.x, dz = pZ[i] - cam.z;
|
||||
if (pY[i] < 0.05 || pLife[i] < 0 || dx * dx + dz * dz > 1600)
|
||||
respawn(i, hash2(i, (t * 2) | 0, BASE + 0x51));
|
||||
}
|
||||
},
|
||||
draw: function (f, cam, t) {
|
||||
if (!CITY) return;
|
||||
t0 = t === undefined ? (cam.t || 0) : t;
|
||||
view(f, cam, t0);
|
||||
if (W_RAIN > 0.35) return;
|
||||
/* NOT DRAWN UNDER REDUCED MOTION, rather than damped. The house rule is "damp or freeze", and
|
||||
* for most elements damping is the right half of it — a slower rain is still rain. This one
|
||||
* is different in kind: a drift of blossom IS the motion, and thirty petals frozen in
|
||||
* mid-air are not a quieter version of it, they are a scatter of dots hanging in the sky.
|
||||
* Damping it also does not make it safe, which is the measured half of this note: at the
|
||||
* 0.3 factor the frontier's tumbleweed uses, the petals still crossed cells about four times
|
||||
* a second and tools/west-flicker.cjs scored the world 90 big steps over its world pass
|
||||
* alone. This is an ornament; the honest answer for a viewer who has asked for less motion is
|
||||
* to leave it out. */
|
||||
if (CC.reducedMotion) return;
|
||||
var fade = clamp(1 - W_RAIN / 0.35, 0, 1);
|
||||
for (var i = 0; i < NPET; i++) {
|
||||
if (!project(pX[i], pY[i], pZ[i])) continue;
|
||||
/* NOTHING INSIDE ELEVEN METRES, AND IT IS A RATE GATE RATHER THAN A LOOK. How fast a petal
|
||||
* crosses a CELL is its screen speed, which is its world speed times scale over distance —
|
||||
* so the near ones are the only ones that switch a cell inside the 3-20 Hz flash band. At
|
||||
* 3 m a petal covers a cell for a twelfth of a second (12 Hz, squarely in it); at 8 m it is
|
||||
* still about 2.9 Hz, which the gate's lowest probe at 3.5 Hz can still see the shoulder
|
||||
* of; at 11 m it is 2.1 Hz and clear of it. Eleven metres is therefore the cut, faded in
|
||||
* over the next five.
|
||||
*
|
||||
* IT HAD TO BE THE RATE AND NOT THE AMPLITUDE, which was measured rather than assumed.
|
||||
* Dimming the petals (150 -> 96) and thinning the pool (64 -> 40 -> 22 -> 10) left
|
||||
* tools/west-flicker.cjs reporting the identical 2.59% at the identical cell every time:
|
||||
* the worst cell is ONE petal's trajectory, so the pool size does not touch it at all, and
|
||||
* the amplitude term is not what the Goertzel is picking up. Distance is the only lever
|
||||
* that changes how fast a cell switches. Without this element the same world measures
|
||||
* 1.27%; with it and this cut, it clears.
|
||||
*
|
||||
* It is also the better picture. A petal a metre from the eye is a fast pale streak across
|
||||
* a third of the frame and reads as a bug on the lens; the drift is a thing you see at
|
||||
* middle distance, against the buildings, which is where every photograph of it is taken
|
||||
* from. */
|
||||
if (PJ.d < 11) continue;
|
||||
var near = PJ.d < 16 ? (PJ.d - 11) / 5 : 1;
|
||||
/* Edge-on for part of every turn, which is why the glyph alternates: a petal seen flat is
|
||||
* a mark and a petal seen edge-on is a line, and that flip at a slow rate is the single
|
||||
* most legible thing about falling blossom. */
|
||||
var e = Math.cos(pPh[i]);
|
||||
var flat = e > 0.3 || e < -0.3;
|
||||
var warm = hash2(i, 0, BASE + 0x52) < 0.34;
|
||||
/* THE LUMINANCE IS A PHOTOSENSITIVITY NUMBER AS MUCH AS A LOOK ONE. A petal is a small
|
||||
* object crossing a cell in about a fifth of a second at conversational distance, which
|
||||
* puts its on/off at roughly 5 Hz — the middle of the 3-20 Hz flash band — and the flash
|
||||
* AMPLITUDE is whatever this line writes. At the first cut's 150 that is 59% of full scale
|
||||
* blinking at 5 Hz on every cell the drift crosses, and tools/west-flicker.cjs scored the
|
||||
* world 2.54% in band against 1.60% for its world pass alone. The rate cannot be fixed —
|
||||
* slowing a petal to leave the band would make it fall at a centimetre a second — so the
|
||||
* amplitude is what gives, along with the pool size (64 -> 40 petals).
|
||||
*
|
||||
* It is also the better picture, which is the usual outcome when a gate is right. A petal
|
||||
* is not a light: it is a pale scrap in whatever the ambient happens to be, and at 150 in
|
||||
* `sand` it was outshining the paper screens behind it. */
|
||||
/* ONE CELL. A two-cell streak was tried — a petal at a sixtieth of a second IS a short
|
||||
* blur, and doubling how long a cell is covered should halve the switching rate out of the
|
||||
* 3-20 Hz band — and MEASURED it made the gate worse, 2.81% to 3.55%, because a trailing
|
||||
* cell does not halve the transitions, it adds a second partial one to every crossing. The
|
||||
* lever that actually moves this number is how OFTEN a cell is hit at all, which is the
|
||||
* 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,
|
||||
(flat ? 96 : 62) * fade * near * (0.42 + 0.58 * (1 - 0.6 * NIGHT)), PJ.d);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
})(typeof CC !== 'undefined' ? CC : require('../core.js'));
|
||||
|
|
@ -135,7 +135,7 @@
|
|||
layer: 78, // before every modulation pass: the shafts are in the world, not on the lens
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. A shaft is light scattering off something in the air.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
|
||||
init: function (city, rng) {
|
||||
this.seed = ((rng() * 4294967296) | 0) ^ 0x5A17;
|
||||
|
|
@ -403,7 +403,7 @@
|
|||
layer: 79, // still in the world: this is light on surfaces, not dirt on glass
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. Likewise: this is airglow round a bright source.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
|
||||
init: function (city, rng) {
|
||||
// Small seed, varied additively — see the note in weather.js about hash2 and large seeds.
|
||||
|
|
@ -628,7 +628,7 @@
|
|||
layer: 80,
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. Mist.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
|
||||
init: function (city, rng) { this.seed = (rng() * 30011) | 0; },
|
||||
|
||||
|
|
@ -807,7 +807,7 @@
|
|||
layer: 94,
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. Beads of rain on the lens.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
|
||||
init: function (city, rng) {
|
||||
var s = ((rng() * 4294967296) | 0) ^ 0x0F71C5;
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@
|
|||
layer: 3,
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. There is no deck for the town to light the underside of.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
draw: function (frame, cam, t) {
|
||||
setup(frame, cam);
|
||||
/* Under about 0.4 the deck is a few wisps nobody would notice and 20 000 noise evaluations
|
||||
|
|
@ -328,7 +328,7 @@
|
|||
/* Both atmospheric worlds, and NOT the Moon: a lunar sky has stars at noon and they are hard,
|
||||
* colourless and welded to a black dome, which is a different object drawn a different way —
|
||||
* see elements/moon_ground.js. This one is a star seen through air. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
init: function (city, rng) {
|
||||
var r = fork(rng), i;
|
||||
stX = new Float32Array(NSTAR); stY = new Float32Array(NSTAR); stZ = new Float32Array(NSTAR);
|
||||
|
|
@ -419,7 +419,7 @@
|
|||
* D_MOON 9.0e4 and west_sky.js parks the sun at 1.02e5, so the moon won the depth test and
|
||||
* painted itself and a cyan halo straight over the sunset. It is now gated to the two worlds
|
||||
* that have a sky to hang it in, and faded out by daylight below. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
init: function (city, rng) {
|
||||
var r = fork(rng);
|
||||
moAz0 = (r() - 0.5) * 0.26; // the avenue runs +z, which is yaw 0
|
||||
|
|
|
|||
|
|
@ -909,7 +909,7 @@
|
|||
* wheels 0.015 kept. A cane-and-iron invalid chair is period and was rare; 0.015 of the
|
||||
* crowd is about one figure in a hundred, which is the rate it should be
|
||||
* The new sum is 0.495 of 1.600. What the eight do NOT change is anything sci-fi: their
|
||||
* accents, rims and linings all run through the PED_WEST gates below like everyone else's,
|
||||
* accents, rims and linings all run through the PED_PRE gates below like everyone else's,
|
||||
* and a west night frame carries no non-period swatch from this file at all. */
|
||||
ARCH_TOT_W += (A.ww === undefined ? A.w : A.ww); A.acc1 = ARCH_TOT_W;
|
||||
}
|
||||
|
|
@ -917,10 +917,42 @@
|
|||
/* Which crowd this is. Read off the CITY rather than off CC.World, for the reason world.js
|
||||
* gives: between a keypress and the rebuild those are two different answers, and this one has to
|
||||
* match the map the walkers are standing on. */
|
||||
var PED_WEST = 0;
|
||||
/* ---- TWO FLAGS, NOT ONE, AND BOTH COME OUT OF A TABLE ------------------------------------------
|
||||
* This was a single `PED_WEST = city.world === 'west'`, which is the shape world.js and city.js
|
||||
* both spend a paragraph forbidding: a boolean meaning "is west" that a third world silently
|
||||
* falls off the end of. It was doing two unrelated jobs and a fourth world needs one of them and
|
||||
* not the other, which is exactly how that kind of flag fails.
|
||||
*
|
||||
* PED_ARCH_W picks the FRONTIER COSTUME WEIGHTS — the duster, the brimmed hat, the bedroll high
|
||||
* on the back. Those are that world's silhouettes and nobody else's.
|
||||
* PED_PRE says the crowd is PRE-ELECTRIC. No phone at chest height, no electroluminescent
|
||||
* piping, no retroreflective courier strip, no hi-vis; rims go warm; a lit thing carried in
|
||||
* the hand is a flame. That is true of 1885 Kansas and it is true of Edo, and it is the half
|
||||
* of the old flag the fourth world needs.
|
||||
*
|
||||
* Both are looked up by world id off a table, so a world that is not in it gets the modern
|
||||
* default rather than whatever the last `else` happened to be. The DRAWS are unchanged in either
|
||||
* case — every gate below still takes its hash and throws the result away rather than skipping
|
||||
* it — so the crowd's noise stream is identical across worlds and one world's walkers are not a
|
||||
* reshuffle of another's. */
|
||||
var PED_ARCH = { west: 1 };
|
||||
var PED_PRE_W = { west: 1, japan: 1 };
|
||||
/* ---- AND WHAT COLOUR THE UMBRELLA IS, WHICH IS THE THIRD THING KEYED BY WORLD ------------------
|
||||
* A wagasa is oiled paper on a bamboo frame and it is one of the few objects in Edo that was
|
||||
* allowed to be loud — two vermilion, one kakishibu-oiled natural, one aizome indigo, one plain,
|
||||
* which is what a wet street of them looks like. Everywhere else the canopy keeps taking `p.rim`,
|
||||
* so a world absent from this table renders byte-for-byte as before: verified over all 27
|
||||
* cyber/west/moon fixtures.
|
||||
*
|
||||
* It is census-NEUTRAL and bought entirely for the picture — the canopy's own luminance is
|
||||
* 30-55, under every printed threshold in the table — which is the honest description of what a
|
||||
* colour that only shows in the rain is worth. */
|
||||
var UMB_HUE = { japan: [P.ember, P.ember, P.warm, P.indigo, P.white] };
|
||||
var UMB_W = null;
|
||||
var PED_ARCH_W = 0, PED_PRE = 0;
|
||||
function archPick(h) {
|
||||
var i;
|
||||
if (PED_WEST) {
|
||||
if (PED_ARCH_W) {
|
||||
var rw = h * ARCH_TOT_W;
|
||||
for (i = 0; i < ARCH.length - 1; i++) if (rw < ARCH[i].acc1) return ARCH[i];
|
||||
return ARCH[ARCH.length - 1];
|
||||
|
|
@ -1213,7 +1245,7 @@
|
|||
* the last of the sun — both warm. One in five still breaks the rule, as in the city, because
|
||||
* a street has more light in it than the wall behind you; it just breaks it towards warm
|
||||
* rather than towards a shopfront monitor. */
|
||||
p.rim = PED_WEST ? ((h10 < 0.80) ? P.amber : P.warm)
|
||||
p.rim = PED_PRE ? ((h10 < 0.80) ? P.amber : P.warm)
|
||||
: ((h10 < 0.80 ? scr : !scr) ? P.azure : P.amber);
|
||||
/* ---- AND THE SIGN OVERHEAD BEATS THE WALL BEHIND ------------------------------------------
|
||||
* The rim has always followed the FRONTAGE, which is right as far as it goes: a screen block
|
||||
|
|
@ -1236,12 +1268,20 @@
|
|||
* NOT ON THE FRONTIER, and the draw is still TAKEN so the noise stream downstream of it does
|
||||
* not move between worlds — the same discipline the phone and the visor keep. Out there the
|
||||
* signs are painted boards under a porch lantern and the rim is warm, which h10 already said. */
|
||||
if (!PED_WEST && bestS >= 0 && h18 < 0.34 &&
|
||||
if (!PED_PRE && bestS >= 0 && h18 < 0.34 &&
|
||||
bestS !== P.white && bestS !== P.slate && bestS !== P.shadow && bestS !== P.violet &&
|
||||
bestS !== P.stone && bestS !== P.timber && bestS !== P.sand &&
|
||||
bestS !== P.moss && bestS !== P.indigo) p.rim = bestS;
|
||||
/* Umbrellas. Owning one is not the same as having it up — see the easing in update(). */
|
||||
p.umbOwn = A.umb && h9 < 0.62 ? 1 : 0;
|
||||
/* THE CANOPY'S OWN HUE, AND THE ASSIGNMENT IS INSIDE THE GATE FOR A REASON. `h9/0.62` is uniform
|
||||
* on 0..1 only for the figures the line above accepted, so indexing the table with it outside
|
||||
* the gate runs off the end of the array for every h9 >= 0.62 and yields `undefined` — which a
|
||||
* Uint8Array coerces to slot 0, amber. That is not hypothetical: pedSpawn does not reset p.umb,
|
||||
* so a walker recycled while its canopy is still easing shut would have drawn an amber umbrella
|
||||
* for a second or so. Conditional-on-the-gate is the same free-draw idiom the phone above uses
|
||||
* and it costs no extra hash. */
|
||||
p.umbHue = (p.umbOwn && UMB_W) ? UMB_W[(h9 / 0.62 * UMB_W.length) | 0] : p.rim;
|
||||
p.uRate = 0.20 + h1 * 0.26; // seconds-scale, and different for every figure
|
||||
/* A phone is a screen, which is the one thing violet is licensed for. Conditional on the gate,
|
||||
* h12/0.18 is itself uniform on 0..1 and independent of it, so the colour needs no extra
|
||||
|
|
@ -1251,7 +1291,7 @@
|
|||
* at chest height, which is a phone, which is a hundred and thirty years early. The draw is
|
||||
* still TAKEN so the hash stream downstream of it is unchanged between worlds — only the
|
||||
* result is thrown away. */
|
||||
if (h12 < 0.18 && !PED_WEST) {
|
||||
if (h12 < 0.18 && !PED_PRE) {
|
||||
var q = h12 / 0.18;
|
||||
p.phone = q < 0.70 ? P.azure : (q < 0.88 ? P.ice : P.violet);
|
||||
} else p.phone = -1;
|
||||
|
|
@ -1268,7 +1308,7 @@
|
|||
* All three fall back to acc 3, which is a cigarette: an ember dot at the face, which is
|
||||
* period-correct, is the same one-cell cost, and is a better read on a frontier figure than
|
||||
* any of them. acc 4 (something carried and lit — a lantern) is kept as it is. */
|
||||
p.acc = PED_WEST ? ((A.acc === 1 || A.acc === 2 || A.acc === 5) ? 3 : A.acc) : A.acc;
|
||||
p.acc = PED_PRE ? ((A.acc === 1 || A.acc === 2 || A.acc === 5) ? 3 : A.acc) : A.acc;
|
||||
/* Piping leans violet rather than spring, and that is a PRINT decision, not a taste one:
|
||||
* core.js gives spring an exposure weight of 1.55 against violet's 0.70, so the same lum
|
||||
* prints spring more than twice as hot and a green seam was reading as the brightest thing
|
||||
|
|
@ -1277,7 +1317,7 @@
|
|||
* neckerchief, an ember bandana, a white collar. Spring, violet and ice all come off the
|
||||
* ladder there — the first two are the city's signage garnish and the third is a glint on
|
||||
* something manufactured. */
|
||||
p.accHue = PED_WEST ? (qa < 0.42 ? P.red : (qa < 0.76 ? P.ember : P.white))
|
||||
p.accHue = PED_PRE ? (qa < 0.42 ? P.red : (qa < 0.76 ? P.ember : P.white))
|
||||
: A.acc === 1 ? (qa < 0.34 ? P.spring : P.violet)
|
||||
: A.acc === 2 ? P.ice
|
||||
: A.acc === 3 ? P.ember
|
||||
|
|
@ -1313,7 +1353,7 @@
|
|||
/* Brass and wool are both entirely 1880s and both stay. An indigo hood LINING is a hood,
|
||||
* and out there a hood is a serape hood, so it falls back to the collar rather than being
|
||||
* dropped — the draw is still taken either way, so no downstream stream moves. */
|
||||
if (PED_WEST && p.wear === 3) p.wear = 2;
|
||||
if (PED_PRE && p.wear === 3) p.wear = 2;
|
||||
} else p.wear = 0;
|
||||
/* THE VISOR — its own independent draw, because welding it to the accent roll is the bug this
|
||||
* file has already been caught with three times (a crossing draw reused for a rim colour made
|
||||
|
|
@ -1329,7 +1369,7 @@
|
|||
* licence covers, and red is hazard, which is what a targeting overlay is. At 15.9% of the
|
||||
* crowd wearing one, red at 0.07 of those is under 1 figure in 90 and does not move red's
|
||||
* 0.3% share of lit energy measurably. */
|
||||
if (h17 < A.visP && !PED_WEST) {
|
||||
if (h17 < A.visP && !PED_PRE) {
|
||||
var qv = h17 / A.visP;
|
||||
p.vis = 1;
|
||||
p.visHue = qv < 0.46 ? P.azure : (qv < 0.74 ? P.ember : (qv < 0.87 ? P.ice
|
||||
|
|
@ -1344,12 +1384,14 @@
|
|||
/* THE TWO WORLDS WITH AIR IN THEM. Nobody walks a lunar plain in shirtsleeves; the crowd is an atmospheric-world
|
||||
* object and a suited figure is a different silhouette that this element cannot draw.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
init: function (city, rng, dims) {
|
||||
this.city = city;
|
||||
/* Which world's costume weights the crowd draws from — see archPick. Set here, at the one
|
||||
* moment the map is handed over, rather than read per walker. */
|
||||
PED_WEST = (city && city.world === 'west') ? 1 : 0;
|
||||
PED_ARCH_W = (city && PED_ARCH[city.world]) ? 1 : 0;
|
||||
PED_PRE = (city && PED_PRE_W[city.world]) ? 1 : 0;
|
||||
UMB_W = (city && UMB_HUE[city.world]) || null;
|
||||
/* Small seed and additive offsets, per the house rule for hash2 — and the draw is still one
|
||||
* rng() call, so no downstream element's stream moves. */
|
||||
this.seed = (rng() * 30011) | 0;
|
||||
|
|
@ -1362,7 +1404,7 @@
|
|||
peds[i] = { x: 0, z: 0, vx: 0, vz: 0, dx: 0, dz: 0, dodge: 0, n: i * 91, tall: 1.7,
|
||||
phase: 0, cross: 0, goSide: 1, shelter: 0, side: 1, rim: P.amber, phone: -1,
|
||||
acc: 0, accHue: P.amber, vis: 0, visHue: P.azure, walked: 0, live: 0, wait: 0,
|
||||
umbOwn: 0, umb: 0, uRate: 0.3, hunch: 0, wear: 0, A: ARCH[0] };
|
||||
umbOwn: 0, umb: 0, umbHue: 0, uRate: 0.3, hunch: 0, wear: 0, A: ARCH[0] };
|
||||
},
|
||||
update: function (dt, t, cam) {
|
||||
/* The full screen basis, not just camBasis, because the retirement below is written in screen
|
||||
|
|
@ -2187,7 +2229,7 @@
|
|||
var ul = rim * (0.46 - 0.30 * f2 * f2) * (0.5 + 0.5 * p.umb);
|
||||
put(frame, Math.round(cx) + q,
|
||||
Math.round(rApex + f2 * f2 * tallRows * 0.17 + q * uTilt * 0.30),
|
||||
(q === -ruI || q === ruI) ? G_TICK : G_DASH, p.rim, ul, nearer(dist));
|
||||
(q === -ruI || q === ruI) ? G_TICK : G_DASH, p.umbHue, ul, nearer(dist));
|
||||
}
|
||||
/* The shaft, and only the stretch between the canopy and the crown: below that it runs
|
||||
* inside a cut-out that is already black, so drawing it again would cost and show
|
||||
|
|
@ -2232,7 +2274,7 @@
|
|||
layer: 21,
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. For the same reason as the crowd, and more so.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
init: function (city, rng) {
|
||||
this.city = city;
|
||||
this.seed = (rng() * 2147483647) | 0;
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@
|
|||
layer: 12,
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. Vacuum has no weather; rain on the Moon was diagonal streaks across a black sky.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
init: function (city, rng) {
|
||||
bindWorld(city, rng);
|
||||
/* The drop table is filled from a fork, not from `rng`, so that RN_MAX cannot re-seed the
|
||||
|
|
@ -835,7 +835,7 @@
|
|||
layer: 8,
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. Fog is suspended water. There is none.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
init: function (city, rng) {
|
||||
bindWorld(city, rng);
|
||||
fgSeed = smallSeed(rng);
|
||||
|
|
@ -1049,7 +1049,7 @@
|
|||
layer: 7,
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. A cloud deck needs an atmosphere to hold it up.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
init: function (city, rng) {
|
||||
bindWorld(city, rng);
|
||||
clSeed = smallSeed(rng);
|
||||
|
|
@ -1205,7 +1205,7 @@
|
|||
layer: 40,
|
||||
/* THE TWO WORLDS WITH AIR IN THEM. A stroke needs a charged medium to travel through.
|
||||
* See src/world.js: `world` may be a string or a set, and absent means every world. */
|
||||
world: ['cyber', 'west'],
|
||||
world: ['cyber', 'west', 'japan'],
|
||||
init: function (city, rng) {
|
||||
bindWorld(city, rng);
|
||||
lgSeed = smallSeed(rng);
|
||||
|
|
|
|||
|
|
@ -228,6 +228,11 @@
|
|||
* frame, and city.js's jitter is bounded well under half a block so the arithmetic guess is
|
||||
* never more than one slot out. */
|
||||
cf.xpitch = pitch;
|
||||
/* And the channel, for a world that has one. Straight onto the block rather than through
|
||||
* configure(), exactly as xn/xc/xw/xpitch above are: this is a per-frame refill of a city fact,
|
||||
* not a viewer setting. `|| null` so the three worlds without water publish nothing and the
|
||||
* painter's guard is a single truthiness test. */
|
||||
cf.rivD = city && city.rivD ? city.rivD : null;
|
||||
}
|
||||
|
||||
/* ---- floor by inverse projection ----------------------------------------------------------
|
||||
|
|
|
|||
1268
src/surf_japan.js
Normal file
1268
src/surf_japan.js
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -88,6 +88,18 @@
|
|||
xw: new Float64Array(8),
|
||||
xz0: 0, xpitch: 26, // xc[0] and the city's block pitch, so the nearest entry can be INDEXED
|
||||
// rather than searched: this runs twenty thousand times a frame
|
||||
/* ---- THE ONE THING THE TEXTURE LAYER CANNOT DERIVE AND CANNOT BE TOLD PER CELL --------------
|
||||
* A world with WATER in its map needs its floor painter to know where the water is, and
|
||||
* floorTex is handed (wx, wz, dist, t) and nothing else — no city, no seed. The precedent for
|
||||
* this is three fields up: the cross-street table is a city fact that the world pass loads in
|
||||
* once per frame because the painter has no city to ask.
|
||||
*
|
||||
* So the map may publish a channel-distance function and raycast.js hangs it here. `null` in
|
||||
* every world that has no water, which is the only value the other three ever see, so this is
|
||||
* one property read per floor cell in the city, the frontier and the Moon and nothing else.
|
||||
* It is a FUNCTION rather than a table of coefficients because the meander already exists,
|
||||
* correctly, in city.js, and two copies of a curve is how they stop matching. */
|
||||
rivD: null,
|
||||
/* Whether THIS street carries tram rails. Rolled once per configure() rather than per cell:
|
||||
* a rail that appears for some cells of a street and not others is not a rail. */
|
||||
rail: 0,
|
||||
|
|
|
|||
|
|
@ -100,6 +100,55 @@
|
|||
];
|
||||
var NEXT_MOON = [[1]];
|
||||
|
||||
/* ---- EDO's six, and the axis is WET rather than windy -------------------------------------------
|
||||
* Same eight physical directions again, and the table that comes out of them is almost the exact
|
||||
* inverse of the frontier's. Out there it is dry for weeks and the middle of the table is made of
|
||||
* dust; here it is a maritime climate on the edge of a monsoon and the middle of the table is
|
||||
* made of RAIN, in four grades of it. There is no row in this table with `wet` under 0.20 and no
|
||||
* row with `rain` at 0.00 except the two that are explicitly the dry interval — which is the
|
||||
* point of the world: the reference prints of this place are prints of rain, and the ground in
|
||||
* every one of them is holding water.
|
||||
*
|
||||
* `haze` never goes below 0.34, on the same argument as the frontier's 0.30 floor and for a
|
||||
* completely different reason. There it is dust, and the thing it does is tell you a mesa is
|
||||
* eight miles off. Here it is HUMIDITY, and the thing it does is put the wooded hills at the end
|
||||
* of the street progressively out of focus — the stacked, flattened, receding ridgelines that
|
||||
* are the one compositional device this setting is most known for. At 0.10 they would all sit in
|
||||
* the same plane and read as a cut-out.
|
||||
*
|
||||
* `steam` is high everywhere (0.44-0.72) and it is the only parameter here that is doing a job
|
||||
* the city invented it for. In the city it is a vent in the road; here it is what elements read
|
||||
* to put mist coming off wet tile and off the river after rain, and a bathhouse is a real
|
||||
* building on this street.
|
||||
*
|
||||
* rel() IS STILL THE CITY'S 'rain' ROW, permanently, exactly as PRESETS_WEST's note says. So
|
||||
* `shower` at rain 0.78 really is 1.2x the rain the whole build was tuned under, and `tsuyu` —
|
||||
* the plum-rain season, a fortnight of grey that never quite stops — is 0.52 of it. Those are
|
||||
* absolute numbers in the same units, not a rebasing. */
|
||||
/* rain wind fog wet storm haze cloud steam */
|
||||
var PRESETS_JAPAN = [
|
||||
{ name: 'clear', p: [0.00, 0.18, 0.14, 0.22, 0.00, 0.40, 0.16, 0.44] },
|
||||
{ name: 'haze', p: [0.00, 0.14, 0.40, 0.20, 0.00, 0.82, 0.34, 0.56] },
|
||||
{ name: 'tsuyu', p: [0.34, 0.26, 0.36, 0.72, 0.02, 0.52, 0.72, 0.62] },
|
||||
{ name: 'shower', p: [0.78, 0.44, 0.32, 0.96, 0.10, 0.44, 0.86, 0.58] },
|
||||
{ name: 'typhoon', p: [1.00, 1.00, 0.42, 1.00, 0.66, 0.50, 1.00, 0.48] },
|
||||
{ name: 'kiri', p: [0.08, 0.10, 1.00, 0.48, 0.00, 0.96, 0.76, 0.72] }
|
||||
];
|
||||
|
||||
/* The sequence is a valley climate: it clears, it hazes over, it rains for a long time, and the
|
||||
* mist comes up off the water afterwards rather than before. `kiri` (the river fog) is reachable
|
||||
* from every wet row and from nothing dry, which is what makes it read as the AFTERMATH of rain
|
||||
* instead of as a weather state in its own right — and clear -> typhoon is zero, because a
|
||||
* typhoon arrives over three hours of thickening cloud and you always see it coming. */
|
||||
var NEXT_JAPAN = [
|
||||
/* clear -> */ [0, 6, 3, 1, 0, 0],
|
||||
/* haze -> */ [3, 0, 5, 2, 1, 2],
|
||||
/* tsuyu -> */ [2, 3, 0, 5, 2, 4],
|
||||
/* shower -> */ [1, 2, 5, 0, 2, 5],
|
||||
/* typhoon -> */ [0, 1, 4, 5, 0, 3],
|
||||
/* kiri -> */ [4, 5, 3, 1, 0, 0]
|
||||
];
|
||||
|
||||
/* ---- the table registry ------------------------------------------------------------------------
|
||||
* Keyed by world id. The two-way string compare this replaced meant a third world silently ran
|
||||
* the CITY's rain schedule — which on the Moon would have been a rainstorm in vacuum.
|
||||
|
|
@ -114,7 +163,8 @@
|
|||
function tables() {
|
||||
if (!TABLES) TABLES = { cyber: [PRESETS_CYBER, NEXT_CYBER],
|
||||
west: [PRESETS_WEST, NEXT_WEST],
|
||||
moon: [PRESETS_MOON, NEXT_MOON] };
|
||||
moon: [PRESETS_MOON, NEXT_MOON],
|
||||
japan: [PRESETS_JAPAN, NEXT_JAPAN] };
|
||||
return TABLES;
|
||||
}
|
||||
|
||||
|
|
|
|||
11
src/world.js
11
src/world.js
|
|
@ -41,7 +41,16 @@
|
|||
var LIST = [
|
||||
{ id: 'cyber', name: 'CYBERCITY', aliases: ['city', 'cybercity', 'c'] },
|
||||
{ id: 'west', name: 'FRONTIER', aliases: ['western', 'frontier', 'w'] },
|
||||
{ id: 'moon', name: 'MOONWALK', aliases: ['moonwalk', 'lunar', 'apollo', 'm'] }
|
||||
{ id: 'moon', name: 'MOONWALK', aliases: ['moonwalk', 'lunar', 'apollo', 'm'] },
|
||||
/* Appended, never inserted, for the reason two paragraphs up: LIST[0] is the URL default and
|
||||
* this row's index is what the 4 key selects. The id is the plain one — `japan` is what a
|
||||
* person types into a fragment from memory and what every `world: 'japan'` tag in src/elements
|
||||
* greps for — while the NAME is the place rather than the country, because the other three
|
||||
* name a place too and because a world called JAPAN would be promising a country's worth of
|
||||
* settings when what is built is one wet evening in one castle town. EDO is four letters of
|
||||
* the 3x5 font's alphabet and it is the period as well as the city, which is the whole
|
||||
* distinction this world is drawing against the other three. */
|
||||
{ id: 'japan', name: 'EDO', aliases: ['japan', 'edo', 'kyoto', 'nihon', 'j'] }
|
||||
];
|
||||
|
||||
var cur = 0;
|
||||
|
|
|
|||
57
tools/canal-flicker.cjs
Normal file
57
tools/canal-flicker.cjs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* 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');
|
||||
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)});
|
||||
fs.readdirSync(R+'src/elements').sort().forEach(p=>require(R+'src/elements/'+p));
|
||||
const COLS=120,ROWS=40,WARM=360,NF=WARM+240,PROBES=[3.5,5,7,9,12,15,19];
|
||||
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,dOff){
|
||||
CC.World.force('japan'); CC.reducedMotion=!!reduced;
|
||||
const city=CC.City.make(seed); CC.Daylight.init(city); 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});
|
||||
// walk the autopilot until it is dOff metres from the channel, then PIN there
|
||||
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};
|
||||
let found=false;
|
||||
for(let k=0;k<40000;k++){CC.Daylight.update(1/60,k/60);CC.Weather.update(1/60,k/60);CC.Control.update(1/60,k/60,cam,city);
|
||||
if(Math.abs(city.rivD(cam.x,cam.z)-dOff)<0.9){found=true;break;}}
|
||||
if(!found) return null;
|
||||
/* SCOPED EXACTLY AS tools/west-flicker.cjs SCOPES IT: only elements EXCLUSIVE to this world are
|
||||
drawn. A shared element (the crowd, the rain) is part of the baseline every world carries and
|
||||
the tool's own header spends a paragraph on why it is not this world's to answer for. Drawing
|
||||
them here measured the pedestrians and called it the canal. */
|
||||
const drawn=live.filter(e=>e.world&&CC.inWorld(e,'japan')&&!CC.inWorld(e,'cyber'));
|
||||
const f=CC.makeFrame(COLS,ROWS),N=COLS*ROWS,keep=NF-WARM,s=new Uint8Array(N*keep);
|
||||
const isWater=new Uint8Array(N);
|
||||
for(let k=0;k<NF;k++){const t=k/60;
|
||||
if(!CC.Weather.P.forced)CC.Weather.set(preset,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 drawn) if(el.draw) el.draw(f,cam,t);
|
||||
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 water=0;
|
||||
for(let i=0;i<N;i++){ const rz=(i/COLS)|0; if(f.kind[i]===2&&rz>ROWS*0.56){isWater[i]=1;water++;} }
|
||||
let big=0,band=0,worst=0;const x=new Float64Array(keep);
|
||||
for(let i=0;i<N;i++){ if(!isWater[i]) continue;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>85)b++;prev=v;x[k]=v;}
|
||||
x[0]=s[i];
|
||||
if(b/(keep/60)>big)big=b/(keep/60);
|
||||
if(mx>worst)worst=mx;
|
||||
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)};
|
||||
}
|
||||
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);
|
||||
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');
|
||||
|
|
@ -861,6 +861,27 @@ testCase('worlds', function (ok) {
|
|||
m.CC && m.CC.Weather.PRESETS.length);
|
||||
ok(m.errors.length === 0, 'Moonwalk threw nothing');
|
||||
|
||||
/* THE FOURTH WORLD, checked the same way and for the same reason. The Moon's test above proves a
|
||||
* world can boot with its own weather table; this one proves the case that table cannot catch —
|
||||
* a world with SIX presets like the city's, where a registry miss would fall through to the city
|
||||
* and the count would still be six. So the check is on the preset NAMES: `tsuyu` exists in
|
||||
* exactly one table in this tree, and if EDO is running the city's schedule it will not be there.
|
||||
*
|
||||
* The alias is exercised rather than the id, because src/world.js's aliases are a table a reader
|
||||
* edits by hand and nothing else in the suite reads one. */
|
||||
const j = makeEnv({ hash: '#edo/11' }).run();
|
||||
j.tick(90);
|
||||
ok(!!j.CC && j.CC.World.id === 'japan', '#edo/11 boots EDO through its alias',
|
||||
j.CC && j.CC.World.id);
|
||||
ok(!!j.CC && j.CC.Main.seed === 11, 'and seed 11', j.CC && j.CC.Main.seed);
|
||||
ok(j.get('drawImage') > 0, 'EDO drew', j.get('drawImage'));
|
||||
ok(!!j.CC && j.CC.Weather.PRESETS.some(function (p) { return p.name === 'tsuyu'; }),
|
||||
'EDO runs its own weather table, not the city\'s',
|
||||
j.CC && j.CC.Weather.PRESETS.map(function (p) { return p.name; }).join(','));
|
||||
ok(!!j.CC && !!j.CC.SURFACES && !!j.CC.SURFACES.japan,
|
||||
'and its own painter is registered', j.CC && Object.keys(j.CC.SURFACES || {}).join(','));
|
||||
ok(j.errors.length === 0, 'EDO threw nothing');
|
||||
|
||||
/* THE CLOCK. T steps the time of day and Y stops it; neither may seize the camera. */
|
||||
const d = makeEnv({}).run();
|
||||
d.tick(60);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,32 @@ import sys, json
|
|||
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
||||
|
||||
CW, CH = 9, 16
|
||||
FONT = ImageFont.truetype("/usr/share/fonts/liberation-mono-fonts/LiberationMono-Bold.ttf", 15)
|
||||
# Liberation Mono Bold at 15 px in a 9x16 cell is the reference print, and it is what
|
||||
# render_canvas.js's atlas bakes and what surf_west.js's INK ramp was measured against — so it is
|
||||
# tried FIRST and every fallback below is a degradation that changes the ink census. The list
|
||||
# exists because this file is the standing verification procedure ("every change gets looked at
|
||||
# this way before it ships") and it was unrunnable on macOS, where that path does not exist: a
|
||||
# gate nobody can run is not a gate. Order is exact match, then the same metrics under another
|
||||
# name, then anything monospace, then PIL's bitmap default.
|
||||
_FONT_PATHS = [
|
||||
"/usr/share/fonts/liberation-mono-fonts/LiberationMono-Bold.ttf",
|
||||
"/usr/share/fonts/truetype/liberation/LiberationMono-Bold.ttf",
|
||||
"/Library/Fonts/LiberationMono-Bold.ttf",
|
||||
"/System/Library/Fonts/SFNSMono.ttf",
|
||||
"/System/Library/Fonts/Menlo.ttc",
|
||||
"/System/Library/Fonts/Supplemental/Courier New Bold.ttf",
|
||||
]
|
||||
FONT = None
|
||||
for _p in _FONT_PATHS:
|
||||
try:
|
||||
FONT = ImageFont.truetype(_p, 15)
|
||||
break
|
||||
except OSError:
|
||||
continue
|
||||
if FONT is None:
|
||||
sys.stderr.write("topng: no mono TTF found, falling back to the bitmap default; "
|
||||
"glyph ink will not match the print\n")
|
||||
FONT = ImageFont.load_default()
|
||||
|
||||
def main(src, dst):
|
||||
lines = open(src).read().split('\n')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue