diff --git a/CONTRACT.md b/CONTRACT.md index 28e85d4..1fec028 100644 --- a/CONTRACT.md +++ b/CONTRACT.md @@ -34,19 +34,42 @@ concatenates them in order and the headless harness `require`s them through a sh | file | global | responsibility | | --- | --- | --- | -| `src/core.js` | `CC` | Frame alloc, PALETTE, GLYPHS, rng/noise, math, `put()` | +| `src/core.js` | `CC`, `CC.Compose` | Frame alloc, PALETTE, GLYPHS, rng/noise, math, `put()`, and the print — the two exposure ladders, `ladder()`, the LUT and `Compose.post()`. `src/compose.js` does not exist; the contract allows it not to and `build.js` filters it out rather than assuming it | | `src/world.js` | `CC.World` | the world registry — which world is live, the id/name/alias table, and `inWorld()` | | `src/daylight.js` | `CC.Daylight` | the clock: sun altitude and bearing, and the light directions everything reads off them | -| `src/city.js` | `CC.City` | `make(seed)` → heightmap + per-cell district/style/sign metadata, for either world | +| `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 both worlds and delegates 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 three painters | | `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/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 | -| `src/compose.js` | `CC.Compose` | fog, element pass ordering, reduced-motion damping | | `src/render_canvas.js` | `CC.Canvas` | glyph atlas, `drawImage` per cell, bloom. **Only DOM-touching module** | -| `src/main.js` | — | loop, resize, fullscreen, seed in hash, prefers-reduced-motion | +| `src/main.js` | `CC.Main` | loop, resize, fullscreen, seed in hash, prefers-reduced-motion | + +## The palette — 20 swatches, two ladder entries each + +`PALETTE` in `core.js` is **append-only**. Slots 0-11 are frozen because a swatch index in this +tree is a literal in other files — `surfaces.js`'s `L_LOW`/`L_LIT`/`L_HOT`, `ads.js`'s `PEAK`, +`signage.js`'s `MIN_C`/`MIN_R` are all arrays indexed by palette slot, and `metrics.py`'s `NAMES` +is a parallel list that wraps rather than raising if it falls short. Inserting a swatch does not +fail; it silently reprints half the frame through some other swatch's curve. + +Rules for the palette: +- Every swatch has an entry in **both** `EXPOSURE` and `EXPOSURE_DAY`, and `ladder(c, mix, sunMix)` + is the only thing that reads them. Adding a swatch without a day entry is `undefined` in the LUT. +- `ladder()` splits the table in two and the test is **"does it emit"**, not "is it bright" and not + "is it an accent". Sources — amber, azure, warm, ice, jade, rose, gold — blend on the **squared + sun**; everything else blends on the **sky**. A surface put on the sun curve holds its night gain + through the whole of dawn, so the wall goes bright only after the sky already has. +- The LUT's stride is read off `PALETTE.length`. It was a literal `12` once and that is exactly the + failure above. +- Any painter that maps a hue to a material must be indexed **by palette slot with every slot + filled**, not by a whitelist. `surf_west.js` carried `hue === P.warm || hue === P.white || + hue === P.ember ? hue : P.amber` and every material the map learned to name after it was written + fell off the end and printed as amber. Degrade to the nearest neighbour, never to a default. ## Ambient element interface @@ -67,9 +90,10 @@ 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 -both worlds next to the numbers it already has — `city.js` holds two district tables, `weather_state.js` -two preset tables, `surfaces.js` delegates its three painters — rather than reading from one central -theme object. The URL fragment is `#` for the default world and `#/` otherwise. +every world next to the numbers it already has — `city.js` holds three district tables (nine +quarters for the city, six for the frontier, eight for the Moon), `weather_state.js` three preset +tables, `surfaces.js` delegates to three painters — rather than reading from one central theme +object. The URL fragment is `#` for the default world and `#/` otherwise. Rules for worlds: - An element that belongs to one world says so with `world:` on itself, as an id or an array of @@ -103,13 +127,30 @@ Rules for the clock: baseline that a 128-frame census was fitted against, so a factor of `0.22 + 0.93 * lamp` — which is 1.15 at night — silently re-tunes the picture the feature was supposed to leave alone. It did, once, and moved 1083 cells of a 12000-cell reference frame before the byte comparison caught it. + The rule is about SCALES. A change that is **material** — terrain relief, a new lattice of + craters, a costume — legitimately changes the night frame, and the way to tell the two apart is + whether the number is read off the clock. If it is, it is the identity at night; if it is not, + say in the source that the night frame moves and why. `surf_moon.js`'s `roll` is the worked + example of the second case. +- A world's **signature hour** gets the same protection as night if it says so. The frontier's + daylight fill is gated above the sky level the clock reports at dawn and dusk (0.657) precisely + so that those two frames stay byte-identical, and the threshold was moved from 0.60 to 0.70 after + a census showed a twentieth of the fill moving dusk's muddy band by five points. - Read the RIGHT direction. `sky` is what lifts structure (in daylight a wall is lit by the whole hemisphere, not by the sun); `lamp` is what takes artificial light away and has hysteresis; `sun` is only for things that need a shadow; `star` keys on the twilight curve and not on the sun, because the whole of civil twilight has no sun in it and no stars either. -- The print has TWO exposure ladders (`EXPOSURE` and `EXPOSURE_DAY` in `core.js`) blended by the - clock through `CC.Compose.post(f, cam, t)` — which has always been called with `cam` and `t` and - always ignored them. The LUT is rebuilt only when the blend crosses one of 32 quantised steps. +- The print has TWO exposure ladders (`EXPOSURE` and `EXPOSURE_DAY` in `core.js`, one entry per + swatch in each) blended by the clock through `CC.Compose.post(f, cam, t)` — which has always been + called with `cam` and `t` and always ignored them. The LUT is rebuilt only when the blend crosses + one of 32 quantised steps, about once every thirteen seconds of a 420 s day. Which of the two + curves a swatch blends along is decided by `ladder()`; see the palette section above. +- A painter that caches the clock's parameters in module state must assign **every** cached field + inside its `view()`/`configure()` body. Three frontier files kept per-frame caches that were + moved out with the projection scaffolding, two were missed, and the desert and the livestock + stopped following the clock while the street behind them still did. Nothing reported it; a + byte-comparison of three fixtures before and after is what caught it, and that comparison is the + standing procedure here. Rules for elements: - **Never** write to the typed arrays directly; always go through `CC.put`, which honours `frame.dist`. @@ -117,8 +158,34 @@ Rules for elements: - Must read `CC.reducedMotion` and damp or freeze accordingly. - Must be deterministic given the seeded rng handed to `init`. +## The build + +`node build.js` must exit 0. It fails over **560 KB** and that line has been raised three times and +held once; the essay in `build.js` is the record and it is addressed to whoever lands here next. +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 +this one had. The bundle must also survive `new Function()`, contain none of `require(`, +`module.exports`, ESM syntax or a closing script tag, and still name every global in the +required-globals list. + ## Verification (this is not optional) `node tools/headless.cjs [--west|--moon] [--time=noon] > f.txt` renders one frame with **no browser** -and dumps `glyph,colourIdx,lum` per cell. `python3 tools/topng.py f.txt out.png` renders that to an -image with the same bloom the canvas does. Every change gets looked at this way before it ships. +and dumps `glyph,colourIdx,lum,kind` per cell. `python3 tools/topng.py f.txt out.png` renders that +to an image with the same bloom the canvas does. Every change gets looked at this way before it +ships. `python3 tools/metrics.py f.txt` is the census; its night targets are muddy under 30% and +hot 3.5-5%, and a daylight frame is not expected to meet the first — see the README's table for +what each world actually measures at each hour. + +The gates, in the order they are worth running: `node build.js`, `node tools/domshim.cjs`, +`node tools/flicker-rate.cjs`, `node tools/lightning-rate.cjs`, `node tools/west-flicker.cjs 4`, +the census, and a determinism check (the same seed, frame, world and hour rendered twice must be +byte-identical). + +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 +a broadband signal falls as one over the square root of the window; it is judged **only** at the +60 s default, prints-without-judging below that, and exits 3 rather than reporting a hazard that +belongs to the estimator. Run it with no arguments. diff --git a/README.md b/README.md index 8291660..3375246 100644 --- a/README.md +++ b/README.md @@ -37,15 +37,17 @@ afternoon, dusk — and `Y` stops and restarts the automatic cycle. That was not a free feature, and the reason is worth stating: the whole print pipeline is fitted to a frame that is more than half pure black with a thin scatter of bright glyphs, and daylight is the -inverse of that picture. It is answered with a **second exposure ladder**. By day the two night -pillars go out — a sodium lamp at noon is a grey tube and a screen is a dark rectangle — and white -and slate take the top of the table, because in daylight the bright things are surfaces rather than -sources. The two ladders are blended by the clock and the lookup table is rebuilt when the blend -crosses one of 32 steps, about once every thirteen seconds. +inverse of that picture. It is answered with a **second exposure ladder** — one entry per swatch, +twenty of each. By day the two night pillars go out (a sodium lamp at noon is a grey tube, a screen +is a dark rectangle) and the surfaces take the top of the table: white 0.92, sand 0.90, stone 0.82, +slate 0.78, moss 0.74, timber 0.72, because in daylight the bright things are surfaces rather than +sources. Rose goes the other way, from 0.20 to 0.18 — the lowest number in either table. The two +ladders are blended by the clock and the lookup table is rebuilt when the blend crosses one of 32 +steps, about once every thirteen seconds. -So a city at noon is a grey concrete canyon with dark glass in it under a bright sky, which is what -a city at noon is; and the frontier at noon is a pale road under a deep blue dome. Neither is the -night frame with the brightness turned up. +So a city at noon is a grey concrete canyon with dark glass in it under a lit sky, which is what a +city at noon is; and the frontier at noon is a road, two walls and a dome that all carry texture, +where a year ago all three were blank. Neither is the night frame with the brightness turned up. ![The same city at noon: concrete, dark glass, and the neon barely reading](docs/city-noon.png) @@ -53,22 +55,66 @@ An honest note on the numbers: `tools/metrics.py` prints a "muddy" census — th in the middle of the print's range — with a target under 30%, and a daylight frame does not meet it. It cannot: that target describes a night picture, where the middle of the range is haze to be crushed, and in daylight the middle of the range is where a lit wall, a road and a blue sky all -live. Measured at 200x60, seed 42: the city runs 32% at night, 56% at dusk and 64% at noon; the frontier -36% / 34% / 26%; and Moonwalk **2.8% / 1.8% / 1.3%**. The Moon can hold the night target at every -hour of its day because it has no air, which is the whole argument for it being the third world. +live. The other number is the hot tail, the share above the print's highlight line, target 3.5-5%, +and it moves the other way. Both, measured at 200x60 on frame 300 at two seeds, muddy% / hot%: -The other number in that census is the hot tail — the share above the print's highlight line, with -a 3.5-5% target — and it moves the other way: the city is 8.0% at night and 3.2% at noon, the -frontier 0.6% at dusk and 5.6% at noon, Moonwalk 3.5% at night and 6.6% at noon. Twilight in the -two atmospheric worlds is the flattest hour of the three, and that is not a bug to be tuned out: -it is the hour when the neon and the sky are the same brightness, which is exactly what makes it -look like twilight. +| | night | dusk | noon | +|---|---|---|---| +| **city** seed 42 | 30.0 / 7.27 | 53.1 / 0.41 | 52.0 / 3.46 | +| **city** seed 7 | 32.6 / 2.32 | 54.5 / 0.27 | 56.1 / 4.03 | +| **frontier** seed 42 | 40.9 / 0.18 | 46.5 / 0.28 | 49.0 / 5.31 | +| **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 | + +Three 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. + +The frontier is muddier at night than the city is, 40.9% against 30.0%, and that is the world and +not a fault: a city at night is towers standing in black, and the frontier is a lamplit dirt street +under a sky that is a third of the frame and never goes to zero. The number moves 14 points between +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. ![A dust storm coming up the road](docs/dust.png) Every cell you see is a character. There is no bitmap anywhere in the renderer — the towers, the rain, the wet road, the people on the pavement and the traffic lights are all `8`, `%`, `M`, `|` -and `.` in twelve colours. +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 +(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. + +Eight more, **appended and never inserted**, because a swatch index in this tree is a literal in +four other files and 0-11 are frozen: `stone`, `timber`, `sand`, `moss`, `indigo` — the five +things a daylight world is actually made of — and `jade`, `rose`, `gold` for signage. That split +is load-bearing. Sources blend on the **sun** through dawn and dusk and surfaces blend on the +**sky**, because "is this wall lit?" and "has this lamp stopped being the brightest thing here?" +are different questions with different answers for the whole of civil twilight. Put a surface on +the sun curve and the wall goes bright hours after the sky does. + +Every swatch carries **two exposure weights**, night and day, and the clock blends them. Measured +ceilings for the eight, printed at lum 255: gold 157, sand 138, jade 134, rose 131, stone 122, +indigo 115, timber 111, moss 94. Not one reaches the lower pillar — the extension added no light, +it added surfaces. Two of the numbers are arguments rather than fits: `sand` takes white's own gain +because a sunlit dirt road and a white wall are the same job in two worlds, and the 13-point gap +between their ceilings is entirely pigment; and `rose` takes 0.20, the lowest gain in either +ladder, because rose is hue 337 and this build's bloom over a hot pink cell is the failure that +walked violet off magenta years ago. At 0.20 the knee crushes every rose cell under lum 96 to +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. ## What is in it @@ -78,14 +124,26 @@ like and it hands them over; stop steering and it picks the walk back up from wh ![A patrol car with its lightbar running, market stalls along the pavement](docs/patrol.png) -- **The city** is generated from a seed. Avenues, cross streets, districts with their own colour - and character, blocks with setbacks and alleys and plazas that open the sky back up. +- **The city** is generated from a seed. Avenues, cross streets, **nine** districts with their own + colour and character, blocks with setbacks and alleys and plazas that open the sky back up. Six + of the nine are the originals; the three new ones are what the extended palette bought — `gilt` + is jade tile under brass sign frames, `market` is moss and weathered board, `finance` is indigo + glass with backlit panels and no chase lighting anywhere, because a bank's sign lights the wall + rather than the street. - **The street** has kerbs, crossings, drain grates, expansion joints, standing water that mirrors whatever is above it, and puddles placed on a world lattice so they hold still as you pass them. -- **People**, in twelve costume archetypes with their own silhouettes and their own walks — coats, - hoods, couriers, umbrellas, visors, a broad one, a slow one with a stick. They stand outside the - lit shops rather than spreading evenly down a dead block, they cross the road, they shelter when - it rains, and some of them walk in pairs. +- **People**, in **twenty-three** costume archetypes with their own silhouettes and their own + walks — coats, hoods, couriers, umbrellas, visors, a broad one, a slow one with a stick. They + stand outside the lit shops rather than spreading evenly down a dead block, they cross the road, + they shelter when it rains, and some of them walk in pairs. Fifteen of the twenty-three had + started repeating, and the honest reason was that all fifteen were one body with different trim: + a single run of black from a crown to a pair of feet, varying in width, hem and headgear. The + eight new ones break that run in a way you can count at eight rows, which is the only test that + matters, because at any moment most of the crowd is between six and twelve rows tall — somebody + holding a child by the hand (two crowns at two heights, and a count is the cheapest thing there + is to see), somebody walking a bicycle (a horizontal at hip height with daylight *under* it), + somebody with a plank over the shoulder drawn as a diagonal, a wheelchair, a tail-heavy hem. The + fifteen are byte-for-byte the silhouettes they were: every new field defaults to zero. - **Traffic** across the junctions, **aerial traffic** in lanes over the rooftops, **police** cars and officers on foot, and a cat. - **Shops** with types you can tell apart — a laundry is a row of round doors, a noodle counter is @@ -103,12 +161,26 @@ third world is the Moon and not, say, a jungle. The art direction is a frame tha pure black with a thin scatter of very bright glyphs, and every other world has to be composed to deliver that. The Moon delivers it by having no air: a shadow with nothing to fill it is genuinely lum 0, a sunlit surface under an unfiltered sun is genuinely the brightest thing there is, and the -sky is the same absolute black at noon as at midnight. Measured, a lunar frame prints **2.5% of its -cells in the muddy band** against the project's under-30% target and the city's 32%. +sky is the same absolute black at noon as at midnight. Measured, a lunar frame prints **5.0% of its +cells in the muddy band** against the project's under-30% target and the city's 30.0%. - **The ground** is an open regolith plain: the street lattice is still there and is made invisible — the pitch nearly doubles, the corridors double again and the blocks go 90% vacant — so the walk - still has somewhere to walk and you cannot see why. + still has somewhere to walk and you cannot see why. It also **rolls** now. Up to 2.8 m of relief + on two smoothstepped octaves of 54 m and 23 m goes onto every non-street lot, and the slope of it + shades the ground, so the horizon undulates and the near field has a direction to it. +- **No straight lines, and that was a removal.** This world used to carry a bootprint trail pinned + inside 0.62 m of the street centreline and two rover rails at exactly 1.03 m either side, running + the full length of every corridor. The argument for them was right — empty ground rendered + honestly reads as television static and needs something that converges — and the result was + wrong: two parallel dashed rails with a churned strip between them, receding to the vanishing + point, **is a road**, on any world, and a viewer said so. The convergence is replaced rather than + deleted, in four places and not one of them axis-aligned: a rover traverse that is a curve at 36 + degrees to the lattice wandering on two octaves, a rille, ejecta rays streaking from a point off + in the plain, and the rolling horizon itself — which is the cue the brief should have asked for + first. Terrain, not tyre tracks. The bootprints moved out of the painter entirely and now + scatter in clusters, the way a crew that mills about a work site and detours to a boulder + actually leaves them. - **Craters.** The one piece of geometry in any world whose height is a function of position *inside* a lot: a flat walkable floor with a raised rim round it on a sine profile, so the route can cross a crater rather than being fenced out of one. @@ -138,6 +210,40 @@ table and about a third of the elements are the frontier's own. sagebrush, saguaro, and one lot in fourteen carrying a flat-topped sandstone butte. - **The light.** One low sun in a fixed direction, and every wall in the world is either rimmed in amber or a silhouette. Which side of the street is lit changes when the walk turns a corner. +- **Daylight, which used to be empty.** At noon this world was a black frame with a scatter of + yellow dashes in it, and there were two separate reasons. The first was one line: the painter + picked its lit colour off a whitelist — `warm`, `white`, `ember`, else amber — written when the + only surface swatches in the palette were the city's, so every material the map has since learned + to name fell off the end and collapsed to amber. It now reads **three swatches per material**, + twenty rows deep and indexed by palette slot so an unknown hue degrades to its nearest neighbour + rather than to `undefined`: the planks that took the sun, the ones that are dusty or split or sit + a degree proud, and the ones with only sky on them. Weathered board in full daylight is silver, + not brown; the brown is what it is in shade, and getting that the wrong way round first put 2099 + of a noon frame's 4231 facade cells into one swatch and printed the middle of the picture as a + single dark band. +- **The second reason was that a glyph is not a pixel.** Rasterising every entry of the glyph table + at the size the print uses gives mean ink coverages from 2.6% for `` ` `` and 3.0% for `.` up to + 27.1% for `%` — a factor of ten between two cells written at the same brightness in the same + colour, and every measurement in this project counts brightness and colour and nothing counts + area. The night look is built out of `-`, `_`, `` ` `` and `.` and that is correct, because a + dark frame wants thin ink. The first cut of the day pass filled the walls, the road and the sky + in those same four glyphs at three times the brightness, and the census scored it 45.2% lit and + 10.5% hot while the picture on screen was still black: 45% of a frame at 4% ink is 1.8% of the + frame's area with anything on it at all. Daylight surfaces pick off an eleven-step ink ramp + instead, stopping at `%` — `8`, `M` and `Q` are spoken for as lit windows and stones, and past + about 30% ink the bloom welds neighbouring cells into a solid block. +- **All of it is gated on one number, and it is zero at dusk.** The fill is the sky level pushed + through a threshold at 0.70 and a smoothstep. The clock reports the sky at 0.000 night, + 0.657 dawn *and* dusk, 0.929 morning, 1.000 noon — so that threshold decides exactly one thing: + whether the two tuned hours get any of this at all. 0.60 looked safe, a twentieth being under the + dither's own noise floor, and it was not: rendered and censused at dusk it moved blank 48.0% -> + 41.7% and muddy 46.3% -> 51.6%, because a twentieth of the fill lands on *every* blank cell of + every wall, road and sky and there are a great many of them. At 0.70, dawn and dusk are + byte-identical to the build before this pass, the same guarantee night has, and the whole + crossover happens in the unnamed hours where nothing is fitted. It is also only ever used as a + **dither probability**, never as a brightness step — the wall does not switch on, it dissolves a + few cells at a time over about ninety seconds of wall clock, which is what keeps it out of the + photosensitivity gate's way. - **The sky.** It is a third of the frame out here, so it is the subject: a banded dusk gradient, the sun with its halo, altocumulus bars lit orange along their undersides, the earth-shadow band rising in the east, and three vultures on a thermal. @@ -163,7 +269,15 @@ a cyan halo straight over the sunset because it won the depth test against the f and four hundred stars — the brightest of them in the neon-cyan swatch — were being painted over a sky with the sun still visibly above the horizon. All of that is gone: the sci-fi costume fields are gated, the night sky is driven by the clock so it fades out properly at dawn, and no surface in -that world takes azure, violet or ice any more. +that world takes azure, violet or ice at night any more. + +All three have since come back, by daylight only, and it is worth saying where so nobody +re-reports the bug. The sky dome takes azure and violet at altitude because a noon sky is blue and +a zenith is deeper than a horizon, and an unlit windowpane takes `ice` because dark glass reflects +the sky and that faint cool cell is the only reason an unlit window is visible at all. `ice` and +not `azure`: ice is a glint weight and azure is a pillar, so one dark pane in azure would be the +brightest thing on the building. Both are dithered on the daylight fill, which is zero at dusk and +at night, so the night frame still has none of it. ## Controls @@ -199,7 +313,8 @@ 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 second world is reached by its URL, `#west/42`. +a control — so on a phone the other two worlds are reached by their URLs, `#west/42` and +`#moon/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. @@ -219,19 +334,46 @@ same for storm lightning specifically. `tools/west-flicker.cjs` does it for ever city, with the camera pinned so nothing in the frame can change except time, in every one of that world's weather states. All three have to pass before anything ships. -A word on how to run it: under two seconds of measured window the 3-20 Hz figure is noise, and the -tool now says so. The same tree measured 10.6% in-band at one second and 2.65% at three; only the -second number means anything, and believing the first cost twenty minutes. +A word on how to run it, and it is the part that has cost the most time. The 3-20 Hz figure is the +largest single bin of a windowed transform. For a *coherent* flicker — a tube alternating at 8 Hz — +that number is the amplitude of the tube and does not care how long you watched. For a *broadband* +one it is a periodogram bin of a noise process, its value is the square root of the power density +times the bin width, the bin width is one over the window, and so the same signal reads lower the +longer you look at it, for ever. The failing-starter personality in the city's signage is +broadband — value noise at 2.8 control points a second through a smoothstep gate has no line in it +at all — and it measures, on one tree, one seed, one window length apart: + +``` + 2 s 8.07% 3 s 5.41% 4 s 4.10% 8 s 3.58% 16 s 2.45% + 30 s 1.58% 45 s 1.58% 60 s 1.46% 90 s 1.13% 120 s 0.94% +``` + +with the reported peak wandering over 3.00-3.53 Hz, always against the bottom edge of the band, +which is what a spectrum with no line in it looks like. So the 2% limit means one thing at 60 +seconds and something else at four, and `flicker-rate.cjs` used to answer a four-second run with +`FAIL 3-20Hz` — a hazard report generated by the estimator rather than by the city. It now runs +that rule only at the window it was fitted at, prints the number without judging it below that, and +exits 3 (NOT APPLICABLE) so a short run cannot be mistaken for a pass. The two tempting repairs +are both refused in the source: normalising by the square root of the window would flatten the +noise case and would shrink a real 5 Hz tube by four times at a four-second window, which is a +safety regression dressed as a fix; and moving the limit is moving the limit. **Run it with no +arguments.** The step, dropout and per-cell rules have no bin width in them and are honest at any +window. The frontier's gate found two real hazards and both were redesigned rather than tuned down. The windmill was eight dark spokes chopping a bright sky at 4.7 big steps a second against a limit of 1 — it is now a static rim with one bright vane travelling round it, because no rotation rate low enough to be safe still reads as a turning wheel. The chimney smoke was five discrete dark puffs crossing the sunset; it is now a continuous plume, drawn far paler, so the cells it occupies stay -occupied and only the sway moves them. After both, the frontier's own elements step at 1.7 times a -second against the city's own 7.7, and carry 2.6% of full scale in the 3-20 Hz band against the -city's 6.5%. 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. +occupied and only the sway moves them. Measured now, at a four-second window with the camera +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. `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 @@ -251,8 +393,21 @@ node build.js `index.html` is generated — don't edit it by hand. `build.js` concatenates the modules in `src/`, strips the CommonJS tails that exist only so the offline tools can `require` the same -files, and writes one file. There is no bundler and no minifier: the source stays readable in -View Source, which is half the point of shipping it as a single file. +files, strips the comments, halves the leading indentation, and writes one file. There is no +bundler and no minifier: the page source stays readable in View Source, which is half the point of +shipping it as a single file. + +The half-indent is the only thing in that list that was not always there, and it is a budget note +rather than a formatting preference. `build.js` fails the build over 560 KB, and the essay attached +to that line says in as many words that the next pass over it must **cut** rather than move the +number. This pass went over, at 575.5 KB. The two things the essay names as cuttable are content +(which is the deliverable — the wrong way round) and indentation, which it refuses on the grounds +that stripping it turns a viewable page source into a wall. Both halves of that refusal turned out +to rest on stale figures: the estimate in the source said "about 25 KB" and the measurement is +**84,232 bytes over 16,505 lines, 14.3% of the file**, and halving is not stripping. Every line +keeps its structure at one space per level. 42,134 bytes, 534.4 KB, and the line did not move. +Nothing you can see in a frame changed: the folded and unfolded bundles are byte-identical once +leading whitespace is removed. ## How it draws @@ -263,14 +418,14 @@ buildings, all for free and all at character resolution. Everything after that — rain, people, signage, cars, optics — is an *element*: a small module with `init`, `update` and `draw`, drawn in layer order onto the same character buffer, depth-tested -against the world so a walker goes behind a lamp post. There are 51 of them. Each one belongs to -one world or to both — an element carries `world: 'cyber'` or `world: 'west'` on itself and -`main.js` filters the list on a rebuild, so the city gets 42 and the frontier gets 26. +against the world so a walker goes behind a lamp post. There are 70 of them. Each one belongs to +one world or to several — an element carries `world: 'cyber'`, or an array of ids, on itself and +`main.js` filters the list on a rebuild, so the city gets 42, the frontier 33 and the Moon 16. -The last stage is a print. Each of the twelve colours has its own exposure weight, then a gamma -lift, a knee and a shoulder rolloff, bucketed by distance. It is the difference between a frame -that is technically correct and one that reads as a photograph of a dark street, and most of the -tuning in this repo is about it. +The last stage is a print. Each of the twenty colours has **two** exposure weights, night and day, +blended by the clock, then a gamma lift, a knee and a shoulder rolloff, bucketed by distance. It is +the difference between a frame that is technically correct and one that reads as a photograph of a +dark street, and most of the tuning in this repo is about it. ## Tools @@ -282,7 +437,7 @@ Everything here runs without a browser, which is how the thing gets verified at | `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 | +| `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/domshim.cjs` | runs the built page against a fake DOM — boot, resize, input, worlds, tab loss | diff --git a/build.js b/build.js index f91001b..8a514f0 100644 --- a/build.js +++ b/build.js @@ -98,12 +98,47 @@ const IDENT = /[A-Za-z0-9_$]/; * literal and every comment after it ships. */ const DIV_AFTER = /[A-Za-z0-9_$)\]]/; +/* ---- indent folding ------------------------------------------------------------------------- + * Two spaces of indent per level become one, and ONLY at the start of a line the scanner reached + * through the code path — never inside a string, because a template literal's newline is emitted + * by the string branch below and the fold only ever fires immediately after the fallthrough or the + * block-comment branch has written a '\n' itself. Multi-line templates are therefore safe by + * construction rather than by inspection, which matters: there are none in src/ today and this has + * to keep being true when there are. + * + * WHY IT HAPPENED, and it is a raise refused rather than a tidy. The 560 KB budget below is a + * commitment with a whole essay attached saying the next pass over the line must CUT before it + * moves the number. This pass went over — three worlds' worth of texture and colour work landed at + * 575.5 KB — and the two things the essay names as cuttable are content (wrong way round; that is + * the deliverable) and indentation, which it refuses on the grounds that stripping it turns a + * viewable page source into a wall. + * + * Both of the numbers that refusal rests on are now false, and that is the finding. The note under + * the return below says indentation costs "~6 KB"; the budget essay says "about 25 KB". MEASURED on + * the bundle this pass produces: 84,232 bytes of leading whitespace over 16,505 lines, 14.3% of the + * file. It stopped being a rounding error two worlds ago and nobody re-measured it. + * + * So the fold is the middle answer neither note considered: HALVE it, do not strip it. Every line + * keeps its indentation and its structure, at one space per level instead of two, and the page + * source is still a nested document rather than a wall — which is the thing the refusal was + * actually protecting. Worth 42,134 bytes, taking the bundle to 534.4 KB with 25.6 KB of headroom + * under a line that does not move. Rejected: stripping indentation outright (worth 84 KB and it is + * the wall the note refuses), and stripping the blank line decomment leaves between paragraphs + * (2.4 KB, and it is the only thing left separating one thought from the next). */ +function foldIndent(src, i) { + let w = 0; + while (i < src.length && (src[i] === ' ' || src[i] === '\t')) { w++; i++; } + return { text: w > 1 ? ' '.repeat(w >> 1) : '', i: i }; +} + function decomment(src) { let out = '', i = 0, prev = '', word = ''; const n = src.length; /* ...except after a keyword, where `return /re/` is a regex even though `n` is an ident char. */ const regexAllowed = () => prev === '' || !DIV_AFTER.test(prev) || REGEX_OK_WORDS.has(word); + { const f = foldIndent(src, 0); out += f.text; i = f.i; } // the file's own first line + while (i < n) { const c = src[i]; @@ -118,7 +153,10 @@ function decomment(src) { /* A comment sits BETWEEN two tokens, so it cannot vanish without leaving a separator behind * or an inline one welds its two neighbours into a single identifier. A multi-line one * collapses to a newline instead, so ASI keeps behaving exactly as it did in src/. */ - out += src.slice(start, i).indexOf('\n') >= 0 ? '\n' : ' '; + if (src.slice(start, i).indexOf('\n') >= 0) { + out += '\n'; + const f = foldIndent(src, i); out += f.text; i = f.i; + } else out += ' '; continue; } if (c === '"' || c === "'" || c === '`') { @@ -145,13 +183,15 @@ function decomment(src) { } out += c; i++; + if (c === '\n') { const f = foldIndent(src, i); out += f.text; i = f.i; continue; } if (!/\s/.test(c)) { prev = c; word = IDENT.test(c) ? word + c : ''; } } - /* Trailing whitespace and the blank lines the comments left behind. Indentation stays — it costs - * ~6 KB and it is the difference between a viewable page source and a wall. */ + /* Trailing whitespace and the blank lines the comments left behind. Indentation is HALVED rather + * than kept whole or stripped — see foldIndent above for the measurement that changed the answer + * and the 84,232 bytes it was hiding. */ return out.replace(/[ \t]+$/gm, '').replace(/\n{2,}/g, '\n\n').trim(); } @@ -342,7 +382,28 @@ console.log('index.html ' + bytes + ' bytes (' + (bytes / 1024).toFixed(1) + ' * There is now an obvious place to find room that did not exist before — the frontier and the city * do not need to be in the same response, and splitting them is a real answer that costs the * "one self-contained file" property. Spend that only when it is the last option, and write down - * that you did. */ + * that you did. + * + * ---- AND THE PASS AFTER THAT WENT OVER AND THE LINE DID NOT MOVE. 560 KB HELD, AT 534.4. ---- + * Fourth time at this line, first time it has held under pressure, and the paragraph two above + * asking for a cut is the one that got answered. + * + * WHAT LANDED: a colour pass across all three worlds — eight swatches appended to the palette with + * a night and a day rung each, a daylight fill for the frontier's walls, road and dome, a widened + * district table and a longer crowd for the city, and relief on the Moon in place of straight + * lattice edges. Sixteen files, +4413 lines of src/, and 49.6 KB of stripped bundle. That put the + * build at 589,337 bytes — 575.5 KB, 15.5 over — and it failed here, which is the gate working. + * + * WHAT WAS CUT: nothing anybody can see. 42,018 bytes of leading whitespace, by halving the indent + * in decomment() rather than stripping it; the reasoning and the rejected alternatives are written + * out at foldIndent(). The short version is that this line's own essay named indentation as worth + * "about 25 KB" and refused it as a wall, and both halves of that are wrong now: it is 84,232 + * bytes, and halving is not stripping. 534.4 KB, 25.6 KB under. + * + * 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'); process.exit(1); diff --git a/docs/city-noon.png b/docs/city-noon.png index ec47a5a..89a352f 100644 Binary files a/docs/city-noon.png and b/docs/city-noon.png differ diff --git a/docs/downpour.png b/docs/downpour.png index e55dfd6..a69c97d 100644 Binary files a/docs/downpour.png and b/docs/downpour.png differ diff --git a/docs/dust.png b/docs/dust.png index 9b9d928..454d08f 100644 Binary files a/docs/dust.png and b/docs/dust.png differ diff --git a/docs/frontier.png b/docs/frontier.png index e8d5924..8ae1e42 100644 Binary files a/docs/frontier.png and b/docs/frontier.png differ diff --git a/docs/moonwalk.png b/docs/moonwalk.png index 0a98bec..7932bae 100644 Binary files a/docs/moonwalk.png and b/docs/moonwalk.png differ diff --git a/docs/patrol.png b/docs/patrol.png index 8e973cd..0d5e990 100644 Binary files a/docs/patrol.png and b/docs/patrol.png differ diff --git a/docs/signage.png b/docs/signage.png index a9456df..b7dad17 100644 Binary files a/docs/signage.png and b/docs/signage.png differ diff --git a/docs/street.png b/docs/street.png index c34342e..83443d0 100644 Binary files a/docs/street.png and b/docs/street.png differ diff --git a/index.html b/index.html index 1211de1..8acf632 100644 --- a/index.html +++ b/index.html @@ -35,15211 +35,16466 @@ (function () { /* src/core.js */ var CC = (function () { - 'use strict'; + 'use strict'; - var PALETTE = [ - [216, 232, 74], - [ 74, 168, 232], - [224, 114, 74], - [ 42, 197, 147], - [130, 86, 230], + var PALETTE = [ + [216, 232, 74], + [ 74, 168, 232], + [224, 114, 74], + [ 42, 197, 147], + [130, 86, 230], - [216, 226, 236], - [255, 92, 92], - [ 62, 98, 138], + [216, 226, 236], + [255, 92, 92], + [ 62, 98, 138], - [255, 214, 120], - [ 90, 240, 255], - [255, 255, 255], - [ 40, 50, 66] - ]; - var P = { amber:0, azure:1, ember:2, spring:3, violet:4, white:5, red:6, - slate:7, warm:8, ice:9, pure:10, shadow:11 }; + [255, 214, 120], + [ 90, 240, 255], + [255, 255, 255], + [ 40, 50, 66], - var GLYPHS = " .,:;'\"`^~-_=+*|/\\()[]{}<>!?#%&$@8OoQ0XZWMNHUVAKY".split(''); - var GI = {}; - for (var i = 0; i < GLYPHS.length; i++) GI[GLYPHS[i]] = i; - function g(c) { var v = GI[c]; return v === undefined ? 0 : v; } + [156, 162, 170], - function makeFrame(cols, rows) { - var n = cols * rows; - return { - cols: cols, rows: rows, n: n, - ch: new Uint8Array(n), - col: new Uint8Array(n), - lum: new Uint8Array(n), - dist: new Float32Array(n), - kind: new Uint8Array(n) - }; - } + [150, 98, 58], - function clearFrame(f) { - f.ch.fill(0); f.col.fill(0); f.lum.fill(0); f.kind.fill(0); - f.dist.fill(Infinity); - } + [216, 186, 132], - function put(f, x, y, chIdx, colIdx, lum, dist, kind) { - x = x | 0; y = y | 0; - if (x < 0 || y < 0 || x >= f.cols || y >= f.rows) return false; - var i = y * f.cols + x; - if (!(dist < f.dist[i])) return false; - f.ch[i] = chIdx; f.col[i] = colIdx; - f.lum[i] = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - f.dist[i] = dist; f.kind[i] = kind === undefined ? 3 : kind; - return true; - } + [ 26, 148, 138], - function poke(f, i, chIdx, colIdx, lum, dist, kind) { - f.ch[i] = chIdx; f.col[i] = colIdx; - f.lum[i] = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - f.dist[i] = dist; f.kind[i] = kind; - } + [238, 102, 150], - function hash2(x, y, s) { - var h = (Math.imul(x | 0, 374761393) + Math.imul(y | 0, 668265263) + - Math.imul(s | 0, 2147483647)) | 0; - h = Math.imul(h ^ (h >>> 15), 2246822507); - h = Math.imul(h ^ (h >>> 13), 3266489909); - return ((h ^ (h >>> 16)) >>> 0) / 4294967296; - } - function hash1(x, s) { return hash2(x, 0, s); } - function mulberry(seed) { - var a = seed >>> 0; - return function () { - a |= 0; a = (a + 0x6D2B79F5) | 0; - var t = Math.imul(a ^ (a >>> 15), 1 | a); - t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; - return ((t ^ (t >>> 14)) >>> 0) / 4294967296; - }; - } - function lerp(a, b, t) { return a + (b - a) * t; } - function clamp(v, a, b) { return v < a ? a : (v > b ? b : v); } - function smooth(t) { return t * t * (3 - 2 * t); } - function vnoise(x, s) { - var i = Math.floor(x), f = x - i; - return lerp(hash1(i, s), hash1(i + 1, s), smooth(f)); - } + [240, 176, 72], - var EXPOSURE = [ - 0.50, + [ 92, 126, 74], - 1.00, + [ 58, 70, 142] - 0.42, + ]; + var P = { amber:0, azure:1, ember:2, spring:3, violet:4, white:5, red:6, + slate:7, warm:8, ice:9, pure:10, shadow:11, + stone:12, timber:13, sand:14, jade:15, rose:16, gold:17, moss:18, indigo:19 }; - 0.60, - - 0.34, - - 0.30, - - 0.56, - - 0.60, - - 0.32, - - 0.36, - - 0.85, - 0.80 - - ]; - - var GAMMA = 0.33; - - var KNEE = 0.075; - - var SHOULDER = 0.62; - var DBUCKETS = 8; - var FOG_START = 12.0, FOG_END = 125.0; - - var SKY_D = FOG_END; - - var EXPOSURE_DAY = [ - - 0.42, - 0.52, - 0.46, - 0.70, - 0.26, - 0.92, - 0.50, - 0.78, - 0.62, - 0.66, - 0.85, - 0.46 - ]; - var GAMMA_DAY = 0.62, KNEE_DAY = 0.030; - - var DAY_STEPS = 32; - var dayMix = 0, daySun = 0, dayStep = -1; - - function ladder(c, mix, sunMix) { - - var src = (c === 0 || c === 1 || c === 8 || c === 9); - var m = src ? sunMix * sunMix : mix; - return EXPOSURE[c] + (EXPOSURE_DAY[c] - EXPOSURE[c]) * m; - } - - var LUT = new Uint8Array(DBUCKETS * PALETTE.length * 256); - function buildLUT(mix, sunMix) { - var np = PALETTE.length, t = LUT; - var GM = GAMMA + (GAMMA_DAY - GAMMA) * mix; - var KN = KNEE + (KNEE_DAY - KNEE) * mix; - for (var b = 0; b < DBUCKETS; b++) { - - var df = (b + 0.5) / DBUCKETS; - var gm = GM + (1 - GM) * df; - for (var c = 0; c < np; c++) { - var gain = ladder(c, mix, sunMix); - for (var l = 0; l < 256; l++) { - var x = l * gain / 255; - - if (x > SHOULDER) x = SHOULDER + (1 - SHOULDER) * (1 - Math.exp(-(x - SHOULDER) / (1 - SHOULDER))); - var k = x / KN; if (k > 1) k = 1; - var y = Math.pow(x, gm) * (k * k * (3 - 2 * k)); - var v = (y * 255 + 0.5) | 0; - t[(b * np + c) * 256 + l] = v > 255 ? 255 : v; - } - } - } - } - buildLUT(0, 0); - dayStep = 0; - - function setDayMix(mix, sunMix) { - if (!(mix >= 0)) mix = 0; else if (mix > 1) mix = 1; - if (!(sunMix >= 0)) sunMix = 0; else if (sunMix > 1) sunMix = 1; - - var step = Math.round(mix * DAY_STEPS) * (DAY_STEPS + 1) + Math.round(sunMix * DAY_STEPS); - if (step === dayStep) return; - dayStep = step; - dayMix = Math.round(mix * DAY_STEPS) / DAY_STEPS; - daySun = Math.round(sunMix * DAY_STEPS) / DAY_STEPS; - buildLUT(dayMix, daySun); - } - - var DSCALE = DBUCKETS / (FOG_END - FOG_START); - - function tone(f) { - var n = f.n, lum = f.lum, col = f.col, dist = f.dist, ch = f.ch, np = PALETTE.length; - for (var i = 0; i < n; i++) { - var l = lum[i]; - if (l === 0 || ch[i] === 0) continue; - var d = dist[i], b; - - if (d >= SKY_D) b = 0; - else if (!(d > FOG_START)) b = 0; - else if (!(d < FOG_END)) b = DBUCKETS - 1; - else { b = ((d - FOG_START) * DSCALE) | 0; if (b > DBUCKETS - 1) b = DBUCKETS - 1; } - lum[i] = LUT[((b * np + (col[i] % np)) << 8) + l]; - } - } - - var Compose = { - post: function (f, cam, t) { - var D = CC && CC.Daylight; - setDayMix(D ? D.P.sky : 0, D ? D.P.sun : 0); - tone(f); - } - }; - - var PAVE = 2.15; + var GLYPHS = " .,:;'\"`^~-_=+*|/\\()[]{}<>!?#%&$@8OoQ0XZWMNHUVAKY".split(''); + var GI = {}; + for (var i = 0; i < GLYPHS.length; i++) GI[GLYPHS[i]] = i; + function g(c) { var v = GI[c]; return v === undefined ? 0 : v; } + function makeFrame(cols, rows) { + var n = cols * rows; return { - PALETTE: PALETTE, P: P, GLYPHS: GLYPHS, g: g, GI: GI, PAVE: PAVE, - tone: tone, Compose: Compose, EXPOSURE: EXPOSURE, EXPOSURE_DAY: EXPOSURE_DAY, - setDayMix: setDayMix, get dayMix() { return dayMix; }, get daySun() { return daySun; }, - makeFrame: makeFrame, clearFrame: clearFrame, put: put, poke: poke, - hash1: hash1, hash2: hash2, mulberry: mulberry, - lerp: lerp, clamp: clamp, smooth: smooth, vnoise: vnoise, - ELEMENTS: [], reducedMotion: false + cols: cols, rows: rows, n: n, + ch: new Uint8Array(n), + col: new Uint8Array(n), + lum: new Uint8Array(n), + dist: new Float32Array(n), + kind: new Uint8Array(n) }; + } + + function clearFrame(f) { + f.ch.fill(0); f.col.fill(0); f.lum.fill(0); f.kind.fill(0); + f.dist.fill(Infinity); + } + + function put(f, x, y, chIdx, colIdx, lum, dist, kind) { + x = x | 0; y = y | 0; + if (x < 0 || y < 0 || x >= f.cols || y >= f.rows) return false; + var i = y * f.cols + x; + if (!(dist < f.dist[i])) return false; + f.ch[i] = chIdx; f.col[i] = colIdx; + f.lum[i] = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + f.dist[i] = dist; f.kind[i] = kind === undefined ? 3 : kind; + return true; + } + + function poke(f, i, chIdx, colIdx, lum, dist, kind) { + f.ch[i] = chIdx; f.col[i] = colIdx; + f.lum[i] = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + f.dist[i] = dist; f.kind[i] = kind; + } + + function hash2(x, y, s) { + var h = (Math.imul(x | 0, 374761393) + Math.imul(y | 0, 668265263) + + Math.imul(s | 0, 2147483647)) | 0; + h = Math.imul(h ^ (h >>> 15), 2246822507); + h = Math.imul(h ^ (h >>> 13), 3266489909); + return ((h ^ (h >>> 16)) >>> 0) / 4294967296; + } + function hash1(x, s) { return hash2(x, 0, s); } + function mulberry(seed) { + var a = seed >>> 0; + return function () { + a |= 0; a = (a + 0x6D2B79F5) | 0; + var t = Math.imul(a ^ (a >>> 15), 1 | a); + t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; + return ((t ^ (t >>> 14)) >>> 0) / 4294967296; + }; + } + function lerp(a, b, t) { return a + (b - a) * t; } + function clamp(v, a, b) { return v < a ? a : (v > b ? b : v); } + function smooth(t) { return t * t * (3 - 2 * t); } + function vnoise(x, s) { + var i = Math.floor(x), f = x - i; + return lerp(hash1(i, s), hash1(i + 1, s), smooth(f)); + } + + var EXPOSURE = [ + 0.50, + + 1.00, + + 0.42, + + 0.60, + + 0.34, + + 0.30, + + 0.56, + + 0.60, + + 0.32, + + 0.36, + + 0.85, + 0.80, + + 0.41, + + 0.44, + + 0.30, + + 0.80, + + 0.20, + + 0.32, + + 0.46, + + 0.56 + + ]; + + var GAMMA = 0.33; + + var KNEE = 0.075; + + var SHOULDER = 0.62; + var DBUCKETS = 8; + var FOG_START = 12.0, FOG_END = 125.0; + + var SKY_D = FOG_END; + + var EXPOSURE_DAY = [ + + 0.42, + 0.52, + 0.46, + 0.70, + 0.26, + 0.92, + 0.50, + 0.78, + 0.62, + 0.66, + 0.85, + 0.46, + + 0.82, + + 0.72, + + 0.90, + + 0.58, + + 0.18, + + 0.38, + + 0.74, + + 0.62 + + ]; + var GAMMA_DAY = 0.62, KNEE_DAY = 0.030; + + var DAY_STEPS = 32; + var dayMix = 0, daySun = 0, dayStep = -1; + + function ladder(c, mix, sunMix) { + + var src = (c === 0 || c === 1 || c === 8 || c === 9 || + c === 15 || c === 16 || c === 17); + var m = src ? sunMix * sunMix : mix; + return EXPOSURE[c] + (EXPOSURE_DAY[c] - EXPOSURE[c]) * m; + } + + var LUT = new Uint8Array(DBUCKETS * PALETTE.length * 256); + function buildLUT(mix, sunMix) { + var np = PALETTE.length, t = LUT; + var GM = GAMMA + (GAMMA_DAY - GAMMA) * mix; + var KN = KNEE + (KNEE_DAY - KNEE) * mix; + for (var b = 0; b < DBUCKETS; b++) { + + var df = (b + 0.5) / DBUCKETS; + var gm = GM + (1 - GM) * df; + for (var c = 0; c < np; c++) { + var gain = ladder(c, mix, sunMix); + for (var l = 0; l < 256; l++) { + var x = l * gain / 255; + + if (x > SHOULDER) x = SHOULDER + (1 - SHOULDER) * (1 - Math.exp(-(x - SHOULDER) / (1 - SHOULDER))); + var k = x / KN; if (k > 1) k = 1; + var y = Math.pow(x, gm) * (k * k * (3 - 2 * k)); + var v = (y * 255 + 0.5) | 0; + t[(b * np + c) * 256 + l] = v > 255 ? 255 : v; + } + } + } + } + buildLUT(0, 0); + dayStep = 0; + + function setDayMix(mix, sunMix) { + if (!(mix >= 0)) mix = 0; else if (mix > 1) mix = 1; + if (!(sunMix >= 0)) sunMix = 0; else if (sunMix > 1) sunMix = 1; + + var step = Math.round(mix * DAY_STEPS) * (DAY_STEPS + 1) + Math.round(sunMix * DAY_STEPS); + if (step === dayStep) return; + dayStep = step; + dayMix = Math.round(mix * DAY_STEPS) / DAY_STEPS; + daySun = Math.round(sunMix * DAY_STEPS) / DAY_STEPS; + buildLUT(dayMix, daySun); + } + + var DSCALE = DBUCKETS / (FOG_END - FOG_START); + + function tone(f) { + var n = f.n, lum = f.lum, col = f.col, dist = f.dist, ch = f.ch, np = PALETTE.length; + for (var i = 0; i < n; i++) { + var l = lum[i]; + if (l === 0 || ch[i] === 0) continue; + var d = dist[i], b; + + if (d >= SKY_D) b = 0; + else if (!(d > FOG_START)) b = 0; + else if (!(d < FOG_END)) b = DBUCKETS - 1; + else { b = ((d - FOG_START) * DSCALE) | 0; if (b > DBUCKETS - 1) b = DBUCKETS - 1; } + lum[i] = LUT[((b * np + (col[i] % np)) << 8) + l]; + } + } + + var Compose = { + post: function (f, cam, t) { + var D = CC && CC.Daylight; + setDayMix(D ? D.P.sky : 0, D ? D.P.sun : 0); + tone(f); + } + }; + + var PAVE = 2.15; + + return { + PALETTE: PALETTE, P: P, GLYPHS: GLYPHS, g: g, GI: GI, PAVE: PAVE, + tone: tone, Compose: Compose, EXPOSURE: EXPOSURE, EXPOSURE_DAY: EXPOSURE_DAY, + setDayMix: setDayMix, get dayMix() { return dayMix; }, get daySun() { return daySun; }, + makeFrame: makeFrame, clearFrame: clearFrame, put: put, poke: poke, + hash1: hash1, hash2: hash2, mulberry: mulberry, + lerp: lerp, clamp: clamp, smooth: smooth, vnoise: vnoise, + ELEMENTS: [], reducedMotion: false + }; })(); /* src/world.js */ (function (CC) { - 'use strict'; + 'use strict'; - 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'] } - ]; + 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'] } + ]; - var cur = 0; + var cur = 0; - function indexOf(id) { - for (var i = 0; i < LIST.length; i++) if (LIST[i].id === id) return i; - return -1; + function indexOf(id) { + for (var i = 0; i < LIST.length; i++) if (LIST[i].id === id) return i; + return -1; + } + + function resolve(v) { + if (typeof v === 'number') { + var i = v | 0; + + if (i >= 1 && i <= LIST.length) return i - 1; + if (i === 0) return 0; + return -1; } + if (typeof v === 'string') { + var s = v.toLowerCase(); + var k = indexOf(s); + if (k >= 0) return k; - function resolve(v) { - if (typeof v === 'number') { - var i = v | 0; - - if (i >= 1 && i <= LIST.length) return i - 1; - if (i === 0) return 0; - return -1; - } - if (typeof v === 'string') { - var s = v.toLowerCase(); - var k = indexOf(s); - if (k >= 0) return k; - - for (var i = 0; i < LIST.length; i++) { - var a = LIST[i].aliases; - if (!a) continue; - for (var j = 0; j < a.length; j++) if (a[j] === s) return i; - } - if (/^\d+$/.test(s)) return resolve(parseInt(s, 10)); - } - return -1; + for (var i = 0; i < LIST.length; i++) { + var a = LIST[i].aliases; + if (!a) continue; + for (var j = 0; j < a.length; j++) if (a[j] === s) return i; + } + if (/^\d+$/.test(s)) return resolve(parseInt(s, 10)); } + return -1; + } - var World = { - LIST: LIST, + var World = { + LIST: LIST, - DEFAULT: LIST[0].id, - id: LIST[0].id, - name: LIST[0].name, - index: 0, + DEFAULT: LIST[0].id, + id: LIST[0].id, + name: LIST[0].name, + index: 0, - get count() { return LIST.length; }, + get count() { return LIST.length; }, - inWorld: function (el, id) { - var w = el && el.world; - if (!w) return true; - if (typeof w === 'string') return w === id; - for (var i = 0; i < w.length; i++) if (w[i] === id) return true; - return false; - }, + inWorld: function (el, id) { + var w = el && el.world; + if (!w) return true; + if (typeof w === 'string') return w === id; + for (var i = 0; i < w.length; i++) if (w[i] === id) return true; + return false; + }, - is: function (id) { return World.id === id; }, + is: function (id) { return World.id === id; }, - at: function (v) { var i = resolve(v); return i < 0 ? null : LIST[i]; }, + at: function (v) { var i = resolve(v); return i < 0 ? null : LIST[i]; }, - set: function (v) { - var i = resolve(v); - if (i < 0 || i === cur) return 0; - cur = i; - World.id = LIST[i].id; World.name = LIST[i].name; World.index = i; - return 1; - }, + set: function (v) { + var i = resolve(v); + if (i < 0 || i === cur) return 0; + cur = i; + World.id = LIST[i].id; World.name = LIST[i].name; World.index = i; + return 1; + }, - force: function (v) { - var i = resolve(v); - if (i < 0) return 0; - cur = i; - World.id = LIST[i].id; World.name = LIST[i].name; World.index = i; - return 1; - }, + force: function (v) { + var i = resolve(v); + if (i < 0) return 0; + cur = i; + World.id = LIST[i].id; World.name = LIST[i].name; World.index = i; + return 1; + }, - cycle: function (dir) { - return World.set(LIST[(cur + (dir < 0 ? LIST.length - 1 : 1)) % LIST.length].id); - } - }; + cycle: function (dir) { + return World.set(LIST[(cur + (dir < 0 ? LIST.length - 1 : 1)) % LIST.length].id); + } + }; - CC.inWorld = World.inWorld; + CC.inWorld = World.inWorld; - CC.World = World; + CC.World = World; })(CC); /* src/proj.js */ (function (CC) { - 'use strict'; + 'use strict'; - var put = CC.put, clamp = CC.clamp; + var put = CC.put, clamp = CC.clamp; - CC.Proj = { + CC.Proj = { - make: function () { + make: function () { - var V = { - ox: 0, oz: 0, eyeY: 1.7, fwx: 0, fwz: 1, rgx: 1, rgz: 0, - hp: 0.7265, colK: 0, colMid: 0, scale: 77, horizon: 33, cols: 0, rows: 0, far: 125, t: 0 - }; - var PJ = { x: 0, y: 0, d: 0 }; - var Surf = null; + var V = { + ox: 0, oz: 0, eyeY: 1.7, fwx: 0, fwz: 1, rgx: 1, rgz: 0, + hp: 0.7265, colK: 0, colMid: 0, scale: 77, horizon: 33, cols: 0, rows: 0, far: 125, t: 0 + }; + var PJ = { x: 0, y: 0, d: 0 }; + var Surf = null; - function view(f, cam, t) { - if (!Surf) Surf = CC.Surf; - var fov = cam.fov || 1.25, hp = Math.tan(fov * 0.5); - var cellA = cam.cellAspect || 0.5625; - V.cols = f.cols; V.rows = f.rows; V.hp = hp; - V.colK = f.cols * 0.5 / hp; V.colMid = f.cols * 0.5; - V.scale = cam.scaleY !== undefined ? cam.scaleY : (f.cols * cellA) / (2 * hp); - V.horizon = cam.horizon !== undefined ? cam.horizon : f.rows * 0.56; - V.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - var yaw = cam.yaw || 0; - V.fwx = Math.sin(yaw); V.fwz = Math.cos(yaw); - V.rgx = Math.cos(yaw); V.rgz = -Math.sin(yaw); - V.ox = cam.x; V.oz = cam.z; - V.far = Surf ? Surf.FOG_END : 125; - V.t = t; - return V; - } + function view(f, cam, t) { + if (!Surf) Surf = CC.Surf; + var fov = cam.fov || 1.25, hp = Math.tan(fov * 0.5); + var cellA = cam.cellAspect || 0.5625; + V.cols = f.cols; V.rows = f.rows; V.hp = hp; + V.colK = f.cols * 0.5 / hp; V.colMid = f.cols * 0.5; + V.scale = cam.scaleY !== undefined ? cam.scaleY : (f.cols * cellA) / (2 * hp); + V.horizon = cam.horizon !== undefined ? cam.horizon : f.rows * 0.56; + V.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + var yaw = cam.yaw || 0; + V.fwx = Math.sin(yaw); V.fwz = Math.cos(yaw); + V.rgx = Math.cos(yaw); V.rgz = -Math.sin(yaw); + V.ox = cam.x; V.oz = cam.z; + V.far = Surf ? Surf.FOG_END : 125; + V.t = t; + return V; + } - function project(px, py, pz) { - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < 0.4) return false; - var sp = (rx * V.rgx + rz * V.rgz) / w; - PJ.d = w * Math.sqrt(1 + sp * sp); - PJ.x = sp * V.colK + V.colMid; - PJ.y = V.horizon - (py - V.eyeY) * V.scale / w; - return PJ.d < V.far; - } + function project(px, py, pz) { + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < 0.4) return false; + var sp = (rx * V.rgx + rz * V.rgz) / w; + PJ.d = w * Math.sqrt(1 + sp * sp); + PJ.x = sp * V.colK + V.colMid; + PJ.y = V.horizon - (py - V.eyeY) * V.scale / w; + return PJ.d < V.far; + } - function emit(f, x, y, ch, col, lum, d) { - if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; - if (lum > 0 && Surf) { lum = Surf.fog(lum, d); if (lum <= 0) ch = 0; } - put(f, x, y, ch, col, lum, d, 3); - } + function emit(f, x, y, ch, col, lum, d) { + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + if (lum > 0 && Surf) { lum = Surf.fog(lum, d); if (lum <= 0) ch = 0; } + put(f, x, y, ch, col, lum, d, 3); + } - function column(f, px, pz, y0, y1, ch, col, lum, wide) { - if (!project(px, y0, pz)) return; - var x = Math.floor(PJ.x), yb = PJ.y, d = PJ.d; - if (x < -2 || x >= V.cols + 2) return; - if (!project(px, y1, pz)) return; - var yt = PJ.y; - if (yt > yb) { var s = yt; yt = yb; yb = s; } - var r0 = Math.floor(yt), r1 = Math.floor(yb); - if (r1 - r0 > V.rows) r1 = r0 + V.rows; - for (var r = r0; r <= r1; r++) { - emit(f, x, r, ch, col, lum, d); - if (wide) emit(f, x + 1, r, ch, col, lum, d); - } - } - - function litFace(nx, nz) { - var W = CC.SURFACES && CC.World ? CC.SURFACES[CC.World.id] : null; - if (!W || W.SUN_X === undefined) return 0.5; - var d = nx * W.SUN_X + nz * W.SUN_Z; - var k = clamp(0.5 + 0.62 * d, 0, 1); - return 0.10 + 0.90 * k * k * (3 - 2 * k); - } - - return { V: V, PJ: PJ, view: view, project: project, emit: emit, - column: column, litFace: litFace }; + function column(f, px, pz, y0, y1, ch, col, lum, wide) { + if (!project(px, y0, pz)) return; + var x = Math.floor(PJ.x), yb = PJ.y, d = PJ.d; + if (x < -2 || x >= V.cols + 2) return; + if (!project(px, y1, pz)) return; + var yt = PJ.y; + if (yt > yb) { var s = yt; yt = yb; yb = s; } + var r0 = Math.floor(yt), r1 = Math.floor(yb); + if (r1 - r0 > V.rows) r1 = r0 + V.rows; + for (var r = r0; r <= r1; r++) { + emit(f, x, r, ch, col, lum, d); + if (wide) emit(f, x + 1, r, ch, col, lum, d); } - }; + } + + function litFace(nx, nz) { + var W = CC.SURFACES && CC.World ? CC.SURFACES[CC.World.id] : null; + if (!W || W.SUN_X === undefined) return 0.5; + var d = nx * W.SUN_X + nz * W.SUN_Z; + var k = clamp(0.5 + 0.62 * d, 0, 1); + return 0.10 + 0.90 * k * k * (3 - 2 * k); + } + + return { V: V, PJ: PJ, view: view, project: project, emit: emit, + column: column, litFace: litFace }; + } + }; })(CC); /* src/daylight.js */ (function (CC) { - 'use strict'; + 'use strict'; - var clamp = CC.clamp, smooth = CC.smooth; + var clamp = CC.clamp, smooth = CC.smooth; - var PERIOD = 420; + var PERIOD = 420; - var ALT_MAX = 0.95; + var ALT_MAX = 0.95; - var ALT_MIN = -0.42; + var ALT_MIN = -0.42; - var AZ_NOON = -0.5, AZ_SWING = 1.35; + var AZ_NOON = -0.5, AZ_SWING = 1.35; - var S = 0; + var S = 0; - var base = 0; + var base = 0; - var off = 0, holdAt = -1, frozen = 0; + var off = 0, holdAt = -1, frozen = 0; - var KEYS = ['alt', 'az', 'sun', 'sky', 'warm', 'lamp', 'star', 'night']; + var KEYS = ['alt', 'az', 'sun', 'sky', 'warm', 'lamp', 'star', 'night']; - var P = { phase: 0.78, name: 'dusk', alt: 0, az: AZ_NOON, sun: 0, sky: 0, warm: 0, - lamp: 1, star: 1, night: 1, frozen: false, period: PERIOD }; + var P = { phase: 0.78, name: 'dusk', alt: 0, az: AZ_NOON, sun: 0, sky: 0, warm: 0, + lamp: 1, star: 1, night: 1, frozen: false, period: PERIOD }; - var STOPS = [ - { name: 'night', phase: 0.00 }, - { name: 'dawn', phase: 0.27 }, - { name: 'morning', phase: 0.36 }, - { name: 'noon', phase: 0.50 }, - { name: 'afternoon', phase: 0.64 }, - { name: 'dusk', phase: 0.73 } - ]; + var STOPS = [ + { name: 'night', phase: 0.00 }, + { name: 'dawn', phase: 0.27 }, + { name: 'morning', phase: 0.36 }, + { name: 'noon', phase: 0.50 }, + { name: 'afternoon', phase: 0.64 }, + { name: 'dusk', phase: 0.73 } + ]; - function nameOf(ph) { - if (ph < 0.225 || ph >= 0.795) return 'night'; - if (ph < 0.315) return 'dawn'; - if (ph < 0.435) return 'morning'; - if (ph < 0.575) return 'noon'; - if (ph < 0.695) return 'afternoon'; - return 'dusk'; + function nameOf(ph) { + if (ph < 0.225 || ph >= 0.795) return 'night'; + if (ph < 0.315) return 'dawn'; + if (ph < 0.435) return 'morning'; + if (ph < 0.575) return 'noon'; + if (ph < 0.695) return 'afternoon'; + return 'dusk'; + } + + function frac(x) { return x - Math.floor(x); } + + function stateAt(tt) { + var ph = frac(tt / PERIOD); + var a = Math.sin((ph - 0.25) * 6.283185307); + + var alt = a >= 0 ? a * ALT_MAX : a * (-ALT_MIN); + + var sun = clamp((alt + 0.06) / 0.30, 0, 1); + sun = sun * sun * (3 - 2 * sun); + + var depr = -alt; + var sky; + if (alt >= 0) sky = clamp(0.55 + 0.45 * (alt / ALT_MAX), 0, 1); + else sky = clamp(1 - depr / 0.21, 0, 1) * 0.55; + sky = sky * sky * (3 - 2 * sky); + + var warm = clamp(1 - Math.abs(alt) / 0.36, 0, 1); + warm = warm * warm * (3 - 2 * warm) * clamp((alt + 0.30) / 0.24, 0, 1); + + var evening = ph > 0.5; + var lampAlt = alt + (evening ? -0.16 : -0.24); + var lamp = clamp(1 - (lampAlt + 0.02) / 0.26, 0, 1); + lamp = lamp * lamp * (3 - 2 * lamp); + + var star = clamp(1 - sky / 0.34, 0, 1); + star = star * star * (3 - 2 * star); + + var az = AZ_NOON + AZ_SWING * -Math.cos((ph - 0.25) * 6.283185307); + + return { ph: ph, alt: alt, az: az, sun: sun, sky: sky, warm: warm, lamp: lamp, star: star }; + } + + function apply(s) { + P.phase = s.ph; P.alt = s.alt; P.az = s.az; + P.sun = s.sun; P.sky = s.sky; P.warm = s.warm; + P.lamp = s.lamp; P.star = s.star; + P.night = s.alt < 0 ? 1 : 0; + P.name = nameOf(s.ph); + P.frozen = !!frozen; + return P; + } + + function update(dt, t) { + if (!(t >= 0)) t = 0; + return apply(stateAt((frozen ? holdAt : t) + off)); + } + + var Daylight = { + P: P, KEYS: KEYS, STOPS: STOPS, PERIOD: PERIOD, + ALT_MAX: ALT_MAX, AZ_NOON: AZ_NOON, AZ_SWING: AZ_SWING, + + init: function (city) { + S = city && city.seed !== undefined ? (city.seed | 0) : 0; + + var h = CC.hash1 ? CC.hash1(0, (S + 4177) | 0) : 0.5; + + off += (0.62 + h * 0.35) * PERIOD - base; + base = (0.62 + h * 0.35) * PERIOD; + return update(0, 0); + }, + update: update, + + step: function (t, dir) { + if (!(t >= 0)) t = 0; + var cur = frac(((frozen ? holdAt : t) + off) / PERIOD); + var d = dir < 0 ? -1 : 1, i, want = -1, bestGap = 2; + + for (i = 0; i < STOPS.length; i++) { + var gap = d > 0 ? frac(STOPS[i].phase - cur) : frac(cur - STOPS[i].phase); + if (gap > 0.02 && gap < bestGap) { bestGap = gap; want = STOPS[i].phase; } + } + if (want < 0) want = STOPS[0].phase; + off += (want - cur) * PERIOD; + + return P.name; + }, + + freeze: function (t) { + if (!(t >= 0)) t = 0; + if (frozen) { off -= (t - holdAt); frozen = 0; holdAt = -1; } + else { holdAt = t; frozen = 1; } + P.frozen = !!frozen; + return !!frozen; + }, + get frozen() { return !!frozen; }, + get current() { return P.name; }, + + set: function (nameOrPhase, t) { + if (!(t >= 0)) t = 0; + var want = -1; + if (typeof nameOrPhase === 'number') want = frac(nameOrPhase); + else for (var i = 0; i < STOPS.length; i++) + if (STOPS[i].name === nameOrPhase) { want = STOPS[i].phase; break; } + if (want < 0) return false; + var cur = frac(((frozen ? holdAt : t) + off) / PERIOD); + off += (want - cur) * PERIOD; + update(0, t); + return true; } + }; - function frac(x) { return x - Math.floor(x); } + Object.defineProperty(Daylight, 'offset', { get: function () { return off; } }); - function stateAt(tt) { - var ph = frac(tt / PERIOD); - var a = Math.sin((ph - 0.25) * 6.283185307); - - var alt = a >= 0 ? a * ALT_MAX : a * (-ALT_MIN); - - var sun = clamp((alt + 0.06) / 0.30, 0, 1); - sun = sun * sun * (3 - 2 * sun); - - var depr = -alt; - var sky; - if (alt >= 0) sky = clamp(0.55 + 0.45 * (alt / ALT_MAX), 0, 1); - else sky = clamp(1 - depr / 0.21, 0, 1) * 0.55; - sky = sky * sky * (3 - 2 * sky); - - var warm = clamp(1 - Math.abs(alt) / 0.36, 0, 1); - warm = warm * warm * (3 - 2 * warm) * clamp((alt + 0.30) / 0.24, 0, 1); - - var evening = ph > 0.5; - var lampAlt = alt + (evening ? -0.16 : -0.24); - var lamp = clamp(1 - (lampAlt + 0.02) / 0.26, 0, 1); - lamp = lamp * lamp * (3 - 2 * lamp); - - var star = clamp(1 - sky / 0.34, 0, 1); - star = star * star * (3 - 2 * star); - - var az = AZ_NOON + AZ_SWING * -Math.cos((ph - 0.25) * 6.283185307); - - return { ph: ph, alt: alt, az: az, sun: sun, sky: sky, warm: warm, lamp: lamp, star: star }; - } - - function apply(s) { - P.phase = s.ph; P.alt = s.alt; P.az = s.az; - P.sun = s.sun; P.sky = s.sky; P.warm = s.warm; - P.lamp = s.lamp; P.star = s.star; - P.night = s.alt < 0 ? 1 : 0; - P.name = nameOf(s.ph); - P.frozen = !!frozen; - return P; - } - - function update(dt, t) { - if (!(t >= 0)) t = 0; - return apply(stateAt((frozen ? holdAt : t) + off)); - } - - var Daylight = { - P: P, KEYS: KEYS, STOPS: STOPS, PERIOD: PERIOD, - ALT_MAX: ALT_MAX, AZ_NOON: AZ_NOON, AZ_SWING: AZ_SWING, - - init: function (city) { - S = city && city.seed !== undefined ? (city.seed | 0) : 0; - - var h = CC.hash1 ? CC.hash1(0, (S + 4177) | 0) : 0.5; - - off += (0.62 + h * 0.35) * PERIOD - base; - base = (0.62 + h * 0.35) * PERIOD; - return update(0, 0); - }, - update: update, - - step: function (t, dir) { - if (!(t >= 0)) t = 0; - var cur = frac(((frozen ? holdAt : t) + off) / PERIOD); - var d = dir < 0 ? -1 : 1, i, want = -1, bestGap = 2; - - for (i = 0; i < STOPS.length; i++) { - var gap = d > 0 ? frac(STOPS[i].phase - cur) : frac(cur - STOPS[i].phase); - if (gap > 0.02 && gap < bestGap) { bestGap = gap; want = STOPS[i].phase; } - } - if (want < 0) want = STOPS[0].phase; - off += (want - cur) * PERIOD; - - return P.name; - }, - - freeze: function (t) { - if (!(t >= 0)) t = 0; - if (frozen) { off -= (t - holdAt); frozen = 0; holdAt = -1; } - else { holdAt = t; frozen = 1; } - P.frozen = !!frozen; - return !!frozen; - }, - get frozen() { return !!frozen; }, - get current() { return P.name; }, - - set: function (nameOrPhase, t) { - if (!(t >= 0)) t = 0; - var want = -1; - if (typeof nameOrPhase === 'number') want = frac(nameOrPhase); - else for (var i = 0; i < STOPS.length; i++) - if (STOPS[i].name === nameOrPhase) { want = STOPS[i].phase; break; } - if (want < 0) return false; - var cur = frac(((frozen ? holdAt : t) + off) / PERIOD); - off += (want - cur) * PERIOD; - update(0, t); - return true; - } - }; - - Object.defineProperty(Daylight, 'offset', { get: function () { return off; } }); - - CC.Daylight = Daylight; + CC.Daylight = Daylight; })(CC); /* src/weather_state.js */ (function (CC) { - 'use strict'; + 'use strict'; - var clamp = CC.clamp, smooth = CC.smooth, hash1 = CC.hash1; + var clamp = CC.clamp, smooth = CC.smooth, hash1 = CC.hash1; - var KEYS = ['rain', 'wind', 'fog', 'wet', 'storm', 'haze', 'cloud', 'steam']; + var KEYS = ['rain', 'wind', 'fog', 'wet', 'storm', 'haze', 'cloud', 'steam']; - var PRESETS_CYBER = [ - { name: 'clear', p: [0.00, 0.25, 0.08, 0.12, 0.00, 0.10, 0.08, 0.55] }, - { name: 'drizzle', p: [0.30, 0.35, 0.22, 0.62, 0.02, 0.26, 0.45, 0.72] }, - { name: 'rain', p: [0.65, 0.55, 0.30, 0.90, 0.12, 0.40, 0.75, 0.85] }, - { name: 'downpour', p: [1.00, 0.85, 0.36, 1.00, 0.34, 0.56, 0.95, 1.00] }, - { name: 'mist', p: [0.06, 0.15, 1.00, 0.46, 0.00, 0.95, 0.70, 0.92] }, - { name: 'storm', p: [0.85, 1.00, 0.44, 1.00, 1.00, 0.60, 1.00, 0.78] } - ]; - var REF_I = 2; + var PRESETS_CYBER = [ + { name: 'clear', p: [0.00, 0.25, 0.08, 0.12, 0.00, 0.10, 0.08, 0.55] }, + { name: 'drizzle', p: [0.30, 0.35, 0.22, 0.62, 0.02, 0.26, 0.45, 0.72] }, + { name: 'rain', p: [0.65, 0.55, 0.30, 0.90, 0.12, 0.40, 0.75, 0.85] }, + { name: 'downpour', p: [1.00, 0.85, 0.36, 1.00, 0.34, 0.56, 0.95, 1.00] }, + { name: 'mist', p: [0.06, 0.15, 1.00, 0.46, 0.00, 0.95, 0.70, 0.92] }, + { name: 'storm', p: [0.85, 1.00, 0.44, 1.00, 1.00, 0.60, 1.00, 0.78] } + ]; + var REF_I = 2; - var PRESETS_WEST = [ - { name: 'blazing', p: [0.00, 0.18, 0.04, 0.04, 0.00, 0.30, 0.04, 0.24] }, - { name: 'breeze', p: [0.00, 0.52, 0.08, 0.04, 0.00, 0.52, 0.16, 0.20] }, - { name: 'dust', p: [0.00, 0.82, 0.34, 0.03, 0.10, 0.88, 0.36, 0.18] }, - { name: 'squall', p: [0.72, 0.72, 0.24, 0.88, 0.22, 0.38, 0.86, 0.50] }, - { name: 'overcast', p: [0.06, 0.34, 0.26, 0.18, 0.00, 0.54, 0.94, 0.32] }, - { name: 'thunder', p: [0.58, 0.98, 0.38, 0.82, 1.00, 0.46, 1.00, 0.42] } - ]; + var PRESETS_WEST = [ + { name: 'blazing', p: [0.00, 0.18, 0.04, 0.04, 0.00, 0.30, 0.04, 0.24] }, + { name: 'breeze', p: [0.00, 0.52, 0.08, 0.04, 0.00, 0.52, 0.16, 0.20] }, + { name: 'dust', p: [0.00, 0.82, 0.34, 0.03, 0.10, 0.88, 0.36, 0.18] }, + { name: 'squall', p: [0.72, 0.72, 0.24, 0.88, 0.22, 0.38, 0.86, 0.50] }, + { name: 'overcast', p: [0.06, 0.34, 0.26, 0.18, 0.00, 0.54, 0.94, 0.32] }, + { name: 'thunder', p: [0.58, 0.98, 0.38, 0.82, 1.00, 0.46, 1.00, 0.42] } + ]; - var NEXT_WEST = [ - [0, 6, 3, 0, 2, 0], - [5, 0, 6, 1, 2, 1], - [4, 6, 0, 3, 2, 2], - [1, 3, 4, 0, 3, 2], - [3, 4, 3, 3, 0, 3], - [0, 2, 4, 4, 3, 0] - ]; + var NEXT_WEST = [ + [0, 6, 3, 0, 2, 0], + [5, 0, 6, 1, 2, 1], + [4, 6, 0, 3, 2, 2], + [1, 3, 4, 0, 3, 2], + [3, 4, 3, 3, 0, 3], + [0, 2, 4, 4, 3, 0] + ]; - var PRESETS_MOON = [ - { name: 'vacuum', p: [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00] } - ]; - var NEXT_MOON = [[1]]; + var PRESETS_MOON = [ + { name: 'vacuum', p: [0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00] } + ]; + var NEXT_MOON = [[1]]; - var TABLES = null; - function tables() { - if (!TABLES) TABLES = { cyber: [PRESETS_CYBER, NEXT_CYBER], - west: [PRESETS_WEST, NEXT_WEST], - moon: [PRESETS_MOON, NEXT_MOON] }; - return TABLES; + var TABLES = null; + function tables() { + if (!TABLES) TABLES = { cyber: [PRESETS_CYBER, NEXT_CYBER], + west: [PRESETS_WEST, NEXT_WEST], + moon: [PRESETS_MOON, NEXT_MOON] }; + return TABLES; + } + + var PRESETS = PRESETS_CYBER, NEXT = NEXT_CYBER; + + var TRANS = 14, TRANS_FORCED = 5; + + var DUR_MIN = 78, DUR_VAR = 92; + + var S = 0; + var segT = [], segI = []; + var forcedI = -1, forcedAt = -1e9; + + var NEXT_CYBER = [ + [0, 5, 2, 0, 3, 0], + [4, 0, 5, 1, 3, 1], + [1, 5, 0, 4, 2, 3], + [0, 2, 6, 0, 1, 4], + [4, 3, 2, 0, 0, 1], + [0, 2, 5, 3, 1, 0] + ]; + + function pickNext(prev, n) { + var row = NEXT[prev], tot = 0, i, m = row.length; + for (i = 0; i < m; i++) tot += row[i]; + if (tot <= 0) return prev; + var r = hash1(n, S + 7717) * tot; + for (i = 0; i < m; i++) { r -= row[i]; if (r <= 0) return i; } + return prev; + } + + function extend(tMax) { + while (segT[segT.length - 1] <= tMax) { + var n = segT.length; + var prev = segI[n - 1]; + segI.push(pickNext(prev, n)); + segT.push(segT[n - 1] + DUR_MIN + hash1(n, S + 991) * DUR_VAR); } + } - var PRESETS = PRESETS_CYBER, NEXT = NEXT_CYBER; + var W = { name: 'rain', from: 'rain', to: 'rain', blend: 1, forced: false }; + for (var ki = 0; ki < KEYS.length; ki++) W[KEYS[ki]] = PRESETS_CYBER[REF_I].p[ki]; - var TRANS = 14, TRANS_FORCED = 5; + function apply(a, b, f) { + var A = PRESETS[a].p, B = PRESETS[b].p; + for (var i = 0; i < KEYS.length; i++) W[KEYS[i]] = A[i] + (B[i] - A[i]) * f; + W.from = PRESETS[a].name; W.to = PRESETS[b].name; W.blend = f; - var DUR_MIN = 78, DUR_VAR = 92; + W.name = PRESETS[f < 0.5 ? a : b].name; + } - var S = 0; - var segT = [], segI = []; - var forcedI = -1, forcedAt = -1e9; + function update(dt, t) { + if (!(t >= 0)) t = 0; + extend(t + 4); - var NEXT_CYBER = [ - [0, 5, 2, 0, 3, 0], - [4, 0, 5, 1, 3, 1], - [1, 5, 0, 4, 2, 3], - [0, 2, 6, 0, 1, 4], - [4, 3, 2, 0, 0, 1], - [0, 2, 5, 3, 1, 0] - ]; + var k = segT.length - 1; + while (k > 0 && segT[k] > t) k--; + var cur = segI[k], prev = k > 0 ? segI[k - 1] : cur; + var into = t - segT[k]; + var f = k > 0 && into < TRANS ? smooth(into / TRANS) : 1; - function pickNext(prev, n) { - var row = NEXT[prev], tot = 0, i, m = row.length; - for (i = 0; i < m; i++) tot += row[i]; - if (tot <= 0) return prev; - var r = hash1(n, S + 7717) * tot; - for (i = 0; i < m; i++) { r -= row[i]; if (r <= 0) return i; } - return prev; - } + if (forcedI >= 0) { - function extend(tMax) { - while (segT[segT.length - 1] <= tMax) { - var n = segT.length; - var prev = segI[n - 1]; - segI.push(pickNext(prev, n)); - segT.push(segT[n - 1] + DUR_MIN + hash1(n, S + 991) * DUR_VAR); - } - } - - var W = { name: 'rain', from: 'rain', to: 'rain', blend: 1, forced: false }; - for (var ki = 0; ki < KEYS.length; ki++) W[KEYS[ki]] = PRESETS_CYBER[REF_I].p[ki]; - - function apply(a, b, f) { - var A = PRESETS[a].p, B = PRESETS[b].p; - for (var i = 0; i < KEYS.length; i++) W[KEYS[i]] = A[i] + (B[i] - A[i]) * f; - W.from = PRESETS[a].name; W.to = PRESETS[b].name; W.blend = f; - - W.name = PRESETS[f < 0.5 ? a : b].name; - } - - function update(dt, t) { - if (!(t >= 0)) t = 0; - extend(t + 4); - - var k = segT.length - 1; - while (k > 0 && segT[k] > t) k--; - var cur = segI[k], prev = k > 0 ? segI[k - 1] : cur; - var into = t - segT[k]; - var f = k > 0 && into < TRANS ? smooth(into / TRANS) : 1; - - if (forcedI >= 0) { - - var fi = t - forcedAt; - if (fi < 0) { forcedI = -1; } - else if (k > 0 && segT[k] > forcedAt) { forcedI = -1; } - else { - apply(prev, forcedI, fi < TRANS_FORCED ? smooth(fi / TRANS_FORCED) : 1); - W.forced = true; - return W; - } - } - W.forced = false; - apply(prev, cur, f); + var fi = t - forcedAt; + if (fi < 0) { forcedI = -1; } + else if (k > 0 && segT[k] > forcedAt) { forcedI = -1; } + else { + apply(prev, forcedI, fi < TRANS_FORCED ? smooth(fi / TRANS_FORCED) : 1); + W.forced = true; return W; + } } + W.forced = false; + apply(prev, cur, f); + return W; + } - var KI = {}, INV_REF = []; - for (var kj = 0; kj < KEYS.length; kj++) { - KI[KEYS[kj]] = kj; - var rv = PRESETS_CYBER[REF_I].p[kj]; - INV_REF.push(rv > 1e-6 ? 1 / rv : 1); - } - function rel(key) { - var i = KI[key]; - return i === undefined ? 1 : W[key] * INV_REF[i]; - } + var KI = {}, INV_REF = []; + for (var kj = 0; kj < KEYS.length; kj++) { + KI[KEYS[kj]] = kj; + var rv = PRESETS_CYBER[REF_I].p[kj]; + INV_REF.push(rv > 1e-6 ? 1 / rv : 1); + } + function rel(key) { + var i = KI[key]; + return i === undefined ? 1 : W[key] * INV_REF[i]; + } - var Weather = { - P: W, - KEYS: KEYS, + var Weather = { + P: W, + KEYS: KEYS, - get PRESETS() { return PRESETS; }, - REF: PRESETS_CYBER[REF_I].p, + get PRESETS() { return PRESETS; }, + REF: PRESETS_CYBER[REF_I].p, - init: function (city) { - S = city && city.seed !== undefined ? (city.seed | 0) : 0; + init: function (city) { + S = city && city.seed !== undefined ? (city.seed | 0) : 0; - var TB = tables(); - var T = TB[(CC.World && CC.World.id) || 'cyber'] || TB.cyber; - PRESETS = T[0]; NEXT = T[1]; - segT = [0]; + var TB = tables(); + var T = TB[(CC.World && CC.World.id) || 'cyber'] || TB.cyber; + PRESETS = T[0]; NEXT = T[1]; + segT = [0]; - segI = [PRESETS.length > 1 ? 1 + ((hash1(0, S + 313) * (PRESETS.length - 1)) | 0) : 0]; - forcedI = -1; forcedAt = -1e9; - update(0, 0); - }, - update: update, - rel: rel, + segI = [PRESETS.length > 1 ? 1 + ((hash1(0, S + 313) * (PRESETS.length - 1)) | 0) : 0]; + forcedI = -1; forcedAt = -1e9; + update(0, 0); + }, + update: update, + rel: rel, - set: function (nameOrIdx, t) { - var i = typeof nameOrIdx === 'number' ? nameOrIdx | 0 : -1; - if (i < 0) for (var j = 0; j < PRESETS.length; j++) - if (PRESETS[j].name === nameOrIdx) { i = j; break; } - if (i < 0 || i >= PRESETS.length) return false; - forcedI = i; forcedAt = t === undefined ? 0 : t; - return true; - }, - cycle: function (t, dir) { - var cur = forcedI >= 0 ? forcedI : PRESETS.map(function (p) { return p.name; }).indexOf(W.name); - if (cur < 0) cur = REF_I; - var n = (cur + (dir < 0 ? -1 : 1) + PRESETS.length) % PRESETS.length; - return Weather.set(n, t); - }, - get current() { return W.name; } - }; + set: function (nameOrIdx, t) { + var i = typeof nameOrIdx === 'number' ? nameOrIdx | 0 : -1; + if (i < 0) for (var j = 0; j < PRESETS.length; j++) + if (PRESETS[j].name === nameOrIdx) { i = j; break; } + if (i < 0 || i >= PRESETS.length) return false; + forcedI = i; forcedAt = t === undefined ? 0 : t; + return true; + }, + cycle: function (t, dir) { + var cur = forcedI >= 0 ? forcedI : PRESETS.map(function (p) { return p.name; }).indexOf(W.name); + if (cur < 0) cur = REF_I; + var n = (cur + (dir < 0 ? -1 : 1) + PRESETS.length) % PRESETS.length; + return Weather.set(n, t); + }, + get current() { return W.name; } + }; - if (CC) CC.Weather = Weather; + if (CC) CC.Weather = Weather; })(CC); /* src/city.js */ (function () { - 'use strict'; + 'use strict'; - var C = (typeof CC !== 'undefined' && CC) ? CC - : (typeof globalThis !== 'undefined' && globalThis.CC) ? globalThis.CC : null; + var C = (typeof CC !== 'undefined' && CC) ? CC + : (typeof globalThis !== 'undefined' && globalThis.CC) ? globalThis.CC : null; - var hash2, clamp, vnoise, P; - var STYLE = null, SIGN_G = null, STYLE_W = null, SIGN_G_W = null; + var hash2, clamp, vnoise, P; + var STYLE = null, SIGN_G = null, STYLE_W = null, SIGN_G_W = null; - function hash(x, y, s) { - return hash2(x + Math.imul(s, 0x2545F491), y + Math.imul(s, 0x9E3779B1), s); - } + function hash(x, y, s) { + return hash2(x + Math.imul(s, 0x2545F491), y + Math.imul(s, 0x9E3779B1), s); + } - var AVE = 30, CROSS = 26, CH = 16; + var AVE = 30, CROSS = 26, CH = 16; - var STYLE_CH = [ - ['#', ':', 'o'], - ['8', '=', 'o'], - ['=', '-', ':'], - ['X', '.', 'Z'], - ['0', '|', 'o'], - ['O', "'", 'o'] - ]; - var SIGN_CH = ['#', '8', '0', 'X', 'O', '=', 'Z']; + var STYLE_CH = [ + ['#', ':', 'o'], + ['8', '=', 'o'], + ['=', '-', ':'], + ['X', '.', 'Z'], + ['0', '|', 'o'], + ['O', "'", 'o'] + ]; + var SIGN_CH = ['#', '8', '0', 'X', 'O', '=', 'Z']; - var STYLE_CH_WEST = [ - ['8', '-', 'o'], - ['0', '|', 'o'], - ['O', '=', ':'], - ['#', "'", 'o'], - ['X', '.', ':'], - ['8', '=', 'o'], + var STYLE_CH_WEST = [ + ['8', '-', 'o'], + ['0', '|', 'o'], + ['O', '=', ':'], + ['#', "'", 'o'], + ['X', '.', ':'], + ['8', '=', 'o'], - ['%', '&', ':'] + ['%', '&', ':'] + ]; + + var SIGN_CH_WEST = ['M', 'W', 'N', 'H', 'X', 'A', 'K']; + + var STYLE_CH_MOON = [ + ['%', '.', ':'], + ['8', ':', '%'], + ['.', ',', "'"] + ]; + + var DIST = null, DIST_CYBER = null, DIST_WEST = null, DIST_MOON = null; + function buildDistricts() { + DIST_CYBER = [ + + { name: 'sodium', hue: P.amber, mix: P.azure, mixP: 0.86, accent: P.warm, styles: [0, 3, 0], + hMin: 15, hMax: 34, lit: 0.32, signP: 0.34, landmark: 0.010, w: 0.22 }, + { name: 'screen', hue: P.azure, mix: P.amber, mixP: 0.86, accent: P.white, styles: [1, 4, 1], + hMin: 24, hMax: 56, lit: 0.27, signP: 0.16, landmark: 0.030, w: 0.21 }, + { name: 'concrete', hue: P.stone, mix: P.azure, mixP: 0.80, accent: P.white, styles: [2, 5], + hMin: 16, hMax: 32, lit: 0.22, signP: 0.05, landmark: 0.006, w: 0.17 }, + + { name: 'ember', hue: P.ember, mix: P.amber, mixP: 0.55, accent: P.red, styles: [5, 2], + hMin: 8, hMax: 19, lit: 0.22, signP: 0.13, landmark: 0.002, w: 0.09 }, + { name: 'spring', hue: P.spring, mix: P.azure, mixP: 0.50, accent: P.white, styles: [2, 0], + hMin: 15, hMax: 29, lit: 0.24, signP: 0.16, landmark: 0.006, w: 0.07 }, + + { name: 'arcade', hue: P.azure, mix: P.amber, mixP: 0.55, accent: P.rose, styles: [1, 3], + hMin: 13, hMax: 27, lit: 0.30, signP: 0.60, landmark: 0.004, w: 0.06 }, + + { name: 'gilt', hue: P.jade, mix: P.amber, mixP: 0.55, accent: P.gold, styles: [0, 2], + hMin: 14, hMax: 30, lit: 0.28, signP: 0.30, landmark: 0.008, w: 0.07 }, + + { name: 'market', hue: P.moss, mix: P.amber, mixP: 0.52, accent: P.timber, styles: [5, 2], + hMin: 7, hMax: 16, lit: 0.20, signP: 0.28, landmark: 0.001, w: 0.06 }, + + { name: 'finance', hue: P.indigo, mix: P.azure, mixP: 0.62, accent: P.white, styles: [1, 4], + hMin: 26, hMax: 60, lit: 0.24, signP: 0.06, landmark: 0.045, w: 0.05 } ]; - var SIGN_CH_WEST = ['M', 'W', 'N', 'H', 'X', 'A', 'K']; + DIST_WEST = [ - var STYLE_CH_MOON = [ - ['%', '.', ':'], - ['8', ':', '%'] + { name: 'main', hue: P.sand, mix: P.white, mixP: 0.64, accent: P.timber, styles: [2, 0, 2, 0], + hMin: 6.2, hMax: 10, lit: 0.20, signP: 0.66, landmark: 0.012, w: 0.21, + vacant: 0.07, butte: 0 }, + + { name: 'boards', hue: P.timber, mix: P.stone, mixP: 0.70, accent: P.sand, styles: [0, 1, 1, 5], + hMin: 5.0, hMax: 8.5, lit: 0.11, signP: 0.18, landmark: 0.004, w: 0.19, + vacant: 0.20, butte: 0 }, + + { name: 'adobe', hue: P.timber, mix: P.sand, mixP: 0.58, accent: P.ember, styles: [3, 3, 4], + hMin: 4.4, hMax: 7.5, lit: 0.13, signP: 0.12, landmark: 0.010, w: 0.14, + vacant: 0.16, butte: 0 }, + + { name: 'stone', hue: P.stone, mix: P.timber, mixP: 0.74, accent: P.sand, styles: [4, 4, 0], + hMin: 5.4, hMax: 9.5, lit: 0.09, signP: 0.09, landmark: 0.006, w: 0.13, + vacant: 0.30, butte: 0.006 }, + + { name: 'mission', hue: P.white, mix: P.sand, mixP: 0.62, accent: P.moss, styles: [3, 4, 2], + hMin: 5.4, hMax: 9.5, lit: 0.14, signP: 0.07, landmark: 0.022, w: 0.07, + vacant: 0.22, butte: 0 }, + + { name: 'range', hue: P.sand, mix: P.ember, mixP: 0.60, accent: P.moss, styles: [4, 1, 4], + hMin: 4.4, hMax: 7.5, lit: 0.06, signP: 0.02, landmark: 0.000, w: 0.26, + vacant: 0.62, butte: 0.072 } ]; - var DIST = null, DIST_CYBER = null, DIST_WEST = null, DIST_MOON = null; - function buildDistricts() { - DIST_CYBER = [ + DIST_MOON = [ - { name: 'sodium', hue: P.amber, mix: P.azure, mixP: 0.86, accent: P.warm, styles: [0, 3, 0], - hMin: 15, hMax: 34, lit: 0.32, signP: 0.34, landmark: 0.010, w: 0.25 }, - { name: 'screen', hue: P.azure, mix: P.amber, mixP: 0.86, accent: P.white, styles: [1, 4, 1], - hMin: 24, hMax: 56, lit: 0.27, signP: 0.16, landmark: 0.030, w: 0.24 }, - { name: 'concrete', hue: P.slate, mix: P.white, mixP: 0.80, accent: P.white, styles: [2, 5], - hMin: 16, hMax: 32, lit: 0.22, signP: 0.05, landmark: 0.006, w: 0.20 }, + { name: 'mare', hue: P.stone, mix: P.white, mixP: 0.72, accent: P.white, styles: [7], + hMin: 0.5, hMax: 2.2, lit: 0, signP: 0, landmark: 0.000, w: 0.24, + vacant: 0.95, boulder: 0.10, crater: 0.03 }, - { name: 'ember', hue: P.ember, mix: P.amber, mixP: 0.55, accent: P.red, styles: [5, 2], - hMin: 8, hMax: 19, lit: 0.22, signP: 0.13, landmark: 0.002, w: 0.11 }, - { name: 'spring', hue: P.spring, mix: P.azure, mixP: 0.50, accent: P.white, styles: [2, 0], - hMin: 15, hMax: 29, lit: 0.24, signP: 0.16, landmark: 0.006, w: 0.12 }, + { name: 'ejecta', hue: P.white, mix: P.stone, mixP: 0.60, accent: P.pure, styles: [8, 7], + hMin: 1.2, hMax: 5.4, lit: 0, signP: 0, landmark: 0.000, w: 0.14, + vacant: 0.72, boulder: 0.55, crater: 0.10 }, - { name: 'arcade', hue: P.azure, mix: P.amber, mixP: 0.55, accent: P.warm, styles: [1, 3], - hMin: 13, hMax: 27, lit: 0.30, signP: 0.60, landmark: 0.004, w: 0.06 } - ]; + { name: 'rays', hue: P.white, mix: P.stone, mixP: 0.86, accent: P.pure, styles: [7], + hMin: 0.3, hMax: 1.0, lit: 0, signP: 0, landmark: 0.000, w: 0.10, + vacant: 0.97, boulder: 0.06, crater: 0.14 }, - DIST_WEST = [ - { name: 'main', hue: P.warm, mix: P.amber, mixP: 0.72, accent: P.amber, styles: [0, 2, 0, 2], - hMin: 6.2, hMax: 10, lit: 0.20, signP: 0.66, landmark: 0.012, w: 0.21, - vacant: 0.07, butte: 0 }, - { name: 'dust', hue: P.slate, mix: P.white, mixP: 0.74, accent: P.white, styles: [0, 1, 5], - hMin: 5.0, hMax: 8.5, lit: 0.11, signP: 0.18, landmark: 0.004, w: 0.19, - vacant: 0.20, butte: 0 }, - { name: 'adobe', hue: P.ember, hue2: P.warm, mix: P.warm, mixP: 0.66, accent: P.warm, styles: [3, 3, 4], - hMin: 4.4, hMax: 7.5, lit: 0.13, signP: 0.12, landmark: 0.010, w: 0.14, - vacant: 0.16, butte: 0 }, - { name: 'ranch', hue: P.ember, mix: P.slate, mixP: 0.58, accent: P.red, styles: [1, 1, 5], - hMin: 5.4, hMax: 9.5, lit: 0.09, signP: 0.09, landmark: 0.006, w: 0.13, - vacant: 0.30, butte: 0.004 }, + { name: 'field', hue: P.stone, mix: P.white, mixP: 0.64, accent: P.pure, styles: [8, 8, 7], + hMin: 0.8, hMax: 3.2, lit: 0, signP: 0, landmark: 0.000, w: 0.10, + vacant: 0.55, boulder: 0.90, crater: 0.02 }, - { name: 'mission', hue: P.white, mix: P.amber, mixP: 0.60, accent: P.spring, styles: [3, 4, 2], - hMin: 5.4, hMax: 9.5, lit: 0.14, signP: 0.07, landmark: 0.022, w: 0.07, - vacant: 0.22, butte: 0 }, - { name: 'range', hue: P.slate, mix: P.ember, mixP: 0.62, accent: P.ember, styles: [4, 1, 4], - hMin: 4.4, hMax: 7.5, lit: 0.06, signP: 0.02, landmark: 0.000, w: 0.26, - vacant: 0.62, butte: 0.072 } - ]; + { name: 'rim', hue: P.white, mix: P.stone, mixP: 0.66, accent: P.pure, styles: [8], + hMin: 2.0, hMax: 7.5, lit: 0, signP: 0, landmark: 0.004, w: 0.14, + vacant: 0.55, boulder: 0.18, crater: 0.58 }, - DIST_MOON = [ + { name: 'highland', hue: P.white, mix: P.stone, mixP: 0.74, accent: P.pure, styles: [8, 7], + hMin: 3.5, hMax: 16.0, lit: 0, signP: 0, landmark: 0.030, w: 0.12, + vacant: 0.60, boulder: 0.24, crater: 0.08 }, - { name: 'mare', hue: P.slate, mix: P.white, mixP: 0.70, accent: P.white, styles: [7], - hMin: 0.5, hMax: 1.8, lit: 0, signP: 0, landmark: 0.000, w: 0.30, - vacant: 0.94, boulder: 0.10, crater: 0.06 }, + { name: 'site', hue: P.stone, mix: P.white, mixP: 0.60, accent: P.amber, styles: [7], + hMin: 0.3, hMax: 1.2, lit: 0, signP: 0, landmark: 0.000, w: 0.06, + vacant: 0.96, boulder: 0.04, crater: 0.02, hardware: 1 }, - { name: 'ejecta', hue: P.white, mix: P.slate, mixP: 0.62, accent: P.pure, styles: [7, 8], - hMin: 1.2, hMax: 5.0, lit: 0, signP: 0, landmark: 0.000, w: 0.20, - vacant: 0.70, boulder: 0.55, crater: 0.10 }, + { name: 'plain', hue: P.stone, mix: P.white, mixP: 0.80, accent: P.white, styles: [7], + hMin: 0.4, hMax: 1.6, lit: 0, signP: 0, landmark: 0.000, w: 0.10, + vacant: 0.93, boulder: 0.14, crater: 0.05 } + ]; - { name: 'rim', hue: P.white, mix: P.slate, mixP: 0.66, accent: P.pure, styles: [8], - hMin: 2.0, hMax: 7.0, lit: 0, signP: 0, landmark: 0.004, w: 0.16, - vacant: 0.52, boulder: 0.18, crater: 0.46 }, + norm(DIST_CYBER); norm(DIST_WEST); norm(DIST_MOON); - { name: 'highland', hue: P.white, mix: P.slate, mixP: 0.74, accent: P.pure, styles: [8, 7], - hMin: 3.5, hMax: 15.0, lit: 0, signP: 0, landmark: 0.030, w: 0.14, - vacant: 0.58, boulder: 0.24, crater: 0.08 }, + TH_CYBER.dist = DIST_CYBER; TH_WEST.dist = DIST_WEST; TH_MOON.dist = DIST_MOON; + DIST = DIST_CYBER; + } + function norm(T) { + var acc = 0; + for (var i = 0; i < T.length; i++) { acc += T[i].w; T[i].acc = acc; } + T.total = acc; + } - { name: 'site', hue: P.slate, mix: P.white, mixP: 0.60, accent: P.amber, styles: [7], - hMin: 0.3, hMax: 1.2, lit: 0, signP: 0, landmark: 0.000, w: 0.08, - vacant: 0.96, boulder: 0.04, crater: 0.02, hardware: 1 }, + var TH_CYBER = { + id: 'cyber', AVE: 30, CROSS: 26, + aveJit: 15, aveOff: -7, crossJit: 13, crossOff: -6, + aveWide: 6, aveMid: 4, aveNarrow: 3, aveMidP: 0.35, aveEvery: 4, + crossWide: 3, crossMid: 2, crossNarrow: 1, crossMidP: 0.28, crossEvery: 5, + lotW: 6, lotWVar: 7, lotD: 6, lotDVar: 8, + alleyMin: 10, alleyP: 0.45, alleyDeepMin: 11, alleyDeepP: 0.35, + plazaP: 0.13, plazaBigP: 0.26, plazaR: 5, plazaRVar: 7, + vacant: 0.06, setbackP: 0.42, podMin: 7, podVar: 10, falseFront: 0, + lmMin: 58, lmVar: 46, crownTall: 55, DG: 26, sky: 0, + styleCh: STYLE_CH, signCh: SIGN_CH, styleBase: 0, + setbackMode: 'podium', signShape: 'blade', signPalette: 'neon' + }; + var TH_WEST = { + id: 'west', AVE: 52, CROSS: 44, + aveJit: 19, aveOff: -9, crossJit: 15, crossOff: -7, + aveWide: 9, aveMid: 7, aveNarrow: 6, aveMidP: 0.42, aveEvery: 3, + crossWide: 6, crossMid: 4, crossNarrow: 3, crossMidP: 0.34, crossEvery: 4, + lotW: 5, lotWVar: 5, lotD: 6, lotDVar: 6, + alleyMin: 9, alleyP: 0.52, alleyDeepMin: 10, alleyDeepP: 0.40, + plazaP: 0.20, plazaBigP: 0.34, plazaR: 6, plazaRVar: 9, + vacant: 0.14, setbackP: 0.68, podMin: 0, podVar: 0, falseFront: 1, - { name: 'plain', hue: P.slate, mix: P.white, mixP: 0.80, accent: P.white, styles: [7], - hMin: 0.4, hMax: 1.4, lit: 0, signP: 0, landmark: 0.000, w: 0.12, - vacant: 0.92, boulder: 0.14, crater: 0.04 } - ]; + lmMin: 9, lmVar: 5, crownTall: 13, DG: 34, sky: 1, + butteMin: 9, butteVar: 23, rockStyle: 6, + styleCh: STYLE_CH_WEST, signCh: SIGN_CH_WEST, styleBase: 0, + setbackMode: 'falsefront', signShape: 'board', signPalette: 'painted' + }; - norm(DIST_CYBER); norm(DIST_WEST); norm(DIST_MOON); + var TH_MOON = { + id: 'moon', AVE: 96, CROSS: 84, + aveJit: 38, aveOff: -18, crossJit: 34, crossOff: -16, + aveWide: 20, aveMid: 15, aveNarrow: 11, aveMidP: 0.55, aveEvery: 5, + crossWide: 17, crossMid: 13, crossNarrow: 10, crossMidP: 0.50, crossEvery: 7, + lotW: 7, lotWVar: 9, lotD: 7, lotDVar: 9, + alleyMin: 12, alleyP: 0.00, alleyDeepMin: 12, alleyDeepP: 0.00, + plazaP: 0.00, plazaBigP: 0.00, plazaR: 14, plazaRVar: 16, + vacant: 0.62, setbackP: 0.00, podMin: 0, podVar: 0, falseFront: 0, + lmMin: 26, lmVar: 34, crownTall: 999, DG: 58, sky: 1, + rimMin: 1.4, rimVar: 4.2, startT: 0.10, + swellAmp: 2.8, swellLat: 54, swellLat2: 23, swellT: 0.56, swellEdge: 12, swellStyle: 9, + styleCh: STYLE_CH_MOON, signCh: SIGN_CH_WEST, styleBase: 7, + setbackMode: 'none', signShape: 'none', signPalette: 'none' + }; - TH_CYBER.dist = DIST_CYBER; TH_WEST.dist = DIST_WEST; TH_MOON.dist = DIST_MOON; - DIST = DIST_CYBER; + var THEMES = { cyber: TH_CYBER, west: TH_WEST, moon: TH_MOON }; + function themeOf(id) { return THEMES[id] || TH_CYBER; } + function worldId() { + return (C && C.World && C.World.id) ? C.World.id : 'cyber'; + } + + function bind() { + if (!C) C = (typeof globalThis !== 'undefined' && globalThis.CC) ? globalThis.CC : null; + if (!C) throw new Error('CC.City needs core.js loaded first'); + hash2 = C.hash2; clamp = C.clamp; vnoise = C.vnoise; P = C.P; + + for (var k in THEMES) { + var T = THEMES[k]; + T.styles = glyphTable(T.styleCh); + T.signs = signTable(T.signCh); } - function norm(T) { - var acc = 0; - for (var i = 0; i < T.length; i++) { acc += T[i].w; T[i].acc = acc; } - T.total = acc; + STYLE = THEMES.cyber.styles; STYLE_W = THEMES.west.styles; + SIGN_G = THEMES.cyber.signs; SIGN_G_W = THEMES.west.signs; + buildDistricts(); + } + function glyphTable(src) { + var out = []; + for (var i = 0; i < src.length; i++) + out.push([C.g(src[i][0]), C.g(src[i][1]), C.g(src[i][2])]); + return out; + } + function signTable(src) { + var out = []; + for (var j = 0; j < src.length; j++) out.push(C.g(src[j])); + return out; + } + + function make(seed) { + if (!STYLE) bind(); + var S = seed | 0; + + var TH = themeOf(worldId()); + var AVE = TH.AVE, CROSS = TH.CROSS; + var DIST = TH.dist; + var STY = TH.styles; + var SIGNS = TH.signs; + + function ax(k) { return k * AVE + ((hash(k, 0, S + 101) * TH.aveJit) | 0) + TH.aveOff; } + function aw(k) { + return (k % TH.aveEvery === 0) ? TH.aveWide + : (hash(k, 0, S + 102) < TH.aveMidP ? TH.aveMid : TH.aveNarrow); + } + function cz(m) { return m * CROSS + ((hash(0, m, S + 201) * TH.crossJit) | 0) + TH.crossOff; } + function cw(m) { + return (m % TH.crossEvery === 0) ? TH.crossWide + : (hash(0, m, S + 202) < TH.crossMidP ? TH.crossMid : TH.crossNarrow); } - var TH_CYBER = { - id: 'cyber', AVE: 30, CROSS: 26, - aveJit: 15, aveOff: -7, crossJit: 13, crossOff: -6, - aveWide: 6, aveMid: 4, aveNarrow: 3, aveMidP: 0.35, aveEvery: 4, - crossWide: 3, crossMid: 2, crossNarrow: 1, crossMidP: 0.28, crossEvery: 5, - lotW: 6, lotWVar: 7, lotD: 6, lotDVar: 8, - alleyMin: 10, alleyP: 0.45, alleyDeepMin: 11, alleyDeepP: 0.35, - plazaP: 0.13, plazaBigP: 0.26, plazaR: 5, plazaRVar: 7, - vacant: 0.06, setbackP: 0.42, podMin: 7, podVar: 10, falseFront: 0, - lmMin: 58, lmVar: 46, crownTall: 55, DG: 26, sky: 0, - styleCh: STYLE_CH, signCh: SIGN_CH, styleBase: 0, - setbackMode: 'podium', signShape: 'blade', signPalette: 'neon' + var SX = { street: 0, k: 0, b: 0, x0: 0, x1: 0 }; + var SZ = { street: 0, m: 0, b: 0, z0: 0, z1: 0 }; + + function colX(gx, o) { + var k = Math.round(gx / AVE), kk, c, w; + for (kk = k - 1; kk <= k + 1; kk++) { + c = ax(kk); w = aw(kk); + if (gx >= c - w && gx <= c + w) { o.street = 1; o.k = kk; return; } + } + + var b = (gx > ax(k)) ? k : k - 1; + o.street = 0; o.b = b; + o.x0 = ax(b) + aw(b) + 1; o.x1 = ax(b + 1) - aw(b + 1) - 1; + } + function rowZ(gz, o) { + var m = Math.round(gz / CROSS), mm, c, w; + for (mm = m - 1; mm <= m + 1; mm++) { + c = cz(mm); w = cw(mm); + if (gz >= c - w && gz <= c + w) { o.street = 1; o.m = mm; return; } + } + var b = (gz > cz(m)) ? m : m - 1; + o.street = 0; o.b = b; + o.z0 = cz(b) + cw(b) + 1; o.z1 = cz(b + 1) - cw(b + 1) - 1; + } + + var DG = TH.DG; + function districtType(p, q) { + var r = hash(p, q, S + 7) * DIST.total, i; + for (i = 0; i < DIST.length - 1; i++) if (r < DIST[i].acc) return i; + return DIST.length - 1; + } + function districtAt(gx, gz) { + var p = Math.floor(gx / DG), q = Math.floor(gz / DG); + var best = 1e18, bd = 0, dp, dq, pp, qq, sx, sz, ddx, ddz, d; + for (dq = -1; dq <= 1; dq++) for (dp = -1; dp <= 1; dp++) { + pp = p + dp; qq = q + dq; + sx = pp * DG + hash(pp, qq, S + 5) * DG; + sz = qq * DG + hash(pp, qq, S + 6) * DG; + ddx = gx - sx; ddz = gz - sz; d = ddx * ddx + ddz * ddz; + if (d < best) { best = d; bd = districtType(pp, qq); } + } + return bd; + } + + function bilin(gx, gz, lat, salt) { + var qx = gx / lat, qz = gz / lat; + var i0 = Math.floor(qx), j0 = Math.floor(qz); + var fx = qx - i0, fz = qz - j0; + fx = fx * fx * (3 - 2 * fx); fz = fz * fz * (3 - 2 * fz); + var a = hash(i0, j0, salt), b = hash(i0 + 1, j0, salt); + var c = hash(i0, j0 + 1, salt), d = hash(i0 + 1, j0 + 1, salt); + var ab = a + (b - a) * fx; + return ab + ((c + (d - c) * fx) - ab) * fz; + } + + function swellAt(gx, gz, x0, x1, z0, z1) { + var eu = gx - x0, e2 = x1 - gx; if (e2 < eu) eu = e2; + if (eu <= 0) return 0; + var ev = gz - z0; e2 = z1 - gz; if (e2 < ev) ev = e2; + if (ev <= 0) return 0; + var fu = eu < TH.swellEdge ? eu / TH.swellEdge : 1; + var fv = ev < TH.swellEdge ? ev / TH.swellEdge : 1; + fu = fu * fu * (3 - 2 * fu); fv = fv * fv * (3 - 2 * fv); + var n = bilin(gx, gz, TH.swellLat, S + 520) * 0.68 + + bilin(gx, gz, TH.swellLat2, S + 521) * 0.32; + if (n <= TH.swellT) return 0; + var m = (n - TH.swellT) / (1 - TH.swellT); + return TH.swellAmp * m * m * (3 - 2 * m) * fu * fv; + } + + var cH = 0, cD = 0, cLX = 0, cLZ = 0; + + var lmX = 0x7fffffff, lmZ = 0x7fffffff, lmD = 0; + + function computeCell(gx, gz) { + colX(gx, SX); rowZ(gz, SZ); + 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; + var bw = x1 - x0 + 1, bd = z1 - z0 + 1; + var t, wid, pos; + + if (bw >= TH.alleyMin && hash(bK, bM, S + 301) < TH.alleyP) { + wid = hash(bK, bM, S + 302) < 0.25 ? 2 : 1; + pos = x0 + 3 + ((hash(bK, bM, S + 303) * (bw - 6 - wid)) | 0); + if (gx >= pos && gx < pos + wid) { cH = 0; cD = districtAt(gx, gz); return; } + } + if (bd >= TH.alleyDeepMin && hash(bK, bM, S + 304) < TH.alleyDeepP) { + wid = hash(bK, bM, S + 305) < 0.25 ? 2 : 1; + pos = z0 + 3 + ((hash(bK, bM, S + 306) * (bd - 6 - wid)) | 0); + if (gz >= pos && gz < pos + wid) { cH = 0; cD = districtAt(gx, gz); return; } + } + + var kk, mm, r, dxp, dzp; + for (kk = bK; kk <= bK + 1; kk++) for (mm = bM; mm <= bM + 1; mm++) { + if (hash(kk, mm, S + 401) < (kk % 4 === 0 ? TH.plazaBigP : TH.plazaP)) { + r = TH.plazaR + ((hash(kk, mm, S + 402) * TH.plazaRVar) | 0); + dxp = gx - ax(kk); if (dxp < 0) dxp = -dxp; + dzp = gz - cz(mm); if (dzp < 0) dzp = -dzp; + if (dxp < r && dzp < r && dxp + dzp < r * 1.4) { cH = 0; cD = districtAt(gx, gz); return; } + } + } + + var lw = TH.lotW + ((hash(bK, bM, S + 307) * TH.lotWVar) | 0); + var ld = TH.lotD + ((hash(bK, bM, S + 308) * TH.lotDVar) | 0); + var lx = x0 + (((gx - x0) / lw) | 0) * lw; + var lz = z0 + (((gz - z0) / ld) | 0) * ld; + + var did; + if (lx === lmX && lz === lmZ) did = lmD; + else { did = districtAt(lx + (lw >> 1), lz + (ld >> 1)); lmX = lx; lmZ = lz; lmD = did; } + var D = DIST[did]; + + var h; + + var vac = D.vacant !== undefined ? D.vacant : TH.vacant; + if (hash(lx, lz, S + 504) < vac) { + h = 0; + } else if (D.butte && TH.butteMin !== undefined && hash(lx, lz, S + 507) < D.butte) { + + h = TH.butteMin + hash(lx, lz, S + 508) * TH.butteVar; + } else if (D.crater && TH.rimMin !== undefined && hash(lx, lz, S + 509) < D.crater) { + + var ccx = lx + lw * 0.5, ccz = lz + ld * 0.5; + var crr = (lw < ld ? lw : ld) * 0.5; + var cdx = gx + 0.5 - ccx, cdz = gz + 0.5 - ccz; + var cq = Math.sqrt(cdx * cdx + cdz * cdz) / crr; + if (cq > 1 || cq < 0.68) h = 0; + else h = (TH.rimMin + hash(lx, lz, S + 510) * TH.rimVar) * + Math.sin(((cq - 0.68) / 0.32) * Math.PI); + } else { + t = hash(lx, lz, S + 501); + h = D.hMin + t * t * (D.hMax - D.hMin); + if (hash(lx, lz, S + 502) < D.landmark) h = TH.lmMin + hash(lx, lz, S + 503) * TH.lmVar; + if (lw >= 4 && ld >= 4 && hash(lx, lz, S + 505) < TH.setbackP) { + var ix = gx - lx, iz = gz - lz; + var edge = (ix === 0 || iz === 0 || ix === lw - 1 || iz === ld - 1); + if (TH.setbackMode === 'falsefront') { + + if (!edge) { + var drop = 1.1 + hash(lx, lz, S + 506) * 1.7; + h -= drop; if (h < 2.4) h = 2.4; + } + } else if (TH.setbackMode === 'podium' && edge) { + + var pod = TH.podMin + hash(lx, lz, S + 506) * TH.podVar; + if (pod < h) h = pod; + } + } + } + + if (TH.swellAmp !== undefined) h += swellAt(gx, gz, x0, x1, z0, z1); + cH = h; cD = did; cLX = lx; cLZ = lz; + } + + function signHue(lx, lz, D) { + var r = hash(lx, lz, S + 701); + + if (TH.signPalette === 'none') return P.white; + if (TH.signPalette === 'painted') { + + if (r < 0.24) return P.warm; + if (r < 0.44) return P.amber; + if (r < 0.62) return P.white; + if (r < 0.74) return P.ember; + if (r < 0.84) return P.gold; + if (r < 0.92) return P.moss; + return P.red; + } + + if (D.accent === P.rose) return r < 0.42 ? P.rose : (r < 0.74 ? P.azure : P.amber); + + if (D.accent === P.gold) return r < 0.38 ? P.gold : (r < 0.62 ? P.jade : (r < 0.88 ? P.amber : P.rose)); + + if (D.accent === P.timber) return r < 0.34 ? P.gold : (r < 0.56 ? P.amber : (r < 0.80 ? P.moss : P.warm)); + if (D.accent === P.violet) return r < 0.42 ? P.violet : (r < 0.74 ? P.azure : P.amber); + if (r < 0.34) return P.amber; + if (r < 0.64) return P.azure; + + if (r < 0.78) return D.hue; + if (r < 0.86) return P.ember; + if (r < 0.93) return P.spring; + return P.violet; + } + + function makeRec(gx, gz, h, did, lx, lz) { + var D = DIST[did]; + var rock = !!(D.butte && TH.rockStyle !== undefined && hash(lx, lz, S + 507) < D.butte); + + var swellOnly = TH.swellStyle !== undefined && + hash(lx, lz, S + 504) < (D.vacant !== undefined ? D.vacant : TH.vacant); + var style = swellOnly ? TH.swellStyle + : (rock ? TH.rockStyle : D.styles[(hash(lx, lz, S + 601) * D.styles.length) | 0]); + + var g = STY[style - (TH.styleBase | 0)] || STY[0]; + var lit = rock ? 0 : clamp(D.lit * (0.5 + hash(lx, lz, S + 602) * 1.3), 0.02, 0.5); + + var sign = null; + if (!rock && D.signP > 0 && TH.signShape !== 'none' && hash(lx, lz, S + 603) < D.signP) { + if (TH.signShape === 'board') { + + var vertW = hash(lx, lz, S + 604) < 0.14; + + var shW = vertW ? 1.4 + hash(lx, lz, S + 605) * 1.0 : 1.00 + hash(lx, lz, S + 606) * 0.7; + var roomW = h - shW - 2.6; if (roomW < 0.4) roomW = 0.4; + sign = { + y: vertW ? 2.3 + hash(lx, lz, S + 607) * 0.5 : 2.6 + hash(lx, lz, S + 607) * roomW, + h: shW, + w: vertW ? 0.9 : 2.4 + hash(lx, lz, S + 608) * 2.2, + hue: signHue(lx, lz, D), + glyph: SIGNS[(hash(lx, lz, S + 609) * SIGNS.length) | 0], + vertical: vertW, + board: 1, + seed: hash(lx, lz, S + 610) + }; + } else { + var vert = hash(lx, lz, S + 604) < 0.45 && h > 16; + var sh = vert ? 5 + hash(lx, lz, S + 605) * 7 : 2 + hash(lx, lz, S + 606) * 2.5; + var room = h - sh - 4; if (room < 1) room = 1; + sign = { + y: 3 + hash(lx, lz, S + 607) * room, + h: sh, + w: vert ? 1 : 2 + ((hash(lx, lz, S + 608) * 3) | 0), + hue: signHue(lx, lz, D), + glyph: SIGNS[(hash(lx, lz, S + 609) * SIGNS.length) | 0], + vertical: vert, + seed: hash(lx, lz, S + 610) + }; + } + } + + var cr = hash(lx, lz, S + 611); + var tall = h > TH.crownTall; + return { + district: D.name, did: did, style: style, rock: rock, + hue: rock ? D.hue : (hash(lx, lz, S + 615) < D.mixP ? D.hue : D.mix), accent: D.accent, + glyph: g[0], dim: g[1], alt: g[2], + dimLum: 22 + ((hash(lx, lz, S + 612) * 20) | 0), + litRate: lit, sign: sign, + h: h, landmark: tall, + + crown: (rock || swellOnly) ? 0 : (tall ? 3 : (cr < 0.14 ? 1 : (cr < 0.24 ? 2 : 0))), + lotX: lx, lotZ: lz, + seed: hash(lx, lz, S + 613), + face: hash(gx, gz, S + 614) + }; + } + + var rows = new Map(); + + var order = [], CAP = 2048; + var mcx = 0x7fffffff, mcz = 0x7fffffff, mch = null; + + function buildChunk(cx, cz2) { + var h = new Float32Array(256), d = new Uint8Array(256); + var bx = cx * CH, bz = cz2 * CH, i = 0, jz, jx; + for (jz = 0; jz < CH; jz++) for (jx = 0; jx < CH; jx++, i++) { + computeCell(bx + jx, bz + jz); + h[i] = cH; d[i] = cD; + } + return { cx: cx, cz: cz2, h: h, d: d, recs: null }; + } + + function evict() { + + var n = CAP >> 2, i, c, row; + for (i = 0; i < n; i++) { + c = order[i]; row = rows.get(c.cz); + if (row) { row.delete(c.cx); if (row.size === 0) rows.delete(c.cz); } + } + order = order.slice(n); + mch = null; mcx = 0x7fffffff; mcz = 0x7fffffff; + } + + function chunkAt(cx, cz2) { + if (cx === mcx && cz2 === mcz) return mch; + var row = rows.get(cz2), ck; + if (row) { + ck = row.get(cx); + if (ck) { mcx = cx; mcz = cz2; mch = ck; return ck; } + } else { row = new Map(); rows.set(cz2, row); } + ck = buildChunk(cx, cz2); + row.set(cx, ck); + order.push(ck); + if (order.length > CAP) evict(); + mcx = cx; mcz = cz2; mch = ck; + return ck; + } + + function height(gx, gz) { + gx = Math.floor(gx); gz = Math.floor(gz); + var c = chunkAt(gx >> 4, gz >> 4); + return c.h[((gz & 15) << 4) | (gx & 15)]; + } + + function cell(gx, gz) { + gx = Math.floor(gx); gz = Math.floor(gz); + var c = chunkAt(gx >> 4, gz >> 4), i = ((gz & 15) << 4) | (gx & 15); + if (c.h[i] <= 0) return null; + var recs = c.recs; + if (!recs) { recs = c.recs = new Array(256); } + var r = recs[i]; + + if (r === undefined || r === null) { + computeCell(gx, gz); + r = recs[i] = makeRec(gx, gz, c.h[i], c.d[i], cLX, cLZ); + } + return r; + } + + function districtOf(gx, gz) { + gx = Math.floor(gx); gz = Math.floor(gz); + var c = chunkAt(gx >> 4, gz >> 4); + return c.d[((gz & 15) << 4) | (gx & 15)]; + } + + var RX = [], RZ = [], RS = [], RK = 0, RM = 0; + + function pushPt(x, z) { + var n = RX.length; + if (n) { + var dx = x - RX[n - 1], dz = z - RZ[n - 1]; + RS.push(RS[n - 1] + Math.sqrt(dx * dx + dz * dz)); + } else RS.push(0); + RX.push(x); RZ.push(z); + } + + function routeStep() { + var k = RK, m = RM; + pushPt(ax(k) + 0.5, cz(m) + 0.5); + + if (hash(k, m, S + 41) < 0.5 && aw(k) >= 2 && (cw(m) >= 2 || aw(k) >= 4)) { + var dir = hash(k, m, S + 42) < 0.5 ? -1 : 1; + if (aw(k + dir) >= 2) { pushPt(ax(k + dir) + 0.5, cz(m) + 0.5); RK = k + dir; } + } + RM = m + 1; + } + + function ensureRoute(sMax) { + while (RS[RS.length - 1] < sMax) routeStep(); + } + + var _pa = { x: 0, z: 0 }, _pb = { x: 0, z: 0 }, _pc = { x: 0, z: 0 }, _pr = { x: 0, z: 0 }; + + function posAt(s, o) { + var n = RS.length; + if (s <= RS[0]) { + var f0 = s - RS[0]; + o.x = RX[0]; o.z = RZ[0] + f0; + return; + } + var lo = 0, hi = n - 1, mid; + while (lo + 1 < hi) { mid = (lo + hi) >> 1; if (RS[mid] <= s) lo = mid; else hi = mid; } + var seg = RS[hi] - RS[lo], f = seg > 1e-6 ? (s - RS[lo]) / seg : 0; + o.x = RX[lo] + (RX[hi] - RX[lo]) * f; + o.z = RZ[lo] + (RZ[hi] - RZ[lo]) * f; + } + + var OFF = [-2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, 2.0], + WT = [0.146, 0.5, 0.854, 1, 1, 1, 0.854, 0.5, 0.146], WTS = 6.0; + function smoothPos(s, o) { + var sx = 0, sz = 0, i; + for (i = 0; i < 9; i++) { posAt(s + OFF[i], _pr); sx += _pr.x * WT[i]; sz += _pr.z * WT[i]; } + o.x = sx / WTS; o.z = sz / WTS; + } + + function nearestRouteS(x, z) { + var best = 0, bd = Infinity; + for (var i = 0; i + 1 < RX.length; i++) { + var x0 = RX[i], z0 = RZ[i], bx = RX[i + 1] - x0, bz = RZ[i + 1] - z0; + var L2 = bx * bx + bz * bz; + if (L2 < 1e-9) continue; + var u = ((x - x0) * bx + (z - z0) * bz) / L2; + if (u < 0) u = 0; else if (u > 1) u = 1; + var dx = x - (x0 + bx * u), dz = z - (z0 + bz * u), d = dx * dx + dz * dz; + if (d < bd) { bd = d; best = RS[i] + Math.sqrt(L2) * u; } + } + return { s: best, d: Math.sqrt(bd) }; + } + + var SPEED = 1.6; + + function camera(cam, city, t) { + var s = SPEED * t; + ensureRoute(s + 40); + + smoothPos(s, _pa); + smoothPos(s + 1.2, _pb); + smoothPos(s - 1.2, _pc); + + var dx = _pb.x - _pc.x, dz = _pb.z - _pc.z; + var dl = Math.sqrt(dx * dx + dz * dz) || 1; + dx /= dl; dz /= dl; + + var damp = C.reducedMotion ? 0.15 : 1; + + var lat = (vnoise(s * 0.09, S + 0x0000012D) - 0.5) * 0.9 * damp; + var x = _pa.x + dz * lat, z = _pa.z - dx * lat; + + if (height(x, z) > 0) { + posAt(s, _pr); + for (var i = 1; i <= 4; i++) { + var f = i / 4; + x = _pa.x + dz * lat * (1 - f) + (_pr.x - _pa.x) * f; + z = _pa.z - dx * lat * (1 - f) + (_pr.z - _pa.z) * f; + if (height(x, z) <= 0) break; + } + if (height(x, z) > 0) { x = _pr.x; z = _pr.z; } + } + + cam.x = x; cam.z = z; + + cam.yaw = Math.atan2(dx, dz) + + ((vnoise(s * 0.13, S + 0x51ED2701) - 0.5) * 0.10 + Math.sin(s * 0.41) * 0.02) * damp; + cam.eyeY = 1.66 + (Math.sin(s * 3.1) * 0.05 + (vnoise(s * 0.7, S + 0xA3C59AC3 | 0) - 0.5) * 0.04) * damp; + return cam; + } + + var START_BACKS = [14, 20, 26]; + + function sideAngle(x, z, dx) { + for (var d = 1; d <= 14; d += 0.5) { + var h = height(x + dx * d, z); + if (h > 0) return Math.atan2(h - 1.7, d); + } + return 0; + } + + function startScore(k, m, back) { + var x = ax(k) + 0.5, z0 = cz(m) + 0.5 - back, acc = 0, n = 0, s, L, R; + for (s = 0; s <= 24; s += 1.5) { + L = sideAngle(x, z0 + s, -1); R = sideAngle(x, z0 + s, 1); + acc += (L < R ? L : R); n++; + } + return acc / n; + } + + var START_T = TH.startT !== undefined ? TH.startT : 1.00; + var _start = { k: 0, m: 0, back: 18 }; + function chooseStart(o) { + var N = 8 * 8 * START_BACKS.length, j, k, m, b, sc; + + var SCAN = 64; + var st = 5 + ((hash(0, 0, S + 901) * 88) | 0) * 2; + if (st % 3 === 0) st += 2; + var i = ((hash(1, 0, S + 902) * N) | 0) % N; + var bestS = -1; + o.k = 0; o.m = 0; o.back = START_BACKS[0]; + for (j = 0; j < SCAN; j++) { + k = i & 7; m = (i >> 3) & 7; b = START_BACKS[(i / 64) | 0]; + sc = startScore(k, m, b); + if (sc > bestS) { bestS = sc; o.k = k; o.m = m; o.back = b; } + if (sc >= START_T) break; + i = (i + st) % N; + } + } + + chooseStart(_start); + RK = _start.k; RM = _start.m; + pushPt(ax(RK) + 0.5, cz(RM) + 0.5 - _start.back); + ensureRoute(60); + + return { + seed: S, + startX: RX[0], startZ: RZ[0], + height: height, cell: cell, camera: camera, + nearestRouteS: nearestRouteS, ensureRoute: ensureRoute, + districtAt: districtOf, DISTRICTS: DIST, + isStreet: function (gx, gz) { return height(gx, gz) <= 0; }, + + aveX: ax, aveW: aw, crossZ: cz, crossW: cw, + AVE: AVE, CROSS: CROSS, SPEED: SPEED, + + world: TH.id }; - var TH_WEST = { - id: 'west', AVE: 52, CROSS: 44, - aveJit: 19, aveOff: -9, crossJit: 15, crossOff: -7, - aveWide: 9, aveMid: 7, aveNarrow: 6, aveMidP: 0.42, aveEvery: 3, - crossWide: 6, crossMid: 4, crossNarrow: 3, crossMidP: 0.34, crossEvery: 4, - lotW: 5, lotWVar: 5, lotD: 6, lotDVar: 6, - alleyMin: 9, alleyP: 0.52, alleyDeepMin: 10, alleyDeepP: 0.40, - plazaP: 0.20, plazaBigP: 0.34, plazaR: 6, plazaRVar: 9, - vacant: 0.14, setbackP: 0.68, podMin: 0, podVar: 0, falseFront: 1, + } - lmMin: 9, lmVar: 5, crownTall: 13, DG: 34, sky: 1, - butteMin: 9, butteVar: 23, rockStyle: 6, - styleCh: STYLE_CH_WEST, signCh: SIGN_CH_WEST, styleBase: 0, - setbackMode: 'falsefront', signShape: 'board', signPalette: 'painted' - }; - - var TH_MOON = { - id: 'moon', AVE: 96, CROSS: 84, - aveJit: 38, aveOff: -18, crossJit: 34, crossOff: -16, - aveWide: 20, aveMid: 15, aveNarrow: 11, aveMidP: 0.55, aveEvery: 2, - crossWide: 17, crossMid: 13, crossNarrow: 10, crossMidP: 0.50, crossEvery: 2, - lotW: 7, lotWVar: 9, lotD: 7, lotDVar: 9, - alleyMin: 12, alleyP: 0.70, alleyDeepMin: 12, alleyDeepP: 0.70, - plazaP: 0.55, plazaBigP: 0.70, plazaR: 14, plazaRVar: 16, - vacant: 0.62, setbackP: 0.00, podMin: 0, podVar: 0, falseFront: 0, - lmMin: 26, lmVar: 34, crownTall: 999, DG: 58, sky: 1, - rimMin: 1.4, rimVar: 4.2, startT: 0.10, - styleCh: STYLE_CH_MOON, signCh: SIGN_CH_WEST, styleBase: 7, - setbackMode: 'none', signShape: 'none', signPalette: 'none' - }; - - var THEMES = { cyber: TH_CYBER, west: TH_WEST, moon: TH_MOON }; - function themeOf(id) { return THEMES[id] || TH_CYBER; } - function worldId() { - return (C && C.World && C.World.id) ? C.World.id : 'cyber'; - } - - function bind() { - if (!C) C = (typeof globalThis !== 'undefined' && globalThis.CC) ? globalThis.CC : null; - if (!C) throw new Error('CC.City needs core.js loaded first'); - hash2 = C.hash2; clamp = C.clamp; vnoise = C.vnoise; P = C.P; - - for (var k in THEMES) { - var T = THEMES[k]; - T.styles = glyphTable(T.styleCh); - T.signs = signTable(T.signCh); - } - STYLE = THEMES.cyber.styles; STYLE_W = THEMES.west.styles; - SIGN_G = THEMES.cyber.signs; SIGN_G_W = THEMES.west.signs; - buildDistricts(); - } - function glyphTable(src) { - var out = []; - for (var i = 0; i < src.length; i++) - out.push([C.g(src[i][0]), C.g(src[i][1]), C.g(src[i][2])]); - return out; - } - function signTable(src) { - var out = []; - for (var j = 0; j < src.length; j++) out.push(C.g(src[j])); - return out; - } - - function make(seed) { - if (!STYLE) bind(); - var S = seed | 0; - - var TH = themeOf(worldId()); - var AVE = TH.AVE, CROSS = TH.CROSS; - var DIST = TH.dist; - var STY = TH.styles; - var SIGNS = TH.signs; - - function ax(k) { return k * AVE + ((hash(k, 0, S + 101) * TH.aveJit) | 0) + TH.aveOff; } - function aw(k) { - return (k % TH.aveEvery === 0) ? TH.aveWide - : (hash(k, 0, S + 102) < TH.aveMidP ? TH.aveMid : TH.aveNarrow); - } - function cz(m) { return m * CROSS + ((hash(0, m, S + 201) * TH.crossJit) | 0) + TH.crossOff; } - function cw(m) { - return (m % TH.crossEvery === 0) ? TH.crossWide - : (hash(0, m, S + 202) < TH.crossMidP ? TH.crossMid : TH.crossNarrow); - } - - var SX = { street: 0, k: 0, b: 0, x0: 0, x1: 0 }; - var SZ = { street: 0, m: 0, b: 0, z0: 0, z1: 0 }; - - function colX(gx, o) { - var k = Math.round(gx / AVE), kk, c, w; - for (kk = k - 1; kk <= k + 1; kk++) { - c = ax(kk); w = aw(kk); - if (gx >= c - w && gx <= c + w) { o.street = 1; o.k = kk; return; } - } - - var b = (gx > ax(k)) ? k : k - 1; - o.street = 0; o.b = b; - o.x0 = ax(b) + aw(b) + 1; o.x1 = ax(b + 1) - aw(b + 1) - 1; - } - function rowZ(gz, o) { - var m = Math.round(gz / CROSS), mm, c, w; - for (mm = m - 1; mm <= m + 1; mm++) { - c = cz(mm); w = cw(mm); - if (gz >= c - w && gz <= c + w) { o.street = 1; o.m = mm; return; } - } - var b = (gz > cz(m)) ? m : m - 1; - o.street = 0; o.b = b; - o.z0 = cz(b) + cw(b) + 1; o.z1 = cz(b + 1) - cw(b + 1) - 1; - } - - var DG = TH.DG; - function districtType(p, q) { - var r = hash(p, q, S + 7) * DIST.total, i; - for (i = 0; i < DIST.length - 1; i++) if (r < DIST[i].acc) return i; - return DIST.length - 1; - } - function districtAt(gx, gz) { - var p = Math.floor(gx / DG), q = Math.floor(gz / DG); - var best = 1e18, bd = 0, dp, dq, pp, qq, sx, sz, ddx, ddz, d; - for (dq = -1; dq <= 1; dq++) for (dp = -1; dp <= 1; dp++) { - pp = p + dp; qq = q + dq; - sx = pp * DG + hash(pp, qq, S + 5) * DG; - sz = qq * DG + hash(pp, qq, S + 6) * DG; - ddx = gx - sx; ddz = gz - sz; d = ddx * ddx + ddz * ddz; - if (d < best) { best = d; bd = districtType(pp, qq); } - } - return bd; - } - - var cH = 0, cD = 0, cLX = 0, cLZ = 0; - - var lmX = 0x7fffffff, lmZ = 0x7fffffff, lmD = 0; - - function computeCell(gx, gz) { - colX(gx, SX); rowZ(gz, SZ); - 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; - var bw = x1 - x0 + 1, bd = z1 - z0 + 1; - var t, wid, pos; - - if (bw >= TH.alleyMin && hash(bK, bM, S + 301) < TH.alleyP) { - wid = hash(bK, bM, S + 302) < 0.25 ? 2 : 1; - pos = x0 + 3 + ((hash(bK, bM, S + 303) * (bw - 6 - wid)) | 0); - if (gx >= pos && gx < pos + wid) { cH = 0; cD = districtAt(gx, gz); return; } - } - if (bd >= TH.alleyDeepMin && hash(bK, bM, S + 304) < TH.alleyDeepP) { - wid = hash(bK, bM, S + 305) < 0.25 ? 2 : 1; - pos = z0 + 3 + ((hash(bK, bM, S + 306) * (bd - 6 - wid)) | 0); - if (gz >= pos && gz < pos + wid) { cH = 0; cD = districtAt(gx, gz); return; } - } - - var kk, mm, r, dxp, dzp; - for (kk = bK; kk <= bK + 1; kk++) for (mm = bM; mm <= bM + 1; mm++) { - if (hash(kk, mm, S + 401) < (kk % 4 === 0 ? TH.plazaBigP : TH.plazaP)) { - r = TH.plazaR + ((hash(kk, mm, S + 402) * TH.plazaRVar) | 0); - dxp = gx - ax(kk); if (dxp < 0) dxp = -dxp; - dzp = gz - cz(mm); if (dzp < 0) dzp = -dzp; - if (dxp < r && dzp < r && dxp + dzp < r * 1.4) { cH = 0; cD = districtAt(gx, gz); return; } - } - } - - var lw = TH.lotW + ((hash(bK, bM, S + 307) * TH.lotWVar) | 0); - var ld = TH.lotD + ((hash(bK, bM, S + 308) * TH.lotDVar) | 0); - var lx = x0 + (((gx - x0) / lw) | 0) * lw; - var lz = z0 + (((gz - z0) / ld) | 0) * ld; - - var did; - if (lx === lmX && lz === lmZ) did = lmD; - else { did = districtAt(lx + (lw >> 1), lz + (ld >> 1)); lmX = lx; lmZ = lz; lmD = did; } - var D = DIST[did]; - - var h; - - var vac = D.vacant !== undefined ? D.vacant : TH.vacant; - if (hash(lx, lz, S + 504) < vac) { - h = 0; - } else if (D.butte && TH.butteMin !== undefined && hash(lx, lz, S + 507) < D.butte) { - - h = TH.butteMin + hash(lx, lz, S + 508) * TH.butteVar; - } else if (D.crater && TH.rimMin !== undefined && hash(lx, lz, S + 509) < D.crater) { - - var ccx = lx + lw * 0.5, ccz = lz + ld * 0.5; - var crr = (lw < ld ? lw : ld) * 0.5; - var cdx = gx + 0.5 - ccx, cdz = gz + 0.5 - ccz; - var cq = Math.sqrt(cdx * cdx + cdz * cdz) / crr; - if (cq > 1 || cq < 0.68) h = 0; - else h = (TH.rimMin + hash(lx, lz, S + 510) * TH.rimVar) * - Math.sin(((cq - 0.68) / 0.32) * Math.PI); - } else { - t = hash(lx, lz, S + 501); - h = D.hMin + t * t * (D.hMax - D.hMin); - if (hash(lx, lz, S + 502) < D.landmark) h = TH.lmMin + hash(lx, lz, S + 503) * TH.lmVar; - if (lw >= 4 && ld >= 4 && hash(lx, lz, S + 505) < TH.setbackP) { - var ix = gx - lx, iz = gz - lz; - var edge = (ix === 0 || iz === 0 || ix === lw - 1 || iz === ld - 1); - if (TH.setbackMode === 'falsefront') { - - if (!edge) { - var drop = 1.1 + hash(lx, lz, S + 506) * 1.7; - h -= drop; if (h < 2.4) h = 2.4; - } - } else if (TH.setbackMode === 'podium' && edge) { - - var pod = TH.podMin + hash(lx, lz, S + 506) * TH.podVar; - if (pod < h) h = pod; - } - } - } - cH = h; cD = did; cLX = lx; cLZ = lz; - } - - function signHue(lx, lz, D) { - var r = hash(lx, lz, S + 701); - - if (TH.signPalette === 'none') return P.white; - if (TH.signPalette === 'painted') { - if (r < 0.30) return P.warm; - if (r < 0.58) return P.amber; - if (r < 0.76) return P.white; - if (r < 0.90) return P.ember; - return P.red; - } - - if (D.accent === P.violet) return r < 0.42 ? P.violet : (r < 0.74 ? P.azure : P.amber); - if (r < 0.34) return P.amber; - if (r < 0.64) return P.azure; - if (r < 0.78) return D.hue; - if (r < 0.86) return P.ember; - if (r < 0.93) return P.spring; - return P.violet; - } - - function makeRec(gx, gz, h, did, lx, lz) { - var D = DIST[did]; - var rock = !!(D.butte && TH.rockStyle !== undefined && hash(lx, lz, S + 507) < D.butte); - var style = rock ? TH.rockStyle : D.styles[(hash(lx, lz, S + 601) * D.styles.length) | 0]; - - var g = STY[style - (TH.styleBase | 0)] || STY[0]; - var lit = rock ? 0 : clamp(D.lit * (0.5 + hash(lx, lz, S + 602) * 1.3), 0.02, 0.5); - - var sign = null; - if (!rock && D.signP > 0 && TH.signShape !== 'none' && hash(lx, lz, S + 603) < D.signP) { - if (TH.signShape === 'board') { - - var vertW = hash(lx, lz, S + 604) < 0.14; - - var shW = vertW ? 1.4 + hash(lx, lz, S + 605) * 1.0 : 1.00 + hash(lx, lz, S + 606) * 0.7; - var roomW = h - shW - 2.6; if (roomW < 0.4) roomW = 0.4; - sign = { - y: vertW ? 2.3 + hash(lx, lz, S + 607) * 0.5 : 2.6 + hash(lx, lz, S + 607) * roomW, - h: shW, - w: vertW ? 0.9 : 2.4 + hash(lx, lz, S + 608) * 2.2, - hue: signHue(lx, lz, D), - glyph: SIGNS[(hash(lx, lz, S + 609) * SIGNS.length) | 0], - vertical: vertW, - board: 1, - seed: hash(lx, lz, S + 610) - }; - } else { - var vert = hash(lx, lz, S + 604) < 0.45 && h > 16; - var sh = vert ? 5 + hash(lx, lz, S + 605) * 7 : 2 + hash(lx, lz, S + 606) * 2.5; - var room = h - sh - 4; if (room < 1) room = 1; - sign = { - y: 3 + hash(lx, lz, S + 607) * room, - h: sh, - w: vert ? 1 : 2 + ((hash(lx, lz, S + 608) * 3) | 0), - hue: signHue(lx, lz, D), - glyph: SIGNS[(hash(lx, lz, S + 609) * SIGNS.length) | 0], - vertical: vert, - seed: hash(lx, lz, S + 610) - }; - } - } - - var cr = hash(lx, lz, S + 611); - var tall = h > TH.crownTall; - return { - district: D.name, did: did, style: style, rock: rock, - hue: rock ? D.hue : (hash(lx, lz, S + 615) < D.mixP ? D.hue : D.mix), accent: D.accent, - glyph: g[0], dim: g[1], alt: g[2], - dimLum: 22 + ((hash(lx, lz, S + 612) * 20) | 0), - litRate: lit, sign: sign, - h: h, landmark: tall, - - crown: rock ? 0 : (tall ? 3 : (cr < 0.14 ? 1 : (cr < 0.24 ? 2 : 0))), - lotX: lx, lotZ: lz, - seed: hash(lx, lz, S + 613), - face: hash(gx, gz, S + 614) - }; - } - - var rows = new Map(); - - var order = [], CAP = 2048; - var mcx = 0x7fffffff, mcz = 0x7fffffff, mch = null; - - function buildChunk(cx, cz2) { - var h = new Float32Array(256), d = new Uint8Array(256); - var bx = cx * CH, bz = cz2 * CH, i = 0, jz, jx; - for (jz = 0; jz < CH; jz++) for (jx = 0; jx < CH; jx++, i++) { - computeCell(bx + jx, bz + jz); - h[i] = cH; d[i] = cD; - } - return { cx: cx, cz: cz2, h: h, d: d, recs: null }; - } - - function evict() { - - var n = CAP >> 2, i, c, row; - for (i = 0; i < n; i++) { - c = order[i]; row = rows.get(c.cz); - if (row) { row.delete(c.cx); if (row.size === 0) rows.delete(c.cz); } - } - order = order.slice(n); - mch = null; mcx = 0x7fffffff; mcz = 0x7fffffff; - } - - function chunkAt(cx, cz2) { - if (cx === mcx && cz2 === mcz) return mch; - var row = rows.get(cz2), ck; - if (row) { - ck = row.get(cx); - if (ck) { mcx = cx; mcz = cz2; mch = ck; return ck; } - } else { row = new Map(); rows.set(cz2, row); } - ck = buildChunk(cx, cz2); - row.set(cx, ck); - order.push(ck); - if (order.length > CAP) evict(); - mcx = cx; mcz = cz2; mch = ck; - return ck; - } - - function height(gx, gz) { - gx = Math.floor(gx); gz = Math.floor(gz); - var c = chunkAt(gx >> 4, gz >> 4); - return c.h[((gz & 15) << 4) | (gx & 15)]; - } - - function cell(gx, gz) { - gx = Math.floor(gx); gz = Math.floor(gz); - var c = chunkAt(gx >> 4, gz >> 4), i = ((gz & 15) << 4) | (gx & 15); - if (c.h[i] <= 0) return null; - var recs = c.recs; - if (!recs) { recs = c.recs = new Array(256); } - var r = recs[i]; - - if (r === undefined || r === null) { - computeCell(gx, gz); - r = recs[i] = makeRec(gx, gz, c.h[i], c.d[i], cLX, cLZ); - } - return r; - } - - function districtOf(gx, gz) { - gx = Math.floor(gx); gz = Math.floor(gz); - var c = chunkAt(gx >> 4, gz >> 4); - return c.d[((gz & 15) << 4) | (gx & 15)]; - } - - var RX = [], RZ = [], RS = [], RK = 0, RM = 0; - - function pushPt(x, z) { - var n = RX.length; - if (n) { - var dx = x - RX[n - 1], dz = z - RZ[n - 1]; - RS.push(RS[n - 1] + Math.sqrt(dx * dx + dz * dz)); - } else RS.push(0); - RX.push(x); RZ.push(z); - } - - function routeStep() { - var k = RK, m = RM; - pushPt(ax(k) + 0.5, cz(m) + 0.5); - - if (hash(k, m, S + 41) < 0.5 && aw(k) >= 2 && (cw(m) >= 2 || aw(k) >= 4)) { - var dir = hash(k, m, S + 42) < 0.5 ? -1 : 1; - if (aw(k + dir) >= 2) { pushPt(ax(k + dir) + 0.5, cz(m) + 0.5); RK = k + dir; } - } - RM = m + 1; - } - - function ensureRoute(sMax) { - while (RS[RS.length - 1] < sMax) routeStep(); - } - - var _pa = { x: 0, z: 0 }, _pb = { x: 0, z: 0 }, _pc = { x: 0, z: 0 }, _pr = { x: 0, z: 0 }; - - function posAt(s, o) { - var n = RS.length; - if (s <= RS[0]) { - var f0 = s - RS[0]; - o.x = RX[0]; o.z = RZ[0] + f0; - return; - } - var lo = 0, hi = n - 1, mid; - while (lo + 1 < hi) { mid = (lo + hi) >> 1; if (RS[mid] <= s) lo = mid; else hi = mid; } - var seg = RS[hi] - RS[lo], f = seg > 1e-6 ? (s - RS[lo]) / seg : 0; - o.x = RX[lo] + (RX[hi] - RX[lo]) * f; - o.z = RZ[lo] + (RZ[hi] - RZ[lo]) * f; - } - - var OFF = [-2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, 2.0], - WT = [0.146, 0.5, 0.854, 1, 1, 1, 0.854, 0.5, 0.146], WTS = 6.0; - function smoothPos(s, o) { - var sx = 0, sz = 0, i; - for (i = 0; i < 9; i++) { posAt(s + OFF[i], _pr); sx += _pr.x * WT[i]; sz += _pr.z * WT[i]; } - o.x = sx / WTS; o.z = sz / WTS; - } - - function nearestRouteS(x, z) { - var best = 0, bd = Infinity; - for (var i = 0; i + 1 < RX.length; i++) { - var x0 = RX[i], z0 = RZ[i], bx = RX[i + 1] - x0, bz = RZ[i + 1] - z0; - var L2 = bx * bx + bz * bz; - if (L2 < 1e-9) continue; - var u = ((x - x0) * bx + (z - z0) * bz) / L2; - if (u < 0) u = 0; else if (u > 1) u = 1; - var dx = x - (x0 + bx * u), dz = z - (z0 + bz * u), d = dx * dx + dz * dz; - if (d < bd) { bd = d; best = RS[i] + Math.sqrt(L2) * u; } - } - return { s: best, d: Math.sqrt(bd) }; - } - - var SPEED = 1.6; - - function camera(cam, city, t) { - var s = SPEED * t; - ensureRoute(s + 40); - - smoothPos(s, _pa); - smoothPos(s + 1.2, _pb); - smoothPos(s - 1.2, _pc); - - var dx = _pb.x - _pc.x, dz = _pb.z - _pc.z; - var dl = Math.sqrt(dx * dx + dz * dz) || 1; - dx /= dl; dz /= dl; - - var damp = C.reducedMotion ? 0.15 : 1; - - var lat = (vnoise(s * 0.09, S + 0x0000012D) - 0.5) * 0.9 * damp; - var x = _pa.x + dz * lat, z = _pa.z - dx * lat; - - if (height(x, z) > 0) { - posAt(s, _pr); - for (var i = 1; i <= 4; i++) { - var f = i / 4; - x = _pa.x + dz * lat * (1 - f) + (_pr.x - _pa.x) * f; - z = _pa.z - dx * lat * (1 - f) + (_pr.z - _pa.z) * f; - if (height(x, z) <= 0) break; - } - if (height(x, z) > 0) { x = _pr.x; z = _pr.z; } - } - - cam.x = x; cam.z = z; - - cam.yaw = Math.atan2(dx, dz) - + ((vnoise(s * 0.13, S + 0x51ED2701) - 0.5) * 0.10 + Math.sin(s * 0.41) * 0.02) * damp; - cam.eyeY = 1.66 + (Math.sin(s * 3.1) * 0.05 + (vnoise(s * 0.7, S + 0xA3C59AC3 | 0) - 0.5) * 0.04) * damp; - return cam; - } - - var START_BACKS = [14, 20, 26]; - - function sideAngle(x, z, dx) { - for (var d = 1; d <= 14; d += 0.5) { - var h = height(x + dx * d, z); - if (h > 0) return Math.atan2(h - 1.7, d); - } - return 0; - } - - function startScore(k, m, back) { - var x = ax(k) + 0.5, z0 = cz(m) + 0.5 - back, acc = 0, n = 0, s, L, R; - for (s = 0; s <= 24; s += 1.5) { - L = sideAngle(x, z0 + s, -1); R = sideAngle(x, z0 + s, 1); - acc += (L < R ? L : R); n++; - } - return acc / n; - } - - var START_T = TH.startT !== undefined ? TH.startT : 1.00; - var _start = { k: 0, m: 0, back: 18 }; - function chooseStart(o) { - var N = 8 * 8 * START_BACKS.length, j, k, m, b, sc; - - var SCAN = 64; - var st = 5 + ((hash(0, 0, S + 901) * 88) | 0) * 2; - if (st % 3 === 0) st += 2; - var i = ((hash(1, 0, S + 902) * N) | 0) % N; - var bestS = -1; - o.k = 0; o.m = 0; o.back = START_BACKS[0]; - for (j = 0; j < SCAN; j++) { - k = i & 7; m = (i >> 3) & 7; b = START_BACKS[(i / 64) | 0]; - sc = startScore(k, m, b); - if (sc > bestS) { bestS = sc; o.k = k; o.m = m; o.back = b; } - if (sc >= START_T) break; - i = (i + st) % N; - } - } - - chooseStart(_start); - RK = _start.k; RM = _start.m; - pushPt(ax(RK) + 0.5, cz(RM) + 0.5 - _start.back); - ensureRoute(60); - - return { - seed: S, - startX: RX[0], startZ: RZ[0], - height: height, cell: cell, camera: camera, - nearestRouteS: nearestRouteS, ensureRoute: ensureRoute, - districtAt: districtOf, DISTRICTS: DIST, - isStreet: function (gx, gz) { return height(gx, gz) <= 0; }, - - aveX: ax, aveW: aw, crossZ: cz, crossW: cw, - AVE: AVE, CROSS: CROSS, SPEED: SPEED, - - world: TH.id - }; - } - - var City = { make: make }; - if (C) C.City = City; - else if (typeof globalThis !== 'undefined' && globalThis.CC) globalThis.CC.City = City; + var City = { make: make }; + if (C) C.City = City; + else if (typeof globalThis !== 'undefined' && globalThis.CC) globalThis.CC.City = City; })(); /* src/surfaces.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise; + var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise; - var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), - G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_PLUS = g('+'), - G_PIPE = g('|'), G_SLASH = g('/'), G_BSLASH = g('\\'), G_HASH = g('#'), G_PCT = g('%'), - G_8 = g('8'), G_O = g('O'), G_0 = g('0'), G_X = g('X'), G_Z = g('Z'), G_W = g('W'), - G_M = g('M'), G_TILDE = g('~'), G_oo = g('o'), G_DQ = g('"'), G_V = g('V'); + var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), + G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_PLUS = g('+'), + G_PIPE = g('|'), G_SLASH = g('/'), G_BSLASH = g('\\'), G_HASH = g('#'), G_PCT = g('%'), + G_8 = g('8'), G_O = g('O'), G_0 = g('0'), G_X = g('X'), G_Z = g('Z'), G_W = g('W'), + G_M = g('M'), G_TILDE = g('~'), G_oo = g('o'), G_DQ = g('"'), G_V = g('V'); - var SHOP_OPEN = 0.52; + var SHOP_OPEN = 0.52; - var FILL = [G_8, G_0, G_O, G_HASH, G_X, G_Z, G_8, G_M, G_W, G_PCT]; - var FILL_N = FILL.length; - var DIMGL = [G_COLON, G_DOT, G_QUOTE, G_DASH, G_SEMI, G_COMMA, G_TICK, G_UNDER]; - var DIMGL_N = DIMGL.length; + var FILL = [G_8, G_0, G_O, G_HASH, G_X, G_Z, G_8, G_M, G_W, G_PCT]; + var FILL_N = FILL.length; + var DIMGL = [G_COLON, G_DOT, G_QUOTE, G_DASH, G_SEMI, G_COMMA, G_TICK, G_UNDER]; + var DIMGL_N = DIMGL.length; - var STYLE = [ - { pu: 2.60, pv: 3.30, mu: 0.20, sill: 0.20, head: 0.86, panes: 2, prow: 1, band: 4, gnd: 4.2 }, - { pu: 3.40, pv: 3.90, mu: 0.15, sill: 0.13, head: 0.90, panes: 3, prow: 2, band: 3, gnd: 4.8 }, - { pu: 2.10, pv: 2.90, mu: 0.26, sill: 0.26, head: 0.80, panes: 1, prow: 1, band: 5, gnd: 3.6 }, - { pu: 4.10, pv: 4.40, mu: 0.12, sill: 0.10, head: 0.93, panes: 4, prow: 2, band: 3, gnd: 5.4 }, - { pu: 3.00, pv: 3.60, mu: 0.18, sill: 0.22, head: 0.84, panes: 2, prow: 2, band: 4, gnd: 4.4 } - ]; + var STYLE = [ + { pu: 2.60, pv: 3.30, mu: 0.20, sill: 0.20, head: 0.86, panes: 2, prow: 1, band: 4, gnd: 4.2 }, + { pu: 3.40, pv: 3.90, mu: 0.15, sill: 0.13, head: 0.90, panes: 3, prow: 2, band: 3, gnd: 4.8 }, + { pu: 2.10, pv: 2.90, mu: 0.26, sill: 0.26, head: 0.80, panes: 1, prow: 1, band: 5, gnd: 3.6 }, + { pu: 4.10, pv: 4.40, mu: 0.12, sill: 0.10, head: 0.93, panes: 4, prow: 2, band: 3, gnd: 5.4 }, + { pu: 3.00, pv: 3.60, mu: 0.18, sill: 0.22, head: 0.84, panes: 2, prow: 2, band: 4, gnd: 4.4 } + ]; - var CFG = { - grid: 8.0, - streetX: 4.0, - streetPeriod: 8.0, - half: 3.10, - horizon: 33.6, + var CFG = { + grid: 8.0, + streetX: 4.0, + streetPeriod: 8.0, + half: 3.10, + horizon: 33.6, - rows: 60, + rows: 60, - xn: 0, - xc: new Float64Array(8), - xw: new Float64Array(8), - xz0: 0, xpitch: 26, + xn: 0, + xc: new Float64Array(8), + xw: new Float64Array(8), + xz0: 0, xpitch: 26, - rail: 0, - skySeed: 0x5EED, + rail: 0, + skySeed: 0x5EED, - skyVScale: 1, + skyVScale: 1, - skyK: 1, + skyK: 1, - swap: 0 - }; - function configure(o) { - if (!o) return CFG; - for (var k in o) if (CFG[k] !== undefined && o[k] !== undefined && k !== 'xc' && k !== 'xw') - CFG[k] = o[k]; + swap: 0 + }; + function configure(o) { + if (!o) return CFG; + for (var k in o) if (CFG[k] !== undefined && o[k] !== undefined && k !== 'xc' && k !== 'xw') + CFG[k] = o[k]; - CFG.rail = (CFG.half > 2.7 && hash2((CFG.streetX * 4) | 0, (CFG.half * 8) | 0, 0x5A11) < 0.34) - ? 1 : 0; - return CFG; + CFG.rail = (CFG.half > 2.7 && hash2((CFG.streetX * 4) | 0, (CFG.half * 8) | 0, 0x5A11) < 0.34) + ? 1 : 0; + return CFG; + } + + var dT = 1 / 0, dSky = 0, dLamp = 1, dSun = 0, dWarm = 0; + + var SUNX = 0, SUNZ = 1, SUN_ALT = 0; + function dayAt(t) { + if (t === dT) return; + dT = t; + var D = CC.Daylight; + if (!D) return; + dSky = D.P.sky; dLamp = D.P.lamp; dSun = D.P.sun; dWarm = D.P.warm; + SUNX = Math.sin(D.P.az); SUNZ = Math.cos(D.P.az); SUN_ALT = D.P.alt; + + refog(); + } + + function sunFace(cell) { + if (!cell || cell.faceX === undefined) return 0.5; + + var d = cell.faceX ? -cell.side * SUNX : -cell.side * SUNZ; + var split = 1 - 0.62 * clamp(SUN_ALT / 0.95, 0, 1); + return clamp(0.5 + 0.70 * d * split, 0, 1); + } + + var wT = 1 / 0, wWet = 1, wRain = 1, wWind = 1, wFogP = 0.30; + function weatherAt(t) { + if (t === wT) return; + wT = t; + var W = CC.Weather; + if (!W) return; + wWet = W.rel('wet'); wRain = W.rel('rain'); wWind = W.rel('wind'); + wFogP = W.P.fog; + refog(); + } + + function seedOf(cell) { + if (!cell || typeof cell !== 'object') return 0; + if (cell.seed !== undefined) return cell.seed | 0; + if (cell.id !== undefined) return cell.id | 0; + var x = cell.gx !== undefined ? cell.gx : (cell.x !== undefined ? cell.x : 0); + var z = cell.gz !== undefined ? cell.gz : (cell.z !== undefined ? cell.z : 0); + return (hash2(x, z, 7717) * 2147483647) | 0; + } + function styleOf(cell, sd) { + var s = cell && cell.style; + if (typeof s === 'number') return STYLE[((s | 0) % STYLE.length + STYLE.length) % STYLE.length]; + return STYLE[(hash2(sd, 11, 0x51) * STYLE.length) | 0]; + } + function litOf(cell) { + var r = cell && cell.litRate; + r = typeof r === 'number' ? r : 0.34; + + return clamp(r * (0.22 + 0.78 * dLamp), 0, 1); + } + + function accentOf(cell, sd) { + if (cell && typeof cell.accent === 'number') return cell.accent | 0; + var r = hash2(sd, 5, 0x33A); + return r < 0.46 ? P.ember : (r < 0.86 ? P.spring : P.violet); + } + + function hueOf(cell, sd) { + if (cell && typeof cell.hue === 'number') return cell.hue | 0; + var dr = hash2(0, 0, sd ^ 0x2B1D); + return dr < 0.58 ? P.azure : (dr < 0.90 ? P.amber : P.warm); + } + + var FOUT = { ch: 0, col: 0, lum: 0 }; + var fU = 0, fV = 0, fSd = 0; + + var fMat = 0, fSun = 0.5, fUp = 0, fGrain = 0, dayG = 1; + + function upFace() { + var alt = clamp(SUN_ALT / 0.95, 0, 1); + return fSun * 0.35 + 0.65 * (0.45 + 0.55 * alt); + } + + function dayMat(dK) { + + if (dK < 0.50) { dayG = 1; return dK > 0.06 ? P.indigo : P.slate; } + + var sn = fUp ? upFace() : fSun; + var s = 0.85 + 1.10 * sn; + + if (fMat === 1) { dayG = 0.90 * s; return P.indigo; } + + if (fGrain) { dayG = 1.95 * s; return P.stone; } + + dayG = s; + return (fSd & 7) < 2 ? P.sand : P.white; + } + function fset(ch, col, lum) { + if (dSky > 0.02) { + + var dK = dSky * dSky; + if (ch === 0 || lum <= 0) { + var hb = hash2(Math.floor(fU * 2.6), Math.floor(fV * 2.6), (fSd ^ 0x7D13) | 0); + + if (hb < 0.14 + 0.50 * dK + 0.22 * dK * dK * dK) { + ch = hb < 0.34 ? G_DASH : (hb < 0.62 ? G_COLON : G_QUOTE); + lum = (26 + hb * 96) * dK; + + fGrain = 1; col = dayMat(dK); lum *= dayG; fGrain = 0; + } + } else if (col === P.shadow) { + lum = lum * (1 + 2.6 * dK) + 62 * dK; + col = dayMat(dK); lum *= dayG; + } else if (col === P.slate) { + + lum = lum * (1 + 3.4 * dK) + 66 * dK; + col = dayMat(dK); lum *= dayG; + } else if (col === P.warm || col === P.amber || col === P.azure || col === P.ice) { + + lum *= 1 - 0.52 * dSun * dSun; + } + } + FOUT.ch = ch; FOUT.col = col; + FOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + return FOUT; + } + + function grain(u, v, sd, lod) { + if (lod < 2) return 1; + var h = hash2(Math.floor(u * 11), Math.floor(v * 11), sd ^ 0x6A11); + return h < 0.12 ? 0.30 : 0.74 + h * 0.52; + } + + function facade(u, v, cell, dist, t) { + if (alt) return alt.facade(u, v, cell, dist, t); + if (v < 0) v = 0; + weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + var sd = seedOf(cell), st = styleOf(cell, sd); + + fU = u; fV = v; fSd = sd; + + fMat = 0; fUp = 0; + fSun = dSky > 0.02 ? sunFace(cell) : 0.5; + + var wu = Math.floor(u / st.pu), wv = Math.floor(v / st.pv); + var fu = u / st.pu - wu, fv = v / st.pv - wv; + + var lj = dist + (hash2(wu, wv, sd ^ 0x9C) - 0.5) * 7; + var lod = lj < 13 ? 2 : (lj < 34 ? 1 : 0); + + var bu = wu, bv = wv; + var glu = lod === 0 ? (wu >> 1) : wu; + + if (v < st.gnd) return ground(u, v, st, sd, cell, lod, t); + + var bh = cell && typeof cell.h === 'number' ? cell.h : 0; + if (bh > 6 && v > bh - 2.35) { + var pu2 = Math.floor(u / 1.9); + if (v > bh - 0.42) { + + fUp = 1; + return fset((u - pu2 * 1.9) < 0.16 ? G_PIPE : G_EQ, P.slate, + 24 + hash2(pu2, 0, sd ^ 0x2A1) * 22); + } + if (v > bh - 1.85) { + var pg = hash2(pu2, Math.floor(v * 2.2), sd ^ 0x2A2); + return pg < 0.32 ? fset(DIMGL[(pg * DIMGL_N * 3.1) | 0], P.shadow, 14 + pg * 34) + : fset(0, P.shadow, 0); + } + return fset(G_UNDER, P.shadow, 30 + hash2(pu2, 3, sd ^ 0x2A3) * 28); } - var dT = 1 / 0, dSky = 0, dLamp = 1, dSun = 0, dWarm = 0; - function dayAt(t) { - if (t === dT) return; - dT = t; - var D = CC.Daylight; - if (!D) return; - dSky = D.P.sky; dLamp = D.P.lamp; dSun = D.P.sun; dWarm = D.P.warm; + var streak = 0; + if (lod > 0 && wRain > 0.15 && + hash2(Math.floor(u * 3.1), 0, sd ^ 0x7C1) < 0.30 * clamp(wRain, 0, 1.3)) streak = 1; + + if (lod > 0 && hash2(sd, 17, 0x3D1) < 0.26 && + (((bu % 3) + 3) % 3) === ((hash2(sd, 18, 0x3D1) * 3) | 0) && fu < 0.085) { + var dg = hash2(0, Math.floor(v * 1.6), sd ^ 0x3D2); + return fset(dg < 0.13 ? G_O : G_PIPE, P.slate, 13 + dg * 20); } - var wT = 1 / 0, wWet = 1, wRain = 1, wWind = 1, wFogP = 0.30; - function weatherAt(t) { - if (t === wT) return; - wT = t; - var W = CC.Weather; - if (!W) return; - wWet = W.rel('wet'); wRain = W.rel('rain'); wWind = W.rel('wind'); - wFogP = W.P.fog; - refog(); + if (hash2(wu >> 1, wv >> 1, sd ^ 0x1F35) < 0.18) { + return fset(0, P.shadow, 0); } - function seedOf(cell) { - if (!cell || typeof cell !== 'object') return 0; - if (cell.seed !== undefined) return cell.seed | 0; - if (cell.id !== undefined) return cell.id | 0; - var x = cell.gx !== undefined ? cell.gx : (cell.x !== undefined ? cell.x : 0); - var z = cell.gz !== undefined ? cell.gz : (cell.z !== undefined ? cell.z : 0); - return (hash2(x, z, 7717) * 2147483647) | 0; - } - function styleOf(cell, sd) { - var s = cell && cell.style; - if (typeof s === 'number') return STYLE[((s | 0) % STYLE.length + STYLE.length) % STYLE.length]; - return STYLE[(hash2(sd, 11, 0x51) * STYLE.length) | 0]; - } - function litOf(cell) { - var r = cell && cell.litRate; - r = typeof r === 'number' ? r : 0.34; - - return clamp(r * (0.22 + 0.78 * dLamp), 0, 1); + if (lod > 0) { + var ge = u / CFG.grid; ge -= Math.floor(ge); + if (ge * CFG.grid < 0.20 || (1 - ge) * CFG.grid < 0.20) { + return fset(G_PIPE, P.slate, 9 + hash2(wu, wv, sd ^ 0x4C) * 13); + } } - function accentOf(cell, sd) { - if (cell && typeof cell.accent === 'number') return cell.accent | 0; - var r = hash2(sd, 5, 0x33A); - return r < 0.46 ? P.ember : (r < 0.86 ? P.spring : P.violet); + if (fv < 0.11 && (wv % st.band) === 0 && hash2(wu, wv, sd ^ 0xB2) < 0.72) { + + fUp = 1; + return fset(G_EQ, P.slate, 12 + hash2(wu, wv, sd ^ 0xB1) * 16); } - function hueOf(cell, sd) { - if (cell && typeof cell.hue === 'number') return cell.hue | 0; - var dr = hash2(0, 0, sd ^ 0x2B1D); - return dr < 0.58 ? P.azure : (dr < 0.90 ? P.amber : P.warm); + var pcol = 0.35 + 1.30 * hash2(bu, 0, sd ^ 0x71); + var prow = 0.45 + 1.10 * hash2(0, bv, sd ^ 0x37); + var lit = hash2(bu, bv, sd) < litOf(cell) * pcol * prow; + var hue = P.slate, base = 0; + + var isAcc = 0, curtain = 0, occupied = 0, ws = 0; + if (lit) { + + if (hash2(bu, bv, sd ^ 0x4D) < 0.62) { + hue = hueOf(cell, sd); + } else { + var hr = hash2(bu >> 1, bv, sd ^ 0x2B1D); + if (hr < 0.30) hue = P.azure; + else if (hr < 0.72) hue = P.amber; + else if (hr < 0.78) hue = P.warm; + + else if (hr < 0.86) hue = P.slate; + else { + + var slot = (hash2(sd, 9, 0x2C7) * 5) | 0; + if ((((bu % 5) + 5) % 5) === slot) { hue = accentOf(cell, sd); isAcc = 1; } + else hue = hash2(bu, 0, sd ^ 0x2C8) < 0.5 ? P.azure : P.amber; + } + } + + base = 172 + hash2(0, bv, sd ^ 0x5) * 56 + hash2(bu, bv, sd ^ 0x9E) * 28; + + base *= 1 - clamp(v / 190, 0, 0.24); + + if (isAcc && base > 148) base = 148; + + if (lod > 0 && !CC.reducedMotion && hash2(bu, bv, sd ^ 0x5BD1) < 0.055) { + var tk = Math.floor(t * 1.9 + hash2(bu, bv, sd ^ 0x5BE2) * 40); + if (hash2(bu ^ tk, bv, sd ^ 0x77) < 0.34) base *= 0.22; + } + + ws = hash2(bu, bv, sd ^ 0x6C21); + if (ws < 0.15) { + curtain = 1; + base *= 0.64; + if (hash2(bu, bv, sd ^ 0x6C22) < 0.30) hue = P.warm; + } else if (ws < 0.22) occupied = 1; } - var FOUT = { ch: 0, col: 0, lum: 0 }; - var fU = 0, fV = 0, fSd = 0; - function fset(ch, col, lum) { - if (dSky > 0.02) { + if (lod === 0) { - var dK = dSky * dSky; - if (ch === 0 || lum <= 0) { - var hb = hash2(Math.floor(fU * 2.6), Math.floor(fV * 2.6), (fSd ^ 0x7D13) | 0); - if (hb < 0.14 + 0.50 * dK) { - ch = hb < 0.34 ? G_DASH : (hb < 0.62 ? G_COLON : G_QUOTE); - col = dK > 0.55 ? P.white : P.slate; - lum = (26 + hb * 96) * dK; - } - } else if (col === P.shadow) { - col = dK > 0.48 ? P.white : P.slate; - lum = lum * (1 + 2.6 * dK) + 62 * dK; - } else if (col === P.warm || col === P.amber || col === P.azure || col === P.ice) { - - lum *= 1 - 0.52 * dSun * dSun; - } - } - FOUT.ch = ch; FOUT.col = col; - FOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - return FOUT; + if (lit) return fset(FILL[(hash2(glu, bv, sd ^ 0x3) * FILL_N) | 0], hue, base * 0.92); + return hash2(wu, wv, sd ^ 0x5) < 0.17 + ? fset(G_COLON, P.shadow, 9 + hash2(wu, wv, sd ^ 0x6) * 6) : fset(0, P.shadow, 0); } - function grain(u, v, sd, lod) { - if (lod < 2) return 1; - var h = hash2(Math.floor(u * 11), Math.floor(v * 11), sd ^ 0x6A11); - return h < 0.12 ? 0.30 : 0.74 + h * 0.52; + var inU = fu > st.mu && fu < 1 - st.mu; + var inV = fv > st.sill && fv < st.head; + + if (!inU || !inV) { + + var onU = fu < st.mu * 0.45 || fu > 1 - st.mu * 0.45; + var onV = fv < st.sill * 0.40 || fv > 1 - (1 - st.head) * 0.40; + var ml = (lod === 2 ? 62 : 48) + hash2(wu, wv + 9973, sd) * 26; + + if (lit) return fset(onV ? G_DASH : G_PIPE, hue, ml + base * 0.16); + + if (lod === 2 && fv < st.sill * 0.86 && fu > 0.26 && fu < 0.74 && + hash2(bu, bv, sd ^ 0x4E1) < 0.10) { + var acg = hash2(Math.floor(u * 4.4), Math.floor(v * 4.4), sd ^ 0x4E3); + return fset(acg < 0.34 ? G_HASH : (acg < 0.72 ? G_EQ : G_PIPE), P.slate, 15 + acg * 26); + } + + if (onU || onV) { + + if (hash2(wu, wv + 5, sd ^ 0xE) < 0.50) return fset(0, P.shadow, 0); + return fset(onV ? DIMGL[(hash2(wu, wv + 31, sd ^ 0xD) * DIMGL_N) | 0] : G_PIPE, + P.shadow, 30 + hash2(wu, wv + 31, sd ^ 0xD) * 50); + } + + if (streak) { + var stg = hash2(Math.floor(u * 3.1), Math.floor(v * 1.5), sd ^ 0x7C2); + if (stg < 0.50) return fset(G_PIPE, P.shadow, 24 + stg * 46); + } + + if (hash2((u * 3.2) | 0, (v * 3.2) | 0, sd ^ 0xE5) < 0.74) return fset(0, P.shadow, 0); + return fset(DIMGL[(hash2((u * 3.2) | 0, (v * 3.2) | 0, sd ^ 0xD3) * DIMGL_N) | 0], + P.shadow, 16 + hash2((u * 3.2) | 0, (v * 3.2) | 0, sd ^ 0xC1) * 26); } - function facade(u, v, cell, dist, t) { - if (alt) return alt.facade(u, v, cell, dist, t); - if (v < 0) v = 0; - weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); - var sd = seedOf(cell), st = styleOf(cell, sd); + if (!lit) { - fU = u; fV = v; fSd = sd; + fMat = 1; - var wu = Math.floor(u / st.pu), wv = Math.floor(v / st.pv); - var fu = u / st.pu - wu, fv = v / st.pv - wv; + if (hash2(wu, wv, sd ^ 0x1C3) < 0.07) { + var dgl = hash2(Math.floor(u * 2.6), Math.floor(v * 2.6), sd ^ 0x1C4); + return dgl < 0.24 ? fset(dgl < 0.12 ? G_SLASH : G_BSLASH, P.shadow, 30 + dgl * 60) + : fset(0, P.shadow, 0); + } - var lj = dist + (hash2(wu, wv, sd ^ 0x9C) - 0.5) * 7; - var lod = lj < 13 ? 2 : (lj < 34 ? 1 : 0); - - var bu = wu, bv = wv; - var glu = lod === 0 ? (wu >> 1) : wu; - - if (v < st.gnd) return ground(u, v, st, sd, cell, lod, t); - - var bh = cell && typeof cell.h === 'number' ? cell.h : 0; - if (bh > 6 && v > bh - 2.35) { - var pu2 = Math.floor(u / 1.9); - if (v > bh - 0.42) - return fset((u - pu2 * 1.9) < 0.16 ? G_PIPE : G_EQ, P.slate, - 24 + hash2(pu2, 0, sd ^ 0x2A1) * 22); - if (v > bh - 1.85) { - var pg = hash2(pu2, Math.floor(v * 2.2), sd ^ 0x2A2); - return pg < 0.32 ? fset(DIMGL[(pg * DIMGL_N * 3.1) | 0], P.shadow, 14 + pg * 34) - : fset(0, P.shadow, 0); - } - return fset(G_UNDER, P.shadow, 30 + hash2(pu2, 3, sd ^ 0x2A3) * 28); - } - - var streak = 0; - if (lod > 0 && wRain > 0.15 && - hash2(Math.floor(u * 3.1), 0, sd ^ 0x7C1) < 0.30 * clamp(wRain, 0, 1.3)) streak = 1; - - if (lod > 0 && hash2(sd, 17, 0x3D1) < 0.26 && - (((bu % 3) + 3) % 3) === ((hash2(sd, 18, 0x3D1) * 3) | 0) && fu < 0.085) { - var dg = hash2(0, Math.floor(v * 1.6), sd ^ 0x3D2); - return fset(dg < 0.13 ? G_O : G_PIPE, P.slate, 13 + dg * 20); - } - - if (hash2(wu >> 1, wv >> 1, sd ^ 0x1F35) < 0.18) { - return fset(0, P.shadow, 0); - } - - if (lod > 0) { - var ge = u / CFG.grid; ge -= Math.floor(ge); - if (ge * CFG.grid < 0.20 || (1 - ge) * CFG.grid < 0.20) { - return fset(G_PIPE, P.slate, 9 + hash2(wu, wv, sd ^ 0x4C) * 13); - } - } - - if (fv < 0.11 && (wv % st.band) === 0 && hash2(wu, wv, sd ^ 0xB2) < 0.72) { - return fset(G_EQ, P.slate, 12 + hash2(wu, wv, sd ^ 0xB1) * 16); - } - - var pcol = 0.35 + 1.30 * hash2(bu, 0, sd ^ 0x71); - var prow = 0.45 + 1.10 * hash2(0, bv, sd ^ 0x37); - var lit = hash2(bu, bv, sd) < litOf(cell) * pcol * prow; - var hue = P.slate, base = 0; - - var isAcc = 0, curtain = 0, occupied = 0, ws = 0; - if (lit) { - - if (hash2(bu, bv, sd ^ 0x4D) < 0.62) { - hue = hueOf(cell, sd); - } else { - var hr = hash2(bu >> 1, bv, sd ^ 0x2B1D); - if (hr < 0.30) hue = P.azure; - else if (hr < 0.72) hue = P.amber; - else if (hr < 0.78) hue = P.warm; - - else if (hr < 0.86) hue = P.slate; - else { - - var slot = (hash2(sd, 9, 0x2C7) * 5) | 0; - if ((((bu % 5) + 5) % 5) === slot) { hue = accentOf(cell, sd); isAcc = 1; } - else hue = hash2(bu, 0, sd ^ 0x2C8) < 0.5 ? P.azure : P.amber; - } - } - - base = 172 + hash2(0, bv, sd ^ 0x5) * 56 + hash2(bu, bv, sd ^ 0x9E) * 28; - - base *= 1 - clamp(v / 190, 0, 0.24); - - if (isAcc && base > 148) base = 148; - - if (lod > 0 && !CC.reducedMotion && hash2(bu, bv, sd ^ 0x5BD1) < 0.055) { - var tk = Math.floor(t * 1.9 + hash2(bu, bv, sd ^ 0x5BE2) * 40); - if (hash2(bu ^ tk, bv, sd ^ 0x77) < 0.34) base *= 0.22; - } - - ws = hash2(bu, bv, sd ^ 0x6C21); - if (ws < 0.15) { - curtain = 1; - base *= 0.64; - if (hash2(bu, bv, sd ^ 0x6C22) < 0.30) hue = P.warm; - } else if (ws < 0.22) occupied = 1; - } - - if (lod === 0) { - - if (lit) return fset(FILL[(hash2(glu, bv, sd ^ 0x3) * FILL_N) | 0], hue, base * 0.92); - return hash2(wu, wv, sd ^ 0x5) < 0.17 - ? fset(G_COLON, P.shadow, 9 + hash2(wu, wv, sd ^ 0x6) * 6) : fset(0, P.shadow, 0); - } - - var inU = fu > st.mu && fu < 1 - st.mu; - var inV = fv > st.sill && fv < st.head; - - if (!inU || !inV) { - - var onU = fu < st.mu * 0.45 || fu > 1 - st.mu * 0.45; - var onV = fv < st.sill * 0.40 || fv > 1 - (1 - st.head) * 0.40; - var ml = (lod === 2 ? 62 : 48) + hash2(wu, wv + 9973, sd) * 26; - - if (lit) return fset(onV ? G_DASH : G_PIPE, hue, ml + base * 0.16); - - if (lod === 2 && fv < st.sill * 0.86 && fu > 0.26 && fu < 0.74 && - hash2(bu, bv, sd ^ 0x4E1) < 0.10) { - var acg = hash2(Math.floor(u * 4.4), Math.floor(v * 4.4), sd ^ 0x4E3); - return fset(acg < 0.34 ? G_HASH : (acg < 0.72 ? G_EQ : G_PIPE), P.slate, 15 + acg * 26); - } - - if (onU || onV) { - - if (hash2(wu, wv + 5, sd ^ 0xE) < 0.50) return fset(0, P.shadow, 0); - return fset(onV ? DIMGL[(hash2(wu, wv + 31, sd ^ 0xD) * DIMGL_N) | 0] : G_PIPE, - P.shadow, 30 + hash2(wu, wv + 31, sd ^ 0xD) * 50); - } - - if (streak) { - var stg = hash2(Math.floor(u * 3.1), Math.floor(v * 1.5), sd ^ 0x7C2); - if (stg < 0.50) return fset(G_PIPE, P.shadow, 24 + stg * 46); - } - - if (hash2((u * 3.2) | 0, (v * 3.2) | 0, sd ^ 0xE5) < 0.74) return fset(0, P.shadow, 0); - return fset(DIMGL[(hash2((u * 3.2) | 0, (v * 3.2) | 0, sd ^ 0xD3) * DIMGL_N) | 0], - P.shadow, 16 + hash2((u * 3.2) | 0, (v * 3.2) | 0, sd ^ 0xC1) * 26); - } - - if (!lit) { - - if (hash2(wu, wv, sd ^ 0x1C3) < 0.07) { - var dgl = hash2(Math.floor(u * 2.6), Math.floor(v * 2.6), sd ^ 0x1C4); - return dgl < 0.24 ? fset(dgl < 0.12 ? G_SLASH : G_BSLASH, P.shadow, 30 + dgl * 60) - : fset(0, P.shadow, 0); - } - - return hash2(wu, wv, sd ^ 0x1B) < 0.38 - ? fset(hash2(wu, wv, sd ^ 0x2C) < 0.5 ? G_COLON : G_QUOTE, - P.shadow, 15 + hash2(wu, wv, sd ^ 0x2C) * 16) - : fset(0, P.shadow, 0); - } - - if (curtain && lod === 2) { - var cfd = u / 0.24; cfd -= Math.floor(cfd); - return fset(cfd < 0.42 ? G_PCT : G_HASH, hue, - base * (0.76 + 0.36 * hash2(Math.floor(u * 4.1), bv, sd ^ 0x6C23))); - } - - if (lod === 2) { - - var gu = (fu - st.mu) / (1 - 2 * st.mu), gv = (fv - st.sill) / (st.head - st.sill); - var pi = (gu * st.panes) | 0, pj = (gv * st.prow) | 0; - var pfu = gu * st.panes - pi, pfv = gv * st.prow - pj; - if (pfu < 0.11 || pfv < 0.13) return fset(pfu < 0.11 ? G_PIPE : G_DASH, hue, base * 0.50); - - if (occupied && pfv > 0.38 && pfu > 0.28 && pfu < 0.70) return fset(0, P.shadow, 0); - var ph = hash2(bu * 7 + pi, bv * 5 + pj, sd ^ 0x77E1); - if (ph < 0.15) return fset(G_COLON, hue, base * 0.20); - base *= (0.80 + ph * 0.38) * grain(u, v, sd, lod); - } - - return fset(FILL[(hash2(glu, bv, sd ^ 0x3) * FILL_N) | 0], hue, base); + return hash2(wu, wv, sd ^ 0x1B) < 0.38 + ? fset(hash2(wu, wv, sd ^ 0x2C) < 0.5 ? G_COLON : G_QUOTE, + P.shadow, 15 + hash2(wu, wv, sd ^ 0x2C) * 16) + : fset(0, P.shadow, 0); } - var SHOP = (function () { - var t = [], i; - function fill(hue, list) { t[hue] = list; } - var A = P.amber, Z = P.azure, W = P.warm; - fill(A, [A,A,A,A,A,A,A,A,A,A, Z,Z,Z,Z, W,W]); - fill(Z, [Z,Z,Z,Z,Z,Z,Z,Z,Z,Z, A,A,A,A, W,W]); - fill(P.ember, [P.ember,P.ember,P.ember,P.ember,P.ember, A,A,A,A,A,A,A, Z,Z, W,W]); - fill(P.spring, [P.spring,P.spring,P.spring,P.spring,P.spring, Z,Z,Z,Z,Z,Z,Z, A,A, W,W]); - var neutral = [A,A,A,A,A,A,A, Z,Z,Z,Z,Z,Z,Z, W,W]; - - for (i = 0; i < 16; i++) if (!t[i]) t[i] = neutral; - return t; - })(); - - var L_LOW = [103, 52, 135, 133, 154, 165, 71, 255, 124, 110, 47, 255]; - var L_LIT = [157, 79, 206, 206, 239, 254, 109, 255, 190, 169, 72, 255]; - var L_HOT = [240, 120, 255, 255, 255, 255, 165, 255, 255, 255, 109, 255]; - - var T_NOODLE = 0, T_CONV = 1, T_LAUNDRY = 2, T_BAR = 3, - T_ARCADE = 4, T_HARD = 5, T_PHARM = 6, T_BARBER = 7; - - function typeOf(su, sd) { - var r = hash2(su, 29, sd ^ 0x9F51); - if (r < 0.21) return T_NOODLE; - if (r < 0.34) return T_CONV; - if (r < 0.46) return T_LAUNDRY; - if (r < 0.58) return T_BAR; - if (r < 0.68) return T_ARCADE; - if (r < 0.79) return T_HARD; - if (r < 0.90) return T_PHARM; - return T_BARBER; + if (curtain && lod === 2) { + var cfd = u / 0.24; cfd -= Math.floor(cfd); + return fset(cfd < 0.42 ? G_PCT : G_HASH, hue, + base * (0.76 + 0.36 * hash2(Math.floor(u * 4.1), bv, sd ^ 0x6C23))); } - var T_LEAN = [1, -1, -1, 1, -1, 0, -1, 0]; - function lean(ty, lite, su, sd, sel) { - var b = T_LEAN[ty]; - if (b === 0) return lite; - var pil = b < 0 ? P.azure : P.amber; - if (lite === pil) return lite; + if (lod === 2) { - var q = hash2(su, sel, sd ^ 0x9F63); - if (lite === P.warm) return q < 0.30 ? pil : lite; - if (lite === P.amber || lite === P.azure) return q < 0.20 ? pil : lite; - return lite; + var gu = (fu - st.mu) / (1 - 2 * st.mu), gv = (fv - st.sill) / (st.head - st.sill); + var pi = (gu * st.panes) | 0, pj = (gv * st.prow) | 0; + var pfu = gu * st.panes - pi, pfv = gv * st.prow - pj; + if (pfu < 0.11 || pfv < 0.13) return fset(pfu < 0.11 ? G_PIPE : G_DASH, hue, base * 0.50); + + if (occupied && pfv > 0.38 && pfu > 0.28 && pfu < 0.70) return fset(0, P.shadow, 0); + var ph = hash2(bu * 7 + pi, bv * 5 + pj, sd ^ 0x77E1); + if (ph < 0.15) return fset(G_COLON, hue, base * 0.20); + base *= (0.80 + ph * 0.38) * grain(u, v, sd, lod); } - var T_AWN = [1, 0, 1, 1, 0, 1, 0, 0]; + return fset(FILL[(hash2(glu, bv, sd ^ 0x3) * FILL_N) | 0], hue, base); + } - var SIGN_FILL = [0.92, 0.98, 0.80, 0.56, 0.86, 0.92, 0.72, 0.68]; - var SIGN_PITCH = [0.30, 1.70, 0.64, 0.44, 0.34, 0.92, 0.52, 0.40]; + var SHOP = (function () { + var t = [], i; + function fill(hue, list) { t[hue] = list; } + var A = P.amber, Z = P.azure, W = P.warm; + fill(A, [A,A,A,A,A,A,A,A,A,A, Z,Z,Z,Z, W,W]); + fill(Z, [Z,Z,Z,Z,Z,Z,Z,Z,Z,Z, A,A,A,A, W,W]); + fill(P.ember, [P.ember,P.ember,P.ember,P.ember,P.ember, A,A,A,A,A,A,A, Z,Z, W,W]); + fill(P.spring, [P.spring,P.spring,P.spring,P.spring,P.spring, Z,Z,Z,Z,Z,Z,Z, A,A, W,W]); + var neutral = [A,A,A,A,A,A,A, Z,Z,Z,Z,Z,Z,Z, W,W]; + fill(P.stone, neutral); + fill(P.jade, [Z,Z,Z,Z,Z,Z,Z,Z,Z,Z, A,A,A,A, W,W]); + fill(P.moss, [A,A,A,A,A,A,A,A,A,A, Z,Z,Z,Z, W,W]); + fill(P.indigo, [Z,Z,Z,Z,Z,Z,Z,Z,Z,Z, A,A,A,A, W,W]); + for (i = 0; i < CC.PALETTE.length; i++) if (!t[i]) t[i] = neutral; + return t; + })(); - function storeIn(ty, u, v, su, sd, lite, lite2, gTop) { - var xm = u - su * 2.55; - var h, a, b, i, j; - switch (ty) { + function shopRoll(cell, sd) { + var h = hueOf(cell, sd); + return SHOP[h >= 0 && h < SHOP.length ? h : 0] || SHOP[0]; + } - case T_NOODLE: + var L_LOW = [103, 52, 135, 133, 154, 165, 71, 255, 124, 110, 47, 255, + 255, 255, 206, 215, 238, 146, 255, 255]; + var L_LIT = [157, 79, 206, 206, 239, 254, 109, 255, 190, 169, 72, 255, + 255, 255, 255, 255, 255, 222, 255, 255]; + var L_HOT = [240, 120, 255, 255, 255, 255, 165, 255, 255, 255, 109, 255, + 255, 255, 255, 255, 255, 255, 255, 255]; - if (v > 0.99 && v < 1.31) { - h = hash2((u * 3) | 0, 0, sd ^ 0x9F71); - return fset(h < 0.5 ? G_EQ : G_8, lite, - (v > 1.19 ? L_HOT[lite] : L_LIT[lite]) * (0.90 + h * 0.18)); - } - if (v > 0.80 && v < 0.99) { - h = xm / 0.62; h -= Math.floor(h); - return h < 0.34 ? fset(G_oo, lite, L_LOW[lite]) : fset(0, P.shadow, 0); - } + var T_NOODLE = 0, T_CONV = 1, T_LAUNDRY = 2, T_BAR = 3, + T_ARCADE = 4, T_HARD = 5, T_PHARM = 6, T_BARBER = 7; - if (v > 0.66 && v < 0.80) { - h = hash2((u * 2.2) | 0, 0, sd ^ 0x9F79); - return h < 0.74 ? fset(G_UNDER, lite, L_LOW[lite]) : fset(0, P.shadow, 0); - } - if (v < 0.99) return fset(0, P.shadow, 0); - if (v > 1.58 && v < 2.24) { - h = hash2((u / 0.42) | 0, 0, sd ^ 0x9F83); - if (h < 0.72) { - a = h < 0.20 ? lite2 : lite; - return fset(FILL[(h * 1.7 * FILL_N) | 0], a, L_LIT[a] * (0.88 + h * 0.20)); - } - return fset(0, P.shadow, 0); - } + function typeOf(su, sd) { + var r = hash2(su, 29, sd ^ 0x9F51); + if (r < 0.21) return T_NOODLE; + if (r < 0.34) return T_CONV; + if (r < 0.46) return T_LAUNDRY; + if (r < 0.58) return T_BAR; + if (r < 0.68) return T_ARCADE; + if (r < 0.79) return T_HARD; + if (r < 0.90) return T_PHARM; + return T_BARBER; + } - if (v > 2.26 && v < 2.46) { - h = xm / 1.27; h -= Math.floor(h); - if (h > 0.36 && h < 0.60) return fset(G_0, P.warm, L_HOT[P.warm]); - } - return fset(0, P.shadow, 0); + var T_LEAN = [1, -1, -1, 1, -1, 0, -1, 0]; + function lean(ty, lite, su, sd, sel) { + var b = T_LEAN[ty]; + if (b === 0) return lite; + var pil = b < 0 ? P.azure : P.amber; + if (lite === pil) return lite; - case T_CONV: + var q = hash2(su, sel, sd ^ 0x9F63); + if (lite === P.warm) return q < 0.30 ? pil : lite; + if (lite === P.amber || lite === P.azure) return q < 0.20 ? pil : lite; + return lite; + } - if (xm > 1.62 && xm < 2.18) { - if (xm < 1.72 || xm > 2.08) return fset(G_PIPE, lite, L_HOT[lite]); - if (v > gTop - 0.30) return fset(G_DASH, lite, L_HOT[lite]); - return fset(0, P.shadow, 0); - } - h = v / 0.58; h -= Math.floor(h); - if (h < 0.24) return fset(G_EQ, lite, L_HOT[lite]); - h = hash2((u * 1.6) | 0, (v * 1.7) | 0, sd ^ 0x9F91); - a = h < 0.22 ? lite2 : lite; + var T_AWN = [1, 0, 1, 1, 0, 1, 0, 0]; - return fset(FILL[(h * FILL_N) | 0], a, L_HOT[a] * (0.90 + h * 0.14)); + var SIGN_FILL = [0.92, 0.98, 0.80, 0.56, 0.86, 0.92, 0.72, 0.68]; + var SIGN_PITCH = [0.30, 1.70, 0.64, 0.44, 0.34, 0.92, 0.52, 0.40]; - case T_LAUNDRY: + function storeIn(ty, u, v, su, sd, lite, lite2, gTop) { + var xm = u - su * 2.55; + var h, a, b, i, j; + switch (ty) { - if (v > 0.72 && v < 1.98) { - b = (v - 0.72) / 0.63; j = b | 0; b -= j; - a = xm / 0.52; i = su * 5 + (a | 0); a -= a | 0; - a -= 0.5; b -= 0.5; - h = (a * a + b * b) * 4; - if (h < 0.52) { - a = hash2(i, j, sd ^ 0x9FA3) < 0.24 ? lite2 : lite; - return fset(h < 0.22 ? G_0 : G_O, a, h < 0.22 ? L_HOT[a] : L_LIT[a]); - } - if (h < 0.78) return fset(G_oo, lite, L_LOW[lite]); - return fset(0, P.shadow, 0); - } - if (v > 2.08 && v < 2.30) return fset(G_DASH, lite, L_LIT[lite]); - return fset(0, P.shadow, 0); + case T_NOODLE: - case T_BAR: + if (v > 0.99 && v < 1.31) { + h = hash2((u * 3) | 0, 0, sd ^ 0x9F71); + return fset(h < 0.5 ? G_EQ : G_8, lite, + (v > 1.19 ? L_HOT[lite] : L_LIT[lite]) * (0.90 + h * 0.18)); + } + if (v > 0.80 && v < 0.99) { + h = xm / 0.62; h -= Math.floor(h); + return h < 0.34 ? fset(G_oo, lite, L_LOW[lite]) : fset(0, P.shadow, 0); + } - if (v > 1.52 && v < 1.74) { - i = su * 17 + ((xm / 0.15) | 0); - h = hash2(i, 0, sd ^ 0x9FB1); - if (h < 0.62) { - a = h < 0.18 ? lite2 : lite; - return fset(h < 0.30 ? G_8 : G_PIPE, a, L_LIT[a] * (0.84 + h * 0.30)); - } - return fset(0, P.shadow, 0); - } - if (v > 1.06 && v < 1.20) return fset(G_DASH, lite, L_LOW[lite]); - return fset(0, P.shadow, 0); - - case T_ARCADE: - - a = xm / 0.62; i = su * 5 + (a | 0); a -= a | 0; - b = v / 0.52; j = b | 0; b -= j; - if (a > 0.07 && b > 0.10) { - h = hash2(i, j, sd ^ 0x9FD1); - if (h > 0.90) return fset(0, P.shadow, 0); - a = h < 0.09 ? P.violet : (h < 0.30 ? lite2 : lite); - - b = hash2(i, j, sd ^ 0xA0E3); - return fset(FILL[(b * FILL_N) | 0], a, - (b < 0.34 ? L_HOT[a] : L_LIT[a]) * (0.88 + b * 0.22)); - } - return fset(0, P.shadow, 0); - - case T_HARD: - - if (v > 2.14 && v < 2.30) return fset(G_DASH, lite, L_LIT[lite]); - if (v > 1.30 && v < 2.14) { - h = xm / 0.26; i = su * 10 + (h | 0); h -= h | 0; - b = hash2(i, 0, sd ^ 0x9FE1); - if (h < 0.58 && v > 1.84 - b * 0.54) { - a = b < 0.20 ? lite2 : lite; - return fset(b < 0.34 ? G_PIPE : G_V, a, L_LIT[a] * 0.94); - } - return fset(0, P.shadow, 0); - } - if (v < 1.24) { - h = hash2((u / 0.44) | 0, (v / 0.31) | 0, sd ^ 0x9FE3); - return h < 0.55 ? fset(G_HASH, lite, L_LOW[lite]) : fset(0, P.shadow, 0); - } - return fset(0, P.shadow, 0); - - case T_PHARM: - - a = xm - 1.27; if (a < 0) a = -a; - b = v - (gTop - 0.90); if (b < 0) b = -b; - if ((a < 0.15 && b < 0.52) || (b < 0.15 && a < 0.52)) - return fset(a < 0.15 && b < 0.15 ? G_8 : G_HASH, P.white, L_LIT[P.white]); - - if (a < 0.72 && b < 0.72) return fset(0, P.shadow, 0); - if (v > 0.70 && v < gTop - 0.20) { - - h = hash2((u / 0.45) | 0, (v / 0.45) | 0, sd ^ 0x9FC1); - if (h < 0.46) return fset(FILL[(h * 2.1 * FILL_N) | 0], lite, L_LIT[lite] * (0.94 + h * 0.16)); - return fset(0, P.shadow, 0); - } - return fset(0, P.shadow, 0); - - default: - - if (xm > 0.16 && xm < 0.38 && v > 1.10 && v < 2.05) { - h = v * 2.9 + xm * 2.2; h -= Math.floor(h); - - return h < 0.5 ? fset(G_8, P.white, L_LIT[P.white]) : fset(G_8, P.red, L_LOW[P.red]); - } - if (v > 0.86 && v < gTop - 0.24) { - a = (xm > 0.58 && xm < 1.14) || (xm > 1.48 && xm < 2.04) ? 1 : 0; - if (a) { - h = hash2((v / 0.28) | 0, su, sd ^ 0x9FF1); - if (h < 0.76) return fset(h < 0.28 ? G_8 : G_EQ, lite, L_LIT[lite] * (0.90 + h * 0.18)); - } - return fset(0, P.shadow, 0); - } - return fset(0, P.shadow, 0); + if (v > 0.66 && v < 0.80) { + h = hash2((u * 2.2) | 0, 0, sd ^ 0x9F79); + return h < 0.74 ? fset(G_UNDER, lite, L_LOW[lite]) : fset(0, P.shadow, 0); + } + if (v < 0.99) return fset(0, P.shadow, 0); + if (v > 1.58 && v < 2.24) { + h = hash2((u / 0.42) | 0, 0, sd ^ 0x9F83); + if (h < 0.72) { + a = h < 0.20 ? lite2 : lite; + return fset(FILL[(h * 1.7 * FILL_N) | 0], a, L_LIT[a] * (0.88 + h * 0.20)); } + return fset(0, P.shadow, 0); + } + + if (v > 2.26 && v < 2.46) { + h = xm / 1.27; h -= Math.floor(h); + if (h > 0.36 && h < 0.60) return fset(G_0, P.warm, L_HOT[P.warm]); + } + return fset(0, P.shadow, 0); + + case T_CONV: + + if (xm > 1.62 && xm < 2.18) { + if (xm < 1.72 || xm > 2.08) return fset(G_PIPE, lite, L_HOT[lite]); + if (v > gTop - 0.30) return fset(G_DASH, lite, L_HOT[lite]); + return fset(0, P.shadow, 0); + } + h = v / 0.58; h -= Math.floor(h); + if (h < 0.24) return fset(G_EQ, lite, L_HOT[lite]); + h = hash2((u * 1.6) | 0, (v * 1.7) | 0, sd ^ 0x9F91); + a = h < 0.22 ? lite2 : lite; + + return fset(FILL[(h * FILL_N) | 0], a, L_HOT[a] * (0.90 + h * 0.14)); + + case T_LAUNDRY: + + if (v > 0.72 && v < 1.98) { + b = (v - 0.72) / 0.63; j = b | 0; b -= j; + a = xm / 0.52; i = su * 5 + (a | 0); a -= a | 0; + a -= 0.5; b -= 0.5; + h = (a * a + b * b) * 4; + if (h < 0.52) { + a = hash2(i, j, sd ^ 0x9FA3) < 0.24 ? lite2 : lite; + return fset(h < 0.22 ? G_0 : G_O, a, h < 0.22 ? L_HOT[a] : L_LIT[a]); + } + if (h < 0.78) return fset(G_oo, lite, L_LOW[lite]); + return fset(0, P.shadow, 0); + } + if (v > 2.08 && v < 2.30) return fset(G_DASH, lite, L_LIT[lite]); + return fset(0, P.shadow, 0); + + case T_BAR: + + if (v > 1.52 && v < 1.74) { + i = su * 17 + ((xm / 0.15) | 0); + h = hash2(i, 0, sd ^ 0x9FB1); + if (h < 0.62) { + a = h < 0.18 ? lite2 : lite; + return fset(h < 0.30 ? G_8 : G_PIPE, a, L_LIT[a] * (0.84 + h * 0.30)); + } + return fset(0, P.shadow, 0); + } + if (v > 1.06 && v < 1.20) return fset(G_DASH, lite, L_LOW[lite]); + + if (v > 1.86 && v < 2.00 && hash2(su, 71, sd ^ 0x9FB7) < 0.25) { + h = hash2((u * 5.4) | 0, 0, sd ^ 0x9FB9); + return fset(h < 0.34 ? G_UNDER : (h < 0.72 ? G_DASH : G_TILDE), P.rose, + L_LOW[P.rose] * (0.94 + h * 0.10)); + } + return fset(0, P.shadow, 0); + + case T_ARCADE: + + a = xm / 0.62; i = su * 5 + (a | 0); a -= a | 0; + b = v / 0.52; j = b | 0; b -= j; + if (a > 0.07 && b > 0.10) { + h = hash2(i, j, sd ^ 0x9FD1); + if (h > 0.90) return fset(0, P.shadow, 0); + a = h < 0.09 ? P.violet : (h < 0.30 ? lite2 : lite); + + b = hash2(i, j, sd ^ 0xA0E3); + return fset(FILL[(b * FILL_N) | 0], a, + (b < 0.34 ? L_HOT[a] : L_LIT[a]) * (0.88 + b * 0.22)); + } + return fset(0, P.shadow, 0); + + case T_HARD: + + if (v > 2.14 && v < 2.30) return fset(G_DASH, lite, L_LIT[lite]); + if (v > 1.30 && v < 2.14) { + h = xm / 0.26; i = su * 10 + (h | 0); h -= h | 0; + b = hash2(i, 0, sd ^ 0x9FE1); + if (h < 0.58 && v > 1.84 - b * 0.54) { + a = b < 0.20 ? lite2 : lite; + return fset(b < 0.34 ? G_PIPE : G_V, a, L_LIT[a] * 0.94); + } + return fset(0, P.shadow, 0); + } + if (v < 1.24) { + h = hash2((u / 0.44) | 0, (v / 0.31) | 0, sd ^ 0x9FE3); + return h < 0.55 ? fset(G_HASH, lite, L_LOW[lite]) : fset(0, P.shadow, 0); + } + return fset(0, P.shadow, 0); + + case T_PHARM: + + a = xm - 1.27; if (a < 0) a = -a; + b = v - (gTop - 0.90); if (b < 0) b = -b; + if ((a < 0.15 && b < 0.52) || (b < 0.15 && a < 0.52)) { + + var pxc = hash2(su, 83, sd ^ 0x9FC7) < 0.50 ? P.jade : P.white; + return fset(a < 0.15 && b < 0.15 ? G_8 : G_HASH, pxc, L_LIT[pxc]); + } + + if (a < 0.72 && b < 0.72) return fset(0, P.shadow, 0); + if (v > 0.70 && v < gTop - 0.20) { + + h = hash2((u / 0.45) | 0, (v / 0.45) | 0, sd ^ 0x9FC1); + if (h < 0.46) return fset(FILL[(h * 2.1 * FILL_N) | 0], lite, L_LIT[lite] * (0.94 + h * 0.16)); + return fset(0, P.shadow, 0); + } + return fset(0, P.shadow, 0); + + default: + + if (xm > 0.16 && xm < 0.38 && v > 1.10 && v < 2.05) { + h = v * 2.9 + xm * 2.2; h -= Math.floor(h); + + return h < 0.5 ? fset(G_8, P.white, L_LIT[P.white]) : fset(G_8, P.red, L_LOW[P.red]); + } + if (v > 0.86 && v < gTop - 0.24) { + a = (xm > 0.58 && xm < 1.14) || (xm > 1.48 && xm < 2.04) ? 1 : 0; + if (a) { + h = hash2((v / 0.28) | 0, su, sd ^ 0x9FF1); + if (h < 0.76) return fset(h < 0.28 ? G_8 : G_EQ, lite, L_LIT[lite] * (0.90 + h * 0.18)); + } + return fset(0, P.shadow, 0); + } + return fset(0, P.shadow, 0); + } + } + + function ground(u, v, st, sd, cell, lod, t) { + var su = Math.floor(u / 2.55), fs = u / 2.55 - Math.floor(u / 2.55); + var r = hash2(su, 0, sd ^ 0x7E31); + + var open = r < SHOP_OPEN; + + var cr = hash2(su, 3, sd ^ 0x1D7); + var roll = shopRoll(cell, sd); + var lite = roll[(cr * 16) | 0]; + + var lite2 = roll[(hash2(su, 11, sd ^ 0x1D8) * 16) | 0]; + + var ty = typeOf(su, sd); + if (open) { lite = lean(ty, lite, su, sd, 31); lite2 = lean(ty, lite2, su, sd, 37); } + + if (v > st.gnd - 0.42) { + return open ? fset(G_EQ, lite, 58) : fset(0, P.shadow, 0); } - function ground(u, v, st, sd, cell, lod, t) { - var su = Math.floor(u / 2.55), fs = u / 2.55 - Math.floor(u / 2.55); - var r = hash2(su, 0, sd ^ 0x7E31); + if (fs < 0.06 || fs > 0.94) return fset(0, P.shadow, 0); + if (open) { - var open = r < SHOP_OPEN; + if (T_AWN[ty] && hash2(su, 21, sd ^ 0x8A1) < 0.46 && + v > st.gnd - 2.55 && v < st.gnd - 1.62) { + var aw = (st.gnd - 1.62 - v) / 0.93; + if (aw > 0.86) { - var cr = hash2(su, 3, sd ^ 0x1D7); - var roll = SHOP[hueOf(cell, sd) & 15]; - var lite = roll[(cr * 16) | 0]; - - var lite2 = roll[(hash2(su, 11, sd ^ 0x1D8) * 16) | 0]; - - var ty = typeOf(su, sd); - if (open) { lite = lean(ty, lite, su, sd, 31); lite2 = lean(ty, lite2, su, sd, 37); } - - if (v > st.gnd - 0.42) { - return open ? fset(G_EQ, lite, 58) : fset(0, P.shadow, 0); + var vg = u / 0.42; vg -= Math.floor(vg); + return fset(vg < 0.5 ? G_V : G_UNDER, lite, + L_LOW[lite] * (1.00 + hash2(su, (u * 2.4) | 0, sd ^ 0x8A2) * 0.20)); } - if (fs < 0.06 || fs > 0.94) return fset(0, P.shadow, 0); - if (open) { + var ag = u / 0.42; ag -= Math.floor(ag); + if (ag < 0.30) return fset(G_SLASH, lite, L_LOW[lite] * (1.18 - aw * 0.20)); + return fset(0, P.shadow, 0); + } - if (T_AWN[ty] && hash2(su, 21, sd ^ 0x8A1) < 0.46 && - v > st.gnd - 2.55 && v < st.gnd - 1.62) { - var aw = (st.gnd - 1.62 - v) / 0.93; - if (aw > 0.86) { + if (v > st.gnd - 1.55) { - var vg = u / 0.42; vg -= Math.floor(vg); - return fset(vg < 0.5 ? G_V : G_UNDER, lite, - L_LOW[lite] * (1.00 + hash2(su, (u * 2.4) | 0, sd ^ 0x8A2) * 0.20)); - } - - var ag = u / 0.42; ag -= Math.floor(ag); - if (ag < 0.30) return fset(G_SLASH, lite, L_LOW[lite] * (1.18 - aw * 0.20)); - return fset(0, P.shadow, 0); - } - - if (v > st.gnd - 1.55) { - var sp = u / SIGN_PITCH[ty]; - var sg = hash2(sp | 0, su, sd ^ 0x515); - if (sg > SIGN_FILL[ty]) return fset(0, P.shadow, 0); - - var sc = ty === T_ARCADE && sg < 0.20 ? P.violet - : (ty === T_PHARM && sg < 0.05 ? P.white - : (hash2(su, 47, sd ^ 0x517) < 0.10 ? accentOf(cell, sd) : lite)); - - return fset(FILL[((sg / SIGN_FILL[ty]) * FILL_N) | 0], sc, L_HOT[sc] * (1.00 + sg * 0.14)); - } - if (v < 0.62) - return hash2(su, Math.floor(v * 6), sd ^ 0x3) < 0.5 ? fset(G_UNDER, P.shadow, 14) - : fset(0, P.shadow, 0); - - var fm = u / 0.85; fm -= Math.floor(fm); - if (fm < 0.10) return fset(0, P.shadow, 0); - - if (lod > 0) return storeIn(ty, u, v, su, sd, lite, lite2, st.gnd - 1.55); - - var fcov = 0.30 + SIGN_FILL[ty] * 0.38; - var fh = hash2(Math.floor(u * 1.1), Math.floor(v * 1.1), sd ^ 0x6C1); - if (fh > fcov) return fset(0, P.shadow, 0); - var fcol = hash2(Math.floor(u * 0.8), Math.floor(v * 1.3), sd ^ 0x6C3) < 0.30 ? lite2 : lite; - return fset(FILL[((fh / fcov) * FILL_N) | 0], fcol, L_LIT[fcol] * (0.90 + fh * 0.20)); + if (hash2(su, 91, sd ^ 0x519) < 0.62) { + if (v < st.gnd - 1.44) + return fset(G_UNDER, P.gold, + L_LOW[P.gold] * (0.94 + hash2((u * 3.6) | 0, 1, sd ^ 0x51A) * 0.14)); + if (fs < 0.085 || fs > 0.915) + return fset(G_PIPE, P.gold, + L_LOW[P.gold] * (0.90 + hash2(su, (v * 4.2) | 0, sd ^ 0x51B) * 0.16)); } + var sp = u / SIGN_PITCH[ty]; + var sg = hash2(sp | 0, su, sd ^ 0x515); + if (sg > SIGN_FILL[ty]) return fset(0, P.shadow, 0); - var sh1 = hash2(su, 41, sd ^ 0xA31), sh2 = hash2(su, 53, sd ^ 0xA32), - sh3 = hash2(su, 67, sd ^ 0xA33), sh4 = hash2(su, 79, sd ^ 0xA35); + var sc = ty === T_ARCADE && sg < 0.20 ? P.violet + : (ty === T_PHARM && sg < 0.05 ? P.white + : (hash2(su, 47, sd ^ 0x517) < 0.10 ? accentOf(cell, sd) : lite)); - if (v > st.gnd - 0.72) return fset(G_DASH, roll[(sh4 * 16) | 0], 90 + sh1 * 44); + return fset(FILL[((sg / SIGN_FILL[ty]) * FILL_N) | 0], sc, L_HOT[sc] * (1.00 + sg * 0.14)); + } + if (v < 0.62) { - if (sh2 < 0.11 && v < 0.34) - return fset(v < 0.17 ? G_UNDER : G_EQ, lite, 128 + sh3 * 58); - - if (sh2 > 0.68 && sh2 < 0.79) { - var dl = v - 2.28, du = fs - 0.80; - if (du < 0) du = -du; - if (du < 0.075 && dl > -0.16 && dl < 0.16) return fset(G_0, P.warm, 156 + sh3 * 40); + if (v > 0.30 && v < 0.48 && hash2(su, 59, sd ^ 0x3B7) < 0.34) { + var tl = u / 0.21; tl -= Math.floor(tl); + return fset(tl < 0.30 ? G_PIPE : G_EQ, P.jade, + L_LOW[P.jade] * (0.86 + hash2((u * 4.8) | 0, 0, sd ^ 0x3B8) * 0.20)); } + return hash2(su, Math.floor(v * 6), sd ^ 0x3) < 0.5 ? fset(G_UNDER, P.shadow, 14) + : fset(0, P.shadow, 0); + } - if (sh1 < 0.34 && v > 1.05 && v < 2.15) { - var tgu = (u - su * 2.55 - 0.28) / 1.75; - if (tgu > 0 && tgu < 1) { - var tg = hash2(Math.floor(tgu * 9), Math.floor((v - 1.05) * 6.4), sd ^ 0xA34); - if (tg < 0.46) { + var fm = u / 0.85; fm -= Math.floor(fm); + if (fm < 0.10) return fset(0, P.shadow, 0); - return fset(tg < 0.16 ? G_HASH : (tg < 0.31 ? G_PCT : G_SLASH), - accentOf(cell, sd), 116 + tg * 116); - } - } - } + if (lod > 0) return storeIn(ty, u, v, su, sd, lite, lite2, st.gnd - 1.55); - var rib = Math.floor(v * 3.4); - return (rib % 3) ? fset(0, P.shadow, 0) - : fset(G_UNDER, P.shadow, 11 + hash2(su, rib, sd ^ 0xA9) * 8); + var fcov = 0.30 + SIGN_FILL[ty] * 0.38; + var fh = hash2(Math.floor(u * 1.1), Math.floor(v * 1.1), sd ^ 0x6C1); + if (fh > fcov) return fset(0, P.shadow, 0); + var fcol = hash2(Math.floor(u * 0.8), Math.floor(v * 1.3), sd ^ 0x6C3) < 0.30 ? lite2 : lite; + return fset(FILL[((fh / fcov) * FILL_N) | 0], fcol, L_LIT[fcol] * (0.90 + fh * 0.20)); } - var ROUT = { ch: 0, col: 0, lum: 0, mir: 0, rip: 0, wch: 0 }; + var sh1 = hash2(su, 41, sd ^ 0xA31), sh2 = hash2(su, 53, sd ^ 0xA32), + sh3 = hash2(su, 67, sd ^ 0xA33), sh4 = hash2(su, 79, sd ^ 0xA35); - var mirNow = 0, ripNow = 0, wchNow = 0, bounceNow = 0; - function rset(ch, col, lum) { - ROUT.ch = ch; ROUT.col = col; - ROUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - ROUT.mir = mirNow > bounceNow ? mirNow : bounceNow; - ROUT.rip = ripNow; ROUT.wch = wchNow; - return ROUT; + if (v > st.gnd - 0.72) return fset(G_DASH, roll[(sh4 * 16) | 0], 90 + sh1 * 44); + + if (sh2 < 0.11 && v < 0.34) + return fset(v < 0.17 ? G_UNDER : G_EQ, lite, 128 + sh3 * 58); + + if (sh2 > 0.68 && sh2 < 0.79) { + var dl = v - 2.28, du = fs - 0.80; + if (du < 0) du = -du; + if (du < 0.075 && dl > -0.16 && dl < 0.16) return fset(G_0, P.warm, 156 + sh3 * 40); } - var WATER = [G_COLON, G_QUOTE, G_TILDE, G_SEMI, G_DQ, G_DASH, G_COMMA, G_TICK]; - var WATER_N = WATER.length; + if (sh1 < 0.34 && v > 1.05 && v < 2.15) { + var tgu = (u - su * 2.55 - 0.28) / 1.75; + if (tgu > 0 && tgu < 1) { + var tg = hash2(Math.floor(tgu * 9), Math.floor((v - 1.05) * 6.4), sd ^ 0xA34); + if (tg < 0.46) { - function floorTex(wx, wz, dist, t) { - if (alt) return alt.floorTex(wx, wz, dist, t); - weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); - var lane = wx - CFG.streetX; - if (CFG.streetPeriod > 0) lane -= Math.round(lane / CFG.streetPeriod) * CFG.streetPeriod; - var al = lane < 0 ? -lane : lane; - var half = CFG.half; - - var fl = dist < 22 ? 2 : (dist < 50 ? 1 : 0); - - var sheet = vnoise(wx * 0.11 + 3.1, 91) * 0.72 + vnoise(wz * 0.05, 57) * 0.62 - - 0.42 + (wWet - 1) * 0.34; - sheet = clamp(sheet, 0, 1) * clamp(wWet, 0, 1.15); - - var pi = Math.floor(lane / 2.4), pj = Math.floor(wz / 5.6); - var pd = 0; - - if (fl > 0 && hash2(pi, pj, 0x9D1) < 0.26 + 0.40 * clamp(wWet, 0, 1.2)) { - var pra = (0.30 + hash2(pi, pj, 0x9D4) * 0.60) * clamp(0.42 + wWet * 0.64, 0.22, 1.25); - if (pra > 1.05) pra = 1.05; - var prz = pra * (1.5 + hash2(pi, pj, 0x9D5) * 1.4); - if (prz > 2.55) prz = 2.55; - var pcx = pi * 2.4 + pra + (2.4 - 2 * pra) * hash2(pi, pj, 0x9D2); - var pcz = pj * 5.6 + prz + (5.6 - 2 * prz) * hash2(pi, pj, 0x9D3); - var dl = (lane - pcx) / pra, dpz = (wz - pcz) / prz; - var rr2 = dl * dl + dpz * dpz; - - if (rr2 < 1) pd = 1 - rr2 * rr2; + return fset(tg < 0.16 ? G_HASH : (tg < 0.31 ? G_PCT : G_SLASH), + accentOf(cell, sd), 116 + tg * 116); } - - var rc = half * 0.55, rut = al - rc; if (rut < 0) rut = -rut; - rut = 1 - clamp(rut / 0.62, 0, 1); - - var lampK = 0; - if (fl > 0) { - var lj = Math.floor(wz / 13.5); - var lcl = (hash2(lj, 0, 0x1A3) < 0.5 ? 1 : -1) * (half - 0.55); - var lcz = lj * 13.5 + 3.4 + hash2(lj, 1, 0x1A3) * 6.6; - var dll = (lane - lcl) / 3.0, dlpz = (wz - lcz) / 4.1; - lampK = 1 - (dll * dll + dlpz * dlpz); - if (lampK < 0) lampK = 0; else lampK *= lampK; - lampK *= dLamp; - } - - mirNow = clamp(pd * 0.95 + sheet * (0.40 + rut * 0.26), 0, 1); - - bounceNow = 0.13; - - ripNow = 0; - if (mirNow > 0.20) { - ripNow = (hash2(Math.floor(wx * 2.7), Math.floor(wz * 1.9), 0x2E2) - 0.5) - * (1.2 + 1.8 * clamp(wWind, 0, 1.4)); - if (!CC.reducedMotion && wRain > 0.05) - ripNow += (vnoise(wz * 0.85 + t * 1.7, 0x2E3) - 0.5) * 2.4 * clamp(wRain, 0, 1.2); - } - wchNow = WATER[(hash2(Math.floor(wx * 2.3), Math.floor(wz * 1.1), 0x2E1) * WATER_N) | 0]; - - var xd = 1e9, xh = 0, xcv = 0, i, ad2; - if (CFG.xn > 0) { - - var xg = Math.round((wz - CFG.xz0) / CFG.xpitch); - var xlo = xg - 1, xhi = xg + 1; - if (xlo < 0) xlo = 0; - if (xhi > CFG.xn - 1) xhi = CFG.xn - 1; - for (i = xlo; i <= xhi; i++) { - ad2 = wz - CFG.xc[i]; if (ad2 < 0) ad2 = -ad2; - if (ad2 < xd) { xd = ad2; xh = CFG.xw[i]; xcv = CFG.xc[i]; } - } - } - var inX = xd < xh; - - if (CFG.xn > 0) { - if (inX) { - - if (al < half + xh && hash2((xcv * 2) | 0, 0, 0x2C9) < 0.40) { - var d1 = lane + wz, d2 = lane - wz; - d1 -= Math.floor(d1 / 2.6) * 2.6; d2 -= Math.floor(d2 / 2.6) * 2.6; - if (d1 < 0.14 || d2 < 0.14) { - var hb = hash2(Math.floor(wx * 1.3), Math.floor(wz * 1.3), 0x2CA); - if (hb > 0.20) - return rset(d1 < 0.14 ? G_SLASH : G_BSLASH, P.amber, 30 + hb * 26); - } - } - } else if (al < half) { - var apr = xd - xh; - - if (apr > 0.40 && apr < 2.60) { - var zk = lane - Math.floor(lane / 1.30) * 1.30; - if (zk < 0.52) { - var zw = hash2(Math.floor(lane * 1.6), Math.floor(wz * 1.6), 0x2C4); - if (zw > 0.52) return rset(zw < 0.72 ? G_HASH : G_8, P.white, 24 + zw * 20); - return rset(G_DASH, P.slate, 14); - } - } else if (apr > 2.86 && apr < 3.04) { - - var sw = hash2(Math.floor(lane * 1.7), 0, 0x2C5); - if (sw < 0.22) return rset(0, P.shadow, 0); - return rset(G_EQ, P.white, 27 + sw * 18); - } - } - } - - if (!inX) { - var az = Math.floor(wz / 26); - if (hash2(az, 0, 0xA55) < 0.40) { - var z0 = az * 26 + hash2(az, 1, 0xA55) * 18; - var dz = wz - z0, dlz = lane - (hash2(az, 2, 0xA55) - 0.5) * 3.0; - if (dz >= 0 && dz < 3.2) { - var adl = dlz < 0 ? -dlz : dlz; - - if (dz > 1.0 && adl < 0.15) return rset(G_PIPE, P.white, 84 + sheet * 34); - var hw = dz * 0.85; - if (dz <= 1.0 && adl - hw < 0.17 && hw - adl < 0.17) - return rset(dlz < 0 ? G_SLASH : G_BSLASH, P.white, 84 + sheet * 34); - } - } - - if (al < 0.13 && (wz - Math.floor(wz / 4.6) * 4.6) < 2.8) - - return rset(G_PIPE, dSky > 0.45 ? P.white : P.amber, - (150 + sheet * 60) * (dSky > 0.45 ? 0.9 + 0.5 * dSky : 1)); - - var el = half - 0.46, ael = al - el; if (ael < 0) ael = -ael; - if (ael < 0.062) { - var ew = hash2(Math.floor(wz * 0.55), 0, 0x2C7); - if (ew > 0.16) return rset(G_PIPE, P.white, 26 + ew * 22 + mirNow * 22); - } - } - - if (CFG.rail && !inX) { - var rg = al - 0.62; if (rg < 0) rg = -rg; - var rg2 = al - 2.06; if (rg2 < 0) rg2 = -rg2; - if (rg < 0.055 || rg2 < 0.055) { - var rh = hash2(Math.floor(wz * 1.4), 0, 0x5A12); - if (fl === 2 && rh < 0.30) - return rset(G_EQ, P.white, 40 + rh * 62 + mirNow * 34); - return rset(G_PIPE, P.slate, 16 + rh * 22); - } - } - - if (!inX && al > half && al < half + 0.34) { - - var kw = hash2(Math.floor(wz * 3), 0, 0x3); - if (al < half + 0.14) - - return dSky > 0.45 - ? rset(G_UNDER, P.white, (96 + kw * 30 + mirNow * 26) * (0.7 + 0.7 * dSky)) - : rset(G_UNDER, P.amber, 124 + kw * 34 + lampK * 74 + mirNow * 30); - return rset(G_EQ, P.slate, 10 + kw * 12); - } - - if (!inX && al > half + 0.34) { - - mirNow *= 0.35; bounceNow = 0.05; - if (fl === 0) return rset(0, P.shadow, 0); - - if (CFG.xn > 0 && xd > xh - 0.2 && xd < xh + 2.4 && al < half + 2.2) { - var tp = hash2(Math.floor(wx * 3.4), Math.floor(wz * 3.4), 0x2D3); - if (tp < 0.38) return rset(G_oo, P.slate, 15 + tp * 34); - return rset(0, P.shadow, 0); - } - - if (fl === 2) { - var du = al - (half + 1.05); if (du < 0) du = -du; - if (du < 0.17) { - var dj = wz - Math.floor(wz / 1.15) * 1.15; - if (hash2(Math.floor(wz / 1.15), 0, 0x2D4) < 0.42) - return rset(dj < 0.12 ? G_PIPE : (du < 0.08 ? G_EQ : G_DASH), P.slate, - dj < 0.12 ? 10 : 20 + hash2(Math.floor(wz * 2), 0, 0x2D5) * 18); - } - } - - var jp = fl === 2 ? 1.25 : 2.50, jw = fl === 2 ? 0.09 : 0.17; - var jx = wx - Math.floor(wx / jp) * jp, jz = wz - Math.floor(wz / jp) * jp; - if (jx < jw || jz < jw) return rset(G_COLON, P.slate, fl === 2 ? 15 : 11); - - var ps = hash2(Math.floor(wx * (fl === 2 ? 1.6 : 0.8)), - Math.floor(wz * (fl === 2 ? 1.6 : 0.8)), 0x2F); - if (ps < (fl === 2 ? 0.30 : 0.15)) - return rset(ps < 0.15 ? G_DOT : G_COMMA, P.slate, (fl === 2 ? 7 : 6) + ps * 20); - return rset(0, P.shadow, 0); - } - - if (!inX && al > half - 0.34) { - mirNow = clamp(mirNow + 0.20 + sheet * 0.45, 0, 1); - var gt = hash2(Math.floor(wz * 2.4), 0, 0x2D8); - if (gt < 0.15 + mirNow * 0.36) - return rset(wchNow, gt < 0.09 ? P.azure : P.slate, - gt < 0.09 ? 48 + mirNow * 54 : 9 + mirNow * 30 + gt * 12); - } - - if (fl > 0) { - - var mz = Math.floor(wz / 9); - var dcl = lane - (hash2(mz, 0, 0x404) - 0.5) * 4.4; - var dcz = wz - (mz * 9 + hash2(mz, 1, 0x404) * 7); - var rr = dcl * dcl + dcz * dcz; - if (hash2(mz, 2, 0x404) < 0.34 && rr < 0.42) { - if (rr > 0.30) return rset(G_O, P.slate, 16); - return rset(hash2(Math.floor(wx * 3), Math.floor(wz * 3), 0x9) < 0.5 ? G_COLON : G_DASH, - P.slate, 9 + sheet * 8); - } - - var iz = Math.floor(wz / 7.3); - if (hash2(iz, 3, 0x404) < 0.22) { - var ipl = lane - (hash2(iz, 4, 0x404) - 0.5) * 4.0; - var ipz = wz - (iz * 7.3 + hash2(iz, 5, 0x404) * 5.6); - var aip = ipl < 0 ? -ipl : ipl; - if (aip < 0.46 && ipz > 0 && ipz < 0.78) { - if (aip > 0.38 || ipz < 0.07 || ipz > 0.71) - return rset(aip > 0.38 ? G_PIPE : G_DASH, P.slate, 26); - var bh = hash2(Math.floor(ipl * 7), Math.floor(ipz * 7), 0x405); - return rset(bh < 0.22 ? G_PLUS : G_DOT, P.slate, 11 + bh * 16); - } - } - - if (!inX && al > half - 0.62 && al < half - 0.08) { - var gz = Math.floor(wz / 2.6); - if (hash2(gz, 0, 0x6A2) < 0.22 && (wz - gz * 2.6) < 1.5) - return rset(G_HASH, P.slate, 12 + sheet * 10); - } - } - - if (fl > 0) { - var sq = Math.floor(lane / 1.35); - if (hash2(sq, 1, 0x33B) < 0.44) { - var sp = sq * 1.35 + 0.18 + hash2(sq, 0, 0x33B) * 0.98 - + (vnoise(wz * 0.21 + sq * 7.3, 0x3C) - 0.5) * 0.55; - var asp = lane - sp; if (asp < 0) asp = -asp; - if (asp < (fl === 2 ? 0.05 : 0.09)) - return rset(G_PIPE, P.slate, 8 + hash2(sq, Math.floor(wz * 0.7), 0x33C) * 12); - } - } - - if (fl > 0 && (wz - Math.floor(wz / 4.0) * 4.0) < 0.10) - return rset(G_DASH, P.slate, 16); - - if (lampK > 0.05 && fl > 0) { - var lh = hash2(Math.floor(wx * (fl === 2 ? 2.1 : 1.0)), - Math.floor(wz * (fl === 2 ? 2.1 : 1.0)), 0x1A5); - if (lh < 0.24 + lampK * 0.40) - return rset(lh < 0.5 ? G_DOT : G_COMMA, P.amber, - 112 + lampK * 118 + lh * 26 + mirNow * 44); - } - - if (pd > 0.015 && pd < 0.30) { - var mh2 = hash2(Math.floor(wx * 4.1), Math.floor(wz * 4.1), 0x2E5); - if (mh2 < 0.38) - return rset(mh2 < 0.09 ? G_QUOTE : wchNow, mh2 < 0.09 ? P.ice : P.white, - 22 + pd * 90 + mh2 * 40); - } - - if (mirNow > 0.12) { - var wg = hash2(Math.floor(wx * 3.1), Math.floor(wz * 1.3), 0x717); - - if (lampK > 0.16 && wg < 0.14 + mirNow * 0.44) - return rset(wchNow, P.amber, 98 + lampK * 76 + mirNow * 46); - if (wg < 0.13 + mirNow * 0.48) - - return rset(wchNow, wg < 0.055 ? P.azure : P.slate, - wg < 0.055 ? 48 + mirNow * 50 : 8 + mirNow * 30 + wg * 14); - } - - if (fl === 0) return rset(0, P.shadow, 0); - - var qi = Math.floor(lane / 2.6), qj = Math.floor(wz / 3.4); - var patch = hash2(qi, qj, 0x7A9) < 0.30; - if (patch && fl === 2) { - - var el2 = lane - qi * 2.6, ez = wz - qj * 3.4; - if (el2 < 0.09 || ez < 0.09 || el2 > 2.51 || ez > 3.31) - return rset(el2 < 0.09 || el2 > 2.51 ? G_PIPE : G_DASH, P.slate, 13); - } - - if (fl === 1) { - var mh = hash2(Math.floor(wx * 0.9), Math.floor(wz * 0.9), 0x12); - return mh < 0.23 ? rset(mh < 0.11 ? G_DOT : G_COMMA, P.slate, 13 + mh * 40) - : rset(0, P.shadow, 0); - } - var ah = hash2(Math.floor(wx * 2.2), Math.floor(wz * 2.2), 0x12); - - var acov = patch ? 0.24 : 0.33 + rut * 0.12; - return ah < acov ? rset(ah < 0.15 ? G_DOT : G_COMMA, P.slate, - (patch ? 11 : 13) + ah * (patch ? 26 : 40) + rut * 6) - : rset(0, P.shadow, 0); + } } - var SOUT = { ch: 0, col: 0, lum: 0 }; - function sset(ch, col, lum) { - SOUT.ch = ch; SOUT.col = col; - SOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - return SOUT; + var rib = Math.floor(v * 3.4); + return (rib % 3) ? fset(0, P.shadow, 0) + : fset(G_UNDER, P.shadow, 11 + hash2(su, rib, sd ^ 0xA9) * 8); + } + + var ROUT = { ch: 0, col: 0, lum: 0, mir: 0, rip: 0, wch: 0 }; + + var mirNow = 0, ripNow = 0, wchNow = 0, bounceNow = 0; + + function rday(col, lum) { + if (dSky <= 0.02) return lum; + var dK = dSky * dSky; + + if (col === P.slate) { + RCOL = dK > 0.50 ? P.stone : (dK > 0.06 ? P.indigo : P.slate); + return lum * (1 + 2.2 * dK) + 26 * dK; + } + if (col === P.shadow) { RCOL = dK > 0.50 ? P.indigo : P.shadow; return lum * (1 + 1.8 * dK); } + RCOL = col; + return lum; + } + var RCOL = 0; + function rset(ch, col, lum) { + RCOL = col; + if (dSky > 0.02 && ch !== 0) lum = rday(col, lum); + ROUT.ch = ch; ROUT.col = RCOL; + ROUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + ROUT.mir = mirNow > bounceNow ? mirNow : bounceNow; + ROUT.rip = ripNow; ROUT.wch = wchNow; + return ROUT; + } + + var WATER = [G_COLON, G_QUOTE, G_TILDE, G_SEMI, G_DQ, G_DASH, G_COMMA, G_TICK]; + var WATER_N = WATER.length; + + function floorTex(wx, wz, dist, t) { + if (alt) return alt.floorTex(wx, wz, dist, t); + weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + var lane = wx - CFG.streetX; + if (CFG.streetPeriod > 0) lane -= Math.round(lane / CFG.streetPeriod) * CFG.streetPeriod; + var al = lane < 0 ? -lane : lane; + var half = CFG.half; + + var fl = dist < 22 ? 2 : (dist < 50 ? 1 : 0); + + var sheet = vnoise(wx * 0.11 + 3.1, 91) * 0.72 + vnoise(wz * 0.05, 57) * 0.62 + - 0.42 + (wWet - 1) * 0.34; + sheet = clamp(sheet, 0, 1) * clamp(wWet, 0, 1.15); + + var pi = Math.floor(lane / 2.4), pj = Math.floor(wz / 5.6); + var pd = 0; + + if (fl > 0 && hash2(pi, pj, 0x9D1) < 0.26 + 0.40 * clamp(wWet, 0, 1.2)) { + var pra = (0.30 + hash2(pi, pj, 0x9D4) * 0.60) * clamp(0.42 + wWet * 0.64, 0.22, 1.25); + if (pra > 1.05) pra = 1.05; + var prz = pra * (1.5 + hash2(pi, pj, 0x9D5) * 1.4); + if (prz > 2.55) prz = 2.55; + var pcx = pi * 2.4 + pra + (2.4 - 2 * pra) * hash2(pi, pj, 0x9D2); + var pcz = pj * 5.6 + prz + (5.6 - 2 * prz) * hash2(pi, pj, 0x9D3); + var dl = (lane - pcx) / pra, dpz = (wz - pcz) / prz; + var rr2 = dl * dl + dpz * dpz; + + if (rr2 < 1) pd = 1 - rr2 * rr2; } - var skyLastSy = 1e9, skyRoof = 0; + var rc = half * 0.55, rut = al - rc; if (rut < 0) rut = -rut; + rut = 1 - clamp(rut / 0.62, 0, 1); - function dStarSurf() { return CC.Daylight ? CC.Daylight.P.star : 1; } + var lampK = 0; + if (fl > 0) { + var lj = Math.floor(wz / 13.5); + var lcl = (hash2(lj, 0, 0x1A3) < 0.5 ? 1 : -1) * (half - 0.55); + var lcz = lj * 13.5 + 3.4 + hash2(lj, 1, 0x1A3) * 6.6; + var dll = (lane - lcl) / 3.0, dlpz = (wz - lcz) / 4.1; + lampK = 1 - (dll * dll + dlpz * dlpz); + if (lampK < 0) lampK = 0; else lampK *= lampK; + lampK *= dLamp; + } - function skyDay(sx, sy, ey, aboveH) { - var rows = CFG.rows > 8 ? CFG.rows : 60; + mirNow = clamp(pd * 0.95 + sheet * (0.40 + rut * 0.26), 0, 1); - var a = aboveH / rows; - var hs = hash2(sx, ey, CFG.skySeed ^ 0x3D), hs2 = hash2(sx, ey, CFG.skySeed ^ 0x5B); + bounceNow = 0.13; - var murk = Math.exp(-a / (0.16 + 0.20 * wFogP)) * (0.55 + 0.45 * wFogP); - var lift = dSky * (1 - 0.45 * W_CLOUD_DAY()); + ripNow = 0; + if (mirNow > 0.20) { + ripNow = (hash2(Math.floor(wx * 2.7), Math.floor(wz * 1.9), 0x2E2) - 0.5) + * (1.2 + 1.8 * clamp(wWind, 0, 1.4)); + if (!CC.reducedMotion && wRain > 0.05) + ripNow += (vnoise(wz * 0.85 + t * 1.7, 0x2E3) - 0.5) * 2.4 * clamp(wRain, 0, 1.2); + } + wchNow = WATER[(hash2(Math.floor(wx * 2.3), Math.floor(wz * 1.1), 0x2E1) * WATER_N) | 0]; - var cover = (0.94 - 0.30 * a) * lift; - if (hs > cover) return sset(0, P.shadow, 0); + var xd = 1e9, xh = 0, xcv = 0, i, ad2; + if (CFG.xn > 0) { - if (murk > 0.55) { + var xg = Math.round((wz - CFG.xz0) / CFG.xpitch); + var xlo = xg - 1, xhi = xg + 1; + if (xlo < 0) xlo = 0; + if (xhi > CFG.xn - 1) xhi = CFG.xn - 1; + for (i = xlo; i <= xhi; i++) { + ad2 = wz - CFG.xc[i]; if (ad2 < 0) ad2 = -ad2; + if (ad2 < xd) { xd = ad2; xh = CFG.xw[i]; xcv = CFG.xc[i]; } + } + } + var inX = xd < xh; - return sset(hs2 > 0.5 ? G_EQ : G_DASH, P.white, - (150 + 70 * murk) * lift * (0.86 + 0.22 * hs2)); + if (CFG.xn > 0) { + if (inX) { + + if (al < half + xh && hash2((xcv * 2) | 0, 0, 0x2C9) < 0.40) { + var d1 = lane + wz, d2 = lane - wz; + d1 -= Math.floor(d1 / 2.6) * 2.6; d2 -= Math.floor(d2 / 2.6) * 2.6; + if (d1 < 0.14 || d2 < 0.14) { + var hb = hash2(Math.floor(wx * 1.3), Math.floor(wz * 1.3), 0x2CA); + if (hb > 0.20) + return rset(d1 < 0.14 ? G_SLASH : G_BSLASH, P.amber, 30 + hb * 26); + } } - if (murk > 0.22) { - return sset(G_TICK, hs2 > 0.34 ? P.ice : P.white, - (120 + 90 * murk) * lift * (0.84 + 0.26 * hs2)); + } else if (al < half) { + var apr = xd - xh; + + if (apr > 0.40 && apr < 2.60) { + var zk = lane - Math.floor(lane / 1.30) * 1.30; + if (zk < 0.52) { + var zw = hash2(Math.floor(lane * 1.6), Math.floor(wz * 1.6), 0x2C4); + if (zw > 0.52) return rset(zw < 0.72 ? G_HASH : G_8, P.white, 24 + zw * 20); + return rset(G_DASH, P.slate, 14); + } + } else if (apr > 2.86 && apr < 3.04) { + + var sw = hash2(Math.floor(lane * 1.7), 0, 0x2C5); + if (sw < 0.22) return rset(0, P.shadow, 0); + return rset(G_EQ, P.white, 27 + sw * 18); } - - return sset(hs2 > 0.72 ? G_COLON : G_DOT, P.ice, - (74 + 84 * murk) * lift * (0.8 + 0.3 * hs2)); + } } - function W_CLOUD_DAY() { return CC.Weather ? CC.Weather.P.cloud : 0.75; } - function sky(sx, sy, t) { + if (!inX) { + var az = Math.floor(wz / 26); + if (hash2(az, 0, 0xA55) < 0.40) { + var z0 = az * 26 + hash2(az, 1, 0xA55) * 18; + var dz = wz - z0, dlz = lane - (hash2(az, 2, 0xA55) - 0.5) * 3.0; + if (dz >= 0 && dz < 3.2) { + var adl = dlz < 0 ? -dlz : dlz; - if (alt) return alt.sky(sx, sy, t); - dayAt(t === undefined ? 0 : t); - if (sy >= skyLastSy) skyRoof = sy + 1; - skyLastSy = sy; - - var e = CFG.rows * 0.185; - if (e < 3) e = 3; - var aboveH = CFG.horizon - sy; if (aboveH < 0) aboveH = 0; - - if (dSky > 0.30) { - var ey0 = Math.floor((CFG.horizon - sy) * CFG.skyVScale); - return skyDay(sx, sy, ey0, aboveH); + if (dz > 1.0 && adl < 0.15) return rset(G_PIPE, P.white, 84 + sheet * 34); + var hw = dz * 0.85; + if (dz <= 1.0 && adl - hw < 0.17 && hw - adl < 0.17) + return rset(dlz < 0 ? G_SLASH : G_BSLASH, P.white, 84 + sheet * 34); } + } - var ey = Math.floor((CFG.horizon - sy) * CFG.skyVScale); - var aboveR = skyRoof - sy; if (aboveR < 0) aboveR = 0; - var glow = Math.exp(-aboveR / e) * 0.94; - var gh = Math.exp(-aboveH / e); - if (gh > glow) glow = gh; + if (al < 0.13 && (wz - Math.floor(wz / 4.6) * 4.6) < 2.8) - glow *= 0.15 + 0.85 * dLamp; + return rset(G_PIPE, dSky > 0.45 ? P.white : P.amber, + (150 + sheet * 60) * (dSky > 0.45 ? 0.9 + 0.5 * dSky : 1)); - if (glow > 0.02 && hash2(sx, ey, CFG.skySeed) < glow * 0.86) { - var lum = 124 * glow * (0.7 + 0.6 * hash2(sx, ey, CFG.skySeed ^ 0x11)); + var el = half - 0.46, ael = al - el; if (ael < 0) ael = -ael; + if (ael < 0.062) { + var ew = hash2(Math.floor(wz * 0.55), 0, 0x2C7); + if (ew > 0.16) return rset(G_PIPE, P.white, 26 + ew * 22 + mirNow * 22); + } + } - if (lum >= 4) return sset(glow > 0.32 ? G_DOT : G_TICK, - glow > 0.32 ? P.amber : (glow > 0.11 ? P.slate : P.shadow), lum); + if (CFG.rail && !inX) { + var rg = al - 0.62; if (rg < 0) rg = -rg; + var rg2 = al - 2.06; if (rg2 < 0) rg2 = -rg2; + if (rg < 0.055 || rg2 < 0.055) { + var rh = hash2(Math.floor(wz * 1.4), 0, 0x5A12); + if (fl === 2 && rh < 0.30) + return rset(G_EQ, P.white, 40 + rh * 62 + mirNow * 34); + return rset(G_PIPE, P.slate, 16 + rh * 22); + } + } + + if (!inX && al > half && al < half + 0.34) { + + var kw = hash2(Math.floor(wz * 3), 0, 0x3); + if (al < half + 0.14) + + return dSky > 0.45 + ? rset(G_UNDER, P.sand, (96 + kw * 30 + mirNow * 26) * (0.7 + 0.7 * dSky)) + : rset(G_UNDER, P.amber, 124 + kw * 34 + lampK * 74 + mirNow * 30); + + if (dSky > 0.45 && hash2(Math.floor(wz * 1.7), 0, 0x3C1) < 0.34) + return rset(G_EQ, P.moss, (44 + kw * 30) * (0.6 + 0.8 * dSky)); + return rset(G_EQ, P.slate, 10 + kw * 12); + } + + if (!inX && al > half + 0.34) { + + mirNow *= 0.35; bounceNow = 0.05; + if (fl === 0) return rset(0, P.shadow, 0); + + if (CFG.xn > 0 && xd > xh - 0.2 && xd < xh + 2.4 && al < half + 2.2) { + var tp = hash2(Math.floor(wx * 3.4), Math.floor(wz * 3.4), 0x2D3); + + if (tp < 0.38) return rset(G_oo, dSky > 0.45 ? P.sand : P.slate, + dSky > 0.45 ? (34 + tp * 44) * (0.6 + 0.8 * dSky) : 15 + tp * 34); + return rset(0, P.shadow, 0); + } + + if (fl === 2) { + var du = al - (half + 1.05); if (du < 0) du = -du; + if (du < 0.17) { + var dj = wz - Math.floor(wz / 1.15) * 1.15; + if (hash2(Math.floor(wz / 1.15), 0, 0x2D4) < 0.42) + return rset(dj < 0.12 ? G_PIPE : (du < 0.08 ? G_EQ : G_DASH), P.slate, + dj < 0.12 ? 10 : 20 + hash2(Math.floor(wz * 2), 0, 0x2D5) * 18); } + } - if (glow < 0.53 && dStarSurf() > 0.02) { - var s = hash2(sx, ey, 0x1337); - if (s < 0.0075 * dStarSurf()) { + var jp = fl === 2 ? 1.25 : 2.50, jw = fl === 2 ? 0.09 : 0.17; + var jx = wx - Math.floor(wx / jp) * jp, jz = wz - Math.floor(wz / jp) * jp; + if (jx < jw || jz < jw) return rset(G_COLON, P.slate, fl === 2 ? 15 : 11); - var tw = CC.reducedMotion ? 0.86 - : 0.55 + 0.45 * hash2(sx ^ Math.floor(t * 0.8), ey, 0x99); - return sset(s < 0.0018 ? G_PLUS : G_DOT, s < 0.0035 ? P.ice : P.white, - (52 + s * 9000) * tw * dStarSurf()); - } + var ps = hash2(Math.floor(wx * (fl === 2 ? 1.6 : 0.8)), + Math.floor(wz * (fl === 2 ? 1.6 : 0.8)), 0x2F); + if (ps < (fl === 2 ? 0.30 : 0.15)) + return rset(ps < 0.15 ? G_DOT : G_COMMA, P.slate, (fl === 2 ? 7 : 6) + ps * 20); + return rset(0, P.shadow, 0); + } + + if (!inX && al > half - 0.34) { + mirNow = clamp(mirNow + 0.20 + sheet * 0.45, 0, 1); + var gt = hash2(Math.floor(wz * 2.4), 0, 0x2D8); + if (gt < 0.15 + mirNow * 0.36) + return rset(wchNow, gt < 0.09 ? P.azure : P.slate, + gt < 0.09 ? 48 + mirNow * 54 : 9 + mirNow * 30 + gt * 12); + } + + if (fl > 0) { + + var mz = Math.floor(wz / 9); + var dcl = lane - (hash2(mz, 0, 0x404) - 0.5) * 4.4; + var dcz = wz - (mz * 9 + hash2(mz, 1, 0x404) * 7); + var rr = dcl * dcl + dcz * dcz; + if (hash2(mz, 2, 0x404) < 0.34 && rr < 0.42) { + if (rr > 0.30) return rset(G_O, P.slate, 16); + return rset(hash2(Math.floor(wx * 3), Math.floor(wz * 3), 0x9) < 0.5 ? G_COLON : G_DASH, + P.slate, 9 + sheet * 8); + } + + var iz = Math.floor(wz / 7.3); + if (hash2(iz, 3, 0x404) < 0.22) { + var ipl = lane - (hash2(iz, 4, 0x404) - 0.5) * 4.0; + var ipz = wz - (iz * 7.3 + hash2(iz, 5, 0x404) * 5.6); + var aip = ipl < 0 ? -ipl : ipl; + if (aip < 0.46 && ipz > 0 && ipz < 0.78) { + if (aip > 0.38 || ipz < 0.07 || ipz > 0.71) + return rset(aip > 0.38 ? G_PIPE : G_DASH, P.slate, 26); + var bh = hash2(Math.floor(ipl * 7), Math.floor(ipz * 7), 0x405); + return rset(bh < 0.22 ? G_PLUS : G_DOT, P.slate, 11 + bh * 16); } - return sset(0, P.shadow, 0); + } + + if (!inX && al > half - 0.62 && al < half - 0.08) { + var gz = Math.floor(wz / 2.6); + if (hash2(gz, 0, 0x6A2) < 0.22 && (wz - gz * 2.6) < 1.5) + return rset(G_HASH, P.slate, 12 + sheet * 10); + } } - var FOG_START = 12.0, FOG_END = 125.0; - - var fogEnd = FOG_END, fogSpan = FOG_END - FOG_START; - - function refog() { - - var k = (wFogP - 0.30) / 0.70; - if (k > 1) k = 1; else if (k < -0.45) k = -0.45; - - fogStart = (alt && alt.fogStart !== undefined) ? alt.fogStart : FOG_START; - fogEnd = ((alt && alt.fogEnd !== undefined) ? alt.fogEnd : FOG_END) * (1 - 0.26 * k); - fogSpan = fogEnd - fogStart; - fogPow = (alt && alt.fogPow !== undefined) ? alt.fogPow : 1.5; - - var D = CC.Daylight; - - hazeFloor = (D && !(alt && alt.airless)) ? D.P.sky * (0.30 + 0.55 * wFogP) * 46 : 0; - } - var fogStart = FOG_START, fogPow = 1.5, hazeFloor = 0; - function fog(lum, dist) { - if (!(dist === dist) || dist === Infinity) return lum; - if (dist <= fogStart) return lum; - if (dist >= fogEnd) return 0; - var k = 1 - (dist - fogStart) / fogSpan; - - k = fogPow === 1.5 ? k * Math.sqrt(k) : Math.pow(k, fogPow); - var v = lum * k; - - if (hazeFloor > 0) v += hazeFloor * (1 - k) * (lum > 24 ? 1 : lum / 24); - return v < 4 ? 0 : (v > 255 ? 255 : v | 0); + if (fl > 0) { + var sq = Math.floor(lane / 1.35); + if (hash2(sq, 1, 0x33B) < 0.44) { + var sp = sq * 1.35 + 0.18 + hash2(sq, 0, 0x33B) * 0.98 + + (vnoise(wz * 0.21 + sq * 7.3, 0x3C) - 0.5) * 0.55; + var asp = lane - sp; if (asp < 0) asp = -asp; + if (asp < (fl === 2 ? 0.05 : 0.09)) + return rset(G_PIPE, P.slate, 8 + hash2(sq, Math.floor(wz * 0.7), 0x33C) * 12); + } } - var alt = null; - if (!CC.SURFACES) CC.SURFACES = {}; - function resolveWorld() { - alt = (CC.World && CC.SURFACES[CC.World.id]) || null; + if (fl > 0 && (wz - Math.floor(wz / 4.0) * 4.0) < 0.10) + return rset(G_DASH, P.slate, 16); + + if (lampK > 0.05 && fl > 0) { + var lh = hash2(Math.floor(wx * (fl === 2 ? 2.1 : 1.0)), + Math.floor(wz * (fl === 2 ? 2.1 : 1.0)), 0x1A5); + if (lh < 0.24 + lampK * 0.40) + return rset(lh < 0.5 ? G_DOT : G_COMMA, P.amber, + 112 + lampK * 118 + lh * 26 + mirNow * 44); } - function beginFrame(t) { - resolveWorld(); - dayAt(t === undefined ? 0 : t); - weatherAt(t === undefined ? 0 : t); - return fogEnd; + if (pd > 0.015 && pd < 0.30) { + var mh2 = hash2(Math.floor(wx * 4.1), Math.floor(wz * 4.1), 0x2E5); + if (mh2 < 0.38) + return rset(mh2 < 0.09 ? G_QUOTE : wchNow, mh2 < 0.09 ? P.ice : P.white, + 22 + pd * 90 + mh2 * 40); } - CC.Surf = { - facade: facade, floorTex: floorTex, sky: sky, fog: fog, + if (mirNow > 0.12) { + var wg = hash2(Math.floor(wx * 3.1), Math.floor(wz * 1.3), 0x717); - resolveWorld: resolveWorld, - configure: configure, cfg: CFG, beginFrame: beginFrame, - FOG_START: FOG_START, FOG_END: FOG_END, + if (lampK > 0.16 && wg < 0.14 + mirNow * 0.44) + return rset(wchNow, P.amber, 98 + lampK * 76 + mirNow * 46); + if (wg < 0.13 + mirNow * 0.48) - SHOP_OPEN: SHOP_OPEN - }; + return rset(wchNow, wg < 0.055 ? P.azure : P.slate, + wg < 0.055 ? 48 + mirNow * 50 : 8 + mirNow * 30 + wg * 14); + } + + if (fl === 0) return rset(0, P.shadow, 0); + + var qi = Math.floor(lane / 2.6), qj = Math.floor(wz / 3.4); + var patch = hash2(qi, qj, 0x7A9) < 0.30; + if (patch && fl === 2) { + + var el2 = lane - qi * 2.6, ez = wz - qj * 3.4; + if (el2 < 0.09 || ez < 0.09 || el2 > 2.51 || ez > 3.31) + return rset(el2 < 0.09 || el2 > 2.51 ? G_PIPE : G_DASH, P.slate, 13); + } + + if (fl === 1) { + var mh = hash2(Math.floor(wx * 0.9), Math.floor(wz * 0.9), 0x12); + return mh < 0.23 ? rset(mh < 0.11 ? G_DOT : G_COMMA, P.slate, 13 + mh * 40) + : rset(0, P.shadow, 0); + } + var ah = hash2(Math.floor(wx * 2.2), Math.floor(wz * 2.2), 0x12); + + var acov = patch ? 0.24 : 0.33 + rut * 0.12; + return ah < acov ? rset(ah < 0.15 ? G_DOT : G_COMMA, P.slate, + (patch ? 11 : 13) + ah * (patch ? 26 : 40) + rut * 6) + : rset(0, P.shadow, 0); + } + + var SOUT = { ch: 0, col: 0, lum: 0 }; + function sset(ch, col, lum) { + SOUT.ch = ch; SOUT.col = col; + SOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + return SOUT; + } + + var skyLastSy = 1e9, skyRoof = 0; + + function dStarSurf() { return CC.Daylight ? CC.Daylight.P.star : 1; } + + function skyDay(sx, sy, ey, aboveH) { + var rows = CFG.rows > 8 ? CFG.rows : 60; + + var a = aboveH / rows; + var hs = hash2(sx, ey, CFG.skySeed ^ 0x3D), hs2 = hash2(sx, ey, CFG.skySeed ^ 0x5B); + + var murk = Math.exp(-a / (0.16 + 0.20 * wFogP)) * (0.55 + 0.45 * wFogP); + var lift = dSky * (1 - 0.45 * W_CLOUD_DAY()); + + var cover = (0.94 - 0.30 * a) * lift; + if (hs > cover) return sset(0, P.shadow, 0); + + if (murk > 0.55) { + + return sset(hs2 > 0.5 ? G_EQ : G_DASH, P.white, + (150 + 70 * murk) * lift * (0.86 + 0.22 * hs2)); + } + if (murk > 0.22) { + return sset(G_TICK, hs2 > 0.34 ? P.ice : P.white, + (120 + 90 * murk) * lift * (0.84 + 0.26 * hs2)); + } + + return sset(hs2 > 0.72 ? G_COLON : G_DOT, P.ice, + (74 + 84 * murk) * lift * (0.8 + 0.3 * hs2)); + } + function W_CLOUD_DAY() { return CC.Weather ? CC.Weather.P.cloud : 0.75; } + + function sky(sx, sy, t) { + + if (alt) return alt.sky(sx, sy, t); + dayAt(t === undefined ? 0 : t); + if (sy >= skyLastSy) skyRoof = sy + 1; + skyLastSy = sy; + + var e = CFG.rows * 0.185; + if (e < 3) e = 3; + var aboveH = CFG.horizon - sy; if (aboveH < 0) aboveH = 0; + + if (dSky > 0.30) { + var ey0 = Math.floor((CFG.horizon - sy) * CFG.skyVScale); + return skyDay(sx, sy, ey0, aboveH); + } + + var ey = Math.floor((CFG.horizon - sy) * CFG.skyVScale); + var aboveR = skyRoof - sy; if (aboveR < 0) aboveR = 0; + var glow = Math.exp(-aboveR / e) * 0.94; + var gh = Math.exp(-aboveH / e); + if (gh > glow) glow = gh; + + glow *= 0.15 + 0.85 * dLamp; + + if (glow > 0.02 && hash2(sx, ey, CFG.skySeed) < glow * 0.86) { + var lum = 124 * glow * (0.7 + 0.6 * hash2(sx, ey, CFG.skySeed ^ 0x11)); + + if (lum >= 4) return sset(glow > 0.32 ? G_DOT : G_TICK, + glow > 0.32 ? P.amber : (glow > 0.11 ? P.slate : P.shadow), lum); + } + + if (glow < 0.53 && dStarSurf() > 0.02) { + var s = hash2(sx, ey, 0x1337); + if (s < 0.0075 * dStarSurf()) { + + var tw = CC.reducedMotion ? 0.86 + : 0.55 + 0.45 * hash2(sx ^ Math.floor(t * 0.8), ey, 0x99); + return sset(s < 0.0018 ? G_PLUS : G_DOT, s < 0.0035 ? P.ice : P.white, + (52 + s * 9000) * tw * dStarSurf()); + } + } + return sset(0, P.shadow, 0); + } + + var FOG_START = 12.0, FOG_END = 125.0; + + var fogEnd = FOG_END, fogSpan = FOG_END - FOG_START; + + function refog() { + + var k = (wFogP - 0.30) / 0.70; + if (k > 1) k = 1; else if (k < -0.45) k = -0.45; + + fogStart = (alt && alt.fogStart !== undefined) ? alt.fogStart : FOG_START; + fogEnd = ((alt && alt.fogEnd !== undefined) ? alt.fogEnd : FOG_END) * (1 - 0.26 * k); + fogSpan = fogEnd - fogStart; + + fogPow = (alt && alt.fogPow !== undefined) ? alt.fogPow : 1.5; + + var D = CC.Daylight; + + hazeFloor = (D && !(alt && alt.airless)) ? D.P.sky * (0.30 + 0.55 * wFogP) * 46 : 0; + } + var fogStart = FOG_START, fogPow = 1.5, hazeFloor = 0; + function fog(lum, dist) { + if (!(dist === dist) || dist === Infinity) return lum; + if (dist <= fogStart) return lum; + if (dist >= fogEnd) return 0; + var k = 1 - (dist - fogStart) / fogSpan; + + k = fogPow === 1.5 ? k * Math.sqrt(k) : Math.pow(k, fogPow); + var v = lum * k; + + if (hazeFloor > 0) v += hazeFloor * (1 - k) * (lum > 24 ? 1 : lum / 24); + return v < 4 ? 0 : (v > 255 ? 255 : v | 0); + } + + var alt = null; + if (!CC.SURFACES) CC.SURFACES = {}; + function resolveWorld() { + alt = (CC.World && CC.SURFACES[CC.World.id]) || null; + } + + function beginFrame(t) { + resolveWorld(); + dayAt(t === undefined ? 0 : t); + weatherAt(t === undefined ? 0 : t); + return fogEnd; + } + + CC.Surf = { + facade: facade, floorTex: floorTex, sky: sky, fog: fog, + + resolveWorld: resolveWorld, + configure: configure, cfg: CFG, beginFrame: beginFrame, + FOG_START: FOG_START, FOG_END: FOG_END, + + SHOP_OPEN: SHOP_OPEN + }; })(CC); /* src/surf_moon.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp; + var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp; - var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), - G_TICK = g('`'), G_DASH = g('-'), G_EQ = g('='), G_TILDE = g('~'), G_STAR = g('*'), - G_PLUS = g('+'), G_PCT = g('%'), G_HASH = g('#'), G_8 = g('8'), G_o = g('o'), G_O = g('O'); + var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), + G_TICK = g('`'), G_DASH = g('-'), G_EQ = g('='), G_TILDE = g('~'), G_STAR = g('*'), + G_PLUS = g('+'), G_PCT = g('%'), G_HASH = g('#'), G_8 = g('8'), G_o = g('o'), G_O = g('O'); - function cfg() { return CC.Surf ? CC.Surf.cfg : null; } + function cfg() { return CC.Surf ? CC.Surf.cfg : null; } - var AZ_OFFSET = Math.PI; + var AZ_OFFSET = Math.PI; - var EARTH_AZ = 0.28, EARTH_ALT = 0.24; + var EARTH_AZ = 0.28, EARTH_ALT = 0.24; - var SUN_AZ = AZ_OFFSET, SUN_X = Math.sin(AZ_OFFSET), SUN_Z = Math.cos(AZ_OFFSET), SUN_ALT = 0.25; + var SUN_AZ = AZ_OFFSET, SUN_X = Math.sin(AZ_OFFSET), SUN_Z = Math.cos(AZ_OFFSET), SUN_ALT = 0.25; - var dT = 1 / 0, dNight = 0, dMix = 0; + var dT = 1 / 0, dNight = 0, dMix = 0; - var ALT_LO = 0.09, ALT_HI = 0.45; + var ALT_LO = 0.09, ALT_HI = 0.45; - function dayAt(t) { - if (t === dT) return; - dT = t; + function dayAt(t) { + if (t === dT) return; + dT = t; - dMix = (CC.dayMix === undefined) ? 0 : CC.dayMix; - var D = CC.Daylight; - if (!D) return; - var alt = D.P.alt; + dMix = (CC.dayMix === undefined) ? 0 : CC.dayMix; + var D = CC.Daylight; + if (!D) return; + var alt = D.P.alt; - dNight = 1 - clamp(D.P.sky / 0.16, 0, 1); + dNight = 1 - clamp(D.P.sky / 0.16, 0, 1); - SUN_X = Math.sin(D.P.az + AZ_OFFSET); SUN_Z = Math.cos(D.P.az + AZ_OFFSET); - SUN_AZ = Math.atan2(SUN_X, SUN_Z); + SUN_X = Math.sin(D.P.az + AZ_OFFSET); SUN_Z = Math.cos(D.P.az + AZ_OFFSET); + SUN_AZ = Math.atan2(SUN_X, SUN_Z); - var lift = clamp(alt / 0.95, 0, 1); - SUN_ALT = ALT_LO + (ALT_HI - ALT_LO) * lift; + var lift = clamp(alt / 0.95, 0, 1); + SUN_ALT = ALT_LO + (ALT_HI - ALT_LO) * lift; - SUN_ALT = SUN_ALT + (EARTH_ALT - SUN_ALT) * dNight; + SUN_ALT = SUN_ALT + (EARTH_ALT - SUN_ALT) * dNight; + + var tg = Math.tan(SUN_ALT); if (tg < 0.02) tg = 0.02; + SLOPE_G = clamp(0.255 / tg, 0.6, 1.9); + } + + var wT = 1 / 0, wFines = 0; + function weatherAt(t) { + if (t === wT) return; + wT = t; + var W = CC.Weather; + if (!W) return; + wFines = W.P.haze; + } + + function seedOf(cell) { + if (!cell || typeof cell !== 'object') return 0; + if (cell.seed !== undefined) return cell.seed | 0; + return 0; + } + + var FOUT = { ch: 0, col: 0, lum: 0 }; + function fset(ch, col, lum) { + FOUT.ch = ch; FOUT.col = col; + FOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + return FOUT; + } + + function dim(o, k) { o.lum = (o.lum * k) | 0; return o; } + + var NEAR0 = 24.0, NEAR1 = 40.0, CLIFF = 125.0; + + function litSet(ch, base, dist, hv) { + var far = dist >= NEAR1 || + (dist > NEAR0 && hv > (NEAR1 - dist) / (NEAR1 - NEAR0)); + if (!far) { + + var nl = (150 + 62 * base) * (1 - 0.20 * dMix); + if (dNight > 0.5 || (dNight > 0 && hv < dNight)) + + return base > 0.72 ? fset(ch, P.pure, 52 + 26 * base) + : fset(ch, P.azure, 44 + 26 * base); + return fset(ch, P.white, nl); } - var wT = 1 / 0, wFines = 0; - function weatherAt(t) { - if (t === wT) return; - wT = t; - var W = CC.Weather; - if (!W) return; - wFines = W.P.haze; + if (dNight > 0.5 || (dNight > 0 && hv < dNight)) + return fset(ch, P.azure, (dist < CLIFF ? 70 + dist * 0.62 : 60) * (0.90 + 0.26 * base)); + return fset(ch, P.pure, (dist < CLIFF ? 96 + dist * 0.62 : 88) * (0.90 + 0.26 * base)); + } + + function specSet(ch, base, dist) { + + if (dNight > 0.5) return fset(ch, P.pure, 78 + 34 * base); + return fset(ch, P.pure, (dist < CLIFF ? 186 + 50 * base : 150 + 40 * base)); + } + + var SUN_FRONT = 1.00, SUN_SIDE = 0.34; + function sunOf(cell) { + var back = 0.18 * dNight; + if (!cell || cell.faceX === undefined) return SUN_SIDE + (0.5 - SUN_SIDE) * dNight; + + var nx = cell.faceX ? -cell.side : 0, nz = cell.faceX ? 0 : -cell.side; + var d = nx * SUN_X + nz * SUN_Z; + var slope = 3.0 + (1.2 - 3.0) * dNight; + var f = clamp(0.5 + slope * d, 0, 1); + return back + (SUN_FRONT - back) * f * f * (3 - 2 * f); + } + + function darkFace(dist, hv) { + if (dist >= 25) return fset(0, P.shadow, 0); + if (hv > 0.08) return fset(0, P.shadow, 0); + return fset(hv < 0.03 ? G_DOT : G_COMMA, P.slate, 16 + hv * 96); + } + + var STYLE_M = [ + { pitch: 1.35, fill: 0.55, cap: 0.9, hard: 0, erode: 1.00, seamP: 0.06, glint: 0.34 }, + { pitch: 0.52, fill: 0.86, cap: 1.0, hard: 1, erode: 1.00, seamP: 0.13, glint: 0.34 }, + { pitch: 2.60, fill: 0.44, cap: 0.4, hard: 0, erode: 0.34, seamP: 0.00, glint: 0.08 } + ]; + + var Q_D = [4, 8, 14, 22, 34, 55, 90], + Q_V = [60, 23, 12.5, 7.6, 4.9, 3.1, 1.9, 1.2]; + function qOf(dist) { + for (var i = 0; i < 7; i++) if (dist < Q_D[i]) return Q_V[i]; + return Q_V[7]; + } + + function capOf(dist, mul) { + var c = dist * 0.0145 * mul; + return c < 0.08 ? 0.08 : (c > 1.1 ? 1.1 : c); + } + + function facade(u, v, cell, dist, t) { + if (v < 0) v = 0; + weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + + var sd = seedOf(cell); + + var sti = cell ? (cell.style | 0) - 7 : 0; + var st = STYLE_M[sti === 1 ? 1 : (sti === 2 ? 2 : 0)]; + var h = cell && cell.h ? cell.h : 2; + var sun = sunOf(cell); + + var q = qOf(dist); + var hv = hash2(Math.floor(u * q), Math.floor(v * q), sd ^ 0x4D31); + + var top = h - h * (0.06 + 0.20 * hash2(Math.floor(u * 0.42), 0, sd ^ 0x4D78)) * + hash2(Math.floor(u * 1.3), 0, sd ^ 0x4D77) * st.erode; + var crest = top - v; + if (crest < 0) return fset(0, P.shadow, 0); + + var tv = hash2(Math.floor(u * q), Math.floor(v * q), sd ^ 0x4D33) * 0.74; + var edge = sun - tv; + + var soft = edge < 0.26 ? 0.24 + 2.923 * edge : 1; + if (edge <= 0) { + + if (st.hard && crest < capOf(dist, 0.7) && dist < 34 && hv < 0.34) + return fset(G_DASH, P.slate, 26 + hv * 40); + return darkFace(dist, hv); } - function seedOf(cell) { - if (!cell || typeof cell !== 'object') return 0; - if (cell.seed !== undefined) return cell.seed | 0; - return 0; + var cap = capOf(dist, st.cap); + if (crest < cap) { + if (st.hard) + + return dim(specSet(crest < cap * 0.5 ? (hv < 0.58 ? G_EQ : G_DASH) + : (hv < 0.45 ? G_DASH : G_TICK), + 0.55 + hv * 0.45, dist), soft); + + if (hv < st.glint) return dim(specSet(G_QUOTE, hv, dist), soft); + return dim(litSet(G_TICK, 0.7 + hv * 0.3, dist, hv), soft); } - var FOUT = { ch: 0, col: 0, lum: 0 }; - function fset(ch, col, lum) { - FOUT.ch = ch; FOUT.col = col; - FOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - return FOUT; + if (st.seamP > 0) { + var seam = hash2(Math.floor(u / st.pitch), Math.floor(v / (st.pitch * 1.3)), sd ^ 0x4D42); + if (seam < st.seamP) return fset(0, P.shadow, 0); } - function dim(o, k) { o.lum = (o.lum * k) | 0; return o; } + if (hv > st.fill) return fset(0, P.shadow, 0); + var k = hv / st.fill; - var NEAR0 = 24.0, NEAR1 = 40.0, CLIFF = 125.0; + if (st.hard && k > 0.962) return dim(specSet(G_STAR, k, dist), soft); - function litSet(ch, base, dist, hv) { - var far = dist >= NEAR1 || - (dist > NEAR0 && hv > (NEAR1 - dist) / (NEAR1 - NEAR0)); - if (!far) { + if (st.hard) + return dim(litSet(k < 0.30 ? G_8 : (k < 0.62 ? G_PCT : (k < 0.86 ? G_HASH : G_O)), + k, dist, hv), soft); + return dim(litSet(k < 0.34 ? G_DOT : (k < 0.68 ? G_COMMA : G_TICK), k * 0.8, dist, hv), soft); + } - var nl = (150 + 62 * base) * (1 - 0.20 * dMix); - if (dNight > 0.5 || (dNight > 0 && hv < dNight)) + var ROUT = { ch: 0, col: 0, lum: 0, mir: 0, rip: 0, wch: 0 }; + function rset(o) { + ROUT.ch = o.ch; ROUT.col = o.col; ROUT.lum = o.lum; - return base > 0.72 ? fset(ch, P.pure, 52 + 26 * base) - : fset(ch, P.azure, 44 + 26 * base); - return fset(ch, P.white, nl); - } + ROUT.mir = 0; ROUT.rip = 0; ROUT.wch = 0; + return ROUT; + } + function rblank() { return rset(fset(0, P.shadow, 0)); } - if (dNight > 0.5 || (dNight > 0 && hv < dNight)) - return fset(ch, P.azure, (dist < CLIFF ? 70 + dist * 0.62 : 60) * (0.90 + 0.26 * base)); - return fset(ch, P.pure, (dist < CLIFF ? 96 + dist * 0.62 : 88) * (0.90 + 0.26 * base)); + var SW_LAT = [128.0, 54.0, 23.0, 9.0], SW_W = [0.26, 0.32, 0.26, 0.16], + SW_SALT = [0x4D71, 0x4D7B, 0x4D85, 0x4D8F]; + var swVal = 0, swGX = 0, swGZ = 0; + function swellOf(wx, wz) { + var v = 0, gx = 0, gz = 0, o; + for (o = 0; o < 4; o++) { + var lat = SW_LAT[o], w = SW_W[o], sl = SW_SALT[o]; + var qx = wx / lat, qz = wz / lat; + var i0 = Math.floor(qx), j0 = Math.floor(qz); + var fx = qx - i0, fz = qz - j0; + var sx = fx * fx * (3 - 2 * fx), sz = fz * fz * (3 - 2 * fz); + + var dx = 6 * fx * (1 - fx) / lat, dz = 6 * fz * (1 - fz) / lat; + var a = hash2(i0, j0, sl), b = hash2(i0 + 1, j0, sl), + c = hash2(i0, j0 + 1, sl), d = hash2(i0 + 1, j0 + 1, sl); + var ab = a + (b - a) * sx, cd = c + (d - c) * sx; + v += w * (ab + (cd - ab) * sz); + gx += w * (((b - a) + ((d - c) - (b - a)) * sz) * dx); + gz += w * ((cd - ab) * dz); + } + swVal = v; swGX = gx; swGZ = gz; + } + + var SLOPE_K = 3.9, SLOPE_G = 1; + + var TRK_AZ = 0.62, TRK_SIN = Math.sin(TRK_AZ), TRK_COS = Math.cos(TRK_AZ); + var TRK_PITCH = 128.0, TRK_HALF = 1.03; + + function trkWander(a, k) { + return (CC.vnoise(a * 0.0128 + k * 7.3, 0x4D86) - 0.5) * 26.0 + + (CC.vnoise(a * 0.0345 + k * 3.1, 0x4D87) - 0.5) * 14.0; + } + + var RIL_AZ = -0.44, RIL_SIN = Math.sin(RIL_AZ), RIL_COS = Math.cos(RIL_AZ); + var RIL_PITCH = 330.0, RIL_HALF = 5.5; + + function rilWander(a, k) { + return (CC.vnoise(a * 0.0048 + k * 5.7, 0x4D88) - 0.5) * 76.0 + + (CC.vnoise(a * 0.0135 + k * 2.9, 0x4D89) - 0.5) * 24.0; + } + + var RAY_Q = 300.0, RAY_IN = 26.0, RAY_LEN = 340.0, RAY_SECT = 8.5; + + var CVIS = 968.0; + var CDIR_X = [], CDIR_Z = []; + (function () { + for (var i = 0; i < 16; i++) { + var a = i * 0.3926990817; + CDIR_X.push(Math.cos(a)); CDIR_Z.push(Math.sin(a)); + } + })(); + + var CR_HALO = 0; + + function bowl(wx, wz, dist, q, roll, cq, rmin, rvar, take, chainP, salt) { + + if ((rmin + rvar) * CVIS < dist * dist) return null; + var ci = Math.floor(wx / cq), cj = Math.floor(wz / cq); + var h1 = hash2(ci, cj, salt); + if (h1 >= take) return null; + var cr = rmin + rvar * (h1 / take); + var ccx = (ci + 0.16 + 0.68 * hash2(ci, cj, salt ^ 0x0101)) * cq; + var ccz = (cj + 0.16 + 0.68 * hash2(ci, cj, salt ^ 0x0202)) * cq; + var ddx = wx - ccx, ddz = wz - ccz; + + var hc = hash2(ci, cj, salt ^ 0x0303); + if (hc < chainP) { + var di = (hc / chainP * 16) | 0; if (di > 15) di = 15; + var cdx = CDIR_X[di], cdz = CDIR_Z[di]; + var step = cr * 2.35; + + var j = Math.round((ddx * cdx + ddz * cdz) / step); + if (j < -1) j = -1; else if (j > 2) j = 2; + ddx -= cdx * step * j; ddz -= cdz * step * j; + cr *= 0.62 + 0.30 * hash2(ci * 31 + j, cj, salt ^ 0x0404); } - function specSet(ch, base, dist) { + if (cr * CVIS < dist * dist) return null; - if (dNight > 0.5) return fset(ch, P.pure, 78 + 34 * base); - return fset(ch, P.pure, (dist < CLIFF ? 186 + 50 * base : 150 + 40 * base)); + var rd = Math.sqrt(ddx * ddx + ddz * ddz); + var age = hash2(ci, cj, salt ^ 0x0505); + if (rd > cr) { + + if (age < 0.26 && rd < cr * 1.95) + CR_HALO = 0.62 * (1 - (rd - cr) / (cr * 0.95)); + return null; } - var SUN_FRONT = 1.00, SUN_SIDE = 0.34; - function sunOf(cell) { - var back = 0.18 * dNight; - if (!cell || cell.faceX === undefined) return SUN_SIDE + (0.5 - SUN_SIDE) * dNight; + var fac = rd > 1e-4 ? -(ddx * SUN_X + ddz * SUN_Z) / rd : 0; - var nx = cell.faceX ? -cell.side : 0, nz = cell.faceX ? 0 : -cell.side; - var d = nx * SUN_X + nz * SUN_Z; - var slope = 3.0 + (1.2 - 3.0) * dNight; - var f = clamp(0.5 + slope * d, 0, 1); - return back + (SUN_FRONT - back) * f * f * (3 - 2 * f); + var lip = 0.62 - 1.5 * (SUN_ALT - ALT_LO) + (age < 0.26 ? 0.12 : (age > 0.78 ? -0.44 : 0)); + var cg = hash2(Math.floor(wx * q), Math.floor(wz * q), salt ^ 0x0606); + var rn = rd / cr; + + if (rn < 0.52 && hash2(ci, cj, salt ^ 0x0707) < 0.11) + return (dist < 25 && cg < 0.07) ? rset(fset(G_DOT, P.slate, 16 + cg * 96)) : rblank(); + + if (fac < lip) { + + return (cg < 0.07) ? rset(fset(G_DOT, P.slate, 16 + cg * 96)) : rblank(); } - function darkFace(dist, hv) { - if (dist >= 25) return fset(0, P.shadow, 0); - if (hv > 0.08) return fset(0, P.shadow, 0); - return fset(hv < 0.03 ? G_DOT : G_COMMA, P.slate, 16 + hv * 96); + var cs = fac - lip < 0.30 ? 0.24 + 2.533 * (fac - lip) : 1; + + var fillC = (age < 0.26 ? 0.92 : (age > 0.78 ? 0.52 : 0.76)) * roll; + if (rn > 0.84) fillC *= 1.35; + if (cg < fillC) + return rset(dim(litSet(cg < 0.3 ? G_COMMA : (cg < 0.7 ? G_TICK : G_QUOTE), + 0.45 + 0.55 * (cg / fillC), dist, cg), cs)); + return rblank(); + } + + function rayAt(wx, wz) { + var gi = Math.round(wx / RAY_Q), gj = Math.round(wz / RAY_Q); + var ox = (gi + (hash2(gi, gj, 0x4D8A) - 0.5) * 0.7) * RAY_Q; + var oz = (gj + (hash2(gi, gj, 0x4D8B) - 0.5) * 0.7) * RAY_Q; + var dx = wx - ox, dz = wz - oz; + var r = Math.sqrt(dx * dx + dz * dz); + if (r < RAY_IN || r > RAY_LEN) return 0; + var ax = dx < 0 ? -dx : dx, az = dz < 0 ? -dz : dz, sm = ax + az; + if (sm < 1e-6) return 0; + var oa = dz / sm; + if (dx < 0) oa = oa >= 0 ? 2 - oa : -2 - oa; + var sp = oa * RAY_SECT, si = Math.floor(sp), sf = sp - si; + if (hash2(si, gi * 131 + gj, 0x4D8C) > 0.24) return 0; + + var e = sf < 0.34 ? sf / 0.34 : (sf > 0.66 ? (1 - sf) / 0.34 : 1); + + var rk = r < RAY_IN * 2 ? (r - RAY_IN) / RAY_IN + : 1 - (r - RAY_IN * 2) / (RAY_LEN - RAY_IN * 2); + + return 0.90 * e * rk * (0.45 + 0.55 * CC.vnoise(r * 0.045 + si * 3.7, 0x4D8D)); + } + + function floorTex(wx, wz, dist, t) { + weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + var lod = dist < 22 ? 2 : (dist < 60 ? 1 : 0); + + var q = qOf(dist); + + swellOf(wx, wz); + var sw = swVal; + + var roll = 1 + (0.5 - sw) * 2.6; if (roll < 0.15) roll = 0.15; + var slope = -(swGX * SUN_X + swGZ * SUN_Z) * SLOPE_K * SLOPE_G; + if (slope < -0.45) slope = -0.45; else if (slope > 0.45) slope = 0.45; + + var ta = wx * TRK_SIN + wz * TRK_COS; + var tp = wx * TRK_COS - wz * TRK_SIN; + var tk = Math.round(tp / TRK_PITCH); + var to = tp - (tk * TRK_PITCH + trkWander(ta, tk)); + var tr = (to < 0 ? -to : to) - TRK_HALF; if (tr < 0) tr = -tr; + var trw = 0.17 + dist * 0.0035; + if (tr < trw) { + + var hr = hash2(Math.floor(ta * q), Math.floor(to * 6), 0x4D54); + return rset(litSet(hr < 0.32 ? G_EQ : (hr < 0.58 ? G_DASH : (hr < 0.82 ? G_COMMA : G_COLON)), + 0.40 + hr * 0.45, dist, hr)); } - var STYLE_M = [ - { pitch: 1.35, fill: 0.55, cap: 0.9, hard: 0 }, - { pitch: 0.52, fill: 0.86, cap: 1.0, hard: 1 } - ]; + var rla = wx * RIL_SIN + wz * RIL_COS, rlp = wx * RIL_COS - wz * RIL_SIN; + var rk2 = Math.round(rlp / RIL_PITCH); + var ro = rlp - (rk2 * RIL_PITCH + rilWander(rla, rk2)); + var rw = RIL_HALF * (0.72 + 0.56 * CC.vnoise(rla * 0.019, 0x4D8E)); + var ar = ro < 0 ? -ro : ro; + if (ar < rw) { + var rt = ar / rw; + var wl = (ro > 0 ? 1 : -1) * -(RIL_COS * SUN_X - RIL_SIN * SUN_Z); - var Q_D = [4, 8, 14, 22, 34, 55, 90], - Q_V = [60, 23, 12.5, 7.6, 4.9, 3.1, 1.9, 1.2]; - function qOf(dist) { - for (var i = 0; i < 7; i++) if (dist < Q_D[i]) return Q_V[i]; - return Q_V[7]; + roll *= (0.45 + 0.55 * rt) * (1 + 0.80 * wl * rt); } - function capOf(dist, mul) { - var c = dist * 0.0145 * mul; - return c < 0.08 ? 0.08 : (c > 1.1 ? 1.1 : c); + CR_HALO = 0; + + var cout = bowl(wx, wz, dist, q, roll, 1.45, 0.14, 0.41, 0.38, 0.18, 0x4D6F); + if (cout) return cout; + cout = bowl(wx, wz, dist, q, roll, 5.5, 0.5, 1.9, 0.42, 0.22, 0x4D61); + if (cout) return cout; + cout = bowl(wx, wz, dist, q, roll, 27.0, 3.2, 7.8, 0.26, 0.14, 0x4D68); + if (cout) return cout; + + var dens = 0.34 * (lod === 2 ? 1 : (lod === 1 ? 0.80 : 0.55)); + dens *= 0.94 + 0.5 * wFines; + dens *= roll * (1 + slope) * (1 + CR_HALO); + if (dist < RAY_LEN) dens *= 1 + rayAt(wx, wz); + + if (dens > 0.62) dens = 0.62; + var d1 = hash2(Math.floor(wx * q), Math.floor(wz * q), 0x4D01); + if (d1 < dens) { + var k1 = d1 / dens; + + if (k1 > 0.92) return rset(specSet(G_STAR, (k1 - 0.92) / 0.08, dist)); + return rset(litSet(k1 < 0.34 ? G_DOT : (k1 < 0.68 ? G_COMMA : G_TICK), k1, dist, d1)); } - function facade(u, v, cell, dist, t) { - if (v < 0) v = 0; - weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + if (lod === 2) { + var d2 = hash2(Math.floor(wx * q * 0.5), Math.floor(wz * q * 0.5), 0x4D03); + if (d2 < 0.010 * (1.9 - roll)) return rset(litSet(G_o, 0.9, dist, d2)); + } + return rblank(); + } - var sd = seedOf(cell); - var st = STYLE_M[cell && (cell.style | 0) === 8 ? 1 : 0]; - var h = cell && cell.h ? cell.h : 2; - var sun = sunOf(cell); + var SOUT = { ch: 0, col: 0, lum: 0 }; + function sset(ch, col, lum) { + SOUT.ch = ch; SOUT.col = col; + SOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + return SOUT; + } - var q = qOf(dist); - var hv = hash2(Math.floor(u * q), Math.floor(v * q), sd ^ 0x4D31); + function sky(sx, sy, t) { + weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + var C = cfg(); + var rows = C && C.rows ? C.rows : 60; + var hor = C ? C.horizon : rows * 0.56; + var vs = C && C.skyVScale ? C.skyVScale : 1; + var kk = C && C.skyK ? C.skyK : (rows / 0.7); + var sd = C ? C.skySeed : 0x5EED; - var top = h - h * (0.06 + 0.20 * hash2(Math.floor(u * 0.42), 0, sd ^ 0x4D78)) * - hash2(Math.floor(u * 1.3), 0, sd ^ 0x4D77); - var crest = top - v; - if (crest < 0) return fset(0, P.shadow, 0); + var ey = Math.floor((hor - sy) * vs); + var a = ey / rows; if (a < 0) a = 0; - var tv = hash2(Math.floor(u * q), Math.floor(v * q), sd ^ 0x4D33) * 0.74; - var edge = sun - tv; + var da = sx / kk - SUN_AZ; + da = Math.atan2(Math.sin(da), Math.cos(da)); + var away = Math.abs(da) / Math.PI; - var soft = edge < 0.26 ? 0.24 + 2.923 * edge : 1; - if (edge <= 0) { - - if (st.hard && crest < capOf(dist, 0.7) && dist < 34 && hv < 0.34) - return fset(G_DASH, P.slate, 26 + hv * 40); - return darkFace(dist, hv); - } - - var cap = capOf(dist, st.cap); - if (crest < cap) { - if (st.hard) - return dim(specSet(crest < cap * 0.5 ? G_EQ : G_DASH, 0.55 + hv * 0.45, dist), soft); - - if (hv < 0.34) return dim(specSet(G_QUOTE, hv, dist), soft); - return dim(litSet(G_TICK, 0.7 + hv * 0.3, dist, hv), soft); - } - - var seam = hash2(Math.floor(u / st.pitch), Math.floor(v / (st.pitch * 1.3)), sd ^ 0x4D42); - if (seam < (st.hard ? 0.13 : 0.06)) return fset(0, P.shadow, 0); - - if (hv > st.fill) return fset(0, P.shadow, 0); - var k = hv / st.fill; - - if (st.hard && k > 0.962) return dim(specSet(G_STAR, k, dist), soft); - - if (st.hard) - return dim(litSet(k < 0.30 ? G_8 : (k < 0.62 ? G_PCT : (k < 0.86 ? G_HASH : G_O)), - k, dist, hv), soft); - return dim(litSet(k < 0.34 ? G_DOT : (k < 0.68 ? G_COMMA : G_TICK), k * 0.8, dist, hv), soft); + if (away < 0.040 && a < 0.22) { + var hc = hash2(sx, ey, sd ^ 0x4D22); + if (hc < 0.20 * (1 - a / 0.22)) { + var nearK = 1 - away / 0.040; + return sset(hc < 0.09 ? G_TILDE : G_QUOTE, P.pure, (16 + hc * 300) * nearK * nearK); + } } - var ROUT = { ch: 0, col: 0, lum: 0, mir: 0, rip: 0, wch: 0 }; - function rset(o) { - ROUT.ch = o.ch; ROUT.col = o.col; ROUT.lum = o.lum; + var p = 0.0135 * (0.55 + 0.45 * a) * 1.4; + var hs = hash2(sx, ey, sd ^ 0x4D00); + if (hs >= p) return sset(0, P.shadow, 0); - ROUT.mir = 0; ROUT.rip = 0; ROUT.wch = 0; - return ROUT; - } - function rblank() { return rset(fset(0, P.shadow, 0)); } + var k = hs / p, h2 = hash2(sx, ey, sd ^ 0x4D11); - var STRIDE = 0.72, TRACK = 1.03; + var dm = 1 - 0.22 * dMix; + if (k > 0.965) return sset(G_STAR, P.pure, 168 + h2 * 62); + if (k > 0.93) return sset(G_PLUS, P.ice, (88 + h2 * 62) * dm); + if (k > 0.34) return sset(G_DOT, P.white, (142 + h2 * 46) * dm); + return sset(G_DOT, P.slate, (40 + h2 * 34) * dm); + } - function floorTex(wx, wz, dist, t) { - weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); - var C = cfg(); - var lane = wx - (C ? C.streetX : 4.0); - var al = lane < 0 ? -lane : lane; - var lod = dist < 22 ? 2 : (dist < 60 ? 1 : 0); + var FOG_START_M = 150.0, FOG_END_M = 240.0, FOG_POW_M = 0.45; - var q = qOf(dist); + CC.SurfMoon = { - if (al < 0.62) { - var sp = wz / STRIDE, si = Math.floor(sp), fsp = sp - si; - var hb = hash2(si, 0, 0x4D51); - var foot = (si & 1) ? 0.17 : -0.17; - var off = lane - foot; if (off < 0) off = -off; - if (lod === 2) { - if (fsp < 0.46 && off < 0.14) + airless: 1, + facade: facade, floorTex: floorTex, sky: sky, STYLE: STYLE_M, + fogStart: FOG_START_M, fogEnd: FOG_END_M, fogPow: FOG_POW_M, + sunOf: sunOf, EARTH_AZ: EARTH_AZ, EARTH_ALT: EARTH_ALT }; - return rset(litSet(hb < 0.5 ? G_COLON : G_SEMI, 0.72 + hb * 0.28, dist, hb)); + Object.defineProperty(CC.SurfMoon, 'SUN_AZ', { get: function () { return SUN_AZ; } }); + Object.defineProperty(CC.SurfMoon, 'SUN_X', { get: function () { return SUN_X; } }); + Object.defineProperty(CC.SurfMoon, 'SUN_Z', { get: function () { return SUN_Z; } }); + Object.defineProperty(CC.SurfMoon, 'SUN_ALT', { get: function () { return SUN_ALT; } }); + Object.defineProperty(CC.SurfMoon, 'night', { get: function () { return dNight; } }); - if (fsp < 0.72 && off < 0.30 && hash2(Math.floor(wx * 6), Math.floor(wz * 6), 0x4D52) < 0.16) - return rset(litSet(G_DOT, 0.3, dist, hb)); - return rblank(); - } - if (al < 0.34) { - var hf = hash2(Math.floor(wx * 2.2), Math.floor(wz * 2.2), 0x4D53); - if (hf < 0.62) return rset(litSet(hf < 0.3 ? G_COLON : G_DOT, 0.6 + hf * 0.4, dist, hf)); - } - return rblank(); - } - - var tr = al - TRACK; if (tr < 0) tr = -tr; - if (tr < 0.15) { - var ch = (Math.floor(wz / 0.34) & 1) ? G_EQ : G_DASH; - var hr = hash2(Math.floor(wz * 3), (al * 2) | 0, 0x4D54); - return rset(litSet(ch, 0.35 + hr * 0.45, dist, hr)); - } - - if (lod === 2) { - var CQ = 5.5; - - var ci = Math.floor(wx / CQ), cj = Math.floor(wz / CQ); - var ch1 = hash2(ci, cj, 0x4D61); - if (ch1 < 0.42) { - var ccx = (ci + 0.18 + 0.64 * hash2(ci, cj, 0x4D62)) * CQ; - var ccz = (cj + 0.18 + 0.64 * hash2(ci, cj, 0x4D63)) * CQ; - var ddx = wx - ccx, ddz = wz - ccz; - var cr = 0.5 + 1.9 * (ch1 / 0.42); - var rd = Math.sqrt(ddx * ddx + ddz * ddz); - if (rd < cr) { - - var fac = rd > 1e-4 ? -(ddx * SUN_X + ddz * SUN_Z) / rd : 0; - - var lip = 0.62 - 1.5 * (SUN_ALT - ALT_LO); - var cg = hash2(Math.floor(wx * q), Math.floor(wz * q), 0x4D64); - if (fac < lip) { - - return cg < 0.07 ? rset(fset(G_DOT, P.slate, 16 + cg * 96)) : rblank(); - } - - var cs = fac - lip < 0.30 ? 0.24 + 2.533 * (fac - lip) : 1; - - if (cg < 0.62) - return rset(dim(litSet(cg < 0.3 ? G_COMMA : (cg < 0.7 ? G_TICK : G_QUOTE), - 0.45 + 0.55 * (cg / 0.62), dist, cg), cs)); - return rblank(); - } - } - } - - var dens = 0.34 * (lod === 2 ? 1 : (lod === 1 ? 0.80 : 0.55)); - dens *= 0.94 + 0.5 * wFines; - - var sxq = wx / 9.0, szq = wz / 9.0; - var s0 = Math.floor(sxq), s1 = Math.floor(szq); - var fx = sxq - s0, fz = szq - s1; - fx = fx * fx * (3 - 2 * fx); fz = fz * fz * (3 - 2 * fz); - var n00 = hash2(s0, s1, 0x4D71), n10 = hash2(s0 + 1, s1, 0x4D71); - var n01 = hash2(s0, s1 + 1, 0x4D71), n11 = hash2(s0 + 1, s1 + 1, 0x4D71); - var sw = (n00 + (n10 - n00) * fx) + ((n01 + (n11 - n01) * fx) - (n00 + (n10 - n00) * fx)) * fz; - dens *= 0.55 + 0.90 * sw; - var d1 = hash2(Math.floor(wx * q), Math.floor(wz * q), 0x4D01); - if (d1 < dens) { - var k1 = d1 / dens; - - if (k1 > 0.92) return rset(specSet(G_STAR, (k1 - 0.92) / 0.08, dist)); - return rset(litSet(k1 < 0.34 ? G_DOT : (k1 < 0.68 ? G_COMMA : G_TICK), k1, dist, d1)); - } - - if (lod === 2) { - var d2 = hash2(Math.floor(wx * q * 0.5), Math.floor(wz * q * 0.5), 0x4D03); - if (d2 < 0.010) return rset(litSet(G_o, 0.9, dist, d2)); - } - return rblank(); - } - - var SOUT = { ch: 0, col: 0, lum: 0 }; - function sset(ch, col, lum) { - SOUT.ch = ch; SOUT.col = col; - SOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - return SOUT; - } - - function sky(sx, sy, t) { - weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); - var C = cfg(); - var rows = C && C.rows ? C.rows : 60; - var hor = C ? C.horizon : rows * 0.56; - var vs = C && C.skyVScale ? C.skyVScale : 1; - var kk = C && C.skyK ? C.skyK : (rows / 0.7); - var sd = C ? C.skySeed : 0x5EED; - - var ey = Math.floor((hor - sy) * vs); - var a = ey / rows; if (a < 0) a = 0; - - var da = sx / kk - SUN_AZ; - da = Math.atan2(Math.sin(da), Math.cos(da)); - var away = Math.abs(da) / Math.PI; - - if (away < 0.040 && a < 0.22) { - var hc = hash2(sx, ey, sd ^ 0x4D22); - if (hc < 0.20 * (1 - a / 0.22)) { - var nearK = 1 - away / 0.040; - return sset(hc < 0.09 ? G_TILDE : G_QUOTE, P.pure, (16 + hc * 300) * nearK * nearK); - } - } - - var p = 0.0135 * (0.55 + 0.45 * a) * 1.4; - var hs = hash2(sx, ey, sd ^ 0x4D00); - if (hs >= p) return sset(0, P.shadow, 0); - - var k = hs / p, h2 = hash2(sx, ey, sd ^ 0x4D11); - - var dm = 1 - 0.22 * dMix; - if (k > 0.965) return sset(G_STAR, P.pure, 168 + h2 * 62); - if (k > 0.93) return sset(G_PLUS, P.ice, (88 + h2 * 62) * dm); - if (k > 0.34) return sset(G_DOT, P.white, (142 + h2 * 46) * dm); - return sset(G_DOT, P.slate, (40 + h2 * 34) * dm); - } - - var FOG_START_M = 150.0, FOG_END_M = 240.0, FOG_POW_M = 0.45; - - CC.SurfMoon = { - - airless: 1, - facade: facade, floorTex: floorTex, sky: sky, STYLE: STYLE_M, - fogStart: FOG_START_M, fogEnd: FOG_END_M, fogPow: FOG_POW_M, - sunOf: sunOf, EARTH_AZ: EARTH_AZ, EARTH_ALT: EARTH_ALT }; - - Object.defineProperty(CC.SurfMoon, 'SUN_AZ', { get: function () { return SUN_AZ; } }); - Object.defineProperty(CC.SurfMoon, 'SUN_X', { get: function () { return SUN_X; } }); - Object.defineProperty(CC.SurfMoon, 'SUN_Z', { get: function () { return SUN_Z; } }); - Object.defineProperty(CC.SurfMoon, 'SUN_ALT', { get: function () { return SUN_ALT; } }); - Object.defineProperty(CC.SurfMoon, 'night', { get: function () { return dNight; } }); - - if (!CC.SURFACES) CC.SURFACES = {}; - CC.SURFACES.moon = CC.SurfMoon; + if (!CC.SURFACES) CC.SURFACES = {}; + CC.SURFACES.moon = CC.SurfMoon; })(CC); /* src/surf_west.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise; + var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise, smooth = CC.smooth; - var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), - G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_TILDE = g('~'), - G_PIPE = g('|'), G_SLASH = g('/'), G_PCT = g('%'), G_AMP = g('&'), G_8 = g('8'), - G_0 = g('0'), G_o = g('o'); + var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), + G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_TILDE = g('~'), + G_PIPE = g('|'), G_SLASH = g('/'), G_PCT = g('%'), G_AMP = g('&'), G_8 = g('8'), + G_0 = g('0'), G_o = g('o'), G_HASH = g('#'), G_PLUS = g('+'), G_STAR = g('*'), + G_CARET = g('^'), G_DQ = g('"'); - function cfg() { return CC.Surf ? CC.Surf.cfg : null; } + function cfg() { return CC.Surf ? CC.Surf.cfg : null; } - var SUN_AZ = -0.5; - var SUN_X = Math.sin(SUN_AZ), SUN_Z = Math.cos(SUN_AZ), SUN_ALT = 0.16; + var SUN_AZ = -0.5; + var SUN_X = Math.sin(SUN_AZ), SUN_Z = Math.cos(SUN_AZ), SUN_ALT = 0.16; - function dayAt(t) { - if (t === dT) return; - dT = t; - var D = CC.Daylight; - if (!D) return; - SUN_AZ = D.P.az; SUN_ALT = D.P.alt; - SUN_X = Math.sin(SUN_AZ); SUN_Z = Math.cos(SUN_AZ); - dSun = D.P.sun; dSky = D.P.sky; dWarm = D.P.warm; dLamp = D.P.lamp; dStar = D.P.star; - } - var dT = 1 / 0, dSun = 0.64, dSky = 0.66, dWarm = 0.74, dLamp = 1, dStar = 0; - function dAlt() { return SUN_ALT; } + function dayAt(t) { + if (t === dT) return; + dT = t; + var D = CC.Daylight; + if (!D) return; + SUN_AZ = D.P.az; SUN_ALT = D.P.alt; + SUN_X = Math.sin(SUN_AZ); SUN_Z = Math.cos(SUN_AZ); + dSun = D.P.sun; dSky = D.P.sky; dWarm = D.P.warm; dLamp = D.P.lamp; dStar = D.P.star; + dFill = smooth(clamp((dSky - 0.70) / 0.30, 0, 1)); + } - var SUN_FRONT = 1.00, SUN_BACK = 0.10, SUN_SIDE = 0.42; - function sunOf(cell) { + var dT = 1 / 0, dSun = 0.64, dSky = 0.66, dWarm = 0.74, dLamp = 1, dStar = 0, dFill = 0; + function dAlt() { return SUN_ALT; } - var floor = 0.05 + 0.16 * dSky; - if (!cell || cell.faceX === undefined) return floor + (SUN_SIDE - 0.10) * dSun; + var MAT_SUN = [ + P.sand, P.white, P.ember, P.moss, + P.stone, P.white, P.ember, P.stone, + P.sand, P.white, P.white, P.stone, + P.stone, P.sand, P.sand, P.jade, + P.sand, P.gold, P.moss, P.stone + ]; + var MAT_MID = [ + P.sand, P.stone, P.timber, P.moss, + P.indigo, P.sand, P.timber, P.stone, + P.sand, P.stone, P.sand, P.timber, + P.stone, P.stone, P.timber, P.moss, + P.timber, P.sand, P.moss, P.indigo + ]; + var MAT_SHD = [ + P.timber, P.indigo, P.timber, P.moss, + P.indigo, P.stone, P.timber, P.indigo, + P.timber, P.stone, P.stone, P.indigo, + P.indigo, P.timber, P.stone, P.indigo, + P.timber, P.timber, P.moss, P.indigo + ]; - var nx = cell.faceX ? -cell.side : 0, nz = cell.faceX ? 0 : -cell.side; - var d = nx * SUN_X + nz * SUN_Z; - var split = 1 - 0.65 * clamp(SUN_ALT / 0.95, 0, 1); - var f = clamp(0.5 + 0.62 * d * split, 0, 1); + var SUN_FRONT = 1.00, SUN_BACK = 0.10, SUN_SIDE = 0.42; + function sunOf(cell) { - var direct = (SUN_FRONT - SUN_BACK) * f * f * (3 - 2 * f) * Math.sqrt(dSun); + var floor = 0.05 + 0.16 * dSky; + if (!cell || cell.faceX === undefined) return floor + (SUN_SIDE - 0.10) * dSun; - return clamp(floor + direct * (0.42 + 0.58 * (1 - clamp(SUN_ALT / 0.95, 0, 1))) + - dSun * 0.34 * clamp(SUN_ALT / 0.95, 0, 1), 0, 1.25); + var nx = cell.faceX ? -cell.side : 0, nz = cell.faceX ? 0 : -cell.side; + var d = nx * SUN_X + nz * SUN_Z; + var split = 1 - 0.65 * clamp(SUN_ALT / 0.95, 0, 1); + var f = clamp(0.5 + 0.62 * d * split, 0, 1); + + var direct = (SUN_FRONT - SUN_BACK) * f * f * (3 - 2 * f) * Math.sqrt(dSun); + + return clamp(floor + direct * (0.42 + 0.58 * (1 - clamp(SUN_ALT / 0.95, 0, 1))) + + dSun * 0.34 * clamp(SUN_ALT / 0.95, 0, 1), 0, 1.25); + } + + var wT = 1 / 0, wWet = 1, wRain = 1, wWind = 1, wDust = 0.3, wCloud = 0.1; + function weatherAt(t) { + if (t === wT) return; + wT = t; + var W = CC.Weather; + if (!W) return; + wWet = W.rel('wet'); wRain = W.rel('rain'); wWind = W.rel('wind'); + wDust = W.P.haze; wCloud = W.P.cloud; + } + + function seedOf(cell) { + if (!cell || typeof cell !== 'object') return 0; + if (cell.seed !== undefined) return cell.seed | 0; + return 0; + } + + var STYLE_W = [ + { lap: 0.34, bay: 4.4, gnd: 2.90, up: 2.55, winW: 1.05, winH: 1.35, + shopW: 2.30, shopH: 1.75, rough: 0, vert: 0 }, + { lap: 0.62, bay: 5.2, gnd: 3.20, up: 2.70, winW: 0.90, winH: 1.20, + shopW: 1.90, shopH: 1.60, rough: 0, vert: 1 }, + { lap: 0.28, bay: 4.0, gnd: 3.05, up: 2.60, winW: 1.20, winH: 1.50, + shopW: 2.60, shopH: 1.95, rough: 0, vert: 0 }, + { lap: 0.90, bay: 5.0, gnd: 2.60, up: 2.30, winW: 0.75, winH: 0.95, + shopW: 1.10, shopH: 1.20, rough: 1, vert: 0 }, + { lap: 0.50, bay: 4.6, gnd: 2.85, up: 2.45, winW: 0.85, winH: 1.10, + shopW: 1.40, shopH: 1.45, rough: 1, vert: 0 }, + { lap: 0.42, bay: 5.6, gnd: 2.70, up: 2.40, winW: 0.80, winH: 1.05, + shopW: 1.30, shopH: 1.35, rough: 0, vert: 0 } + ]; + + var INK = [G_TICK, G_DOT, G_UNDER, G_DASH, G_COLON, G_TILDE, G_DQ, G_PLUS, G_EQ, G_HASH, G_PCT]; + function ink(t) { + var i = (t * 11) | 0; + return INK[i < 0 ? 0 : (i > 10 ? 10 : i)]; + } + + var FOUT = { ch: 0, col: 0, lum: 0 }; + function fset(ch, col, lum) { + FOUT.ch = ch; FOUT.col = col; + FOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + return FOUT; + } + + function grain(u, v, sd, lod) { + if (lod < 2) return 1; + var h = hash2(Math.floor(u * 11), Math.floor(v * 11), sd ^ 0x6A11); + return h < 0.14 ? 0.34 : 0.72 + h * 0.56; + } + + function rockFace(u, v, cell, dist, sd) { + var h = cell && cell.h ? cell.h : 12; + var lod = dist < 26 ? 2 : (dist < 60 ? 1 : 0); + var sun = sunOf(cell); + + var wob = vnoise(u * 0.10 + sd * 0.017, 0x7A) * 1.3; + var bandF = (v + wob) / 1.55; + var band = Math.floor(bandF), inB = bandF - band; + var bh = hash2(band, sd & 1023, 0x51C); + + var chan = hash2(Math.floor(u * 0.55), 0, sd ^ 0x2C4); + var shade = chan < 0.22 ? 0.42 : (chan < 0.36 ? 0.72 : 1); + + var crest = h - v; + if (crest < 0.9) { + var k = 1 - crest / 0.9; + return fset(inB < 0.5 ? G_PCT : G_AMP, sun > 0.6 ? P.amber : P.ember, + (26 + 88 * k) * (0.5 + 0.5 * sun) * shade); } - var wT = 1 / 0, wWet = 1, wRain = 1, wWind = 1, wDust = 0.3, wCloud = 0.1; - function weatherAt(t) { - if (t === wT) return; - wT = t; - var W = CC.Weather; - if (!W) return; - wWet = W.rel('wet'); wRain = W.rel('rain'); wWind = W.rel('wind'); - wDust = W.P.haze; wCloud = W.P.cloud; + if (inB < 0.13) { + return fset(bh < 0.5 ? G_DASH : G_UNDER, P.slate, + (13 + bh * 15) * shade * (0.55 + 0.45 * sun)); } - function seedOf(cell) { - if (!cell || typeof cell !== 'object') return 0; - if (cell.seed !== undefined) return cell.seed | 0; - return 0; + var rd = 0.20 + 0.12 * bh; + rd += (0.95 - rd) * dFill; + if (lod > 0 && hash2(Math.floor(u * 3.1), Math.floor(v * 2.7), sd ^ 0x9B) < rd) { + var rn = (10 + bh * 16) * shade * (0.5 + 0.5 * sun); + var rday = (30 + 150 * sun * sun + bh * 40) * shade; + var rcol = P.slate; + if (dFill > 0.002 && hash2(Math.floor(u * 1.9), Math.floor(v * 1.9), sd ^ 0x7D3) < dFill) + rcol = sun > 0.66 && bh > 0.55 ? (bh > 0.80 ? P.sand : P.ember) + : (bh < 0.30 ? P.timber : P.stone); + else if (sun > 0.6 && bh > 0.6) rcol = P.ember; + return fset(bh < 0.4 ? G_COLON : (bh < 0.75 ? G_PCT : G_AMP), rcol, + rn + (rday - rn) * dFill); + } + return fset(0, P.shadow, 0); + } + + function facade(u, v, cell, dist, t) { + if (v < 0) v = 0; + weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + var sd = seedOf(cell); + if (cell && cell.style === 6) return rockFace(u, v, cell, dist, sd); + + var st = STYLE_W[cell ? (((cell.style | 0) % 6 + 6) % 6) : 0]; + var h = cell && cell.h ? cell.h : 6; + var lit = cell && typeof cell.litRate === 'number' ? cell.litRate : 0.1; + var hue = cell && typeof cell.hue === 'number' ? cell.hue : P.slate; + var accent = cell && typeof cell.accent === 'number' ? cell.accent : P.warm; + var sun = sunOf(cell); + var lod = dist < 20 ? 2 : (dist < 46 ? 1 : 0); + var gr = grain(u, v, sd, lod); + + var mh = hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x1D5); + var dayMat = mh < dFill; + var ms = dFill > 0.002 ? mh / dFill : 0; + + var k = clamp((sun - 0.22) / 0.52, 0, 1); + var mat = ms < 0.72 * k * k ? MAT_SUN[hue] + : (ms < 0.72 * k * k + 0.24 + 0.20 * k ? MAT_MID[hue] : MAT_SHD[hue]); + + var litHue = dayMat ? mat + : ((hue === P.warm || hue === P.white || hue === P.ember) ? hue : P.amber); + var sunHue = dayMat ? mat : (sun >= 0.62 ? P.amber : litHue); + + var shdHue = dayMat ? MAT_SHD[hue] : P.slate; + + if (h - v < 0.34) { + return fset(G_EQ, sun >= 0.62 ? sunHue : (sun > 0.30 ? litHue : shdHue), + (sun >= 0.62 ? 214 : (sun > 0.30 ? 82 : 32)) * gr); } - var STYLE_W = [ - { lap: 0.34, bay: 4.4, gnd: 2.90, up: 2.55, winW: 1.05, winH: 1.35, - shopW: 2.30, shopH: 1.75, rough: 0, vert: 0 }, - { lap: 0.62, bay: 5.2, gnd: 3.20, up: 2.70, winW: 0.90, winH: 1.20, - shopW: 1.90, shopH: 1.60, rough: 0, vert: 1 }, - { lap: 0.28, bay: 4.0, gnd: 3.05, up: 2.60, winW: 1.20, winH: 1.50, - shopW: 2.60, shopH: 1.95, rough: 0, vert: 0 }, - { lap: 0.90, bay: 5.0, gnd: 2.60, up: 2.30, winW: 0.75, winH: 0.95, - shopW: 1.10, shopH: 1.20, rough: 1, vert: 0 }, - { lap: 0.50, bay: 4.6, gnd: 2.85, up: 2.45, winW: 0.85, winH: 1.10, - shopW: 1.40, shopH: 1.45, rough: 1, vert: 0 }, - { lap: 0.42, bay: 5.6, gnd: 2.70, up: 2.40, winW: 0.80, winH: 1.05, - shopW: 1.30, shopH: 1.35, rough: 0, vert: 0 } - ]; - - var FOUT = { ch: 0, col: 0, lum: 0 }; - function fset(ch, col, lum) { - FOUT.ch = ch; FOUT.col = col; - FOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - return FOUT; + if (h - v < 0.62) { + if (dFill <= 0.002) return fset(0, P.shadow, 0); + var wr = hash2(Math.floor(u * 4.3), 0, sd ^ 0x3E9); + if (wr > 0.86 * dFill) return fset(0, P.shadow, 0); + return fset(wr < 0.30 ? G_PIPE : G_COLON, wr < 0.50 ? P.timber : shdHue, + (12 + 54 * sun) * gr); } - function grain(u, v, sd, lod) { - if (lod < 2) return 1; - var h = hash2(Math.floor(u * 11), Math.floor(v * 11), sd ^ 0x6A11); - return h < 0.14 ? 0.34 : 0.72 + h * 0.56; + var bay = Math.floor(u / st.bay), fu = u / st.bay - bay; + var bh = hash2(bay, sd, 0x3F1); + + if (v > st.gnd && v < st.gnd + 0.30) { + if (dFill <= 0.002) return fset(0, P.shadow, 0); + + var pz = hash2(Math.floor(u * 3.3), Math.floor(v * 6), sd ^ 0x91); + if (pz > 0.82 * dFill) return fset(0, P.shadow, 0); + return fset(pz < 0.5 ? G_UNDER : G_DASH, P.indigo, (14 + 38 * dSky) * gr); + } + if (v > st.gnd + 0.30 && v < st.gnd + 0.52) + return fset(G_DASH, sun >= 0.62 ? sunHue : shdHue, (sun >= 0.62 ? 74 : 22) * gr); + + if (v <= st.gnd) { + + var doorL = bh < 0.5; + var dw = 0.34, ww = st.shopW / st.bay; + var d0 = doorL ? 0.10 : 0.86 - dw, d1 = d0 + dw; + var w0 = doorL ? 0.52 : 0.10, w1 = w0 + ww; if (w1 > 0.90) w1 = 0.90; + + var open = hash2(bay, sd, 0x5E1) < clamp(lit * 3.1, 0.05, 0.62); + + if (v < 2.15 && fu > d0 && fu < d1) { + + if (fu - d0 < 0.05 || d1 - fu < 0.05 || v > 2.02) + return fset(G_PIPE, shdHue, (20 + 44 * dFill * sun) * gr); + if (open && dFill > 0.002 && + hash2(Math.floor(u * 3.9), Math.floor(v * 3.9), sd ^ 0x2E7) < dFill) { + + var dv2 = 1 - v / 2.15; + return fset(v < 0.30 ? G_EQ : (dv2 > 0.62 ? G_COLON : G_DOT), + v < 0.30 ? P.timber : P.indigo, + v < 0.30 ? 96 : (34 + 44 * dv2) * (0.5 + 0.5 * dSky)); + } + if (!open) { + + if (dFill <= 0.002) return fset(0, P.shadow, 0); + var dz = (fu - d0) / dw * 5; + return fset(Math.abs(v - 1.18) < 0.09 ? G_EQ : (dz - Math.floor(dz) < 0.16 ? G_PIPE : G_UNDER), + P.timber, (16 + 66 * sun) * gr); + } + var dk = 1 - v / 2.15; + return fset(v < 0.35 ? G_UNDER : G_8, P.warm, (96 + 74 * dk) * (0.7 + 0.5 * gr)); + } + + var wv0 = 0.80, wv1 = wv0 + st.shopH; + if (v > wv0 && v < wv1 && fu > w0 && fu < w1) { + + if (v - wv0 < 0.14 || wv1 - v < 0.14 || fu - w0 < 0.04 || w1 - fu < 0.04) + return fset(G_EQ, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate), + ((sun >= 0.62 ? 66 : 26) + 78 * dFill * sun) * gr); + if (!open) { + + var bd = Math.floor((v * 1.6 + fu * 2.2) * 2.4); + if (bd & 1) return fset(G_SLASH, dayMat ? P.timber : P.slate, + (15 + 74 * dFill * sun) * gr); + + return dFill <= 0.002 ? fset(0, P.shadow, 0) + : fset(G_DOT, P.indigo, (10 + 44 * dSky) * gr); + } + + var mull = Math.abs(fu - (w0 + w1) * 0.5) < 0.022; + if (mull) return fset(G_PIPE, shdHue, 30 + 52 * dFill * sun); + var gl = hash2(Math.floor(u * 2.6), Math.floor(v * 2.6), sd ^ 0x77); + + if (dFill > 0.002 && + hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x6A3) < dFill) { + var rv = (v - wv0) / st.shopH; + if (rv > 0.58) { + var rk = (rv - 0.58) / 0.42; + return fset(ink(0.44 + 0.38 * rk + 0.14 * (gl - 0.5)), + gl < 0.62 ? P.white : P.ice, (108 + 84 * rk) * (0.5 + 0.5 * dSky)); + } + + if (gl > 0.86) return fset(G_UNDER, P.sand, (86 + 54 * gl) * (0.4 + 0.6 * dSky)); + return fset(gl < 0.34 ? G_HASH : (gl < 0.66 ? G_COLON : G_DOT), + gl < 0.34 ? P.timber : P.indigo, + (52 + 78 * gl) * (0.5 + 0.5 * dSky)); + } + if (gl < 0.17) return fset(G_0, P.shadow, 0); + + if (gl > 0.62) return fset(gl > 0.90 ? G_o : G_8, P.amber, (208 + gl * 46) * gr); + return fset(gl < 0.42 ? G_8 : G_0, gl > 0.56 ? accent : P.warm, (120 + gl * 96) * gr); + } + + return board(u, v, st, sd, lod, gr, sun * (0.42 + 0.20 * dFill), sunHue, shdHue, dayMat, dist); } - function rockFace(u, v, cell, dist, sd) { - var h = cell && cell.h ? cell.h : 12; - var lod = dist < 26 ? 2 : (dist < 60 ? 1 : 0); - var sun = sunOf(cell); + var uy = v - (st.gnd + 0.52); + var storey = Math.floor(uy / st.up); + var sv = uy - storey * st.up; - var wob = vnoise(u * 0.10 + sd * 0.017, 0x7A) * 1.3; - var bandF = (v + wob) / 1.55; - var band = Math.floor(bandF), inB = bandF - band; - var bh = hash2(band, sd & 1023, 0x51C); + if (storey >= 0 && storey < 2 && sv > 0.55 && sv < 0.55 + st.winH) { + var cw = st.winW / st.bay, c0 = 0.5 - cw * 0.5, c1 = 0.5 + cw * 0.5; + if (fu > c0 && fu < c1) { + var wh = hash2(bay * 7 + storey, sd, 0x8D2); + if (sv - 0.55 < 0.11 || 0.55 + st.winH - sv < 0.11 || fu - c0 < 0.05 || c1 - fu < 0.05) + return fset(G_DASH, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate), + ((sun >= 0.62 ? 58 : 22) + 82 * dFill * sun) * gr); + if (wh < lit) { + var lg = hash2(Math.floor(u * 3.4), Math.floor(v * 3.4), sd ^ 0xA3); - var chan = hash2(Math.floor(u * 0.55), 0, sd ^ 0x2C4); - var shade = chan < 0.22 ? 0.42 : (chan < 0.36 ? 0.72 : 1); - - var crest = h - v; - if (crest < 0.9) { - var k = 1 - crest / 0.9; - return fset(inB < 0.5 ? G_PCT : G_AMP, sun > 0.6 ? P.amber : P.ember, - (26 + 88 * k) * (0.5 + 0.5 * sun) * shade); + if (dFill > 0.002 && + hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x6A3) < dFill) { + if (Math.abs(sv - (0.55 + st.winH * 0.5)) < 0.06) + return fset(G_DASH, P.white, (30 + 96 * sun) * gr); + if (lg > 0.80) return fset(G_UNDER, P.white, (96 + 60 * lg) * (0.4 + 0.6 * dSky)); + return fset(lg < 0.40 ? G_COLON : G_DOT, P.indigo, + (34 + 62 * dSky + lg * 34) * gr); + } + if (lg < 0.16) return fset(G_o, P.shadow, 0); + if (lg > 0.66) return fset(lg > 0.92 ? G_o : G_8, P.amber, (204 + lg * 50) * gr); + return fset(G_8, P.warm, (112 + lg * 84) * gr); } - if (inB < 0.13) { - return fset(bh < 0.5 ? G_DASH : G_UNDER, P.slate, - (13 + bh * 15) * shade * (0.55 + 0.45 * sun)); - } - if (lod > 0 && hash2(Math.floor(u * 3.1), Math.floor(v * 2.7), sd ^ 0x9B) < 0.20 + 0.12 * bh) { - return fset(bh < 0.4 ? G_COLON : (bh < 0.75 ? G_PCT : G_AMP), - sun > 0.6 && bh > 0.6 ? P.ember : P.slate, - (10 + bh * 16) * shade * (0.5 + 0.5 * sun)); - } - return fset(0, P.shadow, 0); + var dg = hash2(Math.floor(u * 2.2), Math.floor(v * 2.2), sd ^ 0xB5); + if (dg < 0.30) return fset(G_COLON, P.ice, (20 + 46 * dFill) * gr); + + if (dFill <= 0.002) return fset(0, P.shadow, 0); + if (Math.abs(sv - (0.55 + st.winH * 0.5)) < 0.06) + return fset(G_DASH, P.white, (30 + 96 * sun) * gr); + return fset(dg < 0.62 ? G_COLON : G_DOT, P.indigo, (18 + 50 * dSky + dg * 26) * gr); + } + + if (st.rough === 0 && (sv - 0.55 < 0.10 || 0.55 + st.winH - sv < 0.10) && bh > 0.62) + return fset(G_DASH, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate), + ((sun >= 0.62 ? 50 : 18) + 76 * dFill * sun) * gr); } - function facade(u, v, cell, dist, t) { - if (v < 0) v = 0; - weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); - var sd = seedOf(cell); - if (cell && cell.style === 6) return rockFace(u, v, cell, dist, sd); + var gs = hash2(sd, 0x51, 0x6C7); + if (dFill > 0.002 && gs < 0.17 && h > 6.2) { + var gy0 = st.gnd + 1.35, gy1 = gy0 + 1.60; + if (v > gy0 && v < gy1 && h - v > 1.10) { + var gu = u / 0.62, fgu = gu - Math.floor(gu); + var gvb = Math.floor((v - gy0) / 0.40); + var gw = hash2(Math.floor(gu), gvb, sd ^ 0x5A3); - var st = STYLE_W[cell ? (((cell.style | 0) % 6 + 6) % 6) : 0]; - var h = cell && cell.h ? cell.h : 6; - var lit = cell && typeof cell.litRate === 'number' ? cell.litRate : 0.1; - var hue = cell && typeof cell.hue === 'number' ? cell.hue : P.slate; - var accent = cell && typeof cell.accent === 'number' ? cell.accent : P.warm; - var sun = sunOf(cell); - var lod = dist < 20 ? 2 : (dist < 46 ? 1 : 0); - var gr = grain(u, v, sd, lod); - - var litHue = (hue === P.warm || hue === P.white || hue === P.ember) ? hue : P.amber; - var sunHue = sun >= 0.62 ? P.amber : litHue; - - if (h - v < 0.34) { - return fset(G_EQ, sun >= 0.62 ? P.amber : (sun > 0.30 ? litHue : P.slate), - (sun >= 0.62 ? 214 : (sun > 0.30 ? 82 : 32)) * gr); - } - - if (h - v < 0.62) return fset(0, P.shadow, 0); - - var bay = Math.floor(u / st.bay), fu = u / st.bay - bay; - var bh = hash2(bay, sd, 0x3F1); - - if (v > st.gnd && v < st.gnd + 0.30) return fset(0, P.shadow, 0); - if (v > st.gnd + 0.30 && v < st.gnd + 0.52) - return fset(G_DASH, sun >= 0.62 ? P.amber : P.slate, (sun >= 0.62 ? 74 : 22) * gr); - - if (v <= st.gnd) { - - var doorL = bh < 0.5; - var dw = 0.34, ww = st.shopW / st.bay; - var d0 = doorL ? 0.10 : 0.86 - dw, d1 = d0 + dw; - var w0 = doorL ? 0.52 : 0.10, w1 = w0 + ww; if (w1 > 0.90) w1 = 0.90; - - var open = hash2(bay, sd, 0x5E1) < clamp(lit * 3.1, 0.05, 0.62); - - if (v < 2.15 && fu > d0 && fu < d1) { - - if (fu - d0 < 0.05 || d1 - fu < 0.05 || v > 2.02) - return fset(G_PIPE, P.slate, 20 * gr); - if (!open) return fset(0, P.shadow, 0); - var dk = 1 - v / 2.15; - return fset(v < 0.35 ? G_UNDER : G_8, P.warm, (96 + 74 * dk) * (0.7 + 0.5 * gr)); - } - - var wv0 = 0.80, wv1 = wv0 + st.shopH; - if (v > wv0 && v < wv1 && fu > w0 && fu < w1) { - - if (v - wv0 < 0.14 || wv1 - v < 0.14 || fu - w0 < 0.04 || w1 - fu < 0.04) - return fset(G_EQ, sun >= 0.62 ? P.white : P.slate, (sun >= 0.62 ? 66 : 26) * gr); - if (!open) { - - var bd = Math.floor((v * 1.6 + fu * 2.2) * 2.4); - return (bd & 1) ? fset(G_SLASH, P.slate, 15 * gr) : fset(0, P.shadow, 0); - } - - var mull = Math.abs(fu - (w0 + w1) * 0.5) < 0.022; - if (mull) return fset(G_PIPE, P.slate, 30); - var gl = hash2(Math.floor(u * 2.6), Math.floor(v * 2.6), sd ^ 0x77); - if (gl < 0.17) return fset(G_0, P.shadow, 0); - - if (gl > 0.62) return fset(gl > 0.90 ? G_o : G_8, P.amber, (208 + gl * 46) * gr); - return fset(gl < 0.42 ? G_8 : G_0, gl > 0.56 ? accent : P.warm, (120 + gl * 96) * gr); - } - - return board(u, v, st, sd, lod, gr, sun * 0.42, sunHue, dist); - } - - var uy = v - (st.gnd + 0.52); - var storey = Math.floor(uy / st.up); - var sv = uy - storey * st.up; - - if (storey >= 0 && storey < 2 && sv > 0.55 && sv < 0.55 + st.winH) { - var cw = st.winW / st.bay, c0 = 0.5 - cw * 0.5, c1 = 0.5 + cw * 0.5; - if (fu > c0 && fu < c1) { - var wh = hash2(bay * 7 + storey, sd, 0x8D2); - if (sv - 0.55 < 0.11 || 0.55 + st.winH - sv < 0.11 || fu - c0 < 0.05 || c1 - fu < 0.05) - return fset(G_DASH, sun >= 0.62 ? P.white : P.slate, - (sun >= 0.62 ? 58 : 22) * gr); - if (wh < lit) { - var lg = hash2(Math.floor(u * 3.4), Math.floor(v * 3.4), sd ^ 0xA3); - if (lg < 0.16) return fset(G_o, P.shadow, 0); - if (lg > 0.66) return fset(lg > 0.92 ? G_o : G_8, P.amber, (204 + lg * 50) * gr); - return fset(G_8, P.warm, (112 + lg * 84) * gr); - } - - if (hash2(Math.floor(u * 2.2), Math.floor(v * 2.2), sd ^ 0xB5) < 0.30) - return fset(G_COLON, P.ice, 20 * gr); - return fset(0, P.shadow, 0); - } - - if (st.rough === 0 && (sv - 0.55 < 0.10 || 0.55 + st.winH - sv < 0.10) && bh > 0.62) - return fset(G_DASH, sun >= 0.62 ? P.white : P.slate, (sun >= 0.62 ? 50 : 18) * gr); - } - - return board(u, v, st, sd, lod, gr, sun, sunHue, dist); + var inkP = (gvb === 0 || gvb === 3) ? 0.80 : 0.42; + if (fgu < 0.58 && gw < inkP && + hash2(Math.floor(u * 3.4), Math.floor(v * 3.4), sd ^ 0x9E1) < 0.74 * dFill) + return fset(gw < 0.34 ? G_HASH : G_8, + gs < 0.085 ? P.ember : P.white, (54 + 128 * sun + gw * 30) * gr); + } } - function board(u, v, st, sd, lod, gr, sun, sunHue, dist) { - if (st.rough) { + return board(u, v, st, sd, lod, gr, sun, sunHue, shdHue, dayMat, dist); + } - var m = hash2(Math.floor(u * 2.4), Math.floor(v * 2.4), sd ^ 0x4C1); - var dens = 0.10 + 0.26 * sun; - if (m > dens) return fset(0, P.shadow, 0); - return fset(m < dens * 0.4 ? G_QUOTE : G_COLON, - sun >= 0.62 ? sunHue : P.slate, (10 + 62 * sun + m * 40) * gr); - } + function board(u, v, st, sd, lod, gr, sun, sunHue, shdHue, dayMat, dist) { + if (st.rough) { - var lap = st.lap * (lod === 2 ? 1 : (lod === 1 ? 2 : 4)); - if (st.vert) { + var m = hash2(Math.floor(u * 2.4), Math.floor(v * 2.4), sd ^ 0x4C1); - var bx = u / (lap * 1.4), fbx = bx - Math.floor(bx); - if (fbx > 0.14) { - return (sun >= 0.62 && hash2(Math.floor(u * 1.7), Math.floor(v * 1.7), sd ^ 0x2A) < 0.12) - ? fset(G_QUOTE, sunHue, 26 * gr) : fset(0, P.shadow, 0); - } - return fset(G_PIPE, sun >= 0.62 ? sunHue : P.slate, (12 + 58 * sun) * gr); - } + var mdens = 0.10 + 0.26 * sun; + mdens += (0.94 - mdens) * dFill; + if (m > mdens) return fset(0, P.shadow, 0); + var mn = 10 + 62 * sun + m * 40; - var bv = v / lap, fbv = bv - Math.floor(bv); - var wob = hash2(Math.floor(u * 1.3), Math.floor(v / lap), sd ^ 0x31); + var md = 40 + 44 * dSky + 184 * sun * sun + 44 * m; - if (sun >= 0.62) { - var body = hash2(Math.floor(u * 2.4), Math.floor(v * 2.4), sd ^ 0x66); - if (fbv <= 0.30) - return fset(wob < 0.22 ? G_UNDER : G_DASH, sunHue, (176 + wob * 68) * gr); - if (body < 0.62) - return fset(body < 0.20 ? G_DASH : (body < 0.44 ? G_UNDER : G_TICK), sunHue, - (124 + body * 74) * gr); - return fset(0, P.shadow, 0); - } - - if (fbv > 0.30) { - - if (lod === 2 && hash2(Math.floor(u * 2.8), Math.floor(v * 2.8), sd ^ 0x66) < 0.10) - return fset(G_DOT, P.slate, (10 + 46 * sun) * gr); - return fset(0, P.shadow, 0); - } - - return fset(wob < 0.22 ? G_UNDER : G_DASH, P.slate, (13 + 74 * sun + wob * 22) * gr); + return fset(dayMat ? ink(0.32 + 0.76 * sun * sun + 0.26 * (m / mdens - 0.5)) + : (m < mdens * (0.40 - 0.12 * dFill) ? G_QUOTE + : (m < mdens * (1 - 0.38 * dFill) ? G_COLON : G_DOT)), + sun >= 0.62 ? sunHue : shdHue, (mn + (md - mn) * dFill) * gr); } - var ROUT = { ch: 0, col: 0, lum: 0, mir: 0, rip: 0, wch: 0 }; - var mirNow = 0, ripNow = 0, wchNow = 0; - function rset(ch, col, lum) { - ROUT.ch = ch; ROUT.col = col; - ROUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - ROUT.mir = mirNow; ROUT.rip = ripNow; ROUT.wch = wchNow; - return ROUT; + var lap = st.lap * (lod === 2 ? 1 : (lod === 1 ? 2 : 4)); + if (st.vert) { + + var bx = u / (lap * 1.4), fbx = bx - Math.floor(bx); + if (fbx > 0.14) { + return (sun >= 0.62 && hash2(Math.floor(u * 1.7), Math.floor(v * 1.7), sd ^ 0x2A) < 0.12) + ? fset(G_QUOTE, sunHue, 26 * gr) + : fillCell(u, v, sd, gr, sun, sun >= 0.62 ? sunHue : shdHue, lod); + } + + var dark = fbx > 0.085 && dFill > 0.002 && lod === 2; + return fset(G_PIPE, sun >= 0.62 && !dark ? sunHue : shdHue, + ((12 + 58 * sun) + ((dark ? 30 : 128) + 110 * sun * sun - 12 - 58 * sun) * dFill) * gr); } - var BOARDWALK = 1.72; + var bv = v / lap, fbv = bv - Math.floor(bv); + var wob = hash2(Math.floor(u * 1.3), Math.floor(v / lap), sd ^ 0x31); - function inCross(C, wz) { - if (!C.xn) return 0; - var i = Math.round((wz - C.xz0) / (C.xpitch || 26)); - if (i < 0) i = 0; else if (i >= C.xn) i = C.xn - 1; - var d = wz - C.xc[i]; if (d < 0) d = -d; - if (d <= C.xw[i] + 1.1) return 1; + if (lod === 2 && dFill > 0.002) { + var course = Math.floor(v / lap); - if (i > 0) { d = wz - C.xc[i - 1]; if (d < 0) d = -d; if (d <= C.xw[i - 1] + 1.1) return 1; } - if (i < C.xn - 1) { d = wz - C.xc[i + 1]; if (d < 0) d = -d; if (d <= C.xw[i + 1] + 1.1) return 1; } - return 0; + var ju = (u + hash2(course, sd, 0x4B7) * 3.7) / 4.1; + var fju = ju - Math.floor(ju); + if (fju < 0.045 && hash2(Math.floor(ju), course, sd ^ 0x7C1) < dFill) + return fset(G_PIPE, shdHue, (26 + 74 * sun * sun) * gr); + var stud = u / 0.61, fst = stud - Math.floor(stud); + if (fst < 0.10 && fbv > 0.30 && fbv < 0.52 && + hash2(Math.floor(stud), course, sd ^ 0x2B9) < 0.44 * dFill) + return fset(G_COLON, P.timber, (22 + 62 * sun) * gr); } - function floorTex(wx, wz, dist, t) { - weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); - var C = cfg(); - var half = C ? C.half : 3.1; - var lane = wx - (C ? C.streetX : 4.0); - var al = lane < 0 ? -lane : lane; - var lod = dist < 20 ? 2 : (dist < 46 ? 1 : 0); - mirNow = 0; ripNow = 0; wchNow = 0; + if (sun >= 0.62) { + var body = hash2(Math.floor(u * 2.4), Math.floor(v * 2.4), sd ^ 0x66); - var comp = (C && C.swap) ? SUN_Z : SUN_X; - var lit = -lane * comp; - var sunSide = lit > 0.4 ? 1 : (lit < -0.4 ? 0 : (Math.abs(comp) < 0.35 ? 1 : 0)); - - if (al > half && al < half + BOARDWALK) { - if (inCross(C, wz)) { - - } else { - var into = al - half; - - if (into < 0.16) - return rset(G_UNDER, sunSide ? P.amber : P.white, (sunSide ? 214 : 60) * (0.8 + 0.4 * hash2((wz * 3) | 0, 0, 0x11))); - - var pj = wz / 0.92, fpj = pj - Math.floor(pj); - var pw = hash2(Math.floor(pj), (al * 2) | 0, 0x5B); - if (fpj < 0.10) - return rset(G_DASH, P.slate, (14 + pw * 12)); - if (lod === 2 && pw < 0.10) - return rset(pw < 0.04 ? G_COMMA : G_DOT, P.slate, 12 + pw * 60); - - if (sunSide) return rset(G_UNDER, P.white, (62 + pw * 40)); - return (pw < 0.30) ? rset(G_UNDER, P.slate, 12 + pw * 20) : rset(0, P.shadow, 0); - } - } - - if (al >= half + BOARDWALK) { - if (lod === 0) return rset(0, P.shadow, 0); - var og = hash2(Math.floor(wx * 1.6), Math.floor(wz * 1.6), 0x2D9); - if (og > 0.14) return rset(0, P.shadow, 0); - return rset(og < 0.05 ? G_COMMA : G_DOT, P.slate, 10 + og * 60); - } - - var n = al / half; - - var wet = wWet * 1.05; - var rut = 0; - if (lod > 0) { - - var rc = 0.44 + vnoise(wz * 0.055, 0x3B) * 0.10; - var dr = Math.abs(n - rc); - rut = dr < 0.075 ? 1 - dr / 0.075 : 0; - } - - if (rut > 0.25 && wet > 0.45) { - - var wsurf = rut * clamp(wet - 0.4, 0, 1); - if (wsurf > 0.12) { - mirNow = clamp(wsurf * 1.25, 0, 1); - ripNow = CC.reducedMotion ? 0 : Math.sin(wz * 1.7 + t * 1.4) * 0.9 * wWind; - wchNow = G_TILDE; - var ws = hash2(Math.floor(wx * 3), Math.floor(wz * 3), 0x71C); - return rset(ws < 0.5 ? G_TILDE : G_SEMI, P.slate, 12 + ws * 22); - } - } - - if (rut > 0.22) { - var rs = hash2(Math.floor(wx * (lod === 2 ? (dist < 9 ? 6.2 : 3.0) : 1.7)), - Math.floor(wz * (lod === 2 ? (dist < 9 ? 6.2 : 3.0) : 1.7)), 0x18F); - var rd = (0.34 + 0.42 * rut) * (lod === 2 ? 1 : 0.8); - if (rs < rd) - return rset(rs < 0.14 ? G_UNDER : (rs < 0.34 ? G_COMMA : G_DOT), - sunSide ? P.white : P.slate, - (26 + rs * 150) * rut * (sunSide ? 1.15 : 0.72)); - - if (lod === 2 && dist > 8 && rs > 0.988) return rset(G_o, P.slate, 30 + (1 - rs) * 3200); - return rset(0, P.shadow, 0); - } - - var sideK = 0.25 + 0.75 * clamp(1 - dAlt() / 0.95, 0, 1); - - var lightK = clamp(0.18 + 0.62 * dSky + 0.26 * dSun, 0, 1.0); - var sideBias = sunSide ? (1 + 0.25 * sideK) : (1 - 0.28 * sideK); - var dens = (0.42 - 0.20 * n * n) * sideBias * lightK * - (lod === 2 ? 1 : (lod === 1 ? 0.82 : 0.6)); - - dens *= (0.82 + 0.5 * wDust) * (1 - 0.45 * clamp(wet - 0.3, 0, 1)); - - var q = lod === 2 ? (dist < 9 ? 5.6 : 2.6) : (lod === 1 ? 1.5 : 0.85); - var d1 = hash2(Math.floor(wx * q), Math.floor(wz * q), 0x4A7); - if (d1 < dens) { - var hot = d1 < dens * 0.16 && sunSide; - - var k1 = d1 / dens; - - var dayGround = dSun > 0.55; - return rset(k1 < 0.3 ? G_DOT : (k1 < 0.62 ? G_COMMA : G_TICK), - hot ? P.amber : ((sunSide || dayGround) ? P.white : P.slate), - (hot ? 132 : 22 + k1 * 128) * (sunSide ? 1 : 0.78) * - (0.6 + 0.7 * lightK + 0.9 * dSun)); - } - - if (lod === 2) { - var d2 = hash2(Math.floor(wx * q * 0.5), Math.floor(wz * q * 0.5), 0x6E3); - if (d2 < 0.014) return rset(G_o, P.slate, 26 + d2 * 1300); - if (d2 > 0.990) return rset(G_QUOTE, P.spring, 22 + (1 - d2) * 1300); - } - return rset(0, P.shadow, 0); + if (fbv <= 0.30) { + var lapN = 176 + wob * 68; + var lapD = 42 + 96 * sun * sun + wob * 30; + return fset(wob < 0.22 ? G_UNDER : G_DASH, + dFill > 0.5 ? shdHue : sunHue, (lapN + (lapD - lapN) * dFill) * gr); + } + if (body < 0.62) + return fset(dayMat ? ink(0.34 + 0.72 * sun * sun + 0.28 * (body / 0.62 - 0.5)) + : (body < 0.20 ? G_DASH : (body < 0.44 ? G_UNDER : G_TICK)), sunHue, + ((124 + body * 74) + + ((58 + 46 * dSky + 168 * sun * sun + body * 40) - 124 - body * 74) * dFill) * gr); + return fillCell(u, v, sd, gr, sun, sunHue, lod); } - var SOUT = { ch: 0, col: 0, lum: 0 }; - function sset(ch, col, lum) { - SOUT.ch = ch; SOUT.col = col; - SOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); - return SOUT; + if (fbv > 0.30) { + + if (lod === 2 && hash2(Math.floor(u * 2.8), Math.floor(v * 2.8), sd ^ 0x66) < 0.10) + return fset(G_DOT, shdHue, (10 + 46 * sun) * gr); + return fillCell(u, v, sd, gr, sun, shdHue, lod); } - function sky(sx, sy, t) { - weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); - var C = cfg(); - var rows = C && C.rows ? C.rows : 60; - var hor = C ? C.horizon : rows * 0.56; - var vs = C && C.skyVScale ? C.skyVScale : 1; - var kk = C && C.skyK ? C.skyK : (rows / 0.7); + return fset(wob < 0.22 ? G_UNDER : G_DASH, shdHue, + ((13 + 74 * sun + wob * 22) + + ((22 + 88 * sun * sun + wob * 24) - 13 - 74 * sun - wob * 22) * dFill) * gr); + } - var ey = Math.floor((hor - sy) * vs); - var a = ey / rows; - if (a < 0) a = 0; + function fillCell(u, v, sd, gr, sun, hue, lod) { + if (dFill <= 0.002) return fset(0, P.shadow, 0); + var h = hash2(Math.floor(u * 3.7), Math.floor(v * 3.7), sd ^ 0xC13); + var cov = 0.93 * dFill; + if (h > cov) return fset(0, P.shadow, 0); + var q = h / cov; - var bear = sx / kk; - var da = bear - SUN_AZ; - da = Math.atan2(Math.sin(da), Math.cos(da)); - var away = Math.abs(da) / Math.PI; + return fset(ink(0.34 + 0.72 * sun * sun + 0.30 * (q - 0.5)), + hue, (34 + 46 * dSky + 178 * sun * sun + 40 * q) * gr); + } - var west = 1 - away; west = west * west * (0.55 + 0.45 * west); + var ROUT = { ch: 0, col: 0, lum: 0, mir: 0, rip: 0, wch: 0 }; + var mirNow = 0, ripNow = 0, wchNow = 0; + function rset(ch, col, lum) { + ROUT.ch = ch; ROUT.col = col; + ROUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + ROUT.mir = mirNow; ROUT.rip = ripNow; ROUT.wch = wchNow; + return ROUT; + } - var lift = 0.90 + 0.50 * wDust; - var cap = 1 - 0.52 * wCloud; + var BOARDWALK = 1.72; - var warmK = dWarm; - var efold = 0.50 + 0.95 * (1 - warmK); + function inCross(C, wz) { + if (!C.xn) return 0; + var i = Math.round((wz - C.xz0) / (C.xpitch || 26)); + if (i < 0) i = 0; else if (i >= C.xn) i = C.xn - 1; + var d = wz - C.xc[i]; if (d < 0) d = -d; + if (d <= C.xw[i] + 1.1) return 1; - var e = Math.exp(-a / efold) * (0.30 + 0.70 * (warmK * west + (1 - warmK) * 0.55)) * - lift * cap * (0.10 + 1.05 * dSky); + if (i > 0) { d = wz - C.xc[i - 1]; if (d < 0) d = -d; if (d <= C.xw[i - 1] + 1.1) return 1; } + if (i < C.xn - 1) { d = wz - C.xc[i + 1]; if (d < 0) d = -d; if (d <= C.xw[i + 1] + 1.1) return 1; } + return 0; + } - var hs = hash2(sx, ey, C ? C.skySeed : 0x5EED); - var hs2 = hash2(sx, ey, (C ? C.skySeed : 0x5EED) ^ 0x11); + function floorTex(wx, wz, dist, t) { + weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + var C = cfg(); + var half = C ? C.half : 3.1; + var lane = wx - (C ? C.streetX : 4.0); + var al = lane < 0 ? -lane : lane; + var lod = dist < 20 ? 2 : (dist < 46 ? 1 : 0); + mirNow = 0; ripNow = 0; wchNow = 0; - var band = a > 0.16 && a < 0.44 ? 1 - Math.abs(a - 0.30) / 0.14 : 0; - if (band > 0) { - var ve = band * away * away * cap * lift; - if (hs < 0.075 * ve) return sset(G_DOT, P.violet, (70 + 96 * ve) * (0.7 + 0.5 * hs2)); - } + var comp = (C && C.swap) ? SUN_Z : SUN_X; + var lit = -lane * comp; + var sunSide = lit > 0.4 ? 1 : (lit < -0.4 ? 0 : (Math.abs(comp) < 0.35 ? 1 : 0)); - if (hs < 0.05 + 1.18 * e) { + if (al > half && al < half + BOARDWALK) { + if (inCross(C, wz)) { - if (warmK > 0.42) { - if (e > 0.80) return sset(G_EQ, P.pure, 168 * (0.7 + 0.4 * hs2)); - if (e > 0.58) return sset(G_EQ, P.amber, 248 * (0.72 + 0.32 * e) * (0.86 + 0.22 * hs2)); - if (e > 0.32) return sset(e > 0.46 ? G_EQ : G_DASH, P.ember, - 204 * (0.50 + 0.72 * e) * (0.78 + 0.40 * hs2)); - if (e > 0.13) return sset(G_TICK, P.slate, 138 * (0.52 + 0.78 * e) * (0.78 + 0.38 * hs2)); - return sset(G_DOT, P.azure, (16 + 46 * e) * (0.7 + 0.6 * hs2)); - } - if (e > 0.80) return sset(G_EQ, P.white, 214 * (0.80 + 0.24 * e) * (0.88 + 0.18 * hs2)); - if (e > 0.62) return sset(G_DASH, P.white, 176 * (0.72 + 0.32 * e) * (0.86 + 0.22 * hs2)); - if (e > 0.38) return sset(G_TICK, P.ice, 168 * (0.62 + 0.50 * e) * (0.82 + 0.30 * hs2)); - return sset(hs2 > 0.6 ? G_COLON : G_DOT, P.ice, (54 + 150 * e) * (0.78 + 0.36 * hs2)); - } - return sset(0, P.shadow, 0); + } else { + var into = al - half; + + if (into < 0.16) + return rset(G_UNDER, sunSide ? P.amber : P.white, (sunSide ? 214 : 60) * (0.8 + 0.4 * hash2((wz * 3) | 0, 0, 0x11))); + + var pj = wz / 0.92, fpj = pj - Math.floor(pj); + var pw = hash2(Math.floor(pj), (al * 2) | 0, 0x5B); + if (fpj < 0.10) + return rset(G_DASH, P.slate, (14 + pw * 12)); + if (lod === 2 && pw < 0.10) + return rset(pw < 0.04 ? G_COMMA : G_DOT, P.slate, 12 + pw * 60); + + if (dFill > 0.002 && hash2(Math.floor(wz * 4.1), (al * 3) | 0, 0x2F7) < 0.94 * dFill) + return rset(ink((sunSide ? 0.60 : 0.36) + 0.26 * (pw - 0.5)), + sunSide ? P.sand : P.timber, + (sunSide ? 150 : 78) + pw * 52); + if (sunSide) return rset(G_UNDER, P.white, (62 + pw * 40)); + return (pw < 0.30) ? rset(G_UNDER, P.slate, 12 + pw * 20) : rset(0, P.shadow, 0); + } } - var FOG_START_W = 20.0, FOG_END_W = 210.0, FOG_POW_W = 1.25; + if (al >= half + BOARDWALK) { + if (lod === 0) return rset(0, P.shadow, 0); + var og = hash2(Math.floor(wx * 1.6), Math.floor(wz * 1.6), 0x2D9); - CC.SurfWest = { id: 'west', - facade: facade, floorTex: floorTex, sky: sky, STYLE: STYLE_W, - fogStart: FOG_START_W, fogEnd: FOG_END_W, fogPow: FOG_POW_W, - sunOf: sunOf, BOARDWALK: BOARDWALK }; + var od = 0.14 + (0.82 - 0.14) * dFill; + if (og > od) return rset(0, P.shadow, 0); + if (dFill > 0.002 && og < od * dFill) + return rset(ink(0.30 + 0.24 * (og / od - 0.5)), P.timber, 46 + og * 90); + return rset(og < 0.05 ? G_COMMA : G_DOT, P.slate, 10 + og * 60); + } - Object.defineProperty(CC.SurfWest, 'SUN_AZ', { get: function () { return SUN_AZ; } }); - Object.defineProperty(CC.SurfWest, 'SUN_X', { get: function () { return SUN_X; } }); - Object.defineProperty(CC.SurfWest, 'SUN_Z', { get: function () { return SUN_Z; } }); - Object.defineProperty(CC.SurfWest, 'SUN_ALT', { get: function () { return SUN_ALT; } }); + var n = al / half; - if (!CC.SURFACES) CC.SURFACES = {}; - CC.SURFACES.west = CC.SurfWest; + var wet = wWet * 1.05; + var rut = 0; + if (lod > 0) { + + var rc = 0.44 + vnoise(wz * 0.055, 0x3B) * 0.10; + var dr = Math.abs(n - rc); + rut = dr < 0.075 ? 1 - dr / 0.075 : 0; + } + + if (rut > 0.25 && wet > 0.45) { + + var wsurf = rut * clamp(wet - 0.4, 0, 1); + if (wsurf > 0.12) { + mirNow = clamp(wsurf * 1.25, 0, 1); + ripNow = CC.reducedMotion ? 0 : Math.sin(wz * 1.7 + t * 1.4) * 0.9 * wWind; + wchNow = G_TILDE; + var ws = hash2(Math.floor(wx * 3), Math.floor(wz * 3), 0x71C); + return rset(ws < 0.5 ? G_TILDE : G_SEMI, P.slate, 12 + ws * 22); + } + } + + if (rut > 0.22) { + var rs = hash2(Math.floor(wx * (lod === 2 ? (dist < 9 ? 6.2 : 3.0) : 1.7)), + Math.floor(wz * (lod === 2 ? (dist < 9 ? 6.2 : 3.0) : 1.7)), 0x18F); + var rd = (0.34 + 0.42 * rut) * (lod === 2 ? 1 : 0.8); + rd += (0.96 - rd) * dFill; + if (rs < rd) { + + var rk = rs / rd; + var rn = (26 + rs * 150) * rut * (sunSide ? 1.15 : 0.72); + var rdy = (108 + rk * 104) * (0.55 + 0.45 * rut) * (sunSide ? 1.10 : 0.80); + return rset(dFill > 0.002 && hash2(Math.floor(wx * 2.7), Math.floor(wz * 2.7), 0x3C8) < dFill + ? ink((sunSide ? 0.66 : 0.50) + 0.26 * (rk - 0.5)) + : (rs < 0.14 ? G_UNDER : (rs < 0.34 ? G_COMMA : G_DOT)), + sunSide ? (dFill > 0.5 ? P.sand : P.white) : (dFill > 0.5 ? P.timber : P.slate), + rn + (rdy - rn) * dFill); + } + + if (lod === 2 && dist > 8 && rs > 0.988) return rset(G_o, P.slate, 30 + (1 - rs) * 3200); + return rset(0, P.shadow, 0); + } + + var sideK = 0.25 + 0.75 * clamp(1 - dAlt() / 0.95, 0, 1); + + var lightK = clamp(0.18 + 0.62 * dSky + 0.26 * dSun, 0, 1.0); + var sideBias = sunSide ? (1 + 0.25 * sideK) : (1 - 0.28 * sideK); + var lodQ = lod === 2 ? 1 : (lod === 1 ? 0.82 : 0.6); + + var dnight = (0.42 - 0.20 * n * n) * sideBias * lightK * lodQ; + + var dday = (0.94 - 0.22 * n * n) * sideBias * (lod === 2 ? 1 : (lod === 1 ? 0.92 : 0.82)); + var dens = dnight + (dday - dnight) * dFill; + + dens *= (0.82 + 0.5 * wDust) * (1 - (0.45 - 0.27 * dFill) * clamp(wet - 0.3, 0, 1)); + + var q = lod === 2 ? (dist < 9 ? 5.6 : 2.6) : (lod === 1 ? 1.5 : 0.85); + var d1 = hash2(Math.floor(wx * q), Math.floor(wz * q), 0x4A7); + if (d1 < dens) { + var hot = d1 < dens * 0.16 && sunSide; + + var k1 = d1 / dens; + + var sc = hash2(Math.floor(wx * q * 1.7), Math.floor(wz * q * 1.7), 0x1C5); + + var dayGround = dSun > 0.55; + + var gn = (hot ? 132 : 22 + k1 * 128); + var gd = (hot ? 176 : 88 + k1 * 96); + + var gsc = sunSide ? 0.62 : 0.44; + + var lightMul = 0.6 + 0.7 * lightK + 0.9 * dSun; + lightMul += (1.40 - lightMul) * dFill; + return rset(sc < dFill * 0.86 + ? ink(gsc + 0.30 * (k1 - 0.5) + 0.16 * dSun) + : (k1 < 0.3 ? G_DOT : (k1 < 0.62 ? G_COMMA : G_TICK)), + hot ? P.amber + : (sc < dFill * 0.86 ? P.sand : ((sunSide || dayGround) ? P.white : P.slate)), + (gn + (gd - gn) * dFill) * (sunSide ? 1 : 0.78) * lightMul); + } + + if (lod === 2) { + var d2 = hash2(Math.floor(wx * q * 0.5), Math.floor(wz * q * 0.5), 0x6E3); + if (d2 < 0.014) return rset(G_o, P.slate, 26 + d2 * 1300); + if (d2 > 0.990) return rset(G_QUOTE, P.spring, 22 + (1 - d2) * 1300); + } + return rset(0, P.shadow, 0); + } + + var SOUT = { ch: 0, col: 0, lum: 0 }; + function sset(ch, col, lum) { + SOUT.ch = ch; SOUT.col = col; + SOUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); + return SOUT; + } + + function sky(sx, sy, t) { + weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); + var C = cfg(); + var rows = C && C.rows ? C.rows : 60; + var hor = C ? C.horizon : rows * 0.56; + var vs = C && C.skyVScale ? C.skyVScale : 1; + var kk = C && C.skyK ? C.skyK : (rows / 0.7); + + var ey = Math.floor((hor - sy) * vs); + var a = ey / rows; + if (a < 0) a = 0; + + var bear = sx / kk; + var da = bear - SUN_AZ; + da = Math.atan2(Math.sin(da), Math.cos(da)); + var away = Math.abs(da) / Math.PI; + + var west = 1 - away; west = west * west * (0.55 + 0.45 * west); + + var lift = 0.90 + 0.50 * wDust; + + var cap = 1 - 0.52 * wCloud * (1 - 0.80 * dFill); + + var warmK = dWarm; + var efold = 0.50 + 0.95 * (1 - warmK); + + var e = Math.exp(-a / efold) * (0.30 + 0.70 * (warmK * west + (1 - warmK) * 0.55)) * + lift * cap * (0.10 + 1.05 * dSky); + + var hs = hash2(sx, ey, C ? C.skySeed : 0x5EED); + var hs2 = hash2(sx, ey, (C ? C.skySeed : 0x5EED) ^ 0x11); + + var band = a > 0.16 && a < 0.44 ? 1 - Math.abs(a - 0.30) / 0.14 : 0; + if (band > 0) { + var ve = band * away * away * cap * lift; + if (hs < 0.075 * ve) return sset(G_DOT, P.violet, (70 + 96 * ve) * (0.7 + 0.5 * hs2)); + } + + var covr = 0.05 + 1.18 * e; + covr += (0.96 - covr) * dFill; + if (hs < covr) { + + if (warmK > 0.42) { + if (e > 0.80) return sset(G_EQ, P.pure, 168 * (0.7 + 0.4 * hs2)); + if (e > 0.58) return sset(G_EQ, P.amber, 248 * (0.72 + 0.32 * e) * (0.86 + 0.22 * hs2)); + if (e > 0.32) return sset(e > 0.46 ? G_EQ : G_DASH, P.ember, + 204 * (0.50 + 0.72 * e) * (0.78 + 0.40 * hs2)); + if (e > 0.13) return sset(G_TICK, P.slate, 138 * (0.52 + 0.78 * e) * (0.78 + 0.38 * hs2)); + return sset(G_DOT, P.azure, (16 + 46 * e) * (0.7 + 0.6 * hs2)); + } + + var dayHz = 1 - 0.20 * dFill; + if (e > 0.80) return sset(G_EQ, P.white, dayHz * 214 * (0.80 + 0.24 * e) * (0.88 + 0.18 * hs2)); + if (e > 0.62) return sset(G_DASH, P.white, dayHz * 176 * (0.72 + 0.32 * e) * (0.86 + 0.22 * hs2)); + if (e > 0.38) return sset(G_TICK, P.ice, 168 * (0.62 + 0.50 * e) * (0.82 + 0.30 * hs2)); + return sset(hs2 > 0.6 ? G_COLON : G_DOT, P.ice, (54 + 150 * e) * (0.78 + 0.36 * hs2)); + } + return sset(0, P.shadow, 0); + } + + var FOG_START_W = 20.0, FOG_END_W = 210.0, FOG_POW_W = 1.25; + + CC.SurfWest = { id: 'west', + facade: facade, floorTex: floorTex, sky: sky, STYLE: STYLE_W, + fogEnd: FOG_END_W, + sunOf: sunOf, BOARDWALK: BOARDWALK }; + Object.defineProperty(CC.SurfWest, 'fogStart', + { get: function () { return FOG_START_W + 20.0 * dFill; } }); + Object.defineProperty(CC.SurfWest, 'fogPow', + { get: function () { return FOG_POW_W - 0.53 * dFill; } }); + + Object.defineProperty(CC.SurfWest, 'SUN_AZ', { get: function () { return SUN_AZ; } }); + Object.defineProperty(CC.SurfWest, 'SUN_X', { get: function () { return SUN_X; } }); + Object.defineProperty(CC.SurfWest, 'SUN_Z', { get: function () { return SUN_Z; } }); + Object.defineProperty(CC.SurfWest, 'SUN_ALT', { get: function () { return SUN_ALT; } }); + + Object.defineProperty(CC.SurfWest, 'dayFill', { get: function () { return dFill; } }); + + CC.SurfWest.dayAt = dayAt; + + if (!CC.SURFACES) CC.SURFACES = {}; + CC.SURFACES.west = CC.SurfWest; })(CC); /* src/raycast.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, poke = CC.poke, hash2 = CC.hash2, vnoise = CC.vnoise; - var G_COLON = CC.g(':'), G_DASH = CC.g('-'); + var P = CC.P, poke = CC.poke, hash2 = CC.hash2, vnoise = CC.vnoise; + var G_COLON = CC.g(':'), G_DASH = CC.g('-'); - var HMAX = 108; + var HMAX = 108; - var MAXSTEP = 512; + var MAXSTEP = 512; - var SC = { seed: 0, style: 0, litRate: 0.3, accent: 0, hue: undefined, h: 0, faceX: 1, side: 1 }; - var scRec = null; - function bindCell(rec) { - if (rec !== scRec) { - scRec = rec; - SC.seed = (rec.seed * 4294967296) | 0; - SC.style = rec.style | 0; - SC.litRate = rec.litRate; - SC.accent = rec.accent; - SC.hue = rec.hue; + var SC = { seed: 0, style: 0, litRate: 0.3, accent: 0, hue: undefined, h: 0, faceX: 1, side: 1 }; + var scRec = null; + function bindCell(rec) { + if (rec !== scRec) { + scRec = rec; + SC.seed = (rec.seed * 4294967296) | 0; + SC.style = rec.style | 0; + SC.litRate = rec.litRate; + SC.accent = rec.accent; + SC.hue = rec.hue; + } + return SC; + } + + var SGO = { ch: 0, col: 0, lum: 0 }; + function sgset(ch, col, lum) { SGO.ch = ch; SGO.col = col; SGO.lum = lum; return SGO; } + + function signPixel(rec, u, v, faceX, t) { + var s = rec.sign; + + var u0 = (faceX ? rec.lotZ : rec.lotX) + 0.7 + s.seed * 2.2; + var du = u - u0, dv = v - s.y; + if (du < 0 || dv < 0 || du > s.w || dv > s.h) return null; + + if (du < 0.22 || dv < 0.22 || s.w - du < 0.22 || s.h - dv < 0.22) + return sgset(0, P.shadow, 0); + if (s.vertical) { + var seg = dv / 1.5; seg -= Math.floor(seg); + if (seg > 0.72) return sgset(0, P.shadow, 0); + } + var sd = (s.seed * 4294967296) | 0; + + var pulse = CC.reducedMotion ? 0.93 : 0.86 + 0.14 * vnoise(t * 0.7 + s.seed * 40, 0x51); + + if (s.board) { + var lu = Math.floor(du * 2.9), lv = Math.floor(dv * 3.4); + var ink = hash2(lu, lv, sd ^ 0x2C1D); + if (dv > s.h * 0.24 && dv < s.h * 0.80 && ink < 0.46) + return sgset(s.glyph, s.hue, (148 + ink * 220) * pulse); + return hash2(lu, lv, sd ^ 0x5D33) < 0.34 ? sgset(G_DASH, P.slate, 16) + : sgset(0, P.shadow, 0); + } + + var h = hash2(Math.floor(du * 2.4), Math.floor(dv * 2.4), sd); + return sgset(s.glyph, s.hue, (172 + h * 66) * (h < 0.10 ? 0.3 : 1) * pulse); + } + + var swapFloor = 0; + + var swapLatch = 0; + + var CFGARG = { grid: 8.0, streetX: 4.0, streetPeriod: 0, half: 3.1, + horizon: 33.6, rows: 60, skyVScale: 1, skyK: 1, swap: 0 }; + + var SKY_NEUTRAL = 0.5625 / (2 * Math.tan(0.625)); + function configureFor(city, camx, camz, fwx, fwz, horizon, rows, scale, cols) { + var cx = 4.0, hw = 3.1; + swapFloor = 0; + if (city && city.aveX) { + var k = Math.round(camx / city.AVE), m = Math.round(camz / city.CROSS); + var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d; + for (i = k - 1; i <= k + 1; i++) { + c = city.aveX(i) + 0.5; d = camx - c; if (d < 0) d = -d; + if (d < bA) { bA = d; aC = c; aW = city.aveW(i) + 0.5; } + } + for (i = m - 1; i <= m + 1; i++) { + c = city.crossZ(i) + 0.5; d = camz - c; if (d < 0) d = -d; + if (d < bC) { bC = d; cC = c; cW = city.crossW(i) + 0.5; } + } + + var onAve = bA <= aW, onCross = bC <= cW; + var afz = fwz < 0 ? -fwz : fwz, afx = fwx < 0 ? -fwx : fwx; + var want; + if (onCross && !onAve) want = 1; + else if (!onCross) want = 0; + else want = swapLatch ? (afz > afx * 1.35 ? 0 : 1) + : (afx > afz * 1.35 ? 1 : 0); + swapLatch = want; + if (want) { swapFloor = 1; cx = cC; hw = cW; } + else { cx = aC; hw = aW; } + + hw = hw - CC.PAVE; if (hw < 1.7) hw = 1.7; + } + + CFGARG.grid = 8.0; CFGARG.streetX = cx; CFGARG.streetPeriod = 0; CFGARG.half = hw; + CFGARG.swap = swapFloor; + CFGARG.horizon = horizon; CFGARG.rows = rows; + + CFGARG.skyVScale = (scale > 0 && cols > 0) ? (SKY_NEUTRAL * cols) / scale : 1; + + CFGARG.skyK = cols > 0 ? cols / 1.25 : 1; + CC.Surf.configure(CFGARG); + loadCrossings(city, camx, camz); + } + + function loadCrossings(city, camx, camz) { + var cf = CC.Surf.cfg; + if (!city || !city.aveX) { cf.xn = 0; return; } + + var along = swapFloor ? camx : camz; + var pitch = swapFloor ? city.AVE : city.CROSS; + var n = 0, i, k0 = Math.round(along / pitch); + + for (i = k0 - 1; i <= k0 + 6 && n < 8; i++) { + cf.xc[n] = (swapFloor ? city.aveX(i) : city.crossZ(i)) + 0.5; + + var w = (swapFloor ? city.aveW(i) : city.crossW(i)) + 0.5 - CC.PAVE; + cf.xw[n] = w < 1.7 ? 1.7 : w; + if (n === 0) cf.xz0 = cf.xc[0]; + n++; + } + cf.xn = n; + + cf.xpitch = pitch; + } + + function floorRow(frame, i, r, rowC, ox, oz, dx, dz, len, horizon, scale, eyeY, t) { + var Surf = CC.Surf, den = rowC - horizon; + + if (den < 1e-3) { poke(frame, i, 0, P.shadow, 0, 1e6, 2); mirA[r] = 0; return; } + var w = eyeY * scale / den, d = w * len; + var px = ox + dx * w, pz = oz + dz * w; + var o = swapFloor ? Surf.floorTex(pz, px, d, t) : Surf.floorTex(px, pz, d, t); + poke(frame, i, o.ch, o.col, Surf.fog(o.lum, d), d, 2); + + mirA[r] = o.mir; ripA[r] = o.rip; wchA[r] = o.wch; + } + + var mirA = new Float32Array(0), ripA = new Float32Array(0), wchA = new Uint8Array(0); + function scratch(rows) { + if (mirA.length === rows) return; + mirA = new Float32Array(rows); ripA = new Float32Array(rows); wchA = new Uint8Array(rows); + } + + function reflectColumn(frame, x, cols, rows, horizon) { + var Surf = CC.Surf; + var r0 = horizon < 0 ? 0 : (horizon | 0); + for (var r = r0; r < rows; r++) { + var m = mirA[r]; + if (m < 0.06) continue; + var i = r * cols + x; + if (frame.kind[i] !== 2) continue; + var sr = Math.floor(2 * horizon - r - 0.5 + ripA[r]); + if (sr < 0 || sr >= r) continue; + var j = sr * cols + x; + var sl = frame.lum[j]; + + if (sl < (m > 0.22 ? 55 : 118) || frame.ch[j] === 0) continue; + + var add = Surf.fog(sl * (0.30 + 0.60 * m), frame.dist[i]); + if (add < 5) continue; + var own = frame.lum[i]; + if (add > own) { + + var ch = frame.ch[i]; + if (ch === 0) ch = wchA[r] || G_COLON; + poke(frame, i, ch, frame.col[j], add + own * 0.3 > 255 ? 255 : add + own * 0.3, + frame.dist[i], 2); + } else if (frame.ch[i] !== 0) { + + poke(frame, i, frame.ch[i], frame.col[i], own + add * 0.45, frame.dist[i], 2); + } + } + } + + function render(frame, cam, city) { + var Surf = CC.Surf; + if (!Surf) throw new Error('CC.Cast needs surfaces.js loaded first'); + + var cols = frame.cols, rows = frame.rows; + + var horizon = cam.horizon !== undefined ? cam.horizon : rows * 0.56; + var fov = cam.fov || 1.25; + var eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + var halfPlane = Math.tan(fov * 0.5); + + var cellA = cam.cellAspect || 0.5625; + var scale = cam.scaleY !== undefined ? cam.scaleY : (cols * cellA) / (2 * halfPlane); + var t = cam.t || 0; + var ox = cam.x, oz = cam.z, yaw = cam.yaw || 0; + + var fwx = Math.sin(yaw), fwz = Math.cos(yaw); + var rgx = Math.cos(yaw), rgz = -Math.sin(yaw); + + var FAR = Surf.beginFrame ? Surf.beginFrame(t) : Surf.FOG_END; + + scratch(rows); + configureFor(city, ox, oz, fwx, fwz, horizon, rows, scale, cols); + + var skyK = cols / 1.25; + + for (var x = 0; x < cols; x++) { + var sp = (2 * (x + 0.5) / cols - 1) * halfPlane; + + var skyX = Math.floor((yaw + Math.atan(sp)) * skyK); + var dx = fwx + rgx * sp, dz = fwz + rgz * sp; + var len = Math.sqrt(1 + sp * sp); + var wFar = FAR / len; + + var cx = Math.floor(ox), cz = Math.floor(oz); + var sX = dx > 0 ? 1 : -1, sZ = dz > 0 ? 1 : -1; + var adx = dx === 0 ? 1e30 : Math.abs(1 / dx), adz = dz === 0 ? 1e30 : Math.abs(1 / dz); + var mX = (dx > 0 ? (cx + 1 - ox) : (ox - cx)) * adx; + var mZ = (dz > 0 ? (cz + 1 - oz) : (oz - cz)) * adz; + + var sil = rows; + var w = 0, faceX = 1, steps = 0; + + while (sil > 0 && steps++ < MAXSTEP) { + + if (mX < mZ) { w = mX; mX += adx; cx += sX; faceX = 1; } + else { w = mZ; mZ += adz; cz += sZ; faceX = 0; } + if (w > wFar) break; + + var h = city ? city.height(cx, cz) : 0; + if (h <= 0) continue; + + var topRow = horizon - (h - eyeY) * scale / w; + if (topRow > sil - 0.5) continue; + + var r0 = Math.ceil(topRow - 0.5); if (r0 < 0) r0 = 0; + var dist = w * len; + var grF = horizon + eyeY * scale / w; + + var u = faceX ? (oz + dz * w) : (ox + dx * w); + var rec = city.cell(cx, cz); + var sc = rec ? bindCell(rec) : null; + if (sc) { sc.h = h; sc.faceX = faceX; sc.side = faceX ? sX : sZ; } + var sign = rec && rec.sign; + + for (var r = sil - 1; r >= r0; r--) { + var rowC = r + 0.5, i = r * cols + x; + if (rowC > grF) { + + floorRow(frame, i, r, rowC, ox, oz, dx, dz, len, horizon, scale, eyeY, t); + continue; + } + mirA[r] = 0; + var v = eyeY + (horizon - rowC) * w / scale; + var o = Surf.facade(u, v, sc, dist, t); + var ch = o.ch, cl = o.col, lm = o.lum, sg; + if (sign && (sg = signPixel(rec, u, v, faceX, t))) { ch = sg.ch; cl = sg.col; lm = sg.lum; } + poke(frame, i, ch, cl, Surf.fog(lm, dist), dist, 1); } - return SC; - } + sil = r0; - var SGO = { ch: 0, col: 0, lum: 0 }; - function sgset(ch, col, lum) { SGO.ch = ch; SGO.col = col; SGO.lum = lum; return SGO; } - - function signPixel(rec, u, v, faceX, t) { - var s = rec.sign; - - var u0 = (faceX ? rec.lotZ : rec.lotX) + 0.7 + s.seed * 2.2; - var du = u - u0, dv = v - s.y; - if (du < 0 || dv < 0 || du > s.w || dv > s.h) return null; - - if (du < 0.22 || dv < 0.22 || s.w - du < 0.22 || s.h - dv < 0.22) - return sgset(0, P.shadow, 0); - if (s.vertical) { - var seg = dv / 1.5; seg -= Math.floor(seg); - if (seg > 0.72) return sgset(0, P.shadow, 0); + var room = horizon - sil + 0.5; + if (room > 0.5) { + var wCut = (HMAX - eyeY) * scale / room; + if (wCut < wFar) wFar = wCut; } - var sd = (s.seed * 4294967296) | 0; + } - var pulse = CC.reducedMotion ? 0.93 : 0.86 + 0.14 * vnoise(t * 0.7 + s.seed * 40, 0x51); - - if (s.board) { - var lu = Math.floor(du * 2.9), lv = Math.floor(dv * 3.4); - var ink = hash2(lu, lv, sd ^ 0x2C1D); - if (dv > s.h * 0.24 && dv < s.h * 0.80 && ink < 0.46) - return sgset(s.glyph, s.hue, (148 + ink * 220) * pulse); - return hash2(lu, lv, sd ^ 0x5D33) < 0.34 ? sgset(G_DASH, P.slate, 16) - : sgset(0, P.shadow, 0); + for (var q = sil - 1; q >= 0; q--) { + var j = q * cols + x, qc = q + 0.5; + if (qc > horizon) { + floorRow(frame, j, q, qc, ox, oz, dx, dz, len, horizon, scale, eyeY, t); + } else { + var s = Surf.sky(skyX, q, t); + poke(frame, j, s.ch, s.col, s.lum, Infinity, 0); } + } - var h = hash2(Math.floor(du * 2.4), Math.floor(dv * 2.4), sd); - return sgset(s.glyph, s.hue, (172 + h * 66) * (h < 0.10 ? 0.3 : 1) * pulse); + reflectColumn(frame, x, cols, rows, horizon); } + return frame; + } - var swapFloor = 0; - - var swapLatch = 0; - - var CFGARG = { grid: 8.0, streetX: 4.0, streetPeriod: 0, half: 3.1, - horizon: 33.6, rows: 60, skyVScale: 1, skyK: 1, swap: 0 }; - - var SKY_NEUTRAL = 0.5625 / (2 * Math.tan(0.625)); - function configureFor(city, camx, camz, fwx, fwz, horizon, rows, scale, cols) { - var cx = 4.0, hw = 3.1; - swapFloor = 0; - if (city && city.aveX) { - var k = Math.round(camx / city.AVE), m = Math.round(camz / city.CROSS); - var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d; - for (i = k - 1; i <= k + 1; i++) { - c = city.aveX(i) + 0.5; d = camx - c; if (d < 0) d = -d; - if (d < bA) { bA = d; aC = c; aW = city.aveW(i) + 0.5; } - } - for (i = m - 1; i <= m + 1; i++) { - c = city.crossZ(i) + 0.5; d = camz - c; if (d < 0) d = -d; - if (d < bC) { bC = d; cC = c; cW = city.crossW(i) + 0.5; } - } - - var onAve = bA <= aW, onCross = bC <= cW; - var afz = fwz < 0 ? -fwz : fwz, afx = fwx < 0 ? -fwx : fwx; - var want; - if (onCross && !onAve) want = 1; - else if (!onCross) want = 0; - else want = swapLatch ? (afz > afx * 1.35 ? 0 : 1) - : (afx > afz * 1.35 ? 1 : 0); - swapLatch = want; - if (want) { swapFloor = 1; cx = cC; hw = cW; } - else { cx = aC; hw = aW; } - - hw = hw - CC.PAVE; if (hw < 1.7) hw = 1.7; - } - - CFGARG.grid = 8.0; CFGARG.streetX = cx; CFGARG.streetPeriod = 0; CFGARG.half = hw; - CFGARG.swap = swapFloor; - CFGARG.horizon = horizon; CFGARG.rows = rows; - - CFGARG.skyVScale = (scale > 0 && cols > 0) ? (SKY_NEUTRAL * cols) / scale : 1; - - CFGARG.skyK = cols > 0 ? cols / 1.25 : 1; - CC.Surf.configure(CFGARG); - loadCrossings(city, camx, camz); - } - - function loadCrossings(city, camx, camz) { - var cf = CC.Surf.cfg; - if (!city || !city.aveX) { cf.xn = 0; return; } - - var along = swapFloor ? camx : camz; - var pitch = swapFloor ? city.AVE : city.CROSS; - var n = 0, i, k0 = Math.round(along / pitch); - - for (i = k0 - 1; i <= k0 + 6 && n < 8; i++) { - cf.xc[n] = (swapFloor ? city.aveX(i) : city.crossZ(i)) + 0.5; - - var w = (swapFloor ? city.aveW(i) : city.crossW(i)) + 0.5 - CC.PAVE; - cf.xw[n] = w < 1.7 ? 1.7 : w; - if (n === 0) cf.xz0 = cf.xc[0]; - n++; - } - cf.xn = n; - - cf.xpitch = pitch; - } - - function floorRow(frame, i, r, rowC, ox, oz, dx, dz, len, horizon, scale, eyeY, t) { - var Surf = CC.Surf, den = rowC - horizon; - - if (den < 1e-3) { poke(frame, i, 0, P.shadow, 0, 1e6, 2); mirA[r] = 0; return; } - var w = eyeY * scale / den, d = w * len; - var px = ox + dx * w, pz = oz + dz * w; - var o = swapFloor ? Surf.floorTex(pz, px, d, t) : Surf.floorTex(px, pz, d, t); - poke(frame, i, o.ch, o.col, Surf.fog(o.lum, d), d, 2); - - mirA[r] = o.mir; ripA[r] = o.rip; wchA[r] = o.wch; - } - - var mirA = new Float32Array(0), ripA = new Float32Array(0), wchA = new Uint8Array(0); - function scratch(rows) { - if (mirA.length === rows) return; - mirA = new Float32Array(rows); ripA = new Float32Array(rows); wchA = new Uint8Array(rows); - } - - function reflectColumn(frame, x, cols, rows, horizon) { - var Surf = CC.Surf; - var r0 = horizon < 0 ? 0 : (horizon | 0); - for (var r = r0; r < rows; r++) { - var m = mirA[r]; - if (m < 0.06) continue; - var i = r * cols + x; - if (frame.kind[i] !== 2) continue; - var sr = Math.floor(2 * horizon - r - 0.5 + ripA[r]); - if (sr < 0 || sr >= r) continue; - var j = sr * cols + x; - var sl = frame.lum[j]; - - if (sl < (m > 0.22 ? 55 : 118) || frame.ch[j] === 0) continue; - - var add = Surf.fog(sl * (0.30 + 0.60 * m), frame.dist[i]); - if (add < 5) continue; - var own = frame.lum[i]; - if (add > own) { - - var ch = frame.ch[i]; - if (ch === 0) ch = wchA[r] || G_COLON; - poke(frame, i, ch, frame.col[j], add + own * 0.3 > 255 ? 255 : add + own * 0.3, - frame.dist[i], 2); - } else if (frame.ch[i] !== 0) { - - poke(frame, i, frame.ch[i], frame.col[i], own + add * 0.45, frame.dist[i], 2); - } - } - } - - function render(frame, cam, city) { - var Surf = CC.Surf; - if (!Surf) throw new Error('CC.Cast needs surfaces.js loaded first'); - - var cols = frame.cols, rows = frame.rows; - - var horizon = cam.horizon !== undefined ? cam.horizon : rows * 0.56; - var fov = cam.fov || 1.25; - var eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - var halfPlane = Math.tan(fov * 0.5); - - var cellA = cam.cellAspect || 0.5625; - var scale = cam.scaleY !== undefined ? cam.scaleY : (cols * cellA) / (2 * halfPlane); - var t = cam.t || 0; - var ox = cam.x, oz = cam.z, yaw = cam.yaw || 0; - - var fwx = Math.sin(yaw), fwz = Math.cos(yaw); - var rgx = Math.cos(yaw), rgz = -Math.sin(yaw); - - var FAR = Surf.beginFrame ? Surf.beginFrame(t) : Surf.FOG_END; - - scratch(rows); - configureFor(city, ox, oz, fwx, fwz, horizon, rows, scale, cols); - - var skyK = cols / 1.25; - - for (var x = 0; x < cols; x++) { - var sp = (2 * (x + 0.5) / cols - 1) * halfPlane; - - var skyX = Math.floor((yaw + Math.atan(sp)) * skyK); - var dx = fwx + rgx * sp, dz = fwz + rgz * sp; - var len = Math.sqrt(1 + sp * sp); - var wFar = FAR / len; - - var cx = Math.floor(ox), cz = Math.floor(oz); - var sX = dx > 0 ? 1 : -1, sZ = dz > 0 ? 1 : -1; - var adx = dx === 0 ? 1e30 : Math.abs(1 / dx), adz = dz === 0 ? 1e30 : Math.abs(1 / dz); - var mX = (dx > 0 ? (cx + 1 - ox) : (ox - cx)) * adx; - var mZ = (dz > 0 ? (cz + 1 - oz) : (oz - cz)) * adz; - - var sil = rows; - var w = 0, faceX = 1, steps = 0; - - while (sil > 0 && steps++ < MAXSTEP) { - - if (mX < mZ) { w = mX; mX += adx; cx += sX; faceX = 1; } - else { w = mZ; mZ += adz; cz += sZ; faceX = 0; } - if (w > wFar) break; - - var h = city ? city.height(cx, cz) : 0; - if (h <= 0) continue; - - var topRow = horizon - (h - eyeY) * scale / w; - if (topRow > sil - 0.5) continue; - - var r0 = Math.ceil(topRow - 0.5); if (r0 < 0) r0 = 0; - var dist = w * len; - var grF = horizon + eyeY * scale / w; - - var u = faceX ? (oz + dz * w) : (ox + dx * w); - var rec = city.cell(cx, cz); - var sc = rec ? bindCell(rec) : null; - if (sc) { sc.h = h; sc.faceX = faceX; sc.side = faceX ? sX : sZ; } - var sign = rec && rec.sign; - - for (var r = sil - 1; r >= r0; r--) { - var rowC = r + 0.5, i = r * cols + x; - if (rowC > grF) { - - floorRow(frame, i, r, rowC, ox, oz, dx, dz, len, horizon, scale, eyeY, t); - continue; - } - mirA[r] = 0; - var v = eyeY + (horizon - rowC) * w / scale; - var o = Surf.facade(u, v, sc, dist, t); - var ch = o.ch, cl = o.col, lm = o.lum, sg; - if (sign && (sg = signPixel(rec, u, v, faceX, t))) { ch = sg.ch; cl = sg.col; lm = sg.lum; } - poke(frame, i, ch, cl, Surf.fog(lm, dist), dist, 1); - } - sil = r0; - - var room = horizon - sil + 0.5; - if (room > 0.5) { - var wCut = (HMAX - eyeY) * scale / room; - if (wCut < wFar) wFar = wCut; - } - } - - for (var q = sil - 1; q >= 0; q--) { - var j = q * cols + x, qc = q + 0.5; - if (qc > horizon) { - floorRow(frame, j, q, qc, ox, oz, dx, dz, len, horizon, scale, eyeY, t); - } else { - var s = Surf.sky(skyX, q, t); - poke(frame, j, s.ch, s.col, s.lum, Infinity, 0); - } - } - - reflectColumn(frame, x, cols, rows, horizon); - } - return frame; - } - - var Cast = { render: render, HMAX: HMAX }; - CC.Cast = Cast; + var Cast = { render: render, HMAX: HMAX }; + CC.Cast = Cast; })(CC); /* src/control.js */ (function (CC) { - 'use strict'; + 'use strict'; - var clamp = CC.clamp, smooth = CC.smooth; + var clamp = CC.clamp, smooth = CC.smooth; - var K = { - fwd: 0, back: 0, left: 0, right: 0, run: 0, crouch: 0, - yawL: 0, yawR: 0, pitchU: 0, pitchD: 0, - mdx: 0, mdy: 0, - tx: 0, tz: 0, trun: 0, - gx: 0, gz: 0, grun: 0, - glx: 0, gly: 0, - any: 0, - act: 0 + var K = { + fwd: 0, back: 0, left: 0, right: 0, run: 0, crouch: 0, + yawL: 0, yawR: 0, pitchU: 0, pitchD: 0, + mdx: 0, mdy: 0, + tx: 0, tz: 0, trun: 0, + gx: 0, gz: 0, grun: 0, + glx: 0, gly: 0, + any: 0, + act: 0 + }; + + var mode = 0; + var blend = 0; + + var autoOff = 0; + var idle = 0; + var IDLE_RESUME = 15; + var BLEND_IN = 0.18, BLEND_OUT = 1.6; + + var px = 0, pz = 0, pyaw = 0, pitch = 0, vx = 0, vz = 0, bob = 0, crouchK = 0; + var fovT = 1.25; + var placed = 0; + + var WALK = 2.7, RUN = 5.8, CROUCH = 1.25; + + var ACCEL = 9.0; + + var MOUSE = 0.0022, KEYLOOK = 1.35; + var PADLOOK = 2.30; + var PITCH_MAX = 0.30; + + var qYaw = 0, qPitch = 0; + var LOOK_LAG = 22, YAW_MAX = 3.1, YAW_MAX_RM = 1.15; + var paused = 0; + + var RAD = 0.34; + function solid(city, x, z) { + if (!city || !city.height) return false; + return city.height(x, z) > 0 || + city.height(x + RAD, z) > 0 || city.height(x - RAD, z) > 0 || + city.height(x, z + RAD) > 0 || city.height(x, z - RAD) > 0; + } + + function move(city, nx, nz) { + if (!solid(city, nx, pz)) px = nx; + if (!solid(city, px, nz)) pz = nz; + } + + function angDelta(a, b) { + var d = b - a; + while (d > Math.PI) d -= 6.283185307; + while (d < -Math.PI) d += 6.283185307; + return d; + } + + var A = { x: 0, z: 0, yaw: 0, eyeY: 1.7, fov: 1.25 }; + + function seedFromAuto() { + px = A.x; pz = A.z; pyaw = A.yaw; vx = 0; vz = 0; placed = 1; seedWanted = 0; + + pitch = apitch; + } + + var apitch = 0; + var AUTO_PITCH = 0.15; + var AUTO_LO = 26, AUTO_HI = 52; + var AUTO_RATE = 0.55; + var SWAY = 0.025; + + function autoLook(dt, city, ta) { + var tgt = 0; + if (city && city.height) { + var fx = Math.sin(A.yaw), fz = Math.cos(A.yaw); + + var h = 0, hh; + hh = city.height(A.x + fx * 5 + fz * 4.5, A.z + fz * 5 - fx * 4.5); if (hh > h) h = hh; + hh = city.height(A.x + fx * 5 - fz * 4.5, A.z + fz * 5 + fx * 4.5); if (hh > h) h = hh; + hh = city.height(A.x + fx * 13 + fz * 5, A.z + fz * 13 - fx * 5); if (hh > h) h = hh; + hh = city.height(A.x + fx * 13 - fz * 5, A.z + fz * 13 + fx * 5); if (hh > h) h = hh; + var u = (h - AUTO_LO) / (AUTO_HI - AUTO_LO); + if (u < 0) u = 0; else if (u > 1) u = 1; + tgt = smooth(u) * AUTO_PITCH; + } + + tgt += (CC.vnoise(ta * 0.043, 1913) - 0.5) * 2 * SWAY; + if (CC.reducedMotion) tgt *= 0.45; + apitch += (tgt - apitch) * Math.min(1, dt * AUTO_RATE); + } + + var seedWanted = 0; + + function takeOver() { + if (mode) return; + mode = 1; + vx = 0; vz = 0; + seedWanted = 1; + } + + function giveBack(city, t) { + if (!mode) return; + mode = 0; + if (t === undefined) t = 0; + + if (city && city.nearestRouteS) { + var sp = city.SPEED || 1.6; + if (city.ensureRoute) city.ensureRoute(sp * (t - autoOff) + 80); + autoOff = t - city.nearestRouteS(px, pz).s / sp; + } + } + + function dead(v, d) { + if (v > d) return (v - d) / (1 - d); + if (v < -d) return (v + d) / (1 - d); + return 0; + } + var PAD_DZ = 0.16; + + var padSeen = 0, padProbe = 0; + + var padWorld = 0; + function pollPad(dt) { + K.gx = 0; K.gz = 0; K.grun = 0; K.glx = 0; K.gly = 0; + if (typeof navigator === 'undefined' || !navigator.getGamepads) return; + if (!padSeen) { + padProbe -= dt; + if (padProbe > 0) return; + padProbe = 1; + } + var pads = navigator.getGamepads(); + if (!pads) return; + for (var i = 0; i < pads.length; i++) { + var p = pads[i]; + if (!p || !p.connected || !p.axes || p.axes.length < 2) continue; + padSeen = 1; + var lx = dead(p.axes[0] || 0, PAD_DZ), ly = dead(p.axes[1] || 0, PAD_DZ); + + K.gx += lx; K.gz += -ly; + if (p.axes.length >= 4) { + K.glx += dead(p.axes[2] || 0, PAD_DZ); + K.gly += -dead(p.axes[3] || 0, PAD_DZ); + } + var b = p.buttons; + if (b) { + + for (var j = 4; j <= 7; j++) { + var bb = b[j]; + if (!bb) continue; + var v = typeof bb === 'number' ? bb : (bb.value !== undefined ? bb.value : (bb.pressed ? 1 : 0)); + if (v > 0.35) K.grun = 1; + } + + var y = b[3]; + var down = y ? (typeof y === 'number' ? y > 0.5 : !!y.pressed) : false; + if (down && !padWorld && CC.World && hooksRef && hooksRef.world) { + + hooksRef.world(CC.World.LIST[(CC.World.index + 1) % CC.World.count].id); + K.act = 1; + } + padWorld = down; + } + } + + if (K.gx || K.gz || K.glx || K.gly || K.grun) K.any = 1; + } + + function update(dt, t, cam, city) { + if (!(dt > 0)) dt = 1 / 60; + var k = CC.reducedMotion ? 0.5 : 1; + + pollPad(dt); + + if (K.any || K.act) { + idle = 0; + if (K.any && !mode) takeOver(); + K.any = 0; K.act = 0; + } else idle += dt; + + if (mode && !paused && idle > IDLE_RESUME) giveBack(city, t); + + if (mode && !paused) autoOff += dt; + if (city && city.camera) city.camera(A, city, t - autoOff); + else { A.x = cam.x; A.z = cam.z; A.yaw = cam.yaw; A.eyeY = 1.7; } + + if (!paused) autoLook(dt, city, t - autoOff); + + if (!placed || seedWanted) seedFromAuto(); + + qYaw += (K.mdx * MOUSE) + (K.yawR - K.yawL) * KEYLOOK * dt + + K.glx * (K.glx < 0 ? -K.glx : K.glx) * PADLOOK * dt; + qPitch += (-K.mdy * MOUSE * 0.62) + (K.pitchU - K.pitchD) * KEYLOOK * 0.5 * dt + + K.gly * (K.gly < 0 ? -K.gly : K.gly) * PADLOOK * 0.42 * dt; + K.mdx = 0; K.mdy = 0; + + var lag = Math.min(1, dt * LOOK_LAG); + var maxYaw = (CC.reducedMotion ? YAW_MAX_RM : YAW_MAX) * dt; + var dy = qYaw * lag; + if (dy > maxYaw) dy = maxYaw; else if (dy < -maxYaw) dy = -maxYaw; + var dp = qPitch * lag; + + if (dy > -1e-7 && dy < 1e-7) { dy = qYaw; qYaw = 0; } else qYaw -= dy; + if (dp > -1e-7 && dp < 1e-7) { dp = qPitch; qPitch = 0; } else qPitch -= dp; + + if (mode) { + pyaw += dy; + pitch = clamp(pitch + dp, -PITCH_MAX, PITCH_MAX); + } + + var tgtC = K.crouch ? 1 : 0; + crouchK += (tgtC - crouchK) * Math.min(1, dt * 7); + + var mf = (K.fwd - K.back) + K.tz + K.gz, ms = (K.right - K.left) + K.tx + K.gx; + var sp = (K.crouch ? CROUCH : ((K.run || K.trun || K.grun) ? RUN : WALK)) * k; + + var ml = Math.sqrt(mf * mf + ms * ms); + if (ml > 1) { mf /= ml; ms /= ml; } + var tvx = 0, tvz = 0; + if (ml > 0.001) { + + var fx = Math.sin(pyaw), fz = Math.cos(pyaw); + tvx = (fx * mf + fz * ms) * sp; + tvz = (fz * mf - fx * ms) * sp; + } + var a = Math.min(1, dt * ACCEL); + vx += (tvx - vx) * a; vz += (tvz - vz) * a; + + if (mode) move(city, px + vx * dt, pz + vz * dt); + else { px = A.x; pz = A.z; } + + var spd = Math.sqrt(vx * vx + vz * vz); + bob += spd * dt * 2.1; + + var bobA = CC.reducedMotion ? 0.012 : 0.034; + var pEye = 1.66 - crouchK * 0.52 + Math.sin(bob * 3.1) * bobA * Math.min(1, spd / WALK); + + var tgtB = mode ? 1 : 0; + var rate = mode ? BLEND_IN : BLEND_OUT; + blend += clamp((tgtB - blend), -1, 1) * Math.min(1, dt / rate); + if (blend < 0.0005) blend = 0; else if (blend > 0.9995) blend = 1; + var b = smooth(blend); + + cam.x = A.x + (px - A.x) * b; + cam.z = A.z + (pz - A.z) * b; + cam.yaw = A.yaw + angDelta(A.yaw, pyaw) * b; + cam.eyeY = A.eyeY + (pEye - A.eyeY) * b; + + if (cam.horizonBase === undefined) cam.horizonBase = cam.horizon; + var hb = cam.horizonBase; + + var rows = cam.rows || (hb / 0.56); + + cam.horizon = hb + (apitch + (pitch - apitch) * b) * rows; + + cam.fov = A.fov + (fovT - A.fov) * b; + + Control.mode = mode; Control.blend = b; Control.speed = spd * b; Control.idle = idle; + Control.paused = paused; + return cam; + } + + var HINT_IN = 1.0, HINT_HOLD = 7.0, HINT_OUT = 1.2; + var hintOpen = 0, hintClose = HINT_IN + HINT_HOLD; + + function hintAlpha(t) { + if (!(t >= 0)) t = 0; + var a = (t - hintOpen) / HINT_IN; if (a > 1) a = 1; else if (a < 0) a = 0; + var b = 1 - (t - hintClose) / HINT_OUT; if (b > 1) b = 1; else if (b < 0) b = 0; + return a * b; + } + + function hintToggle(t) { + if (!(t >= 0)) t = 0; + if (t < hintClose) { hintClose = t; return; } + + var cur = hintAlpha(t); + hintOpen = t - HINT_IN * cur; + hintClose = t + HINT_IN + HINT_HOLD; + } + + var el = null; + + var hooksRef = null; + + function attach(win, doc, canvas, hooks) { + if (!win || !doc) return; + hooksRef = hooks || null; + el = canvas || doc.documentElement; + + function set(e, down) { + var c = e.code || '', h = e.key || ''; + var hit = 1; + switch (c) { + case 'KeyW': case 'Numpad8': K.fwd = down; break; + case 'KeyS': case 'Numpad5': K.back = down; break; + case 'KeyA': K.left = down; break; + case 'KeyD': K.right = down; break; + case 'ArrowLeft': K.yawL = down; break; + case 'ArrowRight': K.yawR = down; break; + case 'ArrowUp': K.pitchU = down; break; + case 'ArrowDown': K.pitchD = down; break; + case 'ShiftLeft': case 'ShiftRight': K.run = down; break; + case 'KeyC': case 'ControlLeft': K.crouch = down; break; + default: hit = 0; + } + if (!hit && down) { + hit = 2; + switch (c) { + case 'Tab': + if (mode) { giveBack(hooks && hooks.city && hooks.city(), + hooks && hooks.now ? hooks.now() : 0); idle = 0; } + else { takeOver(); hit = 1; } + e.preventDefault(); + break; + case 'Escape': giveBack(hooks && hooks.city && hooks.city(), + hooks && hooks.now ? hooks.now() : 0); idle = 0; + if (doc.exitPointerLock) doc.exitPointerLock(); + break; + case 'KeyH': hintToggle(hooks && hooks.now ? hooks.now() : 0); break; + + case 'KeyP': paused = paused ? 0 : 1; Control.paused = paused; break; + case 'KeyF': if (hooks && hooks.fullscreen) hooks.fullscreen(); break; + case 'KeyN': if (hooks && hooks.reseed) hooks.reseed(); break; + + case 'KeyT': + if (CC.Daylight) CC.Daylight.step(hooks && hooks.now ? hooks.now() : 0, + e.shiftKey ? -1 : 1); + break; + case 'KeyY': + if (CC.Daylight) CC.Daylight.freeze(hooks && hooks.now ? hooks.now() : 0); + break; + case 'BracketLeft': if (CC.Weather) CC.Weather.cycle(hooks && hooks.now ? hooks.now() : 0, -1); break; + case 'BracketRight': if (CC.Weather) CC.Weather.cycle(hooks && hooks.now ? hooks.now() : 0, 1); break; + default: hit = 0; + } + + var dg = /^Digit[1-9]$/.test(c) ? parseInt(c.slice(5), 10) + : (h && h.length === 1 && h >= '1' && h <= '9' ? h.charCodeAt(0) - 48 : 0); + if (!hit && dg) { + if (e.shiftKey) { + + if (CC.Weather && /^Digit[1-9]$/.test(c) && dg <= CC.Weather.PRESETS.length) { + CC.Weather.set(dg - 1, hooks && hooks.now ? hooks.now() : 0); + hit = 2; + } + } else if (hooks && hooks.world && CC.World && dg <= CC.World.count) { + + hooks.world(dg); + hit = 2; + } + } + } + + if (hit === 1) K.any = 1; + else if (hit === 2) K.act = 1; + return hit; + } + + win.addEventListener('keydown', function (e) { + if (e.metaKey || e.ctrlKey && e.code !== 'ControlLeft' || e.altKey) return; + if (e.repeat) { K.any = 1; return; } + if (set(e, 1) && e.code !== 'Tab') { } + }); + win.addEventListener('keyup', function (e) { set(e, 0); }); + + win.addEventListener('blur', function () { + K.fwd = K.back = K.left = K.right = K.run = K.crouch = 0; + K.yawL = K.yawR = K.pitchU = K.pitchD = 0; + K.tx = K.tz = K.trun = 0; + stickId = -1; lookId = -1; mouseDrag = 0; + }); + + var STICK_DEAD = 13, STICK_FULL = 78, STICK_RUN = 0.93; + var TOUCH_LOOK = 0.0038; + var mouseDrag = 0, mlx = 0, mly = 0; + var stickId = -1, stickX0 = 0, stickY0 = 0; + var lookId = -1, llx = 0, lly = 0; + + function isTouch(e) { return e.pointerType === 'touch' || e.pointerType === 'pen'; } + + el.addEventListener('pointerdown', function (e) { + if (el.setPointerCapture) { try { el.setPointerCapture(e.pointerId); } catch (err) {} } + if (!isTouch(e)) { mouseDrag = 1; mlx = e.clientX; mly = e.clientY; return; } + + Control.touch = 1; + var w = win.innerWidth || el.clientWidth || 800; + if (e.clientX < w * 0.5) { + if (stickId < 0) { stickId = e.pointerId; stickX0 = e.clientX; stickY0 = e.clientY; } + } else if (lookId < 0) { lookId = e.pointerId; llx = e.clientX; lly = e.clientY; } + + }); + + function release(e) { + if (e.pointerId === stickId) { stickId = -1; K.tx = 0; K.tz = 0; K.trun = 0; } + else if (e.pointerId === lookId) lookId = -1; + else mouseDrag = 0; + } + win.addEventListener('pointerup', release); + win.addEventListener('pointercancel', release); + + win.addEventListener('pointermove', function (e) { + if (doc.pointerLockElement === el) { + K.mdx += e.movementX || 0; K.mdy += e.movementY || 0; + if (e.movementX || e.movementY) K.any = 1; + return; + } + if (e.pointerId === stickId) { + var dx = e.clientX - stickX0, dy = e.clientY - stickY0; + var m = Math.sqrt(dx * dx + dy * dy); + if (m <= STICK_DEAD) { K.tx = 0; K.tz = 0; K.trun = 0; return; } + + var g = (m - STICK_DEAD) / (STICK_FULL - STICK_DEAD); + if (g > 1) g = 1; + K.tx = dx / m * g; + K.tz = -dy / m * g; + K.trun = g >= STICK_RUN ? 1 : 0; + K.any = 1; + return; + } + if (e.pointerId === lookId) { + K.mdx += (e.clientX - llx) * (TOUCH_LOOK / MOUSE); + K.mdy += (e.clientY - lly) * (TOUCH_LOOK / MOUSE); + llx = e.clientX; lly = e.clientY; + K.any = 1; + return; + } + if (!mouseDrag) return; + K.mdx += e.clientX - mlx; K.mdy += e.clientY - mly; + mlx = e.clientX; mly = e.clientY; + K.any = 1; + }); + win.addEventListener('wheel', function (e) { + fovT = clamp(fovT + (e.deltaY > 0 ? 0.045 : -0.045), 1.02, 1.52); + K.any = 1; + }, { passive: true }); + + if (el.style) { el.style.touchAction = 'none'; } + + win.addEventListener('gamepadconnected', function () { padSeen = 1; }); + + Control.requestLook = function () { + if (el.requestPointerLock && doc.pointerLockElement !== el) { + + try { + var p = el.requestPointerLock(); + if (p && p.catch) p.catch(function () { }); + } catch (err) {} + } }; + } - var mode = 0; - var blend = 0; + var Control = { + attach: attach, update: update, + mode: 0, blend: 0, speed: 0, idle: 0, - var autoOff = 0; - var idle = 0; - var IDLE_RESUME = 15; - var BLEND_IN = 0.18, BLEND_OUT = 1.6; + touch: 0, - var px = 0, pz = 0, pyaw = 0, pitch = 0, vx = 0, vz = 0, bob = 0, crouchK = 0; - var fovT = 1.25; - var placed = 0; + paused: 0, - var WALK = 2.7, RUN = 5.8, CROUCH = 1.25; + hintAlpha: hintAlpha, - var ACCEL = 9.0; + tickHint: function () {}, - var MOUSE = 0.0022, KEYLOOK = 1.35; - var PADLOOK = 2.30; - var PITCH_MAX = 0.30; + get pose() { return { x: px, z: pz, yaw: pyaw, pitch: pitch, mode: mode, blend: blend }; }, + reset: function () { + mode = 0; blend = 0; autoOff = 0; idle = 0; placed = 0; pitch = 0; apitch = 0; fovT = 1.25; + vx = 0; vz = 0; bob = 0; crouchK = 0; qYaw = 0; qPitch = 0; + K.fwd = K.back = K.left = K.right = K.run = K.crouch = 0; + K.yawL = K.yawR = K.pitchU = K.pitchD = 0; K.mdx = 0; K.mdy = 0; K.any = 0; K.act = 0; + K.tx = K.tz = K.trun = 0; K.gx = K.gz = K.grun = 0; K.glx = K.gly = 0; + seedWanted = 0; padWorld = 0; - var qYaw = 0, qPitch = 0; - var LOOK_LAG = 22, YAW_MAX = 3.1, YAW_MAX_RM = 1.15; - var paused = 0; - - var RAD = 0.34; - function solid(city, x, z) { - if (!city || !city.height) return false; - return city.height(x, z) > 0 || - city.height(x + RAD, z) > 0 || city.height(x - RAD, z) > 0 || - city.height(x, z + RAD) > 0 || city.height(x, z - RAD) > 0; + paused = 0; Control.paused = 0; + hintOpen = 0; hintClose = HINT_IN + HINT_HOLD; } + }; - function move(city, nx, nz) { - if (!solid(city, nx, pz)) px = nx; - if (!solid(city, px, nz)) pz = nz; - } - - function angDelta(a, b) { - var d = b - a; - while (d > Math.PI) d -= 6.283185307; - while (d < -Math.PI) d += 6.283185307; - return d; - } - - var A = { x: 0, z: 0, yaw: 0, eyeY: 1.7, fov: 1.25 }; - - function seedFromAuto() { - px = A.x; pz = A.z; pyaw = A.yaw; vx = 0; vz = 0; placed = 1; seedWanted = 0; - - pitch = apitch; - } - - var apitch = 0; - var AUTO_PITCH = 0.15; - var AUTO_LO = 26, AUTO_HI = 52; - var AUTO_RATE = 0.55; - var SWAY = 0.025; - - function autoLook(dt, city, ta) { - var tgt = 0; - if (city && city.height) { - var fx = Math.sin(A.yaw), fz = Math.cos(A.yaw); - - var h = 0, hh; - hh = city.height(A.x + fx * 5 + fz * 4.5, A.z + fz * 5 - fx * 4.5); if (hh > h) h = hh; - hh = city.height(A.x + fx * 5 - fz * 4.5, A.z + fz * 5 + fx * 4.5); if (hh > h) h = hh; - hh = city.height(A.x + fx * 13 + fz * 5, A.z + fz * 13 - fx * 5); if (hh > h) h = hh; - hh = city.height(A.x + fx * 13 - fz * 5, A.z + fz * 13 + fx * 5); if (hh > h) h = hh; - var u = (h - AUTO_LO) / (AUTO_HI - AUTO_LO); - if (u < 0) u = 0; else if (u > 1) u = 1; - tgt = smooth(u) * AUTO_PITCH; - } - - tgt += (CC.vnoise(ta * 0.043, 1913) - 0.5) * 2 * SWAY; - if (CC.reducedMotion) tgt *= 0.45; - apitch += (tgt - apitch) * Math.min(1, dt * AUTO_RATE); - } - - var seedWanted = 0; - - function takeOver() { - if (mode) return; - mode = 1; - vx = 0; vz = 0; - seedWanted = 1; - } - - function giveBack(city, t) { - if (!mode) return; - mode = 0; - if (t === undefined) t = 0; - - if (city && city.nearestRouteS) { - var sp = city.SPEED || 1.6; - if (city.ensureRoute) city.ensureRoute(sp * (t - autoOff) + 80); - autoOff = t - city.nearestRouteS(px, pz).s / sp; - } - } - - function dead(v, d) { - if (v > d) return (v - d) / (1 - d); - if (v < -d) return (v + d) / (1 - d); - return 0; - } - var PAD_DZ = 0.16; - - var padSeen = 0, padProbe = 0; - - var padWorld = 0; - function pollPad(dt) { - K.gx = 0; K.gz = 0; K.grun = 0; K.glx = 0; K.gly = 0; - if (typeof navigator === 'undefined' || !navigator.getGamepads) return; - if (!padSeen) { - padProbe -= dt; - if (padProbe > 0) return; - padProbe = 1; - } - var pads = navigator.getGamepads(); - if (!pads) return; - for (var i = 0; i < pads.length; i++) { - var p = pads[i]; - if (!p || !p.connected || !p.axes || p.axes.length < 2) continue; - padSeen = 1; - var lx = dead(p.axes[0] || 0, PAD_DZ), ly = dead(p.axes[1] || 0, PAD_DZ); - - K.gx += lx; K.gz += -ly; - if (p.axes.length >= 4) { - K.glx += dead(p.axes[2] || 0, PAD_DZ); - K.gly += -dead(p.axes[3] || 0, PAD_DZ); - } - var b = p.buttons; - if (b) { - - for (var j = 4; j <= 7; j++) { - var bb = b[j]; - if (!bb) continue; - var v = typeof bb === 'number' ? bb : (bb.value !== undefined ? bb.value : (bb.pressed ? 1 : 0)); - if (v > 0.35) K.grun = 1; - } - - var y = b[3]; - var down = y ? (typeof y === 'number' ? y > 0.5 : !!y.pressed) : false; - if (down && !padWorld && CC.World && hooksRef && hooksRef.world) { - - hooksRef.world(CC.World.LIST[(CC.World.index + 1) % CC.World.count].id); - K.act = 1; - } - padWorld = down; - } - } - - if (K.gx || K.gz || K.glx || K.gly || K.grun) K.any = 1; - } - - function update(dt, t, cam, city) { - if (!(dt > 0)) dt = 1 / 60; - var k = CC.reducedMotion ? 0.5 : 1; - - pollPad(dt); - - if (K.any || K.act) { - idle = 0; - if (K.any && !mode) takeOver(); - K.any = 0; K.act = 0; - } else idle += dt; - - if (mode && !paused && idle > IDLE_RESUME) giveBack(city, t); - - if (mode && !paused) autoOff += dt; - if (city && city.camera) city.camera(A, city, t - autoOff); - else { A.x = cam.x; A.z = cam.z; A.yaw = cam.yaw; A.eyeY = 1.7; } - - if (!paused) autoLook(dt, city, t - autoOff); - - if (!placed || seedWanted) seedFromAuto(); - - qYaw += (K.mdx * MOUSE) + (K.yawR - K.yawL) * KEYLOOK * dt + - K.glx * (K.glx < 0 ? -K.glx : K.glx) * PADLOOK * dt; - qPitch += (-K.mdy * MOUSE * 0.62) + (K.pitchU - K.pitchD) * KEYLOOK * 0.5 * dt + - K.gly * (K.gly < 0 ? -K.gly : K.gly) * PADLOOK * 0.42 * dt; - K.mdx = 0; K.mdy = 0; - - var lag = Math.min(1, dt * LOOK_LAG); - var maxYaw = (CC.reducedMotion ? YAW_MAX_RM : YAW_MAX) * dt; - var dy = qYaw * lag; - if (dy > maxYaw) dy = maxYaw; else if (dy < -maxYaw) dy = -maxYaw; - var dp = qPitch * lag; - - if (dy > -1e-7 && dy < 1e-7) { dy = qYaw; qYaw = 0; } else qYaw -= dy; - if (dp > -1e-7 && dp < 1e-7) { dp = qPitch; qPitch = 0; } else qPitch -= dp; - - if (mode) { - pyaw += dy; - pitch = clamp(pitch + dp, -PITCH_MAX, PITCH_MAX); - } - - var tgtC = K.crouch ? 1 : 0; - crouchK += (tgtC - crouchK) * Math.min(1, dt * 7); - - var mf = (K.fwd - K.back) + K.tz + K.gz, ms = (K.right - K.left) + K.tx + K.gx; - var sp = (K.crouch ? CROUCH : ((K.run || K.trun || K.grun) ? RUN : WALK)) * k; - - var ml = Math.sqrt(mf * mf + ms * ms); - if (ml > 1) { mf /= ml; ms /= ml; } - var tvx = 0, tvz = 0; - if (ml > 0.001) { - - var fx = Math.sin(pyaw), fz = Math.cos(pyaw); - tvx = (fx * mf + fz * ms) * sp; - tvz = (fz * mf - fx * ms) * sp; - } - var a = Math.min(1, dt * ACCEL); - vx += (tvx - vx) * a; vz += (tvz - vz) * a; - - if (mode) move(city, px + vx * dt, pz + vz * dt); - else { px = A.x; pz = A.z; } - - var spd = Math.sqrt(vx * vx + vz * vz); - bob += spd * dt * 2.1; - - var bobA = CC.reducedMotion ? 0.012 : 0.034; - var pEye = 1.66 - crouchK * 0.52 + Math.sin(bob * 3.1) * bobA * Math.min(1, spd / WALK); - - var tgtB = mode ? 1 : 0; - var rate = mode ? BLEND_IN : BLEND_OUT; - blend += clamp((tgtB - blend), -1, 1) * Math.min(1, dt / rate); - if (blend < 0.0005) blend = 0; else if (blend > 0.9995) blend = 1; - var b = smooth(blend); - - cam.x = A.x + (px - A.x) * b; - cam.z = A.z + (pz - A.z) * b; - cam.yaw = A.yaw + angDelta(A.yaw, pyaw) * b; - cam.eyeY = A.eyeY + (pEye - A.eyeY) * b; - - if (cam.horizonBase === undefined) cam.horizonBase = cam.horizon; - var hb = cam.horizonBase; - - var rows = cam.rows || (hb / 0.56); - - cam.horizon = hb + (apitch + (pitch - apitch) * b) * rows; - - cam.fov = A.fov + (fovT - A.fov) * b; - - Control.mode = mode; Control.blend = b; Control.speed = spd * b; Control.idle = idle; - Control.paused = paused; - return cam; - } - - var HINT_IN = 1.0, HINT_HOLD = 7.0, HINT_OUT = 1.2; - var hintOpen = 0, hintClose = HINT_IN + HINT_HOLD; - - function hintAlpha(t) { - if (!(t >= 0)) t = 0; - var a = (t - hintOpen) / HINT_IN; if (a > 1) a = 1; else if (a < 0) a = 0; - var b = 1 - (t - hintClose) / HINT_OUT; if (b > 1) b = 1; else if (b < 0) b = 0; - return a * b; - } - - function hintToggle(t) { - if (!(t >= 0)) t = 0; - if (t < hintClose) { hintClose = t; return; } - - var cur = hintAlpha(t); - hintOpen = t - HINT_IN * cur; - hintClose = t + HINT_IN + HINT_HOLD; - } - - var el = null; - - var hooksRef = null; - - function attach(win, doc, canvas, hooks) { - if (!win || !doc) return; - hooksRef = hooks || null; - el = canvas || doc.documentElement; - - function set(e, down) { - var c = e.code || '', h = e.key || ''; - var hit = 1; - switch (c) { - case 'KeyW': case 'Numpad8': K.fwd = down; break; - case 'KeyS': case 'Numpad5': K.back = down; break; - case 'KeyA': K.left = down; break; - case 'KeyD': K.right = down; break; - case 'ArrowLeft': K.yawL = down; break; - case 'ArrowRight': K.yawR = down; break; - case 'ArrowUp': K.pitchU = down; break; - case 'ArrowDown': K.pitchD = down; break; - case 'ShiftLeft': case 'ShiftRight': K.run = down; break; - case 'KeyC': case 'ControlLeft': K.crouch = down; break; - default: hit = 0; - } - if (!hit && down) { - hit = 2; - switch (c) { - case 'Tab': - if (mode) { giveBack(hooks && hooks.city && hooks.city(), - hooks && hooks.now ? hooks.now() : 0); idle = 0; } - else { takeOver(); hit = 1; } - e.preventDefault(); - break; - case 'Escape': giveBack(hooks && hooks.city && hooks.city(), - hooks && hooks.now ? hooks.now() : 0); idle = 0; - if (doc.exitPointerLock) doc.exitPointerLock(); - break; - case 'KeyH': hintToggle(hooks && hooks.now ? hooks.now() : 0); break; - - case 'KeyP': paused = paused ? 0 : 1; Control.paused = paused; break; - case 'KeyF': if (hooks && hooks.fullscreen) hooks.fullscreen(); break; - case 'KeyN': if (hooks && hooks.reseed) hooks.reseed(); break; - - case 'KeyT': - if (CC.Daylight) CC.Daylight.step(hooks && hooks.now ? hooks.now() : 0, - e.shiftKey ? -1 : 1); - break; - case 'KeyY': - if (CC.Daylight) CC.Daylight.freeze(hooks && hooks.now ? hooks.now() : 0); - break; - case 'BracketLeft': if (CC.Weather) CC.Weather.cycle(hooks && hooks.now ? hooks.now() : 0, -1); break; - case 'BracketRight': if (CC.Weather) CC.Weather.cycle(hooks && hooks.now ? hooks.now() : 0, 1); break; - default: hit = 0; - } - - var dg = /^Digit[1-9]$/.test(c) ? parseInt(c.slice(5), 10) - : (h && h.length === 1 && h >= '1' && h <= '9' ? h.charCodeAt(0) - 48 : 0); - if (!hit && dg) { - if (e.shiftKey) { - - if (CC.Weather && /^Digit[1-9]$/.test(c) && dg <= CC.Weather.PRESETS.length) { - CC.Weather.set(dg - 1, hooks && hooks.now ? hooks.now() : 0); - hit = 2; - } - } else if (hooks && hooks.world && CC.World && dg <= CC.World.count) { - - hooks.world(dg); - hit = 2; - } - } - } - - if (hit === 1) K.any = 1; - else if (hit === 2) K.act = 1; - return hit; - } - - win.addEventListener('keydown', function (e) { - if (e.metaKey || e.ctrlKey && e.code !== 'ControlLeft' || e.altKey) return; - if (e.repeat) { K.any = 1; return; } - if (set(e, 1) && e.code !== 'Tab') { } - }); - win.addEventListener('keyup', function (e) { set(e, 0); }); - - win.addEventListener('blur', function () { - K.fwd = K.back = K.left = K.right = K.run = K.crouch = 0; - K.yawL = K.yawR = K.pitchU = K.pitchD = 0; - K.tx = K.tz = K.trun = 0; - stickId = -1; lookId = -1; mouseDrag = 0; - }); - - var STICK_DEAD = 13, STICK_FULL = 78, STICK_RUN = 0.93; - var TOUCH_LOOK = 0.0038; - var mouseDrag = 0, mlx = 0, mly = 0; - var stickId = -1, stickX0 = 0, stickY0 = 0; - var lookId = -1, llx = 0, lly = 0; - - function isTouch(e) { return e.pointerType === 'touch' || e.pointerType === 'pen'; } - - el.addEventListener('pointerdown', function (e) { - if (el.setPointerCapture) { try { el.setPointerCapture(e.pointerId); } catch (err) {} } - if (!isTouch(e)) { mouseDrag = 1; mlx = e.clientX; mly = e.clientY; return; } - - Control.touch = 1; - var w = win.innerWidth || el.clientWidth || 800; - if (e.clientX < w * 0.5) { - if (stickId < 0) { stickId = e.pointerId; stickX0 = e.clientX; stickY0 = e.clientY; } - } else if (lookId < 0) { lookId = e.pointerId; llx = e.clientX; lly = e.clientY; } - - }); - - function release(e) { - if (e.pointerId === stickId) { stickId = -1; K.tx = 0; K.tz = 0; K.trun = 0; } - else if (e.pointerId === lookId) lookId = -1; - else mouseDrag = 0; - } - win.addEventListener('pointerup', release); - win.addEventListener('pointercancel', release); - - win.addEventListener('pointermove', function (e) { - if (doc.pointerLockElement === el) { - K.mdx += e.movementX || 0; K.mdy += e.movementY || 0; - if (e.movementX || e.movementY) K.any = 1; - return; - } - if (e.pointerId === stickId) { - var dx = e.clientX - stickX0, dy = e.clientY - stickY0; - var m = Math.sqrt(dx * dx + dy * dy); - if (m <= STICK_DEAD) { K.tx = 0; K.tz = 0; K.trun = 0; return; } - - var g = (m - STICK_DEAD) / (STICK_FULL - STICK_DEAD); - if (g > 1) g = 1; - K.tx = dx / m * g; - K.tz = -dy / m * g; - K.trun = g >= STICK_RUN ? 1 : 0; - K.any = 1; - return; - } - if (e.pointerId === lookId) { - K.mdx += (e.clientX - llx) * (TOUCH_LOOK / MOUSE); - K.mdy += (e.clientY - lly) * (TOUCH_LOOK / MOUSE); - llx = e.clientX; lly = e.clientY; - K.any = 1; - return; - } - if (!mouseDrag) return; - K.mdx += e.clientX - mlx; K.mdy += e.clientY - mly; - mlx = e.clientX; mly = e.clientY; - K.any = 1; - }); - win.addEventListener('wheel', function (e) { - fovT = clamp(fovT + (e.deltaY > 0 ? 0.045 : -0.045), 1.02, 1.52); - K.any = 1; - }, { passive: true }); - - if (el.style) { el.style.touchAction = 'none'; } - - win.addEventListener('gamepadconnected', function () { padSeen = 1; }); - - Control.requestLook = function () { - if (el.requestPointerLock && doc.pointerLockElement !== el) { - - try { - var p = el.requestPointerLock(); - if (p && p.catch) p.catch(function () { }); - } catch (err) {} - } - }; - } - - var Control = { - attach: attach, update: update, - mode: 0, blend: 0, speed: 0, idle: 0, - - touch: 0, - - paused: 0, - - hintAlpha: hintAlpha, - - tickHint: function () {}, - - get pose() { return { x: px, z: pz, yaw: pyaw, pitch: pitch, mode: mode, blend: blend }; }, - reset: function () { - mode = 0; blend = 0; autoOff = 0; idle = 0; placed = 0; pitch = 0; apitch = 0; fovT = 1.25; - vx = 0; vz = 0; bob = 0; crouchK = 0; qYaw = 0; qPitch = 0; - K.fwd = K.back = K.left = K.right = K.run = K.crouch = 0; - K.yawL = K.yawR = K.pitchU = K.pitchD = 0; K.mdx = 0; K.mdy = 0; K.any = 0; K.act = 0; - K.tx = K.tz = K.trun = 0; K.gx = K.gz = K.grun = 0; K.glx = K.gly = 0; - seedWanted = 0; padWorld = 0; - - paused = 0; Control.paused = 0; - hintOpen = 0; hintClose = HINT_IN + HINT_HOLD; - } - }; - - if (CC) CC.Control = Control; + if (CC) CC.Control = Control; })(CC); /* src/elements/ads.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2, clamp = CC.clamp, smooth = CC.smooth; + var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2, clamp = CC.clamp, smooth = CC.smooth; - var G_8 = g('8'), G_HASH = g('#'), G_M = g('M'), G_W = g('W'), G_X = g('X'), - G_0 = g('0'), G_AT = g('@'), G_N = g('N'), G_Q = g('Q'), G_O = g('O'); - var G_EQ = g('='), G_DASH = g('-'), G_COLON = g(':'), G_STAR = g('*'), - G_PLUS = g('+'), G_SEMI = g(';'), G_o = g('o'), G_PCT = g('%'); - var MASS_G = [G_8, G_HASH, G_M, G_W, G_X, G_0, G_AT, G_N, G_Q, G_O], MASS_N = 10; - var TEXT_G = [G_EQ, G_DASH, G_COLON, G_STAR, G_PLUS, G_SEMI, G_o, G_PCT], TEXT_N = 8; + var G_8 = g('8'), G_HASH = g('#'), G_M = g('M'), G_W = g('W'), G_X = g('X'), + G_0 = g('0'), G_AT = g('@'), G_N = g('N'), G_Q = g('Q'), G_O = g('O'); + var G_EQ = g('='), G_DASH = g('-'), G_COLON = g(':'), G_STAR = g('*'), + G_PLUS = g('+'), G_SEMI = g(';'), G_o = g('o'), G_PCT = g('%'); + var MASS_G = [G_8, G_HASH, G_M, G_W, G_X, G_0, G_AT, G_N, G_Q, G_O], MASS_N = 10; + var TEXT_G = [G_EQ, G_DASH, G_COLON, G_STAR, G_PLUS, G_SEMI, G_o, G_PCT], TEXT_N = 8; - var PEAK = [196, 95, 220, 150, 255, 205, 150, 255, 200, 180, 150, 9]; + var PEAK = [196, 95, 220, 150, 255, 205, 150, 255, 200, 180, 150, 9]; - var PANEL_LUM = 9; + var PANEL_LUM = 9; - var SWEEP_AMP = 0.30; - var SWEEP_RATE = 0.22; - var CUT_MIN = 15.0, CUT_VAR = 5.0; + var SWEEP_AMP = 0.30; + var SWEEP_RATE = 0.22; + var CUT_MIN = 15.0, CUT_VAR = 5.0; - var DISSOLVE = 2.6; - var CELL_FADE = 0.36; - var CELL_CF = 2 * CELL_FADE / DISSOLVE; + var DISSOLVE = 2.6; + var CELL_FADE = 0.36; + var CELL_CF = 2 * CELL_FADE / DISSOLVE; - var FADE_H = CELL_CF * 0.5, FADE_SPAN = 1 - CELL_CF; + var FADE_H = CELL_CF * 0.5, FADE_SPAN = 1 - CELL_CF; - var NEAR = 7.0, FAR = 52.0, DISS_W = 10.0; + var NEAR = 7.0, FAR = 52.0, DISS_W = 10.0; - var AREA_MAX = 620; + var AREA_MAX = 620; - var FONT = [ - 0x0E,0x11,0x11,0x1F,0x11,0x11,0x11, - 0x0E,0x11,0x10,0x10,0x10,0x11,0x0E, - 0x1F,0x10,0x10,0x1E,0x10,0x10,0x1F, - 0x11,0x12,0x14,0x18,0x14,0x12,0x11, - 0x11,0x19,0x19,0x15,0x13,0x13,0x11, - 0x0E,0x11,0x11,0x11,0x11,0x11,0x0E, - 0x1E,0x11,0x11,0x1E,0x14,0x12,0x11, - 0x0F,0x10,0x10,0x0E,0x01,0x01,0x1E, - 0x1F,0x04,0x04,0x04,0x04,0x04,0x04, - 0x11,0x11,0x0A,0x04,0x0A,0x11,0x11, - 0x11,0x11,0x0A,0x04,0x04,0x04,0x04, - 0x1F,0x01,0x02,0x04,0x08,0x10,0x1F - ]; + var FONT = [ + 0x0E,0x11,0x11,0x1F,0x11,0x11,0x11, + 0x0E,0x11,0x10,0x10,0x10,0x11,0x0E, + 0x1F,0x10,0x10,0x1E,0x10,0x10,0x1F, + 0x11,0x12,0x14,0x18,0x14,0x12,0x11, + 0x11,0x19,0x19,0x15,0x13,0x13,0x11, + 0x0E,0x11,0x11,0x11,0x11,0x11,0x0E, + 0x1E,0x11,0x11,0x1E,0x14,0x12,0x11, + 0x0F,0x10,0x10,0x0E,0x01,0x01,0x1E, + 0x1F,0x04,0x04,0x04,0x04,0x04,0x04, + 0x11,0x11,0x0A,0x04,0x0A,0x11,0x11, + 0x11,0x11,0x0A,0x04,0x04,0x04,0x04, + 0x1F,0x01,0x02,0x04,0x08,0x10,0x1F + ]; - var WORDS = [ 4,5,9, 1,0,8, 7,0,11, 2,3,5, 6,2,9, 8,5,3, 0,11,4, 5,6,1 ], WORD_N = 8; + var WORDS = [ 4,5,9, 1,0,8, 7,0,11, 2,3,5, 6,2,9, 8,5,3, 0,11,4, 5,6,1 ], WORD_N = 8; - function rel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } - var AT = { dim: 1, far: FAR }; - function airPrep() { - var f = rel('fog'); - AT.dim = clamp(1 - 0.13 * (f - 1), 0.72, 1.06); - AT.far = clamp(FAR * (1 - 0.22 * (f - 1)), 28, 54); - } + function rel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } + var AT = { dim: 1, far: FAR }; + function airPrep() { + var f = rel('fog'); + AT.dim = clamp(1 - 0.13 * (f - 1), 0.72, 1.06); + AT.far = clamp(FAR * (1 - 0.22 * (f - 1)), 28, 54); + } - var CO = { cols: 0, rows: 0, horizon: 0, hp: 0, scale: 1, eyeY: 1.7, - ox: 0, oz: 0, fwx: 0, fwz: 1, rgx: 1, rgz: 0 }; - function setCam(frame, cam) { - CO.cols = frame.cols; CO.rows = frame.rows; - CO.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; - CO.hp = Math.tan((cam.fov || 1.25) * 0.5); - CO.scale = cam.scaleY !== undefined ? cam.scaleY - : (frame.cols * (cam.cellAspect || 0.5625)) / (2 * CO.hp); - CO.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - CO.ox = cam.x; CO.oz = cam.z; - var yaw = cam.yaw || 0; - CO.fwx = Math.sin(yaw); CO.fwz = Math.cos(yaw); - CO.rgx = Math.cos(yaw); CO.rgz = -Math.sin(yaw); - } - var VA = { x: 0, w: 0 }, VB = { x: 0, w: 0 }; - function projInto(px, py, pz, O) { - var rx = px - CO.ox, rz = pz - CO.oz; - var w = rx * CO.fwx + rz * CO.fwz; - if (w < 1.2) return false; - var sp = (rx * CO.rgx + rz * CO.rgz) / w; - O.x = (sp / CO.hp + 1) * 0.5 * CO.cols - 0.5; - O.w = w; + var CO = { cols: 0, rows: 0, horizon: 0, hp: 0, scale: 1, eyeY: 1.7, + ox: 0, oz: 0, fwx: 0, fwz: 1, rgx: 1, rgz: 0 }; + function setCam(frame, cam) { + CO.cols = frame.cols; CO.rows = frame.rows; + CO.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; + CO.hp = Math.tan((cam.fov || 1.25) * 0.5); + CO.scale = cam.scaleY !== undefined ? cam.scaleY + : (frame.cols * (cam.cellAspect || 0.5625)) / (2 * CO.hp); + CO.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + CO.ox = cam.x; CO.oz = cam.z; + var yaw = cam.yaw || 0; + CO.fwx = Math.sin(yaw); CO.fwz = Math.cos(yaw); + CO.rgx = Math.cos(yaw); CO.rgz = -Math.sin(yaw); + } + var VA = { x: 0, w: 0 }, VB = { x: 0, w: 0 }; + function projInto(px, py, pz, O) { + var rx = px - CO.ox, rz = pz - CO.oz; + var w = rx * CO.fwx + rz * CO.fwz; + if (w < 1.2) return false; + var sp = (rx * CO.rgx + rz * CO.rgz) / w; + O.x = (sp / CO.hp + 1) * 0.5 * CO.cols - 0.5; + O.w = w; + return true; + } + + var HKX = [0, 104729, 611953, 1999993, 3391993, 4796027, 7919, 2750159, 4256233, 1299709]; + var HKZ = [0, 4256233, 1299709, 4796027, 611953, 2750159, 3391993, 104729, 7919, 1999993]; + function hk(a, b, salt, i) { return hash2(a + HKX[i], b + HKZ[i], salt); } + + function crest(d, hold, soft) { + d -= Math.floor(d); + if (d > 0.5) d = 1 - d; + return smooth(clamp((hold + soft - d) / soft, 0, 1)); + } + + var FACE = { nx: 0, nz: 0, fx: 0, fz: 0 }; + function faceOf(city, gx, gz, rx, rz) { + var xFirst = (rx < 0 ? -rx : rx) > (rz < 0 ? -rz : rz); + var i, nx, nz; + for (i = 0; i < 2; i++) { + if ((i === 0) === xFirst) { nx = rx > 0 ? -1 : 1; nz = 0; } + else { nx = 0; nz = rz > 0 ? -1 : 1; } + if (city.height(gx + nx, gz + nz) <= 0) { + FACE.nx = nx; FACE.nz = nz; + FACE.fx = gx + 0.5 + nx * 0.5; FACE.fz = gz + 0.5 + nz * 0.5; return true; + } + } + return false; + } + + var AD = { + ax: 0, az: 0, bx: 0, bz: 0, + v0: 0, H: 0, + NC: 0, NR: 0, + hue: 0, hue2: 0, acc: 0, + sd: 0, ph: 0, + modeA: 0, modeB: 0, mix: 0, + w0: 0, w1: 0, w2: 0, + lamp: 0, + sweep: 0 + }; + + var MODE_FIGURE = 0, MODE_WORD = 1, MODE_PRODUCT = 2; + + function setup(city, gx, gz, t) { + var bh = city.height(gx, gz); + if (bh < 15) return 0; + + var rx = gx + 0.5 - CO.ox, rz = gz + 0.5 - CO.oz; + if (!faceOf(city, gx, gz, rx, rz)) return 0; + var nx = FACE.nx, nz = FACE.nz; + + var rlen = Math.sqrt(rx * rx + rz * rz); + if (rlen < 1e-3) return 0; + var facing = -(nx * rx + nz * rz) / rlen; + if (facing < 0.18) return 0; + + var tx = nz, tz = -nx; + var minH = bh, i, hx, hz, hA, hB; + for (i = 1; i <= 5; i++) { + hx = gx + tx * i; hz = gz + tz * i; + hA = city.height(hx, hz); + if (hA < 13 || city.height(hx + nx, hz + nz) > 0) break; + hx = gx - tx * i; hz = gz - tz * i; + hB = city.height(hx, hz); + if (hB < 13 || city.height(hx + nx, hz + nz) > 0) break; + if (hA < minH) minH = hA; + if (hB < minH) minH = hB; + } + var half = i - 1; + if (half < 2) return 0; + + var r1 = hk(gx, gz, SALT, 1), r2 = hk(gx, gz, SALT, 2), r3 = hk(gx, gz, SALT, 3); + var r4 = hk(gx, gz, SALT, 4), r5 = hk(gx, gz, SALT, 5), r6 = hk(gx, gz, SALT, 6); + var r7 = hk(gx, gz, SALT, 7), r8 = hk(gx, gz, SALT, 8), r9 = hk(gx, gz, SALT, 9); + + var W = 2 * (half + 0.35); + + var wWant = 7.2 + r3 * 3.8; + if (W > wWant) W = wWant; + + var H = r2 < 0.62 ? W * (0.42 + 0.22 * r4) : W * (0.95 + 0.55 * r4); + + if (H > 7.0) H = 7.0; + if (H > minH - 7.3) H = minH - 7.3; + if (H < 4.2) return 0; + + var v0hi = minH - H - 2.5; + var tv = 12.0 - H; + if (tv < v0hi) v0hi = tv; + if (v0hi < 4.6) return 0; + var v0 = 4.6 + r9 * (v0hi - 4.6); + + var cx = FACE.fx + nx * 0.34, cz = FACE.fz + nz * 0.34; + AD.ax = cx - tx * W * 0.5; AD.az = cz - tz * W * 0.5; + AD.bx = cx + tx * W * 0.5; AD.bz = cz + tz * W * 0.5; + AD.v0 = v0; AD.H = H; + + AD.NC = Math.round(W / 0.55); if (AD.NC < 8) AD.NC = 8; else if (AD.NC > 20) AD.NC = 20; + AD.NR = Math.round(H / 0.55); if (AD.NR < 8) AD.NR = 8; else if (AD.NR > 18) AD.NR = 18; + + AD.hue = r1 < 0.48 ? P.amber : r1 < 0.86 ? P.azure : P.ember; + + AD.hue2 = r5 < 0.55 ? (AD.hue === P.azure ? P.amber : P.azure) : AD.hue; + AD.acc = r6 < 0.26 ? P.violet : (AD.hue === P.amber ? P.azure : P.amber); + + AD.sd = 1 + ((hk(gx + 13, gz + 17, SALT, 2) * 29989) | 0); + AD.ph = r7; + AD.lamp = r8 < 0.55 ? 3 : 0; + + var wi = ((hk(gx + 9, gz - 7, SALT, 8) * WORD_N) | 0) * 3; + AD.w0 = WORDS[wi]; AD.w1 = WORDS[wi + 1]; AD.w2 = WORDS[wi + 2]; + + var period = CUT_MIN + AD.ph * CUT_VAR; + var tt = t / period + AD.ph * 7.0; + var cut = Math.floor(tt); + var frac = (tt - cut) * period; + var stride = 1 + ((r3 * 2) | 0); + AD.modeA = (((cut * stride) % 3) + 3) % 3; + AD.modeB = (AD.modeA + stride) % 3; + AD.mix = clamp(frac / DISSOLVE, 0, 1); + AD.sweep = (AD.ph + t * SWEEP_RATE) % 1; + if (CC.reducedMotion) { + + AD.modeA = ((AD.ph * 3) | 0) % 3; AD.modeB = AD.modeA; AD.mix = 0; + AD.sweep = AD.ph; + } + return 1; + } + + function copyAt(cu, cv) { + return ((cv & 1) === 0 && hash2(cu, cv, AD.sd + 7) < 0.66) ? 2 : 0; + } + function inkAt(mode, cu, cv, iu, iv) { + var dx, dy, ex, hw, d, nL, fu, li, fx, bx, by, m, ltr; + if (mode === MODE_WORD) { + if (iv > 0.84) return copyAt(cu, cv); + if (iv > 0.71 && iv < 0.78 && iu > 0.05 && iu < 0.95) return 3; + if (iv < 0.05 || iv > 0.67) return 0; + nL = AD.NC >= 15 ? 3 : 2; + fu = iu * nL; li = fu | 0; if (li >= nL) li = nL - 1; + fx = fu - li; + if (fx > 0.84) return 0; + bx = (fx / 0.84 * 5) | 0; if (bx > 4) bx = 4; + by = ((iv - 0.05) / 0.62 * 7) | 0; if (by > 6) by = 6; + ltr = li === 0 ? AD.w0 : (li === 1 ? AD.w1 : AD.w2); + m = FONT[ltr * 7 + by]; + return ((m >> (4 - bx)) & 1) ? 1 : 0; + } + if (mode === MODE_PRODUCT) { + if (iv > 0.82) return copyAt(cu, cv); + + if (iu < 0.20 || iu > 0.80) return (iv > 0.22 && iv < 0.76) ? copyAt(cu, cv) : 0; + if (iv < 0.06) hw = 0; + else if (iv < 0.13) hw = 0.055; + else if (iv < 0.24) hw = 0.045; + else if (iv < 0.34) hw = 0.045 + (iv - 0.24) * 1.80; + else if (iv < 0.80) hw = 0.225; + else hw = 0; + d = iu - 0.5; if (d < 0) d = -d; + if (d > hw) return 0; + if (iv > 0.46 && iv < 0.60) return 0; + + if (iv > 0.34 && iu < 0.5 && d > hw * 0.55) return 3; + return 1; } - var HKX = [0, 104729, 611953, 1999993, 3391993, 4796027, 7919, 2750159, 4256233, 1299709]; - var HKZ = [0, 4256233, 1299709, 4796027, 611953, 2750159, 3391993, 104729, 7919, 1999993]; - function hk(a, b, salt, i) { return hash2(a + HKX[i], b + HKZ[i], salt); } + if (iv > 0.80) return copyAt(cu, cv); - function crest(d, hold, soft) { - d -= Math.floor(d); - if (d > 0.5) d = 1 - d; - return smooth(clamp((hold + soft - d) / soft, 0, 1)); + dx = (iu - 0.50) / 0.38; dy = (iv - 0.40) / 0.42; + d = dx * dx + dy * dy; + if (d > 1) return 0; + ex = iu < 0.5 ? 0.355 : 0.645; + if ((iu > ex - 0.085 && iu < ex + 0.085) && iv > 0.270 && iv < 0.400) return 0; + if (iu > 0.35 && iu < 0.65 && iv > 0.545 && iv < 0.635) return 0; + if (d > 0.74 && iv < 0.52) return 3; + return 1; + } + + var M = { xL: 0, xR: 0, wL: 0, wR: 0, span: 0, hRows: 0, cy: 0, dist: 0 }; + function measure(cam) { + if (!projInto(AD.ax, AD.v0, AD.az, VA)) return 0; + if (!projInto(AD.bx, AD.v0, AD.bz, VB)) return 0; + if (VA.x <= VB.x) { M.xL = VA.x; M.wL = VA.w; M.xR = VB.x; M.wR = VB.w; } + else { M.xL = VB.x; M.wL = VB.w; M.xR = VA.x; M.wR = VA.w; } + M.span = M.xR - M.xL; + if (M.span < 1) return 0; + if (M.xR < 0 || M.xL > CO.cols - 1) return 0; + var wMid = 2 / (1 / M.wL + 1 / M.wR); + M.hRows = AD.H * CO.scale / wMid; + M.cy = CO.horizon - (AD.v0 + AD.H * 0.5 - CO.eyeY) * CO.scale / wMid; + var spC = (2 * ((M.xL + M.xR) * 0.5 + 0.5) / CO.cols - 1) * CO.hp; + M.dist = wMid * Math.sqrt(1 + spC * spC); + return 1; + } + + function visibleFrac(frame) { + var q, s, x, y, i, n = 0, seen = 0, fr, iw, lim, sp; + for (q = 0; q < 4; q++) { + y = Math.round(M.cy + (q - 1.5) * M.hRows * 0.26); + + if (y < 0 || y > CO.rows - 1) continue; + for (s = 0; s < 4; s++) { + fr = 0.10 + 0.2667 * s; + x = Math.round(M.xL + M.span * fr); + if (x < 0 || x > CO.cols - 1) continue; + n++; + + iw = (1 - fr) / M.wL + fr / M.wR; + sp = (2 * (x + 0.5) / CO.cols - 1) * CO.hp; + lim = 0.90 * Math.sqrt(1 + sp * sp) / iw; + i = y * CO.cols + x; + if (!(frame.dist[i] < lim)) seen++; + } } - var FACE = { nx: 0, nz: 0, fx: 0, fz: 0 }; - function faceOf(city, gx, gz, rx, rz) { - var xFirst = (rx < 0 ? -rx : rx) > (rz < 0 ? -rz : rz); - var i, nx, nz; - for (i = 0; i < 2; i++) { - if ((i === 0) === xFirst) { nx = rx > 0 ? -1 : 1; nz = 0; } - else { nx = 0; nz = rz > 0 ? -1 : 1; } - if (city.height(gx + nx, gz + nz) <= 0) { - FACE.nx = nx; FACE.nz = nz; - FACE.fx = gx + 0.5 + nx * 0.5; FACE.fz = gz + 0.5 + nz * 0.5; - return true; + return n === 0 ? 1 : seen / n; + } + + function clipFrac(cy, hRows, rows) { + var vy0 = cy - hRows * 0.5, vy1 = cy + hRows * 0.5; + if (vy0 < 0) vy0 = 0; + if (vy1 > rows - 1) vy1 = rows - 1; + if (hRows < 1) hRows = 1; + return clamp(((vy1 - vy0) / hRows - 0.55) / 0.15, 0, 1); + } + + function drawAd(frame) { + var cols = CO.cols, rows = CO.rows; + var xL = M.xL, xR = M.xR, wL = M.wL, wR = M.wR, span = M.span; + var xa = Math.floor(xL), xb = Math.ceil(xR); + if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; + if (xb < xa) return; + + var d0 = AT.far - DISS_W; if (d0 < 14) d0 = 14; + var dens = 1 - clamp((M.dist - d0) / (AT.far - d0), 0, 1); + + dens *= clipFrac(M.cy, M.hRows, rows); + if (dens < 0.06) return; + var area = span * (M.hRows < 1 ? 1 : M.hRows); + var idens = area > AREA_MAX ? AREA_MAX / area : 1; + if (idens > dens) idens = dens; + + var NCW = AD.NC, NRW = AD.NR, mix = AD.mix, sd = AD.sd; + var NC = Math.round(span); if (NC < 6) NC = 6; if (NC > NCW) NC = NCW; + var NR = Math.round(M.hRows); if (NR < 6) NR = 6; if (NR > NRW) NR = NRW; + var x, r, s, iw, w, u, sp, dist, yBot, yTop, vspan, vv, cu, cv, iu, iv, r0, r1, lp; + var code, colr, glyph, k, lum, boost, atten, wu, wv, fade, fp, cA, cB; + for (x = xa; x <= xb; x++) { + s = (x + 0.5 - xL) / span; + if (s < 0) s = 0; else if (s > 1) s = 1; + iw = (1 - s) / wL + s / wR; + w = 1 / iw; + u = (s / wR) / iw; + sp = (2 * (x + 0.5) / cols - 1) * CO.hp; + + dist = w * Math.sqrt(1 + sp * sp) * 0.996; + yBot = CO.horizon - (AD.v0 - CO.eyeY) * CO.scale / w; + yTop = yBot - AD.H * CO.scale / w; + vspan = yBot - yTop; + if (vspan < 0.5) vspan = 0.5; + + boost = 1 + SWEEP_AMP * crest(u - AD.sweep, 0.06, 0.18); + + atten = AT.dim * (1 - 0.12 * clamp((dist - 20) / 30, 0, 1)); + + r0 = Math.ceil(yTop); r1 = Math.floor(yBot); + if (r0 < 0) r0 = 0; if (r1 > rows - 1) r1 = rows - 1; + for (r = r0; r <= r1; r++) { + vv = ((r + 0.5) - yTop) / vspan; + if (vv < 0) vv = 0; else if (vv > 1) vv = 1; + cu = (u * NC) | 0; if (cu > NC - 1) cu = NC - 1; + cv = (vv * NR) | 0; if (cv > NR - 1) cv = NR - 1; + wu = (u * NCW) | 0; if (wu > NCW - 1) wu = NCW - 1; + wv = (vv * NRW) | 0; if (wv > NRW - 1) wv = NRW - 1; + + if (dens < 1 && hash2(wu + 5, wv + 3, sd + 19) > dens) continue; + + fade = 1; + if (cu === 0 || cu === NC - 1 || cv === 0 || cv === NR - 1) { + + code = 0; + if (AD.lamp && cv === NR - 1) { + lp = ((cu * 4) / NC) | 0; + if (lp >= 1 && lp <= 3 && ((cu * 4) % NC) < 4) { code = 3; } + } + } else { + iu = (cu - 0.5) / (NC - 2); if (iu < 0) iu = 0; else if (iu > 1) iu = 1; + iv = (cv - 0.5) / (NR - 2); if (iv < 0) iv = 0; else if (iv > 1) iv = 1; + + if (mix <= 0) { code = inkAt(AD.modeA, wu, wv, iu, iv); } + else if (mix >= 1) { code = inkAt(AD.modeB, wu, wv, iu, iv); } + else { + fp = (mix - (FADE_H + hash2(wu + 61, wv + 29, sd + 5) * FADE_SPAN)) / FADE_H; + if (fp <= -1) { code = inkAt(AD.modeA, wu, wv, iu, iv); } + else if (fp >= 1) { code = inkAt(AD.modeB, wu, wv, iu, iv); } + else { + cA = inkAt(AD.modeA, wu, wv, iu, iv); + cB = inkAt(AD.modeB, wu, wv, iu, iv); + if (cA === cB) { code = cA; } + else if (fp < 0) { code = cA; fade = -fp; } + else { code = cB; fade = fp; } } - } - return false; - } + } - var AD = { - ax: 0, az: 0, bx: 0, bz: 0, - v0: 0, H: 0, - NC: 0, NR: 0, - hue: 0, hue2: 0, acc: 0, - sd: 0, ph: 0, - modeA: 0, modeB: 0, mix: 0, - w0: 0, w1: 0, w2: 0, - lamp: 0, - sweep: 0 - }; - - var MODE_FIGURE = 0, MODE_WORD = 1, MODE_PRODUCT = 2; - - function setup(city, gx, gz, t) { - var bh = city.height(gx, gz); - if (bh < 15) return 0; - - var rx = gx + 0.5 - CO.ox, rz = gz + 0.5 - CO.oz; - if (!faceOf(city, gx, gz, rx, rz)) return 0; - var nx = FACE.nx, nz = FACE.nz; - - var rlen = Math.sqrt(rx * rx + rz * rz); - if (rlen < 1e-3) return 0; - var facing = -(nx * rx + nz * rz) / rlen; - if (facing < 0.18) return 0; - - var tx = nz, tz = -nx; - var minH = bh, i, hx, hz, hA, hB; - for (i = 1; i <= 5; i++) { - hx = gx + tx * i; hz = gz + tz * i; - hA = city.height(hx, hz); - if (hA < 13 || city.height(hx + nx, hz + nz) > 0) break; - hx = gx - tx * i; hz = gz - tz * i; - hB = city.height(hx, hz); - if (hB < 13 || city.height(hx + nx, hz + nz) > 0) break; - if (hA < minH) minH = hA; - if (hB < minH) minH = hB; - } - var half = i - 1; - if (half < 2) return 0; - - var r1 = hk(gx, gz, SALT, 1), r2 = hk(gx, gz, SALT, 2), r3 = hk(gx, gz, SALT, 3); - var r4 = hk(gx, gz, SALT, 4), r5 = hk(gx, gz, SALT, 5), r6 = hk(gx, gz, SALT, 6); - var r7 = hk(gx, gz, SALT, 7), r8 = hk(gx, gz, SALT, 8), r9 = hk(gx, gz, SALT, 9); - - var W = 2 * (half + 0.35); - - var wWant = 7.2 + r3 * 3.8; - if (W > wWant) W = wWant; - - var H = r2 < 0.62 ? W * (0.42 + 0.22 * r4) : W * (0.95 + 0.55 * r4); - - if (H > 7.0) H = 7.0; - if (H > minH - 7.3) H = minH - 7.3; - if (H < 4.2) return 0; - - var v0hi = minH - H - 2.5; - var tv = 12.0 - H; - if (tv < v0hi) v0hi = tv; - if (v0hi < 4.6) return 0; - var v0 = 4.6 + r9 * (v0hi - 4.6); - - var cx = FACE.fx + nx * 0.34, cz = FACE.fz + nz * 0.34; - AD.ax = cx - tx * W * 0.5; AD.az = cz - tz * W * 0.5; - AD.bx = cx + tx * W * 0.5; AD.bz = cz + tz * W * 0.5; - AD.v0 = v0; AD.H = H; - - AD.NC = Math.round(W / 0.55); if (AD.NC < 8) AD.NC = 8; else if (AD.NC > 20) AD.NC = 20; - AD.NR = Math.round(H / 0.55); if (AD.NR < 8) AD.NR = 8; else if (AD.NR > 18) AD.NR = 18; - - AD.hue = r1 < 0.48 ? P.amber : r1 < 0.86 ? P.azure : P.ember; - - AD.hue2 = r5 < 0.55 ? (AD.hue === P.azure ? P.amber : P.azure) : AD.hue; - AD.acc = r6 < 0.26 ? P.violet : (AD.hue === P.amber ? P.azure : P.amber); - - AD.sd = 1 + ((hk(gx + 13, gz + 17, SALT, 2) * 29989) | 0); - AD.ph = r7; - AD.lamp = r8 < 0.55 ? 3 : 0; - - var wi = ((hk(gx + 9, gz - 7, SALT, 8) * WORD_N) | 0) * 3; - AD.w0 = WORDS[wi]; AD.w1 = WORDS[wi + 1]; AD.w2 = WORDS[wi + 2]; - - var period = CUT_MIN + AD.ph * CUT_VAR; - var tt = t / period + AD.ph * 7.0; - var cut = Math.floor(tt); - var frac = (tt - cut) * period; - var stride = 1 + ((r3 * 2) | 0); - AD.modeA = (((cut * stride) % 3) + 3) % 3; - AD.modeB = (AD.modeA + stride) % 3; - AD.mix = clamp(frac / DISSOLVE, 0, 1); - AD.sweep = (AD.ph + t * SWEEP_RATE) % 1; - if (CC.reducedMotion) { - - AD.modeA = ((AD.ph * 3) | 0) % 3; AD.modeB = AD.modeA; AD.mix = 0; - AD.sweep = AD.ph; - } - return 1; - } - - function copyAt(cu, cv) { - return ((cv & 1) === 0 && hash2(cu, cv, AD.sd + 7) < 0.66) ? 2 : 0; - } - function inkAt(mode, cu, cv, iu, iv) { - var dx, dy, ex, hw, d, nL, fu, li, fx, bx, by, m, ltr; - if (mode === MODE_WORD) { - if (iv > 0.84) return copyAt(cu, cv); - if (iv > 0.71 && iv < 0.78 && iu > 0.05 && iu < 0.95) return 3; - if (iv < 0.05 || iv > 0.67) return 0; - nL = AD.NC >= 15 ? 3 : 2; - fu = iu * nL; li = fu | 0; if (li >= nL) li = nL - 1; - fx = fu - li; - if (fx > 0.84) return 0; - bx = (fx / 0.84 * 5) | 0; if (bx > 4) bx = 4; - by = ((iv - 0.05) / 0.62 * 7) | 0; if (by > 6) by = 6; - ltr = li === 0 ? AD.w0 : (li === 1 ? AD.w1 : AD.w2); - m = FONT[ltr * 7 + by]; - return ((m >> (4 - bx)) & 1) ? 1 : 0; - } - if (mode === MODE_PRODUCT) { - if (iv > 0.82) return copyAt(cu, cv); - - if (iu < 0.20 || iu > 0.80) return (iv > 0.22 && iv < 0.76) ? copyAt(cu, cv) : 0; - if (iv < 0.06) hw = 0; - else if (iv < 0.13) hw = 0.055; - else if (iv < 0.24) hw = 0.045; - else if (iv < 0.34) hw = 0.045 + (iv - 0.24) * 1.80; - else if (iv < 0.80) hw = 0.225; - else hw = 0; - d = iu - 0.5; if (d < 0) d = -d; - if (d > hw) return 0; - if (iv > 0.46 && iv < 0.60) return 0; - - if (iv > 0.34 && iu < 0.5 && d > hw * 0.55) return 3; - return 1; + if (code !== 0 && idens < 1 && hash2(wu + 23, wv + 41, sd + 29) > idens) code = 0; } - if (iv > 0.80) return copyAt(cu, cv); + if (code === 0) { - dx = (iu - 0.50) / 0.38; dy = (iv - 0.40) / 0.42; - d = dx * dx + dy * dy; - if (d > 1) return 0; - ex = iu < 0.5 ? 0.355 : 0.645; - if ((iu > ex - 0.085 && iu < ex + 0.085) && iv > 0.270 && iv < 0.400) return 0; - if (iu > 0.35 && iu < 0.65 && iv > 0.545 && iv < 0.635) return 0; - if (d > 0.74 && iv < 0.52) return 3; - return 1; + put(frame, x, r, ((wu + wv) & 1) ? G_HASH : G_8, P.shadow, PANEL_LUM, dist); + continue; + } + if (code === 2) { colr = AD.hue2; glyph = TEXT_G[(hash2(wu, wv, sd + 11) * TEXT_N) | 0]; k = 1.0; } + else if (code === 3) { colr = AD.acc; glyph = MASS_G[(hash2(wu, wv, sd + 13) * MASS_N) | 0]; k = 1.06; } + else { colr = AD.hue; glyph = MASS_G[(hash2(wu, wv, sd + 17) * MASS_N) | 0]; k = 1.0; } + lum = PEAK[colr] * atten * boost * k * fade; + if (lum > 255) lum = 255; + + if (lum <= PANEL_LUM) { + put(frame, x, r, ((wu + wv) & 1) ? G_HASH : G_8, P.shadow, PANEL_LUM, dist); + continue; + } + put(frame, x, r, glyph, colr, lum, dist); + } } + } - var M = { xL: 0, xR: 0, wL: 0, wR: 0, span: 0, hRows: 0, cy: 0, dist: 0 }; - function measure(cam) { - if (!projInto(AD.ax, AD.v0, AD.az, VA)) return 0; - if (!projInto(AD.bx, AD.v0, AD.bz, VB)) return 0; - if (VA.x <= VB.x) { M.xL = VA.x; M.wL = VA.w; M.xR = VB.x; M.wR = VB.w; } - else { M.xL = VB.x; M.wL = VB.w; M.xR = VA.x; M.wR = VA.w; } - M.span = M.xR - M.xL; - if (M.span < 1) return 0; - if (M.xR < 0 || M.xL > CO.cols - 1) return 0; - var wMid = 2 / (1 / M.wL + 1 / M.wR); - M.hRows = AD.H * CO.scale / wMid; - M.cy = CO.horizon - (AD.v0 + AD.H * 0.5 - CO.eyeY) * CO.scale / wMid; - var spC = (2 * ((M.xL + M.xR) * 0.5 + 0.5) / CO.cols - 1) * CO.hp; - M.dist = wMid * Math.sqrt(1 + spC * spC); - return 1; - } + var SEL = { n: 0, ax: 0, az: 0, as: 0, bx: 0, bz: 0, bs: 0 }; + var SALT = 0; - function visibleFrac(frame) { - var q, s, x, y, i, n = 0, seen = 0, fr, iw, lim, sp; - for (q = 0; q < 4; q++) { - y = Math.round(M.cy + (q - 1.5) * M.hRows * 0.26); + CC.ELEMENTS.push({ + name: 'ads', - if (y < 0 || y > CO.rows - 1) continue; - for (s = 0; s < 4; s++) { - fr = 0.10 + 0.2667 * s; - x = Math.round(M.xL + M.span * fr); - if (x < 0 || x > CO.cols - 1) continue; - n++; + world: 'cyber', + layer: 34, - iw = (1 - fr) / M.wL + fr / M.wR; - sp = (2 * (x + 0.5) / CO.cols - 1) * CO.hp; - lim = 0.90 * Math.sqrt(1 + sp * sp) / iw; - i = y * CO.cols + x; - if (!(frame.dist[i] < lim)) seen++; + init: function (city, rng) { + this.city = city; + SALT = (rng() * 2147483647) | 0; + }, + + update: function () {}, + + draw: function (frame, cam, t) { + var city = this.city; + if (!city) return; + setCam(frame, cam); + airPrep(); + + var R = AT.far; + var gx0 = Math.floor(CO.ox - R), gx1 = Math.ceil(CO.ox + R); + var gz0 = Math.floor(CO.oz - R), gz1 = Math.ceil(CO.oz + R); + var gx, gz, rx, rz, w, side, lim, vy0, vy1, vx0, vx1, visR, visC, score, cf; + var rows = frame.rows, cols = frame.cols; + SEL.n = 0; SEL.as = 0; SEL.bs = 0; + + for (gz = gz0; gz <= gz1; gz++) { + for (gx = gx0; gx <= gx1; gx++) { + rx = gx + 0.5 - CO.ox; rz = gz + 0.5 - CO.oz; + w = rx * CO.fwx + rz * CO.fwz; + if (w < NEAR || w > R) continue; + side = rx * CO.rgx + rz * CO.rgz; lim = w * CO.hp + 4; + if (side > lim || side < -lim) continue; + + if (city.height(gx, gz) < 15) continue; + if (!setup(city, gx, gz, t)) continue; + if (!measure(cam)) continue; + + if (M.span < 10 || M.hRows < 5) continue; + + if (M.wR > M.wL * 1.8 || M.wL > M.wR * 1.8) continue; + + vy0 = M.cy - M.hRows * 0.5; vy1 = M.cy + M.hRows * 0.5; + if (vy0 < 0) vy0 = 0; if (vy1 > rows - 1) vy1 = rows - 1; + vx0 = M.xL; vx1 = M.xR; + if (vx0 < 0) vx0 = 0; if (vx1 > cols - 1) vx1 = cols - 1; + visR = vy1 - vy0; visC = vx1 - vx0; + if (visR < 8 || visC < 8) continue; + + cf = clipFrac(M.cy, M.hRows, rows); + if (cf <= 0) continue; + + if (visibleFrac(frame) < 0.45) continue; + + score = visR * visC * cf; + if (score > SEL.as) { + + if (SEL.n > 0 && Math.abs(gx - SEL.ax) <= 8 && Math.abs(gz - SEL.az) <= 8) { + SEL.ax = gx; SEL.az = gz; SEL.as = score; + } else { + if (SEL.n > 0) { SEL.bx = SEL.ax; SEL.bz = SEL.az; SEL.bs = SEL.as; SEL.n = 2; } + else SEL.n = 1; + SEL.ax = gx; SEL.az = gz; SEL.as = score; } + } else if (score > SEL.bs && + (SEL.n === 0 || Math.abs(gx - SEL.ax) > 8 || Math.abs(gz - SEL.az) > 8)) { + SEL.bx = gx; SEL.bz = gz; SEL.bs = score; SEL.n = 2; + } } + } - return n === 0 ? 1 : seen / n; + if (SEL.n >= 1 && setup(city, SEL.ax, SEL.az, t) && measure(cam)) drawAd(frame); + if (SEL.n >= 2 && setup(city, SEL.bx, SEL.bz, t) && measure(cam)) drawAd(frame); } - - function clipFrac(cy, hRows, rows) { - var vy0 = cy - hRows * 0.5, vy1 = cy + hRows * 0.5; - if (vy0 < 0) vy0 = 0; - if (vy1 > rows - 1) vy1 = rows - 1; - if (hRows < 1) hRows = 1; - return clamp(((vy1 - vy0) / hRows - 0.55) / 0.15, 0, 1); - } - - function drawAd(frame) { - var cols = CO.cols, rows = CO.rows; - var xL = M.xL, xR = M.xR, wL = M.wL, wR = M.wR, span = M.span; - var xa = Math.floor(xL), xb = Math.ceil(xR); - if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; - if (xb < xa) return; - - var d0 = AT.far - DISS_W; if (d0 < 14) d0 = 14; - var dens = 1 - clamp((M.dist - d0) / (AT.far - d0), 0, 1); - - dens *= clipFrac(M.cy, M.hRows, rows); - if (dens < 0.06) return; - var area = span * (M.hRows < 1 ? 1 : M.hRows); - var idens = area > AREA_MAX ? AREA_MAX / area : 1; - if (idens > dens) idens = dens; - - var NCW = AD.NC, NRW = AD.NR, mix = AD.mix, sd = AD.sd; - var NC = Math.round(span); if (NC < 6) NC = 6; if (NC > NCW) NC = NCW; - var NR = Math.round(M.hRows); if (NR < 6) NR = 6; if (NR > NRW) NR = NRW; - var x, r, s, iw, w, u, sp, dist, yBot, yTop, vspan, vv, cu, cv, iu, iv, r0, r1, lp; - var code, colr, glyph, k, lum, boost, atten, wu, wv, fade, fp, cA, cB; - for (x = xa; x <= xb; x++) { - s = (x + 0.5 - xL) / span; - if (s < 0) s = 0; else if (s > 1) s = 1; - iw = (1 - s) / wL + s / wR; - w = 1 / iw; - u = (s / wR) / iw; - sp = (2 * (x + 0.5) / cols - 1) * CO.hp; - - dist = w * Math.sqrt(1 + sp * sp) * 0.996; - yBot = CO.horizon - (AD.v0 - CO.eyeY) * CO.scale / w; - yTop = yBot - AD.H * CO.scale / w; - vspan = yBot - yTop; - if (vspan < 0.5) vspan = 0.5; - - boost = 1 + SWEEP_AMP * crest(u - AD.sweep, 0.06, 0.18); - - atten = AT.dim * (1 - 0.12 * clamp((dist - 20) / 30, 0, 1)); - - r0 = Math.ceil(yTop); r1 = Math.floor(yBot); - if (r0 < 0) r0 = 0; if (r1 > rows - 1) r1 = rows - 1; - for (r = r0; r <= r1; r++) { - vv = ((r + 0.5) - yTop) / vspan; - if (vv < 0) vv = 0; else if (vv > 1) vv = 1; - cu = (u * NC) | 0; if (cu > NC - 1) cu = NC - 1; - cv = (vv * NR) | 0; if (cv > NR - 1) cv = NR - 1; - wu = (u * NCW) | 0; if (wu > NCW - 1) wu = NCW - 1; - wv = (vv * NRW) | 0; if (wv > NRW - 1) wv = NRW - 1; - - if (dens < 1 && hash2(wu + 5, wv + 3, sd + 19) > dens) continue; - - fade = 1; - if (cu === 0 || cu === NC - 1 || cv === 0 || cv === NR - 1) { - - code = 0; - if (AD.lamp && cv === NR - 1) { - lp = ((cu * 4) / NC) | 0; - if (lp >= 1 && lp <= 3 && ((cu * 4) % NC) < 4) { code = 3; } - } - } else { - iu = (cu - 0.5) / (NC - 2); if (iu < 0) iu = 0; else if (iu > 1) iu = 1; - iv = (cv - 0.5) / (NR - 2); if (iv < 0) iv = 0; else if (iv > 1) iv = 1; - - if (mix <= 0) { code = inkAt(AD.modeA, wu, wv, iu, iv); } - else if (mix >= 1) { code = inkAt(AD.modeB, wu, wv, iu, iv); } - else { - fp = (mix - (FADE_H + hash2(wu + 61, wv + 29, sd + 5) * FADE_SPAN)) / FADE_H; - if (fp <= -1) { code = inkAt(AD.modeA, wu, wv, iu, iv); } - else if (fp >= 1) { code = inkAt(AD.modeB, wu, wv, iu, iv); } - else { - cA = inkAt(AD.modeA, wu, wv, iu, iv); - cB = inkAt(AD.modeB, wu, wv, iu, iv); - if (cA === cB) { code = cA; } - else if (fp < 0) { code = cA; fade = -fp; } - else { code = cB; fade = fp; } - } - } - - if (code !== 0 && idens < 1 && hash2(wu + 23, wv + 41, sd + 29) > idens) code = 0; - } - - if (code === 0) { - - put(frame, x, r, ((wu + wv) & 1) ? G_HASH : G_8, P.shadow, PANEL_LUM, dist); - continue; - } - if (code === 2) { colr = AD.hue2; glyph = TEXT_G[(hash2(wu, wv, sd + 11) * TEXT_N) | 0]; k = 1.0; } - else if (code === 3) { colr = AD.acc; glyph = MASS_G[(hash2(wu, wv, sd + 13) * MASS_N) | 0]; k = 1.06; } - else { colr = AD.hue; glyph = MASS_G[(hash2(wu, wv, sd + 17) * MASS_N) | 0]; k = 1.0; } - lum = PEAK[colr] * atten * boost * k * fade; - if (lum > 255) lum = 255; - - if (lum <= PANEL_LUM) { - put(frame, x, r, ((wu + wv) & 1) ? G_HASH : G_8, P.shadow, PANEL_LUM, dist); - continue; - } - put(frame, x, r, glyph, colr, lum, dist); - } - } - } - - var SEL = { n: 0, ax: 0, az: 0, as: 0, bx: 0, bz: 0, bs: 0 }; - var SALT = 0; - - CC.ELEMENTS.push({ - name: 'ads', - - world: 'cyber', - layer: 34, - - init: function (city, rng) { - this.city = city; - SALT = (rng() * 2147483647) | 0; - }, - - update: function () {}, - - draw: function (frame, cam, t) { - var city = this.city; - if (!city) return; - setCam(frame, cam); - airPrep(); - - var R = AT.far; - var gx0 = Math.floor(CO.ox - R), gx1 = Math.ceil(CO.ox + R); - var gz0 = Math.floor(CO.oz - R), gz1 = Math.ceil(CO.oz + R); - var gx, gz, rx, rz, w, side, lim, vy0, vy1, vx0, vx1, visR, visC, score, cf; - var rows = frame.rows, cols = frame.cols; - SEL.n = 0; SEL.as = 0; SEL.bs = 0; - - for (gz = gz0; gz <= gz1; gz++) { - for (gx = gx0; gx <= gx1; gx++) { - rx = gx + 0.5 - CO.ox; rz = gz + 0.5 - CO.oz; - w = rx * CO.fwx + rz * CO.fwz; - if (w < NEAR || w > R) continue; - side = rx * CO.rgx + rz * CO.rgz; lim = w * CO.hp + 4; - if (side > lim || side < -lim) continue; - - if (city.height(gx, gz) < 15) continue; - if (!setup(city, gx, gz, t)) continue; - if (!measure(cam)) continue; - - if (M.span < 10 || M.hRows < 5) continue; - - if (M.wR > M.wL * 1.8 || M.wL > M.wR * 1.8) continue; - - vy0 = M.cy - M.hRows * 0.5; vy1 = M.cy + M.hRows * 0.5; - if (vy0 < 0) vy0 = 0; if (vy1 > rows - 1) vy1 = rows - 1; - vx0 = M.xL; vx1 = M.xR; - if (vx0 < 0) vx0 = 0; if (vx1 > cols - 1) vx1 = cols - 1; - visR = vy1 - vy0; visC = vx1 - vx0; - if (visR < 8 || visC < 8) continue; - - cf = clipFrac(M.cy, M.hRows, rows); - if (cf <= 0) continue; - - if (visibleFrac(frame) < 0.45) continue; - - score = visR * visC * cf; - if (score > SEL.as) { - - if (SEL.n > 0 && Math.abs(gx - SEL.ax) <= 8 && Math.abs(gz - SEL.az) <= 8) { - SEL.ax = gx; SEL.az = gz; SEL.as = score; - } else { - if (SEL.n > 0) { SEL.bx = SEL.ax; SEL.bz = SEL.az; SEL.bs = SEL.as; SEL.n = 2; } - else SEL.n = 1; - SEL.ax = gx; SEL.az = gz; SEL.as = score; - } - } else if (score > SEL.bs && - (SEL.n === 0 || Math.abs(gx - SEL.ax) > 8 || Math.abs(gz - SEL.az) > 8)) { - SEL.bx = gx; SEL.bz = gz; SEL.bs = score; SEL.n = 2; - } - } - } - - if (SEL.n >= 1 && setup(city, SEL.ax, SEL.az, t) && measure(cam)) drawAd(frame); - if (SEL.n >= 2 && setup(city, SEL.bx, SEL.bz, t) && measure(cam)) drawAd(frame); - } - }); + }); })(CC); /* src/elements/hud.js */ (function (CC) { - 'use strict'; + 'use strict'; - var GH = CC.g('@'); + var GH = CC.g('@'); - var SLATE = CC.P.slate, WHITE = CC.P.white; + var SLATE = CC.P.slate, WHITE = CC.P.white; - var HUD_D = 0.02, PLATE_D = 0.03; + var HUD_D = 0.02, PLATE_D = 0.03; - var FONT = new Int32Array(96); + var FONT = new Int32Array(96); - function face(ch, r0, r1, r2, r3, r4) { - var rows = [r0, r1, r2, r3, r4], bits = 0; - for (var r = 0; r < 5; r++) - for (var c = 0; c < 3; c++) - if (rows[r].charAt(c) === '#') bits |= 1 << (r * 3 + (2 - c)); - FONT[ch.charCodeAt(0) - 32] = bits; - } + function face(ch, r0, r1, r2, r3, r4) { + var rows = [r0, r1, r2, r3, r4], bits = 0; + for (var r = 0; r < 5; r++) + for (var c = 0; c < 3; c++) + if (rows[r].charAt(c) === '#') bits |= 1 << (r * 3 + (2 - c)); + FONT[ch.charCodeAt(0) - 32] = bits; + } - face('A', '.#.', '#.#', '###', '#.#', '#.#'); - face('B', '##.', '#.#', '##.', '#.#', '##.'); - face('C', '.##', '#..', '#..', '#..', '.##'); - face('D', '##.', '#.#', '#.#', '#.#', '##.'); - face('E', '###', '#..', '##.', '#..', '###'); - face('F', '###', '#..', '##.', '#..', '#..'); - face('G', '.##', '#..', '#.#', '#.#', '.##'); - face('H', '#.#', '#.#', '###', '#.#', '#.#'); - face('I', '###', '.#.', '.#.', '.#.', '###'); - face('J', '..#', '..#', '..#', '#.#', '.#.'); - face('K', '#.#', '#.#', '##.', '#.#', '#.#'); - face('L', '#..', '#..', '#..', '#..', '###'); + face('A', '.#.', '#.#', '###', '#.#', '#.#'); + face('B', '##.', '#.#', '##.', '#.#', '##.'); + face('C', '.##', '#..', '#..', '#..', '.##'); + face('D', '##.', '#.#', '#.#', '#.#', '##.'); + face('E', '###', '#..', '##.', '#..', '###'); + face('F', '###', '#..', '##.', '#..', '#..'); + face('G', '.##', '#..', '#.#', '#.#', '.##'); + face('H', '#.#', '#.#', '###', '#.#', '#.#'); + face('I', '###', '.#.', '.#.', '.#.', '###'); + face('J', '..#', '..#', '..#', '#.#', '.#.'); + face('K', '#.#', '#.#', '##.', '#.#', '#.#'); + face('L', '#..', '#..', '#..', '#..', '###'); - face('M', '#.#', '###', '###', '#.#', '#.#'); - face('N', '#.#', '###', '#.#', '#.#', '#.#'); - face('O', '.#.', '#.#', '#.#', '#.#', '.#.'); - face('P', '##.', '#.#', '##.', '#..', '#..'); - face('Q', '.#.', '#.#', '#.#', '##.', '.##'); - face('R', '##.', '#.#', '##.', '#.#', '#.#'); - face('S', '.##', '#..', '.#.', '..#', '##.'); - face('T', '###', '.#.', '.#.', '.#.', '.#.'); - face('U', '#.#', '#.#', '#.#', '#.#', '###'); - face('V', '#.#', '#.#', '#.#', '.#.', '.#.'); - face('W', '#.#', '#.#', '###', '###', '#.#'); - face('X', '#.#', '#.#', '.#.', '#.#', '#.#'); - face('Y', '#.#', '#.#', '.#.', '.#.', '.#.'); - face('Z', '###', '..#', '.#.', '#..', '###'); - face('0', '###', '#.#', '#.#', '#.#', '###'); - face('1', '.#.', '##.', '.#.', '.#.', '###'); - face('2', '##.', '..#', '.#.', '#..', '###'); - face('3', '##.', '..#', '.#.', '..#', '##.'); - face('4', '#.#', '#.#', '###', '..#', '..#'); - face('5', '###', '#..', '##.', '..#', '##.'); - face('6', '.##', '#..', '##.', '#.#', '.#.'); - face('7', '###', '..#', '.#.', '.#.', '.#.'); - face('8', '.#.', '#.#', '.#.', '#.#', '.#.'); - face('9', '.#.', '#.#', '.##', '..#', '##.'); - face('-', '...', '...', '###', '...', '...'); - face('/', '..#', '..#', '.#.', '#..', '#..'); - face('.', '...', '...', '...', '...', '.#.'); + face('M', '#.#', '###', '###', '#.#', '#.#'); + face('N', '#.#', '###', '#.#', '#.#', '#.#'); + face('O', '.#.', '#.#', '#.#', '#.#', '.#.'); + face('P', '##.', '#.#', '##.', '#..', '#..'); + face('Q', '.#.', '#.#', '#.#', '##.', '.##'); + face('R', '##.', '#.#', '##.', '#.#', '#.#'); + face('S', '.##', '#..', '.#.', '..#', '##.'); + face('T', '###', '.#.', '.#.', '.#.', '.#.'); + face('U', '#.#', '#.#', '#.#', '#.#', '###'); + face('V', '#.#', '#.#', '#.#', '.#.', '.#.'); + face('W', '#.#', '#.#', '###', '###', '#.#'); + face('X', '#.#', '#.#', '.#.', '#.#', '#.#'); + face('Y', '#.#', '#.#', '.#.', '.#.', '.#.'); + face('Z', '###', '..#', '.#.', '#..', '###'); + face('0', '###', '#.#', '#.#', '#.#', '###'); + face('1', '.#.', '##.', '.#.', '.#.', '###'); + face('2', '##.', '..#', '.#.', '#..', '###'); + face('3', '##.', '..#', '.#.', '..#', '##.'); + face('4', '#.#', '#.#', '###', '..#', '..#'); + face('5', '###', '#..', '##.', '..#', '##.'); + face('6', '.##', '#..', '##.', '#.#', '.#.'); + face('7', '###', '..#', '.#.', '.#.', '.#.'); + face('8', '.#.', '#.#', '.#.', '#.#', '.#.'); + face('9', '.#.', '#.#', '.##', '..#', '##.'); + face('-', '...', '...', '###', '...', '...'); + face('/', '..#', '..#', '.#.', '#..', '#..'); + face('.', '...', '...', '...', '...', '.#.'); - var CW = 4; + var CW = 4; - var LH = 5, LGAP = 1; + var LH = 5, LGAP = 1; - function textW(s) { return s.length * CW - 1; } + function textW(s) { return s.length * CW - 1; } - var PSEED = 1471; + var PSEED = 1471; - function plate(f, x, y, a) { - for (var r = -1; r <= LH; r++) - for (var c = -1; c <= CW - 1; c++) - if (a > 0.995 || CC.hash2(x + c, y + r, PSEED) < a) - CC.put(f, x + c, y + r, 0, 0, 0, PLATE_D); - } + function plate(f, x, y, a) { + for (var r = -1; r <= LH; r++) + for (var c = -1; c <= CW - 1; c++) + if (a > 0.995 || CC.hash2(x + c, y + r, PSEED) < a) + CC.put(f, x + c, y + r, 0, 0, 0, PLATE_D); + } - function text(f, s, x, y, ci, lum, a) { - for (var i = 0; i < s.length; i++) { - var code = s.charCodeAt(i) - 32; - plate(f, x, y, a); - if (code > 0 && code < 96) { - var bits = FONT[code]; - if (bits) { - for (var r = 0; r < LH; r++) { - var row = (bits >> (r * 3)) & 7; - if (!row) continue; - if (row & 4) CC.put(f, x, y + r, GH, ci, lum, HUD_D); - if (row & 2) CC.put(f, x + 1, y + r, GH, ci, lum, HUD_D); - if (row & 1) CC.put(f, x + 2, y + r, GH, ci, lum, HUD_D); - } - } - } - x += CW; + function text(f, s, x, y, ci, lum, a) { + for (var i = 0; i < s.length; i++) { + var code = s.charCodeAt(i) - 32; + plate(f, x, y, a); + if (code > 0 && code < 96) { + var bits = FONT[code]; + if (bits) { + for (var r = 0; r < LH; r++) { + var row = (bits >> (r * 3)) & 7; + if (!row) continue; + if (row & 4) CC.put(f, x, y + r, GH, ci, lum, HUD_D); + if (row & 2) CC.put(f, x + 1, y + r, GH, ci, lum, HUD_D); + if (row & 1) CC.put(f, x + 2, y + r, GH, ci, lum, HUD_D); + } } - return x; + } + x += CW; } + return x; + } - var TIERS = [ - ['WASD MOVE', 'DRAG LOOK'], - ['WASD MOVE SHIFT RUN', 'DRAG LOOK 1-3 WORLD T TIME'], - ['WASD MOVE SHIFT RUN C CROUCH', 'DRAG LOOK 1-3 WORLD T TIME Y HOLD N SEED'] - ]; + var TIERS = [ + ['WASD MOVE', 'DRAG LOOK'], + ['WASD MOVE SHIFT RUN', 'DRAG LOOK 1-3 WORLD T TIME'], + ['WASD MOVE SHIFT RUN C CROUCH', 'DRAG LOOK 1-3 WORLD T TIME Y HOLD N SEED'] + ]; - var TOUCH = [ - ['LEFT WALK', 'RIGHT LOOK'], - ['LEFT WALK PUSH FAR RUNS', 'RIGHT LOOK TAP FULLSCREEN'], - ['LEFT HALF WALKS PUSH FAR RUNS', 'RIGHT HALF LOOKS TAP FULLSCREEN'] - ]; + var TOUCH = [ + ['LEFT WALK', 'RIGHT LOOK'], + ['LEFT WALK PUSH FAR RUNS', 'RIGHT LOOK TAP FULLSCREEN'], + ['LEFT HALF WALKS PUSH FAR RUNS', 'RIGHT HALF LOOKS TAP FULLSCREEN'] + ]; - var MARGIN_X = 3, MARGIN_Y = 2; + var MARGIN_X = 3, MARGIN_Y = 2; - var MIN_COLS = 48; + var MIN_COLS = 48; - var MAX_SHARE = 0.55; + var MAX_SHARE = 0.55; - var ROWS_3 = 64, ROWS_2 = 40; + var ROWS_3 = 64, ROWS_2 = 40; - var LUM_KEYS = 58; + var LUM_KEYS = 58; - var LUM_STAT = 92; + var LUM_STAT = 92; - var hud = { - name: 'hud', - layer: 90, + var hud = { + name: 'hud', + layer: 90, - init: function () { + init: function () { - this.wnames = []; + this.wnames = []; - var pr = CC.Weather ? CC.Weather.PRESETS : null; - if (pr) for (var i = 0; i < pr.length; i++) this.wnames.push(pr[i].name.toUpperCase()); + var pr = CC.Weather ? CC.Weather.PRESETS : null; + if (pr) for (var i = 0; i < pr.length; i++) this.wnames.push(pr[i].name.toUpperCase()); - this.dig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; - this.spd = 0; - }, + this.dig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; + this.spd = 0; + }, - update: function (dt, t, cam) { + update: function (dt, t, cam) { - var s = CC.Control ? CC.Control.speed : 0; - this.spd += (s - this.spd) * Math.min(1, dt * 2.2); - }, + var s = CC.Control ? CC.Control.speed : 0; + this.spd += (s - this.spd) * Math.min(1, dt * 2.2); + }, - draw: function (f, cam, t) { - if (!CC.Control || !CC.Control.hintAlpha) return; - var a = CC.Control.hintAlpha(t); - if (a <= 0.01) return; - var cols = f.cols, rows = f.rows; - if (cols < MIN_COLS) return; + draw: function (f, cam, t) { + if (!CC.Control || !CC.Control.hintAlpha) return; + var a = CC.Control.hintAlpha(t); + if (a <= 0.01) return; + var cols = f.cols, rows = f.rows; + if (cols < MIN_COLS) return; - var room = cols - MARGIN_X * 2; - var avail = cols * MAX_SHARE; - if (room < avail) avail = room; + var room = cols - MARGIN_X * 2; + var avail = cols * MAX_SHARE; + if (room < avail) avail = room; - var set = (CC.Control.touch ? TOUCH : TIERS); - var tier = 0; - for (var i = set.length - 1; i > 0; i--) { - if (textW(set[i][0]) <= avail && textW(set[i][1]) <= avail) { tier = i; break; } - } + var set = (CC.Control.touch ? TOUCH : TIERS); + var tier = 0; + for (var i = set.length - 1; i > 0; i--) { + if (textW(set[i][0]) <= avail && textW(set[i][1]) <= avail) { tier = i; break; } + } - if (textW(set[0][0]) > room || textW(set[0][1]) > room) return; + if (textW(set[0][0]) > room || textW(set[0][1]) > room) return; - var lines = rows >= ROWS_3 ? 3 : rows >= ROWS_2 ? 2 : 1; + var lines = rows >= ROWS_3 ? 3 : rows >= ROWS_2 ? 2 : 1; - var mode = CC.Control.mode || CC.Control.blend > 0.02; - var paused = !!CC.Control.paused; + var mode = CC.Control.mode || CC.Control.blend > 0.02; + var paused = !!CC.Control.paused; - var y = rows - MARGIN_Y - LH; - var kl = (LUM_KEYS * a) | 0, sl = (LUM_STAT * a) | 0; - if (sl < 1) return; + var y = rows - MARGIN_Y - LH; + var kl = (LUM_KEYS * a) | 0, sl = (LUM_STAT * a) | 0; + if (sl < 1) return; - var x = MARGIN_X; - if (paused) x = text(f, 'PAUSED', x, y, WHITE, sl, a) + CW; - else if (mode) { - x = text(f, 'MANUAL', x, y, WHITE, sl, a) + CW; + var x = MARGIN_X; + if (paused) x = text(f, 'PAUSED', x, y, WHITE, sl, a) + CW; + else if (mode) { + x = text(f, 'MANUAL', x, y, WHITE, sl, a) + CW; - if (tier > 0) { + if (tier > 0) { - var d = Math.round(this.spd); - if (!(d > 0)) d = 0; else if (d > 9) d = 9; - x = text(f, this.dig[d], x, y, SLATE, kl, a); - x = text(f, 'M/S', x, y, SLATE, kl, a) + CW; - } - } - - if (tier > 0 && CC.World && CC.World.name) { - var wn = CC.World.name; - if (x + textW(wn) + CW + 44 <= cols - MARGIN_X) x = text(f, wn, x, y, SLATE, kl, a) + CW; - } - - if (tier > 1 && CC.Daylight) { - var dn = CC.Daylight.P.name.toUpperCase(); - if (CC.Daylight.P.frozen) dn = '-' + dn; - if (x + textW(dn) + CW + 24 <= cols - MARGIN_X) x = text(f, dn, x, y, SLATE, kl, a) + CW; - } - var w = CC.Weather ? CC.Weather.P.name : ''; - for (var wi = 0; wi < this.wnames.length; wi++) { - if (CC.Weather.PRESETS[wi].name === w) { - - if (x + textW(this.wnames[wi]) <= cols - MARGIN_X) - text(f, this.wnames[wi], x, y, WHITE, sl, a); - break; - } - } - - if (lines > 1) { - y -= LH + LGAP; - - text(f, set[tier][lines > 2 ? 1 : 0], MARGIN_X, y, SLATE, kl, a); - } - if (lines > 2) { - y -= LH + LGAP; - text(f, set[tier][0], MARGIN_X, y, SLATE, kl, a); - } + var d = Math.round(this.spd); + if (!(d > 0)) d = 0; else if (d > 9) d = 9; + x = text(f, this.dig[d], x, y, SLATE, kl, a); + x = text(f, 'M/S', x, y, SLATE, kl, a) + CW; } - }; + } - CC.ELEMENTS.push(hud); + if (tier > 0 && CC.World && CC.World.name) { + var wn = CC.World.name; + if (x + textW(wn) + CW + 44 <= cols - MARGIN_X) x = text(f, wn, x, y, SLATE, kl, a) + CW; + } + + if (tier > 1 && CC.Daylight) { + var dn = CC.Daylight.P.name.toUpperCase(); + if (CC.Daylight.P.frozen) dn = '-' + dn; + if (x + textW(dn) + CW + 24 <= cols - MARGIN_X) x = text(f, dn, x, y, SLATE, kl, a) + CW; + } + var w = CC.Weather ? CC.Weather.P.name : ''; + for (var wi = 0; wi < this.wnames.length; wi++) { + if (CC.Weather.PRESETS[wi].name === w) { + + if (x + textW(this.wnames[wi]) <= cols - MARGIN_X) + text(f, this.wnames[wi], x, y, WHITE, sl, a); + break; + } + } + + if (lines > 1) { + y -= LH + LGAP; + + text(f, set[tier][lines > 2 ? 1 : 0], MARGIN_X, y, SLATE, kl, a); + } + if (lines > 2) { + y -= LH + LGAP; + text(f, set[tier][0], MARGIN_X, y, SLATE, kl, a); + } + } + }; + + CC.ELEMENTS.push(hud); })(CC); /* src/elements/market.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise; + var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise; - var G_DASH = CC.g('-'), G_EQ = CC.g('='), - G_8 = CC.g('8'), G_0 = CC.g('0'), G_HASH = CC.g('#'), G_X = CC.g('X'), - G_M = CC.g('M'), G_W = CC.g('W'), G_o = CC.g('o'), - G_COLON = CC.g(':'), G_COMMA = CC.g(','), G_DOT = CC.g('.'), G_QUOTE = CC.g("'"), - G_TICK = CC.g('`'); + var G_DASH = CC.g('-'), G_EQ = CC.g('='), + G_8 = CC.g('8'), G_0 = CC.g('0'), G_HASH = CC.g('#'), G_X = CC.g('X'), + G_M = CC.g('M'), G_W = CC.g('W'), G_o = CC.g('o'), + G_COLON = CC.g(':'), G_COMMA = CC.g(','), G_DOT = CC.g('.'), G_QUOTE = CC.g("'"), + G_TICK = CC.g('`'), G_V = CC.g('V'), G_UNDER = CC.g('_'); - var FILL = [G_8, G_0, G_HASH, G_M, G_W, G_X], FILL_N = 6; + var FILL = [G_8, G_0, G_HASH, G_M, G_W, G_X], FILL_N = 6; - var CITY = null, BASE = 0, Surf = null; - function boot(city) { - CITY = city && city.aveX ? city : null; - BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 8) & 0x3fffff) : 0; + var CITY = null, BASE = 0, Surf = null; + function boot(city) { + CITY = city && city.aveX ? city : null; + BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 8) & 0x3fffff) : 0; + } + + var V = { + ox: 0, oz: 0, eyeY: 1.7, fwx: 0, fwz: 1, rgx: 1, rgz: 0, + hp: 0.7265, colK: 0, colMid: 0, scale: 77, horizon: 33, cols: 0, rows: 0, far: 125, + t: 0, tt: 0 + }; + + var W_WET = 1; + + function view(f, cam, t) { + if (!Surf) Surf = CC.Surf; + var fov = cam.fov || 1.25, hp = Math.tan(fov * 0.5); + var cellA = cam.cellAspect || 0.5625; + V.cols = f.cols; V.rows = f.rows; V.hp = hp; + V.colK = f.cols * 0.5 / hp; V.colMid = f.cols * 0.5; + V.scale = cam.scaleY !== undefined ? cam.scaleY : (f.cols * cellA) / (2 * hp); + V.horizon = cam.horizon !== undefined ? cam.horizon : f.rows * 0.56; + V.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + var yaw = cam.yaw || 0; + V.fwx = Math.sin(yaw); V.fwz = Math.cos(yaw); + V.rgx = Math.cos(yaw); V.rgz = -Math.sin(yaw); + V.ox = cam.x; V.oz = cam.z; + V.far = Surf ? Surf.FOG_END : 125; + V.t = t; + + V.tt = CC.reducedMotion ? 11.7 : t; + W_WET = CC.Weather ? CC.Weather.rel('wet') : 1; + } + + var PJ = { x: 0, y: 0, d: 0 }; + function project(px, py, pz) { + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < 0.4) return false; + var sp = (rx * V.rgx + rz * V.rgz) / w; + PJ.d = w * Math.sqrt(1 + sp * sp); + PJ.x = sp * V.colK + V.colMid; + PJ.y = V.horizon - (py - V.eyeY) * V.scale / w; + return PJ.d < V.far; + } + + function emit(f, x, y, ch, col, lum, d) { + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + if (lum > 0 && Surf) { lum = Surf.fog(lum, d); if (lum <= 0) ch = 0; } + put(f, x, y, ch, col, lum, d, 3); + } + + var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 }; + function streetSpan(axis, idx) { + var c, h; + if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); } + else { c = CITY.aveX(idx); h = CITY.aveW(idx); } + SPAN.c0 = c - h; SPAN.c1 = c + h + 1; + SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0; + } + function wx(axis, along, cross) { return axis ? along : cross; } + function wz(axis, along, cross) { return axis ? cross : along; } + + function paveOf(spanW) { + var p = CC.PAVE, avail = spanW * 0.5 - 1.7; + return avail < p ? avail : p; + } + + var KERB_LIP = 0.34; + + function frontage(axis, along, len, cross) { + var i, a; + for (i = 0; i <= 3; i++) { + a = along + len * (i / 3); + if (CITY.height(wx(axis, a, cross), wz(axis, a, cross)) < 3) return 0; + } + return 1; + } + + function objVisible(axis, along, cross, near) { + var px = wx(axis, along, cross), pz = wz(axis, along, cross); + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < near || w > V.far) return 0; + var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 16; + if (s < -lim || s > lim) return 0; + return w; + } + + var REACH = 44; + function idxLo(axis) { + return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)) - (axis ? 3 : 2); + } + function idxHi(axis) { + return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)) + (axis ? 3 : 2); + } + function alongLo(axis, pitch) { return Math.floor(((axis ? V.ox : V.oz) - REACH) / pitch); } + function alongHi(axis, pitch) { return Math.floor(((axis ? V.ox : V.oz) + REACH) / pitch); } + + var CLIP = { u0: 0, u1: 1 }; + function clipNear(axis, a0, a1, cross) { + var rx = wx(axis, a0, cross) - V.ox, rz = wz(axis, a0, cross) - V.oz; + var g0 = rx * V.fwx + rz * V.fwz - 0.42; + rx = wx(axis, a1, cross) - V.ox; rz = wz(axis, a1, cross) - V.oz; + var g1 = rx * V.fwx + rz * V.fwz - 0.42; + if (g0 < 0 && g1 < 0) return false; + CLIP.u0 = 0; CLIP.u1 = 1; + if (g0 < 0) CLIP.u0 = g0 / (g0 - g1); + else if (g1 < 0) CLIP.u1 = g0 / (g0 - g1); + return true; + } + + var COV_MAX = 0.05, COV_LIT_GAIN = 2.4; + var COV = 1, COV_LIT = 1; + function coverOf(axis, a0, a1, cross, H) { + var K = 6, i, a, rx, rz, w, x, dx, wm, rws, area = 0, px = 0, pw = 0, have = 0, budget; + for (i = 0; i <= K; i++) { + a = a0 + (a1 - a0) * (i / K); + rx = wx(axis, a, cross) - V.ox; rz = wz(axis, a, cross) - V.oz; + w = rx * V.fwx + rz * V.fwz; + if (w < 0.6) { have = 0; continue; } + x = (rx * V.rgx + rz * V.rgz) / w * V.colK + V.colMid; + if (x < 0) x = 0; else if (x > V.cols) x = V.cols; + if (have) { + dx = x - px; if (dx < 0) dx = -dx; + wm = (w + pw) * 0.5; + rws = H * V.scale / wm; + if (rws > V.rows) rws = V.rows; + area += dx * rws; + } + px = x; pw = w; have = 1; + } + budget = V.cols * V.rows * COV_MAX; + COV = area <= budget ? 1 : budget / area; + COV_LIT = COV * COV_LIT_GAIN; + if (COV_LIT > 1) COV_LIT = 1; + return COV; + } + function coverClear() { COV = 1; COV_LIT = 1; } + + function panel(f, axis, a0, a1, cross, y0, y1, ch, col, lum, jit, mesh, sd) { + if (!clipNear(axis, a0, a1, cross)) return; + var b0 = a0 + (a1 - a0) * CLIP.u0, b1 = a0 + (a1 - a0) * CLIP.u1; + var rx = wx(axis, b0, cross) - V.ox, rz = wz(axis, b0, cross) - V.oz; + var w0 = rx * V.fwx + rz * V.fwz, s0 = rx * V.rgx + rz * V.rgz; + rx = wx(axis, b1, cross) - V.ox; rz = wz(axis, b1, cross) - V.oz; + var w1 = rx * V.fwx + rz * V.fwz, s1 = rx * V.rgx + rz * V.rgz; + var dw = w1 - w0, ds = s1 - s0; + var xa = s0 / w0 * V.colK + V.colMid, xb = s1 / w1 * V.colK + V.colMid; + var j0 = Math.floor(xa < xb ? xa : xb), j1 = Math.floor(xa < xb ? xb : xa); + if (j1 < 0 || j0 >= V.cols) return; + if (j0 < 0) j0 = 0; + if (j1 > V.cols - 1) j1 = V.cols - 1; + var j, sp, den, u, a, rt, rb, r0, r1, row, dd, lat, l, tmp, pat, fade; + for (j = j0; j <= j1; j++) { + sp = (j + 0.5 - V.colMid) / V.colK; + den = sp * dw - ds; + + u = (den > 1e-9 || den < -1e-9) ? (s0 - sp * w0) / den : 0.5; + if (u < 0) u = 0; else if (u > 1) u = 1; + a = b0 + (b1 - b0) * u; + if (!project(wx(axis, a, cross), y1, wz(axis, a, cross))) continue; + rt = PJ.y; dd = PJ.d; + fade = (dd - 1.2) * 0.5556; + if (fade <= 0) continue; + if (fade > 1) fade = 1; + + if (lum > 0) { if (COV_LIT < 1) fade *= COV_LIT; } + else if (COV < 1) fade *= COV; + if (!project(wx(axis, a, cross), y0, wz(axis, a, cross))) continue; + rb = PJ.y; + r0 = Math.floor(rt); r1 = Math.floor(rb); + if (r1 < r0) { tmp = r0; r0 = r1; r1 = tmp; } + + pat = r0; + if (r0 < -1) r0 = -1; + if (r1 > V.rows) r1 = V.rows; + lat = Math.floor(a * 4.7) + (sd & 15); + for (row = r0; row <= r1; row++) { + if (fade < 1 && hash2(lat, row - pat, sd + 51) > fade) continue; + if (mesh && ((lat + row - pat) & 1)) continue; + l = lum; + if (jit) l += hash2(lat, row - pat, sd + 113) * jit; + emit(f, j, row, ch, col, l, dd); + } + } + } + + function pcell(f, axis, a, cross, y, ch, col, lum, bias) { + if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) return; + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), ch, col, lum, PJ.d * bias); + } + + function counterHue(r) { + if (r < 0.60) return P.amber; + if (r < 0.74) return P.azure; + if (r < 0.81) return P.ember; + if (r < 0.89) return P.spring; + if (r < 0.93) return P.jade; + return P.warm; + } + + function vendHue(r) { + if (r < 0.40) return P.azure; + if (r < 0.74) return P.amber; + if (r < 0.92) return P.spring; + return P.ember; + } + + function litLum(col) { + if (col === P.azure) return 96; + if (col === P.warm) return 152; + if (col === P.spring) return 155; + if (col === P.violet) return 228; + if (col === P.jade) return 240; + if (col === P.rose) return 250; + if (col === P.gold) return 178; + return 165; + } + + var MR_PITCH = 30, MR_P = 0.25, STALL_W = 2.30; + + function rowStalls(sd) { return 3 + ((hash2(1, 0, sd + 101) * 2.99) | 0); } + + function marketRow(f, axis, along, wallC, inw, strip, sd) { + var nst = rowStalls(sd); + var len = nst * STALL_W; + var back = wallC + inw * strip * 0.10; + var cnt = wallC + inw * strip * 0.62; + var gds = wallC + inw * strip * 0.82; + var rail = wallC + inw * strip * 0.90; + var fas = wallC + inw * strip * 0.98; + var a0 = along, a1 = along + len; + var hue = counterHue(hash2(2, 0, sd + 211)); + var lum = litLum(hue); + var i, a, h, hh, chue, clum; + + coverOf(axis, a0 - 0.45, a1 + 0.45, cnt, 2.54); + + panel(f, axis, a0 - 0.45, a1 + 0.45, fas, 2.26, 2.54, 0, P.shadow, 0, 0, 0, sd); + panel(f, axis, a0 - 0.45, a1 + 0.45, cnt, 2.30, 2.50, 0, P.shadow, 0, 0, 0, sd); + + var cvs = hash2(3, 0, sd + 313); + var cvh = cvs < 0.44 ? P.moss : (cvs < 0.78 ? P.timber : P.sand); + + panel(f, axis, a0 - 0.45, a1 + 0.45, fas, 2.10, 2.24, + cvs < 0.5 ? G_V : G_UNDER, cvh, cvh === P.sand ? 200 : 214, 22, 1, sd + 313); + + panel(f, axis, a0 - 0.30, a1 + 0.30, cnt, 1.92, 2.02, G_EQ, hue, lum * 0.86, 0, 0, sd); + + for (i = 0; i < nst; i++) { + a = along + i * STALL_W; + h = hash2(i, 3, sd + 307); + + panel(f, axis, a + 0.06, a + STALL_W - 0.06, cnt, 0, 0.94, 0, P.shadow, 0, 0, 0, sd + i); + panel(f, axis, a + 0.16, a + STALL_W - 0.16, back, 0, 1.10, 0, P.shadow, 0, 0, 0, sd + i); + + if (hash2(i, 8, sd + 907) < 0.40) + panel(f, axis, a + 0.78, a + 1.38, back, 0.90, 1.86, 0, P.shadow, 0, 0, 0, sd + i); + + chue = hash2(i, 10, sd + 1103) < 0.64 ? hue : counterHue(hash2(i, 11, sd + 1201)); + + if (chue === P.ember) chue = P.amber; + clum = litLum(chue); + panel(f, axis, a + 0.10, a + STALL_W - 0.10, cnt, 0.98, 1.15, + FILL[(h * FILL_N) | 0], chue, clum * (0.90 + h * 0.14), 26, 0, sd + i); + + if (hash2(i, 9, sd + 1009) < 0.55) + panel(f, axis, a + 0.34, a + 0.94, gds, 0, 1.06, 0, P.shadow, 0, 0, 0, sd + i); + if (hash2(i, 12, sd + 1307) < 0.48) + panel(f, axis, a + 1.32, a + 1.86, gds, 0, 0.86, 0, P.shadow, 0, 0, 0, sd + i); + + panel(f, axis, a + STALL_W - 0.08, a + STALL_W + 0.02, cnt, 0.94, 2.30, 0, P.shadow, 0, 0, 0, sd); + + hh = hash2(i, 4, sd + 401); + if (hh < 0.62) + panel(f, axis, a + 0.45 + hh * 0.5, a + 0.78 + hh * 0.5, rail, 1.62, 2.04, + 0, P.shadow, 0, 0, 0, sd + i); + hh = hash2(i, 5, sd + 503); + if (hh < 0.44) + panel(f, axis, a + 1.30 + hh * 0.5, a + 1.55 + hh * 0.5, rail, 1.70, 2.04, + 0, P.shadow, 0, 0, 0, sd + i); } - var V = { - ox: 0, oz: 0, eyeY: 1.7, fwx: 0, fwz: 1, rgx: 1, rgz: 0, - hp: 0.7265, colK: 0, colMid: 0, scale: 77, horizon: 33, cols: 0, rows: 0, far: 125, - t: 0, tt: 0 - }; + i = (hash2(6, 0, sd + 601) * nst) | 0; + a = along + i * STALL_W; + panel(f, axis, a + 0.30, a + 1.50, wallC + inw * strip * 0.80, 0.44, 0.52, + G_DASH, hue, lum * 0.74, 0, 1, sd); + coverClear(); - var W_WET = 1; + var wl = 24 + 28 * W_WET; + a = along + len * 0.5; + pcell(f, axis, a - 1.1, wallC + inw * strip * 0.88, 0.02, G_COMMA, hue, wl, 0.985); + pcell(f, axis, a, wallC + inw * strip * 0.99, 0.02, G_COLON, hue, wl * 1.25, 0.985); + pcell(f, axis, a + 1.1, wallC + inw * strip * 0.88, 0.02, G_DOT, hue, wl, 0.985); + } - function view(f, cam, t) { - if (!Surf) Surf = CC.Surf; - var fov = cam.fov || 1.25, hp = Math.tan(fov * 0.5); - var cellA = cam.cellAspect || 0.5625; - V.cols = f.cols; V.rows = f.rows; V.hp = hp; - V.colK = f.cols * 0.5 / hp; V.colMid = f.cols * 0.5; - V.scale = cam.scaleY !== undefined ? cam.scaleY : (f.cols * cellA) / (2 * hp); - V.horizon = cam.horizon !== undefined ? cam.horizon : f.rows * 0.56; - V.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - var yaw = cam.yaw || 0; - V.fwx = Math.sin(yaw); V.fwz = Math.cos(yaw); - V.rgx = Math.cos(yaw); V.rgz = -Math.sin(yaw); - V.ox = cam.x; V.oz = cam.z; - V.far = Surf ? Surf.FOG_END : 125; - V.t = t; + var PUFF_N = 3, PUFF_RATE = 0.34; + var PUFF_ATK = 0.16, PUFF_ATK_INV = 1 / 0.16; - V.tt = CC.reducedMotion ? 11.7 : t; - W_WET = CC.Weather ? CC.Weather.rel('wet') : 1; + function rowSteam(f, axis, along, wallC, inw, strip, sd, dd) { + if (dd > 26) return; + var cross = wallC + inw * strip * 0.62, j, ph, age, fade, l, drift; + for (j = 0; j < PUFF_N; j++) { + ph = hash2(j, 7, sd + 701); + age = (V.tt * PUFF_RATE + ph) % 1; + fade = (1 - age) * (1 - age); + + if (age < PUFF_ATK) fade *= age * PUFF_ATK_INV; + l = 44 * fade; + + if (l < 1) continue; + + drift = (vnoise(V.tt * 0.5 + ph * 20, sd + 811) - 0.5) * age * 1.9; + pcell(f, axis, along + 1.1 + drift, cross, 2.62 + age * 2.2, + age < 0.4 ? G_QUOTE : G_TICK, P.slate, l, 0.99); } + } - var PJ = { x: 0, y: 0, d: 0 }; - function project(px, py, pz) { - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < 0.4) return false; - var sp = (rx * V.rgx + rz * V.rgz) / w; - PJ.d = w * Math.sqrt(1 + sp * sp); - PJ.x = sp * V.colK + V.colMid; - PJ.y = V.horizon - (py - V.eyeY) * V.scale / w; - return PJ.d < V.far; + var KI_PITCH = 13, KI_P = 0.15; + + function kiosk(f, axis, along, wallC, inw, strip, sd) { + var face = wallC + inw * strip * 0.58; + var lip = wallC + inw * strip * 0.74; + var roof = wallC + inw * strip * 0.90; + var hue = counterHue(hash2(1, 0, sd + 101)); + var lum = litLum(hue); + coverOf(axis, along - 1.00, along + 1.00, face, 2.50); + + panel(f, axis, along - 0.85, along + 0.85, face, 0, 2.28, 0, P.shadow, 0, 0, 0, sd); + panel(f, axis, along - 1.00, along + 1.00, roof, 2.28, 2.50, 0, P.shadow, 0, 0, 0, sd); + panel(f, axis, along - 1.00, along + 1.00, face, 2.30, 2.48, 0, P.shadow, 0, 0, 0, sd); + + panel(f, axis, along - 0.55, along + 0.55, face, 1.08, 1.40, + G_8, hue, lum, 24, 0, sd); + + panel(f, axis, along - 0.66, along + 0.66, lip, 0.94, 1.02, G_DASH, hue, lum * 0.78, 0, 0, sd); + + var sr = hash2(2, 0, sd + 211); + var shue = sr < 0.17 ? P.violet : (sr < 0.29 ? P.rose : (sr < 0.60 ? P.amber : P.azure)); + var slum = litLum(shue); + pcell(f, axis, along - 0.22, face, 1.74, G_0, shue, slum, 1); + pcell(f, axis, along + 0.22, face, 1.74, G_0, shue, slum * 0.9, 1); + + var st = wallC + inw * strip * 0.94, k, sa; + for (k = 0; k < 2; k++) { + sa = along - 0.42 + k * 0.84; + panel(f, axis, sa - 0.10, sa + 0.10, st, 0, 0.56, 0, P.shadow, 0, 0, 0, sd); + pcell(f, axis, sa, st, 0.60, G_o, hue, lum * 0.70, 1); } + coverClear(); - function emit(f, x, y, ch, col, lum, d) { - if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; - if (lum > 0 && Surf) { lum = Surf.fog(lum, d); if (lum <= 0) ch = 0; } - put(f, x, y, ch, col, lum, d, 3); + var wl = 24 + 28 * W_WET; + pcell(f, axis, along - 0.4, wallC + inw * strip * 0.86, 0.02, G_COLON, hue, wl * 1.2, 0.985); + pcell(f, axis, along + 0.5, wallC + inw * strip * 0.99, 0.02, G_DOT, hue, wl, 0.985); + } + + var VB_PITCH = 19, VB_P = 0.17, VB_W = 0.92; + + function vendBank(f, axis, along, wallC, inw, strip, sd) { + var n = 3 + (hash2(1, 0, sd + 101) < 0.45 ? 1 : 0); + var face = wallC + inw * 0.40; + var len = n * VB_W, i, a, hue, lum; + coverOf(axis, along - 0.08, along + len + 0.08, face, 2.02); + + panel(f, axis, along - 0.08, along + len + 0.08, face - inw * 0.04, 0, 2.02, + 0, P.shadow, 0, 0, 0, sd); + for (i = 0; i < n; i++) { + a = along + i * VB_W; + hue = vendHue(hash2(i, 2, sd + 211)); + lum = litLum(hue); + + panel(f, axis, a + 0.08, a + VB_W - 0.10, face, 1.72, 1.80, G_DASH, hue, lum, 0, 0, sd + i); + + panel(f, axis, a + 0.14, a + VB_W - 0.16, face, 1.10, 1.42, + G_8, hue, lum * 0.86, 30, 1, sd + i); + + pcell(f, axis, a + VB_W * 0.5, face, 0.92, G_DASH, hue, lum * 0.6, 1); } + coverClear(); - var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 }; - function streetSpan(axis, idx) { - var c, h; - if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); } - else { c = CITY.aveX(idx); h = CITY.aveW(idx); } - SPAN.c0 = c - h; SPAN.c1 = c + h + 1; - SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0; - } - function wx(axis, along, cross) { return axis ? along : cross; } - function wz(axis, along, cross) { return axis ? cross : along; } + var wl = 22 + 26 * W_WET; + pcell(f, axis, along + VB_W * 0.5, wallC + inw * strip * 0.62, 0.02, G_COLON, + vendHue(hash2(0, 2, sd + 211)), wl, 0.985); + pcell(f, axis, along + len - VB_W * 0.5, wallC + inw * strip * 0.62, 0.02, G_DOT, + vendHue(hash2(n - 1, 2, sd + 211)), wl, 0.985); + } - function paveOf(spanW) { - var p = CC.PAVE, avail = spanW * 0.5 - 1.7; - return avail < p ? avail : p; - } + function drawMarket(f) { + if (!CITY) return; + var axis, idx, n, side, wallC, inw, pave, strip, along, dd, sd, len; + for (axis = 0; axis < 2; axis++) { + for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { + streetSpan(axis, idx); - var KERB_LIP = 0.34; + if (SPAN.w < 5) continue; + pave = paveOf(SPAN.w); + strip = pave - KERB_LIP; + if (strip < 1.05) continue; + for (side = 0; side < 2; side++) { + wallC = side ? SPAN.c1 : SPAN.c0; + inw = side ? -1 : 1; - function frontage(axis, along, len, cross) { - var i, a; - for (i = 0; i <= 3; i++) { - a = along + len * (i / 3); - if (CITY.height(wx(axis, a, cross), wz(axis, a, cross)) < 3) return 0; + for (n = alongLo(axis, MR_PITCH); n <= alongHi(axis, MR_PITCH); n++) { + if (hash2(idx * 2 + side, n, BASE + 907) > MR_P) continue; + along = n * MR_PITCH + hash2(idx * 2 + side, n, BASE + 1013) * 12; + sd = BASE + idx * 977 + n * 6151 + side * 37; + len = rowStalls(sd) * STALL_W; + + dd = objVisible(axis, along + len * 0.5, wallC + inw, -8); + if (!dd || dd > REACH) continue; + if (!frontage(axis, along, len, wallC - inw * 0.5)) continue; + marketRow(f, axis, along, wallC, inw, strip, sd); + rowSteam(f, axis, along, wallC, inw, strip, sd, dd); + } + + for (n = alongLo(axis, KI_PITCH); n <= alongHi(axis, KI_PITCH); n++) { + if (hash2(idx * 2 + side, n, BASE + 1117) > KI_P) continue; + along = n * KI_PITCH + hash2(idx * 2 + side, n, BASE + 1223) * 8; + dd = objVisible(axis, along, wallC + inw, -3); + if (!dd || dd > REACH) continue; + if (!frontage(axis, along - 1, 2, wallC - inw * 0.5)) continue; + kiosk(f, axis, along, wallC, inw, strip, BASE + idx * 1301 + n * 4099 + side * 53); + } + + for (n = alongLo(axis, VB_PITCH); n <= alongHi(axis, VB_PITCH); n++) { + if (hash2(idx * 2 + side, n, BASE + 1327) > VB_P) continue; + along = n * VB_PITCH + hash2(idx * 2 + side, n, BASE + 1433) * 9; + dd = objVisible(axis, along + 1.4, wallC + inw, -4); + if (!dd || dd > REACH) continue; + if (!frontage(axis, along, 3.7, wallC - inw * 0.5)) continue; + vendBank(f, axis, along, wallC, inw, strip, + BASE + idx * 1523 + n * 3671 + side * 61); + } } - return 1; + } } + } - function objVisible(axis, along, cross, near) { - var px = wx(axis, along, cross), pz = wz(axis, along, cross); - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < near || w > V.far) return 0; - var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 16; - if (s < -lim || s > lim) return 0; - return w; + CC.ELEMENTS.push({ + name: 'market', + + world: 'cyber', + + layer: 17, + init: function (city) { boot(city); }, + draw: function (f, cam, t) { + view(f, cam, t === undefined ? (cam.t || 0) : t); + drawMarket(f); } - - var REACH = 44; - function idxLo(axis) { - return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)) - (axis ? 3 : 2); - } - function idxHi(axis) { - return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)) + (axis ? 3 : 2); - } - function alongLo(axis, pitch) { return Math.floor(((axis ? V.ox : V.oz) - REACH) / pitch); } - function alongHi(axis, pitch) { return Math.floor(((axis ? V.ox : V.oz) + REACH) / pitch); } - - var CLIP = { u0: 0, u1: 1 }; - function clipNear(axis, a0, a1, cross) { - var rx = wx(axis, a0, cross) - V.ox, rz = wz(axis, a0, cross) - V.oz; - var g0 = rx * V.fwx + rz * V.fwz - 0.42; - rx = wx(axis, a1, cross) - V.ox; rz = wz(axis, a1, cross) - V.oz; - var g1 = rx * V.fwx + rz * V.fwz - 0.42; - if (g0 < 0 && g1 < 0) return false; - CLIP.u0 = 0; CLIP.u1 = 1; - if (g0 < 0) CLIP.u0 = g0 / (g0 - g1); - else if (g1 < 0) CLIP.u1 = g0 / (g0 - g1); - return true; - } - - var COV_MAX = 0.05, COV_LIT_GAIN = 2.4; - var COV = 1, COV_LIT = 1; - function coverOf(axis, a0, a1, cross, H) { - var K = 6, i, a, rx, rz, w, x, dx, wm, rws, area = 0, px = 0, pw = 0, have = 0, budget; - for (i = 0; i <= K; i++) { - a = a0 + (a1 - a0) * (i / K); - rx = wx(axis, a, cross) - V.ox; rz = wz(axis, a, cross) - V.oz; - w = rx * V.fwx + rz * V.fwz; - if (w < 0.6) { have = 0; continue; } - x = (rx * V.rgx + rz * V.rgz) / w * V.colK + V.colMid; - if (x < 0) x = 0; else if (x > V.cols) x = V.cols; - if (have) { - dx = x - px; if (dx < 0) dx = -dx; - wm = (w + pw) * 0.5; - rws = H * V.scale / wm; - if (rws > V.rows) rws = V.rows; - area += dx * rws; - } - px = x; pw = w; have = 1; - } - budget = V.cols * V.rows * COV_MAX; - COV = area <= budget ? 1 : budget / area; - COV_LIT = COV * COV_LIT_GAIN; - if (COV_LIT > 1) COV_LIT = 1; - return COV; - } - function coverClear() { COV = 1; COV_LIT = 1; } - - function panel(f, axis, a0, a1, cross, y0, y1, ch, col, lum, jit, mesh, sd) { - if (!clipNear(axis, a0, a1, cross)) return; - var b0 = a0 + (a1 - a0) * CLIP.u0, b1 = a0 + (a1 - a0) * CLIP.u1; - var rx = wx(axis, b0, cross) - V.ox, rz = wz(axis, b0, cross) - V.oz; - var w0 = rx * V.fwx + rz * V.fwz, s0 = rx * V.rgx + rz * V.rgz; - rx = wx(axis, b1, cross) - V.ox; rz = wz(axis, b1, cross) - V.oz; - var w1 = rx * V.fwx + rz * V.fwz, s1 = rx * V.rgx + rz * V.rgz; - var dw = w1 - w0, ds = s1 - s0; - var xa = s0 / w0 * V.colK + V.colMid, xb = s1 / w1 * V.colK + V.colMid; - var j0 = Math.floor(xa < xb ? xa : xb), j1 = Math.floor(xa < xb ? xb : xa); - if (j1 < 0 || j0 >= V.cols) return; - if (j0 < 0) j0 = 0; - if (j1 > V.cols - 1) j1 = V.cols - 1; - var j, sp, den, u, a, rt, rb, r0, r1, row, dd, lat, l, tmp, pat, fade; - for (j = j0; j <= j1; j++) { - sp = (j + 0.5 - V.colMid) / V.colK; - den = sp * dw - ds; - - u = (den > 1e-9 || den < -1e-9) ? (s0 - sp * w0) / den : 0.5; - if (u < 0) u = 0; else if (u > 1) u = 1; - a = b0 + (b1 - b0) * u; - if (!project(wx(axis, a, cross), y1, wz(axis, a, cross))) continue; - rt = PJ.y; dd = PJ.d; - fade = (dd - 1.2) * 0.5556; - if (fade <= 0) continue; - if (fade > 1) fade = 1; - - if (lum > 0) { if (COV_LIT < 1) fade *= COV_LIT; } - else if (COV < 1) fade *= COV; - if (!project(wx(axis, a, cross), y0, wz(axis, a, cross))) continue; - rb = PJ.y; - r0 = Math.floor(rt); r1 = Math.floor(rb); - if (r1 < r0) { tmp = r0; r0 = r1; r1 = tmp; } - - pat = r0; - if (r0 < -1) r0 = -1; - if (r1 > V.rows) r1 = V.rows; - lat = Math.floor(a * 4.7) + (sd & 15); - for (row = r0; row <= r1; row++) { - if (fade < 1 && hash2(lat, row - pat, sd + 51) > fade) continue; - if (mesh && ((lat + row - pat) & 1)) continue; - l = lum; - if (jit) l += hash2(lat, row - pat, sd + 113) * jit; - emit(f, j, row, ch, col, l, dd); - } - } - } - - function pcell(f, axis, a, cross, y, ch, col, lum, bias) { - if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) return; - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), ch, col, lum, PJ.d * bias); - } - - function counterHue(r) { - if (r < 0.60) return P.amber; - if (r < 0.74) return P.azure; - if (r < 0.81) return P.ember; - if (r < 0.93) return P.spring; - return P.warm; - } - - function vendHue(r) { - if (r < 0.40) return P.azure; - if (r < 0.74) return P.amber; - if (r < 0.92) return P.spring; - return P.ember; - } - function litLum(col) { - if (col === P.azure) return 96; - if (col === P.warm) return 152; - if (col === P.spring) return 155; - if (col === P.violet) return 228; - return 165; - } - - var MR_PITCH = 30, MR_P = 0.25, STALL_W = 2.30; - - function rowStalls(sd) { return 3 + ((hash2(1, 0, sd + 101) * 2.99) | 0); } - - function marketRow(f, axis, along, wallC, inw, strip, sd) { - var nst = rowStalls(sd); - var len = nst * STALL_W; - var back = wallC + inw * strip * 0.10; - var cnt = wallC + inw * strip * 0.62; - var gds = wallC + inw * strip * 0.82; - var rail = wallC + inw * strip * 0.90; - var fas = wallC + inw * strip * 0.98; - var a0 = along, a1 = along + len; - var hue = counterHue(hash2(2, 0, sd + 211)); - var lum = litLum(hue); - var i, a, h, hh, chue, clum; - - coverOf(axis, a0 - 0.45, a1 + 0.45, cnt, 2.54); - - panel(f, axis, a0 - 0.45, a1 + 0.45, fas, 2.26, 2.54, 0, P.shadow, 0, 0, 0, sd); - panel(f, axis, a0 - 0.45, a1 + 0.45, cnt, 2.30, 2.50, 0, P.shadow, 0, 0, 0, sd); - - panel(f, axis, a0 - 0.30, a1 + 0.30, cnt, 1.92, 2.02, G_EQ, hue, lum * 0.86, 0, 0, sd); - - for (i = 0; i < nst; i++) { - a = along + i * STALL_W; - h = hash2(i, 3, sd + 307); - - panel(f, axis, a + 0.06, a + STALL_W - 0.06, cnt, 0, 0.94, 0, P.shadow, 0, 0, 0, sd + i); - panel(f, axis, a + 0.16, a + STALL_W - 0.16, back, 0, 1.10, 0, P.shadow, 0, 0, 0, sd + i); - - if (hash2(i, 8, sd + 907) < 0.40) - panel(f, axis, a + 0.78, a + 1.38, back, 0.90, 1.86, 0, P.shadow, 0, 0, 0, sd + i); - - chue = hash2(i, 10, sd + 1103) < 0.64 ? hue : counterHue(hash2(i, 11, sd + 1201)); - - if (chue === P.ember) chue = P.amber; - clum = litLum(chue); - panel(f, axis, a + 0.10, a + STALL_W - 0.10, cnt, 0.98, 1.15, - FILL[(h * FILL_N) | 0], chue, clum * (0.90 + h * 0.14), 26, 0, sd + i); - - if (hash2(i, 9, sd + 1009) < 0.55) - panel(f, axis, a + 0.34, a + 0.94, gds, 0, 1.06, 0, P.shadow, 0, 0, 0, sd + i); - if (hash2(i, 12, sd + 1307) < 0.48) - panel(f, axis, a + 1.32, a + 1.86, gds, 0, 0.86, 0, P.shadow, 0, 0, 0, sd + i); - - panel(f, axis, a + STALL_W - 0.08, a + STALL_W + 0.02, cnt, 0.94, 2.30, 0, P.shadow, 0, 0, 0, sd); - - hh = hash2(i, 4, sd + 401); - if (hh < 0.62) - panel(f, axis, a + 0.45 + hh * 0.5, a + 0.78 + hh * 0.5, rail, 1.62, 2.04, - 0, P.shadow, 0, 0, 0, sd + i); - hh = hash2(i, 5, sd + 503); - if (hh < 0.44) - panel(f, axis, a + 1.30 + hh * 0.5, a + 1.55 + hh * 0.5, rail, 1.70, 2.04, - 0, P.shadow, 0, 0, 0, sd + i); - } - - i = (hash2(6, 0, sd + 601) * nst) | 0; - a = along + i * STALL_W; - panel(f, axis, a + 0.30, a + 1.50, wallC + inw * strip * 0.80, 0.44, 0.52, - G_DASH, hue, lum * 0.74, 0, 1, sd); - coverClear(); - - var wl = 24 + 28 * W_WET; - a = along + len * 0.5; - pcell(f, axis, a - 1.1, wallC + inw * strip * 0.88, 0.02, G_COMMA, hue, wl, 0.985); - pcell(f, axis, a, wallC + inw * strip * 0.99, 0.02, G_COLON, hue, wl * 1.25, 0.985); - pcell(f, axis, a + 1.1, wallC + inw * strip * 0.88, 0.02, G_DOT, hue, wl, 0.985); - } - - var PUFF_N = 3, PUFF_RATE = 0.34; - var PUFF_ATK = 0.16, PUFF_ATK_INV = 1 / 0.16; - - function rowSteam(f, axis, along, wallC, inw, strip, sd, dd) { - if (dd > 26) return; - var cross = wallC + inw * strip * 0.62, j, ph, age, fade, l, drift; - for (j = 0; j < PUFF_N; j++) { - ph = hash2(j, 7, sd + 701); - age = (V.tt * PUFF_RATE + ph) % 1; - fade = (1 - age) * (1 - age); - - if (age < PUFF_ATK) fade *= age * PUFF_ATK_INV; - l = 44 * fade; - - if (l < 1) continue; - - drift = (vnoise(V.tt * 0.5 + ph * 20, sd + 811) - 0.5) * age * 1.9; - pcell(f, axis, along + 1.1 + drift, cross, 2.62 + age * 2.2, - age < 0.4 ? G_QUOTE : G_TICK, P.slate, l, 0.99); - } - } - - var KI_PITCH = 13, KI_P = 0.15; - - function kiosk(f, axis, along, wallC, inw, strip, sd) { - var face = wallC + inw * strip * 0.58; - var lip = wallC + inw * strip * 0.74; - var roof = wallC + inw * strip * 0.90; - var hue = counterHue(hash2(1, 0, sd + 101)); - var lum = litLum(hue); - coverOf(axis, along - 1.00, along + 1.00, face, 2.50); - - panel(f, axis, along - 0.85, along + 0.85, face, 0, 2.28, 0, P.shadow, 0, 0, 0, sd); - panel(f, axis, along - 1.00, along + 1.00, roof, 2.28, 2.50, 0, P.shadow, 0, 0, 0, sd); - panel(f, axis, along - 1.00, along + 1.00, face, 2.30, 2.48, 0, P.shadow, 0, 0, 0, sd); - - panel(f, axis, along - 0.55, along + 0.55, face, 1.08, 1.40, - G_8, hue, lum, 24, 0, sd); - - panel(f, axis, along - 0.66, along + 0.66, lip, 0.94, 1.02, G_DASH, hue, lum * 0.78, 0, 0, sd); - - var sr = hash2(2, 0, sd + 211); - var shue = sr < 0.17 ? P.violet : (sr < 0.60 ? P.amber : P.azure); - var slum = litLum(shue); - pcell(f, axis, along - 0.22, face, 1.74, G_0, shue, slum, 1); - pcell(f, axis, along + 0.22, face, 1.74, G_0, shue, slum * 0.9, 1); - - var st = wallC + inw * strip * 0.94, k, sa; - for (k = 0; k < 2; k++) { - sa = along - 0.42 + k * 0.84; - panel(f, axis, sa - 0.10, sa + 0.10, st, 0, 0.56, 0, P.shadow, 0, 0, 0, sd); - pcell(f, axis, sa, st, 0.60, G_o, hue, lum * 0.70, 1); - } - coverClear(); - - var wl = 24 + 28 * W_WET; - pcell(f, axis, along - 0.4, wallC + inw * strip * 0.86, 0.02, G_COLON, hue, wl * 1.2, 0.985); - pcell(f, axis, along + 0.5, wallC + inw * strip * 0.99, 0.02, G_DOT, hue, wl, 0.985); - } - - var VB_PITCH = 19, VB_P = 0.17, VB_W = 0.92; - - function vendBank(f, axis, along, wallC, inw, strip, sd) { - var n = 3 + (hash2(1, 0, sd + 101) < 0.45 ? 1 : 0); - var face = wallC + inw * 0.40; - var len = n * VB_W, i, a, hue, lum; - coverOf(axis, along - 0.08, along + len + 0.08, face, 2.02); - - panel(f, axis, along - 0.08, along + len + 0.08, face - inw * 0.04, 0, 2.02, - 0, P.shadow, 0, 0, 0, sd); - for (i = 0; i < n; i++) { - a = along + i * VB_W; - hue = vendHue(hash2(i, 2, sd + 211)); - lum = litLum(hue); - - panel(f, axis, a + 0.08, a + VB_W - 0.10, face, 1.72, 1.80, G_DASH, hue, lum, 0, 0, sd + i); - - panel(f, axis, a + 0.14, a + VB_W - 0.16, face, 1.10, 1.42, - G_8, hue, lum * 0.86, 30, 1, sd + i); - - pcell(f, axis, a + VB_W * 0.5, face, 0.92, G_DASH, hue, lum * 0.6, 1); - } - coverClear(); - - var wl = 22 + 26 * W_WET; - pcell(f, axis, along + VB_W * 0.5, wallC + inw * strip * 0.62, 0.02, G_COLON, - vendHue(hash2(0, 2, sd + 211)), wl, 0.985); - pcell(f, axis, along + len - VB_W * 0.5, wallC + inw * strip * 0.62, 0.02, G_DOT, - vendHue(hash2(n - 1, 2, sd + 211)), wl, 0.985); - } - - function drawMarket(f) { - if (!CITY) return; - var axis, idx, n, side, wallC, inw, pave, strip, along, dd, sd, len; - for (axis = 0; axis < 2; axis++) { - for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { - streetSpan(axis, idx); - - if (SPAN.w < 5) continue; - pave = paveOf(SPAN.w); - strip = pave - KERB_LIP; - if (strip < 1.05) continue; - for (side = 0; side < 2; side++) { - wallC = side ? SPAN.c1 : SPAN.c0; - inw = side ? -1 : 1; - - for (n = alongLo(axis, MR_PITCH); n <= alongHi(axis, MR_PITCH); n++) { - if (hash2(idx * 2 + side, n, BASE + 907) > MR_P) continue; - along = n * MR_PITCH + hash2(idx * 2 + side, n, BASE + 1013) * 12; - sd = BASE + idx * 977 + n * 6151 + side * 37; - len = rowStalls(sd) * STALL_W; - - dd = objVisible(axis, along + len * 0.5, wallC + inw, -8); - if (!dd || dd > REACH) continue; - if (!frontage(axis, along, len, wallC - inw * 0.5)) continue; - marketRow(f, axis, along, wallC, inw, strip, sd); - rowSteam(f, axis, along, wallC, inw, strip, sd, dd); - } - - for (n = alongLo(axis, KI_PITCH); n <= alongHi(axis, KI_PITCH); n++) { - if (hash2(idx * 2 + side, n, BASE + 1117) > KI_P) continue; - along = n * KI_PITCH + hash2(idx * 2 + side, n, BASE + 1223) * 8; - dd = objVisible(axis, along, wallC + inw, -3); - if (!dd || dd > REACH) continue; - if (!frontage(axis, along - 1, 2, wallC - inw * 0.5)) continue; - kiosk(f, axis, along, wallC, inw, strip, BASE + idx * 1301 + n * 4099 + side * 53); - } - - for (n = alongLo(axis, VB_PITCH); n <= alongHi(axis, VB_PITCH); n++) { - if (hash2(idx * 2 + side, n, BASE + 1327) > VB_P) continue; - along = n * VB_PITCH + hash2(idx * 2 + side, n, BASE + 1433) * 9; - dd = objVisible(axis, along + 1.4, wallC + inw, -4); - if (!dd || dd > REACH) continue; - if (!frontage(axis, along, 3.7, wallC - inw * 0.5)) continue; - vendBank(f, axis, along, wallC, inw, strip, - BASE + idx * 1523 + n * 3671 + side * 61); - } - } - } - } - } - - CC.ELEMENTS.push({ - name: 'market', - - world: 'cyber', - - layer: 17, - init: function (city) { boot(city); }, - draw: function (f, cam, t) { - view(f, cam, t === undefined ? (cam.t || 0) : t); - drawMarket(f); - } - }); + }); })(CC); /* src/elements/moon_craft.js */ (function (CC) { - 'use strict'; + 'use strict'; - var PR = CC.Proj.make(), V = PR.V, PJ = PR.PJ; - var project = PR.project, emit = PR.emit, column = PR.column; + 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, put = CC.put, clamp = CC.clamp; + var P = CC.P, hash2 = CC.hash2, put = CC.put, clamp = CC.clamp; - var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_UNDER = CC.g('_'), - G_DOT = CC.g('.'), G_COLON = CC.g(':'), G_STAR = CC.g('*'), G_PLUS = CC.g('+'), - G_HASH = CC.g('#'), G_PCT = CC.g('%'), - G_8 = CC.g('8'), G_O = CC.g('O'), G_o = CC.g('o'), G_0 = CC.g('0'), - G_SLASH = CC.g('/'), G_BACK = CC.g('\\'), G_CARET = CC.g('^'); + var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_UNDER = CC.g('_'), + G_DOT = CC.g('.'), G_COLON = CC.g(':'), G_STAR = CC.g('*'), G_PLUS = CC.g('+'), + G_HASH = CC.g('#'), G_PCT = CC.g('%'), + G_8 = CC.g('8'), G_O = CC.g('O'), G_o = CC.g('o'), G_0 = CC.g('0'), + G_SLASH = CC.g('/'), G_BACK = CC.g('\\'), G_CARET = CC.g('^'), + G_COMMA = CC.g(','), G_QUOTE = CC.g("'"), G_TICK = CC.g('`'); - var CITY = null, BASE = 0, MOON = null; + var CITY = null, BASE = 0, MOON = null; - var SITE_MAX = 3, SITE_MIN = 400.0; + var SITE_MAX = 3, SITE_MIN = 400.0; - var SITE_SCAN = 1800.0, SITE_STEP = 12.0; + var SITE_SCAN = 1800.0, SITE_STEP = 12.0; - var SITE_OFF = [0, 16, -16, 30, -30]; + var SITE_OFF = [0, 16, -16, 30, -30]; - var sX = new Float64Array(SITE_MAX), sZ = new Float64Array(SITE_MAX), sN = 0; - var SCAN_CAM = { x: 0, z: 0, yaw: 0, eyeY: 1.7 }; + var sX = new Float64Array(SITE_MAX), sZ = new Float64Array(SITE_MAX), sN = 0; + var SCAN_CAM = { x: 0, z: 0, yaw: 0, eyeY: 1.7 }; - function siteScan(city) { - sN = 0; - var s, i, D; - for (s = SITE_STEP; s < SITE_SCAN && sN < SITE_MAX; s += SITE_STEP) { - city.camera(SCAN_CAM, city, s / city.SPEED); + function siteScan(city) { + sN = 0; + var s, i, D; + for (s = SITE_STEP; s < SITE_SCAN && sN < SITE_MAX; s += SITE_STEP) { + city.camera(SCAN_CAM, city, s / city.SPEED); - var rx = Math.cos(SCAN_CAM.yaw), rz = -Math.sin(SCAN_CAM.yaw); - for (i = 0; i < SITE_OFF.length; i++) { - var px = SCAN_CAM.x + rx * SITE_OFF[i], pz = SCAN_CAM.z + rz * SITE_OFF[i]; - D = city.DISTRICTS[city.districtAt(px, pz)]; - if (!D || !D.hardware) continue; + var rx = Math.cos(SCAN_CAM.yaw), rz = -Math.sin(SCAN_CAM.yaw); + for (i = 0; i < SITE_OFF.length; i++) { + var px = SCAN_CAM.x + rx * SITE_OFF[i], pz = SCAN_CAM.z + rz * SITE_OFF[i]; + D = city.DISTRICTS[city.districtAt(px, pz)]; + if (!D || !D.hardware) continue; - if (city.height(px, pz) > 0.05) continue; - if (sN && near2(px, pz, sX[sN - 1], sZ[sN - 1]) < SITE_MIN * SITE_MIN) continue; - sX[sN] = px; sZ[sN] = pz; sN++; - break; - } + if (city.height(px, pz) > 0.05) continue; + if (sN && near2(px, pz, sX[sN - 1], sZ[sN - 1]) < SITE_MIN * SITE_MIN) continue; + sX[sN] = px; sZ[sN] = pz; sN++; + break; + } + } + } + + function near2(ax, az, bx, bz) { + var dx = ax - bx, dz = az - bz; + return dx * dx + dz * dz; + } + + var BOOTED = null; + function boot(city) { + CITY = (city && city.aveX && city.world === 'moon') ? city : null; + if (CITY === BOOTED) return; + BOOTED = CITY; + BASE = CITY ? ((Math.imul(CITY.seed | 0, 19391) >>> 6) & 0x3fffff) : 0; + + LAY_AZ = Math.PI + (CC.Daylight ? CC.Daylight.AZ_NOON : -0.5); + sN = 0; + if (CITY) siteScan(CITY); + } + + var KX = 0, KZ = 1, KALT = 0.25, KNIGHT = 0, KDAY = 1, KMIX = 0; + + var LAY_AZ = Math.PI - 0.5; + + function key() { + if (!MOON) MOON = CC.SurfMoon || (CC.SURFACES ? CC.SURFACES.moon : null); + if (!MOON) return; + KX = MOON.SUN_X; KZ = MOON.SUN_Z; KALT = MOON.SUN_ALT; + KNIGHT = MOON.night; KDAY = 1 - KNIGHT; + KMIX = (CC.dayMix === undefined) ? 0 : CC.dayMix; + } + + function faceSun(nx, nz) { + var k = clamp(0.5 + 3.0 * (nx * KX + nz * KZ), 0, 1); + return k * k * (3 - 2 * k); + } + + function rimLum(base) { return KDAY * (198 + 34 * base) + KNIGHT * (84 + 28 * base); } + function bodyLum(base) { + return (KDAY * (190 + 46 * base) + KNIGHT * (60 + 26 * base)) * (1 - 0.30 * KMIX); + } + function foilLum(base) { + return (KDAY * (228 + 22 * base) + KNIGHT * (92 + 26 * base)) * (1 + 0.10 * KMIX); + } + + function seeAt(px, pz, near) { + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < near || w > V.far) return 0; + var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; + if (s < -lim || s > lim) return 0; + return w; + } + + function qOf(dist) { + var q = V.colK / (2 * dist); + return q < 2.2 ? 2.2 : (q > 30 ? 30 : q); + } + + var LOOK_MASS = 0, LOOK_FOIL = 1, LOOK_BODY = 2, LOOK_WIN = 3; + + var WIN_U = 0, WIN_V = 0, WIN_W = 0.62, WIN_H = 0.50; + + function quad(f, ax, az, bx, bz, y0, y1, look, salt, sun) { + var ddx = bx - ax, ddz = bz - az; + var mx = ax + ddx * 0.5, mz = az + ddz * 0.5; + var rx = mx - V.ox, rz = mz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < 0.5 || w > V.far) return; + var len = Math.sqrt(ddx * ddx + ddz * ddz); + var n = Math.ceil(len * V.colK / w) + 2; + if (n > 240) n = 240; + var q = qOf(w); + var i, r; + for (i = 0; i <= n; i++) { + var u = i / n, px = ax + ddx * u, pz = az + ddz * u; + if (!project(px, y0, pz)) continue; + var x = Math.floor(PJ.x), yb = PJ.y, d = PJ.d; + if (x < 0 || x >= V.cols) continue; + if (!project(px, y1, pz)) 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; + var r0 = Math.floor(yt), r1 = Math.floor(yb); + if (r1 - r0 > V.rows) r1 = r0 + V.rows; + if (r1 < 0 || r0 >= V.rows) continue; + if (r0 < 0) r0 = 0; + if (r1 >= V.rows) r1 = V.rows - 1; + var uu = u * len; + for (r = r0; r <= r1; r++) { + var vv = y0 + (y1 - y0) * ((yb - r) / span); + var hv = hash2(Math.floor(uu * q), Math.floor(vv * q), salt); + if (look === LOOK_MASS) { emit(f, x, r, 0, P.shadow, 0, d); continue; } + + var edge = 1, soft = 1; + if (sun !== undefined) { + edge = sun - hash2(Math.floor(uu * q), Math.floor(vv * q), salt ^ 0x2B) * 0.74; + soft = edge < 0.26 ? 0.24 + 2.923 * edge : 1; } + if (edge <= 0) { + + if (d < 25 && hv < 0.08) emit(f, x, r, hv < 0.03 ? G_DOT : G_COLON, P.slate, 16 + hv * 96, d); + else emit(f, x, r, 0, P.shadow, 0, d); + continue; + } + if (look === LOOK_FOIL) { + + if (hv > 0.86) emit(f, x, r, 0, P.shadow, 0, d); + else if (hv < 0.12) emit(f, x, r, hv < 0.05 ? G_STAR : G_8, P.pure, rimLum(hv * 7) * soft, d); + else emit(f, x, r, hv < 0.45 ? G_HASH : (hv < 0.66 ? G_PCT : G_8), P.amber, + foilLum((hv - 0.12) * 1.35) * soft, d); + continue; + } + + if (look === LOOK_WIN) { + + var wu = (uu - WIN_U) / WIN_W, wv = (vv - WIN_V) / WIN_H; + if (wu > 0 && wv > 0 && wu + wv < 1) { emit(f, x, r, 0, P.shadow, 0, d); continue; } + } + if (hv > 0.90) emit(f, x, r, 0, P.shadow, 0, d); + else if (hv < 0.04) emit(f, x, r, G_STAR, P.pure, rimLum(hv * 14) * soft, d); + else emit(f, x, r, hv < 0.30 ? G_8 : (hv < 0.58 ? G_HASH : (hv < 0.78 ? G_PCT : G_O)), + P.white, bodyLum(hv) * soft, d); + } } + } - function near2(ax, az, bx, bz) { - var dx = ax - bx, dz = az - bz; - return dx * dx + dz * dz; + function run(f, ax, ay, az, bx, by, bz, ch, col, lum, n, thick) { + var lx = -1, ly = 0, ld = 0, i; + for (i = 0; i <= n; i++) { + var u = i / n; + if (!project(ax + (bx - ax) * u, ay + (by - ay) * u, az + (bz - az) * u)) { lx = -1; continue; } + var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d; + if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1; + if (lx >= 0) { + var dx = x - lx, dy = r - ly; + var st = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); + if (st > V.cols * 2) st = 0; + for (var qq = 1; qq < st; qq++) { + var tq = qq / st; + var sx = lx + Math.round(dx * tq), sy = ly + Math.round(dy * tq), sd = ld + (d - ld) * tq; + emit(f, sx, sy, ch, col, lum, sd); + if (thick) emit(f, sx, sy + 1, ch, col, lum, sd); + } + } + emit(f, x, r, ch, col, lum, d); + if (thick) emit(f, x, r + 1, ch, col, lum, d); + lx = x; ly = r; ld = d; } + } - var BOOTED = null; - function boot(city) { - CITY = (city && city.aveX && city.world === 'moon') ? city : null; - if (CITY === BOOTED) return; - BOOTED = CITY; - BASE = CITY ? ((Math.imul(CITY.seed | 0, 19391) >>> 6) & 0x3fffff) : 0; - sN = 0; - if (CITY) siteScan(CITY); + function disc(f, px, py, pz, rad, ring, ch, col, lum) { + if (!project(px, py, pz)) return; + var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d; + var rw = rad * V.colK / d, rh = rad * V.scale / d; + if (rw < 0.8) { emit(f, x, y, ch, col, lum, d); return; } + var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; + if (iw > 12) iw = 12; + if (ih > 12) ih = 12; + for (dy = -ih; dy <= ih; dy++) { + for (dx = -iw; dx <= iw; dx++) { + var u = dx / rw, v = dy / rh, r2 = u * u + v * v; + if (r2 > 1.08) continue; + if (ring && r2 < 0.34) continue; + emit(f, x + dx, y + dy, ch, col, lum, d); + } } + } - var KX = 0, KZ = 1, KALT = 0.25, KNIGHT = 0, KDAY = 1, KMIX = 0; + var SH_MAX = 30.0, SH_SOFT = 0.9; - function key() { - if (!MOON) MOON = CC.SurfMoon || (CC.SURFACES ? CC.SURFACES.moon : null); - if (!MOON) return; - KX = MOON.SUN_X; KZ = MOON.SUN_Z; KALT = MOON.SUN_ALT; - KNIGHT = MOON.night; KDAY = 1 - KNIGHT; - KMIX = (CC.dayMix === undefined) ? 0 : CC.dayMix; + function shadowPatch(f, cx, cz, w0, w1, hgt, salt) { + if (KALT < 0.02) return; + var len = hgt / Math.tan(KALT); + if (len > SH_MAX) len = SH_MAX; + if (len < 0.4) return; + + var dx = -KX, dz = -KZ; + var ex = -dz, ez = dx; + + var bx0 = 1e9, bx1 = -1e9, by0 = 1e9, by1 = -1e9, k, hit = 0; + for (k = 0; k < 4; k++) { + var a = (k & 2) ? len : 0, b = ((k & 1) ? 1 : -1) * ((k & 2) ? w1 : w0); + if (!project(cx + dx * a + ex * b, 0, cz + dz * a + ez * b)) continue; + hit = 1; + if (PJ.x < bx0) bx0 = PJ.x; + if (PJ.x > bx1) bx1 = PJ.x; + if (PJ.y < by0) by0 = PJ.y; + if (PJ.y > by1) by1 = PJ.y; } + if (!hit) return; + var x0 = Math.floor(bx0) - 1, x1 = Math.ceil(bx1) + 1; + var y0 = Math.floor(by0) - 1, y1 = Math.ceil(by1) + 1; + if (x0 < 0) x0 = 0; + if (y0 < 0) y0 = 0; + if (x1 >= V.cols) x1 = V.cols - 1; + if (y1 >= V.rows) y1 = V.rows - 1; - function faceSun(nx, nz) { - var k = clamp(0.5 + 3.0 * (nx * KX + nz * KZ), 0, 1); - return k * k * (3 - 2 * k); + var top = Math.ceil(V.horizon) + 1; + if (y0 < top) y0 = top; + + var slope = (w1 - w0) / len; + for (var r = y0; r <= y1; r++) { + var w = V.eyeY * V.scale / ((r + 0.5) - V.horizon); + if (w <= 0 || w > V.far) continue; + for (var x = x0; x <= x1; x++) { + var i = r * V.cols + x; + if (f.kind[i] !== 2) continue; + if (f.dist[i] > 1e5) continue; + var sp = ((x + 0.5) - V.colMid) / V.colK; + var px = V.ox + (V.fwx + V.rgx * sp) * w, pz = V.oz + (V.fwz + V.rgz * sp) * w; + var qx = px - cx, qz = pz - cz; + var a2 = qx * dx + qz * dz; + if (a2 < -0.6 || a2 > len) continue; + var b2 = qx * ex + qz * ez; if (b2 < 0) b2 = -b2; + var hw = w0 + slope * (a2 < 0 ? 0 : a2); + + var m = hw - b2; + var m2 = len - a2; if (m2 < m) m = m2; + if (m <= 0) continue; + var d = w * Math.sqrt(1 + sp * sp) * 0.985; + if (!(d < f.dist[i])) continue; + if (m >= SH_SOFT) { put(f, x, r, 0, P.shadow, 0, d, 2); continue; } + var kk = m / SH_SOFT; + if (hash2(Math.floor(px * 2.7), Math.floor(pz * 2.7), salt) < kk) { + put(f, x, r, 0, P.shadow, 0, d, 2); + } else { + + f.lum[i] = (f.lum[i] * (1 - 0.62 * kk)) | 0; + } + } } + } - function rimLum(base) { return KDAY * (198 + 34 * base) + KNIGHT * (84 + 28 * base); } - function bodyLum(base) { - return (KDAY * (190 + 46 * base) + KNIGHT * (60 + 26 * base)) * (1 - 0.30 * KMIX); + var LM_HW = 2.11; + var LM_D0 = 1.50, LM_D1 = 4.73; + + var SCOUR_R = 11.5; + + var SC = { col: 0, lum: 0 }; + function fineOf(base, dist, hv) { + var far = dist >= 40 || (dist > 24 && hv > (40 - dist) / 16); + var dark = KNIGHT > 0.5 || (KNIGHT > 0 && hv < KNIGHT); + if (!far) { + if (dark) { SC.col = base > 0.72 ? P.pure : P.azure; SC.lum = (base > 0.72 ? 52 : 44) + 26 * base; } + else { SC.col = P.white; SC.lum = (150 + 62 * base) * (1 - 0.20 * KMIX); } + return SC; } - function foilLum(base) { - return (KDAY * (228 + 22 * base) + KNIGHT * (92 + 26 * base)) * (1 + 0.10 * KMIX); + SC.col = dark ? P.azure : P.pure; + SC.lum = (dark ? (dist < 125 ? 70 + dist * 0.62 : 60) : (dist < 125 ? 96 + dist * 0.62 : 88)) * + (0.90 + 0.26 * base); + return SC; + } + + function blastScour(f, cx, cz, salt) { + var w0 = seeAt(cx, cz, 1.0); + if (!w0) return; + + var bx0 = 1e9, bx1 = -1e9, by0 = 1e9, by1 = -1e9, k, hit = 0; + for (k = 0; k < 8; k++) { + var a = k * 0.7853981634; + if (!project(cx + Math.sin(a) * SCOUR_R, 0, cz + Math.cos(a) * SCOUR_R)) continue; + hit = 1; + if (PJ.x < bx0) bx0 = PJ.x; + if (PJ.x > bx1) bx1 = PJ.x; + if (PJ.y < by0) by0 = PJ.y; + if (PJ.y > by1) by1 = PJ.y; } + if (!hit) return; + var x0 = Math.floor(bx0) - 1, x1 = Math.ceil(bx1) + 1; + var y0 = Math.floor(by0) - 1, y1 = Math.ceil(by1) + 1; + if (x0 < 0) x0 = 0; + if (y0 < 0) y0 = 0; + if (x1 >= V.cols) x1 = V.cols - 1; + if (y1 >= V.rows) y1 = V.rows - 1; + var top = Math.ceil(V.horizon) + 1; + if (y0 < top) y0 = top; - function seeAt(px, pz, near) { - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < near || w > V.far) return 0; - var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; - if (s < -lim || s > lim) return 0; - return w; - } + for (var r = y0; r <= y1; r++) { + var w = V.eyeY * V.scale / ((r + 0.5) - V.horizon); + if (w <= 0 || w > V.far) continue; + for (var x = x0; x <= x1; x++) { + var i = r * V.cols + x; + if (f.kind[i] !== 2) continue; + if (f.dist[i] > 1e5) continue; + var sp = ((x + 0.5) - V.colMid) / V.colK; + var px = V.ox + (V.fwx + V.rgx * sp) * w, pz = V.oz + (V.fwz + V.rgz * sp) * w; + var qx = px - cx, qz = pz - cz; + var rr = Math.sqrt(qx * qx + qz * qz); - function qOf(dist) { - var q = V.colK / (2 * dist); - return q < 2.2 ? 2.2 : (q > 30 ? 30 : q); - } - - var LOOK_MASS = 0, LOOK_FOIL = 1, LOOK_BODY = 2, LOOK_WIN = 3; - - var WIN_U = 0, WIN_V = 0, WIN_W = 0.62, WIN_H = 0.50; - - function quad(f, ax, az, bx, bz, y0, y1, look, salt, sun) { - var ddx = bx - ax, ddz = bz - az; - var mx = ax + ddx * 0.5, mz = az + ddz * 0.5; - var rx = mx - V.ox, rz = mz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < 0.5 || w > V.far) return; - var len = Math.sqrt(ddx * ddx + ddz * ddz); - var n = Math.ceil(len * V.colK / w) + 2; - if (n > 240) n = 240; + if (rr < 2.6 || rr > SCOUR_R) continue; + var kf = 1 - (rr - 2.6) / (SCOUR_R - 2.6); + kf = kf * kf; + var ax = qx < 0 ? -qx : qx, az = qz < 0 ? -qz : qz, sm = ax + az; + if (sm < 1e-6) continue; + var oa = qz / sm; if (qx < 0) oa = oa >= 0 ? 2 - oa : -2 - oa; + var sf = oa * 9.0, si = Math.floor(sf); sf -= si; + var e = hash2(si, 0, salt + 0x11) < 0.42 + ? (sf < 0.3 ? sf / 0.3 : (sf > 0.7 ? (1 - sf) / 0.3 : 1)) : 0; + var dens = 0.30 * kf * (0.55 + 1.25 * e); var q = qOf(w); - var i, r; - for (i = 0; i <= n; i++) { - var u = i / n, px = ax + ddx * u, pz = az + ddz * u; - if (!project(px, y0, pz)) continue; - var x = Math.floor(PJ.x), yb = PJ.y, d = PJ.d; - if (x < 0 || x >= V.cols) continue; - if (!project(px, y1, pz)) 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; - var r0 = Math.floor(yt), r1 = Math.floor(yb); - if (r1 - r0 > V.rows) r1 = r0 + V.rows; - if (r1 < 0 || r0 >= V.rows) continue; - if (r0 < 0) r0 = 0; - if (r1 >= V.rows) r1 = V.rows - 1; - var uu = u * len; - for (r = r0; r <= r1; r++) { - var vv = y0 + (y1 - y0) * ((yb - r) / span); - var hv = hash2(Math.floor(uu * q), Math.floor(vv * q), salt); - if (look === LOOK_MASS) { emit(f, x, r, 0, P.shadow, 0, d); continue; } + var hv = hash2(Math.floor(px * q), Math.floor(pz * q), salt); + if (hv >= dens) continue; + var d = w * Math.sqrt(1 + sp * sp) * 0.99; + if (!(d < f.dist[i])) continue; + var lf = fineOf(0.62 + 0.38 * (hv / dens), d, hv); + put(f, x, r, hv < 0.34 ? G_DOT : (hv < 0.68 ? G_COMMA : G_QUOTE), + lf.col, lf.lum | 0, d, 2); + } + } + } - var edge = 1, soft = 1; - if (sun !== undefined) { - edge = sun - hash2(Math.floor(uu * q), Math.floor(vv * q), salt ^ 0x2B) * 0.74; - soft = edge < 0.26 ? 0.24 + 2.923 * edge : 1; - } - if (edge <= 0) { + var LM_A1 = 6.55; + var LM_AHW = 1.17; + var LM_PAD = 4.70; - if (d < 25 && hv < 0.08) emit(f, x, r, hv < 0.03 ? G_DOT : G_COLON, P.slate, 16 + hv * 96, d); - else emit(f, x, r, 0, P.shadow, 0, d); - continue; - } - if (look === LOOK_FOIL) { + var LM_ATT = 2.35, LM_ATY = 2.05; - if (hv > 0.86) emit(f, x, r, 0, P.shadow, 0, d); - else if (hv < 0.12) emit(f, x, r, hv < 0.05 ? G_STAR : G_8, P.pure, rimLum(hv * 7) * soft, d); - else emit(f, x, r, hv < 0.45 ? G_HASH : (hv < 0.66 ? G_PCT : G_8), P.amber, - foilLum((hv - 0.12) * 1.35) * soft, d); - continue; - } + function drawLM(f, k) { + var cx = sX[k], cz = sZ[k]; + var w = seeAt(cx, cz, 1.2); + if (!w) return; - if (look === LOOK_WIN) { + var head = LAY_AZ + (hash2(k, 1, BASE + 0x81) - 0.5) * 1.5; + var fx = Math.sin(head), fz = Math.cos(head); + var rx = Math.cos(head), rz = -Math.sin(head); - var wu = (uu - WIN_U) / WIN_W, wv = (vv - WIN_V) / WIN_H; - if (wu > 0 && wv > 0 && wu + wv < 1) { emit(f, x, r, 0, P.shadow, 0, d); continue; } - } - if (hv > 0.90) emit(f, x, r, 0, P.shadow, 0, d); - else if (hv < 0.04) emit(f, x, r, G_STAR, P.pure, rimLum(hv * 14) * soft, d); - else emit(f, x, r, hv < 0.30 ? G_8 : (hv < 0.58 ? G_HASH : (hv < 0.78 ? G_PCT : G_O)), - P.white, bodyLum(hv) * soft, d); - } - } + blastScour(f, cx, cz, BASE + 0x83); + shadowPatch(f, cx, cz, 4.9, 1.7, LM_A1, BASE + 0x82); + + var s, nx, nz, ax, az, bx, bz; + for (s = 0; s < 4; s++) { + + nx = (s === 0 ? fx : (s === 1 ? rx : (s === 2 ? -fx : -rx))); + nz = (s === 0 ? fz : (s === 1 ? rz : (s === 2 ? -fz : -rz))); + var tx = -nz, tz = nx; + ax = cx + nx * LM_HW - tx * LM_HW; az = cz + nz * LM_HW - tz * LM_HW; + bx = cx + nx * LM_HW + tx * LM_HW; bz = cz + nz * LM_HW + tz * LM_HW; + var fsun = faceSun(nx, nz); + quad(f, ax, az, bx, bz, LM_D0, LM_D1, LOOK_FOIL, BASE + 0x90 + s, fsun); + + if (fsun < 0.02) continue; + run(f, ax, LM_D1, az, bx, LM_D1, bz, G_EQ, P.pure, rimLum(0.8) * fsun, 14, 0); + + run(f, ax, LM_D0, az, bx, LM_D0, bz, G_DASH, P.pure, rimLum(0.6) * fsun, 14, 0); + run(f, ax, LM_D0 - 0.10, az, bx, LM_D0 - 0.10, bz, 0, P.shadow, 0, 14, 1); } - function run(f, ax, ay, az, bx, by, bz, ch, col, lum, n, thick) { - var lx = -1, ly = 0, ld = 0, i; - for (i = 0; i <= n; i++) { - var u = i / n; - if (!project(ax + (bx - ax) * u, ay + (by - ay) * u, az + (bz - az) * u)) { lx = -1; continue; } - var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d; - if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1; - if (lx >= 0) { - var dx = x - lx, dy = r - ly; - var st = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); - if (st > V.cols * 2) st = 0; - for (var qq = 1; qq < st; qq++) { - var tq = qq / st; - var sx = lx + Math.round(dx * tq), sy = ly + Math.round(dy * tq), sd = ld + (d - ld) * tq; - emit(f, sx, sy, ch, col, lum, sd); - if (thick) emit(f, sx, sy + 1, ch, col, lum, sd); - } - } - emit(f, x, r, ch, col, lum, d); - if (thick) emit(f, x, r + 1, ch, col, lum, d); - lx = x; ly = r; ld = d; + var bestS = -2, bestX = 0, bestZ = 0; + for (s = 0; s < 4; s++) { + var ox = (s < 2 ? 1 : -1) * fx + ((s & 1) ? -1 : 1) * rx; + var oz = (s < 2 ? 1 : -1) * fz + ((s & 1) ? -1 : 1) * rz; + var dp = ox * KX + oz * KZ; + if (dp > bestS) { bestS = dp; bestX = ox; bestZ = oz; } + } + column(f, cx + bestX * LM_HW, cz + bestZ * LM_HW, LM_D0, LM_D1, G_PIPE, P.pure, + rimLum(1) * clamp(bestS, 0, 1), w < 14 ? 1 : 0); + + quad(f, cx - rx * 0.72, cz - rz * 0.72, cx + rx * 0.72, cz + rz * 0.72, 0.55, LM_D0, + LOOK_MASS, BASE + 0x95); + + var dg, pxs, pzs; + var strutLum = rimLum(0.85), thick = w < 34 ? 1 : 0; + for (dg = 0; dg < 4; dg++) { + var a = head + Math.PI * 0.25 + dg * Math.PI * 0.5; + var lx = Math.sin(a), lz = Math.cos(a); + pxs = cx + lx * LM_PAD; pzs = cz + lz * LM_PAD; + + var sl = strutLum * (0.60 + 0.40 * faceSun(lx, lz)); + + var gl = G_PIPE; + if (project(cx + lx * LM_ATT, LM_ATY, cz + lz * LM_ATT)) { + var gx0 = PJ.x, gy0 = PJ.y; + if (project(pxs, 0.20, pzs)) { + var gdx = PJ.x - gx0, gdy = PJ.y - gy0; + var agx = gdx < 0 ? -gdx : gdx, agy = gdy < 0 ? -gdy : gdy; + gl = agx > agy * 1.7 ? G_UNDER + : (agy > agx * 1.7 ? G_PIPE : (gdx * gdy > 0 ? G_BACK : G_SLASH)); } + } + + run(f, cx + lx * LM_ATT, LM_ATY, cz + lz * LM_ATT, pxs, 0.20, pzs, + gl, P.pure, sl, 12, thick); + run(f, cx + lx * LM_ATT, LM_ATY - 0.08, cz + lz * LM_ATT, pxs, 0.12, pzs, + 0, P.shadow, 0, 12, 1); + run(f, cx + lx * (LM_ATT + 0.15), LM_D1 - 0.55, cz + lz * (LM_ATT + 0.15), + cx + lx * (LM_PAD * 0.62), 0.55, cz + lz * (LM_PAD * 0.62), + G_SLASH, P.pure, sl * 0.8, 10, 0); + + run(f, pxs - lz * 0.47, 0.12, pzs + lx * 0.47, pxs + lz * 0.47, 0.12, pzs - lx * 0.47, + G_UNDER, P.pure, rimLum(0.7), 6, 0); + run(f, pxs - lz * 0.47, 0.02, pzs + lx * 0.47, pxs + lz * 0.47, 0.02, pzs - lx * 0.47, + 0, P.shadow, 0, 6, 1); + + if (dg !== 1 && w < 46) + run(f, pxs, 0.20, pzs, pxs + lx * 0.5, 0.02, pzs + lz * 0.5, G_DOT, P.pure, + rimLum(0.2), 4, 0); } - function disc(f, px, py, pz, rad, ring, ch, col, lum) { - if (!project(px, py, pz)) return; - var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d; - var rw = rad * V.colK / d, rh = rad * V.scale / d; - if (rw < 0.8) { emit(f, x, y, ch, col, lum, d); return; } - var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; - if (iw > 12) iw = 12; - if (ih > 12) ih = 12; - for (dy = -ih; dy <= ih; dy++) { - for (dx = -iw; dx <= iw; dx++) { - var u = dx / rw, v = dy / rh, r2 = u * u + v * v; - if (r2 > 1.08) continue; - if (ring && r2 < 0.34) continue; - emit(f, x + dx, y + dy, ch, col, lum, d); - } - } + for (s = 0; s < 4; s++) { + nx = (s === 0 ? fx : (s === 1 ? rx : (s === 2 ? -fx : -rx))); + nz = (s === 0 ? fz : (s === 1 ? rz : (s === 2 ? -fz : -rz))); + var ux = -nz, uz = nx; + ax = cx + nx * LM_AHW - ux * LM_AHW; az = cz + nz * LM_AHW - uz * LM_AHW; + bx = cx + nx * LM_AHW + ux * LM_AHW; bz = cz + nz * LM_AHW + uz * LM_AHW; + var look = LOOK_BODY; + if (s === 0) { + + WIN_U = LM_AHW * 0.62; WIN_V = LM_D1 + 0.95; WIN_W = 0.66; WIN_H = 0.54; + look = LOOK_WIN; + } + var asun = faceSun(nx, nz); + quad(f, ax, az, bx, bz, LM_D1, LM_A1, look, BASE + 0xA0 + s, asun); + if (asun > 0.02) + run(f, ax, LM_A1, az, bx, LM_A1, bz, G_EQ, P.pure, rimLum(1) * asun, 12, 0); } - var SH_MAX = 30.0, SH_SOFT = 0.9; + quad(f, cx - rx * 0.78 - fx * 0.3, cz - rz * 0.78 - fz * 0.3, + cx + rx * 0.78 - fx * 0.3, cz + rz * 0.78 - fz * 0.3, LM_A1, LM_A1 + 0.48, + LOOK_BODY, BASE + 0xA8, faceSun(-fx, -fz)); - function shadowPatch(f, cx, cz, w0, w1, hgt, salt) { - if (KALT < 0.02) return; - var len = hgt / Math.tan(KALT); - if (len > SH_MAX) len = SH_MAX; - if (len < 0.4) return; + column(f, cx + fx * 0.35, cz + fz * 0.35, LM_A1, LM_A1 + 1.05, G_PIPE, P.pure, rimLum(0.5), 0); + disc(f, cx + fx * 0.35, LM_A1 + 1.28, cz + fz * 0.35, 0.36, 1, G_0, P.pure, rimLum(0.9)); + column(f, cx - rx * 0.95, cz - rz * 0.95, LM_A1 - 0.2, LM_A1 + 0.72, G_PIPE, P.pure, + rimLum(0.35), 0); - var dx = -KX, dz = -KZ; - var ex = -dz, ez = dx; + if (w < 40 && project(cx + fx * LM_AHW - rx * 0.55, LM_D1 + 1.62, cz + fz * LM_AHW - rz * 0.55)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_PLUS, P.pure, + rimLum(1) * faceSun(fx, fz), PJ.d); - var bx0 = 1e9, bx1 = -1e9, by0 = 1e9, by1 = -1e9, k, hit = 0; - for (k = 0; k < 4; k++) { - var a = (k & 2) ? len : 0, b = ((k & 1) ? 1 : -1) * ((k & 2) ? w1 : w0); - if (!project(cx + dx * a + ex * b, 0, cz + dz * a + ez * b)) continue; - hit = 1; - if (PJ.x < bx0) bx0 = PJ.x; - if (PJ.x > bx1) bx1 = PJ.x; - if (PJ.y < by0) by0 = PJ.y; - if (PJ.y > by1) by1 = PJ.y; - } - if (!hit) return; - var x0 = Math.floor(bx0) - 1, x1 = Math.ceil(bx1) + 1; - var y0 = Math.floor(by0) - 1, y1 = Math.ceil(by1) + 1; - if (x0 < 0) x0 = 0; - if (y0 < 0) y0 = 0; - if (x1 >= V.cols) x1 = V.cols - 1; - if (y1 >= V.rows) y1 = V.rows - 1; + if (w < 55) { + var lax = cx + fx * (LM_PAD * 0.72), laz = cz + fz * (LM_PAD * 0.72); + var lbx = cx + fx * LM_ATT, lbz = cz + fz * LM_ATT; + var rungs = 9, ri; + for (ri = 0; ri <= rungs; ri++) { + var u = ri / rungs; + var px2 = lax + (lbx - lax) * u, pz2 = laz + (lbz - laz) * u; + var py2 = 0.30 + u * (LM_D0 + 0.42 - 0.30); + run(f, px2 - rx * 0.24, py2, pz2 - rz * 0.24, px2 + rx * 0.24, py2, pz2 + rz * 0.24, + G_DASH, P.pure, rimLum(0.5), 3); + } - var top = Math.ceil(V.horizon) + 1; - if (y0 < top) y0 = top; + run(f, lbx - rx * 0.45, LM_D0 + 0.44, lbz - rz * 0.45, lbx + rx * 0.45, LM_D0 + 0.44, + lbz + rz * 0.45, G_EQ, P.pure, rimLum(0.9), 5); + } + } - var slope = (w1 - w0) / len; - for (var r = y0; r <= y1; r++) { - var w = V.eyeY * V.scale / ((r + 0.5) - V.horizon); - if (w <= 0 || w > V.far) continue; - for (var x = x0; x <= x1; x++) { - var i = r * V.cols + x; - if (f.kind[i] !== 2) continue; - if (f.dist[i] > 1e5) continue; - var sp = ((x + 0.5) - V.colMid) / V.colK; - var px = V.ox + (V.fwx + V.rgx * sp) * w, pz = V.oz + (V.fwz + V.rgz * sp) * w; - var qx = px - cx, qz = pz - cz; - var a2 = qx * dx + qz * dz; - if (a2 < -0.6 || a2 > len) continue; - var b2 = qx * ex + qz * ez; if (b2 < 0) b2 = -b2; - var hw = w0 + slope * (a2 < 0 ? 0 : a2); + var FLAG_Y0 = 1.42, FLAG_Y1 = 2.33, FLAG_W = 1.52, FLAG_POLE = 2.45; - var m = hw - b2; - var m2 = len - a2; if (m2 < m) m = m2; - if (m <= 0) continue; - var d = w * Math.sqrt(1 + sp * sp) * 0.985; - if (!(d < f.dist[i])) continue; - if (m >= SH_SOFT) { put(f, x, r, 0, P.shadow, 0, d, 2); continue; } - var kk = m / SH_SOFT; - if (hash2(Math.floor(px * 2.7), Math.floor(pz * 2.7), salt) < kk) { - put(f, x, r, 0, P.shadow, 0, d, 2); - } else { + function drawFlag(f, k) { + var cx = sX[k], cz = sZ[k]; - f.lum[i] = (f.lum[i] * (1 - 0.62 * kk)) | 0; - } - } - } + var b = LAY_AZ + 1.15 + hash2(k, 2, BASE + 0xB0) * 0.5; + var px = cx + Math.sin(b) * 9.6, pz = cz + Math.cos(b) * 9.6; + var w = seeAt(px, pz, 1.0); + if (!w) return; + + var fb = LAY_AZ + Math.PI * 0.5; + var ex = Math.sin(fb), ez = Math.cos(fb); + + shadowPatch(f, px, pz, 0.5, 0.9, FLAG_POLE, BASE + 0xB1); + + column(f, px, pz, 0, FLAG_POLE, G_PIPE, P.pure, rimLum(0.6), 0); + + var i, r; + var ax = px, az = pz, bx = px + ex * FLAG_W, bz = pz + ez * FLAG_W; + var n = Math.ceil(FLAG_W * V.colK / w) + 2; + if (n > 90) n = 90; + var redLum = (KDAY * 214 + KNIGHT * 96) * (1 + 0.10 * KMIX); + for (i = 0; i <= n; i++) { + var u = i / n; + if (!project(ax + (bx - ax) * u, FLAG_Y0, az + (bz - az) * u)) continue; + var x = Math.floor(PJ.x), yb = PJ.y, d = PJ.d; + if (!project(ax + (bx - ax) * u, FLAG_Y1, az + (bz - az) * u)) continue; + var yt = PJ.y; + if (yt > yb) { var sw = yt; yt = yb; yb = sw; } + var r0 = Math.floor(yt), r1 = Math.floor(yb), span = (yb - yt) || 1e-4; + if (r1 - r0 > 24) r1 = r0 + 24; + for (r = r0; r <= r1; r++) { + var band = Math.floor(((yb - r) / span) * 3); + if (band < 0) band = 0; + if (band > 2) band = 2; + + if (band === 1) emit(f, x, r, G_HASH, P.pure, rimLum(0.9), d); + else emit(f, x, r, G_HASH, P.red, redLum, d); + } } - var LM_HW = 2.11; - var LM_D0 = 1.50, LM_D1 = 4.73; - var LM_A1 = 6.55; - var LM_AHW = 1.17; - var LM_PAD = 4.70; + run(f, ax, FLAG_Y1, az, bx, FLAG_Y1, bz, G_DASH, P.pure, rimLum(1), 10); + } - var LM_ATT = 2.35, LM_ATY = 2.05; + var RV_LEN = 3.05, RV_TRK = 1.03, RV_WH = 0.41, RV_DECK = 0.62, RV_SEAT = 1.14; - function drawLM(f, k) { - var cx = sX[k], cz = sZ[k]; - var w = seeAt(cx, cz, 1.2); - if (!w) return; + function hasRover(k) { return hash2(k, 3, BASE + 0xC0) < 0.58; } - var head = Math.atan2(KX, KZ) + (hash2(k, 1, BASE + 0x81) - 0.5) * 1.5; - var fx = Math.sin(head), fz = Math.cos(head); - var rx = Math.cos(head), rz = -Math.sin(head); + function drawRover(f, k) { + var cx = sX[k], cz = sZ[k]; + var b = LAY_AZ - 0.85 - hash2(k, 4, BASE + 0xC1) * 0.6; + var px = cx + Math.sin(b) * 24.0, pz = cz + Math.cos(b) * 24.0; + var w = seeAt(px, pz, 1.0); + if (!w) return; - shadowPatch(f, cx, cz, 4.9, 1.7, LM_A1, BASE + 0x82); + var hd = LAY_AZ + 1.35 + (hash2(k, 5, BASE + 0xC2) - 0.5) * 0.7; + var fx = Math.sin(hd), fz = Math.cos(hd); + var rx = Math.cos(hd), rz = -Math.sin(hd); - var s, nx, nz, ax, az, bx, bz; - for (s = 0; s < 4; s++) { + drawTracks(f, px, pz, fx, fz, rx, rz, k); + shadowPatch(f, px, pz, 1.8, 0.9, RV_SEAT + 0.5, BASE + 0xC3); - nx = (s === 0 ? fx : (s === 1 ? rx : (s === 2 ? -fx : -rx))); - nz = (s === 0 ? fz : (s === 1 ? rz : (s === 2 ? -fz : -rz))); - var tx = -nz, tz = nx; - ax = cx + nx * LM_HW - tx * LM_HW; az = cz + nz * LM_HW - tz * LM_HW; - bx = cx + nx * LM_HW + tx * LM_HW; bz = cz + nz * LM_HW + tz * LM_HW; - var fsun = faceSun(nx, nz); - quad(f, ax, az, bx, bz, LM_D0, LM_D1, LOOK_FOIL, BASE + 0x90 + s, fsun); + var hx = fx * RV_LEN * 0.5, hz = fz * RV_LEN * 0.5; + quad(f, px - hx, pz - hz, px + hx, pz + hz, 0.50, RV_DECK, LOOK_MASS, BASE + 0xC4); + run(f, px - hx, RV_DECK, pz - hz, px + hx, RV_DECK, pz + hz, G_EQ, P.pure, rimLum(0.8), 10); - if (fsun < 0.02) continue; - run(f, ax, LM_D1, az, bx, LM_D1, bz, G_EQ, P.pure, rimLum(0.8) * fsun, 14, 0); - - run(f, ax, LM_D0, az, bx, LM_D0, bz, G_DASH, P.pure, rimLum(0.6) * fsun, 14, 0); - run(f, ax, LM_D0 - 0.10, az, bx, LM_D0 - 0.10, bz, 0, P.shadow, 0, 14, 1); - } - - var bestS = -2, bestX = 0, bestZ = 0; - for (s = 0; s < 4; s++) { - var ox = (s < 2 ? 1 : -1) * fx + ((s & 1) ? -1 : 1) * rx; - var oz = (s < 2 ? 1 : -1) * fz + ((s & 1) ? -1 : 1) * rz; - var dp = ox * KX + oz * KZ; - if (dp > bestS) { bestS = dp; bestX = ox; bestZ = oz; } - } - column(f, cx + bestX * LM_HW, cz + bestZ * LM_HW, LM_D0, LM_D1, G_PIPE, P.pure, - rimLum(1) * clamp(bestS, 0, 1), w < 14 ? 1 : 0); - - quad(f, cx - rx * 0.72, cz - rz * 0.72, cx + rx * 0.72, cz + rz * 0.72, 0.55, LM_D0, - LOOK_MASS, BASE + 0x95); - - var dg, pxs, pzs; - var strutLum = rimLum(0.85), thick = w < 34 ? 1 : 0; - for (dg = 0; dg < 4; dg++) { - var a = head + Math.PI * 0.25 + dg * Math.PI * 0.5; - var lx = Math.sin(a), lz = Math.cos(a); - pxs = cx + lx * LM_PAD; pzs = cz + lz * LM_PAD; - - var sl = strutLum * (0.60 + 0.40 * faceSun(lx, lz)); - - var gl = G_PIPE; - if (project(cx + lx * LM_ATT, LM_ATY, cz + lz * LM_ATT)) { - var gx0 = PJ.x, gy0 = PJ.y; - if (project(pxs, 0.20, pzs)) { - var gdx = PJ.x - gx0, gdy = PJ.y - gy0; - var agx = gdx < 0 ? -gdx : gdx, agy = gdy < 0 ? -gdy : gdy; - gl = agx > agy * 1.7 ? G_UNDER - : (agy > agx * 1.7 ? G_PIPE : (gdx * gdy > 0 ? G_BACK : G_SLASH)); - } - } - - run(f, cx + lx * LM_ATT, LM_ATY, cz + lz * LM_ATT, pxs, 0.20, pzs, - gl, P.pure, sl, 12, thick); - run(f, cx + lx * LM_ATT, LM_ATY - 0.08, cz + lz * LM_ATT, pxs, 0.12, pzs, - 0, P.shadow, 0, 12, 1); - run(f, cx + lx * (LM_ATT + 0.15), LM_D1 - 0.55, cz + lz * (LM_ATT + 0.15), - cx + lx * (LM_PAD * 0.62), 0.55, cz + lz * (LM_PAD * 0.62), - G_SLASH, P.pure, sl * 0.8, 10, 0); - - run(f, pxs - lz * 0.47, 0.12, pzs + lx * 0.47, pxs + lz * 0.47, 0.12, pzs - lx * 0.47, - G_UNDER, P.pure, rimLum(0.7), 6, 0); - run(f, pxs - lz * 0.47, 0.02, pzs + lx * 0.47, pxs + lz * 0.47, 0.02, pzs - lx * 0.47, - 0, P.shadow, 0, 6, 1); - - if (dg !== 1 && w < 46) - run(f, pxs, 0.20, pzs, pxs + lx * 0.5, 0.02, pzs + lz * 0.5, G_DOT, P.pure, - rimLum(0.2), 4, 0); - } - - for (s = 0; s < 4; s++) { - nx = (s === 0 ? fx : (s === 1 ? rx : (s === 2 ? -fx : -rx))); - nz = (s === 0 ? fz : (s === 1 ? rz : (s === 2 ? -fz : -rz))); - var ux = -nz, uz = nx; - ax = cx + nx * LM_AHW - ux * LM_AHW; az = cz + nz * LM_AHW - uz * LM_AHW; - bx = cx + nx * LM_AHW + ux * LM_AHW; bz = cz + nz * LM_AHW + uz * LM_AHW; - var look = LOOK_BODY; - if (s === 0) { - - WIN_U = LM_AHW * 0.62; WIN_V = LM_D1 + 0.95; WIN_W = 0.66; WIN_H = 0.54; - look = LOOK_WIN; - } - var asun = faceSun(nx, nz); - quad(f, ax, az, bx, bz, LM_D1, LM_A1, look, BASE + 0xA0 + s, asun); - if (asun > 0.02) - run(f, ax, LM_A1, az, bx, LM_A1, bz, G_EQ, P.pure, rimLum(1) * asun, 12, 0); - } - - quad(f, cx - rx * 0.78 - fx * 0.3, cz - rz * 0.78 - fz * 0.3, - cx + rx * 0.78 - fx * 0.3, cz + rz * 0.78 - fz * 0.3, LM_A1, LM_A1 + 0.48, - LOOK_BODY, BASE + 0xA8, faceSun(-fx, -fz)); - - column(f, cx + fx * 0.35, cz + fz * 0.35, LM_A1, LM_A1 + 1.05, G_PIPE, P.pure, rimLum(0.5), 0); - disc(f, cx + fx * 0.35, LM_A1 + 1.28, cz + fz * 0.35, 0.36, 1, G_0, P.pure, rimLum(0.9)); - column(f, cx - rx * 0.95, cz - rz * 0.95, LM_A1 - 0.2, LM_A1 + 0.72, G_PIPE, P.pure, - rimLum(0.35), 0); - - if (w < 40 && project(cx + fx * LM_AHW - rx * 0.55, LM_D1 + 1.62, cz + fz * LM_AHW - rz * 0.55)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_PLUS, P.pure, - rimLum(1) * faceSun(fx, fz), PJ.d); - - if (w < 55) { - var lax = cx + fx * (LM_PAD * 0.72), laz = cz + fz * (LM_PAD * 0.72); - var lbx = cx + fx * LM_ATT, lbz = cz + fz * LM_ATT; - var rungs = 9, ri; - for (ri = 0; ri <= rungs; ri++) { - var u = ri / rungs; - var px2 = lax + (lbx - lax) * u, pz2 = laz + (lbz - laz) * u; - var py2 = 0.30 + u * (LM_D0 + 0.42 - 0.30); - run(f, px2 - rx * 0.24, py2, pz2 - rz * 0.24, px2 + rx * 0.24, py2, pz2 + rz * 0.24, - G_DASH, P.pure, rimLum(0.5), 3); - } - - run(f, lbx - rx * 0.45, LM_D0 + 0.44, lbz - rz * 0.45, lbx + rx * 0.45, LM_D0 + 0.44, - lbz + rz * 0.45, G_EQ, P.pure, rimLum(0.9), 5); - } + var si; + for (si = -1; si <= 1; si += 2) { + var sxp = px + rx * 0.42 * si + fx * 0.15, szp = pz + rz * 0.42 * si + fz * 0.15; + quad(f, sxp - fx * 0.28, szp - fz * 0.28, sxp + fx * 0.28, szp + fz * 0.28, + RV_DECK, RV_SEAT, LOOK_MASS, BASE + 0xC5); + run(f, sxp - fx * 0.28, RV_SEAT, szp - fz * 0.28, sxp + fx * 0.28, RV_SEAT, + szp + fz * 0.28, G_DASH, P.pure, rimLum(0.6), 4); } - var FLAG_Y0 = 1.42, FLAG_Y1 = 2.33, FLAG_W = 1.52, FLAG_POLE = 2.45; - - function drawFlag(f, k) { - var cx = sX[k], cz = sZ[k]; - - var b = Math.atan2(KX, KZ) + 1.15 + hash2(k, 2, BASE + 0xB0) * 0.5; - var px = cx + Math.sin(b) * 9.6, pz = cz + Math.cos(b) * 9.6; - var w = seeAt(px, pz, 1.0); - if (!w) return; - - var fb = Math.atan2(KX, KZ) + Math.PI * 0.5; - var ex = Math.sin(fb), ez = Math.cos(fb); - - shadowPatch(f, px, pz, 0.5, 0.9, FLAG_POLE, BASE + 0xB1); - - column(f, px, pz, 0, FLAG_POLE, G_PIPE, P.pure, rimLum(0.6), 0); - - var i, r; - var ax = px, az = pz, bx = px + ex * FLAG_W, bz = pz + ez * FLAG_W; - var n = Math.ceil(FLAG_W * V.colK / w) + 2; - if (n > 90) n = 90; - var redLum = (KDAY * 214 + KNIGHT * 96) * (1 + 0.10 * KMIX); - for (i = 0; i <= n; i++) { - var u = i / n; - if (!project(ax + (bx - ax) * u, FLAG_Y0, az + (bz - az) * u)) continue; - var x = Math.floor(PJ.x), yb = PJ.y, d = PJ.d; - if (!project(ax + (bx - ax) * u, FLAG_Y1, az + (bz - az) * u)) continue; - var yt = PJ.y; - if (yt > yb) { var sw = yt; yt = yb; yb = sw; } - var r0 = Math.floor(yt), r1 = Math.floor(yb), span = (yb - yt) || 1e-4; - if (r1 - r0 > 24) r1 = r0 + 24; - for (r = r0; r <= r1; r++) { - var band = Math.floor(((yb - r) / span) * 3); - if (band < 0) band = 0; - if (band > 2) band = 2; - - if (band === 1) emit(f, x, r, G_HASH, P.pure, rimLum(0.9), d); - else emit(f, x, r, G_HASH, P.red, redLum, d); - } - } - - run(f, ax, FLAG_Y1, az, bx, FLAG_Y1, bz, G_DASH, P.pure, rimLum(1), 10); + var wi, wj; + for (wi = -1; wi <= 1; wi += 2) for (wj = -1; wj <= 1; wj += 2) { + var wxp = px + fx * (RV_LEN * 0.375) * wi + rx * RV_TRK * 0.5 * wj; + var wzp = pz + fz * (RV_LEN * 0.375) * wi + rz * RV_TRK * 0.5 * wj; + disc(f, wxp, RV_WH, wzp, RV_WH, 1, w < 16 ? G_O : G_o, P.pure, rimLum(0.5)); } - var RV_LEN = 3.05, RV_TRK = 1.03, RV_WH = 0.41, RV_DECK = 0.62, RV_SEAT = 1.14; + var mx = px - fx * (RV_LEN * 0.42), mz = pz - fz * (RV_LEN * 0.42); + column(f, mx, mz, RV_DECK, 1.62, G_PIPE, P.pure, rimLum(0.4), 0); + var dr = 0.455; - function hasRover(k) { return hash2(k, 3, BASE + 0xC0) < 0.58; } + var eb = MOON ? MOON.EARTH_AZ : 0.28; + var dxp = mx + Math.sin(eb) * 0.22, dzp = mz + Math.cos(eb) * 0.22; + disc(f, dxp, 1.62 + dr * 0.7, dzp, dr, 1, G_0, P.pure, rimLum(0.3)); + var ph = CC.reducedMotion ? 1.1 : V.t * 0.185; + if (project(dxp + Math.cos(ph) * dr * 0.9, 1.62 + dr * 0.7 + Math.sin(ph) * dr * 0.9, dzp)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_STAR, P.pure, rimLum(1.0), PJ.d); + } - function drawRover(f, k) { - var cx = sX[k], cz = sZ[k]; - var b = Math.atan2(KX, KZ) - 0.85 - hash2(k, 4, BASE + 0xC1) * 0.6; - var px = cx + Math.sin(b) * 24.0, pz = cz + Math.cos(b) * 24.0; - var w = seeAt(px, pz, 1.0); - if (!w) return; + var TRK_LEN = 52.0; - var hd = Math.atan2(KX, KZ) + 1.35 + (hash2(k, 5, BASE + 0xC2) - 0.5) * 0.7; - var fx = Math.sin(hd), fz = Math.cos(hd); - var rx = Math.cos(hd), rz = -Math.sin(hd); + function drawTracks(f, px, pz, fx, fz, rx, rz, k) { - drawTracks(f, px, pz, fx, fz, rx, rz, k); - shadowPatch(f, px, pz, 1.8, 0.9, RV_SEAT + 0.5, BASE + 0xC3); + var bend = (hash2(k, 6, BASE + 0xC8) - 0.5) * 0.9; + var side, seg; + var N = 13; + for (side = -1; side <= 1; side += 2) { + var lx = -1, ly = 0, ld = 0; + for (seg = 0; seg <= N; seg++) { + var u = seg / N, s2 = u * TRK_LEN; + var a = bend * u * u; + var dx2 = fx * Math.cos(a) + rx * Math.sin(a), dz2 = fz * Math.cos(a) + rz * Math.sin(a); + var qx = px + dx2 * s2 + (rx * Math.cos(a) - fx * Math.sin(a)) * RV_TRK * 0.5 * side; + var qz = pz + dz2 * s2 + (rz * Math.cos(a) - fz * Math.sin(a)) * RV_TRK * 0.5 * side; + if (!project(qx, 0.03, qz)) { lx = -1; continue; } + var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d; - var hx = fx * RV_LEN * 0.5, hz = fz * RV_LEN * 0.5; - quad(f, px - hx, pz - hz, px + hx, pz + hz, 0.50, RV_DECK, LOOK_MASS, BASE + 0xC4); - run(f, px - hx, RV_DECK, pz - hz, px + hx, RV_DECK, pz + hz, G_EQ, P.pure, rimLum(0.8), 10); + var fv = hash2(seg, side + 2, BASE + 0xC9); + var far = d >= 40 || (d > 26 && fv > (40 - d) / 14); + var col = far ? P.pure : P.white; + var lum = far ? ((96 + d * 0.62) * KDAY + (70 + d * 0.62) * KNIGHT * 0.7) : bodyLum(0.35); + if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1; + if (lx >= 0) { + var ddx = x - lx, ddy = r - ly; + var st = Math.abs(ddx) > Math.abs(ddy) ? Math.abs(ddx) : Math.abs(ddy); + if (st > V.cols * 2) st = 0; + for (var qq = 1; qq < st; qq++) { + var tq = qq / st; - var si; - for (si = -1; si <= 1; si += 2) { - var sxp = px + rx * 0.42 * si + fx * 0.15, szp = pz + rz * 0.42 * si + fz * 0.15; - quad(f, sxp - fx * 0.28, szp - fz * 0.28, sxp + fx * 0.28, szp + fz * 0.28, - RV_DECK, RV_SEAT, LOOK_MASS, BASE + 0xC5); - run(f, sxp - fx * 0.28, RV_SEAT, szp - fz * 0.28, sxp + fx * 0.28, RV_SEAT, - szp + fz * 0.28, G_DASH, P.pure, rimLum(0.6), 4); + emit(f, lx + Math.round(ddx * tq), ly + Math.round(ddy * tq), + (qq & 1) ? G_EQ : G_DASH, col, lum, ld + (d - ld) * tq); + } } + emit(f, x, r, G_EQ, col, lum, d); + lx = x; ly = r; ld = d; + } + } + } - var wi, wj; - for (wi = -1; wi <= 1; wi += 2) for (wj = -1; wj <= 1; wj += 2) { - var wxp = px + fx * (RV_LEN * 0.375) * wi + rx * RV_TRK * 0.5 * wj; - var wzp = pz + fz * (RV_LEN * 0.375) * wi + rz * RV_TRK * 0.5 * wj; - disc(f, wxp, RV_WH, wzp, RV_WH, 1, w < 16 ? G_O : G_o, P.pure, rimLum(0.5)); - } + function drawStation(f, k) { + var cx = sX[k], cz = sZ[k]; + var b = LAY_AZ - 1.42 + (hash2(k, 12, BASE + 0xF0) - 0.5) * 0.8; + var rng = 12 + hash2(k, 13, BASE + 0xF1) * 10; + var wx = cx + Math.sin(b) * rng, wz = cz + Math.cos(b) * rng; + var w = seeAt(wx, wz, 0.6); + if (!w) return; + var rx = Math.cos(b), rz = -Math.sin(b), fx = Math.sin(b), fz = Math.cos(b); - var mx = px - fx * (RV_LEN * 0.42), mz = pz - fz * (RV_LEN * 0.42); - column(f, mx, mz, RV_DECK, 1.62, G_PIPE, P.pure, rimLum(0.4), 0); - var dr = 0.455; + shadowPatch(f, wx, wz, 0.16, 0.30, 0.46, BASE + 0xF2); + column(f, wx, wz, 0.06, 0.46, G_PIPE, P.pure, rimLum(0.9), 0); - var eb = MOON ? MOON.EARTH_AZ : 0.28; - var dxp = mx + Math.sin(eb) * 0.22, dzp = mz + Math.cos(eb) * 0.22; - disc(f, dxp, 1.62 + dr * 0.7, dzp, dr, 1, G_0, P.pure, rimLum(0.3)); - var ph = CC.reducedMotion ? 1.1 : V.t * 0.185; - if (project(dxp + Math.cos(ph) * dr * 0.9, 1.62 + dr * 0.7 + Math.sin(ph) * dr * 0.9, dzp)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_STAR, P.pure, rimLum(1.0), PJ.d); + if (w < 30 && project(wx, 0.10, wz)) { + var kc = w < 22 ? 1 : (30 - w) / 8; + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, P.ember, + (KDAY * 176 + KNIGHT * 76) * kc, PJ.d); } - var TRK_LEN = 52.0; + var tx = wx + rx * 1.9 - fx * 0.7, tz = wz + rz * 1.9 - fz * 0.7; + shadowPatch(f, tx, tz, 0.10, 0.22, 0.40, BASE + 0xF3); + column(f, tx, tz, 0.0, 0.40, G_PIPE, P.pure, rimLum(0.6), 0); - function drawTracks(f, px, pz, fx, fz, rx, rz, k) { + var s, sx2, sz2; + for (s = 0; s < 3; s++) { + var ha = hash2(k * 5 + s, 14, BASE + 0xF4), hb = hash2(k * 5 + s, 15, BASE + 0xF5); + sx2 = wx + (ha - 0.5) * 5.2 + rx * 0.6; + sz2 = wz + (hb - 0.5) * 5.2 + rz * 0.6; + if (project(sx2, 0.11, sz2)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), s === 2 ? G_o : G_8, + P.pure, rimLum(0.3 + 0.5 * ha), PJ.d); + shadowPatch(f, sx2, sz2, 0.09, 0.16, 0.20, BASE + 0xF6 + s); + } + } - var bend = (hash2(k, 6, BASE + 0xC8) - 0.5) * 0.9; - var side, seg; - var N = 13; - for (side = -1; side <= 1; side += 2) { - var lx = -1, ly = 0, ld = 0; - for (seg = 0; seg <= N; seg++) { - var u = seg / N, s2 = u * TRK_LEN; - var a = bend * u * u; - var dx2 = fx * Math.cos(a) + rx * Math.sin(a), dz2 = fz * Math.cos(a) + rz * Math.sin(a); - var qx = px + dx2 * s2 + (rx * Math.cos(a) - fx * Math.sin(a)) * RV_TRK * 0.5 * side; - var qz = pz + dz2 * s2 + (rz * Math.cos(a) - fz * Math.sin(a)) * RV_TRK * 0.5 * side; - if (!project(qx, 0.03, qz)) { lx = -1; continue; } - var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d; + var ALSEP_N = 3; - var fv = hash2(seg, side + 2, BASE + 0xC9); - var far = d >= 40 || (d > 26 && fv > (40 - d) / 14); - var col = far ? P.pure : P.white; - var lum = far ? ((96 + d * 0.62) * KDAY + (70 + d * 0.62) * KNIGHT * 0.7) : bodyLum(0.35); - if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1; - if (lx >= 0) { - var ddx = x - lx, ddy = r - ly; - var st = Math.abs(ddx) > Math.abs(ddy) ? Math.abs(ddx) : Math.abs(ddy); - if (st > V.cols * 2) st = 0; - for (var qq = 1; qq < st; qq++) { - var tq = qq / st; + function drawALSEP(f, k) { + var cx = sX[k], cz = sZ[k]; - emit(f, lx + Math.round(ddx * tq), ly + Math.round(ddy * tq), - (qq & 1) ? G_EQ : G_DASH, col, lum, ld + (d - ld) * tq); - } - } - emit(f, x, r, G_EQ, col, lum, d); - lx = x; ly = r; ld = d; - } - } + var b = LAY_AZ + Math.PI + 0.55 + (hash2(k, 7, BASE + 0xD0) - 0.5) * 0.9; + var rng = 34 + hash2(k, 8, BASE + 0xD1) * 18; + var stx = cx + Math.sin(b) * rng, stz = cz + Math.cos(b) * rng; + + var w = seeAt(stx, stz, 1.0); + if (w) { + shadowPatch(f, stx, stz, 0.7, 0.4, 1.2, BASE + 0xD2); + quad(f, stx - 0.3, stz - 0.3, stx + 0.3, stz + 0.3, 0.05, 0.62, LOOK_MASS, BASE + 0xD3); + run(f, stx - 0.34, 0.62, stz - 0.34, stx + 0.34, 0.62, stz + 0.34, G_DASH, P.pure, + rimLum(0.8), 4); + column(f, stx, stz, 0.62, 1.24, G_PIPE, P.pure, rimLum(0.5), 0); + + if (project(stx - 0.42, 0.66, stz)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_CARET, P.amber, foilLum(0.7), PJ.d); + if (project(stx + 0.42, 0.66, stz)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_CARET, P.amber, foilLum(0.4), PJ.d); } - var ALSEP_N = 3; + var e; + for (e = 0; e < ALSEP_N; e++) { + if (e === 2 && hash2(k, 9, BASE + 0xD4) > 0.6) continue; + var eb = hash2(k, 20 + e, BASE + 0xD5) * 6.2831853; + var er = 9 + hash2(k, 30 + e, BASE + 0xD6) * 10; + var ex = stx + Math.sin(eb) * er, ez = stz + Math.cos(eb) * er; + var ew = seeAt(ex, ez, 1.0); - function drawALSEP(f, k) { - var cx = sX[k], cz = sZ[k]; - - var b = Math.atan2(KX, KZ) + Math.PI + 0.55 + (hash2(k, 7, BASE + 0xD0) - 0.5) * 0.9; - var rng = 34 + hash2(k, 8, BASE + 0xD1) * 18; - var stx = cx + Math.sin(b) * rng, stz = cz + Math.cos(b) * rng; - - var w = seeAt(stx, stz, 1.0); - if (w) { - shadowPatch(f, stx, stz, 0.7, 0.4, 1.2, BASE + 0xD2); - quad(f, stx - 0.3, stz - 0.3, stx + 0.3, stz + 0.3, 0.05, 0.62, LOOK_MASS, BASE + 0xD3); - run(f, stx - 0.34, 0.62, stz - 0.34, stx + 0.34, 0.62, stz + 0.34, G_DASH, P.pure, - rimLum(0.8), 4); - column(f, stx, stz, 0.62, 1.24, G_PIPE, P.pure, rimLum(0.5), 0); - - if (project(stx - 0.42, 0.66, stz)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_CARET, P.amber, foilLum(0.7), PJ.d); - if (project(stx + 0.42, 0.66, stz)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_CARET, P.amber, foilLum(0.4), PJ.d); - } - - var e; - for (e = 0; e < ALSEP_N; e++) { - if (e === 2 && hash2(k, 9, BASE + 0xD4) > 0.6) continue; - var eb = hash2(k, 20 + e, BASE + 0xD5) * 6.2831853; - var er = 9 + hash2(k, 30 + e, BASE + 0xD6) * 10; - var ex = stx + Math.sin(eb) * er, ez = stz + Math.cos(eb) * er; - var ew = seeAt(ex, ez, 1.0); - - if (w || ew) - run(f, stx, 0.02, stz, ex, 0.02, ez, G_DOT, P.white, bodyLum(0.15), 26); - if (!ew) continue; - shadowPatch(f, ex, ez, 0.45, 0.3, 0.7, BASE + 0xD7 + e); - quad(f, ex - 0.22, ez - 0.22, ex + 0.22, ez + 0.22, 0.03, 0.38, LOOK_MASS, BASE + 0xDA + e); - run(f, ex - 0.26, 0.38, ez - 0.26, ex + 0.26, 0.38, ez + 0.26, G_DASH, P.pure, - rimLum(0.7), 3); - } - - run(f, stx, 0.02, stz, cx + Math.sin(b) * 4.2, 0.02, cz + Math.cos(b) * 4.2, - G_DOT, P.white, bodyLum(0.25), 34); - - drawRetro(f, k, cx, cz); - drawTV(f, k, cx, cz); + if (w || ew) + run(f, stx, 0.02, stz, ex, 0.02, ez, G_DOT, P.white, bodyLum(0.15), 26); + if (!ew) continue; + shadowPatch(f, ex, ez, 0.45, 0.3, 0.7, BASE + 0xD7 + e); + quad(f, ex - 0.22, ez - 0.22, ex + 0.22, ez + 0.22, 0.03, 0.38, LOOK_MASS, BASE + 0xDA + e); + run(f, ex - 0.26, 0.38, ez - 0.26, ex + 0.26, 0.38, ez + 0.26, G_DASH, P.pure, + rimLum(0.7), 3); } - function drawRetro(f, k, cx, cz) { - var b = Math.atan2(KX, KZ) + 2.35 + (hash2(k, 10, BASE + 0xE0) - 0.5) * 0.7; - var px = cx + Math.sin(b) * 17.0, pz = cz + Math.cos(b) * 17.0; - var w = seeAt(px, pz, 1.0); - if (!w) return; - var eaz = MOON ? MOON.EARTH_AZ : 0.28; - var saz = Math.atan2(KX, KZ); - var flare = 2 * eaz - saz; + run(f, stx, 0.02, stz, cx + Math.sin(b) * 4.2, 0.02, cz + Math.cos(b) * 4.2, + G_DOT, P.white, bodyLum(0.25), 34); - var vb = Math.atan2(V.ox - px, V.oz - pz); - var da = vb - flare; - da = Math.atan2(Math.sin(da), Math.cos(da)); - var kk = 1 - clamp((da < 0 ? -da : da) / 0.42, 0, 1); - kk = kk * kk * (3 - 2 * kk); + drawRetro(f, k, cx, cz); + drawTV(f, k, cx, cz); + } - shadowPatch(f, px, pz, 0.4, 0.25, 0.5, BASE + 0xE1); - if (!project(px, 0.26, pz)) return; - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), kk > 0.55 ? G_STAR : G_EQ, P.pure, - 14 + kk * kk * (rimLum(1) - 14), PJ.d); + function drawRetro(f, k, cx, cz) { + var b = LAY_AZ + 2.35 + (hash2(k, 10, BASE + 0xE0) - 0.5) * 0.7; + var px = cx + Math.sin(b) * 17.0, pz = cz + Math.cos(b) * 17.0; + var w = seeAt(px, pz, 1.0); + if (!w) return; + var eaz = MOON ? MOON.EARTH_AZ : 0.28; + var saz = Math.atan2(KX, KZ); + var flare = 2 * eaz - saz; + + var vb = Math.atan2(V.ox - px, V.oz - pz); + var da = vb - flare; + da = Math.atan2(Math.sin(da), Math.cos(da)); + var kk = 1 - clamp((da < 0 ? -da : da) / 0.42, 0, 1); + kk = kk * kk * (3 - 2 * kk); + + shadowPatch(f, px, pz, 0.4, 0.25, 0.5, BASE + 0xE1); + if (!project(px, 0.26, pz)) return; + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), kk > 0.55 ? G_STAR : G_EQ, P.pure, + 14 + kk * kk * (rimLum(1) - 14), PJ.d); + } + + function drawTV(f, k, cx, cz) { + var b = LAY_AZ - 1.9 + (hash2(k, 11, BASE + 0xE8) - 0.5) * 0.6; + var px = cx + Math.sin(b) * 14.0, pz = cz + Math.cos(b) * 14.0; + var w = seeAt(px, pz, 1.0); + if (!w) return; + shadowPatch(f, px, pz, 0.6, 0.35, 1.35, BASE + 0xE9); + + var li; + for (li = 0; li < 3; li++) { + var a = b + li * 2.0944; + run(f, px, 1.28, pz, px + Math.sin(a) * 0.5, 0.02, pz + Math.cos(a) * 0.5, + li === 1 ? G_PIPE : (li === 0 ? G_SLASH : G_BACK), P.pure, rimLum(0.45), 5); } + quad(f, px - 0.16, pz - 0.16, px + 0.16, pz + 0.16, 1.28, 1.62, LOOK_MASS, BASE + 0xEA); - function drawTV(f, k, cx, cz) { - var b = Math.atan2(KX, KZ) - 1.9 + (hash2(k, 11, BASE + 0xE8) - 0.5) * 0.6; - var px = cx + Math.sin(b) * 14.0, pz = cz + Math.cos(b) * 14.0; - var w = seeAt(px, pz, 1.0); - if (!w) return; - shadowPatch(f, px, pz, 0.6, 0.35, 1.35, BASE + 0xE9); + var tox = cx - px, toz = cz - pz, tl = Math.sqrt(tox * tox + toz * toz) || 1; + if (project(px + (tox / tl) * 0.18, 1.5, pz + (toz / tl) * 0.18)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_o, P.ice, KDAY * 178 + KNIGHT * 74, PJ.d); + } - var li; - for (li = 0; li < 3; li++) { - var a = b + li * 2.0944; - run(f, px, 1.28, pz, px + Math.sin(a) * 0.5, 0.02, pz + Math.cos(a) * 0.5, - li === 1 ? G_PIPE : (li === 0 ? G_SLASH : G_BACK), P.pure, rimLum(0.45), 5); - } - quad(f, px - 0.16, pz - 0.16, px + 0.16, pz + 0.16, 1.28, 1.62, LOOK_MASS, BASE + 0xEA); + function each(f, fn) { + var i; + for (i = 0; i < sN; i++) { - var tox = cx - px, toz = cz - pz, tl = Math.sqrt(tox * tox + toz * toz) || 1; - if (project(px + (tox / tl) * 0.18, 1.5, pz + (toz / tl) * 0.18)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_o, P.ice, KDAY * 178 + KNIGHT * 74, PJ.d); + if (near2(sX[i], sZ[i], V.ox, V.oz) > 205 * 205) continue; + fn(f, i); } + } - function each(f, fn) { - var i; - for (i = 0; i < sN; i++) { + function mk(name, layer, fn) { + return { + name: name, layer: layer, world: 'moon', + init: function (city) { boot(city); }, + draw: function (f, cam, t) { + if (!CITY || !sN) return; + PR.view(f, cam, t === undefined ? (cam.t || 0) : t); + key(); + if (!MOON) return; + each(f, fn); + } + }; + } - if (near2(sX[i], sZ[i], V.ox, V.oz) > 205 * 205) continue; - fn(f, i); - } - } - - function mk(name, layer, fn) { - return { - name: name, layer: layer, world: 'moon', - init: function (city) { boot(city); }, - draw: function (f, cam, t) { - if (!CITY || !sN) return; - PR.view(f, cam, t === undefined ? (cam.t || 0) : t); - key(); - if (!MOON) return; - each(f, fn); - } - }; - } - - CC.ELEMENTS.push(mk('moon-alsep', 19, drawALSEP)); - CC.ELEMENTS.push(mk('moon-flag', 20, drawFlag)); - CC.ELEMENTS.push(mk('moon-rover', 21, function (f, k) { if (hasRover(k)) drawRover(f, k); })); - CC.ELEMENTS.push(mk('moon-lm', 21, drawLM)); + CC.ELEMENTS.push(mk('moon-station', 18, drawStation)); + CC.ELEMENTS.push(mk('moon-alsep', 19, drawALSEP)); + CC.ELEMENTS.push(mk('moon-flag', 20, drawFlag)); + CC.ELEMENTS.push(mk('moon-rover', 21, function (f, k) { if (hasRover(k)) drawRover(f, k); })); + CC.ELEMENTS.push(mk('moon-lm', 21, drawLM)); })(CC); /* src/elements/moon_ground.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, put = CC.put, hash1 = CC.hash1, hash2 = CC.hash2, clamp = CC.clamp; + var P = CC.P, g = CC.g, put = CC.put, hash1 = CC.hash1, hash2 = CC.hash2, clamp = CC.clamp; - var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), - G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_PLUS = g('+'), - G_STAR = g('*'), G_HASH = g('#'), G_PCT = g('%'), G_8 = g('8'), G_O = g('O'), G_o = g('o'), - G_X = g('X'), G_AT = g('@'); + var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), + G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_PLUS = g('+'), + G_STAR = g('*'), G_HASH = g('#'), G_PCT = g('%'), G_8 = g('8'), G_O = g('O'), G_o = g('o'), + G_X = g('X'), G_AT = g('@'); - var D_STAR = 1.00e5, D_RIDGE = 9.2e4, D_EARTH = 8.4e4, D_SUN = 8.0e4; + var D_STAR = 1.00e5, D_RIDGE = 9.2e4, D_EARTH = 8.4e4, D_SUN = 8.0e4; - var CITY = null, BASE = 0, Surf = null, MOON = null; - function boot(city) { - CITY = (city && city.aveX && city.world === 'moon') ? city : null; + var CITY = null, BASE = 0, Surf = null, MOON = null; + function boot(city) { + CITY = (city && city.aveX && city.world === 'moon') ? city : null; - BASE = CITY ? ((Math.imul(CITY.seed | 0, 40507) >>> 6) & 0x3fffff) : 0; + BASE = CITY ? ((Math.imul(CITY.seed | 0, 40507) >>> 6) & 0x3fffff) : 0; + } + + var V = { + cols: 0, rows: 0, half: 0.7265, colK: 0, colMid: 0, scale: 77, horizon: 33, eyeY: 1.7, + fwx: 0, fwz: 1, rgx: 1, rgz: 0, ox: 0, oz: 0, yaw: 0, far: 240 + }; + + function view(f, cam) { + if (!Surf) { Surf = CC.Surf; MOON = CC.SurfMoon; } + var fov = cam.fov || 1.25; + V.half = Math.tan(fov * 0.5); + V.cols = f.cols; V.rows = f.rows; + V.colK = f.cols * 0.5 / V.half; V.colMid = f.cols * 0.5; + V.scale = cam.scaleY !== undefined ? cam.scaleY : (f.cols * (cam.cellAspect || 0.5625)) / (2 * V.half); + V.horizon = cam.horizon !== undefined ? cam.horizon : f.rows * 0.56; + V.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + V.yaw = cam.yaw || 0; + V.fwx = Math.sin(V.yaw); V.fwz = Math.cos(V.yaw); + V.rgx = Math.cos(V.yaw); V.rgz = -Math.sin(V.yaw); + V.ox = cam.x; V.oz = cam.z; + V.far = Surf ? Surf.FOG_END : 240; + } + + function sunAz() { return MOON ? MOON.SUN_AZ : Math.PI; } + function sunX() { return MOON ? MOON.SUN_X : Math.sin(Math.PI); } + function sunZ() { return MOON ? MOON.SUN_Z : Math.cos(Math.PI); } + function sunAlt() { return MOON ? MOON.SUN_ALT : 0.25; } + function night() { return MOON ? MOON.night : 0; } + function dayMix() { return CC.dayMix === undefined ? 0 : CC.dayMix; } + + var PJ = { x: 0, y: 0, d: 0, w: 0 }; + function project(px, py, pz) { + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < 0.40) return false; + var sp = (rx * V.rgx + rz * V.rgz) / w; + PJ.w = w; + PJ.d = w * Math.sqrt(1 + sp * sp); + PJ.x = sp * V.colK + V.colMid; + PJ.y = V.horizon - (py - V.eyeY) * V.scale / w; + return PJ.d < V.far; + } + + function emit(f, x, y, ch, col, lum, d) { + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + if (lum > 0 && Surf) { lum = Surf.fog(lum, d); if (lum <= 0) ch = 0; } + put(f, x, y, ch, col, lum, d, 3); + } + function plot(f, x, y, ch, col, lum, d) { + x = Math.round(x); y = Math.round(y); + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + put(f, x, y, ch, col, lum > 255 ? 255 : lum | 0, d, 3); + } + + var GP = { wx: 0, wz: 0, d: 0 }; + function groundAt(f, x, y, i) { + if (f.kind[i] !== 2) return false; + var d = f.dist[i]; + + if (!(d > 0.2) || d > 260) return false; + var sp = (2 * (x + 0.5) / V.cols - 1) * V.half; + var w = d / Math.sqrt(1 + sp * sp); + GP.wx = V.ox + (V.fwx + V.rgx * sp) * w; + GP.wz = V.oz + (V.fwz + V.rgz * sp) * w; + GP.d = d; + return true; + } + + var LC = { col: 0, lum: 0 }; + function litOf(base, dist, hv) { + var far = dist >= 40 || (dist > 24 && hv > (40 - dist) / 16); + var nt = night(); + var dark = nt > 0.5 || (nt > 0 && hv < nt); + if (!far) { + if (dark) { + LC.col = base > 0.72 ? P.pure : P.azure; + LC.lum = base > 0.72 ? 52 + 26 * base : 44 + 26 * base; + } else { + LC.col = P.white; LC.lum = (150 + 62 * base) * (1 - 0.20 * dayMix()); + } + return LC; + } + LC.col = dark ? P.azure : P.pure; + LC.lum = (dark ? (dist < 125 ? 70 + dist * 0.62 : 60) : (dist < 125 ? 96 + dist * 0.62 : 88)) * + (0.90 + 0.26 * base); + return LC; + } + + function specOf(base, dist) { + if (night() > 0.5) { LC.col = P.pure; LC.lum = 78 + 34 * base; return LC; } + LC.col = P.pure; LC.lum = dist < 125 ? 186 + 50 * base : 150 + 40 * base; + return LC; + } + + function softOf(edge) { return edge < 0.26 ? 0.24 + 2.923 * edge : 1; } + + var NH = 7; + + var HF = [3, 5, 8, 13, 21, 34, 55]; + var HA = [0, 0, 0, 0, 0, 0, 0], HP = [0, 0, 0, 0, 0, 0, 0]; + + var RIDGE_DC = 0.055, RIDGE_AMP = 0.140; + + function ridgeInit() { + var i, s = 0; + for (i = 0; i < NH; i++) { + HA[i] = (0.55 + 0.9 * hash1(BASE + i, 0x4DA0)) / Math.pow(HF[i], 0.35); s += HA[i]; + } + for (i = 0; i < NH; i++) { HA[i] *= RIDGE_AMP / s; HP[i] = hash1(BASE + i, 0x4DA1) * 6.2831853; } + } + function ridgeEl(b) { + var e = RIDGE_DC, i; + for (i = 0; i < NH; i++) e += HA[i] * Math.sin(HF[i] * b + HP[i]); + return e; + } + function ridgeSlope(b) { + var e = 0, i; + for (i = 0; i < NH; i++) e += HA[i] * HF[i] * Math.cos(HF[i] * b + HP[i]); + return e; + } + + function drawMassif(f) { + var y1 = Math.floor(V.horizon); if (y1 > V.rows) y1 = V.rows; + if (y1 <= 0) return; + var saz = sunAz(), x, y; + for (x = 0; x < V.cols; x++) { + var sp = (2 * (x + 0.5) / V.cols - 1) * V.half; + var bear = V.yaw + Math.atan(sp); + var el = ridgeEl(bear); + if (el <= 0.002) continue; + + var da = saz - bear - Math.atan(14.0 * ridgeSlope(bear)); + da = Math.atan2(Math.sin(da), Math.cos(da)); + var litK = clamp(0.5 - 2.2 * Math.cos(da), 0, 1); + var top = V.horizon - el * V.scale; + var span = V.horizon - top; + var y0 = Math.floor(top); if (y0 < 0) y0 = 0; + for (y = y0; y < y1; y++) { + + var elr = (V.horizon - y - 0.5) / V.scale; + var hv = hash2(Math.floor(bear * 900), Math.floor(elr * 4200), BASE + 0x4DA2); + var edge = litK - hv * 0.74; + var depth = (y - top) / (span + 1e-6); + var crest = y <= top + 1.0; + if (edge <= 0) { + + if (crest) plot(f, x, y, G_DOT, P.slate, 30 + hv * 22, D_RIDGE); + else if (hv > 0.93) plot(f, x, y, hv > 0.965 ? G_DOT : G_COMMA, P.slate, 18 + hv * 14, D_RIDGE); + else plot(f, x, y, 0, P.shadow, 0, D_RIDGE); + continue; + } + var soft = softOf(edge); + + var nt = night(); + var dk = nt > 0.5 || (nt > 0 && hv < nt); + var col = dk ? P.azure : P.pure, nk = dk ? 0.80 : 1; + if (crest) + + plot(f, x, y, hv < 0.4 ? G_DASH : G_EQ, col, (198 + 44 * hv) * nk * soft, D_RIDGE); + else if (hv < 0.66) + + plot(f, x, y, hv < 0.22 ? G_PCT : (hv < 0.44 ? G_HASH : G_8), col, + (58 + 40 * hv) * nk * (0.80 + 0.28 * (1 - depth)) * soft, D_RIDGE); + else + plot(f, x, y, 0, P.shadow, 0, D_RIDGE); + } + } + } + + var NSTAR = 90; + + function drawStars(f) { + var i; + for (i = 0; i < NSTAR; i++) { + var az = hash1(i, 0x4DB0) * 6.2831853; + + var hu = hash1(i, 0x4DB1); + var alt = 0.015 + hu * hu * hu * 0.62; + var ca = Math.cos(alt); + if (!projDir(Math.sin(az) * ca, Math.sin(alt), Math.cos(az) * ca)) continue; + var mag = hash1(i, 0x4DB2); + var x = VP.x, y = VP.y; + if (mag > 0.88) { + + plot(f, x, y, G_PLUS, P.pure, 244, D_STAR); + plot(f, x - 1, y, G_DASH, P.pure, 120, D_STAR); + plot(f, x + 1, y, G_DASH, P.pure, 120, D_STAR); + } else if (mag > 0.62) { + plot(f, x, y, G_STAR, P.pure, 176 + mag * 70, D_STAR); + } else { + + plot(f, x, y, G_DOT, P.white, (150 + mag * 64) * (1 - 0.22 * dayMix()), D_STAR); + } + } + } + + var VP = { x: 0, y: 0, w: 0 }; + function projDir(dx, dy, dz) { + var w = dx * V.fwx + dz * V.fwz; + if (w <= 0.02) return false; + var s = dx * V.rgx + dz * V.rgz; + VP.w = w; + VP.x = (s / w) * V.colK + V.colMid; + VP.y = V.horizon - (dy / w) * V.scale; + return true; + } + + var EARTH_R = 0.030; + + function drawEarth(f) { + var eaz = MOON ? MOON.EARTH_AZ : 0.28, ealt = MOON ? MOON.EARTH_ALT : 0.24; + var eca = Math.cos(ealt); + var ex = Math.sin(eaz) * eca, ey = Math.sin(ealt), ez = Math.cos(eaz) * eca; + if (!projDir(ex, ey, ez)) return; + var cx = VP.x, cy = VP.y, w = VP.w; + var rw = EARTH_R * V.colK / w, rh = EARTH_R * V.scale / w; + if (rw < 0.7) return; + + var salt = sunAlt(), sca = Math.cos(salt); + var sx = sunX() * sca, sy = Math.sin(salt), sz = sunZ() * sca; + + var cosPA = ex * sx + ey * sy + ez * sz; + var frac = clamp((1 - cosPA) * 0.5, 0.30, 0.96); + + var tx = sx - cosPA * ex, ty = sy - cosPA * ey, tz = sz - cosPA * ez; + var tn = Math.sqrt(tx * tx + ty * ty + tz * tz); + if (tn < 1e-5) { tx = 1; ty = 0; tz = 0; tn = 1; } + tx /= tn; ty /= tn; tz /= tn; + var lu = tx * V.rgx + tz * V.rgz, lv = -ty; + var ln = Math.sqrt(lu * lu + lv * lv); if (ln < 1e-5) { lu = 1; lv = 0; ln = 1; } + lu /= ln; lv /= ln; + + var sd = 0x4DC0; + var iw = Math.ceil(rw) + 1, ih = Math.ceil(rh) + 1, dx, dy; + for (dy = -ih; dy <= ih; dy++) { + for (dx = -iw; dx <= iw; dx++) { + var u = (Math.round(cx) + dx - cx) / rw, v = (Math.round(cy) + dy - cy) / rh; + var r2 = u * u + v * v; + if (r2 > 1.04) continue; + var px = Math.round(cx) + dx, py = Math.round(cy) + dy; + + var p = u * lu + v * lv, s = -u * lv + v * lu; + var ss = 1 - s * s; if (ss < 0) ss = 0; + var pt = (1 - 2 * frac) * Math.sqrt(ss); + var lit = p - pt; + if (lit <= 0) { + + if (r2 > 0.72 && hash2(px, py, sd ^ 0x11) < 0.13) + plot(f, px, py, G_DOT, P.slate, 24, D_EARTH); + else plot(f, px, py, 0, P.shadow, 0, D_EARTH); + continue; + } + + var soft = lit < 0.22 ? 0.30 + 3.18 * lit : 1; + var hb = hash2(Math.floor((u + 1) * 2.6), Math.floor((v + 1) * 2.6), sd); + var hf = hash2(px * 7, py * 13, sd ^ 0x22); + + var lam = 0.55 + 0.45 * Math.sqrt(clamp(1 - r2, 0, 1)); + if (hb < 0.45) { + + plot(f, px, py, hf < 0.4 ? G_AT : G_8, P.pure, (190 + 45 * hf) * lam * soft, D_EARTH); + } else if (hb < 0.82) { + + plot(f, px, py, hf < 0.5 ? G_O : G_o, P.azure, (96 + 34 * hf) * lam * soft, D_EARTH); + } else { + + plot(f, px, py, hf < 0.5 ? G_PCT : G_HASH, P.white, (150 + 32 * hf) * lam * soft, D_EARTH); + } + } + } + } + + var SUN_R = 0.00465; + + function drawSun(f) { + + var k = 1 - night(); + if (k <= 0.02) return; + var salt = sunAlt(), ca = Math.cos(salt); + if (!projDir(sunX() * ca, Math.sin(salt), sunZ() * ca)) return; + var cx = VP.x, cy = VP.y, w = VP.w; + var rw = SUN_R * V.colK / w, rh = SUN_R * V.scale / w; + + var wx2 = 2 * rw < 1 ? 2 * rw : 1, wy2 = 2 * rh < 1 ? 2 * rh : 1; + var iw = Math.ceil(rw) + 1, ih = Math.ceil(rh) + 1, dx, dy; + var x0 = Math.round(cx), y0 = Math.round(cy); + for (dy = -ih; dy <= ih; dy++) { + for (dx = -iw; dx <= iw; dx++) { + var px = x0 + dx, py = y0 + dy; + var ax = (px + 0.5 < cx + rw ? px + 0.5 : cx + rw) - (px - 0.5 > cx - rw ? px - 0.5 : cx - rw); + if (ax <= 0) continue; + var ay = (py + 0.5 < cy + rh ? py + 0.5 : cy + rh) - (py - 0.5 > cy - rh ? py - 0.5 : cy - rh); + if (ay <= 0) continue; + + var cov = clamp(1.8 * (ax / wx2) * (ay / wy2), 0, 1); + if (cov <= 0.02) continue; + plot(f, px, py, cov > 0.6 ? G_AT : (cov > 0.3 ? G_8 : G_o), P.pure, 255 * cov * k, D_SUN); + } + } + } + + var STRIDE = 0.72, PRINT_FAR = 72.0, PRINT_NEAR = 20.0; + var trailX0 = 0, trailZ0 = 0; + + function trailX(wz) { + return trailX0 + + (CC.vnoise(wz * 0.0222, BASE + 0x51) - 0.5) * 13.0 + + (CC.vnoise(wz * 0.0750, BASE + 0x52) - 0.5) * 4.0; + } + function trailZ(wx) { + return trailZ0 + + (CC.vnoise(wx * 0.0222, BASE + 0x53) - 0.5) * 13.0 + + (CC.vnoise(wx * 0.0750, BASE + 0x54) - 0.5) * 4.0; + } + + var Q_D = [4, 8, 14, 22, 34, 55, 90], Q_V = [60, 23, 12.5, 7.6, 4.9, 3.1, 1.9, 1.2]; + function qOf(dist) { + for (var i = 0; i < 7; i++) if (dist < Q_D[i]) return Q_V[i]; + return Q_V[7]; + } + + function walked(along, salt) { + return hash2(Math.floor(along / 9.4), 0, BASE + salt + 0x0A) < 0.58; + } + + function printAt(f, x, y, d, along, off, salt) { + if (!walked(along, salt)) return; + if (d > PRINT_NEAR) { + + if (off < -0.34 || off > 0.34) return; + var q = qOf(d); + var hc = hash2(Math.floor(along * q), Math.floor(off * 40), BASE + salt + 0x05); + if (hc > 0.66) return; + var lf = litOf(0.58 + hc * 0.42, d, hc); + emit(f, x, y, hc < 0.30 ? G_COLON : (hc < 0.5 ? G_DOT : G_SEMI), lf.col, lf.lum, d * 0.996); + return; + } + var sp = along / STRIDE, si = Math.floor(sp), fz = sp - si; + + var lat = off - ((si & 1) ? 0.19 : -0.19); + if (lat < 0) lat = -lat; + var hp = hash2(si, 0, BASE + salt + 0x06); + if (fz < 0.42 && lat < 0.13) { + + var hd = hash2(Math.floor(along * 40), Math.floor(off * 40), BASE + salt + 0x07); + if (hd < 0.09) emit(f, x, y, G_DOT, P.slate, 16 + hd * 110, d * 0.996); + else emit(f, x, y, 0, P.shadow, 0, d * 0.996); + return; + } + if (fz < 0.54 && lat < 0.21) { + + var lr = litOf(0.80 + hp * 0.20, d, hp); + emit(f, x, y, hp < 0.5 ? G_UNDER : G_DASH, lr.col, lr.lum, d * 0.996); + return; } - var V = { - cols: 0, rows: 0, half: 0.7265, colK: 0, colMid: 0, scale: 77, horizon: 33, eyeY: 1.7, - fwx: 0, fwz: 1, rgx: 1, rgz: 0, ox: 0, oz: 0, yaw: 0, far: 240 - }; - - function view(f, cam) { - if (!Surf) { Surf = CC.Surf; MOON = CC.SurfMoon; } - var fov = cam.fov || 1.25; - V.half = Math.tan(fov * 0.5); - V.cols = f.cols; V.rows = f.rows; - V.colK = f.cols * 0.5 / V.half; V.colMid = f.cols * 0.5; - V.scale = cam.scaleY !== undefined ? cam.scaleY : (f.cols * (cam.cellAspect || 0.5625)) / (2 * V.half); - V.horizon = cam.horizon !== undefined ? cam.horizon : f.rows * 0.56; - V.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - V.yaw = cam.yaw || 0; - V.fwx = Math.sin(V.yaw); V.fwz = Math.cos(V.yaw); - V.rgx = Math.cos(V.yaw); V.rgz = -Math.sin(V.yaw); - V.ox = cam.x; V.oz = cam.z; - V.far = Surf ? Surf.FOG_END : 240; + if (fz < 0.80 && lat < 0.36) { + var hs = hash2(Math.floor(along * 14), Math.floor(off * 14), BASE + salt + 0x08); + if (hs < 0.20) { + var ls = litOf(0.35 + hs, d, hs); + emit(f, x, y, G_DOT, ls.col, ls.lum * 0.8, d * 0.996); + } } + } - function sunAz() { return MOON ? MOON.SUN_AZ : Math.PI; } - function sunX() { return MOON ? MOON.SUN_X : Math.sin(Math.PI); } - function sunZ() { return MOON ? MOON.SUN_Z : Math.cos(Math.PI); } - function sunAlt() { return MOON ? MOON.SUN_ALT : 0.25; } - function night() { return MOON ? MOON.night : 0; } - function dayMix() { return CC.dayMix === undefined ? 0 : CC.dayMix; } + function drawPrints(f) { + var y0 = Math.floor(V.horizon); if (y0 < 0) y0 = 0; + var x, y; + for (y = y0; y < V.rows; y++) { + var row = y * V.cols; + for (x = 0; x < V.cols; x++) { + var i = row + x; + if (!groundAt(f, x, y, i)) continue; + var d = GP.d; + if (d > PRINT_FAR) continue; + + var o1 = GP.wx - trailX(GP.wz); + if (o1 > -0.8 && o1 < 0.8) { printAt(f, x, y, d, GP.wz, o1, 0x50); continue; } + var o2 = GP.wz - trailZ(GP.wx); + if (o2 > -0.8 && o2 < 0.8) { printAt(f, x, y, d, GP.wx, o2, 0x60); continue; } + millAt(f, x, y, d, GP.wx, GP.wz); + } + } + } + + var MILL_LAT = 34.0; + + function millAt(f, x, y, d, wx, wz) { + if (d > PRINT_NEAR) return; + var mi = Math.floor(wx / MILL_LAT), mj = Math.floor(wz / MILL_LAT); + var hm = hash2(mi, mj, BASE + 0x70); + if (hm > 0.26) return; + var cx = (mi + 0.2 + 0.6 * hash2(mi, mj, BASE + 0x72)) * MILL_LAT; + var cz = (mj + 0.2 + 0.6 * hash2(mi, mj, BASE + 0x73)) * MILL_LAT; + var rr = 1.6 + 2.8 * (hm / 0.26); + var dx = wx - cx, dz = wz - cz; + var rd = Math.sqrt(dx * dx + dz * dz); + if (rd > rr) return; + var k = 1 - rd / rr; + var hp = hash2(Math.floor(wx * 7), Math.floor(wz * 7), BASE + 0x74); + if (hp > 0.30 + 0.40 * k) return; + + if (hp < 0.09) { + emit(f, x, y, hp < 0.03 ? G_DOT : 0, P.slate, hp < 0.03 ? 20 + hp * 300 : 0, d * 0.996); + return; + } + var lm = litOf(0.72 + hp * 0.28, d, hp); + emit(f, x, y, hp < 0.19 ? G_UNDER : (hp < 0.26 ? G_COLON : G_DOT), lm.col, lm.lum, d * 0.996); + } + + var BLD_LAT = 4.2, BLD_R = 92.0, BLD_P = 0.46; + + function bldField(i, j) { + var qx = i / 9, qz = j / 9; + var i0 = Math.floor(qx), j0 = Math.floor(qz); + var fx = qx - i0, fz = qz - j0; + fx = fx * fx * (3 - 2 * fx); fz = fz * fz * (3 - 2 * fz); + var a = hash2(i0, j0, BASE + 0x6D), b = hash2(i0 + 1, j0, BASE + 0x6D), + c = hash2(i0, j0 + 1, BASE + 0x6D), d = hash2(i0 + 1, j0 + 1, BASE + 0x6D); + var ab = a + (b - a) * fx; + return 0.20 + 1.60 * (ab + ((c + (d - c) * fx) - ab) * fz); + } + + function drawBoulders(f) { + if (!CITY) return; + var lo0 = Math.floor((V.ox - BLD_R) / BLD_LAT), hi0 = Math.floor((V.ox + BLD_R) / BLD_LAT); + var lo1 = Math.floor((V.oz - BLD_R) / BLD_LAT), hi1 = Math.floor((V.oz + BLD_R) / BLD_LAT); + var i, j; + var salt = sunAlt(), tanA = Math.tan(salt), sinA = Math.sin(salt); + if (tanA < 0.02) tanA = 0.02; + if (sinA < 0.02) sinA = 0.02; + var sX = sunX(), sZ = sunZ(); + for (j = lo1; j <= hi1; j++) { + for (i = lo0; i <= hi0; i++) { + var h = hash2(i, j, BASE + 0x61); + + if (h > BLD_P * bldField(i, j)) continue; + var px = (i + 0.12 + 0.76 * hash2(i, j, BASE + 0x62)) * BLD_LAT; + var pz = (j + 0.12 + 0.76 * hash2(i, j, BASE + 0x63)) * BLD_LAT; - var PJ = { x: 0, y: 0, d: 0, w: 0 }; - function project(px, py, pz) { var rx = px - V.ox, rz = pz - V.oz; var w = rx * V.fwx + rz * V.fwz; - if (w < 0.40) return false; - var sp = (rx * V.rgx + rz * V.rgz) / w; - PJ.w = w; - PJ.d = w * Math.sqrt(1 + sp * sp); - PJ.x = sp * V.colK + V.colMid; - PJ.y = V.horizon - (py - V.eyeY) * V.scale / w; - return PJ.d < V.far; + if (w < 0.9 || w > BLD_R) continue; + + if (CITY.height(px, pz) > 0.1) continue; + + var hr = hash2(i, j, BASE + 0x64); + var r = 0.15 + hr * hr * hr * 1.35; + + var clr = 1.1 + 1.7 * r; + var ka = Math.round(px / CITY.AVE), kc = Math.round(pz / CITY.CROSS); + var da = px - (CITY.aveX(ka) + 0.5); if (da < 0) da = -da; + if (da < clr) continue; + var dc = pz - (CITY.crossZ(kc) + 0.5); if (dc < 0) dc = -dc; + if (dc < clr) continue; + + var fh = hash2(i, j, BASE + 0x6C); + var fw = 4.2 * (0.45 + 1.1 * CC.vnoise(pz * 0.023, BASE + 0x6A)); + if (da < clr + fw && fh > (da - clr) / fw) continue; + fw = 4.2 * (0.45 + 1.1 * CC.vnoise(px * 0.023, BASE + 0x6B)); + if (dc < clr + fw && fh > (dc - clr) / fw) continue; + + var sd = (BASE + i * 7919 + j * 104729) & 0x3fffff; + drawShadow(f, px, pz, r, sX, sZ, tanA, sinA, sd); + drawRock(f, px, pz, r, sX, sZ, sd); + } } + } - function emit(f, x, y, ch, col, lum, d) { - if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; - if (lum > 0 && Surf) { lum = Surf.fog(lum, d); if (lum <= 0) ch = 0; } - put(f, x, y, ch, col, lum, d, 3); - } - function plot(f, x, y, ch, col, lum, d) { - x = Math.round(x); y = Math.round(y); - if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; - put(f, x, y, ch, col, lum > 255 ? 255 : lum | 0, d, 3); + function drawShadow(f, px, pz, r, sX, sZ, tanA, sinA, sd) { + var ax = -sX, az = -sZ; + var L = 2 * r / tanA; + if (L > 44) L = 44; + var w0 = (px - V.ox) * V.fwx + (pz - V.oz) * V.fwz; + var aw = ax * V.fwx + az * V.fwz; + var s0 = 0, s1 = L; + if (aw > 1e-6) { var c0 = (0.6 - w0) / aw; if (c0 > s0) s0 = c0; } + else if (aw < -1e-6) { var c1 = (0.6 - w0) / aw; if (c1 < s1) s1 = c1; } + else if (w0 < 0.6) return; + if (s1 <= s0) return; + + var bx0 = 1e9, bx1 = -1e9, by0 = 1e9, by1 = -1e9, k, q; + var qx = -az, qz = ax; + for (k = 0; k <= 4; k++) { + var s = s0 + (s1 - s0) * (k / 4); + for (q = -1; q <= 1; q += 2) { + if (!project(px + ax * s + qx * r * q, 0, pz + az * s + qz * r * q)) continue; + if (PJ.x < bx0) bx0 = PJ.x; if (PJ.x > bx1) bx1 = PJ.x; + if (PJ.y < by0) by0 = PJ.y; if (PJ.y > by1) by1 = PJ.y; + } } + if (bx1 < bx0) return; + var X0 = Math.floor(bx0) - 2, X1 = Math.ceil(bx1) + 2; + var Y0 = Math.floor(by0) - 2, Y1 = Math.ceil(by1) + 2; + if (X0 < 0) X0 = 0; if (X1 >= V.cols) X1 = V.cols - 1; + if (Y0 < Math.floor(V.horizon)) Y0 = Math.floor(V.horizon); + if (Y0 < 0) Y0 = 0; + if (Y1 >= V.rows) Y1 = V.rows - 1; + if (X1 < X0 || Y1 < Y0) return; - var GP = { wx: 0, wz: 0, d: 0 }; - function groundAt(f, x, y, i) { - if (f.kind[i] !== 2) return false; - var d = f.dist[i]; + var hl = L * 0.5, mx = px + ax * hl, mz = pz + az * hl; - if (!(d > 0.2) || d > 260) return false; - var sp = (2 * (x + 0.5) / V.cols - 1) * V.half; - var w = d / Math.sqrt(1 + sp * sp); - GP.wx = V.ox + (V.fwx + V.rgx * sp) * w; - GP.wz = V.oz + (V.fwz + V.rgz * sp) * w; - GP.d = d; - return true; - } + var pen = 0.0093 * L / sinA; + if (pen < 0.04) pen = 0.04; + if (pen > r * 1.4) pen = r * 1.4; - var LC = { col: 0, lum: 0 }; - function litOf(base, dist, hv) { - var far = dist >= 40 || (dist > 24 && hv > (40 - dist) / 16); - var nt = night(); - var dark = nt > 0.5 || (nt > 0 && hv < nt); - if (!far) { - if (dark) { - LC.col = base > 0.72 ? P.pure : P.azure; - LC.lum = base > 0.72 ? 52 + 26 * base : 44 + 26 * base; - } else { - LC.col = P.white; LC.lum = (150 + 62 * base) * (1 - 0.20 * dayMix()); - } - return LC; - } - LC.col = dark ? P.azure : P.pure; - LC.lum = (dark ? (dist < 125 ? 70 + dist * 0.62 : 60) : (dist < 125 ? 96 + dist * 0.62 : 88)) * - (0.90 + 0.26 * base); - return LC; - } + var x, y; + for (y = Y0; y <= Y1; y++) { + var row = y * V.cols; + for (x = X0; x <= X1; x++) { + var i = row + x; + if (!groundAt(f, x, y, i)) continue; + var lum = f.lum[i]; + if (lum <= 0) continue; + var ex = GP.wx - mx, ez = GP.wz - mz; + var u = (ex * ax + ez * az) / hl, v = (ex * qx + ez * qz) / r; + var rq = Math.sqrt(u * u + v * v); + if (rq >= 1.001) continue; - function specOf(base, dist) { - if (night() > 0.5) { LC.col = P.pure; LC.lum = 78 + 34 * base; return LC; } - LC.col = P.pure; LC.lum = dist < 125 ? 186 + 50 * base : 150 + 40 * base; - return LC; - } + var kk = (1 - rq) * r / pen; + if (kk >= 1) { + if (GP.d < 25) { - function softOf(edge) { return edge < 0.26 ? 0.24 + 2.923 * edge : 1; } - - var NH = 7; - - var HF = [3, 5, 8, 13, 21, 34, 55]; - var HA = [0, 0, 0, 0, 0, 0, 0], HP = [0, 0, 0, 0, 0, 0, 0]; - - var RIDGE_DC = 0.055, RIDGE_AMP = 0.140; - - function ridgeInit() { - var i, s = 0; - for (i = 0; i < NH; i++) { - HA[i] = (0.55 + 0.9 * hash1(BASE + i, 0x4DA0)) / Math.pow(HF[i], 0.35); s += HA[i]; - } - for (i = 0; i < NH; i++) { HA[i] *= RIDGE_AMP / s; HP[i] = hash1(BASE + i, 0x4DA1) * 6.2831853; } - } - function ridgeEl(b) { - var e = RIDGE_DC, i; - for (i = 0; i < NH; i++) e += HA[i] * Math.sin(HF[i] * b + HP[i]); - return e; - } - function ridgeSlope(b) { - var e = 0, i; - for (i = 0; i < NH; i++) e += HA[i] * HF[i] * Math.cos(HF[i] * b + HP[i]); - return e; - } - - function drawMassif(f) { - var y1 = Math.floor(V.horizon); if (y1 > V.rows) y1 = V.rows; - if (y1 <= 0) return; - var saz = sunAz(), x, y; - for (x = 0; x < V.cols; x++) { - var sp = (2 * (x + 0.5) / V.cols - 1) * V.half; - var bear = V.yaw + Math.atan(sp); - var el = ridgeEl(bear); - if (el <= 0.002) continue; - - var da = saz - bear - Math.atan(14.0 * ridgeSlope(bear)); - da = Math.atan2(Math.sin(da), Math.cos(da)); - var litK = clamp(0.5 - 2.2 * Math.cos(da), 0, 1); - var top = V.horizon - el * V.scale; - var span = V.horizon - top; - var y0 = Math.floor(top); if (y0 < 0) y0 = 0; - for (y = y0; y < y1; y++) { - - var elr = (V.horizon - y - 0.5) / V.scale; - var hv = hash2(Math.floor(bear * 900), Math.floor(elr * 4200), BASE + 0x4DA2); - var edge = litK - hv * 0.74; - var depth = (y - top) / (span + 1e-6); - var crest = y <= top + 1.0; - if (edge <= 0) { - - if (crest) plot(f, x, y, G_DOT, P.slate, 30 + hv * 22, D_RIDGE); - else if (hv > 0.93) plot(f, x, y, hv > 0.965 ? G_DOT : G_COMMA, P.slate, 18 + hv * 14, D_RIDGE); - else plot(f, x, y, 0, P.shadow, 0, D_RIDGE); - continue; - } - var soft = softOf(edge); - - var nt = night(); - var dk = nt > 0.5 || (nt > 0 && hv < nt); - var col = dk ? P.azure : P.pure, nk = dk ? 0.80 : 1; - if (crest) - - plot(f, x, y, hv < 0.4 ? G_DASH : G_EQ, col, (198 + 44 * hv) * nk * soft, D_RIDGE); - else if (hv < 0.66) - - plot(f, x, y, hv < 0.22 ? G_PCT : (hv < 0.44 ? G_HASH : G_8), col, - (58 + 40 * hv) * nk * (0.80 + 0.28 * (1 - depth)) * soft, D_RIDGE); - else - plot(f, x, y, 0, P.shadow, 0, D_RIDGE); - } - } - } - - var NSTAR = 90; - - function drawStars(f) { - var i; - for (i = 0; i < NSTAR; i++) { - var az = hash1(i, 0x4DB0) * 6.2831853; - - var hu = hash1(i, 0x4DB1); - var alt = 0.015 + hu * hu * hu * 0.62; - var ca = Math.cos(alt); - if (!projDir(Math.sin(az) * ca, Math.sin(alt), Math.cos(az) * ca)) continue; - var mag = hash1(i, 0x4DB2); - var x = VP.x, y = VP.y; - if (mag > 0.88) { - - plot(f, x, y, G_PLUS, P.pure, 244, D_STAR); - plot(f, x - 1, y, G_DASH, P.pure, 120, D_STAR); - plot(f, x + 1, y, G_DASH, P.pure, 120, D_STAR); - } else if (mag > 0.62) { - plot(f, x, y, G_STAR, P.pure, 176 + mag * 70, D_STAR); - } else { - - plot(f, x, y, G_DOT, P.white, (150 + mag * 64) * (1 - 0.22 * dayMix()), D_STAR); - } - } - } - - var VP = { x: 0, y: 0, w: 0 }; - function projDir(dx, dy, dz) { - var w = dx * V.fwx + dz * V.fwz; - if (w <= 0.02) return false; - var s = dx * V.rgx + dz * V.rgz; - VP.w = w; - VP.x = (s / w) * V.colK + V.colMid; - VP.y = V.horizon - (dy / w) * V.scale; - return true; - } - - var EARTH_R = 0.030; - - function drawEarth(f) { - var eaz = MOON ? MOON.EARTH_AZ : 0.28, ealt = MOON ? MOON.EARTH_ALT : 0.24; - var eca = Math.cos(ealt); - var ex = Math.sin(eaz) * eca, ey = Math.sin(ealt), ez = Math.cos(eaz) * eca; - if (!projDir(ex, ey, ez)) return; - var cx = VP.x, cy = VP.y, w = VP.w; - var rw = EARTH_R * V.colK / w, rh = EARTH_R * V.scale / w; - if (rw < 0.7) return; - - var salt = sunAlt(), sca = Math.cos(salt); - var sx = sunX() * sca, sy = Math.sin(salt), sz = sunZ() * sca; - - var cosPA = ex * sx + ey * sy + ez * sz; - var frac = clamp((1 - cosPA) * 0.5, 0.30, 0.96); - - var tx = sx - cosPA * ex, ty = sy - cosPA * ey, tz = sz - cosPA * ez; - var tn = Math.sqrt(tx * tx + ty * ty + tz * tz); - if (tn < 1e-5) { tx = 1; ty = 0; tz = 0; tn = 1; } - tx /= tn; ty /= tn; tz /= tn; - var lu = tx * V.rgx + tz * V.rgz, lv = -ty; - var ln = Math.sqrt(lu * lu + lv * lv); if (ln < 1e-5) { lu = 1; lv = 0; ln = 1; } - lu /= ln; lv /= ln; - - var sd = 0x4DC0; - var iw = Math.ceil(rw) + 1, ih = Math.ceil(rh) + 1, dx, dy; - for (dy = -ih; dy <= ih; dy++) { - for (dx = -iw; dx <= iw; dx++) { - var u = (Math.round(cx) + dx - cx) / rw, v = (Math.round(cy) + dy - cy) / rh; - var r2 = u * u + v * v; - if (r2 > 1.04) continue; - var px = Math.round(cx) + dx, py = Math.round(cy) + dy; - - var p = u * lu + v * lv, s = -u * lv + v * lu; - var ss = 1 - s * s; if (ss < 0) ss = 0; - var pt = (1 - 2 * frac) * Math.sqrt(ss); - var lit = p - pt; - if (lit <= 0) { - - if (r2 > 0.72 && hash2(px, py, sd ^ 0x11) < 0.13) - plot(f, px, py, G_DOT, P.slate, 24, D_EARTH); - else plot(f, px, py, 0, P.shadow, 0, D_EARTH); - continue; - } - - var soft = lit < 0.22 ? 0.30 + 3.18 * lit : 1; - var hb = hash2(Math.floor((u + 1) * 2.6), Math.floor((v + 1) * 2.6), sd); - var hf = hash2(px * 7, py * 13, sd ^ 0x22); - - var lam = 0.55 + 0.45 * Math.sqrt(clamp(1 - r2, 0, 1)); - if (hb < 0.45) { - - plot(f, px, py, hf < 0.4 ? G_AT : G_8, P.pure, (190 + 45 * hf) * lam * soft, D_EARTH); - } else if (hb < 0.82) { - - plot(f, px, py, hf < 0.5 ? G_O : G_o, P.azure, (96 + 34 * hf) * lam * soft, D_EARTH); - } else { - - plot(f, px, py, hf < 0.5 ? G_PCT : G_HASH, P.white, (150 + 32 * hf) * lam * soft, D_EARTH); - } - } - } - } - - var SUN_R = 0.00465; - - function drawSun(f) { - - var k = 1 - night(); - if (k <= 0.02) return; - var salt = sunAlt(), ca = Math.cos(salt); - if (!projDir(sunX() * ca, Math.sin(salt), sunZ() * ca)) return; - var cx = VP.x, cy = VP.y, w = VP.w; - var rw = SUN_R * V.colK / w, rh = SUN_R * V.scale / w; - - var wx2 = 2 * rw < 1 ? 2 * rw : 1, wy2 = 2 * rh < 1 ? 2 * rh : 1; - var iw = Math.ceil(rw) + 1, ih = Math.ceil(rh) + 1, dx, dy; - var x0 = Math.round(cx), y0 = Math.round(cy); - for (dy = -ih; dy <= ih; dy++) { - for (dx = -iw; dx <= iw; dx++) { - var px = x0 + dx, py = y0 + dy; - var ax = (px + 0.5 < cx + rw ? px + 0.5 : cx + rw) - (px - 0.5 > cx - rw ? px - 0.5 : cx - rw); - if (ax <= 0) continue; - var ay = (py + 0.5 < cy + rh ? py + 0.5 : cy + rh) - (py - 0.5 > cy - rh ? py - 0.5 : cy - rh); - if (ay <= 0) continue; - - var cov = clamp(1.8 * (ax / wx2) * (ay / wy2), 0, 1); - if (cov <= 0.02) continue; - plot(f, px, py, cov > 0.6 ? G_AT : (cov > 0.3 ? G_8 : G_o), P.pure, 255 * cov * k, D_SUN); - } - } - } - - var STRIDE = 0.72, PRINT_FAR = 72.0, PRINT_NEAR = 20.0; - var trailX0 = 0, trailZ0 = 0; - - function trailX(wz) { - return trailX0 + - (CC.vnoise(wz * 0.0222, BASE + 0x51) - 0.5) * 13.0 + - (CC.vnoise(wz * 0.0750, BASE + 0x52) - 0.5) * 4.0; - } - function trailZ(wx) { - return trailZ0 + - (CC.vnoise(wx * 0.0222, BASE + 0x53) - 0.5) * 13.0 + - (CC.vnoise(wx * 0.0750, BASE + 0x54) - 0.5) * 4.0; - } - - var Q_D = [4, 8, 14, 22, 34, 55, 90], Q_V = [60, 23, 12.5, 7.6, 4.9, 3.1, 1.9, 1.2]; - function qOf(dist) { - for (var i = 0; i < 7; i++) if (dist < Q_D[i]) return Q_V[i]; - return Q_V[7]; - } - - function printAt(f, x, y, d, along, off, salt) { - if (d > PRINT_NEAR) { - - if (off < -0.34 || off > 0.34) return; - var q = qOf(d); - var hc = hash2(Math.floor(along * q), Math.floor(off * 40), BASE + salt + 0x05); - if (hc > 0.66) return; - var lf = litOf(0.58 + hc * 0.42, d, hc); - emit(f, x, y, hc < 0.30 ? G_COLON : (hc < 0.5 ? G_DOT : G_SEMI), lf.col, lf.lum, d * 0.996); - return; - } - var sp = along / STRIDE, si = Math.floor(sp), fz = sp - si; - - var lat = off - ((si & 1) ? 0.19 : -0.19); - if (lat < 0) lat = -lat; - var hp = hash2(si, 0, BASE + salt + 0x06); - if (fz < 0.42 && lat < 0.13) { - - var hd = hash2(Math.floor(along * 40), Math.floor(off * 40), BASE + salt + 0x07); - if (hd < 0.09) emit(f, x, y, G_DOT, P.slate, 16 + hd * 110, d * 0.996); - else emit(f, x, y, 0, P.shadow, 0, d * 0.996); - return; - } - if (fz < 0.54 && lat < 0.21) { - - var lr = litOf(0.80 + hp * 0.20, d, hp); - emit(f, x, y, hp < 0.5 ? G_UNDER : G_DASH, lr.col, lr.lum, d * 0.996); - return; + var hf = hash2(Math.floor(GP.wx * 30), Math.floor(GP.wz * 30), sd ^ 0x91); + if (hf < 0.08) { put(f, x, y, G_DOT, P.slate, 16 + hf * 110, GP.d * 0.99, 2); continue; } + } + put(f, x, y, 0, P.shadow, 0, GP.d * 0.99, 2); + continue; } - if (fz < 0.80 && lat < 0.36) { - var hs = hash2(Math.floor(along * 14), Math.floor(off * 14), BASE + salt + 0x08); - if (hs < 0.20) { - var ls = litOf(0.35 + hs, d, hs); - emit(f, x, y, G_DOT, ls.col, ls.lum * 0.8, d * 0.996); - } - } + put(f, x, y, f.ch[i], f.col[i], lum * (0.24 + 0.76 * (1 - kk)), GP.d * 0.99, 2); + } + } + } + + var NFACET = 7, TAU_F = 6.283185307; + + var FU = new Float64Array(NFACET), FV = new Float64Array(NFACET), FB = new Float64Array(NFACET); + + function facetR(k, sd) { + return 0.58 + hash2(((k % NFACET) + NFACET) % NFACET, 3, sd ^ 0x5C13) * 0.42; + } + function drawRock(f, px, pz, r, sX, sZ, sd) { + if (!project(px, r, pz)) return; + var cx = PJ.x, cy = PJ.y, d = PJ.d, w = PJ.w; + var rw = r * V.colK / w, rh = r * V.scale / w; + + var vx = px - V.ox, vy = r - V.eyeY, vz = pz - V.oz; + var vn = Math.sqrt(vx * vx + vy * vy + vz * vz); if (vn < 1e-4) return; + vx /= vn; vy /= vn; vz /= vn; + var salt = sunAlt(), sca = Math.cos(salt); + var Sx = sX * sca, Sy = Math.sin(salt), Sz = sZ * sca; + var sr = V.rgx * Sx + V.rgz * Sz; + var su = Sy; + var sf = -(vx * Sx + vy * Sy + vz * Sz); + + if (rw < 0.75) { + + var lk = clamp(0.5 + 3.0 * sf, 0, 1); + if (lk < 0.25) return; + var hs = hash2(Math.floor(px * 4), Math.floor(pz * 4), sd ^ 0x71); + var l1 = litOf(0.55 + hs * 0.45, d, hs); + + emit(f, Math.floor(cx), Math.floor(cy), hs < 0.35 ? G_PCT : (hs < 0.7 ? G_8 : G_DOT), + l1.col, l1.lum * lk, d); + return; } - function drawPrints(f) { - var y0 = Math.floor(V.horizon); if (y0 < 0) y0 = 0; - var x, y; - for (y = y0; y < V.rows; y++) { - var row = y * V.cols; - for (x = 0; x < V.cols; x++) { - var i = row + x; - if (!groundAt(f, x, y, i)) continue; - var d = GP.d; - if (d > PRINT_FAR) continue; + var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; + var x0 = Math.floor(cx), y0 = Math.floor(cy); - var o1 = GP.wx - trailX(GP.wz); - if (o1 > -0.8 && o1 < 0.8) { printAt(f, x, y, d, GP.wz, o1, 0x50); continue; } - var o2 = GP.wz - trailZ(GP.wx); - if (o2 > -0.8 && o2 < 0.8) printAt(f, x, y, d, GP.wx, o2, 0x60); - } - } + var dx0 = -iw, dx1 = iw, dy0 = -ih, dy1 = ih; + if (x0 + dx0 < 0) dx0 = -x0; + if (x0 + dx1 > V.cols - 1) dx1 = V.cols - 1 - x0; + if (y0 + dy0 < 0) dy0 = -y0; + if (y0 + dy1 > V.rows - 1) dy1 = V.rows - 1 - y0; + + var fu = FU, fv = FV, fb = FB, fk; + for (fk = 0; fk < NFACET; fk++) { + var mid = (fk + 0.5) * TAU_F / NFACET; + var lean = 0.34 + hash2(fk, 7, sd ^ 0x6D2) * 0.52; + var cxn = Math.cos(mid) * lean, cyn = Math.sin(mid) * lean; + var cbn = Math.sqrt(1 - lean * lean * 0.92); + var nn = Math.sqrt(cxn * cxn + cyn * cyn + cbn * cbn); + fu[fk] = cxn / nn; fv[fk] = cyn / nn; fb[fk] = cbn / nn; } - var BLD_LAT = 4.2, BLD_R = 92.0, BLD_P = 0.46; - - function drawBoulders(f) { - if (!CITY) return; - var lo0 = Math.floor((V.ox - BLD_R) / BLD_LAT), hi0 = Math.floor((V.ox + BLD_R) / BLD_LAT); - var lo1 = Math.floor((V.oz - BLD_R) / BLD_LAT), hi1 = Math.floor((V.oz + BLD_R) / BLD_LAT); - var i, j; - var salt = sunAlt(), tanA = Math.tan(salt), sinA = Math.sin(salt); - if (tanA < 0.02) tanA = 0.02; - if (sinA < 0.02) sinA = 0.02; - var sX = sunX(), sZ = sunZ(); - for (j = lo1; j <= hi1; j++) { - for (i = lo0; i <= hi0; i++) { - var h = hash2(i, j, BASE + 0x61); - if (h > BLD_P) continue; - var px = (i + 0.12 + 0.76 * hash2(i, j, BASE + 0x62)) * BLD_LAT; - var pz = (j + 0.12 + 0.76 * hash2(i, j, BASE + 0x63)) * BLD_LAT; - - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < 0.9 || w > BLD_R) continue; - - if (CITY.height(px, pz) > 0.1) continue; - - var hr = hash2(i, j, BASE + 0x64); - var r = 0.15 + hr * hr * hr * 1.35; - - var clr = 1.1 + 1.7 * r; - var ka = Math.round(px / CITY.AVE), kc = Math.round(pz / CITY.CROSS); - var da = px - (CITY.aveX(ka) + 0.5); if (da < 0) da = -da; - if (da < clr) continue; - var dc = pz - (CITY.crossZ(kc) + 0.5); if (dc < 0) dc = -dc; - if (dc < clr) continue; - - var sd = (BASE + i * 7919 + j * 104729) & 0x3fffff; - drawShadow(f, px, pz, r, sX, sZ, tanA, sinA, sd); - drawRock(f, px, pz, r, sX, sZ, sd); - } - } + var bestF = 0, bestD = -2; + for (fk = 0; fk < NFACET; fk++) { + var bd = fu[fk] * sr - fv[fk] * su + fb[fk] * sf; + if (bd > bestD) { bestD = bd; bestF = fk; } } - function drawShadow(f, px, pz, r, sX, sZ, tanA, sinA, sd) { - var ax = -sX, az = -sZ; - var L = 2 * r / tanA; - if (L > 44) L = 44; - var w0 = (px - V.ox) * V.fwx + (pz - V.oz) * V.fwz; - var aw = ax * V.fwx + az * V.fwz; - var s0 = 0, s1 = L; - if (aw > 1e-6) { var c0 = (0.6 - w0) / aw; if (c0 > s0) s0 = c0; } - else if (aw < -1e-6) { var c1 = (0.6 - w0) / aw; if (c1 < s1) s1 = c1; } - else if (w0 < 0.6) return; - if (s1 <= s0) return; + for (dy = dy0; dy <= dy1; dy++) { + for (dx = dx0; dx <= dx1; dx++) { + var u = (x0 + dx - cx) / rw, v = (y0 + dy - cy) / rh; + var r2 = u * u + v * v; + if (r2 > 1.0) continue; - var bx0 = 1e9, bx1 = -1e9, by0 = 1e9, by1 = -1e9, k, q; - var qx = -az, qz = ax; - for (k = 0; k <= 4; k++) { - var s = s0 + (s1 - s0) * (k / 4); - for (q = -1; q <= 1; q += 2) { - if (!project(px + ax * s + qx * r * q, 0, pz + az * s + qz * r * q)) continue; - if (PJ.x < bx0) bx0 = PJ.x; if (PJ.x > bx1) bx1 = PJ.x; - if (PJ.y < by0) by0 = PJ.y; if (PJ.y > by1) by1 = PJ.y; - } + var ang = Math.atan2(v, u); if (ang < 0) ang += TAU_F; + var tt = ang * NFACET / TAU_F; + var kk0 = Math.floor(tt), ff = tt - kk0; + var a0 = kk0 * TAU_F / NFACET, dA = TAU_F / NFACET; + var r0 = facetR(kk0, sd), r1 = facetR(kk0 + 1, sd); + var den = r0 * Math.sin(ff * dA) + r1 * Math.sin(dA - ff * dA); + var lim = den > 1e-6 ? (r0 * r1 * Math.sin(dA)) / den : 1; + if (r2 > lim * lim) continue; + + var fi = kk0 % NFACET; + + var bulge = (1 - r2) * 0.55; + var dd = d - bulge * r; + var dot = fu[fi] * sr - fv[fi] * su + fb[fi] * sf; + var litK = clamp(0.5 + 3.0 * dot, 0, 1); + + var hv = hash2(Math.floor((u + 1.2) * 9), Math.floor((v + 1.2) * 9), sd ^ 0x72); + var edge = litK - hv * 0.74; + if (edge <= 0) { + + if (d < 25 && hv > 0.94) emit(f, x0 + dx, y0 + dy, G_COMMA, P.slate, 18 + hv * 40, dd); + else emit(f, x0 + dx, y0 + dy, 0, P.shadow, 0, dd); + continue; } - if (bx1 < bx0) return; - var X0 = Math.floor(bx0) - 2, X1 = Math.ceil(bx1) + 2; - var Y0 = Math.floor(by0) - 2, Y1 = Math.ceil(by1) + 2; - if (X0 < 0) X0 = 0; if (X1 >= V.cols) X1 = V.cols - 1; - if (Y0 < Math.floor(V.horizon)) Y0 = Math.floor(V.horizon); - if (Y0 < 0) Y0 = 0; - if (Y1 >= V.rows) Y1 = V.rows - 1; - if (X1 < X0 || Y1 < Y0) return; + var soft = softOf(edge); - var hl = L * 0.5, mx = px + ax * hl, mz = pz + az * hl; - - var pen = 0.0093 * L / sinA; - if (pen < 0.04) pen = 0.04; - if (pen > r * 1.4) pen = r * 1.4; - - var x, y; - for (y = Y0; y <= Y1; y++) { - var row = y * V.cols; - for (x = X0; x <= X1; x++) { - var i = row + x; - if (!groundAt(f, x, y, i)) continue; - var lum = f.lum[i]; - if (lum <= 0) continue; - var ex = GP.wx - mx, ez = GP.wz - mz; - var u = (ex * ax + ez * az) / hl, v = (ex * qx + ez * qz) / r; - var rq = Math.sqrt(u * u + v * v); - if (rq >= 1.001) continue; - - var kk = (1 - rq) * r / pen; - if (kk >= 1) { - if (GP.d < 25) { - - var hf = hash2(Math.floor(GP.wx * 30), Math.floor(GP.wz * 30), sd ^ 0x91); - if (hf < 0.08) { put(f, x, y, G_DOT, P.slate, 16 + hf * 110, GP.d * 0.99, 2); continue; } - } - put(f, x, y, 0, P.shadow, 0, GP.d * 0.99, 2); - continue; - } - - put(f, x, y, f.ch[i], f.col[i], lum * (0.24 + 0.76 * (1 - kk)), GP.d * 0.99, 2); - } + if (fi === bestF && bestD > 0.15 && hv < 0.26) { + var ls = specOf(0.55 + hv, d); + emit(f, x0 + dx, y0 + dy, G_EQ, ls.col, ls.lum * soft, dd); + continue; } + + if (hv > 0.86) { emit(f, x0 + dx, y0 + dy, 0, P.shadow, 0, dd); continue; } + var k = hv / 0.86; + var lf = litOf(k * 0.85 + 0.15 * bulge, d, hv); + emit(f, x0 + dx, y0 + dy, + k < 0.28 ? G_8 : (k < 0.56 ? G_PCT : (k < 0.82 ? G_HASH : G_X)), + lf.col, lf.lum * soft, dd); + } } + } - var NFACET = 7, TAU_F = 6.283185307; + var TS_FAR = 45.0, TS_NEAR = 6, TS_FARN = 4, TS_SOFT = 0.55; + var TS_REACH = 28.0, TS_HARD = 4.0, TS_RAG = 0.18; + var TS_FILL = 0.20, TS_FILL_D = 20.0, TS_FILL_E = 45.0; + var TS_EDGE = 0.45, TS_EDGE_I = 1 / TS_EDGE; - var FU = new Float64Array(NFACET), FV = new Float64Array(NFACET), FB = new Float64Array(NFACET); + var BG_PITCH = 2.0, BG_INV = 1 / BG_PITCH, BG_N = 128, BG_MASK = BG_N - 1, BG_SH = 7; + var bgH = new Float32Array(BG_N * BG_N), bgS = new Int32Array(BG_N * BG_N), bgStamp = 0; - function facetR(k, sd) { - return 0.58 + hash2(((k % NFACET) + NFACET) % NFACET, 3, sd ^ 0x5C13) * 0.42; + function bgAt(gi, gj) { + var idx = ((gj & BG_MASK) << BG_SH) | (gi & BG_MASK); + if (bgS[idx] === bgStamp) return bgH[idx]; + var wx = gi * BG_PITCH, wz = gj * BG_PITCH; + var h = CITY.height(wx, wz), h2; + h2 = CITY.height(wx + 1, wz); if (h2 > h) h = h2; + h2 = CITY.height(wx, wz + 1); if (h2 > h) h = h2; + h2 = CITY.height(wx + 1, wz + 1); if (h2 > h) h = h2; + bgS[idx] = bgStamp; bgH[idx] = h; + return h; + } + + function bgSample(wx, wz) { + var qx = wx * BG_INV, qz = wz * BG_INV; + var i0 = Math.floor(qx), j0 = Math.floor(qz); + var fx = qx - i0, fz = qz - j0; + var a = bgAt(i0, j0), b = bgAt(i0 + 1, j0), c = bgAt(i0, j0 + 1), d = bgAt(i0 + 1, j0 + 1); + var ab = a + (b - a) * fx; + return ab + ((c + (d - c) * fx) - ab) * fz; + } + + var TS_UN = new Float64Array(TS_NEAR), TS_RN = new Float64Array(TS_NEAR), + TS_UF = new Float64Array(TS_FARN), TS_RF = new Float64Array(TS_FARN); + + function drawRelief(f) { + if (!CITY) return; + bgStamp++; if (bgStamp > 2000000000) { bgStamp = 1; bgS.fill(0); } + var ta = Math.tan(sunAlt()); if (ta < 0.05) ta = 0.05; + var sX = sunX(), sZ = sunZ(); + var reach = 6.0 / ta; if (reach > TS_REACH) reach = TS_REACH; + var x, y, s, u; + for (s = 0; s < TS_NEAR; s++) { + u = (s + 1) * reach / TS_NEAR; TS_UN[s] = u; + TS_RN[s] = u <= TS_HARD ? 1 : 1 - (1 - TS_RAG) * (u - TS_HARD) / (TS_REACH - TS_HARD); } - function drawRock(f, px, pz, r, sX, sZ, sd) { - if (!project(px, r, pz)) return; - var cx = PJ.x, cy = PJ.y, d = PJ.d, w = PJ.w; - var rw = r * V.colK / w, rh = r * V.scale / w; - - var vx = px - V.ox, vy = r - V.eyeY, vz = pz - V.oz; - var vn = Math.sqrt(vx * vx + vy * vy + vz * vz); if (vn < 1e-4) return; - vx /= vn; vy /= vn; vz /= vn; - var salt = sunAlt(), sca = Math.cos(salt); - var Sx = sX * sca, Sy = Math.sin(salt), Sz = sZ * sca; - var sr = V.rgx * Sx + V.rgz * Sz; - var su = Sy; - var sf = -(vx * Sx + vy * Sy + vz * Sz); - - if (rw < 0.75) { - - var lk = clamp(0.5 + 3.0 * sf, 0, 1); - if (lk < 0.25) return; - var hs = hash2(Math.floor(px * 4), Math.floor(pz * 4), sd ^ 0x71); - var l1 = litOf(0.55 + hs * 0.45, d, hs); - - emit(f, Math.floor(cx), Math.floor(cy), hs < 0.35 ? G_PCT : (hs < 0.7 ? G_8 : G_DOT), - l1.col, l1.lum * lk, d); - return; - } - - var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; - var x0 = Math.floor(cx), y0 = Math.floor(cy); - - var dx0 = -iw, dx1 = iw, dy0 = -ih, dy1 = ih; - if (x0 + dx0 < 0) dx0 = -x0; - if (x0 + dx1 > V.cols - 1) dx1 = V.cols - 1 - x0; - if (y0 + dy0 < 0) dy0 = -y0; - if (y0 + dy1 > V.rows - 1) dy1 = V.rows - 1 - y0; - - var fu = FU, fv = FV, fb = FB, fk; - for (fk = 0; fk < NFACET; fk++) { - var mid = (fk + 0.5) * TAU_F / NFACET; - var lean = 0.34 + hash2(fk, 7, sd ^ 0x6D2) * 0.52; - var cxn = Math.cos(mid) * lean, cyn = Math.sin(mid) * lean; - var cbn = Math.sqrt(1 - lean * lean * 0.92); - var nn = Math.sqrt(cxn * cxn + cyn * cyn + cbn * cbn); - fu[fk] = cxn / nn; fv[fk] = cyn / nn; fb[fk] = cbn / nn; - } - - var bestF = 0, bestD = -2; - for (fk = 0; fk < NFACET; fk++) { - var bd = fu[fk] * sr - fv[fk] * su + fb[fk] * sf; - if (bd > bestD) { bestD = bd; bestF = fk; } - } - - for (dy = dy0; dy <= dy1; dy++) { - for (dx = dx0; dx <= dx1; dx++) { - var u = (x0 + dx - cx) / rw, v = (y0 + dy - cy) / rh; - var r2 = u * u + v * v; - if (r2 > 1.0) continue; - - var ang = Math.atan2(v, u); if (ang < 0) ang += TAU_F; - var tt = ang * NFACET / TAU_F; - var kk0 = Math.floor(tt), ff = tt - kk0; - var a0 = kk0 * TAU_F / NFACET, dA = TAU_F / NFACET; - var r0 = facetR(kk0, sd), r1 = facetR(kk0 + 1, sd); - var den = r0 * Math.sin(ff * dA) + r1 * Math.sin(dA - ff * dA); - var lim = den > 1e-6 ? (r0 * r1 * Math.sin(dA)) / den : 1; - if (r2 > lim * lim) continue; - - var fi = kk0 % NFACET; - - var bulge = (1 - r2) * 0.55; - var dd = d - bulge * r; - var dot = fu[fi] * sr - fv[fi] * su + fb[fi] * sf; - var litK = clamp(0.5 + 3.0 * dot, 0, 1); - - var hv = hash2(Math.floor((u + 1.2) * 9), Math.floor((v + 1.2) * 9), sd ^ 0x72); - var edge = litK - hv * 0.74; - if (edge <= 0) { - - if (d < 25 && hv > 0.94) emit(f, x0 + dx, y0 + dy, G_COMMA, P.slate, 18 + hv * 40, dd); - else emit(f, x0 + dx, y0 + dy, 0, P.shadow, 0, dd); - continue; - } - var soft = softOf(edge); - - if (fi === bestF && bestD > 0.15 && hv < 0.26) { - var ls = specOf(0.55 + hv, d); - emit(f, x0 + dx, y0 + dy, G_EQ, ls.col, ls.lum * soft, dd); - continue; - } - - if (hv > 0.86) { emit(f, x0 + dx, y0 + dy, 0, P.shadow, 0, dd); continue; } - var k = hv / 0.86; - var lf = litOf(k * 0.85 + 0.15 * bulge, d, hv); - emit(f, x0 + dx, y0 + dy, - k < 0.28 ? G_8 : (k < 0.56 ? G_PCT : (k < 0.82 ? G_HASH : G_X)), - lf.col, lf.lum * soft, dd); - } - } + for (s = 0; s < TS_FARN; s++) { + u = (s + 1) * reach / TS_FARN; TS_UF[s] = u; + TS_RF[s] = u <= TS_HARD ? 1 : 1 - (1 - TS_RAG) * (u - TS_HARD) / (TS_REACH - TS_HARD); } - - function mk(name, layer, fn) { - return { - name: name, layer: layer, world: 'moon', - init: function (city) { - boot(city); - ridgeInit(); - trailX0 = (city && city.startX !== undefined ? city.startX : 0) - 0.6; - trailZ0 = (city && city.startZ !== undefined ? city.startZ : 0) + 0.9; - }, - draw: function (f, cam) { - view(f, cam); - fn(f); - } - }; + var y0 = Math.floor(V.horizon); if (y0 < 0) y0 = 0; + for (y = y0; y < V.rows; y++) { + var row = y * V.cols; + for (x = 0; x < V.cols; x++) { + var i = row + x; + if (!groundAt(f, x, y, i)) continue; + var d = GP.d; + if (d > TS_FAR) continue; + var near = d < 30, n = near ? TS_NEAR : TS_FARN; + var k = 0; + for (s = 0; s < n; s++) { + u = near ? TS_UN[s] : TS_UF[s]; + var rise = bgSample(GP.wx + sX * u, GP.wz + sZ * u) - u * ta; + if (rise <= 0) continue; + var c = (rise < TS_SOFT ? rise / TS_SOFT : 1) * (near ? TS_RN[s] : TS_RF[s]); + if (c > k) k = c; + } + if (k <= 0) continue; + var q = qOf(d); + var hv = hash2(Math.floor(GP.wx * q), Math.floor(GP.wz * q), BASE + 0x71); + var e = (k * (1 + TS_EDGE) - hv) * TS_EDGE_I; + if (e <= 0) continue; + if (e < 1) { + if (f.lum[i] > 0) put(f, x, y, f.ch[i], f.col[i], f.lum[i] * (1 - e), d * 0.996, 2); + continue; + } + var ff = d < TS_FILL_D ? 1 : (d > TS_FILL_E ? 0 : (TS_FILL_E - d) / (TS_FILL_E - TS_FILL_D)); + if (hv < TS_FILL * k * ff) + emit(f, x, y, hv < 0.06 ? G_DOT : G_COMMA, P.slate, 14 + hv * 130, d * 0.996); + else + emit(f, x, y, 0, P.shadow, 0, d * 0.996); + } } + } - CC.ELEMENTS.push(mk('moon-massif', 3, drawMassif)); - CC.ELEMENTS.push(mk('moon-stars', 4, drawStars)); - CC.ELEMENTS.push(mk('moon-earth', 5, drawEarth)); - CC.ELEMENTS.push(mk('moon-sun', 6, drawSun)); + function mk(name, layer, fn) { + return { + name: name, layer: layer, world: 'moon', + init: function (city) { + boot(city); + ridgeInit(); + trailX0 = (city && city.startX !== undefined ? city.startX : 0) - 0.6; + trailZ0 = (city && city.startZ !== undefined ? city.startZ : 0) + 0.9; + }, + draw: function (f, cam) { + view(f, cam); + fn(f); + } + }; + } - CC.ELEMENTS.push(mk('moon-bootprints', 14, drawPrints)); - CC.ELEMENTS.push(mk('moon-boulders', 15, drawBoulders)); + CC.ELEMENTS.push(mk('moon-massif', 3, drawMassif)); + CC.ELEMENTS.push(mk('moon-stars', 4, drawStars)); + CC.ELEMENTS.push(mk('moon-earth', 5, drawEarth)); + CC.ELEMENTS.push(mk('moon-sun', 6, drawSun)); + + CC.ELEMENTS.push(mk('moon-relief', 13, drawRelief)); + CC.ELEMENTS.push(mk('moon-bootprints', 14, drawPrints)); + CC.ELEMENTS.push(mk('moon-boulders', 15, drawBoulders)); })(CC); /* src/elements/optics.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, put = CC.put, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise, - lerp = CC.lerp, smoothstep = CC.smooth; + var P = CC.P, put = CC.put, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise, + lerp = CC.lerp, smoothstep = CC.smooth; - var G_DOT = CC.g('.'), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_COLON = CC.g(':'), - G_o = CC.g('o'), G_O = CC.g('O'), G_DASH = CC.g('-'); + var G_DOT = CC.g('.'), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_COLON = CC.g(':'), + G_o = CC.g('o'), G_O = CC.g('O'), G_DASH = CC.g('-'); - function rel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } + function rel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } - function airDensity() { - return clamp(0.22 + 0.46 * rel('fog') + 0.32 * rel('haze'), 0.26, 2.40); - } + function airDensity() { + return clamp(0.22 + 0.46 * rel('fog') + 0.32 * rel('haze'), 0.26, 2.40); + } - function nearer(d) { - if (!(d < 1e30)) return -1; - var n = d - d * 1e-4; - return n < d ? n : -1; - } + function nearer(d) { + if (!(d < 1e30)) return -1; + var n = d - d * 1e-4; + return n < d ? n : -1; + } - var BACKDROP_D = 1e34; + var BACKDROP_D = 1e34; - function gainDepth(d) { - if (d === Infinity) return BACKDROP_D; - if (!(d < 1e35)) return -1; - var n = d - d * 1e-4; - return n < d ? n : -1; - } + function gainDepth(d) { + if (d === Infinity) return BACKDROP_D; + if (!(d < 1e35)) return -1; + var n = d - d * 1e-4; + return n < d ? n : -1; + } - function gain(f, x, y, g) { - var i = y * f.cols + x, lum = f.lum[i]; - if (lum === 0) return; - var nl = (lum * g + 0.5) | 0; - if (nl === lum) return; - var d = gainDepth(f.dist[i]); - if (d < 0) return; - put(f, x, y, f.ch[i], f.col[i], nl, d, f.kind[i]); - } + function gain(f, x, y, g) { + var i = y * f.cols + x, lum = f.lum[i]; + if (lum === 0) return; + var nl = (lum * g + 0.5) | 0; + if (nl === lum) return; + var d = gainDepth(f.dist[i]); + if (d < 0) return; + put(f, x, y, f.ch[i], f.col[i], nl, d, f.kind[i]); + } - var SHAFTS = 3; + var SHAFTS = 3; - var shaft = { - name: 'lightshafts', - layer: 78, + var shaft = { + name: 'lightshafts', + layer: 78, - world: ['cyber', 'west'], + world: ['cyber', 'west'], - init: function (city, rng) { - this.seed = ((rng() * 4294967296) | 0) ^ 0x5A17; - this.primed = false; - this.found = 0; - this.cols = 0; + init: function (city, rng) { + this.seed = ((rng() * 4294967296) | 0) ^ 0x5A17; + this.primed = false; + this.found = 0; + this.cols = 0; - this.score = null; this.smooth = null; this.srcY = null; this.srcC = null; this.hits = null; + this.score = null; this.smooth = null; this.srcY = null; this.srcC = null; this.hits = null; - this.sx = new Float32Array(SHAFTS); - this.sy = new Float32Array(SHAFTS); - this.sc = new Uint8Array(SHAFTS); - this.ss = new Float32Array(SHAFTS); - this.pkX = new Int32Array(SHAFTS); - this.pkY = new Int32Array(SHAFTS); - this.pkC = new Uint8Array(SHAFTS); - this.pkS = new Float32Array(SHAFTS); - this.tilt = new Float32Array(SHAFTS); - for (var i = 0; i < SHAFTS; i++) this.tilt[i] = (rng() - 0.5) * 0.62; - }, + this.sx = new Float32Array(SHAFTS); + this.sy = new Float32Array(SHAFTS); + this.sc = new Uint8Array(SHAFTS); + this.ss = new Float32Array(SHAFTS); + this.pkX = new Int32Array(SHAFTS); + this.pkY = new Int32Array(SHAFTS); + this.pkC = new Uint8Array(SHAFTS); + this.pkS = new Float32Array(SHAFTS); + this.tilt = new Float32Array(SHAFTS); + for (var i = 0; i < SHAFTS; i++) this.tilt[i] = (rng() - 0.5) * 0.62; + }, - update: function (dt) { - if (!this.primed) return; - var d = dt > 0.25 ? 0.25 : dt; - var eP = 1 - Math.exp(-d * 6.0); - var eS = 1 - Math.exp(-d * 2.2); - var found = this.found; - for (var s = 0; s < SHAFTS; s++) { - var tgt = s < found ? clamp((this.pkS[s] - 150) / 420, 0, 1) : 0; - if (s < found) { - var dxs = this.pkX[s] - this.sx[s]; + update: function (dt) { + if (!this.primed) return; + var d = dt > 0.25 ? 0.25 : dt; + var eP = 1 - Math.exp(-d * 6.0); + var eS = 1 - Math.exp(-d * 2.2); + var found = this.found; + for (var s = 0; s < SHAFTS; s++) { + var tgt = s < found ? clamp((this.pkS[s] - 150) / 420, 0, 1) : 0; + if (s < found) { + var dxs = this.pkX[s] - this.sx[s]; - if (this.ss[s] < 0.06 || dxs > 14 || dxs < -14) { - this.sx[s] = this.pkX[s]; this.sy[s] = this.pkY[s]; - } else { - this.sx[s] += dxs * eP; - this.sy[s] += (this.pkY[s] - this.sy[s]) * eP; - } - this.sc[s] = this.pkC[s]; - } - this.ss[s] += (tgt - this.ss[s]) * eS; - } - }, - - sizeTo: function (cols) { - if (this.cols === cols) return; - this.cols = cols; - - this.score = new Float32Array(cols); - this.smooth = new Float32Array(cols); - this.srcY = new Int32Array(cols); - this.srcC = new Uint8Array(cols); - this.hits = new Uint8Array(cols); - }, - - isSource: function (c) { - return c !== P.slate && c !== P.white && c !== P.shadow && c !== P.pure; - }, - - detect: function (f, hz) { - var cols = f.cols, rows = f.rows, x, y, i; - var score = this.score, srcY = this.srcY, srcC = this.srcC, hits = this.hits; - for (x = 0; x < cols; x++) { score[x] = 0; srcY[x] = -1; srcC[x] = 0; hits[x] = 0; } - - var yEnd = (hz + rows * 0.12) | 0; - if (yEnd > rows - 1) yEnd = rows - 1; - for (y = 0; y <= yEnd; y++) { - for (x = 0; x < cols; x++) { - i = y * cols + x; - var l = f.lum[i]; - if (l < 150) continue; - var c = f.col[i]; - if (!this.isSource(c)) continue; - score[x] += l - 150; - if (hits[x] < 255) hits[x]++; - - if (y > srcY[x]) { srcY[x] = y; srcC[x] = c; } - } - } - - var sm = this.smooth; - for (x = 0; x < cols; x++) { - var a = 0, n = 0; - for (i = x - 2; i <= x + 2; i++) if (i >= 0 && i < cols) { a += score[i]; n++; } - sm[x] = a / n; - } - - var found = 0, k, best, bv; - for (k = 0; k < SHAFTS; k++) { - best = -1; bv = 170; - for (x = 0; x < cols; x++) if (sm[x] > bv) { bv = sm[x]; best = x; } - if (best < 0) break; - - var pick = best, pv = -1; - for (i = best - 2; i <= best + 2; i++) - if (i >= 0 && i < cols && srcY[i] >= 0 && score[i] > pv) { pv = score[i]; pick = i; } - if (srcY[pick] < 0 || hits[pick] < 3) { sm[best] = 0; k--; continue; } - this.pkX[found] = pick; this.pkY[found] = srcY[pick]; - this.pkC[found] = srcC[pick]; this.pkS[found] = bv; - found++; - for (i = best - 9; i <= best + 9; i++) if (i >= 0 && i < cols) sm[i] = 0; - } - - for (k = 1; k < found; k++) { - var jx = this.pkX[k], jy = this.pkY[k], jc = this.pkC[k], js = this.pkS[k], j = k - 1; - while (j >= 0 && this.pkX[j] > jx) { - this.pkX[j + 1] = this.pkX[j]; this.pkY[j + 1] = this.pkY[j]; - this.pkC[j + 1] = this.pkC[j]; this.pkS[j + 1] = this.pkS[j]; j--; - } - this.pkX[j + 1] = jx; this.pkY[j + 1] = jy; this.pkC[j + 1] = jc; this.pkS[j + 1] = js; - } - return found; - }, - - draw: function (f, cam, t) { - var cols = f.cols, rows = f.rows; - this.sizeTo(cols); - var hz = cam && cam.horizon !== undefined ? cam.horizon : rows * 0.56; - var found = this.detect(f, hz); - - this.found = found; - - var s, i, x, y; - - if (!this.primed) { - this.primed = true; - for (s = 0; s < SHAFTS; s++) { - this.ss[s] = s < found ? clamp((this.pkS[s] - 150) / 420, 0, 1) : 0; - if (s < found) { - this.sx[s] = this.pkX[s]; this.sy[s] = this.pkY[s]; this.sc[s] = this.pkC[s]; - } - } - } - - var air = airDensity(); - var reach = 0.80 + 0.20 * air; - var spread = 0.66 + 0.34 * air; - var dense = 0.35 + 0.65 * air; - - var glow = 0.45 + 0.55 * air; - - var wet = clamp(0.55 * rel('rain') + 0.45 * rel('steam'), 0, 1.6); - - for (s = 0; s < SHAFTS; s++) { - var str = this.ss[s]; - if (str < 0.07) continue; - - var x0 = this.sx[s], y0 = this.sy[s], hue = this.sc[s], tilt = this.tilt[s]; - var L = (8 + 10 * str) * reach; - - var moving = !CC.reducedMotion; - - for (var k = 1; k <= L; k++) { - y = (y0 + k) | 0; - if (y >= rows) break; - if (y < 0) continue; - var fall = 1 - k / L; - - var along = 0.30 + 0.70 * fall; - var hw = (0.62 + k * 0.22) * spread; - var cxr = x0 + k * tilt; - - var breathe = moving ? 0.70 + 0.44 * vnoise(k * 0.42 - t * 1.7 + s * 13.7, this.seed) - : 0.90; - var xa = Math.ceil(cxr - hw), xb = Math.floor(cxr + hw); - for (x = xa; x <= xb; x++) { - if (x < 0 || x >= cols) continue; - var dn = (x - cxr) / hw; - var e2 = 1 - dn * dn; - if (e2 <= 0) continue; - - var a = str * along * Math.sqrt(e2) * breathe * dense; - if (a < 0.06) continue; - i = y * cols + x; - - if (f.ch[i] !== 0 && f.lum[i] > 4) { - if (f.kind[i] === 3 && f.lum[i] < 130 && wet > 0.05) - gain(f, x, y, 1 + a * 0.85 * wet); - continue; - } - - if (hash2(x, y * 3 + s * 97, this.seed) > a * 1.15) continue; - var d = nearer(f.dist[i]); - if (d < 0) continue; - - put(f, x, y, a > 0.62 && air > 1.25 ? G_COLON : (a > 0.46 ? G_QUOTE : G_TICK), - hue, (7 + a * 17) * glow, d, 3); - } - } - } + if (this.ss[s] < 0.06 || dxs > 14 || dxs < -14) { + this.sx[s] = this.pkX[s]; this.sy[s] = this.pkY[s]; + } else { + this.sx[s] += dxs * eP; + this.sy[s] += (this.pkY[s] - this.sy[s]) * eP; + } + this.sc[s] = this.pkC[s]; } - }; + this.ss[s] += (tgt - this.ss[s]) * eS; + } + }, - var WASH = 2; - var W_NEAR = 26; - var W_ON = 70, W_FULL = 320; + sizeTo: function (cols) { + if (this.cols === cols) return; + this.cols = cols; - var wash = { - name: 'lightwash', - layer: 79, + this.score = new Float32Array(cols); + this.smooth = new Float32Array(cols); + this.srcY = new Int32Array(cols); + this.srcC = new Uint8Array(cols); + this.hits = new Uint8Array(cols); + }, - world: ['cyber', 'west'], + isSource: function (c) { + return c !== P.slate && c !== P.white && c !== P.shadow && c !== P.pure; + }, - init: function (city, rng) { + detect: function (f, hz) { + var cols = f.cols, rows = f.rows, x, y, i; + var score = this.score, srcY = this.srcY, srcC = this.srcC, hits = this.hits; + for (x = 0; x < cols; x++) { score[x] = 0; srcY[x] = -1; srcC[x] = 0; hits[x] = 0; } - this.seed = (rng() * 30011) | 0; - this.cols = 0; this.rows = 0; this.tw = 0; this.th = 0; - this.te = null; this.tx = null; this.ty = null; - this.tc = null; this.tl = null; this.td = null; - this.found = 0; this.primed = false; - this.pkX = new Float32Array(WASH); this.pkY = new Float32Array(WASH); - this.pkS = new Float32Array(WASH); this.pkD = new Float32Array(WASH); - this.pkC = new Uint8Array(WASH); - this.sx = new Float32Array(WASH); this.sy = new Float32Array(WASH); - this.ss = new Float32Array(WASH); this.sd = new Float32Array(WASH); - this.sc = new Uint8Array(WASH); - this.lead = new Float32Array(WASH); - }, + var yEnd = (hz + rows * 0.12) | 0; + if (yEnd > rows - 1) yEnd = rows - 1; + for (y = 0; y <= yEnd; y++) { + for (x = 0; x < cols; x++) { + i = y * cols + x; + var l = f.lum[i]; + if (l < 150) continue; + var c = f.col[i]; + if (!this.isSource(c)) continue; + score[x] += l - 150; + if (hits[x] < 255) hits[x]++; - update: function (dt) { - if (!this.primed) return; - var d = dt > 0.25 ? 0.25 : dt; - var eP = 1 - Math.exp(-d * 7.0), eS = 1 - Math.exp(-d * 2.6); - var found = this.found; - for (var s = 0; s < WASH; s++) { - var tgt = s < found ? clamp((this.pkS[s] - W_ON) / (W_FULL - W_ON), 0, 1) : 0; - if (s < found) { - var dxs = this.pkX[s] - this.sx[s]; - - if (this.ss[s] < 0.05 || dxs > 20 || dxs < -20) { - this.sx[s] = this.pkX[s]; this.sy[s] = this.pkY[s]; this.lead[s] = 0; - } else { - this.sx[s] += dxs * eP; - this.sy[s] += (this.pkY[s] - this.sy[s]) * eP; - - this.lead[s] += (clamp(dxs * 1.7, -10, 10) - this.lead[s]) * eP; - } - this.sc[s] = this.pkC[s]; this.sd[s] = this.pkD[s]; - } - this.ss[s] += (tgt - this.ss[s]) * eS; - } - }, - - sizeTo: function (cols, rows) { - if (this.cols === cols && this.rows === rows) return; - this.cols = cols; this.rows = rows; - - this.tw = Math.ceil(cols / 6); this.th = Math.ceil(rows / 3); - var n = this.tw * this.th; - this.te = new Float32Array(n); this.tx = new Float32Array(n); this.ty = new Float32Array(n); - this.tc = new Uint8Array(n); this.tl = new Uint8Array(n); this.td = new Float32Array(n); - }, - - detect: function (f) { - var cols = f.cols, rows = f.rows, tw = this.tw; - var te = this.te, tx = this.tx, ty = this.ty, tc = this.tc, tl = this.tl, td = this.td; - var n = tw * this.th, i, x, y; - for (i = 0; i < n; i++) { te[i] = 0; tx[i] = 0; ty[i] = 0; tc[i] = 0; tl[i] = 0; td[i] = 0; } - - for (y = 0; y < rows; y++) { - var ry = ((y / 3) | 0) * tw; - for (x = 0; x < cols; x++) { - i = y * cols + x; - var l = f.lum[i]; - if (l < 150) continue; - var c = f.col[i]; - - if (c === P.slate || c === P.white || c === P.shadow) continue; - var dd = f.dist[i]; - if (!(dd < W_NEAR)) continue; - - var w = 1 - dd / W_NEAR; w *= w; - var e = (l - 150) * w; - var ti = ry + ((x / 6) | 0); - te[ti] += e; tx[ti] += x * e; ty[ti] += y * e; - if (l > tl[ti]) { tl[ti] = l; tc[ti] = c; td[ti] = dd; } - } - } - - var found = 0, k, best, bv, tj; - for (k = 0; k < WASH; k++) { - best = -1; bv = W_ON; - for (i = 0; i < n; i++) if (te[i] > bv) { bv = te[i]; best = i; } - if (best < 0) break; - this.pkX[found] = tx[best] / te[best]; - this.pkY[found] = ty[best] / te[best]; - this.pkC[found] = tc[best]; this.pkD[found] = td[best]; this.pkS[found] = bv; - found++; - - var bx = best % tw, by = (best / tw) | 0; - for (var oy = -2; oy <= 2; oy++) - for (var ox = -3; ox <= 3; ox++) { - var nx = bx + ox, ny = by + oy; - if (nx < 0 || ny < 0 || nx >= tw || ny >= this.th) continue; - te[ny * tw + nx] = 0; - } - } - - for (k = 1; k < found; k++) { - var jx = this.pkX[k], jy = this.pkY[k], jc = this.pkC[k], js = this.pkS[k], jd = this.pkD[k]; - tj = k - 1; - while (tj >= 0 && this.pkX[tj] > jx) { - this.pkX[tj + 1] = this.pkX[tj]; this.pkY[tj + 1] = this.pkY[tj]; - this.pkC[tj + 1] = this.pkC[tj]; this.pkS[tj + 1] = this.pkS[tj]; - this.pkD[tj + 1] = this.pkD[tj]; tj--; - } - this.pkX[tj + 1] = jx; this.pkY[tj + 1] = jy; this.pkC[tj + 1] = jc; - this.pkS[tj + 1] = js; this.pkD[tj + 1] = jd; - } - return found; - }, - - draw: function (f, cam, t) { - var cols = f.cols, rows = f.rows; - this.sizeTo(cols, rows); - var found = this.detect(f); - this.found = found; - - var s, x, y, i; - - if (!this.primed) { - this.primed = true; - for (s = 0; s < WASH; s++) { - this.ss[s] = s < found ? clamp((this.pkS[s] - W_ON) / (W_FULL - W_ON), 0, 1) : 0; - if (s < found) { - this.sx[s] = this.pkX[s]; this.sy[s] = this.pkY[s]; - this.sc[s] = this.pkC[s]; this.sd[s] = this.pkD[s]; - } - } - } - - var air = airDensity(); - var reach = 0.78 + 0.22 * air; - var amp0 = 0.52 * (0.72 + 0.28 * air); - - var motes = clamp((air - 0.85) * 0.55, 0, 0.42); - var S = this.seed; - - for (s = 0; s < WASH; s++) { - var str = this.ss[s]; - if (str < 0.06) continue; - var cx = this.sx[s], cy = this.sy[s], srcD = this.sd[s], hue = this.sc[s]; - - var lead = CC.reducedMotion ? this.lead[s] * 0.25 : this.lead[s]; - var rx = (8 + 10 * str) * reach, ry = (2.4 + 2.6 * str) * reach; - var amp = amp0 * str; - var skew = 1 + (lead < 0 ? -lead : lead) / rx * 1.6; - var ya = Math.ceil(cy - ry), yb = Math.floor(cy + ry); - if (ya < 0) ya = 0; if (yb > rows - 1) yb = rows - 1; - for (y = ya; y <= yb; y++) { - var dy = (y - cy) / ry; - var room = 1 - dy * dy; - if (room <= 0) continue; - var xa = Math.ceil(cx - rx * skew), xb = Math.floor(cx + rx * skew); - if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; - for (x = xa; x <= xb; x++) { - var dx = (x - cx) / rx; - - if (dx * lead > 0) dx /= skew; - var r2 = dx * dx + dy * dy; - if (r2 >= 1) continue; - i = y * cols + x; - var fall = 1 - r2; fall *= fall; - if (f.lum[i] === 0) { - - if (motes < 0.01 || fall < 0.30) continue; - if (hash2(x, y * 5 + s * 131, S) > motes * fall) continue; - var dm = nearer(f.dist[i]); - if (dm < 0) continue; - put(f, x, y, fall > 0.62 ? G_QUOTE : G_TICK, hue, 6 + 16 * fall * amp, dm, 3); - continue; - } - - if (f.dist[i] < srcD * 0.72) continue; - gain(f, x, y, 1 + amp * fall); - } - } - } + if (y > srcY[x]) { srcY[x] = y; srcC[x] = c; } } - }; + } - var mistfar = { - name: 'mistfar', - layer: 80, + var sm = this.smooth; + for (x = 0; x < cols; x++) { + var a = 0, n = 0; + for (i = x - 2; i <= x + 2; i++) if (i >= 0 && i < cols) { a += score[i]; n++; } + sm[x] = a / n; + } - world: ['cyber', 'west'], + var found = 0, k, best, bv; + for (k = 0; k < SHAFTS; k++) { + best = -1; bv = 170; + for (x = 0; x < cols; x++) if (sm[x] > bv) { bv = sm[x]; best = x; } + if (best < 0) break; - init: function (city, rng) { this.seed = (rng() * 30011) | 0; }, + var pick = best, pv = -1; + for (i = best - 2; i <= best + 2; i++) + if (i >= 0 && i < cols && srcY[i] >= 0 && score[i] > pv) { pv = score[i]; pick = i; } + if (srcY[pick] < 0 || hits[pick] < 3) { sm[best] = 0; k--; continue; } + this.pkX[found] = pick; this.pkY[found] = srcY[pick]; + this.pkC[found] = srcC[pick]; this.pkS[found] = bv; + found++; + for (i = best - 9; i <= best + 9; i++) if (i >= 0 && i < cols) sm[i] = 0; + } - draw: function (f) { - - var str = clamp((rel('fog') - 1.30) / 1.70, 0, 1); - if (str < 0.02) return; - var EX = CC.EXPOSURE, kS = EX[P.slate]; - var cols = f.cols, rows = f.rows, S = this.seed, x, y, i; - - var D0 = 30 - 18 * str, DR = 60 - 30 * str; - for (y = 0; y < rows; y++) - for (x = 0; x < cols; x++) { - i = y * cols + x; - var l = f.lum[i]; - if (l === 0 || f.ch[i] === 0) continue; - var c = f.col[i]; - - if (c !== P.amber && c !== P.warm && c !== P.ember && c !== P.spring) continue; - var d = f.dist[i]; - if (!(d > D0) || d > 1e30) continue; - - var p = clamp((d - D0) / DR, 0, 1) * str * 0.78; - - if (hash2(x, y, S) > p) continue; - var nl = (l * EX[c] / kS + 0.5) | 0; - if (nl < 1) continue; - var dd = nearer(d); - if (dd < 0) continue; - put(f, x, y, f.ch[i], P.slate, nl, dd, f.kind[i]); - } + for (k = 1; k < found; k++) { + var jx = this.pkX[k], jy = this.pkY[k], jc = this.pkC[k], js = this.pkS[k], j = k - 1; + while (j >= 0 && this.pkX[j] > jx) { + this.pkX[j + 1] = this.pkX[j]; this.pkY[j + 1] = this.pkY[j]; + this.pkC[j + 1] = this.pkC[j]; this.pkS[j + 1] = this.pkS[j]; j--; } - }; + this.pkX[j + 1] = jx; this.pkY[j + 1] = jy; this.pkC[j + 1] = jc; this.pkS[j + 1] = js; + } + return found; + }, - function vn2(x, y, s) { - var xi = Math.floor(x), yi = Math.floor(y); - var fx = smoothstep(x - xi), fy = smoothstep(y - yi); - var a = lerp(hash2(xi, yi, s), hash2(xi + 1, yi, s), fx); - var b = lerp(hash2(xi, yi + 1, s), hash2(xi + 1, yi + 1, s), fx); - return a + (b - a) * fy; - } + draw: function (f, cam, t) { + var cols = f.cols, rows = f.rows; + this.sizeTo(cols); + var hz = cam && cam.horizon !== undefined ? cam.horizon : rows * 0.56; + var found = this.detect(f, hz); - var vignette = { - name: 'vignette', - layer: 92, + this.found = found; - init: function (city, rng) { - this.seed = (rng() * 30011) | 0; - this.w = 0; this.h = 0; this.map = null; this.cond = null; - }, + var s, i, x, y; - build: function (cols, rows) { - if (this.w === cols && this.h === rows) return; - this.w = cols; this.h = rows; - this.map = new Float32Array(cols * rows); - this.cond = null; - for (var y = 0; y < rows; y++) { - var ny = (y + 0.5) / rows * 2 - 1; - for (var x = 0; x < cols; x++) { - var nx = (x + 0.5) / cols * 2 - 1; - var r = Math.sqrt(nx * nx + ny * ny) * 0.70710678; - var k = clamp((r - 0.52) / 0.48, 0, 1); - this.map[y * cols + x] = 1 - 0.32 * k * k; - } - } - }, - - buildCond: function (cols, rows) { - if (this.cond) return; - this.cond = new Float32Array(cols * rows); - var S = this.seed; - for (var y = 0; y < rows; y++) { - var ny = (y + 0.5) / rows * 2 - 1; - for (var x = 0; x < cols; x++) { - var nx = (x + 0.5) / cols * 2 - 1; - var r = Math.sqrt(nx * nx + ny * ny) * 0.70710678; - - var v = vn2(x * 0.055, y * 0.10, S) * 0.68 + vn2(x * 0.16, y * 0.30, S + 41) * 0.32; - v = clamp((v - 0.34) / 0.52, 0, 1); - - this.cond[y * cols + x] = v * v * clamp((r - 0.30) / 0.62, 0, 1) * 0.30; - } - } - }, - - draw: function (f) { - this.build(f.cols, f.rows); - - var str = clamp((rel('fog') - 1.55) / 1.45, 0, 1); - var cond = null; - if (str >= 0.02) { this.buildCond(f.cols, f.rows); cond = this.cond; } - var map = this.map, cols = f.cols, rows = f.rows, i = 0; - for (var y = 0; y < rows; y++) - for (var x = 0; x < cols; x++, i++) { - var g = map[i]; - if (cond) g *= 1 - cond[i] * str; - if (g > 0.995) continue; - gain(f, x, y, g); - } + if (!this.primed) { + this.primed = true; + for (s = 0; s < SHAFTS; s++) { + this.ss[s] = s < found ? clamp((this.pkS[s] - 150) / 420, 0, 1) : 0; + if (s < found) { + this.sx[s] = this.pkX[s]; this.sy[s] = this.pkY[s]; this.sc[s] = this.pkC[s]; + } } - }; + } - var BEADS = 14; + var air = airDensity(); + var reach = 0.80 + 0.20 * air; + var spread = 0.66 + 0.34 * air; + var dense = 0.35 + 0.65 * air; - var beads = { - name: 'lensrain', - layer: 94, + var glow = 0.45 + 0.55 * air; - world: ['cyber', 'west'], + var wet = clamp(0.55 * rel('rain') + 0.45 * rel('steam'), 0, 1.6); - init: function (city, rng) { - var s = ((rng() * 4294967296) | 0) ^ 0x0F71C5; - this.rnd = CC.mulberry(s); - this.n = BEADS; - this.nx = new Float32Array(this.n); - this.ny = new Float32Array(this.n); - this.r = new Float32Array(this.n); - this.age = new Float32Array(this.n); - this.life = new Float32Array(this.n); + for (s = 0; s < SHAFTS; s++) { + var str = this.ss[s]; + if (str < 0.07) continue; - this.want = this.target(); - for (var i = 0; i < this.n; i++) { - this.spawn(i); - this.age[i] = this.rnd() * this.life[i]; + var x0 = this.sx[s], y0 = this.sy[s], hue = this.sc[s], tilt = this.tilt[s]; + var L = (8 + 10 * str) * reach; + + var moving = !CC.reducedMotion; + + for (var k = 1; k <= L; k++) { + y = (y0 + k) | 0; + if (y >= rows) break; + if (y < 0) continue; + var fall = 1 - k / L; + + var along = 0.30 + 0.70 * fall; + var hw = (0.62 + k * 0.22) * spread; + var cxr = x0 + k * tilt; + + var breathe = moving ? 0.70 + 0.44 * vnoise(k * 0.42 - t * 1.7 + s * 13.7, this.seed) + : 0.90; + var xa = Math.ceil(cxr - hw), xb = Math.floor(cxr + hw); + for (x = xa; x <= xb; x++) { + if (x < 0 || x >= cols) continue; + var dn = (x - cxr) / hw; + var e2 = 1 - dn * dn; + if (e2 <= 0) continue; + + var a = str * along * Math.sqrt(e2) * breathe * dense; + if (a < 0.06) continue; + i = y * cols + x; + + if (f.ch[i] !== 0 && f.lum[i] > 4) { + if (f.kind[i] === 3 && f.lum[i] < 130 && wet > 0.05) + gain(f, x, y, 1 + a * 0.85 * wet); + continue; } - }, - target: function () { return clamp(9 * (0.45 + 0.55 * rel('rain')), 3.2, BEADS); }, - - spawn: function (i) { - var R = this.rnd; - this.nx[i] = 0.04 + R() * 0.92; - - this.ny[i] = 0.03 + R() * R() * 0.94; - - this.r[i] = (0.5 + R() * R() * 1.1) * (0.86 + 0.14 * rel('rain')); - this.age[i] = 0; - this.life[i] = 9 + R() * 17; - }, - - update: function (dt) { - var d = dt > 0.25 ? 0.25 : dt; - var tgt = this.target(); - - var e = 1 - Math.exp(-d / (tgt > this.want ? 12 : 90)); - this.want += (tgt - this.want) * e; - if (CC.reducedMotion) return; - for (var i = 0; i < this.n; i++) { - this.age[i] += dt; - - if (this.r[i] > 1.0) this.ny[i] += dt * 0.006; - if (this.age[i] > this.life[i] || this.ny[i] > 0.99) this.spawn(i); - } - }, - - cell: function (f, x, y, str) { - var cols = f.cols, rows = f.rows; - if (x < 0 || y < 0 || x >= cols || y >= rows) return; - var i = y * cols + x; + if (hash2(x, y * 3 + s * 97, this.seed) > a * 1.15) continue; var d = nearer(f.dist[i]); - if (d < 0) return; - var la = f.lum[i], ca = f.col[i]; - var jy = y + 1 < rows ? y + 1 : y - 1; - var j = jy * cols + x; - var lb = f.lum[j], cb = f.col[j]; - var out = (la * 0.42 + lb * 0.44) * str; - var top = la > lb ? la : lb; - if (out < 4.5) { - if (str < 0.9) return; - put(f, x, y, G_DOT, P.ice, 10 + top * 0.08, d, 3); - return; - } - var hue = la >= lb ? ca : cb; + if (d < 0) continue; - if (top > 118) { hue = P.ice; out *= 0.74; } - put(f, x, y, out > 46 ? G_O : (out > 16 ? G_o : G_COLON), hue, out, d, 3); - }, - - draw: function (f) { - var cols = f.cols, rows = f.rows; - - if (!(this.want > 0)) this.want = this.target(); - var want = this.want; - for (var i = 0; i < this.n; i++) { - - var edge = want - i; - if (edge <= 0) break; - var str = edge < 1 ? edge : 1; - var x = (this.nx[i] * cols) | 0, y = (this.ny[i] * rows) | 0; - this.cell(f, x, y, str); - - if (this.r[i] > 1.05) this.cell(f, x, y + 1, 0.62 * str); - } + put(f, x, y, a > 0.62 && air > 1.25 ? G_COLON : (a > 0.46 ? G_QUOTE : G_TICK), + hue, (7 + a * 17) * glow, d, 3); + } } - }; + } + } + }; - var BSRC = 20; + var WASH = 2; + var W_NEAR = 26; + var W_ON = 70, W_FULL = 320; - var lensbloom = { - name: 'lensbloom', - layer: 95, + var wash = { + name: 'lightwash', + layer: 79, - init: function (city, rng) { - this.seed = (rng() * 30011) | 0; - this.bx = new Int32Array(BSRC); this.by = new Int32Array(BSRC); - this.bl = new Int32Array(BSRC); this.bc = new Uint8Array(BSRC); - this.n = 0; + world: ['cyber', 'west'], - this.yaw = 0; this.panned = false; this.pan = 0; - }, + init: function (city, rng) { - update: function (dt, t, cam) { - if (!cam) return; - var y = cam.yaw || 0; - if (!this.panned) { this.yaw = y; this.panned = true; return; } - var d = y - this.yaw; + this.seed = (rng() * 30011) | 0; + this.cols = 0; this.rows = 0; this.tw = 0; this.th = 0; + this.te = null; this.tx = null; this.ty = null; + this.tc = null; this.tl = null; this.td = null; + this.found = 0; this.primed = false; + this.pkX = new Float32Array(WASH); this.pkY = new Float32Array(WASH); + this.pkS = new Float32Array(WASH); this.pkD = new Float32Array(WASH); + this.pkC = new Uint8Array(WASH); + this.sx = new Float32Array(WASH); this.sy = new Float32Array(WASH); + this.ss = new Float32Array(WASH); this.sd = new Float32Array(WASH); + this.sc = new Uint8Array(WASH); + this.lead = new Float32Array(WASH); + }, - while (d > 3.14159265) d -= 6.28318531; - while (d < -3.14159265) d += 6.28318531; - this.yaw = y; - var rate = dt > 1e-4 ? d / dt : 0; + update: function (dt) { + if (!this.primed) return; + var d = dt > 0.25 ? 0.25 : dt; + var eP = 1 - Math.exp(-d * 7.0), eS = 1 - Math.exp(-d * 2.6); + var found = this.found; + for (var s = 0; s < WASH; s++) { + var tgt = s < found ? clamp((this.pkS[s] - W_ON) / (W_FULL - W_ON), 0, 1) : 0; + if (s < found) { + var dxs = this.pkX[s] - this.sx[s]; - var e = 1 - Math.exp(-(dt > 0.25 ? 0.25 : dt) * 3.0); - this.pan += (clamp(rate * 1.1, -1, 1) - this.pan) * e; - }, + if (this.ss[s] < 0.05 || dxs > 20 || dxs < -20) { + this.sx[s] = this.pkX[s]; this.sy[s] = this.pkY[s]; this.lead[s] = 0; + } else { + this.sx[s] += dxs * eP; + this.sy[s] += (this.pkY[s] - this.sy[s]) * eP; - draw: function (f) { - var cols = f.cols, rows = f.rows, x, y, i, k; - var haze = rel('haze'), windy = rel('wind'); - - var halo = clamp(0.14 + 0.18 * haze, 0.10, 0.46); - - var pan = CC.reducedMotion ? this.pan * 0.3 : this.pan; - var reach = 2.2 + 1.5 * haze + 1.2 * windy * (0.4 + 0.6 * (pan < 0 ? -pan : pan)); - var TH = 175; - - var n = 0, bl = this.bl, bx = this.bx, by = this.by, bc = this.bc; - for (y = 1; y < rows - 1; y++) - for (x = 1; x < cols - 1; x++) { - i = y * cols + x; - var l = f.lum[i]; - if (l < TH) continue; - var c = f.col[i]; - if (c === P.slate || c === P.shadow) continue; - - if (f.lum[i - 1] > l || f.lum[i + 1] >= l) continue; - if (f.lum[i - cols] > l || f.lum[i + cols] >= l) continue; - if (n < BSRC) { - k = n++; - } else { - - var worst = 0; - for (k = 1; k < BSRC; k++) if (bl[k] < bl[worst]) worst = k; - if (bl[worst] >= l) continue; - k = worst; - } - bx[k] = x; by[k] = y; bl[k] = l; bc[k] = c; - } - this.n = n; - - for (k = 0; k < n; k++) { - var sx = bx[k], sy = by[k], hue = bc[k]; - var s = clamp((bl[k] - TH) / 70, 0.30, 1); - - var g1 = 1 + halo * s, g2 = 1 + halo * s * 0.45; - gain(f, sx - 1, sy, g1); gain(f, sx + 1, sy, g1); - gain(f, sx, sy - 1, g1); gain(f, sx, sy + 1, g1); - gain(f, sx - 1, sy - 1, g2); gain(f, sx + 1, sy - 1, g2); - gain(f, sx - 1, sy + 1, g2); gain(f, sx + 1, sy + 1, g2); - - for (var side = -1; side <= 1; side += 2) { - var len = reach * s * (side * pan > 0 ? 1.45 : 0.75); - var L = len | 0; - for (var j = 1; j <= L; j++) { - x = sx + side * j; - if (x < 0 || x >= cols) break; - i = sy * cols + x; - var a = (1 - j / (len + 0.6)); - a *= a; - var lum = bl[k] * a * 0.30; - if (lum < 6) break; - - if (f.ch[i] !== 0 && f.lum[i] > lum) continue; - var d = nearer(f.dist[i]); - if (d < 0) continue; - put(f, x, sy, j < 2 ? G_DASH : G_TICK, hue, lum, d, 3); - } - } - } + this.lead[s] += (clamp(dxs * 1.7, -10, 10) - this.lead[s]) * eP; + } + this.sc[s] = this.pkC[s]; this.sd[s] = this.pkD[s]; } - }; + this.ss[s] += (tgt - this.ss[s]) * eS; + } + }, - var exposure = { - name: 'exposure', - layer: 96, + sizeTo: function (cols, rows) { + if (this.cols === cols && this.rows === rows) return; + this.cols = cols; this.rows = rows; - init: function (city, rng) { - this.phase = rng(); - this.p0 = rng() * 6.2831853; - this.p1 = rng() * 6.2831853; - this.rows = 0; - this.g = null; - this.meas = -1; - this.fast = -1; this.slow = -1; - this.adapt = 1; - }, + this.tw = Math.ceil(cols / 6); this.th = Math.ceil(rows / 3); + var n = this.tw * this.th; + this.te = new Float32Array(n); this.tx = new Float32Array(n); this.ty = new Float32Array(n); + this.tc = new Uint8Array(n); this.tl = new Uint8Array(n); this.td = new Float32Array(n); + }, - update: function (dt) { - if (this.meas < 0) return; - var d = dt > 0.25 ? 0.25 : dt; - this.fast += (this.meas - this.fast) * (1 - Math.exp(-d / 0.5)); + detect: function (f) { + var cols = f.cols, rows = f.rows, tw = this.tw; + var te = this.te, tx = this.tx, ty = this.ty, tc = this.tc, tl = this.tl, td = this.td; + var n = tw * this.th, i, x, y; + for (i = 0; i < n; i++) { te[i] = 0; tx[i] = 0; ty[i] = 0; tc[i] = 0; tl[i] = 0; td[i] = 0; } - var tau = this.meas > this.slow ? 2.5 : 5.0; - this.slow += (this.fast - this.slow) * (1 - Math.exp(-d / tau)); - var f = this.fast, s = this.slow; - if (!(f > 0.01) || !(s > 0.01)) { this.adapt = 1; return; } + for (y = 0; y < rows; y++) { + var ry = ((y / 3) | 0) * tw; + for (x = 0; x < cols; x++) { + i = y * cols + x; + var l = f.lum[i]; + if (l < 150) continue; + var c = f.col[i]; - var k = clamp(0.34 - 0.09 * (airDensity() - 1), 0.16, 0.44); - if (CC.reducedMotion) k *= 0.5; - var e = Math.pow(s / f, k); - var lo = CC.reducedMotion ? 0.94 : 0.88, hi = CC.reducedMotion ? 1.05 : 1.11; - this.adapt = e < lo ? lo : (e > hi ? hi : e); - }, + if (c === P.slate || c === P.white || c === P.shadow) continue; + var dd = f.dist[i]; + if (!(dd < W_NEAR)) continue; - draw: function (f, cam, t) { - - var n = f.n, lum = f.lum, ch = f.ch, sum = 0, i; - for (i = 0; i < n; i++) if (ch[i] !== 0) sum += lum[i]; - this.meas = sum / n; - if (this.fast < 0) { this.fast = this.meas; this.slow = this.meas; } - - var e = this.adapt; - - if (!CC.reducedMotion) - e *= 1 + 0.020 * Math.sin(t * 0.61 + this.p0) + 0.011 * Math.sin(t * 0.233 + this.p1); - - var cols = f.cols, rows = f.rows, x, y; - if (this.rows !== rows) { this.rows = rows; this.g = new Float32Array(rows); } - var g = this.g; - - var ph = CC.reducedMotion ? this.phase : this.phase + t * 0.040; - - for (y = 0; y < rows; y++) { - var bar = 0.5 + 0.5 * Math.cos((y / rows * 1.6 - ph) * 6.2831853); - g[y] = (1 - 0.070 * (y & 1)) * (1 - 0.026 * bar) * e; - } - for (y = 0; y < rows; y++) { - var gy = g[y]; - if (gy > 0.9975 && gy < 1.0025) continue; - for (x = 0; x < cols; x++) gain(f, x, y, gy); - } + var w = 1 - dd / W_NEAR; w *= w; + var e = (l - 150) * w; + var ti = ry + ((x / 6) | 0); + te[ti] += e; tx[ti] += x * e; ty[ti] += y * e; + if (l > tl[ti]) { tl[ti] = l; tc[ti] = c; td[ti] = dd; } } - }; + } - var LIST = [shaft, wash, mistfar, vignette, beads, lensbloom, exposure]; - for (var q = 0; q < LIST.length; q++) CC.ELEMENTS.push(LIST[q]); + var found = 0, k, best, bv, tj; + for (k = 0; k < WASH; k++) { + best = -1; bv = W_ON; + for (i = 0; i < n; i++) if (te[i] > bv) { bv = te[i]; best = i; } + if (best < 0) break; + this.pkX[found] = tx[best] / te[best]; + this.pkY[found] = ty[best] / te[best]; + this.pkC[found] = tc[best]; this.pkD[found] = td[best]; this.pkS[found] = bv; + found++; + + var bx = best % tw, by = (best / tw) | 0; + for (var oy = -2; oy <= 2; oy++) + for (var ox = -3; ox <= 3; ox++) { + var nx = bx + ox, ny = by + oy; + if (nx < 0 || ny < 0 || nx >= tw || ny >= this.th) continue; + te[ny * tw + nx] = 0; + } + } + + for (k = 1; k < found; k++) { + var jx = this.pkX[k], jy = this.pkY[k], jc = this.pkC[k], js = this.pkS[k], jd = this.pkD[k]; + tj = k - 1; + while (tj >= 0 && this.pkX[tj] > jx) { + this.pkX[tj + 1] = this.pkX[tj]; this.pkY[tj + 1] = this.pkY[tj]; + this.pkC[tj + 1] = this.pkC[tj]; this.pkS[tj + 1] = this.pkS[tj]; + this.pkD[tj + 1] = this.pkD[tj]; tj--; + } + this.pkX[tj + 1] = jx; this.pkY[tj + 1] = jy; this.pkC[tj + 1] = jc; + this.pkS[tj + 1] = js; this.pkD[tj + 1] = jd; + } + return found; + }, + + draw: function (f, cam, t) { + var cols = f.cols, rows = f.rows; + this.sizeTo(cols, rows); + var found = this.detect(f); + this.found = found; + + var s, x, y, i; + + if (!this.primed) { + this.primed = true; + for (s = 0; s < WASH; s++) { + this.ss[s] = s < found ? clamp((this.pkS[s] - W_ON) / (W_FULL - W_ON), 0, 1) : 0; + if (s < found) { + this.sx[s] = this.pkX[s]; this.sy[s] = this.pkY[s]; + this.sc[s] = this.pkC[s]; this.sd[s] = this.pkD[s]; + } + } + } + + var air = airDensity(); + var reach = 0.78 + 0.22 * air; + var amp0 = 0.52 * (0.72 + 0.28 * air); + + var motes = clamp((air - 0.85) * 0.55, 0, 0.42); + var S = this.seed; + + for (s = 0; s < WASH; s++) { + var str = this.ss[s]; + if (str < 0.06) continue; + var cx = this.sx[s], cy = this.sy[s], srcD = this.sd[s], hue = this.sc[s]; + + var lead = CC.reducedMotion ? this.lead[s] * 0.25 : this.lead[s]; + var rx = (8 + 10 * str) * reach, ry = (2.4 + 2.6 * str) * reach; + var amp = amp0 * str; + var skew = 1 + (lead < 0 ? -lead : lead) / rx * 1.6; + var ya = Math.ceil(cy - ry), yb = Math.floor(cy + ry); + if (ya < 0) ya = 0; if (yb > rows - 1) yb = rows - 1; + for (y = ya; y <= yb; y++) { + var dy = (y - cy) / ry; + var room = 1 - dy * dy; + if (room <= 0) continue; + var xa = Math.ceil(cx - rx * skew), xb = Math.floor(cx + rx * skew); + if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; + for (x = xa; x <= xb; x++) { + var dx = (x - cx) / rx; + + if (dx * lead > 0) dx /= skew; + var r2 = dx * dx + dy * dy; + if (r2 >= 1) continue; + i = y * cols + x; + var fall = 1 - r2; fall *= fall; + if (f.lum[i] === 0) { + + if (motes < 0.01 || fall < 0.30) continue; + if (hash2(x, y * 5 + s * 131, S) > motes * fall) continue; + var dm = nearer(f.dist[i]); + if (dm < 0) continue; + put(f, x, y, fall > 0.62 ? G_QUOTE : G_TICK, hue, 6 + 16 * fall * amp, dm, 3); + continue; + } + + if (f.dist[i] < srcD * 0.72) continue; + gain(f, x, y, 1 + amp * fall); + } + } + } + } + }; + + var mistfar = { + name: 'mistfar', + layer: 80, + + world: ['cyber', 'west'], + + init: function (city, rng) { this.seed = (rng() * 30011) | 0; }, + + draw: function (f) { + + var str = clamp((rel('fog') - 1.30) / 1.70, 0, 1); + if (str < 0.02) return; + var EX = CC.EXPOSURE, kS = EX[P.slate]; + var cols = f.cols, rows = f.rows, S = this.seed, x, y, i; + + var D0 = 30 - 18 * str, DR = 60 - 30 * str; + for (y = 0; y < rows; y++) + for (x = 0; x < cols; x++) { + i = y * cols + x; + var l = f.lum[i]; + if (l === 0 || f.ch[i] === 0) continue; + var c = f.col[i]; + + if (c !== P.amber && c !== P.warm && c !== P.ember && c !== P.spring) continue; + var d = f.dist[i]; + if (!(d > D0) || d > 1e30) continue; + + var p = clamp((d - D0) / DR, 0, 1) * str * 0.78; + + if (hash2(x, y, S) > p) continue; + var nl = (l * EX[c] / kS + 0.5) | 0; + if (nl < 1) continue; + var dd = nearer(d); + if (dd < 0) continue; + put(f, x, y, f.ch[i], P.slate, nl, dd, f.kind[i]); + } + } + }; + + function vn2(x, y, s) { + var xi = Math.floor(x), yi = Math.floor(y); + var fx = smoothstep(x - xi), fy = smoothstep(y - yi); + var a = lerp(hash2(xi, yi, s), hash2(xi + 1, yi, s), fx); + var b = lerp(hash2(xi, yi + 1, s), hash2(xi + 1, yi + 1, s), fx); + return a + (b - a) * fy; + } + + var vignette = { + name: 'vignette', + layer: 92, + + init: function (city, rng) { + this.seed = (rng() * 30011) | 0; + this.w = 0; this.h = 0; this.map = null; this.cond = null; + }, + + build: function (cols, rows) { + if (this.w === cols && this.h === rows) return; + this.w = cols; this.h = rows; + this.map = new Float32Array(cols * rows); + this.cond = null; + for (var y = 0; y < rows; y++) { + var ny = (y + 0.5) / rows * 2 - 1; + for (var x = 0; x < cols; x++) { + var nx = (x + 0.5) / cols * 2 - 1; + var r = Math.sqrt(nx * nx + ny * ny) * 0.70710678; + var k = clamp((r - 0.52) / 0.48, 0, 1); + this.map[y * cols + x] = 1 - 0.32 * k * k; + } + } + }, + + buildCond: function (cols, rows) { + if (this.cond) return; + this.cond = new Float32Array(cols * rows); + var S = this.seed; + for (var y = 0; y < rows; y++) { + var ny = (y + 0.5) / rows * 2 - 1; + for (var x = 0; x < cols; x++) { + var nx = (x + 0.5) / cols * 2 - 1; + var r = Math.sqrt(nx * nx + ny * ny) * 0.70710678; + + var v = vn2(x * 0.055, y * 0.10, S) * 0.68 + vn2(x * 0.16, y * 0.30, S + 41) * 0.32; + v = clamp((v - 0.34) / 0.52, 0, 1); + + this.cond[y * cols + x] = v * v * clamp((r - 0.30) / 0.62, 0, 1) * 0.30; + } + } + }, + + draw: function (f) { + this.build(f.cols, f.rows); + + var str = clamp((rel('fog') - 1.55) / 1.45, 0, 1); + var cond = null; + if (str >= 0.02) { this.buildCond(f.cols, f.rows); cond = this.cond; } + var map = this.map, cols = f.cols, rows = f.rows, i = 0; + for (var y = 0; y < rows; y++) + for (var x = 0; x < cols; x++, i++) { + var g = map[i]; + if (cond) g *= 1 - cond[i] * str; + if (g > 0.995) continue; + gain(f, x, y, g); + } + } + }; + + var BEADS = 14; + + var beads = { + name: 'lensrain', + layer: 94, + + world: ['cyber', 'west'], + + init: function (city, rng) { + var s = ((rng() * 4294967296) | 0) ^ 0x0F71C5; + this.rnd = CC.mulberry(s); + this.n = BEADS; + this.nx = new Float32Array(this.n); + this.ny = new Float32Array(this.n); + this.r = new Float32Array(this.n); + this.age = new Float32Array(this.n); + this.life = new Float32Array(this.n); + + this.want = this.target(); + for (var i = 0; i < this.n; i++) { + this.spawn(i); + this.age[i] = this.rnd() * this.life[i]; + } + }, + + target: function () { return clamp(9 * (0.45 + 0.55 * rel('rain')), 3.2, BEADS); }, + + spawn: function (i) { + var R = this.rnd; + this.nx[i] = 0.04 + R() * 0.92; + + this.ny[i] = 0.03 + R() * R() * 0.94; + + this.r[i] = (0.5 + R() * R() * 1.1) * (0.86 + 0.14 * rel('rain')); + this.age[i] = 0; + this.life[i] = 9 + R() * 17; + }, + + update: function (dt) { + var d = dt > 0.25 ? 0.25 : dt; + var tgt = this.target(); + + var e = 1 - Math.exp(-d / (tgt > this.want ? 12 : 90)); + this.want += (tgt - this.want) * e; + if (CC.reducedMotion) return; + for (var i = 0; i < this.n; i++) { + this.age[i] += dt; + + if (this.r[i] > 1.0) this.ny[i] += dt * 0.006; + if (this.age[i] > this.life[i] || this.ny[i] > 0.99) this.spawn(i); + } + }, + + cell: function (f, x, y, str) { + var cols = f.cols, rows = f.rows; + if (x < 0 || y < 0 || x >= cols || y >= rows) return; + var i = y * cols + x; + var d = nearer(f.dist[i]); + if (d < 0) return; + var la = f.lum[i], ca = f.col[i]; + var jy = y + 1 < rows ? y + 1 : y - 1; + var j = jy * cols + x; + var lb = f.lum[j], cb = f.col[j]; + var out = (la * 0.42 + lb * 0.44) * str; + var top = la > lb ? la : lb; + if (out < 4.5) { + if (str < 0.9) return; + put(f, x, y, G_DOT, P.ice, 10 + top * 0.08, d, 3); + return; + } + var hue = la >= lb ? ca : cb; + + if (top > 118) { hue = P.ice; out *= 0.74; } + put(f, x, y, out > 46 ? G_O : (out > 16 ? G_o : G_COLON), hue, out, d, 3); + }, + + draw: function (f) { + var cols = f.cols, rows = f.rows; + + if (!(this.want > 0)) this.want = this.target(); + var want = this.want; + for (var i = 0; i < this.n; i++) { + + var edge = want - i; + if (edge <= 0) break; + var str = edge < 1 ? edge : 1; + var x = (this.nx[i] * cols) | 0, y = (this.ny[i] * rows) | 0; + this.cell(f, x, y, str); + + if (this.r[i] > 1.05) this.cell(f, x, y + 1, 0.62 * str); + } + } + }; + + var BSRC = 20; + + var lensbloom = { + name: 'lensbloom', + layer: 95, + + init: function (city, rng) { + this.seed = (rng() * 30011) | 0; + this.bx = new Int32Array(BSRC); this.by = new Int32Array(BSRC); + this.bl = new Int32Array(BSRC); this.bc = new Uint8Array(BSRC); + this.n = 0; + + this.yaw = 0; this.panned = false; this.pan = 0; + }, + + update: function (dt, t, cam) { + if (!cam) return; + var y = cam.yaw || 0; + if (!this.panned) { this.yaw = y; this.panned = true; return; } + var d = y - this.yaw; + + while (d > 3.14159265) d -= 6.28318531; + while (d < -3.14159265) d += 6.28318531; + this.yaw = y; + var rate = dt > 1e-4 ? d / dt : 0; + + var e = 1 - Math.exp(-(dt > 0.25 ? 0.25 : dt) * 3.0); + this.pan += (clamp(rate * 1.1, -1, 1) - this.pan) * e; + }, + + draw: function (f) { + var cols = f.cols, rows = f.rows, x, y, i, k; + var haze = rel('haze'), windy = rel('wind'); + + var halo = clamp(0.14 + 0.18 * haze, 0.10, 0.46); + + var pan = CC.reducedMotion ? this.pan * 0.3 : this.pan; + var reach = 2.2 + 1.5 * haze + 1.2 * windy * (0.4 + 0.6 * (pan < 0 ? -pan : pan)); + var TH = 175; + + var n = 0, bl = this.bl, bx = this.bx, by = this.by, bc = this.bc; + for (y = 1; y < rows - 1; y++) + for (x = 1; x < cols - 1; x++) { + i = y * cols + x; + var l = f.lum[i]; + if (l < TH) continue; + var c = f.col[i]; + if (c === P.slate || c === P.shadow) continue; + + if (f.lum[i - 1] > l || f.lum[i + 1] >= l) continue; + if (f.lum[i - cols] > l || f.lum[i + cols] >= l) continue; + if (n < BSRC) { + k = n++; + } else { + + var worst = 0; + for (k = 1; k < BSRC; k++) if (bl[k] < bl[worst]) worst = k; + if (bl[worst] >= l) continue; + k = worst; + } + bx[k] = x; by[k] = y; bl[k] = l; bc[k] = c; + } + this.n = n; + + for (k = 0; k < n; k++) { + var sx = bx[k], sy = by[k], hue = bc[k]; + var s = clamp((bl[k] - TH) / 70, 0.30, 1); + + var g1 = 1 + halo * s, g2 = 1 + halo * s * 0.45; + gain(f, sx - 1, sy, g1); gain(f, sx + 1, sy, g1); + gain(f, sx, sy - 1, g1); gain(f, sx, sy + 1, g1); + gain(f, sx - 1, sy - 1, g2); gain(f, sx + 1, sy - 1, g2); + gain(f, sx - 1, sy + 1, g2); gain(f, sx + 1, sy + 1, g2); + + for (var side = -1; side <= 1; side += 2) { + var len = reach * s * (side * pan > 0 ? 1.45 : 0.75); + var L = len | 0; + for (var j = 1; j <= L; j++) { + x = sx + side * j; + if (x < 0 || x >= cols) break; + i = sy * cols + x; + var a = (1 - j / (len + 0.6)); + a *= a; + var lum = bl[k] * a * 0.30; + if (lum < 6) break; + + if (f.ch[i] !== 0 && f.lum[i] > lum) continue; + var d = nearer(f.dist[i]); + if (d < 0) continue; + put(f, x, sy, j < 2 ? G_DASH : G_TICK, hue, lum, d, 3); + } + } + } + } + }; + + var exposure = { + name: 'exposure', + layer: 96, + + init: function (city, rng) { + this.phase = rng(); + this.p0 = rng() * 6.2831853; + this.p1 = rng() * 6.2831853; + this.rows = 0; + this.g = null; + this.meas = -1; + this.fast = -1; this.slow = -1; + this.adapt = 1; + }, + + update: function (dt) { + if (this.meas < 0) return; + var d = dt > 0.25 ? 0.25 : dt; + this.fast += (this.meas - this.fast) * (1 - Math.exp(-d / 0.5)); + + var tau = this.meas > this.slow ? 2.5 : 5.0; + this.slow += (this.fast - this.slow) * (1 - Math.exp(-d / tau)); + var f = this.fast, s = this.slow; + if (!(f > 0.01) || !(s > 0.01)) { this.adapt = 1; return; } + + var k = clamp(0.34 - 0.09 * (airDensity() - 1), 0.16, 0.44); + if (CC.reducedMotion) k *= 0.5; + var e = Math.pow(s / f, k); + var lo = CC.reducedMotion ? 0.94 : 0.88, hi = CC.reducedMotion ? 1.05 : 1.11; + this.adapt = e < lo ? lo : (e > hi ? hi : e); + }, + + draw: function (f, cam, t) { + + var n = f.n, lum = f.lum, ch = f.ch, sum = 0, i; + for (i = 0; i < n; i++) if (ch[i] !== 0) sum += lum[i]; + this.meas = sum / n; + if (this.fast < 0) { this.fast = this.meas; this.slow = this.meas; } + + var e = this.adapt; + + if (!CC.reducedMotion) + e *= 1 + 0.020 * Math.sin(t * 0.61 + this.p0) + 0.011 * Math.sin(t * 0.233 + this.p1); + + var cols = f.cols, rows = f.rows, x, y; + if (this.rows !== rows) { this.rows = rows; this.g = new Float32Array(rows); } + var g = this.g; + + var ph = CC.reducedMotion ? this.phase : this.phase + t * 0.040; + + for (y = 0; y < rows; y++) { + var bar = 0.5 + 0.5 * Math.cos((y / rows * 1.6 - ph) * 6.2831853); + g[y] = (1 - 0.070 * (y & 1)) * (1 - 0.026 * bar) * e; + } + for (y = 0; y < rows; y++) { + var gy = g[y]; + if (gy > 0.9975 && gy < 1.0025) continue; + for (x = 0; x < cols; x++) gain(f, x, y, gy); + } + } + }; + + var LIST = [shaft, wash, mistfar, vignette, beads, lensbloom, exposure]; + for (var q = 0; q < LIST.length; q++) CC.ELEMENTS.push(LIST[q]); })(CC); /* src/elements/police.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, hash2 = CC.hash2, put = CC.put; + var P = CC.P, g = CC.g, hash2 = CC.hash2, put = CC.put; - var G_QUOTE = g("'"), G_DASH = g('-'), G_EQ = g('='), - G_8 = g('8'), G_o = g('o'), G_0 = g('0'); + var G_QUOTE = g("'"), G_DASH = g('-'), G_EQ = g('='), + G_8 = g('8'), G_o = g('o'), G_0 = g('0'); - var W_STILL = { rain: 0.65, wind: 0.55, fog: 0.30, wet: 0.90, storm: 0.12, haze: 0.40, - cloud: 0.75, steam: 0.85 }; - function wp() { return CC.Weather ? CC.Weather.P : W_STILL; } - function wrel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } + var W_STILL = { rain: 0.65, wind: 0.55, fog: 0.30, wet: 0.90, storm: 0.12, haze: 0.40, + cloud: 0.75, steam: 0.85 }; + function wp() { return CC.Weather ? CC.Weather.P : W_STILL; } + function wrel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } - var CX = 0, CZ = 0, FWX = 0, FWZ = 1, RGX = 1, RGZ = 0, HP = 0.7, EYE = 1.7; - var COLS = 0, ROWS = 0, HOR = 0, SCALE = 1, CPM = 1; + var CX = 0, CZ = 0, FWX = 0, FWZ = 1, RGX = 1, RGZ = 0, HP = 0.7, EYE = 1.7; + var COLS = 0, ROWS = 0, HOR = 0, SCALE = 1, CPM = 1; - function camBasis(cam) { - var yaw = cam.yaw || 0; - FWX = Math.sin(yaw); FWZ = Math.cos(yaw); - RGX = Math.cos(yaw); RGZ = -Math.sin(yaw); - CX = cam.x; CZ = cam.z; - HP = Math.tan((cam.fov || 1.25) * 0.5); - EYE = cam.eyeY !== undefined ? cam.eyeY : 1.7; + function camBasis(cam) { + var yaw = cam.yaw || 0; + FWX = Math.sin(yaw); FWZ = Math.cos(yaw); + RGX = Math.cos(yaw); RGZ = -Math.sin(yaw); + CX = cam.x; CZ = cam.z; + HP = Math.tan((cam.fov || 1.25) * 0.5); + EYE = cam.eyeY !== undefined ? cam.eyeY : 1.7; + } + + function camScreenAt(cam, cols, rows) { + camBasis(cam); + COLS = cols; ROWS = rows; + HOR = cam.horizon !== undefined ? cam.horizon : ROWS * 0.56; + SCALE = cam.scaleY !== undefined ? cam.scaleY + : (COLS * (cam.cellAspect || 0.5625)) / (2 * HP); + CPM = COLS * 0.5 / HP; + } + function camScreen(frame, cam) { camScreenAt(cam, frame.cols, frame.rows); } + + var PJ = { ok: 0, w: 0, sp: 0, x: 0, dist: 0 }; + + function project(px, pz) { + var dx = px - CX, dz = pz - CZ; + var w = dx * FWX + dz * FWZ; + if (w < 0.45) { PJ.ok = 0; return PJ; } + var sp = (dx * RGX + dz * RGZ) / w; + PJ.ok = 1; PJ.w = w; PJ.sp = sp; + PJ.x = (sp / HP + 1) * COLS * 0.5 - 0.5; + PJ.dist = w * Math.sqrt(1 + sp * sp); + return PJ; + } + function rowOf(y, w) { return HOR - (y - EYE) * SCALE / w; } + + function roadDist(row, sp) { + var den = row + 0.5 - HOR; + if (den < 0.5) return 1e6; + return (EYE * SCALE / den) * Math.sqrt(1 + sp * sp); + } + function fg(lum, dist) { + var S = CC.Surf; + return S ? S.fog(lum, dist) : lum; + } + + function near(d) { return d * 0.994; } + function nearer(d) { return d * 0.982; } + + var COR = { axis: 0, ctr: 0, half: 3.5, along: 0, dir: 1 }; + function corridor(city, cam) { + if (!city || !city.aveX) { + COR.axis = 0; COR.ctr = 0.5; COR.half = 3.5; + COR.along = cam.z; COR.dir = FWZ < 0 ? -1 : 1; + return COR; } - - function camScreenAt(cam, cols, rows) { - camBasis(cam); - COLS = cols; ROWS = rows; - HOR = cam.horizon !== undefined ? cam.horizon : ROWS * 0.56; - SCALE = cam.scaleY !== undefined ? cam.scaleY - : (COLS * (cam.cellAspect || 0.5625)) / (2 * HP); - CPM = COLS * 0.5 / HP; + var k = Math.round(cam.x / city.AVE), m = Math.round(cam.z / city.CROSS); + var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d; + for (i = k - 1; i <= k + 1; i++) { + c = city.aveX(i) + 0.5; d = cam.x - c; if (d < 0) d = -d; + if (d < bA) { bA = d; aC = c; aW = city.aveW(i) + 0.5; } } - function camScreen(frame, cam) { camScreenAt(cam, frame.cols, frame.rows); } - - var PJ = { ok: 0, w: 0, sp: 0, x: 0, dist: 0 }; - - function project(px, pz) { - var dx = px - CX, dz = pz - CZ; - var w = dx * FWX + dz * FWZ; - if (w < 0.45) { PJ.ok = 0; return PJ; } - var sp = (dx * RGX + dz * RGZ) / w; - PJ.ok = 1; PJ.w = w; PJ.sp = sp; - PJ.x = (sp / HP + 1) * COLS * 0.5 - 0.5; - PJ.dist = w * Math.sqrt(1 + sp * sp); - return PJ; + for (i = m - 1; i <= m + 1; i++) { + c = city.crossZ(i) + 0.5; d = cam.z - c; if (d < 0) d = -d; + if (d < bC) { bC = d; cC = c; cW = city.crossW(i) + 0.5; } } - function rowOf(y, w) { return HOR - (y - EYE) * SCALE / w; } - - function roadDist(row, sp) { - var den = row + 0.5 - HOR; - if (den < 0.5) return 1e6; - return (EYE * SCALE / den) * Math.sqrt(1 + sp * sp); + var afz = FWZ < 0 ? -FWZ : FWZ, afx = FWX < 0 ? -FWX : FWX; + if (bC <= cW && (bA > aW || afx > afz)) { + COR.axis = 1; COR.ctr = cC; COR.half = cW; COR.along = cam.x; COR.dir = FWX < 0 ? -1 : 1; + } else { + COR.axis = 0; COR.ctr = aC; COR.half = aW; COR.along = cam.z; COR.dir = FWZ < 0 ? -1 : 1; } - function fg(lum, dist) { - var S = CC.Surf; - return S ? S.fog(lum, dist) : lum; + return COR; + } + + function wX(axis, ctr, a, l) { return axis ? a : ctr + l; } + function wZ(axis, ctr, a, l) { return axis ? ctr + l : a; } + + function carriage() { + var p = COR.half - CC.PAVE; + if (p < 1.7) p = 1.7; + if (p > COR.half * 0.86) p = COR.half * 0.86; + return p; + } + + var BAR_ALT_HZ = 2.2; + var BAR_FLOOR = 0.20; + + var BAR_PEAK_RED = 174, BAR_PEAK_AZURE = 150; + var TAU = 6.283185307179586; + + function barEnv(t, ph) { + + if (CC.reducedMotion) return 0.5; + var u = t * (BAR_ALT_HZ * 0.5) + ph; + return 0.5 - 0.5 * Math.cos(u * TAU); + } + + function barLum(peak, fade, e) { return peak * fade * (BAR_FLOOR + (1 - BAR_FLOOR) * e); } + + var cars = null, CAR_N = 2, PARKED = 0, CRUISER = 1; + + var BAR_COLS_MAX = 15; + + var CAR_FADE_AT = 0.020, CAR_HIDE_AT = 0.048; + + var BX0 = 0, BR0 = 0, BD0 = 0, BX1 = 0, BR1 = 0, BD1 = 0, BDN = 0, BOK = 0; + + var CROSS_NEAR = 14, CROSS_FAR = 40; + function crossAhead(city, pick) { + if (!city || !city.aveX) return NaN; + var period = COR.axis ? city.AVE : city.CROSS; + var i0 = Math.round(COR.along / period), i, c, dd, cnt = 0, want; + for (i = i0 - 4; i <= i0 + 4; i++) { + c = (COR.axis ? city.aveX(i) : city.crossZ(i)) + 0.5; + dd = (c - COR.along) * COR.dir; + if (dd >= CROSS_NEAR && dd <= CROSS_FAR) cnt++; } + if (!cnt) return NaN; + want = (pick * cnt) | 0; if (want >= cnt) want = cnt - 1; + for (i = i0 - 4; i <= i0 + 4; i++) { + c = (COR.axis ? city.aveX(i) : city.crossZ(i)) + 0.5; + dd = (c - COR.along) * COR.dir; + if (dd >= CROSS_NEAR && dd <= CROSS_FAR) { if (want === 0) return c; want--; } + } + return NaN; + } + function crossHalf(city, c) { + if (!city || !city.aveX) return 2.0; + var period = COR.axis ? city.AVE : city.CROSS; + var i = Math.round((c - 0.5) / period); + return (COR.axis ? city.aveW(i) : city.crossW(i)) + 0.5; + } - function near(d) { return d * 0.994; } - function nearer(d) { return d * 0.982; } + function carCover(c) { + var hx = c.hx, hz = c.hz, lx = -hz, lz = hx; + var hw = c.wid * 0.5, hl = c.len * 0.5; + var x0 = 1e9, x1 = -1e9, wmin = 1e9, k, sx, sz, pr; + for (k = 0; k < 4; k++) { + sx = c.x + hx * (k < 2 ? hl : -hl) + lx * ((k & 1) ? hw : -hw); + sz = c.z + hz * (k < 2 ? hl : -hl) + lz * ((k & 1) ? hw : -hw); + pr = project(sx, sz); + if (!pr.ok) return 1; + if (pr.x < x0) x0 = pr.x; + if (pr.x > x1) x1 = pr.x; + if (pr.w < wmin) wmin = pr.w; + } + if (x0 < 0) x0 = 0; + if (x1 > COLS - 1) x1 = COLS - 1; + if (x1 <= x0) return 0; + var rr = (c.tall + 0.35) * SCALE / wmin; + if (rr > ROWS) rr = ROWS; + return (x1 - x0) * rr / (COLS * ROWS); + } - var COR = { axis: 0, ctr: 0, half: 3.5, along: 0, dir: 1 }; - function corridor(city, cam) { - if (!city || !city.aveX) { - COR.axis = 0; COR.ctr = 0.5; COR.half = 3.5; - COR.along = cam.z; COR.dir = FWZ < 0 ? -1 : 1; - return COR; + var CAR_SLICES_MIN = 6, CAR_SLICES_MAX = 72; + + var ROOF_READ_D = 26; + function carBody(f, c, fade, S) { + var hx = c.hx, hz = c.hz, lx = -hz, lz = hx; + var hw = c.wid * 0.5, hl = c.len * 0.5, i, j, r; + var pn0 = project(c.x + hx * hl, c.z + hz * hl); + var sp0 = pn0.ok ? pn0.x : 0, ok0 = pn0.ok; + var pn1 = project(c.x - hx * hl, c.z - hz * hl); + var lspan = (ok0 && pn1.ok) ? (pn1.x - sp0) : 0; + if (lspan < 0) lspan = -lspan; + var NS = (lspan + 2) | 0; + if (NS < CAR_SLICES_MIN) NS = CAR_SLICES_MIN; + if (NS > CAR_SLICES_MAX) NS = CAR_SLICES_MAX; + for (i = 0; i < NS; i++) { + var s = ((i + 0.5) / NS - 0.5) * c.len; + var mx = c.x + hx * s, mz = c.z + hz * s; + var pa = project(mx + lx * hw, mz + lz * hw); if (!pa.ok) continue; + var xa = pa.x; + var pb = project(mx - lx * hw, mz - lz * hw); if (!pb.ok) continue; + var xb = pb.x; + var pc = project(mx, mz); if (!pc.ok) continue; + var w = pc.w, d = near(pc.dist), dd = pc.dist; + + var cab = s > -c.cab && s < c.cab; + var rT = rowOf(cab ? c.tall + 0.30 : c.tall, w), rB = rowOf(0.04, w); + var x0 = Math.round(xa < xb ? xa : xb), x1 = Math.round(xa < xb ? xb : xa); + if (x1 < 0 || x0 > COLS - 1) continue; + var span = xb - xa; + if (x0 < 0) x0 = 0; + if (x1 > COLS - 1) x1 = COLS - 1; + var r0 = Math.round(rT), r1 = Math.round(rB); + if (r1 < r0) r1 = r0; + if (r0 < 0) r0 = 0; + if (r1 > ROWS - 1) r1 = ROWS - 1; + + var si = (((s / c.len) + 0.5) * 16) | 0; + for (j = x0; j <= x1; j++) { + var q = fade < 1 ? (((j - xa) / (span === 0 ? 1 : span) * 12) | 0) : 0; + for (r = r0; r <= r1; r++) { + if (fade < 1 && hash2(si * 16 + q, r - r0, S + 1601) > fade) continue; + put(f, j, r, 0, P.shadow, 0, d); } - var k = Math.round(cam.x / city.AVE), m = Math.round(cam.z / city.CROSS); - var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d; - for (i = k - 1; i <= k + 1; i++) { - c = city.aveX(i) + 0.5; d = cam.x - c; if (d < 0) d = -d; - if (d < bA) { bA = d; aC = c; aW = city.aveW(i) + 0.5; } + } + + if (dd <= ROOF_READ_D) { + var rl = fg(cab ? 172 : 148, dd); + if (rl >= 5) + for (j = x0; j <= x1; j++) { + var rq = fade < 1 ? (((j - xa) / (span === 0 ? 1 : span) * 12) | 0) : 0; + if (fade < 1 && hash2(si * 16 + rq, 0, S + 1601) > fade) continue; + put(f, j, r0, G_DASH, P.amber, rl, nearer(dd)); + } + } + } + } + + function barEnds(c) { + var hx = c.hx, hz = c.hz, lx = -hz, lz = hx; + var hw = c.wid * 0.5 * 0.86, hl = c.len * 0.13; + var y = c.tall + 0.22; + BOK = 0; + var pa = project(c.x + lx * hw, c.z + lz * hw); if (!pa.ok) return; + var ax1 = pa.x, aw1 = pa.w, ad1 = pa.dist; + var pb = project(c.x - lx * hw, c.z - lz * hw); if (!pb.ok) return; + var bx1 = pb.x, bw1 = pb.w, bd1 = pb.dist; + var pc = project(c.x + hx * hl, c.z + hz * hl); if (!pc.ok) return; + var ax2 = pc.x, aw2 = pc.w, ad2 = pc.dist; + var pd = project(c.x - hx * hl, c.z - hz * hl); if (!pd.ok) return; + var bx2 = pd.x, bw2 = pd.w, bd2 = pd.dist; + + var hl2 = c.len * 0.5, k, dn = 1e9, pe; + for (k = 0; k < 4; k++) { + pe = project(c.x + hx * (k < 2 ? hl2 : -hl2) + lx * ((k & 1) ? hw : -hw), + c.z + hz * (k < 2 ? hl2 : -hl2) + lz * ((k & 1) ? hw : -hw)); + if (pe.ok && pe.dist < dn) dn = pe.dist; + } + BDN = dn < 1e8 ? dn : ad1; + var s1 = ax1 - bx1; if (s1 < 0) s1 = -s1; + var s2 = ax2 - bx2; if (s2 < 0) s2 = -s2; + if (s1 >= s2) { + BX0 = ax1; BR0 = rowOf(y, aw1); BD0 = ad1; + BX1 = bx1; BR1 = rowOf(y, bw1); BD1 = bd1; + } else { + BX0 = ax2; BR0 = rowOf(y, aw2); BD0 = ad2; + BX1 = bx2; BR1 = rowOf(y, bw2); BD1 = bd2; + } + BOK = 1; + } + + function lightbar(f, c, fade, t) { + barEnds(c); + if (!BOK) return; + var e = barEnv(t, c.ph); + var lo = BX0 < BX1 ? BX0 : BX1, hi = BX0 < BX1 ? BX1 : BX0; + var ctr = (lo + hi) * 0.5; + + if (hi - lo > BAR_COLS_MAX) { lo = ctr - BAR_COLS_MAX * 0.5; hi = ctr + BAR_COLS_MAX * 0.5; } + var j0 = Math.round(lo), j1 = Math.round(hi); + if (j1 < 0 || j0 > COLS - 1) return; + if (j0 < 0) j0 = 0; + if (j1 > COLS - 1) j1 = COLS - 1; + var dx = BX1 - BX0, j; + for (j = j0; j <= j1; j++) { + var u = dx === 0 ? 0.5 : (j - BX0) / dx; + if (u < 0) u = 0; else if (u > 1) u = 1; + var row = Math.round(BR0 + (BR1 - BR0) * u); + var dd = BD0 + (BD1 - BD0) * u; + var red = u < 0.5; + + var lum = fg(barLum(red ? BAR_PEAK_RED : BAR_PEAK_AZURE, fade, red ? e : 1 - e), dd); + if (lum < 5) continue; + + put(f, j, row, G_8, red ? P.red : P.azure, lum, nearer(BDN)); + } + } + + var WASH_ROWS = 2, WASH_COLS_MAX = 11, WASH_REACH = 3.4, WASH_D_MAX = 26; + function washRoad(f, c, fade, t, wetR) { + var e = barEnv(t, c.ph); + var hx = c.hx, hz = c.hz, lx = -hz, lz = hx; + + var out = c.out; + var pc = project(c.x, c.z); if (!pc.ok) return; + var baseRow = Math.round(rowOf(0, pc.w)); + + var pn = project(c.x + lx * out * (c.wid * 0.5 + 0.3), c.z + lz * out * (c.wid * 0.5 + 0.3)); + if (!pn.ok) return; + var xc = pn.x; + var pf = project(c.x + lx * out * WASH_REACH, c.z + lz * out * WASH_REACH); if (!pf.ok) return; + var xf = pf.x; + + if (xf > xc + WASH_COLS_MAX) xf = xc + WASH_COLS_MAX; + else if (xf < xc - WASH_COLS_MAX) xf = xc - WASH_COLS_MAX; + var lo = xc < xf ? xc : xf, hi = xc < xf ? xf : xc; + var j0 = Math.round(lo), j1 = Math.round(hi), j, r; + if (j1 < 0 || j0 > COLS - 1) return; + if (j0 < 0) j0 = 0; + if (j1 > COLS - 1) j1 = COLS - 1; + var halfC = COLS * 0.5; + for (r = 0; r < WASH_ROWS; r++) { + var row = baseRow + r; + if (row < 0 || row > ROWS - 1) continue; + + var den = row + 0.5 - HOR; + if (den < 0.5) continue; + var w = EYE * SCALE / den; + for (j = j0; j <= j1; j++) { + + var sp = ((j + 0.5) / halfC - 1) * HP; + var pxw = CX + (FWX + sp * RGX) * w, pzw = CZ + (FWZ + sp * RGZ) * w; + var ddx = pxw - c.x, ddz = pzw - c.z; + var dd2 = Math.sqrt(ddx * ddx + ddz * ddz); + if (dd2 > WASH_REACH) continue; + var fall = 1 - dd2 * 0.05; + var key = (Math.floor(pxw * 1.15) + Math.floor(pzw * 1.15)) % 3; + if (key < 0) key += 3; + var red = key === 0; + var rd = w * Math.sqrt(1 + sp * sp); + + var lum = fg((red ? 150 : 112) * fall * (0.62 + 0.38 * wetR) * fade * + (0.66 + 0.34 * (red ? e : 1 - e)), rd); + if (lum < 5) continue; + put(f, j, row, r === 0 ? G_EQ : G_DASH, red ? P.red : P.azure, lum, near(rd)); + } + } + } + + function carLamps(f, c, wetR) { + var hx = c.hx, hz = c.hz; + var hl = c.len * 0.5; + var pn = project(c.x + hx * hl, c.z + hz * hl); if (!pn.ok) return; + var xn = pn.x, wn = pn.w, dn = pn.dist; + var pt = project(c.x - hx * hl, c.z - hz * hl); if (!pt.ok) return; + var xt = pt.x, wt = pt.w, dtl = pt.dist, spt = pt.sp; + var back = xn > xt ? -1 : 1; + var hl2 = fg(236, dn), tl = fg(188, dtl); + var rHl = Math.round(rowOf(0.62, wn)), rTl = Math.round(rowOf(0.78, wt)); + if (hl2 >= 5) { + put(f, Math.round(xn), rHl, G_0, P.ice, hl2, nearer(dn)); + put(f, Math.round(xn) + back, rHl, G_o, P.ice, hl2 * 0.46, nearer(dn)); + } + if (tl >= 5) { + put(f, Math.round(xt), rTl, G_o, P.red, tl, nearer(dtl)); + + put(f, Math.round(xt) + back, rTl, G_o, P.red, tl * 0.44, nearer(dtl)); + + var rr0 = Math.round(rowOf(0, wt)) + 1; + var rd = roadDist(rr0, spt); + var rl = fg(66 * (0.55 + 0.45 * wetR), rd); + if (rl >= 5) put(f, Math.round(xt), rr0, G_QUOTE, P.red, rl, near(rd)); + } + } + + var offs = null, OFF_N = 3; + var OFF_COVER_MAX = 0.030; + + function offCover(o, pr) { + var shw = offShoulder(pr.w); + var xw = shw * 1.34; + var x0 = pr.x - xw, x1 = pr.x + xw; + if (x0 < 0) x0 = 0; + if (x1 > COLS - 1) x1 = COLS - 1; + if (x1 <= x0) return 0; + var rr = o.tall * SCALE / pr.w; + if (rr > ROWS) rr = ROWS; + return (x1 - x0) * rr / (COLS * ROWS); + } + + function offShoulder(w) { + var shw = 0.29 * CPM / w; + return shw < 0.5 ? 0.5 : shw; + } + + function offSpawn(o, i, S, fresh, city, car) { + o.n++; + var n = o.n; + + var h1 = hash2(i, n, S + 101), h2 = hash2(i, n, S + 211), h3 = hash2(i, n, S + 307), + h4 = hash2(i, n, S + 401), h5 = hash2(i, n, S + 503), h6 = hash2(i, n, S + 601), + h7 = hash2(i, n, S + 701), h8 = hash2(i, n, S + 809), h9 = hash2(i, n, S + 907); + + var cw = carriage(); + var a, l, side; + o.chk = 0; + var atCar = car && car.live && car.chk && h1 < 0.78; + if (atCar) { + + a = (car.axis ? car.x : car.z) + (h2 - 0.5) * 5.6; + l = car.lat - (car.lat < 0 ? -1 : 1) * (0.9 + h3 * 1.5); + side = car.lat < 0 ? -1 : 1; + o.vx = 0; o.vz = 0; + o.chk = 1; + o.axis = car.axis; o.ctr = car.ctr; + } else { + + if (i === 2) { o.live = 0; o.wait = 6 + h4 * 14; return; } + + var band = COR.half - cw - 0.7; + if (band < 0.2) band = 0.2; + side = h2 < 0.5 ? -1 : 1; + a = COR.along + COR.dir * (fresh ? 9 + h3 * 22 : 30 + h3 * 12); + l = side * (cw + 0.35 + h4 * band); + + if (h5 < 0.66) { + var sp = (1.02 + h6 * 0.26) * (1 - 0.14 * wp().rain); + var go = (h7 < 0.55 ? -1 : 1) * COR.dir; + o.vx = COR.axis ? go * sp : 0; + o.vz = COR.axis ? 0 : go * sp; + } else { o.vx = 0; o.vz = 0; } + o.axis = COR.axis; o.ctr = COR.ctr; + } + o.x = wX(o.axis, o.ctr, a, l); o.z = wZ(o.axis, o.ctr, a, l); + o.lat = l; + o.tall = 1.74 + h8 * 0.12; + o.walked = 0; + + o.phase = hash2(i, n, S + 1013) * TAU; + o.side = h9 < 0.5 ? -1 : 1; + + o.rim = hash2(i, n, S + 1117) < 0.74 ? P.amber : P.azure; + + var h12 = hash2(i, n, S + 1301); + o.acc = h12 < 0.42 ? 0 : (h12 < 0.74 ? 1 : 2); + o.live = 1; + } + + function offGone(o) { + var pro = project(o.x, o.z); + if (!pro.ok || pro.w > 70 || pro.sp > HP * 1.8 || pro.sp < -HP * 1.8) return 1; + + return offCover(o, pro) > OFF_COVER_MAX ? 1 : 0; + } + + function offSettle(o, i, S, city, park) { + var tries = 0; + do { + + offSpawn(o, i, S, 1, city, park); + tries++; + } while (o.live && offGone(o) && tries < 8); + if (o.live && offGone(o)) o.live = 0; + } + + var OFF_DRAW_D = 26; + + function drawOfficer(f, o, i, S, bareLit) { + var pr = project(o.x, o.z); + if (!pr.ok || pr.dist > OFF_DRAW_D) return; + var w = pr.w, dist = pr.dist, d = near(dist), cx = pr.x; + var rFeet = rowOf(0, w), rHead = rowOf(o.tall, w); + var tallRows = rFeet - rHead; + if (tallRows < 2.2) return; + if (offCover(o, pr) > OFF_COVER_MAX * 2) return; + var shw = offShoulder(w); + var x0 = Math.round(cx - shw * 1.34), x1 = Math.round(cx + shw * 1.34); + if (x1 < 0 || x0 > COLS - 1) return; + if (x0 < 0) x0 = 0; + if (x1 > COLS - 1) x1 = COLS - 1; + + var st = CC.reducedMotion ? 0 : Math.sin(o.walked * 3.4 + o.phase); + + var rim = fg(148 + hash2(i, o.n, S + 5) * 22, dist); + + if (bareLit >= 0) rim *= 0.88 + 0.12 * bareLit; + var x, v0, v1, q; + for (x = x0; x <= x1; x++) { + var u = (x - cx) / shw, au = u < 0 ? -u : u; + v0 = 9; v1 = -9; + if (au <= 1.0) { + + v0 = au > 0.44 ? 0.145 : 0; + v1 = au > 0.66 ? 0.60 : 1; + + if (au < 0.36 && tallRows > 6) { + var lg = (u < 0 ? -1 : 1) * st; + if (lg > 0.30) v1 = 0.95; + else if (lg < -0.30) v1 = 0.87; } - for (i = m - 1; i <= m + 1; i++) { - c = city.crossZ(i) + 0.5; d = cam.z - c; if (d < 0) d = -d; - if (d < bC) { bC = d; cC = c; cW = city.crossW(i) + 0.5; } + } + + if (au > 0.44 && au <= 1.34) { + if (0.055 < v0) v0 = 0.055; + if (0.115 > v1) v1 = 0.115; + } + if (v1 < v0) continue; + var rt = rHead + v0 * tallRows, rb = rHead + v1 * tallRows; + var r0 = Math.round(rt), r1 = Math.round(rb); + if (r1 < r0) r1 = r0; + if (r0 < 0) r0 = 0; + if (r1 > ROWS - 1) r1 = ROWS - 1; + for (q = r0; q <= r1; q++) put(f, x, q, 0, P.shadow, 0, d); + if (rim >= 5) { + + var rl = au < 0.44 ? 1 : (au <= 1.0 ? 0.90 : 0.95); + put(f, x, r0, au < 0.44 ? G_o : G_DASH, o.rim, rim * rl, nearer(dist)); + } + } + if (rim < 5) return; + + if (tallRows > 8) { + var rx = Math.round(cx + o.side * shw); + for (q = 1; q <= 2; q++) + put(f, rx, Math.round(rHead + q + 1), G_QUOTE, o.rim, rim * (q === 1 ? 0.96 : 0.88), + nearer(dist)); + } + + if (tallRows > 4) { + if (o.acc === 0) { + + var a1 = fg(168, dist); + if (a1 >= 5) { + var by = Math.round(rHead + tallRows * 0.30); + put(f, Math.round(cx - shw * 0.5), by, G_DASH, P.spring, a1, nearer(dist)); + + put(f, Math.round(cx + shw * 0.5), by, G_DASH, P.spring, a1 * 0.90, nearer(dist)); } - var afz = FWZ < 0 ? -FWZ : FWZ, afx = FWX < 0 ? -FWX : FWX; - if (bC <= cW && (bA > aW || afx > afz)) { - COR.axis = 1; COR.ctr = cC; COR.half = cW; COR.along = cam.x; COR.dir = FWX < 0 ? -1 : 1; + } else if (o.acc === 1) { + + var a2 = fg(112, dist); + if (a2 >= 5) + put(f, Math.round(cx), Math.round(rHead + tallRows * 0.075), G_DASH, P.azure, a2, + nearer(dist)); + } else { + + var a3 = fg(150, dist); + if (a3 >= 5) + put(f, Math.round(cx + o.side * shw * 0.9), Math.round(rHead + tallRows * 0.17), + G_o, P.ice, a3, nearer(dist)); + } + } + + } + + CC.ELEMENTS.push({ + name: 'police', + + world: 'cyber', + layer: 25, + init: function (city, rng, dims) { + this.city = city; + + this.seed = (rng() * 30011) | 0; + this.boot = 0; + this.settled = 0; + this.warm = 0; + + this.cols = dims && dims.cols ? dims.cols : 200; + this.rows = dims && dims.rows ? dims.rows : 60; + var i; + cars = new Array(CAR_N); + for (i = 0; i < CAR_N; i++) + cars[i] = { x: 0, z: 0, hx: 0, hz: 1, vx: 0, vz: 0, live: 0, wait: 4 + i * 9, n: i * 67, + len: 4.4, wid: 1.85, tall: 1.42, cab: 1.0, ph: i * 0.37, chk: 0, + lat: 0, wl: 0, out: 1, go: 1, chalf: 2, axis: 0, ctr: 0, fade: 1 }; + offs = new Array(OFF_N); + for (i = 0; i < OFF_N; i++) + offs[i] = { x: 0, z: 0, vx: 0, vz: 0, live: 0, wait: 2 + i * 5, n: i * 83, + tall: 1.78, walked: 0, phase: 0, side: 1, rim: P.amber, acc: 0, chk: 0, + lat: 0, axis: 0, ctr: 0 }; + }, + + update: function (dt, t, cam) { + + camScreenAt(cam, this.cols, this.rows); + var city = this.city; + corridor(city, cam); + var S = this.seed, i; + + var k = CC.reducedMotion ? 0 : 1; + + if (!this.boot) { + + this.boot = 1; + for (i = 0; i < OFF_N; i++) offs[i].wait = 1.5 + i * 4.5; + } + + for (i = 0; i < CAR_N; i++) { + var c = cars[i]; + + var now = 0; + if (c.live) { + c.x += c.vx * dt * k; c.z += c.vz * dt * k; + var cov = carCover(c); + var pr = project(c.x, c.z); + var gone = 0; + if (!pr.ok || pr.w > 78) gone = 1; + if (i === PARKED) { + + if (cov > CAR_HIDE_AT) gone = 1; + if (pr.sp > HP * 2.4 || pr.sp < -HP * 2.4) gone = 1; + c.fade = cov <= CAR_FADE_AT ? 1 + : (CAR_HIDE_AT - cov) / (CAR_HIDE_AT - CAR_FADE_AT); + if (c.fade < 0) c.fade = 0; + } else { + + var l = (c.axis ? c.z - c.ctr : c.x - c.ctr); + if (l * c.go > c.chalf + 11) gone = 1; + if (cov > CAR_HIDE_AT * 1.6) gone = 1; + c.fade = 1; + } + if (gone) { + c.live = 0; + + c.wait = i === PARKED ? 9 + hash2(i, c.n, S + 1409) * 17 + : (14 + hash2(i, c.n, S + 1511) * 26); + if (CC.reducedMotion && i === PARKED) now = 1; + } + if (!now) continue; + } else if (CC.reducedMotion) { + + if (i === PARKED && !this.settled) now = 1; + if (!now) continue; } else { - COR.axis = 0; COR.ctr = aC; COR.half = aW; COR.along = cam.z; COR.dir = FWZ < 0 ? -1 : 1; + c.wait -= dt * (i === PARKED ? 1 : k); + if (c.wait > 0) continue; } - return COR; - } - - function wX(axis, ctr, a, l) { return axis ? a : ctr + l; } - function wZ(axis, ctr, a, l) { return axis ? ctr + l : a; } - - function carriage() { - var p = COR.half - CC.PAVE; - if (p < 1.7) p = 1.7; - if (p > COR.half * 0.86) p = COR.half * 0.86; - return p; - } - - var BAR_ALT_HZ = 2.2; - var BAR_FLOOR = 0.20; - - var BAR_PEAK_RED = 174, BAR_PEAK_AZURE = 150; - var TAU = 6.283185307179586; - - function barEnv(t, ph) { - - if (CC.reducedMotion) return 0.5; - var u = t * (BAR_ALT_HZ * 0.5) + ph; - return 0.5 - 0.5 * Math.cos(u * TAU); - } - - function barLum(peak, fade, e) { return peak * fade * (BAR_FLOOR + (1 - BAR_FLOOR) * e); } - - var cars = null, CAR_N = 2, PARKED = 0, CRUISER = 1; - - var BAR_COLS_MAX = 15; - - var CAR_FADE_AT = 0.020, CAR_HIDE_AT = 0.048; - - var BX0 = 0, BR0 = 0, BD0 = 0, BX1 = 0, BR1 = 0, BD1 = 0, BDN = 0, BOK = 0; - - var CROSS_NEAR = 14, CROSS_FAR = 40; - function crossAhead(city, pick) { - if (!city || !city.aveX) return NaN; - var period = COR.axis ? city.AVE : city.CROSS; - var i0 = Math.round(COR.along / period), i, c, dd, cnt = 0, want; - for (i = i0 - 4; i <= i0 + 4; i++) { - c = (COR.axis ? city.aveX(i) : city.crossZ(i)) + 0.5; - dd = (c - COR.along) * COR.dir; - if (dd >= CROSS_NEAR && dd <= CROSS_FAR) cnt++; - } - if (!cnt) return NaN; - want = (pick * cnt) | 0; if (want >= cnt) want = cnt - 1; - for (i = i0 - 4; i <= i0 + 4; i++) { - c = (COR.axis ? city.aveX(i) : city.crossZ(i)) + 0.5; - dd = (c - COR.along) * COR.dir; - if (dd >= CROSS_NEAR && dd <= CROSS_FAR) { if (want === 0) return c; want--; } - } - return NaN; - } - function crossHalf(city, c) { - if (!city || !city.aveX) return 2.0; - var period = COR.axis ? city.AVE : city.CROSS; - var i = Math.round((c - 0.5) / period); - return (COR.axis ? city.aveW(i) : city.crossW(i)) + 0.5; - } - - function carCover(c) { - var hx = c.hx, hz = c.hz, lx = -hz, lz = hx; - var hw = c.wid * 0.5, hl = c.len * 0.5; - var x0 = 1e9, x1 = -1e9, wmin = 1e9, k, sx, sz, pr; - for (k = 0; k < 4; k++) { - sx = c.x + hx * (k < 2 ? hl : -hl) + lx * ((k & 1) ? hw : -hw); - sz = c.z + hz * (k < 2 ? hl : -hl) + lz * ((k & 1) ? hw : -hw); - pr = project(sx, sz); - if (!pr.ok) return 1; - if (pr.x < x0) x0 = pr.x; - if (pr.x > x1) x1 = pr.x; - if (pr.w < wmin) wmin = pr.w; - } - if (x0 < 0) x0 = 0; - if (x1 > COLS - 1) x1 = COLS - 1; - if (x1 <= x0) return 0; - var rr = (c.tall + 0.35) * SCALE / wmin; - if (rr > ROWS) rr = ROWS; - return (x1 - x0) * rr / (COLS * ROWS); - } - - var CAR_SLICES_MIN = 6, CAR_SLICES_MAX = 72; - - var ROOF_READ_D = 26; - function carBody(f, c, fade, S) { - var hx = c.hx, hz = c.hz, lx = -hz, lz = hx; - var hw = c.wid * 0.5, hl = c.len * 0.5, i, j, r; - var pn0 = project(c.x + hx * hl, c.z + hz * hl); - var sp0 = pn0.ok ? pn0.x : 0, ok0 = pn0.ok; - var pn1 = project(c.x - hx * hl, c.z - hz * hl); - var lspan = (ok0 && pn1.ok) ? (pn1.x - sp0) : 0; - if (lspan < 0) lspan = -lspan; - var NS = (lspan + 2) | 0; - if (NS < CAR_SLICES_MIN) NS = CAR_SLICES_MIN; - if (NS > CAR_SLICES_MAX) NS = CAR_SLICES_MAX; - for (i = 0; i < NS; i++) { - var s = ((i + 0.5) / NS - 0.5) * c.len; - var mx = c.x + hx * s, mz = c.z + hz * s; - var pa = project(mx + lx * hw, mz + lz * hw); if (!pa.ok) continue; - var xa = pa.x; - var pb = project(mx - lx * hw, mz - lz * hw); if (!pb.ok) continue; - var xb = pb.x; - var pc = project(mx, mz); if (!pc.ok) continue; - var w = pc.w, d = near(pc.dist), dd = pc.dist; - - var cab = s > -c.cab && s < c.cab; - var rT = rowOf(cab ? c.tall + 0.30 : c.tall, w), rB = rowOf(0.04, w); - var x0 = Math.round(xa < xb ? xa : xb), x1 = Math.round(xa < xb ? xb : xa); - if (x1 < 0 || x0 > COLS - 1) continue; - var span = xb - xa; - if (x0 < 0) x0 = 0; - if (x1 > COLS - 1) x1 = COLS - 1; - var r0 = Math.round(rT), r1 = Math.round(rB); - if (r1 < r0) r1 = r0; - if (r0 < 0) r0 = 0; - if (r1 > ROWS - 1) r1 = ROWS - 1; - - var si = (((s / c.len) + 0.5) * 16) | 0; - for (j = x0; j <= x1; j++) { - var q = fade < 1 ? (((j - xa) / (span === 0 ? 1 : span) * 12) | 0) : 0; - for (r = r0; r <= r1; r++) { - if (fade < 1 && hash2(si * 16 + q, r - r0, S + 1601) > fade) continue; - put(f, j, r, 0, P.shadow, 0, d); - } - } - - if (dd <= ROOF_READ_D) { - var rl = fg(cab ? 172 : 148, dd); - if (rl >= 5) - for (j = x0; j <= x1; j++) { - var rq = fade < 1 ? (((j - xa) / (span === 0 ? 1 : span) * 12) | 0) : 0; - if (fade < 1 && hash2(si * 16 + rq, 0, S + 1601) > fade) continue; - put(f, j, r0, G_DASH, P.amber, rl, nearer(dd)); - } - } - } - } - - function barEnds(c) { - var hx = c.hx, hz = c.hz, lx = -hz, lz = hx; - var hw = c.wid * 0.5 * 0.86, hl = c.len * 0.13; - var y = c.tall + 0.22; - BOK = 0; - var pa = project(c.x + lx * hw, c.z + lz * hw); if (!pa.ok) return; - var ax1 = pa.x, aw1 = pa.w, ad1 = pa.dist; - var pb = project(c.x - lx * hw, c.z - lz * hw); if (!pb.ok) return; - var bx1 = pb.x, bw1 = pb.w, bd1 = pb.dist; - var pc = project(c.x + hx * hl, c.z + hz * hl); if (!pc.ok) return; - var ax2 = pc.x, aw2 = pc.w, ad2 = pc.dist; - var pd = project(c.x - hx * hl, c.z - hz * hl); if (!pd.ok) return; - var bx2 = pd.x, bw2 = pd.w, bd2 = pd.dist; - - var hl2 = c.len * 0.5, k, dn = 1e9, pe; - for (k = 0; k < 4; k++) { - pe = project(c.x + hx * (k < 2 ? hl2 : -hl2) + lx * ((k & 1) ? hw : -hw), - c.z + hz * (k < 2 ? hl2 : -hl2) + lz * ((k & 1) ? hw : -hw)); - if (pe.ok && pe.dist < dn) dn = pe.dist; - } - BDN = dn < 1e8 ? dn : ad1; - var s1 = ax1 - bx1; if (s1 < 0) s1 = -s1; - var s2 = ax2 - bx2; if (s2 < 0) s2 = -s2; - if (s1 >= s2) { - BX0 = ax1; BR0 = rowOf(y, aw1); BD0 = ad1; - BX1 = bx1; BR1 = rowOf(y, bw1); BD1 = bd1; - } else { - BX0 = ax2; BR0 = rowOf(y, aw2); BD0 = ad2; - BX1 = bx2; BR1 = rowOf(y, bw2); BD1 = bd2; - } - BOK = 1; - } - - function lightbar(f, c, fade, t) { - barEnds(c); - if (!BOK) return; - var e = barEnv(t, c.ph); - var lo = BX0 < BX1 ? BX0 : BX1, hi = BX0 < BX1 ? BX1 : BX0; - var ctr = (lo + hi) * 0.5; - - if (hi - lo > BAR_COLS_MAX) { lo = ctr - BAR_COLS_MAX * 0.5; hi = ctr + BAR_COLS_MAX * 0.5; } - var j0 = Math.round(lo), j1 = Math.round(hi); - if (j1 < 0 || j0 > COLS - 1) return; - if (j0 < 0) j0 = 0; - if (j1 > COLS - 1) j1 = COLS - 1; - var dx = BX1 - BX0, j; - for (j = j0; j <= j1; j++) { - var u = dx === 0 ? 0.5 : (j - BX0) / dx; - if (u < 0) u = 0; else if (u > 1) u = 1; - var row = Math.round(BR0 + (BR1 - BR0) * u); - var dd = BD0 + (BD1 - BD0) * u; - var red = u < 0.5; - - var lum = fg(barLum(red ? BAR_PEAK_RED : BAR_PEAK_AZURE, fade, red ? e : 1 - e), dd); - if (lum < 5) continue; - - put(f, j, row, G_8, red ? P.red : P.azure, lum, nearer(BDN)); - } - } - - var WASH_ROWS = 2, WASH_COLS_MAX = 11, WASH_REACH = 3.4, WASH_D_MAX = 26; - function washRoad(f, c, fade, t, wetR) { - var e = barEnv(t, c.ph); - var hx = c.hx, hz = c.hz, lx = -hz, lz = hx; - - var out = c.out; - var pc = project(c.x, c.z); if (!pc.ok) return; - var baseRow = Math.round(rowOf(0, pc.w)); - - var pn = project(c.x + lx * out * (c.wid * 0.5 + 0.3), c.z + lz * out * (c.wid * 0.5 + 0.3)); - if (!pn.ok) return; - var xc = pn.x; - var pf = project(c.x + lx * out * WASH_REACH, c.z + lz * out * WASH_REACH); if (!pf.ok) return; - var xf = pf.x; - - if (xf > xc + WASH_COLS_MAX) xf = xc + WASH_COLS_MAX; - else if (xf < xc - WASH_COLS_MAX) xf = xc - WASH_COLS_MAX; - var lo = xc < xf ? xc : xf, hi = xc < xf ? xf : xc; - var j0 = Math.round(lo), j1 = Math.round(hi), j, r; - if (j1 < 0 || j0 > COLS - 1) return; - if (j0 < 0) j0 = 0; - if (j1 > COLS - 1) j1 = COLS - 1; - var halfC = COLS * 0.5; - for (r = 0; r < WASH_ROWS; r++) { - var row = baseRow + r; - if (row < 0 || row > ROWS - 1) continue; - - var den = row + 0.5 - HOR; - if (den < 0.5) continue; - var w = EYE * SCALE / den; - for (j = j0; j <= j1; j++) { - - var sp = ((j + 0.5) / halfC - 1) * HP; - var pxw = CX + (FWX + sp * RGX) * w, pzw = CZ + (FWZ + sp * RGZ) * w; - var ddx = pxw - c.x, ddz = pzw - c.z; - var dd2 = Math.sqrt(ddx * ddx + ddz * ddz); - if (dd2 > WASH_REACH) continue; - var fall = 1 - dd2 * 0.05; - var key = (Math.floor(pxw * 1.15) + Math.floor(pzw * 1.15)) % 3; - if (key < 0) key += 3; - var red = key === 0; - var rd = w * Math.sqrt(1 + sp * sp); - - var lum = fg((red ? 150 : 112) * fall * (0.62 + 0.38 * wetR) * fade * - (0.66 + 0.34 * (red ? e : 1 - e)), rd); - if (lum < 5) continue; - put(f, j, row, r === 0 ? G_EQ : G_DASH, red ? P.red : P.azure, lum, near(rd)); - } - } - } - - function carLamps(f, c, wetR) { - var hx = c.hx, hz = c.hz; - var hl = c.len * 0.5; - var pn = project(c.x + hx * hl, c.z + hz * hl); if (!pn.ok) return; - var xn = pn.x, wn = pn.w, dn = pn.dist; - var pt = project(c.x - hx * hl, c.z - hz * hl); if (!pt.ok) return; - var xt = pt.x, wt = pt.w, dtl = pt.dist, spt = pt.sp; - var back = xn > xt ? -1 : 1; - var hl2 = fg(236, dn), tl = fg(188, dtl); - var rHl = Math.round(rowOf(0.62, wn)), rTl = Math.round(rowOf(0.78, wt)); - if (hl2 >= 5) { - put(f, Math.round(xn), rHl, G_0, P.ice, hl2, nearer(dn)); - put(f, Math.round(xn) + back, rHl, G_o, P.ice, hl2 * 0.46, nearer(dn)); - } - if (tl >= 5) { - put(f, Math.round(xt), rTl, G_o, P.red, tl, nearer(dtl)); - - put(f, Math.round(xt) + back, rTl, G_o, P.red, tl * 0.44, nearer(dtl)); - - var rr0 = Math.round(rowOf(0, wt)) + 1; - var rd = roadDist(rr0, spt); - var rl = fg(66 * (0.55 + 0.45 * wetR), rd); - if (rl >= 5) put(f, Math.round(xt), rr0, G_QUOTE, P.red, rl, near(rd)); - } - } - - var offs = null, OFF_N = 3; - var OFF_COVER_MAX = 0.030; - - function offCover(o, pr) { - var shw = offShoulder(pr.w); - var xw = shw * 1.34; - var x0 = pr.x - xw, x1 = pr.x + xw; - if (x0 < 0) x0 = 0; - if (x1 > COLS - 1) x1 = COLS - 1; - if (x1 <= x0) return 0; - var rr = o.tall * SCALE / pr.w; - if (rr > ROWS) rr = ROWS; - return (x1 - x0) * rr / (COLS * ROWS); - } - - function offShoulder(w) { - var shw = 0.29 * CPM / w; - return shw < 0.5 ? 0.5 : shw; - } - - function offSpawn(o, i, S, fresh, city, car) { - o.n++; - var n = o.n; + c.n++; + var n = c.n; var h1 = hash2(i, n, S + 101), h2 = hash2(i, n, S + 211), h3 = hash2(i, n, S + 307), - h4 = hash2(i, n, S + 401), h5 = hash2(i, n, S + 503), h6 = hash2(i, n, S + 601), - h7 = hash2(i, n, S + 701), h8 = hash2(i, n, S + 809), h9 = hash2(i, n, S + 907); + h4 = hash2(i, n, S + 401), h5 = hash2(i, n, S + 503), h6 = hash2(i, n, S + 701), + h7 = hash2(i, n, S + 809); + c.ph = hash2(i, n, S + 601); + c.axis = COR.axis; c.ctr = COR.ctr; + if (i === PARKED) { + var cw = carriage(); + var lane = cw - 1.0; if (lane < 0.85) lane = 0.85; + var side = h2 < 0.5 ? -1 : 1; - var cw = carriage(); - var a, l, side; - o.chk = 0; - var atCar = car && car.live && car.chk && h1 < 0.78; - if (atCar) { + var a = COR.along + COR.dir * (30 + h1 * 18); + c.lat = side * lane; + c.out = -side; - a = (car.axis ? car.x : car.z) + (h2 - 0.5) * 5.6; - l = car.lat - (car.lat < 0 ? -1 : 1) * (0.9 + h3 * 1.5); - side = car.lat < 0 ? -1 : 1; - o.vx = 0; o.vz = 0; - o.chk = 1; - o.axis = car.axis; o.ctr = car.ctr; + c.wl = side * COR.half; + c.x = wX(c.axis, c.ctr, a, c.lat); + c.z = wZ(c.axis, c.ctr, a, c.lat); + + var hd = (h3 < 0.5 ? 1 : -1) * COR.dir; + c.hx = COR.axis ? hd : 0; c.hz = COR.axis ? 0 : hd; + c.vx = 0; c.vz = 0; + + c.chk = h4 < 0.46 ? 1 : 0; + c.len = 4.3 + h5 * 0.5; + c.wid = 1.82; + c.tall = 1.40 + h6 * 0.10; + c.cab = c.len * 0.22; + c.fade = 1; + c.live = 1; } else { + var ca = crossAhead(city, h1); + if (ca !== ca) { c.wait = 3.0; continue; } - if (i === 2) { o.live = 0; o.wait = 6 + h4 * 14; return; } + var ch = crossHalf(city, ca) - CC.PAVE; + if (ch < 1.7) ch = 1.7; + c.chalf = ch; + c.go = h2 < 0.5 ? -1 : 1; + var a2 = ca + (ch > 1.6 ? 0.55 + h3 * (ch - 1.2) : 0) * -c.go; + var l0 = -c.go * (COR.half + 10); + c.x = wX(c.axis, c.ctr, a2, l0); + c.z = wZ(c.axis, c.ctr, a2, l0); + c.lat = l0; - var band = COR.half - cw - 0.7; - if (band < 0.2) band = 0.2; - side = h2 < 0.5 ? -1 : 1; - a = COR.along + COR.dir * (fresh ? 9 + h3 * 22 : 30 + h3 * 12); - l = side * (cw + 0.35 + h4 * band); - - if (h5 < 0.66) { - var sp = (1.02 + h6 * 0.26) * (1 - 0.14 * wp().rain); - var go = (h7 < 0.55 ? -1 : 1) * COR.dir; - o.vx = COR.axis ? go * sp : 0; - o.vz = COR.axis ? 0 : go * sp; - } else { o.vx = 0; o.vz = 0; } - o.axis = COR.axis; o.ctr = COR.ctr; + c.out = h6 < 0.5 ? 1 : -1; + var sp2 = 9 + h4 * 6; + c.vx = COR.axis ? 0 : c.go * sp2; + c.vz = COR.axis ? c.go * sp2 : 0; + c.hx = c.vx === 0 ? 0 : (c.vx > 0 ? 1 : -1); + c.hz = c.vz === 0 ? 0 : (c.vz > 0 ? 1 : -1); + c.len = 4.4 + h5 * 0.4; + c.wid = 1.85; + c.tall = 1.38 + h7 * 0.12; + c.cab = c.len * 0.22; + c.chk = 0; + c.fade = 1; + c.live = 1; } - o.x = wX(o.axis, o.ctr, a, l); o.z = wZ(o.axis, o.ctr, a, l); - o.lat = l; - o.tall = 1.74 + h8 * 0.12; - o.walked = 0; + } - o.phase = hash2(i, n, S + 1013) * TAU; - o.side = h9 < 0.5 ? -1 : 1; + var park = cars[PARKED]; + for (i = 0; i < OFF_N; i++) { + var o = offs[i]; + var onow = 0; + if (!o.live) { - o.rim = hash2(i, n, S + 1117) < 0.74 ? P.amber : P.azure; + if (CC.reducedMotion) { if (!this.settled) onow = 1; } + else o.wait -= dt; + if (CC.reducedMotion ? !onow : o.wait > 0) continue; + if (CC.reducedMotion) offSettle(o, i, S, city, park); + else offSpawn(o, i, S, !this.warm, city, park); + continue; + } + o.x += o.vx * dt * k; o.z += o.vz * dt * k; + o.walked += (o.vx === 0 ? (o.vz < 0 ? -o.vz : o.vz) : (o.vx < 0 ? -o.vx : o.vx)) * dt * k; - var h12 = hash2(i, n, S + 1301); - o.acc = h12 < 0.42 ? 0 : (h12 < 0.74 ? 1 : 2); - o.live = 1; + if (o.chk && !(park.live && park.chk)) { + o.chk = 0; + var away = hash2(i, o.n, S + 1607) < 0.5 ? -1 : 1; + var wsp = 1.06 * (1 - 0.14 * wp().rain); + o.vx = o.axis ? away * wsp : 0; + o.vz = o.axis ? 0 : away * wsp; + } + if (offGone(o)) { + o.live = 0; o.wait = 4 + hash2(i, o.n, S + 1223) * 13; + + if (CC.reducedMotion) offSettle(o, i, S, city, park); + } + } + this.warm = 1; + + this.settled = CC.reducedMotion ? 1 : 0; + }, + + draw: function (frame, cam, t) { + camScreen(frame, cam); + + this.cols = frame.cols; this.rows = frame.rows; + var S = this.seed, i; + var wetR = wrel('wet'); + for (i = 0; i < CAR_N; i++) { + var c = cars[i]; + if (!c.live || c.fade <= 0) continue; + var pc = project(c.x, c.z); + if (!pc.ok) continue; + + var cdist = pc.dist; + if (cdist > 74) continue; + carBody(frame, c, c.fade, S); + lightbar(frame, c, c.fade, t); + + if (cdist < WASH_D_MAX) washRoad(frame, c, c.fade, t, wetR); + if (i === CRUISER) carLamps(frame, c, wetR); + } + var park = cars[PARKED]; + for (i = 0; i < OFF_N; i++) { + var o = offs[i]; + if (!o.live) continue; + + var bl = (o.chk && park.live) ? barEnv(t, park.ph) : -1; + drawOfficer(frame, o, i, S, bl); + } } - - function offGone(o) { - var pro = project(o.x, o.z); - if (!pro.ok || pro.w > 70 || pro.sp > HP * 1.8 || pro.sp < -HP * 1.8) return 1; - - return offCover(o, pro) > OFF_COVER_MAX ? 1 : 0; - } - - function offSettle(o, i, S, city, park) { - var tries = 0; - do { - - offSpawn(o, i, S, 1, city, park); - tries++; - } while (o.live && offGone(o) && tries < 8); - if (o.live && offGone(o)) o.live = 0; - } - - var OFF_DRAW_D = 26; - - function drawOfficer(f, o, i, S, bareLit) { - var pr = project(o.x, o.z); - if (!pr.ok || pr.dist > OFF_DRAW_D) return; - var w = pr.w, dist = pr.dist, d = near(dist), cx = pr.x; - var rFeet = rowOf(0, w), rHead = rowOf(o.tall, w); - var tallRows = rFeet - rHead; - if (tallRows < 2.2) return; - if (offCover(o, pr) > OFF_COVER_MAX * 2) return; - var shw = offShoulder(w); - var x0 = Math.round(cx - shw * 1.34), x1 = Math.round(cx + shw * 1.34); - if (x1 < 0 || x0 > COLS - 1) return; - if (x0 < 0) x0 = 0; - if (x1 > COLS - 1) x1 = COLS - 1; - - var st = CC.reducedMotion ? 0 : Math.sin(o.walked * 3.4 + o.phase); - - var rim = fg(148 + hash2(i, o.n, S + 5) * 22, dist); - - if (bareLit >= 0) rim *= 0.88 + 0.12 * bareLit; - var x, v0, v1, q; - for (x = x0; x <= x1; x++) { - var u = (x - cx) / shw, au = u < 0 ? -u : u; - v0 = 9; v1 = -9; - if (au <= 1.0) { - - v0 = au > 0.44 ? 0.145 : 0; - v1 = au > 0.66 ? 0.60 : 1; - - if (au < 0.36 && tallRows > 6) { - var lg = (u < 0 ? -1 : 1) * st; - if (lg > 0.30) v1 = 0.95; - else if (lg < -0.30) v1 = 0.87; - } - } - - if (au > 0.44 && au <= 1.34) { - if (0.055 < v0) v0 = 0.055; - if (0.115 > v1) v1 = 0.115; - } - if (v1 < v0) continue; - var rt = rHead + v0 * tallRows, rb = rHead + v1 * tallRows; - var r0 = Math.round(rt), r1 = Math.round(rb); - if (r1 < r0) r1 = r0; - if (r0 < 0) r0 = 0; - if (r1 > ROWS - 1) r1 = ROWS - 1; - for (q = r0; q <= r1; q++) put(f, x, q, 0, P.shadow, 0, d); - if (rim >= 5) { - - var rl = au < 0.44 ? 1 : (au <= 1.0 ? 0.90 : 0.95); - put(f, x, r0, au < 0.44 ? G_o : G_DASH, o.rim, rim * rl, nearer(dist)); - } - } - if (rim < 5) return; - - if (tallRows > 8) { - var rx = Math.round(cx + o.side * shw); - for (q = 1; q <= 2; q++) - put(f, rx, Math.round(rHead + q + 1), G_QUOTE, o.rim, rim * (q === 1 ? 0.96 : 0.88), - nearer(dist)); - } - - if (tallRows > 4) { - if (o.acc === 0) { - - var a1 = fg(168, dist); - if (a1 >= 5) { - var by = Math.round(rHead + tallRows * 0.30); - put(f, Math.round(cx - shw * 0.5), by, G_DASH, P.spring, a1, nearer(dist)); - - put(f, Math.round(cx + shw * 0.5), by, G_DASH, P.spring, a1 * 0.90, nearer(dist)); - } - } else if (o.acc === 1) { - - var a2 = fg(112, dist); - if (a2 >= 5) - put(f, Math.round(cx), Math.round(rHead + tallRows * 0.075), G_DASH, P.azure, a2, - nearer(dist)); - } else { - - var a3 = fg(150, dist); - if (a3 >= 5) - put(f, Math.round(cx + o.side * shw * 0.9), Math.round(rHead + tallRows * 0.17), - G_o, P.ice, a3, nearer(dist)); - } - } - - } - - CC.ELEMENTS.push({ - name: 'police', - - world: 'cyber', - layer: 25, - init: function (city, rng, dims) { - this.city = city; - - this.seed = (rng() * 30011) | 0; - this.boot = 0; - this.settled = 0; - this.warm = 0; - - this.cols = dims && dims.cols ? dims.cols : 200; - this.rows = dims && dims.rows ? dims.rows : 60; - var i; - cars = new Array(CAR_N); - for (i = 0; i < CAR_N; i++) - cars[i] = { x: 0, z: 0, hx: 0, hz: 1, vx: 0, vz: 0, live: 0, wait: 4 + i * 9, n: i * 67, - len: 4.4, wid: 1.85, tall: 1.42, cab: 1.0, ph: i * 0.37, chk: 0, - lat: 0, wl: 0, out: 1, go: 1, chalf: 2, axis: 0, ctr: 0, fade: 1 }; - offs = new Array(OFF_N); - for (i = 0; i < OFF_N; i++) - offs[i] = { x: 0, z: 0, vx: 0, vz: 0, live: 0, wait: 2 + i * 5, n: i * 83, - tall: 1.78, walked: 0, phase: 0, side: 1, rim: P.amber, acc: 0, chk: 0, - lat: 0, axis: 0, ctr: 0 }; - }, - - update: function (dt, t, cam) { - - camScreenAt(cam, this.cols, this.rows); - var city = this.city; - corridor(city, cam); - var S = this.seed, i; - - var k = CC.reducedMotion ? 0 : 1; - - if (!this.boot) { - - this.boot = 1; - for (i = 0; i < OFF_N; i++) offs[i].wait = 1.5 + i * 4.5; - } - - for (i = 0; i < CAR_N; i++) { - var c = cars[i]; - - var now = 0; - if (c.live) { - c.x += c.vx * dt * k; c.z += c.vz * dt * k; - var cov = carCover(c); - var pr = project(c.x, c.z); - var gone = 0; - if (!pr.ok || pr.w > 78) gone = 1; - if (i === PARKED) { - - if (cov > CAR_HIDE_AT) gone = 1; - if (pr.sp > HP * 2.4 || pr.sp < -HP * 2.4) gone = 1; - c.fade = cov <= CAR_FADE_AT ? 1 - : (CAR_HIDE_AT - cov) / (CAR_HIDE_AT - CAR_FADE_AT); - if (c.fade < 0) c.fade = 0; - } else { - - var l = (c.axis ? c.z - c.ctr : c.x - c.ctr); - if (l * c.go > c.chalf + 11) gone = 1; - if (cov > CAR_HIDE_AT * 1.6) gone = 1; - c.fade = 1; - } - if (gone) { - c.live = 0; - - c.wait = i === PARKED ? 9 + hash2(i, c.n, S + 1409) * 17 - : (14 + hash2(i, c.n, S + 1511) * 26); - if (CC.reducedMotion && i === PARKED) now = 1; - } - if (!now) continue; - } else if (CC.reducedMotion) { - - if (i === PARKED && !this.settled) now = 1; - if (!now) continue; - } else { - c.wait -= dt * (i === PARKED ? 1 : k); - if (c.wait > 0) continue; - } - c.n++; - var n = c.n; - - var h1 = hash2(i, n, S + 101), h2 = hash2(i, n, S + 211), h3 = hash2(i, n, S + 307), - h4 = hash2(i, n, S + 401), h5 = hash2(i, n, S + 503), h6 = hash2(i, n, S + 701), - h7 = hash2(i, n, S + 809); - c.ph = hash2(i, n, S + 601); - c.axis = COR.axis; c.ctr = COR.ctr; - if (i === PARKED) { - var cw = carriage(); - var lane = cw - 1.0; if (lane < 0.85) lane = 0.85; - var side = h2 < 0.5 ? -1 : 1; - - var a = COR.along + COR.dir * (30 + h1 * 18); - c.lat = side * lane; - c.out = -side; - - c.wl = side * COR.half; - c.x = wX(c.axis, c.ctr, a, c.lat); - c.z = wZ(c.axis, c.ctr, a, c.lat); - - var hd = (h3 < 0.5 ? 1 : -1) * COR.dir; - c.hx = COR.axis ? hd : 0; c.hz = COR.axis ? 0 : hd; - c.vx = 0; c.vz = 0; - - c.chk = h4 < 0.46 ? 1 : 0; - c.len = 4.3 + h5 * 0.5; - c.wid = 1.82; - c.tall = 1.40 + h6 * 0.10; - c.cab = c.len * 0.22; - c.fade = 1; - c.live = 1; - } else { - var ca = crossAhead(city, h1); - if (ca !== ca) { c.wait = 3.0; continue; } - - var ch = crossHalf(city, ca) - CC.PAVE; - if (ch < 1.7) ch = 1.7; - c.chalf = ch; - c.go = h2 < 0.5 ? -1 : 1; - var a2 = ca + (ch > 1.6 ? 0.55 + h3 * (ch - 1.2) : 0) * -c.go; - var l0 = -c.go * (COR.half + 10); - c.x = wX(c.axis, c.ctr, a2, l0); - c.z = wZ(c.axis, c.ctr, a2, l0); - c.lat = l0; - - c.out = h6 < 0.5 ? 1 : -1; - var sp2 = 9 + h4 * 6; - c.vx = COR.axis ? 0 : c.go * sp2; - c.vz = COR.axis ? c.go * sp2 : 0; - c.hx = c.vx === 0 ? 0 : (c.vx > 0 ? 1 : -1); - c.hz = c.vz === 0 ? 0 : (c.vz > 0 ? 1 : -1); - c.len = 4.4 + h5 * 0.4; - c.wid = 1.85; - c.tall = 1.38 + h7 * 0.12; - c.cab = c.len * 0.22; - c.chk = 0; - c.fade = 1; - c.live = 1; - } - } - - var park = cars[PARKED]; - for (i = 0; i < OFF_N; i++) { - var o = offs[i]; - var onow = 0; - if (!o.live) { - - if (CC.reducedMotion) { if (!this.settled) onow = 1; } - else o.wait -= dt; - if (CC.reducedMotion ? !onow : o.wait > 0) continue; - if (CC.reducedMotion) offSettle(o, i, S, city, park); - else offSpawn(o, i, S, !this.warm, city, park); - continue; - } - o.x += o.vx * dt * k; o.z += o.vz * dt * k; - o.walked += (o.vx === 0 ? (o.vz < 0 ? -o.vz : o.vz) : (o.vx < 0 ? -o.vx : o.vx)) * dt * k; - - if (o.chk && !(park.live && park.chk)) { - o.chk = 0; - var away = hash2(i, o.n, S + 1607) < 0.5 ? -1 : 1; - var wsp = 1.06 * (1 - 0.14 * wp().rain); - o.vx = o.axis ? away * wsp : 0; - o.vz = o.axis ? 0 : away * wsp; - } - if (offGone(o)) { - o.live = 0; o.wait = 4 + hash2(i, o.n, S + 1223) * 13; - - if (CC.reducedMotion) offSettle(o, i, S, city, park); - } - } - this.warm = 1; - - this.settled = CC.reducedMotion ? 1 : 0; - }, - - draw: function (frame, cam, t) { - camScreen(frame, cam); - - this.cols = frame.cols; this.rows = frame.rows; - var S = this.seed, i; - var wetR = wrel('wet'); - for (i = 0; i < CAR_N; i++) { - var c = cars[i]; - if (!c.live || c.fade <= 0) continue; - var pc = project(c.x, c.z); - if (!pc.ok) continue; - - var cdist = pc.dist; - if (cdist > 74) continue; - carBody(frame, c, c.fade, S); - lightbar(frame, c, c.fade, t); - - if (cdist < WASH_D_MAX) washRoad(frame, c, c.fade, t, wetR); - if (i === CRUISER) carLamps(frame, c, wetR); - } - var park = cars[PARKED]; - for (i = 0; i < OFF_N; i++) { - var o = offs[i]; - if (!o.live) continue; - - var bl = (o.chk && park.live) ? barEnv(t, park.ph) : -1; - drawOfficer(frame, o, i, S, bl); - } - } - }); + }); })(CC); /* src/elements/signage.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, hash2 = CC.hash2, vnoise = CC.vnoise, clamp = CC.clamp, put = CC.put; + var P = CC.P, g = CC.g, hash2 = CC.hash2, vnoise = CC.vnoise, clamp = CC.clamp, put = CC.put; - var G_HASH = g('#'), G_8 = g('8'), G_0 = g('0'), G_O = g('O'), G_oo = g('o'), - G_X = g('X'), G_Z = g('Z'), G_EQ = g('='), G_COLON = g(':'), G_DOT = g('.'), - G_QUOTE = g("'"), G_DASH = g('-'), G_COMMA = g(','); + var G_HASH = g('#'), G_8 = g('8'), G_0 = g('0'), G_O = g('O'), G_oo = g('o'), + G_X = g('X'), G_Z = g('Z'), G_EQ = g('='), G_COLON = g(':'), G_DOT = g('.'), + G_QUOTE = g("'"), G_DASH = g('-'), G_COMMA = g(','); - var G_PIPE = g('|'), G_V = g('V'), G_M = g('M'), G_W = g('W'), G_N = g('N'), - G_H = g('H'), G_U = g('U'), G_K = g('K'), G_Y = g('Y'), G_Q = g('Q'), - G_AT = g('@'), G_PCT = g('%'), G_PLUS = g('+'), G_STAR = g('*'), G_SEMI = g(';'); + var G_PIPE = g('|'), G_V = g('V'), G_M = g('M'), G_W = g('W'), G_N = g('N'), + G_H = g('H'), G_U = g('U'), G_K = g('K'), G_Y = g('Y'), G_Q = g('Q'), + G_AT = g('@'), G_PCT = g('%'), G_PLUS = g('+'), G_STAR = g('*'), G_SEMI = g(';'); - var NEON_G = [G_HASH, G_8, G_0, G_X, G_O, G_Z, G_EQ], NEON_N = 7; - var HOLO_G = [G_COLON, G_DASH, G_EQ, G_oo, G_Z, G_X], HOLO_N = 6; - var SPILL_G = [G_DOT, G_COLON, G_QUOTE, G_COMMA], SPILL_N = 4; + var NEON_G = [G_HASH, G_8, G_0, G_X, G_O, G_Z, G_EQ], NEON_N = 7; + var HOLO_G = [G_COLON, G_DASH, G_EQ, G_oo, G_Z, G_X], HOLO_N = 6; + var SPILL_G = [G_DOT, G_COLON, G_QUOTE, G_COMMA], SPILL_N = 4; - var BLOCK_G = [G_HASH, G_8, G_M, G_W, G_N, G_H, G_U, G_K, G_Y, G_X, G_Q, G_0, G_AT], BLOCK_N = 13; + var BLOCK_G = [G_HASH, G_8, G_M, G_W, G_N, G_H, G_U, G_K, G_Y, G_X, G_Q, G_0, G_AT], BLOCK_N = 13; - var TICK_G = [G_EQ, G_DASH, G_COLON, G_PLUS, G_STAR, G_X, G_Z, G_oo, G_PCT, G_SEMI], TICK_N = 10; + var TICK_G = [G_EQ, G_DASH, G_COLON, G_PLUS, G_STAR, G_X, G_Z, G_oo, G_PCT, G_SEMI], TICK_N = 10; - var SCREEN_G = [G_DOT, G_COLON, G_oo, G_O, G_8, G_HASH], SCREEN_N = 6; + var SCREEN_G = [G_DOT, G_COLON, G_oo, G_O, G_8, G_HASH], SCREEN_N = 6; - var _fog = null; - function passthrough(l) { return l; } - function fog(l, d) { - if (!_fog) _fog = (CC.Surf && CC.Surf.fog) || passthrough; - return _fog(l, d); - } + var _fog = null; + function passthrough(l) { return l; } + function fog(l, d) { + if (!_fog) _fog = (CC.Surf && CC.Surf.fog) || passthrough; + return _fog(l, d); + } - function rel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } + function rel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } - var AT = { dim: 1, halo: 1, wet: 1, gust: 1 }; - function airPrep() { - var f = rel('fog'), h = rel('haze'); - AT.dim = clamp(1 - 0.17 * (f - 1) - 0.11 * (h - 1), 0.46, 1.14); - AT.halo = clamp(1 + 0.42 * (f - 1) + 0.26 * (h - 1), 0.72, 2.10); - AT.wet = clamp(rel('wet'), 0, 1.30); - AT.gust = clamp(1 + 0.60 * (rel('wind') - 1), 0.55, 1.90); - } + var AT = { dim: 1, halo: 1, wet: 1, gust: 1 }; + function airPrep() { + var f = rel('fog'), h = rel('haze'); + AT.dim = clamp(1 - 0.17 * (f - 1) - 0.11 * (h - 1), 0.46, 1.14); + AT.halo = clamp(1 + 0.42 * (f - 1) + 0.26 * (h - 1), 0.72, 2.10); + AT.wet = clamp(rel('wet'), 0, 1.30); + AT.gust = clamp(1 + 0.60 * (rel('wind') - 1), 0.55, 1.90); + } - function gutter(t, ph) { - if (CC.reducedMotion || AT.gust <= 1.02) return 1; + function gutter(t, ph) { + if (CC.reducedMotion || AT.gust <= 1.02) return 1; - var shared = CC.Wind ? clamp((CC.Wind.mult - 0.70) / 0.60, 0, 1) - : vnoise(t * 1.1, 0x4C1); - return 1 - 0.26 * (AT.gust - 1) * - (0.65 * shared + 0.35 * vnoise(t * 1.1 + ph * 23, 0x4C1)); - } + var shared = CC.Wind ? clamp((CC.Wind.mult - 0.70) / 0.60, 0, 1) + : vnoise(t * 1.1, 0x4C1); + return 1 - 0.26 * (AT.gust - 1) * + (0.65 * shared + 0.35 * vnoise(t * 1.1 + ph * 23, 0x4C1)); + } - var CO = { cols: 0, rows: 0, horizon: 0, hp: 0, scale: 1, eyeY: 1.7, - ox: 0, oz: 0, fwx: 0, fwz: 1, rgx: 1, rgz: 0 }; - var VP = { x: 0, y: 0, w: 0, dist: 0 }; + var CO = { cols: 0, rows: 0, horizon: 0, hp: 0, scale: 1, eyeY: 1.7, + ox: 0, oz: 0, fwx: 0, fwz: 1, rgx: 1, rgz: 0 }; + var VP = { x: 0, y: 0, w: 0, dist: 0 }; - function setCam(frame, cam) { - CO.cols = frame.cols; CO.rows = frame.rows; - CO.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; - CO.hp = Math.tan((cam.fov || 1.25) * 0.5); - CO.scale = cam.scaleY !== undefined ? cam.scaleY - : (frame.cols * (cam.cellAspect || 0.5625)) / (2 * CO.hp); - CO.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - CO.ox = cam.x; CO.oz = cam.z; - var yaw = cam.yaw || 0; - CO.fwx = Math.sin(yaw); CO.fwz = Math.cos(yaw); - CO.rgx = Math.cos(yaw); CO.rgz = -Math.sin(yaw); - } + function setCam(frame, cam) { + CO.cols = frame.cols; CO.rows = frame.rows; + CO.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; + CO.hp = Math.tan((cam.fov || 1.25) * 0.5); + CO.scale = cam.scaleY !== undefined ? cam.scaleY + : (frame.cols * (cam.cellAspect || 0.5625)) / (2 * CO.hp); + CO.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + CO.ox = cam.x; CO.oz = cam.z; + var yaw = cam.yaw || 0; + CO.fwx = Math.sin(yaw); CO.fwz = Math.cos(yaw); + CO.rgx = Math.cos(yaw); CO.rgz = -Math.sin(yaw); + } - function project(px, py, pz) { - var rx = px - CO.ox, rz = pz - CO.oz; - var w = rx * CO.fwx + rz * CO.fwz; - if (w < 0.6) return false; - var sp = (rx * CO.rgx + rz * CO.rgz) / w; + function project(px, py, pz) { + var rx = px - CO.ox, rz = pz - CO.oz; + var w = rx * CO.fwx + rz * CO.fwz; + if (w < 0.6) return false; + var sp = (rx * CO.rgx + rz * CO.rgz) / w; - if (sp < -CO.hp * 2 || sp > CO.hp * 2) return false; - VP.x = (sp / CO.hp + 1) * 0.5 * CO.cols - 0.5; - VP.y = CO.horizon - (py - CO.eyeY) * CO.scale / w; - VP.w = w; - VP.dist = w * Math.sqrt(1 + sp * sp); + if (sp < -CO.hp * 2 || sp > CO.hp * 2) return false; + VP.x = (sp / CO.hp + 1) * 0.5 * CO.cols - 0.5; + VP.y = CO.horizon - (py - CO.eyeY) * CO.scale / w; + VP.w = w; + VP.dist = w * Math.sqrt(1 + sp * sp); + return true; + } + + var VA = { x: 0, y: 0, w: 0, dist: 0 }, VB = { x: 0, y: 0, w: 0, dist: 0 }; + function projInto(px, py, pz, O) { + var rx = px - CO.ox, rz = pz - CO.oz; + var w = rx * CO.fwx + rz * CO.fwz; + if (w < 0.9) return false; + var sp = (rx * CO.rgx + rz * CO.rgz) / w; + O.x = (sp / CO.hp + 1) * 0.5 * CO.cols - 0.5; + O.y = CO.horizon - (py - CO.eyeY) * CO.scale / w; + O.w = w; + O.dist = w * Math.sqrt(1 + sp * sp); + return true; + } + + function colsFor(m, w) { return (m / w / CO.hp) * CO.cols * 0.5; } + + function nearer(d) { + if (!(d < 1e30)) return -1; + var n = d - d * 1e-4; + return n < d ? n : -1; + } + + var FACE = { nx: 0, nz: 0, fx: 0, fz: 0 }; + function faceOf(city, gx, gz, rx, rz) { + var xFirst = (rx < 0 ? -rx : rx) > (rz < 0 ? -rz : rz); + var i, nx, nz; + for (i = 0; i < 2; i++) { + if ((i === 0) === xFirst) { + nx = rx > 0 ? -1 : 1; nz = 0; + } else { + nx = 0; nz = rz > 0 ? -1 : 1; + } + if (city.height(gx + nx, gz + nz) <= 0) { + FACE.nx = nx; FACE.nz = nz; + FACE.fx = gx + 0.5 + nx * 0.5; FACE.fz = gz + 0.5 + nz * 0.5; return true; + } } + return false; + } - var VA = { x: 0, y: 0, w: 0, dist: 0 }, VB = { x: 0, y: 0, w: 0, dist: 0 }; - function projInto(px, py, pz, O) { - var rx = px - CO.ox, rz = pz - CO.oz; - var w = rx * CO.fwx + rz * CO.fwz; - if (w < 0.9) return false; - var sp = (rx * CO.rgx + rz * CO.rgz) / w; - O.x = (sp / CO.hp + 1) * 0.5 * CO.cols - 0.5; - O.y = CO.horizon - (py - CO.eyeY) * CO.scale / w; - O.w = w; - O.dist = w * Math.sqrt(1 + sp * sp); + function flick(kind, ph, t, j, dead) { + if (kind === 2 && j === dead) return 0.10; + if (CC.reducedMotion) return 0.88; + if (kind === 0) return 1; + if (kind === 1) { + + var b = vnoise(t * 2.8 + ph * 17, 0x8117); + var w = CC.smooth(clamp((b - 0.20) / 0.12, 0, 1)); + return (0.30 + 0.5 * b) * (1 - w) + (0.84 + 0.16 * b) * w; + } + if (kind === 2) return 0.97; + return 0.66 + 0.34 * (0.5 + 0.5 * Math.sin(t * 0.8 + ph * 6.283)); + } + + function crest(d, hold, soft) { + d -= Math.floor(d); + if (d > 0.5) d = 1 - d; + return CC.smooth(clamp((hold + soft - d) / soft, 0, 1)); + } + + var HKX = [0, 104729, 611953, 1999993, 3391993, 4796027, 7919, 2750159, 4256233, 1299709]; + var HKZ = [0, 4256233, 1299709, 4796027, 611953, 2750159, 3391993, 104729, 7919, 1999993]; + function hk(a, b, salt, i) { return hash2(a + HKX[i], b + HKZ[i], salt); } + + function neonHue(r) { + + return r < 0.34 ? P.amber : r < 0.68 ? P.azure : r < 0.80 ? P.warm + : r < 0.90 ? P.ember : P.spring; + } + + var S_TUBE = 0, + S_BLADE = 1, + S_CHASE = 2, + S_WIPE = 3, + S_TICKER = 4, + S_BLOCK = 5, + S_FLAP = 6, + S_FAIL = 7, + S_BACKLIT = 8, + S_ARROW = 9, + S_SCREEN = 10, + S_MARQUEE = 11, + S_N = 12; + + var STYLE_W = [ + + [ 6, 3, 3, 2, 1, 4, 2, 3, 2, 3, 1, 5], + [ 2, 3, 2, 4, 5, 3, 3, 1, 3, 1, 6, 2], + [ 3, 1, 1, 1, 1, 2, 2, 6, 5, 2, 1, 3], + [ 4, 2, 2, 1, 1, 2, 2, 5, 2, 5, 1, 3], + [ 3, 3, 2, 2, 2, 3, 4, 2, 3, 2, 2, 3], + [ 3, 5, 6, 4, 4, 6, 3, 2, 2, 4, 5, 2], + [ 7, 6, 3, 1, 1, 3, 2, 2, 4, 2, 1, 4], + [ 3, 3, 4, 1, 1, 7, 5, 3, 1, 2, 1, 7], + [ 2, 2, 1, 2, 5, 2, 3, 3, 7, 1, 4, 3] + ]; + + var MIN_C = [4, 1, 4, 3, 3, 5, 3, 3, 3, 2, 3, 3]; + var MIN_R = [3, 4, 3, 2, 2, 2, 2, 2, 2, 4, 2, 2]; + + function blockGrid(n) { + var k = ((n + 1) / 3) | 0; + return (k < 1 ? 1 : k) * 3 - 1; + } + + function pickStyle(did, r) { + var w = STYLE_W[did] || STYLE_W[0], tot = 0, i; + for (i = 0; i < S_N; i++) tot += w[i]; + var x = r * tot; + for (i = 0; i < S_N; i++) { x -= w[i]; if (x <= 0) return i; } + return S_MARQUEE; + } + + var BD = { + style: 0, hue: 0, sd: 0, ph: 0, kind: 0, dead: 0, dead2: 0, + gl: 0, gl2: 0, nc: 2, nr: 2, ncW: 2, nrW: 2, gs: 1, rs: 1, + bv: 0, peak: 200, halo: 0.55, dens: 1, cased: 1, lod: 0, massk: 0.82, sweep: 0, tt: 0 + }; + var SH = { g: 0, k: 0, c: 0 }; + var GEO = { ax: 0, az: 0, bx: 0, bz: 0, v0: 0, H: 0 }; + + function signHue(rec, r, style) { + var h = (rec && rec.sign) ? rec.sign.hue : neonHue(r); + + if (h === P.violet && style !== S_SCREEN && style !== S_TICKER) h = P.azure; + + if (h === P.rose && style !== S_BLADE && style !== S_TUBE) h = P.amber; + + if (h === P.slate || h === P.white || h === P.shadow || + h === P.stone || h === P.timber || h === P.sand || + h === P.moss || h === P.indigo) h = r < 0.5 ? P.amber : P.azure; + return h; + } + + function shade(u, v, t) { + var nc = BD.nc, nr = BD.nr; + var ci = (u * nc) | 0; if (ci < 0) ci = 0; else if (ci >= nc) ci = nc - 1; + var ri = (v * nr) | 0; if (ri < 0) ri = 0; else if (ri >= nr) ri = nr - 1; + + var cw = BD.gs > 1 ? (ci * BD.gs) | 0 : ci; + var rw = BD.rs > 1 ? (ri * BD.rs) | 0 : ri; + var edge, quad, pl, pi, p, k, j, ff, st, fr, d, lv, a, b, bi, ix, iy, pk, cs; + SH.c = BD.hue; + + switch (BD.style) { + + case S_TUBE: + + edge = (ci === 0 || ci === nc - 1 || ri === 0 || ri === nr - 1); + if (!edge) { + if (nr < 5 || ri !== (nr >> 1) || (ci & 1)) return false; + SH.g = (cw & 2) ? BD.gl : BD.gl2; + SH.k = 0.60 * flick(BD.kind, BD.ph, t, cw, BD.dead2); return true; + } + + quad = (ci * 2 >= nc ? 1 : 0) + (ri * 2 >= nr ? 2 : 0); + SH.g = (ri === 0 || ri === nr - 1) ? BD.gl : G_PIPE; + SH.k = quad === (BD.dead & 3) ? 0.09 + : (0.86 + 0.14 * hk(cw, rw, BD.sd, 3)) * flick(BD.kind, BD.ph, t, 0, -1); + return true; + + case S_BLADE: + + k = v * nr; + j = k | 0; ff = k - j; + if (ff > 0.66) return false; + j = BD.rs > 1 ? (j * BD.rs) | 0 : j; + SH.g = hk(j, cw, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; + SH.k = (0.86 + 0.20 * hk(j, cw, BD.sd, 1)) * flick(BD.kind, BD.ph, t, j, BD.dead); + return true; + + case S_CHASE: + + edge = (ci === 0 || ci === nc - 1 || ri === 0 || ri === nr - 1); + if (edge) { + pl = 2 * (nc + nr) - 4; if (pl < 1) pl = 1; + if (ri === 0) pi = ci; + else if (ci === nc - 1) pi = (nc - 1) + ri; + else if (ri === nr - 1) pi = (nc - 1) + (nr - 1) + (nc - 1 - ci); + else pi = 2 * (nc - 1) + (nr - 1) + (nr - 1 - ri); + p = crest(pi / pl - BD.sweep, 0.10, 0.09); + SH.g = p > 0.34 ? G_O : G_oo; + SH.k = 0.26 + 0.86 * p; + return true; + } + if (nr < 3 || ri !== (nr >> 1)) return false; + if ((ci & 3) === 3) return false; + SH.g = hk(cw, 0, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; + SH.k = 0.74 * flick(BD.kind, BD.ph, t, cw, BD.dead); + return true; + + case S_WIPE: + + k = u * nc; + j = k | 0; ff = k - j; + if (ff > 0.68) return false; + SH.g = hk(cw, rw, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; + SH.k = (0.30 + 0.68 * crest(u - BD.sweep, 0.08, 0.13)) * + flick(BD.kind, BD.ph, t, cw, BD.dead); + return true; + + case S_TICKER: + + if (nr > 2 && (ri === 0 || ri === nr - 1)) { + SH.g = G_DASH; SH.k = 0.22; return true; + } + st = CC.reducedMotion ? 0 : (BD.tt * 2.0) | 0; + SH.g = TICK_G[((hk(cw + st, rw, BD.sd, 4) * 1361) | 0) % TICK_N]; + SH.k = 0.52 + 0.44 * hk(cw, rw, BD.sd, 5); + return true; + + case S_BLOCK: + + if (BD.bv) { + if (ri % 3 === 2) return false; + bi = (ri / 3) | 0; ix = ci; iy = ri % 3; + } else { + if (ci % 3 === 2) return false; + bi = (ci / 3) | 0; ix = ci % 3; iy = ri; + } + + bi = BD.bv ? (BD.rs > 1 ? (bi * BD.rs) | 0 : bi) : (BD.gs > 1 ? (bi * BD.gs) | 0 : bi); + pk = hk(bi * 4 + ix, iy, BD.sd + 41, 8); + if (pk < 0.15) return false; + cs = hk(bi, 0, BD.sd + 7, 7); + SH.g = BLOCK_G[(((cs * 977 + pk * 131) | 0) % BLOCK_N)]; + SH.k = (0.82 + 0.18 * pk) * flick(BD.kind, BD.ph, t, bi, BD.dead); + return true; + + case S_FLAP: + + p = hk(cw, rw, BD.sd, 6); + k = BD.tt * 0.55 + p * 7; + st = k | 0; fr = k - st; + d = fr < 0.5 ? fr : 1 - fr; + SH.g = TICK_G[((hk(st + cw * 5, rw, BD.sd, 4) * 1361) | 0) % TICK_N]; + + SH.k = 0.94 - 0.52 * CC.smooth(clamp((0.28 - d) / 0.28, 0, 1)); + return true; + + case S_FAIL: + + if (ri === BD.dead2 % nr) { SH.g = BD.gl2; SH.k = 0.07; return true; } + if (ci === BD.dead % nc) { + SH.g = BD.gl; + SH.k = CC.reducedMotion ? 0.56 + : 0.42 + 0.28 * (0.5 + 0.5 * Math.sin(BD.tt * 13.82 + BD.ph * 6.283)); + return true; + } + k = u * nc; j = k | 0; ff = k - j; + if (ff > 0.70) return false; + SH.g = hk(cw, rw, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; + SH.k = 0.80 + 0.14 * hk(cw, rw, BD.sd, 1); + return true; + + case S_BACKLIT: + + edge = (ci === 0 || ci === nc - 1 || ri === 0 || ri === nr - 1); + if (edge) { SH.g = BD.gl; SH.k = 0.42 + 0.12 * hk(cw, rw, BD.sd, 3); return true; } + SH.c = P.shadow; + SH.g = G_HASH; SH.k = 0.34; + return true; + + case S_ARROW: + + p = crest((nr - 1 - ri) / nr - BD.sweep, 0.09, 0.16); + SH.g = ri === nr - 1 ? G_EQ : G_V; + SH.k = 0.24 + 0.82 * p; + return true; + + case S_SCREEN: + + a = vnoise(BD.tt * 0.45 + cw * 0.83 + BD.ph * 9, BD.sd + 101); + b = vnoise(BD.tt * 0.37 + rw * 1.29 + BD.ph * 5, BD.sd + 211); + lv = clamp(a * 0.66 + b * 0.52 - 0.13, 0, 1); + + j = (lv * SCREEN_N) | 0; if (j >= SCREEN_N) j = SCREEN_N - 1; + SH.g = SCREEN_G[j]; + SH.k = 0.16 + 0.90 * lv * lv; + return true; + + default: + + k = u * nc; + j = k | 0; ff = k - j; + if (ff > 0.62) return false; + SH.g = hk(cw, rw, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; + SH.k = (0.84 + 0.22 * hk(cw, rw, BD.sd, 1)) * flick(BD.kind, BD.ph, t, cw, BD.dead); + return true; } + } - function colsFor(m, w) { return (m / w / CO.hp) * CO.cols * 0.5; } - - function nearer(d) { - if (!(d < 1e30)) return -1; - var n = d - d * 1e-4; - return n < d ? n : -1; + function castGlow(frame, cx, cy, rx, ry, hue, amt, dist) { + if (amt < 0.03 || rx < 0.5 || ry < 0.5) return; + var cols = CO.cols, rows = CO.rows; + var xa = Math.floor(cx - rx), xb = Math.ceil(cx + rx); + var ya = Math.floor(cy - ry), yb = Math.ceil(cy + ry); + if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; + if (ya < 0) ya = 0; if (yb > rows - 1) yb = rows - 1; + if (xb < xa || yb < ya) return; + var dNear = dist * 0.55, dFar = dist * 1.5; + var x, y, dx, dy, rr, i, l0, nd, k, add; + for (y = ya; y <= yb; y++) { + dy = (y + 0.5 - cy) / ry; + if (dy < -1 || dy > 1) continue; + for (x = xa; x <= xb; x++) { + dx = (x + 0.5 - cx) / rx; + rr = dx * dx + dy * dy; + if (rr > 1) continue; + i = y * cols + x; + if (frame.ch[i] === 0) continue; + l0 = frame.lum[i]; + if (l0 === 0) continue; + if (!(frame.dist[i] > dNear && frame.dist[i] < dFar)) continue; + k = 1 - Math.sqrt(rr); k *= k; + add = fog(amt * k * 104, frame.dist[i]); + if (add < 3) continue; + nd = nearer(frame.dist[i]); + if (nd < 0) continue; + put(frame, x, y, frame.ch[i], k > 0.44 ? hue : frame.col[i], l0 + add, nd, + frame.kind[i]); + } } + } - var FACE = { nx: 0, nz: 0, fx: 0, fz: 0 }; - function faceOf(city, gx, gz, rx, rz) { - var xFirst = (rx < 0 ? -rx : rx) > (rz < 0 ? -rz : rz); - var i, nx, nz; - for (i = 0; i < 2; i++) { - if ((i === 0) === xFirst) { - nx = rx > 0 ? -1 : 1; nz = 0; - } else { - nx = 0; nz = rz > 0 ? -1 : 1; - } - if (city.height(gx + nx, gz + nz) <= 0) { - FACE.nx = nx; FACE.nz = nz; - FACE.fx = gx + 0.5 + nx * 0.5; FACE.fz = gz + 0.5 + nz * 0.5; - return true; + function boardVisible(frame, xL, xR, cy, dist) { + var cols = CO.cols, y = Math.round(cy); + if (y < 0) y = 0; else if (y > CO.rows - 1) y = CO.rows - 1; + var lim = dist * 0.86, q, x; + for (q = 0; q < 3; q++) { + x = Math.round(xL + (xR - xL) * (0.1 + 0.4 * q)); + if (x < 0 || x > cols - 1) continue; + if (!(frame.dist[y * cols + x] < lim)) return true; + } + return false; + } + + function wetSmear(frame, cx, w, hue, peak, sd) { + if (AT.wet < 0.22 || peak < 20) return; + var cols = CO.cols, rows = CO.rows, horizon = CO.horizon; + var x = Math.round(cx); + if (x < 0 || x > cols - 1 || w < 1.6 || w > 44) return; + var sp = (2 * (x + 0.5) / cols - 1) * CO.hp, len = Math.sqrt(1 + sp * sp); + var r0 = Math.floor(horizon + CO.eyeY * CO.scale / w); + var lo = Math.floor(horizon) + 1; if (r0 < lo) r0 = lo; + + var wEnd = w * (0.60 - 0.30 * AT.wet); if (wEnd < 1.1) wEnd = 1.1; + var r1 = Math.ceil(horizon + CO.eyeY * CO.scale / wEnd); + if (r1 > rows - 1) r1 = rows - 1; + var d = w - wEnd; if (d < 0.2) return; + var r, den, wf, q, fall, dth, lum, dd; + for (r = r0; r <= r1; r++) { + den = r + 0.5 - horizon; + if (den < 0.4) continue; + wf = CO.eyeY * CO.scale / den; + q = (w - wf) / d; + if (q < 0) q = 0; else if (q > 1) continue; + fall = (1 - q) * (1 - q); + dth = hk(x, r, sd, 5); + if (dth > 0.26 + 0.62 * fall * AT.wet) continue; + dd = wf * len; + lum = fog(peak * 0.50 * fall * AT.wet * AT.dim, dd); + if (lum < 5) continue; + + put(frame, x + ((hk(x, r >> 1, sd, 6) * 2.6) | 0) - 1, r, + dth < 0.11 ? G_QUOTE : G_COLON, hue, lum, dd * 0.994); + } + } + + var SP = { salt: 0 }; + + function shopOpen(rec, u) { + var sd = (rec.seed * 4294967296) | 0; + var th = (CC.Surf && CC.Surf.SHOP_OPEN) || 0.52; + return hash2(Math.floor(u / 2.55), 0, sd ^ 0x7E31) < th; + } + + CC.ELEMENTS.push({ + name: 'shopSpill', + + world: 'cyber', + layer: 28, + + init: function (city, rng) { + this.city = city; + SP.salt = (rng() * 2147483647) | 0; + }, + + update: function () {}, + + draw: function (frame, cam, t) { + var city = this.city; + if (!city) return; + setCam(frame, cam); + airPrep(); + + var R = 25; + var gx0 = Math.floor(CO.ox - R), gx1 = Math.floor(CO.ox + R); + var gz0 = Math.floor(CO.oz - R), gz1 = Math.floor(CO.oz + R); + var rows = CO.rows, cols = CO.cols, horizon = CO.horizon; + var drawn = 0, gx, gz; + + for (gz = gz0; gz <= gz1; gz++) { + for (gx = gx0; gx <= gx1; gx++) { + + if (drawn > 22) return; + var rx = gx + 0.5 - CO.ox, rz = gz + 0.5 - CO.oz; + var w = rx * CO.fwx + rz * CO.fwz; + if (w < 1.2 || w > R) continue; + var side = rx * CO.rgx + rz * CO.rgz, lim = w * CO.hp + 2.5; + if (side > lim || side < -lim) continue; + if (hk(gx, gz, SP.salt, 6) > 0.62) continue; + if (city.height(gx, gz) <= 0) continue; + if (!faceOf(city, gx, gz, rx, rz)) continue; + + var rec = city.cell(gx, gz); + if (!rec) continue; + var nx = FACE.nx, nz = FACE.nz; + + var u = nx ? FACE.fz : FACE.fx; + if (!shopOpen(rec, u)) continue; + + if (!project(FACE.fx + nx * 0.5, 0.1, FACE.fz + nz * 0.5)) continue; + var span = colsFor(0.75, VP.w); + var xa = Math.floor(VP.x - span), xb = Math.ceil(VP.x + span); + if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; + if (xb < xa) continue; + + var hs = hk(gx, gz, SP.salt, 1); + + var hue = (rec.sign && hs < 0.58) ? signHue(rec, hs, S_MARQUEE) + : (hs < 0.74 ? P.warm : (hs < 0.93 ? P.amber : P.ice)); + var depth = 1.15 + hs * 0.75; + var peak = 74 + hk(gx, gz, SP.salt, 2) * 46; + + if (!CC.reducedMotion) peak *= 0.90 + 0.10 * vnoise(t * 0.5 + hs * 30, SP.salt); + + peak *= clamp(0.68 + 0.32 * AT.wet, 0.60, 1.16) * AT.dim; + + var hit = 0; + + var planeX = FACE.fx, planeZ = FACE.fz; + + var wLo = w - depth - 1.2; if (wLo < 0.9) wLo = 0.9; + var rTop = Math.floor(horizon + CO.eyeY * CO.scale / (w + 1.2)); + var rBot = Math.ceil(horizon + CO.eyeY * CO.scale / wLo); + if (rTop < Math.floor(horizon) + 1) rTop = Math.floor(horizon) + 1; + if (rBot > rows - 1) rBot = rows - 1; + var a0 = (nx ? FACE.fz : FACE.fx) - 0.5, a1 = a0 + 1; + + for (var x = xa; x <= xb; x++) { + var sp = (2 * (x + 0.5) / cols - 1) * CO.hp; + var dx = CO.fwx + CO.rgx * sp, dz = CO.fwz + CO.rgz * sp; + var len = Math.sqrt(1 + sp * sp); + + for (var r = rTop; r <= rBot; r++) { + var den = r + 0.5 - horizon; + if (den < 0.4) continue; + var wf = CO.eyeY * CO.scale / den; + var px = CO.ox + dx * wf, pz = CO.oz + dz * wf; + var out = (px - planeX) * nx + (pz - planeZ) * nz; + if (out < 0.04 || out > depth) continue; + var along = nx ? pz : px; + if (along < a0 || along > a1) continue; + var k = 1 - out / depth; + var dith = hk(Math.floor(px * 3.1), Math.floor(pz * 3.1), SP.salt, 3); + if (dith > 0.30 + k * 0.20) continue; + var lum = fog(peak * k * k * (0.6 + 0.8 * dith), wf * len); + if (lum < 5) continue; + + if (put(frame, x, r, SPILL_G[((dith * 977) | 0) % SPILL_N], hue, lum, + wf * len * 0.994)) hit = 1; } + } + drawn += hit; } - return false; + } + } + }); + + var NE = { salt: 0 }; + var SIGN_CAP = 14; + + var AREA_T = 108; + + function setupSign(gx, gz, bh, rec, t) { + var nx = FACE.nx, nz = FACE.nz; + var tx = nz, tz = -nx; + var r1 = hk(gx, gz, NE.salt, 1), r2 = hk(gx, gz, NE.salt, 2), r3 = hk(gx, gz, NE.salt, 3); + var r4 = hk(gx, gz, NE.salt, 4), r9 = hk(gx, gz, NE.salt, 9); + var style = pickStyle(rec ? rec.did : 0, hk(gx, gz, NE.salt, 5)); + var W, H, v0, L, blade = 0, vert = 0; + + if (style === S_BLADE && bh < 15) style = S_MARQUEE; + + switch (style) { + case S_BLADE: + + blade = 1; + L = 0.85 + r2 * 0.80; + H = 3.4 + r3 * 4.6; + if (H > bh - 6) H = bh - 6; + if (H < 2.2) H = 2.2; + v0 = 5.0 + r9 * (bh - H - 7 > 0 ? bh - H - 7 : 0); + W = L; + break; + case S_BLOCK: + + vert = (bh > 19 && r2 < 0.66) ? 1 : 0; + if (vert) { + W = 0.95; H = 2.9 + r3 * 3.4; + if (H > bh - 8) H = bh - 8; + if (H < 2.0) { vert = 0; } + } + if (vert) v0 = 4.6 + r9 * (bh - H - 8 > 0 ? bh - H - 8 : 0); + else { W = 1.9 + r3 * 0.9; H = 1.05; v0 = 3.0 + r9 * 1.9; } + break; + case S_TUBE: W = 1.7 + r3 * 0.9; H = 0.95 + r2 * 0.80; v0 = 2.95 + r9 * 1.7; break; + case S_ARROW: W = 0.70; H = 1.9 + r3 * 0.9; v0 = 2.45 + r9 * 0.7; break; + case S_SCREEN: W = 1.5 + r3 * 1.1; H = 1.05 + r2 * 0.9; v0 = 3.1 + r9 * 2.6; break; + case S_TICKER: W = 2.0 + r3 * 0.9; H = 0.60; v0 = 3.2 + r9 * 1.6; break; + case S_CHASE: W = 1.8 + r3 * 0.8; H = 0.95 + r2 * 0.5; v0 = 3.0 + r9 * 1.5; break; + case S_FLAP: W = 1.5 + r3 * 0.8; H = 0.70 + r2 * 0.4; v0 = 3.0 + r9 * 1.5; break; + case S_BACKLIT: W = 1.5 + r3 * 1.0; H = 0.95 + r2 * 0.7; v0 = 3.2 + r9 * 2.2; break; + default: W = 1.6 + r3 * 0.9; H = 0.62 + r2 * 0.5; v0 = 3.1 + r9 * 1.4; break; } - function flick(kind, ph, t, j, dead) { - if (kind === 2 && j === dead) return 0.10; - if (CC.reducedMotion) return 0.88; - if (kind === 0) return 1; - if (kind === 1) { + var cx = FACE.fx, cz = FACE.fz; + if (blade) { + GEO.ax = cx + nx * 0.18; GEO.az = cz + nz * 0.18; + GEO.bx = cx + nx * (0.18 + L); GEO.bz = cz + nz * (0.18 + L); + } else { - var b = vnoise(t * 2.8 + ph * 17, 0x8117); - var w = CC.smooth(clamp((b - 0.20) / 0.12, 0, 1)); - return (0.30 + 0.5 * b) * (1 - w) + (0.84 + 0.16 * b) * w; + var off = (r4 - 0.5) * 0.30; + GEO.ax = cx + nx * 0.30 + tx * (off - W * 0.5); + GEO.az = cz + nz * 0.30 + tz * (off - W * 0.5); + GEO.bx = cx + nx * 0.30 + tx * (off + W * 0.5); + GEO.bz = cz + nz * 0.30 + tz * (off + W * 0.5); + } + GEO.v0 = v0; GEO.H = H; + + BD.ncW = Math.round(W / 0.30); if (BD.ncW < 2) BD.ncW = 2; else if (BD.ncW > 9) BD.ncW = 9; + BD.nrW = Math.round(H / 0.34); if (BD.nrW < 2) BD.nrW = 2; else if (BD.nrW > 14) BD.nrW = 14; + BD.bv = vert; + if (style === S_BLOCK) { + + var nch; + if (vert) { + BD.ncW = 2; + nch = Math.round(H / 1.02); if (nch < 2) nch = 2; else if (nch > 6) nch = 6; + BD.nrW = nch * 3 - 1; + } else { + nch = Math.round(W / 0.92); if (nch < 2) nch = 2; else if (nch > 4) nch = 4; + BD.ncW = nch * 3 - 1; BD.nrW = 2; + } + } + if (style === S_ARROW) { BD.ncW = 2; BD.nrW = Math.round(H / 0.42); if (BD.nrW < 3) BD.nrW = 3; } + + BD.nc = BD.ncW; BD.nr = BD.nrW; BD.gs = 1; BD.rs = 1; + + BD.style = style; + BD.hue = signHue(rec, r1, style); + BD.kind = (hk(gx, gz, NE.salt, 6) * 4) | 0; + BD.ph = hk(gx, gz, NE.salt, 7); + BD.gl = NEON_G[(r3 * NEON_N) | 0]; + + BD.gl2 = NEON_G[(hk(gx, gz, NE.salt, 8) * NEON_N) | 0]; + + BD.dead = (hk(gx + 7, gz - 3, NE.salt, 0) * BD.ncW) | 0; + BD.dead2 = (hk(gx - 5, gz + 11, NE.salt, 0) * BD.nrW) | 0; + + BD.sd = (hk(gx + 13, gz + 17, NE.salt, 2) * 30011) | 0; + BD.tt = CC.reducedMotion ? BD.ph * 31 : t; + + BD.cased = style === S_BACKLIT ? 0 : 1; + + BD.massk = 0.82 * flick(BD.kind, BD.ph, t, -1, -2); + + var peak = 178 + hk(gx + 3, gz - 5, NE.salt, 1) * 66; + BD.halo = 0.50; + if (style === S_SCREEN) { peak *= 0.80; BD.halo = 0.70; } + else if (style === S_BACKLIT) { peak *= 0.50; BD.halo = 1.70; } + else if (style === S_TICKER) { peak *= 0.86; BD.halo = 0.42; } + else if (style === S_BLOCK) BD.halo = 0.62; + BD.peak = peak * gutter(t, BD.ph); + + var rate = style === S_CHASE ? 0.22 : (style === S_WIPE ? 0.26 : 0.30); + BD.sweep = CC.reducedMotion ? BD.ph : (BD.ph + t * rate) % 1; + } + + function board(frame, t) { + if (!projInto(GEO.ax, GEO.v0, GEO.az, VA)) return 0; + if (!projInto(GEO.bx, GEO.v0, GEO.bz, VB)) return 0; + var cols = CO.cols, rows = CO.rows; + var xL, xR, wL, wR; + if (VA.x <= VB.x) { xL = VA.x; wL = VA.w; xR = VB.x; wR = VB.w; } + else { xL = VB.x; wL = VB.w; xR = VA.x; wR = VA.w; } + + var span = xR - xL; + if (span < 0.9) { var mid = (xL + xR) * 0.5; xL = mid - 0.45; xR = mid + 0.45; span = 0.9; } + if (xR < 0 || xL > cols - 1) return 0; + + var wMid = 2 / (1 / wL + 1 / wR); + var hRows = GEO.H * CO.scale / wMid; + var cxs = (xL + xR) * 0.5; + var cys = CO.horizon - (GEO.v0 + GEO.H * 0.5 - CO.eyeY) * CO.scale / wMid; + var spC = (2 * (cxs + 0.5) / cols - 1) * CO.hp; + var distMid = wMid * Math.sqrt(1 + spC * spC); + + var xa = Math.floor(xL), xb = Math.ceil(xR); + if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; + if (xb < xa) return 0; + + var sgc = Math.round(span); if (sgc < 2) sgc = 2; + var sgr = Math.round(hRows); if (sgr < 2) sgr = 2; + BD.nc = BD.ncW < sgc ? BD.ncW : sgc; + BD.nr = BD.nrW < sgr ? BD.nrW : sgr; + if (BD.style === S_BLOCK) { + + if (BD.bv) BD.nr = blockGrid(BD.nr); else BD.nc = blockGrid(BD.nc); + } + BD.gs = BD.nc > 0 ? BD.ncW / BD.nc : 1; + BD.rs = BD.nr > 0 ? BD.nrW / BD.nr : 1; + + var mnc = MIN_C[BD.style], mnr = MIN_R[BD.style]; + if (BD.style === S_BLOCK && BD.bv) { mnc = 2; mnr = 5; } + var dfc = (mnc - span) * 0.5, dfr = (mnr - hRows) * 0.5; + if (dfr > dfc) dfc = dfr; + BD.lod = BD.cased ? CC.smooth(clamp(dfc, 0, 1)) : 0; + + var area = (xb - xa + 1) * (hRows < 1 ? 1 : hRows); + BD.dens = area > AREA_T ? AREA_T / area : 1; + if (BD.dens < 0.24) BD.dens = 0.24; + + var vis = boardVisible(frame, xL, xR, cys, distMid); + if (vis) { + + var gr = span * 0.55 + 1.8; if (gr > 15) gr = 15; + var gy = hRows * 0.55 + 1.4; if (gy > 9) gy = 9; + + castGlow(frame, cxs, cys, gr, gy, BD.hue, + BD.halo * AT.halo * clamp(BD.peak / 210, 0.40, 1.20), distMid); + } + + var hit = 0, x, r, s, iw, w, u, sp, len, dist, yBot, yTop, vspan, r0, r1, v, lum; + for (x = xa; x <= xb; x++) { + s = (x + 0.5 - xL) / span; + if (s < 0) s = 0; else if (s > 1) s = 1; + iw = (1 - s) / wL + s / wR; + w = 1 / iw; + u = (s / wR) / iw; + sp = (2 * (x + 0.5) / cols - 1) * CO.hp; + len = Math.sqrt(1 + sp * sp); + dist = w * len * 0.996; + yBot = CO.horizon - (GEO.v0 - CO.eyeY) * CO.scale / w; + yTop = yBot - GEO.H * CO.scale / w; + vspan = yBot - yTop; + if (vspan < 0.4) vspan = 0.4; + r0 = Math.ceil(yTop); r1 = Math.floor(yBot); + if (r0 < 0) r0 = 0; if (r1 > rows - 1) r1 = rows - 1; + if (r1 < r0) continue; + for (r = r0; r <= r1; r++) { + v = (yBot - (r + 0.5)) / vspan; + if (v < 0) v = 0; else if (v > 1) v = 1; + + if (BD.dens < 1 && hk((u * BD.ncW * 3) | 0, (v * BD.nrW * 3) | 0, BD.sd, 4) > BD.dens) continue; + if (!shade(u, v, t)) { + + if (!BD.cased) continue; + SH.c = BD.hue; + + SH.g = ((((u * BD.ncW) | 0) + ((v * BD.nrW) | 0)) & 1) ? BD.gl : BD.gl2; + SH.k = 0.10; } - if (kind === 2) return 0.97; - return 0.66 + 0.34 * (0.5 + 0.5 * Math.sin(t * 0.8 + ph * 6.283)); + + if (BD.lod > 0) SH.k += (BD.massk - SH.k) * BD.lod; + lum = fog(BD.peak * SH.k * AT.dim, dist); + + if (lum < 4) lum = 4; + if (put(frame, x, r, SH.g, SH.c, lum, dist)) hit = 1; + } } - function crest(d, hold, soft) { - d -= Math.floor(d); - if (d > 0.5) d = 1 - d; - return CC.smooth(clamp((hold + soft - d) / soft, 0, 1)); - } + if (vis) wetSmear(frame, cxs, wMid, BD.hue, BD.peak, BD.sd); + return hit; + } - var HKX = [0, 104729, 611953, 1999993, 3391993, 4796027, 7919, 2750159, 4256233, 1299709]; - var HKZ = [0, 4256233, 1299709, 4796027, 611953, 2750159, 3391993, 104729, 7919, 1999993]; - function hk(a, b, salt, i) { return hash2(a + HKX[i], b + HKZ[i], salt); } + CC.ELEMENTS.push({ + name: 'neon', - function neonHue(r) { + world: 'cyber', + layer: 30, - return r < 0.34 ? P.amber : r < 0.68 ? P.azure : r < 0.80 ? P.warm - : r < 0.90 ? P.ember : P.spring; - } + init: function (city, rng) { + this.city = city; + NE.salt = (rng() * 2147483647) | 0; + }, - var S_TUBE = 0, - S_BLADE = 1, - S_CHASE = 2, - S_WIPE = 3, - S_TICKER = 4, - S_BLOCK = 5, - S_FLAP = 6, - S_FAIL = 7, - S_BACKLIT = 8, - S_ARROW = 9, - S_SCREEN = 10, - S_MARQUEE = 11, - S_N = 12; + update: function () {}, - var STYLE_W = [ + draw: function (frame, cam, t) { + var city = this.city; + if (!city) return; + setCam(frame, cam); + airPrep(); - [ 6, 3, 3, 2, 1, 4, 2, 3, 2, 3, 1, 5], - [ 2, 3, 2, 4, 5, 3, 3, 1, 3, 1, 6, 2], - [ 3, 1, 1, 1, 1, 2, 2, 6, 5, 2, 1, 3], - [ 4, 2, 2, 1, 1, 2, 2, 5, 2, 5, 1, 3], - [ 3, 3, 2, 2, 2, 3, 4, 2, 3, 2, 2, 3], - [ 3, 5, 6, 4, 4, 6, 3, 2, 2, 4, 5, 2] - ]; + var R = 58; + var gx0 = Math.floor(CO.ox - R), gx1 = Math.floor(CO.ox + R); + var gz0 = Math.floor(CO.oz - R), gz1 = Math.floor(CO.oz + R); + var drawn = 0, gx, gz; - var MIN_C = [4, 1, 4, 3, 3, 5, 3, 3, 3, 2, 3, 3]; - var MIN_R = [3, 4, 3, 2, 2, 2, 2, 2, 2, 4, 2, 2]; + for (gz = gz0; gz <= gz1; gz++) { + for (gx = gx0; gx <= gx1; gx++) { - function blockGrid(n) { - var k = ((n + 1) / 3) | 0; - return (k < 1 ? 1 : k) * 3 - 1; - } + if (drawn > SIGN_CAP) return; + var rx = gx + 0.5 - CO.ox, rz = gz + 0.5 - CO.oz; + var w = rx * CO.fwx + rz * CO.fwz; + if (w < 2.2 || w > R) continue; + var side = rx * CO.rgx + rz * CO.rgz, lim = w * CO.hp + 3; + if (side > lim || side < -lim) continue; - function pickStyle(did, r) { - var w = STYLE_W[did] || STYLE_W[0], tot = 0, i; - for (i = 0; i < S_N; i++) tot += w[i]; - var x = r * tot; - for (i = 0; i < S_N; i++) { x -= w[i]; if (x <= 0) return i; } - return S_MARQUEE; - } + if (hk(gx, gz, NE.salt, 0) > 0.105) continue; + var bh = city.height(gx, gz); + if (bh < 6) continue; + if (!faceOf(city, gx, gz, rx, rz)) continue; - var BD = { - style: 0, hue: 0, sd: 0, ph: 0, kind: 0, dead: 0, dead2: 0, - gl: 0, gl2: 0, nc: 2, nr: 2, ncW: 2, nrW: 2, gs: 1, rs: 1, - bv: 0, peak: 200, halo: 0.55, dens: 1, cased: 1, lod: 0, massk: 0.82, sweep: 0, tt: 0 - }; - var SH = { g: 0, k: 0, c: 0 }; - var GEO = { ax: 0, az: 0, bx: 0, bz: 0, v0: 0, H: 0 }; + var rec = city.cell(gx, gz); + if (!rec) continue; - function signHue(rec, r, style) { - var h = (rec && rec.sign) ? rec.sign.hue : neonHue(r); - - if (h === P.violet && style !== S_SCREEN && style !== S_TICKER) h = P.azure; - - if (h === P.slate || h === P.white || h === P.shadow) h = r < 0.5 ? P.amber : P.azure; - return h; - } - - function shade(u, v, t) { - var nc = BD.nc, nr = BD.nr; - var ci = (u * nc) | 0; if (ci < 0) ci = 0; else if (ci >= nc) ci = nc - 1; - var ri = (v * nr) | 0; if (ri < 0) ri = 0; else if (ri >= nr) ri = nr - 1; - - var cw = BD.gs > 1 ? (ci * BD.gs) | 0 : ci; - var rw = BD.rs > 1 ? (ri * BD.rs) | 0 : ri; - var edge, quad, pl, pi, p, k, j, ff, st, fr, d, lv, a, b, bi, ix, iy, pk, cs; - SH.c = BD.hue; - - switch (BD.style) { - - case S_TUBE: - - edge = (ci === 0 || ci === nc - 1 || ri === 0 || ri === nr - 1); - if (!edge) { - if (nr < 5 || ri !== (nr >> 1) || (ci & 1)) return false; - SH.g = (cw & 2) ? BD.gl : BD.gl2; - SH.k = 0.60 * flick(BD.kind, BD.ph, t, cw, BD.dead2); - return true; - } - - quad = (ci * 2 >= nc ? 1 : 0) + (ri * 2 >= nr ? 2 : 0); - SH.g = (ri === 0 || ri === nr - 1) ? BD.gl : G_PIPE; - SH.k = quad === (BD.dead & 3) ? 0.09 - : (0.86 + 0.14 * hk(cw, rw, BD.sd, 3)) * flick(BD.kind, BD.ph, t, 0, -1); - return true; - - case S_BLADE: - - k = v * nr; - j = k | 0; ff = k - j; - if (ff > 0.66) return false; - j = BD.rs > 1 ? (j * BD.rs) | 0 : j; - SH.g = hk(j, cw, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; - SH.k = (0.86 + 0.20 * hk(j, cw, BD.sd, 1)) * flick(BD.kind, BD.ph, t, j, BD.dead); - return true; - - case S_CHASE: - - edge = (ci === 0 || ci === nc - 1 || ri === 0 || ri === nr - 1); - if (edge) { - pl = 2 * (nc + nr) - 4; if (pl < 1) pl = 1; - if (ri === 0) pi = ci; - else if (ci === nc - 1) pi = (nc - 1) + ri; - else if (ri === nr - 1) pi = (nc - 1) + (nr - 1) + (nc - 1 - ci); - else pi = 2 * (nc - 1) + (nr - 1) + (nr - 1 - ri); - p = crest(pi / pl - BD.sweep, 0.10, 0.09); - SH.g = p > 0.34 ? G_O : G_oo; - SH.k = 0.26 + 0.86 * p; - return true; - } - if (nr < 3 || ri !== (nr >> 1)) return false; - if ((ci & 3) === 3) return false; - SH.g = hk(cw, 0, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; - SH.k = 0.74 * flick(BD.kind, BD.ph, t, cw, BD.dead); - return true; - - case S_WIPE: - - k = u * nc; - j = k | 0; ff = k - j; - if (ff > 0.68) return false; - SH.g = hk(cw, rw, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; - SH.k = (0.30 + 0.68 * crest(u - BD.sweep, 0.08, 0.13)) * - flick(BD.kind, BD.ph, t, cw, BD.dead); - return true; - - case S_TICKER: - - if (nr > 2 && (ri === 0 || ri === nr - 1)) { - SH.g = G_DASH; SH.k = 0.22; return true; - } - st = CC.reducedMotion ? 0 : (BD.tt * 2.0) | 0; - SH.g = TICK_G[((hk(cw + st, rw, BD.sd, 4) * 1361) | 0) % TICK_N]; - SH.k = 0.52 + 0.44 * hk(cw, rw, BD.sd, 5); - return true; - - case S_BLOCK: - - if (BD.bv) { - if (ri % 3 === 2) return false; - bi = (ri / 3) | 0; ix = ci; iy = ri % 3; - } else { - if (ci % 3 === 2) return false; - bi = (ci / 3) | 0; ix = ci % 3; iy = ri; - } - - bi = BD.bv ? (BD.rs > 1 ? (bi * BD.rs) | 0 : bi) : (BD.gs > 1 ? (bi * BD.gs) | 0 : bi); - pk = hk(bi * 4 + ix, iy, BD.sd + 41, 8); - if (pk < 0.15) return false; - cs = hk(bi, 0, BD.sd + 7, 7); - SH.g = BLOCK_G[(((cs * 977 + pk * 131) | 0) % BLOCK_N)]; - SH.k = (0.82 + 0.18 * pk) * flick(BD.kind, BD.ph, t, bi, BD.dead); - return true; - - case S_FLAP: - - p = hk(cw, rw, BD.sd, 6); - k = BD.tt * 0.55 + p * 7; - st = k | 0; fr = k - st; - d = fr < 0.5 ? fr : 1 - fr; - SH.g = TICK_G[((hk(st + cw * 5, rw, BD.sd, 4) * 1361) | 0) % TICK_N]; - - SH.k = 0.94 - 0.52 * CC.smooth(clamp((0.28 - d) / 0.28, 0, 1)); - return true; - - case S_FAIL: - - if (ri === BD.dead2 % nr) { SH.g = BD.gl2; SH.k = 0.07; return true; } - if (ci === BD.dead % nc) { - SH.g = BD.gl; - SH.k = CC.reducedMotion ? 0.56 - : 0.42 + 0.28 * (0.5 + 0.5 * Math.sin(BD.tt * 13.82 + BD.ph * 6.283)); - return true; - } - k = u * nc; j = k | 0; ff = k - j; - if (ff > 0.70) return false; - SH.g = hk(cw, rw, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; - SH.k = 0.80 + 0.14 * hk(cw, rw, BD.sd, 1); - return true; - - case S_BACKLIT: - - edge = (ci === 0 || ci === nc - 1 || ri === 0 || ri === nr - 1); - if (edge) { SH.g = BD.gl; SH.k = 0.42 + 0.12 * hk(cw, rw, BD.sd, 3); return true; } - SH.c = P.shadow; - SH.g = G_HASH; SH.k = 0.34; - return true; - - case S_ARROW: - - p = crest((nr - 1 - ri) / nr - BD.sweep, 0.09, 0.16); - SH.g = ri === nr - 1 ? G_EQ : G_V; - SH.k = 0.24 + 0.82 * p; - return true; - - case S_SCREEN: - - a = vnoise(BD.tt * 0.45 + cw * 0.83 + BD.ph * 9, BD.sd + 101); - b = vnoise(BD.tt * 0.37 + rw * 1.29 + BD.ph * 5, BD.sd + 211); - lv = clamp(a * 0.66 + b * 0.52 - 0.13, 0, 1); - - j = (lv * SCREEN_N) | 0; if (j >= SCREEN_N) j = SCREEN_N - 1; - SH.g = SCREEN_G[j]; - SH.k = 0.16 + 0.90 * lv * lv; - return true; - - default: - - k = u * nc; - j = k | 0; ff = k - j; - if (ff > 0.62) return false; - SH.g = hk(cw, rw, BD.sd, 2) < 0.55 ? BD.gl : BD.gl2; - SH.k = (0.84 + 0.22 * hk(cw, rw, BD.sd, 1)) * flick(BD.kind, BD.ph, t, cw, BD.dead); - return true; + setupSign(gx, gz, bh, rec, t); + drawn += board(frame, t); } + } } + }); - function castGlow(frame, cx, cy, rx, ry, hue, amt, dist) { - if (amt < 0.03 || rx < 0.5 || ry < 0.5) return; - var cols = CO.cols, rows = CO.rows; - var xa = Math.floor(cx - rx), xb = Math.ceil(cx + rx); - var ya = Math.floor(cy - ry), yb = Math.ceil(cy + ry); - if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; - if (ya < 0) ya = 0; if (yb > rows - 1) yb = rows - 1; - if (xb < xa || yb < ya) return; - var dNear = dist * 0.55, dFar = dist * 1.5; - var x, y, dx, dy, rr, i, l0, nd, k, add; - for (y = ya; y <= yb; y++) { - dy = (y + 0.5 - cy) / ry; - if (dy < -1 || dy > 1) continue; + var TS = { salt: 0 }; + var LAMP_V = [4.30, 4.66, 5.02]; + var LAMP_C = [P.spring, P.amber, P.red]; + var CYCLE = 46; + + CC.ELEMENTS.push({ + name: 'signals', + + world: 'cyber', + layer: 31, + + init: function (city, rng) { + this.city = city; + TS.salt = (rng() * 2147483647) | 0; + }, + + update: function () {}, + + draw: function (frame, cam, t) { + var city = this.city; + if (!city || !city.aveX) return; + setCam(frame, cam); + airPrep(); + + var R = 62; + var k0 = Math.round((CO.ox - R) / city.AVE), k1 = Math.round((CO.ox + R) / city.AVE); + var m0 = Math.round((CO.oz - R) / city.CROSS), m1 = Math.round((CO.oz + R) / city.CROSS); + var k, m, s; + + for (k = k0; k <= k1; k++) { + var aw = city.aveW(k); + if (aw < 3) continue; + var ix = city.aveX(k) + 0.5; + for (m = m0; m <= m1; m++) { + var cw = city.crossW(m); + if (cw < 2) continue; + var iz = city.crossZ(m) + 0.5; + + var phase = hk(k, m, TS.salt, 1) * CYCLE; + var u = CC.reducedMotion ? phase : (t + phase) % CYCLE; + if (u < 0) u += CYCLE; + var on = u < 21 ? 0 : (u < 25 ? 1 : 2); + + var blink = (on === 1 && !CC.reducedMotion) ? (0.55 + 0.45 * Math.sin(u * 9)) : 1; + + var zs = hk(k, m, TS.salt, 2) < 0.5 ? -1 : 1; + for (s = -1; s <= 1; s += 2) { + + var hx = ix + s * (aw - 0.2), hz = iz + zs * (cw + 0.9); + if (city.height(hx, hz) > 0) continue; + var lit = 0, lw = 0, lx = 0; + for (var li = 0; li < 3; li++) { + if (!project(hx, LAMP_V[li], hz)) break; + var near = VP.dist < 21; + if (li !== on && !near) continue; + var lum = li === on ? fog(236 * blink * AT.dim, VP.dist) : fog(15, VP.dist); + if (lum < 5) continue; + put(frame, Math.round(VP.x), Math.round(VP.y), + li === on ? G_O : G_oo, li === on ? LAMP_C[li] : P.shadow, lum, VP.dist); + if (li === on) { lw = VP.w; lx = VP.x; } + lit++; + } + + if (lit && VP.dist < 15 && project(hx, 4.05, hz)) + put(frame, Math.round(VP.x), Math.round(VP.y), G_EQ, P.shadow, + fog(20, VP.dist), VP.dist); + + if (lw > 0) wetSmear(frame, lx, lw, LAMP_C[on], 96, TS.salt & 0x7fff); + } + } + } + } + }); + + var HO = { salt: 0 }; + var HZ = 30; + + var HXF = 0.30; + + CC.ELEMENTS.push({ + name: 'holo', + + world: 'cyber', + layer: 33, + + init: function (city, rng) { + this.city = city; + HO.salt = (rng() * 2147483647) | 0; + }, + + update: function () {}, + + draw: function (frame, cam, t) { + var city = this.city; + if (!city || !city.aveX) return; + setCam(frame, cam); + airPrep(); + + var kn = Math.round(CO.ox / city.AVE), k0 = kn - 1, k1 = kn + 1; + var j0 = Math.floor((CO.oz - 30) / HZ), j1 = Math.floor((CO.oz + 105) / HZ); + var rows = CO.rows, cols = CO.cols, drawn = 0, k, j; + + for (k = k0; k <= k1; k++) { + var aw = city.aveW(k); + if (aw < 3) continue; + var ax = city.aveX(k) + 0.5; + for (j = j0; j <= j1; j++) { + if (drawn > 1) return; + if (hk(k, j, HO.salt, 0) > 0.42) continue; + + var hx = ax + (hk(k, j, HO.salt, 1) - 0.5) * aw * 1.1; + var hz = j * HZ + hk(k, j, HO.salt, 2) * (HZ - 6); + var hy = 5.4 + hk(k, j, HO.salt, 3) * 4.6; + var ph = hk(k, j, HO.salt, 4); + if (!CC.reducedMotion) hy += Math.sin(t * 0.33 + ph * 6.283) * 0.28; + + if (!project(hx, hy, hz)) continue; + var d = VP.dist; + + if (d < 17) continue; + var near = d < 34 ? clamp((d - 17) / 17, 0, 1) : 1; + + near *= clamp(AT.dim * 0.92 + 0.08 * AT.halo, 0.42, 1.12); + + if (fog(335 * near, d) < 5) continue; + + var W = 3.4 + hk(k, j, HO.salt, 5) * 3.0; + var H = 2.2 + hk(k, j, HO.salt, 6) * 2.2; + var hw = colsFor(W * 0.5, VP.w); + var hh = H * 0.5 * CO.scale / VP.w; + if (hw < 0.8 || hh < 0.6) continue; + + var pL = VP.x - hw, pT = VP.y - hh; + var xa0 = Math.floor(pL), xb0 = Math.ceil(VP.x + hw); + var ya0 = Math.floor(pT), yb0 = Math.ceil(VP.y + hh); + var xa = xa0 < 0 ? 0 : xa0, xb = xb0 > cols - 1 ? cols - 1 : xb0; + var ya = ya0 < 0 ? 0 : ya0, yb = yb0 > rows - 1 ? rows - 1 : yb0; + if (xb < xa || yb < ya) continue; + + var NC = Math.round(W / 0.30); if (NC < 4) NC = 4; + var NR = Math.round(H / 0.30); if (NR < 3) NR = 3; + + var hr = hk(k, j, HO.salt, 7); + + var hue = hr < 0.54 ? P.azure : (hr < 0.86 ? P.ice : (hr < 0.94 ? P.violet : P.spring)); + + var sweep = CC.reducedMotion ? ph : (ph + t * 0.30) % 1; + var cover = 0; + + var NRi = NR / (2 * hh); + var pB = pT + 2 * hh; + var edged = hh > 1.2, laced = hh > 1.6; + + var yLo = ya - 1; if (yLo < 0) yLo = 0; + var yHi = yb + 1; if (yHi > rows - 1) yHi = rows - 1; + var y, yc, ew, eT, eB, gv, band, gr, mA, mB, wA, wB, lwA, lwB, lwMax, lineOnly; + var x, gu, cb, val, best, gsel, h2, vv, lum; + + for (y = yLo; y <= yHi; y++) { + yc = y + 0.5; + + ew = 0; + if (edged) { + eT = 1 - (yc > pT ? yc - pT : pT - yc); + eB = 1 - (yc > pB ? yc - pB : pB - yc); + ew = eT > eB ? eT : eB; + if (ew < 0) ew = 0; + } + + if (ew <= 0 && (y & 1) === 1 && laced) continue; + + lineOnly = laced && (y & 1) === 1; + gv = (yc - pT) / (2 * hh); + + band = 1 + 0.7 * crest(gv - sweep, 0.10, 0.10); + + gr = (yc - pT) * NRi - 0.5; + mA = Math.floor(gr); + mB = mA + 1; + wB = CC.smooth(clamp((gr - mA - 0.5) / HXF + 0.5, 0, 1)); + wA = 1 - wB; + if (mA < 0 || mA >= NR) wA = 0; + if (mB < 0 || mB >= NR) wB = 0; + if (lineOnly) { wA = 0; wB = 0; } + if (wA <= 0 && wB <= 0 && ew <= 0) continue; + + lwA = wA > 0 ? 0.42 + 0.58 * hk(mA, j * 31 + k, HO.salt, 8) : 0; + lwB = wB > 0 ? 0.42 + 0.58 * hk(mB, j * 31 + k, HO.salt, 8) : 0; + lwMax = ew > 0 ? 1 : (lwA > lwB ? lwA : lwB); for (x = xa; x <= xb; x++) { - dx = (x + 0.5 - cx) / rx; - rr = dx * dx + dy * dy; - if (rr > 1) continue; - i = y * cols + x; - if (frame.ch[i] === 0) continue; - l0 = frame.lum[i]; - if (l0 === 0) continue; - if (!(frame.dist[i] > dNear && frame.dist[i] < dFar)) continue; - k = 1 - Math.sqrt(rr); k *= k; - add = fog(amt * k * 104, frame.dist[i]); - if (add < 3) continue; - nd = nearer(frame.dist[i]); - if (nd < 0) continue; - put(frame, x, y, frame.ch[i], k > 0.44 ? hue : frame.col[i], l0 + add, nd, - frame.kind[i]); - } - } - } - - function boardVisible(frame, xL, xR, cy, dist) { - var cols = CO.cols, y = Math.round(cy); - if (y < 0) y = 0; else if (y > CO.rows - 1) y = CO.rows - 1; - var lim = dist * 0.86, q, x; - for (q = 0; q < 3; q++) { - x = Math.round(xL + (xR - xL) * (0.1 + 0.4 * q)); - if (x < 0 || x > cols - 1) continue; - if (!(frame.dist[y * cols + x] < lim)) return true; - } - return false; - } - - function wetSmear(frame, cx, w, hue, peak, sd) { - if (AT.wet < 0.22 || peak < 20) return; - var cols = CO.cols, rows = CO.rows, horizon = CO.horizon; - var x = Math.round(cx); - if (x < 0 || x > cols - 1 || w < 1.6 || w > 44) return; - var sp = (2 * (x + 0.5) / cols - 1) * CO.hp, len = Math.sqrt(1 + sp * sp); - var r0 = Math.floor(horizon + CO.eyeY * CO.scale / w); - var lo = Math.floor(horizon) + 1; if (r0 < lo) r0 = lo; - - var wEnd = w * (0.60 - 0.30 * AT.wet); if (wEnd < 1.1) wEnd = 1.1; - var r1 = Math.ceil(horizon + CO.eyeY * CO.scale / wEnd); - if (r1 > rows - 1) r1 = rows - 1; - var d = w - wEnd; if (d < 0.2) return; - var r, den, wf, q, fall, dth, lum, dd; - for (r = r0; r <= r1; r++) { - den = r + 0.5 - horizon; - if (den < 0.4) continue; - wf = CO.eyeY * CO.scale / den; - q = (w - wf) / d; - if (q < 0) q = 0; else if (q > 1) continue; - fall = (1 - q) * (1 - q); - dth = hk(x, r, sd, 5); - if (dth > 0.26 + 0.62 * fall * AT.wet) continue; - dd = wf * len; - lum = fog(peak * 0.50 * fall * AT.wet * AT.dim, dd); - if (lum < 5) continue; - - put(frame, x + ((hk(x, r >> 1, sd, 6) * 2.6) | 0) - 1, r, - dth < 0.11 ? G_QUOTE : G_COLON, hue, lum, dd * 0.994); - } - } - - var SP = { salt: 0 }; - - function shopOpen(rec, u) { - var sd = (rec.seed * 4294967296) | 0; - var th = (CC.Surf && CC.Surf.SHOP_OPEN) || 0.52; - return hash2(Math.floor(u / 2.55), 0, sd ^ 0x7E31) < th; - } - - CC.ELEMENTS.push({ - name: 'shopSpill', - - world: 'cyber', - layer: 28, - - init: function (city, rng) { - this.city = city; - SP.salt = (rng() * 2147483647) | 0; - }, - - update: function () {}, - - draw: function (frame, cam, t) { - var city = this.city; - if (!city) return; - setCam(frame, cam); - airPrep(); - - var R = 25; - var gx0 = Math.floor(CO.ox - R), gx1 = Math.floor(CO.ox + R); - var gz0 = Math.floor(CO.oz - R), gz1 = Math.floor(CO.oz + R); - var rows = CO.rows, cols = CO.cols, horizon = CO.horizon; - var drawn = 0, gx, gz; - - for (gz = gz0; gz <= gz1; gz++) { - for (gx = gx0; gx <= gx1; gx++) { - - if (drawn > 22) return; - var rx = gx + 0.5 - CO.ox, rz = gz + 0.5 - CO.oz; - var w = rx * CO.fwx + rz * CO.fwz; - if (w < 1.2 || w > R) continue; - var side = rx * CO.rgx + rz * CO.rgz, lim = w * CO.hp + 2.5; - if (side > lim || side < -lim) continue; - if (hk(gx, gz, SP.salt, 6) > 0.62) continue; - if (city.height(gx, gz) <= 0) continue; - if (!faceOf(city, gx, gz, rx, rz)) continue; - - var rec = city.cell(gx, gz); - if (!rec) continue; - var nx = FACE.nx, nz = FACE.nz; - - var u = nx ? FACE.fz : FACE.fx; - if (!shopOpen(rec, u)) continue; - - if (!project(FACE.fx + nx * 0.5, 0.1, FACE.fz + nz * 0.5)) continue; - var span = colsFor(0.75, VP.w); - var xa = Math.floor(VP.x - span), xb = Math.ceil(VP.x + span); - if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; - if (xb < xa) continue; - - var hs = hk(gx, gz, SP.salt, 1); - - var hue = (rec.sign && hs < 0.58) ? signHue(rec, hs, S_MARQUEE) - : (hs < 0.74 ? P.warm : (hs < 0.93 ? P.amber : P.ice)); - var depth = 1.15 + hs * 0.75; - var peak = 74 + hk(gx, gz, SP.salt, 2) * 46; - - if (!CC.reducedMotion) peak *= 0.90 + 0.10 * vnoise(t * 0.5 + hs * 30, SP.salt); - - peak *= clamp(0.68 + 0.32 * AT.wet, 0.60, 1.16) * AT.dim; - - var hit = 0; - - var planeX = FACE.fx, planeZ = FACE.fz; - - var wLo = w - depth - 1.2; if (wLo < 0.9) wLo = 0.9; - var rTop = Math.floor(horizon + CO.eyeY * CO.scale / (w + 1.2)); - var rBot = Math.ceil(horizon + CO.eyeY * CO.scale / wLo); - if (rTop < Math.floor(horizon) + 1) rTop = Math.floor(horizon) + 1; - if (rBot > rows - 1) rBot = rows - 1; - var a0 = (nx ? FACE.fz : FACE.fx) - 0.5, a1 = a0 + 1; - - for (var x = xa; x <= xb; x++) { - var sp = (2 * (x + 0.5) / cols - 1) * CO.hp; - var dx = CO.fwx + CO.rgx * sp, dz = CO.fwz + CO.rgz * sp; - var len = Math.sqrt(1 + sp * sp); - - for (var r = rTop; r <= rBot; r++) { - var den = r + 0.5 - horizon; - if (den < 0.4) continue; - var wf = CO.eyeY * CO.scale / den; - var px = CO.ox + dx * wf, pz = CO.oz + dz * wf; - var out = (px - planeX) * nx + (pz - planeZ) * nz; - if (out < 0.04 || out > depth) continue; - var along = nx ? pz : px; - if (along < a0 || along > a1) continue; - var k = 1 - out / depth; - var dith = hk(Math.floor(px * 3.1), Math.floor(pz * 3.1), SP.salt, 3); - if (dith > 0.30 + k * 0.20) continue; - var lum = fog(peak * k * k * (0.6 + 0.8 * dith), wf * len); - if (lum < 5) continue; - - if (put(frame, x, r, SPILL_G[((dith * 977) | 0) % SPILL_N], hue, lum, - wf * len * 0.994)) hit = 1; - } - } - drawn += hit; + gu = (x + 0.5 - pL) / (2 * hw); + if (gu > lwMax) break; + cb = (gu * NC) | 0; + if (cb < 0) cb = 0; else if (cb >= NC) cb = NC - 1; + val = 0; best = 0; gsel = G_DASH; + if (wA > 0 && gu <= lwA) { + h2 = hk(cb + j * 13, mA + k * 7, HO.salt, 9); + if (h2 <= 0.50) { + vv = wA * (72 + h2 * 250); + val += vv; + if (vv > best) { best = vv; gsel = HOLO_G[((h2 * 1361) | 0) % HOLO_N]; } } + } + if (wB > 0 && gu <= lwB) { + h2 = hk(cb + j * 13, mB + k * 7, HO.salt, 9); + if (h2 <= 0.50) { + vv = wB * (72 + h2 * 250); + val += vv; + if (vv > best) { best = vv; gsel = HOLO_G[((h2 * 1361) | 0) % HOLO_N]; } + } + } + val *= band; best *= band; + + if (ew > 0) { + val *= 1 - ew; best *= 1 - ew; + if ((cb & 1) === 0) { + vv = 74 * ew; + val += vv; + if (vv > best) { best = vv; gsel = G_DASH; } + } + } + if (val <= 0) continue; + lum = fog(val * near, d); + + if (lum < 5) { + if (!cover && d < frame.dist[y * cols + x]) cover = 1; + continue; + } + if (put(frame, x, y, gsel, hue, lum, d)) cover = 1; } + } + drawn += cover; } - }); - - var NE = { salt: 0 }; - var SIGN_CAP = 14; - - var AREA_T = 108; - - function setupSign(gx, gz, bh, rec, t) { - var nx = FACE.nx, nz = FACE.nz; - var tx = nz, tz = -nx; - var r1 = hk(gx, gz, NE.salt, 1), r2 = hk(gx, gz, NE.salt, 2), r3 = hk(gx, gz, NE.salt, 3); - var r4 = hk(gx, gz, NE.salt, 4), r9 = hk(gx, gz, NE.salt, 9); - var style = pickStyle(rec ? rec.did : 0, hk(gx, gz, NE.salt, 5)); - var W, H, v0, L, blade = 0, vert = 0; - - if (style === S_BLADE && bh < 15) style = S_MARQUEE; - - switch (style) { - case S_BLADE: - - blade = 1; - L = 0.85 + r2 * 0.80; - H = 3.4 + r3 * 4.6; - if (H > bh - 6) H = bh - 6; - if (H < 2.2) H = 2.2; - v0 = 5.0 + r9 * (bh - H - 7 > 0 ? bh - H - 7 : 0); - W = L; - break; - case S_BLOCK: - - vert = (bh > 19 && r2 < 0.66) ? 1 : 0; - if (vert) { - W = 0.95; H = 2.9 + r3 * 3.4; - if (H > bh - 8) H = bh - 8; - if (H < 2.0) { vert = 0; } - } - if (vert) v0 = 4.6 + r9 * (bh - H - 8 > 0 ? bh - H - 8 : 0); - else { W = 1.9 + r3 * 0.9; H = 1.05; v0 = 3.0 + r9 * 1.9; } - break; - case S_TUBE: W = 1.7 + r3 * 0.9; H = 0.95 + r2 * 0.80; v0 = 2.95 + r9 * 1.7; break; - case S_ARROW: W = 0.70; H = 1.9 + r3 * 0.9; v0 = 2.45 + r9 * 0.7; break; - case S_SCREEN: W = 1.5 + r3 * 1.1; H = 1.05 + r2 * 0.9; v0 = 3.1 + r9 * 2.6; break; - case S_TICKER: W = 2.0 + r3 * 0.9; H = 0.60; v0 = 3.2 + r9 * 1.6; break; - case S_CHASE: W = 1.8 + r3 * 0.8; H = 0.95 + r2 * 0.5; v0 = 3.0 + r9 * 1.5; break; - case S_FLAP: W = 1.5 + r3 * 0.8; H = 0.70 + r2 * 0.4; v0 = 3.0 + r9 * 1.5; break; - case S_BACKLIT: W = 1.5 + r3 * 1.0; H = 0.95 + r2 * 0.7; v0 = 3.2 + r9 * 2.2; break; - default: W = 1.6 + r3 * 0.9; H = 0.62 + r2 * 0.5; v0 = 3.1 + r9 * 1.4; break; - } - - var cx = FACE.fx, cz = FACE.fz; - if (blade) { - GEO.ax = cx + nx * 0.18; GEO.az = cz + nz * 0.18; - GEO.bx = cx + nx * (0.18 + L); GEO.bz = cz + nz * (0.18 + L); - } else { - - var off = (r4 - 0.5) * 0.30; - GEO.ax = cx + nx * 0.30 + tx * (off - W * 0.5); - GEO.az = cz + nz * 0.30 + tz * (off - W * 0.5); - GEO.bx = cx + nx * 0.30 + tx * (off + W * 0.5); - GEO.bz = cz + nz * 0.30 + tz * (off + W * 0.5); - } - GEO.v0 = v0; GEO.H = H; - - BD.ncW = Math.round(W / 0.30); if (BD.ncW < 2) BD.ncW = 2; else if (BD.ncW > 9) BD.ncW = 9; - BD.nrW = Math.round(H / 0.34); if (BD.nrW < 2) BD.nrW = 2; else if (BD.nrW > 14) BD.nrW = 14; - BD.bv = vert; - if (style === S_BLOCK) { - - var nch; - if (vert) { - BD.ncW = 2; - nch = Math.round(H / 1.02); if (nch < 2) nch = 2; else if (nch > 6) nch = 6; - BD.nrW = nch * 3 - 1; - } else { - nch = Math.round(W / 0.92); if (nch < 2) nch = 2; else if (nch > 4) nch = 4; - BD.ncW = nch * 3 - 1; BD.nrW = 2; - } - } - if (style === S_ARROW) { BD.ncW = 2; BD.nrW = Math.round(H / 0.42); if (BD.nrW < 3) BD.nrW = 3; } - - BD.nc = BD.ncW; BD.nr = BD.nrW; BD.gs = 1; BD.rs = 1; - - BD.style = style; - BD.hue = signHue(rec, r1, style); - BD.kind = (hk(gx, gz, NE.salt, 6) * 4) | 0; - BD.ph = hk(gx, gz, NE.salt, 7); - BD.gl = NEON_G[(r3 * NEON_N) | 0]; - - BD.gl2 = NEON_G[(hk(gx, gz, NE.salt, 8) * NEON_N) | 0]; - - BD.dead = (hk(gx + 7, gz - 3, NE.salt, 0) * BD.ncW) | 0; - BD.dead2 = (hk(gx - 5, gz + 11, NE.salt, 0) * BD.nrW) | 0; - - BD.sd = (hk(gx + 13, gz + 17, NE.salt, 2) * 30011) | 0; - BD.tt = CC.reducedMotion ? BD.ph * 31 : t; - - BD.cased = style === S_BACKLIT ? 0 : 1; - - BD.massk = 0.82 * flick(BD.kind, BD.ph, t, -1, -2); - - var peak = 178 + hk(gx + 3, gz - 5, NE.salt, 1) * 66; - BD.halo = 0.50; - if (style === S_SCREEN) { peak *= 0.80; BD.halo = 0.70; } - else if (style === S_BACKLIT) { peak *= 0.50; BD.halo = 1.70; } - else if (style === S_TICKER) { peak *= 0.86; BD.halo = 0.42; } - else if (style === S_BLOCK) BD.halo = 0.62; - BD.peak = peak * gutter(t, BD.ph); - - var rate = style === S_CHASE ? 0.22 : (style === S_WIPE ? 0.26 : 0.30); - BD.sweep = CC.reducedMotion ? BD.ph : (BD.ph + t * rate) % 1; + } } - - function board(frame, t) { - if (!projInto(GEO.ax, GEO.v0, GEO.az, VA)) return 0; - if (!projInto(GEO.bx, GEO.v0, GEO.bz, VB)) return 0; - var cols = CO.cols, rows = CO.rows; - var xL, xR, wL, wR; - if (VA.x <= VB.x) { xL = VA.x; wL = VA.w; xR = VB.x; wR = VB.w; } - else { xL = VB.x; wL = VB.w; xR = VA.x; wR = VA.w; } - - var span = xR - xL; - if (span < 0.9) { var mid = (xL + xR) * 0.5; xL = mid - 0.45; xR = mid + 0.45; span = 0.9; } - if (xR < 0 || xL > cols - 1) return 0; - - var wMid = 2 / (1 / wL + 1 / wR); - var hRows = GEO.H * CO.scale / wMid; - var cxs = (xL + xR) * 0.5; - var cys = CO.horizon - (GEO.v0 + GEO.H * 0.5 - CO.eyeY) * CO.scale / wMid; - var spC = (2 * (cxs + 0.5) / cols - 1) * CO.hp; - var distMid = wMid * Math.sqrt(1 + spC * spC); - - var xa = Math.floor(xL), xb = Math.ceil(xR); - if (xa < 0) xa = 0; if (xb > cols - 1) xb = cols - 1; - if (xb < xa) return 0; - - var sgc = Math.round(span); if (sgc < 2) sgc = 2; - var sgr = Math.round(hRows); if (sgr < 2) sgr = 2; - BD.nc = BD.ncW < sgc ? BD.ncW : sgc; - BD.nr = BD.nrW < sgr ? BD.nrW : sgr; - if (BD.style === S_BLOCK) { - - if (BD.bv) BD.nr = blockGrid(BD.nr); else BD.nc = blockGrid(BD.nc); - } - BD.gs = BD.nc > 0 ? BD.ncW / BD.nc : 1; - BD.rs = BD.nr > 0 ? BD.nrW / BD.nr : 1; - - var mnc = MIN_C[BD.style], mnr = MIN_R[BD.style]; - if (BD.style === S_BLOCK && BD.bv) { mnc = 2; mnr = 5; } - var dfc = (mnc - span) * 0.5, dfr = (mnr - hRows) * 0.5; - if (dfr > dfc) dfc = dfr; - BD.lod = BD.cased ? CC.smooth(clamp(dfc, 0, 1)) : 0; - - var area = (xb - xa + 1) * (hRows < 1 ? 1 : hRows); - BD.dens = area > AREA_T ? AREA_T / area : 1; - if (BD.dens < 0.24) BD.dens = 0.24; - - var vis = boardVisible(frame, xL, xR, cys, distMid); - if (vis) { - - var gr = span * 0.55 + 1.8; if (gr > 15) gr = 15; - var gy = hRows * 0.55 + 1.4; if (gy > 9) gy = 9; - - castGlow(frame, cxs, cys, gr, gy, BD.hue, - BD.halo * AT.halo * clamp(BD.peak / 210, 0.40, 1.20), distMid); - } - - var hit = 0, x, r, s, iw, w, u, sp, len, dist, yBot, yTop, vspan, r0, r1, v, lum; - for (x = xa; x <= xb; x++) { - s = (x + 0.5 - xL) / span; - if (s < 0) s = 0; else if (s > 1) s = 1; - iw = (1 - s) / wL + s / wR; - w = 1 / iw; - u = (s / wR) / iw; - sp = (2 * (x + 0.5) / cols - 1) * CO.hp; - len = Math.sqrt(1 + sp * sp); - dist = w * len * 0.996; - yBot = CO.horizon - (GEO.v0 - CO.eyeY) * CO.scale / w; - yTop = yBot - GEO.H * CO.scale / w; - vspan = yBot - yTop; - if (vspan < 0.4) vspan = 0.4; - r0 = Math.ceil(yTop); r1 = Math.floor(yBot); - if (r0 < 0) r0 = 0; if (r1 > rows - 1) r1 = rows - 1; - if (r1 < r0) continue; - for (r = r0; r <= r1; r++) { - v = (yBot - (r + 0.5)) / vspan; - if (v < 0) v = 0; else if (v > 1) v = 1; - - if (BD.dens < 1 && hk((u * BD.ncW * 3) | 0, (v * BD.nrW * 3) | 0, BD.sd, 4) > BD.dens) continue; - if (!shade(u, v, t)) { - - if (!BD.cased) continue; - SH.c = BD.hue; - - SH.g = ((((u * BD.ncW) | 0) + ((v * BD.nrW) | 0)) & 1) ? BD.gl : BD.gl2; - SH.k = 0.10; - } - - if (BD.lod > 0) SH.k += (BD.massk - SH.k) * BD.lod; - lum = fog(BD.peak * SH.k * AT.dim, dist); - - if (lum < 4) lum = 4; - if (put(frame, x, r, SH.g, SH.c, lum, dist)) hit = 1; - } - } - - if (vis) wetSmear(frame, cxs, wMid, BD.hue, BD.peak, BD.sd); - return hit; - } - - CC.ELEMENTS.push({ - name: 'neon', - - world: 'cyber', - layer: 30, - - init: function (city, rng) { - this.city = city; - NE.salt = (rng() * 2147483647) | 0; - }, - - update: function () {}, - - draw: function (frame, cam, t) { - var city = this.city; - if (!city) return; - setCam(frame, cam); - airPrep(); - - var R = 58; - var gx0 = Math.floor(CO.ox - R), gx1 = Math.floor(CO.ox + R); - var gz0 = Math.floor(CO.oz - R), gz1 = Math.floor(CO.oz + R); - var drawn = 0, gx, gz; - - for (gz = gz0; gz <= gz1; gz++) { - for (gx = gx0; gx <= gx1; gx++) { - - if (drawn > SIGN_CAP) return; - var rx = gx + 0.5 - CO.ox, rz = gz + 0.5 - CO.oz; - var w = rx * CO.fwx + rz * CO.fwz; - if (w < 2.2 || w > R) continue; - var side = rx * CO.rgx + rz * CO.rgz, lim = w * CO.hp + 3; - if (side > lim || side < -lim) continue; - - if (hk(gx, gz, NE.salt, 0) > 0.105) continue; - var bh = city.height(gx, gz); - if (bh < 6) continue; - if (!faceOf(city, gx, gz, rx, rz)) continue; - - var rec = city.cell(gx, gz); - if (!rec) continue; - - setupSign(gx, gz, bh, rec, t); - drawn += board(frame, t); - } - } - } - }); - - var TS = { salt: 0 }; - var LAMP_V = [4.30, 4.66, 5.02]; - var LAMP_C = [P.spring, P.amber, P.red]; - var CYCLE = 46; - - CC.ELEMENTS.push({ - name: 'signals', - - world: 'cyber', - layer: 31, - - init: function (city, rng) { - this.city = city; - TS.salt = (rng() * 2147483647) | 0; - }, - - update: function () {}, - - draw: function (frame, cam, t) { - var city = this.city; - if (!city || !city.aveX) return; - setCam(frame, cam); - airPrep(); - - var R = 62; - var k0 = Math.round((CO.ox - R) / city.AVE), k1 = Math.round((CO.ox + R) / city.AVE); - var m0 = Math.round((CO.oz - R) / city.CROSS), m1 = Math.round((CO.oz + R) / city.CROSS); - var k, m, s; - - for (k = k0; k <= k1; k++) { - var aw = city.aveW(k); - if (aw < 3) continue; - var ix = city.aveX(k) + 0.5; - for (m = m0; m <= m1; m++) { - var cw = city.crossW(m); - if (cw < 2) continue; - var iz = city.crossZ(m) + 0.5; - - var phase = hk(k, m, TS.salt, 1) * CYCLE; - var u = CC.reducedMotion ? phase : (t + phase) % CYCLE; - if (u < 0) u += CYCLE; - var on = u < 21 ? 0 : (u < 25 ? 1 : 2); - - var blink = (on === 1 && !CC.reducedMotion) ? (0.55 + 0.45 * Math.sin(u * 9)) : 1; - - var zs = hk(k, m, TS.salt, 2) < 0.5 ? -1 : 1; - for (s = -1; s <= 1; s += 2) { - - var hx = ix + s * (aw - 0.2), hz = iz + zs * (cw + 0.9); - if (city.height(hx, hz) > 0) continue; - var lit = 0, lw = 0, lx = 0; - for (var li = 0; li < 3; li++) { - if (!project(hx, LAMP_V[li], hz)) break; - var near = VP.dist < 21; - if (li !== on && !near) continue; - var lum = li === on ? fog(236 * blink * AT.dim, VP.dist) : fog(15, VP.dist); - if (lum < 5) continue; - put(frame, Math.round(VP.x), Math.round(VP.y), - li === on ? G_O : G_oo, li === on ? LAMP_C[li] : P.shadow, lum, VP.dist); - if (li === on) { lw = VP.w; lx = VP.x; } - lit++; - } - - if (lit && VP.dist < 15 && project(hx, 4.05, hz)) - put(frame, Math.round(VP.x), Math.round(VP.y), G_EQ, P.shadow, - fog(20, VP.dist), VP.dist); - - if (lw > 0) wetSmear(frame, lx, lw, LAMP_C[on], 96, TS.salt & 0x7fff); - } - } - } - } - }); - - var HO = { salt: 0 }; - var HZ = 30; - - var HXF = 0.30; - - CC.ELEMENTS.push({ - name: 'holo', - - world: 'cyber', - layer: 33, - - init: function (city, rng) { - this.city = city; - HO.salt = (rng() * 2147483647) | 0; - }, - - update: function () {}, - - draw: function (frame, cam, t) { - var city = this.city; - if (!city || !city.aveX) return; - setCam(frame, cam); - airPrep(); - - var kn = Math.round(CO.ox / city.AVE), k0 = kn - 1, k1 = kn + 1; - var j0 = Math.floor((CO.oz - 30) / HZ), j1 = Math.floor((CO.oz + 105) / HZ); - var rows = CO.rows, cols = CO.cols, drawn = 0, k, j; - - for (k = k0; k <= k1; k++) { - var aw = city.aveW(k); - if (aw < 3) continue; - var ax = city.aveX(k) + 0.5; - for (j = j0; j <= j1; j++) { - if (drawn > 1) return; - if (hk(k, j, HO.salt, 0) > 0.42) continue; - - var hx = ax + (hk(k, j, HO.salt, 1) - 0.5) * aw * 1.1; - var hz = j * HZ + hk(k, j, HO.salt, 2) * (HZ - 6); - var hy = 5.4 + hk(k, j, HO.salt, 3) * 4.6; - var ph = hk(k, j, HO.salt, 4); - if (!CC.reducedMotion) hy += Math.sin(t * 0.33 + ph * 6.283) * 0.28; - - if (!project(hx, hy, hz)) continue; - var d = VP.dist; - - if (d < 17) continue; - var near = d < 34 ? clamp((d - 17) / 17, 0, 1) : 1; - - near *= clamp(AT.dim * 0.92 + 0.08 * AT.halo, 0.42, 1.12); - - if (fog(335 * near, d) < 5) continue; - - var W = 3.4 + hk(k, j, HO.salt, 5) * 3.0; - var H = 2.2 + hk(k, j, HO.salt, 6) * 2.2; - var hw = colsFor(W * 0.5, VP.w); - var hh = H * 0.5 * CO.scale / VP.w; - if (hw < 0.8 || hh < 0.6) continue; - - var pL = VP.x - hw, pT = VP.y - hh; - var xa0 = Math.floor(pL), xb0 = Math.ceil(VP.x + hw); - var ya0 = Math.floor(pT), yb0 = Math.ceil(VP.y + hh); - var xa = xa0 < 0 ? 0 : xa0, xb = xb0 > cols - 1 ? cols - 1 : xb0; - var ya = ya0 < 0 ? 0 : ya0, yb = yb0 > rows - 1 ? rows - 1 : yb0; - if (xb < xa || yb < ya) continue; - - var NC = Math.round(W / 0.30); if (NC < 4) NC = 4; - var NR = Math.round(H / 0.30); if (NR < 3) NR = 3; - - var hr = hk(k, j, HO.salt, 7); - - var hue = hr < 0.54 ? P.azure : (hr < 0.86 ? P.ice : (hr < 0.94 ? P.violet : P.spring)); - - var sweep = CC.reducedMotion ? ph : (ph + t * 0.30) % 1; - var cover = 0; - - var NRi = NR / (2 * hh); - var pB = pT + 2 * hh; - var edged = hh > 1.2, laced = hh > 1.6; - - var yLo = ya - 1; if (yLo < 0) yLo = 0; - var yHi = yb + 1; if (yHi > rows - 1) yHi = rows - 1; - var y, yc, ew, eT, eB, gv, band, gr, mA, mB, wA, wB, lwA, lwB, lwMax, lineOnly; - var x, gu, cb, val, best, gsel, h2, vv, lum; - - for (y = yLo; y <= yHi; y++) { - yc = y + 0.5; - - ew = 0; - if (edged) { - eT = 1 - (yc > pT ? yc - pT : pT - yc); - eB = 1 - (yc > pB ? yc - pB : pB - yc); - ew = eT > eB ? eT : eB; - if (ew < 0) ew = 0; - } - - if (ew <= 0 && (y & 1) === 1 && laced) continue; - - lineOnly = laced && (y & 1) === 1; - gv = (yc - pT) / (2 * hh); - - band = 1 + 0.7 * crest(gv - sweep, 0.10, 0.10); - - gr = (yc - pT) * NRi - 0.5; - mA = Math.floor(gr); - mB = mA + 1; - wB = CC.smooth(clamp((gr - mA - 0.5) / HXF + 0.5, 0, 1)); - wA = 1 - wB; - if (mA < 0 || mA >= NR) wA = 0; - if (mB < 0 || mB >= NR) wB = 0; - if (lineOnly) { wA = 0; wB = 0; } - if (wA <= 0 && wB <= 0 && ew <= 0) continue; - - lwA = wA > 0 ? 0.42 + 0.58 * hk(mA, j * 31 + k, HO.salt, 8) : 0; - lwB = wB > 0 ? 0.42 + 0.58 * hk(mB, j * 31 + k, HO.salt, 8) : 0; - lwMax = ew > 0 ? 1 : (lwA > lwB ? lwA : lwB); - for (x = xa; x <= xb; x++) { - gu = (x + 0.5 - pL) / (2 * hw); - if (gu > lwMax) break; - cb = (gu * NC) | 0; - if (cb < 0) cb = 0; else if (cb >= NC) cb = NC - 1; - val = 0; best = 0; gsel = G_DASH; - if (wA > 0 && gu <= lwA) { - h2 = hk(cb + j * 13, mA + k * 7, HO.salt, 9); - if (h2 <= 0.50) { - vv = wA * (72 + h2 * 250); - val += vv; - if (vv > best) { best = vv; gsel = HOLO_G[((h2 * 1361) | 0) % HOLO_N]; } - } - } - if (wB > 0 && gu <= lwB) { - h2 = hk(cb + j * 13, mB + k * 7, HO.salt, 9); - if (h2 <= 0.50) { - vv = wB * (72 + h2 * 250); - val += vv; - if (vv > best) { best = vv; gsel = HOLO_G[((h2 * 1361) | 0) % HOLO_N]; } - } - } - val *= band; best *= band; - - if (ew > 0) { - val *= 1 - ew; best *= 1 - ew; - if ((cb & 1) === 0) { - vv = 74 * ew; - val += vv; - if (vv > best) { best = vv; gsel = G_DASH; } - } - } - if (val <= 0) continue; - lum = fog(val * near, d); - - if (lum < 5) { - if (!cover && d < frame.dist[y * cols + x]) cover = 1; - continue; - } - if (put(frame, x, y, gsel, hue, lum, d)) cover = 1; - } - } - drawn += cover; - } - } - } - }); + }); })(CC); /* src/elements/sky.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2, hash1 = CC.hash1, vnoise = CC.vnoise; + var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2, hash1 = CC.hash1, vnoise = CC.vnoise; - var G_DOT = g('.'), G_COLON = g(':'), G_QUOTE = g("'"), G_TICK = g('`'), - G_DASH = g('-'), G_EQ = g('='), G_PLUS = g('+'), G_PIPE = g('|'), G_SLASH = g('/'), - G_BSLASH = g('\\'), G_HASH = g('#'), G_UNDER = g('_'), - G_8 = g('8'), G_OO = g('O'), G_o = g('o'), G_0 = g('0'), G_X = g('X'), G_Z = g('Z'), - G_W = g('W'), G_M = g('M'), G_N = g('N'), G_H = g('H'), G_A = g('A'), G_V = g('V'), - G_K = g('K'), G_Y = g('Y'), G_U = g('U'), G_TILDE = g('~'), G_CARET = g('^'), - G_COMMA = g(','), G_STAR = g('*'); + var G_DOT = g('.'), G_COLON = g(':'), G_QUOTE = g("'"), G_TICK = g('`'), + G_DASH = g('-'), G_EQ = g('='), G_PLUS = g('+'), G_PIPE = g('|'), G_SLASH = g('/'), + G_BSLASH = g('\\'), G_HASH = g('#'), G_UNDER = g('_'), + G_8 = g('8'), G_OO = g('O'), G_o = g('o'), G_0 = g('0'), G_X = g('X'), G_Z = g('Z'), + G_W = g('W'), G_M = g('M'), G_N = g('N'), G_H = g('H'), G_A = g('A'), G_V = g('V'), + G_K = g('K'), G_Y = g('Y'), G_U = g('U'), G_TILDE = g('~'), G_CARET = g('^'), + G_COMMA = g(','), G_STAR = g('*'); - var TAU = 6.283185307, QUARTER = 1.570796327; + var TAU = 6.283185307, QUARTER = 1.570796327; - var D_STAR = 1.0e5, D_CLOUD = 9.5e4, D_MOON = 9.0e4; + var D_STAR = 1.0e5, D_CLOUD = 9.5e4, D_MOON = 9.0e4; - var W_CLOUD = 0.75, W_FOG = 0.30, W_HAZE = 0.40, W_RAIN = 0.65, W_WIND = 0.55, W_FOGREL = 1; + var W_CLOUD = 0.75, W_FOG = 0.30, W_HAZE = 0.40, W_RAIN = 0.65, W_WIND = 0.55, W_FOGREL = 1; - var D_STAR_V = 1, D_LAMP = 1, D_SKY = 0; - function bindDay() { - var D = CC.Daylight; - D_STAR_V = D ? D.P.star : 1; - D_LAMP = D ? D.P.lamp : 1; - D_SKY = D ? D.P.sky : 0; + var D_STAR_V = 1, D_LAMP = 1, D_SKY = 0; + function bindDay() { + var D = CC.Daylight; + D_STAR_V = D ? D.P.star : 1; + D_LAMP = D ? D.P.lamp : 1; + D_SKY = D ? D.P.sky : 0; + } + function bindWeather() { + var Wm = CC.Weather, p = Wm ? Wm.P : null; + W_CLOUD = p ? p.cloud : 0.75; + W_FOG = p ? p.fog : 0.30; + W_HAZE = p ? p.haze : 0.40; + W_RAIN = p ? p.rain : 0.65; + W_WIND = p ? p.wind : 0.55; + W_FOGREL = Wm ? Wm.rel('fog') : 1; + } + + function cloudAt(dx, dy, dz, t) { + + var d = CC.reducedMotion ? 0 : t * (0.045 + 0.14 * W_WIND); + return vnoise(dx * 9.0 + dz * 2.5 + d, 0x6C1) * 0.56 + + vnoise(dz * 7.5 - dx * 3.0 + dy * 6.5 - d * 0.62, 0x6C2) * 0.44; + } + + function cloudThr() { return 0.88 - W_CLOUD * 0.72; } + + var CB = { fwx: 0, fwz: 1, rgx: 1, rgz: 0, half: 0.71, cols: 0, rows: 0, + horizon: 0, eyeY: 1.7, scale: 1, colsPerTan: 1 }; + + function setup(frame, cam) { + bindWeather(); + bindDay(); + var yaw = cam.yaw || 0, fov = cam.fov || 1.25; + CB.fwx = Math.sin(yaw); CB.fwz = Math.cos(yaw); + CB.rgx = Math.cos(yaw); CB.rgz = -Math.sin(yaw); + CB.half = Math.tan(fov * 0.5); + CB.cols = frame.cols; CB.rows = frame.rows; + CB.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; + CB.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + CB.colsPerTan = frame.cols / (2 * CB.half); + CB.scale = cam.scaleY !== undefined ? cam.scaleY : CB.colsPerTan * (cam.cellAspect || 0.5625); + } + + var VP = { ok: 0, x: 0, y: 0, w: 0, d: 0 }; + function proj(ex, ey, ez) { + VP.ok = 0; + var w = ex * CB.fwx + ez * CB.fwz; + if (w <= 1e-3) return VP; + var sp = (ex * CB.rgx + ez * CB.rgz) / w; + if (sp > 8 * CB.half || sp < -8 * CB.half) return VP; + VP.x = (sp / CB.half + 1) * CB.cols * 0.5 - 0.5; + VP.y = CB.horizon - ey * CB.scale / w; + VP.w = w; + VP.d = w * Math.sqrt(1 + sp * sp); + VP.ok = 1; + return VP; + } + + function plot(f, x, y, ch, col, lum, dist) { + if (lum < 3 || ch === 0) return; + x = Math.round(x); y = Math.round(y); + if (x < 0 || y < 0 || x >= CB.cols || y >= CB.rows) return; + if (y > CB.horizon) return; + put(f, x, y, ch, col, lum, dist); + } + + function fork(rng) { return CC.mulberry(((rng() * 4294967296) | 0) ^ 0x5C1E); } + + function forkCity(city, salt) { + return CC.mulberry((((city && city.seed !== undefined ? city.seed : 0) | 0) ^ salt) >>> 0); + } + + CC.ELEMENTS.push({ + name: 'cloudbase', + layer: 3, + + world: ['cyber', 'west'], + draw: function (frame, cam, t) { + setup(frame, cam); + + if (W_CLOUD < 0.40) return; + var thr = cloudThr(), cols = CB.cols; + var maxRow = Math.floor(CB.horizon); if (maxRow > CB.rows - 1) maxRow = CB.rows - 1; + + var dens = 0.15 + 0.19 * W_CLOUD; + + var base = 26 + 16 * W_CLOUD; + + var deckC = D_SKY > 0.50 ? P.stone : (D_SKY > 0.16 ? P.indigo : P.shadow); + var deckK = 1 + 2.6 * D_SKY * D_SKY; + + var lowRow = CB.horizon - CB.rows * 0.17; + var dist = frame.dist, col, row, sp, dirx, dirz, dy, len, nx, ny, nz, v, i, lum, gl, hue; + for (col = 0; col < cols; col++) { + sp = ((col + 0.5) * 2 / cols - 1) * CB.half; + dirx = CB.fwx + CB.rgx * sp; dirz = CB.fwz + CB.rgz * sp; + for (row = 0; row <= maxRow; row++) { + i = row * cols + col; + if (dist[i] < D_CLOUD) continue; + dy = (CB.horizon - row) / CB.scale; + len = Math.sqrt(dirx * dirx + dirz * dirz + dy * dy); + nx = dirx / len; ny = dy / len; nz = dirz / len; + v = cloudAt(nx, ny, nz, t); + if (v <= thr) continue; + + v = (v - thr) * 4; if (v > 1) v = 1; + + if (hash2((nx * 190) | 0, (ny * 260) | 0, 0x71C3) > dens * (0.30 + 1.2 * v)) continue; + gl = v > 0.62 ? G_TILDE : (v > 0.3 ? G_DASH : G_TICK); + lum = base * (0.55 + 0.75 * v) * deckK; + hue = deckC; + + if (row > lowRow && v > 0.55 && D_LAMP > 0.15 && CC.World && CC.World.is('cyber') && + hash2((nx * 190) | 0, (ny * 260) | 0, 0x71C4) < 0.30) { + hue = P.amber; lum = (44 + 30 * v) * D_LAMP; + } + plot(frame, col, row, gl, hue, lum, D_CLOUD); + } + } } - function bindWeather() { - var Wm = CC.Weather, p = Wm ? Wm.P : null; - W_CLOUD = p ? p.cloud : 0.75; - W_FOG = p ? p.fog : 0.30; - W_HAZE = p ? p.haze : 0.40; - W_RAIN = p ? p.rain : 0.65; - W_WIND = p ? p.wind : 0.55; - W_FOGREL = Wm ? Wm.rel('fog') : 1; + }); + + var NSTAR = 400; + var stX, stY, stZ, stL, stC, stG, stPh, stTw; + + CC.ELEMENTS.push({ + name: 'stars', + layer: 4, + + world: ['cyber', 'west'], + init: function (city, rng) { + var r = fork(rng), i; + stX = new Float32Array(NSTAR); stY = new Float32Array(NSTAR); stZ = new Float32Array(NSTAR); + stL = new Float32Array(NSTAR); stC = new Uint8Array(NSTAR); stG = new Uint8Array(NSTAR); + stPh = new Float32Array(NSTAR); stTw = new Float32Array(NSTAR); + for (i = 0; i < NSTAR; i++) { + var az = r() * TAU, u = r(); + var alt = 0.03 + u * u * 0.39; + var ca = Math.cos(alt); + stX[i] = Math.sin(az) * ca; stY[i] = Math.sin(alt); stZ[i] = Math.cos(az) * ca; + var m = r(); + + stL[i] = 30 + m * m * m * 118; + stC[i] = m > 0.94 ? P.ice : (m > 0.55 ? P.white : P.slate); + stG[i] = m > 0.97 ? G_PLUS : (m > 0.62 ? G_DOT : (r() < 0.5 ? G_QUOTE : G_TICK)); + stPh[i] = r() * 60; + stTw[i] = 1; + } + }, + update: function (dt, t) { + var still = CC.reducedMotion; + for (var i = 0; i < NSTAR; i++) + stTw[i] = still ? 0.88 : 0.52 + 0.48 * vnoise(t * 0.6 + stPh[i], 0x2A7 + i); + }, + draw: function (frame, cam, t) { + setup(frame, cam); + + var thr = cloudThr() - 0.05, FEATHER = 0.05; + var vis = 1 - W_FOG * 1.25; if (vis <= 0) return; if (vis > 1) vis = 1; + + vis *= D_STAR_V; if (vis <= 0.01) return; + for (var i = 0; i < NSTAR; i++) { + var p = proj(stX[i], stY[i], stZ[i]); + if (!p.ok) continue; + var m = (thr - cloudAt(stX[i], stY[i], stZ[i], t)) / FEATHER; + if (m <= 0) continue; + if (m > 1) m = 1; else m = m * m * (3 - 2 * m); + plot(frame, p.x, p.y, stG[i], stC[i], stL[i] * stTw[i] * vis * m, D_STAR); + } } + }); - function cloudAt(dx, dy, dz, t) { + var moAz0 = 0, moAlt = 0.2, moR = 0.030, moSeed = 0, moPhase = 0.42, moAz = 0; - var d = CC.reducedMotion ? 0 : t * (0.045 + 0.14 * W_WIND); - return vnoise(dx * 9.0 + dz * 2.5 + d, 0x6C1) * 0.56 + - vnoise(dz * 7.5 - dx * 3.0 + dy * 6.5 - d * 0.62, 0x6C2) * 0.44; + CC.ELEMENTS.push({ + name: 'moon', + layer: 5, + + world: ['cyber', 'west'], + init: function (city, rng) { + var r = fork(rng); + moAz0 = (r() - 0.5) * 0.26; + moAlt = 0.17 + r() * 0.08; + moR = 0.026 + r() * 0.008; + moSeed = (r() * 4294967296) | 0; + + moPhase = 0.34 + r() * 0.24; + moAz = moAz0; + }, + update: function (dt, t) { + moAz = moAz0 + (CC.reducedMotion ? 0 : t * 7.3e-5); + }, + draw: function (frame, cam) { + setup(frame, cam); + var ca = Math.cos(moAlt); + var p = proj(Math.sin(moAz) * ca, Math.sin(moAlt), Math.cos(moAz) * ca); + if (!p.ok) return; + var cx = p.x, cy = p.y; + var rw = moR * CB.colsPerTan / p.w, rh = moR * CB.scale / p.w; + if (rw < 1 || cx + rw < 0 || cx - rw >= CB.cols) return; + + var disc = 1.18 - 1.28 * W_CLOUD; if (disc <= 0.02) return; if (disc > 1) disc = 1; + + disc *= 0.10 + 0.90 * D_STAR_V; if (disc <= 0.02) return; + + var halo = (W_HAZE * 0.75 + W_CLOUD * 0.45) * Math.sqrt(disc); if (halo > 1) halo = 1; + if (halo > 0.10) { + + var hr = 2.1, hiw = Math.ceil(rw * hr), hih = Math.ceil(rh * hr), hx, hy, hu, hv, h2; + for (hy = -hih; hy <= hih; hy++) { + for (hx = -hiw; hx <= hiw; hx++) { + hu = hx / rw; hv = hy / rh; h2 = hu * hu + hv * hv; + if (h2 < 1.05 || h2 > hr * hr) continue; + if (hash2(hx, hy, moSeed ^ 0x5D) > 0.34) continue; + + plot(frame, cx + hx, cy + hy, h2 > 2.6 ? G_DOT : G_COMMA, P.ice, + 70 * halo * (1 - (h2 - 1.05) / (hr * hr - 1.05)), D_MOON + 1); + } + } + } + + var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; + for (dy = -ih; dy <= ih; dy++) { + for (dx = -iw; dx <= iw; dx++) { + var u = dx / rw, v = dy / rh, r2 = u * u + v * v; + if (r2 > 1.02) continue; + var su = u + moPhase; + if (su * su + v * v < 1.0) { + + if (r2 > 0.72 && hash2(dx, dy, moSeed ^ 0x3B) < 0.55) + plot(frame, cx + dx, cy + dy, G_DOT, P.slate, 13 * disc, D_MOON); + continue; + } + var lum = (124 + 76 * (1 - r2 * 0.6)) * disc; + + if (hash2(Math.floor(u * 2.6), Math.floor(v * 2.6), moSeed) < 0.24) lum *= 0.44; + var gl = r2 > 0.80 ? G_o : (hash2(dx, dy, moSeed ^ 0x91) < 0.5 ? G_8 : G_OO); + plot(frame, cx + dx, cy + dy, gl, P.white, lum, D_MOON); + } + } } + }); - function cloudThr() { return 0.88 - W_CLOUD * 0.72; } + var NAIR = 6, AIR_SPAN = 3200; + var acB, acD, acY, acS, acPh, acOff; - var CB = { fwx: 0, fwz: 1, rgx: 1, rgz: 0, half: 0.71, cols: 0, rows: 0, - horizon: 0, eyeY: 1.7, scale: 1, colsPerTan: 1 }; + CC.ELEMENTS.push({ + name: 'aircraft', - function setup(frame, cam) { - bindWeather(); - bindDay(); - var yaw = cam.yaw || 0, fov = cam.fov || 1.25; - CB.fwx = Math.sin(yaw); CB.fwz = Math.cos(yaw); - CB.rgx = Math.cos(yaw); CB.rgz = -Math.sin(yaw); - CB.half = Math.tan(fov * 0.5); - CB.cols = frame.cols; CB.rows = frame.rows; - CB.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; - CB.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - CB.colsPerTan = frame.cols / (2 * CB.half); - CB.scale = cam.scaleY !== undefined ? cam.scaleY : CB.colsPerTan * (cam.cellAspect || 0.5625); + world: 'cyber', + layer: 6, + init: function (city, rng) { + var r = fork(rng), i; + acB = new Float32Array(NAIR); acD = new Float32Array(NAIR); acY = new Float32Array(NAIR); + acS = new Float32Array(NAIR); acPh = new Float32Array(NAIR); acOff = new Float32Array(NAIR); + for (i = 0; i < NAIR; i++) { + acB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.6; + acD[i] = 1400 + r() * 1400; + acY[i] = acD[i] * (0.10 + r() * 0.15); + acS[i] = (r() < 0.5 ? -1 : 1) * (58 + r() * 40); + acPh[i] = r() * AIR_SPAN; + acOff[i] = 0; + } + }, + update: function (dt, t) { + var tt = CC.reducedMotion ? t * 0.08 : t; + for (var i = 0; i < NAIR; i++) { + var s = (acS[i] * tt + acPh[i]) % AIR_SPAN; + if (s < 0) s += AIR_SPAN; + acOff[i] = s - AIR_SPAN * 0.5; + } + }, + draw: function (frame, cam, t) { + setup(frame, cam); + var tt = CC.reducedMotion ? 0 : t; + + var seen = 1.25 - 1.30 * W_CLOUD; if (seen <= 0.03) return; if (seen > 1) seen = 1; + + var glow = W_FOG > 0.34 ? (W_FOG - 0.34) * 1.5 : 0; if (glow > 1) glow = 1; + for (var i = 0; i < NAIR; i++) { + var b = acB[i], sb = Math.sin(b), cb = Math.cos(b), s = acOff[i]; + var p = proj(acD[i] * sb + s * cb, acY[i] - CB.eyeY, acD[i] * cb - s * sb); + if (!p.ok) continue; + var px = p.x, py = p.y, pd = p.d; + plot(frame, px, py, G_DOT, P.slate, 17 * seen, pd); + var ph = tt * 0.55 + i * 0.4; ph -= Math.floor(ph); + var on = CC.reducedMotion ? 0.33 : (ph < 0.06 ? 1 : 0); + if (!on) continue; + plot(frame, px, py, G_DOT, P.red, 176 * on * seen, pd - 1); + if (glow > 0.02) { + + var gl = 74 * glow * on * seen; + plot(frame, px - 1, py, G_DOT, P.red, gl, pd - 0.5); + plot(frame, px + 1, py, G_DOT, P.red, gl, pd - 0.5); + plot(frame, px, py - 1, G_DOT, P.red, gl * 0.7, pd - 0.5); + plot(frame, px, py + 1, G_DOT, P.red, gl * 0.7, pd - 0.5); + } + } } + }); - var VP = { ok: 0, x: 0, y: 0, w: 0, d: 0 }; - function proj(ex, ey, ez) { - VP.ok = 0; - var w = ex * CB.fwx + ez * CB.fwz; - if (w <= 1e-3) return VP; - var sp = (ex * CB.rgx + ez * CB.rgz) / w; - if (sp > 8 * CB.half || sp < -8 * CB.half) return VP; - VP.x = (sp / CB.half + 1) * CB.cols * 0.5 - 0.5; - VP.y = CB.horizon - ey * CB.scale / w; - VP.w = w; - VP.d = w * Math.sqrt(1 + sp * sp); - VP.ok = 1; - return VP; + var NBEAM = 8, BEAM_LEN = 460; + var bmB, bmR, bmYb, bmAz0, bmAmp, bmW, bmPh, bmEl0, bmSeed, bmAz, bmEl; + + var BEAM_DENS = 0.46, BEAM_GAIN = 1; + + CC.ELEMENTS.push({ + name: 'searchlights', + + world: 'cyber', + layer: 8, + init: function (city, rng) { + var r = fork(rng), i; + bmB = new Float32Array(NBEAM); bmR = new Float32Array(NBEAM); bmYb = new Float32Array(NBEAM); + bmAz0 = new Float32Array(NBEAM); bmAmp = new Float32Array(NBEAM); + bmW = new Float32Array(NBEAM); bmPh = new Float32Array(NBEAM); bmEl0 = new Float32Array(NBEAM); + bmSeed = new Int32Array(NBEAM); bmAz = new Float32Array(NBEAM); bmEl = new Float32Array(NBEAM); + for (i = 0; i < NBEAM; i++) { + + bmB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.40; + bmR[i] = (i < 4 ? 230 : 420) + r() * 200; + bmYb[i] = bmR[i] * (0.13 + r() * 0.13); + bmAz0[i] = bmB[i] + (r() - 0.5) * 0.4; + bmAmp[i] = 0.30 + r() * 0.26; + bmW[i] = 0.20 + r() * 0.14; + bmPh[i] = r() * TAU; + bmEl0[i] = 0.60 + r() * 0.24; + bmSeed[i] = (r() * 4294967296) | 0; + bmAz[i] = bmAz0[i]; bmEl[i] = bmEl0[i]; + } + }, + update: function (dt, t) { + var tt = CC.reducedMotion ? 0 : t; + for (var i = 0; i < NBEAM; i++) { + bmAz[i] = bmAz0[i] + Math.sin(tt * bmW[i] + bmPh[i]) * bmAmp[i]; + + bmEl[i] = bmEl0[i] + Math.sin(tt * bmW[i] * 0.37 + bmPh[i] * 1.7) * 0.20; + } + }, + draw: function (frame, cam) { + setup(frame, cam); + + var k = W_FOGREL; if (k > 2.6) k = 2.6; + BEAM_DENS = 0.16 + 0.30 * k; if (BEAM_DENS > 0.80) BEAM_DENS = 0.80; + BEAM_GAIN = 0.40 + 0.60 * k; if (BEAM_GAIN > 1.9) BEAM_GAIN = 1.9; + for (var i = 0; i < NBEAM; i++) { + var sb = Math.sin(bmB[i]), cb = Math.cos(bmB[i]); + var ox = bmR[i] * sb, oz = bmR[i] * cb, oy = bmYb[i] - CB.eyeY; + var p = proj(ox, oy, oz); + if (!p.ok) continue; + var bx = p.x, by = p.y, bd = p.d; + + var el = bmEl[i], az = bmAz[i], ce = Math.cos(el); + var dx = Math.sin(az) * ce, dy = Math.sin(el), dz = Math.cos(az) * ce; + + var len = BEAM_LEN, k, ok = 0, tx = 0, ty = 0, td = 0; + for (k = 0; k < 5; k++) { + p = proj(ox + dx * len, oy + dy * len, oz + dz * len); + if (p.ok) { ok = 1; tx = p.x; ty = p.y; td = p.d; break; } + len *= 0.5; + } + if (!ok) continue; + + var sx = tx - bx, sy = ty - by; + var asx = sx < 0 ? -sx : sx, asy = sy < 0 ? -sy : sy; + var n = Math.round(asx > asy ? asx : asy); + if (n < 3) continue; + if (n > 140) n = 140; + + var gl = asy > asx * 1.4 ? G_PIPE : (sx * sy > 0 ? G_BSLASH : G_SLASH); + for (k = 0; k <= n; k++) { + + if (hash2(k, i, bmSeed[i]) > BEAM_DENS) continue; + var f = k / n, ff = 1 - f; + + plot(frame, bx + sx * f, by + sy * f, k < 3 ? G_COLON : gl, + f < 0.34 ? P.white : P.slate, 62 * BEAM_GAIN * ff * ff * Math.sqrt(ff), + bd + (td - bd) * f); + } + plot(frame, bx, by, G_OO, P.white, 96, bd); + } } + }); - function plot(f, x, y, ch, col, lum, dist) { - if (lum < 3 || ch === 0) return; - x = Math.round(x); y = Math.round(y); - if (x < 0 || y < 0 || x >= CB.cols || y >= CB.rows) return; - if (y > CB.horizon) return; - put(f, x, y, ch, col, lum, dist); + var D_TOWER = 9.2e4, NTOWER = 7; + var twB, twR, twH, twPer, twPh, twSeed; + + CC.ELEMENTS.push({ + name: 'beacons', + + world: 'cyber', + layer: 7, + init: function (city) { + var r = forkCity(city, 0x2B9A31), i; + twB = new Float32Array(NTOWER); twR = new Float32Array(NTOWER); twH = new Float32Array(NTOWER); + twPer = new Float32Array(NTOWER); twPh = new Float32Array(NTOWER); + twSeed = new Int32Array(NTOWER); + for (i = 0; i < NTOWER; i++) { + + twB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.34; + twR[i] = 520 + r() * 1500; + twH[i] = twR[i] * (0.10 + r() * 0.13); + + twPer[i] = 1.35 + r() * 1.9; + twPh[i] = r() * 10; + twSeed[i] = (r() * 30011) | 0; + } + }, + draw: function (frame, cam, t) { + setup(frame, cam); + + var vis = 1 - W_FOG * 1.5 - W_HAZE * 0.35; if (vis <= 0.02) return; if (vis > 1) vis = 1; + var tt = CC.reducedMotion ? 0 : t; + for (var i = 0; i < NTOWER; i++) { + var sb = Math.sin(twB[i]), cb = Math.cos(twB[i]); + var ox = twR[i] * sb, oz = twR[i] * cb; + var p = proj(ox, twH[i] - CB.eyeY, oz); + if (!p.ok) continue; + var cx = Math.round(p.x), yTop = p.y, d = p.d; + if (cx < 0 || cx >= CB.cols) continue; + p = proj(ox, twH[i] * 0.42 - CB.eyeY, oz); + if (!p.ok) continue; + var yBot = p.y, row; + if (yBot - yTop < 2) continue; + if (yBot - yTop > 46) yBot = yTop + 46; + + for (row = Math.round(yTop) + 1; row <= yBot; row++) + if (!((row - Math.round(yTop)) & 1)) + plot(frame, cx, row, G_PIPE, P.slate, 15 * vis, D_TOWER); + var ph = tt / twPer[i] + twPh[i]; ph -= Math.floor(ph); + var on = CC.reducedMotion ? 0.5 : (ph < 0.16 ? 1 : 0.10); + plot(frame, cx, yTop, on > 0.5 ? G_STAR : G_DOT, P.red, (40 + 150 * on) * vis, D_TOWER - 1); + + if (yBot - yTop > 9) + plot(frame, cx, (yTop + yBot) * 0.5, G_DOT, P.red, (24 + 84 * on) * vis, D_TOWER - 1); + } } + }); - function fork(rng) { return CC.mulberry(((rng() * 4294967296) | 0) ^ 0x5C1E); } + var D_BIRD = 9.3e4, NBIRD = 7, BIRD_CYCLE = 96, SHUTTLE_CYCLE = 214; + var bdSeed = 0, shSeed = 0; - function forkCity(city, salt) { - return CC.mulberry((((city && city.seed !== undefined ? city.seed : 0) | 0) ^ salt) >>> 0); + CC.ELEMENTS.push({ + name: 'skyrare', + + world: 'cyber', + layer: 9, + init: function (city) { + var r = forkCity(city, 0x77E115); + bdSeed = (r() * 30011) | 0; + shSeed = (r() * 30011) | 0; + }, + draw: function (frame, cam, t) { + setup(frame, cam); + + t = CC.reducedMotion ? t * 0.12 : t; + var i, k, u, az, el, ca, p; + + if (W_RAIN < 0.45) { + k = Math.floor(t / BIRD_CYCLE); + u = t / BIRD_CYCLE - k; + if (hash1(k, bdSeed + 3) < 0.42 && u > 0.10 && u < 0.30) { + var q = (u - 0.10) / 0.20; + var fb = ((k & 3) * QUARTER) + (hash1(k, bdSeed + 9) - 0.5) * 0.5; + var fel = 0.11 + hash1(k, bdSeed + 17) * 0.16; + var dirn = hash1(k, bdSeed + 23) < 0.5 ? -1 : 1; + for (i = 0; i < NBIRD; i++) { + + az = fb + dirn * (q - 0.5) * 0.62 + (hash1(i, bdSeed) - 0.5) * 0.10 - i * 0.017 * dirn; + el = fel + (hash1(i, bdSeed + 5) - 0.5) * 0.045; + ca = Math.cos(el); + p = proj(Math.sin(az) * ca, Math.sin(el), Math.cos(az) * ca); + if (!p.ok) continue; + + var wb = CC.reducedMotion ? 0.5 + : (t * 3.4 + i * 0.7) - Math.floor(t * 3.4 + i * 0.7); + plot(frame, p.x, p.y, wb < 0.45 ? G_CARET : G_DASH, P.slate, + (26 + 16 * hash1(i, bdSeed + 11)) * (1 - W_FOG * 0.8), D_BIRD); + } + } + } + + if (W_CLOUD > 0.80) return; + k = Math.floor(t / SHUTTLE_CYCLE); + u = t / SHUTTLE_CYCLE - k; + if (hash1(k, shSeed + 1) > 0.5) return; + if (u < 0.14 || u > 0.30) return; + var s = (u - 0.14) / 0.16; + var sb2 = ((k & 3) * QUARTER) + (hash1(k, shSeed + 7) - 0.5) * 0.30; + + var sel = 0.035 + s * s * 0.42; + var fade = 1 - W_CLOUD * 0.9; + for (i = 0; i < 9; i++) { + el = sel - i * i * 0.0042; + if (el < 0.02) break; + az = sb2 + i * 0.0026; + ca = Math.cos(el); + p = proj(Math.sin(az) * ca, Math.sin(el), Math.cos(az) * ca); + if (!p.ok) continue; + plot(frame, p.x, p.y, + i === 0 ? G_STAR : (i < 3 ? G_o : G_DOT), + i === 0 ? P.pure : (i < 4 ? P.ember : P.slate), + (i === 0 ? 235 : 150 / (1 + i * 0.9)) * fade, D_STAR - 2); + } } + }); - CC.ELEMENTS.push({ - name: 'cloudbase', - layer: 3, + var NBLIMP = 8, TXTN = 44, BL_SPAN = 1100; + var blB, blD, blY, blL, blH, blSpd, blPh, blHue, blSeed, blOff, blTxt; + var TXT_POOL = null; - world: ['cyber', 'west'], - draw: function (frame, cam, t) { - setup(frame, cam); + CC.ELEMENTS.push({ + name: 'blimps', - if (W_CLOUD < 0.40) return; - var thr = cloudThr(), cols = CB.cols; - var maxRow = Math.floor(CB.horizon); if (maxRow > CB.rows - 1) maxRow = CB.rows - 1; + world: 'cyber', + layer: 12, + init: function (city, rng) { + var r = fork(rng), i, j; + if (!TXT_POOL) TXT_POOL = [G_8, G_0, G_OO, G_X, G_Z, G_HASH, G_H, G_N, G_A, G_V, + G_K, G_Y, G_U, G_M, G_W, G_EQ]; + blB = new Float32Array(NBLIMP); blD = new Float32Array(NBLIMP); blY = new Float32Array(NBLIMP); + blL = new Float32Array(NBLIMP); blH = new Float32Array(NBLIMP); + blSpd = new Float32Array(NBLIMP); blPh = new Float32Array(NBLIMP); + blHue = new Uint8Array(NBLIMP); blSeed = new Int32Array(NBLIMP); + blOff = new Float32Array(NBLIMP); blTxt = new Uint8Array(NBLIMP * TXTN); + for (i = 0; i < NBLIMP; i++) { + blB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.5; + blD[i] = 320 + r() * 300; + blY[i] = blD[i] * (0.16 + r() * 0.13); + blL[i] = 46 + r() * 26; + blH[i] = blL[i] * 0.23; + blSpd[i] = (r() < 0.5 ? -1 : 1) * (3.4 + r() * 2.4); + blPh[i] = r() * BL_SPAN; - var dens = 0.15 + 0.19 * W_CLOUD; + blHue[i] = i === 2 ? P.violet : (i & 1 ? P.azure : P.amber); + blSeed[i] = (r() * 4294967296) | 0; + for (j = 0; j < TXTN; j++) { + var q = r(); - var base = 26 + 16 * W_CLOUD; - - var lowRow = CB.horizon - CB.rows * 0.17; - var dist = frame.dist, col, row, sp, dirx, dirz, dy, len, nx, ny, nz, v, i, lum, gl, hue; - for (col = 0; col < cols; col++) { - sp = ((col + 0.5) * 2 / cols - 1) * CB.half; - dirx = CB.fwx + CB.rgx * sp; dirz = CB.fwz + CB.rgz * sp; - for (row = 0; row <= maxRow; row++) { - i = row * cols + col; - if (dist[i] < D_CLOUD) continue; - dy = (CB.horizon - row) / CB.scale; - len = Math.sqrt(dirx * dirx + dirz * dirz + dy * dy); - nx = dirx / len; ny = dy / len; nz = dirz / len; - v = cloudAt(nx, ny, nz, t); - if (v <= thr) continue; - - v = (v - thr) * 4; if (v > 1) v = 1; - - if (hash2((nx * 190) | 0, (ny * 260) | 0, 0x71C3) > dens * (0.30 + 1.2 * v)) continue; - gl = v > 0.62 ? G_TILDE : (v > 0.3 ? G_DASH : G_TICK); - lum = base * (0.55 + 0.75 * v); - hue = P.shadow; - - if (row > lowRow && v > 0.55 && D_LAMP > 0.15 && CC.World && CC.World.is('cyber') && - hash2((nx * 190) | 0, (ny * 260) | 0, 0x71C4) < 0.30) { - hue = P.amber; lum = (44 + 30 * v) * D_LAMP; - } - plot(frame, col, row, gl, hue, lum, D_CLOUD); - } - } + blTxt[i * TXTN + j] = q < 0.32 ? 0 : TXT_POOL[(q * TXT_POOL.length) | 0]; } - }); + } + }, + update: function (dt, t) { + var tt = CC.reducedMotion ? t * 0.12 : t; + for (var i = 0; i < NBLIMP; i++) { + var s = (blSpd[i] * tt + blPh[i]) % BL_SPAN; + if (s < 0) s += BL_SPAN; + blOff[i] = s - BL_SPAN * 0.5; + } + }, + draw: function (frame, cam, t) { + setup(frame, cam); + var tt = CC.reducedMotion ? 0 : t; + for (var i = 0; i < NBLIMP; i++) { + var b = blB[i], sb = Math.sin(b), cb = Math.cos(b), s = blOff[i]; + var p = proj(blD[i] * sb + s * cb, blY[i] - CB.eyeY, blD[i] * cb - s * sb); + if (!p.ok) continue; + var cx = p.x, cy = p.y, d = p.d; + var rw = blL[i] * 0.5 / p.w * CB.colsPerTan; + var rh = blH[i] * 0.5 / p.w * CB.scale; + if (rw < 2.5 || cx + rw < 0 || cx - rw >= CB.cols) continue; - var NSTAR = 400; - var stX, stY, stZ, stL, stC, stG, stPh, stTw; + if (rh < 1.5) rh = 1.5; - CC.ELEMENTS.push({ - name: 'stars', - layer: 4, - - world: ['cyber', 'west'], - init: function (city, rng) { - var r = fork(rng), i; - stX = new Float32Array(NSTAR); stY = new Float32Array(NSTAR); stZ = new Float32Array(NSTAR); - stL = new Float32Array(NSTAR); stC = new Uint8Array(NSTAR); stG = new Uint8Array(NSTAR); - stPh = new Float32Array(NSTAR); stTw = new Float32Array(NSTAR); - for (i = 0; i < NSTAR; i++) { - var az = r() * TAU, u = r(); - var alt = 0.03 + u * u * 0.39; - var ca = Math.cos(alt); - stX[i] = Math.sin(az) * ca; stY[i] = Math.sin(alt); stZ[i] = Math.cos(az) * ca; - var m = r(); - - stL[i] = 30 + m * m * m * 118; - stC[i] = m > 0.94 ? P.ice : (m > 0.55 ? P.white : P.slate); - stG[i] = m > 0.97 ? G_PLUS : (m > 0.62 ? G_DOT : (r() < 0.5 ? G_QUOTE : G_TICK)); - stPh[i] = r() * 60; - stTw[i] = 1; + var sd = blSeed[i], hue = blHue[i], base = i * TXTN; + var scroll = Math.floor(tt * 3.2); + var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; + for (dy = -ih; dy <= ih; dy++) { + for (dx = -iw; dx <= iw; dx++) { + var u = dx / rw, v = dy / rh, r2 = u * u + v * v; + if (r2 > 1) continue; + if (dy === 0) { + if (u > -0.84 && u < 0.84) { + var ti = (dx + scroll) % TXTN; if (ti < 0) ti += TXTN; + var tg = blTxt[base + ti]; + if (tg) plot(frame, cx + dx, cy + dy, tg, hue, 132 + hash2(ti, i, sd) * 64, d - 1); + } else { + plot(frame, cx + dx, cy + dy, G_o, P.slate, 30 + hash2(dx, dy, sd) * 14, d); + } + continue; } - }, - update: function (dt, t) { - var still = CC.reducedMotion; - for (var i = 0; i < NSTAR; i++) - stTw[i] = still ? 0.88 : 0.52 + 0.48 * vnoise(t * 0.6 + stPh[i], 0x2A7 + i); - }, - draw: function (frame, cam, t) { - setup(frame, cam); + if (r2 > 0.42) { - var thr = cloudThr() - 0.05, FEATHER = 0.05; - var vis = 1 - W_FOG * 1.25; if (vis <= 0) return; if (vis > 1) vis = 1; - - vis *= D_STAR_V; if (vis <= 0.01) return; - for (var i = 0; i < NSTAR; i++) { - var p = proj(stX[i], stY[i], stZ[i]); - if (!p.ok) continue; - var m = (thr - cloudAt(stX[i], stY[i], stZ[i], t)) / FEATHER; - if (m <= 0) continue; - if (m > 1) m = 1; else m = m * m * (3 - 2 * m); - plot(frame, p.x, p.y, stG[i], stC[i], stL[i] * stTw[i] * vis * m, D_STAR); + if (v > 0) plot(frame, cx + dx, cy + dy, G_UNDER, P.amber, + 25 + hash2(dx, dy, sd) * 13, d); + else plot(frame, cx + dx, cy + dy, G_DASH, P.slate, + 29 + hash2(dx, dy, sd ^ 0x7) * 15, d); + continue; } + if (hash2(dx, dy, sd ^ 0x2C) < 0.30) + plot(frame, cx + dx, cy + dy, G_COLON, P.slate, 12, d); + } } - }); - var moAz0 = 0, moAlt = 0.2, moR = 0.030, moSeed = 0, moPhase = 0.42, moAz = 0; - - CC.ELEMENTS.push({ - name: 'moon', - layer: 5, - - world: ['cyber', 'west'], - init: function (city, rng) { - var r = fork(rng); - moAz0 = (r() - 0.5) * 0.26; - moAlt = 0.17 + r() * 0.08; - moR = 0.026 + r() * 0.008; - moSeed = (r() * 4294967296) | 0; - - moPhase = 0.34 + r() * 0.24; - moAz = moAz0; - }, - update: function (dt, t) { - moAz = moAz0 + (CC.reducedMotion ? 0 : t * 7.3e-5); - }, - draw: function (frame, cam) { - setup(frame, cam); - var ca = Math.cos(moAlt); - var p = proj(Math.sin(moAz) * ca, Math.sin(moAlt), Math.cos(moAz) * ca); - if (!p.ok) return; - var cx = p.x, cy = p.y; - var rw = moR * CB.colsPerTan / p.w, rh = moR * CB.scale / p.w; - if (rw < 1 || cx + rw < 0 || cx - rw >= CB.cols) return; - - var disc = 1.18 - 1.28 * W_CLOUD; if (disc <= 0.02) return; if (disc > 1) disc = 1; - - disc *= 0.10 + 0.90 * D_STAR_V; if (disc <= 0.02) return; - - var halo = (W_HAZE * 0.75 + W_CLOUD * 0.45) * Math.sqrt(disc); if (halo > 1) halo = 1; - if (halo > 0.10) { - - var hr = 2.1, hiw = Math.ceil(rw * hr), hih = Math.ceil(rh * hr), hx, hy, hu, hv, h2; - for (hy = -hih; hy <= hih; hy++) { - for (hx = -hiw; hx <= hiw; hx++) { - hu = hx / rw; hv = hy / rh; h2 = hu * hu + hv * hv; - if (h2 < 1.05 || h2 > hr * hr) continue; - if (hash2(hx, hy, moSeed ^ 0x5D) > 0.34) continue; - - plot(frame, cx + hx, cy + hy, h2 > 2.6 ? G_DOT : G_COMMA, P.ice, - 70 * halo * (1 - (h2 - 1.05) / (hr * hr - 1.05)), D_MOON + 1); - } - } - } - - var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; - for (dy = -ih; dy <= ih; dy++) { - for (dx = -iw; dx <= iw; dx++) { - var u = dx / rw, v = dy / rh, r2 = u * u + v * v; - if (r2 > 1.02) continue; - var su = u + moPhase; - if (su * su + v * v < 1.0) { - - if (r2 > 0.72 && hash2(dx, dy, moSeed ^ 0x3B) < 0.55) - plot(frame, cx + dx, cy + dy, G_DOT, P.slate, 13 * disc, D_MOON); - continue; - } - var lum = (124 + 76 * (1 - r2 * 0.6)) * disc; - - if (hash2(Math.floor(u * 2.6), Math.floor(v * 2.6), moSeed) < 0.24) lum *= 0.44; - var gl = r2 > 0.80 ? G_o : (hash2(dx, dy, moSeed ^ 0x91) < 0.5 ? G_8 : G_OO); - plot(frame, cx + dx, cy + dy, gl, P.white, lum, D_MOON); - } - } + var ph = tt * 0.75 + i * 0.37; ph -= Math.floor(ph); + if (CC.reducedMotion || ph < 0.13) { + var al = CC.reducedMotion ? 80 : 204; + plot(frame, cx - rw * 0.94, cy, G_DOT, P.red, al, d - 2); + plot(frame, cx + rw * 0.94, cy, G_DOT, P.red, al, d - 2); } - }); - var NAIR = 6, AIR_SPAN = 3200; - var acB, acD, acY, acS, acPh, acOff; + plot(frame, cx, cy + Math.floor(rh) + 1, G_DOT, P.warm, 70, d); + } + } + }); - CC.ELEMENTS.push({ - name: 'aircraft', + var NDRONE = 26; + var drB, drD, drY, drSpd, drPh, drSpan, drStrobe, drOff; - world: 'cyber', - layer: 6, - init: function (city, rng) { - var r = fork(rng), i; - acB = new Float32Array(NAIR); acD = new Float32Array(NAIR); acY = new Float32Array(NAIR); - acS = new Float32Array(NAIR); acPh = new Float32Array(NAIR); acOff = new Float32Array(NAIR); - for (i = 0; i < NAIR; i++) { - acB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.6; - acD[i] = 1400 + r() * 1400; - acY[i] = acD[i] * (0.10 + r() * 0.15); - acS[i] = (r() < 0.5 ? -1 : 1) * (58 + r() * 40); - acPh[i] = r() * AIR_SPAN; - acOff[i] = 0; - } - }, - update: function (dt, t) { - var tt = CC.reducedMotion ? t * 0.08 : t; - for (var i = 0; i < NAIR; i++) { - var s = (acS[i] * tt + acPh[i]) % AIR_SPAN; - if (s < 0) s += AIR_SPAN; - acOff[i] = s - AIR_SPAN * 0.5; - } - }, - draw: function (frame, cam, t) { - setup(frame, cam); - var tt = CC.reducedMotion ? 0 : t; + CC.ELEMENTS.push({ + name: 'drones', - var seen = 1.25 - 1.30 * W_CLOUD; if (seen <= 0.03) return; if (seen > 1) seen = 1; + world: 'cyber', + layer: 13, + init: function (city, rng) { + var r = fork(rng), i; + drB = new Float32Array(NDRONE); drD = new Float32Array(NDRONE); drY = new Float32Array(NDRONE); + drSpd = new Float32Array(NDRONE); drPh = new Float32Array(NDRONE); drSpan = new Float32Array(NDRONE); + drStrobe = new Uint8Array(NDRONE); drOff = new Float32Array(NDRONE); + for (i = 0; i < NDRONE; i++) { + drB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.7; + drD[i] = 70 + r() * 80; - var glow = W_FOG > 0.34 ? (W_FOG - 0.34) * 1.5 : 0; if (glow > 1) glow = 1; - for (var i = 0; i < NAIR; i++) { - var b = acB[i], sb = Math.sin(b), cb = Math.cos(b), s = acOff[i]; - var p = proj(acD[i] * sb + s * cb, acY[i] - CB.eyeY, acD[i] * cb - s * sb); - if (!p.ok) continue; - var px = p.x, py = p.y, pd = p.d; - plot(frame, px, py, G_DOT, P.slate, 17 * seen, pd); - var ph = tt * 0.55 + i * 0.4; ph -= Math.floor(ph); - var on = CC.reducedMotion ? 0.33 : (ph < 0.06 ? 1 : 0); - if (!on) continue; - plot(frame, px, py, G_DOT, P.red, 176 * on * seen, pd - 1); - if (glow > 0.02) { + drY[i] = drD[i] * (0.24 + r() * 0.18); + drSpd[i] = (r() < 0.5 ? -1 : 1) * (6 + r() * 6); - var gl = 74 * glow * on * seen; - plot(frame, px - 1, py, G_DOT, P.red, gl, pd - 0.5); - plot(frame, px + 1, py, G_DOT, P.red, gl, pd - 0.5); - plot(frame, px, py - 1, G_DOT, P.red, gl * 0.7, pd - 0.5); - plot(frame, px, py + 1, G_DOT, P.red, gl * 0.7, pd - 0.5); - } - } + drSpan[i] = drD[i] * 2.2; + drPh[i] = r() * drSpan[i]; + drStrobe[i] = r() < 0.4 ? 1 : 0; + } + }, + update: function (dt, t) { + var tt = CC.reducedMotion ? t * 0.1 : t; + for (var i = 0; i < NDRONE; i++) { + var sp = drSpan[i], s = (drSpd[i] * tt + drPh[i]) % sp; + if (s < 0) s += sp; + drOff[i] = s - sp * 0.5; + } + }, + draw: function (frame, cam, t) { + setup(frame, cam); + var tt = CC.reducedMotion ? 0 : t; + for (var i = 0; i < NDRONE; i++) { + var b = drB[i], sb = Math.sin(b), cb = Math.cos(b), s = drOff[i]; + var p = proj(drD[i] * sb + s * cb, drY[i] - CB.eyeY, drD[i] * cb - s * sb); + if (!p.ok) continue; + var x = p.x, y = p.y, d = p.d; + if (x < -2 || x >= CB.cols + 2) continue; + + plot(frame, x, y, G_DASH, P.slate, 30, d); + if (CC.reducedMotion) { + plot(frame, x - 1, y, G_DOT, P.red, 74, d); + plot(frame, x + 1, y, G_DOT, P.spring, 66, d); + continue; } - }); - var NBEAM = 8, BEAM_LEN = 460; - var bmB, bmR, bmYb, bmAz0, bmAmp, bmW, bmPh, bmEl0, bmSeed, bmAz, bmEl; - - var BEAM_DENS = 0.46, BEAM_GAIN = 1; - - CC.ELEMENTS.push({ - name: 'searchlights', - - world: 'cyber', - layer: 8, - init: function (city, rng) { - var r = fork(rng), i; - bmB = new Float32Array(NBEAM); bmR = new Float32Array(NBEAM); bmYb = new Float32Array(NBEAM); - bmAz0 = new Float32Array(NBEAM); bmAmp = new Float32Array(NBEAM); - bmW = new Float32Array(NBEAM); bmPh = new Float32Array(NBEAM); bmEl0 = new Float32Array(NBEAM); - bmSeed = new Int32Array(NBEAM); bmAz = new Float32Array(NBEAM); bmEl = new Float32Array(NBEAM); - for (i = 0; i < NBEAM; i++) { - - bmB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.40; - bmR[i] = (i < 4 ? 230 : 420) + r() * 200; - bmYb[i] = bmR[i] * (0.13 + r() * 0.13); - bmAz0[i] = bmB[i] + (r() - 0.5) * 0.4; - bmAmp[i] = 0.30 + r() * 0.26; - bmW[i] = 0.20 + r() * 0.14; - bmPh[i] = r() * TAU; - bmEl0[i] = 0.60 + r() * 0.24; - bmSeed[i] = (r() * 4294967296) | 0; - bmAz[i] = bmAz0[i]; bmEl[i] = bmEl0[i]; - } - }, - update: function (dt, t) { - var tt = CC.reducedMotion ? 0 : t; - for (var i = 0; i < NBEAM; i++) { - bmAz[i] = bmAz0[i] + Math.sin(tt * bmW[i] + bmPh[i]) * bmAmp[i]; - - bmEl[i] = bmEl0[i] + Math.sin(tt * bmW[i] * 0.37 + bmPh[i] * 1.7) * 0.20; - } - }, - draw: function (frame, cam) { - setup(frame, cam); - - var k = W_FOGREL; if (k > 2.6) k = 2.6; - BEAM_DENS = 0.16 + 0.30 * k; if (BEAM_DENS > 0.80) BEAM_DENS = 0.80; - BEAM_GAIN = 0.40 + 0.60 * k; if (BEAM_GAIN > 1.9) BEAM_GAIN = 1.9; - for (var i = 0; i < NBEAM; i++) { - var sb = Math.sin(bmB[i]), cb = Math.cos(bmB[i]); - var ox = bmR[i] * sb, oz = bmR[i] * cb, oy = bmYb[i] - CB.eyeY; - var p = proj(ox, oy, oz); - if (!p.ok) continue; - var bx = p.x, by = p.y, bd = p.d; - - var el = bmEl[i], az = bmAz[i], ce = Math.cos(el); - var dx = Math.sin(az) * ce, dy = Math.sin(el), dz = Math.cos(az) * ce; - - var len = BEAM_LEN, k, ok = 0, tx = 0, ty = 0, td = 0; - for (k = 0; k < 5; k++) { - p = proj(ox + dx * len, oy + dy * len, oz + dz * len); - if (p.ok) { ok = 1; tx = p.x; ty = p.y; td = p.d; break; } - len *= 0.5; - } - if (!ok) continue; - - var sx = tx - bx, sy = ty - by; - var asx = sx < 0 ? -sx : sx, asy = sy < 0 ? -sy : sy; - var n = Math.round(asx > asy ? asx : asy); - if (n < 3) continue; - if (n > 140) n = 140; - - var gl = asy > asx * 1.4 ? G_PIPE : (sx * sy > 0 ? G_BSLASH : G_SLASH); - for (k = 0; k <= n; k++) { - - if (hash2(k, i, bmSeed[i]) > BEAM_DENS) continue; - var f = k / n, ff = 1 - f; - - plot(frame, bx + sx * f, by + sy * f, k < 3 ? G_COLON : gl, - f < 0.34 ? P.white : P.slate, 62 * BEAM_GAIN * ff * ff * Math.sqrt(ff), - bd + (td - bd) * f); - } - plot(frame, bx, by, G_OO, P.white, 96, bd); - } - } - }); - - var D_TOWER = 9.2e4, NTOWER = 7; - var twB, twR, twH, twPer, twPh, twSeed; - - CC.ELEMENTS.push({ - name: 'beacons', - - world: 'cyber', - layer: 7, - init: function (city) { - var r = forkCity(city, 0x2B9A31), i; - twB = new Float32Array(NTOWER); twR = new Float32Array(NTOWER); twH = new Float32Array(NTOWER); - twPer = new Float32Array(NTOWER); twPh = new Float32Array(NTOWER); - twSeed = new Int32Array(NTOWER); - for (i = 0; i < NTOWER; i++) { - - twB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.34; - twR[i] = 520 + r() * 1500; - twH[i] = twR[i] * (0.10 + r() * 0.13); - - twPer[i] = 1.35 + r() * 1.9; - twPh[i] = r() * 10; - twSeed[i] = (r() * 30011) | 0; - } - }, - draw: function (frame, cam, t) { - setup(frame, cam); - - var vis = 1 - W_FOG * 1.5 - W_HAZE * 0.35; if (vis <= 0.02) return; if (vis > 1) vis = 1; - var tt = CC.reducedMotion ? 0 : t; - for (var i = 0; i < NTOWER; i++) { - var sb = Math.sin(twB[i]), cb = Math.cos(twB[i]); - var ox = twR[i] * sb, oz = twR[i] * cb; - var p = proj(ox, twH[i] - CB.eyeY, oz); - if (!p.ok) continue; - var cx = Math.round(p.x), yTop = p.y, d = p.d; - if (cx < 0 || cx >= CB.cols) continue; - p = proj(ox, twH[i] * 0.42 - CB.eyeY, oz); - if (!p.ok) continue; - var yBot = p.y, row; - if (yBot - yTop < 2) continue; - if (yBot - yTop > 46) yBot = yTop + 46; - - for (row = Math.round(yTop) + 1; row <= yBot; row++) - if (!((row - Math.round(yTop)) & 1)) - plot(frame, cx, row, G_PIPE, P.slate, 15 * vis, D_TOWER); - var ph = tt / twPer[i] + twPh[i]; ph -= Math.floor(ph); - var on = CC.reducedMotion ? 0.5 : (ph < 0.16 ? 1 : 0.10); - plot(frame, cx, yTop, on > 0.5 ? G_STAR : G_DOT, P.red, (40 + 150 * on) * vis, D_TOWER - 1); - - if (yBot - yTop > 9) - plot(frame, cx, (yTop + yBot) * 0.5, G_DOT, P.red, (24 + 84 * on) * vis, D_TOWER - 1); - } - } - }); - - var D_BIRD = 9.3e4, NBIRD = 7, BIRD_CYCLE = 96, SHUTTLE_CYCLE = 214; - var bdSeed = 0, shSeed = 0; - - CC.ELEMENTS.push({ - name: 'skyrare', - - world: 'cyber', - layer: 9, - init: function (city) { - var r = forkCity(city, 0x77E115); - bdSeed = (r() * 30011) | 0; - shSeed = (r() * 30011) | 0; - }, - draw: function (frame, cam, t) { - setup(frame, cam); - - t = CC.reducedMotion ? t * 0.12 : t; - var i, k, u, az, el, ca, p; - - if (W_RAIN < 0.45) { - k = Math.floor(t / BIRD_CYCLE); - u = t / BIRD_CYCLE - k; - if (hash1(k, bdSeed + 3) < 0.42 && u > 0.10 && u < 0.30) { - var q = (u - 0.10) / 0.20; - var fb = ((k & 3) * QUARTER) + (hash1(k, bdSeed + 9) - 0.5) * 0.5; - var fel = 0.11 + hash1(k, bdSeed + 17) * 0.16; - var dirn = hash1(k, bdSeed + 23) < 0.5 ? -1 : 1; - for (i = 0; i < NBIRD; i++) { - - az = fb + dirn * (q - 0.5) * 0.62 + (hash1(i, bdSeed) - 0.5) * 0.10 - i * 0.017 * dirn; - el = fel + (hash1(i, bdSeed + 5) - 0.5) * 0.045; - ca = Math.cos(el); - p = proj(Math.sin(az) * ca, Math.sin(el), Math.cos(az) * ca); - if (!p.ok) continue; - - var wb = CC.reducedMotion ? 0.5 - : (t * 3.4 + i * 0.7) - Math.floor(t * 3.4 + i * 0.7); - plot(frame, p.x, p.y, wb < 0.45 ? G_CARET : G_DASH, P.slate, - (26 + 16 * hash1(i, bdSeed + 11)) * (1 - W_FOG * 0.8), D_BIRD); - } - } - } - - if (W_CLOUD > 0.80) return; - k = Math.floor(t / SHUTTLE_CYCLE); - u = t / SHUTTLE_CYCLE - k; - if (hash1(k, shSeed + 1) > 0.5) return; - if (u < 0.14 || u > 0.30) return; - var s = (u - 0.14) / 0.16; - var sb2 = ((k & 3) * QUARTER) + (hash1(k, shSeed + 7) - 0.5) * 0.30; - - var sel = 0.035 + s * s * 0.42; - var fade = 1 - W_CLOUD * 0.9; - for (i = 0; i < 9; i++) { - el = sel - i * i * 0.0042; - if (el < 0.02) break; - az = sb2 + i * 0.0026; - ca = Math.cos(el); - p = proj(Math.sin(az) * ca, Math.sin(el), Math.cos(az) * ca); - if (!p.ok) continue; - plot(frame, p.x, p.y, - i === 0 ? G_STAR : (i < 3 ? G_o : G_DOT), - i === 0 ? P.pure : (i < 4 ? P.ember : P.slate), - (i === 0 ? 235 : 150 / (1 + i * 0.9)) * fade, D_STAR - 2); - } - } - }); - - var NBLIMP = 8, TXTN = 44, BL_SPAN = 1100; - var blB, blD, blY, blL, blH, blSpd, blPh, blHue, blSeed, blOff, blTxt; - var TXT_POOL = null; - - CC.ELEMENTS.push({ - name: 'blimps', - - world: 'cyber', - layer: 12, - init: function (city, rng) { - var r = fork(rng), i, j; - if (!TXT_POOL) TXT_POOL = [G_8, G_0, G_OO, G_X, G_Z, G_HASH, G_H, G_N, G_A, G_V, - G_K, G_Y, G_U, G_M, G_W, G_EQ]; - blB = new Float32Array(NBLIMP); blD = new Float32Array(NBLIMP); blY = new Float32Array(NBLIMP); - blL = new Float32Array(NBLIMP); blH = new Float32Array(NBLIMP); - blSpd = new Float32Array(NBLIMP); blPh = new Float32Array(NBLIMP); - blHue = new Uint8Array(NBLIMP); blSeed = new Int32Array(NBLIMP); - blOff = new Float32Array(NBLIMP); blTxt = new Uint8Array(NBLIMP * TXTN); - for (i = 0; i < NBLIMP; i++) { - blB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.5; - blD[i] = 320 + r() * 300; - blY[i] = blD[i] * (0.16 + r() * 0.13); - blL[i] = 46 + r() * 26; - blH[i] = blL[i] * 0.23; - blSpd[i] = (r() < 0.5 ? -1 : 1) * (3.4 + r() * 2.4); - blPh[i] = r() * BL_SPAN; - - blHue[i] = i === 2 ? P.violet : (i & 1 ? P.azure : P.amber); - blSeed[i] = (r() * 4294967296) | 0; - for (j = 0; j < TXTN; j++) { - var q = r(); - - blTxt[i * TXTN + j] = q < 0.32 ? 0 : TXT_POOL[(q * TXT_POOL.length) | 0]; - } - } - }, - update: function (dt, t) { - var tt = CC.reducedMotion ? t * 0.12 : t; - for (var i = 0; i < NBLIMP; i++) { - var s = (blSpd[i] * tt + blPh[i]) % BL_SPAN; - if (s < 0) s += BL_SPAN; - blOff[i] = s - BL_SPAN * 0.5; - } - }, - draw: function (frame, cam, t) { - setup(frame, cam); - var tt = CC.reducedMotion ? 0 : t; - for (var i = 0; i < NBLIMP; i++) { - var b = blB[i], sb = Math.sin(b), cb = Math.cos(b), s = blOff[i]; - var p = proj(blD[i] * sb + s * cb, blY[i] - CB.eyeY, blD[i] * cb - s * sb); - if (!p.ok) continue; - var cx = p.x, cy = p.y, d = p.d; - var rw = blL[i] * 0.5 / p.w * CB.colsPerTan; - var rh = blH[i] * 0.5 / p.w * CB.scale; - if (rw < 2.5 || cx + rw < 0 || cx - rw >= CB.cols) continue; - - if (rh < 1.5) rh = 1.5; - - var sd = blSeed[i], hue = blHue[i], base = i * TXTN; - var scroll = Math.floor(tt * 3.2); - var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; - for (dy = -ih; dy <= ih; dy++) { - for (dx = -iw; dx <= iw; dx++) { - var u = dx / rw, v = dy / rh, r2 = u * u + v * v; - if (r2 > 1) continue; - if (dy === 0) { - if (u > -0.84 && u < 0.84) { - var ti = (dx + scroll) % TXTN; if (ti < 0) ti += TXTN; - var tg = blTxt[base + ti]; - if (tg) plot(frame, cx + dx, cy + dy, tg, hue, 132 + hash2(ti, i, sd) * 64, d - 1); - } else { - plot(frame, cx + dx, cy + dy, G_o, P.slate, 30 + hash2(dx, dy, sd) * 14, d); - } - continue; - } - if (r2 > 0.42) { - - if (v > 0) plot(frame, cx + dx, cy + dy, G_UNDER, P.amber, - 25 + hash2(dx, dy, sd) * 13, d); - else plot(frame, cx + dx, cy + dy, G_DASH, P.slate, - 29 + hash2(dx, dy, sd ^ 0x7) * 15, d); - continue; - } - if (hash2(dx, dy, sd ^ 0x2C) < 0.30) - plot(frame, cx + dx, cy + dy, G_COLON, P.slate, 12, d); - } - } - - var ph = tt * 0.75 + i * 0.37; ph -= Math.floor(ph); - if (CC.reducedMotion || ph < 0.13) { - var al = CC.reducedMotion ? 80 : 204; - plot(frame, cx - rw * 0.94, cy, G_DOT, P.red, al, d - 2); - plot(frame, cx + rw * 0.94, cy, G_DOT, P.red, al, d - 2); - } - - plot(frame, cx, cy + Math.floor(rh) + 1, G_DOT, P.warm, 70, d); - } - } - }); - - var NDRONE = 26; - var drB, drD, drY, drSpd, drPh, drSpan, drStrobe, drOff; - - CC.ELEMENTS.push({ - name: 'drones', - - world: 'cyber', - layer: 13, - init: function (city, rng) { - var r = fork(rng), i; - drB = new Float32Array(NDRONE); drD = new Float32Array(NDRONE); drY = new Float32Array(NDRONE); - drSpd = new Float32Array(NDRONE); drPh = new Float32Array(NDRONE); drSpan = new Float32Array(NDRONE); - drStrobe = new Uint8Array(NDRONE); drOff = new Float32Array(NDRONE); - for (i = 0; i < NDRONE; i++) { - drB[i] = (i & 3) * QUARTER + (r() - 0.5) * 0.7; - drD[i] = 70 + r() * 80; - - drY[i] = drD[i] * (0.24 + r() * 0.18); - drSpd[i] = (r() < 0.5 ? -1 : 1) * (6 + r() * 6); - - drSpan[i] = drD[i] * 2.2; - drPh[i] = r() * drSpan[i]; - drStrobe[i] = r() < 0.4 ? 1 : 0; - } - }, - update: function (dt, t) { - var tt = CC.reducedMotion ? t * 0.1 : t; - for (var i = 0; i < NDRONE; i++) { - var sp = drSpan[i], s = (drSpd[i] * tt + drPh[i]) % sp; - if (s < 0) s += sp; - drOff[i] = s - sp * 0.5; - } - }, - draw: function (frame, cam, t) { - setup(frame, cam); - var tt = CC.reducedMotion ? 0 : t; - for (var i = 0; i < NDRONE; i++) { - var b = drB[i], sb = Math.sin(b), cb = Math.cos(b), s = drOff[i]; - var p = proj(drD[i] * sb + s * cb, drY[i] - CB.eyeY, drD[i] * cb - s * sb); - if (!p.ok) continue; - var x = p.x, y = p.y, d = p.d; - if (x < -2 || x >= CB.cols + 2) continue; - - plot(frame, x, y, G_DASH, P.slate, 30, d); - if (CC.reducedMotion) { - plot(frame, x - 1, y, G_DOT, P.red, 74, d); - plot(frame, x + 1, y, G_DOT, P.spring, 66, d); - continue; - } - - var ph = tt * 1.5 + i * 0.41; ph -= Math.floor(ph); - if (ph < 0.12) plot(frame, x - 1, y, G_DOT, P.red, 194, d - 0.5); - if (ph > 0.50 && ph < 0.62) plot(frame, x + 1, y, G_DOT, P.spring, 174, d - 0.5); - if (drStrobe[i] && ph > 0.83 && ph < 0.855) - plot(frame, x, y, G_PLUS, P.pure, 242, d - 1); - } - } - }); + var ph = tt * 1.5 + i * 0.41; ph -= Math.floor(ph); + if (ph < 0.12) plot(frame, x - 1, y, G_DOT, P.red, 194, d - 0.5); + if (ph > 0.50 && ph < 0.62) plot(frame, x + 1, y, G_DOT, P.spring, 174, d - 0.5); + if (drStrobe[i] && ph > 0.83 && ph < 0.855) + plot(frame, x, y, G_PLUS, P.pure, 242, d - 1); + } + } + }); })(CC); /* src/elements/skylanes.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2; + var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2; - var G_DASH = g('-'), G_EQ = g('='), G_HASH = g('#'), G_o = g('o'), G_UNDER = g('_'); + var G_DASH = g('-'), G_EQ = g('='), G_HASH = g('#'), G_o = g('o'), G_UNDER = g('_'); - var NLEV = 3; - var ALT = [29.0, 38.0, 49.0]; - var DIRS = [1, -1, 1]; + var NLEV = 3; + var ALT = [29.0, 38.0, 49.0]; + var DIRS = [1, -1, 1]; - var LANE_P = 0.74; + var LANE_P = 0.74; - var NPER = 7, SPAN = 480.0, SLOT = SPAN / NPER; + var NPER = 7, SPAN = 480.0, SLOT = SPAN / NPER; - var FREIGHT_P = 0.15; + var FREIGHT_P = 0.15; - var CAR_L = 4.8, CAR_W = 3.2, CAR_H = 1.5; - var FR_L = 17.0, FR_W = 5.4, FR_H = 3.4; + var CAR_L = 4.8, CAR_W = 3.2, CAR_H = 1.5; + var FR_L = 17.0, FR_W = 5.4, FR_H = 3.4; - var W_MIN = 78.0, W_MAX = 380.0; + var W_MIN = 78.0, W_MAX = 380.0; - var MAXCELLS = 14; + var MAXCELLS = 14; - var NMIN = 1; + var NMIN = 1; - var KSPAN = 12, MSPAN = 14; + var KSPAN = 12, MSPAN = 14; - var LANE_SIDE = 22.0; + var LANE_SIDE = 22.0; - var SKY_NEAR = 126.0, DSLOPE = 0.38; + var SKY_NEAR = 126.0, DSLOPE = 0.38; - var HEAD_AMBER = 152, HEAD_AZURE = 92, TAIL_RED = 118, UNDER_AMBER = 132, BEACON_RED = 138; - var MIN_SCALE = 0.66; + var HEAD_AMBER = 152, HEAD_AZURE = 92, TAIL_RED = 118, UNDER_AMBER = 132, BEACON_RED = 138; - var FADE = 0.00117; + var HEAD_JADE = 236; + var MIN_SCALE = 0.66; - var HULL_CAR = 15, HULL_FR = 15, HULL_ROOF = 12; + var FADE = 0.00117; - var BEACON_HZ = 0.42, BEACON_DUTY = 0.24, RM_BEACON = 0.70, BEACON_MIN = 0.45; + var HULL_CAR = 15, HULL_FR = 15, HULL_ROOF = 12; - var SALT_JIT = 2003, SALT_SPD = 2111, SALT_FRT = 2221, SALT_LAT = 2333, - SALT_ALT = 2441, SALT_HUE = 2551, SALT_LEN = 2663, SALT_BCN = 2777, SALT_LANE = 2887; + var BEACON_HZ = 0.42, BEACON_DUTY = 0.24, RM_BEACON = 0.70, BEACON_MIN = 0.45; - var CX = 0, CZ = 0, FWX = 0, FWZ = 1, RGX = 1, RGZ = 0, HP = 0.7, EYE = 1.7; - var COLS = 0, ROWS = 0, HOR = 0, SCALE = 1, CPM = 1; + var SALT_JIT = 2003, SALT_SPD = 2111, SALT_FRT = 2221, SALT_LAT = 2333, + SALT_ALT = 2441, SALT_HUE = 2551, SALT_LEN = 2663, SALT_BCN = 2777, SALT_LANE = 2887; - function camScreen(frame, cam) { - var yaw = cam.yaw || 0; - FWX = Math.sin(yaw); FWZ = Math.cos(yaw); - RGX = Math.cos(yaw); RGZ = -Math.sin(yaw); - CX = cam.x; CZ = cam.z; - HP = Math.tan((cam.fov || 1.25) * 0.5); - EYE = cam.eyeY !== undefined ? cam.eyeY : 1.7; - COLS = frame.cols; ROWS = frame.rows; - HOR = cam.horizon !== undefined ? cam.horizon : ROWS * 0.56; - SCALE = cam.scaleY !== undefined ? cam.scaleY - : (COLS * (cam.cellAspect || 0.5625)) / (2 * HP); - CPM = COLS * 0.5 / HP; - } + var CX = 0, CZ = 0, FWX = 0, FWZ = 1, RGX = 1, RGZ = 0, HP = 0.7, EYE = 1.7; + var COLS = 0, ROWS = 0, HOR = 0, SCALE = 1, CPM = 1; - var PJ = { ok: 0, w: 0, sp: 0, x: 0, dist: 0 }; - function project(px, pz) { - var dx = px - CX, dz = pz - CZ; - var w = dx * FWX + dz * FWZ; - if (w < 0.45) { PJ.ok = 0; return PJ; } - var sp = (dx * RGX + dz * RGZ) / w; - PJ.ok = 1; PJ.w = w; PJ.sp = sp; - PJ.x = (sp / HP + 1) * COLS * 0.5 - 0.5; - PJ.dist = w * Math.sqrt(1 + sp * sp); - return PJ; - } - function rowOf(y, w) { return HOR - (y - EYE) * SCALE / w; } + function camScreen(frame, cam) { + var yaw = cam.yaw || 0; + FWX = Math.sin(yaw); FWZ = Math.cos(yaw); + RGX = Math.cos(yaw); RGZ = -Math.sin(yaw); + CX = cam.x; CZ = cam.z; + HP = Math.tan((cam.fov || 1.25) * 0.5); + EYE = cam.eyeY !== undefined ? cam.eyeY : 1.7; + COLS = frame.cols; ROWS = frame.rows; + HOR = cam.horizon !== undefined ? cam.horizon : ROWS * 0.56; + SCALE = cam.scaleY !== undefined ? cam.scaleY + : (COLS * (cam.cellAspect || 0.5625)) / (2 * HP); + CPM = COLS * 0.5 / HP; + } - function plot(f, x, y, ch, col, lum, dist) { - if (lum < 3) return; - x = Math.round(x); y = Math.round(y); - if (x < 0 || y < 0 || x >= COLS || y >= ROWS) return; - if (y > HOR) return; - put(f, x, y, ch, col, lum, dist); - } + var PJ = { ok: 0, w: 0, sp: 0, x: 0, dist: 0 }; + function project(px, pz) { + var dx = px - CX, dz = pz - CZ; + var w = dx * FWX + dz * FWZ; + if (w < 0.45) { PJ.ok = 0; return PJ; } + var sp = (dx * RGX + dz * RGZ) / w; + PJ.ok = 1; PJ.w = w; PJ.sp = sp; + PJ.x = (sp / HP + 1) * COLS * 0.5 - 0.5; + PJ.dist = w * Math.sqrt(1 + sp * sp); + return PJ; + } + function rowOf(y, w) { return HOR - (y - EYE) * SCALE / w; } - var W_FOG = 0.30, W_HAZE = 0.40; - function bindWeather() { - var p = CC.Weather ? CC.Weather.P : null; - W_FOG = p ? p.fog : 0.30; - W_HAZE = p ? p.haze : 0.40; - } + function plot(f, x, y, ch, col, lum, dist) { + if (lum < 3) return; + x = Math.round(x); y = Math.round(y); + if (x < 0 || y < 0 || x >= COLS || y >= ROWS) return; + if (y > HOR) return; + put(f, x, y, ch, col, lum, dist); + } - var CITY = null, S = 0, AVE = 30, CROSS = 26; - var FRAME = null, TT = 0, VIS = 1; + var W_FOG = 0.30, W_HAZE = 0.40; + function bindWeather() { + var p = CC.Weather ? CC.Weather.P : null; + W_FOG = p ? p.fog : 0.30; + W_HAZE = p ? p.haze : 0.40; + } - function lane(ax, idx, c, hw) { + var CITY = null, S = 0, AVE = 30, CROSS = 26; + var FRAME = null, TT = 0, VIS = 1; - var p = ax === 0 ? c - CX : c - CZ; - var fp = ax === 0 ? FWX : FWZ; - var ap = p < 0 ? -p : p; - var wp = p * fp; - if (ap > LANE_SIDE && (wp < W_MIN * 0.5 || wp > W_MAX)) return; + function lane(ax, idx, c, hw) { - var lanew = hw * 1.1; if (lanew > 4.0) lanew = 4.0; if (lanew < 1.2) lanew = 1.2; + var p = ax === 0 ? c - CX : c - CZ; + var fp = ax === 0 ? FWX : FWZ; + var ap = p < 0 ? -p : p; + var wp = p * fp; + if (ap > LANE_SIDE && (wp < W_MIN * 0.5 || wp > W_MAX)) return; - var camAlong = ax === 0 ? CZ : CX; - var lv, j, ky; - for (lv = 0; lv < NLEV; lv++) { - if (hash2(idx, lv * 97 + ax * 13, S + SALT_LANE) > LANE_P) continue; - var dir = DIRS[lv]; - var alt0 = ALT[lv]; - for (j = 0; j < NPER; j++) { + var lanew = hw * 1.1; if (lanew > 4.0) lanew = 4.0; if (lanew < 1.2) lanew = 1.2; - ky = j + lv * 32 + ax * 256; + var camAlong = ax === 0 ? CZ : CX; + var lv, j, ky; + for (lv = 0; lv < NLEV; lv++) { + if (hash2(idx, lv * 97 + ax * 13, S + SALT_LANE) > LANE_P) continue; + var dir = DIRS[lv]; + var alt0 = ALT[lv]; + for (j = 0; j < NPER; j++) { - var jit = hash2(idx, ky, S + SALT_JIT); - var sp0 = hash2(idx, ky, S + SALT_SPD); - var freight = hash2(idx, ky, S + SALT_FRT) < FREIGHT_P; + ky = j + lv * 32 + ax * 256; - var base = (j + jit * 0.62) * SLOT; + var jit = hash2(idx, ky, S + SALT_JIT); + var sp0 = hash2(idx, ky, S + SALT_SPD); + var freight = hash2(idx, ky, S + SALT_FRT) < FREIGHT_P; - var spd = freight ? (0.96 + sp0 * 0.66) : (2.55 + sp0 * 2.25); + var base = (j + jit * 0.62) * SLOT; - var a = base + dir * spd * TT - camAlong; - a -= SPAN * Math.floor(a / SPAN + 0.5); - a += camAlong; + var spd = freight ? (0.96 + sp0 * 0.66) : (2.55 + sp0 * 2.25); - var lat = (hash2(idx, ky, S + SALT_LAT) - 0.5) * lanew; - var px, pz, dirx, dirz; - if (ax === 0) { px = c + lat; pz = a; dirx = 0; dirz = dir; } - else { px = a; pz = c + lat; dirx = dir; dirz = 0; } + var a = base + dir * spd * TT - camAlong; + a -= SPAN * Math.floor(a / SPAN + 0.5); + a += camAlong; - project(px, pz); - if (!PJ.ok) continue; - var w = PJ.w; - if (w < W_MIN || w > W_MAX) continue; - var sp = PJ.sp; - if (sp > HP * 1.15 || sp < -HP * 1.15) continue; - var sx = PJ.x, dTrue = PJ.dist; + var lat = (hash2(idx, ky, S + SALT_LAT) - 0.5) * lanew; + var px, pz, dirx, dirz; + if (ax === 0) { px = c + lat; pz = a; dirx = 0; dirz = dir; } + else { px = a; pz = c + lat; dirx = dir; dirz = 0; } - var ay = alt0 + (hash2(idx, ky, S + SALT_ALT) - 0.5) * 2.2; - var row = rowOf(ay, w); - if (row < -1 || row > HOR) continue; + project(px, pz); + if (!PJ.ok) continue; + var w = PJ.w; + if (w < W_MIN || w > W_MAX) continue; + var sp = PJ.sp; + if (sp > HP * 1.15 || sp < -HP * 1.15) continue; + var sx = PJ.x, dTrue = PJ.dist; - var L = CAR_L, WD = CAR_W, HT = CAR_H; - if (freight) { + var ay = alt0 + (hash2(idx, ky, S + SALT_ALT) - 0.5) * 2.2; + var row = rowOf(ay, w); + if (row < -1 || row > HOR) continue; - L = FR_L * (0.82 + hash2(idx, ky, S + SALT_LEN) * 0.42); WD = FR_W; HT = FR_H; - } - var dR = dirx * RGX + dirz * RGZ; if (dR < 0) dR = -dR; - var pR = -dirz * RGX + dirx * RGZ; if (pR < 0) pR = -pR; - var hx = 0.5 * (L * dR + WD * pR) * CPM / w; - var hy = 0.5 * HT * SCALE / w; + var L = CAR_L, WD = CAR_W, HT = CAR_H; + if (freight) { - var nxT = Math.round(hx); - var nmax = freight ? 4 : 2; + L = FR_L * (0.82 + hash2(idx, ky, S + SALT_LEN) * 0.42); WD = FR_W; HT = FR_H; + } + var dR = dirx * RGX + dirz * RGZ; if (dR < 0) dR = -dR; + var pR = -dirz * RGX + dirx * RGZ; if (pR < 0) pR = -pR; + var hx = 0.5 * (L * dR + WD * pR) * CPM / w; + var hy = 0.5 * HT * SCALE / w; - var two = (freight && hy >= 0.62 && (2 * nxT + 1) * 2 <= MAXCELLS) ? 1 : 0; - if ((2 * nxT + 1) * (two ? 2 : 1) > MAXCELLS) continue; + var nxT = Math.round(hx); + var nmax = freight ? 4 : 2; - var nx = nxT > nmax ? nmax : (nxT < NMIN ? NMIN : nxT); + var two = (freight && hy >= 0.62 && (2 * nxT + 1) * 2 <= MAXCELLS) ? 1 : 0; + if ((2 * nxT + 1) * (two ? 2 : 1) > MAXCELLS) continue; - var scale = VIS * (1 - (w - 90) * FADE); - if (scale > 1) scale = 1; - if (scale < MIN_SCALE) continue; + var nx = nxT > nmax ? nmax : (nxT < NMIN ? NMIN : nxT); - var dh = SKY_NEAR + dTrue * DSLOPE; - var dl = dh * 0.996; - var r0 = Math.round(row); - var q; - if (r0 < 0 || r0 >= ROWS) continue; + var scale = VIS * (1 - (w - 90) * FADE); + if (scale > 1) scale = 1; + if (scale < MIN_SCALE) continue; - var xi = Math.round(sx), xx, lx = 0, rx = 0, rowBase = r0 * COLS; - if (!(xi >= 0 && xi < COLS && FRAME.dist[rowBase + xi] >= SKY_NEAR)) continue; - for (q = -1; q >= -nx; q--) { - xx = xi + q; - if (!(xx >= 0 && xx < COLS && FRAME.dist[rowBase + xx] >= SKY_NEAR)) break; - lx = q; - } - for (q = 1; q <= nx; q++) { - xx = xi + q; - if (!(xx >= 0 && xx < COLS && FRAME.dist[rowBase + xx] >= SKY_NEAR)) break; - rx = q; - } - if (rx - lx + 1 < 3) continue; + var dh = SKY_NEAR + dTrue * DSLOPE; + var dl = dh * 0.996; + var r0 = Math.round(row); + var q; + if (r0 < 0 || r0 >= ROWS) continue; - var rr = dirx * RGX + dirz * RGZ; - var sgn = rr > 0 ? 1 : -1; + var xi = Math.round(sx), xx, lx = 0, rx = 0, rowBase = r0 * COLS; + if (!(xi >= 0 && xi < COLS && FRAME.dist[rowBase + xi] >= SKY_NEAR)) continue; + for (q = -1; q >= -nx; q--) { + xx = xi + q; + if (!(xx >= 0 && xx < COLS && FRAME.dist[rowBase + xx] >= SKY_NEAR)) break; + lx = q; + } + for (q = 1; q <= nx; q++) { + xx = xi + q; + if (!(xx >= 0 && xx < COLS && FRAME.dist[rowBase + xx] >= SKY_NEAR)) break; + rx = q; + } + if (rx - lx + 1 < 3) continue; - var hlum = freight ? HULL_FR : HULL_CAR; - var hg = freight ? G_HASH : G_EQ; - for (q = lx; q <= rx; q++) plot(FRAME, sx + q, r0, hg, P.shadow, hlum, dh); - if (two) { - for (q = lx + 1; q <= rx - 1; q++) - plot(FRAME, sx + q, r0 - 1, G_DASH, P.shadow, HULL_ROOF, dh); + var rr = dirx * RGX + dirz * RGZ; + var sgn = rr > 0 ? 1 : -1; - plot(FRAME, sx + (sgn > 0 ? rx - 1 : lx + 1), r0 - 1, G_o, P.amber, - UNDER_AMBER * 0.86 * scale, dl); - } + var hlum = freight ? HULL_FR : HULL_CAR; + var hg = freight ? G_HASH : G_EQ; + for (q = lx; q <= rx; q++) plot(FRAME, sx + q, r0, hg, P.shadow, hlum, dh); + if (two) { + for (q = lx + 1; q <= rx - 1; q++) + plot(FRAME, sx + q, r0 - 1, G_DASH, P.shadow, HULL_ROOF, dh); - var dot = dirx * FWX + dirz * FWZ; - var hue = hash2(idx, ky, S + SALT_HUE); - var headC = hue < 0.52 ? P.amber : P.azure; - var headL = (hue < 0.52 ? HEAD_AMBER : HEAD_AZURE) * scale; + plot(FRAME, sx + (sgn > 0 ? rx - 1 : lx + 1), r0 - 1, G_o, P.amber, + UNDER_AMBER * 0.86 * scale, dl); + } - if (dot > 0.55) { + var dot = dirx * FWX + dirz * FWZ; - plot(FRAME, sx + lx, r0, G_o, P.red, TAIL_RED * scale, dl); - plot(FRAME, sx + rx, r0, G_o, P.red, TAIL_RED * scale, dl); - } else if (dot < -0.55) { + var hue = hash2(idx, ky, S + SALT_HUE); + var headC = hue < 0.48 ? P.amber : (hue < 0.92 ? P.azure : P.jade); + var headL = (hue < 0.48 ? HEAD_AMBER : (hue < 0.92 ? HEAD_AZURE : HEAD_JADE)) * scale; - plot(FRAME, sx + lx, r0, G_o, headC, headL, dl); - plot(FRAME, sx + rx, r0, G_o, headC, headL * 0.80, dl); - } else { + if (dot > 0.55) { - plot(FRAME, sx + (sgn > 0 ? rx : lx), r0, G_o, headC, headL, dl); - plot(FRAME, sx + (sgn > 0 ? lx : rx), r0, G_o, P.red, TAIL_RED * 0.82 * scale, dl); + plot(FRAME, sx + lx, r0, G_o, P.red, TAIL_RED * scale, dl); + plot(FRAME, sx + rx, r0, G_o, P.red, TAIL_RED * scale, dl); + } else if (dot < -0.55) { - plot(FRAME, sx, r0 + 1, G_UNDER, P.amber, UNDER_AMBER * scale, dl); - } + plot(FRAME, sx + lx, r0, G_o, headC, headL, dl); + plot(FRAME, sx + rx, r0, G_o, headC, headL * 0.80, dl); + } else { - if (freight) { - if (CC.reducedMotion) { + plot(FRAME, sx + (sgn > 0 ? rx : lx), r0, G_o, headC, headL, dl); + plot(FRAME, sx + (sgn > 0 ? lx : rx), r0, G_o, P.red, TAIL_RED * 0.82 * scale, dl); - plot(FRAME, sx, r0 - two - 1, G_o, P.red, BEACON_RED * RM_BEACON * scale, dl); - } else { - var ph = TT * BEACON_HZ + hash2(idx, ky, S + SALT_BCN); - ph -= Math.floor(ph); - if (ph < BEACON_DUTY) { - var e = Math.sin(ph * Math.PI / BEACON_DUTY); - e *= e; + plot(FRAME, sx, r0 + 1, G_UNDER, P.amber, UNDER_AMBER * scale, dl); + } - if (e >= BEACON_MIN) plot(FRAME, sx, r0 - two - 1, G_o, P.red, BEACON_RED * e * scale, dl); - } - } - } + if (freight) { + if (CC.reducedMotion) { + + plot(FRAME, sx, r0 - two - 1, G_o, P.red, BEACON_RED * RM_BEACON * scale, dl); + } else { + var ph = TT * BEACON_HZ + hash2(idx, ky, S + SALT_BCN); + ph -= Math.floor(ph); + if (ph < BEACON_DUTY) { + var e = Math.sin(ph * Math.PI / BEACON_DUTY); + e *= e; + + if (e >= BEACON_MIN) plot(FRAME, sx, r0 - two - 1, G_o, P.red, BEACON_RED * e * scale, dl); } + } } + } } + } - CC.ELEMENTS.push({ - name: 'skylanes', + CC.ELEMENTS.push({ + name: 'skylanes', - world: 'cyber', - layer: 16, + world: 'cyber', + layer: 16, - init: function (city) { - CITY = city || null; - S = city && city.seed !== undefined ? (city.seed | 0) : 0; - AVE = city && city.AVE ? city.AVE : 30; - CROSS = city && city.CROSS ? city.CROSS : 26; - }, + init: function (city) { + CITY = city || null; + S = city && city.seed !== undefined ? (city.seed | 0) : 0; + AVE = city && city.AVE ? city.AVE : 30; + CROSS = city && city.CROSS ? city.CROSS : 26; + }, - draw: function (frame, cam, t) { - var city = CITY; - if (!city || !city.aveX) return; - camScreen(frame, cam); - bindWeather(); + draw: function (frame, cam, t) { + var city = CITY; + if (!city || !city.aveX) return; + camScreen(frame, cam); + bindWeather(); - VIS = 1 - (W_FOG > 0.34 ? (W_FOG - 0.34) * 1.70 : 0) - W_HAZE * 0.10; - if (VIS <= MIN_SCALE) return; - if (VIS > 1) VIS = 1; + VIS = 1 - (W_FOG > 0.34 ? (W_FOG - 0.34) * 1.70 : 0) - W_HAZE * 0.10; + if (VIS <= MIN_SCALE) return; + if (VIS > 1) VIS = 1; - TT = CC.reducedMotion ? 0 : t; - FRAME = frame; + TT = CC.reducedMotion ? 0 : t; + FRAME = frame; - var kc = Math.round(cam.x / AVE), mc = Math.round(cam.z / CROSS), i; - for (i = kc - KSPAN; i <= kc + KSPAN; i++) - lane(0, i, city.aveX(i) + 0.5, city.aveW(i) + 0.5); - for (i = mc - MSPAN; i <= mc + MSPAN; i++) - lane(1, i, city.crossZ(i) + 0.5, city.crossW(i) + 0.5); + var kc = Math.round(cam.x / AVE), mc = Math.round(cam.z / CROSS), i; + for (i = kc - KSPAN; i <= kc + KSPAN; i++) + lane(0, i, city.aveX(i) + 0.5, city.aveW(i) + 0.5); + for (i = mc - MSPAN; i <= mc + MSPAN; i++) + lane(1, i, city.crossZ(i) + 0.5, city.crossW(i) + 0.5); - FRAME = null; - } - }); + FRAME = null; + } + }); })(CC); /* src/elements/street.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise, put = CC.put; + var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise, put = CC.put; - var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), - G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_PIPE = g('|'), - G_HASH = g('#'), G_8 = g('8'), G_0 = g('0'), G_X = g('X'), G_o = g('o'), G_M = g('M'), - G_W = g('W'), G_CARET = g('^'), G_STAR = g('*'), G_SLASH = g('/'), G_BSLASH = g('\\'); + var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), + G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_PIPE = g('|'), + G_HASH = g('#'), G_8 = g('8'), G_0 = g('0'), G_X = g('X'), G_o = g('o'), G_M = g('M'), + G_W = g('W'), G_CARET = g('^'), G_STAR = g('*'), G_SLASH = g('/'), G_BSLASH = g('\\'); - var FILL = [G_8, G_0, G_HASH, G_M, G_W, G_X], FILL_N = FILL.length; - var PAPER = [G_QUOTE, G_TICK, G_COMMA, G_DOT, G_DASH, G_UNDER, G_COLON, G_SEMI], - PAPER_N = PAPER.length; + var FILL = [G_8, G_0, G_HASH, G_M, G_W, G_X], FILL_N = FILL.length; + var PAPER = [G_QUOTE, G_TICK, G_COMMA, G_DOT, G_DASH, G_UNDER, G_COLON, G_SEMI], + PAPER_N = PAPER.length; - var W_STILL = { rain: 0.65, wind: 0.55, fog: 0.30, wet: 0.90, storm: 0.12, haze: 0.40, - cloud: 0.75, steam: 0.85 }; - function wp() { return CC.Weather ? CC.Weather.P : W_STILL; } - function wrel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } + var W_STILL = { rain: 0.65, wind: 0.55, fog: 0.30, wet: 0.90, storm: 0.12, haze: 0.40, + cloud: 0.75, steam: 0.85 }; + function wp() { return CC.Weather ? CC.Weather.P : W_STILL; } + function wrel(k) { return CC.Weather ? CC.Weather.rel(k) : 1; } - function ctrlBlend() { return CC.Control ? CC.Control.blend : 0; } + function ctrlBlend() { return CC.Control ? CC.Control.blend : 0; } - function windRight() { - var W = CC.Wind; + function windRight() { + var W = CC.Wind; - if (!W) return 1.3; - if (CC.reducedMotion) { - var m = W.mult > 0.05 ? W.mult : 1; - return (W.x * RGX + W.z * RGZ) / m; + if (!W) return 1.3; + if (CC.reducedMotion) { + var m = W.mult > 0.05 ? W.mult : 1; + return (W.x * RGX + W.z * RGZ) / m; + } + return W.x * RGX + W.z * RGZ; + } + + var CX = 0, CZ = 0, FWX = 0, FWZ = 1, RGX = 1, RGZ = 0, HP = 0.7, EYE = 1.7; + var COLS = 0, ROWS = 0, HOR = 0, SCALE = 1, CPM = 1; + + function camBasis(cam) { + var yaw = cam.yaw || 0; + FWX = Math.sin(yaw); FWZ = Math.cos(yaw); + RGX = Math.cos(yaw); RGZ = -Math.sin(yaw); + CX = cam.x; CZ = cam.z; + HP = Math.tan((cam.fov || 1.25) * 0.5); + EYE = cam.eyeY !== undefined ? cam.eyeY : 1.7; + } + + function camScreenAt(cam, cols, rows) { + camBasis(cam); + COLS = cols; ROWS = rows; + HOR = cam.horizon !== undefined ? cam.horizon : ROWS * 0.56; + + SCALE = cam.scaleY !== undefined ? cam.scaleY + : (COLS * (cam.cellAspect || 0.5625)) / (2 * HP); + CPM = COLS * 0.5 / HP; + } + function camScreen(frame, cam) { camScreenAt(cam, frame.cols, frame.rows); } + + var PJ = { ok: 0, w: 0, sp: 0, x: 0, dist: 0 }; + + function project(px, pz) { + var dx = px - CX, dz = pz - CZ; + var w = dx * FWX + dz * FWZ; + + if (w < 0.45) { PJ.ok = 0; return PJ; } + var sp = (dx * RGX + dz * RGZ) / w; + PJ.ok = 1; PJ.w = w; PJ.sp = sp; + PJ.x = (sp / HP + 1) * COLS * 0.5 - 0.5; + PJ.dist = w * Math.sqrt(1 + sp * sp); + return PJ; + } + function rowOf(y, w) { return HOR - (y - EYE) * SCALE / w; } + + function roadDist(row, sp) { + var den = row - HOR; + if (den < 0.5) return 1e6; + return (EYE * SCALE / den) * Math.sqrt(1 + sp * sp); + } + + function fg(lum, dist) { + var S = CC.Surf; + return S ? S.fog(lum, dist) : lum; + } + + function near(d) { return d * 0.994; } + + function nearer(d) { return d * 0.982; } + + var COR = { axis: 0, ctr: 0, half: 3.5, along: 0, dir: 1 }; + function corridor(city, cam) { + if (!city || !city.aveX) { + COR.axis = 0; COR.ctr = 0.5; COR.half = 3.5; + COR.along = cam.z; COR.dir = FWZ < 0 ? -1 : 1; + return COR; + } + var k = Math.round(cam.x / city.AVE), m = Math.round(cam.z / city.CROSS); + var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d; + for (i = k - 1; i <= k + 1; i++) { + c = city.aveX(i) + 0.5; d = cam.x - c; if (d < 0) d = -d; + if (d < bA) { bA = d; aC = c; aW = city.aveW(i) + 0.5; } + } + for (i = m - 1; i <= m + 1; i++) { + c = city.crossZ(i) + 0.5; d = cam.z - c; if (d < 0) d = -d; + if (d < bC) { bC = d; cC = c; cW = city.crossW(i) + 0.5; } + } + var afz = FWZ < 0 ? -FWZ : FWZ, afx = FWX < 0 ? -FWX : FWX; + if (bC <= cW && (bA > aW || afx > afz)) { + COR.axis = 1; COR.ctr = cC; COR.half = cW; COR.along = cam.x; COR.dir = FWX < 0 ? -1 : 1; + } else { + COR.axis = 0; COR.ctr = aC; COR.half = aW; COR.along = cam.z; COR.dir = FWZ < 0 ? -1 : 1; + } + return COR; + } + function worldX(a, l) { return COR.axis ? a : COR.ctr + l; } + function worldZ(a, l) { return COR.axis ? COR.ctr + l : a; } + + function kerbL() { + var p = COR.half - CC.PAVE; + if (p < 1.7) p = 1.7; + + if (p > COR.half * 0.72) p = COR.half * 0.72; + return p; + } + + function bar(f, x, rTop, rBot, ch, col, lum, dist) { + var r0 = Math.round(rTop), r1 = Math.round(rBot); + if (r1 < r0) r1 = r0; + if (r0 < 0) r0 = 0; + if (r1 > ROWS - 1) r1 = ROWS - 1; + for (var r = r0; r <= r1; r++) put(f, x, r, ch, col, lum, dist); + } + + var stalls = null, STALL_N = 3, PUFF_N = 5; + + CC.ELEMENTS.push({ + name: 'foodstalls', + + world: 'cyber', + layer: 18, + init: function (city, rng) { + this.city = city; + this.seed = (rng() * 2147483647) | 0; + + this.boot = 0; + stalls = new Array(STALL_N); + for (var i = 0; i < STALL_N; i++) + stalls[i] = { x: 0, z: 0, side: 1, n: i * 37 + 1, live: 0, hue: P.amber, + w: 1.8, tall: 2.2 }; + }, + + update: function (dt, t, cam) { + camBasis(cam); + corridor(this.city, cam); + var S = this.seed, kl = kerbL(), i; + var fresh = !this.boot; + this.boot = 1; + for (i = 0; i < STALL_N; i++) { + var s = stalls[i]; + if (s.live) { + var p = project(s.x, s.z); + + var sl = COR.axis ? s.z - COR.ctr : s.x - COR.ctr; + if (sl < 0) sl = -sl; + + if (p.ok && p.w < 96 && p.sp < HP * 2.4 && p.sp > -HP * 2.4 && sl < COR.half + 3) continue; + s.live = 0; } - return W.x * RGX + W.z * RGZ; - } + s.n++; - var CX = 0, CZ = 0, FWX = 0, FWZ = 1, RGX = 1, RGZ = 0, HP = 0.7, EYE = 1.7; - var COLS = 0, ROWS = 0, HOR = 0, SCALE = 1, CPM = 1; + var h1 = hash2(i, s.n, S), h2 = hash2(i, s.n, S ^ 0x5A1), h3 = hash2(i, s.n, S ^ 0x9B), + h4 = hash2(i, s.n, S + 101), h5 = hash2(i, s.n, S + 211), h6 = hash2(i, s.n, S + 307); - function camBasis(cam) { - var yaw = cam.yaw || 0; - FWX = Math.sin(yaw); FWZ = Math.cos(yaw); - RGX = Math.cos(yaw); RGZ = -Math.sin(yaw); - CX = cam.x; CZ = cam.z; - HP = Math.tan((cam.fov || 1.25) * 0.5); - EYE = cam.eyeY !== undefined ? cam.eyeY : 1.7; - } + var a = COR.along + COR.dir * (fresh ? 8 + i * 25 + h1 * 14 : 66 + h1 * 24); + s.side = h2 < 0.5 ? -1 : 1; + var l = s.side * (kl + 0.25 + h3 * 0.55); + s.x = worldX(a, l); s.z = worldZ(a, l); + s.w = 1.5 + h4 * 1.3; + s.tall = 2.05 + h5 * 0.45; - function camScreenAt(cam, cols, rows) { - camBasis(cam); - COLS = cols; ROWS = rows; - HOR = cam.horizon !== undefined ? cam.horizon : ROWS * 0.56; + s.hue = h6 < 0.55 ? P.amber : P.warm; + s.live = 1; + } + }, + draw: function (frame, cam, t) { + camScreen(frame, cam); + var S = this.seed, i, j, x; + for (i = 0; i < STALL_N; i++) { + var s = stalls[i]; + if (!s.live) continue; + var p = project(s.x, s.z); - SCALE = cam.scaleY !== undefined ? cam.scaleY - : (COLS * (cam.cellAspect || 0.5625)) / (2 * HP); - CPM = COLS * 0.5 / HP; - } - function camScreen(frame, cam) { camScreenAt(cam, frame.cols, frame.rows); } + if (!p.ok || p.dist > 96) continue; - var PJ = { ok: 0, w: 0, sp: 0, x: 0, dist: 0 }; + var w = p.w, cx = p.x, dist = p.dist, sp = p.sp, d = near(dist); + var hw = s.w * 0.5 * CPM / w; + if (hw < 0.5) hw = 0.5; + var x0 = Math.round(cx - hw), x1 = Math.round(cx + hw); + if (x1 < 0 || x0 > COLS - 1) continue; - function project(px, pz) { - var dx = px - CX, dz = pz - CZ; - var w = dx * FWX + dz * FWZ; + var rGnd = rowOf(0, w); + var rCtT = rowOf(1.36, w), rCtB = rowOf(0.98, w); + var rTop = rowOf(s.tall, w), rEave = rowOf(s.tall - 0.28, w); + var lit = fg(196 + hash2(i, s.n, S ^ 0x3) * 46, dist); + var dim = fg(30, dist); - if (w < 0.45) { PJ.ok = 0; return PJ; } - var sp = (dx * RGX + dz * RGZ) / w; - PJ.ok = 1; PJ.w = w; PJ.sp = sp; - PJ.x = (sp / HP + 1) * COLS * 0.5 - 0.5; - PJ.dist = w * Math.sqrt(1 + sp * sp); - return PJ; - } - function rowOf(y, w) { return HOR - (y - EYE) * SCALE / w; } + var cpm = CPM / w; + for (x = x0; x <= x1; x++) { + if (x < 0 || x > COLS - 1) continue; + var hx = hash2(Math.floor((x - cx) / cpm * 3), s.n, S ^ 0x71); - function roadDist(row, sp) { - var den = row - HOR; - if (den < 0.5) return 1e6; - return (EYE * SCALE / den) * Math.sqrt(1 + sp * sp); - } - - function fg(lum, dist) { - var S = CC.Surf; - return S ? S.fog(lum, dist) : lum; - } - - function near(d) { return d * 0.994; } - - function nearer(d) { return d * 0.982; } - - var COR = { axis: 0, ctr: 0, half: 3.5, along: 0, dir: 1 }; - function corridor(city, cam) { - if (!city || !city.aveX) { - COR.axis = 0; COR.ctr = 0.5; COR.half = 3.5; - COR.along = cam.z; COR.dir = FWZ < 0 ? -1 : 1; - return COR; + bar(frame, x, rTop, rEave, hx < 0.55 ? G_EQ : 0, P.shadow, hx < 0.55 ? dim * 0.6 : 0, d); + bar(frame, x, rEave + 1, rCtT - 1, 0, P.shadow, 0, d); + bar(frame, x, rCtT, rCtB, FILL[(hx * FILL_N) | 0], s.hue, lit * (0.82 + hx * 0.30), d); + bar(frame, x, rCtB + 1, rGnd, hx < 0.30 ? G_PIPE : 0, P.shadow, + hx < 0.30 ? dim * 0.5 : 0, d); } - var k = Math.round(cam.x / city.AVE), m = Math.round(cam.z / city.CROSS); - var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d; - for (i = k - 1; i <= k + 1; i++) { - c = city.aveX(i) + 0.5; d = cam.x - c; if (d < 0) d = -d; - if (d < bA) { bA = d; aC = c; aW = city.aveW(i) + 0.5; } + + if (dist < 40) { + var bl = fg(150, dist); + if (bl >= 5) + put(frame, Math.round(cx + (hash2(i, s.n, S ^ 0xE) - 0.5) * hw), + Math.round(rCtT - 1), G_o, P.ember, bl, nearer(dist)); } - for (i = m - 1; i <= m + 1; i++) { - c = city.crossZ(i) + 0.5; d = cam.z - c; if (d < 0) d = -d; - if (d < bC) { bC = d; cC = c; cW = city.crossW(i) + 0.5; } + + if (dist < 40) { + var wetS = wrel('wet'); + var spn = 2 + ((wetS * 2.2) | 0); if (spn > 5) spn = 5; + var rp0 = Math.round(rGnd) + 1; + for (j = 0; j < spn; j++) { + var rr = rp0 + j, rd = roadDist(rr, sp); + var sl = fg(58 * (1 - j * 0.22) * (0.55 + 0.45 * wetS), rd); + if (sl < 5) continue; + put(frame, Math.round(cx - s.side * (j * 0.6)), rr, + j < 2 ? G_COLON : G_QUOTE, s.hue, sl, near(rd)); + } } - var afz = FWZ < 0 ? -FWZ : FWZ, afx = FWX < 0 ? -FWX : FWX; - if (bC <= cW && (bA > aW || afx > afz)) { - COR.axis = 1; COR.ctr = cC; COR.half = cW; COR.along = cam.x; COR.dir = FWX < 0 ? -1 : 1; - } else { - COR.axis = 0; COR.ctr = aC; COR.half = aW; COR.along = cam.z; COR.dir = FWZ < 0 ? -1 : 1; + + var tt = CC.reducedMotion ? t * (0.05 / 0.42) : t; + for (j = 0; j < PUFF_N; j++) { + var ph = hash2(j, s.n, S ^ 0xC0FE); + var age = (tt * 0.42 + ph) % 1; + + var drift = (vnoise(tt * 0.5 + ph * 20, S ^ 0x1D) - 0.5) * age * 2.6; + + var fade = (1 - age) * (1 - age) * (age < 0.14 ? age / 0.14 : 1); + var sl2 = fg(50 * fade, dist); + if (sl2 < 6) continue; + + put(frame, Math.round(cx + drift * CPM / w * 0.6), + Math.round(rowOf(s.tall + 0.15 + age * 3.4, w)), + age < 0.35 ? G_QUOTE : G_TICK, P.slate, sl2, near(dist)); } - return COR; + } } - function worldX(a, l) { return COR.axis ? a : COR.ctr + l; } - function worldZ(a, l) { return COR.axis ? COR.ctr + l : a; } + }); - function kerbL() { - var p = COR.half - CC.PAVE; - if (p < 1.7) p = 1.7; + var ARCH = [ + { name: 'plain', w: 0.13, ww: 0.140, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 1.00, crest: 0.00, cane: 0, + tallB: 0.00, stride: 1.00, bob: 0.035, spd: 1.00, accP: 0.06, acc: 3, + visP: 0.10, scarf: 0, hair: 0.00 }, + { name: 'coat', w: 0.14, ww: 0.200, hem: 0.70, hemTop: 0.46, hemBot: 0.97, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 1.00, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.86, bob: 0.028, spd: 0.96, accP: 0.10, acc: 3, + visP: 0.08, scarf: 1, hair: 0.00 }, + { name: 'hood', w: 0.12, ww: 0.030, hem: 0.26, hemTop: 0.58, hemBot: 0.92, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 1, umb: 0, wide: 1.02, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.96, bob: 0.024, spd: 1.08, accP: 0.14, acc: 1, + visP: 0.22, scarf: 0, hair: 0.00 }, + { name: 'skirt', w: 0.10, ww: 0.120, hem: 0.34, hemTop: 0.50, hemBot: 0.76, legTop: 0.76, legW: 0.19, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 0.92, crest: 0.00, cane: 0, + tallB: 0.00, stride: 1.24, bob: 0.052, spd: 1.02, accP: 0.10, acc: 4, + visP: 0.08, scarf: 1, hair: 0.00 }, + { name: 'courier', w: 0.09, ww: 0.000, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.55, bag: 0.00, hood: 0, umb: 0, wide: 1.00, crest: 0.00, cane: 0, + tallB: 0.00, stride: 1.14, bob: 0.030, spd: 1.30, accP: 0.34, acc: 2, + visP: 0.34, scarf: 0, hair: 0.00 }, - if (p > COR.half * 0.72) p = COR.half * 0.72; - return p; + { name: 'shell', w: 0.06, ww: 0.000, hem: 0.16, hemTop: 0.55, hemBot: 0.95, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.00, crest: 0.00, cane: 0, + tallB: 0.14, stride: 0.98, bob: 0.032, spd: 1.04, accP: 0.78, acc: 1, + visP: 0.40, scarf: 0, hair: 0.00 }, + { name: 'hat', w: 0.07, ww: 0.230, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.55, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 1.00, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.92, bob: 0.026, spd: 0.94, accP: 0.06, acc: 3, + visP: 0.04, scarf: 0, hair: 0.00 }, + { name: 'bagger', w: 0.11, ww: 0.080, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.60, hood: 0, umb: 1, wide: 1.00, crest: 0.00, cane: 0, + tallB: 0.00, stride: 1.00, bob: 0.034, spd: 0.97, accP: 0.18, acc: 4, + visP: 0.08, scarf: 0, hair: 0.00 }, + + { name: 'suit', w: 0.08, ww: 0.030, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.26, + brim: 0.00, pack: 0.00, bag: 0.34, hood: 0, umb: 1, wide: 0.90, crest: 0.00, cane: 0, + tallB: 0.04, stride: 1.06, bob: 0.022, spd: 1.12, accP: 0.05, acc: 4, + visP: 0.06, scarf: 1, hair: 0.00 }, + + { name: 'heavy', w: 0.06, ww: 0.050, hem: 0.10, hemTop: 0.62, hemBot: 0.94, legTop: 1.00, legW: 0.34, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.46, crest: 0.00, cane: 0, + tallB: -0.06, stride: 0.78, bob: 0.030, spd: 0.82, accP: 0.12, acc: 3, + visP: 0.10, scarf: 0, hair: 0.00 }, + + { name: 'crest', w: 0.05, ww: 0.000, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.28, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.94, crest: 0.16, cane: 0, + tallB: 0.02, stride: 1.10, bob: 0.040, spd: 1.14, accP: 0.46, acc: 1, + visP: 0.44, scarf: 0, hair: 0.00 }, + + { name: 'elder', w: 0.05, ww: 0.080, hem: 0.30, hemTop: 0.48, hemBot: 0.90, legTop: 1.00, legW: 0.28, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 0.96, crest: 0.00, cane: 1, + tallB: -0.11, stride: 0.70, bob: 0.016, spd: 0.66, accP: 0.08, acc: 4, + visP: 0.02, scarf: 1, hair: 0.00 }, + + { name: 'cloak', w: 0.055, ww: 0.075, hem: 0.95, hemTop: 0.42, hemBot: 0.74, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 1, umb: 0, wide: 0.94, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.82, bob: 0.022, spd: 0.90, accP: 0.16, acc: 1, + visP: 0.16, scarf: 0, hair: 0.00 }, + + { name: 'mane', w: 0.05, ww: 0.020, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.26, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 0.96, crest: 0.00, cane: 0, + tallB: 0.00, stride: 1.08, bob: 0.046, spd: 1.06, accP: 0.20, acc: 4, + visP: 0.12, scarf: 1, hair: 0.30 }, + + { name: 'rigger', w: 0.070, ww: 0.050, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 0.66, legW: 0.50, + brim: 0.00, pack: 0.30, bag: 0.00, hood: 0, umb: 0, wide: 1.12, crest: 0.00, cane: 0, + tallB: -0.02, stride: 0.84, bob: 0.026, spd: 0.88, accP: 0.75, acc: 5, + visP: 0.30, scarf: 0, hair: 0.00 }, + + { name: 'child', w: 0.055, ww: 0.075, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.00, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.90, bob: 0.030, spd: 0.74, accP: 0.10, acc: 4, + visP: 0.04, scarf: 0, hair: 0.00, child: 0.58 }, + + { name: 'cycle', w: 0.050, ww: 0.000, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.28, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.96, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.94, bob: 0.020, spd: 1.06, accP: 0.24, acc: 2, + visP: 0.18, scarf: 0, hair: 0.00, barW: 2.30, barV: 0.54, wheel: 1 }, + + { name: 'carry', w: 0.050, ww: 0.120, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.32, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.10, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.82, bob: 0.024, spd: 0.86, accP: 0.14, acc: 3, + visP: 0.10, scarf: 0, hair: 0.00, pole: 3.00 }, + + { name: 'flare', w: 0.055, ww: 0.110, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.28, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.98, crest: 0.00, cane: 0, + tallB: 0.02, stride: 1.12, bob: 0.026, spd: 1.18, accP: 0.16, acc: 3, + visP: 0.10, scarf: 1, hair: 0.00, tail: 0.80, tailTop: 0.34, tailBot: 0.86 }, + + { name: 'vendor', w: 0.045, ww: 0.030, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.28, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.94, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.60, bob: 0.012, spd: 0.30, accP: 0.62, acc: 4, + visP: 0.06, scarf: 0, hair: 0.00, barW: 1.55, barV: 0.50, barBoth: 1 }, + + { name: 'bedroll', w: 0.045, ww: 0.120, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.32, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.18, crest: 0.00, cane: 0, + tallB: -0.04, stride: 0.80, bob: 0.028, spd: 0.80, accP: 0.20, acc: 3, + visP: 0.06, scarf: 0, hair: 0.00, roll: 0.70 }, + + { name: 'wheels', w: 0.040, ww: 0.015, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 1.02, crest: 0.00, cane: 0, + tallB: -0.30, stride: 1.00, bob: 0.008, spd: 0.92, accP: 0.14, acc: 4, + visP: 0.08, scarf: 0, hair: 0.00, seat: 0.56, wheelW: 1.30 }, + + { name: 'runner', w: 0.040, ww: 0.025, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.94, crest: 0.00, cane: 0, + tallB: 0.02, stride: 1.72, bob: 0.062, spd: 1.74, accP: 0.10, acc: 2, + visP: 0.14, scarf: 0, hair: 0.00, lean: 0.55, legSpread: 1 } + ]; + + var ARM_EXT = 0.20; + var ARCH_TOT = 0, ARCH_TOT_W = 0; + (function () { + + for (var i = 0; i < ARCH.length; i++) { + var A = ARCH[i], e = A.hem; + + if (A.child === undefined) A.child = 0; + if (A.barW === undefined) { A.barW = 0; A.barV = 0.5; A.barBoth = 0; } + if (A.barBoth === undefined) A.barBoth = 0; + if (A.wheel === undefined) A.wheel = 0; + if (A.pole === undefined) A.pole = 0; + if (A.tail === undefined) { A.tail = 0; A.tailTop = 0.4; A.tailBot = 0.9; } + if (A.roll === undefined) A.roll = 0; + if (A.seat === undefined) { A.seat = 0; A.wheelW = 0; } + if (A.lean === undefined) A.lean = 0; + if (A.legSpread === undefined) A.legSpread = 0; + if (A.brim > e) e = A.brim; + if (A.pack > e) e = A.pack; + if (A.bag > e) e = A.bag; + + if (A.child > 0 && 1.25 > e) e = 1.25; + if (A.tail > e) e = A.tail; + if (A.roll > e) e = A.roll; + if (A.wheelW > e) e = A.wheelW; + if (A.lean > e) e = A.lean; + + if (ARM_EXT > e) e = ARM_EXT; + A.ext = e; + ARCH_TOT += A.w; A.acc0 = ARCH_TOT; + + ARCH_TOT_W += (A.ww === undefined ? A.w : A.ww); A.acc1 = ARCH_TOT_W; + } + })(); + + var PED_WEST = 0; + function archPick(h) { + var i; + if (PED_WEST) { + 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]; + } + var r = h * ARCH_TOT; + for (i = 0; i < ARCH.length - 1; i++) if (r < ARCH[i].acc0) return ARCH[i]; + return ARCH[ARCH.length - 1]; + } + + var peds = null, PED_MAX = 70, PED_AT_REF = 26, REF_CELLS = 200 * 60; + + function pedWant(cells) { + var n = PED_AT_REF * Math.sqrt(cells / REF_CELLS); + + n *= 1 - 0.38 * wp().rain; + n = n | 0; + return n > PED_MAX ? PED_MAX : (n < 4 ? 4 : n); + } + + function pedShoulder(w, A) { + var shw = 0.24 * (A ? A.wide : 1) * CPM / w; + return shw < 0.45 ? 0.45 : shw; + } + function pedCover(p, pr) { + var xw = pedShoulder(pr.w, p.A) * (1 + p.A.ext); + + var x0 = pr.x - xw, x1 = pr.x + xw; + if (x0 < 0) x0 = 0; + if (x1 > COLS - 1) x1 = COLS - 1; + if (x1 <= x0) return 0; + var rr = (p.tall + p.A.tallB) * SCALE / pr.w; + if (rr > ROWS) rr = ROWS; + return (x1 - x0) * rr / (COLS * ROWS); + } + + var PED_COVER_MAX = 0.035; + + var FF_HUE = 0, FF_SIGN = -1; + function footfall(city, a, l) { + FF_HUE = P.amber; FF_SIGN = -1; + if (!city || !city.cell) return 1; + + var ll = l + (l < 0 ? -2.2 : 2.2); + var c = city.cell(worldX(a, ll), worldZ(a, ll)); + if (!c) return 0.62; + FF_HUE = c.hue; + if (c.sign && typeof c.sign.hue === 'number') FF_SIGN = c.sign.hue | 0; + return 0.34 + c.litRate * 2.4 + (c.sign ? 0.55 : 0); + } + + function pedSpawn(p, i, S, fresh, city) { + p.n++; + var n = p.n; + + var h1 = hash2(i, n, S + 101), h2 = hash2(i, n, S + 211), h3 = hash2(i, n, S + 307), + h4 = hash2(i, n, S + 401), h5 = hash2(i, n, S + 503), h6 = hash2(i, n, S + 601), + h7 = hash2(i, n, S + 701), h8 = hash2(i, n, S + 809), h9 = hash2(i, n, S + 907), + h10 = hash2(i, n, S + 1013), h11 = hash2(i, n, S + 1117), h12 = hash2(i, n, S + 1223), + h13 = hash2(i, n, S + 1301), h14 = hash2(i, n, S + 1409), + h15 = hash2(i, n, S + 1511), h16 = hash2(i, n, S + 1607), + h17 = hash2(i, n, S + 1709), h18 = hash2(i, n, S + 1811), + h19 = hash2(i, n, S + 1907); + var rain = wp().rain; + var kl = kerbL(), band = COR.half - kl - 0.6; + if (band < 0.2) band = 0.2; + var side = h2 < 0.5 ? -1 : 1; + var A = archPick(h4); + var a, l, ki; + + var l0 = side * (kl + 0.2 + h3 * band); + var bestA = COR.along + COR.dir * 58, bestF = -1, bestH = P.amber, bestS = -1; + for (ki = 0; ki < 3; ki++) { + var hk = hash2(i, n * 4 + ki, S + 1361); + + var ak = COR.along + COR.dir * (fresh ? 5 + hk * 42 : 52 + hk * 16); + var ff = footfall(city, ak, l0); + if (ff > bestF) { bestF = ff; bestA = ak; bestH = FF_HUE; bestS = FF_SIGN; } } - function bar(f, x, rTop, rBot, ch, col, lum, dist) { - var r0 = Math.round(rTop), r1 = Math.round(rBot); - if (r1 < r0) r1 = r0; - if (r0 < 0) r0 = 0; - if (r1 > ROWS - 1) r1 = ROWS - 1; - for (var r = r0; r <= r1; r++) put(f, x, r, ch, col, lum, dist); + if (!fresh && bestF < 0.55 + h6 * 0.80) { + p.live = 0; p.wait = 0.5 + h6 * 2.4; + return; } - var stalls = null, STALL_N = 3, PUFF_N = 5; + var sp = (0.95 + h1 * 0.55) * A.spd; - CC.ELEMENTS.push({ - name: 'foodstalls', + sp *= 1 - 0.16 * rain; + p.shelter = 0; - world: 'cyber', - layer: 18, - init: function (city, rng) { - this.city = city; - this.seed = (rng() * 2147483647) | 0; + var shP = 0.05 + 0.22 * rain; + if (h7 < 0.28) { - this.boot = 0; - stalls = new Array(STALL_N); - for (var i = 0; i < STALL_N; i++) - stalls[i] = { x: 0, z: 0, side: 1, n: i * 37 + 1, live: 0, hue: P.amber, - w: 1.8, tall: 2.2 }; - }, + p.cross = 1; p.goSide = side; + a = COR.along + COR.dir * (fresh ? 7 + h1 * 22 : 15 + h1 * 17); + l = -side * (COR.half + 1.2); + p.vx = COR.axis ? 0 : side * sp; + p.vz = COR.axis ? side * sp : 0; + } else if (h7 < 0.28 + shP) { - update: function (dt, t, cam) { - camBasis(cam); - corridor(this.city, cam); - var S = this.seed, kl = kerbL(), i; - var fresh = !this.boot; - this.boot = 1; - for (i = 0; i < STALL_N; i++) { - var s = stalls[i]; - if (s.live) { - var p = project(s.x, s.z); + p.cross = 0; p.shelter = 1; + p.vx = 0; p.vz = 0; + a = bestA; l = side * (COR.half - 0.5); - var sl = COR.axis ? s.z - COR.ctr : s.x - COR.ctr; - if (sl < 0) sl = -sl; + var sst = h13 < 0.5 && stalls ? stalls[(h13 * 2 * STALL_N) | 0] : null; + if (sst && sst.live) { - if (p.ok && p.w < 96 && p.sp < HP * 2.4 && p.sp > -HP * 2.4 && sl < COR.half + 3) continue; - s.live = 0; - } - s.n++; + var sa = COR.axis ? sst.x : sst.z; + var sl = (COR.axis ? sst.z : sst.x) - COR.ctr; + a = sa + (h1 - 0.5) * 3.6; - var h1 = hash2(i, s.n, S), h2 = hash2(i, s.n, S ^ 0x5A1), h3 = hash2(i, s.n, S ^ 0x9B), - h4 = hash2(i, s.n, S + 101), h5 = hash2(i, s.n, S + 211), h6 = hash2(i, s.n, S + 307); + l = sl + (sl < 0 ? 1 : -1) * (sst.w * 0.5 + 0.62); + side = sl < 0 ? -1 : 1; + } + } else { - var a = COR.along + COR.dir * (fresh ? 8 + i * 25 + h1 * 14 : 66 + h1 * 24); - s.side = h2 < 0.5 ? -1 : 1; - var l = s.side * (kl + 0.25 + h3 * 0.55); - s.x = worldX(a, l); s.z = worldZ(a, l); - s.w = 1.5 + h4 * 1.3; - s.tall = 2.05 + h5 * 0.45; + p.cross = 0; + a = bestA; l = l0; + var go = (h5 < 0.62 ? -1 : 1) * COR.dir; + p.vx = COR.axis ? go * sp : 0; + p.vz = COR.axis ? 0 : go * sp; - s.hue = h6 < 0.55 ? P.amber : P.warm; - s.live = 1; - } - }, - draw: function (frame, cam, t) { - camScreen(frame, cam); - var S = this.seed, i, j, x; - for (i = 0; i < STALL_N; i++) { - var s = stalls[i]; - if (!s.live) continue; - var p = project(s.x, s.z); + var q = i > 0 ? peds[i - 1] : null; + if (q && q.live && !q.cross && !q.shelter && h13 < 0.26) { + var qa = COR.axis ? q.x : q.z, ql = (COR.axis ? q.z : q.x) - COR.ctr; - if (!p.ok || p.dist > 96) continue; + var gl = ql + (ql < 0 ? 1 : -1) * (0.62 + h15 * 0.34); + if (gl > kl + 0.15) gl = kl + 0.15; + if (gl < -kl - 0.15) gl = -kl - 0.15; + a = qa + (h16 - 0.5) * 1.1; + l = gl; + side = gl < 0 ? -1 : 1; + p.vx = q.vx; p.vz = q.vz; + } + } + p.x = worldX(a, l); p.z = worldZ(a, l); + p.dodge = 0; p.dx = 0; p.dz = 0; + p.A = A; + p.tall = 1.62 + h11 * 0.22; + p.walked = 0; + p.phase = h3 * 6.283; - var w = p.w, cx = p.x, dist = p.dist, sp = p.sp, d = near(dist); - var hw = s.w * 0.5 * CPM / w; - if (hw < 0.5) hw = 0.5; - var x0 = Math.round(cx - hw), x1 = Math.round(cx + hw); - if (x1 < 0 || x0 > COLS - 1) continue; + p.side = p.shelter ? (l < 0 ? -1 : 1) : (h14 < 0.5 ? -1 : 1); - var rGnd = rowOf(0, w); - var rCtT = rowOf(1.36, w), rCtB = rowOf(0.98, w); - var rTop = rowOf(s.tall, w), rEave = rowOf(s.tall - 0.28, w); - var lit = fg(196 + hash2(i, s.n, S ^ 0x3) * 46, dist); - var dim = fg(30, dist); + var scr = bestH === P.azure; - var cpm = CPM / w; - for (x = x0; x <= x1; x++) { - if (x < 0 || x > COLS - 1) continue; - var hx = hash2(Math.floor((x - cx) / cpm * 3), s.n, S ^ 0x71); + p.rim = PED_WEST ? ((h10 < 0.80) ? P.amber : P.warm) + : ((h10 < 0.80 ? scr : !scr) ? P.azure : P.amber); - bar(frame, x, rTop, rEave, hx < 0.55 ? G_EQ : 0, P.shadow, hx < 0.55 ? dim * 0.6 : 0, d); - bar(frame, x, rEave + 1, rCtT - 1, 0, P.shadow, 0, d); - bar(frame, x, rCtT, rCtB, FILL[(hx * FILL_N) | 0], s.hue, lit * (0.82 + hx * 0.30), d); - bar(frame, x, rCtB + 1, rGnd, hx < 0.30 ? G_PIPE : 0, P.shadow, - hx < 0.30 ? dim * 0.5 : 0, d); - } + if (!PED_WEST && 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; - if (dist < 40) { - var bl = fg(150, dist); - if (bl >= 5) - put(frame, Math.round(cx + (hash2(i, s.n, S ^ 0xE) - 0.5) * hw), - Math.round(rCtT - 1), G_o, P.ember, bl, nearer(dist)); - } + p.umbOwn = A.umb && h9 < 0.62 ? 1 : 0; + p.uRate = 0.20 + h1 * 0.26; - if (dist < 40) { - var wetS = wrel('wet'); - var spn = 2 + ((wetS * 2.2) | 0); if (spn > 5) spn = 5; - var rp0 = Math.round(rGnd) + 1; - for (j = 0; j < spn; j++) { - var rr = rp0 + j, rd = roadDist(rr, sp); - var sl = fg(58 * (1 - j * 0.22) * (0.55 + 0.45 * wetS), rd); - if (sl < 5) continue; - put(frame, Math.round(cx - s.side * (j * 0.6)), rr, - j < 2 ? G_COLON : G_QUOTE, s.hue, sl, near(rd)); - } - } + if (h12 < 0.18 && !PED_WEST) { + var q = h12 / 0.18; + p.phone = q < 0.70 ? P.azure : (q < 0.88 ? P.ice : P.violet); + } else p.phone = -1; - var tt = CC.reducedMotion ? t * (0.05 / 0.42) : t; - for (j = 0; j < PUFF_N; j++) { - var ph = hash2(j, s.n, S ^ 0xC0FE); - var age = (tt * 0.42 + ph) % 1; + if (h8 < A.accP) { + var qa = h8 / A.accP; - var drift = (vnoise(tt * 0.5 + ph * 20, S ^ 0x1D) - 0.5) * age * 2.6; + p.acc = PED_WEST ? ((A.acc === 1 || A.acc === 2 || A.acc === 5) ? 3 : A.acc) : A.acc; - var fade = (1 - age) * (1 - age) * (age < 0.14 ? age / 0.14 : 1); - var sl2 = fg(50 * fade, dist); - if (sl2 < 6) continue; + p.accHue = PED_WEST ? (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 + : A.acc === 5 ? P.amber + : (qa < 0.60 ? P.warm : P.amber); + } else { p.acc = 0; p.accHue = P.amber; } - put(frame, Math.round(cx + drift * CPM / w * 0.6), - Math.round(rowOf(s.tall + 0.15 + age * 3.4, w)), - age < 0.35 ? G_QUOTE : G_TICK, P.slate, sl2, near(dist)); - } - } + if (h19 < 0.20) { + var qw = h19 / 0.20; + p.wear = qw < 0.34 ? 1 : (qw < 0.72 ? 2 : 3); + + if (PED_WEST && p.wear === 3) p.wear = 2; + } else p.wear = 0; + + if (h17 < A.visP && !PED_WEST) { + 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 + : (qv < 0.93 ? P.violet : P.red))); + } else { p.vis = 0; p.visHue = P.azure; } + p.live = 1; + } + + CC.ELEMENTS.push({ + name: 'pedestrians', + layer: 20, + + world: ['cyber', 'west'], + init: function (city, rng, dims) { + this.city = city; + + PED_WEST = (city && city.world === 'west') ? 1 : 0; + + this.seed = (rng() * 30011) | 0; + this.boot = 0; + this.cols = dims && dims.cols ? dims.cols : 200; + this.rows = dims && dims.rows ? dims.rows : 60; + this.cells = this.cols * this.rows; + peds = new Array(PED_MAX); + for (var i = 0; i < PED_MAX; i++) + 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] }; + }, + update: function (dt, t, cam) { + + camScreenAt(cam, this.cols, this.rows); + corridor(this.city, cam); + var S = this.seed, city = this.city, i, p; + + if (!this.boot) { + this.boot = 1; + for (i = 0; i < PED_MAX; i++) pedSpawn(peds[i], i, S, 1, city); + } + var k = CC.reducedMotion ? 0.10 : 1; + var eK = CC.reducedMotion ? 0.35 : 1; + var want = pedWant(this.cells); + var rain = wp().rain, cb = ctrlBlend(); + var latX = COR.axis ? 0 : 1, latZ = COR.axis ? 1 : 0; + for (i = 0; i < PED_MAX; i++) { + p = peds[i]; + if (i >= want) { + + if (p.live) { p.live = 0; p.wait = 0.4 + (i % 7) * 0.35; } + continue; } - }); + if (!p.live) { - var ARCH = [ - { name: 'plain', w: 0.13, ww: 0.140, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 1.00, crest: 0.00, cane: 0, - tallB: 0.00, stride: 1.00, bob: 0.035, spd: 1.00, accP: 0.06, acc: 3, - visP: 0.10, scarf: 0, hair: 0.00 }, - { name: 'coat', w: 0.14, ww: 0.200, hem: 0.70, hemTop: 0.46, hemBot: 0.97, legTop: 1.00, legW: 0.30, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 1.00, crest: 0.00, cane: 0, - tallB: 0.00, stride: 0.86, bob: 0.028, spd: 0.96, accP: 0.10, acc: 3, - visP: 0.08, scarf: 1, hair: 0.00 }, - { name: 'hood', w: 0.12, ww: 0.030, hem: 0.26, hemTop: 0.58, hemBot: 0.92, legTop: 1.00, legW: 0.30, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 1, umb: 0, wide: 1.02, crest: 0.00, cane: 0, - tallB: 0.00, stride: 0.96, bob: 0.024, spd: 1.08, accP: 0.14, acc: 1, - visP: 0.22, scarf: 0, hair: 0.00 }, - { name: 'skirt', w: 0.10, ww: 0.120, hem: 0.34, hemTop: 0.50, hemBot: 0.76, legTop: 0.76, legW: 0.19, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 0.92, crest: 0.00, cane: 0, - tallB: 0.00, stride: 1.24, bob: 0.052, spd: 1.02, accP: 0.10, acc: 4, - visP: 0.08, scarf: 1, hair: 0.00 }, - { name: 'courier', w: 0.09, ww: 0.000, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, - brim: 0.00, pack: 0.55, bag: 0.00, hood: 0, umb: 0, wide: 1.00, crest: 0.00, cane: 0, - tallB: 0.00, stride: 1.14, bob: 0.030, spd: 1.30, accP: 0.34, acc: 2, - visP: 0.34, scarf: 0, hair: 0.00 }, - - { name: 'shell', w: 0.06, ww: 0.000, hem: 0.16, hemTop: 0.55, hemBot: 0.95, legTop: 1.00, legW: 0.30, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.00, crest: 0.00, cane: 0, - tallB: 0.14, stride: 0.98, bob: 0.032, spd: 1.04, accP: 0.78, acc: 1, - visP: 0.40, scarf: 0, hair: 0.00 }, - { name: 'hat', w: 0.07, ww: 0.230, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, - brim: 0.55, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 1.00, crest: 0.00, cane: 0, - tallB: 0.00, stride: 0.92, bob: 0.026, spd: 0.94, accP: 0.06, acc: 3, - visP: 0.04, scarf: 0, hair: 0.00 }, - { name: 'bagger', w: 0.11, ww: 0.080, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, - brim: 0.00, pack: 0.00, bag: 0.60, hood: 0, umb: 1, wide: 1.00, crest: 0.00, cane: 0, - tallB: 0.00, stride: 1.00, bob: 0.034, spd: 0.97, accP: 0.18, acc: 4, - visP: 0.08, scarf: 0, hair: 0.00 }, - - { name: 'suit', w: 0.08, ww: 0.030, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.26, - brim: 0.00, pack: 0.00, bag: 0.34, hood: 0, umb: 1, wide: 0.90, crest: 0.00, cane: 0, - tallB: 0.04, stride: 1.06, bob: 0.022, spd: 1.12, accP: 0.05, acc: 4, - visP: 0.06, scarf: 1, hair: 0.00 }, - - { name: 'heavy', w: 0.06, ww: 0.050, hem: 0.10, hemTop: 0.62, hemBot: 0.94, legTop: 1.00, legW: 0.34, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.46, crest: 0.00, cane: 0, - tallB: -0.06, stride: 0.78, bob: 0.030, spd: 0.82, accP: 0.12, acc: 3, - visP: 0.10, scarf: 0, hair: 0.00 }, - - { name: 'crest', w: 0.05, ww: 0.000, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.28, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.94, crest: 0.16, cane: 0, - tallB: 0.02, stride: 1.10, bob: 0.040, spd: 1.14, accP: 0.46, acc: 1, - visP: 0.44, scarf: 0, hair: 0.00 }, - - { name: 'elder', w: 0.05, ww: 0.080, hem: 0.30, hemTop: 0.48, hemBot: 0.90, legTop: 1.00, legW: 0.28, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 0.96, crest: 0.00, cane: 1, - tallB: -0.11, stride: 0.70, bob: 0.016, spd: 0.66, accP: 0.08, acc: 4, - visP: 0.02, scarf: 1, hair: 0.00 }, - - { name: 'cloak', w: 0.055, ww: 0.075, hem: 0.95, hemTop: 0.42, hemBot: 0.74, legTop: 1.00, legW: 0.30, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 1, umb: 0, wide: 0.94, crest: 0.00, cane: 0, - tallB: 0.00, stride: 0.82, bob: 0.022, spd: 0.90, accP: 0.16, acc: 1, - visP: 0.16, scarf: 0, hair: 0.00 }, - - { name: 'mane', w: 0.05, ww: 0.020, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.26, - brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 0.96, crest: 0.00, cane: 0, - tallB: 0.00, stride: 1.08, bob: 0.046, spd: 1.06, accP: 0.20, acc: 4, - visP: 0.12, scarf: 1, hair: 0.30 }, - - { name: 'rigger', w: 0.070, ww: 0.050, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 0.66, legW: 0.50, - brim: 0.00, pack: 0.30, bag: 0.00, hood: 0, umb: 0, wide: 1.12, crest: 0.00, cane: 0, - tallB: -0.02, stride: 0.84, bob: 0.026, spd: 0.88, accP: 0.75, acc: 5, - visP: 0.30, scarf: 0, hair: 0.00 } - ]; - - var ARM_EXT = 0.20; - var ARCH_TOT = 0, ARCH_TOT_W = 0; - (function () { - - for (var i = 0; i < ARCH.length; i++) { - var A = ARCH[i], e = A.hem; - if (A.brim > e) e = A.brim; - if (A.pack > e) e = A.pack; - if (A.bag > e) e = A.bag; - - if (ARM_EXT > e) e = ARM_EXT; - A.ext = e; - ARCH_TOT += A.w; A.acc0 = ARCH_TOT; - - ARCH_TOT_W += (A.ww === undefined ? A.w : A.ww); A.acc1 = ARCH_TOT_W; + p.wait -= dt; + if (p.wait <= 0) pedSpawn(p, i, S, 0, city); + continue; } - })(); + p.x += p.vx * dt * k; p.z += p.vz * dt * k; + p.walked += (p.vx === 0 ? (p.vz < 0 ? -p.vz : p.vz) : (p.vx < 0 ? -p.vx : p.vx)) * dt * k; - var PED_WEST = 0; - function archPick(h) { - var i; - if (PED_WEST) { - 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]; + p.hunch += (rain - p.hunch) * Math.min(1, dt * 0.55 * eK); + var uT = (p.umbOwn && rain > 0.22) ? 1 : 0; + p.umb += (uT - p.umb) * Math.min(1, dt * p.uRate * eK); + if (p.umb < 0.002) p.umb = 0; + + var pr = project(p.x + p.dx, p.z + p.dz); + + var dodgeT = 0; + if (cb > 0.02 && pr.ok && pr.w < 9) { + + var off = pr.sp * pr.w; + if (off < 1.3 && off > -1.3) { + var lat = COR.axis ? p.z - COR.ctr : p.x - COR.ctr; + dodgeT = (lat < 0 ? -1 : 1) * 0.55 * cb; + } } - var r = h * ARCH_TOT; - for (i = 0; i < ARCH.length - 1; i++) if (r < ARCH[i].acc0) return ARCH[i]; - return ARCH[ARCH.length - 1]; - } + p.dodge += (dodgeT - p.dodge) * Math.min(1, dt * 1.5); + p.dx = latX * p.dodge; p.dz = latZ * p.dodge; - var peds = null, PED_MAX = 70, PED_AT_REF = 26, REF_CELLS = 200 * 60; + var gone = !pr.ok || pr.w > 74 || pr.sp > HP * 1.8 || pr.sp < -HP * 1.8; - function pedWant(cells) { - var n = PED_AT_REF * Math.sqrt(cells / REF_CELLS); + if (!gone && pedCover(p, pr) > PED_COVER_MAX) gone = 1; - n *= 1 - 0.38 * wp().rain; - n = n | 0; - return n > PED_MAX ? PED_MAX : (n < 4 ? 4 : n); - } + if (!gone && p.cross) { + var l2 = (COR.axis ? p.z - COR.ctr : p.x - COR.ctr) * p.goSide; + if (l2 > COR.half + 0.6) gone = 1; + } + if (gone) { p.live = 0; p.wait = 0; } + } + }, + draw: function (frame, cam, t) { + camScreen(frame, cam); - function pedShoulder(w, A) { - var shw = 0.24 * (A ? A.wide : 1) * CPM / w; - return shw < 0.45 ? 0.45 : shw; - } - function pedCover(p, pr) { - var xw = pedShoulder(pr.w, p.A) * (1 + p.A.ext); + this.cols = frame.cols; this.rows = frame.rows; + this.cells = frame.cols * frame.rows; + var S = this.seed, i, x, q; + var wetR = wrel('wet'); + for (i = 0; i < PED_MAX; i++) { + var p = peds[i]; + if (!p.live) continue; + var pr = project(p.x + p.dx, p.z + p.dz); + + if (!pr.ok || pr.dist > 72) continue; + var w = pr.w, dist = pr.dist, d = near(dist), cx = pr.x, A = p.A; + + var st = CC.reducedMotion ? 0 : Math.sin(p.walked * 3.6 * A.stride + p.phase); + var bobA = CC.reducedMotion ? A.bob * 0.12 : A.bob; + var hunch = p.hunch; + var rFeet = rowOf(0, w); + var rHead = rowOf((p.tall + A.tallB) * (1 - hunch * 0.055) + st * bobA, w); + var tallRows = rFeet - rHead; + if (tallRows < 1.4) continue; + var shw = pedShoulder(w, A); + var xw = shw * (1 + A.ext); + var x0 = Math.round(cx - xw), x1 = Math.round(cx + xw); + if (x1 < 0 || x0 > COLS - 1) continue; + + if (pedCover(p, pr) > PED_COVER_MAX * 2) continue; - var x0 = pr.x - xw, x1 = pr.x + xw; if (x0 < 0) x0 = 0; if (x1 > COLS - 1) x1 = COLS - 1; - if (x1 <= x0) return 0; - var rr = (p.tall + p.A.tallB) * SCALE / pr.w; - if (rr > ROWS) rr = ROWS; - return (x1 - x0) * rr / (COLS * ROWS); + + var rim = fg(70 + hash2(i, p.n, S + 5) * 44, dist); + var sTop = 0.13 + hunch * 0.06; + + var headHW = 0.34 + A.hair; + var legHW = A.legW > 0.34 ? A.legW : 0.34; + + var face = (p.vx * RGX + p.vz * RGZ) < 0 ? -1 : 1; + + var legPl = A.legSpread ? 0.99 : 0.94, legTr = A.legSpread ? 0.78 : 0.86; + + var hemSlope = A.hem > 0 ? (A.hemBot - A.hemTop) * tallRows / (A.hem * shw) : 0; + for (x = x0; x <= x1; x++) { + var u = (x - cx) / shw, au = u < 0 ? -u : u; + var onAcc = (u < 0 ? -1 : 1) === p.side; + + var onFace = (u < 0 ? -1 : 1) === face; + + var v0 = 9, v1 = -9, diag = 0; + if (au <= 1.0) { + v0 = au > 0.62 ? 0.20 + hunch * 0.05 : (au > 0.34 ? sTop : 0); + + if (A.hood && au <= 0.34) v0 = au * 0.30; + + if (A.crest > 0 && au <= 0.30) v0 = -A.crest * (1 - au / 0.30); + v1 = au > 0.62 ? 0.66 : (au > A.legW ? A.legTop : 1); + + if (au < legHW && tallRows > 5) { + var lg = (u < 0 ? -1 : 1) * st; + if (lg > 0.30) v1 = legPl; + else if (lg < -0.30) v1 = legTr; + } + } + + if (tallRows > 7 && au > 1) { + var sw = (u < 0 ? -1 : 1) * st; + if (sw > 0.22 && au <= 1 + ARM_EXT * sw) { + if (0.24 < v0) v0 = 0.24; + if (0.30 + 0.22 * sw > v1) v1 = 0.30 + 0.22 * sw; + } + } + + if (A.hair > 0 && au > 0.34 && au <= headHW) { + q = 0.02 + 0.040 * (au - 0.34) / A.hair; + if (q < v0) v0 = q; + } + if (A.hem > 0 && au > 1 && au <= 1 + A.hem) { + + q = A.hemTop + (A.hemBot - A.hemTop) * (au - 1) / A.hem; + + if (q < v0) { v0 = q; diag = 1; } + if (A.hemBot > v1) v1 = A.hemBot; + } + if (A.brim > 0 && au <= 1 + A.brim) { + if (0.05 < v0) v0 = 0.05; + if (0.13 > v1) v1 = 0.13; + } + + if (A.pack > 0 && onAcc && au > 0.50 && au <= 1 + A.pack) { + if (0.15 < v0) v0 = 0.15; + if (0.54 > v1) v1 = 0.54; + } + if (A.bag > 0 && onAcc && au > 0.60 && au <= 1 + A.bag) { + + q = 0.40 - 0.05 * st; + if (q < v0) v0 = q; + if (q + 0.26 > v1) v1 = q + 0.26; + } + + if (A.roll > 0 && onAcc && au > 0.44 && au <= 1 + A.roll) { + q = -0.05 + 0.16 * (au - 0.44) / (0.56 + A.roll); + if (q < v0) v0 = q; + if (0.50 > v1) v1 = 0.50; + } + + if (A.tail > 0 && !onFace && au > 1 && au <= 1 + A.tail) { + q = A.tailTop + (A.tailBot - A.tailTop) * (au - 1) / A.tail; + if (q < v0) { v0 = q; diag = 1; } + if (A.tailBot > v1) v1 = A.tailBot; + } + + if (A.child > 0 && onAcc && au > 0.90 && au <= 1.78) { + if (au < 1.04) { + if (0.50 < v0) v0 = 0.50; + if (0.58 > v1) v1 = 0.58; + } else { + var cu = (au - 1.40) / 0.38; if (cu < 0) cu = -cu; + q = (1 - A.child) + (cu > 0.60 ? 0.07 : 0); + if (q < v0) v0 = q; + if (1 > v1) v1 = 1; + } + } + + if (A.seat > 0) { + if (v1 > A.seat && v1 < 9) v1 = A.seat; + if (au <= A.wheelW && tallRows > 4) { + q = A.seat - 0.02 + 0.34 * (au / A.wheelW) * (au / A.wheelW); + if (q < 0.98) { + if (q < v0) v0 = q; + if (1 > v1) v1 = 1; + } + } + } + + if (A.lean > 0 && tallRows > 6) { + var ld = u * face; + if (ld > 0 && au <= 1 + A.lean) { + var hu = (au - A.lean) / 0.42; if (hu < 0) hu = -hu; + if (hu < 1) { + q = 0.02 + 0.07 * hu; + if (q < v0) v0 = q; + if (0.34 > v1) v1 = 0.34; + } + } else if (ld < 0 && au <= 1 && v0 < 0.22) v0 = 0.22; + } + if (v1 < v0) continue; + var rt = rHead + v0 * tallRows, rb = rHead + v1 * tallRows; + bar(frame, x, rt, rb, 0, P.shadow, 0, d); + if (rim >= 5) { + + var rl = au < 0.34 ? (A.hood ? 0.60 : 1) : (au <= 1.0 ? 0.72 : 0.88); + + put(frame, x, Math.round(rt), + (diag && hemSlope > 1.3 && A.hem * shw >= 2) ? (u < 0 ? G_SLASH : G_BSLASH) + : au < headHW ? ((A.hood || (A.crest > 0 && au < 0.30)) ? G_CARET : G_o) : G_DASH, + p.rim, rim * rl, nearer(dist)); + } + } + if (rim < 5) continue; + + if (tallRows > 8) { + var rx = Math.round(cx + p.side * shw), qn = (tallRows * 0.42) | 0; + if (qn > 13) qn = 13; + + for (q = 1; q <= qn; q++) + put(frame, rx, Math.round(rHead + q), G_QUOTE, p.rim, + rim * (0.62 - 0.44 * q / qn), nearer(dist)); + } + + if (A.scarf && tallRows > 9) { + var wr = windRight(), wa = wr < 0 ? -wr : wr; + var wf = wa / 3.4; if (wf > 1) wf = 1; + var sdir = wr < 0 ? -1 : 1; + var sn = Math.round(shw * (0.55 + 1.30 * wf)); + if (sn > 5) sn = 5; + if (sn >= 1) { + + var sr0 = rHead + tallRows * (0.18 + 0.025 * st); + for (q = 1; q <= sn; q++) { + var sf = q / sn; + + put(frame, Math.round(cx + sdir * (shw * 0.85 + q)), + Math.round(sr0 - sf * tallRows * 0.15 * wf), + + G_DASH, p.rim, rim * (0.78 - 0.36 * sf), nearer(dist)); + } + } + } + + if (p.vis && tallRows > 3.2) { + var vl = fg(146 + hash2(i, p.n, S + 29) * 40, dist); + if (vl >= 5) { + var vy = Math.round(rHead + tallRows * 0.045); + var vx = Math.round(cx), hcol = shw * headHW; + var vd = dist * 0.970; + put(frame, vx, vy, hcol >= 1.3 ? G_EQ : G_DASH, p.visHue, vl, vd); + if (hcol >= 1.3) { + + put(frame, vx - 1, vy, G_DASH, p.visHue, vl * 0.55, vd); + put(frame, vx + 1, vy, G_DASH, p.visHue, vl * 0.55, vd); + } + } + } + + if (A.cane && tallRows > 9) { + var cnx = cx - p.side * shw * (0.95 + st * 0.30); + var cn0 = Math.round(rHead + tallRows * 0.52), cn1 = Math.round(rFeet); + for (q = cn0; q <= cn1; q++) { + + var cf = (q - cn0) / (cn1 - cn0 + 0.001); + put(frame, Math.round(cnx - p.side * shw * 0.42 * cf), q, + cf > 0.88 ? G_DOT : G_PIPE, p.rim, rim * (0.30 + 0.22 * cf), nearer(dist)); + } + } + + if (A.barW > 0 && tallRows > 5) { + var bdir = A.barBoth ? 0 : p.side; + var bn = Math.round(shw * A.barW); if (bn > 22) bn = 22; + var byr = Math.round(rHead + tallRows * A.barV); + var bq0 = A.barBoth ? -bn : (bdir > 0 ? 1 : -bn); + var bq1 = A.barBoth ? bn : (bdir > 0 ? bn : -1); + for (q = bq0; q <= bq1; q++) { + var bf = q < 0 ? -q : q; + + put(frame, Math.round(cx) + q, byr, G_DASH, p.rim, + rim * (0.80 - 0.30 * bf / (bn + 1)), nearer(dist)); + } + + if (A.wheel && tallRows > 7) { + var wrr = Math.round(shw * 0.55); if (wrr < 1) wrr = 1; if (wrr > 5) wrr = 5; + for (var wi = 0; wi < 2; wi++) { + var wcx = Math.round(cx + bdir * shw * A.barW * (wi ? 0.88 : 0.34)); + for (q = -wrr; q <= wrr; q++) { + var wf = q / wrr, waf = wf < 0 ? -wf : wf; + put(frame, wcx + q, + Math.round(rFeet - tallRows * 0.04 - (1 - wf * wf) * wrr * 0.9), + (waf > 0.7) ? G_TICK : G_DASH, p.rim, + rim * (0.56 - 0.20 * waf), nearer(dist)); + } + } + } + } + + if (A.pole > 0 && tallRows > 6) { + var pn = Math.round(shw * A.pole * 0.5); if (pn > 20) pn = 20; + if (pn >= 2) { + var pRow = rHead + tallRows * 0.20; + var pSlope = tallRows * 0.34 / pn; + var pGly = pSlope > 0.85 ? (p.side > 0 ? G_SLASH : G_BSLASH) : G_DASH; + for (q = -pn; q <= pn; q++) + put(frame, Math.round(cx) + q, Math.round(pRow - q * pSlope * p.side), + pGly, p.rim, rim * (0.70 - 0.16 * (q * p.side) / pn), nearer(dist)); + } + } + + if (p.acc && tallRows > 4) { + if (p.acc === 1) { + + var al = fg(52, dist); + if (al >= 5) { + var qn2 = (tallRows * 0.40) | 0; if (qn2 > 8) qn2 = 8; + var px2 = Math.round(cx - p.side * shw * 0.70); + for (q = 0; q <= qn2; q++) + put(frame, px2, Math.round(rHead + tallRows * 0.18) + q, G_PIPE, p.accHue, + al * (0.90 - 0.55 * q / (qn2 + 1)), nearer(dist)); + } + } else if (p.acc === 2) { + + var al2 = fg(165, dist); + if (al2 >= 5) { + var bx = Math.round(cx + p.side * shw * (1 + A.pack * 0.7)); + put(frame, bx, Math.round(rHead + tallRows * 0.30), G_DASH, P.ice, al2, nearer(dist)); + if (tallRows > 9) + put(frame, bx - p.side, Math.round(rHead + tallRows * 0.30), G_DOT, P.ice, + al2 * 0.45, nearer(dist)); + } + } else if (p.acc === 3) { + + var glow = CC.reducedMotion ? 0.72 + : 0.55 + 0.45 * vnoise(t * 0.7 + p.phase * 3, S + 47); + var al3 = fg(120 * glow, dist); + if (al3 >= 5) + put(frame, Math.round(cx + p.side * shw * 0.55), + Math.round(rHead + tallRows * 0.10), G_DOT, P.ember, al3, nearer(dist)); + } else if (p.acc === 5) { + + var al5 = fg(225, dist); + if (al5 >= 5) { + var lx5 = Math.round(cx + p.side * shw * 0.86); + var ly5 = Math.round(rHead + tallRows * 0.13); + + var ld5 = dist * 0.970; + put(frame, lx5, ly5, G_o, p.accHue, al5, ld5); + + if (tallRows > 9) + for (q = 1; q <= 3; q++) + put(frame, lx5 + p.side * q, ly5 + q, G_DASH, p.accHue, + fg(50 - q * 12, dist), ld5); + } + } else { + + var al4 = fg(128, dist); + if (al4 >= 5) { + var hx2 = Math.round(cx + p.side * shw * (0.85 + st * 0.22)); + var hy2 = Math.round(rHead + tallRows * (0.56 + st * 0.03)); + put(frame, hx2, hy2, G_STAR, p.accHue, al4, nearer(dist)); + if (tallRows > 11) + put(frame, hx2, hy2 + 1, G_DOT, p.accHue, al4 * 0.40, nearer(dist)); + } + } + } + + if (p.wear && tallRows > 8) { + var wl = fg(rim * 0.82, dist); + if (wl >= 5) { + var wd = dist * 0.974; + if (p.wear === 1) { + if (tallRows > 16) + put(frame, Math.round(cx + p.side * shw * headHW), + Math.round(rHead + tallRows * 0.075), G_DOT, P.gold, wl * 1.15, wd); + } else if (p.wear === 2) { + + var wy = Math.round(rHead + tallRows * 0.155); + put(frame, Math.round(cx - shw * 0.30), wy, G_DASH, P.moss, wl, wd); + put(frame, Math.round(cx + shw * 0.30), wy, G_DASH, P.moss, wl * 0.80, wd); + } else if (A.hood || tallRows > 13) { + + put(frame, Math.round(cx), Math.round(rHead + tallRows * 0.11), G_DASH, + P.indigo, wl * 1.10, wd); + } + } + } + + if (tallRows > 16 && rim >= 5) { + var nd2 = dist * 0.974; + + if (!A.hood) { + var fy = Math.round(rHead + tallRows * 0.055); + var fx = Math.round(cx + p.side * shw * 0.20); + put(frame, fx, fy, G_QUOTE, p.rim, rim * 0.46, nd2); + put(frame, fx, Math.round(rHead + tallRows * 0.115), G_DOT, p.rim, + rim * 0.30, nd2); + } + + var hsw = p.side * st; + if (hsw > 0.20) { + put(frame, Math.round(cx + p.side * shw * (1 + ARM_EXT * hsw + 0.10)), + Math.round(rHead + tallRows * (0.44 + 0.20 * hsw)), G_o, p.rim, + rim * 0.52, nd2); + } + + if (A.bag > 0) { + var sy0 = rHead + tallRows * 0.15, sy1 = rHead + tallRows * 0.42; + for (q = 0; q <= 3; q++) { + var sfk = q / 3; + put(frame, Math.round(cx + p.side * shw * (-0.55 + 1.30 * sfk)), + Math.round(sy0 + (sy1 - sy0) * sfk), + p.side > 0 ? G_BSLASH : G_SLASH, p.rim, rim * (0.40 - 0.10 * sfk), nd2); + } + } + + if (A.seat === 0) { + var bsd = st > 0 ? 1 : -1; + put(frame, Math.round(cx + bsd * shw * legHW * 0.7), Math.round(rFeet), + G_UNDER, p.rim, rim * 0.34, nd2); + } + } + + if (p.umb > 0.03 && tallRows > 3.5) { + var ru = shw * 2.0 * p.umb; + if (ru < 1) ru = 1; + var ruI = ru | 0; + var rApex = rHead - tallRows * (0.07 + 0.08 * p.umb); + + var uw = windRight() / 3.4; if (uw > 1) uw = 1; else if (uw < -1) uw = -1; + var uTilt = uw * ru * 0.30; + for (q = -ruI; q <= ruI; q++) { + var f2 = q / ru; + 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)); + } + + bar(frame, Math.round(cx), rApex + 1, rHead - 1, 0, P.shadow, 0, nearer(dist)); + } + + var rn = 1 + ((wetR * 3.4) | 0); if (rn > 5) rn = 5; + var dry = 1 - 0.55 * p.umb; + for (var rj = 1; rj <= rn; rj++) { + var rr = Math.round(rFeet) + rj, rd = roadDist(rr, pr.sp); + var rl2 = fg(rim * (0.52 - rj * 0.11) * (0.55 + 0.45 * wetR) * dry, rd); + if (rl2 < 5) break; + put(frame, Math.round(cx), rr, rj < 3 ? G_QUOTE : G_DOT, p.rim, rl2, near(rd)); + } + if (p.phone >= 0 && tallRows > 3.2) { + var pl = fg(150, dist); + if (pl >= 5) + put(frame, Math.round(cx - p.side * shw * 0.6), + Math.round(rHead + tallRows * 0.40), G_DOT, p.phone, pl, nearer(dist)); + } + } } + }); - var PED_COVER_MAX = 0.035; + var cat = null; - var FF_HUE = 0; - function footfall(city, a, l) { - FF_HUE = P.amber; - if (!city || !city.cell) return 1; + CC.ELEMENTS.push({ + name: 'cat', + layer: 21, - var ll = l + (l < 0 ? -2.2 : 2.2); - var c = city.cell(worldX(a, ll), worldZ(a, ll)); - if (!c) return 0.62; - FF_HUE = c.hue; - return 0.34 + c.litRate * 2.4 + (c.sign ? 0.55 : 0); + world: ['cyber', 'west'], + init: function (city, rng) { + this.city = city; + this.seed = (rng() * 2147483647) | 0; + cat = { x: 0, z: 0, vx: 0, vz: 0, live: 0, wait: 5, n: 0, len: 0.5, side: 1 }; + }, + update: function (dt, t, cam) { + camBasis(cam); + corridor(this.city, cam); + var S = this.seed, k = CC.reducedMotion ? 0.10 : 1, rain = wp().rain; + if (cat.live) { + cat.x += cat.vx * dt * k; cat.z += cat.vz * dt * k; + var pr = project(cat.x, cat.z); + var l = COR.axis ? cat.z - COR.ctr : cat.x - COR.ctr; + if (l < 0) l = -l; + if (!pr.ok || pr.w > 48 || l > COR.half + 0.9) { + cat.live = 0; + + cat.wait = (19 + hash2(0, cat.n, S ^ 0x11) * 26) * (1 + 1.5 * rain); + } + return; + } + + cat.wait -= dt * k; + if (cat.wait > 0) return; + cat.n++; + var h1 = hash2(1, cat.n, S), h2 = hash2(2, cat.n, S), h3 = hash2(3, cat.n, S); + cat.side = h2 < 0.5 ? -1 : 1; + + var a = COR.along + COR.dir * (34 + h1 * 8); + var l0 = -cat.side * (COR.half + 0.9); + cat.x = worldX(a, l0); cat.z = worldZ(a, l0); + + var sp = (1.05 + h3 * 0.75) * (1 + 0.55 * rain); + cat.vx = COR.axis ? 0 : cat.side * sp; + cat.vz = COR.axis ? cat.side * sp : 0; + cat.len = 0.44 + h3 * 0.16; + cat.live = 1; + }, + draw: function (frame, cam, t) { + if (!cat || !cat.live) return; + camScreen(frame, cam); + var pr = project(cat.x, cat.z); + + if (!pr.ok || pr.dist > 46) return; + var w = pr.w, dist = pr.dist, d = near(dist), cx = pr.x; + var hw = cat.len * 0.5 * CPM / w; + if (hw < 0.5) hw = 0.5; + var rGnd = rowOf(0, w), rBack = rowOf(0.26, w); + var x, x0 = Math.round(cx - hw), x1 = Math.round(cx + hw); + for (x = x0; x <= x1; x++) bar(frame, x, rBack, rGnd, 0, P.shadow, 0, d); + + put(frame, Math.round(cx - cat.side * (hw + 1)), Math.round(rBack - 0.6), 0, P.shadow, 0, d); + + var el = fg(198, dist); + if (el < 6) return; + var ex = Math.round(cx + cat.side * hw); + put(frame, ex, Math.round(rBack), G_DOT, P.spring, el, nearer(dist)); + if (hw > 2.4) + put(frame, ex - cat.side, Math.round(rBack), G_DOT, P.spring, el * 0.7, nearer(dist)); } + }); - function pedSpawn(p, i, S, fresh, city) { - p.n++; - var n = p.n; + var cars = null, CAR_N = 2; - var h1 = hash2(i, n, S + 101), h2 = hash2(i, n, S + 211), h3 = hash2(i, n, S + 307), - h4 = hash2(i, n, S + 401), h5 = hash2(i, n, S + 503), h6 = hash2(i, n, S + 601), - h7 = hash2(i, n, S + 701), h8 = hash2(i, n, S + 809), h9 = hash2(i, n, S + 907), - h10 = hash2(i, n, S + 1013), h11 = hash2(i, n, S + 1117), h12 = hash2(i, n, S + 1223), - h13 = hash2(i, n, S + 1301), h14 = hash2(i, n, S + 1409), - h15 = hash2(i, n, S + 1511), h16 = hash2(i, n, S + 1607), - h17 = hash2(i, n, S + 1709); - var rain = wp().rain; - var kl = kerbL(), band = COR.half - kl - 0.6; - if (band < 0.2) band = 0.2; - var side = h2 < 0.5 ? -1 : 1; - var A = archPick(h4); - var a, l, ki; - - var l0 = side * (kl + 0.2 + h3 * band); - var bestA = COR.along + COR.dir * 58, bestF = -1, bestH = P.amber; - for (ki = 0; ki < 3; ki++) { - var hk = hash2(i, n * 4 + ki, S + 1361); - - var ak = COR.along + COR.dir * (fresh ? 5 + hk * 42 : 52 + hk * 16); - var ff = footfall(city, ak, l0); - if (ff > bestF) { bestF = ff; bestA = ak; bestH = FF_HUE; } - } - - if (!fresh && bestF < 0.55 + h6 * 0.80) { - p.live = 0; p.wait = 0.5 + h6 * 2.4; - return; - } - - var sp = (0.95 + h1 * 0.55) * A.spd; - - sp *= 1 - 0.16 * rain; - p.shelter = 0; - - var shP = 0.05 + 0.22 * rain; - if (h7 < 0.28) { - - p.cross = 1; p.goSide = side; - a = COR.along + COR.dir * (fresh ? 7 + h1 * 22 : 15 + h1 * 17); - l = -side * (COR.half + 1.2); - p.vx = COR.axis ? 0 : side * sp; - p.vz = COR.axis ? side * sp : 0; - } else if (h7 < 0.28 + shP) { - - p.cross = 0; p.shelter = 1; - p.vx = 0; p.vz = 0; - a = bestA; l = side * (COR.half - 0.5); - - var sst = h13 < 0.5 && stalls ? stalls[(h13 * 2 * STALL_N) | 0] : null; - if (sst && sst.live) { - - var sa = COR.axis ? sst.x : sst.z; - var sl = (COR.axis ? sst.z : sst.x) - COR.ctr; - a = sa + (h1 - 0.5) * 3.6; - - l = sl + (sl < 0 ? 1 : -1) * (sst.w * 0.5 + 0.62); - side = sl < 0 ? -1 : 1; - } - } else { - - p.cross = 0; - a = bestA; l = l0; - var go = (h5 < 0.62 ? -1 : 1) * COR.dir; - p.vx = COR.axis ? go * sp : 0; - p.vz = COR.axis ? 0 : go * sp; - - var q = i > 0 ? peds[i - 1] : null; - if (q && q.live && !q.cross && !q.shelter && h13 < 0.26) { - var qa = COR.axis ? q.x : q.z, ql = (COR.axis ? q.z : q.x) - COR.ctr; - - var gl = ql + (ql < 0 ? 1 : -1) * (0.62 + h15 * 0.34); - if (gl > kl + 0.15) gl = kl + 0.15; - if (gl < -kl - 0.15) gl = -kl - 0.15; - a = qa + (h16 - 0.5) * 1.1; - l = gl; - side = gl < 0 ? -1 : 1; - p.vx = q.vx; p.vz = q.vz; - } - } - p.x = worldX(a, l); p.z = worldZ(a, l); - p.dodge = 0; p.dx = 0; p.dz = 0; - p.A = A; - p.tall = 1.62 + h11 * 0.22; - p.walked = 0; - p.phase = h3 * 6.283; - - p.side = p.shelter ? (l < 0 ? -1 : 1) : (h14 < 0.5 ? -1 : 1); - - var scr = bestH === P.azure; - - p.rim = PED_WEST ? ((h10 < 0.80) ? P.amber : P.warm) - : ((h10 < 0.80 ? scr : !scr) ? P.azure : P.amber); - - p.umbOwn = A.umb && h9 < 0.62 ? 1 : 0; - p.uRate = 0.20 + h1 * 0.26; - - if (h12 < 0.18 && !PED_WEST) { - var q = h12 / 0.18; - p.phone = q < 0.70 ? P.azure : (q < 0.88 ? P.ice : P.violet); - } else p.phone = -1; - - if (h8 < A.accP) { - var qa = h8 / A.accP; - - p.acc = PED_WEST ? ((A.acc === 1 || A.acc === 2 || A.acc === 5) ? 3 : A.acc) : A.acc; - - p.accHue = PED_WEST ? (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 - : A.acc === 5 ? P.amber - : (qa < 0.60 ? P.warm : P.amber); - } else { p.acc = 0; p.accHue = P.amber; } - - if (h17 < A.visP && !PED_WEST) { - 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 - : (qv < 0.93 ? P.violet : P.red))); - } else { p.vis = 0; p.visHue = P.azure; } - p.live = 1; + function crossAhead(city, pick) { + if (!city || !city.aveX) return NaN; + var period = COR.axis ? city.AVE : city.CROSS; + var i0 = Math.round(COR.along / period), i, c, dd, cnt = 0, want; + for (i = i0 - 4; i <= i0 + 4; i++) { + c = (COR.axis ? city.aveX(i) : city.crossZ(i)) + 0.5; + dd = (c - COR.along) * COR.dir; + if (dd >= 14 && dd <= 58) cnt++; } - - CC.ELEMENTS.push({ - name: 'pedestrians', - layer: 20, - - world: ['cyber', 'west'], - init: function (city, rng, dims) { - this.city = city; - - PED_WEST = (city && city.world === 'west') ? 1 : 0; - - this.seed = (rng() * 30011) | 0; - this.boot = 0; - this.cols = dims && dims.cols ? dims.cols : 200; - this.rows = dims && dims.rows ? dims.rows : 60; - this.cells = this.cols * this.rows; - peds = new Array(PED_MAX); - for (var i = 0; i < PED_MAX; i++) - 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, A: ARCH[0] }; - }, - update: function (dt, t, cam) { - - camScreenAt(cam, this.cols, this.rows); - corridor(this.city, cam); - var S = this.seed, city = this.city, i, p; - - if (!this.boot) { - this.boot = 1; - for (i = 0; i < PED_MAX; i++) pedSpawn(peds[i], i, S, 1, city); - } - var k = CC.reducedMotion ? 0.10 : 1; - var eK = CC.reducedMotion ? 0.35 : 1; - var want = pedWant(this.cells); - var rain = wp().rain, cb = ctrlBlend(); - var latX = COR.axis ? 0 : 1, latZ = COR.axis ? 1 : 0; - for (i = 0; i < PED_MAX; i++) { - p = peds[i]; - if (i >= want) { - - if (p.live) { p.live = 0; p.wait = 0.4 + (i % 7) * 0.35; } - continue; - } - if (!p.live) { - - p.wait -= dt; - if (p.wait <= 0) pedSpawn(p, i, S, 0, city); - continue; - } - p.x += p.vx * dt * k; p.z += p.vz * dt * k; - p.walked += (p.vx === 0 ? (p.vz < 0 ? -p.vz : p.vz) : (p.vx < 0 ? -p.vx : p.vx)) * dt * k; - - p.hunch += (rain - p.hunch) * Math.min(1, dt * 0.55 * eK); - var uT = (p.umbOwn && rain > 0.22) ? 1 : 0; - p.umb += (uT - p.umb) * Math.min(1, dt * p.uRate * eK); - if (p.umb < 0.002) p.umb = 0; - - var pr = project(p.x + p.dx, p.z + p.dz); - - var dodgeT = 0; - if (cb > 0.02 && pr.ok && pr.w < 9) { - - var off = pr.sp * pr.w; - if (off < 1.3 && off > -1.3) { - var lat = COR.axis ? p.z - COR.ctr : p.x - COR.ctr; - dodgeT = (lat < 0 ? -1 : 1) * 0.55 * cb; - } - } - p.dodge += (dodgeT - p.dodge) * Math.min(1, dt * 1.5); - p.dx = latX * p.dodge; p.dz = latZ * p.dodge; - - var gone = !pr.ok || pr.w > 74 || pr.sp > HP * 1.8 || pr.sp < -HP * 1.8; - - if (!gone && pedCover(p, pr) > PED_COVER_MAX) gone = 1; - - if (!gone && p.cross) { - var l2 = (COR.axis ? p.z - COR.ctr : p.x - COR.ctr) * p.goSide; - if (l2 > COR.half + 0.6) gone = 1; - } - if (gone) { p.live = 0; p.wait = 0; } - } - }, - draw: function (frame, cam, t) { - camScreen(frame, cam); - - this.cols = frame.cols; this.rows = frame.rows; - this.cells = frame.cols * frame.rows; - var S = this.seed, i, x, q; - var wetR = wrel('wet'); - for (i = 0; i < PED_MAX; i++) { - var p = peds[i]; - if (!p.live) continue; - var pr = project(p.x + p.dx, p.z + p.dz); - - if (!pr.ok || pr.dist > 72) continue; - var w = pr.w, dist = pr.dist, d = near(dist), cx = pr.x, A = p.A; - - var st = CC.reducedMotion ? 0 : Math.sin(p.walked * 3.6 * A.stride + p.phase); - var bobA = CC.reducedMotion ? A.bob * 0.12 : A.bob; - var hunch = p.hunch; - var rFeet = rowOf(0, w); - var rHead = rowOf((p.tall + A.tallB) * (1 - hunch * 0.055) + st * bobA, w); - var tallRows = rFeet - rHead; - if (tallRows < 1.4) continue; - var shw = pedShoulder(w, A); - var xw = shw * (1 + A.ext); - var x0 = Math.round(cx - xw), x1 = Math.round(cx + xw); - if (x1 < 0 || x0 > COLS - 1) continue; - - if (pedCover(p, pr) > PED_COVER_MAX * 2) continue; - - if (x0 < 0) x0 = 0; - if (x1 > COLS - 1) x1 = COLS - 1; - - var rim = fg(70 + hash2(i, p.n, S + 5) * 44, dist); - var sTop = 0.13 + hunch * 0.06; - - var headHW = 0.34 + A.hair; - var legHW = A.legW > 0.34 ? A.legW : 0.34; - - var hemSlope = A.hem > 0 ? (A.hemBot - A.hemTop) * tallRows / (A.hem * shw) : 0; - for (x = x0; x <= x1; x++) { - var u = (x - cx) / shw, au = u < 0 ? -u : u; - var onAcc = (u < 0 ? -1 : 1) === p.side; - - var v0 = 9, v1 = -9, diag = 0; - if (au <= 1.0) { - v0 = au > 0.62 ? 0.20 + hunch * 0.05 : (au > 0.34 ? sTop : 0); - - if (A.hood && au <= 0.34) v0 = au * 0.30; - - if (A.crest > 0 && au <= 0.30) v0 = -A.crest * (1 - au / 0.30); - v1 = au > 0.62 ? 0.66 : (au > A.legW ? A.legTop : 1); - - if (au < legHW && tallRows > 5) { - var lg = (u < 0 ? -1 : 1) * st; - if (lg > 0.30) v1 = 0.94; - else if (lg < -0.30) v1 = 0.86; - } - } - - if (tallRows > 7 && au > 1) { - var sw = (u < 0 ? -1 : 1) * st; - if (sw > 0.22 && au <= 1 + ARM_EXT * sw) { - if (0.24 < v0) v0 = 0.24; - if (0.30 + 0.22 * sw > v1) v1 = 0.30 + 0.22 * sw; - } - } - - if (A.hair > 0 && au > 0.34 && au <= headHW) { - q = 0.02 + 0.040 * (au - 0.34) / A.hair; - if (q < v0) v0 = q; - } - if (A.hem > 0 && au > 1 && au <= 1 + A.hem) { - - q = A.hemTop + (A.hemBot - A.hemTop) * (au - 1) / A.hem; - - if (q < v0) { v0 = q; diag = 1; } - if (A.hemBot > v1) v1 = A.hemBot; - } - if (A.brim > 0 && au <= 1 + A.brim) { - if (0.05 < v0) v0 = 0.05; - if (0.13 > v1) v1 = 0.13; - } - - if (A.pack > 0 && onAcc && au > 0.50 && au <= 1 + A.pack) { - if (0.15 < v0) v0 = 0.15; - if (0.54 > v1) v1 = 0.54; - } - if (A.bag > 0 && onAcc && au > 0.60 && au <= 1 + A.bag) { - if (0.40 < v0) v0 = 0.40; - if (0.66 > v1) v1 = 0.66; - } - if (v1 < v0) continue; - var rt = rHead + v0 * tallRows, rb = rHead + v1 * tallRows; - bar(frame, x, rt, rb, 0, P.shadow, 0, d); - if (rim >= 5) { - - var rl = au < 0.34 ? (A.hood ? 0.60 : 1) : (au <= 1.0 ? 0.72 : 0.88); - - put(frame, x, Math.round(rt), - (diag && hemSlope > 1.3 && A.hem * shw >= 2) ? (u < 0 ? G_SLASH : G_BSLASH) - : au < headHW ? ((A.hood || (A.crest > 0 && au < 0.30)) ? G_CARET : G_o) : G_DASH, - p.rim, rim * rl, nearer(dist)); - } - } - if (rim < 5) continue; - - if (tallRows > 8) { - var rx = Math.round(cx + p.side * shw), qn = (tallRows * 0.42) | 0; - if (qn > 13) qn = 13; - - for (q = 1; q <= qn; q++) - put(frame, rx, Math.round(rHead + q), G_QUOTE, p.rim, - rim * (0.62 - 0.44 * q / qn), nearer(dist)); - } - - if (A.scarf && tallRows > 9) { - var wr = windRight(), wa = wr < 0 ? -wr : wr; - var wf = wa / 3.4; if (wf > 1) wf = 1; - var sdir = wr < 0 ? -1 : 1; - var sn = Math.round(shw * (0.55 + 1.30 * wf)); - if (sn > 5) sn = 5; - if (sn >= 1) { - - var sr0 = rHead + tallRows * (0.18 + 0.025 * st); - for (q = 1; q <= sn; q++) { - var sf = q / sn; - - put(frame, Math.round(cx + sdir * (shw * 0.85 + q)), - Math.round(sr0 - sf * tallRows * 0.15 * wf), - - G_DASH, p.rim, rim * (0.78 - 0.36 * sf), nearer(dist)); - } - } - } - - if (p.vis && tallRows > 3.2) { - var vl = fg(146 + hash2(i, p.n, S + 29) * 40, dist); - if (vl >= 5) { - var vy = Math.round(rHead + tallRows * 0.045); - var vx = Math.round(cx), hcol = shw * headHW; - var vd = dist * 0.970; - put(frame, vx, vy, hcol >= 1.3 ? G_EQ : G_DASH, p.visHue, vl, vd); - if (hcol >= 1.3) { - - put(frame, vx - 1, vy, G_DASH, p.visHue, vl * 0.55, vd); - put(frame, vx + 1, vy, G_DASH, p.visHue, vl * 0.55, vd); - } - } - } - - if (A.cane && tallRows > 9) { - var cnx = cx - p.side * shw * (0.95 + st * 0.30); - var cn0 = Math.round(rHead + tallRows * 0.52), cn1 = Math.round(rFeet); - for (q = cn0; q <= cn1; q++) { - - var cf = (q - cn0) / (cn1 - cn0 + 0.001); - put(frame, Math.round(cnx - p.side * shw * 0.42 * cf), q, - cf > 0.88 ? G_DOT : G_PIPE, p.rim, rim * (0.30 + 0.22 * cf), nearer(dist)); - } - } - - if (p.acc && tallRows > 4) { - if (p.acc === 1) { - - var al = fg(52, dist); - if (al >= 5) { - var qn2 = (tallRows * 0.40) | 0; if (qn2 > 8) qn2 = 8; - var px2 = Math.round(cx - p.side * shw * 0.70); - for (q = 0; q <= qn2; q++) - put(frame, px2, Math.round(rHead + tallRows * 0.18) + q, G_PIPE, p.accHue, - al * (0.90 - 0.55 * q / (qn2 + 1)), nearer(dist)); - } - } else if (p.acc === 2) { - - var al2 = fg(165, dist); - if (al2 >= 5) { - var bx = Math.round(cx + p.side * shw * (1 + A.pack * 0.7)); - put(frame, bx, Math.round(rHead + tallRows * 0.30), G_DASH, P.ice, al2, nearer(dist)); - if (tallRows > 9) - put(frame, bx - p.side, Math.round(rHead + tallRows * 0.30), G_DOT, P.ice, - al2 * 0.45, nearer(dist)); - } - } else if (p.acc === 3) { - - var glow = CC.reducedMotion ? 0.72 - : 0.55 + 0.45 * vnoise(t * 0.7 + p.phase * 3, S + 47); - var al3 = fg(120 * glow, dist); - if (al3 >= 5) - put(frame, Math.round(cx + p.side * shw * 0.55), - Math.round(rHead + tallRows * 0.10), G_DOT, P.ember, al3, nearer(dist)); - } else if (p.acc === 5) { - - var al5 = fg(225, dist); - if (al5 >= 5) { - var lx5 = Math.round(cx + p.side * shw * 0.86); - var ly5 = Math.round(rHead + tallRows * 0.13); - - var ld5 = dist * 0.970; - put(frame, lx5, ly5, G_o, p.accHue, al5, ld5); - - if (tallRows > 9) - for (q = 1; q <= 3; q++) - put(frame, lx5 + p.side * q, ly5 + q, G_DASH, p.accHue, - fg(50 - q * 12, dist), ld5); - } - } else { - - var al4 = fg(128, dist); - if (al4 >= 5) { - var hx2 = Math.round(cx + p.side * shw * (0.85 + st * 0.22)); - var hy2 = Math.round(rHead + tallRows * (0.56 + st * 0.03)); - put(frame, hx2, hy2, G_STAR, p.accHue, al4, nearer(dist)); - if (tallRows > 11) - put(frame, hx2, hy2 + 1, G_DOT, p.accHue, al4 * 0.40, nearer(dist)); - } - } - } - - if (p.umb > 0.03 && tallRows > 3.5) { - var ru = shw * 2.0 * p.umb; - if (ru < 1) ru = 1; - var ruI = ru | 0; - var rApex = rHead - tallRows * (0.07 + 0.08 * p.umb); - for (q = -ruI; q <= ruI; q++) { - var f2 = q / ru; - 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 === -ruI || q === ruI) ? G_TICK : G_DASH, p.rim, ul, nearer(dist)); - } - - bar(frame, Math.round(cx), rApex + 1, rHead - 1, 0, P.shadow, 0, nearer(dist)); - } - - var rn = 1 + ((wetR * 3.4) | 0); if (rn > 5) rn = 5; - var dry = 1 - 0.55 * p.umb; - for (var rj = 1; rj <= rn; rj++) { - var rr = Math.round(rFeet) + rj, rd = roadDist(rr, pr.sp); - var rl2 = fg(rim * (0.52 - rj * 0.11) * (0.55 + 0.45 * wetR) * dry, rd); - if (rl2 < 5) break; - put(frame, Math.round(cx), rr, rj < 3 ? G_QUOTE : G_DOT, p.rim, rl2, near(rd)); - } - if (p.phone >= 0 && tallRows > 3.2) { - var pl = fg(150, dist); - if (pl >= 5) - put(frame, Math.round(cx - p.side * shw * 0.6), - Math.round(rHead + tallRows * 0.40), G_DOT, p.phone, pl, nearer(dist)); - } - } - } - }); - - var cat = null; - - CC.ELEMENTS.push({ - name: 'cat', - layer: 21, - - world: ['cyber', 'west'], - init: function (city, rng) { - this.city = city; - this.seed = (rng() * 2147483647) | 0; - cat = { x: 0, z: 0, vx: 0, vz: 0, live: 0, wait: 5, n: 0, len: 0.5, side: 1 }; - }, - update: function (dt, t, cam) { - camBasis(cam); - corridor(this.city, cam); - var S = this.seed, k = CC.reducedMotion ? 0.10 : 1, rain = wp().rain; - if (cat.live) { - cat.x += cat.vx * dt * k; cat.z += cat.vz * dt * k; - var pr = project(cat.x, cat.z); - var l = COR.axis ? cat.z - COR.ctr : cat.x - COR.ctr; - if (l < 0) l = -l; - if (!pr.ok || pr.w > 48 || l > COR.half + 0.9) { - cat.live = 0; - - cat.wait = (19 + hash2(0, cat.n, S ^ 0x11) * 26) * (1 + 1.5 * rain); - } - return; - } - - cat.wait -= dt * k; - if (cat.wait > 0) return; - cat.n++; - var h1 = hash2(1, cat.n, S), h2 = hash2(2, cat.n, S), h3 = hash2(3, cat.n, S); - cat.side = h2 < 0.5 ? -1 : 1; - - var a = COR.along + COR.dir * (34 + h1 * 8); - var l0 = -cat.side * (COR.half + 0.9); - cat.x = worldX(a, l0); cat.z = worldZ(a, l0); - - var sp = (1.05 + h3 * 0.75) * (1 + 0.55 * rain); - cat.vx = COR.axis ? 0 : cat.side * sp; - cat.vz = COR.axis ? cat.side * sp : 0; - cat.len = 0.44 + h3 * 0.16; - cat.live = 1; - }, - draw: function (frame, cam, t) { - if (!cat || !cat.live) return; - camScreen(frame, cam); - var pr = project(cat.x, cat.z); - - if (!pr.ok || pr.dist > 46) return; - var w = pr.w, dist = pr.dist, d = near(dist), cx = pr.x; - var hw = cat.len * 0.5 * CPM / w; - if (hw < 0.5) hw = 0.5; - var rGnd = rowOf(0, w), rBack = rowOf(0.26, w); - var x, x0 = Math.round(cx - hw), x1 = Math.round(cx + hw); - for (x = x0; x <= x1; x++) bar(frame, x, rBack, rGnd, 0, P.shadow, 0, d); - - put(frame, Math.round(cx - cat.side * (hw + 1)), Math.round(rBack - 0.6), 0, P.shadow, 0, d); - - var el = fg(198, dist); - if (el < 6) return; - var ex = Math.round(cx + cat.side * hw); - put(frame, ex, Math.round(rBack), G_DOT, P.spring, el, nearer(dist)); - if (hw > 2.4) - put(frame, ex - cat.side, Math.round(rBack), G_DOT, P.spring, el * 0.7, nearer(dist)); - } - }); - - var cars = null, CAR_N = 2; - - function crossAhead(city, pick) { - if (!city || !city.aveX) return NaN; - var period = COR.axis ? city.AVE : city.CROSS; - var i0 = Math.round(COR.along / period), i, c, dd, cnt = 0, want; - for (i = i0 - 4; i <= i0 + 4; i++) { - c = (COR.axis ? city.aveX(i) : city.crossZ(i)) + 0.5; - dd = (c - COR.along) * COR.dir; - if (dd >= 14 && dd <= 58) cnt++; - } - if (!cnt) return NaN; - want = (pick * cnt) | 0; if (want >= cnt) want = cnt - 1; - for (i = i0 - 4; i <= i0 + 4; i++) { - c = (COR.axis ? city.aveX(i) : city.crossZ(i)) + 0.5; - dd = (c - COR.along) * COR.dir; - if (dd >= 14 && dd <= 58) { if (want === 0) return c; want--; } - } - return NaN; - } - function crossHalf(city, c) { - if (!city || !city.aveX) return 2.0; - var period = COR.axis ? city.AVE : city.CROSS; - var i = Math.round((c - 0.5) / period); - return (COR.axis ? city.aveW(i) : city.crossW(i)) + 0.5; + if (!cnt) return NaN; + want = (pick * cnt) | 0; if (want >= cnt) want = cnt - 1; + for (i = i0 - 4; i <= i0 + 4; i++) { + c = (COR.axis ? city.aveX(i) : city.crossZ(i)) + 0.5; + dd = (c - COR.along) * COR.dir; + if (dd >= 14 && dd <= 58) { if (want === 0) return c; want--; } } + return NaN; + } + function crossHalf(city, c) { + if (!city || !city.aveX) return 2.0; + var period = COR.axis ? city.AVE : city.CROSS; + var i = Math.round((c - 0.5) / period); + return (COR.axis ? city.aveW(i) : city.crossW(i)) + 0.5; + } - CC.ELEMENTS.push({ - name: 'traffic', + CC.ELEMENTS.push({ + name: 'traffic', - world: 'cyber', - layer: 22, - init: function (city, rng) { - this.city = city; - this.seed = (rng() * 2147483647) | 0; - cars = new Array(CAR_N); - for (var i = 0; i < CAR_N; i++) - cars[i] = { x: 0, z: 0, vx: 0, vz: 0, live: 0, wait: 1.5 + i * 6, n: i * 53, - len: 4.2, tall: 1.4, go: 1, tail: P.red }; - }, - update: function (dt, t, cam) { - var city = this.city; - camBasis(cam); - corridor(city, cam); - var S = this.seed, k = CC.reducedMotion ? 0.08 : 1, i; - for (i = 0; i < CAR_N; i++) { - var c = cars[i]; - if (c.live) { - c.x += c.vx * dt * k; c.z += c.vz * dt * k; - var pr = project(c.x, c.z); - var l = COR.axis ? c.z - COR.ctr : c.x - COR.ctr; + world: 'cyber', + layer: 22, + init: function (city, rng) { + this.city = city; + this.seed = (rng() * 2147483647) | 0; + cars = new Array(CAR_N); + for (var i = 0; i < CAR_N; i++) + cars[i] = { x: 0, z: 0, vx: 0, vz: 0, live: 0, wait: 1.5 + i * 6, n: i * 53, + len: 4.2, tall: 1.4, go: 1, tail: P.red }; + }, + update: function (dt, t, cam) { + var city = this.city; + camBasis(cam); + corridor(city, cam); + var S = this.seed, k = CC.reducedMotion ? 0.08 : 1, i; + for (i = 0; i < CAR_N; i++) { + var c = cars[i]; + if (c.live) { + c.x += c.vx * dt * k; c.z += c.vz * dt * k; + var pr = project(c.x, c.z); + var l = COR.axis ? c.z - COR.ctr : c.x - COR.ctr; - if (!pr.ok || pr.w > 70 || l * c.go > COR.half + 11) { - c.live = 0; - c.wait = 3.5 + hash2(i, c.n, S ^ 0x4D) * 11; - } - continue; - } - - c.wait -= dt * k; - if (c.wait > 0) continue; - c.n++; - var h1 = hash2(i, c.n, S), h2 = hash2(i, c.n, S ^ 0x21), h3 = hash2(i, c.n, S ^ 0x8F); - var ca = crossAhead(city, h1); - if (ca !== ca) { c.wait = 2.5; continue; } - - var ch = crossHalf(city, ca) - CC.PAVE; - if (ch < 1.7) ch = 1.7; - c.go = h2 < 0.5 ? -1 : 1; - - var a = ca + (ch > 1.6 ? 0.55 + h3 * (ch - 1.2) : 0) * -c.go; - var l0 = -c.go * (COR.half + 10); - c.x = worldX(a, l0); c.z = worldZ(a, l0); - var sp = 8 + h3 * 7; - c.vx = COR.axis ? 0 : c.go * sp; - c.vz = COR.axis ? c.go * sp : 0; - c.len = 3.6 + h1 * 1.7; - c.tall = 1.25 + h2 * 0.35; - c.tail = h3 < 0.82 ? P.red : P.ember; - c.live = 1; - } - }, - draw: function (frame, cam, t) { - camScreen(frame, cam); - var i, j; - - var wetR = wrel('wet'); - for (i = 0; i < CAR_N; i++) { - var c = cars[i]; - if (!c.live) continue; - - var half = c.len * 0.5; - var nx = c.x + (c.vx > 0 ? half : (c.vx < 0 ? -half : 0)); - var nz = c.z + (c.vz > 0 ? half : (c.vz < 0 ? -half : 0)); - var tx = c.x * 2 - nx, tz = c.z * 2 - nz; - - var pn = project(nx, nz); if (!pn.ok) continue; - var xn = pn.x, wn = pn.w, dn = pn.dist; - var pt = project(tx, tz); if (!pt.ok) continue; - var xt = pt.x, wt = pt.w, dtl = pt.dist, spt = pt.sp; - if (dn > 72 && dtl > 72) continue; - - var span = xn - xt; if (span < 0) span = -span; - var ns = (span + 2) | 0; if (ns < 4) ns = 4; if (ns > 72) ns = 72; - for (j = 0; j <= ns; j++) { - var s = j / ns; - var ps = project(tx + (nx - tx) * s, tz + (nz - tz) * s); - if (!ps.ok) continue; - var sd = near(ps.dist); - var rB = rowOf(0.06, ps.w), rT = rowOf(c.tall, ps.w); - - var cab = s > 0.28 && s < 0.74; - if (cab) rT = rowOf(c.tall + 0.34, ps.w); - bar(frame, Math.round(ps.x), rT, rB, 0, P.shadow, 0, sd); - - var rfl = fg(cab ? 58 : 42, ps.dist); - if (rfl >= 5) - put(frame, Math.round(ps.x), Math.round(rT), G_DASH, P.amber, rfl, nearer(ps.dist)); - - var sll = fg(30 * (0.45 + 0.55 * wetR), ps.dist); - if (sll >= 5) - put(frame, Math.round(ps.x), Math.round(rB) - 1, G_UNDER, P.amber, sll, nearer(ps.dist)); - - if (s > 0.30 && s < 0.72 && ps.dist < 42 && (j & 1) === 0) { - var gl = fg(54, ps.dist); - if (gl >= 5) - put(frame, Math.round(ps.x), Math.round(rT + 1), G_DASH, P.azure, gl, nearer(ps.dist)); - } - } - - var back = xn > xt ? -1 : 1; - var hl = fg(240, dn), tl = fg(196, dtl); - var rHl = Math.round(rowOf(0.62, wn)), rTl = Math.round(rowOf(0.78, wt)); - if (hl >= 5) { - put(frame, Math.round(xn), rHl, G_0, P.ice, hl, nearer(dn)); - put(frame, Math.round(xn) + back, rHl, G_o, P.ice, hl * 0.46, nearer(dn)); - put(frame, Math.round(xn) + back * 2, rHl, G_DOT, P.ice, hl * 0.20, nearer(dn)); - put(frame, Math.round(xn), rHl + 1, G_DOT, P.ice, hl * 0.34, nearer(dn)); - - if (wetR > 0.80) { - var bw = hl * 0.16 * wetR; - put(frame, Math.round(xn) + back * 3, rHl, G_DOT, P.ice, bw, nearer(dn)); - put(frame, Math.round(xn) - back, rHl, G_DOT, P.ice, bw * 1.2, nearer(dn)); - } - } - if (tl >= 5) { - put(frame, Math.round(xt), rTl, G_o, c.tail, tl, nearer(dtl)); - put(frame, Math.round(xt) + back, rTl, G_DOT, c.tail, tl * 0.44, nearer(dtl)); - if (span > 8) - put(frame, Math.round(xt) - back, rTl, G_DOT, c.tail, tl * 0.34, nearer(dtl)); - } - - if (dn < 46) { - var bn = 4 + ((wetR * 2.4) | 0); if (bn > 8) bn = 8; - var ux = c.vx === 0 ? 0 : (c.vx > 0 ? 1 : -1), uz = c.vz === 0 ? 0 : (c.vz > 0 ? 1 : -1); - for (j = 1; j <= bn; j++) { - var bp = project(nx + ux * (1.1 + j * 1.35), nz + uz * (1.1 + j * 1.35)); - if (!bp.ok) continue; - var bl = fg(120 * (1 - j / (bn + 1.5)), bp.dist); - if (bl < 5) continue; - put(frame, Math.round(bp.x), Math.round(rowOf(0.02, bp.w)), - j < 3 ? G_EQ : G_DASH, P.amber, bl, near(bp.dist)); - } - - var tn = 1 + ((wetR * 2.2) | 0); if (tn > 4) tn = 4; - var rr0 = Math.round(rowOf(0, wt)) + 1; - for (j = 0; j < tn; j++) { - var rrd = roadDist(rr0 + j, spt); - var rl = fg((70 - j * 22) * (0.55 + 0.45 * wetR), rrd); - if (rl >= 5) put(frame, Math.round(xt), rr0 + j, G_QUOTE, c.tail, rl, near(rrd)); - } - } - } + if (!pr.ok || pr.w > 70 || l * c.go > COR.half + 11) { + c.live = 0; + c.wait = 3.5 + hash2(i, c.n, S ^ 0x4D) * 11; + } + continue; } - }); - var bits = null, BIT_N = 18; + c.wait -= dt * k; + if (c.wait > 0) continue; + c.n++; + var h1 = hash2(i, c.n, S), h2 = hash2(i, c.n, S ^ 0x21), h3 = hash2(i, c.n, S ^ 0x8F); + var ca = crossAhead(city, h1); + if (ca !== ca) { c.wait = 2.5; continue; } - function bitSpawn(b, i, S, fresh) { - b.n++; - var h1 = hash2(i, b.n, S), h2 = hash2(i, b.n, S ^ 0x2F), h3 = hash2(i, b.n, S ^ 0x5C); + var ch = crossHalf(city, ca) - CC.PAVE; + if (ch < 1.7) ch = 1.7; + c.go = h2 < 0.5 ? -1 : 1; - var a = COR.along + COR.dir * (fresh ? 3 + h1 * 20 : 8 + h1 * 16); - var l = (h2 * 2 - 1) * COR.half * 0.94; - b.x = worldX(a, l); b.z = worldZ(a, l); - b.lift = h3 < 0.55 ? 0.05 + h3 * 0.35 : 0.40 + h3 * 1.10; - b.ph = h1 * 6.283; - b.rate = 0.8 + h2 * 1.9; - b.hue = h3 < 0.62 ? P.slate : (h3 < 0.87 ? P.white : P.amber); - b.gl = PAPER[(h1 * PAPER_N) | 0]; - } + var a = ca + (ch > 1.6 ? 0.55 + h3 * (ch - 1.2) : 0) * -c.go; + var l0 = -c.go * (COR.half + 10); + c.x = worldX(a, l0); c.z = worldZ(a, l0); + var sp = 8 + h3 * 7; + c.vx = COR.axis ? 0 : c.go * sp; + c.vz = COR.axis ? c.go * sp : 0; + c.len = 3.6 + h1 * 1.7; + c.tall = 1.25 + h2 * 0.35; + c.tail = h3 < 0.82 ? P.red : P.ember; + c.live = 1; + } + }, + draw: function (frame, cam, t) { + camScreen(frame, cam); + var i, j; - CC.ELEMENTS.push({ - name: 'litter', + var wetR = wrel('wet'); + for (i = 0; i < CAR_N; i++) { + var c = cars[i]; + if (!c.live) continue; - world: 'cyber', - layer: 24, - init: function (city, rng) { - this.city = city; - this.seed = (rng() * 2147483647) | 0; - this.boot = 0; - bits = new Array(BIT_N); - for (var i = 0; i < BIT_N; i++) - bits[i] = { x: 0, z: 0, n: i * 17 + 3, lift: 0.2, ph: 0, rate: 1, y: 0.05, - hue: P.slate, gl: G_QUOTE }; - }, - update: function (dt, t, cam) { - camBasis(cam); - corridor(this.city, cam); - var S = this.seed, i, b; - if (!this.boot) { this.boot = 1; for (i = 0; i < BIT_N; i++) bitSpawn(bits[i], i, S, 1); } - var k = CC.reducedMotion ? 0.12 : 1; + var half = c.len * 0.5; + var nx = c.x + (c.vx > 0 ? half : (c.vx < 0 ? -half : 0)); + var nz = c.z + (c.vz > 0 ? half : (c.vz < 0 ? -half : 0)); + var tx = c.x * 2 - nx, tz = c.z * 2 - nz; - var wR = wrel('wind'); + var pn = project(nx, nz); if (!pn.ok) continue; + var xn = pn.x, wn = pn.w, dn = pn.dist; + var pt = project(tx, tz); if (!pt.ok) continue; + var xt = pt.x, wt = pt.w, dtl = pt.dist, spt = pt.sp; + if (dn > 72 && dtl > 72) continue; - var wmult = CC.Wind ? CC.Wind.mult : (0.27 + vnoise(t * 0.31, S ^ 0x77) * 1.46); - var gust = 1.30 * wmult * (0.35 + 0.65 * wR); - var swirl = (vnoise(t * 0.24 + 11, S ^ 0x9A) - 0.5) * 1.4 * (0.35 + 0.65 * wR); - for (i = 0; i < BIT_N; i++) { - b = bits[i]; - b.ph += dt * b.rate * k; + var span = xn - xt; if (span < 0) span = -span; + var ns = (span + 2) | 0; if (ns < 4) ns = 4; if (ns > 72) ns = 72; + for (j = 0; j <= ns; j++) { + var s = j / ns; + var ps = project(tx + (nx - tx) * s, tz + (nz - tz) * s); + if (!ps.ok) continue; + var sd = near(ps.dist); + var rB = rowOf(0.06, ps.w), rT = rowOf(c.tall, ps.w); - b.y = 0.04 + b.lift * (0.5 - 0.5 * Math.cos(b.ph)) * (CC.reducedMotion ? 0.3 : 1); - var along = gust * (0.6 + b.lift), lat = swirl * b.lift; - b.x += (COR.axis ? COR.dir * along : lat) * dt * k; - b.z += (COR.axis ? lat : COR.dir * along) * dt * k; - var pr = project(b.x, b.z); - if (!pr.ok || pr.w > 30 || pr.sp > HP * 1.6 || pr.sp < -HP * 1.6) bitSpawn(b, i, S, 0); - } - }, - draw: function (frame, cam, t) { - camScreen(frame, cam); - for (var i = 0; i < BIT_N; i++) { - var b = bits[i]; - var pr = project(b.x, b.z); - if (!pr.ok || pr.dist > 32) continue; + var cab = s > 0.28 && s < 0.74; + if (cab) rT = rowOf(c.tall + 0.34, ps.w); + bar(frame, Math.round(ps.x), rT, rB, 0, P.shadow, 0, sd); - var lum = fg(18 + clamp(b.y / (b.lift + 0.05), 0, 1) * 48, pr.dist); - if (lum < 5) continue; - put(frame, Math.round(pr.x), Math.round(rowOf(b.y, pr.w)), b.gl, b.hue, lum, - near(pr.dist)); - } + var rfl = fg(cab ? 58 : 42, ps.dist); + if (rfl >= 5) + put(frame, Math.round(ps.x), Math.round(rT), G_DASH, P.amber, rfl, nearer(ps.dist)); + + var sll = fg(30 * (0.45 + 0.55 * wetR), ps.dist); + if (sll >= 5) + put(frame, Math.round(ps.x), Math.round(rB) - 1, G_UNDER, P.amber, sll, nearer(ps.dist)); + + if (s > 0.30 && s < 0.72 && ps.dist < 42 && (j & 1) === 0) { + var gl = fg(54, ps.dist); + if (gl >= 5) + put(frame, Math.round(ps.x), Math.round(rT + 1), G_DASH, P.azure, gl, nearer(ps.dist)); + } } - }); + + var back = xn > xt ? -1 : 1; + var hl = fg(240, dn), tl = fg(196, dtl); + var rHl = Math.round(rowOf(0.62, wn)), rTl = Math.round(rowOf(0.78, wt)); + if (hl >= 5) { + put(frame, Math.round(xn), rHl, G_0, P.ice, hl, nearer(dn)); + put(frame, Math.round(xn) + back, rHl, G_o, P.ice, hl * 0.46, nearer(dn)); + put(frame, Math.round(xn) + back * 2, rHl, G_DOT, P.ice, hl * 0.20, nearer(dn)); + put(frame, Math.round(xn), rHl + 1, G_DOT, P.ice, hl * 0.34, nearer(dn)); + + if (wetR > 0.80) { + var bw = hl * 0.16 * wetR; + put(frame, Math.round(xn) + back * 3, rHl, G_DOT, P.ice, bw, nearer(dn)); + put(frame, Math.round(xn) - back, rHl, G_DOT, P.ice, bw * 1.2, nearer(dn)); + } + } + if (tl >= 5) { + put(frame, Math.round(xt), rTl, G_o, c.tail, tl, nearer(dtl)); + put(frame, Math.round(xt) + back, rTl, G_DOT, c.tail, tl * 0.44, nearer(dtl)); + if (span > 8) + put(frame, Math.round(xt) - back, rTl, G_DOT, c.tail, tl * 0.34, nearer(dtl)); + } + + if (dn < 46) { + var bn = 4 + ((wetR * 2.4) | 0); if (bn > 8) bn = 8; + var ux = c.vx === 0 ? 0 : (c.vx > 0 ? 1 : -1), uz = c.vz === 0 ? 0 : (c.vz > 0 ? 1 : -1); + for (j = 1; j <= bn; j++) { + var bp = project(nx + ux * (1.1 + j * 1.35), nz + uz * (1.1 + j * 1.35)); + if (!bp.ok) continue; + var bl = fg(120 * (1 - j / (bn + 1.5)), bp.dist); + if (bl < 5) continue; + put(frame, Math.round(bp.x), Math.round(rowOf(0.02, bp.w)), + j < 3 ? G_EQ : G_DASH, P.amber, bl, near(bp.dist)); + } + + var tn = 1 + ((wetR * 2.2) | 0); if (tn > 4) tn = 4; + var rr0 = Math.round(rowOf(0, wt)) + 1; + for (j = 0; j < tn; j++) { + var rrd = roadDist(rr0 + j, spt); + var rl = fg((70 - j * 22) * (0.55 + 0.45 * wetR), rrd); + if (rl >= 5) put(frame, Math.round(xt), rr0 + j, G_QUOTE, c.tail, rl, near(rrd)); + } + } + } + } + }); + + var bits = null, BIT_N = 18; + + function bitSpawn(b, i, S, fresh) { + b.n++; + var h1 = hash2(i, b.n, S), h2 = hash2(i, b.n, S ^ 0x2F), h3 = hash2(i, b.n, S ^ 0x5C); + + var a = COR.along + COR.dir * (fresh ? 3 + h1 * 20 : 8 + h1 * 16); + var l = (h2 * 2 - 1) * COR.half * 0.94; + b.x = worldX(a, l); b.z = worldZ(a, l); + b.lift = h3 < 0.55 ? 0.05 + h3 * 0.35 : 0.40 + h3 * 1.10; + b.ph = h1 * 6.283; + b.rate = 0.8 + h2 * 1.9; + b.hue = h3 < 0.62 ? P.slate : (h3 < 0.87 ? P.white : P.amber); + b.gl = PAPER[(h1 * PAPER_N) | 0]; + } + + CC.ELEMENTS.push({ + name: 'litter', + + world: 'cyber', + layer: 24, + init: function (city, rng) { + this.city = city; + this.seed = (rng() * 2147483647) | 0; + this.boot = 0; + bits = new Array(BIT_N); + for (var i = 0; i < BIT_N; i++) + bits[i] = { x: 0, z: 0, n: i * 17 + 3, lift: 0.2, ph: 0, rate: 1, y: 0.05, + hue: P.slate, gl: G_QUOTE }; + }, + update: function (dt, t, cam) { + camBasis(cam); + corridor(this.city, cam); + var S = this.seed, i, b; + if (!this.boot) { this.boot = 1; for (i = 0; i < BIT_N; i++) bitSpawn(bits[i], i, S, 1); } + var k = CC.reducedMotion ? 0.12 : 1; + + var wR = wrel('wind'); + + var wmult = CC.Wind ? CC.Wind.mult : (0.27 + vnoise(t * 0.31, S ^ 0x77) * 1.46); + var gust = 1.30 * wmult * (0.35 + 0.65 * wR); + var swirl = (vnoise(t * 0.24 + 11, S ^ 0x9A) - 0.5) * 1.4 * (0.35 + 0.65 * wR); + for (i = 0; i < BIT_N; i++) { + b = bits[i]; + b.ph += dt * b.rate * k; + + b.y = 0.04 + b.lift * (0.5 - 0.5 * Math.cos(b.ph)) * (CC.reducedMotion ? 0.3 : 1); + var along = gust * (0.6 + b.lift), lat = swirl * b.lift; + b.x += (COR.axis ? COR.dir * along : lat) * dt * k; + b.z += (COR.axis ? lat : COR.dir * along) * dt * k; + var pr = project(b.x, b.z); + if (!pr.ok || pr.w > 30 || pr.sp > HP * 1.6 || pr.sp < -HP * 1.6) bitSpawn(b, i, S, 0); + } + }, + draw: function (frame, cam, t) { + camScreen(frame, cam); + for (var i = 0; i < BIT_N; i++) { + var b = bits[i]; + var pr = project(b.x, b.z); + if (!pr.ok || pr.dist > 32) continue; + + var lum = fg(18 + clamp(b.y / (b.lift + 0.05), 0, 1) * 48, pr.dist); + if (lum < 5) continue; + put(frame, Math.round(pr.x), Math.round(rowOf(b.y, pr.w)), b.gl, b.hue, lum, + near(pr.dist)); + } + } + }); })(CC); /* src/elements/structure.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, hash2 = CC.hash2, vnoise = CC.vnoise, put = CC.put; + var P = CC.P, hash2 = CC.hash2, vnoise = CC.vnoise, put = CC.put; - var G_DASH = CC.g('-'), G_PIPE = CC.g('|'), G_SL = CC.g('/'), G_BS = CC.g('\\'), - G_EQ = CC.g('='), G_HASH = CC.g('#'), G_O = CC.g('O'), G_oo = CC.g('o'), - G_0 = CC.g('0'), G_8 = CC.g('8'), G_U = CC.g('U'), G_V = CC.g('V'), - G_Y = CC.g('Y'), G_STAR = CC.g('*'), G_PLUS = CC.g('+'), G_COLON = CC.g(':'), - G_UNDER = CC.g('_'), G_DOT = CC.g('.'), G_COMMA = CC.g(','), G_SEMI = CC.g(';'), - G_X = CC.g('X'), G_M = CC.g('M'), G_W = CC.g('W'), G_N = CC.g('N'), G_A = CC.g('A'), - G_PCT = CC.g('%'), G_AMP = CC.g('&'), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"); + var G_DASH = CC.g('-'), G_PIPE = CC.g('|'), G_SL = CC.g('/'), G_BS = CC.g('\\'), + G_EQ = CC.g('='), G_HASH = CC.g('#'), G_O = CC.g('O'), G_oo = CC.g('o'), + G_0 = CC.g('0'), G_8 = CC.g('8'), G_U = CC.g('U'), G_V = CC.g('V'), + G_Y = CC.g('Y'), G_STAR = CC.g('*'), G_PLUS = CC.g('+'), G_COLON = CC.g(':'), + G_UNDER = CC.g('_'), G_DOT = CC.g('.'), G_COMMA = CC.g(','), G_SEMI = CC.g(';'), + G_X = CC.g('X'), G_M = CC.g('M'), G_W = CC.g('W'), G_N = CC.g('N'), G_A = CC.g('A'), + G_PCT = CC.g('%'), G_AMP = CC.g('&'), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"); - var LANTERN_G = [G_oo, G_O, G_0, G_8]; + var LANTERN_G = [G_oo, G_O, G_0, G_8]; - var CITY = null, BASE = 0, bootWorld, Surf = null; - function boot(city, rng) { - if (rng && bootWorld !== city) { bootWorld = city; BASE = (rng() * 4294967296) | 0; } - CITY = city && city.aveX ? city : null; + var CITY = null, BASE = 0, bootWorld, Surf = null; + function boot(city, rng) { + if (rng && bootWorld !== city) { bootWorld = city; BASE = (rng() * 4294967296) | 0; } + CITY = city && city.aveX ? city : null; + } + + var V = { + ox: 0, oz: 0, eyeY: 1.7, fwx: 0, fwz: 1, rgx: 1, rgz: 0, + hp: 0.7265, colK: 0, colMid: 0, scale: 77, horizon: 33, cols: 0, rows: 0, far: 125, + t: 0, tt: 0 + }; + + var W_WET = 1, W_GUST = 0.55, W_RAIN = 1; + + var W_SWAY = 1; + + function gustOf(Wm, t) { + var G = CC.Wind ? CC.Wind.gust : undefined; + if (typeof G === 'number') return G; + var base = Wm ? Wm.P.wind : 0.55; + return base * (0.70 + 0.66 * vnoise(t * 0.27, 0x51D)); + } + + function view(f, cam, t) { + if (!Surf) Surf = CC.Surf; + var fov = cam.fov || 1.25, hp = Math.tan(fov * 0.5); + var cellA = cam.cellAspect || 0.5625; + V.cols = f.cols; V.rows = f.rows; V.hp = hp; + V.colK = f.cols * 0.5 / hp; V.colMid = f.cols * 0.5; + V.scale = cam.scaleY !== undefined ? cam.scaleY : (f.cols * cellA) / (2 * hp); + V.horizon = cam.horizon !== undefined ? cam.horizon : f.rows * 0.56; + V.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + var yaw = cam.yaw || 0; + V.fwx = Math.sin(yaw); V.fwz = Math.cos(yaw); + V.rgx = Math.cos(yaw); V.rgz = -Math.sin(yaw); + V.ox = cam.x; V.oz = cam.z; + V.far = Surf ? Surf.FOG_END : 125; + V.t = t; + V.tt = CC.reducedMotion ? 0 : t; + var Wm = CC.Weather; + W_WET = Wm ? Wm.rel('wet') : 1; + W_RAIN = Wm ? Wm.rel('rain') : 1; + W_GUST = gustOf(Wm, t); + W_SWAY = CC.reducedMotion ? 0.38 : 1; + } + + var PJ = { x: 0, y: 0, d: 0 }; + function project(px, py, pz) { + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < 0.4) return false; + var sp = (rx * V.rgx + rz * V.rgz) / w; + PJ.d = w * Math.sqrt(1 + sp * sp); + PJ.x = sp * V.colK + V.colMid; + PJ.y = V.horizon - (py - V.eyeY) * V.scale / w; + return PJ.d < V.far; + } + + function emit(f, x, y, ch, col, lum, d) { + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + if (lum > 0 && Surf) { lum = Surf.fog(lum, d); if (lum <= 0) ch = 0; } + put(f, x, y, ch, col, lum, d, 3); + } + + function emitLamp(f, x, y, ch, col, lum, d) { + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + var l = Surf ? Surf.fog(lum, d) : lum, fl = lum * 0.42; + put(f, x, y, ch, col, l < fl ? fl : l, d, 3); + } + + var TICK_MIN = 0.03125, TICK_MAX = 64; + function segment3(f, x0, y0, z0, x1, y1, z1, ch, col, lum, dash) { + var okA = project(x0, y0, z0), ax = PJ.x, ay = PJ.y; + var okB = project(x1, y1, z1), bx = PJ.x, by = PJ.y; + if (!okA && !okB) return; + var n, span; + if (okA && okB) { + var dx = bx - ax, dy = by - ay; + if (dx < 0) dx = -dx; if (dy < 0) dy = -dy; + span = dx > dy ? dx : dy; + + n = (span * 3 + 2) | 0; + if (n > 480) n = 480; + } else { n = 48; span = 24; } + var wl = 0, tpm = 0, anchor = 0; + if (dash > 1) { + var wdx = x1 - x0, wdy = y1 - y0, wdz = z1 - z0; + wl = Math.sqrt(wdx * wdx + wdy * wdy + wdz * wdz); + if (wl < 1e-4) wl = 1e-4; + + tpm = Math.pow(2, Math.round(Math.log(span / wl) / Math.LN2)); + if (!(tpm >= TICK_MIN)) tpm = TICK_MIN; else if (tpm > TICK_MAX) tpm = TICK_MAX; + anchor = x0 * 0.37 + y0 * 1.13 + z0 * 0.71; } - - var V = { - ox: 0, oz: 0, eyeY: 1.7, fwx: 0, fwz: 1, rgx: 1, rgz: 0, - hp: 0.7265, colK: 0, colMid: 0, scale: 77, horizon: 33, cols: 0, rows: 0, far: 125, - t: 0, tt: 0 - }; - - var W_WET = 1, W_GUST = 0.55, W_RAIN = 1; - - var W_SWAY = 1; - - function gustOf(Wm, t) { - var G = CC.Wind ? CC.Wind.gust : undefined; - if (typeof G === 'number') return G; - var base = Wm ? Wm.P.wind : 0.55; - return base * (0.70 + 0.66 * vnoise(t * 0.27, 0x51D)); + var lx = -9999, ly = -9999, i, u, cx, cy; + for (i = 0; i <= n; i++) { + u = i / n; + if (!project(x0 + (x1 - x0) * u, y0 + (y1 - y0) * u, z0 + (z1 - z0) * u)) { lx = -9999; continue; } + cx = Math.floor(PJ.x); cy = Math.floor(PJ.y); + if (cx === lx && cy === ly) continue; + lx = cx; ly = cy; + if (dash > 1 && (Math.floor((anchor + u * wl) * tpm) % dash)) continue; + emit(f, cx, cy, ch, col, lum, PJ.d); } + } - function view(f, cam, t) { - if (!Surf) Surf = CC.Surf; - var fov = cam.fov || 1.25, hp = Math.tan(fov * 0.5); - var cellA = cam.cellAspect || 0.5625; - V.cols = f.cols; V.rows = f.rows; V.hp = hp; - V.colK = f.cols * 0.5 / hp; V.colMid = f.cols * 0.5; - V.scale = cam.scaleY !== undefined ? cam.scaleY : (f.cols * cellA) / (2 * hp); - V.horizon = cam.horizon !== undefined ? cam.horizon : f.rows * 0.56; - V.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - var yaw = cam.yaw || 0; - V.fwx = Math.sin(yaw); V.fwz = Math.cos(yaw); - V.rgx = Math.cos(yaw); V.rgz = -Math.sin(yaw); - V.ox = cam.x; V.oz = cam.z; - V.far = Surf ? Surf.FOG_END : 125; - V.t = t; - V.tt = CC.reducedMotion ? 0 : t; - var Wm = CC.Weather; - W_WET = Wm ? Wm.rel('wet') : 1; - W_RAIN = Wm ? Wm.rel('rain') : 1; - W_GUST = gustOf(Wm, t); - W_SWAY = CC.reducedMotion ? 0.38 : 1; - } + var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 }; + function streetSpan(axis, idx) { + var c, h; + if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); } + else { c = CITY.aveX(idx); h = CITY.aveW(idx); } + SPAN.c0 = c - h; SPAN.c1 = c + h + 1; + SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0; + } + function wx(axis, along, cross) { return axis ? along : cross; } + function wz(axis, along, cross) { return axis ? cross : along; } - var PJ = { x: 0, y: 0, d: 0 }; - function project(px, py, pz) { - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < 0.4) return false; - var sp = (rx * V.rgx + rz * V.rgz) / w; - PJ.d = w * Math.sqrt(1 + sp * sp); - PJ.x = sp * V.colK + V.colMid; - PJ.y = V.horizon - (py - V.eyeY) * V.scale / w; - return PJ.d < V.far; - } + function anchorH(axis, along, cross) { + var a = CITY.height(wx(axis, along, cross), wz(axis, along, cross)); + var b = CITY.height(wx(axis, along - 2.5, cross), wz(axis, along - 2.5, cross)); + var c = CITY.height(wx(axis, along + 2.5, cross), wz(axis, along + 2.5, cross)); + if (b > a) a = b; + return c > a ? c : a; + } - function emit(f, x, y, ch, col, lum, d) { - if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; - if (lum > 0 && Surf) { lum = Surf.fog(lum, d); if (lum <= 0) ch = 0; } - put(f, x, y, ch, col, lum, d, 3); - } + function spanVisible(axis, along, cross, near) { + var px = wx(axis, along, cross), pz = wz(axis, along, cross); + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < (near === undefined ? 1 : near) || w > V.far) return 0; + var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; + if (s < -lim || s > lim) return 0; + return w; + } - function emitLamp(f, x, y, ch, col, lum, d) { - if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; - var l = Surf ? Surf.fog(lum, d) : lum, fl = lum * 0.42; - put(f, x, y, ch, col, l < fl ? fl : l, d, 3); - } + function idxLo(axis) { + return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)) - (axis ? 5 : 3); + } + function idxHi(axis) { + return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)) + (axis ? 5 : 3); + } + function alongLo(axis, pitch) { return Math.floor(((axis ? V.ox : V.oz) - V.far) / pitch); } + function alongHi(axis, pitch) { return Math.floor(((axis ? V.ox : V.oz) + V.far) / pitch); } - var TICK_MIN = 0.03125, TICK_MAX = 64; - function segment3(f, x0, y0, z0, x1, y1, z1, ch, col, lum, dash) { - var okA = project(x0, y0, z0), ax = PJ.x, ay = PJ.y; - var okB = project(x1, y1, z1), bx = PJ.x, by = PJ.y; - if (!okA && !okB) return; - var n, span; - if (okA && okB) { - var dx = bx - ax, dy = by - ay; - if (dx < 0) dx = -dx; if (dy < 0) dy = -dy; - span = dx > dy ? dx : dy; + function drawBridges(f) { + if (!CITY) return; + var axis, idx, n, r, along, hA, hB, y, thick, near, hue, sd, w, cnt, i, u, cross; + var rt, rb, r0, r1, row, cx, dd, lit, lastCx, cw, band; + for (axis = 0; axis < 2; axis++) { + for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { + streetSpan(axis, idx); + if (SPAN.w < 5) continue; + for (n = alongLo(axis, 34); n <= alongHi(axis, 34); n++) { + if (hash2(idx, n, BASE ^ 0x5B12) > 0.46) continue; + along = n * 34 + hash2(idx, n, BASE ^ 0x5B13) * 24; + w = spanVisible(axis, along, SPAN.mid); + if (!w) continue; + hA = anchorH(axis, along, SPAN.c0 - 0.5); + hB = anchorH(axis, along, SPAN.c1 + 0.5); + if (hA < 15 || hB < 15) continue; + sd = BASE ^ (idx * 131 + n * 7919); + y = 9 + hash2(idx, n, BASE ^ 0x5B14) * 14; + r = (hA < hB ? hA : hB) - 3.2; + if (y > r) y = r; - n = (span * 3 + 2) | 0; - if (n > 480) n = 480; - } else { n = 48; span = 24; } - var wl = 0, tpm = 0, anchor = 0; - if (dash > 1) { - var wdx = x1 - x0, wdy = y1 - y0, wdz = z1 - z0; - wl = Math.sqrt(wdx * wdx + wdy * wdy + wdz * wdz); - if (wl < 1e-4) wl = 1e-4; + if (y < 7.5) continue; + thick = 2.3 + hash2(idx, n, BASE ^ 0x5B15) * 1.3; - tpm = Math.pow(2, Math.round(Math.log(span / wl) / Math.LN2)); - if (!(tpm >= TICK_MIN)) tpm = TICK_MIN; else if (tpm > TICK_MAX) tpm = TICK_MAX; - anchor = x0 * 0.37 + y0 * 1.13 + z0 * 0.71; - } - var lx = -9999, ly = -9999, i, u, cx, cy; - for (i = 0; i <= n; i++) { - u = i / n; - if (!project(x0 + (x1 - x0) * u, y0 + (y1 - y0) * u, z0 + (z1 - z0) * u)) { lx = -9999; continue; } - cx = Math.floor(PJ.x); cy = Math.floor(PJ.y); - if (cx === lx && cy === ly) continue; - lx = cx; ly = cy; - if (dash > 1 && (Math.floor((anchor + u * wl) * tpm) % dash)) continue; - emit(f, cx, cy, ch, col, lum, PJ.d); - } - } + near = ((axis ? V.ox : V.oz) < along) ? along - 1.7 : along + 1.7; + r = hash2(idx, n, BASE ^ 0x5B16); + hue = r < 0.55 ? P.azure : (r < 0.90 ? P.amber : P.warm); - var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 }; - function streetSpan(axis, idx) { - var c, h; - if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); } - else { c = CITY.aveX(idx); h = CITY.aveW(idx); } - SPAN.c0 = c - h; SPAN.c1 = c + h + 1; - SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0; - } - function wx(axis, along, cross) { return axis ? along : cross; } - function wz(axis, along, cross) { return axis ? cross : along; } - - function anchorH(axis, along, cross) { - var a = CITY.height(wx(axis, along, cross), wz(axis, along, cross)); - var b = CITY.height(wx(axis, along - 2.5, cross), wz(axis, along - 2.5, cross)); - var c = CITY.height(wx(axis, along + 2.5, cross), wz(axis, along + 2.5, cross)); - if (b > a) a = b; - return c > a ? c : a; - } - - function spanVisible(axis, along, cross, near) { - var px = wx(axis, along, cross), pz = wz(axis, along, cross); - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < (near === undefined ? 1 : near) || w > V.far) return 0; - var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; - if (s < -lim || s > lim) return 0; - return w; - } - - function idxLo(axis) { - return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)) - (axis ? 5 : 3); - } - function idxHi(axis) { - return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)) + (axis ? 5 : 3); - } - function alongLo(axis, pitch) { return Math.floor(((axis ? V.ox : V.oz) - V.far) / pitch); } - function alongHi(axis, pitch) { return Math.floor(((axis ? V.ox : V.oz) + V.far) / pitch); } - - function drawBridges(f) { - if (!CITY) return; - var axis, idx, n, r, along, hA, hB, y, thick, near, hue, sd, w, cnt, i, u, cross; - var rt, rb, r0, r1, row, cx, dd, lit, lastCx, cw, band; - for (axis = 0; axis < 2; axis++) { - for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { - streetSpan(axis, idx); - if (SPAN.w < 5) continue; - for (n = alongLo(axis, 34); n <= alongHi(axis, 34); n++) { - if (hash2(idx, n, BASE ^ 0x5B12) > 0.46) continue; - along = n * 34 + hash2(idx, n, BASE ^ 0x5B13) * 24; - w = spanVisible(axis, along, SPAN.mid); - if (!w) continue; - hA = anchorH(axis, along, SPAN.c0 - 0.5); - hB = anchorH(axis, along, SPAN.c1 + 0.5); - if (hA < 15 || hB < 15) continue; - sd = BASE ^ (idx * 131 + n * 7919); - y = 9 + hash2(idx, n, BASE ^ 0x5B14) * 14; - r = (hA < hB ? hA : hB) - 3.2; - if (y > r) y = r; - - if (y < 7.5) continue; - thick = 2.3 + hash2(idx, n, BASE ^ 0x5B15) * 1.3; - - near = ((axis ? V.ox : V.oz) < along) ? along - 1.7 : along + 1.7; - r = hash2(idx, n, BASE ^ 0x5B16); - hue = r < 0.55 ? P.azure : (r < 0.90 ? P.amber : P.warm); - - cnt = (SPAN.w * 210 / w) | 0; - if (cnt < 10) cnt = 10; if (cnt > 260) cnt = 260; - lastCx = -99999; - for (i = 0; i <= cnt; i++) { - u = i / cnt; - cross = SPAN.c0 + SPAN.w * u; - if (!project(wx(axis, near, cross), y + thick, wz(axis, near, cross))) continue; - rt = PJ.y; cx = Math.floor(PJ.x); dd = PJ.d; - - if (cx === lastCx) continue; - lastCx = cx; - if (!project(wx(axis, near, cross), y, wz(axis, near, cross))) continue; - rb = PJ.y; - r0 = Math.floor(rt); r1 = Math.floor(rb); - if (r1 < r0) r1 = r0; - if (r1 - r0 > 24) r1 = r0 + 24; - - cw = Math.floor(cross * 1.6) + (sd & 3); - band = cw & 3; - for (row = r0; row <= r1; row++) { - if (row === r0) { emit(f, cx, row, G_EQ, P.slate, 34, dd); continue; } - if (row === r1 && r1 > r0) { - - if (!(cw & 7)) emit(f, cx, row, G_oo, P.amber, 150, dd); - else emit(f, cx, row, band === 2 ? G_DASH : 0, P.slate, band === 2 ? 15 : 0, dd); - continue; - } - - lit = (row === r0 + 1) && band === 0; - if (lit) emit(f, cx, row, G_8, hue, 150 + hash2(cw, row - r0, sd) * 62, dd); - else emit(f, cx, row, 0, P.shadow, 0, dd); - } - } - } - } - } - } - - function drawPlant(f) { - if (!CITY) return; - var axis, idx, n, side, r, along, cross, px, pz, w, h, top, wide, tall; - var x0, y0, x1, y1, cx0, cx1, ry0, ry1, col, row, dd, lum; - for (axis = 0; axis < 2; axis++) { - for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { - streetSpan(axis, idx); - for (n = alongLo(axis, 9); n <= alongHi(axis, 9); n++) { - for (side = 0; side < 2; side++) { - r = hash2(idx * 2 + side, n, BASE + 0x7A0F); - if (r > 0.30) continue; - along = n * 9 + hash2(idx * 2 + side, n, BASE + 0x7A10) * 7; - - cross = side ? SPAN.c1 + 1.4 : SPAN.c0 - 1.4; - w = spanVisible(axis, along, cross); - if (!w || w < 14) continue; - px = wx(axis, along, cross); pz = wz(axis, along, cross); - h = CITY.height(px, pz); - if (h < 7) continue; - - if (r < 0.08) { - - if (!project(px, h + 1.5, pz)) continue; - dd = PJ.d; col = Math.floor(PJ.x); row = Math.floor(PJ.y); - emit(f, col, row, G_U, hash2(idx * 2 + side, n, BASE + 0x7A12) < 0.7 ? P.slate : P.white, 52, dd); - emit(f, col, row + 1, G_COLON, P.slate, 26, dd); - continue; - } - - top = h + 1.1 + r * 2.9; - wide = 1.5 + r * 3.8; - if (!project(px - wide * 0.5, top, pz)) continue; - x0 = PJ.x; y0 = PJ.y; dd = PJ.d; - if (!project(px + wide * 0.5, h, pz)) continue; - x1 = PJ.x; y1 = PJ.y; - cx0 = Math.floor(x0); cx1 = Math.floor(x1); - if (cx1 < cx0) { tall = cx0; cx0 = cx1; cx1 = tall; } - if (cx1 - cx0 > 9) cx1 = cx0 + 9; - ry0 = Math.floor(y0); ry1 = Math.floor(y1); - if (ry1 > ry0 + 2) ry1 = ry0 + 2; - for (row = ry0; row <= ry1; row++) { - lum = row === ry0 ? 46 : 28; - for (col = cx0; col <= cx1; col++) - emit(f, col, row, row === ry0 ? G_EQ : G_HASH, P.slate, lum, dd); - } - } - } - } - } - } - - function drawMasts(f) { - if (!CITY) return; - var axis, idx, n, side, r, along, cross, h, mh, col, row, rowTop, dd, k, ph, blink; - for (axis = 0; axis < 2; axis++) { - for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { - streetSpan(axis, idx); - for (n = alongLo(axis, 15); n <= alongHi(axis, 15); n++) { - for (side = 0; side < 2; side++) { - r = hash2(idx * 2 + side, n, BASE ^ 0x2E10); - if (r > 0.30) continue; - along = n * 15 + hash2(idx * 2 + side, n, BASE ^ 0x2E11) * 11; - - cross = side ? SPAN.c1 + 1.0 : SPAN.c0 - 1.0; - if (!spanVisible(axis, along, cross)) continue; - h = CITY.height(wx(axis, along, cross), wz(axis, along, cross)); - - if (h < 11) continue; - - mh = 3.5 + r * 26 + (h > 55 ? 9 : 0); - if (!project(wx(axis, along, cross), h + mh, wz(axis, along, cross))) continue; - col = Math.floor(PJ.x); rowTop = Math.floor(PJ.y); dd = PJ.d; - if (rowTop >= V.rows) continue; - if (!project(wx(axis, along, cross), h, wz(axis, along, cross))) continue; - row = Math.floor(PJ.y); - if (row - rowTop > 30) row = rowTop + 30; - - for (k = rowTop + 1; k <= row; k++) - if (!((k - rowTop) & 1) || (k - rowTop) < 3) - emit(f, col, k, G_PIPE, P.slate, 26, dd); - - if (hash2(idx * 2 + side, n, BASE ^ 0x2E13) < 0.34 && row - rowTop > 4) { - k = rowTop + 2; - emit(f, col - 1, k, G_DASH, P.slate, 22, dd); - emit(f, col + 1, k, G_DASH, P.slate, 22, dd); - emit(f, col, rowTop + 1, G_Y, P.slate, 30, dd); - } - ph = V.t * 0.55 + hash2(idx * 2 + side, n, BASE ^ 0x2E14); - blink = CC.reducedMotion ? 0.72 : ((ph - Math.floor(ph)) < 0.34 ? 1 : 0.16); - emitLamp(f, col, rowTop, blink > 0.5 ? G_STAR : G_PLUS, P.red, 78 + 150 * blink, dd); - - if (mh > 22 && row - rowTop > 12) - emitLamp(f, col, rowTop + ((row - rowTop) >> 1), G_PLUS, P.red, 40 + 90 * blink, dd); - } - } - } - } - } - - function drawEscapes(f) { - if (!CITY) return; - var axis, idx, n, side, r, along, plane, h, top, y, lev, wdt, dd, dir, a0, a1, lum, pw, flights; - for (axis = 0; axis < 2; axis++) { - for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { - streetSpan(axis, idx); - for (n = alongLo(axis, 11); n <= alongHi(axis, 11); n++) { - for (side = 0; side < 2; side++) { - r = hash2(idx * 2 + side, n, BASE ^ 0x3E5C); - if (r > 0.18) continue; - along = n * 11 + hash2(idx * 2 + side, n, BASE ^ 0x3E5D) * 7.5; - dd = spanVisible(axis, along, side ? SPAN.c1 : SPAN.c0); - if (!dd) continue; - h = anchorH(axis, along, side ? SPAN.c1 + 0.5 : SPAN.c0 - 0.5); - if (h < 12) continue; - plane = side ? SPAN.c1 - 0.42 : SPAN.c0 + 0.42; - top = h - 1.7; if (top > 21) top = 21; - wdt = 1.15 + r * 2.2; - - if (dd > 74 || dd < 12) continue; - - a0 = along - wdt; a1 = along + wdt; - if (!project(wx(axis, a0, plane), 8, wz(axis, a0, plane))) continue; - pw = PJ.x; - if (!project(wx(axis, a1, plane), 8, wz(axis, a1, plane))) continue; - pw = PJ.x - pw; if (pw < 0) pw = -pw; - if (pw < 2.2) continue; - flights = pw >= 5; - lev = 0; - for (y = 2.9; y < top; y += 3.3, lev++) { - - lum = (lev === 1 && r < 0.06) ? 62 : 33; - segment3(f, wx(axis, a0, plane), y, wz(axis, a0, plane), - wx(axis, a1, plane), y, wz(axis, a1, plane), - G_EQ, (lev === 1 && r < 0.06) ? P.amber : P.slate, lum, 3); - if (!flights || y + 3.3 >= top) continue; - - dir = (lev & 1) ? 1 : -1; - segment3(f, wx(axis, along - wdt * dir, plane), y, wz(axis, along - wdt * dir, plane), - wx(axis, along + wdt * dir, plane), y + 3.3, wz(axis, along + wdt * dir, plane), - dir > 0 ? G_SL : G_BS, P.slate, 24, 2); - } - } - } - } - } - } - - function drawCableRun(f, axis, along, c0, c1, yA, yB, sag, col, lum, w) { - var cnt = ((c1 - c0) * 220 / w) | 0; - if (cnt < 12) cnt = 12; if (cnt > 300) cnt = 300; - var lx = -9999, ly = -9999, i, u, cross, y, cx, cy, dy, ch, k; - for (i = 0; i <= cnt; i++) { + cnt = (SPAN.w * 210 / w) | 0; + if (cnt < 10) cnt = 10; if (cnt > 260) cnt = 260; + lastCx = -99999; + for (i = 0; i <= cnt; i++) { u = i / cnt; - cross = c0 + (c1 - c0) * u; - y = yA + (yB - yA) * u - sag * 4 * u * (1 - u); - if (!project(wx(axis, along, cross), y, wz(axis, along, cross))) { lx = -9999; continue; } - cx = Math.floor(PJ.x); cy = Math.floor(PJ.y); - if (cx === lx && cy === ly) continue; - if (lx === -9999) ch = G_DASH; - else { - dy = cy - ly; + cross = SPAN.c0 + SPAN.w * u; + if (!project(wx(axis, near, cross), y + thick, wz(axis, near, cross))) continue; + rt = PJ.y; cx = Math.floor(PJ.x); dd = PJ.d; - if (dy > 1 || dy < -1) { - for (k = ly + (dy > 0 ? 1 : -1); k !== cy; k += (dy > 0 ? 1 : -1)) - emit(f, cx, k, G_PIPE, col, lum, PJ.d); - ch = G_PIPE; - } else ch = dy === 0 ? G_DASH : (dy > 0 ? G_BS : G_SL); - } - emit(f, cx, cy, ch, col, lum, PJ.d); - lx = cx; ly = cy; - } - } - - function drawCables(f) { - if (!CITY) return; - var axis, idx, n, r, along, hA, hB, yA, yB, sag, w, tram, lum; - for (axis = 0; axis < 2; axis++) { - for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { - streetSpan(axis, idx); - - for (n = alongLo(axis, 26); n <= alongHi(axis, 26); n++) { - r = hash2(idx, n, BASE ^ 0x1CAB); - if (r > 0.26) continue; - along = n * 26 + hash2(idx, n, BASE ^ 0x1CAC) * 18; - w = spanVisible(axis, along, SPAN.mid); - if (!w) continue; - hA = anchorH(axis, along, SPAN.c0 - 0.5); - hB = anchorH(axis, along, SPAN.c1 + 0.5); - if (hA < 8 || hB < 8) continue; - yA = 6.5 + hash2(idx, n, BASE ^ 0x1CAD) * 6.5; - - yB = yA + (hash2(idx, n, BASE ^ 0x1CAE) - 0.5) * 1.2; - if (yA > hA - 1.4) yA = hA - 1.4; - if (yB > hB - 1.4) yB = hB - 1.4; - if (yA < 5 || yB < 5) continue; - sag = SPAN.w * (0.075 + hash2(idx, n, BASE ^ 0x1CAF) * 0.075); - - tram = r < 0.10; - lum = tram ? 62 : 44; - drawCableRun(f, axis, along, SPAN.c0, SPAN.c1, yA, yB, sag, P.slate, lum, w); - - if (tram && w < 46) - drawCableRun(f, axis, along, SPAN.c0, SPAN.c1, yA - 1.15, yB - 1.15, - sag * 0.55, P.slate, 34, w); - } - } - } - } - - function drawLanterns(f) { - if (!CITY) return; - var axis, idx, n, r, along, hA, hB, y, sag, w, cnt, i, u, cross, yy, hue, sd, flick, lum; - var col, row, dd, pennant, swing, ph; - for (axis = 0; axis < 2; axis++) { - for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { - streetSpan(axis, idx); - for (n = alongLo(axis, 14); n <= alongHi(axis, 14); n++) { - r = hash2(idx, n, BASE ^ 0x4A17); - if (r > 0.46) continue; - along = n * 14 + hash2(idx, n, BASE ^ 0x4A18) * 10; - w = spanVisible(axis, along, SPAN.mid); - if (!w) continue; - hA = anchorH(axis, along, SPAN.c0 - 0.5); - hB = anchorH(axis, along, SPAN.c1 + 0.5); - if (hA < 6 || hB < 6) continue; - y = 4.6 + hash2(idx, n, BASE ^ 0x4A19) * 1.9; - sag = 0.30 + r * 1.4; - sd = BASE ^ (idx * 613 + n * 4099); - - hue = (r = hash2(idx, n, BASE ^ 0x4A1B)) < 0.26 ? P.ember : (r < 0.40 ? P.warm : P.amber); - pennant = hash2(idx, n, BASE ^ 0x4A1A) < 0.34; - cnt = (SPAN.w / 1.9) | 0; if (cnt < 4) cnt = 4; - - swing = W_GUST * (0.34 + r * 0.30) * W_SWAY; - for (i = 0; i < cnt; i++) { - u = (i + 0.5) / cnt; - cross = SPAN.c0 + SPAN.w * u; - yy = y - sag * 4 * u * (1 - u); - - ph = Math.sin(V.tt * 1.25 + (sd & 31) * 0.19 + i * 0.22); - yy += swing * 0.13 * (ph > 0 ? ph : -ph); - if (!project(wx(axis, along + swing * ph, cross), yy, - wz(axis, along + swing * ph, cross))) continue; - col = Math.floor(PJ.x); row = Math.floor(PJ.y); dd = PJ.d; - - flick = CC.reducedMotion ? 0.94 - : 0.80 + 0.24 * vnoise(V.t * 1.7 + i * 0.7 + (sd & 255) * 0.13, 0x4A1); - lum = (168 + hash2(i, n, sd) * 60) * flick; - emit(f, col, row, LANTERN_G[(hash2(i, 0, sd) * 4) | 0], hue, lum, dd); - if (pennant && (i & 1)) - emit(f, col, row + 1, G_V, hue, lum * 0.26, dd); - } - } - } - } - } - - var K_VEND = 0, K_SHUTTER = 1, K_BOLLARD = 2, K_CRATES = 3, K_AC = 4, - K_BANNER = 5, K_CALLBOX = 6, K_LADDER = 7, K_PLANTER = 8, K_HOARD = 9, K_SCAFF = 10, - K_SHELTER = 11, K_NEWSBOX = 12, K_STAIR = 13, K_WASH = 14; - - var KIND = new Uint8Array([ - K_VEND, K_VEND, K_VEND, K_VEND, K_VEND, - K_CRATES, K_CRATES, K_CRATES, - K_SHUTTER, K_SHUTTER, - K_BOLLARD, K_BOLLARD, - K_AC, K_AC, - K_CALLBOX, K_CALLBOX, - K_PLANTER, K_NEWSBOX, - K_LADDER, K_BANNER, - K_STAIR, K_SHELTER, K_HOARD, K_WASH, K_SCAFF - ]); - - var STY_FLAT = 0, STY_RIB = 1, STY_MESH = 2; - - var CLIP = { u0: 0, u1: 1 }; - function clipNear(axis, a0, a1, cross) { - var rx = wx(axis, a0, cross) - V.ox, rz = wz(axis, a0, cross) - V.oz; - var g0 = rx * V.fwx + rz * V.fwz - 0.42; - rx = wx(axis, a1, cross) - V.ox; rz = wz(axis, a1, cross) - V.oz; - var g1 = rx * V.fwx + rz * V.fwz - 0.42; - if (g0 < 0 && g1 < 0) return false; - CLIP.u0 = 0; CLIP.u1 = 1; - if (g0 < 0) CLIP.u0 = g0 / (g0 - g1); - else if (g1 < 0) CLIP.u1 = g0 / (g0 - g1); - return true; - } - - function panel(f, axis, a0, a1, cross, y0, y1, ch, col, lum, jit, sty, sd) { - if (!clipNear(axis, a0, a1, cross)) return; - var b0 = a0 + (a1 - a0) * CLIP.u0, b1 = a0 + (a1 - a0) * CLIP.u1; - var rx = wx(axis, b0, cross) - V.ox, rz = wz(axis, b0, cross) - V.oz; - var w0 = rx * V.fwx + rz * V.fwz, s0 = rx * V.rgx + rz * V.rgz; - rx = wx(axis, b1, cross) - V.ox; rz = wz(axis, b1, cross) - V.oz; - var w1 = rx * V.fwx + rz * V.fwz, s1 = rx * V.rgx + rz * V.rgz; - var dw = w1 - w0, ds = s1 - s0; - var xa = s0 / w0 * V.colK + V.colMid, xb = s1 / w1 * V.colK + V.colMid; - var j0 = Math.floor(xa < xb ? xa : xb), j1 = Math.floor(xa < xb ? xb : xa); - if (j1 < 0 || j0 >= V.cols) return; - if (j0 < 0) j0 = 0; - if (j1 > V.cols - 1) j1 = V.cols - 1; - var j, sp, den, u, a, rt, rb, r0, r1, row, dd, lat, l, tmp, pat, fade; - for (j = j0; j <= j1; j++) { - sp = (j + 0.5 - V.colMid) / V.colK; - den = sp * dw - ds; - - u = (den > 1e-9 || den < -1e-9) ? (s0 - sp * w0) / den : 0.5; - if (u < 0) u = 0; else if (u > 1) u = 1; - a = b0 + (b1 - b0) * u; - if (!project(wx(axis, a, cross), y1, wz(axis, a, cross))) continue; - rt = PJ.y; dd = PJ.d; - - fade = (dd - 1.2) * 0.5556; - if (fade <= 0) continue; - if (fade > 1) fade = 1; - if (!project(wx(axis, a, cross), y0, wz(axis, a, cross))) continue; + if (cx === lastCx) continue; + lastCx = cx; + if (!project(wx(axis, near, cross), y, wz(axis, near, cross))) continue; rb = PJ.y; r0 = Math.floor(rt); r1 = Math.floor(rb); - if (r1 < r0) { tmp = r0; r0 = r1; r1 = tmp; } + if (r1 < r0) r1 = r0; + if (r1 - r0 > 24) r1 = r0 + 24; - pat = r0; - - if (r0 < -1) r0 = -1; - if (r1 > V.rows) r1 = V.rows; - lat = Math.floor(a * 4.7) + (sd & 15); + cw = Math.floor(cross * 1.6) + (sd & 3); + band = cw & 3; for (row = r0; row <= r1; row++) { + if (row === r0) { emit(f, cx, row, G_EQ, P.slate, 34, dd); continue; } + if (row === r1 && r1 > r0) { - if (fade < 1 && hash2(lat, row - pat, sd + 0x51) > fade) continue; - l = lum; - if (sty === STY_RIB) { if ((row - pat) & 1) l *= 0.32; } - else if (sty === STY_MESH && ((lat + row - pat) & 1)) continue; - if (jit) l += hash2(lat, row - pat, sd) * jit; - emit(f, j, row, ch, col, l, dd); + if (!(cw & 7)) emit(f, cx, row, G_oo, P.amber, 150, dd); + else emit(f, cx, row, band === 2 ? G_DASH : 0, P.slate, band === 2 ? 15 : 0, dd); + continue; + } + + lit = (row === r0 + 1) && band === 0; + if (lit) emit(f, cx, row, G_8, hue, 150 + hash2(cw, row - r0, sd) * 62, dd); + else emit(f, cx, row, 0, P.shadow, 0, dd); } + } } + } } + } - function pcell(f, axis, a, cross, y, ch, col, lum, bias) { - if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) return; - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), ch, col, lum, PJ.d * bias); - } + function drawPlant(f) { + if (!CITY) return; + var axis, idx, n, side, r, along, cross, px, pz, w, h, top, wide, tall; + var x0, y0, x1, y1, cx0, cx1, ry0, ry1, col, row, dd, lum; + for (axis = 0; axis < 2; axis++) { + for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { + streetSpan(axis, idx); + for (n = alongLo(axis, 9); n <= alongHi(axis, 9); n++) { + for (side = 0; side < 2; side++) { + r = hash2(idx * 2 + side, n, BASE + 0x7A0F); + if (r > 0.30) continue; + along = n * 9 + hash2(idx * 2 + side, n, BASE + 0x7A10) * 7; - function propVend(f, axis, a, wp, kp, inw, sd, dd) { - var q = hash2(1, 0, sd); + cross = side ? SPAN.c1 + 1.4 : SPAN.c0 - 1.4; + w = spanVisible(axis, along, cross); + if (!w || w < 14) continue; + px = wx(axis, along, cross); pz = wz(axis, along, cross); + h = CITY.height(px, pz); + if (h < 7) continue; - var hue = q < 0.44 ? P.azure : (q < 0.82 ? P.amber : P.spring); - panel(f, axis, a - 0.44, a + 0.44, wp, 0.60, 1.74, G_8, hue, 92, 58, STY_FLAT, sd); - panel(f, axis, a - 0.58, a + 0.58, wp - inw * 0.05, 0, 2.04, 0, P.shadow, 0, 0, STY_FLAT, sd); + if (r < 0.08) { - panel(f, axis, a - 0.58, a + 0.58, wp - inw * 0.05, 1.98, 2.06, G_EQ, P.slate, 40, 0, STY_FLAT, sd); - - var wl = 26 + 30 * W_WET; - pcell(f, axis, a - 0.30, wp + inw * 0.55, 0.02, G_COMMA, hue, wl, 0.985); - pcell(f, axis, a, wp + inw * 0.75, 0.02, G_COLON, hue, wl * 1.2, 0.985); - pcell(f, axis, a + 0.30, wp + inw * 0.55, 0.02, G_DOT, hue, wl, 0.985); - } - - function propShutter(f, axis, a, wp, kp, inw, sd, dd) { - - panel(f, axis, a - 1.30, a + 1.30, wp, 0.18, 0.48, G_UNDER, P.warm, 76, 30, STY_MESH, sd); - panel(f, axis, a - 1.35, a + 1.35, wp - inw * 0.05, 0, 1.16, 0, P.shadow, 0, 0, STY_FLAT, sd); - panel(f, axis, a - 1.40, a + 1.40, wp, 1.16, 2.72, G_EQ, P.slate, 30, 10, STY_RIB, sd); - - panel(f, axis, a - 1.40, a + 1.40, wp + inw * 0.03, 1.16, 1.24, G_DASH, P.slate, 54, 0, STY_FLAT, sd); - pcell(f, axis, a, wp + inw * 0.6, 0.02, G_COLON, P.warm, 30 + 26 * W_WET, 0.985); - } - - function propBollard(f, axis, a, wp, kp, inw, sd, dd) { - - var i, aa; - for (i = 0; i < 4; i++) { - aa = a - 1.65 + i * 1.1; - segment3(f, wx(axis, aa, kp), 0.02, wz(axis, aa, kp), - wx(axis, aa, kp), 0.86, wz(axis, aa, kp), G_PIPE, P.slate, 34, 1); - - pcell(f, axis, aa, kp, 0.90, G_oo, P.white, 74, 1); - } - } - - function propCrates(f, axis, a, wp, kp, inw, sd, dd) { - - var hL = 1.26, hR = 0.94 + hash2(3, 0, sd) * 0.22; - panel(f, axis, a - 0.85, a - 0.34, wp - inw * 0.05, 0, hL, G_HASH, P.shadow, 16, 8, STY_FLAT, sd); - panel(f, axis, a - 0.85, a - 0.34, wp, hL - 0.08, hL + 0.02, G_EQ, P.slate, 44, 0, STY_FLAT, sd); - panel(f, axis, a - 0.34, a + 0.15, wp - inw * 0.05, 0, hR, G_HASH, P.shadow, 14, 8, STY_FLAT, sd); - panel(f, axis, a - 0.34, a + 0.15, wp, hR - 0.08, hR + 0.02, G_EQ, P.slate, 36, 0, STY_FLAT, sd); - panel(f, axis, a + 0.15, a + 0.92, wp - inw * 0.05, 0, 0.62, G_oo, P.shadow, 14, 8, STY_FLAT, sd); - - if (hash2(4, 0, sd) < 0.4) { - panel(f, axis, a - 0.78, a - 0.40, wp + inw * 0.10, hL, hL + 0.44, G_HASH, P.shadow, 15, 8, STY_FLAT, sd); - panel(f, axis, a - 0.78, a - 0.40, wp + inw * 0.10, hL + 0.36, hL + 0.46, G_EQ, P.slate, 38, 0, STY_FLAT, sd); - } - } - - function propAC(f, axis, a, wp, kp, inw, sd, dd) { - - panel(f, axis, a - 0.40, a + 0.40, wp + inw * 0.15, 3.22, 3.68, G_EQ, P.slate, 32, 0, STY_RIB, sd); - panel(f, axis, a - 0.46, a + 0.46, wp + inw * 0.10, 3.05, 3.86, G_HASH, P.slate, 22, 10, STY_FLAT, sd); - - if (!CC.reducedMotion) { - var ph = V.t * 0.62 + (sd & 31) * 0.19, k = Math.floor(ph), fr = ph - k; - if (hash2(k, 0, sd + 11) < 0.22 + 0.46 * W_WET) - pcell(f, axis, a + 0.12, wp + inw * 0.18, 3.02 - fr * fr * 3.0, G_QUOTE, P.ice, 96, 1); - } - - if (W_WET > 0.5) - pcell(f, axis, a + 0.12, wp + inw * 0.35, 0.02, G_COMMA, P.ice, 16 + 18 * W_WET, 0.985); - } - - function propBanner(f, axis, a, wp, kp, inw, sd, dd) { - - var q = hash2(6, 0, sd); - var hue = q < 0.44 ? P.ember : (q < 0.84 ? P.amber : P.violet); - var p = wp + inw * 0.42, i, y, s, amp = W_GUST * 0.40 * W_SWAY, ph = (sd & 63) * 0.11; - segment3(f, wx(axis, a, wp - inw * 0.3), 4.02, wz(axis, a, wp - inw * 0.3), - wx(axis, a, p), 4.02, wz(axis, a, p), G_DASH, P.slate, 32, 1); - for (i = 0; i < 9; i++) { - y = 3.92 - i * 0.20; - - s = amp * (i / 8) * (i / 8) * Math.sin(V.tt * 1.45 + ph + i * 0.30); - segment3(f, wx(axis, a - 0.26 + s, p), y, wz(axis, a - 0.26 + s, p), - wx(axis, a + 0.26 + s, p), y, wz(axis, a + 0.26 + s, p), - i === 8 ? G_V : G_8, hue, i === 8 ? 46 : 62 + hash2(i, 0, sd) * 40, 1); - } - } - - function propCallbox(f, axis, a, wp, kp, inw, sd, dd) { - - panel(f, axis, a - 0.26, a + 0.26, wp, 1.48, 2.06, G_8, P.azure, 104, 40, STY_FLAT, sd); - panel(f, axis, a - 0.40, a + 0.40, wp - inw * 0.05, 0, 2.28, 0, P.shadow, 0, 0, STY_FLAT, sd); - panel(f, axis, a - 0.40, a + 0.40, wp - inw * 0.05, 2.22, 2.30, G_EQ, P.slate, 38, 0, STY_FLAT, sd); - var ph = V.t * 0.31 + (sd & 15) * 0.21; ph -= Math.floor(ph); - pcell(f, axis, a, wp, 2.42, G_oo, P.ember, - CC.reducedMotion ? 96 : (ph < 0.5 ? 150 : 44), 1); - pcell(f, axis, a, wp + inw * 0.5, 0.02, G_COLON, P.azure, 18 + 20 * W_WET, 0.985); - } - - function propLadder(f, axis, a, wp, kp, inw, sd, dd) { - - var p = wp + inw * 0.08, i, y, top = 4.6 + hash2(7, 0, sd) * 1.6; - segment3(f, wx(axis, a - 0.26, p), 0.1, wz(axis, a - 0.26, p), - wx(axis, a - 0.26, p), top, wz(axis, a - 0.26, p), G_PIPE, P.slate, 30, 1); - segment3(f, wx(axis, a + 0.26, p), 0.1, wz(axis, a + 0.26, p), - wx(axis, a + 0.26, p), top, wz(axis, a + 0.26, p), G_PIPE, P.slate, 30, 1); - for (y = 0.45; y < top; y += 0.52) - segment3(f, wx(axis, a - 0.26, p), y, wz(axis, a - 0.26, p), - wx(axis, a + 0.26, p), y, wz(axis, a + 0.26, p), G_DASH, P.slate, 26, 1); - } - - function propPlanter(f, axis, a, wp, kp, inw, sd, dd) { - - panel(f, axis, a - 0.70, a + 0.70, kp, 0, 0.54, G_HASH, P.slate, 24, 8, STY_FLAT, sd); - panel(f, axis, a - 0.70, a + 0.70, kp, 0.50, 0.58, G_EQ, P.slate, 46, 0, STY_FLAT, sd); - var i, aa, y; - for (i = 0; i < 7; i++) { - aa = a - 0.55 + hash2(i, 1, sd) * 1.1; - y = 0.62 + hash2(i, 2, sd) * 0.72; - pcell(f, axis, aa, kp + inw * (hash2(i, 3, sd) - 0.5) * 0.3, y, - hash2(i, 4, sd) < 0.5 ? G_AMP : G_PCT, P.spring, 34 + hash2(i, 5, sd) * 30, 1); - } - } - - function propHoard(f, axis, a, wp, kp, inw, sd, dd) { - - panel(f, axis, a - 2.1, a + 2.1, kp, 0, 2.16, 0, P.shadow, 0, 0, STY_FLAT, sd); - panel(f, axis, a - 2.1, a + 2.1, kp, 2.10, 2.18, G_EQ, P.slate, 36, 0, STY_FLAT, sd); - - panel(f, axis, a - 2.0, a + 2.0, kp + inw * 0.02, 1.72, 1.88, G_SL, P.ember, 30, 12, STY_MESH, sd); - var ph = V.t * 1.05 + (sd & 31) * 0.13; ph -= Math.floor(ph); - pcell(f, axis, a + 1.9, kp, 2.34, G_0, P.amber, - CC.reducedMotion ? 110 : (ph < 0.34 ? 208 : 30), 1); - pcell(f, axis, a + 1.9, kp + inw * 0.4, 0.02, G_COLON, P.amber, - (CC.reducedMotion ? 22 : (ph < 0.34 ? 44 : 8)) * (0.6 + W_WET * 0.8), 0.985); - } - - function propScaff(f, axis, a, wp, kp, inw, sd, dd) { - - var p = wp + inw * 0.55, i, y, aa, top = 6.4 + hash2(8, 0, sd) * 3.4; - for (i = 0; i < 3; i++) { - aa = a - 1.9 + i * 1.85; - segment3(f, wx(axis, aa, p), 0.05, wz(axis, aa, p), - wx(axis, aa, p), top, wz(axis, aa, p), G_PIPE, P.slate, 30, 2); - } - for (y = 2.3; y < top; y += 2.4) { - segment3(f, wx(axis, a - 1.9, p), y, wz(axis, a - 1.9, p), - wx(axis, a + 1.8, p), y, wz(axis, a + 1.8, p), G_EQ, P.slate, 34, 2); - - segment3(f, wx(axis, a - 1.9, p), y - 2.4, wz(axis, a - 1.9, p), - wx(axis, a - 0.05, p), y, wz(axis, a - 0.05, p), G_SL, P.slate, 22, 3); - } - - panel(f, axis, a - 1.9, a + 1.8, p + inw * 0.06, 0.1, 2.3, G_COLON, P.slate, 18, 6, STY_MESH, sd); - } - - function propShelter(f, axis, a, wp, kp, inw, sd, dd) { - - var p = kp; - panel(f, axis, a - 1.05, a - 0.05, p, 0.55, 2.10, G_8, P.azure, 96, 46, STY_FLAT, sd); - panel(f, axis, a - 1.05, a - 0.05, p - inw * 0.05, 0, 2.20, 0, P.shadow, 0, 0, STY_FLAT, sd); - panel(f, axis, a - 1.75, a + 1.75, p, 2.28, 2.44, G_EQ, P.slate, 38, 0, STY_FLAT, sd); - segment3(f, wx(axis, a + 1.70, p), 0.05, wz(axis, a + 1.70, p), - wx(axis, a + 1.70, p), 2.28, wz(axis, a + 1.70, p), G_PIPE, P.slate, 30, 1); - segment3(f, wx(axis, a - 1.70, p), 0.05, wz(axis, a - 1.70, p), - wx(axis, a - 1.70, p), 2.28, wz(axis, a - 1.70, p), G_PIPE, P.slate, 30, 1); - segment3(f, wx(axis, a + 0.15, p - inw * 0.2), 0.45, wz(axis, a + 0.15, p - inw * 0.2), - wx(axis, a + 1.60, p - inw * 0.2), 0.45, wz(axis, a + 1.60, p - inw * 0.2), - G_UNDER, P.slate, 30, 1); - pcell(f, axis, a - 0.55, p + inw * 0.7, 0.02, G_COLON, P.azure, 24 + 30 * W_WET, 0.985); - } - - function propNewsbox(f, axis, a, wp, kp, inw, sd, dd) { - - panel(f, axis, a - 0.26, a + 0.26, kp, 0.42, 0.96, G_8, P.ember, 64, 26, STY_FLAT, sd); - panel(f, axis, a - 0.30, a + 0.30, kp - inw * 0.05, 0, 1.06, 0, P.shadow, 0, 0, STY_FLAT, sd); - panel(f, axis, a - 0.30, a + 0.30, kp - inw * 0.05, 1.00, 1.08, G_DASH, P.slate, 40, 0, STY_FLAT, sd); - } - - function propStair(f, axis, a, wp, kp, inw, sd, dd) { - - var i, j, c, aa, l, hue = hash2(9, 0, sd) < 0.7 ? P.warm : P.spring; - - for (i = 0; i < 6; i++) { - c = wp + inw * (0.22 + i * 0.30); - l = 118 - i * 19; - for (j = 0; j < 5; j++) { - aa = a - 0.86 + j * 0.43; - pcell(f, axis, aa, c, 0.02, i === 0 ? G_8 : G_EQ, hue, l, 0.985); + if (!project(px, h + 1.5, pz)) continue; + dd = PJ.d; col = Math.floor(PJ.x); row = Math.floor(PJ.y); + emit(f, col, row, G_U, hash2(idx * 2 + side, n, BASE + 0x7A12) < 0.7 ? P.slate : P.white, 52, dd); + emit(f, col, row + 1, G_COLON, P.slate, 26, dd); + continue; } - } - segment3(f, wx(axis, a - 0.95, wp + inw * 1.65), 0.98, wz(axis, a - 0.95, wp + inw * 1.65), - wx(axis, a + 0.95, wp + inw * 1.65), 0.98, wz(axis, a + 0.95, wp + inw * 1.65), - G_DASH, P.slate, 44, 1); - segment3(f, wx(axis, a + 0.95, wp + inw * 1.65), 0.05, wz(axis, a + 0.95, wp + inw * 1.65), - wx(axis, a + 0.95, wp + inw * 1.65), 1.02, wz(axis, a + 0.95, wp + inw * 1.65), - G_PIPE, P.slate, 36, 1); - } - - function propWash(f, axis, a, wp, kp, inw, sd, dd) { - - var p = wp + inw * 0.35, i, aa, s, y, amp = W_GUST * 0.34 * W_SWAY, ph = (sd & 31) * 0.2; - - segment3(f, wx(axis, a - 1.9, p), 4.32, wz(axis, a - 1.9, p), - wx(axis, a + 1.9, p), 4.30, wz(axis, a + 1.9, p), G_DASH, P.slate, 30, 1); - - if (W_RAIN > 0.6) return; - for (i = 0; i < 4; i++) { - aa = a - 1.35 + i * 0.9; - s = amp * Math.sin(V.tt * 1.2 + ph + i * 0.8); - for (y = 4.18; y > 3.35; y -= 0.20) { - segment3(f, wx(axis, aa - 0.18 + s, p), y, wz(axis, aa - 0.18 + s, p), - wx(axis, aa + 0.18 + s, p), y, wz(axis, aa + 0.18 + s, p), - G_8, i & 1 ? P.white : P.slate, 40 + hash2(i, (y * 5) | 0, sd) * 22, 1); + top = h + 1.1 + r * 2.9; + wide = 1.5 + r * 3.8; + if (!project(px - wide * 0.5, top, pz)) continue; + x0 = PJ.x; y0 = PJ.y; dd = PJ.d; + if (!project(px + wide * 0.5, h, pz)) continue; + x1 = PJ.x; y1 = PJ.y; + cx0 = Math.floor(x0); cx1 = Math.floor(x1); + if (cx1 < cx0) { tall = cx0; cx0 = cx1; cx1 = tall; } + if (cx1 - cx0 > 9) cx1 = cx0 + 9; + ry0 = Math.floor(y0); ry1 = Math.floor(y1); + if (ry1 > ry0 + 2) ry1 = ry0 + 2; + for (row = ry0; row <= ry1; row++) { + lum = row === ry0 ? 46 : 28; + for (col = cx0; col <= cx1; col++) + emit(f, col, row, row === ry0 ? G_EQ : G_HASH, P.slate, lum, dd); } + } } + } } + } - function drawProps(f) { - if (!CITY) return; - var axis, idx, n, side, r, along, dd, kind, sd, wallC, inw, wp, kp; - for (axis = 0; axis < 2; axis++) { - for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { - streetSpan(axis, idx); - if (SPAN.w < 4) continue; - for (n = alongLo(axis, 6); n <= alongHi(axis, 6); n++) { - for (side = 0; side < 2; side++) { - r = hash2(idx * 2 + side, n, BASE ^ 0x9701); + function drawMasts(f) { + if (!CITY) return; + var axis, idx, n, side, r, along, cross, h, mh, col, row, rowTop, dd, k, ph, blink; + for (axis = 0; axis < 2; axis++) { + for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { + streetSpan(axis, idx); + for (n = alongLo(axis, 15); n <= alongHi(axis, 15); n++) { + for (side = 0; side < 2; side++) { + r = hash2(idx * 2 + side, n, BASE ^ 0x2E10); + if (r > 0.30) continue; + along = n * 15 + hash2(idx * 2 + side, n, BASE ^ 0x2E11) * 11; - if (r > 0.72) continue; - along = n * 6 + hash2(idx * 2 + side, n, BASE ^ 0x9702) * 4.6; - wallC = side ? SPAN.c1 : SPAN.c0; - inw = side ? -1 : 1; + cross = side ? SPAN.c1 + 1.0 : SPAN.c0 - 1.0; + if (!spanVisible(axis, along, cross)) continue; + h = CITY.height(wx(axis, along, cross), wz(axis, along, cross)); - dd = spanVisible(axis, along, wallC + inw, -3.2); + if (h < 11) continue; - if (!dd || dd > 44) continue; + mh = 3.5 + r * 26 + (h > 55 ? 9 : 0); + if (!project(wx(axis, along, cross), h + mh, wz(axis, along, cross))) continue; + col = Math.floor(PJ.x); rowTop = Math.floor(PJ.y); dd = PJ.d; + if (rowTop >= V.rows) continue; + if (!project(wx(axis, along, cross), h, wz(axis, along, cross))) continue; + row = Math.floor(PJ.y); + if (row - rowTop > 30) row = rowTop + 30; - if (anchorH(axis, along, wallC - inw * 0.5) < 3) continue; - sd = BASE ^ (idx * 977 + n * 6151 + side * 37); - wp = wallC + inw * 0.45; - kp = wallC + inw * 1.55; - kind = KIND[(hash2(idx * 2 + side, n, BASE ^ 0x9703) * KIND.length) | 0]; - switch (kind) { - case K_VEND: propVend(f, axis, along, wp, kp, inw, sd, dd); break; - case K_SHUTTER: propShutter(f, axis, along, wp, kp, inw, sd, dd); break; - case K_BOLLARD: propBollard(f, axis, along, wp, kp, inw, sd, dd); break; - case K_CRATES: propCrates(f, axis, along, wp, kp, inw, sd, dd); break; - case K_AC: propAC(f, axis, along, wp, kp, inw, sd, dd); break; - case K_BANNER: propBanner(f, axis, along, wp, kp, inw, sd, dd); break; - case K_CALLBOX: propCallbox(f, axis, along, wp, kp, inw, sd, dd); break; - case K_LADDER: propLadder(f, axis, along, wp, kp, inw, sd, dd); break; - case K_PLANTER: propPlanter(f, axis, along, wp, kp, inw, sd, dd); break; - case K_HOARD: propHoard(f, axis, along, wp, kp, inw, sd, dd); break; - case K_SCAFF: propScaff(f, axis, along, wp, kp, inw, sd, dd); break; - case K_SHELTER: propShelter(f, axis, along, wp, kp, inw, sd, dd); break; - case K_NEWSBOX: propNewsbox(f, axis, along, wp, kp, inw, sd, dd); break; - case K_STAIR: propStair(f, axis, along, wp, kp, inw, sd, dd); break; - case K_WASH: propWash(f, axis, along, wp, kp, inw, sd, dd); break; + for (k = rowTop + 1; k <= row; k++) + if (!((k - rowTop) & 1) || (k - rowTop) < 3) + emit(f, col, k, G_PIPE, P.slate, 26, dd); - default: propCrates(f, axis, along, wp, kp, inw, sd, dd); break; - } - } - } + if (hash2(idx * 2 + side, n, BASE ^ 0x2E13) < 0.34 && row - rowTop > 4) { + k = rowTop + 2; + emit(f, col - 1, k, G_DASH, P.slate, 22, dd); + emit(f, col + 1, k, G_DASH, P.slate, 22, dd); + emit(f, col, rowTop + 1, G_Y, P.slate, 30, dd); } + ph = V.t * 0.55 + hash2(idx * 2 + side, n, BASE ^ 0x2E14); + blink = CC.reducedMotion ? 0.72 : ((ph - Math.floor(ph)) < 0.34 ? 1 : 0.16); + emitLamp(f, col, rowTop, blink > 0.5 ? G_STAR : G_PLUS, P.red, 78 + 150 * blink, dd); + + if (mh > 22 && row - rowTop > 12) + emitLamp(f, col, rowTop + ((row - rowTop) >> 1), G_PLUS, P.red, 40 + 90 * blink, dd); + } } + } } + } - function mk(name, layer, fn) { - return { - name: name, layer: layer, + function drawEscapes(f) { + if (!CITY) return; + var axis, idx, n, side, r, along, plane, h, top, y, lev, wdt, dd, dir, a0, a1, lum, pw, flights; + for (axis = 0; axis < 2; axis++) { + for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { + streetSpan(axis, idx); + for (n = alongLo(axis, 11); n <= alongHi(axis, 11); n++) { + for (side = 0; side < 2; side++) { + r = hash2(idx * 2 + side, n, BASE ^ 0x3E5C); + if (r > 0.18) continue; + along = n * 11 + hash2(idx * 2 + side, n, BASE ^ 0x3E5D) * 7.5; + dd = spanVisible(axis, along, side ? SPAN.c1 : SPAN.c0); + if (!dd) continue; + h = anchorH(axis, along, side ? SPAN.c1 + 0.5 : SPAN.c0 - 0.5); + if (h < 12) continue; + plane = side ? SPAN.c1 - 0.42 : SPAN.c0 + 0.42; + top = h - 1.7; if (top > 21) top = 21; + wdt = 1.15 + r * 2.2; - world: 'cyber', - init: function (city, rng) { boot(city, rng); }, - draw: function (f, cam, t) { - view(f, cam, t === undefined ? (cam.t || 0) : t); - fn(f); + if (dd > 74 || dd < 12) continue; + + a0 = along - wdt; a1 = along + wdt; + if (!project(wx(axis, a0, plane), 8, wz(axis, a0, plane))) continue; + pw = PJ.x; + if (!project(wx(axis, a1, plane), 8, wz(axis, a1, plane))) continue; + pw = PJ.x - pw; if (pw < 0) pw = -pw; + if (pw < 2.2) continue; + flights = pw >= 5; + lev = 0; + for (y = 2.9; y < top; y += 3.3, lev++) { + + lum = (lev === 1 && r < 0.06) ? 62 : 33; + segment3(f, wx(axis, a0, plane), y, wz(axis, a0, plane), + wx(axis, a1, plane), y, wz(axis, a1, plane), + G_EQ, (lev === 1 && r < 0.06) ? P.amber : P.slate, lum, 3); + if (!flights || y + 3.3 >= top) continue; + + dir = (lev & 1) ? 1 : -1; + segment3(f, wx(axis, along - wdt * dir, plane), y, wz(axis, along - wdt * dir, plane), + wx(axis, along + wdt * dir, plane), y + 3.3, wz(axis, along + wdt * dir, plane), + dir > 0 ? G_SL : G_BS, P.slate, 24, 2); } - }; + } + } + } + } + } + + function drawCableRun(f, axis, along, c0, c1, yA, yB, sag, col, lum, w) { + var cnt = ((c1 - c0) * 220 / w) | 0; + if (cnt < 12) cnt = 12; if (cnt > 300) cnt = 300; + var lx = -9999, ly = -9999, i, u, cross, y, cx, cy, dy, ch, k; + for (i = 0; i <= cnt; i++) { + u = i / cnt; + cross = c0 + (c1 - c0) * u; + y = yA + (yB - yA) * u - sag * 4 * u * (1 - u); + if (!project(wx(axis, along, cross), y, wz(axis, along, cross))) { lx = -9999; continue; } + cx = Math.floor(PJ.x); cy = Math.floor(PJ.y); + if (cx === lx && cy === ly) continue; + if (lx === -9999) ch = G_DASH; + else { + dy = cy - ly; + + if (dy > 1 || dy < -1) { + for (k = ly + (dy > 0 ? 1 : -1); k !== cy; k += (dy > 0 ? 1 : -1)) + emit(f, cx, k, G_PIPE, col, lum, PJ.d); + ch = G_PIPE; + } else ch = dy === 0 ? G_DASH : (dy > 0 ? G_BS : G_SL); + } + emit(f, cx, cy, ch, col, lum, PJ.d); + lx = cx; ly = cy; + } + } + + function drawCables(f) { + if (!CITY) return; + var axis, idx, n, r, along, hA, hB, yA, yB, sag, w, tram, lum; + for (axis = 0; axis < 2; axis++) { + for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { + streetSpan(axis, idx); + + for (n = alongLo(axis, 26); n <= alongHi(axis, 26); n++) { + r = hash2(idx, n, BASE ^ 0x1CAB); + if (r > 0.26) continue; + along = n * 26 + hash2(idx, n, BASE ^ 0x1CAC) * 18; + w = spanVisible(axis, along, SPAN.mid); + if (!w) continue; + hA = anchorH(axis, along, SPAN.c0 - 0.5); + hB = anchorH(axis, along, SPAN.c1 + 0.5); + if (hA < 8 || hB < 8) continue; + yA = 6.5 + hash2(idx, n, BASE ^ 0x1CAD) * 6.5; + + yB = yA + (hash2(idx, n, BASE ^ 0x1CAE) - 0.5) * 1.2; + if (yA > hA - 1.4) yA = hA - 1.4; + if (yB > hB - 1.4) yB = hB - 1.4; + if (yA < 5 || yB < 5) continue; + sag = SPAN.w * (0.075 + hash2(idx, n, BASE ^ 0x1CAF) * 0.075); + + tram = r < 0.10; + lum = tram ? 62 : 44; + drawCableRun(f, axis, along, SPAN.c0, SPAN.c1, yA, yB, sag, P.slate, lum, w); + + if (tram && w < 46) + drawCableRun(f, axis, along, SPAN.c0, SPAN.c1, yA - 1.15, yB - 1.15, + sag * 0.55, P.slate, 34, w); + } + } + } + } + + function drawLanterns(f) { + if (!CITY) return; + var axis, idx, n, r, along, hA, hB, y, sag, w, cnt, i, u, cross, yy, hue, sd, flick, lum; + var col, row, dd, pennant, swing, ph; + for (axis = 0; axis < 2; axis++) { + for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { + streetSpan(axis, idx); + for (n = alongLo(axis, 14); n <= alongHi(axis, 14); n++) { + r = hash2(idx, n, BASE ^ 0x4A17); + if (r > 0.46) continue; + along = n * 14 + hash2(idx, n, BASE ^ 0x4A18) * 10; + w = spanVisible(axis, along, SPAN.mid); + if (!w) continue; + hA = anchorH(axis, along, SPAN.c0 - 0.5); + hB = anchorH(axis, along, SPAN.c1 + 0.5); + if (hA < 6 || hB < 6) continue; + y = 4.6 + hash2(idx, n, BASE ^ 0x4A19) * 1.9; + sag = 0.30 + r * 1.4; + sd = BASE ^ (idx * 613 + n * 4099); + + hue = (r = hash2(idx, n, BASE ^ 0x4A1B)) < 0.26 ? P.ember : (r < 0.40 ? P.warm : P.amber); + pennant = hash2(idx, n, BASE ^ 0x4A1A) < 0.34; + cnt = (SPAN.w / 1.9) | 0; if (cnt < 4) cnt = 4; + + swing = W_GUST * (0.34 + r * 0.30) * W_SWAY; + for (i = 0; i < cnt; i++) { + u = (i + 0.5) / cnt; + cross = SPAN.c0 + SPAN.w * u; + yy = y - sag * 4 * u * (1 - u); + + ph = Math.sin(V.tt * 1.25 + (sd & 31) * 0.19 + i * 0.22); + yy += swing * 0.13 * (ph > 0 ? ph : -ph); + if (!project(wx(axis, along + swing * ph, cross), yy, + wz(axis, along + swing * ph, cross))) continue; + col = Math.floor(PJ.x); row = Math.floor(PJ.y); dd = PJ.d; + + flick = CC.reducedMotion ? 0.94 + : 0.80 + 0.24 * vnoise(V.t * 1.7 + i * 0.7 + (sd & 255) * 0.13, 0x4A1); + lum = (168 + hash2(i, n, sd) * 60) * flick; + emit(f, col, row, LANTERN_G[(hash2(i, 0, sd) * 4) | 0], hue, lum, dd); + if (pennant && (i & 1)) + emit(f, col, row + 1, G_V, hue, lum * 0.26, dd); + } + } + } + } + } + + var K_VEND = 0, K_SHUTTER = 1, K_BOLLARD = 2, K_CRATES = 3, K_AC = 4, + K_BANNER = 5, K_CALLBOX = 6, K_LADDER = 7, K_PLANTER = 8, K_HOARD = 9, K_SCAFF = 10, + K_SHELTER = 11, K_NEWSBOX = 12, K_STAIR = 13, K_WASH = 14; + + var KIND = new Uint8Array([ + K_VEND, K_VEND, K_VEND, K_VEND, K_VEND, + K_CRATES, K_CRATES, K_CRATES, + K_SHUTTER, K_SHUTTER, + K_BOLLARD, K_BOLLARD, + K_AC, K_AC, + K_CALLBOX, K_CALLBOX, + K_PLANTER, K_NEWSBOX, + K_LADDER, K_BANNER, + K_STAIR, K_SHELTER, K_HOARD, K_WASH, K_SCAFF + ]); + + var STY_FLAT = 0, STY_RIB = 1, STY_MESH = 2; + + var CLIP = { u0: 0, u1: 1 }; + function clipNear(axis, a0, a1, cross) { + var rx = wx(axis, a0, cross) - V.ox, rz = wz(axis, a0, cross) - V.oz; + var g0 = rx * V.fwx + rz * V.fwz - 0.42; + rx = wx(axis, a1, cross) - V.ox; rz = wz(axis, a1, cross) - V.oz; + var g1 = rx * V.fwx + rz * V.fwz - 0.42; + if (g0 < 0 && g1 < 0) return false; + CLIP.u0 = 0; CLIP.u1 = 1; + if (g0 < 0) CLIP.u0 = g0 / (g0 - g1); + else if (g1 < 0) CLIP.u1 = g0 / (g0 - g1); + return true; + } + + function panel(f, axis, a0, a1, cross, y0, y1, ch, col, lum, jit, sty, sd) { + if (!clipNear(axis, a0, a1, cross)) return; + var b0 = a0 + (a1 - a0) * CLIP.u0, b1 = a0 + (a1 - a0) * CLIP.u1; + var rx = wx(axis, b0, cross) - V.ox, rz = wz(axis, b0, cross) - V.oz; + var w0 = rx * V.fwx + rz * V.fwz, s0 = rx * V.rgx + rz * V.rgz; + rx = wx(axis, b1, cross) - V.ox; rz = wz(axis, b1, cross) - V.oz; + var w1 = rx * V.fwx + rz * V.fwz, s1 = rx * V.rgx + rz * V.rgz; + var dw = w1 - w0, ds = s1 - s0; + var xa = s0 / w0 * V.colK + V.colMid, xb = s1 / w1 * V.colK + V.colMid; + var j0 = Math.floor(xa < xb ? xa : xb), j1 = Math.floor(xa < xb ? xb : xa); + if (j1 < 0 || j0 >= V.cols) return; + if (j0 < 0) j0 = 0; + if (j1 > V.cols - 1) j1 = V.cols - 1; + var j, sp, den, u, a, rt, rb, r0, r1, row, dd, lat, l, tmp, pat, fade; + for (j = j0; j <= j1; j++) { + sp = (j + 0.5 - V.colMid) / V.colK; + den = sp * dw - ds; + + u = (den > 1e-9 || den < -1e-9) ? (s0 - sp * w0) / den : 0.5; + if (u < 0) u = 0; else if (u > 1) u = 1; + a = b0 + (b1 - b0) * u; + if (!project(wx(axis, a, cross), y1, wz(axis, a, cross))) continue; + rt = PJ.y; dd = PJ.d; + + fade = (dd - 1.2) * 0.5556; + if (fade <= 0) continue; + if (fade > 1) fade = 1; + if (!project(wx(axis, a, cross), y0, wz(axis, a, cross))) continue; + rb = PJ.y; + r0 = Math.floor(rt); r1 = Math.floor(rb); + if (r1 < r0) { tmp = r0; r0 = r1; r1 = tmp; } + + pat = r0; + + if (r0 < -1) r0 = -1; + if (r1 > V.rows) r1 = V.rows; + lat = Math.floor(a * 4.7) + (sd & 15); + for (row = r0; row <= r1; row++) { + + if (fade < 1 && hash2(lat, row - pat, sd + 0x51) > fade) continue; + l = lum; + if (sty === STY_RIB) { if ((row - pat) & 1) l *= 0.32; } + else if (sty === STY_MESH && ((lat + row - pat) & 1)) continue; + if (jit) l += hash2(lat, row - pat, sd) * jit; + emit(f, j, row, ch, col, l, dd); + } + } + } + + function pcell(f, axis, a, cross, y, ch, col, lum, bias) { + if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) return; + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), ch, col, lum, PJ.d * bias); + } + + function propVend(f, axis, a, wp, kp, inw, sd, dd) { + var q = hash2(1, 0, sd); + + var hue = q < 0.44 ? P.azure : (q < 0.82 ? P.amber : P.spring); + panel(f, axis, a - 0.44, a + 0.44, wp, 0.60, 1.74, G_8, hue, 92, 58, STY_FLAT, sd); + panel(f, axis, a - 0.58, a + 0.58, wp - inw * 0.05, 0, 2.04, 0, P.shadow, 0, 0, STY_FLAT, sd); + + panel(f, axis, a - 0.58, a + 0.58, wp - inw * 0.05, 1.98, 2.06, G_EQ, P.slate, 40, 0, STY_FLAT, sd); + + var wl = 26 + 30 * W_WET; + pcell(f, axis, a - 0.30, wp + inw * 0.55, 0.02, G_COMMA, hue, wl, 0.985); + pcell(f, axis, a, wp + inw * 0.75, 0.02, G_COLON, hue, wl * 1.2, 0.985); + pcell(f, axis, a + 0.30, wp + inw * 0.55, 0.02, G_DOT, hue, wl, 0.985); + } + + function propShutter(f, axis, a, wp, kp, inw, sd, dd) { + + panel(f, axis, a - 1.30, a + 1.30, wp, 0.18, 0.48, G_UNDER, P.warm, 76, 30, STY_MESH, sd); + panel(f, axis, a - 1.35, a + 1.35, wp - inw * 0.05, 0, 1.16, 0, P.shadow, 0, 0, STY_FLAT, sd); + panel(f, axis, a - 1.40, a + 1.40, wp, 1.16, 2.72, G_EQ, P.slate, 30, 10, STY_RIB, sd); + + panel(f, axis, a - 1.40, a + 1.40, wp + inw * 0.03, 1.16, 1.24, G_DASH, P.slate, 54, 0, STY_FLAT, sd); + pcell(f, axis, a, wp + inw * 0.6, 0.02, G_COLON, P.warm, 30 + 26 * W_WET, 0.985); + } + + function propBollard(f, axis, a, wp, kp, inw, sd, dd) { + + var i, aa; + for (i = 0; i < 4; i++) { + aa = a - 1.65 + i * 1.1; + segment3(f, wx(axis, aa, kp), 0.02, wz(axis, aa, kp), + wx(axis, aa, kp), 0.86, wz(axis, aa, kp), G_PIPE, P.slate, 34, 1); + + pcell(f, axis, aa, kp, 0.90, G_oo, P.white, 74, 1); + } + } + + function propCrates(f, axis, a, wp, kp, inw, sd, dd) { + + var hL = 1.26, hR = 0.94 + hash2(3, 0, sd) * 0.22; + panel(f, axis, a - 0.85, a - 0.34, wp - inw * 0.05, 0, hL, G_HASH, P.shadow, 16, 8, STY_FLAT, sd); + panel(f, axis, a - 0.85, a - 0.34, wp, hL - 0.08, hL + 0.02, G_EQ, P.slate, 44, 0, STY_FLAT, sd); + panel(f, axis, a - 0.34, a + 0.15, wp - inw * 0.05, 0, hR, G_HASH, P.shadow, 14, 8, STY_FLAT, sd); + panel(f, axis, a - 0.34, a + 0.15, wp, hR - 0.08, hR + 0.02, G_EQ, P.slate, 36, 0, STY_FLAT, sd); + panel(f, axis, a + 0.15, a + 0.92, wp - inw * 0.05, 0, 0.62, G_oo, P.shadow, 14, 8, STY_FLAT, sd); + + if (hash2(4, 0, sd) < 0.4) { + panel(f, axis, a - 0.78, a - 0.40, wp + inw * 0.10, hL, hL + 0.44, G_HASH, P.shadow, 15, 8, STY_FLAT, sd); + panel(f, axis, a - 0.78, a - 0.40, wp + inw * 0.10, hL + 0.36, hL + 0.46, G_EQ, P.slate, 38, 0, STY_FLAT, sd); + } + } + + function propAC(f, axis, a, wp, kp, inw, sd, dd) { + + panel(f, axis, a - 0.40, a + 0.40, wp + inw * 0.15, 3.22, 3.68, G_EQ, P.slate, 32, 0, STY_RIB, sd); + panel(f, axis, a - 0.46, a + 0.46, wp + inw * 0.10, 3.05, 3.86, G_HASH, P.slate, 22, 10, STY_FLAT, sd); + + if (!CC.reducedMotion) { + var ph = V.t * 0.62 + (sd & 31) * 0.19, k = Math.floor(ph), fr = ph - k; + if (hash2(k, 0, sd + 11) < 0.22 + 0.46 * W_WET) + pcell(f, axis, a + 0.12, wp + inw * 0.18, 3.02 - fr * fr * 3.0, G_QUOTE, P.ice, 96, 1); } - CC.ELEMENTS.push(mk('streetprops', 19, drawProps)); - CC.ELEMENTS.push(mk('skybridges', 20, drawBridges)); - CC.ELEMENTS.push(mk('rooftop-plant', 21, drawPlant)); - CC.ELEMENTS.push(mk('masts', 22, drawMasts)); - CC.ELEMENTS.push(mk('fire-escapes', 23, drawEscapes)); - CC.ELEMENTS.push(mk('cables', 24, drawCables)); - CC.ELEMENTS.push(mk('lanterns', 26, drawLanterns)); + if (W_WET > 0.5) + pcell(f, axis, a + 0.12, wp + inw * 0.35, 0.02, G_COMMA, P.ice, 16 + 18 * W_WET, 0.985); + } + + function propBanner(f, axis, a, wp, kp, inw, sd, dd) { + + var q = hash2(6, 0, sd); + var hue = q < 0.44 ? P.ember : (q < 0.84 ? P.amber : P.violet); + var p = wp + inw * 0.42, i, y, s, amp = W_GUST * 0.40 * W_SWAY, ph = (sd & 63) * 0.11; + segment3(f, wx(axis, a, wp - inw * 0.3), 4.02, wz(axis, a, wp - inw * 0.3), + wx(axis, a, p), 4.02, wz(axis, a, p), G_DASH, P.slate, 32, 1); + for (i = 0; i < 9; i++) { + y = 3.92 - i * 0.20; + + s = amp * (i / 8) * (i / 8) * Math.sin(V.tt * 1.45 + ph + i * 0.30); + segment3(f, wx(axis, a - 0.26 + s, p), y, wz(axis, a - 0.26 + s, p), + wx(axis, a + 0.26 + s, p), y, wz(axis, a + 0.26 + s, p), + i === 8 ? G_V : G_8, hue, i === 8 ? 46 : 62 + hash2(i, 0, sd) * 40, 1); + } + } + + function propCallbox(f, axis, a, wp, kp, inw, sd, dd) { + + panel(f, axis, a - 0.26, a + 0.26, wp, 1.48, 2.06, G_8, P.azure, 104, 40, STY_FLAT, sd); + panel(f, axis, a - 0.40, a + 0.40, wp - inw * 0.05, 0, 2.28, 0, P.shadow, 0, 0, STY_FLAT, sd); + panel(f, axis, a - 0.40, a + 0.40, wp - inw * 0.05, 2.22, 2.30, G_EQ, P.slate, 38, 0, STY_FLAT, sd); + var ph = V.t * 0.31 + (sd & 15) * 0.21; ph -= Math.floor(ph); + pcell(f, axis, a, wp, 2.42, G_oo, P.ember, + CC.reducedMotion ? 96 : (ph < 0.5 ? 150 : 44), 1); + pcell(f, axis, a, wp + inw * 0.5, 0.02, G_COLON, P.azure, 18 + 20 * W_WET, 0.985); + } + + function propLadder(f, axis, a, wp, kp, inw, sd, dd) { + + var p = wp + inw * 0.08, i, y, top = 4.6 + hash2(7, 0, sd) * 1.6; + segment3(f, wx(axis, a - 0.26, p), 0.1, wz(axis, a - 0.26, p), + wx(axis, a - 0.26, p), top, wz(axis, a - 0.26, p), G_PIPE, P.slate, 30, 1); + segment3(f, wx(axis, a + 0.26, p), 0.1, wz(axis, a + 0.26, p), + wx(axis, a + 0.26, p), top, wz(axis, a + 0.26, p), G_PIPE, P.slate, 30, 1); + for (y = 0.45; y < top; y += 0.52) + segment3(f, wx(axis, a - 0.26, p), y, wz(axis, a - 0.26, p), + wx(axis, a + 0.26, p), y, wz(axis, a + 0.26, p), G_DASH, P.slate, 26, 1); + } + + function propPlanter(f, axis, a, wp, kp, inw, sd, dd) { + + panel(f, axis, a - 0.70, a + 0.70, kp, 0, 0.54, G_HASH, P.slate, 24, 8, STY_FLAT, sd); + panel(f, axis, a - 0.70, a + 0.70, kp, 0.50, 0.58, G_EQ, P.slate, 46, 0, STY_FLAT, sd); + var i, aa, y; + for (i = 0; i < 7; i++) { + aa = a - 0.55 + hash2(i, 1, sd) * 1.1; + y = 0.62 + hash2(i, 2, sd) * 0.72; + pcell(f, axis, aa, kp + inw * (hash2(i, 3, sd) - 0.5) * 0.3, y, + hash2(i, 4, sd) < 0.5 ? G_AMP : G_PCT, P.spring, 34 + hash2(i, 5, sd) * 30, 1); + } + } + + function propHoard(f, axis, a, wp, kp, inw, sd, dd) { + + panel(f, axis, a - 2.1, a + 2.1, kp, 0, 2.16, 0, P.shadow, 0, 0, STY_FLAT, sd); + panel(f, axis, a - 2.1, a + 2.1, kp, 2.10, 2.18, G_EQ, P.slate, 36, 0, STY_FLAT, sd); + + panel(f, axis, a - 2.0, a + 2.0, kp + inw * 0.02, 1.72, 1.88, G_SL, P.ember, 30, 12, STY_MESH, sd); + var ph = V.t * 1.05 + (sd & 31) * 0.13; ph -= Math.floor(ph); + pcell(f, axis, a + 1.9, kp, 2.34, G_0, P.amber, + CC.reducedMotion ? 110 : (ph < 0.34 ? 208 : 30), 1); + pcell(f, axis, a + 1.9, kp + inw * 0.4, 0.02, G_COLON, P.amber, + (CC.reducedMotion ? 22 : (ph < 0.34 ? 44 : 8)) * (0.6 + W_WET * 0.8), 0.985); + } + + function propScaff(f, axis, a, wp, kp, inw, sd, dd) { + + var p = wp + inw * 0.55, i, y, aa, top = 6.4 + hash2(8, 0, sd) * 3.4; + for (i = 0; i < 3; i++) { + aa = a - 1.9 + i * 1.85; + segment3(f, wx(axis, aa, p), 0.05, wz(axis, aa, p), + wx(axis, aa, p), top, wz(axis, aa, p), G_PIPE, P.slate, 30, 2); + } + for (y = 2.3; y < top; y += 2.4) { + segment3(f, wx(axis, a - 1.9, p), y, wz(axis, a - 1.9, p), + wx(axis, a + 1.8, p), y, wz(axis, a + 1.8, p), G_EQ, P.slate, 34, 2); + + segment3(f, wx(axis, a - 1.9, p), y - 2.4, wz(axis, a - 1.9, p), + wx(axis, a - 0.05, p), y, wz(axis, a - 0.05, p), G_SL, P.slate, 22, 3); + } + + panel(f, axis, a - 1.9, a + 1.8, p + inw * 0.06, 0.1, 2.3, G_COLON, P.slate, 18, 6, STY_MESH, sd); + } + + function propShelter(f, axis, a, wp, kp, inw, sd, dd) { + + var p = kp; + panel(f, axis, a - 1.05, a - 0.05, p, 0.55, 2.10, G_8, P.azure, 96, 46, STY_FLAT, sd); + panel(f, axis, a - 1.05, a - 0.05, p - inw * 0.05, 0, 2.20, 0, P.shadow, 0, 0, STY_FLAT, sd); + panel(f, axis, a - 1.75, a + 1.75, p, 2.28, 2.44, G_EQ, P.slate, 38, 0, STY_FLAT, sd); + segment3(f, wx(axis, a + 1.70, p), 0.05, wz(axis, a + 1.70, p), + wx(axis, a + 1.70, p), 2.28, wz(axis, a + 1.70, p), G_PIPE, P.slate, 30, 1); + segment3(f, wx(axis, a - 1.70, p), 0.05, wz(axis, a - 1.70, p), + wx(axis, a - 1.70, p), 2.28, wz(axis, a - 1.70, p), G_PIPE, P.slate, 30, 1); + segment3(f, wx(axis, a + 0.15, p - inw * 0.2), 0.45, wz(axis, a + 0.15, p - inw * 0.2), + wx(axis, a + 1.60, p - inw * 0.2), 0.45, wz(axis, a + 1.60, p - inw * 0.2), + G_UNDER, P.slate, 30, 1); + pcell(f, axis, a - 0.55, p + inw * 0.7, 0.02, G_COLON, P.azure, 24 + 30 * W_WET, 0.985); + } + + function propNewsbox(f, axis, a, wp, kp, inw, sd, dd) { + + panel(f, axis, a - 0.26, a + 0.26, kp, 0.42, 0.96, G_8, P.ember, 64, 26, STY_FLAT, sd); + panel(f, axis, a - 0.30, a + 0.30, kp - inw * 0.05, 0, 1.06, 0, P.shadow, 0, 0, STY_FLAT, sd); + panel(f, axis, a - 0.30, a + 0.30, kp - inw * 0.05, 1.00, 1.08, G_DASH, P.slate, 40, 0, STY_FLAT, sd); + } + + function propStair(f, axis, a, wp, kp, inw, sd, dd) { + + var i, j, c, aa, l, hue = hash2(9, 0, sd) < 0.7 ? P.warm : P.spring; + + for (i = 0; i < 6; i++) { + c = wp + inw * (0.22 + i * 0.30); + l = 118 - i * 19; + for (j = 0; j < 5; j++) { + aa = a - 0.86 + j * 0.43; + pcell(f, axis, aa, c, 0.02, i === 0 ? G_8 : G_EQ, hue, l, 0.985); + } + } + + segment3(f, wx(axis, a - 0.95, wp + inw * 1.65), 0.98, wz(axis, a - 0.95, wp + inw * 1.65), + wx(axis, a + 0.95, wp + inw * 1.65), 0.98, wz(axis, a + 0.95, wp + inw * 1.65), + G_DASH, P.slate, 44, 1); + segment3(f, wx(axis, a + 0.95, wp + inw * 1.65), 0.05, wz(axis, a + 0.95, wp + inw * 1.65), + wx(axis, a + 0.95, wp + inw * 1.65), 1.02, wz(axis, a + 0.95, wp + inw * 1.65), + G_PIPE, P.slate, 36, 1); + } + + function propWash(f, axis, a, wp, kp, inw, sd, dd) { + + var p = wp + inw * 0.35, i, aa, s, y, amp = W_GUST * 0.34 * W_SWAY, ph = (sd & 31) * 0.2; + + segment3(f, wx(axis, a - 1.9, p), 4.32, wz(axis, a - 1.9, p), + wx(axis, a + 1.9, p), 4.30, wz(axis, a + 1.9, p), G_DASH, P.slate, 30, 1); + + if (W_RAIN > 0.6) return; + for (i = 0; i < 4; i++) { + aa = a - 1.35 + i * 0.9; + s = amp * Math.sin(V.tt * 1.2 + ph + i * 0.8); + for (y = 4.18; y > 3.35; y -= 0.20) { + segment3(f, wx(axis, aa - 0.18 + s, p), y, wz(axis, aa - 0.18 + s, p), + wx(axis, aa + 0.18 + s, p), y, wz(axis, aa + 0.18 + s, p), + G_8, i & 1 ? P.white : P.slate, 40 + hash2(i, (y * 5) | 0, sd) * 22, 1); + } + } + } + + function drawProps(f) { + if (!CITY) return; + var axis, idx, n, side, r, along, dd, kind, sd, wallC, inw, wp, kp; + for (axis = 0; axis < 2; axis++) { + for (idx = idxLo(axis); idx <= idxHi(axis); idx++) { + streetSpan(axis, idx); + if (SPAN.w < 4) continue; + for (n = alongLo(axis, 6); n <= alongHi(axis, 6); n++) { + for (side = 0; side < 2; side++) { + r = hash2(idx * 2 + side, n, BASE ^ 0x9701); + + if (r > 0.72) continue; + along = n * 6 + hash2(idx * 2 + side, n, BASE ^ 0x9702) * 4.6; + wallC = side ? SPAN.c1 : SPAN.c0; + inw = side ? -1 : 1; + + dd = spanVisible(axis, along, wallC + inw, -3.2); + + if (!dd || dd > 44) continue; + + if (anchorH(axis, along, wallC - inw * 0.5) < 3) continue; + sd = BASE ^ (idx * 977 + n * 6151 + side * 37); + wp = wallC + inw * 0.45; + kp = wallC + inw * 1.55; + kind = KIND[(hash2(idx * 2 + side, n, BASE ^ 0x9703) * KIND.length) | 0]; + switch (kind) { + case K_VEND: propVend(f, axis, along, wp, kp, inw, sd, dd); break; + case K_SHUTTER: propShutter(f, axis, along, wp, kp, inw, sd, dd); break; + case K_BOLLARD: propBollard(f, axis, along, wp, kp, inw, sd, dd); break; + case K_CRATES: propCrates(f, axis, along, wp, kp, inw, sd, dd); break; + case K_AC: propAC(f, axis, along, wp, kp, inw, sd, dd); break; + case K_BANNER: propBanner(f, axis, along, wp, kp, inw, sd, dd); break; + case K_CALLBOX: propCallbox(f, axis, along, wp, kp, inw, sd, dd); break; + case K_LADDER: propLadder(f, axis, along, wp, kp, inw, sd, dd); break; + case K_PLANTER: propPlanter(f, axis, along, wp, kp, inw, sd, dd); break; + case K_HOARD: propHoard(f, axis, along, wp, kp, inw, sd, dd); break; + case K_SCAFF: propScaff(f, axis, along, wp, kp, inw, sd, dd); break; + case K_SHELTER: propShelter(f, axis, along, wp, kp, inw, sd, dd); break; + case K_NEWSBOX: propNewsbox(f, axis, along, wp, kp, inw, sd, dd); break; + case K_STAIR: propStair(f, axis, along, wp, kp, inw, sd, dd); break; + case K_WASH: propWash(f, axis, along, wp, kp, inw, sd, dd); break; + + default: propCrates(f, axis, along, wp, kp, inw, sd, dd); break; + } + } + } + } + } + } + + function mk(name, layer, fn) { + return { + name: name, layer: layer, + + world: 'cyber', + init: function (city, rng) { boot(city, rng); }, + draw: function (f, cam, t) { + view(f, cam, t === undefined ? (cam.t || 0) : t); + fn(f); + } + }; + } + + CC.ELEMENTS.push(mk('streetprops', 19, drawProps)); + CC.ELEMENTS.push(mk('skybridges', 20, drawBridges)); + CC.ELEMENTS.push(mk('rooftop-plant', 21, drawPlant)); + CC.ELEMENTS.push(mk('masts', 22, drawMasts)); + CC.ELEMENTS.push(mk('fire-escapes', 23, drawEscapes)); + CC.ELEMENTS.push(mk('cables', 24, drawCables)); + CC.ELEMENTS.push(mk('lanterns', 26, drawLanterns)); })(CC); /* src/elements/weather.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, put = CC.put, hash1 = CC.hash1, hash2 = CC.hash2, - clamp = CC.clamp, lerp = CC.lerp, smooth = CC.smooth, vnoise = CC.vnoise; + var P = CC.P, put = CC.put, hash1 = CC.hash1, hash2 = CC.hash2, + clamp = CC.clamp, lerp = CC.lerp, smooth = CC.smooth, vnoise = CC.vnoise; - var G_PIPE = CC.g('|'), G_SLASH = CC.g('/'), G_BSL = CC.g('\\'), G_DOT = CC.g('.'), - G_COMMA = CC.g(','), G_COLON = CC.g(':'), G_QUOTE = CC.g("'"), G_TICK = CC.g('`'), - G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_TILDE = CC.g('~'), G_STAR = CC.g('*'), - G_SEMI = CC.g(';'), G_EQ = CC.g('='); + var G_PIPE = CC.g('|'), G_SLASH = CC.g('/'), G_BSL = CC.g('\\'), G_DOT = CC.g('.'), + G_COMMA = CC.g(','), G_COLON = CC.g(':'), G_QUOTE = CC.g("'"), G_TICK = CC.g('`'), + G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_TILDE = CC.g('~'), G_STAR = CC.g('*'), + G_SEMI = CC.g(';'), G_EQ = CC.g('='); - var REF_RAIN = 0.65, REF_WIND = 0.55, REF_FOG = 0.30, REF_WET = 0.90, - REF_STORM = 0.12, REF_HAZE = 0.40, REF_CLOUD = 0.75, REF_STEAM = 0.85; + var REF_RAIN = 0.65, REF_WIND = 0.55, REF_FOG = 0.30, REF_WET = 0.90, + REF_STORM = 0.12, REF_HAZE = 0.40, REF_CLOUD = 0.75, REF_STEAM = 0.85; - var WFALL = { rain: REF_RAIN, wind: REF_WIND, fog: REF_FOG, wet: REF_WET, - storm: REF_STORM, haze: REF_HAZE, cloud: REF_CLOUD, steam: REF_STEAM }; + var WFALL = { rain: REF_RAIN, wind: REF_WIND, fog: REF_FOG, wet: REF_WET, + storm: REF_STORM, haze: REF_HAZE, cloud: REF_CLOUD, steam: REF_STEAM }; - var pRain = REF_RAIN, pWind = REF_WIND, pFog = REF_FOG, pWet = REF_WET, - pStorm = REF_STORM, pHaze = REF_HAZE, pCloud = REF_CLOUD, pSteam = REF_STEAM; + var pRain = REF_RAIN, pWind = REF_WIND, pFog = REF_FOG, pWet = REF_WET, + pStorm = REF_STORM, pHaze = REF_HAZE, pCloud = REF_CLOUD, pSteam = REF_STEAM; - var dRain = 1, dWind = 1, dFog = 1, dSteam = 1; + var dRain = 1, dWind = 1, dFog = 1, dSteam = 1; - var wChill = 0, wSleet = 0, wBreath = 0; + var wChill = 0, wSleet = 0, wBreath = 0; - var WIND = { x: 0.0, z: 0.0, dirX: 0.0, dirZ: 1.0, base: 0.0, speed: 0.0, gust: 0.55, mult: 1.0 }; - var WBASE = 2.4, windWorld, wSeed = 0; - function initWind(rng) { - if (windWorld === WCITY) return; - windWorld = WCITY; - var a = rng() * 6.283185; - WBASE = 1.6 + rng() * 2.6; - WIND.dirX = Math.cos(a); WIND.dirZ = Math.sin(a); - wSeed = smallSeed(rng); - wxT = -1e9; - } + var WIND = { x: 0.0, z: 0.0, dirX: 0.0, dirZ: 1.0, base: 0.0, speed: 0.0, gust: 0.55, mult: 1.0 }; + var WBASE = 2.4, windWorld, wSeed = 0; + function initWind(rng) { + if (windWorld === WCITY) return; + windWorld = WCITY; + var a = rng() * 6.283185; + WBASE = 1.6 + rng() * 2.6; + WIND.dirX = Math.cos(a); WIND.dirZ = Math.sin(a); + wSeed = smallSeed(rng); + wxT = -1e9; + } - var wxT = -1e9; - function syncWeather(t) { - if (t === wxT) return; - wxT = t; + var wxT = -1e9; + function syncWeather(t) { + if (t === wxT) return; + wxT = t; - var W = (CC.Weather && CC.Weather.P) || WFALL; - if (CC.Weather && CC.Weather.wind !== WIND) CC.Weather.wind = WIND; - pRain = W.rain; pWind = W.wind; pFog = W.fog; pWet = W.wet; - pStorm = W.storm; pHaze = W.haze; pCloud = W.cloud; pSteam = W.steam; - dRain = pRain / REF_RAIN; dWind = pWind / REF_WIND; - dFog = pFog / REF_FOG; dSteam = pSteam / REF_STEAM; + var W = (CC.Weather && CC.Weather.P) || WFALL; + if (CC.Weather && CC.Weather.wind !== WIND) CC.Weather.wind = WIND; + pRain = W.rain; pWind = W.wind; pFog = W.fog; pWet = W.wet; + pStorm = W.storm; pHaze = W.haze; pCloud = W.cloud; pSteam = W.steam; + dRain = pRain / REF_RAIN; dWind = pWind / REF_WIND; + dFog = pFog / REF_FOG; dSteam = pSteam / REF_STEAM; - var gt = CC.reducedMotion ? 0 : t; - var raw = vnoise(gt * 0.107 + 4.1, wSeed + 3) * 0.68 + vnoise(gt * 0.39, wSeed + 8) * 0.32; - var amp = clamp(dWind, 0, 1.85) * (CC.reducedMotion ? 0.12 : 1); - var g = 1 + (raw - 0.5) * 1.30 * amp; + var gt = CC.reducedMotion ? 0 : t; + var raw = vnoise(gt * 0.107 + 4.1, wSeed + 3) * 0.68 + vnoise(gt * 0.39, wSeed + 8) * 0.32; + var amp = clamp(dWind, 0, 1.85) * (CC.reducedMotion ? 0.12 : 1); + var g = 1 + (raw - 0.5) * 1.30 * amp; - if (g < 0.30) g = 0.30; - WIND.mult = g; + if (g < 0.30) g = 0.30; + WIND.mult = g; - WIND.gust = clamp(pWind * g, 0, 1.6); - WIND.base = WBASE * (0.35 + 0.65 * clamp(dWind, 0, 1.85)); - WIND.speed = WIND.base * g; - WIND.x = WIND.dirX * WIND.speed; WIND.z = WIND.dirZ * WIND.speed; + WIND.gust = clamp(pWind * g, 0, 1.6); + WIND.base = WBASE * (0.35 + 0.65 * clamp(dWind, 0, 1.85)); + WIND.speed = WIND.base * g; + WIND.x = WIND.dirX * WIND.speed; WIND.z = WIND.dirZ * WIND.speed; - var cf = vnoise(t * 0.0037 + 11.3, wSeed + 17) * 0.66 + vnoise(t * 0.0119, wSeed + 23) * 0.34; - cf *= cf; - wChill = clamp(0.10 + cf * 1.05 - pRain * 0.25 + (pFog + pHaze) * 0.20, 0, 1); + var cf = vnoise(t * 0.0037 + 11.3, wSeed + 17) * 0.66 + vnoise(t * 0.0119, wSeed + 23) * 0.34; + cf *= cf; + wChill = clamp(0.10 + cf * 1.05 - pRain * 0.25 + (pFog + pHaze) * 0.20, 0, 1); - wSleet = clamp((wChill - 0.68) / 0.25, 0, 1) * clamp(pRain / 0.30, 0, 1); - wBreath = clamp((wChill - 0.50) / 0.28, 0, 1); - } + wSleet = clamp((wChill - 0.68) / 0.25, 0, 1) * clamp(pRain / 0.30, 0, 1); + wBreath = clamp((wChill - 0.50) / 0.28, 0, 1); + } - var vCols = 0, vHorizon = 0, vScale = 0, vHalf = 0, vCellA = 0.5625, - vEyeY = 1.7, vX = 0, vZ = 0, vFwx = 0, vFwz = 1, vRgx = 1, vRgz = 0, vFar = 125; - var SURF = null; + var vCols = 0, vHorizon = 0, vScale = 0, vHalf = 0, vCellA = 0.5625, + vEyeY = 1.7, vX = 0, vZ = 0, vFwx = 0, vFwz = 1, vRgx = 1, vRgz = 0, vFar = 125; + var SURF = null; - function bindView(frame, cam) { - SURF = CC.Surf || null; - vCols = frame.cols; - var fov = cam.fov || 1.25; - vHalf = Math.tan(fov * 0.5); - vHorizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; - vEyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - vCellA = cam.cellAspect || 0.5625; - vScale = cam.scaleY !== undefined ? cam.scaleY : (frame.cols * vCellA) / (2 * vHalf); - var yaw = cam.yaw || 0; - vFwx = Math.sin(yaw); vFwz = Math.cos(yaw); - vRgx = Math.cos(yaw); vRgz = -Math.sin(yaw); - vX = cam.x; vZ = cam.z; - vFar = SURF ? SURF.FOG_END : 125; - } + function bindView(frame, cam) { + SURF = CC.Surf || null; + vCols = frame.cols; + var fov = cam.fov || 1.25; + vHalf = Math.tan(fov * 0.5); + vHorizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; + vEyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + vCellA = cam.cellAspect || 0.5625; + vScale = cam.scaleY !== undefined ? cam.scaleY : (frame.cols * vCellA) / (2 * vHalf); + var yaw = cam.yaw || 0; + vFwx = Math.sin(yaw); vFwz = Math.cos(yaw); + vRgx = Math.cos(yaw); vRgz = -Math.sin(yaw); + vX = cam.x; vZ = cam.z; + vFar = SURF ? SURF.FOG_END : 125; + } - function fogLum(lum, dist) { return SURF ? SURF.fog(lum, dist) : lum; } + function fogLum(lum, dist) { return SURF ? SURF.fog(lum, dist) : lum; } - var pjW = 0, pjX = 0, pjY = 0, pjD = 0; + var pjW = 0, pjX = 0, pjY = 0, pjD = 0; - function project(wx, wy, wz) { - var rx = wx - vX, rz = wz - vZ; - var w = rx * vFwx + rz * vFwz; - if (w < 0.45 || w > vFar) return 0; - var r = rx * vRgx + rz * vRgz; - var sp = r / w; - if (sp < -vHalf * 1.25 || sp > vHalf * 1.25) return 0; - pjW = w; - pjX = (sp / vHalf + 1) * 0.5 * vCols - 0.5; - pjY = vHorizon - (wy - vEyeY) * vScale / w; - pjD = Math.sqrt(w * w + r * r); - return 1; - } + function project(wx, wy, wz) { + var rx = wx - vX, rz = wz - vZ; + var w = rx * vFwx + rz * vFwz; + if (w < 0.45 || w > vFar) return 0; + var r = rx * vRgx + rz * vRgz; + var sp = r / w; + if (sp < -vHalf * 1.25 || sp > vHalf * 1.25) return 0; + pjW = w; + pjX = (sp / vHalf + 1) * 0.5 * vCols - 0.5; + pjY = vHorizon - (wy - vEyeY) * vScale / w; + pjD = Math.sqrt(w * w + r * r); + return 1; + } - function wrap(v, b) { return v - b * Math.floor(v / b + 0.5); } - function frac(v) { return v - Math.floor(v); } + function wrap(v, b) { return v - b * Math.floor(v / b + 0.5); } + function frac(v) { return v - Math.floor(v); } - function smallSeed(rng) { return (rng() * 30011) | 0; } + function smallSeed(rng) { return (rng() * 30011) | 0; } - function fork(rng) { return CC.mulberry(((rng() * 4294967296) | 0) ^ 0x5C1E); } + function fork(rng) { return CC.mulberry(((rng() * 4294967296) | 0) ^ 0x5C1E); } - function n2(x, z, s) { - var xi = Math.floor(x), zi = Math.floor(z); - var fx = smooth(x - xi), fz = smooth(z - zi); - return lerp(lerp(hash2(xi, zi, s), hash2(xi + 1, zi, s), fx), - lerp(hash2(xi, zi + 1, s), hash2(xi + 1, zi + 1, s), fx), fz); - } + function n2(x, z, s) { + var xi = Math.floor(x), zi = Math.floor(z); + var fx = smooth(x - xi), fz = smooth(z - zi); + return lerp(lerp(hash2(xi, zi, s), hash2(xi + 1, zi, s), fx), + lerp(hash2(xi, zi + 1, s), hash2(xi + 1, zi + 1, s), fx), fz); + } - var RN_MAX = 4200, RN_AT_REF = 640, REF_CELLS = 200 * 60; - var rOx = null, rOz = null, rBox = null, rSpd = null, rPh = null, rHue = null, rFall = null; - var rainT = 0; + var RN_MAX = 4200, RN_AT_REF = 640, REF_CELLS = 200 * 60; + var rOx = null, rOz = null, rBox = null, rSpd = null, rPh = null, rHue = null, rFall = null; + var rainT = 0; - var WCITY = null; - function bindWorld(city, rng) { WCITY = city || null; initWind(rng); } + var WCITY = null; + function bindWorld(city, rng) { WCITY = city || null; initWind(rng); } - var wetEma = REF_WET, wetLastT = -1e9, dripAmt = 0; - function wetIntegrate(dt, t) { - if (t < wetLastT - 0.001) wetEma = pWet; - wetLastT = t; - if (!(dt > 0)) return; - if (dt > 0.1) dt = 0.1; - var k = dt / (pWet > wetEma ? 3.0 : 42.0); - if (k > 1) k = 1; - wetEma += (pWet - wetEma) * k; + var wetEma = REF_WET, wetLastT = -1e9, dripAmt = 0; + function wetIntegrate(dt, t) { + if (t < wetLastT - 0.001) wetEma = pWet; + wetLastT = t; + if (!(dt > 0)) return; + if (dt > 0.1) dt = 0.1; + var k = dt / (pWet > wetEma ? 3.0 : 42.0); + if (k > 1) k = 1; + wetEma += (pWet - wetEma) * k; - dripAmt = clamp((wetEma - 0.22) / 0.52, 0, 1); - } + dripAmt = clamp((wetEma - 0.22) / 0.52, 0, 1); + } - CC.ELEMENTS.push({ - name: 'rain', - layer: 12, + CC.ELEMENTS.push({ + name: 'rain', + layer: 12, - world: ['cyber', 'west'], - init: function (city, rng) { - bindWorld(city, rng); + world: ['cyber', 'west'], + init: function (city, rng) { + bindWorld(city, rng); - var r = fork(rng); - rOx = new Float32Array(RN_MAX); rOz = new Float32Array(RN_MAX); - rBox = new Float32Array(RN_MAX); rSpd = new Float32Array(RN_MAX); - rPh = new Float32Array(RN_MAX); rHue = new Uint8Array(RN_MAX); - rFall = new Float32Array(RN_MAX); - for (var i = 0; i < RN_MAX; i++) { - var near = (i & 1) === 0; - var b = near ? 13 : 34; - rBox[i] = b; + var r = fork(rng); + rOx = new Float32Array(RN_MAX); rOz = new Float32Array(RN_MAX); + rBox = new Float32Array(RN_MAX); rSpd = new Float32Array(RN_MAX); + rPh = new Float32Array(RN_MAX); rHue = new Uint8Array(RN_MAX); + rFall = new Float32Array(RN_MAX); + for (var i = 0; i < RN_MAX; i++) { + var near = (i & 1) === 0; + var b = near ? 13 : 34; + rBox[i] = b; - rFall[i] = near ? 6 : 11; - rOx[i] = r() * b; rOz[i] = r() * b; - rSpd[i] = 6.5 + r() * 4.5; - rPh[i] = r(); + rFall[i] = near ? 6 : 11; + rOx[i] = r() * b; rOz[i] = r() * b; + rSpd[i] = 6.5 + r() * 4.5; + rPh[i] = r(); - var h = r(); + var h = r(); - var wWest = !!(city && city.world === 'west'); - rHue[i] = h < 0.70 ? P.slate - : wWest ? (h < 0.86 ? P.white : (h < 0.94 ? P.amber : P.warm)) - : (h < 0.86 ? P.ice : (h < 0.94 ? P.amber : P.azure)); + var wWest = !!(city && city.world === 'west'); + rHue[i] = h < 0.70 ? P.slate + : wWest ? (h < 0.86 ? P.white : (h < 0.94 ? P.amber : P.warm)) + : (h < 0.86 ? P.ice : (h < 0.94 ? P.amber : P.azure)); + } + syncWeather(0); + wetEma = pWet; wetLastT = -1e9; + dripAmt = clamp((wetEma - 0.22) / 0.52, 0, 1); + drSeed = smallSeed(rng); + }, + update: function (dt, t) { rainT = t; syncWeather(t); wetIntegrate(dt, t); }, + draw: function (frame, cam, t) { + if (!rOx) return; + var tt0 = t !== undefined ? t : rainT; + syncWeather(tt0); + bindView(frame, cam); + + var tt = CC.reducedMotion ? 0 : tt0; + var city = cam.city || WCITY; + var rows = frame.rows, cols = frame.cols; + + var dens = clamp(dRain, 0, 1.62); + if (dens > 0.02) { + + var wRight = WIND.x * vRgx + WIND.z * vRgz; + + var use = (RN_AT_REF * Math.pow(dens, 1.55) * cols * rows / REF_CELLS) | 0; + if (use > RN_MAX) use = RN_MAX; else if (use < 24) use = 24; + + var farUse = use * clamp(0.55 + 0.45 * dens, 0, 1); + + var nMax = ((rows / 15) * (0.55 + 0.45 * dens)) | 0; + if (nMax < 2) nMax = 2; else if (nMax > 8) nMax = 8; + + var fallK = (0.72 + 0.28 * dens) * (1 + 0.28 * wSleet); + + var SH_K = 0.24, SH_MIN = 0.30; + var shAmp = clamp(0.62 * dWind, 0, 1.0); + var shPh = -tt * WIND.speed * SH_K; + var splash = clamp((pRain - 0.60) / 0.40, 0, 1); + + for (var i = 0; i < use; i++) { + if ((i & 1) === 1 && i >= farUse) continue; + var b = rBox[i]; + var wx = vX + wrap(rOx[i] - vX, b); + var wz = vZ + wrap(rOz[i] - vZ, b); + + var rx = wx - vX, rz = wz - vZ; + var w = rx * vFwx + rz * vFwz; + if (w < 0.5) continue; + var rr = rx * vRgx + rz * vRgz; + if (rr > vHalf * 1.3 * w || rr < -vHalf * 1.3 * w) continue; + + var sh = vnoise((wx * WIND.dirX + wz * WIND.dirZ) * SH_K + shPh, wSeed + 61); + var sm = 1 - shAmp + 2 * shAmp * sh; + + if ((i & 1) === 0) sm = 0.35 + 0.65 * sm; + if (sm < SH_MIN) sm = SH_MIN; + + var spd = rSpd[i] * fallK; + + var fall = rFall[i]; + var gh = city ? city.height(wx, wz) : 0; + var ph = frac(rPh[i] + tt * spd / fall); + var y = gh + fall * (1 - ph); + var sleet = wSleet > 0.02 && hash1(i, wSeed + 71) < wSleet; + + if (!project(wx, y, wz)) continue; + var xf = pjX, yf = pjY, d = pjD; + + var n = (spd * 0.021 * vScale / pjW) | 0; + if (sleet) n = (n * 0.45) | 0; + if (n > nMax) n = nMax; + var lean = (wRight / spd) / vCellA; + if (sleet) lean *= 0.55; + + var base = (b < 20 ? 118 : 68 * (0.70 + 0.30 * dens)) * + (1 - clamp(pjW / (b < 20 ? 15 : 30), 0, 0.68)) * sm; + var hue = sleet ? (hash1(i, wSeed + 73) < 0.45 ? P.ice : P.white) : rHue[i]; + var gl = lean > 0.55 ? G_BSL : (lean < -0.55 ? G_SLASH : G_PIPE); + if (sleet) gl = n === 0 ? G_STAR : G_SEMI; + else if (n === 0) gl = d > 14 ? G_DOT : G_QUOTE; + + for (var k = 0; k <= n; k++) { + var sy = Math.floor(yf - k); + if (sy < 0 || sy >= rows) continue; + var sx = Math.floor(xf + lean * k); + if (sx < 0 || sx >= cols) continue; + + var lm = fogLum(base * (1 - k * 0.19), d); + if (lm < 5) continue; + put(frame, sx, sy, gl, hue, lm, d); + } + + if (splash > 0 && (i & 1) === 0 && ph > 0.94 && hash1(i, wSeed + 79) < 0.30 * splash) { + var sa = (ph - 0.94) / 0.06; + var slum = fogLum(126 * splash * (1 - sa * 0.75), d); + if (slum > 6 && project(wx, gh + 0.05, wz)) { + var bx = Math.floor(pjX), by = Math.floor(pjY); + var shue = hash1(i, wSeed + 83) < 0.6 ? P.amber : P.ice; + put(frame, bx, by, sleet ? G_DOT : G_UNDER, shue, slum, pjD); + var lift = sa < 0.5 ? 1 : 2; + put(frame, bx - 1, by - lift, G_QUOTE, shue, slum * 0.7, pjD); + put(frame, bx + 1, by - lift, G_TICK, shue, slum * 0.7, pjD); } - syncWeather(0); - wetEma = pWet; wetLastT = -1e9; - dripAmt = clamp((wetEma - 0.22) / 0.52, 0, 1); - drSeed = smallSeed(rng); - }, - update: function (dt, t) { rainT = t; syncWeather(t); wetIntegrate(dt, t); }, - draw: function (frame, cam, t) { - if (!rOx) return; - var tt0 = t !== undefined ? t : rainT; - syncWeather(tt0); - bindView(frame, cam); - - var tt = CC.reducedMotion ? 0 : tt0; - var city = cam.city || WCITY; - var rows = frame.rows, cols = frame.cols; - - var dens = clamp(dRain, 0, 1.62); - if (dens > 0.02) { - - var wRight = WIND.x * vRgx + WIND.z * vRgz; - - var use = (RN_AT_REF * Math.pow(dens, 1.55) * cols * rows / REF_CELLS) | 0; - if (use > RN_MAX) use = RN_MAX; else if (use < 24) use = 24; - - var farUse = use * clamp(0.55 + 0.45 * dens, 0, 1); - - var nMax = ((rows / 15) * (0.55 + 0.45 * dens)) | 0; - if (nMax < 2) nMax = 2; else if (nMax > 8) nMax = 8; - - var fallK = (0.72 + 0.28 * dens) * (1 + 0.28 * wSleet); - - var SH_K = 0.24, SH_MIN = 0.30; - var shAmp = clamp(0.62 * dWind, 0, 1.0); - var shPh = -tt * WIND.speed * SH_K; - var splash = clamp((pRain - 0.60) / 0.40, 0, 1); - - for (var i = 0; i < use; i++) { - if ((i & 1) === 1 && i >= farUse) continue; - var b = rBox[i]; - var wx = vX + wrap(rOx[i] - vX, b); - var wz = vZ + wrap(rOz[i] - vZ, b); - - var rx = wx - vX, rz = wz - vZ; - var w = rx * vFwx + rz * vFwz; - if (w < 0.5) continue; - var rr = rx * vRgx + rz * vRgz; - if (rr > vHalf * 1.3 * w || rr < -vHalf * 1.3 * w) continue; - - var sh = vnoise((wx * WIND.dirX + wz * WIND.dirZ) * SH_K + shPh, wSeed + 61); - var sm = 1 - shAmp + 2 * shAmp * sh; - - if ((i & 1) === 0) sm = 0.35 + 0.65 * sm; - if (sm < SH_MIN) sm = SH_MIN; - - var spd = rSpd[i] * fallK; - - var fall = rFall[i]; - var gh = city ? city.height(wx, wz) : 0; - var ph = frac(rPh[i] + tt * spd / fall); - var y = gh + fall * (1 - ph); - var sleet = wSleet > 0.02 && hash1(i, wSeed + 71) < wSleet; - - if (!project(wx, y, wz)) continue; - var xf = pjX, yf = pjY, d = pjD; - - var n = (spd * 0.021 * vScale / pjW) | 0; - if (sleet) n = (n * 0.45) | 0; - if (n > nMax) n = nMax; - var lean = (wRight / spd) / vCellA; - if (sleet) lean *= 0.55; - - var base = (b < 20 ? 118 : 68 * (0.70 + 0.30 * dens)) * - (1 - clamp(pjW / (b < 20 ? 15 : 30), 0, 0.68)) * sm; - var hue = sleet ? (hash1(i, wSeed + 73) < 0.45 ? P.ice : P.white) : rHue[i]; - var gl = lean > 0.55 ? G_BSL : (lean < -0.55 ? G_SLASH : G_PIPE); - if (sleet) gl = n === 0 ? G_STAR : G_SEMI; - else if (n === 0) gl = d > 14 ? G_DOT : G_QUOTE; - - for (var k = 0; k <= n; k++) { - var sy = Math.floor(yf - k); - if (sy < 0 || sy >= rows) continue; - var sx = Math.floor(xf + lean * k); - if (sx < 0 || sx >= cols) continue; - - var lm = fogLum(base * (1 - k * 0.19), d); - if (lm < 5) continue; - put(frame, sx, sy, gl, hue, lm, d); - } - - if (splash > 0 && (i & 1) === 0 && ph > 0.94 && hash1(i, wSeed + 79) < 0.30 * splash) { - var sa = (ph - 0.94) / 0.06; - var slum = fogLum(126 * splash * (1 - sa * 0.75), d); - if (slum > 6 && project(wx, gh + 0.05, wz)) { - var bx = Math.floor(pjX), by = Math.floor(pjY); - var shue = hash1(i, wSeed + 83) < 0.6 ? P.amber : P.ice; - put(frame, bx, by, sleet ? G_DOT : G_UNDER, shue, slum, pjD); - var lift = sa < 0.5 ? 1 : 2; - put(frame, bx - 1, by - lift, G_QUOTE, shue, slum * 0.7, pjD); - put(frame, bx + 1, by - lift, G_TICK, shue, slum * 0.7, pjD); - } - } - } - } - - if (dripAmt > 0.02 && city) drips(frame, city, tt); + } } - }); + } - var DR_PITCH = 3.0, DR_R = 21, DR_P = 0.30, drSeed = 0; - function drips(frame, city, tt) { - var gi0 = Math.floor((vX - DR_R) / DR_PITCH), gi1 = Math.floor((vX + DR_R) / DR_PITCH); - var gj0 = Math.floor((vZ - DR_R) / DR_PITCH), gj1 = Math.floor((vZ + DR_R) / DR_PITCH); - var rows = frame.rows; - - for (var gj = gj0; gj <= gj1; gj++) { - for (var gi = gi0; gi <= gi1; gi++) { - if (hash2(gi, gj, drSeed) > DR_P) continue; - var px = gi * DR_PITCH + hash2(gi, gj, drSeed + 11) * DR_PITCH * 0.9; - var pz = gj * DR_PITCH + hash2(gi, gj, drSeed + 22) * DR_PITCH * 0.9; - - var rx = px - vX, rz = pz - vZ; - var w0 = rx * vFwx + rz * vFwz; - if (w0 < 0.8 || w0 > 26) continue; - var r0 = rx * vRgx + rz * vRgz; - if (r0 > vHalf * 1.4 * w0 + 3 || r0 < -(vHalf * 1.4 * w0 + 3)) continue; - if (city.height(px, pz) > 0) continue; - - var q = hash2(gi, gj, drSeed + 33); - var dx = q < 0.25 ? 1 : (q < 0.5 ? -1 : 0); - var dz = q < 0.5 ? 0 : (q < 0.75 ? 1 : -1); - if (!(city.height(px + dx * 1.4, pz + dz * 1.4) > 0)) continue; - - var lx = px + dx * 0.55, lz = pz + dz * 0.55; - var h = 2.5 + hash2(gi, gj, drSeed + 44) * 1.2; - var tf = Math.sqrt(h / 4.9); - - var per = (0.55 + hash2(gi, gj, drSeed + 55) * 1.30) / (0.25 + 0.75 * dripAmt); - - var hue = hash2(gi, gj, drSeed + 66) < 0.35 ? P.ice : P.slate; - var lhue = hash2(gi, gj, drSeed + 88) < 0.55 ? P.amber : P.ice; - - for (var k = 0; k < 2; k++) { - - var p = frac(tt / per + k * 0.5 + hash2(gi * 2 + k, gj, drSeed + 77)); - var age = p * per; - if (age > tf + 0.14) continue; - if (age > tf) { - - if (!project(lx, 0.04, lz)) continue; - var ll = fogLum(150 * dripAmt * (1 - (age - tf) / 0.14), pjD); - if (ll < 6) continue; - put(frame, Math.floor(pjX), Math.floor(pjY), G_UNDER, lhue, ll, pjD); - continue; - } - var y = h - 4.9 * age * age; - - if (!project(lx + WIND.x * age * 0.05, y, lz + WIND.z * age * 0.05)) continue; - var lum = fogLum((66 + 90 * (age / tf)) * dripAmt, pjD); - if (lum < 6) continue; - var cy = Math.floor(pjY), cx = Math.floor(pjX); - put(frame, cx, cy, age < tf * 0.35 ? G_DOT : G_QUOTE, hue, lum, pjD); - - if (age > tf * 0.55 && cy - 1 >= 0 && cy - 1 < rows) - put(frame, cx, cy - 1, G_QUOTE, hue, lum * 0.55, pjD); - } - } - } + if (dripAmt > 0.02 && city) drips(frame, city, tt); } + }); - var ST_PITCH = 4, ST_R = 24, ST_NP = 5, ST_P = 0.28; - var stSeed = 0, stT = 0; + var DR_PITCH = 3.0, DR_R = 21, DR_P = 0.30, drSeed = 0; + function drips(frame, city, tt) { + var gi0 = Math.floor((vX - DR_R) / DR_PITCH), gi1 = Math.floor((vX + DR_R) / DR_PITCH); + var gj0 = Math.floor((vZ - DR_R) / DR_PITCH), gj1 = Math.floor((vZ + DR_R) / DR_PITCH); + var rows = frame.rows; - CC.ELEMENTS.push({ - name: 'steam', + for (var gj = gj0; gj <= gj1; gj++) { + for (var gi = gi0; gi <= gi1; gi++) { + if (hash2(gi, gj, drSeed) > DR_P) continue; + var px = gi * DR_PITCH + hash2(gi, gj, drSeed + 11) * DR_PITCH * 0.9; + var pz = gj * DR_PITCH + hash2(gi, gj, drSeed + 22) * DR_PITCH * 0.9; - world: 'cyber', - layer: 14, - init: function (city, rng) { - bindWorld(city, rng); - stSeed = smallSeed(rng); - }, - update: function (dt, t) { stT = t; syncWeather(t); }, - draw: function (frame, cam, t) { - var tt0 = t !== undefined ? t : stT; - syncWeather(tt0); - bindView(frame, cam); - var city = WCITY; - if (!city) return; - var tt = CC.reducedMotion ? 7.3 : tt0; + var rx = px - vX, rz = pz - vZ; + var w0 = rx * vFwx + rz * vFwz; + if (w0 < 0.8 || w0 > 26) continue; + var r0 = rx * vRgx + rz * vRgz; + if (r0 > vHalf * 1.4 * w0 + 3 || r0 < -(vHalf * 1.4 * w0 + 3)) continue; + if (city.height(px, pz) > 0) continue; - var vol = clamp(0.35 + 0.65 * dSteam, 0, 1.5) * (1 + 0.25 * wBreath); - var gate = ST_P * vol; - var gi0 = Math.floor((vX - ST_R) / ST_PITCH), gi1 = Math.floor((vX + ST_R) / ST_PITCH); - var gj0 = Math.floor((vZ - ST_R) / ST_PITCH), gj1 = Math.floor((vZ + ST_R) / ST_PITCH); + var q = hash2(gi, gj, drSeed + 33); + var dx = q < 0.25 ? 1 : (q < 0.5 ? -1 : 0); + var dz = q < 0.5 ? 0 : (q < 0.75 ? 1 : -1); + if (!(city.height(px + dx * 1.4, pz + dz * 1.4) > 0)) continue; - for (var gj = gj0; gj <= gj1; gj++) { - for (var gi = gi0; gi <= gi1; gi++) { - if (hash2(gi, gj, stSeed) > gate) continue; - var sx = gi * ST_PITCH + hash2(gi, gj, stSeed + 11) * ST_PITCH * 0.9; - var sz = gj * ST_PITCH + hash2(gi, gj, stSeed + 22) * ST_PITCH * 0.9; + var lx = px + dx * 0.55, lz = pz + dz * 0.55; + var h = 2.5 + hash2(gi, gj, drSeed + 44) * 1.2; + var tf = Math.sqrt(h / 4.9); - var rx = sx - vX, rz = sz - vZ; - var w0 = rx * vFwx + rz * vFwz; - if (w0 < -2 || w0 > 42) continue; - var r0 = rx * vRgx + rz * vRgz; - if (r0 > vHalf * 1.5 * w0 + 6 || r0 < -(vHalf * 1.5 * w0 + 6)) continue; - if (city.height(sx, sz) > 0) continue; + var per = (0.55 + hash2(gi, gj, drSeed + 55) * 1.30) / (0.25 + 0.75 * dripAmt); - var sd = (hash2(gi, gj, stSeed + 33) * 30011) | 0; + var hue = hash2(gi, gj, drSeed + 66) < 0.35 ? P.ice : P.slate; + var lhue = hash2(gi, gj, drSeed + 88) < 0.55 ? P.amber : P.ice; - var life = (3.2 + hash2(gi, gj, stSeed + 44) * 2.4) * (1 + 0.45 * wBreath); + for (var k = 0; k < 2; k++) { - var rise = (0.72 + hash2(gi, gj, stSeed + 55) * 0.55) * - (0.70 + 0.30 * clamp(dSteam, 0, 1.4)) * (1 - 0.22 * clamp(dWind - 1, 0, 1)); + var p = frac(tt / per + k * 0.5 + hash2(gi * 2 + k, gj, drSeed + 77)); + var age = p * per; + if (age > tf + 0.14) continue; + if (age > tf) { - var smoke = hash2(gi, gj, stSeed + 66) < 0.34; - var pk = (smoke ? 46 : 88) * clamp(0.55 + 0.45 * dSteam, 0, 1.35); - plume(frame, sx, sz, sd, life, rise, pk, smoke, tt); - } - } + if (!project(lx, 0.04, lz)) continue; + var ll = fogLum(150 * dripAmt * (1 - (age - tf) / 0.14), pjD); + if (ll < 6) continue; + put(frame, Math.floor(pjX), Math.floor(pjY), G_UNDER, lhue, ll, pjD); + continue; + } + var y = h - 4.9 * age * age; - if (wBreath > 0.15) breath(frame, tt); - } - }); - - function plume(frame, sx, sz, sd, life, rise, peak, smoke, tt) { - var rows = frame.rows, cols = frame.cols; - for (var k = 0; k < ST_NP; k++) { - var p = frac(tt / life + k / ST_NP + hash2(k, 0, sd)); - var age = p * life; - var y = 0.12 + age * rise; - - var wob = (vnoise(age * 0.9 + k * 3.7, sd) - 0.5) * age * 0.55; - var px = sx + WIND.x * age * 0.34 + wob; - var pz = sz + WIND.z * age * 0.34 - wob * 0.6; - if (!project(px, y, pz)) continue; - - var a = clamp(p / 0.12, 0, 1) * clamp((1 - p) / 0.55, 0, 1); - - var gut = vnoise((tt - age) * 0.42 + sd * 0.013, sd + 77); - - var lum0 = peak * a * (0.66 + 1.09 * gut * gut); - if (lum0 < 5) continue; - - var hue = (!smoke && y < 2.2) ? P.amber : P.slate; - - var rad = 0.22 + age * 0.30; - var rv = rad * vScale / pjW; - var kv = rv < 0.75 ? 0 : 1; - var rh = rv / vCellA; - var kh = rh < 0.75 ? 0 : (rh < 1.9 ? 1 : 2); - var cx = Math.floor(pjX), cy = Math.floor(pjY), d = pjD; - - for (var dy = -kv; dy <= kv; dy++) { - var yy = cy + dy; if (yy < 0 || yy >= rows) continue; - for (var dx = -kh; dx <= kh; dx++) { - var xx = cx + dx; if (xx < 0 || xx >= cols) continue; - - var hh = hash2(k * 17 + dx, dy * 5, sd + 401); - if (hh > 0.42) continue; - var lm = fogLum(lum0 * (0.55 + hh * 1.05), d); - if (lm < 5) continue; - - var hue2 = (hue === P.slate && wBreath > 0.5 && hh < 0.10) ? P.white : hue; - put(frame, xx, yy, hh < 0.14 ? G_COLON : (hh < 0.28 ? G_DOT : G_COMMA), hue2, lm, d); - } - } + if (!project(lx + WIND.x * age * 0.05, y, lz + WIND.z * age * 0.05)) continue; + var lum = fogLum((66 + 90 * (age / tf)) * dripAmt, pjD); + if (lum < 6) continue; + var cy = Math.floor(pjY), cx = Math.floor(pjX); + put(frame, cx, cy, age < tf * 0.35 ? G_DOT : G_QUOTE, hue, lum, pjD); + + if (age > tf * 0.55 && cy - 1 >= 0 && cy - 1 < rows) + put(frame, cx, cy - 1, G_QUOTE, hue, lum * 0.55, pjD); } + } } + } - function breath(frame, tt) { - var rows = frame.rows, cols = frame.cols; - var per = 4.4; - for (var k = 0; k < 3; k++) { - var p = frac(tt / per + k * 0.16); - if (p > 0.55) continue; - var age = p * per; - var fwd = 0.85 + age * 0.55; - var px = vX + vFwx * fwd + WIND.x * age * 0.22; - var pz = vZ + vFwz * fwd + WIND.z * age * 0.22; - var y = vEyeY - 0.26 + age * 0.16; - if (!project(px, y, pz)) continue; - var a = clamp(age / 0.25, 0, 1) * clamp((2.4 - age) / 1.6, 0, 1); - var lum0 = 58 * a * wBreath; - if (lum0 < 5) continue; - var rad = 0.07 + age * 0.16; - var rv = rad * vScale / pjW; - var kv = rv < 0.8 ? 0 : 1; - var rh = rv / vCellA; - var kh = rh < 0.8 ? 0 : (rh < 2.2 ? 1 : 2); - var cx = Math.floor(pjX), cy = Math.floor(pjY), d = pjD; - for (var dy = -kv; dy <= kv; dy++) { - var yy = cy + dy; if (yy < 0 || yy >= rows) continue; - for (var dx = -kh; dx <= kh; dx++) { - var xx = cx + dx; if (xx < 0 || xx >= cols) continue; - var hh = hash2(k * 13 + dx, dy * 7, wSeed + 503); - if (hh > 0.38) continue; + var ST_PITCH = 4, ST_R = 24, ST_NP = 5, ST_P = 0.28; + var stSeed = 0, stT = 0; - put(frame, xx, yy, hh < 0.16 ? G_DOT : G_COMMA, - hh < 0.18 ? P.white : P.slate, lum0 * (0.5 + hh), d); - } - } + CC.ELEMENTS.push({ + name: 'steam', + + world: 'cyber', + layer: 14, + init: function (city, rng) { + bindWorld(city, rng); + stSeed = smallSeed(rng); + }, + update: function (dt, t) { stT = t; syncWeather(t); }, + draw: function (frame, cam, t) { + var tt0 = t !== undefined ? t : stT; + syncWeather(tt0); + bindView(frame, cam); + var city = WCITY; + if (!city) return; + var tt = CC.reducedMotion ? 7.3 : tt0; + + var vol = clamp(0.35 + 0.65 * dSteam, 0, 1.5) * (1 + 0.25 * wBreath); + var gate = ST_P * vol; + var gi0 = Math.floor((vX - ST_R) / ST_PITCH), gi1 = Math.floor((vX + ST_R) / ST_PITCH); + var gj0 = Math.floor((vZ - ST_R) / ST_PITCH), gj1 = Math.floor((vZ + ST_R) / ST_PITCH); + + for (var gj = gj0; gj <= gj1; gj++) { + for (var gi = gi0; gi <= gi1; gi++) { + if (hash2(gi, gj, stSeed) > gate) continue; + var sx = gi * ST_PITCH + hash2(gi, gj, stSeed + 11) * ST_PITCH * 0.9; + var sz = gj * ST_PITCH + hash2(gi, gj, stSeed + 22) * ST_PITCH * 0.9; + + var rx = sx - vX, rz = sz - vZ; + var w0 = rx * vFwx + rz * vFwz; + if (w0 < -2 || w0 > 42) continue; + var r0 = rx * vRgx + rz * vRgz; + if (r0 > vHalf * 1.5 * w0 + 6 || r0 < -(vHalf * 1.5 * w0 + 6)) continue; + if (city.height(sx, sz) > 0) continue; + + var sd = (hash2(gi, gj, stSeed + 33) * 30011) | 0; + + var life = (3.2 + hash2(gi, gj, stSeed + 44) * 2.4) * (1 + 0.45 * wBreath); + + var rise = (0.72 + hash2(gi, gj, stSeed + 55) * 0.55) * + (0.70 + 0.30 * clamp(dSteam, 0, 1.4)) * (1 - 0.22 * clamp(dWind - 1, 0, 1)); + + var smoke = hash2(gi, gj, stSeed + 66) < 0.34; + var pk = (smoke ? 46 : 88) * clamp(0.55 + 0.45 * dSteam, 0, 1.35); + plume(frame, sx, sz, sd, life, rise, pk, smoke, tt); } + } + + if (wBreath > 0.15) breath(frame, tt); } + }); - var fgSeed = 0, fgT = 0; + function plume(frame, sx, sz, sd, life, rise, peak, smoke, tt) { + var rows = frame.rows, cols = frame.cols; + for (var k = 0; k < ST_NP; k++) { + var p = frac(tt / life + k / ST_NP + hash2(k, 0, sd)); + var age = p * life; + var y = 0.12 + age * rise; - var FG_TOP = 0.85, FG_TH = 0.44, FG_DITHER = 0.34; + var wob = (vnoise(age * 0.9 + k * 3.7, sd) - 0.5) * age * 0.55; + var px = sx + WIND.x * age * 0.34 + wob; + var pz = sz + WIND.z * age * 0.34 - wob * 0.6; + if (!project(px, y, pz)) continue; - CC.ELEMENTS.push({ - name: 'fogbank', - layer: 8, + var a = clamp(p / 0.12, 0, 1) * clamp((1 - p) / 0.55, 0, 1); - world: ['cyber', 'west'], - init: function (city, rng) { - bindWorld(city, rng); - fgSeed = smallSeed(rng); - }, - update: function (dt, t) { fgT = t; syncWeather(t); }, - draw: function (frame, cam, t) { - var tt0 = t !== undefined ? t : fgT; - syncWeather(tt0); - bindView(frame, cam); - var tt = CC.reducedMotion ? 0 : tt0; - var rows = frame.rows, cols = frame.cols; - var thick = clamp(dFog, 0, 3.4); + var gut = vnoise((tt - age) * 0.42 + sd * 0.013, sd + 77); - var top = FG_TOP + 0.42 * clamp(thick - 1, 0, 2.4) - 0.30 * clamp(1 - thick, 0, 1); + var lum0 = peak * a * (0.66 + 1.09 * gut * gut); + if (lum0 < 5) continue; - if (top > vEyeY - 0.45) top = vEyeY - 0.45; - var rise = vEyeY - top; - if (rise < 0.15) return; + var hue = (!smoke && y < 2.2) ? P.amber : P.slate; - var hi = clamp(thick - 1, 0, 2.4), lo = clamp(1 - thick, 0, 1); - var th = clamp(FG_TH - 0.075 * hi + 0.17 * lo, 0.10, 0.90); - var dith = clamp(FG_DITHER * (1 + 0.28 * hi - 0.60 * lo), 0, 0.95); - var glow = 1 + 0.16 * hi - 0.30 * lo; + var rad = 0.22 + age * 0.30; + var rv = rad * vScale / pjW; + var kv = rv < 0.75 ? 0 : 1; + var rh = rv / vCellA; + var kh = rh < 0.75 ? 0 : (rh < 1.9 ? 1 : 2); + var cx = Math.floor(pjX), cy = Math.floor(pjY), d = pjD; - var nearW = lerp(4.5, 1.6, clamp(thick - 1, 0, 1)); - var farW = lerp(70, 96, clamp(thick - 1, 0, 1)); + for (var dy = -kv; dy <= kv; dy++) { + var yy = cy + dy; if (yy < 0 || yy >= rows) continue; + for (var dx = -kh; dx <= kh; dx++) { + var xx = cx + dx; if (xx < 0 || xx >= cols) continue; - var drx = WIND.x * tt * 0.18 * 0.058, drz = WIND.z * tt * 0.18 * 0.058; - var r0 = Math.ceil(vHorizon); + var hh = hash2(k * 17 + dx, dy * 5, sd + 401); + if (hh > 0.42) continue; + var lm = fogLum(lum0 * (0.55 + hh * 1.05), d); + if (lm < 5) continue; - for (var r = r0; r < rows; r++) { - var den = r + 0.5 - vHorizon; - if (den < 0.85) continue; - var w = rise * vScale / den; - if (w > farW) continue; - if (w < nearW) break; - - var band = clamp((w - nearW) / 6, 0, 1) * clamp((farW - w) / 22, 0, 1); - - var bandDith = band * dith; - - for (var x = 0; x < cols; x++) { - var sp = (2 * (x + 0.5) / cols - 1) * vHalf; - var dx = vFwx + vRgx * sp, dz = vFwz + vRgz * sp; - var px = vX + dx * w, pz = vZ + dz * w; - - var hh = hash2(Math.floor(px * 1.7), Math.floor(pz * 1.7), fgSeed + 7); - if (hh > bandDith) continue; - - var coarse = n2(px * 0.058 + drx, pz * 0.058 + drz, fgSeed); - if (coarse * 0.70 + 0.30 <= th) continue; - var d = w * Math.sqrt(1 + sp * sp); - if (d > farW + 2) continue; - var bank = coarse * 0.70 + n2(px * 0.185, pz * 0.185, fgSeed + 5) * 0.30; - if (bank <= th) continue; - var amt = (bank - th) / (1 - th) * band; - - if (hh > amt * dith) continue; - var lm = fogLum((14 + amt * 42) * glow, d); - if (lm < 5) continue; - put(frame, x, r, hh < 0.06 ? G_TILDE : (hh < 0.12 ? G_UNDER : G_DASH), P.slate, lm, d); - } - } - - veil(frame); - } - }); - - function veil(frame) { - - var drive = pFog + 0.55 * clamp(pRain - 0.62, 0, 0.38); - var v = clamp((drive - 0.34) / 0.50, 0, 1); - if (v < 0.015) return; - var cols = frame.cols, rows = frame.rows; - var ch = frame.ch, kind = frame.kind, dist = frame.dist, lum = frame.lum, col = frame.col; - - var v0 = lerp(52, 7, v), v1 = lerp(120, 30, v); - var inv = 1 / (v1 - v0); - - var skyV = clamp((v - 0.35) / 0.5, 0, 1); - var skyD = 45; - - for (var y = 0; y < rows; y++) { - for (var x = 0; x < cols; x++) { - var i = y * cols + x, d = dist[i]; - if (d >= vFar) { - if (skyV < 0.02) continue; - var sh = hash2(x, y, fgSeed + 61); - if (sh > skyV * 0.34) continue; - put(frame, x, y, sh < 0.05 ? G_TILDE : (sh < 0.14 ? G_DASH : G_DOT), - P.slate, (11 + 26 * skyV) * (0.6 + sh), skyD); - continue; - } - if (d <= v0 || ch[i] === 0) continue; - var a = (d - v0) * inv; - if (a > 1) a = 1; - a *= v; - - var hh = hash2(x, y, fgSeed + 51); - if (hh < a * 0.34) { - - var amb = (9 + 30 * a) * (1 - 0.55 * clamp(d / 70, 0, 1)); - var halo = lum[i] * 0.40; - var lm = halo > amb ? halo : amb; - var hue = halo > amb ? col[i] : P.slate; - if (lm < 4) lm = 4; - put(frame, x, y, hh < 0.05 * a ? G_TILDE : (hh < 0.20 * a ? G_DASH : G_DOT), - hue, lm, d * 0.999, 3); - } else { - var l0 = lum[i]; - if (l0 < 3) continue; - var nl = l0 * (1 - 0.86 * a); - if (nl >= l0 - 0.5) continue; - put(frame, x, y, ch[i], col[i], nl, d * 0.999, kind[i]); - } - } + var hue2 = (hue === P.slate && wBreath > 0.5 && hh < 0.10) ? P.white : hue; + put(frame, xx, yy, hh < 0.14 ? G_COLON : (hh < 0.28 ? G_DOT : G_COMMA), hue2, lm, d); } + } } + } - var clSeed = 0, clT = 0, CL_BASE = 46; + function breath(frame, tt) { + var rows = frame.rows, cols = frame.cols; + var per = 4.4; + for (var k = 0; k < 3; k++) { + var p = frac(tt / per + k * 0.16); + if (p > 0.55) continue; + var age = p * per; + var fwd = 0.85 + age * 0.55; + var px = vX + vFwx * fwd + WIND.x * age * 0.22; + var pz = vZ + vFwz * fwd + WIND.z * age * 0.22; + var y = vEyeY - 0.26 + age * 0.16; + if (!project(px, y, pz)) continue; + var a = clamp(age / 0.25, 0, 1) * clamp((2.4 - age) / 1.6, 0, 1); + var lum0 = 58 * a * wBreath; + if (lum0 < 5) continue; + var rad = 0.07 + age * 0.16; + var rv = rad * vScale / pjW; + var kv = rv < 0.8 ? 0 : 1; + var rh = rv / vCellA; + var kh = rh < 0.8 ? 0 : (rh < 2.2 ? 1 : 2); + var cx = Math.floor(pjX), cy = Math.floor(pjY), d = pjD; + for (var dy = -kv; dy <= kv; dy++) { + var yy = cy + dy; if (yy < 0 || yy >= rows) continue; + for (var dx = -kh; dx <= kh; dx++) { + var xx = cx + dx; if (xx < 0 || xx >= cols) continue; + var hh = hash2(k * 13 + dx, dy * 7, wSeed + 503); + if (hh > 0.38) continue; - CC.ELEMENTS.push({ - name: 'lowcloud', - layer: 7, - - world: ['cyber', 'west'], - init: function (city, rng) { - bindWorld(city, rng); - clSeed = smallSeed(rng); - }, - update: function (dt, t) { clT = t; syncWeather(t); }, - draw: function (frame, cam, t) { - var tt0 = t !== undefined ? t : clT; - syncWeather(tt0); - var scud = clamp((pCloud - 0.78) / 0.22, 0, 1); - if (scud < 0.02) return; - bindView(frame, cam); - var tt = CC.reducedMotion ? 0 : tt0; - var cols = frame.cols, rows = frame.rows; - var dist = frame.dist; - var rise = CL_BASE - vEyeY; - - var drx = WIND.x * tt * 1.8 * 0.0075, drz = WIND.z * tt * 1.8 * 0.0075; - var th = 0.52 - 0.16 * scud; - var r1 = Math.floor(vHorizon); - if (r1 > rows) r1 = rows; - - for (var r = 0; r < r1; r++) { - var den = vHorizon - (r + 0.5); - if (den < 0.9) continue; - var w = rise * vScale / den; - if (w > 900) continue; - - var band = clamp((900 - w) / 420, 0, 1); - if (band < 0.04) continue; - - for (var x = 0; x < cols; x++) { - var i = r * cols + x; - - if (dist[i] < 200) continue; - var sp = (2 * (x + 0.5) / cols - 1) * vHalf; - var dx = vFwx + vRgx * sp, dz = vFwz + vRgz * sp; - var px = vX + dx * w, pz = vZ + dz * w; - - var c = n2(px * 0.0075 + drx, pz * 0.0075 + drz, clSeed); - if (c <= th) continue; - var amt = (c - th) / (1 - th) * band * scud; - var hh = hash2(x, r, clSeed + 9); - if (hh > amt * 0.55) continue; - - var lm = (9 + 26 * amt) * (0.65 + 0.35 * (r / (r1 + 1))); - put(frame, x, r, hh < 0.07 ? G_TILDE : (hh < 0.16 ? G_EQ : (hh < 0.34 ? G_DASH : G_UNDER)), - P.slate, lm, 60); - } - } + put(frame, xx, yy, hh < 0.16 ? G_DOT : G_COMMA, + hh < 0.18 ? P.white : P.slate, lum0 * (0.5 + hh), d); } - }); - - var lgSeed = 0, lgI = 0, lgSide = 0, lgBear = 0, lgChan = 0; - var LG_PER = 5.5; - var LG_DUR = 1.20; - var LG_W = 6.8, LG_RISE = 0.15, LG_DECAY = 2.7, LG_FADE = 0.18; - var LG_JIT = 0.5; - - var LG_K = 0.78, LG_BAND = 0.24; - - var LG_FLOOR = 0.02; - - function lgEnv(u) { - if (u < 0 || u > LG_DUR) return 0; - var e = Math.exp(-u * LG_DECAY); - if (u < LG_RISE) e *= smooth(u / LG_RISE); - - if (u > LG_DUR - LG_FADE) e *= smooth((LG_DUR - u) / LG_FADE); - if (CC.reducedMotion) return e; - var c = Math.cos(u * LG_W); - return e * (0.55 + 0.45 * (c > 0 ? c : 0)); + } } + } - CC.ELEMENTS.push({ - name: 'lightning', - layer: 40, + var fgSeed = 0, fgT = 0; - world: ['cyber', 'west'], - init: function (city, rng) { - bindWorld(city, rng); - lgSeed = smallSeed(rng); - }, - update: function (dt, t) { - syncWeather(t); - lgI = 0; + var FG_TOP = 0.85, FG_TH = 0.44, FG_DITHER = 0.34; - if (pStorm < 0.004) return; + CC.ELEMENTS.push({ + name: 'fogbank', + layer: 8, - var ampS = 0.55 + 0.45 * clamp(pStorm / REF_STORM, 0, 1) + - 0.28 * clamp((pStorm - REF_STORM) / (1 - REF_STORM), 0, 1); - var best = 0, side = 0, bear = 0, chan = 0, bestE = 0, bestA = 0; - var n = Math.floor(t / LG_PER); + world: ['cyber', 'west'], + init: function (city, rng) { + bindWorld(city, rng); + fgSeed = smallSeed(rng); + }, + update: function (dt, t) { fgT = t; syncWeather(t); }, + draw: function (frame, cam, t) { + var tt0 = t !== undefined ? t : fgT; + syncWeather(tt0); + bindView(frame, cam); + var tt = CC.reducedMotion ? 0 : tt0; + var rows = frame.rows, cols = frame.cols; + var thick = clamp(dFog, 0, 3.4); - for (var j = n - 1; j <= n; j++) { + var top = FG_TOP + 0.42 * clamp(thick - 1, 0, 2.4) - 0.30 * clamp(1 - thick, 0, 1); - var q = hash1(j, lgSeed + 5); - var gate = (pStorm * LG_K - q) / LG_BAND + 1; - if (gate <= 0) continue; - gate = gate >= 1 ? 1 : smooth(gate); - var st = j * LG_PER + LG_JIT + hash1(j, lgSeed + 1) * (LG_PER - 1.2 - LG_JIT); - var amp = (0.42 + hash1(j, lgSeed + 2) * 0.58) * ampS * gate; - var ev = lgEnv(t - st); - var v = ev * amp; - if (v > best) { - best = v; bestE = ev; bestA = amp; - side = hash1(j, lgSeed + 3) < 0.5 ? -1 : 1; - bear = hash1(j, lgSeed + 4) * 6.283185; - chan = hash1(j, lgSeed + 6); - } - } + if (top > vEyeY - 0.45) top = vEyeY - 0.45; + var rise = vEyeY - top; + if (rise < 0.15) return; - best = bestE > LG_FLOOR ? bestA * (bestE - LG_FLOOR) : 0; - lgI = best <= 0 ? 0 : (CC.reducedMotion ? best * 0.28 : best); - lgSide = side; lgBear = bear; lgChan = chan; - }, - draw: function (frame, cam) { - var I = lgI; - if (I <= 0) return; - bindView(frame, cam); - var cols = frame.cols, rows = frame.rows; - var ch = frame.ch, kind = frame.kind, dist = frame.dist, lum = frame.lum, col = frame.col; - var hz = vHorizon; + var hi = clamp(thick - 1, 0, 2.4), lo = clamp(1 - thick, 0, 1); + var th = clamp(FG_TH - 0.075 * hi + 0.17 * lo, 0.10, 0.90); + var dith = clamp(FG_DITHER * (1 + 0.28 * hi - 0.60 * lo), 0, 0.95); + var glow = 1 + 0.16 * hi - 0.30 * lo; - var reach = 14 + 16 * clamp((pStorm - REF_STORM) / (1 - REF_STORM), 0, 1); + var nearW = lerp(4.5, 1.6, clamp(thick - 1, 0, 1)); + var farW = lerp(70, 96, clamp(thick - 1, 0, 1)); - for (var y = 0; y < rows; y++) { - var above = hz - y; - var sky = above > 0 && above <= reach ? I * 0.13 * (1 - above / reach) : 0; - for (var x = 0; x < cols; x++) { - var i = y * cols + x, k = kind[i], d = dist[i]; + var drx = WIND.x * tt * 0.18 * 0.058, drz = WIND.z * tt * 0.18 * 0.058; + var r0 = Math.ceil(vHorizon); - if (k === 0) { + for (var r = r0; r < rows; r++) { + var den = r + 0.5 - vHorizon; + if (den < 0.85) continue; + var w = rise * vScale / den; + if (w > farW) continue; + if (w < nearW) break; - if (sky === 0 || ch[i] !== 0) continue; - var sg = hash2(x, y, lgSeed + 193); - if (sg > sky) continue; + var band = clamp((w - nearW) / 6, 0, 1) * clamp((farW - w) / 22, 0, 1); - put(frame, x, y, sg < 0.02 ? G_TICK : G_DOT, P.slate, - 14 + I * 40 * hash2(x, y, lgSeed + 197), SURF ? SURF.FOG_START : 12, 0); - continue; - } - if (d >= vFar) continue; + var bandDith = band * dith; - var att = fogLum(255, d) / 255; - if (att < 0.06) continue; + for (var x = 0; x < cols; x++) { + var sp = (2 * (x + 0.5) / cols - 1) * vHalf; + var dx = vFwx + vRgx * sp, dz = vFwz + vRgz * sp; + var px = vX + dx * w, pz = vZ + dz * w; - var lat = 0.55 + 0.45 * (lgSide > 0 ? x / cols : 1 - x / cols); - var g = I * att * lat; + var hh = hash2(Math.floor(px * 1.7), Math.floor(pz * 1.7), fgSeed + 7); + if (hh > bandDith) continue; - if (ch[i] !== 0) { - var add = (k === 2 ? 46 : 78) * g; - if (add < 4) continue; - put(frame, x, y, ch[i], col[i], lum[i] + add, d * 0.999, k); - } else if (k === 1) { + var coarse = n2(px * 0.058 + drx, pz * 0.058 + drz, fgSeed); + if (coarse * 0.70 + 0.30 <= th) continue; + var d = w * Math.sqrt(1 + sp * sp); + if (d > farW + 2) continue; + var bank = coarse * 0.70 + n2(px * 0.185, pz * 0.185, fgSeed + 5) * 0.30; + if (bank <= th) continue; + var amt = (bank - th) / (1 - th) * band; - var fh = hash2(x, y, lgSeed + 211); - if (fh > g * 0.30) continue; - put(frame, x, y, fh < 0.10 ? G_PIPE : (fh < 0.20 ? G_COLON : G_QUOTE), - P.slate, 8 + g * 34, d * 0.999, k); - } - } - } - - if (pStorm > 0.45 && I > 0.30 && lgChan < 0.55) bolt(frame, I, cols, rows); + if (hh > amt * dith) continue; + var lm = fogLum((14 + amt * 42) * glow, d); + if (lm < 5) continue; + put(frame, x, r, hh < 0.06 ? G_TILDE : (hh < 0.12 ? G_UNDER : G_DASH), P.slate, lm, d); } - }); + } - function bolt(frame, I, cols, rows) { - var yaw = Math.atan2(vFwx, vFwz); - var rel0 = lgBear - yaw; - while (rel0 > 3.14159265) rel0 -= 6.283185; - while (rel0 < -3.14159265) rel0 += 6.283185; - if (rel0 > 1.35 || rel0 < -1.35) return; - var sx0 = (Math.tan(rel0) / vHalf + 1) * 0.5 * cols; - if (sx0 < -4 || sx0 > cols + 4) return; - var strength = clamp((pStorm - 0.45) / 0.4, 0, 1) * clamp((I - 0.30) / 0.35, 0, 1); - var bottom = Math.floor(vHorizon) - 1; - if (bottom > rows - 1) bottom = rows - 1; - var x = sx0, dxs = (lgChan - 0.27) * 1.4; - for (var y = 0; y <= bottom; y++) { - - x += dxs + (hash2(y, 0, lgSeed + 313 + ((lgChan * 811) | 0)) - 0.5) * 2.6; - var cx = Math.floor(x); - if (cx < 0 || cx >= cols) continue; - var i = y * cols + cx; - - if (frame.dist[i] < 55) break; - var lm = (70 + 150 * I) * strength * (0.55 + 0.45 * (y / (bottom + 1))); - put(frame, cx, y, hash2(y, 1, lgSeed + 317) < 0.4 ? G_SLASH : G_PIPE, P.white, lm, 58); - - if (lgChan < 0.22 && y > bottom * 0.55) { - var fx = (cx + (y - bottom * 0.55) * (lgChan < 0.11 ? -0.9 : 0.9)) | 0; - if (fx >= 0 && fx < cols && frame.dist[y * cols + fx] >= 55) - put(frame, fx, y, G_BSL, P.white, lm * 0.5, 58); - } - } + veil(frame); } + }); - if (CC) CC.Wind = WIND; + function veil(frame) { + + var drive = pFog + 0.55 * clamp(pRain - 0.62, 0, 0.38); + var v = clamp((drive - 0.34) / 0.50, 0, 1); + if (v < 0.015) return; + var cols = frame.cols, rows = frame.rows; + var ch = frame.ch, kind = frame.kind, dist = frame.dist, lum = frame.lum, col = frame.col; + + var v0 = lerp(52, 7, v), v1 = lerp(120, 30, v); + var inv = 1 / (v1 - v0); + + var skyV = clamp((v - 0.35) / 0.5, 0, 1); + var skyD = 45; + + for (var y = 0; y < rows; y++) { + for (var x = 0; x < cols; x++) { + var i = y * cols + x, d = dist[i]; + if (d >= vFar) { + if (skyV < 0.02) continue; + var sh = hash2(x, y, fgSeed + 61); + if (sh > skyV * 0.34) continue; + put(frame, x, y, sh < 0.05 ? G_TILDE : (sh < 0.14 ? G_DASH : G_DOT), + P.slate, (11 + 26 * skyV) * (0.6 + sh), skyD); + continue; + } + if (d <= v0 || ch[i] === 0) continue; + var a = (d - v0) * inv; + if (a > 1) a = 1; + a *= v; + + var hh = hash2(x, y, fgSeed + 51); + if (hh < a * 0.34) { + + var amb = (9 + 30 * a) * (1 - 0.55 * clamp(d / 70, 0, 1)); + var halo = lum[i] * 0.40; + var lm = halo > amb ? halo : amb; + var hue = halo > amb ? col[i] : P.slate; + if (lm < 4) lm = 4; + put(frame, x, y, hh < 0.05 * a ? G_TILDE : (hh < 0.20 * a ? G_DASH : G_DOT), + hue, lm, d * 0.999, 3); + } else { + var l0 = lum[i]; + if (l0 < 3) continue; + var nl = l0 * (1 - 0.86 * a); + if (nl >= l0 - 0.5) continue; + put(frame, x, y, ch[i], col[i], nl, d * 0.999, kind[i]); + } + } + } + } + + var clSeed = 0, clT = 0, CL_BASE = 46; + + CC.ELEMENTS.push({ + name: 'lowcloud', + layer: 7, + + world: ['cyber', 'west'], + init: function (city, rng) { + bindWorld(city, rng); + clSeed = smallSeed(rng); + }, + update: function (dt, t) { clT = t; syncWeather(t); }, + draw: function (frame, cam, t) { + var tt0 = t !== undefined ? t : clT; + syncWeather(tt0); + var scud = clamp((pCloud - 0.78) / 0.22, 0, 1); + if (scud < 0.02) return; + bindView(frame, cam); + var tt = CC.reducedMotion ? 0 : tt0; + var cols = frame.cols, rows = frame.rows; + var dist = frame.dist; + var rise = CL_BASE - vEyeY; + + var drx = WIND.x * tt * 1.8 * 0.0075, drz = WIND.z * tt * 1.8 * 0.0075; + var th = 0.52 - 0.16 * scud; + var r1 = Math.floor(vHorizon); + if (r1 > rows) r1 = rows; + + for (var r = 0; r < r1; r++) { + var den = vHorizon - (r + 0.5); + if (den < 0.9) continue; + var w = rise * vScale / den; + if (w > 900) continue; + + var band = clamp((900 - w) / 420, 0, 1); + if (band < 0.04) continue; + + for (var x = 0; x < cols; x++) { + var i = r * cols + x; + + if (dist[i] < 200) continue; + var sp = (2 * (x + 0.5) / cols - 1) * vHalf; + var dx = vFwx + vRgx * sp, dz = vFwz + vRgz * sp; + var px = vX + dx * w, pz = vZ + dz * w; + + var c = n2(px * 0.0075 + drx, pz * 0.0075 + drz, clSeed); + if (c <= th) continue; + var amt = (c - th) / (1 - th) * band * scud; + var hh = hash2(x, r, clSeed + 9); + if (hh > amt * 0.55) continue; + + var lm = (9 + 26 * amt) * (0.65 + 0.35 * (r / (r1 + 1))); + put(frame, x, r, hh < 0.07 ? G_TILDE : (hh < 0.16 ? G_EQ : (hh < 0.34 ? G_DASH : G_UNDER)), + P.slate, lm, 60); + } + } + } + }); + + var lgSeed = 0, lgI = 0, lgSide = 0, lgBear = 0, lgChan = 0; + var LG_PER = 5.5; + var LG_DUR = 1.20; + var LG_W = 6.8, LG_RISE = 0.15, LG_DECAY = 2.7, LG_FADE = 0.18; + var LG_JIT = 0.5; + + var LG_K = 0.78, LG_BAND = 0.24; + + var LG_FLOOR = 0.02; + + function lgEnv(u) { + if (u < 0 || u > LG_DUR) return 0; + var e = Math.exp(-u * LG_DECAY); + if (u < LG_RISE) e *= smooth(u / LG_RISE); + + if (u > LG_DUR - LG_FADE) e *= smooth((LG_DUR - u) / LG_FADE); + if (CC.reducedMotion) return e; + var c = Math.cos(u * LG_W); + return e * (0.55 + 0.45 * (c > 0 ? c : 0)); + } + + CC.ELEMENTS.push({ + name: 'lightning', + layer: 40, + + world: ['cyber', 'west'], + init: function (city, rng) { + bindWorld(city, rng); + lgSeed = smallSeed(rng); + }, + update: function (dt, t) { + syncWeather(t); + lgI = 0; + + if (pStorm < 0.004) return; + + var ampS = 0.55 + 0.45 * clamp(pStorm / REF_STORM, 0, 1) + + 0.28 * clamp((pStorm - REF_STORM) / (1 - REF_STORM), 0, 1); + var best = 0, side = 0, bear = 0, chan = 0, bestE = 0, bestA = 0; + var n = Math.floor(t / LG_PER); + + for (var j = n - 1; j <= n; j++) { + + var q = hash1(j, lgSeed + 5); + var gate = (pStorm * LG_K - q) / LG_BAND + 1; + if (gate <= 0) continue; + gate = gate >= 1 ? 1 : smooth(gate); + var st = j * LG_PER + LG_JIT + hash1(j, lgSeed + 1) * (LG_PER - 1.2 - LG_JIT); + var amp = (0.42 + hash1(j, lgSeed + 2) * 0.58) * ampS * gate; + var ev = lgEnv(t - st); + var v = ev * amp; + if (v > best) { + best = v; bestE = ev; bestA = amp; + side = hash1(j, lgSeed + 3) < 0.5 ? -1 : 1; + bear = hash1(j, lgSeed + 4) * 6.283185; + chan = hash1(j, lgSeed + 6); + } + } + + best = bestE > LG_FLOOR ? bestA * (bestE - LG_FLOOR) : 0; + lgI = best <= 0 ? 0 : (CC.reducedMotion ? best * 0.28 : best); + lgSide = side; lgBear = bear; lgChan = chan; + }, + draw: function (frame, cam) { + var I = lgI; + if (I <= 0) return; + bindView(frame, cam); + var cols = frame.cols, rows = frame.rows; + var ch = frame.ch, kind = frame.kind, dist = frame.dist, lum = frame.lum, col = frame.col; + var hz = vHorizon; + + var reach = 14 + 16 * clamp((pStorm - REF_STORM) / (1 - REF_STORM), 0, 1); + + for (var y = 0; y < rows; y++) { + var above = hz - y; + var sky = above > 0 && above <= reach ? I * 0.13 * (1 - above / reach) : 0; + for (var x = 0; x < cols; x++) { + var i = y * cols + x, k = kind[i], d = dist[i]; + + if (k === 0) { + + if (sky === 0 || ch[i] !== 0) continue; + var sg = hash2(x, y, lgSeed + 193); + if (sg > sky) continue; + + put(frame, x, y, sg < 0.02 ? G_TICK : G_DOT, P.slate, + 14 + I * 40 * hash2(x, y, lgSeed + 197), SURF ? SURF.FOG_START : 12, 0); + continue; + } + if (d >= vFar) continue; + + var att = fogLum(255, d) / 255; + if (att < 0.06) continue; + + var lat = 0.55 + 0.45 * (lgSide > 0 ? x / cols : 1 - x / cols); + var g = I * att * lat; + + if (ch[i] !== 0) { + var add = (k === 2 ? 46 : 78) * g; + if (add < 4) continue; + put(frame, x, y, ch[i], col[i], lum[i] + add, d * 0.999, k); + } else if (k === 1) { + + var fh = hash2(x, y, lgSeed + 211); + if (fh > g * 0.30) continue; + put(frame, x, y, fh < 0.10 ? G_PIPE : (fh < 0.20 ? G_COLON : G_QUOTE), + P.slate, 8 + g * 34, d * 0.999, k); + } + } + } + + if (pStorm > 0.45 && I > 0.30 && lgChan < 0.55) bolt(frame, I, cols, rows); + } + }); + + function bolt(frame, I, cols, rows) { + var yaw = Math.atan2(vFwx, vFwz); + var rel0 = lgBear - yaw; + while (rel0 > 3.14159265) rel0 -= 6.283185; + while (rel0 < -3.14159265) rel0 += 6.283185; + if (rel0 > 1.35 || rel0 < -1.35) return; + var sx0 = (Math.tan(rel0) / vHalf + 1) * 0.5 * cols; + if (sx0 < -4 || sx0 > cols + 4) return; + var strength = clamp((pStorm - 0.45) / 0.4, 0, 1) * clamp((I - 0.30) / 0.35, 0, 1); + var bottom = Math.floor(vHorizon) - 1; + if (bottom > rows - 1) bottom = rows - 1; + var x = sx0, dxs = (lgChan - 0.27) * 1.4; + for (var y = 0; y <= bottom; y++) { + + x += dxs + (hash2(y, 0, lgSeed + 313 + ((lgChan * 811) | 0)) - 0.5) * 2.6; + var cx = Math.floor(x); + if (cx < 0 || cx >= cols) continue; + var i = y * cols + cx; + + if (frame.dist[i] < 55) break; + var lm = (70 + 150 * I) * strength * (0.55 + 0.45 * (y / (bottom + 1))); + put(frame, cx, y, hash2(y, 1, lgSeed + 317) < 0.4 ? G_SLASH : G_PIPE, P.white, lm, 58); + + if (lgChan < 0.22 && y > bottom * 0.55) { + var fx = (cx + (y - bottom * 0.55) * (lgChan < 0.11 ? -0.9 : 0.9)) | 0; + if (fx >= 0 && fx < cols && frame.dist[y * cols + fx] >= 55) + put(frame, fx, y, G_BSL, P.white, lm * 0.5, 58); + } + } + } + + if (CC) CC.Wind = WIND; })(CC); /* src/elements/west_desert.js */ (function (CC) { - 'use strict'; + 'use strict'; - 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 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, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp; + var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp; - var G_DOT = CC.g('.'), G_COMMA = CC.g(','), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), - G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_TILDE = CC.g('~'), - G_PIPE = CC.g('|'), G_SLASH = CC.g('/'), G_BSL = CC.g('\\'), G_STAR = CC.g('*'), - G_PCT = CC.g('%'), G_AMP = CC.g('&'), G_o = CC.g('o'), G_8 = CC.g('8'); + var G_DOT = CC.g('.'), G_COMMA = CC.g(','), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), + G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_TILDE = CC.g('~'), + G_PIPE = CC.g('|'), G_SLASH = CC.g('/'), G_BSL = CC.g('\\'), G_STAR = CC.g('*'), + G_PCT = CC.g('%'), G_AMP = CC.g('&'), G_o = CC.g('o'), G_8 = CC.g('8'); - var TAU = 6.283185307; + var TAU = 6.283185307; - var CITY = null, BASE = 0, Surf = null, WEST = null; - function boot(city) { - CITY = (city && city.aveX && city.world === 'west') ? city : null; + var CITY = null, BASE = 0, Surf = null, WEST = null; + function boot(city) { + CITY = (city && city.aveX && city.world === 'west') ? city : null; - BASE = CITY ? ((Math.imul(CITY.seed | 0, 52711) >>> 6) & 0x3fffff) : 0; + BASE = CITY ? ((Math.imul(CITY.seed | 0, 52711) >>> 6) & 0x3fffff) : 0; + } + + var W_WIND = 1, W_HAZE = 1, W_RAIN = 0; + + var D_SKY = 0.66, D_SUN = 0.64, D_WARM = 0.74; + + function view(f, cam, t) { + PR.view(f, cam, t); + + if (!Surf) Surf = CC.Surf; + if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null; + var Wm = CC.Weather; + W_WIND = Wm && Wm.rel ? Wm.rel('wind') : 1; + W_HAZE = Wm && Wm.rel ? Wm.rel('haze') : 1; + W_RAIN = Wm && Wm.P ? Wm.P.rain : 0; + + var Dm = CC.Daylight; + D_SKY = Dm ? Dm.P.sky : 0.66; + D_SUN = Dm ? Dm.P.sun : 0.64; + D_WARM = Dm ? Dm.P.warm : 0.74; + } + + function far(f, x, y, ch, col, lum, d) { + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + put(f, x, y, ch, col, lum, d, 3); + } + + function strand(f, x0, z0, y0, x1, z1, y1, ch, col, lum) { + var n = 9, lx = -1, ly = 0, ld = 0, i; + for (i = 0; i <= n; i++) { + var u = i / n, k = u * u; + if (!project(x0 + (x1 - x0) * k, y0 + (y1 - y0) * u, z0 + (z1 - z0) * k)) { lx = -1; continue; } + var px = Math.floor(PJ.x), py = Math.floor(PJ.y), pd = PJ.d; + if (lx >= 0 && (pd > ld * 2 || ld > pd * 2)) lx = -1; + if (lx >= 0) { + var dx = px - lx, dy = py - ly; + var st = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); + if (st > V.rows * 3) st = 0; + for (var q = 1; q < st; q++) { + var tq = q / st; + emit(f, lx + Math.round(dx * tq), ly + Math.round(dy * tq), ch, col, lum, + ld + (pd - ld) * tq); + } + } + emit(f, px, py, ch, col, lum, pd); + lx = px; ly = py; ld = pd; + } + } + + function onRoad(px, pz, pad) { + var i = Math.round(px / CITY.AVE), j = Math.round(pz / CITY.CROSS), k; + for (k = -1; k <= 1; k++) { + var c = CITY.aveX(i + k) + 0.5, hw = CITY.aveW(i + k) + pad; + if (px > c - hw && px < c + hw) return 1; + var c2 = CITY.crossZ(j + k) + 0.5, hw2 = CITY.crossW(j + k) + pad; + if (pz > c2 - hw2 && pz < c2 + hw2) return 1; + } + return 0; + } + + function standing(px, pz, clear, near, far2) { + if (CITY.height(px, pz) > 0.1) return 0; + if (clear > 0 && (CITY.height(px + clear, pz) > 0.1 || CITY.height(px - clear, pz) > 0.1 || + CITY.height(px, pz + clear) > 0.1 || CITY.height(px, pz - clear) > 0.1)) return 0; + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < near || w > far2) return 0; + var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 8; + if (s < -lim || s > lim) return 0; + return w; + } + + var MB_N = [45, 29]; + var MB_H0 = [0.030, 0.105]; + var MB_HS = [0.115, 0.150]; + var MB_P = [0.62, 0.30]; + var MB_TONE = [1.00, 0.72]; + var MB_D = [8.8e4, 8.6e4]; + var MB_PITCH = [TAU / MB_N[0], TAU / MB_N[1]]; + + function step(dd) { + if (dd < 0.55) return 1.0; + if (dd < 0.78) return 0.66; + if (dd < 1.00) return 0.34; + return 0; + } + + var MF_SIDE = 0; + + function ridge(bear, b) { + var pitch = MB_PITCH[b], n = MB_N[b]; + var k0 = Math.floor(bear / pitch), best = 0, bestSide = 0, kk; + for (kk = k0 - 1; kk <= k0 + 1; kk++) { + + var slot = ((kk % n) + n) % n; + if (hash2(slot, b, BASE + 0x71) > MB_P[b]) continue; + var c = (kk + 0.5 + (hash2(slot, b, BASE + 0x72) - 0.5) * 0.60) * pitch; + var w = pitch * (0.26 + 0.36 * hash2(slot, b, BASE + 0x73)); + + var hh = hash2(slot, b, BASE + 0x74); + var top = MB_H0[b] + hh * hh * hh * MB_HS[b]; + var off = bear - c; + var s = step((off < 0 ? -off : off) / w); + if (s <= 0) continue; + var e = top * s; + if (e > best) { best = e; bestSide = off < 0 ? -1 : 1; } + } + MF_SIDE = bestSide; + + if (b === 0) { + var base = 0.0055 + 0.0115 * vnoise(bear * 2.6 + 31.7, BASE + 0x75); + if (base > best) { best = base; MF_SIDE = 0; } + } + return best; + } + + function drawMesas(f) { + var sunX = WEST ? WEST.SUN_X : -0.479, sunZ = WEST ? WEST.SUN_Z : 0.878; + var cols = V.cols, hp = V.hp, scale = V.scale; + var horiz = V.horizon, hrow = Math.floor(horiz); + if (hrow < 0) return; + if (hrow > V.rows - 1) hrow = V.rows - 1; + + var airlight = (4 + 190 * D_SKY) * clamp(0.42 + 0.46 * W_HAZE, 0.34, 1.30); + + var x, r; + for (x = 0; x < cols; x++) { + var sp = ((x + 0.5) * 2 / cols - 1) * hp; + + var dirx = V.fwx + V.rgx * sp, dirz = V.fwz + V.rgz * sp; + var il = 1 / Math.sqrt(dirx * dirx + dirz * dirz); + var nx = dirx * il, nz = dirz * il; + var bear = V.yaw + Math.atan(sp); + + var toSun = nx * sunX + nz * sunZ; + var rgtSun = nz * sunX - nx * sunZ; + + var b; + for (b = 0; b < 2; b++) { + var elev = ridge(bear, b); + if (elev <= 0) continue; + + var yTop = horiz - Math.tan(elev) * scale; + var r0 = Math.floor(yTop); + if (r0 > hrow) continue; + if (r0 < 0) r0 = 0; + + var d = MF_SIDE * rgtSun; + var kk = clamp(0.5 + 0.62 * d, 0, 1); + var lit = 0.10 + 0.90 * kk * kk * (3 - 2 * kk); + lit = 0.35 + 0.65 * lit * D_SUN; + + var backlit = clamp(toSun, 0, 1) * D_WARM; + var tone = MB_TONE[b]; + + var body = airlight * tone * (0.34 + 0.58 * lit) * (1 - 0.42 * backlit); + var dist = MB_D[b]; + + for (r = r0; r <= hrow; r++) { + if (r === r0) { + + var cl = body * 1.5 + airlight * tone * 0.30 + + 190 * backlit * clamp(toSun - 0.30, 0, 0.7) * 1.4; + var ccol = (D_WARM > 0.35 && (backlit > 0.18 || lit > 0.72)) ? P.amber + : (D_SKY > 0.42 ? P.white : P.slate); + far(f, x, r, elev > 0.030 ? G_UNDER : G_DASH, ccol, cl, dist - 1); + continue; + } + + var dens = 0.16 + 0.40 * D_SKY; + var h = hash2(Math.floor(bear * 240), (hrow - r) * 3 + b, BASE + 0x76); + if (h > dens || body < 4) { far(f, x, r, 0, P.shadow, 0, dist); continue; } + + far(f, x, r, h < dens * 0.42 ? G_DASH : (h < dens * 0.78 ? G_UNDER : G_TICK), + D_SKY > 0.55 ? P.white : (D_WARM > 0.40 ? P.ember : P.slate), + body * (0.62 + 0.70 * (h / dens)), dist); + } + } + } + } + + var YUC_LAT = 6.7, MES_LAT = 11.3, OCO_LAT = 13.9, WASH_LAT = 9.7; + + function drawPlants(f) { + var i, j, w, x, y, dd; + var sunX = (WEST && WEST.SUN_X < 0) ? -1 : 1; + + var sunA = litFace(1, 0), sunB = litFace(0, 1); + var sun = sunA > sunB ? sunA : sunB; + + var day = clamp(0.14 + 0.86 * D_SUN, 0, 1); + var hot = sun > 0.6 && D_SUN > 0.35; + + var dF = dayFill(); + + var lo = Math.floor((V.ox - 46) / YUC_LAT), hi = Math.floor((V.ox + 46) / YUC_LAT); + var lo2 = Math.floor((V.oz - 46) / YUC_LAT), hi2 = Math.floor((V.oz + 46) / YUC_LAT); + for (j = lo2; j <= hi2; j++) { + for (i = lo; i <= hi; i++) { + var yh = hash2(i, j, BASE + 0x21); + if (yh > 0.28) continue; + var yx = i * YUC_LAT + hash2(i, j, BASE + 0x22) * YUC_LAT; + var yz = j * YUC_LAT + hash2(i, j, BASE + 0x23) * YUC_LAT; + if (onRoad(yx, yz, 2.4)) continue; + w = standing(yx, yz, 1.3, 1.0, 52); + if (!w) continue; + var stalk = 1.5 + (yh / 0.28) * 1.0; + column(f, yx, yz, 0, 0.55, G_STAR, leafC(yh, dF), 24 + 30 * day + 84 * dF, 0); + + if (w < 22) { + if (project(yx - 0.34, 0.42, yz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_SLASH, P.slate, 20 + 26 * day, PJ.d); + if (project(yx + 0.34, 0.42, yz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_BSL, P.slate, 20 + 26 * day, PJ.d); + } + column(f, yx, yz, 0.5, stalk, G_PIPE, P.slate, 18 + 34 * day, 0); + if (project(yx, stalk + 0.12, yz)) { + x = Math.floor(PJ.x); y = Math.floor(PJ.y); dd = PJ.d; + emit(f, x, y, G_8, hot ? P.white : P.slate, (hot ? 128 : 40) * (0.6 + 0.5 * day), dd); + if (w < 26) emit(f, x, y + 1, G_o, hot ? P.white : P.slate, (hot ? 92 : 30) * (0.6 + 0.5 * day), dd); + } + } } - var W_WIND = 1, W_HAZE = 1, W_RAIN = 0; + lo = Math.floor((V.ox - 62) / MES_LAT); hi = Math.floor((V.ox + 62) / MES_LAT); + lo2 = Math.floor((V.oz - 62) / MES_LAT); hi2 = Math.floor((V.oz + 62) / MES_LAT); + for (j = lo2; j <= hi2; j++) { + for (i = lo; i <= hi; i++) { + var mh = hash2(i, j, BASE + 0x31); + if (mh > 0.46) continue; + var mx = i * MES_LAT + hash2(i, j, BASE + 0x32) * MES_LAT; + var mz = j * MES_LAT + hash2(i, j, BASE + 0x33) * MES_LAT; + if (onRoad(mx, mz, 2.8)) continue; + w = standing(mx, mz, 2.0, 1.4, 62); + if (!w) continue; + var top = 2.0 + (mh / 0.46) * 1.0; + var half = 0.9 + mh * 1.8; + if (!project(mx, 0.10, mz)) continue; + var bcx = PJ.x, bry = PJ.y, bd = PJ.d; + if (!project(mx, top, mz)) continue; + var trY = PJ.y; + var rw = half * V.colK / w; + var iw = Math.ceil(rw); if (iw > 30) iw = 30; + var q, r2; + for (q = -iw; q <= iw; q++) { + var u = rw > 0.5 ? q / rw : 0; + if (u < -1 || u > 1) continue; + var qh = hash2(i * 31 + q, j, BASE + 0x34); - var D_SKY = 0.66, D_SUN = 0.64, D_WARM = 0.74; + var prof = Math.sqrt(1 - u * u) * (0.72 + 0.34 * qh); + var rTop = Math.floor(bry + (trY - bry) * (0.34 + 0.66 * prof)); + var rBot = Math.floor(bry); + var cx2 = Math.floor(bcx + q); + var side = (q * sunX > 0) ? 1 : 0; + var mcol = hot && side ? (dF > 0.5 ? P.moss : P.amber) : leafC(mh / 0.46, dF); + var mlum = (hot && side ? 68 + 92 * dF : 24 + 74 * dF) * (0.55 + 0.60 * day); + for (r2 = rTop; r2 <= rBot; r2++) { + var deep = r2 - rTop; + if (deep > 1 && hash2(cx2 * 3 + deep, i * 5 + j, BASE + 0x35) > 0.26) continue; + emit(f, cx2, r2, deep === 0 ? G_AMP : (qh < 0.6 ? G_PCT : G_STAR), + mcol, mlum * (deep === 0 ? 1.25 : 0.8) * (0.7 + 0.5 * qh), bd); + } + } - function view(f, cam, t) { - PR.view(f, cam, t); - - if (!Surf) Surf = CC.Surf; - if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null; - var Wm = CC.Weather; - W_WIND = Wm && Wm.rel ? Wm.rel('wind') : 1; - W_HAZE = Wm && Wm.rel ? Wm.rel('haze') : 1; - W_RAIN = Wm && Wm.P ? Wm.P.rain : 0; - - var Dm = CC.Daylight; - D_SKY = Dm ? Dm.P.sky : 0.66; - D_SUN = Dm ? Dm.P.sun : 0.64; - D_WARM = Dm ? Dm.P.warm : 0.74; + if (w < 24 && project(mx, 0.05, mz)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, P.slate, 12, PJ.d); + } } - function far(f, x, y, ch, col, lum, d) { - if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; - put(f, x, y, ch, col, lum, d, 3); + lo = Math.floor((V.ox - 58) / OCO_LAT); hi = Math.floor((V.ox + 58) / OCO_LAT); + lo2 = Math.floor((V.oz - 58) / OCO_LAT); hi2 = Math.floor((V.oz + 58) / OCO_LAT); + for (j = lo2; j <= hi2; j++) { + for (i = lo; i <= hi; i++) { + var oh = hash2(i, j, BASE + 0x41); + if (oh > 0.32) continue; + var ox = i * OCO_LAT + hash2(i, j, BASE + 0x42) * OCO_LAT; + var oz = j * OCO_LAT + hash2(i, j, BASE + 0x43) * OCO_LAT; + if (onRoad(ox, oz, 2.6)) continue; + w = standing(ox, oz, 1.8, 1.6, 58); + if (!w) continue; + var nw = 4 + Math.floor(hash2(i, j, BASE + 0x44) * 3); + var bloom = hash2(i, j, BASE + 0x45) < 0.22; + var q2; + for (q2 = 0; q2 < nw; q2++) { + var a = (q2 / nw) * TAU + hash2(i * 17 + q2, j, BASE + 0x46) * 0.9; + var wh2 = hash2(i, j * 13 + q2, BASE + 0x47); + var len = 2.0 + wh2 * 2.0; + var spread = 0.55 + wh2 * 0.85; + strand(f, ox, oz, 0.05, + ox + Math.cos(a) * spread, oz + Math.sin(a) * spread, len, + Math.abs(Math.cos(a)) > 0.72 ? (Math.cos(a) > 0 ? G_SLASH : G_BSL) : G_PIPE, + P.slate, (16 + 40 * day) * (0.7 + 0.5 * wh2)); + if (bloom && project(ox + Math.cos(a) * spread, len + 0.1, oz + Math.sin(a) * spread)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_STAR, P.ember, 58 + 90 * day, PJ.d); + } + } } - function strand(f, x0, z0, y0, x1, z1, y1, ch, col, lum) { - var n = 9, lx = -1, ly = 0, ld = 0, i; - for (i = 0; i <= n; i++) { - var u = i / n, k = u * u; - if (!project(x0 + (x1 - x0) * k, y0 + (y1 - y0) * u, z0 + (z1 - z0) * k)) { lx = -1; continue; } - var px = Math.floor(PJ.x), py = Math.floor(PJ.y), pd = PJ.d; - if (lx >= 0 && (pd > ld * 2 || ld > pd * 2)) lx = -1; - if (lx >= 0) { - var dx = px - lx, dy = py - ly; - var st = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); - if (st > V.rows * 3) st = 0; - for (var q = 1; q < st; q++) { - var tq = q / st; - emit(f, lx + Math.round(dx * tq), ly + Math.round(dy * tq), ch, col, lum, - ld + (pd - ld) * tq); - } - } - emit(f, px, py, ch, col, lum, pd); - lx = px; ly = py; ld = pd; + lo = Math.floor((V.ox - 40) / WASH_LAT); hi = Math.floor((V.ox + 40) / WASH_LAT); + lo2 = Math.floor((V.oz - 40) / WASH_LAT); hi2 = Math.floor((V.oz + 40) / WASH_LAT); + for (j = lo2; j <= hi2; j++) { + for (i = lo; i <= hi; i++) { + var gh = hash2(i, j, BASE + 0x51); + if (gh > 0.34) continue; + var gx = i * WASH_LAT + hash2(i, j, BASE + 0x52) * WASH_LAT; + var gz = j * WASH_LAT + hash2(i, j, BASE + 0x53) * WASH_LAT; + if (onRoad(gx, gz, 3.0)) continue; + w = standing(gx, gz, 1.6, 1.2, 40); + if (!w) continue; + var ba = hash2(i, j, BASE + 0x54) * TAU; + var bx = Math.cos(ba), bz = Math.sin(ba); + var q3, N = w < 16 ? 15 : 9; + for (q3 = 0; q3 < N; q3++) { + var u2 = (q3 / (N - 1)) * 2 - 1; + var jit = hash2(i * 7 + q3, j * 3, BASE + 0x55) - 0.5; + var wxp = gx + bx * u2 * 3.6 - bz * jit * 1.1; + var wzp = gz + bz * u2 * 3.6 + bx * jit * 1.1; + if (CITY.height(wxp, wzp) > 0.1) continue; + var g2 = hash2(i * 11 + q3, j * 5, BASE + 0x56); + + if (project(wxp, 0.02, wzp)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), g2 < 0.5 ? G_UNDER : G_TILDE, + hot ? P.white : leafC(oh / 0.32, dF), (18 + 66 * day + 76 * dF) * (0.6 + 0.6 * g2), PJ.d); + + if (g2 > 0.62 && (u2 < -0.35 || u2 > 0.35) && project(wxp, 0.10 + g2 * 0.34, wzp)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), g2 > 0.86 ? G_QUOTE : G_TICK, + P.amber, (26 + 76 * day) * (0.6 + 0.5 * g2), PJ.d); } + } + } + } + + var DU_MAX = 3600, DU_AT_REF = 420, DU_REF_CELLS = 200 * 60; + var DU_BOX_N = 24, DU_BOX_F = 68; + var duOx = null, duOz = null, duY = null, duSpd = null, duHue = null; + + function initDust(rng) { + + var r = CC.mulberry(((rng() * 4294967296) | 0) ^ 0x5C1E), i; + duOx = new Float32Array(DU_MAX); duOz = new Float32Array(DU_MAX); + duY = new Float32Array(DU_MAX); duSpd = new Float32Array(DU_MAX); + duHue = new Uint8Array(DU_MAX); + for (i = 0; i < DU_MAX; i++) { + var near = (i & 1) === 0; + var b = near ? DU_BOX_N : DU_BOX_F; + duOx[i] = r() * b; duOz[i] = r() * b; + + var u = r(); u = u * u; u = u * u; + duY[i] = near ? u * 1.45 : u * 3.40; + duSpd[i] = 0.62 + r() * 0.76; + + var h = r(); + duHue[i] = h < 0.52 ? P.slate : (h < 0.82 ? P.white : P.amber); + } + } + + function dayFill() { + return (CC.SurfWest && CC.SurfWest.dayFill !== undefined) ? CC.SurfWest.dayFill : 0; + } + function leafC(seedH, dF) { + if (seedH >= dF) return P.slate; + return seedH < dF * 0.42 ? P.timber : P.moss; + } + + function wrap(v, b) { return v - b * Math.floor(v / b + 0.5); } + + function veilCell(f, x, y, ch, col, lum, d, alpha) { + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + if (lum > 0 && CC.Surf) { lum = CC.Surf.fog(lum, d); if (lum <= 0) ch = 0; } + if (alpha < 0.999) { + var i = y * V.cols + x; + var dl = f.lum[i]; + lum = dl + (lum - dl) * alpha; + if (f.ch[i] !== 0) col = f.col[i]; + + var dc = f.dist[i]; + if (d < dc && dc < 1 / 0) d = dc * 0.99999; + } + put(f, x, y, ch, col, lum > 255 ? 255 : (lum < 0 ? 0 : lum | 0), d, 3); + } + + function drawDust(f) { + if (!duOx || !CITY) return; + + var settle = 1 - clamp(W_RAIN * 1.5, 0, 1); + if (settle <= 0.02) return; + + var amt = Math.pow(clamp(W_HAZE, 0.15, 2.6), 1.45) * + (0.30 + 0.70 * clamp(W_WIND, 0, 2.0)) * settle; + var use = (DU_AT_REF * clamp(amt, 0, 2.2) * V.cols * V.rows / DU_REF_CELLS) | 0; + if (use > DU_MAX) use = DU_MAX; else if (use < 6) return; + + var Wd = CC.Weather ? CC.Weather.wind : null; + var wdx, wdz, wspd; + if (Wd) { wdx = Wd.dirX; wdz = Wd.dirZ; wspd = Wd.speed; } + else { wdx = 0.92; wdz = 0.39; wspd = 2.4 * (0.35 + 0.65 * clamp(W_WIND, 0, 1.85)); } + + var tt = CC.reducedMotion ? 7.0 : V.t; + var travX = wdx * wspd * tt, travZ = wdz * wspd * tt; + + var crossV = (wdx * V.rgx + wdz * V.rgz) * wspd; + var dirSign = crossV < 0 ? -1 : 1; + + var lift = (0.06 + 0.94 * D_SKY) * (1 + 0.55 * D_WARM * D_SUN); + + var dk = dayFill(); dk = dk * (2 - dk); + + var dAlpha = 1 - 0.58 * dk; + + var nCap = (5 - 3 * dk) | 0; + + var farUse = use * clamp(0.34 + 0.46 * amt, 0.22, 1); + + var rows = V.rows, cols = V.cols, i; + for (i = 0; i < use; i++) { + var near = (i & 1) === 0; + if (!near && i >= farUse) continue; + var b = near ? DU_BOX_N : DU_BOX_F; + var wx = V.ox + wrap(duOx[i] + travX * duSpd[i] - V.ox, b); + var wz = V.oz + wrap(duOz[i] + travZ * duSpd[i] - V.oz, b); + + var rx = wx - V.ox, rz = wz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < 0.8) continue; + var rr = rx * V.rgx + rz * V.rgz; + if (rr > V.hp * 1.3 * w || rr < -V.hp * 1.3 * w) continue; + + var gh = CITY.height(wx, wz); + if (gh > 0.4) continue; + + if (!project(wx, gh + duY[i], wz)) continue; + var px = PJ.x, py = Math.floor(PJ.y), d = PJ.d; + + var n = (Math.abs(crossV) * duSpd[i] * 0.028 * V.colK / w) | 0; + if (n > nCap) n = nCap; + + var base = (near ? 74 : 46) * lift * + (1 - clamp(w / (near ? DU_BOX_N * 0.82 : DU_BOX_F * 0.85), 0, 0.72)); + if (base < 5) continue; + + var g = hash2(i, 0, BASE + 0x61); + base *= 0.55 + 0.72 * g; + + var hue = duHue[i]; + + if (hue === P.amber && D_WARM < 0.30) hue = P.white; + + var gl = n >= 3 ? G_DASH : (n >= 1 ? G_TILDE : (d > 18 ? G_DOT : G_COMMA)); + var k; + for (k = 0; k <= n; k++) { + var sx = Math.floor(px - dirSign * k); + if (sx < 0 || sx >= cols) continue; + if (py < 0 || py >= rows) continue; + + var lm = base * (1 - k * 0.17); + if (lm < 4) continue; + veilCell(f, sx, py, k === 0 ? gl : (n >= 3 ? G_DASH : G_TICK), hue, lm, d, dAlpha); + } } - function onRoad(px, pz, pad) { - var i = Math.round(px / CITY.AVE), j = Math.round(pz / CITY.CROSS), k; - for (k = -1; k <= 1; k++) { - var c = CITY.aveX(i + k) + 0.5, hw = CITY.aveW(i + k) + pad; - if (px > c - hw && px < c + hw) return 1; - var c2 = CITY.crossZ(j + k) + 0.5, hw2 = CITY.crossW(j + k) + pad; - if (pz > c2 - hw2 && pz < c2 + hw2) return 1; - } - return 0; + if (W_HAZE < 1.55 || CC.reducedMotion) return; + var veil = clamp((W_HAZE - 1.55) / 0.75, 0, 1) * settle; + + var vl = (10 + 40 * lift + 168 * (1 - dAlpha) / 0.58) * veil; + if (vl < 5) return; + var top = Math.floor(V.horizon - V.rows * 0.10); + if (top < 0) top = 0; + var drift = tt * wspd * 0.055, vy, vx2; + for (vy = top; vy < rows; vy++) { + var band = (vy - top) / (rows - top); + var dv = 0.10 + 0.34 * band * veil; + for (vx2 = 0; vx2 < cols; vx2++) { + var sp2 = ((vx2 + 0.5) * 2 / cols - 1) * V.hp; + var hv = vnoise((V.yaw + sp2) * 9.0 + (vy - top) * 0.37 + drift, BASE + 0x62); + if (hv > dv) continue; + veilCell(f, vx2, vy, band > 0.55 ? G_DOT : G_TICK, P.white, + vl * (0.6 + 0.7 * band), 44, dAlpha); + } } + } - function standing(px, pz, clear, near, far2) { - if (CITY.height(px, pz) > 0.1) return 0; - if (clear > 0 && (CITY.height(px + clear, pz) > 0.1 || CITY.height(px - clear, pz) > 0.1 || - CITY.height(px, pz + clear) > 0.1 || CITY.height(px, pz - clear) > 0.1)) return 0; - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < near || w > far2) return 0; - var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 8; - if (s < -lim || s > lim) return 0; - return w; + function mk(name, layer, fn) { + return { + name: name, layer: layer, world: 'west', + 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('west-mesas', 10, drawMesas)); + CC.ELEMENTS.push(mk('west-desert-plants', 16, drawPlants)); + + CC.ELEMENTS.push({ + name: 'west-dust', + layer: 22, + world: 'west', + init: function (city, rng) { boot(city); initDust(rng); }, + draw: function (f, cam, t) { + if (!CITY) return; + view(f, cam, t === undefined ? (cam.t || 0) : t); + drawDust(f); } - - var MB_N = [45, 29]; - var MB_H0 = [0.030, 0.105]; - var MB_HS = [0.115, 0.150]; - var MB_P = [0.62, 0.30]; - var MB_TONE = [1.00, 0.72]; - var MB_D = [8.8e4, 8.6e4]; - var MB_PITCH = [TAU / MB_N[0], TAU / MB_N[1]]; - - function step(dd) { - if (dd < 0.55) return 1.0; - if (dd < 0.78) return 0.66; - if (dd < 1.00) return 0.34; - return 0; - } - - var MF_SIDE = 0; - - function ridge(bear, b) { - var pitch = MB_PITCH[b], n = MB_N[b]; - var k0 = Math.floor(bear / pitch), best = 0, bestSide = 0, kk; - for (kk = k0 - 1; kk <= k0 + 1; kk++) { - - var slot = ((kk % n) + n) % n; - if (hash2(slot, b, BASE + 0x71) > MB_P[b]) continue; - var c = (kk + 0.5 + (hash2(slot, b, BASE + 0x72) - 0.5) * 0.60) * pitch; - var w = pitch * (0.26 + 0.36 * hash2(slot, b, BASE + 0x73)); - - var hh = hash2(slot, b, BASE + 0x74); - var top = MB_H0[b] + hh * hh * hh * MB_HS[b]; - var off = bear - c; - var s = step((off < 0 ? -off : off) / w); - if (s <= 0) continue; - var e = top * s; - if (e > best) { best = e; bestSide = off < 0 ? -1 : 1; } - } - MF_SIDE = bestSide; - - if (b === 0) { - var base = 0.0055 + 0.0115 * vnoise(bear * 2.6 + 31.7, BASE + 0x75); - if (base > best) { best = base; MF_SIDE = 0; } - } - return best; - } - - function drawMesas(f) { - var sunX = WEST ? WEST.SUN_X : -0.479, sunZ = WEST ? WEST.SUN_Z : 0.878; - var cols = V.cols, hp = V.hp, scale = V.scale; - var horiz = V.horizon, hrow = Math.floor(horiz); - if (hrow < 0) return; - if (hrow > V.rows - 1) hrow = V.rows - 1; - - var airlight = (4 + 190 * D_SKY) * clamp(0.42 + 0.46 * W_HAZE, 0.34, 1.30); - - var x, r; - for (x = 0; x < cols; x++) { - var sp = ((x + 0.5) * 2 / cols - 1) * hp; - - var dirx = V.fwx + V.rgx * sp, dirz = V.fwz + V.rgz * sp; - var il = 1 / Math.sqrt(dirx * dirx + dirz * dirz); - var nx = dirx * il, nz = dirz * il; - var bear = V.yaw + Math.atan(sp); - - var toSun = nx * sunX + nz * sunZ; - var rgtSun = nz * sunX - nx * sunZ; - - var b; - for (b = 0; b < 2; b++) { - var elev = ridge(bear, b); - if (elev <= 0) continue; - - var yTop = horiz - Math.tan(elev) * scale; - var r0 = Math.floor(yTop); - if (r0 > hrow) continue; - if (r0 < 0) r0 = 0; - - var d = MF_SIDE * rgtSun; - var kk = clamp(0.5 + 0.62 * d, 0, 1); - var lit = 0.10 + 0.90 * kk * kk * (3 - 2 * kk); - lit = 0.35 + 0.65 * lit * D_SUN; - - var backlit = clamp(toSun, 0, 1) * D_WARM; - var tone = MB_TONE[b]; - - var body = airlight * tone * (0.34 + 0.58 * lit) * (1 - 0.42 * backlit); - var dist = MB_D[b]; - - for (r = r0; r <= hrow; r++) { - if (r === r0) { - - var cl = body * 1.5 + airlight * tone * 0.30 + - 190 * backlit * clamp(toSun - 0.30, 0, 0.7) * 1.4; - var ccol = (D_WARM > 0.35 && (backlit > 0.18 || lit > 0.72)) ? P.amber - : (D_SKY > 0.42 ? P.white : P.slate); - far(f, x, r, elev > 0.030 ? G_UNDER : G_DASH, ccol, cl, dist - 1); - continue; - } - - var dens = 0.16 + 0.40 * D_SKY; - var h = hash2(Math.floor(bear * 240), (hrow - r) * 3 + b, BASE + 0x76); - if (h > dens || body < 4) { far(f, x, r, 0, P.shadow, 0, dist); continue; } - - far(f, x, r, h < dens * 0.42 ? G_DASH : (h < dens * 0.78 ? G_UNDER : G_TICK), - D_SKY > 0.55 ? P.white : (D_WARM > 0.40 ? P.ember : P.slate), - body * (0.62 + 0.70 * (h / dens)), dist); - } - } - } - } - - var YUC_LAT = 6.7, MES_LAT = 11.3, OCO_LAT = 13.9, WASH_LAT = 9.7; - - function drawPlants(f) { - var i, j, w, x, y, dd; - var sunX = (WEST && WEST.SUN_X < 0) ? -1 : 1; - - var sunA = litFace(1, 0), sunB = litFace(0, 1); - var sun = sunA > sunB ? sunA : sunB; - - var day = clamp(0.14 + 0.86 * D_SUN, 0, 1); - var hot = sun > 0.6 && D_SUN > 0.35; - - var lo = Math.floor((V.ox - 46) / YUC_LAT), hi = Math.floor((V.ox + 46) / YUC_LAT); - var lo2 = Math.floor((V.oz - 46) / YUC_LAT), hi2 = Math.floor((V.oz + 46) / YUC_LAT); - for (j = lo2; j <= hi2; j++) { - for (i = lo; i <= hi; i++) { - var yh = hash2(i, j, BASE + 0x21); - if (yh > 0.28) continue; - var yx = i * YUC_LAT + hash2(i, j, BASE + 0x22) * YUC_LAT; - var yz = j * YUC_LAT + hash2(i, j, BASE + 0x23) * YUC_LAT; - if (onRoad(yx, yz, 2.4)) continue; - w = standing(yx, yz, 1.3, 1.0, 52); - if (!w) continue; - var stalk = 1.5 + (yh / 0.28) * 1.0; - column(f, yx, yz, 0, 0.55, G_STAR, P.slate, 24 + 30 * day, 0); - - if (w < 22) { - if (project(yx - 0.34, 0.42, yz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_SLASH, P.slate, 20 + 26 * day, PJ.d); - if (project(yx + 0.34, 0.42, yz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_BSL, P.slate, 20 + 26 * day, PJ.d); - } - column(f, yx, yz, 0.5, stalk, G_PIPE, P.slate, 18 + 34 * day, 0); - if (project(yx, stalk + 0.12, yz)) { - x = Math.floor(PJ.x); y = Math.floor(PJ.y); dd = PJ.d; - emit(f, x, y, G_8, hot ? P.white : P.slate, (hot ? 128 : 40) * (0.6 + 0.5 * day), dd); - if (w < 26) emit(f, x, y + 1, G_o, hot ? P.white : P.slate, (hot ? 92 : 30) * (0.6 + 0.5 * day), dd); - } - } - } - - lo = Math.floor((V.ox - 62) / MES_LAT); hi = Math.floor((V.ox + 62) / MES_LAT); - lo2 = Math.floor((V.oz - 62) / MES_LAT); hi2 = Math.floor((V.oz + 62) / MES_LAT); - for (j = lo2; j <= hi2; j++) { - for (i = lo; i <= hi; i++) { - var mh = hash2(i, j, BASE + 0x31); - if (mh > 0.46) continue; - var mx = i * MES_LAT + hash2(i, j, BASE + 0x32) * MES_LAT; - var mz = j * MES_LAT + hash2(i, j, BASE + 0x33) * MES_LAT; - if (onRoad(mx, mz, 2.8)) continue; - w = standing(mx, mz, 2.0, 1.4, 62); - if (!w) continue; - var top = 2.0 + (mh / 0.46) * 1.0; - var half = 0.9 + mh * 1.8; - if (!project(mx, 0.10, mz)) continue; - var bcx = PJ.x, bry = PJ.y, bd = PJ.d; - if (!project(mx, top, mz)) continue; - var trY = PJ.y; - var rw = half * V.colK / w; - var iw = Math.ceil(rw); if (iw > 30) iw = 30; - var q, r2; - for (q = -iw; q <= iw; q++) { - var u = rw > 0.5 ? q / rw : 0; - if (u < -1 || u > 1) continue; - var qh = hash2(i * 31 + q, j, BASE + 0x34); - - var prof = Math.sqrt(1 - u * u) * (0.72 + 0.34 * qh); - var rTop = Math.floor(bry + (trY - bry) * (0.34 + 0.66 * prof)); - var rBot = Math.floor(bry); - var cx2 = Math.floor(bcx + q); - var side = (q * sunX > 0) ? 1 : 0; - var mcol = hot && side ? P.amber : P.slate; - var mlum = (hot && side ? 68 : 24) * (0.55 + 0.60 * day); - for (r2 = rTop; r2 <= rBot; r2++) { - var deep = r2 - rTop; - if (deep > 1 && hash2(cx2 * 3 + deep, i * 5 + j, BASE + 0x35) > 0.26) continue; - emit(f, cx2, r2, deep === 0 ? G_AMP : (qh < 0.6 ? G_PCT : G_STAR), - mcol, mlum * (deep === 0 ? 1.25 : 0.8) * (0.7 + 0.5 * qh), bd); - } - } - - if (w < 24 && project(mx, 0.05, mz)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, P.slate, 12, PJ.d); - } - } - - lo = Math.floor((V.ox - 58) / OCO_LAT); hi = Math.floor((V.ox + 58) / OCO_LAT); - lo2 = Math.floor((V.oz - 58) / OCO_LAT); hi2 = Math.floor((V.oz + 58) / OCO_LAT); - for (j = lo2; j <= hi2; j++) { - for (i = lo; i <= hi; i++) { - var oh = hash2(i, j, BASE + 0x41); - if (oh > 0.32) continue; - var ox = i * OCO_LAT + hash2(i, j, BASE + 0x42) * OCO_LAT; - var oz = j * OCO_LAT + hash2(i, j, BASE + 0x43) * OCO_LAT; - if (onRoad(ox, oz, 2.6)) continue; - w = standing(ox, oz, 1.8, 1.6, 58); - if (!w) continue; - var nw = 4 + Math.floor(hash2(i, j, BASE + 0x44) * 3); - var bloom = hash2(i, j, BASE + 0x45) < 0.22; - var q2; - for (q2 = 0; q2 < nw; q2++) { - var a = (q2 / nw) * TAU + hash2(i * 17 + q2, j, BASE + 0x46) * 0.9; - var wh2 = hash2(i, j * 13 + q2, BASE + 0x47); - var len = 2.0 + wh2 * 2.0; - var spread = 0.55 + wh2 * 0.85; - strand(f, ox, oz, 0.05, - ox + Math.cos(a) * spread, oz + Math.sin(a) * spread, len, - Math.abs(Math.cos(a)) > 0.72 ? (Math.cos(a) > 0 ? G_SLASH : G_BSL) : G_PIPE, - P.slate, (16 + 40 * day) * (0.7 + 0.5 * wh2)); - if (bloom && project(ox + Math.cos(a) * spread, len + 0.1, oz + Math.sin(a) * spread)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_STAR, P.ember, 58 + 90 * day, PJ.d); - } - } - } - - lo = Math.floor((V.ox - 40) / WASH_LAT); hi = Math.floor((V.ox + 40) / WASH_LAT); - lo2 = Math.floor((V.oz - 40) / WASH_LAT); hi2 = Math.floor((V.oz + 40) / WASH_LAT); - for (j = lo2; j <= hi2; j++) { - for (i = lo; i <= hi; i++) { - var gh = hash2(i, j, BASE + 0x51); - if (gh > 0.34) continue; - var gx = i * WASH_LAT + hash2(i, j, BASE + 0x52) * WASH_LAT; - var gz = j * WASH_LAT + hash2(i, j, BASE + 0x53) * WASH_LAT; - if (onRoad(gx, gz, 3.0)) continue; - w = standing(gx, gz, 1.6, 1.2, 40); - if (!w) continue; - var ba = hash2(i, j, BASE + 0x54) * TAU; - var bx = Math.cos(ba), bz = Math.sin(ba); - var q3, N = w < 16 ? 15 : 9; - for (q3 = 0; q3 < N; q3++) { - var u2 = (q3 / (N - 1)) * 2 - 1; - var jit = hash2(i * 7 + q3, j * 3, BASE + 0x55) - 0.5; - var wxp = gx + bx * u2 * 3.6 - bz * jit * 1.1; - var wzp = gz + bz * u2 * 3.6 + bx * jit * 1.1; - if (CITY.height(wxp, wzp) > 0.1) continue; - var g2 = hash2(i * 11 + q3, j * 5, BASE + 0x56); - - if (project(wxp, 0.02, wzp)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), g2 < 0.5 ? G_UNDER : G_TILDE, - hot ? P.white : P.slate, (18 + 66 * day) * (0.6 + 0.6 * g2), PJ.d); - - if (g2 > 0.62 && (u2 < -0.35 || u2 > 0.35) && project(wxp, 0.10 + g2 * 0.34, wzp)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), g2 > 0.86 ? G_QUOTE : G_TICK, - P.amber, (26 + 76 * day) * (0.6 + 0.5 * g2), PJ.d); - } - } - } - } - - var DU_MAX = 3600, DU_AT_REF = 420, DU_REF_CELLS = 200 * 60; - var DU_BOX_N = 24, DU_BOX_F = 68; - var duOx = null, duOz = null, duY = null, duSpd = null, duHue = null; - - function initDust(rng) { - - var r = CC.mulberry(((rng() * 4294967296) | 0) ^ 0x5C1E), i; - duOx = new Float32Array(DU_MAX); duOz = new Float32Array(DU_MAX); - duY = new Float32Array(DU_MAX); duSpd = new Float32Array(DU_MAX); - duHue = new Uint8Array(DU_MAX); - for (i = 0; i < DU_MAX; i++) { - var near = (i & 1) === 0; - var b = near ? DU_BOX_N : DU_BOX_F; - duOx[i] = r() * b; duOz[i] = r() * b; - - var u = r(); u = u * u; u = u * u; - duY[i] = near ? u * 1.45 : u * 3.40; - duSpd[i] = 0.62 + r() * 0.76; - - var h = r(); - duHue[i] = h < 0.52 ? P.slate : (h < 0.82 ? P.white : P.amber); - } - } - - function wrap(v, b) { return v - b * Math.floor(v / b + 0.5); } - - function drawDust(f) { - if (!duOx || !CITY) return; - - var settle = 1 - clamp(W_RAIN * 1.5, 0, 1); - if (settle <= 0.02) return; - - var amt = Math.pow(clamp(W_HAZE, 0.15, 2.6), 1.45) * - (0.30 + 0.70 * clamp(W_WIND, 0, 2.0)) * settle; - var use = (DU_AT_REF * clamp(amt, 0, 2.2) * V.cols * V.rows / DU_REF_CELLS) | 0; - if (use > DU_MAX) use = DU_MAX; else if (use < 6) return; - - var Wd = CC.Weather ? CC.Weather.wind : null; - var wdx, wdz, wspd; - if (Wd) { wdx = Wd.dirX; wdz = Wd.dirZ; wspd = Wd.speed; } - else { wdx = 0.92; wdz = 0.39; wspd = 2.4 * (0.35 + 0.65 * clamp(W_WIND, 0, 1.85)); } - - var tt = CC.reducedMotion ? 7.0 : V.t; - var travX = wdx * wspd * tt, travZ = wdz * wspd * tt; - - var crossV = (wdx * V.rgx + wdz * V.rgz) * wspd; - var dirSign = crossV < 0 ? -1 : 1; - - var lift = (0.06 + 0.94 * D_SKY) * (1 + 0.55 * D_WARM * D_SUN); - - var farUse = use * clamp(0.34 + 0.46 * amt, 0.22, 1); - - var rows = V.rows, cols = V.cols, i; - for (i = 0; i < use; i++) { - var near = (i & 1) === 0; - if (!near && i >= farUse) continue; - var b = near ? DU_BOX_N : DU_BOX_F; - var wx = V.ox + wrap(duOx[i] + travX * duSpd[i] - V.ox, b); - var wz = V.oz + wrap(duOz[i] + travZ * duSpd[i] - V.oz, b); - - var rx = wx - V.ox, rz = wz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < 0.8) continue; - var rr = rx * V.rgx + rz * V.rgz; - if (rr > V.hp * 1.3 * w || rr < -V.hp * 1.3 * w) continue; - - var gh = CITY.height(wx, wz); - if (gh > 0.4) continue; - - if (!project(wx, gh + duY[i], wz)) continue; - var px = PJ.x, py = Math.floor(PJ.y), d = PJ.d; - - var n = (Math.abs(crossV) * duSpd[i] * 0.028 * V.colK / w) | 0; - if (n > 5) n = 5; - - var base = (near ? 74 : 46) * lift * - (1 - clamp(w / (near ? DU_BOX_N * 0.82 : DU_BOX_F * 0.85), 0, 0.72)); - if (base < 5) continue; - - var g = hash2(i, 0, BASE + 0x61); - base *= 0.55 + 0.72 * g; - - var hue = duHue[i]; - - if (hue === P.amber && D_WARM < 0.30) hue = P.white; - - var gl = n >= 3 ? G_DASH : (n >= 1 ? G_TILDE : (d > 18 ? G_DOT : G_COMMA)); - var k; - for (k = 0; k <= n; k++) { - var sx = Math.floor(px - dirSign * k); - if (sx < 0 || sx >= cols) continue; - if (py < 0 || py >= rows) continue; - - var lm = base * (1 - k * 0.17); - if (lm < 4) continue; - emit(f, sx, py, k === 0 ? gl : (n >= 3 ? G_DASH : G_TICK), hue, lm, d); - } - } - - if (W_HAZE < 1.55 || CC.reducedMotion) return; - var veil = clamp((W_HAZE - 1.55) / 0.75, 0, 1) * settle; - var vl = (10 + 40 * lift) * veil; - if (vl < 5) return; - var top = Math.floor(V.horizon - V.rows * 0.10); - if (top < 0) top = 0; - var drift = tt * wspd * 0.055, vy, vx2; - for (vy = top; vy < rows; vy++) { - var band = (vy - top) / (rows - top); - var dv = 0.10 + 0.34 * band * veil; - for (vx2 = 0; vx2 < cols; vx2++) { - var sp2 = ((vx2 + 0.5) * 2 / cols - 1) * V.hp; - var hv = vnoise((V.yaw + sp2) * 9.0 + (vy - top) * 0.37 + drift, BASE + 0x62); - if (hv > dv) continue; - emit(f, vx2, vy, band > 0.55 ? G_DOT : G_TICK, P.white, vl * (0.6 + 0.7 * band), 44); - } - } - } - - function mk(name, layer, fn) { - return { - name: name, layer: layer, world: 'west', - 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('west-mesas', 10, drawMesas)); - CC.ELEMENTS.push(mk('west-desert-plants', 16, drawPlants)); - - CC.ELEMENTS.push({ - name: 'west-dust', - layer: 22, - world: 'west', - init: function (city, rng) { boot(city); initDust(rng); }, - draw: function (f, cam, t) { - if (!CITY) return; - view(f, cam, t === undefined ? (cam.t || 0) : t); - drawDust(f); - } - }); + }); })(CC); /* src/elements/west_range.js */ (function (CC) { - 'use strict'; + 'use strict'; - 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 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, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp; + var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp; - var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_DOT = CC.g('.'), - G_COMMA = CC.g(','), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_STAR = CC.g('*'); + var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_DOT = CC.g('.'), + G_COMMA = CC.g(','), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_STAR = CC.g('*'), + G_o = CC.g('o'); - var CITY = null, BASE = 0, Surf = null, WEST = null; - function boot(city) { - CITY = (city && city.aveX && city.world === 'west') ? city : null; - BASE = CITY ? ((Math.imul(CITY.seed | 0, 26417) >>> 7) & 0x3fffff) : 0; - } + var CITY = null, BASE = 0, Surf = null, WEST = null; + function boot(city) { + CITY = (city && city.aveX && city.world === 'west') ? city : null; + BASE = CITY ? ((Math.imul(CITY.seed | 0, 26417) >>> 7) & 0x3fffff) : 0; + } - var W_WIND = 1, W_RAIN = 0, W_DUST = 0.3; + var W_WIND = 1, W_RAIN = 0, W_DUST = 0.3; - function view(f, cam, t) { - PR.view(f, cam, t); + function view(f, cam, t) { + PR.view(f, cam, t); - if (!Surf) Surf = CC.Surf; - if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null; - W_WIND = CC.Weather ? CC.Weather.rel('wind') : 1; - W_RAIN = CC.Weather ? CC.Weather.P.rain : 0; - W_DUST = CC.Weather ? CC.Weather.P.haze : 0.3; - } + if (!Surf) Surf = CC.Surf; + if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null; + W_WIND = CC.Weather ? CC.Weather.rel('wind') : 1; + W_RAIN = CC.Weather ? CC.Weather.P.rain : 0; + W_DUST = CC.Weather ? CC.Weather.P.haze : 0.3; + } - function wx(axis, along, cross) { return axis ? along : cross; } - function wz(axis, along, cross) { return axis ? cross : along; } - function nearIdx(axis) { - return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)); - } + function wx(axis, along, cross) { return axis ? along : cross; } + function wz(axis, along, cross) { return axis ? cross : along; } + function nearIdx(axis) { + return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)); + } - var POLE_PITCH = 27.0, POLE_H = 7.4; + var POLE_PITCH = 27.0, POLE_H = 7.4; - function drawTelegraph(f, axis, idx) { - var c, hw; - if (axis) { c = CITY.crossZ(idx); hw = CITY.crossW(idx); } - else { c = CITY.aveX(idx); hw = CITY.aveW(idx); } + function drawTelegraph(f, axis, idx) { + var c, hw; + if (axis) { c = CITY.crossZ(idx); hw = CITY.crossW(idx); } + else { c = CITY.aveX(idx); hw = CITY.aveW(idx); } - var side = hash2(idx, axis, BASE + 0x11) < 0.5 ? -1 : 1; - var cross = c + 0.5 + side * (hw + 0.75); + var side = hash2(idx, axis, BASE + 0x11) < 0.5 ? -1 : 1; + var cross = c + 0.5 + side * (hw + 0.75); - var here = axis ? V.ox : V.oz; - var lo = Math.floor((here - 90) / POLE_PITCH), hi = Math.floor((here + 90) / POLE_PITCH); - if (hi - lo > 12) hi = lo + 12; + var here = axis ? V.ox : V.oz; + var lo = Math.floor((here - 90) / POLE_PITCH), hi = Math.floor((here + 90) / POLE_PITCH); + if (hi - lo > 12) hi = lo + 12; - var sunA = litFace(axis ? 1 : 0, axis ? 0 : 1); - var sunB = litFace(axis ? -1 : 0, axis ? 0 : -1); - var sun = sunA > sunB ? sunA : sunB; - var pcol = sun > 0.6 ? P.amber : P.slate, plum = sun > 0.6 ? 96 : 26; + var sunA = litFace(axis ? 1 : 0, axis ? 0 : 1); + var sunB = litFace(axis ? -1 : 0, axis ? 0 : -1); + var sun = sunA > sunB ? sunA : sunB; - for (var k = lo; k <= hi; k++) { - var a0 = k * POLE_PITCH + hash2(k, idx, BASE + 0x12) * 3.0; - var a1 = (k + 1) * POLE_PITCH + hash2(k + 1, idx, BASE + 0x12) * 3.0; - var hgt = POLE_H + hash2(k, idx, BASE + 0x13) * 1.2; + var dF = (CC.SurfWest && CC.SurfWest.dayFill !== undefined) ? CC.SurfWest.dayFill : 0; + var day = hash2(idx, axis, BASE + 0x14) < dF; + var pcol = day ? (sun > 0.6 ? P.timber : P.stone) : (sun > 0.6 ? P.amber : P.slate); + var plum = day ? (sun > 0.6 ? 120 : 86) : (sun > 0.6 ? 96 : 26); - if (CITY.height(wx(axis, a0, cross), wz(axis, a0, cross)) > 0.5) continue; + for (var k = lo; k <= hi; k++) { + var a0 = k * POLE_PITCH + hash2(k, idx, BASE + 0x12) * 3.0; + var a1 = (k + 1) * POLE_PITCH + hash2(k + 1, idx, BASE + 0x12) * 3.0; + var hgt = POLE_H + hash2(k, idx, BASE + 0x13) * 1.2; - column(f, wx(axis, a0, cross), wz(axis, a0, cross), 0, hgt, G_PIPE, pcol, plum, 0); + if (CITY.height(wx(axis, a0, cross), wz(axis, a0, cross)) > 0.5) continue; - var ay = hgt - 0.55; - var i; - for (i = -1; i <= 1; i++) { - if (!i) continue; - var ax2 = wx(axis, a0, cross + i * 0.9), az2 = wz(axis, a0, cross + i * 0.9); - if (project(ax2, ay, az2)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, pcol, plum, PJ.d); - } + column(f, wx(axis, a0, cross), wz(axis, a0, cross), 0, hgt, G_PIPE, pcol, plum, 0); - var span = a1 - a0, sag = 0.9; - var lx = -1, ly = 0, ld = 0; - for (i = 0; i <= 16; i++) { - var u = i / 16, a = a0 + span * u; - var yy = hgt - 0.2 - sag * 4 * u * (1 - u); - if (!project(wx(axis, a, cross), yy, wz(axis, a, cross))) { lx = -1; continue; } - var px = Math.floor(PJ.x), py = Math.floor(PJ.y), pd = PJ.d; - if (lx >= 0 && (pd > ld * 2 || ld > pd * 2)) lx = -1; - if (lx >= 0) { - var dx = px - lx, dy = py - ly; - var st = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); - if (st > V.cols * 2) st = 0; - for (var q = 1; q < st; q++) { - var tq = q / st; - emit(f, lx + Math.round(dx * tq), ly + Math.round(dy * tq), G_DOT, P.slate, - sun > 0.6 ? 40 : 18, ld + (pd - ld) * tq); - } - } - emit(f, px, py, G_DOT, P.slate, sun > 0.6 ? 40 : 18, pd); - lx = px; ly = py; ld = pd; - } + var ay = hgt - 0.55; + var i; + + if (day && PJ.d < 26) { + for (i = -1; i <= 1; i += 2) { + if (project(wx(axis, a0, cross + i * 0.9), ay + 0.22, wz(axis, a0, cross + i * 0.9))) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_o, + sun > 0.6 ? P.white : P.stone, sun > 0.6 ? 176 : 108, PJ.d); } - } + } + for (i = -1; i <= 1; i++) { + if (!i) continue; + var ax2 = wx(axis, a0, cross + i * 0.9), az2 = wz(axis, a0, cross + i * 0.9); + if (project(ax2, ay, az2)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_DASH, pcol, plum, PJ.d); + } - var SAGE_LAT = 3.1, CACTUS_LAT = 17.0, BRUSH_R = 52; - - function drawBrush(f) { - var lo0 = Math.floor((V.ox - BRUSH_R) / SAGE_LAT), hi0 = Math.floor((V.ox + BRUSH_R) / SAGE_LAT); - var lo1 = Math.floor((V.oz - BRUSH_R) / SAGE_LAT), hi1 = Math.floor((V.oz + BRUSH_R) / SAGE_LAT); - var i, j; - for (j = lo1; j <= hi1; j++) { - for (i = lo0; i <= hi0; i++) { - var h = hash2(i, j, BASE + 0x21); - if (h > 0.16) continue; - var px = i * SAGE_LAT + hash2(i, j, BASE + 0x22) * SAGE_LAT; - var pz = j * SAGE_LAT + hash2(i, j, BASE + 0x23) * SAGE_LAT; - - if (CITY.height(px, pz) > 0.1) continue; - if (CITY.height(px + 2.4, pz) <= 0.1 && CITY.height(px - 2.4, pz) <= 0.1 && - CITY.height(px, pz + 2.4) <= 0.1 && CITY.height(px, pz - 2.4) <= 0.1 && - hash2(i, j, BASE + 0x24) > 0.45) continue; - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < 0.9 || w > 60) continue; - var hh = 0.30 + h * 2.6; - if (!project(px, hh, pz)) continue; - var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d; - if (x < -1 || x >= V.cols + 1) continue; - var lum = 30 + h * 260; - emit(f, x, y, h < 0.06 ? G_STAR : G_TICK, P.spring, lum, d); - if (d < 16) { - emit(f, x - 1, y, G_QUOTE, P.spring, lum * 0.6, d); - emit(f, x + 1, y, G_TICK, P.spring, lum * 0.6, d); - if (project(px, hh * 0.4, pz)) - emit(f, x, Math.floor(PJ.y), G_COMMA, P.slate, 22, PJ.d); - } - } + var span = a1 - a0, sag = 0.9; + var lx = -1, ly = 0, ld = 0; + for (i = 0; i <= 16; i++) { + var u = i / 16, a = a0 + span * u; + var yy = hgt - 0.2 - sag * 4 * u * (1 - u); + if (!project(wx(axis, a, cross), yy, wz(axis, a, cross))) { lx = -1; continue; } + var px = Math.floor(PJ.x), py = Math.floor(PJ.y), pd = PJ.d; + if (lx >= 0 && (pd > ld * 2 || ld > pd * 2)) lx = -1; + if (lx >= 0) { + var dx = px - lx, dy = py - ly; + var st = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); + if (st > V.cols * 2) st = 0; + for (var q = 1; q < st; q++) { + var tq = q / st; + emit(f, lx + Math.round(dx * tq), ly + Math.round(dy * tq), G_DOT, + day ? P.timber : P.slate, day ? 96 : (sun > 0.6 ? 40 : 18), + ld + (pd - ld) * tq); + } } - var c0 = Math.floor((V.ox - 70) / CACTUS_LAT), c1 = Math.floor((V.ox + 70) / CACTUS_LAT); - var c2 = Math.floor((V.oz - 70) / CACTUS_LAT), c3 = Math.floor((V.oz + 70) / CACTUS_LAT); - for (j = c2; j <= c3; j++) { - for (i = c0; i <= c1; i++) { - var ch2 = hash2(i, j, BASE + 0x31); - if (ch2 > 0.34) continue; - var qx = i * CACTUS_LAT + hash2(i, j, BASE + 0x32) * CACTUS_LAT; - var qz = j * CACTUS_LAT + hash2(i, j, BASE + 0x33) * CACTUS_LAT; - if (CITY.height(qx, qz) > 0.1) continue; - if (CITY.height(qx + 3, qz) > 0.1 || CITY.height(qx - 3, qz) > 0.1) continue; - var rx2 = qx - V.ox, rz2 = qz - V.oz; - var w2 = rx2 * V.fwx + rz2 * V.fwz; - if (w2 < 1.2 || w2 > 78) continue; - var th = 2.6 + ch2 * 7.0; + emit(f, px, py, G_DOT, day ? P.timber : P.slate, + day ? 96 : (sun > 0.6 ? 40 : 18), pd); + lx = px; ly = py; ld = pd; + } + } + } - var sunX = (WEST && WEST.SUN_X < 0) ? -1 : 1; - column(f, qx, qz, 0, th, G_PIPE, P.spring, 98, 0); - if (w2 < 18) column(f, qx - sunX * 0.30, qz, 0, th * 0.96, G_PIPE, P.slate, 26, 0); - var col = P.spring, lum = 98; + var SAGE_LAT = 3.1, CACTUS_LAT = 17.0, BRUSH_R = 52; - var ah = th * (0.42 + ch2 * 0.4); - column(f, qx - 0.55, qz, ah, ah + th * 0.34, G_PIPE, col, lum, 0); - if (project(qx - 0.28, ah, qz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, col, lum, PJ.d); - if (ch2 < 0.20) { - column(f, qx + 0.55, qz, ah * 0.8, ah * 0.8 + th * 0.28, G_PIPE, col, lum, 0); - if (project(qx + 0.28, ah * 0.8, qz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, col, lum, PJ.d); - } - } + function drawBrush(f) { + var lo0 = Math.floor((V.ox - BRUSH_R) / SAGE_LAT), hi0 = Math.floor((V.ox + BRUSH_R) / SAGE_LAT); + var lo1 = Math.floor((V.oz - BRUSH_R) / SAGE_LAT), hi1 = Math.floor((V.oz + BRUSH_R) / SAGE_LAT); + var i, j; + for (j = lo1; j <= hi1; j++) { + for (i = lo0; i <= hi0; i++) { + var h = hash2(i, j, BASE + 0x21); + if (h > 0.16) continue; + var px = i * SAGE_LAT + hash2(i, j, BASE + 0x22) * SAGE_LAT; + var pz = j * SAGE_LAT + hash2(i, j, BASE + 0x23) * SAGE_LAT; + + if (CITY.height(px, pz) > 0.1) continue; + if (CITY.height(px + 2.4, pz) <= 0.1 && CITY.height(px - 2.4, pz) <= 0.1 && + CITY.height(px, pz + 2.4) <= 0.1 && CITY.height(px, pz - 2.4) <= 0.1 && + hash2(i, j, BASE + 0x24) > 0.45) continue; + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < 0.9 || w > 60) continue; + var hh = 0.30 + h * 2.6; + if (!project(px, hh, pz)) continue; + var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d; + if (x < -1 || x >= V.cols + 1) continue; + var lum = 30 + h * 260; + emit(f, x, y, h < 0.06 ? G_STAR : G_TICK, P.spring, lum, d); + if (d < 16) { + emit(f, x - 1, y, G_QUOTE, P.spring, lum * 0.6, d); + emit(f, x + 1, y, G_TICK, P.spring, lum * 0.6, d); + if (project(px, hh * 0.4, pz)) + emit(f, x, Math.floor(PJ.y), G_COMMA, P.slate, 22, PJ.d); } + } } - var NWEED = 3; - var wdX, wdZ, wdVX, wdVZ, wdPh, wdR, wdLife; + var c0 = Math.floor((V.ox - 70) / CACTUS_LAT), c1 = Math.floor((V.ox + 70) / CACTUS_LAT); + var c2 = Math.floor((V.oz - 70) / CACTUS_LAT), c3 = Math.floor((V.oz + 70) / CACTUS_LAT); + for (j = c2; j <= c3; j++) { + for (i = c0; i <= c1; i++) { + var ch2 = hash2(i, j, BASE + 0x31); + if (ch2 > 0.34) continue; + var qx = i * CACTUS_LAT + hash2(i, j, BASE + 0x32) * CACTUS_LAT; + var qz = j * CACTUS_LAT + hash2(i, j, BASE + 0x33) * CACTUS_LAT; + if (CITY.height(qx, qz) > 0.1) continue; + if (CITY.height(qx + 3, qz) > 0.1 || CITY.height(qx - 3, qz) > 0.1) continue; + var rx2 = qx - V.ox, rz2 = qz - V.oz; + var w2 = rx2 * V.fwx + rz2 * V.fwz; + if (w2 < 1.2 || w2 > 78) continue; + var th = 2.6 + ch2 * 7.0; - function respawn(i, rnd) { + var sunX = (WEST && WEST.SUN_X < 0) ? -1 : 1; + column(f, qx, qz, 0, th, G_PIPE, P.spring, 98, 0); + if (w2 < 18) column(f, qx - sunX * 0.30, qz, 0, th * 0.96, G_PIPE, P.slate, 26, 0); + var col = P.spring, lum = 98; - var a = rnd * 6.2831853; - wdX[i] = V.ox + Math.cos(a) * 46; - wdZ[i] = V.oz + Math.sin(a) * 46; - var b = a + 3.14159 + (rnd - 0.5) * 1.5; - var sp = 2.4 + rnd * 3.0; - wdVX[i] = Math.cos(b) * sp; wdVZ[i] = Math.sin(b) * sp; - wdPh[i] = rnd * 6.28; - wdR[i] = 0.30 + rnd * 0.34; - wdLife[i] = 26 + rnd * 30; - } - - CC.ELEMENTS.push({ - name: 'west-tumbleweed', - layer: 23, - world: 'west', - init: function (city, rng) { - boot(city); - wdX = new Float64Array(NWEED); wdZ = new Float64Array(NWEED); - wdVX = new Float64Array(NWEED); wdVZ = new Float64Array(NWEED); - wdPh = new Float64Array(NWEED); wdR = new Float64Array(NWEED); - wdLife = new Float64Array(NWEED); - - V.ox = city && city.startX !== undefined ? city.startX : 0; - V.oz = city && city.startZ !== undefined ? city.startZ : 0; - for (var i = 0; i < NWEED; i++) respawn(i, rng()); - }, - update: function (dt, t, cam) { - if (!CITY) return; - V.ox = cam.x; V.oz = cam.z; - var gust = 0.55 + 0.9 * W_WIND; - var damp = CC.reducedMotion ? 0.3 : 1; - for (var i = 0; i < NWEED; i++) { - wdLife[i] -= dt; - var nx = wdX[i] + wdVX[i] * dt * gust * damp; - var nz = wdZ[i] + wdVZ[i] * dt * gust * damp; - - if (CITY.height(nx, wdZ[i]) > 0.1) { wdVX[i] = -wdVX[i] * 0.7; nx = wdX[i]; } - if (CITY.height(wdX[i], nz) > 0.1) { wdVZ[i] = -wdVZ[i] * 0.7; nz = wdZ[i]; } - wdX[i] = nx; wdZ[i] = nz; - - wdPh[i] += dt * (2.0 + 1.6 * W_WIND) * damp; - var dx = nx - cam.x, dz = nz - cam.z; - if (wdLife[i] < 0 || dx * dx + dz * dz > 4900) - respawn(i, hash2(i, (t * 3) | 0, BASE + 0x41)); - } - }, - draw: function (f, cam, t) { - if (!CITY) return; - view(f, cam, t === undefined ? (cam.t || 0) : t); - if (W_RAIN > 0.5) return; - for (var i = 0; i < NWEED; i++) { - var r = wdR[i]; - - var bounce = Math.abs(Math.sin(wdPh[i] * 0.5)) * r * 1.5; - if (!project(wdX[i], r + bounce, wdZ[i])) continue; - var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d; - var rw = r * V.colK / (d * 0.85), rh = r * V.scale / (d * 0.85); - var lum = 74 + 24 * Math.abs(Math.sin(wdPh[i])); - if (rw < 1.1) { emit(f, x, y, G_STAR, P.slate, lum, d); continue; } - var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; - if (iw > 9) iw = 9; if (ih > 9) ih = 9; - for (dy = -ih; dy <= ih; dy++) { - for (dx = -iw; dx <= iw; dx++) { - var u = dx / rw, v = dy / rh, r2 = u * u + v * v; - if (r2 > 1.05) continue; - - var ca = Math.cos(wdPh[i]), sa = Math.sin(wdPh[i]); - var ru = u * ca - v * sa, rv = u * sa + v * ca; - if (hash2(Math.round(ru * 5), Math.round(rv * 5), BASE + 0x42) > 0.42) continue; - emit(f, x + dx, y + dy, r2 > 0.6 ? G_TICK : G_STAR, P.slate, lum * (1 - 0.3 * r2), d); - } - } - } + var ah = th * (0.42 + ch2 * 0.4); + column(f, qx - 0.55, qz, ah, ah + th * 0.34, G_PIPE, col, lum, 0); + if (project(qx - 0.28, ah, qz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, col, lum, PJ.d); + if (ch2 < 0.20) { + column(f, qx + 0.55, qz, ah * 0.8, ah * 0.8 + th * 0.28, G_PIPE, col, lum, 0); + if (project(qx + 0.28, ah * 0.8, qz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, col, lum, PJ.d); } - }); - - function mk(name, layer, fn) { - return { - name: name, layer: layer, world: 'west', - 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('west-brush', 15, drawBrush)); - CC.ELEMENTS.push(mk('west-telegraph', 19, function (f) { - var i; - for (i = -1; i <= 1; i++) drawTelegraph(f, 0, nearIdx(0) + i); - for (i = -1; i <= 1; i++) drawTelegraph(f, 1, nearIdx(1) + i); - })); + var NWEED = 3; + var wdX, wdZ, wdVX, wdVZ, wdPh, wdR, wdLife; + + function respawn(i, rnd) { + + var a = rnd * 6.2831853; + wdX[i] = V.ox + Math.cos(a) * 46; + wdZ[i] = V.oz + Math.sin(a) * 46; + var b = a + 3.14159 + (rnd - 0.5) * 1.5; + var sp = 2.4 + rnd * 3.0; + wdVX[i] = Math.cos(b) * sp; wdVZ[i] = Math.sin(b) * sp; + wdPh[i] = rnd * 6.28; + wdR[i] = 0.30 + rnd * 0.34; + wdLife[i] = 26 + rnd * 30; + } + + CC.ELEMENTS.push({ + name: 'west-tumbleweed', + layer: 23, + world: 'west', + init: function (city, rng) { + boot(city); + wdX = new Float64Array(NWEED); wdZ = new Float64Array(NWEED); + wdVX = new Float64Array(NWEED); wdVZ = new Float64Array(NWEED); + wdPh = new Float64Array(NWEED); wdR = new Float64Array(NWEED); + wdLife = new Float64Array(NWEED); + + V.ox = city && city.startX !== undefined ? city.startX : 0; + V.oz = city && city.startZ !== undefined ? city.startZ : 0; + for (var i = 0; i < NWEED; i++) respawn(i, rng()); + }, + update: function (dt, t, cam) { + if (!CITY) return; + V.ox = cam.x; V.oz = cam.z; + var gust = 0.55 + 0.9 * W_WIND; + var damp = CC.reducedMotion ? 0.3 : 1; + for (var i = 0; i < NWEED; i++) { + wdLife[i] -= dt; + var nx = wdX[i] + wdVX[i] * dt * gust * damp; + var nz = wdZ[i] + wdVZ[i] * dt * gust * damp; + + if (CITY.height(nx, wdZ[i]) > 0.1) { wdVX[i] = -wdVX[i] * 0.7; nx = wdX[i]; } + if (CITY.height(wdX[i], nz) > 0.1) { wdVZ[i] = -wdVZ[i] * 0.7; nz = wdZ[i]; } + wdX[i] = nx; wdZ[i] = nz; + + wdPh[i] += dt * (2.0 + 1.6 * W_WIND) * damp; + var dx = nx - cam.x, dz = nz - cam.z; + if (wdLife[i] < 0 || dx * dx + dz * dz > 4900) + respawn(i, hash2(i, (t * 3) | 0, BASE + 0x41)); + } + }, + draw: function (f, cam, t) { + if (!CITY) return; + view(f, cam, t === undefined ? (cam.t || 0) : t); + if (W_RAIN > 0.5) return; + for (var i = 0; i < NWEED; i++) { + var r = wdR[i]; + + var bounce = Math.abs(Math.sin(wdPh[i] * 0.5)) * r * 1.5; + if (!project(wdX[i], r + bounce, wdZ[i])) continue; + var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d; + var rw = r * V.colK / (d * 0.85), rh = r * V.scale / (d * 0.85); + var lum = 74 + 24 * Math.abs(Math.sin(wdPh[i])); + if (rw < 1.1) { emit(f, x, y, G_STAR, P.slate, lum, d); continue; } + var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; + if (iw > 9) iw = 9; if (ih > 9) ih = 9; + for (dy = -ih; dy <= ih; dy++) { + for (dx = -iw; dx <= iw; dx++) { + var u = dx / rw, v = dy / rh, r2 = u * u + v * v; + if (r2 > 1.05) continue; + + var ca = Math.cos(wdPh[i]), sa = Math.sin(wdPh[i]); + var ru = u * ca - v * sa, rv = u * sa + v * ca; + if (hash2(Math.round(ru * 5), Math.round(rv * 5), BASE + 0x42) > 0.42) continue; + emit(f, x + dx, y + dy, r2 > 0.6 ? G_TICK : G_STAR, P.slate, lum * (1 - 0.3 * r2), d); + } + } + } + } + }); + + function mk(name, layer, fn) { + return { + name: name, layer: layer, world: 'west', + 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('west-brush', 15, drawBrush)); + CC.ELEMENTS.push(mk('west-telegraph', 19, function (f) { + var i; + for (i = -1; i <= 1; i++) drawTelegraph(f, 0, nearIdx(0) + i); + for (i = -1; i <= 1; i++) drawTelegraph(f, 1, nearIdx(1) + i); + })); })(CC); /* src/elements/west_sky.js */ (function (CC) { - 'use strict'; + 'use strict'; - var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2, vnoise = CC.vnoise, clamp = CC.clamp; + var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2, vnoise = CC.vnoise, clamp = CC.clamp; - var G_DOT = g('.'), G_TICK = g('`'), G_QUOTE = g("'"), G_DASH = g('-'), G_EQ = g('='), - G_o = g('o'), G_8 = g('8'); + var G_DOT = g('.'), G_TICK = g('`'), G_QUOTE = g("'"), G_DASH = g('-'), G_EQ = g('='), + G_o = g('o'), G_8 = g('8'), G_TILDE = g('~'), G_PLUS = g('+'), G_DQ = g('"'), + G_HASH = g('#'), G_COLON = g(':'), G_UNDER = g('_'), G_PCT = g('%'); - var D_SUN = 1.02e5, D_CLOUD = 9.6e4, D_BIRD = 8.0e4; + var D_SUN = 1.02e5, D_CLOUD = 9.6e4, D_BIRD = 8.0e4; - var W_CLOUD = 0.1, W_HAZE = 0.3, W_WIND = 0.2, W_RAIN = 0; - function bindWeather() { - var p = CC.Weather ? CC.Weather.P : null; - W_CLOUD = p ? p.cloud : 0.1; - W_HAZE = p ? p.haze : 0.3; - W_WIND = p ? p.wind : 0.2; - W_RAIN = p ? p.rain : 0; - } + var D_CLOUD_DAY = 9.4e4; - var CB = { fwx: 0, fwz: 1, rgx: 1, rgz: 0, half: 0.71, cols: 0, rows: 0, - horizon: 0, eyeY: 1.7, scale: 1, colsPerTan: 1 }; - function setup(frame, cam) { - bindWeather(); - var yaw = cam.yaw || 0, fov = cam.fov || 1.25; - CB.fwx = Math.sin(yaw); CB.fwz = Math.cos(yaw); - CB.rgx = Math.cos(yaw); CB.rgz = -Math.sin(yaw); - CB.half = Math.tan(fov * 0.5); - CB.cols = frame.cols; CB.rows = frame.rows; - CB.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; - CB.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; - CB.colsPerTan = frame.cols / (2 * CB.half); - CB.scale = cam.scaleY !== undefined ? cam.scaleY : CB.colsPerTan * (cam.cellAspect || 0.5625); - } + function dayFill() { + if (!CC.SurfWest) return 0; + return CC.SurfWest.dayFill; + } + var INK = [G_TICK, G_DOT, G_UNDER, G_DASH, G_COLON, G_TILDE, G_DQ, G_PLUS, G_EQ, G_HASH, G_PCT]; + function ink(t) { var i = (t * 11) | 0; return INK[i < 0 ? 0 : (i > 10 ? 10 : i)]; } - var VP = { ok: 0, x: 0, y: 0, w: 0 }; - function proj(dx, dy, dz) { - var w = dx * CB.fwx + dz * CB.fwz; - if (w <= 0.02) { VP.ok = 0; return VP; } - var s = dx * CB.rgx + dz * CB.rgz; - VP.ok = 1; VP.w = w; - VP.x = (s / w) * CB.colsPerTan + CB.cols * 0.5; - VP.y = CB.horizon - (dy / w) * CB.scale; - return VP; - } + var W_CLOUD = 0.1, W_HAZE = 0.3, W_WIND = 0.2, W_RAIN = 0; + function bindWeather() { + var p = CC.Weather ? CC.Weather.P : null; + W_CLOUD = p ? p.cloud : 0.1; + W_HAZE = p ? p.haze : 0.3; + W_WIND = p ? p.wind : 0.2; + W_RAIN = p ? p.rain : 0; + } - function plot(frame, x, y, ch, col, lum, d) { - x = Math.round(x); y = Math.round(y); - if (x < 0 || y < 0 || x >= CB.cols || y >= CB.rows) return; - if (lum < 3) return; - put(frame, x, y, ch, col, lum > 255 ? 255 : lum | 0, d, 3); - } + var CB = { fwx: 0, fwz: 1, rgx: 1, rgz: 0, half: 0.71, cols: 0, rows: 0, + horizon: 0, eyeY: 1.7, scale: 1, colsPerTan: 1 }; + function setup(frame, cam) { + bindWeather(); + var yaw = cam.yaw || 0, fov = cam.fov || 1.25; + CB.fwx = Math.sin(yaw); CB.fwz = Math.cos(yaw); + CB.rgx = Math.cos(yaw); CB.rgz = -Math.sin(yaw); + CB.half = Math.tan(fov * 0.5); + CB.cols = frame.cols; CB.rows = frame.rows; + CB.horizon = cam.horizon !== undefined ? cam.horizon : frame.rows * 0.56; + CB.eyeY = cam.eyeY !== undefined ? cam.eyeY : 1.7; + CB.colsPerTan = frame.cols / (2 * CB.half); + CB.scale = cam.scaleY !== undefined ? cam.scaleY : CB.colsPerTan * (cam.cellAspect || 0.5625); + } - function sunAz() { return CC.SurfWest ? CC.SurfWest.SUN_AZ : -0.5; } + var VP = { ok: 0, x: 0, y: 0, w: 0 }; + function proj(dx, dy, dz) { + var w = dx * CB.fwx + dz * CB.fwz; + if (w <= 0.02) { VP.ok = 0; return VP; } + var s = dx * CB.rgx + dz * CB.rgz; + VP.ok = 1; VP.w = w; + VP.x = (s / w) * CB.colsPerTan + CB.cols * 0.5; + VP.y = CB.horizon - (dy / w) * CB.scale; + return VP; + } - var SUN_ALT = 0.16, SUN_R = 0.030; + function plot(frame, x, y, ch, col, lum, d) { + x = Math.round(x); y = Math.round(y); + if (x < 0 || y < 0 || x >= CB.cols || y >= CB.rows) return; + if (lum < 3) return; + put(frame, x, y, ch, col, lum > 255 ? 255 : lum | 0, d, 3); + } - CC.ELEMENTS.push({ - name: 'west-sun', - layer: 5, - world: 'west', - draw: function (frame, cam) { - setup(frame, cam); - var az = sunAz(), ca = Math.cos(SUN_ALT); - var p = proj(Math.sin(az) * ca, Math.sin(SUN_ALT), Math.cos(az) * ca); - if (!p.ok) return; - var cx = p.x, cy = p.y; - var rw = SUN_R * CB.colsPerTan / p.w, rh = SUN_R * CB.scale / p.w; - if (rw < 0.6) return; + function sunAz() { return CC.SurfWest ? CC.SurfWest.SUN_AZ : -0.5; } - var disc = 1.20 - 1.25 * W_CLOUD; if (disc > 1) disc = 1; if (disc < 0) disc = 0; - var halo = clamp(0.35 + 0.85 * W_HAZE + 0.5 * W_CLOUD, 0, 1.35) * (0.35 + 0.65 * disc); + var SUN_ALT = 0.16, SUN_R = 0.030; - var hr = 4.4, hiw = Math.ceil(rw * hr), hih = Math.ceil(rh * hr), hx, hy, hu, hv, h2; - if (hiw > CB.cols) hiw = CB.cols; - if (hih > CB.rows) hih = CB.rows; - for (hy = -hih; hy <= hih; hy++) { - for (hx = -hiw; hx <= hiw; hx++) { - hu = hx / rw; hv = hy / rh; h2 = hu * hu + hv * hv; - if (h2 < 0.98 || h2 > hr * hr) continue; - var fall = 1 - (Math.sqrt(h2) - 1) / (hr - 1); - fall = fall * fall; - if (hash2(hx, hy, 0x5A17) > 0.30 + 0.62 * fall) continue; - plot(frame, cx + hx, cy + hy, - fall > 0.6 ? G_EQ : (fall > 0.3 ? G_DASH : G_TICK), - fall > 0.55 ? P.amber : P.ember, - (166 * fall + 20) * halo, D_SUN); - } - } - if (disc <= 0.03) return; + function drawAlt() { + var live = CC.SurfWest ? CC.SurfWest.SUN_ALT : SUN_ALT; + return SUN_ALT + (live - SUN_ALT) * dayFill(); + } - var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; - for (dy = -ih; dy <= ih; dy++) { - for (dx = -iw; dx <= iw; dx++) { - var u = dx / rw, v = dy / rh, r2 = u * u + v * v; - if (r2 > 1.02) continue; + CC.ELEMENTS.push({ + name: 'west-sun', + layer: 5, + world: 'west', + draw: function (frame, cam) { + setup(frame, cam); + var al = drawAlt(), az = sunAz(), ca = Math.cos(al); + var p = proj(Math.sin(az) * ca, Math.sin(al), Math.cos(az) * ca); + if (!p.ok) return; + var cx = p.x, cy = p.y; + var rw = SUN_R * CB.colsPerTan / p.w, rh = SUN_R * CB.scale / p.w; + if (rw < 0.6) return; - var bandK = hash2(0, Math.floor(dy * 1.3), 0x77) < 0.22 ? 0.42 : 1; - plot(frame, cx + dx, cy + dy, r2 > 0.78 ? G_o : G_8, - r2 > 0.86 ? P.amber : P.pure, (236 - 40 * r2) * disc * bandK, D_SUN); - } - } + var disc = 1.20 - 1.25 * W_CLOUD; if (disc > 1) disc = 1; if (disc < 0) disc = 0; + var halo = clamp(0.35 + 0.85 * W_HAZE + 0.5 * W_CLOUD, 0, 1.35) * (0.35 + 0.65 * disc); + + var hr = 4.4, hiw = Math.ceil(rw * hr), hih = Math.ceil(rh * hr), hx, hy, hu, hv, h2; + if (hiw > CB.cols) hiw = CB.cols; + if (hih > CB.rows) hih = CB.rows; + for (hy = -hih; hy <= hih; hy++) { + for (hx = -hiw; hx <= hiw; hx++) { + hu = hx / rw; hv = hy / rh; h2 = hu * hu + hv * hv; + if (h2 < 0.98 || h2 > hr * hr) continue; + var fall = 1 - (Math.sqrt(h2) - 1) / (hr - 1); + fall = fall * fall; + if (hash2(hx, hy, 0x5A17) > 0.30 + 0.62 * fall) continue; + plot(frame, cx + hx, cy + hy, + fall > 0.6 ? G_EQ : (fall > 0.3 ? G_DASH : G_TICK), + fall > 0.55 ? P.amber : P.ember, + (166 * fall + 20) * halo, D_SUN); } - }); + } + if (disc <= 0.03) return; - var NBAR = 7; + var iw = Math.ceil(rw), ih = Math.ceil(rh), dx, dy; + for (dy = -ih; dy <= ih; dy++) { + for (dx = -iw; dx <= iw; dx++) { + var u = dx / rw, v = dy / rh, r2 = u * u + v * v; + if (r2 > 1.02) continue; - CC.ELEMENTS.push({ - name: 'west-cloudbars', - layer: 6, - world: 'west', - draw: function (frame, cam, t) { - setup(frame, cam); - if (W_CLOUD < 0.03) return; - var tt = CC.reducedMotion ? 0 : t * (0.004 + 0.016 * W_WIND); - var az0 = sunAz(); - - var x, y, y0 = 0, y1 = Math.floor(CB.horizon); - if (y1 > CB.rows) y1 = CB.rows; - for (x = 0; x < CB.cols; x++) { - var sp = (2 * (x + 0.5) / CB.cols - 1) * CB.half; - var bear = (cam.yaw || 0) + Math.atan(sp); - var da = bear - az0; - da = Math.atan2(Math.sin(da), Math.cos(da)); - var west = 1 - Math.abs(da) / Math.PI; - for (y = y0; y < y1; y++) { - - var el = (CB.horizon - y - 0.5) / CB.scale; - if (el < 0.02 || el > 0.62) continue; - - var lad = Math.log(el * 14 + 1) * NBAR + vnoise(bear * 1.7 + tt * 3, 0x81) * 1.4; - var fb = lad - Math.floor(lad); - - var body = vnoise(Math.floor(lad) * 3.1 + bear * 2.0 + tt * 3, 0x9C1); - - if (body > 0.22 + 0.68 * W_CLOUD) continue; - - var d = hash2(Math.floor(bear * 220), Math.floor(el * 900), 0x33B); - if (fb > 0.66) continue; - if (fb > 0.50) { - - if (d > 0.72) continue; - plot(frame, x, y, G_DASH, west > 0.68 ? P.amber : P.ember, - (86 + 132 * west) * (0.7 + 0.5 * d), D_CLOUD); - } else { - - if (d > 0.34 - 0.18 * fb) continue; - plot(frame, x, y, fb > 0.28 ? G_TICK : G_DOT, P.slate, - (26 + 30 * (1 - fb)) * (0.6 + 0.6 * d), D_CLOUD); - } - } - } + var bandK = hash2(0, Math.floor(dy * 1.3), 0x77) < 0.22 ? 0.42 : 1; + plot(frame, cx + dx, cy + dy, r2 > 0.78 ? G_o : G_8, + r2 > 0.86 ? P.amber : P.pure, (236 - 40 * r2) * disc * bandK, D_SUN); } - }); + } + } + }); - var NBIRD = 3; - var bSeed = 0; + var NBAR = 7; - CC.ELEMENTS.push({ - name: 'west-birds', - layer: 9, - world: 'west', - init: function (city, rng) { + CC.ELEMENTS.push({ + name: 'west-cloudbars', + layer: 6, + world: 'west', + draw: function (frame, cam, t) { + setup(frame, cam); + if (W_CLOUD < 0.03) return; + var dF = dayFill(); + var tt = CC.reducedMotion ? 0 : t * (0.004 + 0.016 * W_WIND); + var az0 = sunAz(); - bSeed = (rng() * 4294967296) | 0; - }, - draw: function (frame, cam, t) { - setup(frame, cam); - if (W_RAIN > 0.35) return; - var tt = CC.reducedMotion ? 12.0 : t; - for (var i = 0; i < NBIRD; i++) { - var ph = tt * (0.055 + 0.014 * i) + i * 2.3 + (bSeed & 255) * 0.01; + var x, y, y0 = 0, y1 = Math.floor(CB.horizon); + if (y1 > CB.rows) y1 = CB.rows; + for (x = 0; x < CB.cols; x++) { + var sp = (2 * (x + 0.5) / CB.cols - 1) * CB.half; + var bear = (cam.yaw || 0) + Math.atan(sp); + var da = bear - az0; + da = Math.atan2(Math.sin(da), Math.cos(da)); + var west = 1 - Math.abs(da) / Math.PI; + for (y = y0; y < y1; y++) { - var az = -1.1 + (bSeed >> 8 & 255) * 0.012 + Math.sin(ph) * 0.30; - var alt = 0.30 + 0.09 * i + Math.cos(ph * 0.7) * 0.05; - var ca = Math.cos(alt); - var p = proj(Math.sin(az) * ca, Math.sin(alt), Math.cos(az) * ca); - if (!p.ok) continue; + var el = (CB.horizon - y - 0.5) / CB.scale; + if (el < 0.02 || el > 0.62) continue; - var asp = Math.abs(Math.cos(ph)); - var x = p.x, y = p.y; - plot(frame, x, y, G_DOT, P.slate, 62, D_BIRD); - if (asp > 0.45) { - plot(frame, x - 1, y - (asp > 0.8 ? 1 : 0), G_TICK, P.slate, 54, D_BIRD); - plot(frame, x + 1, y - (asp > 0.8 ? 1 : 0), G_QUOTE, P.slate, 54, D_BIRD); - } + var lad = Math.log(el * 14 + 1) * NBAR + vnoise(bear * 1.7 + tt * 3, 0x81) * 1.4; + var fb = lad - Math.floor(lad); + + var body = vnoise(Math.floor(lad) * 3.1 + bear * 2.0 + tt * 3, 0x9C1); + + if (body > 0.22 + 0.68 * W_CLOUD) continue; + + var d = hash2(Math.floor(bear * 220), Math.floor(el * 900), 0x33B); + if (fb > 0.66) continue; + + var isDay = hash2(Math.floor(bear * 111), Math.floor(el * 640), 0x6B2) < dF; + if (isDay) { + + if (d > 0.86) continue; + if (fb > 0.50) { + + plot(frame, x, y, ink(0.30 + 0.26 * d), d > 0.55 ? P.stone : P.indigo, + (54 + 46 * d) * (0.5 + 0.5 * W_CLOUD), D_CLOUD_DAY); + } else { + + var top = 1 - fb / 0.50; + plot(frame, x, y, ink(0.52 + 0.34 * top + 0.14 * (d - 0.5)), + top > 0.45 ? P.white : P.sand, + (104 + 72 * top) * (0.76 + 0.30 * d), D_CLOUD_DAY); } + continue; + } + if (fb > 0.50) { + + if (d > 0.72) continue; + plot(frame, x, y, G_DASH, west > 0.68 ? P.amber : P.ember, + (86 + 132 * west) * (0.7 + 0.5 * d), D_CLOUD); + } else { + + if (d > 0.34 - 0.18 * fb) continue; + plot(frame, x, y, fb > 0.28 ? G_TICK : G_DOT, P.slate, + (26 + 30 * (1 - fb)) * (0.6 + 0.6 * d), D_CLOUD); + } } - }); + } + } + }); + + CC.ELEMENTS.push({ + name: 'west-daysky', + layer: 7, + world: 'west', + draw: function (frame, cam) { + var dF = dayFill(); + if (dF <= 0.002) return; + setup(frame, cam); + var cols = frame.cols, col = frame.col, lum = frame.lum, dist = frame.dist, kind = frame.kind; + var maxRow = Math.floor(CB.horizon); if (maxRow > CB.rows - 1) maxRow = CB.rows - 1; + var x, y, i, h; + for (y = 0; y <= maxRow; y++) { + for (x = 0; x < cols; x++) { + i = y * cols + x; + if (kind[i] !== 3 || col[i] !== P.shadow || dist[i] < 9.0e4) continue; + + h = hash2((x + (cam.yaw || 0) * CB.colsPerTan) | 0, y, 0x4D77); + if (h > dF) continue; + + var up = 1 - y / (maxRow + 1); + + plot(frame, x, y, ink(0.30 + 0.26 * up + 0.20 * h), + h < 0.60 ? P.white : (up > 0.45 ? P.ice : P.stone), + (96 + 74 * up) * (0.80 + 0.34 * h), dist[i] - 1); + } + } + } + }); + + var NBIRD = 3; + var bSeed = 0; + + CC.ELEMENTS.push({ + name: 'west-birds', + layer: 9, + world: 'west', + init: function (city, rng) { + + bSeed = (rng() * 4294967296) | 0; + }, + draw: function (frame, cam, t) { + setup(frame, cam); + if (W_RAIN > 0.35) return; + var tt = CC.reducedMotion ? 12.0 : t; + for (var i = 0; i < NBIRD; i++) { + var ph = tt * (0.055 + 0.014 * i) + i * 2.3 + (bSeed & 255) * 0.01; + + var az = -1.1 + (bSeed >> 8 & 255) * 0.012 + Math.sin(ph) * 0.30; + var alt = 0.30 + 0.09 * i + Math.cos(ph * 0.7) * 0.05; + var ca = Math.cos(alt); + var p = proj(Math.sin(az) * ca, Math.sin(alt), Math.cos(az) * ca); + if (!p.ok) continue; + + var asp = Math.abs(Math.cos(ph)); + var x = p.x, y = p.y; + + var dF = dayFill(); + var bc = dF > 0.5 ? P.timber : P.slate, bl = 62 - 22 * dF; + plot(frame, x, y, dF > 0.5 ? G_TILDE : G_DOT, bc, bl, D_BIRD); + if (asp > 0.45) { + plot(frame, x - 1, y - (asp > 0.8 ? 1 : 0), G_TICK, bc, bl - 8, D_BIRD); + plot(frame, x + 1, y - (asp > 0.8 ? 1 : 0), G_QUOTE, bc, bl - 8, D_BIRD); + } + } + } + }); })(CC); /* src/elements/west_stock.js */ (function (CC) { - 'use strict'; + 'use strict'; - 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 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, put = CC.put, clamp = CC.clamp; + var P = CC.P, hash2 = CC.hash2, put = CC.put, clamp = CC.clamp; - var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_DOT = CC.g('.'), - G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_UNDER = CC.g('_'), G_o = CC.g('o'), - G_HASH = CC.g('#'), G_SLASH = CC.g('/'), G_BSLASH = CC.g('\\'), G_CARET = CC.g('^'), - G_COMMA = CC.g(','); + var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_DOT = CC.g('.'), + G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_UNDER = CC.g('_'), G_o = CC.g('o'), + G_HASH = CC.g('#'), G_SLASH = CC.g('/'), G_BSLASH = CC.g('\\'), G_CARET = CC.g('^'), + G_COMMA = CC.g(','); - var CITY = null, BASE = 0, RAIL_BASE = 0, Surf = null, WEST = null; + var CITY = null, BASE = 0, RAIL_BASE = 0, Surf = null, WEST = null; - function boot(city) { - CITY = (city && city.aveX && city.world === 'west') ? city : null; + function boot(city) { + CITY = (city && city.aveX && city.world === 'west') ? city : null; - RAIL_BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 8) & 0x3fffff) : 0; - BASE = CITY ? ((Math.imul(CITY.seed | 0, 19477) >>> 6) & 0x3fffff) : 0; + RAIL_BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 8) & 0x3fffff) : 0; + BASE = CITY ? ((Math.imul(CITY.seed | 0, 19477) >>> 6) & 0x3fffff) : 0; + } + + var SUN = 0.64, LAMP = 1.00, WARM = 0.90; + + function view(f, cam, t) { + PR.view(f, cam, t); + + var Dm = CC.Daylight; + SUN = Dm ? Dm.P.sun : 0.64; + LAMP = Dm ? Dm.P.lamp : 1.00; + WARM = Dm ? Dm.P.warm : 0.90; + + if (!Surf) Surf = CC.Surf; + if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null; + } + + var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 }; + function streetSpan(axis, idx) { + var c, h; + if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); } + else { c = CITY.aveX(idx); h = CITY.aveW(idx); } + SPAN.c0 = c - h; SPAN.c1 = c + h + 1; + SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0; + } + function wx(axis, along, cross) { return axis ? along : cross; } + function wz(axis, along, cross) { return axis ? cross : along; } + function paveOf(spanW) { + var p = CC.PAVE, avail = spanW * 0.5 - 1.7; + return avail < p ? avail : p; + } + function frontage(axis, a0, len, cross, dirIn) { + var i, a, c = cross - dirIn * 0.7; + for (i = 0; i <= 3; i++) { + a = a0 + len * (i / 3); + if (CITY.height(wx(axis, a, c), wz(axis, a, c)) < 2.5) return 0; } + return 1; + } + function objVisible(axis, along, cross, near) { + var px = wx(axis, along, cross), pz = wz(axis, along, cross); + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < near || w > V.far) return 0; + var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; + if (s < -lim || s > lim) return 0; + return w; + } + function nearIdx(axis) { + return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)); + } - var SUN = 0.64, LAMP = 1.00, WARM = 0.90; - - function view(f, cam, t) { - PR.view(f, cam, t); - - var Dm = CC.Daylight; - SUN = Dm ? Dm.P.sun : 0.64; - LAMP = Dm ? Dm.P.lamp : 1.00; - WARM = Dm ? Dm.P.warm : 0.90; - - if (!Surf) Surf = CC.Surf; - if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null; - } - - var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 }; - function streetSpan(axis, idx) { - var c, h; - if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); } - else { c = CITY.aveX(idx); h = CITY.aveW(idx); } - SPAN.c0 = c - h; SPAN.c1 = c + h + 1; - SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0; - } - function wx(axis, along, cross) { return axis ? along : cross; } - function wz(axis, along, cross) { return axis ? cross : along; } - function paveOf(spanW) { - var p = CC.PAVE, avail = spanW * 0.5 - 1.7; - return avail < p ? avail : p; - } - function frontage(axis, a0, len, cross, dirIn) { - var i, a, c = cross - dirIn * 0.7; - for (i = 0; i <= 3; i++) { - a = a0 + len * (i / 3); - if (CITY.height(wx(axis, a, c), wz(axis, a, c)) < 2.5) return 0; + function beam(f, axis, a0, a1, cross, y, ch, col, lum) { + var n = 20, i, a, lx = -1, ly = 0, ld = 0; + for (i = 0; i <= n; i++) { + a = a0 + (a1 - a0) * (i / n); + if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) { lx = -1; continue; } + var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d; + if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1; + if (lx >= 0) { + var dx = x - lx, dy = r - ly; + var steps = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); + if (steps > 4 * V.cols) steps = 0; + for (var q = 1; q < steps; q++) { + var t2 = q / steps; + emit(f, lx + Math.round(dx * t2), ly + Math.round(dy * t2), ch, col, lum, + ld + (d - ld) * t2); } - return 1; + } + emit(f, x, r, ch, col, lum, d); + lx = x; ly = r; ld = d; } - function objVisible(axis, along, cross, near) { - var px = wx(axis, along, cross), pz = wz(axis, along, cross); - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < near || w > V.far) return 0; - var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; - if (s < -lim || s > lim) return 0; - return w; + } + + var B = { + x: 0, z: 0, + ux: 0, uz: 1, + len: 2.0, wy: 1.6, + head: 0, + tail: 0, + lift: 0, + fill: 0, fillLum: 0, + rim: 0, rimLum: 0, + legW: 0 + }; + + function topF(u, head) { + if (u <= 0.72) { + + if (u < 0.14) return 0.88 + (0.92 - 0.88) * (u / 0.14); + if (u < 0.45) return 0.92 + (0.86 - 0.92) * ((u - 0.14) / 0.31); + return 0.86 + (0.98 - 0.86) * ((u - 0.45) / 0.27); } - function nearIdx(axis) { - return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)); + var q, up, dn; + if (u <= 1.06) { + + q = (u - 0.72) / 0.34; + up = 0.98 + 0.34 * q; + dn = 0.98 - 0.30 * q; + } else { + + q = (u - 1.06) / 0.20; if (q > 1) q = 1; + up = 1.32 - 0.12 * q; + dn = 0.68 - 0.08 * q; + } + return up + (dn - up) * head; + } + function botF(u, head) { + if (u <= 0.72) { + if (u < 0.25) return 0.60 + (0.55 - 0.60) * (u / 0.25); + return 0.55 + (0.62 - 0.55) * ((u - 0.25) / 0.47); } - function beam(f, axis, a0, a1, cross, y, ch, col, lum) { - var n = 20, i, a, lx = -1, ly = 0, ld = 0; - for (i = 0; i <= n; i++) { - a = a0 + (a1 - a0) * (i / n); - if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) { lx = -1; continue; } - var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d; - if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1; - if (lx >= 0) { - var dx = x - lx, dy = r - ly; - var steps = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); - if (steps > 4 * V.cols) steps = 0; - for (var q = 1; q < steps; q++) { - var t2 = q / steps; - emit(f, lx + Math.round(dx * t2), ly + Math.round(dy * t2), ch, col, lum, - ld + (d - ld) * t2); - } + var d; + if (u <= 1.06) d = 0.36 - 0.18 * ((u - 0.72) / 0.34); + else { d = (u - 1.06) / 0.20; if (d > 1) d = 1; d = 0.18 + 0.06 * d; } + return topF(u, head) - d; + } + + function wideF(u, len) { + var k; + if (u < 0.06) k = 0.20 + 0.08 * (u / 0.06); + else if (u <= 0.70) k = 0.28; + else k = 0.28 - 0.17 * ((u - 0.70) / 0.54); + + if (k < 0.11) k = 0.11; + return k * len; + } + + var CB_N = 1024; + var CB_TOP = new Int16Array(CB_N), CB_BOT = new Int16Array(CB_N), + CB_D = new Float32Array(CB_N), CB_END = new Uint8Array(CB_N), + CB_BAR = new Uint8Array(CB_N), CB_G = new Int32Array(CB_N), CB_GEN = 0; + + function beast(f) { + var lx = B.ux, lz = B.uz; + var px = lz, pz = -lx; + + if (!project(B.x - lx * 0.5 * B.len, B.wy * 0.85, B.z - lz * 0.5 * B.len)) return; + var sx0 = PJ.x; + if (!project(B.x + lx * 0.7 * B.len, B.wy * 0.85, B.z + lz * 0.7 * B.len)) return; + var span = PJ.x - sx0; if (span < 0) span = -span; + var n = (span + 4) | 0; if (n < 8) n = 8; if (n > 140) n = 140; + + var rumpL = litFace(-lx, -lz), chestL = litFace(lx, lz); + var endLit = rumpL > chestL ? 0 : 1; + var endStr = (rumpL > chestL ? rumpL : chestL) * SUN; + + CB_GEN++; + var lo = 1e9, hi = -1e9; + var i, u, y0, y1, wxp, wzp, cx, rt, rb, dd, hw, r, q; + for (i = 0; i <= n; i++) { + u = -0.06 + 1.32 * (i / n); + y0 = topF(u, B.head) * B.wy + B.lift; + y1 = botF(u, B.head) * B.wy + B.lift; + wxp = B.x + lx * (u - 0.5) * B.len; wzp = B.z + lz * (u - 0.5) * B.len; + if (!project(wxp, y0, wzp)) continue; + cx = PJ.x; rt = Math.floor(PJ.y); dd = PJ.d; + if (!project(wxp, y1, wzp)) continue; + rb = Math.floor(PJ.y); + if (rb < rt) { r = rt; rt = rb; rb = r; } + hw = wideF(u, B.len) * 0.5 * V.colK / dd; + if (hw > 20) hw = 20; + var q0 = Math.round(cx - hw), q1 = Math.round(cx + hw); + if (q0 < 0) q0 = 0; + if (q1 > V.cols - 1) q1 = V.cols - 1; + if (q1 >= CB_N) q1 = CB_N - 1; + var isEnd = endStr > 0.30 && + ((endLit === 0 && u < 0.11) || (endLit === 1 && u > 1.02)); + var isBar = u > 0.02 && u < 0.74; + for (q = q0; q <= q1; q++) { + if (CB_G[q] !== CB_GEN) { + CB_G[q] = CB_GEN; CB_TOP[q] = rt; CB_BOT[q] = rb; CB_D[q] = dd; + CB_END[q] = 0; CB_BAR[q] = 0; + } else { + if (rt < CB_TOP[q]) CB_TOP[q] = rt; + if (rb > CB_BOT[q]) CB_BOT[q] = rb; + if (dd < CB_D[q]) CB_D[q] = dd; + } + if (isEnd) CB_END[q] = 1; + if (isBar) CB_BAR[q] = 1; + if (q < lo) lo = q; + if (q > hi) hi = q; + } + } + if (hi < lo) return; + + var el = 24 + 82 * endStr, elCol = WARM > 0.45 ? P.amber : P.white; + var headEnd = (lx * V.rgx + lz * V.rgz) > 0 ? hi : lo; + for (q = lo; q <= hi; q++) { + if (CB_G[q] !== CB_GEN) continue; + rt = CB_TOP[q]; rb = CB_BOT[q]; dd = CB_D[q]; + for (r = rt; r <= rb; r++) emit(f, q, r, G_HASH, B.fill, B.fillLum, dd); + + if (CB_END[q] && el >= 5) { + var eb = rt + (((rb - rt) * 0.66) | 0); + for (r = rt + 1; r <= eb; r++) + emit(f, q, r, G_o, elCol, el * (r === rt + 1 ? 1 : 0.60), dd * 0.988); + } + + if (B.rimLum >= 4) { + var gl = G_DASH, drop = 0; + if (q > lo && CB_G[q - 1] === CB_GEN) drop = rt - CB_TOP[q - 1]; + if (drop > 1) gl = G_BSLASH; + else if (drop < -1) gl = G_SLASH; + + if (q === headEnd) gl = G_o; + emit(f, q, rt, gl, B.rim, B.rimLum, dd * 0.988); + + if (CB_BAR[q] && B.rimLum >= 12) + emit(f, q, rb, G_UNDER, B.rim, B.rimLum * 0.22, dd * 0.988); + } + } + + var lat, uL, k2; + for (k2 = 0; k2 < 4; k2++) { + + uL = (k2 < 2) ? 0.66 : 0.10; + lat = (k2 & 1) ? 0.16 : -0.16; + column(f, B.x + lx * (uL - 0.5) * B.len + px * lat * B.len * 0.5, + B.z + lz * (uL - 0.5) * B.len + pz * lat * B.len * 0.5, + 0, botF(uL, B.head) * B.wy + B.lift + 0.04, + G_PIPE, B.fill, B.fillLum, B.legW); + } + + var tx = B.x - lx * 0.56 * B.len, tz = B.z - lz * 0.56 * B.len; + if (B.tail > 0.5) + column(f, tx, tz, topF(0.02, B.head) * B.wy + B.lift, + (topF(0.02, B.head) + 0.30) * B.wy + B.lift, G_QUOTE, B.rim, B.rimLum * 0.7, 0); + else + column(f, tx, tz, 0.30 * B.wy + B.lift, topF(0.02, B.head) * B.wy + B.lift, + G_PIPE, B.fill, B.fillLum, 0); + } + + function hideLight() { + + B.rimLum = 30 + 128 * SUN + (1 - SUN) * (72 * LAMP); + B.rim = WARM > 0.45 ? P.amber : P.white; + + B.fill = P.ember; + B.fillLum = SUN > 0.33 ? (12 + 34 * (SUN - 0.33) / 0.67) : 0; + } + + var RAIL_PITCH = 15.0; + + function drawHitched(f, axis, idx) { + streetSpan(axis, idx); + var pave = paveOf(SPAN.w); + var lo = Math.floor(((axis ? V.ox : V.oz) - 48) / RAIL_PITCH); + var hi = Math.floor(((axis ? V.ox : V.oz) + 48) / RAIL_PITCH); + + for (var s = 0; s < 2; s++) { + var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1; + var edge = face + dirIn * (pave + 0.15); + + var hx = axis ? 0 : -dirIn, hz = axis ? -dirIn : 0; + + for (var k = lo; k <= hi; k++) { + var h0 = hash2(k, idx * 2 + s, RAIL_BASE + 0x61); + if (h0 > 0.62) continue; + var along = k * RAIL_PITCH + h0 * 9; + if (!objVisible(axis, along, edge, 0.8)) continue; + if (!frontage(axis, along, 5.2, face, dirIn)) continue; + var kind = hash2(k, idx * 2 + s, RAIL_BASE + 0x62); + if (kind >= 0.52) continue; + var L = 3.6 + kind * 3.2; + + var occ = hash2(k, idx * 2 + s, BASE + 0x11); + var nH = occ < 0.70 ? 1 : (occ < 0.94 ? 2 : 3); + + for (var j = 0; j < nH; j++) { + var a = along + 0.72 + j * 1.45; + if (a > along + L - 0.5) break; + var hA = hash2(k * 5 + j, idx * 2 + s, BASE + 0x12); + var hB = hash2(k * 5 + j, idx * 2 + s, BASE + 0x13); + + var cross = edge + dirIn * 1.50; + var w = objVisible(axis, a, cross, 0.9); + if (!w) continue; + + B.x = wx(axis, a, cross); B.z = wz(axis, a, cross); + B.ux = hx; B.uz = hz; + B.len = 1.92 + hA * 0.22; + B.wy = 1.52 + hB * 0.16; + + B.head = hA < 0.34 ? 1 : 0; + B.tail = 0; + + B.lift = CC.reducedMotion ? 0 + : 0.035 * Math.sin(V.t * 0.50 + (hA + hB) * 6.283); + B.legW = w < 16 ? 1 : 0; + hideLight(); + beast(f); + + if (w < 15) { + var muzz = topF(1.16, B.head) * B.wy - 0.10; + var mc = cross - dirIn * 1.30; + var rx2 = wx(axis, a, mc), rz2 = wz(axis, a, mc); + + if (muzz > 1.16 && project(rx2, muzz, rz2)) { + var rcx = Math.floor(PJ.x), rr0 = Math.floor(PJ.y), rdd = PJ.d; + if (project(rx2, 1.04, rz2)) { + var rr1 = Math.floor(PJ.y), rr; + for (rr = rr0; rr <= rr1; rr++) + emit(f, rcx, rr, G_QUOTE, B.rim, B.rimLum * 0.34, rdd * 0.97); + } } - emit(f, x, r, ch, col, lum, d); - lx = x; ly = r; ld = d; + } } + } + } + } + + var COR = { axis: 0, ctr: 0, along: 0, dir: 1 }; + + function corridor() { + var k = Math.round(V.ox / CITY.AVE), m = Math.round(V.oz / CITY.CROSS); + var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d; + for (i = k - 1; i <= k + 1; i++) { + c = CITY.aveX(i) + 0.5; d = V.ox - c; if (d < 0) d = -d; + if (d < bA) { bA = d; aC = c; aW = CITY.aveW(i) + 0.5; } + } + for (i = m - 1; i <= m + 1; i++) { + c = CITY.crossZ(i) + 0.5; d = V.oz - c; if (d < 0) d = -d; + if (d < bC) { bC = d; cC = c; cW = CITY.crossW(i) + 0.5; } + } + var afz = V.fwz < 0 ? -V.fwz : V.fwz, afx = V.fwx < 0 ? -V.fwx : V.fwx; + if (bC <= cW && (bA > aW || afx > afz)) { + COR.axis = 1; COR.ctr = cC; COR.along = V.ox; COR.dir = V.fwx < 0 ? -1 : 1; + } else { + COR.axis = 0; COR.ctr = aC; COR.along = V.oz; COR.dir = V.fwz < 0 ? -1 : 1; + } + } + + function wheel(f, px, pz, cy, rad, col, lum) { + if (!project(px, cy, pz)) return; + var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d; + var rw = rad * V.colK / d, rh = rad * V.scale / d; + if (rw < 1.1 || rh < 0.8) { + + emit(f, x, y, G_o, col, lum, d); + emit(f, x, y + 1, G_COMMA, col, lum * 0.6, d); + return; } - var B = { - x: 0, z: 0, - ux: 0, uz: 1, - len: 2.0, wy: 1.6, - head: 0, - tail: 0, - lift: 0, - fill: 0, fillLum: 0, - rim: 0, rimLum: 0, - legW: 0 + var iw = Math.ceil(rw); if (iw > 26) iw = 26; + var i, r; + for (i = -iw; i < iw; i++) { + var u0 = i / rw, u1 = (i + 1) / rw; + if (u0 < -1) u0 = -1; if (u0 > 1) u0 = 1; + if (u1 < -1) u1 = -1; if (u1 > 1) u1 = 1; + var a0 = Math.sqrt(1 - u0 * u0) * rh, a1 = Math.sqrt(1 - u1 * u1) * rh; + var t0 = Math.round(y - a0), t1 = Math.round(y - a1); + if (t1 < t0) { r = t0; t0 = t1; t1 = r; } + + var g = (t1 - t0) > 1 ? G_PIPE : G_DASH; + for (r = t0; r <= t1; r++) emit(f, x + i, r, g, col, lum, d * 0.99); + var b0 = Math.round(y + a0), b1 = Math.round(y + a1); + if (b1 < b0) { r = b0; b0 = b1; b1 = r; } + g = (b1 - b0) > 1 ? G_PIPE : G_DASH; + for (r = b0; r <= b1; r++) emit(f, x + i, r, g, col, lum * 0.45, d * 0.99); + } + emit(f, x, y, G_o, col, lum * 0.7, d * 0.99); + } + + var WAG_SPAN = 40.0; + + function drawWagons(f) { + corridor(); + var wA = 1 - COR.axis; + var period = wA ? CITY.CROSS : CITY.AVE; + var i0 = Math.round(COR.along / period), m; + + for (m = i0 - 3; m <= i0 + 3; m++) { + var jc = (wA ? CITY.crossZ(m) : CITY.aveX(m)) + 0.5; + var ahead = (jc - COR.along) * COR.dir; + + if (ahead < 11 || ahead > 78) continue; + + var T = 42 + hash2(m, wA, BASE + 0x21) * 44; + var uu = V.t / T + hash2(m, wA, BASE + 0x22); + var cyc = Math.floor(uu), ph = uu - cyc; + + if (CC.reducedMotion) ph = 0.44; + var go = hash2(m, cyc, BASE + 0x23) < 0.5 ? -1 : 1; + var off = (ph * 2 - 1) * WAG_SPAN * go; + + streetSpan(wA, m); + + var road = SPAN.w * 0.5 - paveOf(SPAN.w); + if (road < 1.7) road = 1.7; + var lane = road * 0.42; if (lane > 1.5) lane = 1.5; + var cross = SPAN.mid - go * lane; + var aw = COR.ctr + off; + + var w = objVisible(wA, aw, cross, 2.0); + if (!w) continue; + drawWagon(f, wA, aw, cross, go, m, cyc); + } + } + + function drawWagon(f, axis, a, cross, go, m, cyc) { + var rear = a - go * 1.6, front = a + go * 1.6; + + var wcx = wx(axis, a, cross), wcz = wz(axis, a, cross); + var nx = axis ? 0 : 1, nz = axis ? 1 : 0; + if (nx * (V.ox - wcx) + nz * (V.oz - wcz) < 0) { nx = -nx; nz = -nz; } + var side = litFace(nx, nz); + var boardLum = (14 + 92 * side * SUN + 26 * LAMP * (1 - SUN)) | 0; + var boardCol = WARM > 0.45 ? P.amber : P.white; + + var deck = 1.02, capY = 1.48; + var n = 26, i; + for (i = 0; i <= n; i++) { + var aa = rear + (front - rear) * (i / n); + column(f, wx(axis, aa, cross), wz(axis, aa, cross), deck, capY - 0.06, + G_HASH, boardCol, boardLum * 0.55, 0); + column(f, wx(axis, aa, cross), wz(axis, aa, cross), deck - 0.20, deck, + G_HASH, P.shadow, 0, 0); + } + beam(f, axis, rear, front, cross, capY, G_EQ, boardCol, boardLum); + + var seatA = front - go * 0.42; + column(f, wx(axis, seatA, cross), wz(axis, seatA, cross), capY, 1.72, G_HASH, P.shadow, 0, 1); + column(f, wx(axis, seatA, cross - 0.1), wz(axis, seatA, cross - 0.1), 1.72, 2.34, + G_PIPE, P.shadow, 0, 1); + if (project(wx(axis, seatA, cross - 0.1), 2.36, wz(axis, seatA, cross - 0.1))) { + var dx0 = Math.floor(PJ.x), dy0 = Math.floor(PJ.y), dd0 = PJ.d; + emit(f, dx0, dy0, G_CARET, boardCol, boardLum * 1.2, dd0 * 0.98); + emit(f, dx0 - 1, dy0, G_DASH, boardCol, boardLum * 0.7, dd0 * 0.98); + emit(f, dx0 + 1, dy0, G_DASH, boardCol, boardLum * 0.7, dd0 * 0.98); + } + + var wl = 0.62; + var rw = 0.725, fw = 0.50; + var wheelLum = 30 + 96 * side * SUN + 30 * LAMP * (1 - SUN); + var wheelCol = WARM > 0.45 ? P.amber : P.white; + var rA = rear + go * 0.75, fA = front - go * 0.30; + wheel(f, wx(axis, rA, cross - wl), wz(axis, rA, cross - wl), rw, rw, wheelCol, wheelLum); + wheel(f, wx(axis, rA, cross + wl), wz(axis, rA, cross + wl), rw, rw, wheelCol, wheelLum * 0.7); + wheel(f, wx(axis, fA, cross - wl), wz(axis, fA, cross - wl), fw, fw, wheelCol, wheelLum); + wheel(f, wx(axis, fA, cross + wl), wz(axis, fA, cross + wl), fw, fw, wheelCol, wheelLum * 0.7); + + beam(f, axis, front, front + go * 2.6, cross, 0.74, G_DASH, boardCol, boardLum * 0.34); + + if (LAMP > 0.12) { + var lanA = front - go * 0.15; + if (project(wx(axis, lanA, cross - 0.66), capY + 0.16, wz(axis, lanA, cross - 0.66))) { + var lx2 = Math.floor(PJ.x), ly2 = Math.floor(PJ.y), ld2 = PJ.d; + emit(f, lx2, ly2, G_o, P.amber, 210 * LAMP, ld2 * 0.97); + emit(f, lx2, ly2 - 1, G_DOT, P.warm, 128 * LAMP, ld2 * 0.97); + if (ld2 < 26) { + emit(f, lx2 - 1, ly2, G_TICK, P.warm, 90 * LAMP, ld2 * 0.97); + emit(f, lx2 + 1, ly2, G_TICK, P.warm, 90 * LAMP, ld2 * 0.97); + } + } + } + + var hx2 = axis ? go : 0, hz2 = axis ? 0 : go; + var teamA = front + go * 2.05; + var h; + for (h = 0; h < 2; h++) { + var lat2 = h ? 0.55 : -0.55; + B.x = wx(axis, teamA, cross + lat2); B.z = wz(axis, teamA, cross + lat2); + B.ux = hx2; B.uz = hz2; + B.len = 1.98 + hash2(m + h, cyc, BASE + 0x24) * 0.18; + B.wy = 1.56 + hash2(m + h, cyc, BASE + 0x25) * 0.14; + B.head = 0; + B.tail = 0; + B.lift = 0; + B.legW = objVisible(axis, teamA, cross + lat2, 0.5) < 18 ? 1 : 0; + hideLight(); + beast(f); + } + } + + var DOG_PITCH = 31.0; + + function drawDogs(f, axis, idx) { + streetSpan(axis, idx); + var here = axis ? V.ox : V.oz; + var lo = Math.floor((here - 22) / DOG_PITCH), hi = Math.floor((here + 44) / DOG_PITCH); + + for (var k = lo; k <= hi; k++) { + + var slot = idx * 2 + axis; + var g0 = hash2(k, slot, BASE + 0x31); + if (g0 > 0.60) continue; + var along = k * DOG_PITCH + g0 * 22; + + var f0 = frontage(axis, along - 1.0, 2.0, SPAN.c0, 1); + var f1 = frontage(axis, along - 1.0, 2.0, SPAN.c1, -1); + if (!f0 && !f1) continue; + + var T = 24 + hash2(k, slot, BASE + 0x32) * 26; + var uu = V.t / T + hash2(k, slot, BASE + 0x33); + var cyc = Math.floor(uu), ph = uu - cyc; + + if (CC.reducedMotion) ph = 0.11; + if (ph > 0.26) continue; + var q = ph / 0.26; + + var go = (f0 && f1) ? (hash2(k, cyc, BASE + 0x34) < 0.5 ? 1 : -1) : (f0 ? 1 : -1); + var c0 = SPAN.c0 - 0.9, c1 = SPAN.c1 + 0.9; + var cross = go > 0 ? c0 + (c1 - c0) * q : c1 - (c1 - c0) * q; + var w = objVisible(axis, along, cross, 0.9); + if (!w) continue; + + B.x = wx(axis, along, cross); B.z = wz(axis, along, cross); + B.ux = axis ? 0 : go; B.uz = axis ? go : 0; + B.len = 0.80; B.wy = 0.56; + B.head = 0.25; + B.tail = 1; + + B.lift = 0; + B.legW = 0; + hideLight(); + B.rimLum *= 0.85; + beast(f); + } + } + + function eachStreet(f, fn) { + var i; + for (i = -1; i <= 1; i++) fn(f, 0, nearIdx(0) + i); + for (i = -1; i <= 1; i++) fn(f, 1, nearIdx(1) + i); + } + + function mk(name, layer, fn) { + return { + name: name, layer: layer, world: 'west', + init: function (city) { boot(city); }, + draw: function (f, cam, t) { + if (!CITY) return; + view(f, cam, t === undefined ? (cam.t || 0) : t); + fn(f); + } }; + } - function topF(u, head) { - if (u <= 0.72) { - - if (u < 0.14) return 0.88 + (0.92 - 0.88) * (u / 0.14); - if (u < 0.45) return 0.92 + (0.86 - 0.92) * ((u - 0.14) / 0.31); - return 0.86 + (0.98 - 0.86) * ((u - 0.45) / 0.27); - } - var q, up, dn; - if (u <= 1.06) { - - q = (u - 0.72) / 0.34; - up = 0.98 + 0.34 * q; - dn = 0.98 - 0.30 * q; - } else { - - q = (u - 1.06) / 0.20; if (q > 1) q = 1; - up = 1.32 - 0.12 * q; - dn = 0.68 - 0.08 * q; - } - return up + (dn - up) * head; - } - function botF(u, head) { - if (u <= 0.72) { - if (u < 0.25) return 0.60 + (0.55 - 0.60) * (u / 0.25); - return 0.55 + (0.62 - 0.55) * ((u - 0.25) / 0.47); - } - - var d; - if (u <= 1.06) d = 0.36 - 0.18 * ((u - 0.72) / 0.34); - else { d = (u - 1.06) / 0.20; if (d > 1) d = 1; d = 0.18 + 0.06 * d; } - return topF(u, head) - d; - } - - function wideF(u, len) { - var k; - if (u < 0.06) k = 0.20 + 0.08 * (u / 0.06); - else if (u <= 0.70) k = 0.28; - else k = 0.28 - 0.17 * ((u - 0.70) / 0.54); - - if (k < 0.11) k = 0.11; - return k * len; - } - - var CB_N = 1024; - var CB_TOP = new Int16Array(CB_N), CB_BOT = new Int16Array(CB_N), - CB_D = new Float32Array(CB_N), CB_END = new Uint8Array(CB_N), - CB_BAR = new Uint8Array(CB_N), CB_G = new Int32Array(CB_N), CB_GEN = 0; - - function beast(f) { - var lx = B.ux, lz = B.uz; - var px = lz, pz = -lx; - - if (!project(B.x - lx * 0.5 * B.len, B.wy * 0.85, B.z - lz * 0.5 * B.len)) return; - var sx0 = PJ.x; - if (!project(B.x + lx * 0.7 * B.len, B.wy * 0.85, B.z + lz * 0.7 * B.len)) return; - var span = PJ.x - sx0; if (span < 0) span = -span; - var n = (span + 4) | 0; if (n < 8) n = 8; if (n > 140) n = 140; - - var rumpL = litFace(-lx, -lz), chestL = litFace(lx, lz); - var endLit = rumpL > chestL ? 0 : 1; - var endStr = (rumpL > chestL ? rumpL : chestL) * SUN; - - CB_GEN++; - var lo = 1e9, hi = -1e9; - var i, u, y0, y1, wxp, wzp, cx, rt, rb, dd, hw, r, q; - for (i = 0; i <= n; i++) { - u = -0.06 + 1.32 * (i / n); - y0 = topF(u, B.head) * B.wy + B.lift; - y1 = botF(u, B.head) * B.wy + B.lift; - wxp = B.x + lx * (u - 0.5) * B.len; wzp = B.z + lz * (u - 0.5) * B.len; - if (!project(wxp, y0, wzp)) continue; - cx = PJ.x; rt = Math.floor(PJ.y); dd = PJ.d; - if (!project(wxp, y1, wzp)) continue; - rb = Math.floor(PJ.y); - if (rb < rt) { r = rt; rt = rb; rb = r; } - hw = wideF(u, B.len) * 0.5 * V.colK / dd; - if (hw > 20) hw = 20; - var q0 = Math.round(cx - hw), q1 = Math.round(cx + hw); - if (q0 < 0) q0 = 0; - if (q1 > V.cols - 1) q1 = V.cols - 1; - if (q1 >= CB_N) q1 = CB_N - 1; - var isEnd = endStr > 0.30 && - ((endLit === 0 && u < 0.11) || (endLit === 1 && u > 1.02)); - var isBar = u > 0.02 && u < 0.74; - for (q = q0; q <= q1; q++) { - if (CB_G[q] !== CB_GEN) { - CB_G[q] = CB_GEN; CB_TOP[q] = rt; CB_BOT[q] = rb; CB_D[q] = dd; - CB_END[q] = 0; CB_BAR[q] = 0; - } else { - if (rt < CB_TOP[q]) CB_TOP[q] = rt; - if (rb > CB_BOT[q]) CB_BOT[q] = rb; - if (dd < CB_D[q]) CB_D[q] = dd; - } - if (isEnd) CB_END[q] = 1; - if (isBar) CB_BAR[q] = 1; - if (q < lo) lo = q; - if (q > hi) hi = q; - } - } - if (hi < lo) return; - - var el = 24 + 82 * endStr, elCol = WARM > 0.45 ? P.amber : P.white; - var headEnd = (lx * V.rgx + lz * V.rgz) > 0 ? hi : lo; - for (q = lo; q <= hi; q++) { - if (CB_G[q] !== CB_GEN) continue; - rt = CB_TOP[q]; rb = CB_BOT[q]; dd = CB_D[q]; - for (r = rt; r <= rb; r++) emit(f, q, r, G_HASH, B.fill, B.fillLum, dd); - - if (CB_END[q] && el >= 5) { - var eb = rt + (((rb - rt) * 0.66) | 0); - for (r = rt + 1; r <= eb; r++) - emit(f, q, r, G_o, elCol, el * (r === rt + 1 ? 1 : 0.60), dd * 0.988); - } - - if (B.rimLum >= 4) { - var gl = G_DASH, drop = 0; - if (q > lo && CB_G[q - 1] === CB_GEN) drop = rt - CB_TOP[q - 1]; - if (drop > 1) gl = G_BSLASH; - else if (drop < -1) gl = G_SLASH; - - if (q === headEnd) gl = G_o; - emit(f, q, rt, gl, B.rim, B.rimLum, dd * 0.988); - - if (CB_BAR[q] && B.rimLum >= 12) - emit(f, q, rb, G_UNDER, B.rim, B.rimLum * 0.22, dd * 0.988); - } - } - - var lat, uL, k2; - for (k2 = 0; k2 < 4; k2++) { - - uL = (k2 < 2) ? 0.66 : 0.10; - lat = (k2 & 1) ? 0.16 : -0.16; - column(f, B.x + lx * (uL - 0.5) * B.len + px * lat * B.len * 0.5, - B.z + lz * (uL - 0.5) * B.len + pz * lat * B.len * 0.5, - 0, botF(uL, B.head) * B.wy + B.lift + 0.04, - G_PIPE, B.fill, B.fillLum, B.legW); - } - - var tx = B.x - lx * 0.56 * B.len, tz = B.z - lz * 0.56 * B.len; - if (B.tail > 0.5) - column(f, tx, tz, topF(0.02, B.head) * B.wy + B.lift, - (topF(0.02, B.head) + 0.30) * B.wy + B.lift, G_QUOTE, B.rim, B.rimLum * 0.7, 0); - else - column(f, tx, tz, 0.30 * B.wy + B.lift, topF(0.02, B.head) * B.wy + B.lift, - G_PIPE, B.fill, B.fillLum, 0); - } - - function hideLight() { - - B.rimLum = 30 + 128 * SUN + (1 - SUN) * (72 * LAMP); - B.rim = WARM > 0.45 ? P.amber : P.white; - - B.fill = P.ember; - B.fillLum = SUN > 0.33 ? (12 + 34 * (SUN - 0.33) / 0.67) : 0; - } - - var RAIL_PITCH = 15.0; - - function drawHitched(f, axis, idx) { - streetSpan(axis, idx); - var pave = paveOf(SPAN.w); - var lo = Math.floor(((axis ? V.ox : V.oz) - 48) / RAIL_PITCH); - var hi = Math.floor(((axis ? V.ox : V.oz) + 48) / RAIL_PITCH); - - for (var s = 0; s < 2; s++) { - var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1; - var edge = face + dirIn * (pave + 0.15); - - var hx = axis ? 0 : -dirIn, hz = axis ? -dirIn : 0; - - for (var k = lo; k <= hi; k++) { - var h0 = hash2(k, idx * 2 + s, RAIL_BASE + 0x61); - if (h0 > 0.62) continue; - var along = k * RAIL_PITCH + h0 * 9; - if (!objVisible(axis, along, edge, 0.8)) continue; - if (!frontage(axis, along, 5.2, face, dirIn)) continue; - var kind = hash2(k, idx * 2 + s, RAIL_BASE + 0x62); - if (kind >= 0.52) continue; - var L = 3.6 + kind * 3.2; - - var occ = hash2(k, idx * 2 + s, BASE + 0x11); - var nH = occ < 0.70 ? 1 : (occ < 0.94 ? 2 : 3); - - for (var j = 0; j < nH; j++) { - var a = along + 0.72 + j * 1.45; - if (a > along + L - 0.5) break; - var hA = hash2(k * 5 + j, idx * 2 + s, BASE + 0x12); - var hB = hash2(k * 5 + j, idx * 2 + s, BASE + 0x13); - - var cross = edge + dirIn * 1.50; - var w = objVisible(axis, a, cross, 0.9); - if (!w) continue; - - B.x = wx(axis, a, cross); B.z = wz(axis, a, cross); - B.ux = hx; B.uz = hz; - B.len = 1.92 + hA * 0.22; - B.wy = 1.52 + hB * 0.16; - - B.head = hA < 0.34 ? 1 : 0; - B.tail = 0; - - B.lift = CC.reducedMotion ? 0 - : 0.035 * Math.sin(V.t * 0.50 + (hA + hB) * 6.283); - B.legW = w < 16 ? 1 : 0; - hideLight(); - beast(f); - - if (w < 15) { - var muzz = topF(1.16, B.head) * B.wy - 0.10; - var mc = cross - dirIn * 1.30; - var rx2 = wx(axis, a, mc), rz2 = wz(axis, a, mc); - - if (muzz > 1.16 && project(rx2, muzz, rz2)) { - var rcx = Math.floor(PJ.x), rr0 = Math.floor(PJ.y), rdd = PJ.d; - if (project(rx2, 1.04, rz2)) { - var rr1 = Math.floor(PJ.y), rr; - for (rr = rr0; rr <= rr1; rr++) - emit(f, rcx, rr, G_QUOTE, B.rim, B.rimLum * 0.34, rdd * 0.97); - } - } - } - } - } - } - } - - var COR = { axis: 0, ctr: 0, along: 0, dir: 1 }; - - function corridor() { - var k = Math.round(V.ox / CITY.AVE), m = Math.round(V.oz / CITY.CROSS); - var aC = 0, aW = 0, cC = 0, cW = 0, bA = 1e18, bC = 1e18, i, c, d; - for (i = k - 1; i <= k + 1; i++) { - c = CITY.aveX(i) + 0.5; d = V.ox - c; if (d < 0) d = -d; - if (d < bA) { bA = d; aC = c; aW = CITY.aveW(i) + 0.5; } - } - for (i = m - 1; i <= m + 1; i++) { - c = CITY.crossZ(i) + 0.5; d = V.oz - c; if (d < 0) d = -d; - if (d < bC) { bC = d; cC = c; cW = CITY.crossW(i) + 0.5; } - } - var afz = V.fwz < 0 ? -V.fwz : V.fwz, afx = V.fwx < 0 ? -V.fwx : V.fwx; - if (bC <= cW && (bA > aW || afx > afz)) { - COR.axis = 1; COR.ctr = cC; COR.along = V.ox; COR.dir = V.fwx < 0 ? -1 : 1; - } else { - COR.axis = 0; COR.ctr = aC; COR.along = V.oz; COR.dir = V.fwz < 0 ? -1 : 1; - } - } - - function wheel(f, px, pz, cy, rad, col, lum) { - if (!project(px, cy, pz)) return; - var x = Math.floor(PJ.x), y = Math.floor(PJ.y), d = PJ.d; - var rw = rad * V.colK / d, rh = rad * V.scale / d; - if (rw < 1.1 || rh < 0.8) { - - emit(f, x, y, G_o, col, lum, d); - emit(f, x, y + 1, G_COMMA, col, lum * 0.6, d); - return; - } - - var iw = Math.ceil(rw); if (iw > 26) iw = 26; - var i, r; - for (i = -iw; i < iw; i++) { - var u0 = i / rw, u1 = (i + 1) / rw; - if (u0 < -1) u0 = -1; if (u0 > 1) u0 = 1; - if (u1 < -1) u1 = -1; if (u1 > 1) u1 = 1; - var a0 = Math.sqrt(1 - u0 * u0) * rh, a1 = Math.sqrt(1 - u1 * u1) * rh; - var t0 = Math.round(y - a0), t1 = Math.round(y - a1); - if (t1 < t0) { r = t0; t0 = t1; t1 = r; } - - var g = (t1 - t0) > 1 ? G_PIPE : G_DASH; - for (r = t0; r <= t1; r++) emit(f, x + i, r, g, col, lum, d * 0.99); - var b0 = Math.round(y + a0), b1 = Math.round(y + a1); - if (b1 < b0) { r = b0; b0 = b1; b1 = r; } - g = (b1 - b0) > 1 ? G_PIPE : G_DASH; - for (r = b0; r <= b1; r++) emit(f, x + i, r, g, col, lum * 0.45, d * 0.99); - } - emit(f, x, y, G_o, col, lum * 0.7, d * 0.99); - } - - var WAG_SPAN = 40.0; - - function drawWagons(f) { - corridor(); - var wA = 1 - COR.axis; - var period = wA ? CITY.CROSS : CITY.AVE; - var i0 = Math.round(COR.along / period), m; - - for (m = i0 - 3; m <= i0 + 3; m++) { - var jc = (wA ? CITY.crossZ(m) : CITY.aveX(m)) + 0.5; - var ahead = (jc - COR.along) * COR.dir; - - if (ahead < 11 || ahead > 78) continue; - - var T = 42 + hash2(m, wA, BASE + 0x21) * 44; - var uu = V.t / T + hash2(m, wA, BASE + 0x22); - var cyc = Math.floor(uu), ph = uu - cyc; - - if (CC.reducedMotion) ph = 0.44; - var go = hash2(m, cyc, BASE + 0x23) < 0.5 ? -1 : 1; - var off = (ph * 2 - 1) * WAG_SPAN * go; - - streetSpan(wA, m); - - var road = SPAN.w * 0.5 - paveOf(SPAN.w); - if (road < 1.7) road = 1.7; - var lane = road * 0.42; if (lane > 1.5) lane = 1.5; - var cross = SPAN.mid - go * lane; - var aw = COR.ctr + off; - - var w = objVisible(wA, aw, cross, 2.0); - if (!w) continue; - drawWagon(f, wA, aw, cross, go, m, cyc); - } - } - - function drawWagon(f, axis, a, cross, go, m, cyc) { - var rear = a - go * 1.6, front = a + go * 1.6; - - var wcx = wx(axis, a, cross), wcz = wz(axis, a, cross); - var nx = axis ? 0 : 1, nz = axis ? 1 : 0; - if (nx * (V.ox - wcx) + nz * (V.oz - wcz) < 0) { nx = -nx; nz = -nz; } - var side = litFace(nx, nz); - var boardLum = (14 + 92 * side * SUN + 26 * LAMP * (1 - SUN)) | 0; - var boardCol = WARM > 0.45 ? P.amber : P.white; - - var deck = 1.02, capY = 1.48; - var n = 26, i; - for (i = 0; i <= n; i++) { - var aa = rear + (front - rear) * (i / n); - column(f, wx(axis, aa, cross), wz(axis, aa, cross), deck, capY - 0.06, - G_HASH, boardCol, boardLum * 0.55, 0); - column(f, wx(axis, aa, cross), wz(axis, aa, cross), deck - 0.20, deck, - G_HASH, P.shadow, 0, 0); - } - beam(f, axis, rear, front, cross, capY, G_EQ, boardCol, boardLum); - - var seatA = front - go * 0.42; - column(f, wx(axis, seatA, cross), wz(axis, seatA, cross), capY, 1.72, G_HASH, P.shadow, 0, 1); - column(f, wx(axis, seatA, cross - 0.1), wz(axis, seatA, cross - 0.1), 1.72, 2.34, - G_PIPE, P.shadow, 0, 1); - if (project(wx(axis, seatA, cross - 0.1), 2.36, wz(axis, seatA, cross - 0.1))) { - var dx0 = Math.floor(PJ.x), dy0 = Math.floor(PJ.y), dd0 = PJ.d; - emit(f, dx0, dy0, G_CARET, boardCol, boardLum * 1.2, dd0 * 0.98); - emit(f, dx0 - 1, dy0, G_DASH, boardCol, boardLum * 0.7, dd0 * 0.98); - emit(f, dx0 + 1, dy0, G_DASH, boardCol, boardLum * 0.7, dd0 * 0.98); - } - - var wl = 0.62; - var rw = 0.725, fw = 0.50; - var wheelLum = 30 + 96 * side * SUN + 30 * LAMP * (1 - SUN); - var wheelCol = WARM > 0.45 ? P.amber : P.white; - var rA = rear + go * 0.75, fA = front - go * 0.30; - wheel(f, wx(axis, rA, cross - wl), wz(axis, rA, cross - wl), rw, rw, wheelCol, wheelLum); - wheel(f, wx(axis, rA, cross + wl), wz(axis, rA, cross + wl), rw, rw, wheelCol, wheelLum * 0.7); - wheel(f, wx(axis, fA, cross - wl), wz(axis, fA, cross - wl), fw, fw, wheelCol, wheelLum); - wheel(f, wx(axis, fA, cross + wl), wz(axis, fA, cross + wl), fw, fw, wheelCol, wheelLum * 0.7); - - beam(f, axis, front, front + go * 2.6, cross, 0.74, G_DASH, boardCol, boardLum * 0.34); - - if (LAMP > 0.12) { - var lanA = front - go * 0.15; - if (project(wx(axis, lanA, cross - 0.66), capY + 0.16, wz(axis, lanA, cross - 0.66))) { - var lx2 = Math.floor(PJ.x), ly2 = Math.floor(PJ.y), ld2 = PJ.d; - emit(f, lx2, ly2, G_o, P.amber, 210 * LAMP, ld2 * 0.97); - emit(f, lx2, ly2 - 1, G_DOT, P.warm, 128 * LAMP, ld2 * 0.97); - if (ld2 < 26) { - emit(f, lx2 - 1, ly2, G_TICK, P.warm, 90 * LAMP, ld2 * 0.97); - emit(f, lx2 + 1, ly2, G_TICK, P.warm, 90 * LAMP, ld2 * 0.97); - } - } - } - - var hx2 = axis ? go : 0, hz2 = axis ? 0 : go; - var teamA = front + go * 2.05; - var h; - for (h = 0; h < 2; h++) { - var lat2 = h ? 0.55 : -0.55; - B.x = wx(axis, teamA, cross + lat2); B.z = wz(axis, teamA, cross + lat2); - B.ux = hx2; B.uz = hz2; - B.len = 1.98 + hash2(m + h, cyc, BASE + 0x24) * 0.18; - B.wy = 1.56 + hash2(m + h, cyc, BASE + 0x25) * 0.14; - B.head = 0; - B.tail = 0; - B.lift = 0; - B.legW = objVisible(axis, teamA, cross + lat2, 0.5) < 18 ? 1 : 0; - hideLight(); - beast(f); - } - } - - var DOG_PITCH = 31.0; - - function drawDogs(f, axis, idx) { - streetSpan(axis, idx); - var here = axis ? V.ox : V.oz; - var lo = Math.floor((here - 22) / DOG_PITCH), hi = Math.floor((here + 44) / DOG_PITCH); - - for (var k = lo; k <= hi; k++) { - - var slot = idx * 2 + axis; - var g0 = hash2(k, slot, BASE + 0x31); - if (g0 > 0.60) continue; - var along = k * DOG_PITCH + g0 * 22; - - var f0 = frontage(axis, along - 1.0, 2.0, SPAN.c0, 1); - var f1 = frontage(axis, along - 1.0, 2.0, SPAN.c1, -1); - if (!f0 && !f1) continue; - - var T = 24 + hash2(k, slot, BASE + 0x32) * 26; - var uu = V.t / T + hash2(k, slot, BASE + 0x33); - var cyc = Math.floor(uu), ph = uu - cyc; - - if (CC.reducedMotion) ph = 0.11; - if (ph > 0.26) continue; - var q = ph / 0.26; - - var go = (f0 && f1) ? (hash2(k, cyc, BASE + 0x34) < 0.5 ? 1 : -1) : (f0 ? 1 : -1); - var c0 = SPAN.c0 - 0.9, c1 = SPAN.c1 + 0.9; - var cross = go > 0 ? c0 + (c1 - c0) * q : c1 - (c1 - c0) * q; - var w = objVisible(axis, along, cross, 0.9); - if (!w) continue; - - B.x = wx(axis, along, cross); B.z = wz(axis, along, cross); - B.ux = axis ? 0 : go; B.uz = axis ? go : 0; - B.len = 0.80; B.wy = 0.56; - B.head = 0.25; - B.tail = 1; - - B.lift = 0; - B.legW = 0; - hideLight(); - B.rimLum *= 0.85; - beast(f); - } - } - - function eachStreet(f, fn) { - var i; - for (i = -1; i <= 1; i++) fn(f, 0, nearIdx(0) + i); - for (i = -1; i <= 1; i++) fn(f, 1, nearIdx(1) + i); - } - - function mk(name, layer, fn) { - return { - name: name, layer: layer, world: 'west', - 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('west-hitched', 20, function (f) { eachStreet(f, drawHitched); })); - CC.ELEMENTS.push(mk('west-wagon', 22, drawWagons)); - CC.ELEMENTS.push(mk('west-dog', 22, function (f) { eachStreet(f, drawDogs); })); + CC.ELEMENTS.push(mk('west-hitched', 20, function (f) { eachStreet(f, drawHitched); })); + CC.ELEMENTS.push(mk('west-wagon', 22, drawWagons)); + CC.ELEMENTS.push(mk('west-dog', 22, function (f) { eachStreet(f, drawDogs); })); })(CC); /* src/elements/west_town.js */ (function (CC) { - 'use strict'; + 'use strict'; - 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 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, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp; + var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp; - var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_DOT = CC.g('.'), - G_COLON = CC.g(':'), G_TICK = CC.g('`'), G_CARET = CC.g('^'), G_STAR = CC.g('*'), - G_0 = CC.g('0'), G_O = CC.g('O'), G_o = CC.g('o'), G_HASH = CC.g('#'), G_PLUS = CC.g('+'), - G_TILDE = CC.g('~'); + var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_DOT = CC.g('.'), + G_COLON = CC.g(':'), G_TICK = CC.g('`'), G_CARET = CC.g('^'), G_STAR = CC.g('*'), + G_0 = CC.g('0'), G_O = CC.g('O'), G_o = CC.g('o'), G_HASH = CC.g('#'), G_PLUS = CC.g('+'), + G_TILDE = CC.g('~'), G_UNDER = CC.g('_'), G_SLASH = CC.g('/'), G_PCT = CC.g('%'), + G_DQ = CC.g('"'); - var CITY = null, BASE = 0, Surf = null, WEST = null; - function boot(city) { - CITY = (city && city.aveX && city.world === 'west') ? city : null; - BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 8) & 0x3fffff) : 0; + function dayF() { + var W = CC.SurfWest; + return W && W.dayFill !== undefined ? W.dayFill : 0; + } + + function woodC(sun, day) { + return day ? (sun > 0.6 ? P.sand : P.timber) : (sun > 0.6 ? P.amber : P.slate); + } + + var CITY = null, BASE = 0, Surf = null, WEST = null; + function boot(city) { + CITY = (city && city.aveX && city.world === 'west') ? city : null; + BASE = CITY ? ((Math.imul(CITY.seed | 0, 40503) >>> 8) & 0x3fffff) : 0; + } + + var W_WIND = 1, W_WET = 1; + + function view(f, cam, t) { + PR.view(f, cam, t); + + if (!Surf) Surf = CC.Surf; + if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null; + W_WIND = CC.Weather ? CC.Weather.rel('wind') : 1; + W_WET = CC.Weather ? CC.Weather.rel('wet') : 1; + } + + var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 }; + function streetSpan(axis, idx) { + var c, h; + if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); } + else { c = CITY.aveX(idx); h = CITY.aveW(idx); } + SPAN.c0 = c - h; SPAN.c1 = c + h + 1; + SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0; + } + function wx(axis, along, cross) { return axis ? along : cross; } + function wz(axis, along, cross) { return axis ? cross : along; } + + function nX(axis, s) { return axis ? 0 : (s ? -1 : 1); } + function nZ(axis, s) { return axis ? (s ? -1 : 1) : 0; } + + function paveOf(spanW) { + var p = CC.PAVE, avail = spanW * 0.5 - 1.7; + return avail < p ? avail : p; + } + + function frontage(axis, a0, len, cross, dirIn) { + var i, a, c = cross - dirIn * 0.7; + for (i = 0; i <= 3; i++) { + a = a0 + len * (i / 3); + if (CITY.height(wx(axis, a, c), wz(axis, a, c)) < 2.5) return 0; } + return 1; + } - var W_WIND = 1, W_WET = 1; + function objVisible(axis, along, cross, near) { + var px = wx(axis, along, cross), pz = wz(axis, along, cross); + var rx = px - V.ox, rz = pz - V.oz; + var w = rx * V.fwx + rz * V.fwz; + if (w < near || w > V.far) return 0; + var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; + if (s < -lim || s > lim) return 0; + return w; + } - function view(f, cam, t) { - PR.view(f, cam, t); + function beam(f, axis, a0, a1, cross, y, ch, col, lum) { - if (!Surf) Surf = CC.Surf; - if (!WEST) WEST = (CC.SURFACES && CC.World) ? CC.SURFACES[CC.World.id] : null; - W_WIND = CC.Weather ? CC.Weather.rel('wind') : 1; - W_WET = CC.Weather ? CC.Weather.rel('wet') : 1; - } - - var SPAN = { c0: 0, c1: 0, mid: 0, w: 0 }; - function streetSpan(axis, idx) { - var c, h; - if (axis) { c = CITY.crossZ(idx); h = CITY.crossW(idx); } - else { c = CITY.aveX(idx); h = CITY.aveW(idx); } - SPAN.c0 = c - h; SPAN.c1 = c + h + 1; - SPAN.mid = c + 0.5; SPAN.w = SPAN.c1 - SPAN.c0; - } - function wx(axis, along, cross) { return axis ? along : cross; } - function wz(axis, along, cross) { return axis ? cross : along; } - - function nX(axis, s) { return axis ? 0 : (s ? -1 : 1); } - function nZ(axis, s) { return axis ? (s ? -1 : 1) : 0; } - - function paveOf(spanW) { - var p = CC.PAVE, avail = spanW * 0.5 - 1.7; - return avail < p ? avail : p; - } - - function frontage(axis, a0, len, cross, dirIn) { - var i, a, c = cross - dirIn * 0.7; - for (i = 0; i <= 3; i++) { - a = a0 + len * (i / 3); - if (CITY.height(wx(axis, a, c), wz(axis, a, c)) < 2.5) return 0; + var n = 22, i, a, lx = -1, ly = 0, ld = 0; + for (i = 0; i <= n; i++) { + a = a0 + (a1 - a0) * (i / n); + if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) { lx = -1; continue; } + var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d; + if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1; + if (lx >= 0) { + var dx = x - lx, dy = r - ly; + var steps = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); + if (steps > 4 * V.cols) steps = 0; + for (var q = 1; q < steps; q++) { + var t2 = q / steps; + emit(f, lx + Math.round(dx * t2), ly + Math.round(dy * t2), ch, col, lum, + ld + (d - ld) * t2); } - return 1; + } + emit(f, x, r, ch, col, lum, d); + lx = x; ly = r; ld = d; } + } - function objVisible(axis, along, cross, near) { - var px = wx(axis, along, cross), pz = wz(axis, along, cross); - var rx = px - V.ox, rz = pz - V.oz; - var w = rx * V.fwx + rz * V.fwz; - if (w < near || w > V.far) return 0; - var s = rx * V.rgx + rz * V.rgz, lim = w * V.hp + 14; - if (s < -lim || s > lim) return 0; - return w; - } + var POST = 2.6; + var AWN_Y = 2.94; - function beam(f, axis, a0, a1, cross, y, ch, col, lum) { + function drawVeranda(f, axis, idx) { + streetSpan(axis, idx); + var pave = paveOf(SPAN.w); + if (pave < 1.1) return; + var pitch = axis ? CITY.AVE : CITY.CROSS; + var lo = Math.floor(((axis ? V.ox : V.oz) - 60) / POST); + var hi = Math.floor(((axis ? V.ox : V.oz) + 60) / POST); + if (hi - lo > 60) hi = lo + 60; - var n = 22, i, a, lx = -1, ly = 0, ld = 0; - for (i = 0; i <= n; i++) { - a = a0 + (a1 - a0) * (i / n); - if (!project(wx(axis, a, cross), y, wz(axis, a, cross))) { lx = -1; continue; } - var x = Math.floor(PJ.x), r = Math.floor(PJ.y), d = PJ.d; - if (lx >= 0 && (d > ld * 2 || ld > d * 2)) lx = -1; - if (lx >= 0) { - var dx = x - lx, dy = r - ly; - var steps = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy); - if (steps > 4 * V.cols) steps = 0; - for (var q = 1; q < steps; q++) { - var t2 = q / steps; - emit(f, lx + Math.round(dx * t2), ly + Math.round(dy * t2), ch, col, lum, - ld + (d - ld) * t2); - } + for (var s = 0; s < 2; s++) { + var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1; + var postC = face + dirIn * (pave - 0.34); + var nx = nX(axis, s), nz = nZ(axis, s); + var sun = litFace(nx, nz); + + var dF = dayF(); + + for (var k = lo; k <= hi; k++) { + var along = k * POST + 0.5; + var w = objVisible(axis, along, postC, 0.7); + if (!w) continue; + if (!frontage(axis, along - POST * 0.5, POST, face, dirIn)) continue; + var hh = hash2(k, idx * 2 + s, BASE + (axis ? 0x51 : 0x52)); + var day = hash2(k, idx * 2 + s, BASE + 0x54) < dF; + var pcol = woodC(sun, day); + + var plum = day ? (sun > 0.6 ? 168 : 92) : (sun > 0.6 ? 74 : 20); + + column(f, wx(axis, along, postC), wz(axis, along, postC), 0.0, AWN_Y, + G_PIPE, pcol, plum, w < 12 ? 1 : 0); + + if (day && w < 14) { + if (project(wx(axis, along, postC), 0.10, wz(axis, along, postC))) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, + sun > 0.6 ? P.stone : P.timber, sun > 0.6 ? 132 : 74, PJ.d); + + var bq, by2, bc2; + for (bq = 0; bq < 3; bq++) { + by2 = AWN_Y - 0.30 - bq * 0.22; + bc2 = postC + dirIn * (0.22 + bq * 0.20); + if (project(wx(axis, along, bc2), by2, wz(axis, along, bc2))) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_SLASH, + sun > 0.6 ? P.sand : P.timber, sun > 0.6 ? 118 : 66, PJ.d); + } + } + + beam(f, axis, along - POST, along, postC, AWN_Y + 0.06, G_EQ, + day ? (sun > 0.6 ? P.sand : P.stone) : (sun > 0.6 ? P.amber : P.slate), + day ? (sun > 0.6 ? 196 : 112) : (sun > 0.6 ? 96 : 26)); + + beam(f, axis, along - POST, along, postC, AWN_Y - 0.12, G_DASH, + day ? P.indigo : P.shadow, day ? 58 : 0); + + if (day && hh < 0.34) { + var stripe = (k & 1) === 0; + beam(f, axis, along - POST, along, postC + dirIn * 0.30, AWN_Y + 0.20, G_HASH, + stripe ? P.white : P.ember, sun > 0.6 ? (stripe ? 190 : 150) : (stripe ? 104 : 84)); + beam(f, axis, along - POST, along, postC + dirIn * 0.62, AWN_Y + 0.34, G_EQ, + stripe ? P.ember : P.white, sun > 0.6 ? (stripe ? 150 : 190) : (stripe ? 84 : 104)); + } + + if (hh < 0.30 && hash2(k + 1, idx * 2 + s, BASE + 0x53) > 0.30) { + var ly = AWN_Y - 0.42; + if (project(wx(axis, along, postC), ly, wz(axis, along, postC))) { + var lx = Math.floor(PJ.x), lr = Math.floor(PJ.y), ld = PJ.d; + + var lk = 1 - dF; + if (lk > 0.02) { + emit(f, lx, lr, G_o, P.amber, 236 * lk, ld); + emit(f, lx, lr - 1, G_DOT, P.warm, 150 * lk, ld); + if (ld < 22) { + emit(f, lx + 1, lr, G_TICK, P.warm, 108 * lk, ld); + emit(f, lx - 1, lr, G_TICK, P.warm, 108 * lk, ld); + } } - emit(f, x, r, ch, col, lum, d); - lx = x; ly = r; ld = d; - } - } - - var POST = 2.6; - var AWN_Y = 2.94; - - function drawVeranda(f, axis, idx) { - streetSpan(axis, idx); - var pave = paveOf(SPAN.w); - if (pave < 1.1) return; - var pitch = axis ? CITY.AVE : CITY.CROSS; - var lo = Math.floor(((axis ? V.ox : V.oz) - 60) / POST); - var hi = Math.floor(((axis ? V.ox : V.oz) + 60) / POST); - if (hi - lo > 60) hi = lo + 60; - - for (var s = 0; s < 2; s++) { - var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1; - var postC = face + dirIn * (pave - 0.34); - var nx = nX(axis, s), nz = nZ(axis, s); - var sun = litFace(nx, nz); - - var pcol = sun > 0.6 ? P.amber : P.slate; - var plum = sun > 0.6 ? 74 : 20; - - for (var k = lo; k <= hi; k++) { - var along = k * POST + 0.5; - var w = objVisible(axis, along, postC, 0.7); - if (!w) continue; - if (!frontage(axis, along - POST * 0.5, POST, face, dirIn)) continue; - var hh = hash2(k, idx * 2 + s, BASE + (axis ? 0x51 : 0x52)); - - column(f, wx(axis, along, postC), wz(axis, along, postC), 0.0, AWN_Y, - G_PIPE, pcol, plum, w < 12 ? 1 : 0); - - beam(f, axis, along - POST, along, postC, AWN_Y + 0.06, G_EQ, - sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 96 : 26); - beam(f, axis, along - POST, along, postC, AWN_Y - 0.12, G_DASH, P.shadow, 0); - - if (hh < 0.30 && hash2(k + 1, idx * 2 + s, BASE + 0x53) > 0.30) { - var ly = AWN_Y - 0.42; - if (project(wx(axis, along, postC), ly, wz(axis, along, postC))) { - var lx = Math.floor(PJ.x), lr = Math.floor(PJ.y), ld = PJ.d; - - emit(f, lx, lr, G_o, P.amber, 236, ld); - emit(f, lx, lr - 1, G_DOT, P.warm, 150, ld); - if (ld < 22) { - emit(f, lx + 1, lr, G_TICK, P.warm, 108, ld); - emit(f, lx - 1, lr, G_TICK, P.warm, 108, ld); - } - } - } + if (dF > 0.02) { + emit(f, lx, lr, G_0, sun > 0.6 ? P.gold : P.timber, + (sun > 0.6 ? 150 : 84) * dF, ld); + emit(f, lx, lr - 1, G_CARET, sun > 0.6 ? P.gold : P.timber, + (sun > 0.6 ? 122 : 66) * dF, ld); } - + } } + } + } + } - var RAIL_PITCH = 15.0; + var RAIL_PITCH = 15.0; - function drawStreetProps(f, axis, idx) { - streetSpan(axis, idx); - var pave = paveOf(SPAN.w); - var lo = Math.floor(((axis ? V.ox : V.oz) - 48) / RAIL_PITCH); - var hi = Math.floor(((axis ? V.ox : V.oz) + 48) / RAIL_PITCH); + function drawStreetProps(f, axis, idx) { + streetSpan(axis, idx); + var pave = paveOf(SPAN.w); + var lo = Math.floor(((axis ? V.ox : V.oz) - 48) / RAIL_PITCH); + var hi = Math.floor(((axis ? V.ox : V.oz) + 48) / RAIL_PITCH); - for (var s = 0; s < 2; s++) { - var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1; - var sun = litFace(nX(axis, s), nZ(axis, s)); - var edge = face + dirIn * (pave + 0.15); + var dF = dayF(); + for (var s = 0; s < 2; s++) { + var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1; + var sun = litFace(nX(axis, s), nZ(axis, s)); + var edge = face + dirIn * (pave + 0.15); - for (var k = lo; k <= hi; k++) { - var h0 = hash2(k, idx * 2 + s, BASE + 0x61); - if (h0 > 0.62) continue; - var along = k * RAIL_PITCH + h0 * 9; - var w = objVisible(axis, along, edge, 0.8); - if (!w) continue; - if (!frontage(axis, along, 5.2, face, dirIn)) continue; + for (var k = lo; k <= hi; k++) { + var day = hash2(k, idx * 2 + s, BASE + 0x64) < dF; + var h0 = hash2(k, idx * 2 + s, BASE + 0x61); + if (h0 > 0.62) continue; + var along = k * RAIL_PITCH + h0 * 9; + var w = objVisible(axis, along, edge, 0.8); + if (!w) continue; + if (!frontage(axis, along, 5.2, face, dirIn)) continue; - var kind = hash2(k, idx * 2 + s, BASE + 0x62); - if (kind < 0.52) { + var kind = hash2(k, idx * 2 + s, BASE + 0x62); + if (kind < 0.52) { - var L = 3.6 + kind * 3.2; - column(f, wx(axis, along, edge), wz(axis, along, edge), 0, 1.28, G_PIPE, - sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 62 : 18, 0); - column(f, wx(axis, along + L, edge), wz(axis, along + L, edge), 0, 1.28, G_PIPE, - sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 62 : 18, 0); - beam(f, axis, along, along + L, edge, 1.06, G_DASH, - sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 72 : 20); - } else if (kind < 0.74) { + var L = 3.6 + kind * 3.2; + var rc = woodC(sun, day), rl = day ? (sun > 0.6 ? 148 : 80) : (sun > 0.6 ? 62 : 18); + column(f, wx(axis, along, edge), wz(axis, along, edge), 0, 1.28, G_PIPE, rc, rl, 0); + column(f, wx(axis, along + L, edge), wz(axis, along + L, edge), 0, 1.28, G_PIPE, rc, rl, 0); + beam(f, axis, along, along + L, edge, 1.06, G_DASH, rc, + day ? (sun > 0.6 ? 162 : 88) : (sun > 0.6 ? 72 : 20)); - var TL = 2.5; - beam(f, axis, along, along + TL, edge, 0.62, G_EQ, sun > 0.6 ? P.white : P.slate, - sun > 0.6 ? 76 : 24); - beam(f, axis, along, along + TL, edge, 0.30, G_HASH, P.shadow, 0); - beam(f, axis, along + 0.15, along + TL - 0.15, edge - dirIn * 0.02, 0.55, - G_TILDE, P.ember, 128); - } else { + if (day && objVisible(axis, along, edge, 0.8) < 20) + beam(f, axis, along + 0.5, along + L + 0.5, edge - dirIn * 1.15, 0.02, G_DASH, + P.timber, sun > 0.6 ? 62 : 34); + } else if (kind < 0.74) { - var bc = face + dirIn * 0.55; - for (var b = 0; b < 3; b++) { - var bh = hash2(k * 7 + b, idx * 2 + s, BASE + 0x63); - if (bh > 0.66) continue; - var ba = along + b * 0.95; - if (!objVisible(axis, ba, bc, 0.8)) continue; - var tall = 0.42 + bh * 0.62; - column(f, wx(axis, ba, bc), wz(axis, ba, bc), 0.18, 0.18 + tall, - bh < 0.33 ? G_O : G_HASH, sun > 0.6 ? P.amber : P.slate, - sun > 0.6 ? 56 : 16, 1); - } - } + var TL = 2.5; + beam(f, axis, along, along + TL, edge, 0.62, G_EQ, + day ? (sun > 0.6 ? P.sand : P.stone) : (sun > 0.6 ? P.white : P.slate), + day ? (sun > 0.6 ? 172 : 96) : (sun > 0.6 ? 76 : 24)); + + beam(f, axis, along, along + TL, edge, 0.30, G_HASH, + day ? P.timber : P.shadow, day ? 66 : 0); + + beam(f, axis, along + 0.15, along + TL - 0.15, edge - dirIn * 0.02, 0.55, + G_TILDE, day ? (sun > 0.6 ? P.pure : P.ice) : P.ember, + day ? (sun > 0.6 ? 196 : 150) : 128); + } else { + + var bc = face + dirIn * 0.55; + for (var b = 0; b < 3; b++) { + var bh = hash2(k * 7 + b, idx * 2 + s, BASE + 0x63); + if (bh > 0.66) continue; + var ba = along + b * 0.95; + if (!objVisible(axis, ba, bc, 0.8)) continue; + var tall = 0.42 + bh * 0.62; + column(f, wx(axis, ba, bc), wz(axis, ba, bc), 0.18, 0.18 + tall, + bh < 0.33 ? G_O : G_HASH, woodC(sun, day), + day ? (sun > 0.6 ? 142 : 78) : (sun > 0.6 ? 56 : 16), 1); + + if (day && objVisible(axis, ba, bc, 0.8) < 13 && + project(wx(axis, ba, bc), 0.18 + tall * 0.62, wz(axis, ba, bc))) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), bh < 0.33 ? G_DASH : G_EQ, + sun > 0.6 ? P.stone : P.timber, sun > 0.6 ? 168 : 92, PJ.d); + } + } + } + } + } + + function drawCrowns(f) { + var R = 74; + var gx0 = Math.floor(V.ox - R), gx1 = Math.floor(V.ox + R); + var gz0 = Math.floor(V.oz - R), gz1 = Math.floor(V.oz + R); + + for (var gz = gz0; gz <= gz1; gz += 4) { + for (var gx = gx0; gx <= gx1; gx += 4) { + var h = CITY.height(gx, gz); + if (h < 3) continue; + var rec = CITY.cell(gx, gz); + if (!rec || !rec.crown || rec.rock) continue; + + var cx = rec.lotX + 1.6 + rec.seed * 2.2, cz = rec.lotZ + 1.4 + rec.face * 2.4; + if (Math.abs(cx - gx) > 4 || Math.abs(cz - gz) > 4) continue; + var w = objVisible(0, cz, cx, 2.0); + if (!w) continue; + var sun = litFace(WEST ? WEST.SUN_X : -1, WEST ? WEST.SUN_Z : 0); + var dF = dayF(); + var day = rec.seed < dF; + var lum = 66, col = P.amber; + + if (rec.crown === 1) { + + var ch2 = 1.1 + rec.seed * 0.9; + + column(f, cx, cz, h, h + ch2, G_HASH, day ? (sun > 0.6 ? P.stone : P.timber) : P.slate, + day ? (sun > 0.6 ? 156 : 88) : 30, 1); + emit2smoke(f, cx, cz, h + ch2, rec); + } else if (rec.crown === 2) { + + var ty = h + 1.5, td = 1.5 + rec.seed * 0.8; + var lc = day ? P.timber : P.slate, ll = day ? 82 : 24; + column(f, cx - 0.7, cz - 0.7, h, ty, G_PIPE, lc, ll, 0); + column(f, cx + 0.7, cz - 0.7, h, ty, G_PIPE, lc, ll, 0); + column(f, cx - 0.7, cz + 0.7, h, ty, G_PIPE, lc, ll, 0); + column(f, cx + 0.7, cz + 0.7, h, ty, G_PIPE, lc, ll, 0); + for (var q = 0; q < 5; q++) { + var qx = cx - 0.9 + q * 0.45; + + var qq = q / 4; + column(f, qx, cz, ty, ty + td, G_0, + day ? (sun > 0.6 ? (qq < 0.55 ? P.sand : P.stone) : P.timber) + : (sun > 0.6 ? P.amber : P.slate), + day ? (sun > 0.6 ? 190 - 60 * qq : 92) : (sun > 0.6 ? 86 : 26), 0); + } + beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td, G_EQ, + day ? (sun > 0.6 ? P.sand : P.stone) : P.amber, day ? 176 : 96); + if (day) { + beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td * 0.62, G_DASH, P.timber, 68); + beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td * 0.22, G_DASH, P.timber, 68); + } + } else { + + var mill = rec.seed > 0.55; + var sy = h + 2.2 + rec.face * 3.4; + column(f, cx, cz, h, sy, G_PIPE, woodC(sun, day), + day ? (sun > 0.6 ? 162 : 88) : (sun > 0.6 ? 72 : 22), 0); + if (mill) { + + if (project(cx, sy, cz)) { + var mx = Math.floor(PJ.x), my = Math.floor(PJ.y), md = PJ.d; + for (var b2 = 0; b2 < 12; b2++) { + var an = b2 * Math.PI / 6; + + emit(f, mx + Math.round(Math.cos(an) * 2.2), my + Math.round(Math.sin(an) * 1.2), + G_PLUS, day ? P.stone : P.slate, day ? 92 : 54, md); + } + emit(f, mx, my, G_O, day ? P.timber : P.amber, day ? 96 : 120, md); + var sp = CC.reducedMotion ? 0.9 : V.t * 0.5 * (0.3 + 0.5 * W_WIND); + emit(f, mx + Math.round(Math.cos(sp) * 2.2), my + Math.round(Math.sin(sp) * 1.2), + G_STAR, P.amber, 128, md); } + } else { + + column(f, cx, cz, sy, sy + 1.2, G_CARET, P.white, day ? 190 : 84, 0); + if (project(cx, sy + 1.5, cz)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_PLUS, + day ? (sun > 0.6 ? P.gold : P.stone) : P.amber, day ? 168 : 148, PJ.d); + } } + } } + } - function drawCrowns(f) { - var R = 74; - var gx0 = Math.floor(V.ox - R), gx1 = Math.floor(V.ox + R); - var gz0 = Math.floor(V.oz - R), gz1 = Math.floor(V.oz + R); + function emit2smoke(f, cx, cz, y0, rec) { + var lean = 1.5 * W_WIND; + var tt = CC.reducedMotion ? 4.0 : V.t; + var sway = vnoise(tt * 0.33 + rec.seed * 7, 0x2A) - 0.5; + var N = 16; + for (var i = 0; i < N; i++) { + var u = i / (N - 1); + var yy = y0 + 0.15 + u * 3.8; - for (var gz = gz0; gz <= gz1; gz += 4) { - for (var gx = gx0; gx <= gx1; gx += 4) { - var h = CITY.height(gx, gz); - if (h < 3) continue; - var rec = CITY.cell(gx, gz); - if (!rec || !rec.crown || rec.rock) continue; + var dx = (lean * u * u + sway * 0.9 * u) * 1.6; + if (!project(cx + dx, yy, cz + dx * 0.35)) continue; - var cx = rec.lotX + 1.6 + rec.seed * 2.2, cz = rec.lotZ + 1.4 + rec.face * 2.4; - if (Math.abs(cx - gx) > 4 || Math.abs(cz - gz) > 4) continue; - var w = objVisible(0, cz, cx, 2.0); - if (!w) continue; - var sun = litFace(WEST ? WEST.SUN_X : -1, WEST ? WEST.SUN_Z : 0); - var lum = 66, col = P.amber; + var dF = dayF(); - if (rec.crown === 1) { - - var ch2 = 1.1 + rec.seed * 0.9; - column(f, cx, cz, h, h + ch2, G_HASH, P.slate, 30, 1); - emit2smoke(f, cx, cz, h + ch2, rec); - } else if (rec.crown === 2) { - - var ty = h + 1.5, td = 1.5 + rec.seed * 0.8; - column(f, cx - 0.7, cz - 0.7, h, ty, G_PIPE, P.slate, 24, 0); - column(f, cx + 0.7, cz - 0.7, h, ty, G_PIPE, P.slate, 24, 0); - column(f, cx - 0.7, cz + 0.7, h, ty, G_PIPE, P.slate, 24, 0); - column(f, cx + 0.7, cz + 0.7, h, ty, G_PIPE, P.slate, 24, 0); - for (var q = 0; q < 5; q++) { - var qx = cx - 0.9 + q * 0.45; - column(f, qx, cz, ty, ty + td, G_0, sun > 0.6 ? P.amber : P.slate, - sun > 0.6 ? 86 : 26, 0); - } - beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td, G_EQ, P.amber, 96); - } else { - - var mill = rec.seed > 0.55; - var sy = h + 2.2 + rec.face * 3.4; - column(f, cx, cz, h, sy, G_PIPE, sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 72 : 22, 0); - if (mill) { - - if (project(cx, sy, cz)) { - var mx = Math.floor(PJ.x), my = Math.floor(PJ.y), md = PJ.d; - for (var b2 = 0; b2 < 12; b2++) { - var an = b2 * Math.PI / 6; - emit(f, mx + Math.round(Math.cos(an) * 2.2), my + Math.round(Math.sin(an) * 1.2), - G_PLUS, P.slate, 54, md); - } - emit(f, mx, my, G_O, P.amber, 120, md); - var sp = CC.reducedMotion ? 0.9 : V.t * 0.5 * (0.3 + 0.5 * W_WIND); - emit(f, mx + Math.round(Math.cos(sp) * 2.2), my + Math.round(Math.sin(sp) * 1.2), - G_STAR, P.amber, 128, md); - } - } else { - - column(f, cx, cz, sy, sy + 1.2, G_CARET, P.white, 84, 0); - if (project(cx, sy + 1.5, cz)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_PLUS, P.amber, 148, PJ.d); - } - } - } - } + var lum = (104 + 22 * dF) * (1 - u) * (1 - u * 0.5); + if (lum < 6) continue; + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), u < 0.35 ? G_HASH : (u < 0.7 ? G_COLON : G_DOT), + dF > 0.5 ? P.stone : P.slate, lum, PJ.d); } + } - function emit2smoke(f, cx, cz, y0, rec) { - var lean = 1.5 * W_WIND; - var tt = CC.reducedMotion ? 4.0 : V.t; - var sway = vnoise(tt * 0.33 + rec.seed * 7, 0x2A) - 0.5; - var N = 16; - for (var i = 0; i < N; i++) { - var u = i / (N - 1); - var yy = y0 + 0.15 + u * 3.8; + function nearIdx(axis) { + return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)); + } + function eachStreet(f, fn) { + var i; + for (i = -1; i <= 1; i++) fn(f, 0, nearIdx(0) + i); + for (i = -1; i <= 1; i++) fn(f, 1, nearIdx(1) + i); + } - var dx = (lean * u * u + sway * 0.9 * u) * 1.6; - if (!project(cx + dx, yy, cz + dx * 0.35)) continue; + function mk(name, layer, fn) { + return { + name: name, layer: layer, world: 'west', + init: function (city) { boot(city); }, + draw: function (f, cam, t) { + if (!CITY) return; + view(f, cam, t === undefined ? (cam.t || 0) : t); + fn(f); + } + }; + } - var lum = 104 * (1 - u) * (1 - u * 0.5); - if (lum < 6) continue; - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), u < 0.35 ? G_HASH : (u < 0.7 ? G_COLON : G_DOT), - P.slate, lum, PJ.d); - } - } - - function nearIdx(axis) { - return Math.round((axis ? V.oz : V.ox) / (axis ? CITY.CROSS : CITY.AVE)); - } - function eachStreet(f, fn) { - var i; - for (i = -1; i <= 1; i++) fn(f, 0, nearIdx(0) + i); - for (i = -1; i <= 1; i++) fn(f, 1, nearIdx(1) + i); - } - - function mk(name, layer, fn) { - return { - name: name, layer: layer, world: 'west', - 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('west-props', 17, function (f) { eachStreet(f, drawStreetProps); })); - CC.ELEMENTS.push(mk('west-veranda', 18, function (f) { eachStreet(f, drawVeranda); })); - CC.ELEMENTS.push(mk('west-crowns', 21, drawCrowns)); + CC.ELEMENTS.push(mk('west-props', 17, function (f) { eachStreet(f, drawStreetProps); })); + CC.ELEMENTS.push(mk('west-veranda', 18, function (f) { eachStreet(f, drawVeranda); })); + CC.ELEMENTS.push(mk('west-crowns', 21, drawCrowns)); })(CC); /* src/render_canvas.js */ (function (CC) { - 'use strict'; + 'use strict'; - var PALETTE = CC.PALETTE, GLYPHS = CC.GLYPHS; - var NG = GLYPHS.length, NP = PALETTE.length; + var PALETTE = CC.PALETTE, GLYPHS = CC.GLYPHS; + var NG = GLYPHS.length, NP = PALETTE.length; - var FAMILY = '"Liberation Mono","DejaVu Sans Mono","Menlo","Consolas","Courier New",monospace'; + var FAMILY = '"Liberation Mono","DejaVu Sans Mono","Menlo","Consolas","Courier New",monospace'; - var LUM_FLOOR = 4; + var LUM_FLOOR = 4; - var canvas = null, ctx = null; - var scene = null, sctx = null; - var b2 = null, b4 = null, b8 = null; - var atlas = null, actx = null; + var canvas = null, ctx = null; + var scene = null, sctx = null; + var b2 = null, b4 = null, b8 = null; + var atlas = null, actx = null; - var cols = 0, rows = 0, dw = 0, dh = 0, W = 0, H = 0, dpr = 1; - var quality = 2; + var cols = 0, rows = 0, dw = 0, dh = 0, W = 0, H = 0, dpr = 1; + var quality = 2; - var rTight = 1, rWide = 1, rMid = 1; - var advance = 0.6; + var rTight = 1, rWide = 1, rMid = 1; + var advance = 0.6; - var HAS_FILTER = false; - function probeFilter() { - try { - var c = document.createElement('canvas').getContext('2d'); - c.filter = 'blur(2px)'; - HAS_FILTER = c.filter !== 'none' && c.filter !== '' && c.filter !== undefined; - } catch (e) { HAS_FILTER = false; } + var HAS_FILTER = false; + function probeFilter() { + try { + var c = document.createElement('canvas').getContext('2d'); + c.filter = 'blur(2px)'; + HAS_FILTER = c.filter !== 'none' && c.filter !== '' && c.filter !== undefined; + } catch (e) { HAS_FILTER = false; } + } + + function mkCanvas(w, h) { + var c = document.createElement('canvas'); + c.width = w < 1 ? 1 : w; c.height = h < 1 ? 1 : h; + return c; + } + + function buildAtlas() { + atlas = mkCanvas(NG * dw, NP * dh); + actx = atlas.getContext('2d'); + + actx.font = 'bold 100px ' + FAMILY; + advance = actx.measureText('M').width / 100 || 0.6; + + var fontPx = dw / advance; + if (fontPx > dh * 0.98) fontPx = dh * 0.98; + actx.font = 'bold ' + fontPx.toFixed(2) + 'px ' + FAMILY; + actx.textAlign = 'center'; + actx.textBaseline = 'alphabetic'; + + var m = actx.measureText('Xg'); + var asc = m.actualBoundingBoxAscent || dh * 0.72; + var desc = m.actualBoundingBoxDescent || dh * 0.20; + var base = Math.round((dh - asc - desc) * 0.5 + asc); + if (base > dh - 1) base = dh - 1; + if (base < 1) base = 1; + + var cx = dw * 0.5; + for (var p = 0; p < NP; p++) { + var rgb = PALETTE[p]; + actx.fillStyle = 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')'; + var y = p * dh + base; + for (var gI = 1; gI < NG; gI++) + actx.fillText(GLYPHS[gI], gI * dw + cx, y); } + } - function mkCanvas(w, h) { - var c = document.createElement('canvas'); - c.width = w < 1 ? 1 : w; c.height = h < 1 ? 1 : h; - return c; + function setGrid(nCols, nRows, cellW, cellH, devicePR) { + + var w = cellW | 0, h = cellH | 0; + var reAtlas = (w !== dw || h !== dh); + cols = nCols | 0; rows = nRows | 0; + dw = w; dh = h; dpr = devicePR || 1; + W = cols * dw; H = rows * dh; + + canvas.width = W; canvas.height = H; + canvas.style.width = (W / dpr) + 'px'; + canvas.style.height = (H / dpr) + 'px'; + + scene = mkCanvas(W, H); sctx = scene.getContext('2d', { alpha: false }); + + b2 = mkCanvas(W >> 1, H >> 1); + b4 = mkCanvas(W >> 2, H >> 2); + b8 = mkCanvas(W >> 3, H >> 3); + + rTight = Math.max(0.6, dh * 0.05); + rWide = Math.max(0.8, dh * 0.045); + rMid = Math.max(0.7, dh * 0.06); + + if (reAtlas || !atlas) buildAtlas(); + } + + function init(el) { + canvas = el; + ctx = canvas.getContext('2d', { alpha: false }); + probeFilter(); + return CC.Canvas; + } + + function setQuality(q) { quality = q < 0 ? 0 : (q > 2 ? 2 : q | 0); } + + function glyphPass(f) { + var c = sctx; + c.globalCompositeOperation = 'source-over'; + c.fillStyle = '#000'; + c.fillRect(0, 0, W, H); + + var ch = f.ch, cl = f.col, lu = f.lum; + var n = cols < f.cols ? cols : f.cols; + var r = rows < f.rows ? rows : f.rows; + var curA = -1, fc = f.cols; + + for (var y = 0; y < r; y++) { + var row = y * fc, py = y * dh; + for (var x = 0; x < n; x++) { + var i = row + x, gI = ch[i]; + if (gI === 0) continue; + var L = lu[i]; + if (L < LUM_FLOOR) continue; + var a = L * (1 / 255); + + if (a !== curA) { c.globalAlpha = a; curA = a; } + c.drawImage(atlas, gI * dw, cl[i] * dh, dw, dh, x * dw, py, dw, dh); + } } + c.globalAlpha = 1; + } - function buildAtlas() { - atlas = mkCanvas(NG * dw, NP * dh); - actx = atlas.getContext('2d'); + function tap(dst, src, blurPx) { + var c = dst.getContext('2d'); + c.imageSmoothingEnabled = true; + c.imageSmoothingQuality = 'high'; + c.globalAlpha = 1; + c.globalCompositeOperation = 'copy'; + if (HAS_FILTER && blurPx > 0) c.filter = 'blur(' + blurPx + 'px)'; + c.drawImage(src, 0, 0, dst.width, dst.height); + if (HAS_FILTER) c.filter = 'none'; + c.globalCompositeOperation = 'source-over'; + return dst; + } - actx.font = 'bold 100px ' + FAMILY; - advance = actx.measureText('M').width / 100 || 0.6; + function composite() { + ctx.imageSmoothingEnabled = true; + ctx.imageSmoothingQuality = 'high'; + ctx.globalAlpha = 1; + ctx.globalCompositeOperation = 'copy'; + ctx.drawImage(scene, 0, 0); + if (quality <= 0) { ctx.globalCompositeOperation = 'source-over'; return; } - var fontPx = dw / advance; - if (fontPx > dh * 0.98) fontPx = dh * 0.98; - actx.font = 'bold ' + fontPx.toFixed(2) + 'px ' + FAMILY; - actx.textAlign = 'center'; - actx.textBaseline = 'alphabetic'; + ctx.globalCompositeOperation = 'lighter'; + if (quality >= 2) { + tap(b2, scene, rTight); + ctx.globalAlpha = 0.55; + ctx.drawImage(b2, 0, 0, W, H); + tap(b4, b2, 0); + tap(b8, b4, rWide); - var m = actx.measureText('Xg'); - var asc = m.actualBoundingBoxAscent || dh * 0.72; - var desc = m.actualBoundingBoxDescent || dh * 0.20; - var base = Math.round((dh - asc - desc) * 0.5 + asc); - if (base > dh - 1) base = dh - 1; - if (base < 1) base = 1; + ctx.globalAlpha = 0.85; + ctx.drawImage(b8, 0, 0, W, H); + } else { - var cx = dw * 0.5; - for (var p = 0; p < NP; p++) { - var rgb = PALETTE[p]; - actx.fillStyle = 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')'; - var y = p * dh + base; - for (var gI = 1; gI < NG; gI++) - actx.fillText(GLYPHS[gI], gI * dw + cx, y); - } + tap(b4, scene, rMid); + ctx.globalAlpha = 0.95; + ctx.drawImage(b4, 0, 0, W, H); } + ctx.globalAlpha = 1; + ctx.globalCompositeOperation = 'source-over'; + } - function setGrid(nCols, nRows, cellW, cellH, devicePR) { + function draw(f) { + if (!ctx || !atlas) return; + glyphPass(f); + composite(); + } - var w = cellW | 0, h = cellH | 0; - var reAtlas = (w !== dw || h !== dh); - cols = nCols | 0; rows = nRows | 0; - dw = w; dh = h; dpr = devicePR || 1; - W = cols * dw; H = rows * dh; - - canvas.width = W; canvas.height = H; - canvas.style.width = (W / dpr) + 'px'; - canvas.style.height = (H / dpr) + 'px'; - - scene = mkCanvas(W, H); sctx = scene.getContext('2d', { alpha: false }); - - b2 = mkCanvas(W >> 1, H >> 1); - b4 = mkCanvas(W >> 2, H >> 2); - b8 = mkCanvas(W >> 3, H >> 3); - - rTight = Math.max(0.6, dh * 0.05); - rWide = Math.max(0.8, dh * 0.045); - rMid = Math.max(0.7, dh * 0.06); - - if (reAtlas || !atlas) buildAtlas(); - } - - function init(el) { - canvas = el; - ctx = canvas.getContext('2d', { alpha: false }); - probeFilter(); - return CC.Canvas; - } - - function setQuality(q) { quality = q < 0 ? 0 : (q > 2 ? 2 : q | 0); } - - function glyphPass(f) { - var c = sctx; - c.globalCompositeOperation = 'source-over'; - c.fillStyle = '#000'; - c.fillRect(0, 0, W, H); - - var ch = f.ch, cl = f.col, lu = f.lum; - var n = cols < f.cols ? cols : f.cols; - var r = rows < f.rows ? rows : f.rows; - var curA = -1, fc = f.cols; - - for (var y = 0; y < r; y++) { - var row = y * fc, py = y * dh; - for (var x = 0; x < n; x++) { - var i = row + x, gI = ch[i]; - if (gI === 0) continue; - var L = lu[i]; - if (L < LUM_FLOOR) continue; - var a = L * (1 / 255); - - if (a !== curA) { c.globalAlpha = a; curA = a; } - c.drawImage(atlas, gI * dw, cl[i] * dh, dw, dh, x * dw, py, dw, dh); - } - } - c.globalAlpha = 1; - } - - function tap(dst, src, blurPx) { - var c = dst.getContext('2d'); - c.imageSmoothingEnabled = true; - c.imageSmoothingQuality = 'high'; - c.globalAlpha = 1; - c.globalCompositeOperation = 'copy'; - if (HAS_FILTER && blurPx > 0) c.filter = 'blur(' + blurPx + 'px)'; - c.drawImage(src, 0, 0, dst.width, dst.height); - if (HAS_FILTER) c.filter = 'none'; - c.globalCompositeOperation = 'source-over'; - return dst; - } - - function composite() { - ctx.imageSmoothingEnabled = true; - ctx.imageSmoothingQuality = 'high'; - ctx.globalAlpha = 1; - ctx.globalCompositeOperation = 'copy'; - ctx.drawImage(scene, 0, 0); - if (quality <= 0) { ctx.globalCompositeOperation = 'source-over'; return; } - - ctx.globalCompositeOperation = 'lighter'; - if (quality >= 2) { - tap(b2, scene, rTight); - ctx.globalAlpha = 0.55; - ctx.drawImage(b2, 0, 0, W, H); - tap(b4, b2, 0); - tap(b8, b4, rWide); - - ctx.globalAlpha = 0.85; - ctx.drawImage(b8, 0, 0, W, H); - } else { - - tap(b4, scene, rMid); - ctx.globalAlpha = 0.95; - ctx.drawImage(b4, 0, 0, W, H); - } - ctx.globalAlpha = 1; - ctx.globalCompositeOperation = 'source-over'; - } - - function draw(f) { - if (!ctx || !atlas) return; - glyphPass(f); - composite(); - } - - CC.Canvas = { - init: init, setGrid: setGrid, setQuality: setQuality, draw: draw, - get cellAspect() { return dh ? dw / dh : 0.5625; }, - get quality() { return quality; }, - get hasFilter() { return HAS_FILTER; }, - FAMILY: FAMILY, LUM_FLOOR: LUM_FLOOR - }; + CC.Canvas = { + init: init, setGrid: setGrid, setQuality: setQuality, draw: draw, + get cellAspect() { return dh ? dw / dh : 0.5625; }, + get quality() { return quality; }, + get hasFilter() { return HAS_FILTER; }, + FAMILY: FAMILY, LUM_FLOOR: LUM_FLOOR + }; })(CC); /* src/main.js */ (function (CC) { - 'use strict'; + 'use strict'; - var HAS_DOM = typeof document !== 'undefined' && typeof window !== 'undefined' && - !!(document && document.createElement); + var HAS_DOM = typeof document !== 'undefined' && typeof window !== 'undefined' && + !!(document && document.createElement); - var STEP = 1 / 60; - var ASPECT = 0.5625; - var MAXC = 260, MINC = 48, MINR = 22; + var STEP = 1 / 60; + var ASPECT = 0.5625; + var MAXC = 260, MINC = 48, MINR = 22; - var canvas = null, frame = null, city = null, seed = 0; - var cam = { x: 0, z: 0, yaw: 0, eyeY: 1.7, fov: 1.25, horizon: 0, t: 0, cellAspect: ASPECT }; - var els = [], cols = 0, rows = 0; - var simT = 0, acc = 0, last = 0, running = false; - var zoom = 1; + var canvas = null, frame = null, city = null, seed = 0; + var cam = { x: 0, z: 0, yaw: 0, eyeY: 1.7, fov: 1.25, horizon: 0, t: 0, cellAspect: ASPECT }; + var els = [], cols = 0, rows = 0; + var simT = 0, acc = 0, last = 0, running = false; + var zoom = 1; - function worldFromHash() { - var h = (window.location.hash || '').replace(/^#/, '').trim(); - var i = h.indexOf('/'); + function worldFromHash() { + var h = (window.location.hash || '').replace(/^#/, '').trim(); + var i = h.indexOf('/'); - if (i < 0) return CC.World ? CC.World.DEFAULT : 'cyber'; - var w = CC.World && CC.World.at(h.slice(0, i)); - return w ? w.id : null; + if (i < 0) return CC.World ? CC.World.DEFAULT : 'cyber'; + var w = CC.World && CC.World.at(h.slice(0, i)); + return w ? w.id : null; + } + + function seedFromHash() { + var h = (window.location.hash || '').replace(/^#/, '').trim(); + var sl = h.indexOf('/'); + if (sl >= 0) h = h.slice(sl + 1); + h = h.replace(/^seed=/, '').trim(); + if (!h) return null; + + if (/^-?\d+$/.test(h)) { + var v = parseInt(h, 10); + if (v >= -2147483648 && v <= 4294967295) return v >>> 0; + } + var s = 2166136261; + for (var i = 0; i < h.length; i++) { s ^= h.charCodeAt(i); s = Math.imul(s, 16777619); } + return s >>> 0; + } + + function fragment(w, sd) { + return '#' + (w && w !== CC.World.DEFAULT ? w + '/' : '') + (sd >>> 0); + } + function writeFragment() { + if (window.history && history.replaceState) + history.replaceState(null, '', fragment(CC.World ? CC.World.id : 'cyber', seed)); + } + + function cellCSS(vw) { + var w = vw < 560 ? 6.4 : vw < 1000 ? 7.6 : vw < 1700 ? 8.8 : 9.6; + return w * zoom; + } + + function layout() { + var vw = Math.max(window.innerWidth || 320, 200); + var vh = Math.max(window.innerHeight || 240, 160); + + var dpr = Math.min(window.devicePixelRatio || 1, 2); + + var dw = Math.max(4, Math.round(cellCSS(vw) * dpr)); + var dh = Math.max(7, Math.round(dw / ASPECT)); + + var c = Math.ceil(vw * dpr / dw); + if (c > MAXC) { + c = MAXC; + dw = Math.ceil(vw * dpr / c); + dh = Math.max(7, Math.round(dw / ASPECT)); + + c = Math.ceil(vw * dpr / dw); + } + if (c < MINC) c = MINC; + var r = Math.max(MINR, Math.ceil(vh * dpr / dh)); + + cols = c; rows = r; + CC.Canvas.setGrid(cols, rows, dw, dh, dpr); + frame = CC.makeFrame(cols, rows); + + cam.horizonBase = rows * 0.56; + cam.horizon = cam.horizonBase; + cam.rows = rows; + cam.cellAspect = CC.Canvas.cellAspect; + } + + function build(newSeed) { + seed = newSeed >>> 0; + city = CC.City ? CC.City.make(seed) : null; + cam.x = city && city.startX !== undefined ? city.startX : 0.5; + cam.z = city && city.startZ !== undefined ? city.startZ : 0.5; + + if (CC.Daylight) CC.Daylight.init(city); + if (CC.Weather) CC.Weather.init(city, CC.mulberry(seed ^ 0x5bf03635)); + if (CC.Control) CC.Control.reset(); + var rng = CC.mulberry(seed ^ 0x9e3779b9); + + var live = CC.World ? CC.World.id : 'cyber'; + var seq = [], q; + for (q = 0; q < CC.ELEMENTS.length; q++) + if (CC.inWorld(CC.ELEMENTS[q], live)) seq.push(CC.ELEMENTS[q]); + var rank = []; + for (q = 0; q < seq.length; q++) rank.push(q); + rank.sort(function (a, b) { return ((seq[a].layer | 0) - (seq[b].layer | 0)) || (a - b); }); + els = []; + for (q = 0; q < rank.length; q++) els.push(seq[rank[q]]); + for (var i = 0; i < els.length; i++) + if (els[i].init) els[i].init(city, rng, { cols: cols, rows: rows }); + simT = 0; acc = 0; + } + + function step(dt, t) { + + if (CC.Control && CC.Control.paused) { CC.Control.update(dt, t, cam, city); return; } + + if (CC.Daylight) CC.Daylight.update(dt, t); + if (CC.Weather) CC.Weather.update(dt, t); + + if (CC.Control) CC.Control.update(dt, t, cam, city); + else if (city && city.camera) city.camera(cam, city, t); + if (CC.Control && CC.Control.tickHint) CC.Control.tickHint(dt); + for (var i = 0; i < els.length; i++) if (els[i].update) els[i].update(dt, t, cam); + } + + function render(t) { + cam.t = t; + CC.clearFrame(frame); + if (CC.Cast) CC.Cast.render(frame, cam, city); + for (var i = 0; i < els.length; i++) if (els[i].draw) els[i].draw(frame, cam, t); + if (CC.Compose && CC.Compose.post) CC.Compose.post(frame, cam, t); + CC.Canvas.draw(frame); + } + + var ema = 16, badSince = 0, goodSince = 0; + function adapt(ms, now) { + ema += (ms - ema) * 0.08; + if (ema > 26) { + goodSince = 0; + if (!badSince) badSince = now; + else if (now - badSince > 1200) { + badSince = now; + if (CC.Canvas.quality > 1) CC.Canvas.setQuality(1); + else if (zoom < 1.3) { zoom = 1.3; layout(); } + } + } else if (ema < 11) { + badSince = 0; + if (!goodSince) goodSince = now; + else if (now - goodSince > 6000) { + goodSince = now; + if (zoom > 1) { zoom = 1; layout(); } + else if (CC.Canvas.quality < 2) CC.Canvas.setQuality(2); + } + } else { badSince = 0; goodSince = 0; } + } + + function nowMs() { return window.performance ? performance.now() : Date.now(); } + + function tick(now) { + if (!running) return; + window.requestAnimationFrame(tick); + + var t0 = nowMs(); + var dt = (now - last) / 1000; last = now; + if (!(dt > 0)) dt = STEP; + + if (dt > 0.25) dt = 0.25; + + if (CC.reducedMotion) dt *= 0.35; + + acc += dt; + var n = 0; + + var frozen = !!(CC.Control && CC.Control.paused); + while (acc >= STEP && n < 5) { if (!frozen) simT += STEP; step(STEP, simT); acc -= STEP; n++; } + if (n === 5) acc = 0; + + render(simT); + adapt(nowMs() - t0, now); + } + + var rzT = 0; + function onResize() { + window.clearTimeout(rzT); + + rzT = window.setTimeout(function () { layout(); }, 180); + } + + function goFullscreen() { + if (document.fullscreenElement || document.webkitFullscreenElement) return; + var e = document.documentElement; + var fn = e.requestFullscreen || e.webkitRequestFullscreen; + if (!fn) return; + + try { + var p = fn.call(e); + if (p && p.catch) p.catch(function () { }); + } catch (err) { } + } + + function boot() { + canvas = document.getElementById('cc'); + if (!canvas) { + canvas = document.createElement('canvas'); + canvas.id = 'cc'; + document.body.appendChild(canvas); } - function seedFromHash() { - var h = (window.location.hash || '').replace(/^#/, '').trim(); - var sl = h.indexOf('/'); - if (sl >= 0) h = h.slice(sl + 1); - h = h.replace(/^seed=/, '').trim(); - if (!h) return null; + var mq = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)'); + CC.reducedMotion = !!(mq && mq.matches); + if (mq && mq.addEventListener) + mq.addEventListener('change', function (e) { CC.reducedMotion = !!e.matches; }); - if (/^-?\d+$/.test(h)) { - var v = parseInt(h, 10); - if (v >= -2147483648 && v <= 4294967295) return v >>> 0; - } - var s = 2166136261; - for (var i = 0; i < h.length; i++) { s ^= h.charCodeAt(i); s = Math.imul(s, 16777619); } - return s >>> 0; + CC.Canvas.init(canvas); + layout(); + + var w0 = worldFromHash(); + if (w0 && CC.World) CC.World.force(w0); + var s = seedFromHash(); + + if (s === null) { + s = (Math.random() * 4294967296) >>> 0; + + seed = s; + writeFragment(); + } + build(s); + + window.addEventListener('resize', onResize, { passive: true }); + window.addEventListener('orientationchange', onResize, { passive: true }); + document.addEventListener('fullscreenchange', onResize); + + document.addEventListener('webkitfullscreenchange', onResize); + window.addEventListener('hashchange', function () { + + var nw = worldFromHash(), ns = seedFromHash(); + var moved = 0; + if (nw && CC.World && nw !== CC.World.id) { CC.World.force(nw); moved = 1; } + if (ns !== null && ns !== seed) moved = 1; + if (moved) build(ns === null ? seed : ns); + }); + window.addEventListener('pointerdown', goFullscreen, { passive: true }); + window.addEventListener('keydown', function (e) { + if (!e.metaKey && !e.ctrlKey && !e.altKey) goFullscreen(); + }); + + if (CC.Control && CC.Control.attach) { + CC.Control.attach(window, document, canvas, { + city: function () { return city; }, + now: function () { return simT; }, + fullscreen: goFullscreen, + reseed: function () { + var ns = (Math.random() * 4294967296) >>> 0; + seed = ns; + writeFragment(); + build(ns); + }, + + world: function (v) { + if (!CC.World || !CC.World.set(v)) return 0; + writeFragment(); + build(seed); + return 1; + }, + worldName: function () { return CC.World ? CC.World.name : ''; } + }); + + window.addEventListener('pointerdown', function () { + if (CC.Control.requestLook) CC.Control.requestLook(); + }, { passive: true }); } - function fragment(w, sd) { - return '#' + (w && w !== CC.World.DEFAULT ? w + '/' : '') + (sd >>> 0); - } - function writeFragment() { - if (window.history && history.replaceState) - history.replaceState(null, '', fragment(CC.World ? CC.World.id : 'cyber', seed)); - } + running = true; + last = nowMs(); + window.requestAnimationFrame(tick); + } - function cellCSS(vw) { - var w = vw < 560 ? 6.4 : vw < 1000 ? 7.6 : vw < 1700 ? 8.8 : 9.6; - return w * zoom; - } + if (HAS_DOM) { + if (document.readyState === 'loading') + document.addEventListener('DOMContentLoaded', boot); + else boot(); + } - function layout() { - var vw = Math.max(window.innerWidth || 320, 200); - var vh = Math.max(window.innerHeight || 240, 160); - - var dpr = Math.min(window.devicePixelRatio || 1, 2); - - var dw = Math.max(4, Math.round(cellCSS(vw) * dpr)); - var dh = Math.max(7, Math.round(dw / ASPECT)); - - var c = Math.ceil(vw * dpr / dw); - if (c > MAXC) { - c = MAXC; - dw = Math.ceil(vw * dpr / c); - dh = Math.max(7, Math.round(dw / ASPECT)); - - c = Math.ceil(vw * dpr / dw); - } - if (c < MINC) c = MINC; - var r = Math.max(MINR, Math.ceil(vh * dpr / dh)); - - cols = c; rows = r; - CC.Canvas.setGrid(cols, rows, dw, dh, dpr); - frame = CC.makeFrame(cols, rows); - - cam.horizonBase = rows * 0.56; - cam.horizon = cam.horizonBase; - cam.rows = rows; - cam.cellAspect = CC.Canvas.cellAspect; - } - - function build(newSeed) { - seed = newSeed >>> 0; - city = CC.City ? CC.City.make(seed) : null; - cam.x = city && city.startX !== undefined ? city.startX : 0.5; - cam.z = city && city.startZ !== undefined ? city.startZ : 0.5; - - if (CC.Daylight) CC.Daylight.init(city); - if (CC.Weather) CC.Weather.init(city, CC.mulberry(seed ^ 0x5bf03635)); - if (CC.Control) CC.Control.reset(); - var rng = CC.mulberry(seed ^ 0x9e3779b9); - - var live = CC.World ? CC.World.id : 'cyber'; - var seq = [], q; - for (q = 0; q < CC.ELEMENTS.length; q++) - if (CC.inWorld(CC.ELEMENTS[q], live)) seq.push(CC.ELEMENTS[q]); - var rank = []; - for (q = 0; q < seq.length; q++) rank.push(q); - rank.sort(function (a, b) { return ((seq[a].layer | 0) - (seq[b].layer | 0)) || (a - b); }); - els = []; - for (q = 0; q < rank.length; q++) els.push(seq[rank[q]]); - for (var i = 0; i < els.length; i++) - if (els[i].init) els[i].init(city, rng, { cols: cols, rows: rows }); - simT = 0; acc = 0; - } - - function step(dt, t) { - - if (CC.Control && CC.Control.paused) { CC.Control.update(dt, t, cam, city); return; } - - if (CC.Daylight) CC.Daylight.update(dt, t); - if (CC.Weather) CC.Weather.update(dt, t); - - if (CC.Control) CC.Control.update(dt, t, cam, city); - else if (city && city.camera) city.camera(cam, city, t); - if (CC.Control && CC.Control.tickHint) CC.Control.tickHint(dt); - for (var i = 0; i < els.length; i++) if (els[i].update) els[i].update(dt, t, cam); - } - - function render(t) { - cam.t = t; - CC.clearFrame(frame); - if (CC.Cast) CC.Cast.render(frame, cam, city); - for (var i = 0; i < els.length; i++) if (els[i].draw) els[i].draw(frame, cam, t); - if (CC.Compose && CC.Compose.post) CC.Compose.post(frame, cam, t); - CC.Canvas.draw(frame); - } - - var ema = 16, badSince = 0, goodSince = 0; - function adapt(ms, now) { - ema += (ms - ema) * 0.08; - if (ema > 26) { - goodSince = 0; - if (!badSince) badSince = now; - else if (now - badSince > 1200) { - badSince = now; - if (CC.Canvas.quality > 1) CC.Canvas.setQuality(1); - else if (zoom < 1.3) { zoom = 1.3; layout(); } - } - } else if (ema < 11) { - badSince = 0; - if (!goodSince) goodSince = now; - else if (now - goodSince > 6000) { - goodSince = now; - if (zoom > 1) { zoom = 1; layout(); } - else if (CC.Canvas.quality < 2) CC.Canvas.setQuality(2); - } - } else { badSince = 0; goodSince = 0; } - } - - function nowMs() { return window.performance ? performance.now() : Date.now(); } - - function tick(now) { - if (!running) return; - window.requestAnimationFrame(tick); - - var t0 = nowMs(); - var dt = (now - last) / 1000; last = now; - if (!(dt > 0)) dt = STEP; - - if (dt > 0.25) dt = 0.25; - - if (CC.reducedMotion) dt *= 0.35; - - acc += dt; - var n = 0; - - var frozen = !!(CC.Control && CC.Control.paused); - while (acc >= STEP && n < 5) { if (!frozen) simT += STEP; step(STEP, simT); acc -= STEP; n++; } - if (n === 5) acc = 0; - - render(simT); - adapt(nowMs() - t0, now); - } - - var rzT = 0; - function onResize() { - window.clearTimeout(rzT); - - rzT = window.setTimeout(function () { layout(); }, 180); - } - - function goFullscreen() { - if (document.fullscreenElement || document.webkitFullscreenElement) return; - var e = document.documentElement; - var fn = e.requestFullscreen || e.webkitRequestFullscreen; - if (!fn) return; - - try { - var p = fn.call(e); - if (p && p.catch) p.catch(function () { }); - } catch (err) { } - } - - function boot() { - canvas = document.getElementById('cc'); - if (!canvas) { - canvas = document.createElement('canvas'); - canvas.id = 'cc'; - document.body.appendChild(canvas); - } - - var mq = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)'); - CC.reducedMotion = !!(mq && mq.matches); - if (mq && mq.addEventListener) - mq.addEventListener('change', function (e) { CC.reducedMotion = !!e.matches; }); - - CC.Canvas.init(canvas); - layout(); - - var w0 = worldFromHash(); - if (w0 && CC.World) CC.World.force(w0); - var s = seedFromHash(); - - if (s === null) { - s = (Math.random() * 4294967296) >>> 0; - - seed = s; - writeFragment(); - } - build(s); - - window.addEventListener('resize', onResize, { passive: true }); - window.addEventListener('orientationchange', onResize, { passive: true }); - document.addEventListener('fullscreenchange', onResize); - - document.addEventListener('webkitfullscreenchange', onResize); - window.addEventListener('hashchange', function () { - - var nw = worldFromHash(), ns = seedFromHash(); - var moved = 0; - if (nw && CC.World && nw !== CC.World.id) { CC.World.force(nw); moved = 1; } - if (ns !== null && ns !== seed) moved = 1; - if (moved) build(ns === null ? seed : ns); - }); - window.addEventListener('pointerdown', goFullscreen, { passive: true }); - window.addEventListener('keydown', function (e) { - if (!e.metaKey && !e.ctrlKey && !e.altKey) goFullscreen(); - }); - - if (CC.Control && CC.Control.attach) { - CC.Control.attach(window, document, canvas, { - city: function () { return city; }, - now: function () { return simT; }, - fullscreen: goFullscreen, - reseed: function () { - var ns = (Math.random() * 4294967296) >>> 0; - seed = ns; - writeFragment(); - build(ns); - }, - - world: function (v) { - if (!CC.World || !CC.World.set(v)) return 0; - writeFragment(); - build(seed); - return 1; - }, - worldName: function () { return CC.World ? CC.World.name : ''; } - }); - - window.addEventListener('pointerdown', function () { - if (CC.Control.requestLook) CC.Control.requestLook(); - }, { passive: true }); - } - - running = true; - last = nowMs(); - window.requestAnimationFrame(tick); - } - - if (HAS_DOM) { - if (document.readyState === 'loading') - document.addEventListener('DOMContentLoaded', boot); - else boot(); - } - - var Main = { boot: boot, layout: layout, build: build, - get seed() { return seed; }, get cols() { return cols; }, get rows() { return rows; }, - get cam() { return cam; } }; - CC.Main = Main; + var Main = { boot: boot, layout: layout, build: build, + get seed() { return seed; }, get cols() { return cols; }, get rows() { return rows; }, + get cam() { return cam; } }; + CC.Main = Main; })(CC); diff --git a/src/city.js b/src/city.js index 9286c88..34ab026 100644 --- a/src/city.js +++ b/src/city.js @@ -79,14 +79,24 @@ * writing long before it is legible as writing, and those three carry that shape. */ var SIGN_CH_WEST = ['M', 'W', 'N', 'H', 'X', 'A', 'K']; - /* ---- the Moon's two surfaces, and there are only two ------------------------------------------ - * A world with no buildings needs no styles: index 7 is regolith and index 8 is rock, and the - * triple is read by surf_moon.js as [sunlit, shadowed, grain]. The indices continue the west - * table's numbering rather than restarting, because city.js's `style` is one integer shared by - * every world and a reader who sees 8 should be able to find it in one table. */ + /* ---- the Moon's three surfaces, and there are only three -------------------------------------- + * A world with no buildings needs no styles: index 7 is regolith, index 8 is rock and index 9 is + * the ground itself, and the triple is read by surf_moon.js as [sunlit, shadowed, grain]. The + * indices continue the west table's numbering rather than restarting, because city.js's `style` + * is one integer shared by every world and a reader who sees 8 should be able to find it in one + * table. + * + * 9 IS NOT AN OBJECT AND THAT IS THE WHOLE POINT OF IT. The swell (see swellAt) gives an empty + * lot a height, and a lot with a height is a lot the caster paints a facade on — so without a + * marker the painter cannot tell a two-metre rise in the plain from a two-metre rock. The + * distinction is carried as a style index rather than as a new record field for the same reason + * the frontier's butte is: `style` is one of the six things raycast.js already copies into the + * scratch it hands the texture layer, and a new field would need plumbing in a file this lane + * does not own. Its glyphs are the softest in the table — a mound of powder has no edge. */ var STYLE_CH_MOON = [ ['%', '.', ':'], // 7 regolith — powder, and mostly not painted at all - ['8', ':', '%'] // 8 rock — breccia and basalt, blocky and hard-edged + ['8', ':', '%'], // 8 rock — breccia and basalt, blocky and hard-edged + ['.', ',', "'"] // 9 swell — open ground that happens to be higher than the ground beside it ]; // Districts are the colour masses. Weights keep the two pillars dominant and violet rare, @@ -130,24 +140,87 @@ * share by exactly nothing and only the total energy changes. Anything else here — a bit * more on the pillars, a bit less on concrete — would be re-tasting a split that was * measured over 480 frames, and it is not what was wrong with the picture. */ + /* ---- NINE QUARTERS, AND WHAT THE THREE NEW ONES ARE FOR --------------------------------- + * The table was six rows drawn from a twelve-swatch palette, and four of those swatches are + * signage or specular and cannot lead a wall — so the districts were really amber, azure, + * slate, ember and spring, and two of those five are the pillars. A city with three + * non-pillar quarters cannot be walked through for ten minutes without repeating itself, + * which is what "more colours" is asking about. + * + * The eight new swatches buy three quarters that were unspellable before, and each one is a + * MATERIAL rather than a tint: `gilt` is jade tilework under brass, `market` is moss render + * over timber hoardings, `finance` is indigo glass. They are 18% of the ground between them + * — deliberately narrow, because the pillars are the look. + * + * THE PILLAR ARITHMETIC, which is the constraint this table exists to satisfy. Ground share + * that leads on a pillar: sodium 0.22 + screen 0.21 + arcade 0.06 = 0.49, against 0.55 + * before. The six points come back through `mix`: every one of the six accent quarters + * threads a pillar at (1 - mixP), so the pillar-hued share of LOTS is + * 0.49 + 0.17*0.20 + 0.09*0.45 + 0.07*0.50 + 0.07*0.45 + 0.06*0.48 + 0.05*0.38 = 0.68, + * against 0.66 before — the OLD table's concrete threaded white, which is not a pillar, and + * this one threads amber. So the pillars come out two points AHEAD while the frame gains + * three quarters, and the ground those quarters take is taken off slate and off the two + * pillars' own surplus. It is also energy the print barely notices: jade, moss and indigo + * carry day gains of 0.58, 0.74 and 0.62, the dull half of the day ladder. + * + * `stone` ON CONCRETE IS A DELIBERATE NIGHT CHANGE and the only one in this table. slate is + * blue by construction (core.js says so at length) and it was carrying the daylight concrete + * of the whole city, which is why a noon frame had no grey in it. stone's night ceiling is + * 122 against slate's 114, so the concrete quarter prints eight points brighter after dark; + * that is the price of it printing as CONCRETE at noon (day ceiling 145 against 114) and it + * is worth paying. Nothing else here moves the night frame by more than the ratio arithmetic + * above. + */ { name: 'sodium', hue: P.amber, mix: P.azure, mixP: 0.86, accent: P.warm, styles: [0, 3, 0], - hMin: 15, hMax: 34, lit: 0.32, signP: 0.34, landmark: 0.010, w: 0.25 }, + hMin: 15, hMax: 34, lit: 0.32, signP: 0.34, landmark: 0.010, w: 0.22 }, { name: 'screen', hue: P.azure, mix: P.amber, mixP: 0.86, accent: P.white, styles: [1, 4, 1], - hMin: 24, hMax: 56, lit: 0.27, signP: 0.16, landmark: 0.030, w: 0.24 }, - { name: 'concrete', hue: P.slate, mix: P.white, mixP: 0.80, accent: P.white, styles: [2, 5], - hMin: 16, hMax: 32, lit: 0.22, signP: 0.05, landmark: 0.006, w: 0.20 }, + hMin: 24, hMax: 56, lit: 0.27, signP: 0.16, landmark: 0.030, w: 0.21 }, + { name: 'concrete', hue: P.stone, mix: P.azure, mixP: 0.80, accent: P.white, styles: [2, 5], + hMin: 16, hMax: 32, lit: 0.22, signP: 0.05, landmark: 0.006, w: 0.17 }, // ember is the low industrial pocket — it exists to open the sky slot back up. { name: 'ember', hue: P.ember, mix: P.amber, mixP: 0.55, accent: P.red, styles: [5, 2], - hMin: 8, hMax: 19, lit: 0.22, signP: 0.13, landmark: 0.002, w: 0.11 }, + hMin: 8, hMax: 19, lit: 0.22, signP: 0.13, landmark: 0.002, w: 0.09 }, { name: 'spring', hue: P.spring, mix: P.azure, mixP: 0.50, accent: P.white, styles: [2, 0], - hMin: 15, hMax: 29, lit: 0.24, signP: 0.16, landmark: 0.006, w: 0.12 }, + hMin: 15, hMax: 29, lit: 0.24, signP: 0.16, landmark: 0.006, w: 0.07 }, // The entertainment strip. Its facades are ordinary azure/amber on purpose: violet is a // signage colour only, and a whole wall of it turns the frame into the cliche the // references deliberately avoid. // ...and the accent obeys that too: it used to be P.violet, which put 16-column violet // walls in the frame in direct contradiction of the comment directly above it. - { name: 'arcade', hue: P.azure, mix: P.amber, mixP: 0.55, accent: P.warm, styles: [1, 3], - hMin: 13, hMax: 27, lit: 0.30, signP: 0.60, landmark: 0.004, w: 0.06 } + /* ROSE ARRIVES HERE AND NOWHERE ELSE, as this one quarter's accent. It is never a `hue`, so + * it can never be a wall: `accent` reaches the print only through surfaces.js's window + * accent roll and through signHue below, both of which are a minority of a minority. On top + * of that the swatch defends itself — core.js gives rose the lowest gain in either ladder + * (0.20 night, 0.18 day) and its knee crushes every rose cell under lum 96 to black, so + * "small signage cells only" is arithmetic here rather than a note. Arcade is 6% of the + * ground, which is the narrowest row in the table. */ + { name: 'arcade', hue: P.azure, mix: P.amber, mixP: 0.55, accent: P.rose, styles: [1, 3], + hMin: 13, hMax: 27, lit: 0.30, signP: 0.60, landmark: 0.004, w: 0.06 }, + /* ---- gilt: jade tilework, brass frames --------------------------------------------------- + * The quarter with money in it and no screens. jade is the deep teal of glazed tile and + * oxidised copper and it is a SURFACE swatch — core.js blends it on the sun rather than on + * the sky, so it is the one of the three new hues that goes flat at dusk and comes back at + * noon. gold is the frame round every opening, and it is the brightest new swatch at night + * (ceiling 157) which is why it is an accent and not a hue: a whole wall of it would print + * as a second amber pillar. Amber threads it at 45%. */ + { name: 'gilt', hue: P.jade, mix: P.amber, mixP: 0.55, accent: P.gold, styles: [0, 2], + hMin: 14, hMax: 30, lit: 0.28, signP: 0.30, landmark: 0.008, w: 0.07 }, + /* ---- market: moss render over timber hoardings ------------------------------------------- + * Two storeys of low frontage, the dullest quarter in the city and the only place the eye + * gets a rest. moss is the weakest swatch in either ladder (night ceiling 94, under the + * 110-155 structure band on purpose — a hedge at night IS darker than the concrete beside + * it), so this row takes 6% of the ground for well under 6% of the energy. Its low hMax is + * the other half of the job: it opens the sky slot back up exactly as `ember` does. */ + { name: 'market', hue: P.moss, mix: P.amber, mixP: 0.52, accent: P.timber, styles: [5, 2], + hMin: 7, hMax: 16, lit: 0.20, signP: 0.28, landmark: 0.001, w: 0.06 }, + /* ---- finance: indigo glass --------------------------------------------------------------- + * The tallest row in the table and the darkest. indigo is night glass and shade with sky in + * it — day ceiling 104 against white's, which is what makes a curtain-wall tower read at + * noon as a dark slab against a bright sky instead of as a lit one. landmark 0.045 is the + * highest in the city: this is where the towers are. It is also the thinnest at 5%, because + * a dark quarter is the one thing that must not become the picture. */ + { name: 'finance', hue: P.indigo, mix: P.azure, mixP: 0.62, accent: P.white, styles: [1, 4], + hMin: 26, hMax: 60, lit: 0.24, signP: 0.06, landmark: 0.045, w: 0.05 } ]; /* ---- the frontier's five and a half ---------------------------------------------------------- @@ -170,26 +243,79 @@ * is what opens the town out into country every few blocks instead of tiling frontage to the * horizon. Its `hue` still matters — a butte is lit by the same low sun as everything else. */ + /* ---- MATERIALS, NOT COLOURS ------------------------------------------------------------------ + * This table used to hand the painter warm, slate, ember, white and spring, and the reason is + * that those were the only five swatches in a twelve-colour neon palette that a mud wall could + * plausibly borrow. It showed. surf_west's facade() collapses any hue it does not recognise as + * a surface onto amber, so a whole town of clapboard, adobe, fieldstone and lime render came + * out of the print as one amber building repeated to the horizon at dusk and as nothing at all + * at noon — which is exactly the complaint this pass answers. + * + * The palette now has the swatches the setting is actually made of, so every row below leads + * on the MATERIAL rather than on a tint, and a quarter is meant to be identifiable at noon by + * what it is built out of: + * timber weathered board going silver, and mud brick + * sand planed and painted board in sun, dirt, bone, sunlit adobe + * stone fieldstone, rubble wall, unlit rock + * white lime-washed plaster and render + * ember red rock and red-oxide paint + * moss canvas, sage, and the sage-green paint every second door out here wore + * + * `hue` is therefore a claim about SUBSTANCE and `style` is a claim about CONSTRUCTION, and + * the pair is the whole contract: style 0 with hue timber is unpainted clapboard, style 0 with + * hue sand is the same wall painted, style 4 with hue stone is a rubble bank and style 3 with + * hue timber is adobe. The painter never has to guess a material out of a colour again. + * + * TALL LOTS READ AS MASS BY DAY, and that was checked rather than hoped: a landmark (9-14 m) + * and a butte (9-32 m) both take D.hue, and every hue in this table except ember carries a day + * gain of 0.72-0.90 with a day ceiling of 120-190 — the top of the daylight ladder. There is + * no row here whose tall lots come out as a silhouette, which is what `slate` (day ceiling + * 114, and BLUE) did to two of the six quarters before. + * + * hMin/hMax, lit, signP, landmark, vacant and w are unchanged from the fit they were measured + * against; only the substance moves. The one exception is `ranch`, which was ember-hued + * board-and-batten with no material of its own and is now `stone`, the fieldstone quarter — + * the bank, the jail and the mill — because a stone quarter is the thing this table could not + * previously say at all, and the brief asks for it by name. Its butte rate rises 0.004 -> 0.006 + * because bedrock at the surface is what makes a quarter stone in the first place. + * + * `hue2` is gone from the adobe row. Nothing has ever read it. */ DIST_WEST = [ - { name: 'main', hue: P.warm, mix: P.amber, mixP: 0.72, accent: P.amber, styles: [0, 2, 0, 2], + /* Main street: planed board, painted, and the only quarter that could afford paint. sand is + * the paint gone chalky in the sun; white is the fresh half of it; timber is the raw board + * of the porch posts and the boardwalk, which is why it is the accent here. */ + { name: 'main', hue: P.sand, mix: P.white, mixP: 0.64, accent: P.timber, styles: [2, 0, 2, 0], hMin: 6.2, hMax: 10, lit: 0.20, signP: 0.66, landmark: 0.012, w: 0.21, vacant: 0.07, butte: 0 }, - { name: 'dust', hue: P.slate, mix: P.white, mixP: 0.74, accent: P.white, styles: [0, 1, 5], + /* The unpainted end of town — clapboard and board-and-batten left to weather. Bare pine goes + * silver-grey in a dry climate, which is exactly the timber-to-stone axis this row runs. */ + { name: 'boards', hue: P.timber, mix: P.stone, mixP: 0.70, accent: P.sand, styles: [0, 1, 1, 5], hMin: 5.0, hMax: 8.5, lit: 0.11, signP: 0.18, landmark: 0.004, w: 0.19, vacant: 0.20, butte: 0 }, - { name: 'adobe', hue: P.ember, hue2: P.warm, mix: P.warm, mixP: 0.66, accent: P.warm, styles: [3, 3, 4], + /* Adobe. The palette note for timber lists mud brick against it and that is not a coincidence + * — an adobe wall in shade is the colour of wet earth and in sun it is the colour of dust, + * so this row is timber leading sand rather than either alone. */ + { name: 'adobe', hue: P.timber, mix: P.sand, mixP: 0.58, accent: P.ember, styles: [3, 3, 4], hMin: 4.4, hMax: 7.5, lit: 0.13, signP: 0.12, landmark: 0.010, w: 0.14, vacant: 0.16, butte: 0 }, - { name: 'ranch', hue: P.ember, mix: P.slate, mixP: 0.58, accent: P.red, styles: [1, 1, 5], + /* Fieldstone: the bank, the jail, the mill and the powder house — the buildings a town builds + * out of what it dug up, and the ones still standing. It is the quarter with the lowest lit + * rate in the settled half of the table because most of those buildings are empty at night. */ + { name: 'stone', hue: P.stone, mix: P.timber, mixP: 0.74, accent: P.sand, styles: [4, 4, 0], hMin: 5.4, hMax: 9.5, lit: 0.09, signP: 0.09, landmark: 0.006, w: 0.13, - vacant: 0.30, butte: 0.004 }, + vacant: 0.30, butte: 0.006 }, /* The mission quarter: lime-washed plaster and the one place with trees in it. white leads, - * spring is the cottonwood, and it carries the church — landmark 0.05 is by far the highest - * in either world, because a mission IS its bell tower. */ - { name: 'mission', hue: P.white, mix: P.amber, mixP: 0.60, accent: P.spring, styles: [3, 4, 2], + * moss is the cottonwood and the sage (it replaces spring, which is a neon-transit green and + * had no business on a tree), and it carries the church — landmark 0.022 is the highest in + * this world, because a mission IS its bell tower. */ + { name: 'mission', hue: P.white, mix: P.sand, mixP: 0.62, accent: P.moss, styles: [3, 4, 2], hMin: 5.4, hMax: 9.5, lit: 0.14, signP: 0.07, landmark: 0.022, w: 0.07, vacant: 0.22, butte: 0 }, - { name: 'range', hue: P.slate, mix: P.ember, mixP: 0.62, accent: P.ember, styles: [4, 1, 4], + /* Open range, 26% of the ground and 62% of it empty. Its hue is the BUTTE's hue — a rock lot + * takes D.hue directly — so sand leads, because a flat-topped sandstone butte at noon is the + * palest thing in the frame and at dusk it is the last thing still lit. ember threads the red + * beds through it; moss is the sagebrush. */ + { name: 'range', hue: P.sand, mix: P.ember, mixP: 0.60, accent: P.moss, styles: [4, 1, 4], hMin: 4.4, hMax: 7.5, lit: 0.06, signP: 0.02, landmark: 0.000, w: 0.26, vacant: 0.62, butte: 0.072 } ]; @@ -201,41 +327,69 @@ * and the entire signage path — the brightest thing the caster can draw — is switched off by * DATA, with no code change and no way for a neon blade sign to appear on a crater rim. * - * `hue` is white or slate and never anything warm, and that is the lighting doctrine in the - * table: there is no atmosphere to redden anything, and core.js prints slate at a ceiling of - * 114 — under the muddy band's own ceiling — so slate can never be the LIT face of anything. - * It is the shadow swatch here and nothing else. */ + * `hue` is never anything warm, and that is the lighting doctrine in the table: there is no + * atmosphere to redden anything. It used to be white or slate; slate is gone from every row, + * because core.js prints slate at a ceiling of 114 — under the muddy band's own ceiling — so + * it could never be the LIT face of anything, and the swatch that means "unlit rock, regolith, + * dust" now exists and is called stone. surf_moon.js does not read `hue` at all today; these + * are written so that it CAN, and so that the record does not lie about what it is standing on + * in the meantime. + * + * EIGHT TERRAIN TYPES, UP FROM SIX. The two new rows are the two lunar landforms the table + * could not say: an ejecta RAY (the brightest ground on the Moon, near dead flat, and strung + * with secondary craters) and a BOULDER FIELD (the roughest, and almost entirely rock). The + * crater rate is also spread much wider than it was — 0.02 to 0.58 against 0.02 to 0.46 — so + * that crossing a district boundary changes how pocked the ground is and not just how tall the + * rocks on it are. Weights sum to 1.00. */ DIST_MOON = [ - /* The floor of a mare, and the district that IS the plain: 94% of its lots are open ground, + /* The floor of a mare, and the district that IS the plain: 95% of its lots are open ground, * which is why it is the heaviest row in the table. */ - { name: 'mare', hue: P.slate, mix: P.white, mixP: 0.70, accent: P.white, styles: [7], - hMin: 0.5, hMax: 1.8, lit: 0, signP: 0, landmark: 0.000, w: 0.30, - vacant: 0.94, boulder: 0.10, crater: 0.06 }, - /* Ejecta — the blanket thrown out of a crater, and the one place the ground has real relief - * in it. Its lots are rock piles a metre to five metres high. */ - { name: 'ejecta', hue: P.white, mix: P.slate, mixP: 0.62, accent: P.pure, styles: [7, 8], - hMin: 1.2, hMax: 5.0, lit: 0, signP: 0, landmark: 0.000, w: 0.20, - vacant: 0.70, boulder: 0.55, crater: 0.10 }, - /* Rim. The crater branch in computeCell fires here: a raised ring round a flat walkable - * floor, and the only district in any world that draws a SHAPE rather than a height. */ - { name: 'rim', hue: P.white, mix: P.slate, mixP: 0.66, accent: P.pure, styles: [8], - hMin: 2.0, hMax: 7.0, lit: 0, signP: 0, landmark: 0.004, w: 0.16, - vacant: 0.52, boulder: 0.18, crater: 0.46 }, + { name: 'mare', hue: P.stone, mix: P.white, mixP: 0.72, accent: P.white, styles: [7], + hMin: 0.5, hMax: 2.2, lit: 0, signP: 0, landmark: 0.000, w: 0.24, + vacant: 0.95, boulder: 0.10, crater: 0.03 }, + /* Ejecta — the blanket thrown out of a crater. Its lots are rock piles a metre to five and a + * half metres high, and it is the roughest thing the walk routinely passes through. */ + { name: 'ejecta', hue: P.white, mix: P.stone, mixP: 0.60, accent: P.pure, styles: [8, 7], + hMin: 1.2, hMax: 5.4, lit: 0, signP: 0, landmark: 0.000, w: 0.14, + vacant: 0.72, boulder: 0.55, crater: 0.10 }, + /* A RAY. Fresh fines flung out along a line from a young impact, and the highest-albedo + * ground on the Moon — hence white leading with nothing threaded through it at all. It is + * the FLATTEST row in the table (0.3-1.0 m, 97% vacant) and it earns its place by what it + * carries rather than by what it stands up: crater 0.14 is the secondary chain, a scatter of + * small bowls in a line, which is the one lunar landform that is legible from inside it. */ + { name: 'rays', hue: P.white, mix: P.stone, mixP: 0.86, accent: P.pure, styles: [7], + hMin: 0.3, hMax: 1.0, lit: 0, signP: 0, landmark: 0.000, w: 0.10, + vacant: 0.97, boulder: 0.06, crater: 0.14 }, + /* A BOULDER FIELD. The one district that is mostly not ground: 45% of its lots carry rock, + * against 28% in ejecta and 5% on the mare. Its heights are LOW (0.8-3.2 m) on purpose — + * this is a field of metre blocks you walk between, not a massif you look at, and its whole + * job is to be the near-field terrain that gives the plain a scale. */ + { name: 'field', hue: P.stone, mix: P.white, mixP: 0.64, accent: P.pure, styles: [8, 8, 7], + hMin: 0.8, hMax: 3.2, lit: 0, signP: 0, landmark: 0.000, w: 0.10, + vacant: 0.55, boulder: 0.90, crater: 0.02 }, + /* Rim. The crater branch in computeCell fires here: a raised ring round a flat floor, and the + * only district in any world that draws a SHAPE rather than a height. */ + { name: 'rim', hue: P.white, mix: P.stone, mixP: 0.66, accent: P.pure, styles: [8], + hMin: 2.0, hMax: 7.5, lit: 0, signP: 0, landmark: 0.004, w: 0.14, + vacant: 0.55, boulder: 0.18, crater: 0.58 }, /* Highland — older, rougher, higher, and the only district that draws a massif. That is * what puts something on the horizon which is terrain rather than backdrop. */ - { name: 'highland', hue: P.white, mix: P.slate, mixP: 0.74, accent: P.pure, styles: [8, 7], - hMin: 3.5, hMax: 15.0, lit: 0, signP: 0, landmark: 0.030, w: 0.14, - vacant: 0.58, boulder: 0.24, crater: 0.08 }, + { name: 'highland', hue: P.white, mix: P.stone, mixP: 0.74, accent: P.pure, styles: [8, 7], + hMin: 3.5, hMax: 16.0, lit: 0, signP: 0, landmark: 0.030, w: 0.12, + vacant: 0.60, boulder: 0.24, crater: 0.08 }, /* The landing site: flat, scoured, and the district the hardware elements probe for. Its - * ground is 96% empty because the descent engine cleared it. */ - { name: 'site', hue: P.slate, mix: P.white, mixP: 0.60, accent: P.amber, styles: [7], - hMin: 0.3, hMax: 1.2, lit: 0, signP: 0, landmark: 0.000, w: 0.08, + * ground is 96% empty because the descent engine cleared it. moon_craft.js requires + * height(px,pz) <= 0.05 at the anchor it picks, and the swell added below does NOT break + * that: the nearest of its five probes is the route centreline itself, and a street cell is + * height 0 by construction in every world. See swellAt. */ + { name: 'site', hue: P.stone, mix: P.white, mixP: 0.60, accent: P.amber, styles: [7], + hMin: 0.3, hMax: 1.2, lit: 0, signP: 0, landmark: 0.000, w: 0.06, vacant: 0.96, boulder: 0.04, crater: 0.02, hardware: 1 }, /* Regolith plain — the transitional ground, and deliberately the dullest row in the table. * It exists so that two interesting districts are rarely adjacent. */ - { name: 'plain', hue: P.slate, mix: P.white, mixP: 0.80, accent: P.white, styles: [7], - hMin: 0.4, hMax: 1.4, lit: 0, signP: 0, landmark: 0.000, w: 0.12, - vacant: 0.92, boulder: 0.14, crater: 0.04 } + { name: 'plain', hue: P.stone, mix: P.white, mixP: 0.80, accent: P.white, styles: [7], + hMin: 0.4, hMax: 1.6, lit: 0, signP: 0, landmark: 0.000, w: 0.10, + vacant: 0.93, boulder: 0.14, crater: 0.05 } ]; norm(DIST_CYBER); norm(DIST_WEST); norm(DIST_MOON); @@ -317,22 +471,99 @@ * setbackP 0 — the setback/false-front branch is a BUILDING idea. A rock has no podium and no * capping board, so the branch is skipped outright rather than asked to pick a half. * lmMin/lmVar 26-60 m — a "landmark" here is a massif. raycast.js's HMAX is 108 and must never - * under-estimate the tallest thing emitted; 60 is comfortably under, so HMAX is untouched. + * under-estimate the tallest thing emitted; 60 plus the swell's 2.8 is comfortably under, so + * HMAX is untouched. * startT 0.10 — see chooseStart. The city's threshold asks for a wall at 57 degrees on both * sides, which nothing on the Moon clears, so every seed would scan all 64 candidates and * then fall back to the argmax anyway. + * + * ---- WHAT WAS STILL DRAWING STRAIGHT LINES, and it was three things ------------------------- + * The lattice was made invisible by pitch, width and vacancy, and it was still legible, because + * three of the numbers below were still BUILDING numbers applied to a plain. + * + * aveEvery/crossEvery were BOTH 2, so every second corridor was the wide class. A period-two + * alternation is the most readable rhythm there is — wide, narrow, wide, narrow to the + * horizon is a ruled grid however much the positions are jittered, and jitter cannot hide a + * pattern in WIDTH. They are 5 and 7 now: coprime, so the pair never repeats inside a frame, + * and a wide corridor is a one-in-five event rather than a one-in-two. + * alleyP/alleyDeepP were 0.70. An alley is a gap BETWEEN TWO BUILDINGS. On a plain it is a + * one-or-two-metre strip of ground held at height 0 running the full 54-72 m of a block, + * dead parallel to the corridor beside it — which, once the ground either side of it rolls, + * is a trench with two straight edges. It is the single most axis-aligned feature the moon + * map was producing. Zero, on the same argument as setbackP. + * plazaP/plazaBigP were 0.55/0.70. A plaza is the city's block-breaker and it exists to open + * the sky slot; on a plain the sky is already open and 90% of the blocks are already empty, + * so all it contributed was an OCTAGON of flat ground, at a rate modulated by kk % 4 — a + * period-four lattice artefact on top of a shape with straight edges. Zero. + * + * That leaves the corridors themselves, which cannot go: the route walker follows street + * centrelines and there is nothing else for it to follow. What answers them is the swell. + * + * ---- THE SWELL ------------------------------------------------------------------------------ + * swellAmp 2.8 m — peak relief, and the number is set against eyeY 1.66 rather than against + * what looks like a hill. A mound only reveals anything by being crested if some of it is + * ABOVE THE EYE, and how much of the plain that is, is measurable. Share of ground standing + * 1.66-6 m — i.e. over the walker's head and still terrain rather than massif — over the same + * five-seed patch, against the same map with the swell off: + * off 4.2-5.7 1.8 -> 4.2-6.0 2.8 -> 4.5-6.8 4.5 -> 5.0-8.1 + * At 1.8 the swell adds two tenths of a point and the plain stays a plane with texture on it; + * at 2.8 it roughly doubles the world's above-eye ground, which is the point of it; 4.5 adds + * two and a half points, and every one of those points is a metre of extra wall along a + * corridor whose whole job is to not read as a corridor. + * swellLat 54 / swellLat2 23 m — the two bilinear octaves, weighted 0.68/0.32. 54 m is "several + * tens of metres across" as the brief asks; the second octave is there to stop the first + * reading as a regular swell of one wavelength. Not commensurate with AVE 96 or CROSS 84, + * deliberately: a relief lattice that shared a factor with the street lattice would put its + * crests in the same place on every block. + * swellT 0.56 — the threshold below which the field is EXACTLY zero, and it is a budget rather + * than a taste. Ground at height 0 is what free-walk collision and moon_ground.js's boulder + * scatter (`height > 0.1 -> skip`, and that scatter is most of this world's texture) both + * spend, so the relief cannot be a field that is everywhere non-zero. Swept over a 400x400 m + * patch round the start on seeds 42/7/3/99/1234 — walkable (h <= 0) / boulder ground (<= 0.1), + * as the range over the five seeds: + * off 88.6-92.1 / 88.6-92.1 + * 0.56 72.9-78.8 / 79.0-85.6 + * 0.40 63.6-67.1 / 73.1-76.0 + * 0.20 55.6-59.6 / 63.8-67.0 + * 0.00 54.5-57.7 / 59.6-61.9 + * At 0.56 the boulder field loses under a tenth of its candidate ground and three quarters of + * the plain is still floor. The other thing the threshold buys is the read: the relief has to + * be MOUNDS ON A PLAIN and not an everywhere-rippling surface, because a plain the eye never + * sees flat has no datum to judge the mounds against, and at 0.00 the whole field is in + * motion and none of it reads as ground. + * moon_craft.js's landing-site probe found its full three sites on every seed at every one of + * those settings, INCLUDING 0.00, and that is worth writing down rather than being relieved + * about: the nearest of its five probes is the route centreline itself, and a street cell is + * height 0 by construction. The probe was never at risk; the boulders were. + * WHAT THE RELIEF COSTS THE PRINT, which is the question a new surface always has to answer + * here, measured with-vs-without over nine frames (seeds 42/7/1234, frame 900, 200x60, at + * night, noon and dusk) — muddy(9-119) / hot(v>=170): + * night 6.4 / 1.66 -> 6.2 / 1.61 + * noon 4.1 / 3.63 -> 4.0 / 3.79 + * dusk 4.0 / 3.56 -> 3.9 / 3.67 + * Nothing. The muddy band goes DOWN by a tenth of a point at every hour and the hot tail up + * by a tenth, which is what should happen: this world has no air, so a new face is either + * lit or it is lum 0, and neither of those is in the middle of the range. The Moon can be + * given geometry for free in a way the other two worlds cannot. + * swellEdge 12 m — how far from a corridor the relief takes to reach full amplitude. This is + * the whole anti-straight-line mechanism: the swell is multiplied to ZERO at the block edge, + * so there is no step where the block meets the corridor, only a gradient. The corridors end + * up lying in shallow valleys, which is what a track across rolling ground does anyway. + * swellStyle 9 — the style a lot gets when its height is the swell and nothing else. See + * STYLE_CH_MOON. */ var TH_MOON = { id: 'moon', AVE: 96, CROSS: 84, aveJit: 38, aveOff: -18, crossJit: 34, crossOff: -16, - aveWide: 20, aveMid: 15, aveNarrow: 11, aveMidP: 0.55, aveEvery: 2, - crossWide: 17, crossMid: 13, crossNarrow: 10, crossMidP: 0.50, crossEvery: 2, + aveWide: 20, aveMid: 15, aveNarrow: 11, aveMidP: 0.55, aveEvery: 5, + crossWide: 17, crossMid: 13, crossNarrow: 10, crossMidP: 0.50, crossEvery: 7, lotW: 7, lotWVar: 9, lotD: 7, lotDVar: 9, - alleyMin: 12, alleyP: 0.70, alleyDeepMin: 12, alleyDeepP: 0.70, - plazaP: 0.55, plazaBigP: 0.70, plazaR: 14, plazaRVar: 16, + alleyMin: 12, alleyP: 0.00, alleyDeepMin: 12, alleyDeepP: 0.00, + plazaP: 0.00, plazaBigP: 0.00, plazaR: 14, plazaRVar: 16, vacant: 0.62, setbackP: 0.00, podMin: 0, podVar: 0, falseFront: 0, lmMin: 26, lmVar: 34, crownTall: 999, DG: 58, sky: 1, rimMin: 1.4, rimVar: 4.2, startT: 0.10, + swellAmp: 2.8, swellLat: 54, swellLat2: 23, swellT: 0.56, swellEdge: 12, swellStyle: 9, styleCh: STYLE_CH_MOON, signCh: SIGN_CH_WEST, styleBase: 7, setbackMode: 'none', signShape: 'none', signPalette: 'none' }; @@ -464,6 +695,65 @@ return bd; } + /* ---- rolling relief --------------------------------------------------------------------- + * THE INVARIANT, stated once because three separate consumers depend on it and none of them + * says so out loud: HEIGHT 0 MEANS WALKABLE. camera()'s last-resort guard, control.js's + * free-walk collision, cell()'s `h <= 0 -> return null`, isStreet(), moon_ground.js's boulder + * scatter and moon_craft.js's landing-site probe all read exactly that one test, and there is + * no terrain-following anywhere in the tree — the eye is at a fixed 1.66 above y = 0. So relief + * is not something that can be added to the ground; it is something that can only be added + * where the ground is allowed to stop being ground. + * + * That is the same invariant the crater code respects, and it respects it in the same two + * ways. FIRST, a street cell returns from computeCell before any height branch is reached, so + * a corridor is height 0 by construction and nothing below can touch it. SECOND, the relief is + * thresholded: below swellT the field is exactly zero, so a majority of the open ground stays + * at height 0 and stays walkable, boulder-bearing and probe-able. A field that was everywhere + * non-zero would have fenced the walker into the lattice — the exact thing this world spends + * three theme constants hiding. + * + * Bilinear on a smoothstepped lattice, not a per-lot step. surf_moon.js's 9 m density swell + * carries the argument in full and it applies verbatim to geometry: a hard cell gives the plain + * visible tiles, which is the failure mode this is here to remove rather than to cause. Two + * octaves, then one more smoothstep on the way out of the threshold, so the foot of every mound + * meets the flat with a zero gradient and there is no crease anywhere in the field. + * + * Allocation-free and a pure function of (seed, gx, gz, block bounds): eight hashes and six + * lerps per cell, which is under a third of what districtAt's 27 hashes already cost on the + * same cell. The two octaves take ADJACENT salts, which the header at the top of this file + * would normally forbid — they go through `hash` rather than hash2, and that is the whole + * reason `hash` exists: routed through both coordinate multipliers, a salt step of one moves + * every bit of the accumulator, and the 40-salt sweep this file was measured with leaves no + * pair above 0.018. */ + function bilin(gx, gz, lat, salt) { + var qx = gx / lat, qz = gz / lat; + var i0 = Math.floor(qx), j0 = Math.floor(qz); + var fx = qx - i0, fz = qz - j0; + fx = fx * fx * (3 - 2 * fx); fz = fz * fz * (3 - 2 * fz); + var a = hash(i0, j0, salt), b = hash(i0 + 1, j0, salt); + var c = hash(i0, j0 + 1, salt), d = hash(i0 + 1, j0 + 1, salt); + var ab = a + (b - a) * fx; + return ab + ((c + (d - c) * fx) - ab) * fz; + } + /* x0..x1 / z0..z1 are the block's interior bounds — the same two rectangles colX/rowZ already + * filled in for this cell, so the corridor fade costs no extra lattice work. The two fades are + * MULTIPLIED rather than min()'d: min leaves a crease along the block's diagonal, and a crease + * in a height field is a straight line, which is the one thing this function must not draw. */ + function swellAt(gx, gz, x0, x1, z0, z1) { + var eu = gx - x0, e2 = x1 - gx; if (e2 < eu) eu = e2; + if (eu <= 0) return 0; + var ev = gz - z0; e2 = z1 - gz; if (e2 < ev) ev = e2; + if (ev <= 0) return 0; + var fu = eu < TH.swellEdge ? eu / TH.swellEdge : 1; + var fv = ev < TH.swellEdge ? ev / TH.swellEdge : 1; + fu = fu * fu * (3 - 2 * fu); fv = fv * fv * (3 - 2 * fv); + var n = bilin(gx, gz, TH.swellLat, S + 520) * 0.68 + + bilin(gx, gz, TH.swellLat2, S + 521) * 0.32; + if (n <= TH.swellT) return 0; + var m = (n - TH.swellT) / (1 - TH.swellT); + return TH.swellAmp * m * m * (3 - 2 * m) * fu * fv; + } + /* ---- one cell ------------------------------------------------------ */ var cH = 0, cD = 0, cLX = 0, cLZ = 0; // computeCell's out-params, avoids an alloc per cell // Every cell of a lot asks for the same district; the Voronoi is 27 hashes, so remembering @@ -519,8 +809,9 @@ var h; /* Vacancy is the district's own now rather than one number for the whole map, because on the * frontier it is not an exception — `range` is 62% empty ground and that emptiness is the - * entire reason the world has a horizon in it. The city's six districts all carry 0.06, - * which is exactly the literal that used to be here. */ + * entire reason the world has a horizon in it. None of the city's nine districts states one, + * so they all fall through to TH_CYBER.vacant 0.06, which is exactly the literal that used to + * be here. */ var vac = D.vacant !== undefined ? D.vacant : TH.vacant; if (hash(lx, lz, S + 504) < vac) { h = 0; // vacant lot / interior courtyard / open range @@ -538,9 +829,11 @@ * at character resolution is the RING — a flat floor with a raised lip round it, seen * edge-on from a metre seven off the ground. * - * The floor is height 0, which is deliberate twice over: it is walkable, so the route can - * cross a crater instead of being fenced out of one, and it costs the ray marcher nothing - * until the ray actually reaches the rim. + * The floor is height 0 — or, once the swell is added below, whatever the surrounding + * ground is doing, which is what a bowl in rolling terrain looks like. That is deliberate + * twice over: on flat ground it is walkable, so the route can cross a crater instead of + * being fenced out of one, and it costs the ray marcher nothing until the ray actually + * reaches the rim. * * A sine profile rather than a step, for the same reason the frontier's rock strata are * not ruled lines: a step reads as masonry. */ @@ -577,6 +870,11 @@ } } } + /* Every branch above converges here, which is why the relief is added here and not in six + * places: a vacant lot becomes the mound itself, a rock pile stands ON the mound, a crater's + * floor and rim ride it together. Gated on the field existing at all, so the city and the + * frontier take one `undefined` comparison per cell and are byte-identical without it. */ + if (TH.swellAmp !== undefined) h += swellAt(gx, gz, x0, x1, z0, z1); cH = h; cD = did; cLX = lx; cLZ = lz; } @@ -591,17 +889,40 @@ * 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 if (TH.signPalette === 'painted') { - if (r < 0.30) return P.warm; - if (r < 0.58) return P.amber; - if (r < 0.76) return P.white; - if (r < 0.90) return P.ember; + /* 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 + * sign in the 1880s was laid on. Both are held to a tenth each. gold's night ceiling is + * 157, which is 22 points under amber's 179 — so a gilded board is the brightest painted + * sign in town and still cannot outrank the lamp behind the window beside it. */ + if (r < 0.24) return P.warm; + if (r < 0.44) return P.amber; + if (r < 0.62) return P.white; + if (r < 0.74) return P.ember; + if (r < 0.84) return P.gold; + if (r < 0.92) return P.moss; return P.red; } - // Signage obeys the same two-pillar discipline as everything else; violet stays a garnish, - // and the arcade strip is the one place it is allowed to lead. + /* Signage obeys the same two-pillar discipline as everything else, and the three new signage + * swatches are threaded through the DISTRICT rather than through the general roll, because a + * colour that turns up everywhere is not a district's colour. Each branch is keyed on the + * quarter's ACCENT, which is the one field that is unique per row. + * + * ROSE. The rose-neon strip is here and only here, on the arcade's 6% of the ground, and it + * leads at 0.42 of that quarter's signs — which is 2.5% of the city's, i.e. narrower than + * violet has ever been. It is licensed as signage for the same reason violet is (core.js + * gives it a gain of 0.20 and a ceiling of 131, under every pillar and under white) and + * forbidden as a surface for the same reason too. */ + if (D.accent === P.rose) return r < 0.42 ? P.rose : (r < 0.74 ? P.azure : P.amber); + // The gilt quarter signs itself in brass and tile, with amber carrying the rest. + if (D.accent === P.gold) return r < 0.38 ? P.gold : (r < 0.62 ? P.jade : (r < 0.88 ? P.amber : P.rose)); + // The market's boards are painted timber with a gilded line on the good ones. + if (D.accent === P.timber) return r < 0.34 ? P.gold : (r < 0.56 ? P.amber : (r < 0.80 ? P.moss : P.warm)); if (D.accent === P.violet) return r < 0.42 ? P.violet : (r < 0.74 ? P.azure : P.amber); if (r < 0.34) return P.amber; if (r < 0.64) return P.azure; + /* D.hue is the quarter talking, and it is what puts jade on a gilt facade, moss on a market + * one and indigo on a tower — narrow by construction, because it is 14% of the signs in one + * district rather than a colour the whole city can draw. */ if (r < 0.78) return D.hue; if (r < 0.86) return P.ember; if (r < 0.93) return P.spring; @@ -611,7 +932,16 @@ function makeRec(gx, gz, h, did, lx, lz) { var D = DIST[did]; var rock = !!(D.butte && TH.rockStyle !== undefined && hash(lx, lz, S + 507) < D.butte); - var style = rock ? TH.rockStyle : D.styles[(hash(lx, lz, S + 601) * D.styles.length) | 0]; + /* THE LOT IS EMPTY AND THE SWELL IS THE ONLY REASON IT HAS A HEIGHT AT ALL. Re-drawing S+504 + * rather than plumbing a flag out of computeCell: it is one hash, it is the same draw against + * the same vacancy this cell's height was decided by, and it keeps makeRec a pure function of + * the lot the way every other line in it is. Without the marker the painter cannot tell a + * mound of powder from a metre of rock — both arrive as `style 7, h 1.4` — and it would paint + * bedrock over the whole plain. */ + var swellOnly = TH.swellStyle !== undefined && + hash(lx, lz, S + 504) < (D.vacant !== undefined ? D.vacant : TH.vacant); + var style = swellOnly ? TH.swellStyle + : (rock ? TH.rockStyle : D.styles[(hash(lx, lz, S + 601) * D.styles.length) | 0]); /* THE STYLE INDEX IS WORLD-WIDE AND THE GLYPH TABLE IS PER-THEME, which is why this * subtraction exists. `style` travels on the record and out to the painters, and a reader who * sees 8 should be able to find row 8 in one table rather than having to know which world's @@ -680,7 +1010,10 @@ /* 0 none 1 mast 2 tank 3 beacon in the city; 0 none 1 chimney 2 water tank 3 steeple on the * frontier. Same field, same three shapes at the same three rates — what differs is which * element reads it (structure.js against west_roof.js), and a rock never wears one. */ - crown: rock ? 0 : (tall ? 3 : (cr < 0.14 ? 1 : (cr < 0.24 ? 2 : 0))), + // A rock wears no chimney, and neither does a rise in the ground: both are 0 by the same + // argument, and `swellOnly` is checked here as well as in `style` because crown is read off + // the record by the roof elements rather than off the style. + crown: (rock || swellOnly) ? 0 : (tall ? 3 : (cr < 0.14 ? 1 : (cr < 0.24 ? 2 : 0))), lotX: lx, lotZ: lz, seed: hash(lx, lz, S + 613), // stable per building — hash this for per-facade variety face: hash(gx, gz, S + 614) // stable per cell — hash this for per-column variety diff --git a/src/core.js b/src/core.js index 1ce1e58..7802365 100644 --- a/src/core.js +++ b/src/core.js @@ -3,7 +3,8 @@ var CC = (function () { 'use strict'; // Palette measured off the reference frames: two pillars (sodium amber, screen azure) - // and three narrow accents. Brightness is NOT baked in here — `lum` scales these. + // and three narrow accents, plus the eight-swatch extension below. Brightness is NOT + // baked in here — `lum` scales these, and the two ladders decide how far it can get. var PALETTE = [ [216, 232, 74], // 0 amber — sodium streetlight, the first pillar [ 74, 168, 232], // 1 azure — screenlight, the second pillar @@ -25,10 +26,52 @@ var CC = (function () { [255, 214, 120], // 8 warm — interior spill, windows with someone home [ 90, 240, 255], // 9 ice — holo, glass, rain highlight [255, 255, 255], // 10 pure — specular hits only, use sparingly - [ 40, 50, 66] // 11 shadow — occluded structure that must still read + [ 40, 50, 66], // 11 shadow — occluded structure that must still read + /* ---- the extension ------------------------------------------------------------------------ + * Eight more, appended and never inserted: every swatch index in this tree is a literal in + * some other file (surfaces.js's L_LOW/L_LIT/L_HOT, ads.js's PEAK, signage.js's MIN_C/MIN_R + * are all arrays indexed by palette slot), so 0..11 are frozen and the only safe growth is + * off the end. They are the swatches the first twelve could not spell: there was no neutral + * grey at all (slate is deliberately blue and says so), no brown, no green that is not an + * ACCENT (spring is listed as foliage and is fitted as a district accent — it cannot carry a + * hedge without leading the frame), and nothing warm-metal. FIVE of the eight are SURFACES — + * stone, timber, sand, moss and indigo, which is what the daylight worlds are actually made + * of — and three are SIGNAGE: jade, rose and gold. That split is not decoration, it is the + * thing ladder() switches on further down; a swatch put in the wrong half blends against + * the wrong curve through dawn and dusk, and there is no other place that mistake shows. */ + [156, 162, 170], // 12 stone — neutral mid-grey: daylight concrete, unlit rock, regolith, + // dust. The swatch slate refuses to be. Its max channel is 170 + // against slate's 138, so at equal gain it prints the brighter + // of the two, which is the whole point of having it + [150, 98, 58], // 13 timber — weathered board, mud brick, dirt, leather, rust-earth. Warm + // and DARK on purpose: a board in shade must not compete with + // the same board in sun, which is `sand` + [216, 186, 132], // 14 sand — pale tan: sunlit dust, the crown of a dirt road, bone, adobe + // in sun. The desert's white, and it is a pigment rather than a + // brightness — the ladder is what keeps it under white + [ 26, 148, 138], // 15 jade — deep teal: tilework, oxidised copper, transit livery, + // planting light. Tops out at 148, so it is narrow by pigment + // before the ladder touches it + [238, 102, 150], // 16 rose — pink neon. SIGNAGE AND SCREENS ONLY, and the one swatch in + // this file that carries a prohibition: hue 337 with this + // build's bloom over it is exactly the failure that walked + // violet off magenta (see slot 4). It is licensed for small + // cells and its gain, the lowest in the table, is what makes + // "small" enforceable rather than a note + [240, 176, 72], // 17 gold — brass and gilding: sign frames, lamp housings, warm metal. + // Not a second amber — amber is a sodium DISCHARGE and peaks + // in the green (216,232,74); gold peaks in the red and reads + // as metal being lit rather than as something emitting + [ 92, 126, 74], // 18 moss — dull green: planting, algae on concrete, sage, canvas. The + // darkest pigment in the table after shadow, which is what a + // leaf in ordinary light actually is + [ 58, 70, 142] // 19 indigo — deep blue: night glass, shade with sky in it, dusk haze. The + // shade swatch for a world that has a sky in it, where `shadow` + // is the shade swatch for a world that has none ]; var P = { amber:0, azure:1, ember:2, spring:3, violet:4, white:5, red:6, - slate:7, warm:8, ice:9, pure:10, shadow:11 }; + slate:7, warm:8, ice:9, pure:10, shadow:11, + stone:12, timber:13, sand:14, jade:15, rose:16, gold:17, moss:18, indigo:19 }; // Glyph table. Index 0 must stay blank — the frame is cleared to it. var GLYPHS = " .,:;'\"`^~-_=+*|/\\()[]{}<>!?#%&$@8OoQ0XZWMNHUVAKY".split(''); @@ -276,7 +319,19 @@ var CC = (function () { * The 40-point gap between the two pillars is not sloppiness, it is the correction: amber * paints 1.44 cells for every azure cell (see PILLAR BALANCE above), so the more numerous * pigment gets the lower ceiling and the two arrive at comparable presence. Both still clear - * the v=170 hot line, which is what "the pillars own the top of the lit range" has to mean. */ + * the v=170 hot line, which is what "the pillars own the top of the lit range" has to mean. + * + * THE EIGHT NEW SWATCHES, measured the same way and reported to the same convention (the LUT + * value at lum 255 in bucket 0, times the swatch's own max channel over 255): gold 157, sand + * 138, jade 134, rose 131, stone 122, indigo 115, timber 111, moss 94. Not one of them reaches + * the lower pillar, which is the ladder rule holding: the extension added no light, it added + * SURFACES, and five of the eight sit in the slate-to-white band where structure belongs. + * + * A note on the convention, because the twelve figures above and the eight here were computed + * by different hands. Re-measuring the original twelve with the script that fitted the eight + * reproduces them to within one unit — amber 179 for 180, azure 219 for 220, everything else + * exact — the difference being where the rounding falls between the LUT and the pigment scale. + * The numbers are directly comparable; do not chase the unit. */ var EXPOSURE = [ 0.50, // 0 amber — the first pillar, ceiling 180. The gain has a HARD FLOOR just under it // and it is not a preference: at 0.44 the ceiling is 171 and at 0.42 it @@ -360,7 +415,7 @@ var CC = (function () { // is still the top of the accent tier, still reads as a glint against wet // road, and takes at most 2.7% of a frame's lit energy 0.85, // 10 pure — specular only; it is already at the top of the scale - 0.80 // 11 shadow — occluded structure must READ as occluded structure, not as a hole, and + 0.80, // 11 shadow — occluded structure must READ as occluded structure, not as a hole, and // this one is deliberately NOT 0.60. shadow's pigment tops out at 66, so // unlike slate it was never in the inverted ladder and could not compete // with a pillar at any gain; its only real fault at 2.60 was the same @@ -374,6 +429,88 @@ var CC = (function () { // 28.6%. THE INVARIANT is not "gain below SHOULDER" but "the swatch's // WORKING lum range times its gain stays below SHOULDER" — that is what // 2.00 and 2.60 broke, from lum 79 and 61 up respectively + 0.41, // 12 stone — STRUCTURE, ceiling 122, and it is fitted AGAINST slate rather than in + // isolation: the two are the same job in two temperatures, so the pair + // has to read as one tier. slate prints 114 at gain 0.60 and stone prints + // 122 at 0.41, and the whole of that eight-point gap plus the whole of + // the 0.19 gain gap is pigment — stone tops out at 170 against slate's + // 138. Rejected 0.60, which would have matched slate's gain and printed + // 141 — ten under white and 27 over slate. A neutral grey sitting that + // close to white is the wash of mid-tone the slate entry above spends a + // paragraph removing, and stone will be the most numerous swatch on the + // Moon, where a wash is the one thing an airless frame cannot carry + 0.44, // 13 timber — STRUCTURE, ceiling 111, and deliberately the dimmest of the surface + // tier bar moss. A weathered board at night is lit by a lamp forty feet + // away and is not competing with the lamp; it sits three points under + // slate, which is the right order for a warm swatch against a cold one at + // the same distance from the light. Rejected 0.52 (ceiling 118, above + // slate): timber will carry entire frontier facades, so it is a + // coverage swatch and takes a coverage swatch's ceiling. Its working + // lum range times 0.44 stays under SHOULDER right up to lum 255, so the + // depth fade survives across the whole of it — the fault the slate entry + // two tiers up documents at 2.00 + 0.30, // 14 sand — STRUCTURE, ceiling 138, and it takes WHITE'S OWN GAIN. That is the + // cleanest fact in the extension: sand and white are the same job (the + // thing the light lands on) in two worlds, so they get the same number + // and the 13-point gap between their ceilings is entirely pigment, 216 + // against 236. It also means sand inherits white's argument — specular + // belongs to `pure`, and the desert's white is not a light source. + // Rejected 0.40 (ceiling 153), which is two points OVER white: a dirt + // road that outprints the render on the wall beside it makes the ground + // the brightest broad surface in a night frame, which is the exact fault + // white was brought down from 1.15 to fix + 0.80, // 15 jade — NARROW ACCENT, ceiling 134, under both pillars. The gain is the highest + // of the eight and that is pigment, not licence: jade's max channel is + // 148, so it cannot print above 148 at ANY gain, and 0.80 buys 134 of the + // available 148. Same shape of argument as `shadow` two lines up — a dark + // ink needs a large multiplier to reach a modest ceiling, and the ceiling + // is what the ladder rule is about. SHOULDER bites from lum 198 up, which + // is above anything tilework or a livery panel gets written at + 0.20, // 16 rose — THE NARROWEST THING IN THE TABLE, ceiling 131, and the lowest gain in + // either ladder — under violet's 0.34, which was the previous floor and + // was set for the same reason. The README's rule is "no magenta ever" and + // rose is hue 337 with a max channel of 238, so this entry is a bound and + // not a taste. Rejected 0.42, which prints 173 — over the v=170 hot line, + // six points under the first pillar, and a pink cell that clears the hot + // line takes this build's bloom with it, which is precisely the failure + // that walked violet off magenta. Rejected 0.34, violet's own gain, at + // 160: that is over violet AND over gold, which would make the pink tube + // the brightest of the three signage swatches — precisely backwards. + // The second thing 0.20 buys is worth more than the ceiling — the KNEE + // bites on lum*gain/255, so at 0.20 it crushes every rose cell under + // lum 96 to black (at 0.42 it would crush + // only under 46). Rose can therefore exist ONLY where something wrote it + // near full scale, which is the definition of a small signage cell, and + // "small" stops being a note in a comment and becomes arithmetic + 0.32, // 17 gold — NARROW ACCENT, ceiling 157, the brightest of the eight and still 22 + // points under the lower pillar. It shares warm's gain exactly, which is + // the relationship to want: gilding and interior spill are both warm + // metal-and-glass light at the same remove, and the 10-point ceiling gap + // is gold's slightly darker pigment. Rejected 0.46 (ceiling 180, ONE + // point over amber): a brass sign frame that outprints the sodium lamp + // lighting it is the ladder inverted again, on a swatch invented long + // after the paragraph that forbids it was written. 0.40 prints 170 and + // lands exactly on the hot line, which is the wrong place to sit for a + // swatch that will be painted as thin frames — a hot thin feature is the + // photosensitivity failure, not just a ladder one + 0.46, // 18 moss — STRUCTURE, ceiling 94, and it is the one entry that misses the 110-155 + // band the other four surfaces hold, on purpose and after trying. moss + // tops out at 126, so a ceiling of 110 needs gain 0.69 — and 0.69 is the + // trap, because the DAY table's weaker gamma (0.62 against 0.33) means a + // swatch needs roughly 1.3x its night gain merely to hold its ceiling + // level. At 0.69 the day entry would have to be 0.85 to stand still, + // which is outside the 0.60-0.75 band a daylight surface belongs in, and + // the swatch would print DARKER at noon than at midnight. 94 is also the + // honest reading: a hedge at night is darker than the concrete beside it, + // and moss is 20 points under slate + 0.56 // 19 indigo — STRUCTURE, ceiling 115, which is slate's 114 to within a unit and is + // meant to be. indigo is the shade swatch for a world with a sky in it + // and slate is the far-haze swatch for the same world; they are two + // readings of the same cold structure and they print at the same height, + // so a wall that changes from one to the other across a shadow edge + // changes HUE and not brightness. Rejected 0.70 (ceiling 124): night + // glass that outprints the concrete around it reads as a lit window, + // which is azure's job and comes with azure's gain ]; /* GAMMA and KNEE are held at the values the previous round fitted, and that is a measurement * rather than an omission: re-swept over the 128 frames with the new EXPOSURE in place, GAMMA @@ -471,14 +608,82 @@ var CC = (function () { 0.62, // 8 warm — sunlit timber and skin; it stops being "interior spill" at noon 0.66, // 9 ice — the daylight sky, which is the largest bright surface either world has 0.85, // 10 pure — specular, and specular is what a sun makes - 0.46 // 11 shadow — filled by the sky rather than empty; see the note above + 0.46, // 11 shadow — filled by the sky rather than empty; see the note above + /* THE EIGHT, and the thing to understand before reading them is that a DAY ceiling and a NIGHT + * ceiling are not on the same scale even though they are computed the same way. GAMMA_DAY is a + * far weaker lift (0.62 against 0.33), so a swatch needs roughly 1.3x its night gain simply to + * print at the same height — slate does exactly that, 0.60 -> 0.78 for 114 -> 115. A gain that + * merely goes UP therefore says nothing; what says something is where the gain sits in the + * table's order, and the daylight frame gets its actual brightness from the lums the surfaces + * write, not from these numbers. That is why stone at 0.82 is "top of the structure tier" on a + * ceiling of 145: it is above slate and the light is above both. Measured ceilings at mix 1: + * sand 190, stone 145, gold 129, timber 120, jade 104, indigo 104, moss 102, rose 79. */ + 0.82, // 12 stone — top of the structure tier with white and sand, ceiling 145. A touch + // above slate's 0.78 and not level with it, because stone is genuinely + // neutral where slate is deliberately blue, and by day the neutral read + // is the correct one for concrete: at noon a wall is lit by the whole + // hemisphere, so the blue cast that makes slate right at night is the + // thing daylight takes away. Rejected 0.92 (white's gain, ceiling 151), + // which is white's own ceiling to within six points and would leave + // nothing between rendered wall and raw concrete + 0.72, // 13 timber — a real daylight surface, ceiling 120, and the biggest ladder move of + // the eight: 0.44 -> 0.72, from the bottom of the night surface tier to + // mid-table. That is sunlit board, and the ceiling barely moving (111 -> + // 120) while the gain moves 1.6x is the day gamma being paid for, not a + // failed fit. Rejected 0.60 (ceiling 108), which is BELOW its own night + // ceiling — a plank cannot be dimmer at noon than under a street lamp + 0.90, // 14 sand — sunlit dust, ceiling 190, and it sits one step under white exactly as + // the night table has it: same job, and white keeps the top because it is + // render and cloud and bone rather than the ground. Rejected 0.92, which + // is white's gain and prints 191 — one point apart is not a ladder, it is + // two names for one swatch. NOTE for whoever paints with it: at 0.90 the + // SHOULDER is live from lum 176 up, so sand's depth fade flattens across + // the top fifth of its range. That is white's regime too (0.92, live from + // 172) and is shipped, but it is the fault the slate entry documents and + // a sunlit road written at lum 220 is exactly where it would show + 0.58, // 15 jade — signage, and it DROPS, 0.80 -> 0.58 for 134 -> 104. A teal blade sign + // at noon is readable and is not a highlight, which is the whole shape of + // the day table's treatment of light. It keeps more of its night gain + // than azure does (0.52 of 1.00) because jade is half surface — tilework + // and oxidised copper are lit by the sun, not powered by it — and a + // swatch that is only sometimes a source should not go out entirely. + // Rejected holding 0.80 (ceiling 124), which leaves a blade sign printing + // level with amber's day ceiling — a lit sign matching a sunlit lamp + // housing is the night ladder surviving into a daylight frame + 0.18, // 16 rose — signage, and the lowest number in EITHER table, ceiling 79. Below + // violet's 0.26 for the same reason it is below violet at night. A pink + // sign at noon is a faded pink sign: the sun is broadband and the tube is + // not, so the one hour rose has least licence is the brightest one. + // Rejected 0.20 (ceiling 84), which is not a drop at all — the brief for + // this swatch is that it drops by day the way a pillar does, and 0.20 to + // 0.20 with a weaker gamma under it is a swatch standing still + 0.38, // 17 gold — signage and warm metal, ceiling 129, a step under amber's day ceiling + // of 133. That order is deliberate and it is the right way round: at noon + // both are metal and neither is a light, and a gilded frame reflects a + // shade less than a sodium tube's own envelope does. Rejected 0.62 + // (ceiling 176), which is warm's day gain and would put brass above red, + // spring, stone and BOTH pillars at noon — sixth in a table of twenty, + // for a swatch that exists to edge a sign + 0.74, // 18 moss — a real daylight surface, ceiling 102, and it finally passes its own + // night ceiling (94) rather than falling under it — see the night entry + // for the whole of why this swatch is fitted from the day side backwards. + // Sage and canvas in sun. Rejected 0.60 (ceiling 91), below night again + 0.62 // 19 indigo — shade with the sky in it, ceiling 104, and MID is the entire brief: it + // is the swatch for the part of a daylight frame that is neither lit nor + // black, which is what stops a noon picture reading as a lit object cut + // out of paper — the same job the shadow entry above describes, one tier + // up and with an actual sky in it. Rejected 0.78 (slate's gain, ceiling + // 118), which puts shade level with the sunlit concrete casting it ]; var GAMMA_DAY = 0.62, KNEE_DAY = 0.030; /* ---- how much of the day table is mixed in ------------------------------------------------------ - * Quantised, and that is the whole implementation trick. The LUT is 24 KB of pow() and exp() and + * Quantised, and that is the whole implementation trick. The LUT is 40 KB of pow() and exp() and * the file has always said it is "built once at load, never allocated again"; rebuilding it every - * frame would put 24576 transcendental calls on the frame budget. Rebuilding it when a QUANTISED + * frame would put 40960 transcendental calls on the frame budget — it was 24 KB and 24576 while + * the palette had twelve entries, and the eight added to the end cost a third more. Nothing else + * in the cost model moves: the table is still rebuilt on the same schedule, and the per-cell read + * in tone() is one index into it however wide it is. Rebuilding it when a QUANTISED * mix changes puts them on one frame in every four hundred — the clock runs a 420 s cycle and * there are 32 steps across it, so the rebuild happens about once every thirteen seconds, costs * about a millisecond, and lands inside a 16 ms budget with room to spare. @@ -501,7 +706,7 @@ var CC = (function () { * night and 3.20% at noon: the one hour with both neon AND a bright sky in it was the dimmest * frame of the three. * - * Squaring the mix for the four SOURCE swatches holds them near their night gains until the mix + * Squaring the mix for the SOURCE swatches holds them near their night gains until the mix * passes about 0.6 and then drops them quickly, which is the shape the eye expects and the shape * that keeps a lit sign lit through dusk. */ function ladder(c, mix, sunMix) { @@ -516,13 +721,28 @@ var CC = (function () { * printed ceiling UNDER the 170 the census counts as a highlight, so no amber cell in the frame * could be hot however bright it was written. The measurement said 0.38% of cells hot at dusk * against 8.02% at night. Squared on top, because even direct sun takes a while to beat a neon - * sign at close range. */ - var src = (c === 0 || c === 1 || c === 8 || c === 9); // amber azure warm ice + * sign at close range. + * + * THE TEST FOR MEMBERSHIP IS "DOES IT EMIT", not "is it bright" and not "is it an accent". The + * three swatches added here are the signage half of the extension — jade is transit livery and + * planting light, rose is a tube, gold is the lamp housing and the lit frame around one — and + * they are the same physical object as amber and azure at a different hue, so they hold their + * gain through dusk on the same curve for the same reason. The other five are SURFACES and + * blend on the sky: stone, timber, sand, moss and indigo are concrete, board, dust, planting + * and shade, and every one of them starts being lit by the sky at first light, hours before + * there is a sun to lift it. Put a surface on the sun curve and it stays at its night gain + * through the whole of dawn — the wall goes bright only after the sky already has, which is + * the dusk fault above running backwards. */ + var src = (c === 0 || c === 1 || c === 8 || c === 9 || + c === 15 || c === 16 || c === 17); // amber azure warm ice + jade rose gold var m = src ? sunMix * sunMix : mix; return EXPOSURE[c] + (EXPOSURE_DAY[c] - EXPOSURE[c]) * m; } - // LUT[(bucket*12 + colour)*256 + lum] -> printed lum. 24 KB, rebuilt only when the day step moves. + // LUT[(bucket*PALETTE.length + colour)*256 + lum] -> printed lum. 40 KB, rebuilt only when the + // day step moves. The stride was written out as a literal 12 and is now read off the palette, + // because the palette grew and a stride that disagrees with it does not fail — it silently prints + // every swatch through some other swatch's curve. var LUT = new Uint8Array(DBUCKETS * PALETTE.length * 256); function buildLUT(mix, sunMix) { var np = PALETTE.length, t = LUT; diff --git a/src/elements/market.js b/src/elements/market.js index 470452e..c77d59a 100644 --- a/src/elements/market.js +++ b/src/elements/market.js @@ -55,7 +55,7 @@ G_8 = CC.g('8'), G_0 = CC.g('0'), G_HASH = CC.g('#'), G_X = CC.g('X'), G_M = CC.g('M'), G_W = CC.g('W'), G_o = CC.g('o'), G_COLON = CC.g(':'), G_COMMA = CC.g(','), G_DOT = CC.g('.'), G_QUOTE = CC.g("'"), - G_TICK = CC.g('`'); + G_TICK = CC.g('`'), G_V = CC.g('V'), G_UNDER = CC.g('_'); /* Blocky only. Anything with holes in it dithers instead of massing at this cell size — the * same table street.js keeps, for the same reason. */ @@ -402,11 +402,20 @@ * lit ember cells in horizontal slabs across the right of the frame, which is a garnish being * asked to be a pillar. spring keeps its 12%: it is the draw that stops a row of stalls reading * as one repeated stall, and it is small enough on screen to be affordable. */ + /* JADE TAKES FOUR POINTS OUT OF SPRING AND NOTHING OUT OF EITHER PILLAR, which is the only way + * a swatch gets added to this roll. spring 12% -> 8%: the paragraph above says spring's job is + * "the draw that stops a row of stalls reading as one repeated stall", and jade does exactly + * that job at a different hue — a teal strip light over a fish counter — so the two are + * interchangeable for the purpose and the pair still totals 12%. amber's 60 and azure's 14 are + * untouched, which is what the pillar census requires; ember and warm keep their 7 each. + * jade's night ceiling is 134, under both pillars and under ember and warm, so it cannot become + * the loudest object on the pavement however many stalls it lands on. */ function counterHue(r) { if (r < 0.60) return P.amber; if (r < 0.74) return P.azure; if (r < 0.81) return P.ember; - if (r < 0.93) return P.spring; + if (r < 0.89) return P.spring; + if (r < 0.93) return P.jade; return P.warm; } /* Vending machines are the other way round: a machine is a backlit screen, so azure still leads. @@ -419,11 +428,22 @@ if (r < 0.92) return P.spring; return P.ember; } + /* Every entry is the lum that lands this swatch at v 130-165 on core.js's night curve, which is + * the band the header argues for: above the muddy top and under the hot line. The three added + * here are the ones this file can now be handed and they are all at the bottom of their own + * range because all three are DARK PIGMENTS — jade's ceiling is 134, rose's 131, gold's 157 — + * so each needs a large lum to reach a modest value, and a default of 165 would have printed + * jade at v 115 and rose at black. rose in particular is not a mistake to write at 250: core.js + * crushes every rose cell under lum 96 to zero, so near-full-scale is the only place the swatch + * exists at all, and it still cannot pass v 131. */ function litLum(col) { if (col === P.azure) return 96; if (col === P.warm) return 152; if (col === P.spring) return 155; if (col === P.violet) return 228; + if (col === P.jade) return 240; // v 132, the top of what teal can do + if (col === P.rose) return 250; // v 130, and it can never be hot + if (col === P.gold) return 178; // v 137 return 165; // amber and ember } @@ -498,6 +518,36 @@ * the canopy's coverage for no shape at all. */ panel(f, axis, a0 - 0.45, a1 + 0.45, fas, 2.26, 2.54, 0, P.shadow, 0, 0, 0, sd); panel(f, axis, a0 - 0.45, a1 + 0.45, cnt, 2.30, 2.50, 0, P.shadow, 0, 0, 0, sd); + /* ---- THE CANVAS VALANCE, and it is the only lit cell on the canopy ------------------------ + * The canopy is deliberately a black cut-out — the paragraph above is right that a silhouette + * is the whole read at thirty metres and costs the print nothing. What it never had is any + * indication of WHAT the canopy is made of, and a market canopy is canvas: the one object at + * street level whose material is not concrete, glass or a light. + * + * One row of glyph along the fascia's lower edge, lit from underneath by the strip light two + * courses down — which is where a real awning's only light comes from, and is why this is the + * bottom edge and not the top. Dashed at roughly half duty so it reads as a scalloped hem + * rather than as a rule, and because half the cells is half the cost. + * + * THE THREE SWATCHES ARE THE POINT AND THEY ARE ALL SURFACE SWATCHES. moss is "canvas" by + * name, timber is a weathered board hem, sand is the same canvas gone pale in the sun. None of + * them can clear the muddy band at night — their night ceilings are 94, 111 and 138 — and that + * is exactly right here: a canvas awning lit from below is DARKER than the counter under it, + * and a valance that outprinted the strip light would invert the whole object. Written at lums + * that land v 89 / 101 / 126, i.e. under litLum's dimmest counter (azure, v 128) in every + * case. Rolled once per RUN, because one market's awnings are one bolt of cloth. + * + * NOTHING HERE VARIES WITH TIME. It is a static material on a static object; the flicker gate + * has nothing to measure. */ + var cvs = hash2(3, 0, sd + 313); + var cvh = cvs < 0.44 ? P.moss : (cvs < 0.78 ? P.timber : P.sand); + /* 2.10-2.24, i.e. STRICTLY UNDER the fascia's 2.26 and not overlapping it. That is not a + * layout preference, it is the depth test: the valance sits on the fascia's own plane, so a + * cell it shares with the black fascia is at exactly the same distance, CC.put wants a strict + * improvement, and the fascia — which draws first — keeps it. Written overlapping at first and + * it printed nothing at all, silently, which is this file's own documented failure mode. */ + panel(f, axis, a0 - 0.45, a1 + 0.45, fas, 2.10, 2.24, + cvs < 0.5 ? G_V : G_UNDER, cvh, cvh === P.sand ? 200 : 214, 22, 1, sd + 313); /* THE STRIP LIGHT. One row of glyph, the full length of the run, and it is the long horizontal * that carries the perspective. It is drawn at the counter plane rather than at the fascia so @@ -695,8 +745,15 @@ * of cells. The colour is an independent draw from the hatch's — sharing one roll between the * sign and the counter welds every violet-signed kiosk to one counter colour, which is the bug * this repo has now found three times. */ + /* ROSE JOINS VIOLET HERE AND NOWHERE ELSE IN THIS FILE, and the argument is the paragraph + * above with one swatch substituted. This is a TWO-CELL sign — the smallest lit object the + * file paints — and rose's whole licence is "signage and screens only, small cells, low gain". + * Two cells on one kiosk in eight is about as small as a cell count gets, and core.js's + * ceiling of 131 means the pair cannot clear the hot line or take the bloom with them however + * they are written. Taken out of azure's share rather than out of amber's, because amber is + * the pillar this file's own census says the frame is short of. */ var sr = hash2(2, 0, sd + 211); - var shue = sr < 0.17 ? P.violet : (sr < 0.60 ? P.amber : P.azure); + var shue = sr < 0.17 ? P.violet : (sr < 0.29 ? P.rose : (sr < 0.60 ? P.amber : P.azure)); var slum = litLum(shue); pcell(f, axis, along - 0.22, face, 1.74, G_0, shue, slum, 1); pcell(f, axis, along + 0.22, face, 1.74, G_0, shue, slum * 0.9, 1); diff --git a/src/elements/moon_craft.js b/src/elements/moon_craft.js index edd2979..155e22b 100644 --- a/src/elements/moon_craft.js +++ b/src/elements/moon_craft.js @@ -104,7 +104,8 @@ G_DOT = CC.g('.'), G_COLON = CC.g(':'), G_STAR = CC.g('*'), G_PLUS = CC.g('+'), G_HASH = CC.g('#'), G_PCT = CC.g('%'), G_8 = CC.g('8'), G_O = CC.g('O'), G_o = CC.g('o'), G_0 = CC.g('0'), - G_SLASH = CC.g('/'), G_BACK = CC.g('\\'), G_CARET = CC.g('^'); + G_SLASH = CC.g('/'), G_BACK = CC.g('\\'), G_CARET = CC.g('^'), + G_COMMA = CC.g(','), G_QUOTE = CC.g("'"), G_TICK = CC.g('`'); var CITY = null, BASE = 0, MOON = null; @@ -207,6 +208,9 @@ if (CITY === BOOTED) return; BOOTED = CITY; BASE = CITY ? ((Math.imul(CITY.seed | 0, 19391) >>> 6) & 0x3fffff) : 0; + /* The layout bearing, resolved once per rebuild — see the block above. -0.5 is daylight.js's + * own AZ_NOON and is only the fallback for a standalone require() with no director loaded. */ + LAY_AZ = Math.PI + (CC.Daylight ? CC.Daylight.AZ_NOON : -0.5); sN = 0; if (CITY) siteScan(CITY); } @@ -226,6 +230,48 @@ * background is lum 0 a bright cell that switches is a step of 90% of full scale. */ var KX = 0, KZ = 1, KALT = 0.25, KNIGHT = 0, KDAY = 1, KMIX = 0; + /* ---- THE BEARING EVERYTHING WAS LAID OUT ON, AND IT DOES NOT TURN ----------------------------- + * Every object in this file is placed relative to its site anchor on a bearing, and every one of + * those bearings used to be `Math.atan2(KX, KZ)` — the LIVE sun. The intent is right and is worth + * keeping: the crews put the flag where the television camera would see it, parked the rover + * down-sun, and set the LM down with the crew compartment toward the light, so the layout of a + * landing site genuinely is oriented on the sun. What is wrong is the tense. The sun that decided + * where a flag was planted is the sun of the moment it was planted, and it is over and done with; + * reading the live one makes the entire site — LM, flag, rover, ALSEP, retroreflector, television + * camera and every wheel track — SLOWLY ROTATE about its anchor for the whole seven-minute day. + * + * That is wrong as a picture and it is much worse than that as a photosensitivity hazard, which + * is how it was found. Rotating the hardware moves every face by a fraction of a cell each frame, + * and quad()'s terminator dither is keyed on position along the face — so the dither RE-DEALS + * continuously and cells of gold foil at printed v 190 alternate against a lum-0 sky. Measured + * with the camera pinned and the daylight clock RUNNING (which is the thing the shipped gate does + * not do — see the note below), seed 42, 120x40: the LM alone produced a worst cell making 33 + * big steps a second against the project's 1.0/s ceiling, and 6.3% in the 3-20 Hz band against + * 2%. With the layout bearing frozen it is 0.00/s and 0.8%, which is the world pass's own floor. + * + * THE FROZEN BEARING IS THE SUN'S BEARING AT LOCAL NOON, AND IT IS NOT PI. AZ_OFFSET is an + * offset ADDED to the director's azimuth, not the answer: surf_moon.js computes SUN_AZ from + * D.P.az + AZ_OFFSET, and daylight.js's az is AZ_NOON + AZ_SWING * -cos(...), which at the noon + * stop is exactly AZ_NOON = -0.5. So noon on the Moon is PI - 0.5 = 2.6416, and PI corresponds + * to D.P.az = 0 — a phase the clock passes through between the noon and afternoon stops and + * never stops at. Measured at the six stops, SUN_AZ runs 1.302 (dawn), 1.601 (morning), 2.642 + * (noon), -2.601 (afternoon), -2.302 (dusk). The previous round froze this at PI and wrote "PI + * is the sun's noon bearing" next to it, which laid every site out 0.50 rad — 29 degrees — off + * the composition the paragraph claimed. Freezing it is still right, and the arithmetic for + * WHERE now matches what it says. + * + * WHAT STILL READS THE LIVE SUN, and must: faceSun (which face is lit), shadowPatch (where a + * shadow lies), and drawRetro's `saz` (where a corner cube throws its flare). Those are lighting, + * and lighting is the present tense. + * + * IT IS DERIVED AND NOT WRITTEN DOWN, because the last time it was written down it went stale. + * AZ_NOON is read off the director; the PI is surf_moon.js's AZ_OFFSET, which that file does not + * export, so it is the one number here that is a copy — and if it ever stops being PI over there + * this line is where the site quietly rotates. Refreshed in boot() rather than at module load, + * because element files are evaluated before anything has been initialised and a `CC.Daylight` + * captured at load time is whatever the script order happened to leave. */ + var LAY_AZ = Math.PI - 0.5; + function key() { if (!MOON) MOON = CC.SurfMoon || (CC.SURFACES ? CC.SURFACES.moon : null); if (!MOON) return; @@ -647,6 +693,121 @@ var LM_HW = 2.11; // half the descent stage across the flats var LM_D0 = 1.50, LM_D1 = 4.73; // descent stage: floor 1.5 m up, 3.23 m tall + /* ---- THE BLAST SCOUR --------------------------------------------------------------------------- + * The one mark on this world that only a landing makes. A descent engine at touchdown is a + * 45 kN rocket a metre and a half off the ground with no air to spread its plume, so it does not + * dig a crater — it SWEEPS, radially and almost horizontally, and it blows the loose upper fines + * clean off a disc twenty metres across. What is left is the packed, unweathered material + * underneath, which is markedly paler than the surface around it, striated along the radials the + * gas went out on, and it is the first thing you see in every Apollo photograph taken from the + * ladder: a bright halo with the vehicle's own black shadow lying across it. + * + * surf_moon.js's header names this as the one item of the design it could not do: "blast scour + * keyed to a `site` lot anchor cannot be drawn by floorTex, which is handed nothing but two world + * coordinates. moon_lm.js has the anchor and should draw its own scour." This is that. + * + * IT IS A DENSITY, NOT A FILL. Everything on this ground carries its tone in coverage rather than + * in luminance, and the scour is the same: it raises the fines density and leaves the swatch and + * the luminance alone. Drawn as a fill it would be a white disc on a grey plain, which is a + * searchlight; drawn as a density it is the same regolith with less of it missing. + * + * IT HAS NO EDGE. The coverage tapers as (1 - r/R) squared all the way to zero at the rim, so + * there is no radius at which anything switches — which is both what a scour looks like (the + * plume ran out of momentum, it did not stop) and what keeps a 20 m disc of raised luminance off + * the flicker census entirely. + * + * THE STRIATIONS use the same diamond-angle trick as surf_moon.js's ejecta rays and for the same + * reason: this runs over a few hundred ground cells and an atan2 in it buys a number that is + * immediately floored into one of thirty-odd sectors. They are feathered at the sector edges, so + * the scour has radial STRUCTURE without radial LINES. + * + * It writes kind 2, not kind 3, so the LM's own shadow — drawn immediately after — still lands on + * it. A scour with the vehicle's shadow missing from it is the one way to get this wrong. */ + var SCOUR_R = 11.5; + + /* The ground's own swatch, which is surf_moon.js's litSet written out a third time. THAT IS A + * DEFECT AND IT IS IN THE REPORT — moon_ground.js carries the second copy and says so — but what + * the copy has to preserve is the finding rather than the code: core.js's tone() retires its + * gamma lift across eight depth buckets on FOG_START 12 / FOG_END 125 whatever world is drawing, + * so with no fog to hide it a `white` cell loses 65% of its print by 120 m and a `pure` cell 34%. + * Near field white, far field pure with a ramp that cancels the bucket, crossover dithered so the + * eye sees drifting texture rather than a ring, and azure at a twelfth of the drive at night. */ + var SC = { col: 0, lum: 0 }; + function fineOf(base, dist, hv) { + var far = dist >= 40 || (dist > 24 && hv > (40 - dist) / 16); + var dark = KNIGHT > 0.5 || (KNIGHT > 0 && hv < KNIGHT); + if (!far) { + if (dark) { SC.col = base > 0.72 ? P.pure : P.azure; SC.lum = (base > 0.72 ? 52 : 44) + 26 * base; } + else { SC.col = P.white; SC.lum = (150 + 62 * base) * (1 - 0.20 * KMIX); } + return SC; + } + SC.col = dark ? P.azure : P.pure; + SC.lum = (dark ? (dist < 125 ? 70 + dist * 0.62 : 60) : (dist < 125 ? 96 + dist * 0.62 : 88)) * + (0.90 + 0.26 * base); + return SC; + } + + function blastScour(f, cx, cz, salt) { + var w0 = seeAt(cx, cz, 1.0); + if (!w0) return; + /* Screen bounding box from eight points round the rim. Same treatment as shadowPatch: a point + * that fails to project is off-frame in its own direction rather than a reason to drop the + * whole patch, because the near rim of a scour the camera is standing in is behind the eye. */ + var bx0 = 1e9, bx1 = -1e9, by0 = 1e9, by1 = -1e9, k, hit = 0; + for (k = 0; k < 8; k++) { + var a = k * 0.7853981634; + if (!project(cx + Math.sin(a) * SCOUR_R, 0, cz + Math.cos(a) * SCOUR_R)) continue; + hit = 1; + if (PJ.x < bx0) bx0 = PJ.x; + if (PJ.x > bx1) bx1 = PJ.x; + if (PJ.y < by0) by0 = PJ.y; + if (PJ.y > by1) by1 = PJ.y; + } + if (!hit) return; + var x0 = Math.floor(bx0) - 1, x1 = Math.ceil(bx1) + 1; + var y0 = Math.floor(by0) - 1, y1 = Math.ceil(by1) + 1; + if (x0 < 0) x0 = 0; + if (y0 < 0) y0 = 0; + if (x1 >= V.cols) x1 = V.cols - 1; + if (y1 >= V.rows) y1 = V.rows - 1; + var top = Math.ceil(V.horizon) + 1; + if (y0 < top) y0 = top; + + for (var r = y0; r <= y1; r++) { + var w = V.eyeY * V.scale / ((r + 0.5) - V.horizon); + if (w <= 0 || w > V.far) continue; + for (var x = x0; x <= x1; x++) { + var i = r * V.cols + x; + if (f.kind[i] !== 2) continue; // not floor: hardware, a rock, the sky + if (f.dist[i] > 1e5) continue; // the caster's parallel-ray blank + var sp = ((x + 0.5) - V.colMid) / V.colK; + var px = V.ox + (V.fwx + V.rgx * sp) * w, pz = V.oz + (V.fwz + V.rgz * sp) * w; + var qx = px - cx, qz = pz - cz; + var rr = Math.sqrt(qx * qx + qz * qz); + /* Inside the footpad circle there is nothing to draw: that ground is under the descent + * stage and is about to be black anyway. */ + if (rr < 2.6 || rr > SCOUR_R) continue; + var kf = 1 - (rr - 2.6) / (SCOUR_R - 2.6); + kf = kf * kf; + var ax = qx < 0 ? -qx : qx, az = qz < 0 ? -qz : qz, sm = ax + az; + if (sm < 1e-6) continue; + var oa = qz / sm; if (qx < 0) oa = oa >= 0 ? 2 - oa : -2 - oa; + var sf = oa * 9.0, si = Math.floor(sf); sf -= si; + var e = hash2(si, 0, salt + 0x11) < 0.42 + ? (sf < 0.3 ? sf / 0.3 : (sf > 0.7 ? (1 - sf) / 0.3 : 1)) : 0; + var dens = 0.30 * kf * (0.55 + 1.25 * e); + var q = qOf(w); + var hv = hash2(Math.floor(px * q), Math.floor(pz * q), salt); + if (hv >= dens) continue; + var d = w * Math.sqrt(1 + sp * sp) * 0.99; + if (!(d < f.dist[i])) continue; + var lf = fineOf(0.62 + 0.38 * (hv / dens), d, hv); + put(f, x, r, hv < 0.34 ? G_DOT : (hv < 0.68 ? G_COMMA : G_QUOTE), + lf.col, lf.lum | 0, d, 2); + } + } + } + var LM_A1 = 6.55; // top of the crew compartment var LM_AHW = 1.17; // half the 2.34 m crew compartment var LM_PAD = 4.70; // footpad centre, metres out from the axis @@ -670,10 +831,13 @@ * roughly up-sun. That is not decoration: the LM's windows and its ladder are on the same face, * the crews photographed the vehicle down-sun almost without exception, and it means the face * the walk is looking at is the lit one rather than a black rectangle. */ - var head = Math.atan2(KX, KZ) + (hash2(k, 1, BASE + 0x81) - 0.5) * 1.5; + var head = LAY_AZ + (hash2(k, 1, BASE + 0x81) - 0.5) * 1.5; var fx = Math.sin(head), fz = Math.cos(head); // forward: the crew compartment faces this way var rx = Math.cos(head), rz = -Math.sin(head); // right + /* The scour first, then the shadow on top of it: the vehicle's own black lying across its own + * bright halo is the whole read, and drawn the other way round the shadow is scrubbed out. */ + blastScour(f, cx, cz, BASE + 0x83); shadowPatch(f, cx, cz, 4.9, 1.7, LM_A1, BASE + 0x82); /* ---- the descent stage, four faces --------------------------------------------------------- @@ -944,7 +1108,7 @@ var cx = sX[k], cz = sZ[k]; /* Beside the LM and a little forward of it, which is where every one of them was actually * planted — in shot from the LM's own television camera. */ - var b = Math.atan2(KX, KZ) + 1.15 + hash2(k, 2, BASE + 0xB0) * 0.5; + var b = LAY_AZ + 1.15 + hash2(k, 2, BASE + 0xB0) * 0.5; var px = cx + Math.sin(b) * 9.6, pz = cz + Math.cos(b) * 9.6; var w = seeAt(px, pz, 1.0); if (!w) return; @@ -952,7 +1116,7 @@ /* Which way it faces. Square to the sun, because a flag edge-on is a line and the crossbar means * it cannot turn: the crew set it where it would photograph, and photographing on this world * means down-sun. */ - var fb = Math.atan2(KX, KZ) + Math.PI * 0.5; + var fb = LAY_AZ + Math.PI * 0.5; var ex = Math.sin(fb), ez = Math.cos(fb); shadowPatch(f, px, pz, 0.5, 0.9, FLAG_POLE, BASE + 0xB1); @@ -1026,9 +1190,12 @@ * THE TRACKS ARE WORTH MORE THAN THE VEHICLE. The design brief spends a page on it and * west_range.js opens with the same sentence — empty ground rendered honestly is empty — and a * pair of rails running away across the regolith is the only converging line this part of the - * plain has. surf_moon.js draws a pair down the route centreline for the same reason; these are - * the ones that go somewhere else, and two sets of rails crossing at an angle is what turns a - * plain into a place that has been driven across. + * plain has. It is now the ONLY pair of rails in this world and that is deliberate: surf_moon.js + * used to draw a second pair down the route centreline, and because the walk follows corridor + * centrelines that pair was always dead ahead and always straight, which is what made a viewer + * call this plain a road. Those are gone; the painter's replacement is an oblique traverse that + * wanders, and it draws no rails at all. These are the rover's own, they belong to a vehicle the + * frame can see, and they stop at it. * ============================================================================================= */ var RV_LEN = 3.05, RV_TRK = 1.03, RV_WH = 0.41, RV_DECK = 0.62, RV_SEAT = 1.14; @@ -1037,7 +1204,7 @@ function drawRover(f, k) { var cx = sX[k], cz = sZ[k]; - var b = Math.atan2(KX, KZ) - 0.85 - hash2(k, 4, BASE + 0xC1) * 0.6; + var b = LAY_AZ - 0.85 - hash2(k, 4, BASE + 0xC1) * 0.6; var px = cx + Math.sin(b) * 24.0, pz = cz + Math.cos(b) * 24.0; var w = seeAt(px, pz, 1.0); if (!w) return; @@ -1046,7 +1213,7 @@ * — the dish has to be aimed at Earth and the seats have to be reachable — and which also means * the vehicle presents its long side to a walk that has the sun behind it. A rover seen end-on * is 1.8 m of nothing. */ - var hd = Math.atan2(KX, KZ) + 1.35 + (hash2(k, 5, BASE + 0xC2) - 0.5) * 0.7; + var hd = LAY_AZ + 1.35 + (hash2(k, 5, BASE + 0xC2) - 0.5) * 0.7; var fx = Math.sin(hd), fz = Math.cos(hd); var rx = Math.cos(hd), rz = -Math.sin(hd); @@ -1170,10 +1337,10 @@ for (var qq = 1; qq < st; qq++) { var tq = qq / st; /* The chevron tread, carried by WHICH GLYPH it is rather than by whether there is one. - * surf_moon.js draws its own rails the same way and says why: a rail that is only - * sometimes painted switches cells on and off against a lum-0 background as the camera - * walks, which is the hazard the windmill failed on. A continuous line of alternating - * '=' and '-' reads as a tread pattern anyway. */ + * surf_moon.js's rover traverse carries its own tread the same way and says why: a line + * that is only sometimes painted switches cells on and off against a lum-0 background as + * the camera walks, which is the hazard the windmill failed on. A continuous line of + * alternating '=' and '-' reads as a tread pattern anyway. */ emit(f, lx + Math.round(ddx * tq), ly + Math.round(ddy * tq), (qq & 1) ? G_EQ : G_DASH, col, lum, ld + (d - ld) * tq); } @@ -1184,6 +1351,89 @@ } } + /* ================================================================================ 6. THE WORK === + * WHAT A CREW LEAVES ON THE GROUND WHEN THEY ARE WORKING, and it is the smallest content in this + * world and the only content in it that is a PERSON rather than a machine. + * + * Everything else on this site is a vehicle or an experiment: big, symmetrical, deployed. What + * makes an Apollo surface photograph read as a place somebody stood is the litter — a gnomon + * planted next to a rock so the photograph has a scale and a colour reference in it, two sample + * bags dropped where they were filled, a core tube standing in the ground where it was driven, a + * film magazine tossed aside because there was nowhere to put it. None of these is bigger than a + * forearm. + * + * ---- WHY THEY ARE WORTH DRAWING AT ALL ------------------------------------------------------ + * Not for themselves — a 0.3 m object at 24 m is one cell — but for their SHADOWS. The design + * brief's failure (c) is a page on it and drawBoulders opens with the same sentence: an open + * plain with nothing of known size in it has no scale. A gnomon is 0.46 m of vertical rod, which + * at the Apollo sun throws between one and five metres of jet black; that shadow is a RULER lying + * on the ground, and it is the one on this world whose length the viewer can actually calibrate + * against, because everybody knows how tall a walking stick is and nobody knows how big a lunar + * module is. + * + * ---- AND THE GNOMON IS THE ONE PLACE THIS FILE IS ALLOWED A SECOND COLOUR -------------------- + * surf_moon.js's header lists the exceptions to the greyscale rule and names them: "the only + * saturated objects in the entire frame are man-made (gold Kapton, the flag, a red-striped + * gnomon)". The real gnomon's leg carries a photometric chart in grey steps and in blue, orange + * and green. It is drawn here as ONE cell of ember at the foot of the rod, inside 22 m only, + * because at 22 m the whole leg is under two rows and the chart and the rod are the same cell — + * and a coloured cell that appears when the walk crosses a radius is a step this world cannot + * afford, so it is faded in over 22-30 m rather than switched at 22. The flag is the world's red; + * this is a single pixel of it, once per site. + * + * ---- PLACEMENT ------------------------------------------------------------------------------ + * A work station is 12-22 m from the anchor on the LAY_AZ family of bearings, like everything + * else here, and the four objects are scattered inside three metres of it on their own hashes. + * They are drawn at every distance the site is (no LOD gate on the objects themselves) because + * they are one or two cells and a gate on one bright cell against a lum-0 background is exactly + * the hazard the ALSEP petals record above. */ + function drawStation(f, k) { + var cx = sX[k], cz = sZ[k]; + var b = LAY_AZ - 1.42 + (hash2(k, 12, BASE + 0xF0) - 0.5) * 0.8; + var rng = 12 + hash2(k, 13, BASE + 0xF1) * 10; + var wx = cx + Math.sin(b) * rng, wz = cz + Math.cos(b) * rng; + var w = seeAt(wx, wz, 0.6); + if (!w) return; + var rx = Math.cos(b), rz = -Math.sin(b), fx = Math.sin(b), fz = Math.cos(b); + + /* ---- the gnomon --------------------------------------------------------------------------- + * A gimballed rod that hangs vertical whatever the ground does, on a tripod. Drawn as its rod + * and its shadow and nothing else: the tripod legs are 0.3 m and there is no distance at which + * three of them are more than the one cell the rod already owns. */ + shadowPatch(f, wx, wz, 0.16, 0.30, 0.46, BASE + 0xF2); + column(f, wx, wz, 0.06, 0.46, G_PIPE, P.pure, rimLum(0.9), 0); + /* The photometric chart, faded in over 30-22 m rather than switched — see the block comment. */ + if (w < 30 && project(wx, 0.10, wz)) { + var kc = w < 22 ? 1 : (30 - w) / 8; + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, P.ember, + (KDAY * 176 + KNIGHT * 76) * kc, PJ.d); + } + + /* ---- the core tube, driven and left standing ------------------------------------------------ + * Aluminium, 0.4 m proud of the ground and leaning the way it was hammered. Its own shadow is + * what says it is standing up rather than lying down. */ + var tx = wx + rx * 1.9 - fx * 0.7, tz = wz + rz * 1.9 - fz * 0.7; + shadowPatch(f, tx, tz, 0.10, 0.22, 0.40, BASE + 0xF3); + column(f, tx, tz, 0.0, 0.40, G_PIPE, P.pure, rimLum(0.6), 0); + + /* ---- two sample bags, and one film magazine ------------------------------------------------- + * Teflon bags of dirt, dropped where they were filled, and a magazine of exposed film that came + * off the camera and did not go back on. They are one cell each and they are white — the only + * white objects on a grey plain — with a blank down-sun of each, which is the entire reason to + * draw an object 0.2 m across at all: the pairing of a pale cell and a dark one is a THING, + * and a pale cell on its own is a grain of regolith. */ + var s, sx2, sz2; + for (s = 0; s < 3; s++) { + var ha = hash2(k * 5 + s, 14, BASE + 0xF4), hb = hash2(k * 5 + s, 15, BASE + 0xF5); + sx2 = wx + (ha - 0.5) * 5.2 + rx * 0.6; + sz2 = wz + (hb - 0.5) * 5.2 + rz * 0.6; + if (project(sx2, 0.11, sz2)) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), s === 2 ? G_o : G_8, + P.pure, rimLum(0.3 + 0.5 * ha), PJ.d); + shadowPatch(f, sx2, sz2, 0.09, 0.16, 0.20, BASE + 0xF6 + s); + } + } + /* ================================================================================================ * 4. ALSEP — the Apollo Lunar Surface Experiments Package * @@ -1212,7 +1462,7 @@ var cx = sX[k], cz = sZ[k]; /* Down-sun of the LM and off to one side, which is where they went: the crew walked away from * the vehicle with the sun behind them so they could see the ground they were putting it on. */ - var b = Math.atan2(KX, KZ) + Math.PI + 0.55 + (hash2(k, 7, BASE + 0xD0) - 0.5) * 0.9; + var b = LAY_AZ + Math.PI + 0.55 + (hash2(k, 7, BASE + 0xD0) - 0.5) * 0.9; var rng = 34 + hash2(k, 8, BASE + 0xD1) * 18; var stx = cx + Math.sin(b) * rng, stz = cz + Math.cos(b) * rng; @@ -1305,7 +1555,7 @@ * The kk*kk shapes the ramp so that most of the nine seconds is spent dark and the flare is a * sharp event at the end of it, which is what a corner-cube array does. */ function drawRetro(f, k, cx, cz) { - var b = Math.atan2(KX, KZ) + 2.35 + (hash2(k, 10, BASE + 0xE0) - 0.5) * 0.7; + var b = LAY_AZ + 2.35 + (hash2(k, 10, BASE + 0xE0) - 0.5) * 0.7; var px = cx + Math.sin(b) * 17.0, pz = cz + Math.cos(b) * 17.0; var w = seeAt(px, pz, 1.0); if (!w) return; @@ -1333,7 +1583,7 @@ * FURNITURE in the world — everything else here is either a spacecraft or knee-high — and it is * what tells the eye how big the LM behind it is. */ function drawTV(f, k, cx, cz) { - var b = Math.atan2(KX, KZ) - 1.9 + (hash2(k, 11, BASE + 0xE8) - 0.5) * 0.6; + var b = LAY_AZ - 1.9 + (hash2(k, 11, BASE + 0xE8) - 0.5) * 0.6; var px = cx + Math.sin(b) * 14.0, pz = cz + Math.cos(b) * 14.0; var w = seeAt(px, pz, 1.0); if (!w) return; @@ -1394,6 +1644,7 @@ }; } + CC.ELEMENTS.push(mk('moon-station', 18, drawStation)); CC.ELEMENTS.push(mk('moon-alsep', 19, drawALSEP)); CC.ELEMENTS.push(mk('moon-flag', 20, drawFlag)); CC.ELEMENTS.push(mk('moon-rover', 21, function (f, k) { if (hasRover(k)) drawRover(f, k); })); diff --git a/src/elements/moon_ground.js b/src/elements/moon_ground.js index 5514d1f..d9fe2fa 100644 --- a/src/elements/moon_ground.js +++ b/src/elements/moon_ground.js @@ -839,7 +839,32 @@ * the +x one) and `off` is how far this cell is from the trail's centreline; everything below is * in those two coordinates and knows nothing about which traverse it belongs to. `salt` separates * the two hash streams so the two trails do not print the same sequence of prints. */ + /* ---- A CREW DOES NOT MARCH ------------------------------------------------------------------ + * The trail as it stood was continuous from one end of the frame to the other: an unbroken double + * line of prints, every stride accounted for, running the whole 72 m of PRINT_FAR. That is a + * procession, and it was the other half of what made this world read as having a ROAD — the eye + * does not care that the line curves if it never stops. + * + * What an EVA actually leaves is intermittent. The crew walk somewhere, mill about while one of + * them photographs, detour to a rock, come back on a slightly different line, and cross forty + * metres of untouched ground on the way to the next station. So the trail is cut into 9.4 m + * segments and 58% of them carry prints; the rest are ground nobody stepped on. + * + * 9.4 m IS THIRTEEN STRIDES and the number matters. At 4 m the trail reads as a dashed line, + * which is a road marking and worse than what it replaced. At 30 m the gaps are longer than the + * part of the trail the frame can hold and the whole thing is present or absent per walk. Thirteen + * strides is long enough to read as a stretch of walking and short enough that a single frame + * usually holds two of them with a gap between. + * + * A GAP IS SAFE, which is the thing to check before cutting anything on this world. The mask is a + * function of world position and the seed alone — no camera, no time — so a cell either is or is + * not inside a walked segment for as long as the map exists. Nothing switches. */ + function walked(along, salt) { + return hash2(Math.floor(along / 9.4), 0, BASE + salt + 0x0A) < 0.58; + } + function printAt(f, x, y, d, along, off, salt) { + if (!walked(along, salt)) return; if (d > PRINT_NEAR) { /* The continuous far strip. Always painted, so no cell it owns can ever switch. */ if (off < -0.34 || off > 0.34) return; @@ -904,11 +929,54 @@ var o1 = GP.wx - trailX(GP.wz); if (o1 > -0.8 && o1 < 0.8) { printAt(f, x, y, d, GP.wz, o1, 0x50); continue; } var o2 = GP.wz - trailZ(GP.wx); - if (o2 > -0.8 && o2 < 0.8) printAt(f, x, y, d, GP.wx, o2, 0x60); + if (o2 > -0.8 && o2 < 0.8) { printAt(f, x, y, d, GP.wx, o2, 0x60); continue; } + millAt(f, x, y, d, GP.wx, GP.wz); } } } + /* ---- THE MILLING PATCHES --------------------------------------------------------------------- + * The other thing a crew leaves, and the one that says most about what they were doing: a ROUND + * patch of churned ground three or four metres across, with no line to it, where somebody stood + * and turned round and set a camera down and picked it up again. Every Apollo station photograph + * has one and it is the most human mark on the surface — a trail says a route, a milling patch + * says a person. + * + * On a 34 m lattice at 26% occupancy, radius 1.6-4.4 m, jittered off the lattice cell so the + * spacing does not read. Inside one, prints are scattered on a 2D hash rather than laid out on a + * stride: nobody walks in a circle, they shuffle. Coverage falls off toward the rim (the middle is + * where the boots were) so the patch has no edge, which is both what it looks like and what keeps + * it off the flicker census — an edgeless world-locked feature has nothing to switch. + * + * NEAR FIELD ONLY, at PRINT_NEAR. A milling patch past 20 m is a handful of cells that the strip + * treatment cannot help, because it has no length to be continuous ALONG. */ + var MILL_LAT = 34.0; + + function millAt(f, x, y, d, wx, wz) { + if (d > PRINT_NEAR) return; + var mi = Math.floor(wx / MILL_LAT), mj = Math.floor(wz / MILL_LAT); + var hm = hash2(mi, mj, BASE + 0x70); + if (hm > 0.26) return; + var cx = (mi + 0.2 + 0.6 * hash2(mi, mj, BASE + 0x72)) * MILL_LAT; + var cz = (mj + 0.2 + 0.6 * hash2(mi, mj, BASE + 0x73)) * MILL_LAT; + var rr = 1.6 + 2.8 * (hm / 0.26); + var dx = wx - cx, dz = wz - cz; + var rd = Math.sqrt(dx * dx + dz * dz); + if (rd > rr) return; + var k = 1 - rd / rr; // 1 at the centre, 0 at the rim + var hp = hash2(Math.floor(wx * 7), Math.floor(wz * 7), BASE + 0x74); + if (hp > 0.30 + 0.40 * k) return; + /* Same object as one print of the trail and drawn the same way round: a compacted dark core + * with a bright collar. Here the two are dithered against each other rather than laid out, + * because at 14 cm of lattice a shuffled patch has no stride to hang them on. */ + if (hp < 0.09) { + emit(f, x, y, hp < 0.03 ? G_DOT : 0, P.slate, hp < 0.03 ? 20 + hp * 300 : 0, d * 0.996); + return; + } + var lm = litOf(0.72 + hp * 0.28, d, hp); + emit(f, x, y, hp < 0.19 ? G_UNDER : (hp < 0.26 ? G_COLON : G_DOT), lm.col, lm.lum, d * 0.996); + } + /* ============================================================================= 6. BOULDERS === * THE SHADOWS ARE THE OBJECT. A rock on a scaleless grey plain is a grey blob on a grey plain; the * same rock with seven metres of jet black lying beside it is a rock of known height, on ground of @@ -951,6 +1019,21 @@ * walk goes, which is what a much-driven landing site looks like. */ var BLD_LAT = 4.2, BLD_R = 92.0, BLD_P = 0.46; + /* The block-field modulation. Bilinear over nine boulder-lattice cells, i.e. 37.8 m, smoothstepped + * on both axes so the field has no crease anywhere and no visible tile. Returns 0.20..1.80 with a + * mean of 1, so the boulder count over any large patch is exactly what it was and only its + * DISTRIBUTION has changed. */ + function bldField(i, j) { + var qx = i / 9, qz = j / 9; + var i0 = Math.floor(qx), j0 = Math.floor(qz); + var fx = qx - i0, fz = qz - j0; + fx = fx * fx * (3 - 2 * fx); fz = fz * fz * (3 - 2 * fz); + var a = hash2(i0, j0, BASE + 0x6D), b = hash2(i0 + 1, j0, BASE + 0x6D), + c = hash2(i0, j0 + 1, BASE + 0x6D), d = hash2(i0 + 1, j0 + 1, BASE + 0x6D); + var ab = a + (b - a) * fx; + return 0.20 + 1.60 * (ab + ((c + (d - c) * fx) - ab) * fz); + } + function drawBoulders(f) { if (!CITY) return; var lo0 = Math.floor((V.ox - BLD_R) / BLD_LAT), hi0 = Math.floor((V.ox + BLD_R) / BLD_LAT); @@ -963,7 +1046,18 @@ for (j = lo1; j <= hi1; j++) { for (i = lo0; i <= hi0; i++) { var h = hash2(i, j, BASE + 0x61); - if (h > BLD_P) continue; + /* ---- AND THEY COME IN FIELDS ---------------------------------------------------------- + * A flat 46% over a 4.2 m lattice is a boulder every nine square metres EVERYWHERE, which + * is a gravel bed, not a mare surface. Real ejecta lies in patches: a block field round the + * rim of the crater that threw it, and bare regolith between the fields. So the occupancy + * is modulated by a bilinear field on a 9-cell (38 m) lattice, running 0.20 to 1.80 of the + * nominal rate — bare stretches at 9% and block fields at 83%, mean unchanged at 46%. + * + * 38 m and not the swell's 54: the two must NOT be commensurate, or every block field + * lands on the same crest as every drift of fines and the whole plain acquires one + * frequency. Bilinear rather than per-cell for the reason every other lattice in this + * project is — a hard cell puts visible 38 m tiles on the ground. */ + if (h > BLD_P * bldField(i, j)) continue; var px = (i + 0.12 + 0.76 * hash2(i, j, BASE + 0x62)) * BLD_LAT; var pz = (j + 0.12 + 0.76 * hash2(i, j, BASE + 0x63)) * BLD_LAT; /* Behind the eye plane or out past the field radius: the cheapest two rejects, first. */ @@ -982,6 +1076,28 @@ if (da < clr) continue; var dc = pz - (CITY.crossZ(kc) + 0.5); if (dc < 0) dc = -dc; if (dc < clr) continue; + /* ---- THE EDGE OF THE CLEARED LANE IS FEATHERED, AND ONLY OUTWARD ---------------------- + * The two tests above are exact rectangles centred on the route lattice, so what they leave + * on the ground is a swept corridor with a DEAD STRAIGHT EDGE running the length of every + * avenue and every cross street in the world. On a plain with nothing else straight in it + * that reads as a kerb — a line of absence is as much a line as a line of paint, and this + * one is axis-aligned and infinite. It is the last surviving artefact of the street lattice + * on this world and it is the thing the map spent a whole pass hiding. + * + * The repair is a probabilistic taper outside the hard clearance: a boulder between clr and + * clr+fw survives with probability (da-clr)/fw, so the field thins into the lane over four + * metres or so instead of stopping at a line. The width itself wanders on a 44 m noise, so + * the OUTER edge of the taper is not straight either. + * + * IT CAN ONLY EVER REMOVE A BOULDER. The hard clearance above is untouched and is still the + * thing that keeps a three-metre rock out of the camera's path; this runs after it and + * subtracts. A version that let the wobble push the clearance inward was written first and + * thrown away — the whole safety argument for that constant is that it is a floor. */ + var fh = hash2(i, j, BASE + 0x6C); + var fw = 4.2 * (0.45 + 1.1 * CC.vnoise(pz * 0.023, BASE + 0x6A)); + if (da < clr + fw && fh > (da - clr) / fw) continue; + fw = 4.2 * (0.45 + 1.1 * CC.vnoise(px * 0.023, BASE + 0x6B)); + if (dc < clr + fw && fh > (dc - clr) / fw) continue; var sd = (BASE + i * 7919 + j * 104729) & 0x3fffff; drawShadow(f, px, pz, r, sX, sZ, tanA, sinA, sd); @@ -1255,8 +1371,282 @@ } } + /* =========================================================== 7. THE SHADOWS THE GROUND CASTS === + * THE SINGLE LARGEST LEGIBILITY LEVER ON THIS WORLD, and until this pass nothing drew it. + * + * Every Apollo landing was flown at a sun between 5 and 25 degrees, and the reason is one + * sentence: with no air, no aerial perspective and no vegetation, THE ONLY WAY TO READ RELIEF ON + * A REGOLITH PLAIN IS THE LENGTH OF ITS SHADOWS. A crew standing on a rise at local noon cannot + * tell it is on a rise. surf_moon.js's floor already knows this — it is why the whole file exists + * in shades of coverage rather than of luminance — but it is handed two world coordinates and + * cannot see a metre in any direction, so the one thing it can never draw is the shadow of + * something ELSE. + * + * This element can, because it has the map. city.js puts up to 2.8 m of rolling relief on every + * non-street lot on the Moon, plus rock piles to 5.4 m and crater rims. + * + * ---- HOW ------------------------------------------------------------------------------------ + * For each floor cell the caster has already painted, inverse-project it (groundAt, which recovers + * the caster's own forward depth out of the depth buffer and is therefore exact), then march the + * SUN RAY back from that point: at u metres toward the sun the ray is u*tan(alt) above the ground, + * so any terrain higher than that blocks it. What comes out is `k`, a coverage in 0..1 — how much + * of this cell's regolith the terrain up-sun of it has taken. + * + * ---- THE BLOCKER FIELD IS NOT city.height, AND THAT IS THE PHOTOSENSITIVITY FIX -------------- + * The first cut of this pass read CITY.height directly at each sample, and it was the largest + * in-band flicker source on the world. The mechanism is worth writing out because it is not + * obvious and it is general. + * + * CITY.height is PIECEWISE CONSTANT: it floors its arguments to a metre and a whole lot shares + * one slab. The march's sample points are `s * reach / n` metres along (sX,sZ), and BOTH of those + * move continuously with the clock — `reach` off the altitude, (sX,sZ) off the bearing. So the + * sample points slide across the lattice, and a max over samples of a piecewise-constant field is + * a STEP FUNCTION OF TIME. Worse, it is a non-monotonic one: as one sample leaves a slab and the + * next enters it, `best` falls and rises again, so a cell does not switch once as a shadow edge + * passes over it — it chatters. Measured with the camera pinned and the clock RUNNING — which is + * the thing tools/west-flicker.cjs does NOT do, see the note at the registration block — the pass + * alone ran to 2.80% in the 3-20 Hz band and 0.75 big steps a second, against gates of 2% and + * 1.0/s, on a background of lum 0 where every step is most of full scale. The dithered edge below + * is no defence: it spreads the SPATIAL handover, and gives nothing at all when `best` jumps + * across zero and takes every cell of an edge in one frame. + * + * So the march reads bgSample: a BILINEAR interpolation over a 2 m lattice whose nodes are the + * max of the four metre cells under them. Bilinear over any lattice is continuous, so the sampled + * height is a continuous function of position, `best` is a continuous function of the clock, and + * a sample crossing a lot boundary ramps over the 2 m it takes to cross instead of jumping. The + * node max rather than a point sample because a lot is 7-16 m across but a crater rim is not: + * point-sampling a 2 m lattice can step over a rim ring, and a max cannot. The cost of the max is + * that every blocker is dilated by up to 2 m, which lengthens its shadow by 2 m in a field whose + * shadows are 12-28 m long. + * + * The nodes are cached direct-mapped on a 128x128 wrap, stamped per frame. The wrap is safe + * because the region a frame touches is bounded by TS_FAR + TS_REACH = 73 m, i.e. 37 nodes each + * side of the camera against the 64 the wrap allows; if TS_FAR and TS_REACH ever grow past 128 m + * between them, two different pieces of ground start sharing a slot. Measured at 400x100 noon, + * the cache turns 150,196 CITY.height calls in one drawRelief into 1,868 — and, measured on the + * clock rather than on the call count, that saving pays for the four-tap bilinear exactly: the + * pass costs 2.50 ms where the point-sampled version cost 2.49. The cache is not an optimisation + * that was wanted, it is the price of the interpolation being affordable at all. + * + * ---- THE EDGE IS DITHERED AND THEN RAMPED --------------------------------------------------- + * A lunar shadow has no penumbra — that is one of the four facts at the top of surf_moon.js — and + * a shadow edge drawn as a hard test is a line of cells switching between v 130 and lum 0 as it + * sweeps. Two remedies stacked, and the second one is what actually bought the measurement: + * + * THE DITHER, on the cell's own stable world hash, so the edge is a one-cell scatter rather + * than a line and the handover is spread over every cell of it. This is facade()'s terminator + * remedy, verbatim. + * + * THE RAMP. A dither alone still takes each individual cell from its lit luminance to zero in + * ONE frame, and on this world that is 56% of full scale. So the last TS_EDGE of the coverage + * ramp DIMS THE CELL'S OWN PAINT instead of deleting it: e runs 0..1 across the band and the + * cell is written back at lum * (1-e), so what used to be one 144-point drop is spread over the + * whole time `k` takes to sweep TS_EDGE. + * + * MEASURED, seeds 42/7/1234 at all six stops, 120x40, pinned camera, clock RUNNING, against + * gates of 1.0 big steps/s and 2% in the 3-20 Hz band. BEFORE: the pass alone ran to 2.80% in + * band and 0.75 big steps/s. AFTER, and this is the form the claim should always have taken — + * the world pass alone at the same eighteen (seed, hour) pairs measures 0.04-1.81% in band, + * 0.00-0.25/s, worst step 20.4-85.9%; with this element drawn on top of it the figures are + * 0.34-1.81%, 0.00-0.25/s, worst step 20.4-85.9%. The worst step and the big-step rate are + * IDENTICAL at every one of the eighteen or lower (the element dims cells the world pass was + * stepping), and the largest in-band increment it adds anywhere is 0.52 points. + * + * A handover cell is written back as kind 2 and not kind 3, because it is still floor and is + * only partly shaded — a bootprint may legitimately be drawn on it. Only a cell at full + * coverage becomes kind 3. + * + * ---- THE REACH IS 28 m, AND IT IS NOT 6/tan(alt) -------------------------------------------- + * The obvious reach is "far enough to catch the tallest thing on the map", i.e. 6.0/tan(alt), + * which is 12 m at the top of the Apollo band and 44 m at the bottom. It is wrong, and the render + * says so louder than any census: at the dusk and dawn stops the sun is 7.7 degrees up, a 2.8 m + * mound throws 20 m and a 5 m rock pile throws 37, shadows merge, and a camera that happens to be + * looking up-sun gets a frame with NO GROUND IN IT. Measured at seed 42, dusk, yaw 4.5 — a pose + * looking straight into the low sun — the 40 m version took 90% of the visible floor and the near + * field went black. + * + * It is worth being clear that this is not an error in the shadow arithmetic. It is what a 7.7 + * degree sun does to ground with 2.8 m of relief on it, and standing in the shade of a rock pile + * is a real thing to be doing on the Moon. It is simply not a frame, and this renderer has no + * cut to another one. The autopilot walk itself rarely gets there — over a whole 420 s day it + * never once looked at a frame that bad — but the viewer has a mouse, and "only if you do not + * look that way" is not a defence. + * + * ---- WHAT IS STILL BEARING-DEPENDENT, AND IT IS NOT GOING AWAY ------------------------------ + * The share this pass takes still swings enormously with where the camera is pointed. Measured, + * seed 42 at the start pose, share of the visible ground's light removed, over six yaws: + * dawn 0.0 0.7 51.9 73.8 40.6 6.5 % + * morning 0.0 19.3 73.6 63.0 13.8 0.0 % + * dusk 25.1 12.3 3.9 0.0 21.3 77.4 % + * That is not noise and it is not fixable here. city.js's corridors are straight, 10-20 m wide, + * flat by construction, and lie in shallow valleys because swellEdge fades the relief to zero at + * the block boundary; the walk follows those corridors, so most of the visible floor in any frame + * IS a corridor. A shallow straight valley lit ALONG its axis has no cast shadow on its floor and + * lit ACROSS it is entirely shadowed, so the answer is a function of the angle between the sun + * and the corridor. It is correct terrain behaviour on a map whose terrain has a lattice in it. + * + * The same measurement made over the OPEN GROUND rather than over a frame shows how much of the + * swing is the corridor and how much is the sun: marching this same law over a 121x121 m patch + * of flat ground at the dawn/dusk altitude, the shadowed share runs 11.4% to 26.0% over a full + * turn of the bearing — a factor of 2.3, against the frame's 0 to 77. The other factor of thirty + * is the corridor, and the only place it could be fixed is city.js. + * + * BE CLEAR ABOUT WHICH KNOB DID WHAT, because the reach is the smaller half of it. What actually + * stops the frame emptying is the RAMP and the FILL below: at the same yaw-4.5 dusk pose, the + * share of the visible ground's LIGHT this pass removes goes 86.2% before this round to 73.0% + * with the ramp and the fill in and the reach still at 40. The reach then sets how much of the + * middle of the distribution it takes. Measured over a full 420 s day of the real autopilot walk, + * sampled once a second at 140x44, seeds 42/7/3/1234, the share of the visible floor whose + * luminance the pass changes — + * reach 40 p50 0.0-0.1 p90 0.5-11.9 max 9.9-34.2 mean 0.3-2.9 + * reach 28 p50 0.0-0.1 p90 0.5- 7.5 max 9.8-33.7 mean 0.3-2.3 + * reach 18 p50 0.0-0.1 p90 0.4- 2.5 max 3.2-27.0 mean 0.1-1.3 + * (the pre-round tree, for the same walk: p90 0.7-14.4, max 14.0-36.1, mean 0.5-3.6.) + * + * 28 IS CHOSEN ON ATTRIBUTION RATHER THAN ON THE TAIL. At the worst pose 28 and 40 are within + * four points of each other (77.4% against 73.0%) and neither is the problem any more. What 40 + * buys is shadow from casters 30-40 m up-sun, and at 40 m one floor row already spans 7 m of + * ground — the caster and its shadow are never in the same part of the picture, so what arrives + * is a tonal wash the eye cannot attribute to anything. 28 m holds the day's p90 under 8% and + * still runs the full 20.6 m shadow a 2.8 m mound throws at the dusk sun. 18 was measured and + * rejected the other way: it holds the tail down by giving up the content, and an element costing + * 2.5 ms a frame has to do something with it. + * + * TS_FAR 45 m is the same argument seen down the barrel of the projection. At the reference grid + * (400x100) a floor row spans d^2/263 metres, so a 28 m shadow is 3.6 rows deep at 45 m and 1.6 + * at 68; past 45 the whole shadow is inside a row and is doing nothing the fines are not. + * + * SIX SAMPLES NEAR AND FOUR FAR, EVENLY SPACED. Geometric spacing is the obvious choice and is + * wrong: it puts three samples in the first two metres, where nothing on this map is ever tall + * enough to matter, and leaves the gaps at the far end where the mounds are. Even spacing over a + * 28 m reach gives a step of 4.7 m near and 7 m far, against blockers that are lots 7-16 m across + * on a field that has already been smoothed to a 2 m lattice — so nothing is missed. Ten and six + * were the first cut's numbers and they were sized for a 40 m reach; at 28 m they oversample the + * 2 m lattice by a factor of three and cost 15% of the pass for nothing. + * + * ---- THE FALLOFF AND THE FILL, WHICH ARE THE SAME ARGUMENT ---------------------------------- + * A shadow whose caster is 4 m away is a hole: you can see the rock and you can see its shadow, + * and the two agree. A shadow whose caster is 25 m away is not, and the reason is roughness. A + * natural crest is not a knife edge; its own sub-metre relief is smeared along the shadow by + * 1/tan(alt), which at the dusk sun is a factor of seven, so what a distant crest actually throws + * is a LACE of light and dark rather than a solid band. So the coverage a sample can contribute + * falls from 1 at TS_HARD to TS_RAG at the reach — applied INSIDE the max over samples, never to + * the winning sample's distance afterwards, because the argmax jumps between samples and a term + * keyed on it would put the step function straight back. + * + * And a cell at full coverage is not empty. Inside TS_FILL_D the shadow keeps a TS_FILL scatter + * of slate at lum 14-40 — the same swatch and the same argument as surf_moon.js's darkFace fill, + * which is light bounced off the sunlit ground around it — tapering to nothing by TS_FILL_E. + * Without it a deep shadow is a rectangle of absolutely nothing, and this world already has more + * of those than it can spend. + * + * ---- WHAT IT COSTS -------------------------------------------------------------------------- + * Measured at 400x100, seed 42 noon, best of six runs of 200 replayed frames, pinned camera, + * clock running: + * world pass alone 7.95 before / 8.06 now (untouched) + * world pass + this element alone 10.44 / 10.56 (the pass is 2.5 ms) + * moon element set WITHOUT this pass 10.67 / 10.64 (untouched) + * moon element set with everything 11.72 / 13.16 + * The pass costs the same 2.5 ms it always did. What moved is its MARGINAL cost — 1.05 ms before, + * 2.52 now — and the difference is somebody else's work: a fully shadowed cell becomes kind 3, + * drawPrints and drawBoulders both skip kind 3, so the first cut of this pass partly paid for + * itself by blacking out enough ground to make the two passes below it cheaper. Shading less + * costs more, which is not a sentence anybody expects, and it is the whole gap. The frame budget + * is 16.7 ms and the moon world sits at 13.2 on this machine; the dials if it ever has to come + * down are TS_FAR and TS_NEAR, in that order. + * + * ---- LAYER 13, BEFORE THE PRINTS AND THE BOULDERS, AND THAT IS LOAD-BEARING ------------------ + * A cell at FULL coverage is written by `emit`, so it stops being kind 2. drawPrints and + * drawShadow both gate on groundAt, which tests kind 2 — so a bootprint inside a terrain shadow + * is not drawn dim, it is not drawn at all, and a boulder's own shadow does not get rasterised + * over ground that is already dark. Both of those fall out of the ordering for free. Drawn the + * other way round, the prints would sit on top of the shadow and each one would be a print with + * its own light source. + */ + var TS_FAR = 45.0, TS_NEAR = 6, TS_FARN = 4, TS_SOFT = 0.55; + var TS_REACH = 28.0, TS_HARD = 4.0, TS_RAG = 0.18; + var TS_FILL = 0.20, TS_FILL_D = 20.0, TS_FILL_E = 45.0; + var TS_EDGE = 0.45, TS_EDGE_I = 1 / TS_EDGE; + + var BG_PITCH = 2.0, BG_INV = 1 / BG_PITCH, BG_N = 128, BG_MASK = BG_N - 1, BG_SH = 7; + var bgH = new Float32Array(BG_N * BG_N), bgS = new Int32Array(BG_N * BG_N), bgStamp = 0; + + function bgAt(gi, gj) { + var idx = ((gj & BG_MASK) << BG_SH) | (gi & BG_MASK); + if (bgS[idx] === bgStamp) return bgH[idx]; + var wx = gi * BG_PITCH, wz = gj * BG_PITCH; + var h = CITY.height(wx, wz), h2; + h2 = CITY.height(wx + 1, wz); if (h2 > h) h = h2; + h2 = CITY.height(wx, wz + 1); if (h2 > h) h = h2; + h2 = CITY.height(wx + 1, wz + 1); if (h2 > h) h = h2; + bgS[idx] = bgStamp; bgH[idx] = h; + return h; + } + + function bgSample(wx, wz) { + var qx = wx * BG_INV, qz = wz * BG_INV; + var i0 = Math.floor(qx), j0 = Math.floor(qz); + var fx = qx - i0, fz = qz - j0; + var a = bgAt(i0, j0), b = bgAt(i0 + 1, j0), c = bgAt(i0, j0 + 1), d = bgAt(i0 + 1, j0 + 1); + var ab = a + (b - a) * fx; + return ab + ((c + (d - c) * fx) - ab) * fz; + } + + var TS_UN = new Float64Array(TS_NEAR), TS_RN = new Float64Array(TS_NEAR), + TS_UF = new Float64Array(TS_FARN), TS_RF = new Float64Array(TS_FARN); + + function drawRelief(f) { + if (!CITY) return; + bgStamp++; if (bgStamp > 2000000000) { bgStamp = 1; bgS.fill(0); } + var ta = Math.tan(sunAlt()); if (ta < 0.05) ta = 0.05; + var sX = sunX(), sZ = sunZ(); + var reach = 6.0 / ta; if (reach > TS_REACH) reach = TS_REACH; + var x, y, s, u; + for (s = 0; s < TS_NEAR; s++) { + u = (s + 1) * reach / TS_NEAR; TS_UN[s] = u; + TS_RN[s] = u <= TS_HARD ? 1 : 1 - (1 - TS_RAG) * (u - TS_HARD) / (TS_REACH - TS_HARD); + } + for (s = 0; s < TS_FARN; s++) { + u = (s + 1) * reach / TS_FARN; TS_UF[s] = u; + TS_RF[s] = u <= TS_HARD ? 1 : 1 - (1 - TS_RAG) * (u - TS_HARD) / (TS_REACH - TS_HARD); + } + var y0 = Math.floor(V.horizon); if (y0 < 0) y0 = 0; + for (y = y0; y < V.rows; y++) { + var row = y * V.cols; + for (x = 0; x < V.cols; x++) { + var i = row + x; + if (!groundAt(f, x, y, i)) continue; + var d = GP.d; + if (d > TS_FAR) continue; + var near = d < 30, n = near ? TS_NEAR : TS_FARN; + var k = 0; + for (s = 0; s < n; s++) { + u = near ? TS_UN[s] : TS_UF[s]; + var rise = bgSample(GP.wx + sX * u, GP.wz + sZ * u) - u * ta; + if (rise <= 0) continue; + var c = (rise < TS_SOFT ? rise / TS_SOFT : 1) * (near ? TS_RN[s] : TS_RF[s]); + if (c > k) k = c; + } + if (k <= 0) continue; + var q = qOf(d); + var hv = hash2(Math.floor(GP.wx * q), Math.floor(GP.wz * q), BASE + 0x71); + var e = (k * (1 + TS_EDGE) - hv) * TS_EDGE_I; + if (e <= 0) continue; + if (e < 1) { + if (f.lum[i] > 0) put(f, x, y, f.ch[i], f.col[i], f.lum[i] * (1 - e), d * 0.996, 2); + continue; + } + var ff = d < TS_FILL_D ? 1 : (d > TS_FILL_E ? 0 : (TS_FILL_E - d) / (TS_FILL_E - TS_FILL_D)); + if (hv < TS_FILL * k * ff) + emit(f, x, y, hv < 0.06 ? G_DOT : G_COMMA, P.slate, 14 + hv * 130, d * 0.996); + else + emit(f, x, y, 0, P.shadow, 0, d * 0.996); + } + } + } + /* ---- registration ------------------------------------------------------------------------------- - * All six are pure functions of (world, t) with NO update(). That is the property the offline + * All seven are pure functions of (world, t) with NO update(). That is the property the offline * harness needs to scrub to any frame, and on this world it is easy to keep: nothing here has a * velocity. The only thing that changes between two frames is where CC.Daylight has put the sun, * and every element reads that fresh through surf_moon.js's getters. @@ -1265,7 +1655,20 @@ * omission. There is nothing here to damp: no sway, no drift, no phase, no spawn. What moves is * the director's clock, which belongs to daylight.js, and freezing it in one element while the * painter kept turning the same sun would light the ground and the sky from two different places. - * If the sun should stop under reduced motion, it has to stop in daylight.js. It is in the report. */ + * If the sun should stop under reduced motion, it has to stop in daylight.js — one line in its + * update(), holding the phase at the instant the flag came on exactly as `Y` already does. That + * is a request to whoever owns daylight.js and it is written out as such in the report; the + * previous round's comment said "it is in the report" about an item that was never filed, which + * is how a whole world came to ship with no reduced-motion damping and nobody downstream told. + * + * WHAT THAT COSTS TODAY, measured rather than assumed: with the clock running, camera pinned, + * 120x40, 4 s, seeds 42 and 7 at noon and dusk, THE MOON'S OWN TWELVE ELEMENTS give identical + * worst step, big-step rate and 3-20 Hz figures to the last digit with the flag on and with it + * off. It is not that the damping is working; it is that there is nothing here for the flag to + * reach. (The full moon list also carries the shared optics chain, whose exposure pass is a + * feedback loop on the frame and moves the third digit either way; that is not this file's.) + * The figures themselves pass — see the block on drawRelief — so this is a gap in the contract + * rather than a hazard. */ function mk(name, layer, fn) { return { name: name, layer: layer, world: 'moon', @@ -1289,6 +1692,10 @@ /* Bootprints BEFORE boulders, and the order is load-bearing: both write kind 2, so a boulder's * shadow falling across the trail dims and then erases the prints under it. A print you can see * inside a shadow is a print with its own light source. */ + /* Terrain shadow FIRST of the three ground passes — see the block comment on drawRelief. It + * turns the cells it owns into kind 3, and both of the passes below gate on kind 2, so the + * ordering is what stops a bootprint or a boulder's shadow being drawn inside a dark band. */ + CC.ELEMENTS.push(mk('moon-relief', 13, drawRelief)); CC.ELEMENTS.push(mk('moon-bootprints', 14, drawPrints)); CC.ELEMENTS.push(mk('moon-boulders', 15, drawBoulders)); diff --git a/src/elements/signage.js b/src/elements/signage.js index bda1502..4246a7b 100644 --- a/src/elements/signage.js +++ b/src/elements/signage.js @@ -425,6 +425,21 @@ * hue: the concrete quarter is where signs go to die (S_FAIL, S_BACKLIT, and very little that * moves), the screen district is screens and tickers, and the arcade strip is the only place * that can afford a chase border on every second building. */ + /* ---- AND THREE MORE QUARTERS, because city.js's table is nine rows now ---------------------- + * `pickStyle` reads `STYLE_W[did] || STYLE_W[0]`, so the three new districts were not failing — + * they were silently drawing SODIUM's weights, which is a graceful degradation and also means + * three quarters of the city had no sign construction of their own. Each new row is an argument + * about what that quarter's signs are MADE of, which is the same argument the six above make: + * gilt brass-framed tube and blade work over a teal-tiled parade. Almost no screens: this + * is the oldest-money quarter in the table and its signage is glass and metal, so + * TUBE and BLADE carry it and SCREEN is a 1 where the screen district has a 6 + * market the noisiest, shortest signage in the city. BLOCK (stacked character signboards) + * and MARQUEE (a row of letters over a door) between them take half the roll, because + * a market stall's sign is a painted board and a row of bulbs and nothing else. FLAP + * is high too — a departure-board split-flap is exactly a market's price list + * finance the concrete quarter's discipline with money behind it: BACKLIT above everything, + * because a bank's sign is a dark panel that lights the WALL rather than the street, + * plus tickers. No chase, no arrows, nothing that moves for attention */ var STYLE_W = [ /* TUBE BLADE CHASE WIPE TICK BLOK FLAP FAIL BACK ARRW SCRN MARQ */ /* sodium */ [ 6, 3, 3, 2, 1, 4, 2, 3, 2, 3, 1, 5], @@ -432,7 +447,10 @@ /* concrete*/ [ 3, 1, 1, 1, 1, 2, 2, 6, 5, 2, 1, 3], /* ember */ [ 4, 2, 2, 1, 1, 2, 2, 5, 2, 5, 1, 3], /* spring */ [ 3, 3, 2, 2, 2, 3, 4, 2, 3, 2, 2, 3], - /* arcade */ [ 3, 5, 6, 4, 4, 6, 3, 2, 2, 4, 5, 2] + /* arcade */ [ 3, 5, 6, 4, 4, 6, 3, 2, 2, 4, 5, 2], + /* gilt */ [ 7, 6, 3, 1, 1, 3, 2, 2, 4, 2, 1, 4], + /* market */ [ 3, 3, 4, 1, 1, 7, 5, 3, 1, 2, 1, 7], + /* finance */ [ 2, 2, 1, 2, 5, 2, 3, 3, 7, 1, 4, 3] ]; /* HOW MUCH SCREEN A CONSTRUCTION NEEDS BEFORE IT IS A CONSTRUCTION, in cells across and cells @@ -489,9 +507,38 @@ * dim emissive panel and can carry it; a saturated glass tube on a near wall blooms into the * hot magenta the whole palette exists to avoid. */ if (h === P.violet && style !== S_SCREEN && style !== S_TICKER) h = P.azure; + /* ---- ROSE, AND IT IS THE SAME GUARD FOR A DIFFERENT REASON -------------------------------- + * Violet is diverted because a big violet fixture blooms into magenta. Rose is diverted + * because of AREA, and the two are not the same argument: core.js gives rose a ceiling of 131 + * — under every pillar, under gold, under jade — so a rose fixture can never be the loudest + * thing in the frame however large it is. What it CAN be is a large pink SURFACE, and the + * house rule the swatch was licensed under is "blade signs, a bar's window tube, a strip of + * underlighting, and nothing with a large cell count". + * + * So rose is allowed on the two constructions that are thin BY GEOMETRY and nowhere else. A + * blade projects perpendicular from the facade and is read edge-on, so it is a couple of + * columns wide at any distance (MIN_C[S_BLADE] is 1, the narrowest in the table); a tube is a + * hollow rectangle, i.e. an outline with nothing painted inside it. Every other style in the + * file fills its box — a screen, a ticker, a character block, a marquee, a backlit panel are + * all fields — and a rose FIELD is the cliche the README's "no magenta ever" was written + * against. Diverted to amber rather than azure, because a pink tube that has been replaced is + * a warm sign and the sodium read is the nearer neighbour. */ + if (h === P.rose && style !== S_BLADE && style !== S_TUBE) h = P.amber; /* The concrete district hands out slate and white sign panels, which are structure colours. * A sign is a light source and a light source is never unlit concrete. */ - if (h === P.slate || h === P.white || h === P.shadow) h = r < 0.5 ? P.amber : P.azure; + /* ---- AND FOUR MORE THAT ARE NOT LIGHTS EITHER ---------------------------------------------- + * city.js's widened table can now hand this file stone, timber, sand, moss and indigo on a + * sign record, and every one of them is a SURFACE swatch: core.js fits them for concrete, + * board, dust, planting and shade, with night ceilings of 122, 111, 138, 94 and 115. A sign + * painted in any of them cannot clear the muddy band's own top, so it would print as a grey + * smear where the brightest object in the frame is meant to be. Same divert as slate and + * white, and for exactly the reason the line under this one already gives. jade, rose and + * gold are NOT in this list and must not be: core.js's `ladder()` classes those three as + * SOURCES and blends them on the sun curve alongside amber and azure, which is the whole + * reason the extension was split into five surfaces and three signage swatches. */ + if (h === P.slate || h === P.white || h === P.shadow || + h === P.stone || h === P.timber || h === P.sand || + h === P.moss || h === P.indigo) h = r < 0.5 ? P.amber : P.azure; return h; } diff --git a/src/elements/sky.js b/src/elements/sky.js index 3be3c9b..5efb51f 100644 --- a/src/elements/sky.js +++ b/src/elements/sky.js @@ -244,6 +244,25 @@ * "something is there and it is occluding" — same coverage, printed to a value the eye reads * as mass rather than as light. */ var base = 26 + 16 * W_CLOUD; + /* ---- AND THE DECK IS NOT shadow ONCE THERE IS A SKY BEHIND IT -------------------------- + * The argument above is entirely right about a NIGHT deck: shadow is the swatch for + * "something is there and it is occluding", it cannot blow out, and slate at EXPOSURE 2.00 + * made seven hundred cloud cells the brightest flat area in a dark street. None of that + * survives sunrise. shadow's DAY ceiling is 40 — the lowest number in either ladder — so an + * overcast at noon was printing at a sixth of the brightness of the wall under it, and the + * one thing an overcast sky is, is brighter than the street. + * + * Two tiers, the same pair surfaces.js's dayMat() uses and for the same reasons: + * indigo through twilight. It is the palette's "shade with sky in it" and its night + * ceiling of 115 is slate's 114 to within a unit BY DESIGN, so this cannot re-brighten + * the deck the paragraph above spent its budget darkening — it changes the hue of a + * dusk cloud base and nothing else + * stone once the sky is properly up. Neutral grey, day ceiling 145, which is what an + * overcast actually is, and it sits one step under the sunlit render on the towers + * Both are gated on dSky and the night frame is byte-identical: at D_SKY 0 this is shadow at + * the same lum it always had. */ + var deckC = D_SKY > 0.50 ? P.stone : (D_SKY > 0.16 ? P.indigo : P.shadow); + var deckK = 1 + 2.6 * D_SKY * D_SKY; /* Where the sodium underglow is allowed: the bottom sixth of the sky, near the rooftops, * where ten thousand streetlights are actually pointing. */ var lowRow = CB.horizon - CB.rows * 0.17; @@ -272,8 +291,8 @@ * crawl with the camera while the cloud shape stayed put. */ if (hash2((nx * 190) | 0, (ny * 260) | 0, 0x71C3) > dens * (0.30 + 1.2 * v)) continue; gl = v > 0.62 ? G_TILDE : (v > 0.3 ? G_DASH : G_TICK); - lum = base * (0.55 + 0.75 * v); - hue = P.shadow; + lum = base * (0.55 + 0.75 * v) * deckK; + hue = deckC; /* The underside of a city's cloud base is lit by the city, and that is the whole reason * the sky over a town is orange. It is a MINORITY of the low cells and not a band: a * continuous amber strip along the rooftops is a sunset, and this is one in the morning diff --git a/src/elements/skylanes.js b/src/elements/skylanes.js index bfae8e8..dc2dd75 100644 --- a/src/elements/skylanes.js +++ b/src/elements/skylanes.js @@ -308,6 +308,11 @@ * falls to raw 100 (v 127) and azure 92 to raw 61 (v 137), and one step further down the fade * both are in the muddy band. */ var HEAD_AMBER = 152, HEAD_AZURE = 92, TAIL_RED = 118, UNDER_AMBER = 132, BEACON_RED = 138; + /* The transit livery lamp — see the roll in the draw. 236 prints v 128 on jade's night curve, + * which is the top of what that pigment can do (ceiling 134) and thirty points under the amber + * head it sits beside. It is a MARKER and not a headlamp, so being the dimmest of the three is + * the whole point rather than a compromise. */ + var HEAD_JADE = 236; var MIN_SCALE = 0.66; /* The lamp fade with range: full out to 90 m, MIN_SCALE at W_MAX. It is a visibility term, not * an inverse square — at ASCII resolution a distant lamp loses SIZE, not brightness, and a real @@ -711,9 +716,25 @@ * printed the single unattached specks the review could not tell from stars. Two lamps * bracketing a visible body is the signature; nothing here draws less than that. */ var dot = dirx * FWX + dirz * FWZ; // > 0 means it is running away from the eye + /* ---- ONE VEHICLE IN TWELVE IS LIVERIED, and it is a jade running lamp ----------------- + * The lane traffic is amber and azure and nothing else, which is right for a headlamp — + * that is what a headlamp IS — and it is also why a lane reads as one repeated vehicle. A + * transit unit has a running lamp in its OPERATOR'S colour rather than a headlamp colour, + * and `jade` is that swatch by name ("transit livery"). + * + * 8% and not more, for two measured reasons. This is the highest object in the frame and + * the only lit thing above the roofline, so its colour census reads far above its cell + * count. And jade's ceiling is 134 against amber's 179 and azure's 219 — so a jade lamp is + * DIMMER than either headlamp at any lum, which is correct for a marker light and is also + * what keeps it from becoming the thing the eye tracks across the sky. Written at 236, + * which prints v 128: just clear of the muddy band's top and thirty points under the + * amber head beside it. + * + * The pillar split is untouched: the 8% is taken evenly off both, 0.52 -> 0.48 for amber + * and the tail from 1.00 -> 0.92 for azure. */ var hue = hash2(idx, ky, S + SALT_HUE); - var headC = hue < 0.52 ? P.amber : P.azure; - var headL = (hue < 0.52 ? HEAD_AMBER : HEAD_AZURE) * scale; + var headC = hue < 0.48 ? P.amber : (hue < 0.92 ? P.azure : P.jade); + var headL = (hue < 0.48 ? HEAD_AMBER : (hue < 0.92 ? HEAD_AZURE : HEAD_JADE)) * scale; if (dot > 0.55) { // Receding: tail lamps only, and this is the line of red converging on the slot. diff --git a/src/elements/street.js b/src/elements/street.js index 72c18e7..f039a7b 100644 --- a/src/elements/street.js +++ b/src/elements/street.js @@ -706,7 +706,119 @@ { name: 'rigger', w: 0.070, ww: 0.050, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 0.66, legW: 0.50, brim: 0.00, pack: 0.30, bag: 0.00, hood: 0, umb: 0, wide: 1.12, crest: 0.00, cane: 0, tallB: -0.02, stride: 0.84, bob: 0.026, spd: 0.88, accP: 0.75, acc: 5, - visP: 0.30, scarf: 0, hair: 0.00 } + visP: 0.30, scarf: 0, hair: 0.00 }, + + /* ---- AND EIGHT MORE, BUILT OUT OF THE FIVE THINGS THIS TABLE STILL COULD NOT SPELL --------- + * Fifteen costumes on a pavement two abreast had started to repeat again, and the honest + * reason is that all fifteen were ONE BODY with different trim on it: a single run of black + * from a crown to a pair of feet, varying in width, hem and headgear. Everything below breaks + * that run in a way the eye can count at eight rows, which is the only test that matters — a + * costume that needs sixteen rows to read is a costume the crowd never shows you, because at + * any moment most of the crowd is between six and twelve. + * + * FIVE NEW FIELDS carry all eight, and each is a claim on the span union exactly like `pack` + * and `bag` already are, so the column loop gains five compares and no allocation: + * child a second, shorter figure held by the hand on the accent side + * barW/barV/barBoth something carried HORIZONTALLY at a stated height — a bicycle walked + * beside you, a vendor's tray held in front + * pole something long over the shoulder, drawn as a DIAGONAL rather than a span + * tail hem on the trailing side only, so the outline is asymmetric + * seat the body stops at this fraction and a wheel carries the rest + * lean the head is offset ahead of the feet, in shoulder half-widths + * Every one defaults to 0, which is why the fifteen costumes above are byte-for-byte the + * silhouettes they were — see the normalisation in the build loop below. */ + + /* SOMEBODY WITH A CHILD. Two crowns at two heights, a shoulder-width apart, moving as one. + * This is the only costume in the table whose read is a COUNT rather than a shape, and a + * count is the cheapest thing there is to see: at eight rows the pair is two lit cells at two + * different rows in adjacent columns, and nothing else on the pavement does that. It stops + * reading at about five rows, where the two crowns round into the same cell and it becomes a + * slightly wide figure. The child is 0.58 of the adult, i.e. about a metre — old enough to + * walk and young enough that the height difference is unmistakable. Slow, because that is + * what walking with a small child does to a pace, and no umbrella: the hand is full. */ + { name: 'child', w: 0.055, ww: 0.075, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.00, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.90, bob: 0.030, spd: 0.74, accP: 0.10, acc: 4, + visP: 0.04, scarf: 0, hair: 0.00, child: 0.58 }, + + /* WALKING A BIKE. A long horizontal at hip height with a GAP under it and two wheels below — + * the gap is the whole read, because it is the only place on this pavement where a black + * shape has daylight under it. It needs the bar to be at least three cells to be a bar, which + * at 0.24 m shoulders is about ten rows tall; under that the wheels alone survive as a low + * wide smudge beside the feet, which still says "this person has something with them". Pushed + * rather than ridden, so the pace is a walking pace and the stride is a walking stride. */ + { name: 'cycle', w: 0.050, ww: 0.000, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.28, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.96, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.94, bob: 0.020, spd: 1.06, accP: 0.24, acc: 2, + visP: 0.18, scarf: 0, hair: 0.00, barW: 2.30, barV: 0.54, wheel: 1 }, + + /* SOMETHING LONG OVER THE SHOULDER — a plank, a rolled carpet, a length of conduit. The one + * costume in the table whose distinguishing mark is ABOVE the head and at an angle, so it + * cannot be confused with a hat, a crest or a pack. It reads down to about seven rows, which + * is where the diagonal is still two cells and therefore still has a direction; below that it + * collapses onto the crown and the figure reads as `plain`, which is an honest failure mode + * because the pole is the only thing it had. Slow and wide: carrying does that. */ + { name: 'carry', w: 0.050, ww: 0.120, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.32, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.10, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.82, bob: 0.024, spd: 0.86, accP: 0.14, acc: 3, + visP: 0.10, scarf: 0, hair: 0.00, pole: 3.00 }, + + /* THE OPEN COAT THAT FLARES BEHIND. `cloak` is a symmetric wedge and this is its opposite: + * the hem is on the TRAILING side only, so the outline is asymmetric and the figure reads as + * moving even in a still frame. That asymmetry is a genuinely different cue from everything + * else here — every other costume in the table is left-right symmetric about its own centre — + * and it survives to about eight rows, where the tail is one column of claim past the + * shoulder. It is the fastest walk in the table that is not a courier's, because a coat only + * flares if you are getting somewhere. */ + { name: 'flare', w: 0.055, ww: 0.110, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.28, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.98, crest: 0.00, cane: 0, + tallB: 0.02, stride: 1.12, bob: 0.026, spd: 1.18, accP: 0.16, acc: 3, + visP: 0.10, scarf: 1, hair: 0.00, tail: 0.80, tailTop: 0.34, tailBot: 0.86 }, + + /* A STREET VENDOR WITH A TRAY. A flat bar across the FRONT of a narrow body, reaching both + * ways — so it is a T, and a T is the one letter shape nothing else on this pavement makes. + * It reads to about seven rows. It is the only figure in the table that never walks: a tray + * is carried standing, so the pace is near zero and the stride with it, which also means it + * is the one costume that reliably stays in the near field long enough to be looked at. + * It carries something lit, because a tray at night has a lamp clipped to it. */ + { name: 'vendor', w: 0.045, ww: 0.030, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.28, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.94, crest: 0.00, cane: 0, + tallB: 0.00, stride: 0.60, bob: 0.012, spd: 0.30, accP: 0.62, acc: 4, + visP: 0.06, scarf: 0, hair: 0.00, barW: 1.55, barV: 0.50, barBoth: 1 }, + + /* A BEDROLL, HIGH ON THE BACK. A pack sits below the crown and squares the back off; this one + * rises ABOVE the shoulder line and past the crown, so the head stops being the top of the + * figure and sits BESIDE the highest thing on it. That off-centre top edge is the read and it + * survives all the way to six rows, because it is the crown itself that has moved. Everything + * about the walk says a long way on foot: slow, heavy, and the widest shoulders after the + * docker's. */ + { name: 'bedroll', w: 0.045, ww: 0.120, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.32, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 1.18, crest: 0.00, cane: 0, + tallB: -0.04, stride: 0.80, bob: 0.028, spd: 0.80, accP: 0.20, acc: 3, + visP: 0.06, scarf: 0, hair: 0.00, roll: 0.70 }, + + /* A WHEELCHAIR, and it is the strongest silhouette in the whole table — stronger than the + * cloak. Three things change at once and all three are visible at FIVE rows: the figure is + * shorter than everything else on the pavement by a third, the body ends at the hip instead + * of running to a pair of feet, and below that there is a broad round base that does not + * alternate. Nothing else here has a still bottom edge; a walker's legs are the one part of + * it that always moves. `seat` is what stops the legs being drawn at all, so it also costs + * the frame less black than the figure it replaces. */ + { name: 'wheels', w: 0.040, ww: 0.015, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 1, wide: 1.02, crest: 0.00, cane: 0, + tallB: -0.30, stride: 1.00, bob: 0.008, spd: 0.92, accP: 0.14, acc: 4, + visP: 0.08, scarf: 0, hair: 0.00, seat: 0.56, wheelW: 1.30 }, + + /* A RUNNER. The head is carried AHEAD of the feet, which is the one thing on this pavement + * that is not a vertical, and the legs split further than anybody else's. The lean is in + * shoulder half-widths so it is a fixed fraction of the figure at every distance, and it stops + * reading at about nine rows — below that 0.55 half-widths rounds into the same column as the + * feet and a runner is a fast plain figure, which is at least still true. The fastest thing + * on the pavement by a distance and the shortest stride period. */ + { name: 'runner', w: 0.040, ww: 0.025, hem: 0.00, hemTop: 0.00, hemBot: 1.00, legTop: 1.00, legW: 0.30, + brim: 0.00, pack: 0.00, bag: 0.00, hood: 0, umb: 0, wide: 0.94, crest: 0.00, cane: 0, + tallB: 0.02, stride: 1.72, bob: 0.062, spd: 1.74, accP: 0.10, acc: 2, + visP: 0.14, scarf: 0, hair: 0.00, lean: 0.55, legSpread: 1 } ]; /* How far a swinging arm reaches past the shoulder line, in shoulder half-widths. See the arm * block in the column loop for why the arms are part of the cut-out rather than a lit mark. */ @@ -717,9 +829,44 @@ * knows where to stop without testing every accessory on every column of every figure. */ for (var i = 0; i < ARCH.length; i++) { var A = ARCH[i], e = A.hem; + /* THE NEW FIELDS DEFAULT TO ZERO HERE RATHER THAN IN FIFTEEN ROWS OF THE TABLE, and that is + * a correctness point and not a tidiness one: the column loop tests them with `> 0`, which + * is false for undefined and therefore already safe — but `ext` below and the draw's own + * arithmetic would happily produce NaN from one, and a NaN width silently stops a costume + * being drawn at all with no error anywhere. That is precisely the failure tools/peds.cjs + * exists to make visible, so it is closed here instead. */ + if (A.child === undefined) A.child = 0; + if (A.barW === undefined) { A.barW = 0; A.barV = 0.5; A.barBoth = 0; } + if (A.barBoth === undefined) A.barBoth = 0; + if (A.wheel === undefined) A.wheel = 0; + if (A.pole === undefined) A.pole = 0; + if (A.tail === undefined) { A.tail = 0; A.tailTop = 0.4; A.tailBot = 0.9; } + if (A.roll === undefined) A.roll = 0; + if (A.seat === undefined) { A.seat = 0; A.wheelW = 0; } + if (A.lean === undefined) A.lean = 0; + if (A.legSpread === undefined) A.legSpread = 0; if (A.brim > e) e = A.brim; if (A.pack > e) e = A.pack; if (A.bag > e) e = A.bag; + /* Everything that reaches sideways has to be in here or the column loop stops before it and + * the costume is simply never drawn — and pedCover() measures the same box, so the + * screen-area budget would be protecting the frame from a figure narrower than the one it + * is about to print. `child` reaches a full shoulder-width plus its own half-width; the + * pole is a diagonal and its horizontal reach is its own length. */ + /* barW and pole are DELIBERATELY ABSENT. A bicycle frame and a carried plank are drawn as + * RIMS after the column loop, not as claims inside it — the same decision the scarf and the + * stick already carry, and for the same two reasons. They are thin (a bike tube is 30 mm, a + * plank is a plank on edge) so at every size this crowd prints at they are an edge with no + * interior to be black; and the span union takes ONE RUN per column, so a bar at hip height + * with two wheels under it would fuse into a solid slab and lose the gap that is the entire + * read. Not entering `ext` is therefore correct twice over: they do not need the column loop + * to reach them, and they black out no picture, so pedCover()'s area budget must not size + * its box around them. */ + if (A.child > 0 && 1.25 > e) e = 1.25; + if (A.tail > e) e = A.tail; + if (A.roll > e) e = A.roll; + if (A.wheelW > e) e = A.wheelW; + if (A.lean > e) e = A.lean; /* ARM_EXT is in the floor for EVERY archetype, because everybody has arms and the swinging * one reaches past the shoulder line. Leaving it out is not a cosmetic omission: `ext` is * what the column loop uses to decide where to stop, so an arm outside it is simply never @@ -738,7 +885,32 @@ * * An archetype may go to ZERO — `shell` does — and the pick below handles that correctly * because it tests the RUNNING TOTAL: a zero-weight entry has the same accumulator as its - * predecessor and can never win the comparison. */ + * predecessor and can never win the comparison. + * + * ---- AND THE EIGHT NEW ONES OWE THE SAME ARGUMENT, WHICH THEY DID NOT PAY ---------------- + * They arrived carrying frontier weights summing to 0.475 against the fifteen's 1.105, i.e. + * three walkers in ten out there were a costume nobody had asked the period question about. + * The share is fine — eight of twenty-three costumes is a third of the table, so a third of + * the crowd is what proportion looks like — but the split inside it was not, and one row was + * simply wrong. Row by row, which is what this file owes every weight: + * cycle 0.020 -> 0.000. A walked SAFETY BICYCLE is 1885 and it is an eastern-city + * object; a main street's answer to "walking beside something with wheels" is a + * horse, and the frontier already has horses at every rail and wagons across + * every junction. Refused for the same reason as the phone and the piping + * carry 0.090 -> 0.120. A plank, a rolled hide, a length of pipe over the shoulder is + * the most frontier silhouette in the whole table and it was under-weighted + * bedroll 0.090 -> 0.120. A bedroll high on the back IS frontier kit; same argument + * flare 0.085 -> 0.110. The tail-only hem is a duster coat, which with the brimmed hat + * and the long coat is what the place looks like + * vendor 0.055 -> 0.030. A tray carried on a strap is period, but a standing tray-vendor + * reads as a city pavement and out there the trade happens in the store + * runner 0.045 -> 0.025. Nobody jogs in 1885. People do run, so it is not zero + * child 0.075 kept. A family on a main street needs no argument and wants none + * 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, + * 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; } })(); @@ -837,9 +1009,15 @@ * concrete lot with neither is a dead wall. Asking it is the difference between a crowd that * stands outside the shops and a sprinkle spread evenly along a street that is not even. * Returns roughly 0.34 (blank wall) .. 2.0 (a lit parade under signage). */ - var FF_HUE = 0; + /* FF_HUE is the frontage's own colour and FF_SIGN is the colour of the SIGN on it, which are + * two different lights and only one of them used to be asked for. A lit wall throws its district + * hue on whoever walks past; a blade sign three metres over their head throws its own, and a + * sign is by a long way the brighter of the two. city.js now hangs rose, gold, jade and moss on + * sign records, so this is where those swatches reach the crowd — see the rim roll in pedSpawn. + * -1 means "no sign on this lot", which is most of them. */ + var FF_HUE = 0, FF_SIGN = -1; function footfall(city, a, l) { - FF_HUE = P.amber; + FF_HUE = P.amber; FF_SIGN = -1; if (!city || !city.cell) return 1; /* Sampled 2.2 m PAST the walker, i.e. inside the frontage. The pavement itself is street and * carries no building record, so sampling where the figure stands always returns null. */ @@ -847,6 +1025,7 @@ var c = city.cell(worldX(a, ll), worldZ(a, ll)); if (!c) return 0.62; // a gap in the frontage — an alley mouth or a plaza, not a parade FF_HUE = c.hue; + if (c.sign && typeof c.sign.hue === 'number') FF_SIGN = c.sign.hue | 0; return 0.34 + c.litRate * 2.4 + (c.sign ? 0.55 : 0); } @@ -863,7 +1042,8 @@ h10 = hash2(i, n, S + 1013), h11 = hash2(i, n, S + 1117), h12 = hash2(i, n, S + 1223), h13 = hash2(i, n, S + 1301), h14 = hash2(i, n, S + 1409), h15 = hash2(i, n, S + 1511), h16 = hash2(i, n, S + 1607), - h17 = hash2(i, n, S + 1709); + h17 = hash2(i, n, S + 1709), h18 = hash2(i, n, S + 1811), + h19 = hash2(i, n, S + 1907); var rain = wp().rain; var kl = kerbL(), band = COR.half - kl - 0.6; if (band < 0.2) band = 0.2; @@ -873,7 +1053,7 @@ /* WHERE. Three candidate spots down the street, and the busiest frontage wins. */ var l0 = side * (kl + 0.2 + h3 * band); - var bestA = COR.along + COR.dir * 58, bestF = -1, bestH = P.amber; + var bestA = COR.along + COR.dir * 58, bestF = -1, bestH = P.amber, bestS = -1; for (ki = 0; ki < 3; ki++) { var hk = hash2(i, n * 4 + ki, S + 1361); /* The first fill spreads over the whole visible street; every later respawn arrives from @@ -881,7 +1061,7 @@ * rows and thirty lum rather than switching on at full contrast in the middle of it. */ var ak = COR.along + COR.dir * (fresh ? 5 + hk * 42 : 52 + hk * 16); var ff = footfall(city, ak, l0); - if (ff > bestF) { bestF = ff; bestA = ak; bestH = FF_HUE; } + if (ff > bestF) { bestF = ff; bestA = ak; bestH = FF_HUE; bestS = FF_SIGN; } } /* And if even the best of the three has nothing worth walking past, this slot sits the next * second or two out and asks again. That is what actually thins the pavement on a dead block — @@ -1035,6 +1215,31 @@ * rather than towards a shopfront monitor. */ p.rim = PED_WEST ? ((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 + * throws azure and a sodium one amber. What it missed is that a lit sign is by a long way the + * brightest thing over a pavement, and city.js now hangs jade, rose, gold and moss on sign + * records — so a figure passing under a pink blade sign should be rimmed in pink, and that is + * the single most cyberpunk cell this file can write. + * + * ONE FIGURE IN THREE of those standing under a lot that has a sign at all, which over the + * whole crowd is well under one in ten: `sign` is on a minority of lots and the walker has to + * have picked that lot as its busiest frontage. Measured over a 12-frame fixture the rim's + * pillar split moves by under a point, because the swatches this can hand out are mostly the + * pillars anyway — the district roll puts amber and azure on two thirds of city.js's signs. + * + * FOUR SWATCHES ARE REFUSED and the refusals are the same ones signage.js makes one file over: + * white, slate and the five surface swatches cannot be a light, so a rim in any of them would + * be a grey edge on a black figure. Violet is refused too — a violet rim on a person is the + * cliche the README's rule is about, and unlike a violet SIGN it is not a screen. + * + * 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 && + 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; p.uRate = 0.20 + h1 * 0.26; // seconds-scale, and different for every figure @@ -1079,6 +1284,37 @@ : A.acc === 5 ? P.amber : (qa < 0.60 ? P.warm : P.amber); } else { p.acc = 0; p.accHue = P.amber; } + /* ---- THE WORN ACCENT, and it is the third thing a figure may carry ------------------------ + * The one-accent rule bounds MARKS THAT GLOW: piping, a strip, a cigarette, a carried lamp are + * still mutually exclusive, and the visor is still the one documented exception because it + * lands on the cell the crown rim already occupies. This is a fourth kind of thing and it does + * not compete with any of them, because it is not a light — it is a scrap of DYED CLOTH OR + * METAL catching the same lamp the rim does, at the same brightness, in a different colour. + * That is the difference the extension's three signage swatches and two of its surfaces were + * added to spell, and it is why this can afford to be independent: + * gold a stud or a hoop at the ear. ONE cell, near field only (see the draw), and the + * swatch's own brief — "brass and gilding ... warm metal" + * moss a collar or a scarf turned up at the neck. moss tops out at v 94 at night, which + * is under everything on this figure including its own rim, so a moss collar is a + * DARKER green edge on a black shape — exactly what a wool collar under a street + * lamp is, and it can never compete with the crown + * indigo the lining of a hood turned back, at the same v 115 as the slate structure behind + * it, so it changes hue and not brightness + * ONE FIGURE IN FIVE, on its own draw, which puts it at the same rate as the body accent + * without being correlated with it. + * + * NOT ON THE FRONTIER for the two that are not cloth. A brass earring and a wool collar are + * both entirely 1880s and both stay; an indigo hood LINING is a hood, and the frontier's hoods + * are serape hoods, so it falls back to the collar rather than being dropped — the draw is + * still taken either way, so no downstream stream moves. */ + if (h19 < 0.20) { + var qw = h19 / 0.20; + p.wear = qw < 0.34 ? 1 : (qw < 0.72 ? 2 : 3); + /* 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; + } 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 * every crosser amber). h17 is a fresh salt; conditional on the gate, h17/A.visP is itself @@ -1126,7 +1362,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, A: ARCH[0] }; + umbOwn: 0, umb: 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 @@ -1288,6 +1524,19 @@ * that carries neither feature, so nothing that shipped moves. */ var headHW = 0.34 + A.hair; var legHW = A.legW > 0.34 ? A.legW : 0.34; + /* WHICH WAY THIS FIGURE FACES ON SCREEN, hoisted for the same reason headHW and legHW are: + * it is a per-figure constant and the loop below runs once per column of every walker. + * The walk's world velocity projected onto the camera's RIGHT axis — the same projection + * windRight() uses for the scarf, so a coat tail and the rain behind it agree about which + * way "downwind of the walk" is. A figure with no velocity (a shelterer, a vendor at a + * tray) gets +1, which is arbitrary and correct: it is not going anywhere, so nothing that + * reads off `face` should be moving on it either. */ + var face = (p.vx * RGX + p.vz * RGZ) < 0 ? -1 : 1; + /* How far the legs part at full stride. Everybody walks; one archetype RUNS, and the + * single most legible difference between the two at this size is not the pace, it is how + * far apart the feet get. 0.99/0.78 against the walk's 0.94/0.86 nearly triples the gap + * between the planted foot and the trailing one. */ + var legPl = A.legSpread ? 0.99 : 0.94, legTr = A.legSpread ? 0.78 : 0.86; /* How steep the top edge of the hem is, in SCREEN ROWS PER COLUMN, at this figure's * printed size. A hem is the one edge on a walker that is genuinely diagonal, and at more * than about a row and a half per column a run of dashes stops being a line and becomes a @@ -1298,6 +1547,12 @@ for (x = x0; x <= x1; x++) { var u = (x - cx) / shw, au = u < 0 ? -u : u; var onAcc = (u < 0 ? -1 : 1) === p.side; // the side the bag or the pack is slung on + /* WHICH WAY THIS FIGURE IS GOING ON SCREEN, which is a different question from which + * shoulder the lamp is over. `face` is the walk's own direction projected onto the + * camera's right axis (see the hoist above the loop), so a coat's tail streams behind + * the walk and a runner leans into it — and both reverse correctly the moment the + * camera turns a corner, because the projection does. */ + var onFace = (u < 0 ? -1 : 1) === face; /* v0/v1 are the top and bottom of this column as body fractions. Start empty and let * each piece of the costume claim its own span; a column nothing claims is skipped. The * union is deliberately taken as a single run rather than as separate pieces — at this @@ -1328,8 +1583,8 @@ * while the inner two thirds alternated — a figure walking inside its own trousers. */ if (au < legHW && tallRows > 5) { var lg = (u < 0 ? -1 : 1) * st; - if (lg > 0.30) v1 = 0.94; // planted: this foot is carrying, heel down - else if (lg < -0.30) v1 = 0.86; // trailing: the heel is off the pavement + if (lg > 0.30) v1 = legPl; // planted: this foot is carrying, heel down + else if (lg < -0.30) v1 = legTr; // trailing: the heel is off the pavement } } /* THE ARMS. Part of the CUT-OUT, not a lit mark on it, and that is the whole reason they @@ -1390,8 +1645,78 @@ if (0.54 > v1) v1 = 0.54; } if (A.bag > 0 && onAcc && au > 0.60 && au <= 1 + A.bag) { - if (0.40 < v0) v0 = 0.40; - if (0.66 > v1) v1 = 0.66; + /* THE SATCHEL SWINGS, and it swings OUT OF PHASE with the stride. A bag on a strap is + * a pendulum hung off a shoulder, so it lags the body that is driving it — which is + * the whole reason it reads as a hung object rather than as a bulge on the hip. `-st` + * is that lag at the coarsest useful resolution (half a cycle), and it moves the bag + * up and down by 0.05 of the body, i.e. about one row on a twenty-row figure and + * nothing at all below that, which is exactly where it should stop mattering. */ + q = 0.40 - 0.05 * st; + if (q < v0) v0 = q; + if (q + 0.26 > v1) v1 = q + 0.26; + } + /* ---- THE SIX NEW CLAIMS, in the order they may overwrite one another ------------- */ + /* THE BEDROLL. A pack squares off the BACK; this rises past the crown, so the highest + * thing on the figure is no longer its head. Tapered at the outer edge for the same + * reason the hood's peak is: flat across it prints as a bar sitting on a person. */ + if (A.roll > 0 && onAcc && au > 0.44 && au <= 1 + A.roll) { + q = -0.05 + 0.16 * (au - 0.44) / (0.56 + A.roll); + if (q < v0) v0 = q; + if (0.50 > v1) v1 = 0.50; + } + /* THE TRAILING TAIL. `hem` is symmetric about the figure; this is the same shape on ONE + * side only, which is what makes the outline asymmetric — and asymmetry is a cue no + * other costume in the table offers. Behind, not beside: the tail is on the side away + * from the direction of travel, so it reads as being left behind by the walk. */ + if (A.tail > 0 && !onFace && au > 1 && au <= 1 + A.tail) { + q = A.tailTop + (A.tailBot - A.tailTop) * (au - 1) / A.tail; + if (q < v0) { v0 = q; diag = 1; } + if (A.tailBot > v1) v1 = A.tailBot; + } + /* THE CHILD. Two claims: the held hands, which are a thin bridge at the adult's hip and + * are what stop the pair reading as two unrelated figures; and the child itself, a body + * of its own with a crown that drops away either side exactly as the adult's does. */ + if (A.child > 0 && onAcc && au > 0.90 && au <= 1.78) { + if (au < 1.04) { + if (0.50 < v0) v0 = 0.50; + if (0.58 > v1) v1 = 0.58; + } else { + var cu = (au - 1.40) / 0.38; if (cu < 0) cu = -cu; + q = (1 - A.child) + (cu > 0.60 ? 0.07 : 0); + if (q < v0) v0 = q; + if (1 > v1) v1 = 1; + } + } + /* THE WHEELCHAIR. The body is TRUNCATED at the hip — that is what `seat` does, and it is + * the only field in the table that takes coverage AWAY — and a wheel carries the rest. + * The wheel's top edge is a parabola so that the disc reads as round rather than as a + * box, and it runs to the sole so the figure still stands on the pavement. */ + if (A.seat > 0) { + if (v1 > A.seat && v1 < 9) v1 = A.seat; + if (au <= A.wheelW && tallRows > 4) { + q = A.seat - 0.02 + 0.34 * (au / A.wheelW) * (au / A.wheelW); + if (q < 0.98) { + if (q < v0) v0 = q; + if (1 > v1) v1 = 1; + } + } + } + /* THE LEAN. The one figure here whose top edge is not level. The crown is carried a + * little over half a shoulder-width AHEAD of the feet and the trailing shoulder falls + * away behind it, so the whole top of the silhouette slopes — which is what a person + * running looks like from the side and what nothing else on this pavement does. Both + * halves are needed: the forward head alone reads as a hat, and the dropped shoulder + * alone reads as a stoop. */ + if (A.lean > 0 && tallRows > 6) { + var ld = u * face; + if (ld > 0 && au <= 1 + A.lean) { + var hu = (au - A.lean) / 0.42; if (hu < 0) hu = -hu; + if (hu < 1) { + q = 0.02 + 0.07 * hu; + if (q < v0) v0 = q; + if (0.34 > v1) v1 = 0.34; + } + } else if (ld < 0 && au <= 1 && v0 < 0.22) v0 = 0.22; } if (v1 < v0) continue; var rt = rHead + v0 * tallRows, rb = rHead + v1 * tallRows; @@ -1581,6 +1906,68 @@ } } + /* ---- SOMETHING CARRIED HORIZONTALLY ------------------------------------------------- + * A bicycle walked at the hip, and a vendor's tray held out in front. Both are drawn as + * RIMS and not as part of the cut-out, which is the stick's argument exactly: a bike frame + * is thirty millimetres of tube and a tray is a sheet seen on edge, so at every size this + * crowd is drawn at they are an EDGE catching the lamp with no interior to be black. + * + * It is also the only way the bike can keep the DAYLIGHT UNDER ITS BAR, and that gap is + * the entire read — it is the one place on this pavement where a shape has space beneath + * it. The span union takes ONE RUN per column, so a claimed bar over claimed wheels would + * fuse into a solid slab and the bike would be a wide hip. */ + if (A.barW > 0 && tallRows > 5) { + var bdir = A.barBoth ? 0 : p.side; + var bn = Math.round(shw * A.barW); if (bn > 22) bn = 22; + var byr = Math.round(rHead + tallRows * A.barV); + var bq0 = A.barBoth ? -bn : (bdir > 0 ? 1 : -bn); + var bq1 = A.barBoth ? bn : (bdir > 0 ? bn : -1); + for (q = bq0; q <= bq1; q++) { + var bf = q < 0 ? -q : q; + /* Brighter at the body end and falling away: whatever is lighting this is over the + * figure's own shoulder, and a flat bar of equal cells reads as a rule rather than as + * an object being carried. */ + put(frame, Math.round(cx) + q, byr, G_DASH, p.rim, + rim * (0.80 - 0.30 * bf / (bn + 1)), nearer(dist)); + } + /* THE WHEELS, and they are what stop a bicycle being a stick. Two shallow arcs on the + * pavement under the bar, at a third and at seven eighths of its length — a bike walked + * beside you is foreshortened, so the near wheel sits well inboard. Below nine rows an + * arc is one cell, which is still TWO MARKS IN A ROW under a bar and still not a stick, + * so the floor is deliberately low. */ + if (A.wheel && tallRows > 7) { + var wrr = Math.round(shw * 0.55); if (wrr < 1) wrr = 1; if (wrr > 5) wrr = 5; + for (var wi = 0; wi < 2; wi++) { + var wcx = Math.round(cx + bdir * shw * A.barW * (wi ? 0.88 : 0.34)); + for (q = -wrr; q <= wrr; q++) { + var wf = q / wrr, waf = wf < 0 ? -wf : wf; + put(frame, wcx + q, + Math.round(rFeet - tallRows * 0.04 - (1 - wf * wf) * wrr * 0.9), + (waf > 0.7) ? G_TICK : G_DASH, p.rim, + rim * (0.56 - 0.20 * waf), nearer(dist)); + } + } + } + } + + /* ---- SOMETHING LONG OVER THE SHOULDER ------------------------------------------------ + * One diagonal, resting on the shoulder and rising past the head — the only mark on this + * pavement that is ABOVE the crown AND at an angle, so it can never be read as a hat, a + * crest or a pack. A rim for the same reason the stick is: a plank on edge has no + * interior. It stops under seven rows, where the whole thing is two cells; a single lit + * cell over a head is a speck, and this file has already been bitten by that twice. */ + if (A.pole > 0 && tallRows > 6) { + var pn = Math.round(shw * A.pole * 0.5); if (pn > 20) pn = 20; + if (pn >= 2) { + var pRow = rHead + tallRows * 0.20; + var pSlope = tallRows * 0.34 / pn; // screen rows per column + var pGly = pSlope > 0.85 ? (p.side > 0 ? G_SLASH : G_BSLASH) : G_DASH; + for (q = -pn; q <= pn; q++) + put(frame, Math.round(cx) + q, Math.round(pRow - q * pSlope * p.side), + pGly, p.rim, rim * (0.70 - 0.16 * (q * p.side) / pn), nearer(dist)); + } + } + /* THE BODY ACCENT — at most one per figure, and about one figure in five carries one. * The visor below is the one mark allowed alongside it; see the one-accent note at the top * of this block for the measured overlap and why this is the exception. */ @@ -1670,6 +2057,102 @@ } } + /* ---- THE WORN ACCENT --------------------------------------------------------------- + * A scrap of cloth or metal catching the same lamp the rim does. It is not a light, so it + * is written at a FRACTION of the rim rather than at a lum of its own — which is the whole + * distinction between this and the body accent above, and the reason the two can coexist + * on one figure without it reading as jewellery. See the roll in pedSpawn. + * + * The earring is gated on SIXTEEN ROWS and nothing else here is. That is not caution, it + * is arithmetic: an ear is about 0.04 of a body, so under sixteen rows the stud and the + * crown round into the same cell and CC.put's strict-improvement test drops one of them — + * and a gold cell where a crown should be is a worse figure than no earring. The collar + * and the hood lining are EDGES a whole row deep and read from about eight. */ + if (p.wear && tallRows > 8) { + var wl = fg(rim * 0.82, dist); + if (wl >= 5) { + var wd = dist * 0.974; // inside the crown rim, outside the visor's + if (p.wear === 1) { + if (tallRows > 16) + put(frame, Math.round(cx + p.side * shw * headHW), + Math.round(rHead + tallRows * 0.075), G_DOT, P.gold, wl * 1.15, wd); + } else if (p.wear === 2) { + /* The collar, across the neck: two cells at most, and the reason it is at 0.155 + * rather than at the shoulder line is that a turned-up collar sits ABOVE the + * shoulders — drawn level with them it merges into the rim and buys nothing. */ + var wy = Math.round(rHead + tallRows * 0.155); + put(frame, Math.round(cx - shw * 0.30), wy, G_DASH, P.moss, wl, wd); + put(frame, Math.round(cx + shw * 0.30), wy, G_DASH, P.moss, wl * 0.80, wd); + } else if (A.hood || tallRows > 13) { + /* The lining of a hood turned back, or a coat collar's facing on anyone else. It + * lands one row UNDER the crown, i.e. inside the silhouette, where a lining is. */ + put(frame, Math.round(cx), Math.round(rHead + tallRows * 0.11), G_DASH, + P.indigo, wl * 1.10, wd); + } + } + } + + /* ---- NEAR-FIELD DETAIL, and every line of it is gated on SIXTEEN ROWS ------------------ + * A figure this tall is inside about five metres at the reference grid, which happens to + * one or two walkers in a frame and to none at all for most of a walk. Everything below is + * therefore free in the middle distance — the gate is one compare per figure, not per + * column — and that is the only reason it can afford to exist at all. + * + * WHAT SIXTEEN ROWS BUYS, in the order the eye finds it: the head is five or six cells + * tall, so it has room for a face UNDER its crown; the swinging arm is three or four + * columns clear of the body, so its end is a hand rather than a bump; and a bag on a strap + * has a strap. None of the three is drawable at twelve rows, which is why none of them is + * attempted there. + * + * ALL OF IT IS A RIM, at fractions of the rim the crown already took, so the near figure + * gains DETAIL and not brightness. That distinction is the one this whole element is built + * on and it is easiest to lose exactly here, where there are cells to spare. */ + if (tallRows > 16 && rim >= 5) { + var nd2 = dist * 0.974; + /* THE FACE. Two dark cells and a rim, and the dark cells are free — the body is already + * a cut-out, so what has to be DRAWN is the light: the brow catching the lamp above and + * the jaw catching the shopfront below, with the eye line black between them. Drawn + * only on the lamp side, because a face lit from both sides is the cardboard cut-out + * this element's design note forbids. A hood carries no face and gets neither. */ + if (!A.hood) { + var fy = Math.round(rHead + tallRows * 0.055); + var fx = Math.round(cx + p.side * shw * 0.20); + put(frame, fx, fy, G_QUOTE, p.rim, rim * 0.46, nd2); // the brow + put(frame, fx, Math.round(rHead + tallRows * 0.115), G_DOT, p.rim, // the jaw + rim * 0.30, nd2); + } + /* THE HAND. The forward-swinging arm is part of the cut-out and its END is the one place + * on a near figure where a lit cell says "person" rather than "shape". It rides the + * stride the arm already rides, so it is where the arm is and not beside it. */ + var hsw = p.side * st; + if (hsw > 0.20) { + put(frame, Math.round(cx + p.side * shw * (1 + ARM_EXT * hsw + 0.10)), + Math.round(rHead + tallRows * (0.44 + 0.20 * hsw)), G_o, p.rim, + rim * 0.52, nd2); + } + /* THE STRAP. A bag hangs at one hip off a strap that crosses the body from the OTHER + * shoulder, and that diagonal is the only line on a person that runs corner to corner. + * Three cells, stepped, from the far shoulder toward the near hip. */ + if (A.bag > 0) { + var sy0 = rHead + tallRows * 0.15, sy1 = rHead + tallRows * 0.42; + for (q = 0; q <= 3; q++) { + var sfk = q / 3; + put(frame, Math.round(cx + p.side * shw * (-0.55 + 1.30 * sfk)), + Math.round(sy0 + (sy1 - sy0) * sfk), + p.side > 0 ? G_BSLASH : G_SLASH, p.rim, rim * (0.40 - 0.10 * sfk), nd2); + } + } + /* BOOTS. The one edge of a figure that is not the rim and the one the wet-road + * reflection sits directly under — so at this size it is worth a mark of its own. A + * dash a little wider than the leg, on the PLANTED foot only: the trailing one has its + * heel off the pavement and nothing to catch. */ + if (A.seat === 0) { + var bsd = st > 0 ? 1 : -1; + put(frame, Math.round(cx + bsd * shw * legHW * 0.7), Math.round(rFeet), + G_UNDER, p.rim, rim * 0.34, nd2); + } + } + /* THE UMBRELLA. A shallow arc over the head, wide enough to be a roof and no wider, drawn * as one cell per column so it never masses into a lit blob: the apex takes the light and * the ribs fall away from it. p.umb is the open fraction, so the canopy grows out of the @@ -1679,10 +2162,31 @@ if (ru < 1) ru = 1; var ruI = ru | 0; var rApex = rHead - tallRows * (0.07 + 0.08 * p.umb); + /* ---- AND IT TILTS INTO THE WIND --------------------------------------------------- + * Nobody holds an umbrella level in a cross-wind; you drop the windward edge and lift + * the lee one, and that tilt is the single most legible thing about a person in weather. + * It rides the SAME windRight() the scarf does — the city's own wind projected across + * the view — so the umbrellas, the scarves and the rain curtain behind all of them lean + * together and reverse together when the walk turns a corner. Anything else would be + * three systems disagreeing about which way the wind is blowing. + * + * IT IS NOT A FLICKER SOURCE at any setting, and the reasoning is the scarf's verbatim: + * the carrier is weather.js's gust envelope, which moves at a fraction of a hertz, and + * what it drives here is a POSITION and not a brightness. Under reduced motion + * windRight() already divides the gust out and returns the steady mean, so the canopy + * holds one tilt instead of breathing. + * + * 0.30 of the canopy's own half-width at full cross-wind. Drawn at 34 rows and looked + * at both ways: at 0.60 the windward rib dropped past the shoulder and the thing read as + * a wing rather than as an umbrella; at 0.15 the tilt was under a row across the whole + * canopy and there was nothing to see. */ + var uw = windRight() / 3.4; if (uw > 1) uw = 1; else if (uw < -1) uw = -1; + var uTilt = uw * ru * 0.30; for (q = -ruI; q <= ruI; q++) { var f2 = q / ru; 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), + 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)); } /* The shaft, and only the stretch between the canopy and the crown: below that it runs diff --git a/src/elements/west_desert.js b/src/elements/west_desert.js index dba7d92..c93be39 100644 --- a/src/elements/west_desert.js +++ b/src/elements/west_desert.js @@ -392,6 +392,16 @@ * is what the frontier's furniture did before the clock existed. */ var day = clamp(0.14 + 0.86 * D_SUN, 0, 1); var hot = sun > 0.6 && D_SUN > 0.35; + /* ---- WHAT A PLANT IS MADE OF, and slate is not it --------------------------------------------- + * Every plant in this function is drawn in slate, which is 62,98,138 — a deliberately BLUE + * swatch whose job in this project is unlit concrete. That was the whole vocabulary available + * when this file was written; the palette now has moss (92,126,74, "planting, algae, sage, + * canvas") and timber, and a creosote bush at midday is sage green over dead brown wood. + * + * Dithered per PLANT on the day fill, for the reason west_town.js's posts are: a bush is one + * object and half of it in each swatch is a stripe. slate stays the night swatch untouched, so + * the tuned frame is unchanged to the byte. */ + var dF = dayFill(); /* ---- the yucca ------------------------------------------------------------------------------ * A stiff rosette with a flower stalk out of the middle, and the STALK is the whole silhouette: @@ -409,7 +419,7 @@ w = standing(yx, yz, 1.3, 1.0, 52); if (!w) continue; var stalk = 1.5 + (yh / 0.28) * 1.0; // 1.5-2.5 m - column(f, yx, yz, 0, 0.55, G_STAR, P.slate, 24 + 30 * day, 0); + column(f, yx, yz, 0, 0.55, G_STAR, leafC(yh, dF), 24 + 30 * day + 84 * dF, 0); /* Two blades either side of the base — a rosette seen from any angle without an angle. */ if (w < 22) { if (project(yx - 0.34, 0.42, yz)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_SLASH, P.slate, 20 + 26 * day, PJ.d); @@ -468,8 +478,8 @@ var rBot = Math.floor(bry); var cx2 = Math.floor(bcx + q); var side = (q * sunX > 0) ? 1 : 0; - var mcol = hot && side ? P.amber : P.slate; - var mlum = (hot && side ? 68 : 24) * (0.55 + 0.60 * day); + var mcol = hot && side ? (dF > 0.5 ? P.moss : P.amber) : leafC(mh / 0.46, dF); + var mlum = (hot && side ? 68 + 92 * dF : 24 + 74 * dF) * (0.55 + 0.60 * day); for (r2 = rTop; r2 <= rBot; r2++) { var deep = r2 - rTop; if (deep > 1 && hash2(cx2 * 3 + deep, i * 5 + j, BASE + 0x35) > 0.26) continue; @@ -550,7 +560,7 @@ * is why you can see one from a mile away. */ if (project(wxp, 0.02, wzp)) emit(f, Math.floor(PJ.x), Math.floor(PJ.y), g2 < 0.5 ? G_UNDER : G_TILDE, - hot ? P.white : P.slate, (18 + 66 * day) * (0.6 + 0.6 * g2), PJ.d); + hot ? P.white : leafC(oh / 0.32, dF), (18 + 66 * day + 76 * dF) * (0.6 + 0.6 * g2), PJ.d); /* Dead grass on the bank — amber, which is what season-old bunchgrass is — and only on * the outer third of the run, so it LINES the wash instead of filling it. */ if (g2 > 0.62 && (u2 < -0.35 || u2 > 0.35) && project(wxp, 0.10 + g2 * 0.34, wzp)) @@ -625,8 +635,97 @@ } } + /* Hoisted to module scope rather than closed over the caller's dF, and that is the contract + * rather than a preference: a function DECLARATION inside draw() allocates a closure every frame, + * and this file runs sixty times a second. */ + function dayFill() { + return (CC.SurfWest && CC.SurfWest.dayFill !== undefined) ? CC.SurfWest.dayFill : 0; + } + function leafC(seedH, dF) { + if (seedH >= dF) return P.slate; + return seedH < dF * 0.42 ? P.timber : P.moss; + } + function wrap(v, b) { return v - b * Math.floor(v / b + 0.5); } + /* ---- A GRAIN OF DUST IS TRANSLUCENT, and by day that stops being a nicety -------------------- + * (veilCell and not veil: drawDust below already has a local `var veil` for the sheet, and a var + * declaration hoists over a function of the same name for the whole of that function's body.) + * emit() REPLACES a cell. That is right at dusk — a grain at lum 74 lands on a road at lum 20-60 + * and is the brighter of the two — and it is the single largest photosensitivity fault the + * daylight pass created anywhere in this world. The same grain landing on a NOON road at lum + * 200-255 is a dark object crossing a bright one, several times a second, over the lower third of + * the frame; the step is the whole contrast between the two rather than the 29% of full scale the + * paragraph above so carefully bounds. + * + * Measured with tools/west-flicker.cjs pinned at noon (the shipped gate never pins the clock, so + * it has only ever measured this world after dark): with the daylight fill in and this element + * drawn, the frontier's own big-step rate was 5.50/s against the city's 2.00/s and its 3-20 Hz + * band 4.92% against 2.80%. With this one element suppressed, 1.75/s and 2.45%. It was all of it. + * The SHIPPED build fails the same way for the same reason — 2.50/s and 4.73% at noon on pristine + * sources — so this is a latent fault the fill made loud, not one it invented. + * + * So by day a grain VEILS. It reads the cell it is about to land on and moves it a fraction of + * the way toward its own level, which is what a translucent particle in front of something does, + * and takes that cell's SWATCH so the whole of the change is the fraction. The step is then + * bounded by alpha rather than by the contrast, whatever the background: 0.42 keeps it under the + * gate's third-of-full-scale line against a lum-255 road. + * + * Rejected 0.30, and the reason is worth writing down because it is counter-intuitive. A thinner + * veil does NOT keep going down: successive grains landing on the same cell in the same frame + * each read the value the last one left, so the field COMPOUNDS toward the dust's own level and + * what a dense preset does to a cell is set by how many grains cross it, not by alpha. At 0.30 + * the 3-20 Hz band went UP (noon 3.02% -> 3.22%) because the same total displacement was being + * delivered in more, smaller writes. The lever that works on a compounding field is the number of + * CELLS each grain touches, which is the streak cap below. + * + * At dFill 0, alpha is exactly 1 and this is emit() to the byte — including the fog, which is + * applied here for emit()'s own reason and must be applied BEFORE the blend, since the cell being + * blended against has already been through it. + * + * The read is a READ. The contract's rule is that nothing may WRITE the typed arrays directly, + * and this still goes out through CC.put with a depth argument; optics.js and sky.js both read + * the frame the same way. */ + function veilCell(f, x, y, ch, col, lum, d, alpha) { + if (x < 0 || y < 0 || x >= V.cols || y >= V.rows) return; + if (lum > 0 && CC.Surf) { lum = CC.Surf.fog(lum, d); if (lum <= 0) ch = 0; } + if (alpha < 0.999) { + var i = y * V.cols + x; + var dl = f.lum[i]; + lum = dl + (lum - dl) * alpha; + if (f.ch[i] !== 0) col = f.col[i]; + /* ---- AND IT DOES NOT TAKE THE CELL'S DEPTH, which is the other half of being translucent -- + * This was the largest remaining daylight flicker fault in the world and it is not in the + * blend at all, it is in the fourth argument to put(). west-dust is layer 22 and west-wagon + * is layer 22 as well, so on a stable sort by layer this file's element draws FIRST — and a + * grain a few metres from the eye that claimed d=10 stopped the wagon forty metres up the + * road from drawing at all. The wagon is a black silhouette on a lum-251 road, so the cell it + * lost went 0 -> 169 -> 0 for the three frames the grain sat there: two steps of two thirds + * of full scale, added to a cell that was already stepping at the wagon's own rate. Measured + * at seed 3 under `dust`, clock pinned at morning: eleven big steps in four seconds against + * seven with this element suppressed, which is the whole of the 2.75/s against the 2.00/s + * tolerance. The same grain at NIGHT is opaque and genuinely does hide the wagon, which is + * correct and is why this is gated on alpha rather than applied always. + * + * A translucent thing does not own the cell it tints, so the depth it writes is the depth + * that was already there, a hair nearer — put() tests strictly, so it has to be nearer by + * something. 0.99999 is one part in a hundred thousand, which at the fog ramp's 210 m range + * is two millimetres and cannot reorder anything the caster resolved. A grain over SKY keeps + * its own depth: the cell's is Infinity, there is nothing behind it to be occluding, and + * every sky element in this world draws at layers 5-9, well before this one. + * + * `d < dc` IS THE VISIBILITY TEST AND IT STAYS. Written without it every grain in the shell + * passed put(), including the ones BEHIND the road, and the element took the whole lower half + * of the frame: measured at seed 7 frame 900 noon, rows 28 to 59 went from facade and floor + * to 200 element cells out of 200, because a grain thirty metres out was overwriting the + * glyph of a road cell twelve metres away. What is given up here is OWNERSHIP of the cell, + * not the right to be in front of it. */ + var dc = f.dist[i]; + if (d < dc && dc < 1 / 0) d = dc * 0.99999; + } + put(f, x, y, ch, col, lum > 255 ? 255 : (lum < 0 ? 0 : lum | 0), d, 3); + } + function drawDust(f) { if (!duOx || !CITY) return; /* Rain settles dust, in the literal sense of what dust does when it gets wet, so the two @@ -677,6 +776,43 @@ * the sky's luminance with a lift for the low sun, which is what makes a plume glow at the ends * of the day. */ var lift = (0.06 + 0.94 * D_SKY) * (1 + 0.55 * D_WARM * D_SUN); + /* ---- AND THE RAMP IS NOT LINEAR IN THE FILL, because the ROAD's is not ---------------------- + * Both numbers below were fitted at dFill 1 and then left linear in it, and the MORNING stop is + * where that shows. dFill is 0.858 there, so the veil is still half opaque — but the ground it + * is veiling has already arrived: the floor prints 61.8% of its cells lit at morning against + * 66.3% at noon, i.e. the background is at 93% of its noon brightness while the mitigation is + * only at 86% of its noon strength. + * + * `dk = f(2 - f)` is the fill with its knee pulled forward — 1-(1-f)^2, which is 0 at 0 and 1 + * at 1, so night is the identity to the byte and noon is unchanged to the byte, and the whole + * of the move lands in the middle where the mismatch is. At morning it reads 0.980 rather than + * 0.858, which puts the alpha at 0.432 instead of 0.502. + * + * WHAT IT IS AND IS NOT WORTH. Measured with the gate's own measurement, clock pinned at + * morning (the shipped tools/west-flicker.cjs never touches the clock), against the linear + * version of the same two lines: the big-step RATE does not move — the fault that was costing + * 2.75/s against a 2.30 tolerance is the depth argument in veilCell() above, not the alpha — + * but the 3-20 Hz band does, seed 42 under `dust` 1.71% -> 1.60% and under `breeze` 1.41% -> + * 1.20%. It is margin rather than a fix, and it is written down as margin. Rejected keying on + * dSky directly, which is the quantity the road actually follows but is 0.657 at DUSK as well + * as at dawn and would have re-tuned this world's signature hour. */ + var dk = dayFill(); dk = dk * (2 - dk); + /* How opaque a grain is allowed to be — see veil() above. 1 at dFill 0, so the tuned frontier + * is unchanged to the byte; 0.42 at noon, which is what holds the step under the gate's line + * against the brightest ground this world can print. */ + var dAlpha = 1 - 0.58 * dk; + /* FIVE CELLS AT NIGHT AND TWO BY DAY, and this is the lever that actually moves the day + * flicker numbers. A streak is n+1 cells that change state together every frame, so the cap is + * very nearly a multiplier on how much of the frame this element is modulating — and by day + * every one of those cells is a bright one. The look survives the cut because a streak only + * reads AS a streak against a dark background: at noon what says "the wind is up" is the whole + * lower band going soft, which is the sheet below, not the individual grains. + * + * HOISTED, and it was in the per-grain loop. dayFill() is a property getter on CC.SurfWest and + * `use` reaches a couple of thousand grains under the dust presets; the comment eleven lines + * above the loop is this file's own argument against that — "taken once per frame rather than + * per particle, which is the whole reason the streak is affordable". */ + var nCap = (5 - 3 * dk) | 0; /* Under a light haze the far shell goes first and what is left is a little dust round your * boots; under a storm the whole valley fills in. The rain's farUse, same shape. */ var farUse = use * clamp(0.34 + 0.46 * amt, 0.22, 1); @@ -709,7 +845,7 @@ * down. Capped at five, past which it stops reading as a particle and starts reading as a * rule drawn on the picture. */ var n = (Math.abs(crossV) * duSpd[i] * 0.028 * V.colK / w) | 0; - if (n > 5) n = 5; + if (n > nCap) n = nCap; /* NOT SCALED BY `amt`, which was the first cut's mistake: tying a grain's brightness to the * same number that decides how many grains there are squares the weather. Measured at 260x60, @@ -744,7 +880,7 @@ * under the step budget where two streaks land on the same cell. */ var lm = base * (1 - k * 0.17); if (lm < 4) continue; - emit(f, sx, py, k === 0 ? gl : (n >= 3 ? G_DASH : G_TICK), hue, lm, d); + veilCell(f, sx, py, k === 0 ? gl : (n >= 3 ? G_DASH : G_TICK), hue, lm, d, dAlpha); } } @@ -761,7 +897,16 @@ * rewritten to avoid. It drifts at a fifth of the wind: a sheet travels, its grains faster. */ if (W_HAZE < 1.55 || CC.reducedMotion) return; var veil = clamp((W_HAZE - 1.55) / 0.75, 0, 1) * settle; - var vl = (10 + 40 * lift) * veil; + /* AND THE SHEET IS A VEIL TOO, in the literal sense of the function above. It was emit(), i.e. + * a replacement, at lum 10-50 — which against a dusk road at lum 20-60 is a pale wash and + * against a NOON road at 200+ is a dark speck, dropped and lifted over up to 44% of the lower + * band as the drift walks the dither. It is the largest single contributor to the frontier's + * daylight big-step rate after the grains themselves, and it fails for exactly the same reason. + * + * It also has to get much brighter: a sheet of suspended dust at midday is LIT dust, the + * brightest thing between you and the far end of the street, and the whole read of a dust storm + * at noon is that the distance whites out rather than blacks out. */ + var vl = (10 + 40 * lift + 168 * (1 - dAlpha) / 0.58) * veil; if (vl < 5) return; var top = Math.floor(V.horizon - V.rows * 0.10); if (top < 0) top = 0; @@ -773,7 +918,8 @@ var sp2 = ((vx2 + 0.5) * 2 / cols - 1) * V.hp; var hv = vnoise((V.yaw + sp2) * 9.0 + (vy - top) * 0.37 + drift, BASE + 0x62); if (hv > dv) continue; - emit(f, vx2, vy, band > 0.55 ? G_DOT : G_TICK, P.white, vl * (0.6 + 0.7 * band), 44); + veilCell(f, vx2, vy, band > 0.55 ? G_DOT : G_TICK, P.white, + vl * (0.6 + 0.7 * band), 44, dAlpha); } } } diff --git a/src/elements/west_range.js b/src/elements/west_range.js index da6f155..444aee6 100644 --- a/src/elements/west_range.js +++ b/src/elements/west_range.js @@ -30,7 +30,8 @@ var P = CC.P, hash2 = CC.hash2, put = CC.put, vnoise = CC.vnoise, clamp = CC.clamp; var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_UNDER = CC.g('_'), G_DOT = CC.g('.'), - G_COMMA = CC.g(','), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_STAR = CC.g('*'); + G_COMMA = CC.g(','), G_TICK = CC.g('`'), G_QUOTE = CC.g("'"), G_STAR = CC.g('*'), + G_o = CC.g('o'); var CITY = null, BASE = 0, Surf = null, WEST = null; function boot(city) { @@ -98,7 +99,16 @@ var sunA = litFace(axis ? 1 : 0, axis ? 0 : 1); var sunB = litFace(axis ? -1 : 0, axis ? 0 : -1); var sun = sunA > sunB ? sunA : sunB; - var pcol = sun > 0.6 ? P.amber : P.slate, plum = sun > 0.6 ? 96 : 26; + /* ---- THE DAY, from the painter that owns it (surf_west.js's dFill) ------------------------- + * `sun > 0.6 ? P.amber : P.slate` is a creosoted pole picked out of the dark by a low sun. At + * noon it is a creosoted pole: dark brown against a bright sky, which is the OPPOSITE relation + * to the background and is what makes a pole line read at midday. So the day swatches are + * timber and stone rather than amber and slate, and the pole gets DARKER against its + * surroundings rather than brighter — the one object in this pass that does. */ + var dF = (CC.SurfWest && CC.SurfWest.dayFill !== undefined) ? CC.SurfWest.dayFill : 0; + var day = hash2(idx, axis, BASE + 0x14) < dF; + var pcol = day ? (sun > 0.6 ? P.timber : P.stone) : (sun > 0.6 ? P.amber : P.slate); + var plum = day ? (sun > 0.6 ? 120 : 86) : (sun > 0.6 ? 96 : 26); for (var k = lo; k <= hi; k++) { var a0 = k * POLE_PITCH + hash2(k, idx, BASE + 0x12) * 3.0; @@ -112,6 +122,19 @@ * fencepost, and the only place the insulators can go. */ var ay = hgt - 0.55; var i; + /* THE INSULATORS, day and near field only. Two white glass knobs on the crossarm, and they + * are the only bright thing on a pole — which is exactly how one reads against a sky. Gated + * on distance because at thirty metres they are the same cell as the crossarm. */ + /* No objVisible() in this file, so the distance test is the projected depth of the pole + * head — which project() has already computed one line up in column(). PJ is the shared + * scratch and is still holding it. */ + if (day && PJ.d < 26) { + for (i = -1; i <= 1; i += 2) { + if (project(wx(axis, a0, cross + i * 0.9), ay + 0.22, wz(axis, a0, cross + i * 0.9))) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_o, + sun > 0.6 ? P.white : P.stone, sun > 0.6 ? 176 : 108, PJ.d); + } + } for (i = -1; i <= 1; i++) { if (!i) continue; var ax2 = wx(axis, a0, cross + i * 0.9), az2 = wz(axis, a0, cross + i * 0.9); @@ -135,11 +158,20 @@ if (st > V.cols * 2) st = 0; for (var q = 1; q < st; q++) { var tq = q / st; - emit(f, lx + Math.round(dx * tq), ly + Math.round(dy * tq), G_DOT, P.slate, - sun > 0.6 ? 40 : 18, ld + (pd - ld) * tq); + emit(f, lx + Math.round(dx * tq), ly + Math.round(dy * tq), G_DOT, + day ? P.timber : P.slate, day ? 96 : (sun > 0.6 ? 40 : 18), + ld + (pd - ld) * tq); } } - emit(f, px, py, G_DOT, P.slate, sun > 0.6 ? 40 : 18, pd); + /* THE WIRE ITSELF, and by day it is a DARK line on a bright sky rather than a faint one + * on a dark sky. Same swatch inversion as the pole, and the same reason: a wire is a + * silhouette at every hour, and slate at gain 0.78 by day would print it as a pale streak + * across the dome. It stays one glyph wide and gets no more ink than it had — a thin + * bright line that a walking camera steps across is the failure the whole project's + * photosensitivity rule is written for, and the fix for it here is to keep it thin AND + * dark, not to make it heavier. */ + emit(f, px, py, G_DOT, day ? P.timber : P.slate, + day ? 96 : (sun > 0.6 ? 40 : 18), pd); lx = px; ly = py; ld = pd; } } diff --git a/src/elements/west_sky.js b/src/elements/west_sky.js index a50d4b5..ec592d8 100644 --- a/src/elements/west_sky.js +++ b/src/elements/west_sky.js @@ -25,11 +25,34 @@ var P = CC.P, g = CC.g, put = CC.put, hash2 = CC.hash2, vnoise = CC.vnoise, clamp = CC.clamp; var G_DOT = g('.'), G_TICK = g('`'), G_QUOTE = g("'"), G_DASH = g('-'), G_EQ = g('='), - G_o = g('o'), G_8 = g('8'); + G_o = g('o'), G_8 = g('8'), G_TILDE = g('~'), G_PLUS = g('+'), G_DQ = g('"'), + G_HASH = g('#'), G_COLON = g(':'), G_UNDER = g('_'), G_PCT = g('%'); /* Past Surf.FOG_END so any facade wins the depth test, and ordered among themselves: the sun is * behind the cloud, the cloud is behind the birds. Same mechanism sky.js uses. */ var D_SUN = 1.02e5, D_CLOUD = 9.6e4, D_BIRD = 8.0e4; + /* ---- AND ONE DEPTH IN FRONT OF sky.js's DECK, for the day cells only --------------------------- + * sky.js's `cloudbase` runs at layer 3 with its own D_CLOUD of 9.5e4 and paints the whole slot in + * P.shadow at lum 26-42, which is correct in the city and at night out here and flatly wrong at + * noon: an overcast midday sky is the BRIGHTEST large surface any frame containing one has, and + * it was arriving as 1538 cells of dark blue-grey over the top of a frontier noon (tallied at + * seed 42 frame 300). CC.put tests `dist < f.dist[i]` strictly, so this file's 9.6e4 loses to it + * everywhere the two overlap however late this element draws. + * + * 9.4e4 is used ONLY by the daylight branch below, so the night frame keeps sky.js's deck exactly + * as it has it and nothing about the tuned hour moves. sky.js is not mine to edit; if it ever + * learns the clock, this constant goes back to D_CLOUD and the branch stays. */ + var D_CLOUD_DAY = 9.4e4; + + /* The one published day number, from the painter that owns it — see surf_west.js's dFill. Two + * definitions of "how much day is in the frame" is two clocks, and they disagree for one frame + * every time the viewer presses T. */ + function dayFill() { + if (!CC.SurfWest) return 0; + return CC.SurfWest.dayFill; + } + var INK = [G_TICK, G_DOT, G_UNDER, G_DASH, G_COLON, G_TILDE, G_DQ, G_PLUS, G_EQ, G_HASH, G_PCT]; + function ink(t) { var i = (t * 11) | 0; return INK[i < 0 ? 0 : (i > 10 ? 10 : i)]; } var W_CLOUD = 0.1, W_HAZE = 0.3, W_WIND = 0.2, W_RAIN = 0; function bindWeather() { @@ -93,14 +116,31 @@ * here are the halo and the disc itself is small. */ var SUN_ALT = 0.16, SUN_R = 0.030; + /* ---- AND IT CLIMBS, once there is a day for it to climb through ------------------------------ + * The paragraph above is an argument for pinning the sun at nine degrees, and it is right about + * dusk and wrong about every other hour: at noon the clock puts the sun at 0.95 rad, the frame + * reaches atan(horizon/scale) = 0.56 rad, and a sun drawn at 0.16 is an amber blob sitting on the + * rooftops in the middle of the day. What the eye reads noon by is that there is NO sun in the + * picture and everything below is lit from straight above. + * + * So the drawn altitude is the pinned one blended toward the clock's by the day fill. At dFill 0 + * it is exactly 0.16 and the tuned frame is untouched — including at night, where this element + * currently draws a halo and where removing it is not mine to decide. At dusk (dFill 0.055) it + * moves by a seventh of a degree. By morning the sun has climbed out of the top of the frame and + * plot() clips it, which costs nothing and is the correct picture. */ + function drawAlt() { + var live = CC.SurfWest ? CC.SurfWest.SUN_ALT : SUN_ALT; + return SUN_ALT + (live - SUN_ALT) * dayFill(); + } + CC.ELEMENTS.push({ name: 'west-sun', layer: 5, world: 'west', draw: function (frame, cam) { setup(frame, cam); - var az = sunAz(), ca = Math.cos(SUN_ALT); - var p = proj(Math.sin(az) * ca, Math.sin(SUN_ALT), Math.cos(az) * ca); + var al = drawAlt(), az = sunAz(), ca = Math.cos(al); + var p = proj(Math.sin(az) * ca, Math.sin(al), Math.cos(az) * ca); if (!p.ok) return; var cx = p.x, cy = p.y; var rw = SUN_R * CB.colsPerTan / p.w, rh = SUN_R * CB.scale / p.w; @@ -166,6 +206,7 @@ draw: function (frame, cam, t) { setup(frame, cam); if (W_CLOUD < 0.03) return; + var dF = dayFill(); var tt = CC.reducedMotion ? 0 : t * (0.004 + 0.016 * W_WIND); var az0 = sunAz(); /* One pass over the sky rows of the frame. Cheaper than walking a sphere and exact: every @@ -195,12 +236,60 @@ * the drift rate, which is 0.004-0.02 of a cycle a second. */ var body = vnoise(Math.floor(lad) * 3.1 + bear * 2.0 + tt * 3, 0x9C1); /* Not every rung of the ladder is cloud; cover is the weather. */ + /* Cover is the weather at every hour; what the DAY changes is that the cells inside a + * cloud get painted. See the two branches below. */ if (body > 0.22 + 0.68 * W_CLOUD) continue; /* Keyed on the SKY, not on the glass. hash2(x, y) welds the dither to the screen, so * turning the camera slides the cloud through a fixed stipple — the same bug the star * field had before surfaces.js started hashing on bearing and elevation. */ var d = hash2(Math.floor(bear * 220), Math.floor(el * 900), 0x33B); if (fb > 0.66) continue; // the gap between two bars + /* ---- THE DECK TURNS OVER WITH THE DAY ----------------------------------------------- + * A cloud at dusk is lit FROM UNDERNEATH and is a silhouette everywhere else, which is + * what the two night branches draw and why they are the best thing in this sky. A cloud + * at noon is the exact inverse: lit from ABOVE, so the top of every bar is the brightest + * white in the frame and the underside is the shaded part — and it is OPAQUE, where a + * dusk cloud is a shape you read off one bright edge. + * + * Both facts are drawn on the same ladder, because the geometry of a stacked deck does + * not change with the hour; what changes is which end of each bar has the light on it and + * how much of the bar gets ink. The crossover is dithered on the day fill exactly as the + * walls are, so the sky turns over cell by cell rather than as one plane. + * + * The day cells go in at D_CLOUD_DAY so they win against sky.js's own deck; the night + * cells keep D_CLOUD and lose to it, which is the shipped behaviour. */ + var isDay = hash2(Math.floor(bear * 111), Math.floor(el * 640), 0x6B2) < dF; + if (isDay) { + /* Opaque: 0.86 of the bar takes ink against the night branch's 0.16-0.34. A midday deck + * with holes in it reads as a stipple over black, which is what the dusk treatment + * looked like when the day arrived and it did not survive being looked at. */ + if (d > 0.86) continue; + if (fb > 0.50) { + /* The underside, in shade. Never `shadow` — core.js lifts shadow by day precisely + * because a shaded thing under a bright sky is filled — so it is stone going to + * indigo, which is the palette's own "shade with the sky in it". */ + plot(frame, x, y, ink(0.30 + 0.26 * d), d > 0.55 ? P.stone : P.indigo, + (54 + 46 * d) * (0.5 + 0.5 * W_CLOUD), D_CLOUD_DAY); + } else { + /* The top, in full sun. This is the brightest large surface a frontier noon has and + * it is written like one: white at the crown, sand where the bar thins, on the heavy + * half of the ink ramp. */ + /* THE TOP IS HELD UNDER THE SKY IT SITS IN, and that is a photosensitivity number + * before it is an aesthetic one. `body` jumps discontinuously whenever the ladder's + * integer part steps, so a whole rung of the deck can switch on or off between two + * frames — which is fine when the rung is a dark silhouette against a dark sky (26 to + * 56, the night branch below) and is a large-area step when it is a white mass + * against a blue one. Measured with tools/west-flicker.cjs pinned at noon, this + * element carried the frontier's worst per-cell step from 79.2% to 84.3%; written at + * 180 rather than 220 it is back inside surf_west.js's own day sky ladder, which + * tops out at 214, and the deck stops being able to out-step the dome behind it. */ + var top = 1 - fb / 0.50; + plot(frame, x, y, ink(0.52 + 0.34 * top + 0.14 * (d - 0.5)), + top > 0.45 ? P.white : P.sand, + (104 + 72 * top) * (0.76 + 0.30 * d), D_CLOUD_DAY); + } + continue; + } if (fb > 0.50) { /* THE LIT UNDERSIDE. One or two rows, ember going to amber where the sun is, and the * brightest thing in the sky after the disc itself. */ @@ -218,6 +307,82 @@ } }); + /* ========================================================================= the deck by day === + * A REPAIR, and a narrow one. sky.js's `cloudbase` is the only element in this project that can + * cover the whole slot, and it paints in P.shadow at lum 26-42 on purpose — its own comment + * explains that slate at that lum printed as a LIT cell and turned the sky into the brightest + * flat area in a picture whose subject is a dark street. That is right in the city, right on this + * frontier at night, and wrong at noon by the widest margin anything in this world gets wrong: + * an overcast midday sky is the brightest large surface any frame containing one has, and 1538 + * cells of dark blue-grey were arriving over the top of a frontier noon (tallied at seed 42 + * frame 300, which is 13% of the whole frame). + * + * sky.js is not mine to edit, and the deck belongs to two worlds so it should not simply be + * turned off out here either. So this walks the slot AFTER cloudbase and after the bars, finds + * the cells that are still the night deck, and repaints them as the sky they are covering. It + * identifies them by what they are — a cell painted by an element, in P.shadow, at a depth out + * past the world — rather than by a constant copied from another file, so it repairs the deck and + * nothing else, and it cannot touch a bird (D_BIRD is 8.0e4, inside the test) or a facade. + * + * It costs nothing at night: dF is 0 and the function returns on its first line. + * + * WHAT I WOULD RATHER HAVE DONE: give cloudbase's `base`, `hue` and `dens` a daylight branch off + * CC.Daylight, the way this file's own deck now has one. That is four lines in sky.js and it + * would fix the city's noon as well, which has the same fault for the same reason. + * ========================================================================================== */ + CC.ELEMENTS.push({ + name: 'west-daysky', + layer: 7, + world: 'west', + draw: function (frame, cam) { + var dF = dayFill(); + if (dF <= 0.002) return; + setup(frame, cam); + var cols = frame.cols, col = frame.col, lum = frame.lum, dist = frame.dist, kind = frame.kind; + var maxRow = Math.floor(CB.horizon); if (maxRow > CB.rows - 1) maxRow = CB.rows - 1; + var x, y, i, h; + for (y = 0; y <= maxRow; y++) { + for (x = 0; x < cols; x++) { + i = y * cols + x; + if (kind[i] !== 3 || col[i] !== P.shadow || dist[i] < 9.0e4) continue; + /* Dithered against dF on the SKY rather than on the screen, so the repair crosses over + * with the hour instead of switching, and so it does not crawl when the camera turns. + * + * THE ANCHOR IS THE PROJECTION'S OWN, and it was a hardcoded 260. Turning the camera by + * dyaw slides a fixed world bearing LEFT by colsPerTan * dyaw columns — that is proj()'s + * own arithmetic, VP.x = (s/w) * colsPerTan + cols/2 — so x + yaw * colsPerTan is the + * quantity that stands still while the frame moves under it. 260 is that number for no + * grid this build ever draws: colsPerTan is cols / (2 tan(fov/2)), which is 84 at 120 + * columns, 139 at 200 and 279 at 400, so the constant over-compensated by 87% at the + * default size and under-compensated by 7% at the largest, and the comment above claimed + * the opposite of what the code did at the size it is drawn at. The live value is exact + * at the centre of the frame and 34% short at the edges, where the tangent stretches and + * the true rate is colsPerTan * sec^2(fov/2) — the same linearisation proj() lives with, + * and well inside a dither's own noise. Parenthesised because `+` binds tighter than `|`: + * the |0 was always applying to the whole sum, which is what was wanted and what nothing + * said. */ + h = hash2((x + (cam.yaw || 0) * CB.colsPerTan) | 0, y, 0x4D77); + if (h > dF) continue; + /* The deck's own depth is kept in the cell, and the repair goes in one metre nearer so a + * later pass of cloudbase in the same frame cannot win it back. Written as ice going to + * white with height, which is the same pair surf_west.js's day sky ladder uses — this is + * the same sky, seen through a hole in a deck that is lit from above. */ + var up = 1 - y / (maxRow + 1); + /* WHITE LEADS AND ICE FOLLOWS. ice is 90,240,255 — the most saturated swatch in the + * table — and at the lums a daylight sky wants it prints as a cyan that no sky has ever + * been; written as the majority it turned the top of the frame turquoise. It is the right + * swatch for the COLD part of a dome (core.js lifts it 0.36 -> 0.66 for exactly that) but + * a repaired deck cell is a HOLE IN A CLOUD, and the light coming through one is white + * with a little of the sky in it. So ice is a third of the cells and it goes to the ones + * high in the frame, where the dome actually is blue. */ + plot(frame, x, y, ink(0.30 + 0.26 * up + 0.20 * h), + h < 0.60 ? P.white : (up > 0.45 ? P.ice : P.stone), + (96 + 74 * up) * (0.80 + 0.34 * h), dist[i] - 1); + } + } + } + }); + /* =================================================================================== birds === * Three turkey vultures on one thermal, which is a real thing and also the cheapest way to put a * living creature in the sky: a vulture on a thermal does not flap, so the whole animation is a @@ -253,10 +418,16 @@ * end-on it is a single dot. cos of the phase IS the aspect. */ var asp = Math.abs(Math.cos(ph)); var x = p.x, y = p.y; - plot(frame, x, y, G_DOT, P.slate, 62, D_BIRD); + /* A vulture against a bright sky is a SILHOUETTE, and slate at lum 62 is neither: by + * day slate prints at gain 0.78 and the bird comes out lighter than the cloud behind it. + * timber at a low lum is the darkest warm ink available and reads as a shape with the sun + * behind it, which is what one actually looks like. */ + var dF = dayFill(); + var bc = dF > 0.5 ? P.timber : P.slate, bl = 62 - 22 * dF; + plot(frame, x, y, dF > 0.5 ? G_TILDE : G_DOT, bc, bl, D_BIRD); if (asp > 0.45) { - plot(frame, x - 1, y - (asp > 0.8 ? 1 : 0), G_TICK, P.slate, 54, D_BIRD); - plot(frame, x + 1, y - (asp > 0.8 ? 1 : 0), G_QUOTE, P.slate, 54, D_BIRD); + plot(frame, x - 1, y - (asp > 0.8 ? 1 : 0), G_TICK, bc, bl - 8, D_BIRD); + plot(frame, x + 1, y - (asp > 0.8 ? 1 : 0), G_QUOTE, bc, bl - 8, D_BIRD); } } } diff --git a/src/elements/west_town.js b/src/elements/west_town.js index 1d69a9a..2ad3c63 100644 --- a/src/elements/west_town.js +++ b/src/elements/west_town.js @@ -35,7 +35,32 @@ var G_PIPE = CC.g('|'), G_DASH = CC.g('-'), G_EQ = CC.g('='), G_DOT = CC.g('.'), G_COLON = CC.g(':'), G_TICK = CC.g('`'), G_CARET = CC.g('^'), G_STAR = CC.g('*'), G_0 = CC.g('0'), G_O = CC.g('O'), G_o = CC.g('o'), G_HASH = CC.g('#'), G_PLUS = CC.g('+'), - G_TILDE = CC.g('~'); + G_TILDE = CC.g('~'), G_UNDER = CC.g('_'), G_SLASH = CC.g('/'), G_PCT = CC.g('%'), + G_DQ = CC.g('"'); + + /* ---- THE DAY, AND WHERE THIS FILE GETS IT ----------------------------------------------------- + * One number, read off the painter that owns it — surf_west.js's dFill, published as `dayFill`. + * Every swatch in this file is `sun > 0.6 ? P.amber : P.slate`: sunlit timber and timber in + * shade, spelled in the only two swatches the palette had when this world was built. Both are + * wrong at noon and wrong in the same way the walls were. Amber is a sodium DISCHARGE — core.js + * drops it from 0.50 to 0.42 by day because a sodium tube at midday is a grey object — and slate + * is deliberately blue. A veranda post at noon is a dusty pine post: sand in the sun, timber in + * the shade, and neither of those swatches existed when this was written. + * + * OBJECT BY OBJECT AND NOT CELL BY CELL. A wall crosses over dithered per cell because a wall is + * a texture; a post is one thing and half a post in each swatch is a stripe down it. So the + * crossover is hashed on the object's own lattice index and the colonnade turns over one post at + * a time over the ninety seconds the ramp takes. A post is about eight cells, so what the + * photosensitivity gate sees is eight cells stepping once per 420 s clock cycle, which is four + * orders of magnitude under anything it measures. */ + function dayF() { + var W = CC.SurfWest; + return W && W.dayFill !== undefined ? W.dayFill : 0; + } + /* Sunlit timber and timber in shade, by the hour. `day` is the object's own crossover roll. */ + function woodC(sun, day) { + return day ? (sun > 0.6 ? P.sand : P.timber) : (sun > 0.6 ? P.amber : P.slate); + } var CITY = null, BASE = 0, Surf = null, WEST = null; function boot(city) { @@ -176,8 +201,7 @@ /* A post is a black cut-out with one lit edge — the house idiom for a near object. The lit * edge is on the sun side and it is what makes a colonnade read as round timber rather than * as a row of slots. */ - var pcol = sun > 0.6 ? P.amber : P.slate; - var plum = sun > 0.6 ? 74 : 20; + var dF = dayF(); for (var k = lo; k <= hi; k++) { var along = k * POST + 0.5; @@ -185,18 +209,72 @@ if (!w) continue; if (!frontage(axis, along - POST * 0.5, POST, face, dirIn)) continue; var hh = hash2(k, idx * 2 + s, BASE + (axis ? 0x51 : 0x52)); + var day = hash2(k, idx * 2 + s, BASE + 0x54) < dF; + var pcol = woodC(sun, day); + /* 168 and 92 against 74 and 20. The night pair is a post picked out of the dark by the last + * of the sun and the lantern beside it; the day pair is a post standing in the open with a + * bone-white road under it throwing light back up. Held under the awning fascia above it so + * the colonnade still reads top-lit. */ + var plum = day ? (sun > 0.6 ? 168 : 92) : (sun > 0.6 ? 74 : 20); /* The post. Two cells wide inside 12 m so it has some mass when you walk past it. */ column(f, wx(axis, along, postC), wz(axis, along, postC), 0.0, AWN_Y, G_PIPE, pcol, plum, w < 12 ? 1 : 0); + /* ---- NEAR-FIELD ONLY: the things you can see on a post at ten metres and not at thirty. + * A stone pad under it (a post set straight in dirt rots out in a season, so they stand on + * a rock), and the diagonal knee brace up to the awning plate. Both are lod-gated on w and + * both are day-gated, because at dusk this post is a silhouette with one lit edge and + * putting joinery on a silhouette is drawing what the eye cannot see. */ + if (day && w < 14) { + if (project(wx(axis, along, postC), 0.10, wz(axis, along, postC))) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_UNDER, + sun > 0.6 ? P.stone : P.timber, sun > 0.6 ? 132 : 74, PJ.d); + /* The brace runs in `cross`: it leans from the post out under the awning plate, so it + * steps in the direction of the building and up at the same time. Three samples is + * enough — at ten metres it is three cells long. */ + var bq, by2, bc2; + for (bq = 0; bq < 3; bq++) { + by2 = AWN_Y - 0.30 - bq * 0.22; + bc2 = postC + dirIn * (0.22 + bq * 0.20); + if (project(wx(axis, along, bc2), by2, wz(axis, along, bc2))) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_SLASH, + sun > 0.6 ? P.sand : P.timber, sun > 0.6 ? 118 : 66, PJ.d); + } + } + /* THE AWNING, one bay at a time. It used to be a single run down the whole street and that * is wrong twice over: it bridged every alley mouth and vacant lot in the block, and a * fifty-metre span sampled at a fixed rate is coarse near the camera and wasteful far from * it. Drawn per bay it inherits the frontage test above for free. */ beam(f, axis, along - POST, along, postC, AWN_Y + 0.06, G_EQ, - sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 96 : 26); - beam(f, axis, along - POST, along, postC, AWN_Y - 0.12, G_DASH, P.shadow, 0); + day ? (sun > 0.6 ? P.sand : P.stone) : (sun > 0.6 ? P.amber : P.slate), + day ? (sun > 0.6 ? 196 : 112) : (sun > 0.6 ? 96 : 26)); + /* THE AWNING'S OWN SHADOW, and by day it is the reason a veranda reads as a veranda. At + * night it is drawn at lum 0, i.e. a hole punched in whatever is behind the fascia, which + * is exactly right against a dark wall and reads as nothing at all against a bright one. + * By day it is the dark line the fascia throws on the shopfront behind it, so it gets the + * shade swatch and enough lum to be a line rather than a gap. */ + beam(f, axis, along - POST, along, postC, AWN_Y - 0.12, G_DASH, + day ? P.indigo : P.shadow, day ? 58 : 0); + + /* ---- THE CANVAS, one veranda in three and day only ----------------------------------- + * Half the awnings on a frontier main street are painted duck stretched on a frame, and + * the thing that makes one recognisable at any distance is that it is STRIPED. Two colours + * alternating on the bay pitch is four cells of drawing and it is the only pattern in this + * world that is man-made rather than weathered. + * + * Day only for the reason the ghost sign is day only: at dusk this is a silhouette with a + * lit edge and a stripe on a silhouette is not visible. Alternated on the BAY index rather + * than hashed per cell, so the stripes hold still as the camera walks — a stripe that + * re-rolls is a shimmer, and this is a large near-field object. */ + if (day && hh < 0.34) { + var stripe = (k & 1) === 0; + beam(f, axis, along - POST, along, postC + dirIn * 0.30, AWN_Y + 0.20, G_HASH, + stripe ? P.white : P.ember, sun > 0.6 ? (stripe ? 190 : 150) : (stripe ? 104 : 84)); + beam(f, axis, along - POST, along, postC + dirIn * 0.62, AWN_Y + 0.34, G_EQ, + stripe ? P.ember : P.white, sun > 0.6 ? (stripe ? 150 : 190) : (stripe ? 84 : 104)); + } /* A lantern on one post in three, and never two in a row — a porch light is a thing a * shopkeeper hangs, not a street lighting scheme. It is the brightest object in the world @@ -207,11 +285,28 @@ var lx = Math.floor(PJ.x), lr = Math.floor(PJ.y), ld = PJ.d; /* The flame, then the glass around it. Fog is applied by emit, so a lantern at the far * end of the street dims with everything else instead of hanging in the dark. */ - emit(f, lx, lr, G_o, P.amber, 236, ld); - emit(f, lx, lr - 1, G_DOT, P.warm, 150, ld); - if (ld < 22) { - emit(f, lx + 1, lr, G_TICK, P.warm, 108, ld); - emit(f, lx - 1, lr, G_TICK, P.warm, 108, ld); + /* THE FLAME GOES OUT BY DAY, and this is the one place in the pass where the day + * takes something away rather than adding it. A kerosene porch lantern burning at noon + * is a thing nobody has ever done, and at amber 236 it was the brightest object in a + * midday frame — an oil lamp outshining the sun. What is left is the HOUSING: a small + * brass-and-glass box hung off the post, which is gold in the sun and timber out of it + * and is a better object than the flame was, because it is a shape rather than a blob. + * Scaled continuously on the fill, so it dims through the morning instead of blowing + * out on one frame. */ + var lk = 1 - dF; + if (lk > 0.02) { + emit(f, lx, lr, G_o, P.amber, 236 * lk, ld); + emit(f, lx, lr - 1, G_DOT, P.warm, 150 * lk, ld); + if (ld < 22) { + emit(f, lx + 1, lr, G_TICK, P.warm, 108 * lk, ld); + emit(f, lx - 1, lr, G_TICK, P.warm, 108 * lk, ld); + } + } + if (dF > 0.02) { + emit(f, lx, lr, G_0, sun > 0.6 ? P.gold : P.timber, + (sun > 0.6 ? 150 : 84) * dF, ld); + emit(f, lx, lr - 1, G_CARET, sun > 0.6 ? P.gold : P.timber, + (sun > 0.6 ? 122 : 66) * dF, ld); } } } @@ -231,12 +326,14 @@ var lo = Math.floor(((axis ? V.ox : V.oz) - 48) / RAIL_PITCH); var hi = Math.floor(((axis ? V.ox : V.oz) + 48) / RAIL_PITCH); + var dF = dayF(); for (var s = 0; s < 2; s++) { var face = s ? SPAN.c1 : SPAN.c0, dirIn = s ? -1 : 1; var sun = litFace(nX(axis, s), nZ(axis, s)); var edge = face + dirIn * (pave + 0.15); // just off the boardwalk, in the road for (var k = lo; k <= hi; k++) { + var day = hash2(k, idx * 2 + s, BASE + 0x64) < dF; var h0 = hash2(k, idx * 2 + s, BASE + 0x61); if (h0 > 0.62) continue; var along = k * RAIL_PITCH + h0 * 9; @@ -249,23 +346,39 @@ /* A HITCHING RAIL. Two short posts and a bar at 1.05 m — waist height on the figures * street.js draws, which is what makes it read as furniture rather than as fence. */ var L = 3.6 + kind * 3.2; - column(f, wx(axis, along, edge), wz(axis, along, edge), 0, 1.28, G_PIPE, - sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 62 : 18, 0); - column(f, wx(axis, along + L, edge), wz(axis, along + L, edge), 0, 1.28, G_PIPE, - sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 62 : 18, 0); - beam(f, axis, along, along + L, edge, 1.06, G_DASH, - sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 72 : 20); + var rc = woodC(sun, day), rl = day ? (sun > 0.6 ? 148 : 80) : (sun > 0.6 ? 62 : 18); + column(f, wx(axis, along, edge), wz(axis, along, edge), 0, 1.28, G_PIPE, rc, rl, 0); + column(f, wx(axis, along + L, edge), wz(axis, along + L, edge), 0, 1.28, G_PIPE, rc, rl, 0); + beam(f, axis, along, along + L, edge, 1.06, G_DASH, rc, + day ? (sun > 0.6 ? 162 : 88) : (sun > 0.6 ? 72 : 20)); + /* THE SHADOW THE RAIL THROWS, day only and near field only. A hitching rail at noon + * casts a hard bar across the dust two metres away, and that bar is worth more than the + * rail is: it is the only thing in the frame that says the light is coming from + * overhead. Drawn on the ground plane, in the shade swatch, at a lum well under the road + * around it. It is not a step for the gate to worry about — it is a static shape welded + * to a static object, and neither moves. */ + if (day && objVisible(axis, along, edge, 0.8) < 20) + beam(f, axis, along + 0.5, along + L + 0.5, edge - dirIn * 1.15, 0.02, G_DASH, + P.timber, sun > 0.6 ? 62 : 34); } else if (kind < 0.74) { /* A WATER TROUGH. A dark box with a lit rim, and — the only reason it is worth drawing — * a surface in it, which is the one horizontal reflector at ground level in a world with * no wet road. It picks up the sky, so it is ember at dusk and it is the brightest thing * on the ground. */ var TL = 2.5; - beam(f, axis, along, along + TL, edge, 0.62, G_EQ, sun > 0.6 ? P.white : P.slate, - sun > 0.6 ? 76 : 24); - beam(f, axis, along, along + TL, edge, 0.30, G_HASH, P.shadow, 0); + beam(f, axis, along, along + TL, edge, 0.62, G_EQ, + day ? (sun > 0.6 ? P.sand : P.stone) : (sun > 0.6 ? P.white : P.slate), + day ? (sun > 0.6 ? 172 : 96) : (sun > 0.6 ? 76 : 24)); + /* The body of the trough. At night it is a hole, which is right against a dark road; by + * day it is wet timber, which is the darkest thing at ground level and reads as one. */ + beam(f, axis, along, along + TL, edge, 0.30, G_HASH, + day ? P.timber : P.shadow, day ? 66 : 0); + /* THE WATER. It is a mirror, so what is in it is the SKY, and the sky is a different + * colour at the two ends of the day: ember at dusk, which is the whole reason this + * object is here, and a hard white-blue sheet at noon with the sun in it. */ beam(f, axis, along + 0.15, along + TL - 0.15, edge - dirIn * 0.02, 0.55, - G_TILDE, P.ember, 128); + G_TILDE, day ? (sun > 0.6 ? P.pure : P.ice) : P.ember, + day ? (sun > 0.6 ? 196 : 150) : 128); } else { /* BARRELS AND CRATES, up on the boardwalk against the wall where a shopkeeper would put * them. Round ones and square ones, and the difference is one glyph. */ @@ -277,8 +390,14 @@ if (!objVisible(axis, ba, bc, 0.8)) continue; var tall = 0.42 + bh * 0.62; column(f, wx(axis, ba, bc), wz(axis, ba, bc), 0.18, 0.18 + tall, - bh < 0.33 ? G_O : G_HASH, sun > 0.6 ? P.amber : P.slate, - sun > 0.6 ? 56 : 16, 1); + bh < 0.33 ? G_O : G_HASH, woodC(sun, day), + day ? (sun > 0.6 ? 142 : 78) : (sun > 0.6 ? 56 : 16), 1); + /* The hoop on a barrel and the lid boards on a crate, near field and day only. One + * cell each, and they are the difference between a cylinder and a blob. */ + if (day && objVisible(axis, ba, bc, 0.8) < 13 && + project(wx(axis, ba, bc), 0.18 + tall * 0.62, wz(axis, ba, bc))) + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), bh < 0.33 ? G_DASH : G_EQ, + sun > 0.6 ? P.stone : P.timber, sun > 0.6 ? 168 : 92, PJ.d); } } } @@ -308,6 +427,8 @@ var w = objVisible(0, cz, cx, 2.0); if (!w) continue; var sun = litFace(WEST ? WEST.SUN_X : -1, WEST ? WEST.SUN_Z : 0); + var dF = dayF(); + var day = rec.seed < dF; // one crown's crossover, from its own lot roll var lum = 66, col = P.amber; if (rec.crown === 1) { @@ -315,29 +436,45 @@ * and it is the reason a chimney is worth more than the eight cells it costs: a slow * vertical drift is what tells you the town is inhabited. */ var ch2 = 1.1 + rec.seed * 0.9; - column(f, cx, cz, h, h + ch2, G_HASH, P.slate, 30, 1); + /* Brick or fieldstone, and by day it is the only masonry above a roofline out here. */ + column(f, cx, cz, h, h + ch2, G_HASH, day ? (sun > 0.6 ? P.stone : P.timber) : P.slate, + day ? (sun > 0.6 ? 156 : 88) : 30, 1); emit2smoke(f, cx, cz, h + ch2, rec); } else if (rec.crown === 2) { /* A WATER TANK on legs — four verticals and a drum, and the most recognisable roofline * object of the period after the false front itself. */ var ty = h + 1.5, td = 1.5 + rec.seed * 0.8; - column(f, cx - 0.7, cz - 0.7, h, ty, G_PIPE, P.slate, 24, 0); - column(f, cx + 0.7, cz - 0.7, h, ty, G_PIPE, P.slate, 24, 0); - column(f, cx - 0.7, cz + 0.7, h, ty, G_PIPE, P.slate, 24, 0); - column(f, cx + 0.7, cz + 0.7, h, ty, G_PIPE, P.slate, 24, 0); + var lc = day ? P.timber : P.slate, ll = day ? 82 : 24; + column(f, cx - 0.7, cz - 0.7, h, ty, G_PIPE, lc, ll, 0); + column(f, cx + 0.7, cz - 0.7, h, ty, G_PIPE, lc, ll, 0); + column(f, cx - 0.7, cz + 0.7, h, ty, G_PIPE, lc, ll, 0); + column(f, cx + 0.7, cz + 0.7, h, ty, G_PIPE, lc, ll, 0); for (var q = 0; q < 5; q++) { var qx = cx - 0.9 + q * 0.45; - column(f, qx, cz, ty, ty + td, G_0, sun > 0.6 ? P.amber : P.slate, - sun > 0.6 ? 86 : 26, 0); + /* THE STAVES, and by day they are the point: a tank is a drum of vertical boards with + * two iron bands round it, and against a bright sky the bands are the darkest line on + * the skyline. `qq` picks which stave is nearest the sun so the drum is shaded round + * rather than flat — a flat drum at noon is a rectangle. */ + var qq = q / 4; + column(f, qx, cz, ty, ty + td, G_0, + day ? (sun > 0.6 ? (qq < 0.55 ? P.sand : P.stone) : P.timber) + : (sun > 0.6 ? P.amber : P.slate), + day ? (sun > 0.6 ? 190 - 60 * qq : 92) : (sun > 0.6 ? 86 : 26), 0); + } + beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td, G_EQ, + day ? (sun > 0.6 ? P.sand : P.stone) : P.amber, day ? 176 : 96); + if (day) { + beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td * 0.62, G_DASH, P.timber, 68); + beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td * 0.22, G_DASH, P.timber, 68); } - beam(f, 0, cz - 1.0, cz + 1.0, cx, ty + td, G_EQ, P.amber, 96); } else { /* A STEEPLE, or a windmill — the two things out here that are taller than anything else * and the only reason the eye ever goes above the second storey. Both are a thin shaft * with something on top; the roll decides which. */ var mill = rec.seed > 0.55; var sy = h + 2.2 + rec.face * 3.4; - column(f, cx, cz, h, sy, G_PIPE, sun > 0.6 ? P.amber : P.slate, sun > 0.6 ? 72 : 22, 0); + column(f, cx, cz, h, sy, G_PIPE, woodC(sun, day), + day ? (sun > 0.6 ? 162 : 88) : (sun > 0.6 ? 72 : 22), 0); if (mill) { /* ---- THE WHEEL, AND WHY IT DOES NOT TURN THE WAY IT FIRST DID --------------------- * A rotating windmill is the single most dangerous object either world has ever @@ -361,19 +498,23 @@ var mx = Math.floor(PJ.x), my = Math.floor(PJ.y), md = PJ.d; for (var b2 = 0; b2 < 12; b2++) { var an = b2 * Math.PI / 6; + /* The rim stays STATIC — see the paragraph above, it is the whole reason this + * wheel passes the gate — and only its swatch follows the hour. Against a bright + * noon sky a galvanised rim is a dark ring, so it goes to stone rather than up. */ emit(f, mx + Math.round(Math.cos(an) * 2.2), my + Math.round(Math.sin(an) * 1.2), - G_PLUS, P.slate, 54, md); + G_PLUS, day ? P.stone : P.slate, day ? 92 : 54, md); } - emit(f, mx, my, G_O, P.amber, 120, md); + emit(f, mx, my, G_O, day ? P.timber : P.amber, day ? 96 : 120, md); var sp = CC.reducedMotion ? 0.9 : V.t * 0.5 * (0.3 + 0.5 * W_WIND); emit(f, mx + Math.round(Math.cos(sp) * 2.2), my + Math.round(Math.sin(sp) * 1.2), G_STAR, P.amber, 128, md); } } else { /* A bell tower: a taper and a cross. */ - column(f, cx, cz, sy, sy + 1.2, G_CARET, P.white, 84, 0); + column(f, cx, cz, sy, sy + 1.2, G_CARET, P.white, day ? 190 : 84, 0); if (project(cx, sy + 1.5, cz)) - emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_PLUS, P.amber, 148, PJ.d); + emit(f, Math.floor(PJ.x), Math.floor(PJ.y), G_PLUS, + day ? (sun > 0.6 ? P.gold : P.stone) : P.amber, day ? 168 : 148, PJ.d); } } } @@ -411,10 +552,14 @@ /* Thins with height, and the fade is smooth so the top of the plume dissolves rather than * ending. slate at 46-104 against a sky that runs 120-200: a soft column, and a step of * under a third of full scale wherever the edge does move. */ - var lum = 104 * (1 - u) * (1 - u * 0.5); + var dF = dayF(); + /* Wood smoke against a bright sky is DARKER than the sky, not brighter — the day version of + * the sentence above, and the reason this cannot simply follow everything else up. It stays + * a soft column either way, so the step at its moving edge is the same size it always was. */ + var lum = (104 + 22 * dF) * (1 - u) * (1 - u * 0.5); if (lum < 6) continue; emit(f, Math.floor(PJ.x), Math.floor(PJ.y), u < 0.35 ? G_HASH : (u < 0.7 ? G_COLON : G_DOT), - P.slate, lum, PJ.d); + dF > 0.5 ? P.stone : P.slate, lum, PJ.d); } } diff --git a/src/surf_moon.js b/src/surf_moon.js index 019b517..15b7288 100644 --- a/src/surf_moon.js +++ b/src/surf_moon.js @@ -204,6 +204,14 @@ * is what every element file will read to lay a shadow down, and a shadow that keeps the sun's * length after the sun has gone is the sort of thing nobody notices and everybody feels. */ SUN_ALT = SUN_ALT + (EARTH_ALT - SUN_ALT) * dNight; + + /* The slope-shading gain, which is 1/tan(alt) normalised at the middle of the Apollo band and + * clamped — see the block on SLOPE_K down in the floor section. Computed here because it is a + * fact about the light, it changes once a frame, and floorTex must not carry a tan() call six + * thousand times over. The clamp is what keeps a 5-degree sun from turning the plain into + * corrugated iron; the floor at 0.6 is what stops a high sun flattening it out altogether. */ + var tg = Math.tan(SUN_ALT); if (tg < 0.02) tg = 0.02; + SLOPE_G = clamp(0.255 / tg, 0.6, 1.9); } /* ---- weather, sampled once per frame ------------------------------------------------------------ @@ -425,23 +433,51 @@ return fset(hv < 0.03 ? G_DOT : G_COMMA, P.slate, 16 + hv * 96); } - /* ---- the two surfaces, and there are only two --------------------------------------------------- - * city.js's style 7 is regolith and style 8 is rock, and nothing else exists. They are not two - * materials so much as two SCALES of the same one: rock is a coherent block with fracture planes - * and a hard rim, regolith is the powder that block breaks down into, and the difference the eye - * actually reads at character resolution is the shape of the top edge — a rock has a hard one, a - * mound of fines does not. + /* ---- the three surfaces, and the third one is not an object ------------------------------------ + * city.js's style 7 is regolith and style 8 is rock. They are not two materials so much as two + * SCALES of the same one: rock is a coherent block with fracture planes and a hard rim, regolith + * is the powder that block breaks down into, and the difference the eye actually reads at + * character resolution is the shape of the top edge — a rock has a hard one, a mound of fines + * does not. + * + * STYLE 9 IS NEITHER, AND IT IS THE ONE THE MAP ADDED. A swell lot is EMPTY: its whole height is + * the plain being higher than the plain beside it, so what the ray hits is not the flank of an + * object but a stretch of GROUND stood on end by the projection. Painted as row 7 — which is what + * this file did until the third row existed — every mound in the world came back with regolith's + * fill 0.55 and cap 0.9, i.e. as a two-metre drift of loose powder with a lit crest on it, and a + * plain whose every rise carries a bright edge reads as a field of spoil heaps rather than as + * rolling ground. So row 9 is the FLOOR's own numbers rather than a mound's: the fill matches + * floorTex's own 24%-coverage regime scaled for a face seen square on, the seams are gone + * (nothing fractures), and the cap is small enough to be a change of texture at the skyline + * instead of a rim. * * pitch the lattice the face is broken up on, in metres. Rock is fractured at half a metre; * regolith is smooth and only carries the coarse lumps of a mound. + * seamP how much of the face is a black fracture slot. A swell is 0 and it has to be a + * declared 0 rather than a big pitch: at a pitch past the width of a lot the whole lot + * quantises to ONE seam hash, so 6% of the world's mounds would have come out entirely + * unpainted — a hole in the plain rather than no joints in it. + * glint the share of a SOFT crest that flares as a specular. A drift of fines is 34% — the + * crest of a heap catches the light along its whole length. A ground swell is 8%: the + * top of a ground wave has no edge to flare off at all, and at 34% every rise in the + * plain wore a bright line, which is the exact "spoil heap" read row 9 exists to stop. * fill how much of the lit face is painted at all. This is the DENSITY that carries the * tone, and it is the whole difference between a lit basalt block (nearly solid) and a - * drift of fines (half painted, and its grey comes from the holes). + * drift of fines (half painted, and its grey comes from the holes). 0.44 on the swell + * against regolith's 0.55: a rise in the plain must not print BRIGHTER than the plain, + * or the eye reads it as a different material, and 0.44 is the value at which the two + * match at the mound's foot — measured against floorTex's own near-field 0.34 density + * scaled by the 1.3 the face-on geometry gains over the grazing floor. * cap the lit crest, as a fraction of one printed row — see the note on capOf below. + * erode how hard the per-column notch bites the top edge (see `top` in facade). Rock and + * regolith arrive as boxes and need the full bite; a swell's silhouette is already the + * smooth top of a ground wave and a deep notch turns it back into a ruin, so it takes + * a third of the depth and reads as a soft, grainy horizon. */ var STYLE_M = [ - /* 7 regolith */ { pitch: 1.35, fill: 0.55, cap: 0.9, hard: 0 }, - /* 8 rock */ { pitch: 0.52, fill: 0.86, cap: 1.0, hard: 1 } + /* 7 regolith */ { pitch: 1.35, fill: 0.55, cap: 0.9, hard: 0, erode: 1.00, seamP: 0.06, glint: 0.34 }, + /* 8 rock */ { pitch: 0.52, fill: 0.86, cap: 1.0, hard: 1, erode: 1.00, seamP: 0.13, glint: 0.34 }, + /* 9 swell */ { pitch: 2.60, fill: 0.44, cap: 0.4, hard: 0, erode: 0.34, seamP: 0.00, glint: 0.08 } ]; /* ---- THE DITHER LATTICE IS LOCKED TO THE SCREEN, NOT TO THE WORLD ------------------------------ @@ -500,7 +536,12 @@ weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); var sd = seedOf(cell); - var st = STYLE_M[cell && (cell.style | 0) === 8 ? 1 : 0]; + /* Three-way, and it has to be a lookup rather than the old `=== 8 ? 1 : 0` ternary: style 9 + * fell through that to row 0 and every ground swell in the world was painted as a mound of + * loose fines with a lit crest. Anything the map has not got a row for still lands on 7, which + * is the right degradation — an unknown lunar surface is regolith. */ + var sti = cell ? (cell.style | 0) - 7 : 0; + var st = STYLE_M[sti === 1 ? 1 : (sti === 2 ? 2 : 0)]; var h = cell && cell.h ? cell.h : 2; var sun = sunOf(cell); /* No `lod` variable here, unlike both sibling facades and unlike floorTex below. qOf already @@ -529,9 +570,16 @@ * biting, so the silhouette has both a shape and a grain. One wavelength alone gives an edge * that is uniformly noisy, which reads as a dither on a straight line rather than as erosion. * It is also why `crest` is measured from `top` and not from `h` everywhere below — the lit rim - * has to sit on the eroded edge or it draws the box straight back on. */ + * has to sit on the eroded edge or it draws the box straight back on. + * + * st.erode SCALES THE BITE and exists for style 9. A swell arrives as a box like everything + * else, but it is a box cut out of the GROUND, and the top of it is a ground wave that the map + * has already smoothstepped twice — biting a fifth of the height out of that gives a mound with + * a ragged crown, which reads as a spoil heap. A third of the depth leaves the notch doing its + * one indispensable job, breaking the flat top edge, without inventing erosion the landform + * does not have. */ var top = h - h * (0.06 + 0.20 * hash2(Math.floor(u * 0.42), 0, sd ^ 0x4D78)) * - hash2(Math.floor(u * 1.3), 0, sd ^ 0x4D77); + hash2(Math.floor(u * 1.3), 0, sd ^ 0x4D77) * st.erode; var crest = top - v; // metres below THIS column's own eroded top if (crest < 0) return fset(0, P.shadow, 0); @@ -583,10 +631,22 @@ var cap = capOf(dist, st.cap); if (crest < cap) { if (st.hard) - return dim(specSet(crest < cap * 0.5 ? G_EQ : G_DASH, 0.55 + hv * 0.45, dist), soft); + /* THE GLYPH IS MIXED ON THE CELL'S OWN HASH and not chosen by depth into the cap alone. + * Rendered at seed 3 frame 3000 there is a run of eighteen identical '=' along the crest of + * a low rock ridge at fifty metres, and eighteen identical characters in a row is a RULE, + * which is the artefact this whole pass exists to remove. The cause is underneath this + * function and is written up in the report — adjacent rock lots in the ejecta and field + * districts land within a few tens of centimetres of each other, and at fifty metres a + * printed row is 0.83 m, so a real ridge with 0.4 m of relief on it genuinely does lie in + * one row. What this file can do about it is refuse to draw that row as one character: two + * glyphs at the top of the cap and two below it, dealt on the same stable hash the fill + * uses, so the edge reads as broken rock rather than as a drawn line. */ + return dim(specSet(crest < cap * 0.5 ? (hv < 0.58 ? G_EQ : G_DASH) + : (hv < 0.45 ? G_DASH : G_TICK), + 0.55 + hv * 0.45, dist), soft); /* A mound of fines has no edge, so its crest is a fading-out rather than a flare: the * specular is dithered in at a third of the cells and the rest is ordinary lit surface. */ - if (hv < 0.34) return dim(specSet(G_QUOTE, hv, dist), soft); + if (hv < st.glint) return dim(specSet(G_QUOTE, hv, dist), soft); return dim(litSet(G_TICK, 0.7 + hv * 0.3, dist, hv), soft); } @@ -601,8 +661,10 @@ * because the two faces of a joint cannot both be lit. Drawn as blanks: they cost nothing, they * break the mass into facets, and they are what keeps a 5 m rock from being a 5 m slab. On * regolith they are much rarer and shallower, because powder does not fracture. */ - var seam = hash2(Math.floor(u / st.pitch), Math.floor(v / (st.pitch * 1.3)), sd ^ 0x4D42); - if (seam < (st.hard ? 0.13 : 0.06)) return fset(0, P.shadow, 0); + if (st.seamP > 0) { + var seam = hash2(Math.floor(u / st.pitch), Math.floor(v / (st.pitch * 1.3)), sd ^ 0x4D42); + if (seam < st.seamP) return fset(0, P.shadow, 0); + } if (hv > st.fill) return fset(0, P.shadow, 0); var k = hv / st.fill; /* NORMALISED BY THE FILL, per surf_west.js:659: tying @@ -657,19 +719,450 @@ } function rblank() { return rset(fset(0, P.shadow, 0)); } - /* Stride 0.72 m and a 0.32 m sole: a walking human's pitch, and the reason these are drawn at all - * is that they are the only thing on this ground that CONVERGES. The design brief spends a page on - * it and west_range.js opens with the same sentence: empty ground rendered honestly is empty, and - * a distance-quantised hash field with nothing straight in it does not read as a plain, it reads - * as television static. The prints, the two rover rails and (in moon_alsep.js) the cable run are - * this world's entire supply of straight lines. */ - var STRIDE = 0.72, TRACK = 1.03; + /* ---- WHAT USED TO BE HERE WAS A ROAD, AND IT HAD TO GO ------------------------------------------ + * Until this pass the first two branches of the cascade below were a bootprint TRAIL held inside + * 0.62 m of the street centreline and two rover RAILS at exactly 1.03 m either side of it, both + * running the full length of the corridor. The comment defending them said "the prints, the two + * rover rails and the cable run are this world's entire supply of straight lines", and the + * argument it made — that empty ground rendered honestly reads as television static and needs + * something that CONVERGES — is correct and is not what was wrong. + * + * What was wrong is that two parallel dashed rails with a churned strip down the middle of them, + * locked to the street lattice, receding to the vanishing point, IS A ROAD. On any world. A + * viewer looked at the frame and called it one, and the frame agrees with the viewer: the walk + * follows corridor centrelines, so the one line the camera is guaranteed to be standing on is + * also the one the whole lane pattern was pinned to, and the Moon came out with a carriageway + * down it. + * + * THE CONVERGENCE IS REPLACED RATHER THAN DELETED, in four places, and none of them is axis + * aligned: + * the rover traverse below a CURVE, at 36 degrees to the lattice, wandering on two octaves + * the rille a CURVE, ten metres wide, the one real lunar landform that is one + * the ejecta rays long streaks radiating from a point somewhere off in the plain + * the rolling ground itself a horizon that undulates, which is the convergence cue the design + * brief should have asked for first — terrain, not tyre tracks + * and the bootprints move out of this file entirely: moon_ground.js's drawPrints already lays + * them on a wandering two-octave trail and now scatters them in clusters, which is what a crew + * that mills about a work site and detours to a boulder actually leaves. Two files drawing prints + * on two different paths was the other half of the road: whichever one the eye picked up, the + * straight one was underneath it. */ + + /* ---- the rolling plain, and it is the same field the map's heightmap runs on -------------------- + * city.js now adds up to 2.8 m of relief to every non-street lot on two smoothstepped bilinear + * octaves of 54 m and 23 m. Those lots arrive here as facade() hits with style 9 and are painted + * as ground stood on end. THIS floor is what is left: the corridors, and the majority of open + * ground whose swell fell under the map's 0.56 threshold and is therefore exactly flat. + * + * Flat is not the same as featureless, and the two have to AGREE ABOUT SCALE or the plain reads + * as two unrelated fields laid over each other — mounds every fifty metres, tone varying every + * nine. So the octave table below opens on the map's own two wavelengths and adds a third for the + * metre scale the map cannot express. It cannot be the same field cell-for-cell: floorTex is + * handed two world coordinates and nothing else, has no seed, no block bounds and no city to ask, + * and the map's field is a function of all three. Matching the WAVELENGTHS is what the eye reads; + * matching the phase is what it cannot check. + * + * FOUR OCTAVES AND NOT TWO, and the outer one is the reason. The caster's far plane is about 90 m + * and the frame is 92 m deep, so a field whose longest wavelength is 54 m puts nearly two full + * cycles inside the picture and the whole plain comes out at one tonal frequency — even, regular, + * and as recognisable as a wallpaper repeat. The 128 m octave is longer than the frame, so what it + * contributes is that ONE SIDE of the picture is broadly lighter than the other, which is what a + * real plain does and what no amount of finer noise can imitate. + * + * The weights fall off with the wavelength because that is what a real surface's power spectrum + * does, and none of them is allowed to dominate: measured, at 0.68 on the coarse term (the map's + * own weighting, which is right for a HEIGHT field where the fine octaves are detail on a shape) + * the 128 m term alone decided the density and the plain came out as broad bands with no grain on + * them at all. + * + * IT ALSO RETURNS ITS GRADIENT, analytically and for about six extra multiplies, because the + * gradient is what buys the slope shading below and a finite difference would cost a second whole + * evaluation. */ + var SW_LAT = [128.0, 54.0, 23.0, 9.0], SW_W = [0.26, 0.32, 0.26, 0.16], + SW_SALT = [0x4D71, 0x4D7B, 0x4D85, 0x4D8F]; + var swVal = 0, swGX = 0, swGZ = 0; + function swellOf(wx, wz) { + var v = 0, gx = 0, gz = 0, o; + for (o = 0; o < 4; o++) { + var lat = SW_LAT[o], w = SW_W[o], sl = SW_SALT[o]; + var qx = wx / lat, qz = wz / lat; + var i0 = Math.floor(qx), j0 = Math.floor(qz); + var fx = qx - i0, fz = qz - j0; + var sx = fx * fx * (3 - 2 * fx), sz = fz * fz * (3 - 2 * fz); + /* d/df of the smoothstep. It is what makes the gradient continuous across a lattice line — + * the plain lerp's gradient is not, and a discontinuous gradient prints as a 54 m grid of + * tonal creases, which is a straight line and is the thing this whole pass is removing. */ + var dx = 6 * fx * (1 - fx) / lat, dz = 6 * fz * (1 - fz) / lat; + var a = hash2(i0, j0, sl), b = hash2(i0 + 1, j0, sl), + c = hash2(i0, j0 + 1, sl), d = hash2(i0 + 1, j0 + 1, sl); + var ab = a + (b - a) * sx, cd = c + (d - c) * sx; + v += w * (ab + (cd - ab) * sz); + gx += w * (((b - a) + ((d - c) - (b - a)) * sz) * dx); + gz += w * ((cd - ab) * dz); + } + swVal = v; swGX = gx; swGZ = gz; + } + + /* ---- HOW MUCH A SLOPE IS ALLOWED TO CHANGE THE TONE --------------------------------------------- + * The header of the floor section says this plane does not dim at a low sun, and that is still + * right: regolith is violently non-Lambertian with a backscatter surge, so a flat plain viewed + * down-sun is nearly as bright at a 6-degree sun as at 26. A SLOPE is the other question, and it + * does matter, because a slope changes the incidence rather than the phase angle. + * + * The arithmetic. Tilting a surface by theta toward the sun takes the incidence from 90-alt to + * 90-alt-theta, so a Lambertian return changes by sin(alt+theta)/sin(alt), i.e. by about + * theta/tan(alt) for small theta. swellOf's gradient reaches 0.034 per metre at its extreme and + * the relief it stands for is the map's own 2.8 m over a unit of the field, so theta tops out + * near 0.095 rad — which at the middle of the Apollo altitude band (tan 0.255) would be a 37% + * swing on the very steepest ground the field has. + * + * A THIRD OF THAT IS WHAT GETS DRAWN. The opposition surge retires most of the incidence term at + * the small phase angles a down-sun camera sees, and at the full Lambert figure the plain came + * out looking like corrugated iron: the 9 m octave alone was throwing 25% density steps between + * adjacent metres of ground. + * + * WHAT SLOPE_K 3.9 ACTUALLY DELIVERS, measured over 400k uniform world samples rather than read + * off the endpoints — |grad| is p50 0.0098, p90 0.0183, p99 0.0257, max 0.0339, so SLOPE_K*|grad| + * is 0.038 / 0.071 / 0.100 / 0.132. With the altitude term at its 1.9 ceiling the extreme reaches + * 0.251. That is a swing of +-4% on typical ground, +-10% on the steepest one percent, and +-25% + * on the single worst sample in four hundred thousand — NOT the +-20% the previous version of + * this paragraph claimed for the whole stack, which was an endpoint sum and not a distribution. + * + * THE +-0.45 CLAMP THEREFORE NEVER FIRES, and it is kept and documented rather than deleted. It + * exists to hold the invariant that no single cell of the field may be driven to zero or to + * double — a density that reaches zero is a hole in the plain and a hole reads as a shadow with + * nothing casting it — and it sits 0.20 above the worst measured value so that a future octave + * table with more power in it cannot break the invariant silently. It is a guard, and the + * distribution below it is untouched. + * + * The altitude term is the 1/tan(alt) above, normalised at the band's midpoint and clamped to + * 0.6..1.9 so that the shading strengthens toward the ends of the clock — which is the whole + * reason Apollo flew at a low sun — without a 6-degree sun quadrupling it into the corrugation. + * + * IT IS NOT GATED ON THE DAY MIX AND IT RUNS AT NIGHT, at SLOPE_G 1.04 — because SUN_ALT + * crossfades to EARTH_ALT 0.24 and 0.255/tan(0.24) is 1.04. That is correct rather than an + * oversight: the night key here is EARTHSHINE, a real directional light from a disc fixed 14 + * degrees above the horizon, and ground tilted away from it is genuinely darker. This is a + * LIGHTING term, not a daylight scale, so the contract's "every daylight scale is the identity at + * night" does not reach it. What it costs the tuned night baseline is measurable and it is + * nothing: seed 42 frame 900 at 213x67, SLOPE_K 3.9 against SLOPE_K 0 — night 3.8 / 1.64 / 168 + * against 3.8 / 1.65 / 168, noon 3.3 / 2.84 / 190 against 3.3 / 2.85 / 190. The term moves + * coverage from one side of a swell to the other and leaves the mean alone by construction, which + * is exactly what a census cannot see and the eye can. */ + var SLOPE_K = 3.9, SLOPE_G = 1; + + /* ---- THE ROVER TRAVERSE ------------------------------------------------------------------------- + * Same two ruts 2.06 m apart, and nothing else about it is the same. + * + * IT IS OBLIQUE. TRK_AZ 0.62 rad is 36 degrees off the lattice, and it is not a round fraction of + * anything: the corridors run along +z and +x, the walk follows them, so a traverse at 36 degrees + * enters the frame from one side and leaves by the other instead of running away to the vanishing + * point. That is the single change that stops it reading as a carriageway. + * + * IT WANDERS, on two octaves of 78 m and 29 m carrying +-13 m and +-7 m. Tens of metres, per the + * brief, and the ratio matters more than either number: one octave alone gives a sine wave, which + * is as recognisably artificial as a straight line. The second octave was +-4.5 m first and the + * render said it was not enough — a traverse crossing the frame at 60 m has its whole visible + * length inside one screen row, so a wander of four metres is invisible and what the eye gets is + * a rail. At +-7 m on a 29 m wavelength the same crossing visibly bows. + * + * IT RECURS, on a 128 m cross-track pitch, because one traverse in an infinite plain is one the + * camera almost never stands near. 128 m against the caster's ~92 m far plane means the frame + * usually holds one crossing and sometimes none, which is the right frequency for "a rover came + * through here" rather than "this is a road network". Each copy takes its own noise phase off its + * own index, so they are not parallel curves — parallel is a straightness cue on its own. + * + * ONLY THE NEAREST COPY IS TESTED, and that is exact rather than an approximation. trkWander's + * two octaves carry +-13.0 and +-7.0 (26.0 and 14.0, halved), so the wander is bounded by 20.0 m + * — measured over 200k samples the realised extremes are -19.32 and +18.34 — against a pitch of + * 128. Copy k's centreline therefore never leaves the band k*128 +- 20; a point whose cross-track + * coordinate rounds to k is at most 64+20 = 84 m from copy k's centre and at least 64-20 = 44 m + * from any other's, and the whole double rut spans under 3 m even with the resolution floor below + * widening it. No second copy can ever be the near one. The previous version of this paragraph + * wrote the bound as 17.5 m and got 81.5 / 46.5; the conclusion survives, but the arithmetic did + * not match trkWander and the next person to touch TRK_PITCH would have trusted it. + * + * THE RUT WIDENS WITH DISTANCE and that is the flicker gate, not an aesthetic. A ground cell's + * world footprint at distance d is about d/170 metres across at this grid, so past 60 m a 0.34 m + * rut is narrower than the sampling and the line breaks into dashes that reshuffle as the camera + * walks — a v-140 cell switching against a lum-0 background, which is the one thing this world + * cannot afford. Floored at the real 0.17 m half-width and grown at 0.0035*d, so it is physical + * inside 50 m and a resolution floor outside it. This is capOf's argument applied to a line + * instead of to a crest. */ + var TRK_AZ = 0.62, TRK_SIN = Math.sin(TRK_AZ), TRK_COS = Math.cos(TRK_AZ); + var TRK_PITCH = 128.0, TRK_HALF = 1.03; + + function trkWander(a, k) { + return (CC.vnoise(a * 0.0128 + k * 7.3, 0x4D86) - 0.5) * 26.0 + + (CC.vnoise(a * 0.0345 + k * 3.1, 0x4D87) - 0.5) * 14.0; + } + + /* ---- THE RILLE ---------------------------------------------------------------------------------- + * A sinuous rille is a collapsed lava tube: a shallow channel a few hundred metres wide on the + * real Moon, taken here at eleven metres because the frame is 92 m deep and a landform wider than + * the view is not a landform, it is a change of ground level. It is in this file for one reason + * beyond being real — IT IS A CURVE THAT CONVERGES. An open plain with no converging line has no + * perspective, the old rails were the wrong answer to that, and a channel meandering across the + * middle distance is the right one: it is a line, it goes somewhere, and it is not straight. + * + * IT IS PAINTED, NOT DUG. The heightmap has no negative heights and this file cannot make one, so + * what is drawn is what a shallow depression looks like rather than what it is: fewer fines on the + * floor (the walls shed their fines into it and the floor is swept coarse), a bright lip on the + * rim the sun is behind, and a dark one on the rim it is in front of. That is enough — at the + * grazing incidence this ground is seen at, a channel is a tonal band with two edges anyway. + * + * 330 m pitch, so it is in frame perhaps one walk in three, which is the right rarity for the + * biggest single feature the ground has. The same nearest-copy argument as the traverse holds + * with more room: 50 m of wander against a 165 m half-pitch. */ + var RIL_AZ = -0.44, RIL_SIN = Math.sin(RIL_AZ), RIL_COS = Math.cos(RIL_AZ); + var RIL_PITCH = 330.0, RIL_HALF = 5.5; + + function rilWander(a, k) { + return (CC.vnoise(a * 0.0048 + k * 5.7, 0x4D88) - 0.5) * 76.0 + + (CC.vnoise(a * 0.0135 + k * 2.9, 0x4D89) - 0.5) * 24.0; + } + + /* ---- EJECTA RAYS -------------------------------------------------------------------------------- + * The one pattern a mare surface carries at kilometre scale, and the cheapest large-scale tone + * variation available: a fresh impact throws fines out along preferred azimuths and they land as + * long pale streaks, brighter than the surface they land on because they are unweathered and + * unpacked. Tycho's are visible from Earth with the naked eye. + * + * WHY THEY ARE WORTH THE HASHES. Everything else on this floor varies at 9-54 m. Rays vary at 200, + * and they RADIATE, so they put a set of lines into the frame that all point at the same place — + * convergence, again, from terrain rather than from tyres, and this time convergence on a point + * that is usually off the side of the picture rather than at the vanishing point. + * + * ONE SOURCE PER 300 m CELL AND ONLY THE NEAREST IS TESTED. A point is within 212 m of its own + * cell's source, inside RAY_LEN, and ignoring the further sources costs nothing but a few rays + * that would have crossed — which is the direction to err, since crossing ray systems is what + * turns a plain into plaid. + * + * 300 m AND NOT THE 190 THIS WAS FIRST WRITTEN AT. Rendered as a plan over a square kilometre, + * 190 m put a starburst every 190 m in a visible grid of them — the lattice the whole pass exists + * to hide, drawn in the one feature that was supposed to be at a scale above it. At 300 m against + * the caster's 92 m view radius a frame holds a few rays of ONE system and never the middle of it, + * which is what a ray looks like from inside one: a pale streak going somewhere, not a firework. + * + * THE AZIMUTH IS A DIAMOND ANGLE AND NOT AN ATAN2. dz/(|dx|+|dz|), folded into -2..2 over the + * full circle, is monotone in the true bearing and costs a divide. It is not proportional to it — + * a ray's angular width varies by up to 11% around the circle — and nothing here can tell the + * difference. floorTex runs six thousand times a frame and an atan2 in it is a quarter of a + * millisecond for a number that only ever gets floored. + * + * THE SECTOR EDGES ARE FEATHERED, which is not decoration. A hard-edged sector is a straight line + * radiating from a point, i.e. exactly the artefact this pass exists to remove, and it would be a + * straight line whose position depends on nothing the eye can attribute. Tapered linearly to zero + * across the outer third of the sector on each side. */ + var RAY_Q = 300.0, RAY_IN = 26.0, RAY_LEN = 340.0, RAY_SECT = 8.5; + + /* ---- THE CRATERS, AND THEY ARE THE MOST VALUABLE THING ON THIS FLOOR ---------------------------- + * city.js's crater branch builds the ones with a RIM you can walk round, 3 to 20 m across. It + * cannot build the small ones, because a 1 m crater is smaller than a lot and the heightmap has no + * negative heights — height 0 is the floor and the route walker requires it. But a real mare + * surface is saturated with them: every square metre of regolith has been turned over by impacts + * and the ground is pitted at every scale down to the millimetre. + * + * They matter here for a reason that is nothing to do with realism. A plain with no shadow in it + * has no scale, and the eye cannot tell whether the texture is two metres away or two kilometres. + * A bowl is a scale reference that costs four hashes and a square root, because HALF OF IT IS + * DARK — the inner wall on the sun's side faces away from the light and is a hole, and the far + * wall is in raking light and is the brightest thing on the ground. One crater tells you where the + * light is, which way is down, and how big a metre is. + * + * AND THEY DO NOT READ AS CIRCLES, which is worth writing down because the obvious reaction to the + * render is that they are not working. The ground plane is foreshortened by dist/eyeY: at 8 m one + * screen row spans 0.42 m of depth and one column spans 0.029 m, so a 1.5 m bowl is 50 columns + * wide and 4 rows tall. What lands in the frame is a wide flat band with a dark half and a pale + * half, not a ring — which is what a crater at boot height actually looks like, and it still does + * the two jobs it is here for: relief, and scale. + * + * ---- THE VISIBILITY LAW REPLACES THE OLD 22 m CUT ------------------------------------------ + * The previous version drew craters at lod 2 only and defended the cut: "past 22 m a 1 m crater is + * under a screen cell across, so its lit and dark halves land in the SAME cell and that cell + * switches between v 150 and v 0 as the camera walks". The measurement is right; the CONSTANT is + * the wrong shape, because what it is really saying is that a bowl has to be big compared to a + * ground cell, and a ground cell grows as the square of the distance (a screen row spans + * dist*dist/(scale*eyeY) metres of depth, which is the badly foreshortened axis and the one the + * bowl's terminator lies across). + * + * So the rule is r >= dist*dist/CVIS, and CVIS 968 is chosen to REPRODUCE the old cut exactly at + * its own boundary: the old field's smallest crater was 0.5 m and it was drawn to 22 m, and + * 22*22/0.5 is 968. Inside 22 m the near field is therefore byte-identical in extent to what it + * was. Outside it, craters do not stop — the small ones drop out one size at a time (a 1 m bowl + * survives to 31 m, a 2.4 m one to 48 m) and the big lattice below carries on to 90 m and beyond. + * That is both the honest optics and the thing the frame was missing: a crater field that stopped + * dead at a fixed radius from the camera, in a world with no aerial perspective, was the one place + * this ground admitted it had an LOD. + * + * ---- THREE LATTICES ------------------------------------------------------------------------- + * PITS: one candidate every 1.45 m, 38% taken, 0.28-1.1 m across, and this row exists because of + * a measurement rather than a wish. The bottom third of the frame is the ground between 3.5 and + * 13 m, and at that range the projection is so stretched that the whole of it is a world patch + * about two metres wide and six deep — at one crater candidate per 5.5 m there is a 17% chance + * of ANY crater being in it, so five frames out of six had a near field with no relief in it at + * all, which is the television-static failure exactly. A 1.45 m lattice puts three or four pits + * in the same patch. The visibility law retires them on its own between 12 and 22 m, which is + * where the next lattice up takes over, so nothing is drawn that the grid cannot resolve. + * SMALL: one candidate every 5.5 m, 42% taken, 0.5-2.4 m across. The pitting. Unchanged. + * LARGE: one every 27 m, 26% taken, 3.2-11 m across. These are the ten-metre bowls the mid field + * can carry, and the visibility law is what makes them affordable: an 11 m bowl is legible to + * 103 m, so the middle distance now has relief in it instead of being an even speckle. + * The two lattices are independent and overlap freely, which is what a saturated surface does — + * small craters land inside big ones and the big one's rim is pitted. + * + * ---- CHAINS AND DOUBLETS -------------------------------------------------------------------- + * Secondaries — debris thrown out of a primary impact, falling back at a few hundred metres a + * second — land in STRINGS, and a line of three or four equal bowls on a common bearing is one of + * the most recognisable things on the lunar surface. 22% of the small craters and 14% of the large + * ones are chains of four, on a bearing off a 16-entry direction table, at 2.35 radii spacing, + * each member independently scaled to 62-92% so the string is not a rubber stamp. The member a + * sample belongs to is found by rounding its projection onto the chain axis, so a chain costs one + * extra hash and a dot product rather than four times the work. + * + * ---- AGE ------------------------------------------------------------------------------------ + * A crater's whole appearance is its age, and there are three: + * fresh (26%) deep and steep, so more of it is in shadow; and it carries an EJECTA HALO — + * an annulus of unweathered fines out to 1.95 radii that is markedly paler than + * the surface around it, which is why young craters photograph as bright spots. + * The halo is a density boost handed to the fines branch, not a branch of its + * own, so it has no edge anywhere and cannot flicker. + * mature (52%) as before. + * old (22%) slumped almost flat: the shadow line drops to where only the deepest part of + * the bowl is dark, and what is left reads as a shallow dish. This is most of + * what an old mare surface is actually covered in. + * and 11% of all of them, independently, have a DARK FLOOR — a bowl deep enough to hold shadow at + * this sun angle, or one that punched through the fines into basalt. Drawn as an absence with a + * few slate specks, which is what it costs. + * + * The direction table is 16 fixed unit vectors rather than a cos/sin pair per cell: this runs + * inside the 42%-of-cells branch, six thousand cells a frame, and a chain bearing quantised to + * 22.5 degrees is not something the eye can measure off a bowl string four members long. */ + var CVIS = 968.0; + var CDIR_X = [], CDIR_Z = []; + (function () { + for (var i = 0; i < 16; i++) { + var a = i * 0.3926990817; // 2*PI/16 + CDIR_X.push(Math.cos(a)); CDIR_Z.push(Math.sin(a)); + } + })(); + + /* Out-param: the ejecta-halo density boost for the cell just tested. Reset by every caller before + * the call, exactly like FOUT/ROUT — nothing in this file allocates inside a frame. */ + var CR_HALO = 0; + + function bowl(wx, wz, dist, q, roll, cq, rmin, rvar, take, chainP, salt) { + /* The cheapest reject there is, and it is EXACT rather than an LOD: the visibility law below is + * monotone in the radius, so a lattice whose LARGEST crater cannot be resolved at this distance + * cannot contribute a single cell. One compare in place of six hashes and a square root, and it + * retires the pit lattice at 23 m, the small one at 48 and the large one at 103 — which over a + * whole frame is most of the ground plane skipping most of this function. */ + if ((rmin + rvar) * CVIS < dist * dist) return null; + var ci = Math.floor(wx / cq), cj = Math.floor(wz / cq); + var h1 = hash2(ci, cj, salt); + if (h1 >= take) return null; + var cr = rmin + rvar * (h1 / take); + var ccx = (ci + 0.16 + 0.68 * hash2(ci, cj, salt ^ 0x0101)) * cq; + var ccz = (cj + 0.16 + 0.68 * hash2(ci, cj, salt ^ 0x0202)) * cq; + var ddx = wx - ccx, ddz = wz - ccz; + + var hc = hash2(ci, cj, salt ^ 0x0303); + if (hc < chainP) { + var di = (hc / chainP * 16) | 0; if (di > 15) di = 15; + var cdx = CDIR_X[di], cdz = CDIR_Z[di]; + var step = cr * 2.35; + /* Four members at -1..2, so the string is not centred on the lattice cell and the lattice + * cannot be read off it. Clamped rather than wrapped: outside the string the sample simply + * belongs to the nearest end member and falls outside its radius a moment later. */ + var j = Math.round((ddx * cdx + ddz * cdz) / step); + if (j < -1) j = -1; else if (j > 2) j = 2; + ddx -= cdx * step * j; ddz -= cdz * step * j; + cr *= 0.62 + 0.30 * hash2(ci * 31 + j, cj, salt ^ 0x0404); + } + + /* The visibility law, applied AFTER the chain has scaled the radius, because a chain member is + * the thing that has to be legible and it is smaller than the crater it was derived from. */ + if (cr * CVIS < dist * dist) return null; + + var rd = Math.sqrt(ddx * ddx + ddz * ddz); + var age = hash2(ci, cj, salt ^ 0x0505); + if (rd > cr) { + /* Outside the rim: nothing to draw, but a fresh crater hands the fines branch a halo. */ + if (age < 0.26 && rd < cr * 1.95) + CR_HALO = 0.62 * (1 - (rd - cr) / (cr * 0.95)); + return null; + } + + var fac = rd > 1e-4 ? -(ddx * SUN_X + ddz * SUN_Z) / rd : 0; + /* WHERE THE TERMINATOR SITS INSIDE THE BOWL IS THE SUN'S ALTITUDE, and it is one of the two + * places in this file where the altitude does visible work. A 6-degree sun leaves five sixths + * of a bowl in shadow; a 26-degree sun leaves a bit over half. That swing is the whole + * difference between the two ends of the clock on this world. Age shifts it: a fresh bowl is + * steep and holds more shadow, a slumped one barely shadows itself at all. */ + var lip = 0.62 - 1.5 * (SUN_ALT - ALT_LO) + (age < 0.26 ? 0.12 : (age > 0.78 ? -0.44 : 0)); + var cg = hash2(Math.floor(wx * q), Math.floor(wz * q), salt ^ 0x0606); + var rn = rd / cr; + + /* The dark floor. Independent of age, and drawn before the terminator test so it takes the + * whole bowl and not half of it — the point of it is a black disc with a pale rim round it. */ + if (rn < 0.52 && hash2(ci, cj, salt ^ 0x0707) < 0.11) + return (dist < 25 && cg < 0.07) ? rset(fset(G_DOT, P.slate, 16 + cg * 96)) : rblank(); + + if (fac < lip) { + /* The shadowed wall, and the near-field fill is the same slate as darkFace's for the same + * reason: it is a hole, but a hole two metres from your boot is not black. A grazed lip on + * this side was tried and taken out again: it sits astride the sweeping shadow line and so + * switches every cell it owns as the day turns, which is the one thing this world's + * background luminance makes unaffordable. */ + return (cg < 0.07) ? rset(fset(G_DOT, P.slate, 16 + cg * 96)) : rblank(); + } + /* The same ramp facade() uses, for the same measured reason: `lip` moves with the sun's + * altitude and `fac` with its bearing, so a bowl's shadow line sweeps across the ground as the + * day turns, and every cell it crosses would otherwise step the full height of a lit ground + * cell in one frame. A cell takes about 20 s to cross the 0.30 band. Only reached with + * fac >= lip, so it can never go under its own 0.24 floor. */ + var cs = fac - lip < 0.30 ? 0.24 + 2.533 * (fac - lip) : 1; + /* The lit wall, and its RIM. Denser than the plain around it — a fresh bowl exposes unweathered + * fines and they are markedly brighter, which is why young craters photograph as pale spots — + * and denser again over the outer sixth, which is the raised lip of ejecta the impact piled up. + * `roll` is the ground's own rolling-material term, passed in rather than re-derived: a bowl + * sitting on a swept crest has less loose material in it to catch the light than one in a + * hollow, which is what "the crater field is interrupted by the crests" comes out as when it is + * written continuously instead of as a switch. */ + var fillC = (age < 0.26 ? 0.92 : (age > 0.78 ? 0.52 : 0.76)) * roll; + if (rn > 0.84) fillC *= 1.35; + if (cg < fillC) + return rset(dim(litSet(cg < 0.3 ? G_COMMA : (cg < 0.7 ? G_TICK : G_QUOTE), + 0.45 + 0.55 * (cg / fillC), dist, cg), cs)); + return rblank(); + } + + /* Ejecta rays — see the block comment above RAY_Q. Returns a density boost, 0 outside. */ + function rayAt(wx, wz) { + var gi = Math.round(wx / RAY_Q), gj = Math.round(wz / RAY_Q); + var ox = (gi + (hash2(gi, gj, 0x4D8A) - 0.5) * 0.7) * RAY_Q; + var oz = (gj + (hash2(gi, gj, 0x4D8B) - 0.5) * 0.7) * RAY_Q; + var dx = wx - ox, dz = wz - oz; + var r = Math.sqrt(dx * dx + dz * dz); + if (r < RAY_IN || r > RAY_LEN) return 0; + var ax = dx < 0 ? -dx : dx, az = dz < 0 ? -dz : dz, sm = ax + az; + if (sm < 1e-6) return 0; + var oa = dz / sm; // the diamond angle, -1..1 in the +x half plane + if (dx < 0) oa = oa >= 0 ? 2 - oa : -2 - oa; + var sp = oa * RAY_SECT, si = Math.floor(sp), sf = sp - si; + if (hash2(si, gi * 131 + gj, 0x4D8C) > 0.24) return 0; + /* Feathered both edges. The two sectors either side of the seam at due -z both taper to zero + * at it, so the wrap costs nothing. */ + var e = sf < 0.34 ? sf / 0.34 : (sf > 0.66 ? (1 - sf) / 0.34 : 1); + /* In off the rim, out at the end of the throw. */ + var rk = r < RAY_IN * 2 ? (r - RAY_IN) / RAY_IN + : 1 - (r - RAY_IN * 2) / (RAY_LEN - RAY_IN * 2); + /* Streaky along its length. A ray drawn solid is a wedge, and a wedge is a shape rather than a + * spray of debris; the 22 m modulation is what turns it back into one. */ + return 0.90 * e * rk * (0.45 + 0.55 * CC.vnoise(r * 0.045 + si * 3.7, 0x4D8D)); + } function floorTex(wx, wz, dist, t) { weatherAt(t === undefined ? 0 : t); dayAt(t === undefined ? 0 : t); - var C = cfg(); - var lane = wx - (C ? C.streetX : 4.0); - var al = lane < 0 ? -lane : lane; var lod = dist < 22 ? 2 : (dist < 60 ? 1 : 0); /* THE LATTICE PITCH IS SOLVED RATHER THAN PICKED — see the block comment on qOf. The brief's * pitches (6.0/2.8/1.6/0.9) were measured at 400x100 and print in runs of five to eight @@ -677,131 +1170,117 @@ * cascade because the craters below dither on it too. */ var q = qOf(dist); - /* ---- the trail ---------------------------------------------------------------------------- + /* ---- the rolling plain, once, for everything below it ------------------------------------- + * `roll` is MATERIAL: dust creeps downhill on a body with no wind and no water, so the hollows + * are deep in fines and the crests are swept and coarse. `slope` is LIGHT: which way this piece + * of ground is tilted relative to the sun. Keeping them apart is what makes the relief read — + * one of them says what is there and the other says how it is lit, and a single term that did + * both would have the crests bright on the sunward side of the world and dark on the other. */ + swellOf(wx, wz); + var sw = swVal; + /* THE ENDPOINTS OF A SUM OF OCTAVES ARE NOT THE FIELD, AND WRITING THEM DOWN AS IF THEY WERE + * IS HOW THIS CONSTANT WAS GOT WRONG TWICE. `sw` is four smoothstepped bilinear octaves, so it + * is very nearly Gaussian: measured over 400k uniform world samples its range is 0.147..0.866 + * but its middle 80% is only 0.356..0.642, and its standard deviation is 0.111. The previous + * form, 1.55 - 1.10*sw, was documented as "0.45..1.55, a factor of 3.4" — those endpoints need + * all four octaves at their joint extreme and are unreachable by construction. What it actually + * delivered was a middle 80% of 0.84..1.16, A FACTOR OF 1.37, which is narrower than the field + * it was brought in to replace was claimed to be, and the argument written above it — that a + * spread of 2 is inside the noise of a 30% dither — condemned it. + * + * So the gain is set against the MEASURED spread rather than against the nominal range. At + * 2.6 per unit of `sw` the delivered distribution is + * p10 0.63 p50 1.00 p90 1.37 p1 0.34 p99 1.64 floor 0.15 (0.05% of samples) + * — a factor of 2.2 across the middle 80% and 4.8 across the middle 98%, with the mean still + * exactly 1 because E[sw] is exactly 0.5. That is a plain with stretches that are nearly bare + * and stretches that are nearly drifted, and unlike the old paragraph it is what the code does. + * + * THE FLOOR IS 0.15 AND IT IS NOT A TASTE. A coverage that reaches zero is a hole in the plain, + * and a hole with nothing casting it reads as a shadow that is not there. 0.15 * the 0.34 base + * is a coverage of 5%, which is the sparsest scatter that still says "ground" rather than + * "nothing". It is reached by 0.04% of samples — one in 2600 — so it is a guard and not a + * shaping term. + * + * THIS CHANGES THE NIGHT FRAME AND THAT IS DELIBERATE. The contract's rule is that every + * DAYLIGHT SCALE must be the identity at night, and this is not one: `roll` is material, it + * says how much dust is lying where, and dust does not move when the sun goes down. So the + * night picture moves with the day one and is meant to. Measured, frame 900 at 213x67, the old + * gain against this one — muddy(9-119) / hot(v>=170) / lit p90: + * seed 42 night 4.4 / 1.66 / 159 -> 3.8 / 1.64 / 168 + * seed 42 noon 3.5 / 3.07 / 187 -> 3.3 / 2.84 / 190 + * seed 42 dusk 3.6 / 2.62 / 190 -> 3.2 / 2.47 / 193 + * seed 7 night 10.0 / 1.05 / 156 -> 11.2 / 1.05 / 155 + * On seed 42 the muddy band falls at every hour and the lit p90 rises, which is the shape a + * wider coverage field should have: the extra tone goes into cells being present or absent + * rather than into cells at v 60. Seed 7's night is the other direction and is the worst case + * measured, at 11.2% against a 30% ceiling. The hot tail is unmoved on the seeds that were near + * the 3.5-5% band (seed 7 noon 4.35 -> 4.49) and drifts a tenth on the ones that were never in + * it. */ + var roll = 1 + (0.5 - sw) * 2.6; if (roll < 0.15) roll = 0.15; + var slope = -(swGX * SUN_X + swGZ * SUN_Z) * SLOPE_K * SLOPE_G; + if (slope < -0.45) slope = -0.45; else if (slope > 0.45) slope = 0.45; + + /* ---- the rover traverse ------------------------------------------------------------------- * DRAWN PALER THAN THE GROUND AROUND IT, which is the way round that surprised the frontier too * and then did not: churned fines are unpacked and porous, and unpacked powder backscatters * more than the packed surface it was lifted out of. Drawn darker they read as two cracks; * drawn paler they read as tracks. Every Apollo pan shows them as the bright thing. * - * PAST 22 m THE DISCRETE PRINTS BECOME A CONTINUOUS STRIP, and that is a photosensitivity fix - * rather than an LOD one. At 60 m one screen row spans about 1.4 m of ground and a 0.32 m sole - * lands inside a cell or does not depending on sub-metre camera position — so a walking camera - * would switch a v-130 cell on and off against a lum-0 background several times a second, which - * is precisely the failure west_town.js records its windmill failing tools/west-flicker.cjs on. - * Anything that MOVES ACROSS a bright/dark boundary in this world has to be continuous, so the - * far trail is a strip that is always painted and only its texture changes. */ - if (al < 0.62) { - var sp = wz / STRIDE, si = Math.floor(sp), fsp = sp - si; - var hb = hash2(si, 0, 0x4D51); - var foot = (si & 1) ? 0.17 : -0.17; - var off = lane - foot; if (off < 0) off = -off; - if (lod === 2) { - if (fsp < 0.46 && off < 0.14) - /* The sole. ':' and ';' because a Apollo boot sole is a lugged waffle and at one cell - * across, two stacked dots is what a waffle prints as. */ - return rset(litSet(hb < 0.5 ? G_COLON : G_SEMI, 0.72 + hb * 0.28, dist, hb)); - /* The spray thrown forward out of each print, which is what makes a footprint on a body - * with no air look the way it does: the ejecta lands in a sharp fan and stays exactly where - * it landed, for a million years. */ - if (fsp < 0.72 && off < 0.30 && hash2(Math.floor(wx * 6), Math.floor(wz * 6), 0x4D52) < 0.16) - return rset(litSet(G_DOT, 0.3, dist, hb)); - return rblank(); - } - if (al < 0.34) { - var hf = hash2(Math.floor(wx * 2.2), Math.floor(wz * 2.2), 0x4D53); - if (hf < 0.62) return rset(litSet(hf < 0.3 ? G_COLON : G_DOT, 0.6 + hf * 0.4, dist, hf)); - } - return rblank(); + * CONTINUOUS AT EVERY DISTANCE — always painted, with the chevron tread carried by WHICH glyph + * it is rather than by whether there is one. That is the property the old rails had and the one + * thing about them worth keeping: a line that is only sometimes painted switches cells on and + * off against a lum-0 background as the camera walks, which is the hazard west_town.js's + * windmill failed tools/west-flicker.cjs on. */ + var ta = wx * TRK_SIN + wz * TRK_COS; // along the traverse + var tp = wx * TRK_COS - wz * TRK_SIN; // across it + var tk = Math.round(tp / TRK_PITCH); + var to = tp - (tk * TRK_PITCH + trkWander(ta, tk)); + var tr = (to < 0 ? -to : to) - TRK_HALF; if (tr < 0) tr = -tr; + var trw = 0.17 + dist * 0.0035; // the resolution floor; see the block comment + if (tr < trw) { + /* THE TREAD IS A TEXTURE AND NOT AN ALTERNATION. The old rails carried their chevron as + * `(floor(wz/0.34) & 1) ? '=' : '-'`, and a 0.34 m period is under one screen column past + * 60 m: what that prints is runs of six or eight identical characters lying in ranks, which + * is the corduroy failure qOf exists to prevent, and on a straight line it reads as a + * painted road marking rather than as churned ground. Hashed on the screen-solved lattice + * instead, so the run length stays between one and three columns at every distance, and + * drawn from four glyphs rather than two so the eye reads a disturbed surface. The line is + * still CONTINUOUS — every cell inside the rut is painted, always — which is the one + * property of the old rails worth keeping. */ + var hr = hash2(Math.floor(ta * q), Math.floor(to * 6), 0x4D54); + return rset(litSet(hr < 0.32 ? G_EQ : (hr < 0.58 ? G_DASH : (hr < 0.82 ? G_COMMA : G_COLON)), + 0.40 + hr * 0.45, dist, hr)); } - /* ---- the rover rails ---------------------------------------------------------------------- - * 2.06 m wheelbase, so 1.03 m either side of the centreline, and a 0.23 m chevron tread. These - * are drawn as CONTINUOUS lines at every distance — a rail that is always painted, with the - * chevron carried by which glyph it is rather than by whether there is one. Same reasoning as - * the trail above, and it costs nothing because a line of alternating '=' and '-' reads as a - * tread pattern anyway. */ - var tr = al - TRACK; if (tr < 0) tr = -tr; - if (tr < 0.15) { - var ch = (Math.floor(wz / 0.34) & 1) ? G_EQ : G_DASH; - var hr = hash2(Math.floor(wz * 3), (al * 2) | 0, 0x4D54); - return rset(litSet(ch, 0.35 + hr * 0.45, dist, hr)); - } - - /* ---- THE SMALL CRATERS, and they are the most valuable thing on this floor ----------------- - * city.js's crater branch builds the ones with a RIM you can walk round, 3 to 20 m across. It - * cannot build the small ones, because a 1 m crater is smaller than a lot and the heightmap has - * no negative heights — height 0 is the floor and the route walker requires it. But a real mare - * surface is saturated with them: every square metre of regolith has been turned over by - * impacts and the ground is pitted at every scale down to the millimetre. - * - * They matter here for a reason that is nothing to do with realism. The first render of this - * file was an even speckle from the bottom of the frame to the horizon with no relief in it - * anywhere, which is design-brief failure (c) exactly: a plain with no shadow in it has no - * scale, and the eye cannot tell whether the texture is two metres away or two kilometres. A - * bowl is a scale reference that costs four hashes and a square root, because HALF OF IT IS - * DARK — the inner - * wall on the sun's side of the bowl faces away from the light and is a hole, and the far wall - * is in raking light and is the brightest thing on the ground. One crater tells you where the - * light is, which way is down, and how big a metre is. - * - * NEAR FIELD ONLY (lod 2, i.e. inside 22 m), and that is the flicker gate rather than an LOD - * saving. Past 22 m a 1 m crater is under a screen cell across, so its lit and dark halves land - * in the SAME cell and that cell switches between v 150 and v 0 as the camera walks — a - * 60%-of-full-scale step at walking pace, which is exactly the hazard west_town.js's windmill - * failed on. Inside 22 m the smallest of them is three cells across and every cell it owns - * stays owned. - * - * AND THEY DO NOT READ AS CIRCLES, which is worth writing down because the obvious reaction to - * the render is that they are not working. The ground plane is foreshortened by a factor of - * dist/eyeY: at 8 m one screen row spans 0.42 m of depth and one column spans 0.029 m, so a - * 1.5 m bowl is 50 columns wide and 4 rows tall. What lands in the frame is a wide flat band - * with a dark half and a pale half, not a ring — which is what a crater at boot height actually - * looks like, and it still does the two jobs it is here for: relief, and scale. */ - if (lod === 2) { - var CQ = 5.5; // one candidate every 5.5 m, 42% of them taken, radii - // 0.5-2.4 m: about 8% of the ground ends up inside one - var ci = Math.floor(wx / CQ), cj = Math.floor(wz / CQ); - var ch1 = hash2(ci, cj, 0x4D61); - if (ch1 < 0.42) { - var ccx = (ci + 0.18 + 0.64 * hash2(ci, cj, 0x4D62)) * CQ; - var ccz = (cj + 0.18 + 0.64 * hash2(ci, cj, 0x4D63)) * CQ; - var ddx = wx - ccx, ddz = wz - ccz; - var cr = 0.5 + 1.9 * (ch1 / 0.42); // 0.5 to 2.4 m across the rim - var rd = Math.sqrt(ddx * ddx + ddz * ddz); - if (rd < cr) { - /* Which way this piece of the bowl faces. The inward normal points at the centre, so a - * point on the sun's side of the bowl has its wall turned away from the sun. */ - var fac = rd > 1e-4 ? -(ddx * SUN_X + ddz * SUN_Z) / rd : 0; - /* WHERE THE TERMINATOR SITS INSIDE THE BOWL IS THE SUN'S ALTITUDE, and it is the one - * place in this file where the altitude does visible work. A 6-degree sun leaves five - * sixths of a bowl in shadow; a 26-degree sun leaves a bit over half. That swing is the - * whole difference between the two ends of the clock on this world. */ - var lip = 0.62 - 1.5 * (SUN_ALT - ALT_LO); - var cg = hash2(Math.floor(wx * q), Math.floor(wz * q), 0x4D64); - if (fac < lip) { - /* The shadowed wall, and the near-field fill is the same slate as darkFace's for the - * same reason: it is a hole, but a hole two metres from your boot is not black. A - * grazed lip on this side was tried and taken out again: it sits astride the sweeping - * shadow line and so switches every cell it owns as the day turns, which is the one - * thing this world's background luminance makes unaffordable. */ - return cg < 0.07 ? rset(fset(G_DOT, P.slate, 16 + cg * 96)) : rblank(); - } - /* The same ramp facade() uses, for the same measured reason: `lip` moves with the sun's - * altitude and `fac` with its bearing, so a bowl's shadow line sweeps across the ground - * as the day turns, and every cell it crosses would otherwise step the full height of a - * lit ground cell in one frame. A cell takes about 20 s to cross the 0.30 band. Only - * reached with fac >= lip, so it can never go under its own 0.24 floor. */ - var cs = fac - lip < 0.30 ? 0.24 + 2.533 * (fac - lip) : 1; - /* The lit wall. Denser than the plain around it — a fresh bowl exposes unweathered fines - * and they are markedly brighter, which is why young craters photograph as pale spots. */ - if (cg < 0.62) - return rset(dim(litSet(cg < 0.3 ? G_COMMA : (cg < 0.7 ? G_TICK : G_QUOTE), - 0.45 + 0.55 * (cg / 0.62), dist, cg), cs)); - return rblank(); - } - } + /* ---- the rille ---------------------------------------------------------------------------- + * A tonal cross-section rather than a hole: sparse on the floor, one wall bright and the other + * nearly blank. RIL_SUN is which of the two walls the sun is behind — the cross-channel axis + * dotted into the key direction, computed here because it turns with the clock. */ + var rla = wx * RIL_SIN + wz * RIL_COS, rlp = wx * RIL_COS - wz * RIL_SIN; + var rk2 = Math.round(rlp / RIL_PITCH); + var ro = rlp - (rk2 * RIL_PITCH + rilWander(rla, rk2)); + var rw = RIL_HALF * (0.72 + 0.56 * CC.vnoise(rla * 0.019, 0x4D8E)); + var ar = ro < 0 ? -ro : ro; + if (ar < rw) { + var rt = ar / rw; // 0 on the axis, 1 at the rim + var wl = (ro > 0 ? 1 : -1) * -(RIL_COS * SUN_X - RIL_SIN * SUN_Z); + /* Floor swept to 45% of the plain's coverage, walls climbing back to it, and the wall the sun + * is behind carrying up to 1.8x while the other falls to 0.2x. The break in slope at the rim + * is left as a hard edge on purpose: a rille rim IS a break in slope, and it is a CURVE, which + * is the whole reason this landform is in the file. */ + roll *= (0.45 + 0.55 * rt) * (1 + 0.80 * wl * rt); } + /* ---- the craters --------------------------------------------------------------------------- */ + CR_HALO = 0; + /* Finest first, because a metre-scale pit sitting inside a ten-metre bowl is a pit and not a + * bowl — the later impact is the one on top. */ + var cout = bowl(wx, wz, dist, q, roll, 1.45, 0.14, 0.41, 0.38, 0.18, 0x4D6F); + if (cout) return cout; + cout = bowl(wx, wz, dist, q, roll, 5.5, 0.5, 1.9, 0.42, 0.22, 0x4D61); + if (cout) return cout; + cout = bowl(wx, wz, dist, q, roll, 27.0, 3.2, 7.8, 0.26, 0.14, 0x4D68); + if (cout) return cout; /* ---- the fines ---------------------------------------------------------------------------- * A SPARSE FIELD WHOSE DENSITY CARRIES THE TONE. 24% coverage, and the 76% that is not painted @@ -810,26 +1289,38 @@ * at lum 40-100 in slate is the single fatal mistake available in this world; it would put a * third of the frame in the band core.js is trying to hold under 30%, and no setting of GAMMA, * KNEE or SHOULDER can rescue it, because a knee can delete a shadow but never create a - * highlight. */ + * highlight. + * + * THE MEAN IS UNCHANGED AND ONLY THE SPREAD HAS MOVED. The old field was one 9 m octave on a + * lattice shorter than a stride — which is to say it varied at a scale the projection destroys + * and by an amount the dither hides. It is now the product of four terms each centred on 1, and + * they are quoted here as MEASURED DISTRIBUTIONS rather than as nominal endpoints, because the + * endpoints of a sum of octaves are unreachable and quoting them is how the last two versions + * of this paragraph came to describe a field the code did not have: + * roll p10 0.63 p50 1.00 p90 1.37, p1 0.34, p99 1.64 (four octaves to 128 m) + * 1 + slope p10 0.96 p50 1.00 p90 1.04 at the band midpoint; p10 0.93 p90 1.08 and + * extremes 0.78..1.24 with the altitude term at its 1.9 ceiling + * ray boost 1..1.9 where an ejecta ray crosses, and exactly 1 everywhere else + * 1 + CR_HALO 1..1.62 in the ejecta apron of a crater, 1 everywhere else + * So a hollow with a ray over it runs at three times the mean and a swept crest on the shaded + * side of a swell at a third of it, against a mean that is still exactly what it was. That is what buys a plain that + * undulates: nothing in it is brighter than it was, there is simply somewhere for the eye to + * find an edge. Note which term does the work — `roll` is the wide one and the slope term is + * deliberately narrow, because one of them says what is on the ground and the other only says + * how it is lit. */ var dens = 0.34 * (lod === 2 ? 1 : (lod === 1 ? 0.80 : 0.55)); dens *= 0.94 + 0.5 * wFines; // levitated fines settle out; see weatherAt - /* THE SWELL. A mare surface is not flat, it undulates on a scale of five to fifteen metres, and - * an even field of grit from the bottom of the frame to the horizon is design-brief failure (c) - * in its purest form: television static, with no way to tell whether the texture is two metres - * off or two kilometres. There is no geometry available for it — city.js owns the heightmap and - * a street cell is height 0 by construction — so the swell is carried by DENSITY instead, which - * is the same trick the tone is carried by. Bilinear over a 9 m lattice rather than a hard cell, - * because a hard cell gives the plain visible 9 m tiles; four hashes and three lerps buys a - * surface that reads as gently rolling. 0.55 to 1.45 is a factor of 2.6 in coverage, which at - * this density is the difference between bare ground and a drift. */ - var sxq = wx / 9.0, szq = wz / 9.0; - var s0 = Math.floor(sxq), s1 = Math.floor(szq); - var fx = sxq - s0, fz = szq - s1; - fx = fx * fx * (3 - 2 * fx); fz = fz * fz * (3 - 2 * fz); - var n00 = hash2(s0, s1, 0x4D71), n10 = hash2(s0 + 1, s1, 0x4D71); - var n01 = hash2(s0, s1 + 1, 0x4D71), n11 = hash2(s0 + 1, s1 + 1, 0x4D71); - var sw = (n00 + (n10 - n00) * fx) + ((n01 + (n11 - n01) * fx) - (n00 + (n10 - n00) * fx)) * fz; - dens *= 0.55 + 0.90 * sw; + dens *= roll * (1 + slope) * (1 + CR_HALO); + if (dist < RAY_LEN) dens *= 1 + rayAt(wx, wz); + /* THE CEILING, and it is the one guard the whole product needs. Four terms centred on 1 can in + * principle multiply out past 4, and 0.34 * 4 is a coverage over 1 — a solid white patch of + * ground, which is not a drift of fines, it is a hole in the picture where the black should be. + * 0.62 is the densest the eye still reads as a granular surface rather than as a fill; measured + * over 210k ground samples at 400x100, three hours by six yaws, it is reached by 0.008% of them, + * so the clamp is a guard rather than a shaping term and the distribution below it is untouched. + * It is rarer than it looks because the far LOD scales the base to 0.187 and most ground samples + * in a frame are far. */ + if (dens > 0.62) dens = 0.62; var d1 = hash2(Math.floor(wx * q), Math.floor(wz * q), 0x4D01); if (d1 < dens) { var k1 = d1 / dens; // normalised, for the reason litSet's callers all are @@ -839,18 +1330,19 @@ * about 2.7% of ground cells, which with the ground at 40% of the frame is 1.1% hot from the * floor. Measured at 400x100 seed 42 the whole frame runs 2.1-2.4% hot against the build's * 3.5-5% target, and the shortfall is deliberate: the remainder is meant to come from the LM - * foil, the SWC foil, the crew suit and Earth, none of which exist yet. If those land and the - * census overshoots, this threshold is the first thing to move back. */ + * foil, the SWC foil, the crew suit and Earth. */ if (k1 > 0.92) return rset(specSet(G_STAR, (k1 - 0.92) / 0.08, dist)); return rset(litSet(k1 < 0.34 ? G_DOT : (k1 < 0.68 ? G_COMMA : G_TICK), k1, dist, d1)); } /* A pebble, and the one blank down-sun of it that is its shadow. Rare, near field only, and the * only object on this floor with an edge — which is the whole point of it: a 3 cm stone with a * 20 cm shadow is a scale reference, and an open plain with no scale reference in it has no - * size. The shadow is drawn as an absence because on this world that is exactly what it is. */ + * size. The shadow is drawn as an absence because on this world that is exactly what it is. + * The rate rides the CREST rather than being flat: the coarse fraction is what is left where + * the fines have crept away, so stones come out of the swept tops and not out of the drifts. */ if (lod === 2) { var d2 = hash2(Math.floor(wx * q * 0.5), Math.floor(wz * q * 0.5), 0x4D03); - if (d2 < 0.010) return rset(litSet(G_o, 0.9, dist, d2)); + if (d2 < 0.010 * (1.9 - roll)) return rset(litSet(G_o, 0.9, dist, d2)); } return rblank(); } @@ -989,12 +1481,13 @@ * edit to surfaces.js — which matters, because surfaces.js is shared with two worlds that are * already tuned. * - * ONE THING THIS DOES NOT FIX, recorded because it is in somebody else's file. refog() also lifts - * far cells onto a haze floor of `Daylight.P.sky * (0.30 + 0.55*fog) * 46`, which is aerial - * perspective — the one thing this world does not have. It only bites past fogStart, so on the - * Moon it touches the two screen rows between 150 m and the horizon and is close to invisible; - * the correct fix is for daylight.js to publish sky 0 in a vacuum world, and that is in the report - * rather than worked around here. */ + * AND THE HAZE FLOOR IS ALREADY DEALT WITH, four lines below this one. refog() used to lift far + * cells onto a floor of `Daylight.P.sky * (0.30 + 0.55*fog) * 46`, which is aerial perspective — + * the one thing this world does not have. surfaces.js:2728 now reads + * `hazeFloor = (D && !(alt && alt.airless)) ? ... : 0`, so the `airless: 1` exported below turns + * it off on this world and there is nothing left to work around. The previous version of this + * paragraph escalated it as an open cross-file defect and asked another lane to fix something + * that was already fixed, four lines above the flag that fixes it. */ var FOG_START_M = 150.0, FOG_END_M = 240.0, FOG_POW_M = 0.45; CC.SurfMoon = { diff --git a/src/surf_west.js b/src/surf_west.js index 2d7a92f..9f1f980 100644 --- a/src/surf_west.js +++ b/src/surf_west.js @@ -36,12 +36,13 @@ (function (CC) { 'use strict'; - var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise; + var P = CC.P, g = CC.g, hash2 = CC.hash2, clamp = CC.clamp, vnoise = CC.vnoise, smooth = CC.smooth; var G_DOT = g('.'), G_COMMA = g(','), G_COLON = g(':'), G_SEMI = g(';'), G_QUOTE = g("'"), G_TICK = g('`'), G_DASH = g('-'), G_UNDER = g('_'), G_EQ = g('='), G_TILDE = g('~'), G_PIPE = g('|'), G_SLASH = g('/'), G_PCT = g('%'), G_AMP = g('&'), G_8 = g('8'), - G_0 = g('0'), G_o = g('o'); + G_0 = g('0'), G_o = g('o'), G_HASH = g('#'), G_PLUS = g('+'), G_STAR = g('*'), + G_CARET = g('^'), G_DQ = g('"'); /* The one thing this file and surfaces.js MUST agree on, because raycast.js configures only one * of them: the config block. Resolved lazily rather than captured, so load order cannot bite. */ @@ -96,10 +97,112 @@ SUN_AZ = D.P.az; SUN_ALT = D.P.alt; SUN_X = Math.sin(SUN_AZ); SUN_Z = Math.cos(SUN_AZ); dSun = D.P.sun; dSky = D.P.sky; dWarm = D.P.warm; dLamp = D.P.lamp; dStar = D.P.star; + dFill = smooth(clamp((dSky - 0.70) / 0.30, 0, 1)); } - var dT = 1 / 0, dSun = 0.64, dSky = 0.66, dWarm = 0.74, dLamp = 1, dStar = 0; + /* dFill's standalone default is 0 and not smooth((0.66-0.70)/0.30) rounded up to something + * plausible: the tuned hour this row of defaults exists to hold IS dusk, and dusk's fill is + * exactly zero. It also has to be zero for a second reason. surfaces.js reads fogStart/fogPow off + * this module inside refog(), which weatherAt() calls from beginFrame() BEFORE any painter has + * run, so on frame 0 the ramp is built from whatever dFill happens to be — and a default of 0.062 + * moved five cells of the night reference frame through the exposure element's adaptation. Every + * later frame reads a dFill that is one frame stale, which is 1/60 s of a 420 s clock and cannot + * be seen. */ + var dT = 1 / 0, dSun = 0.64, dSky = 0.66, dWarm = 0.74, dLamp = 1, dStar = 0, dFill = 0; function dAlt() { return SUN_ALT; } + /* ---- HOW MUCH DAY IS IN THE FRAME, and it is deliberately not dSky ---------------------------- + * Everything below that FILLS a surface — a wall, the road, the dome — is gated on this one + * number, and it exists because the two things the gate has to do pull in opposite directions. + * + * The tuned baseline of this world is night and dusk. Night is a hard invariant (the project's + * rule is that every daylight scale must be the identity at night) but DUSK is the world's + * signature hour and it is not allowed to get muddier either — and dusk is not dark: the clock + * reports sky 0.657 and sun 0.644 at the dusk stop, two thirds of the way to noon on both. Gating + * on dSky raw would therefore have poured two thirds of the day treatment into the one hour that + * was already right. + * + * So the fill is dSky pushed through a threshold and a smoothstep. The clock reports dSky at the + * six stops it names as 0.000 night, 0.657 dawn AND dusk, 0.929 morning and afternoon, 1.000 + * noon, so the threshold decides exactly one thing: whether the two tuned hours get any of this + * at all. Measured: + * threshold night dawn/dusk morning noon + * 0.60 0.000 0.055 0.926 1.000 + * 0.70 0.000 0.000 0.840 1.000 + * 0.60 looked safe — a twentieth is under the dither's own noise floor — and it was not. Rendered + * and censused at seed 42 frame 300, dusk moved blank 48.0% -> 41.7% and muddy 46.3% -> 51.6%, + * because a twentieth of the fill is applied to EVERY blank cell of every wall, road and sky in + * the frame and there are a great many of them. Dusk is this world's signature hour and the brief + * for this pass is that it must not get muddier, so the threshold goes above dawn and dusk + * outright: at 0.70 both are byte-identical to the shipped build, the same guarantee night has, + * and the whole transition happens in the unnamed hours between dusk and morning where nothing is + * fitted. Rejected 0.90, which leaves morning at 0.13 — the brightest hour of the day still + * empty, and the entire crossover crammed into the twenty minutes before noon. + * + * It is a SLOW, CONTINUOUS ramp — the clock's cycle is 420 s, so the crossing takes about ninety + * seconds of wall time — and it is only ever used as a DITHER PROBABILITY, never as a brightness + * step. That matters for the photosensitivity gate: a wall does not switch on, it dissolves in a + * few cells at a time, and no single cell changes more than once on the way through. */ + + /* ---- WHAT A MATERIAL LOOKS LIKE IN DAYLIGHT -------------------------------------------------- + * city.js hands `hue` as a claim about SUBSTANCE now — sand, white, timber, stone or ember — and + * this is the file that has to turn substance into ink. The line it replaced was a whitelist, + * var litHue = (hue === P.warm || hue === P.white || hue === P.ember) ? hue : P.amber; + * written when the only surface swatches in the palette were the city's; every material city.js + * has since learned to name fell off it and collapsed to amber. That one expression is why the + * frontier census was byte-for-byte identical before and after the new district table landed, and + * it is the whole of the "daylight is empty" complaint in a single line of code. + * + * THREE SWATCHES PER MATERIAL, because a board wall is never one colour and a flood fill in one + * swatch is worse than a blank wall — it is a blank wall with a tint. The three are the planks + * that took the sun, the ones that are dusty or split or sit a degree proud, and the ones with + * only sky on them: + * SUN direct sun. The pale end: sand (day ceiling 190) and white (151) are the only two + * swatches in the table that can carry a large bright surface at noon. + * MID the broken half-tone. It is the swatch that carries the BROWNS and the GREYS the + * complaint asks for, and it is where the first cut of this table went wrong: timber's MID + * was timber, so a boards quarter — 24% of the frontier's lots lead on timber — printed + * 2099 of a noon frame's 4231 facade cells in one swatch whose day ceiling is 120, and the + * whole middle of the picture came out as one dark brown band. Weathered board in full + * daylight is SILVER, not brown; the brown is what it is in shade. So MID is stone + * (ceiling 145) and SHD keeps timber, which is the same three-swatch story told the right + * way round. + * SHD the same material with the sky on it and no sun. Never `shadow`: core.js lifts shadow + * from 0.80 to 0.46 by day precisely because a shadow under a bright hemisphere is filled, + * so the shade side of a timber wall is dark brown (timber, ceiling 120) or blue-grey + * (indigo, 104) and not a hole. It is also the row to be MEANEST with, because it is the + * one the largest share of cells lands on: sand leads 39.8% of the frontier's lots and its + * SHD was timber first, which put 2084 of a noon frame's 4231 facade cells into a swatch + * printing a mean max-channel of 54 — half the town, in the dark. It is stone now, which + * is what a pale wall in shade under a blue sky actually is; the browns come from the two + * rows that are genuinely brown. + * + * Twenty rows and not five, indexed by palette slot rather than by district, because a hue this + * file has not been told about has to degrade to the nearest material rather than to `undefined` + * — which is the fault surfaces.js's L_LOW/L_LIT/L_HOT carry to this day. Rows 0-11 can only be + * reached through a theme edit; they are filled with the frontier material each legacy swatch + * most resembles so that such an edit degrades quietly. */ + var MAT_SUN = [ + /* 0 amber */ P.sand, /* 1 azure */ P.white, /* 2 ember */ P.ember, /* 3 spring */ P.moss, + /* 4 violet */ P.stone, /* 5 white */ P.white, /* 6 red */ P.ember, /* 7 slate */ P.stone, + /* 8 warm */ P.sand, /* 9 ice */ P.white, /* 10 pure */ P.white, /* 11 shadow */ P.stone, + /* 12 stone */ P.stone, /* 13 timber */ P.sand, /* 14 sand */ P.sand, /* 15 jade */ P.jade, + /* 16 rose */ P.sand, /* 17 gold */ P.gold, /* 18 moss */ P.moss, /* 19 indigo */ P.stone + ]; + var MAT_MID = [ + /* 0 amber */ P.sand, /* 1 azure */ P.stone, /* 2 ember */ P.timber, /* 3 spring */ P.moss, + /* 4 violet */ P.indigo,/* 5 white */ P.sand, /* 6 red */ P.timber, /* 7 slate */ P.stone, + /* 8 warm */ P.sand, /* 9 ice */ P.stone, /* 10 pure */ P.sand, /* 11 shadow */ P.timber, + /* 12 stone */ P.stone, /* 13 timber */ P.stone, /* 14 sand */ P.timber, /* 15 jade */ P.moss, + /* 16 rose */ P.timber,/* 17 gold */ P.sand, /* 18 moss */ P.moss, /* 19 indigo */ P.indigo + ]; + var MAT_SHD = [ + /* 0 amber */ P.timber,/* 1 azure */ P.indigo,/* 2 ember */ P.timber, /* 3 spring */ P.moss, + /* 4 violet */ P.indigo,/* 5 white */ P.stone, /* 6 red */ P.timber, /* 7 slate */ P.indigo, + /* 8 warm */ P.timber,/* 9 ice */ P.stone, /* 10 pure */ P.stone, /* 11 shadow */ P.indigo, + /* 12 stone */ P.indigo,/* 13 timber */ P.timber,/* 14 sand */ P.stone, /* 15 jade */ P.indigo, + /* 16 rose */ P.timber,/* 17 gold */ P.timber,/* 18 moss */ P.moss, /* 19 indigo */ P.indigo + ]; + /* How much of the last light a face gets, by which way it points. CONTINUOUS rather than three * buckets, and that is a repair rather than a refinement: with the sun off-axis the two street * walls sit at +-0.48 of the sun vector, so a three-bucket version with its thresholds at +-0.5 @@ -202,6 +305,41 @@ shopW: 1.30, shopH: 1.35, rough: 0, vert: 0 } ]; + /* ---- THE INK RAMP ----------------------------------------------------------------------------- + * A glyph is not a pixel, and this is the one place in the project where that bites hardest. + * + * Measured, by rasterising every entry of core.js's GLYPHS at the size the print uses (Liberation + * Mono Bold at 15 px in a 9x16 cell, which is what tools/topng.py draws and what + * render_canvas.js's atlas bakes) and taking the mean alpha: + * '`' 2.6% '.' 3.0% '_' 4.4% '-' 5.3% ':' 5.9% ',' 6.2% '~' 8.6% ';' 9.2% + * '"' 12.1% '+' 15.5% '=' 17.1% '|' 18.7% '#' 23.9% '%' 27.1% '8' 31.6% 'Q' 38.4% + * So two cells written at the same lum in the same swatch can differ by a factor of TEN in what + * the eye actually receives, and every measurement this file has ever taken — muddy, hot, lit — + * is blind to it, because they all count lum and swatch and nothing counts area. + * + * That is the whole of the "daylight is empty" complaint. The night look is built out of '-', + * '_', '`' and '.' — 2.6 to 5.3 per cent ink — and it is CORRECT: a dark frame wants thin ink and + * a scatter of it. The first cut of this day pass filled the walls, filled the road and filled the + * sky in the same four glyphs at three times the lum, and the census scored the result 45.2% lit + * and 10.5% hot while the picture on screen was still black. 45% of a frame at 4% ink is 1.8% of + * the frame's area with anything on it at all. + * + * So a daylight surface picks its glyph off this ramp instead, keyed on its own tone. The heavy + * end stops at '%' (27.1%) rather than going on to '8', 'M' or 'Q': those three are already + * spoken for in this world — '8' and 'o' are a lit window and a stone in the road, and reading a + * wall in them would say "there is a lamp in it" — and past about 30% ink the bloom in + * render_canvas.js starts to weld neighbouring cells into a solid block. + * + * NOT A FLICKER RISK, and the arithmetic matters: within one surface the ramp index moves by at + * most three steps (about 12% ink to 27%, under 2x), because the spread term below is +-0.15 of + * the ramp. The step this file actually has to fear is surface-to-blank, and filling the surface + * is what removes it. */ + var INK = [G_TICK, G_DOT, G_UNDER, G_DASH, G_COLON, G_TILDE, G_DQ, G_PLUS, G_EQ, G_HASH, G_PCT]; + function ink(t) { + var i = (t * 11) | 0; + return INK[i < 0 ? 0 : (i > 10 ? 10 : i)]; + } + var FOUT = { ch: 0, col: 0, lum: 0 }; function fset(ch, col, lum) { FOUT.ch = ch; FOUT.col = col; @@ -258,10 +396,26 @@ return fset(bh < 0.5 ? G_DASH : G_UNDER, P.slate, (13 + bh * 15) * shade * (0.55 + 0.45 * sun)); } - if (lod > 0 && hash2(Math.floor(u * 3.1), Math.floor(v * 2.7), sd ^ 0x9B) < 0.20 + 0.12 * bh) { - return fset(bh < 0.4 ? G_COLON : (bh < 0.75 ? G_PCT : G_AMP), - sun > 0.6 && bh > 0.6 ? P.ember : P.slate, - (10 + bh * 16) * shade * (0.5 + 0.5 * sun)); + /* THE BODY OF A BED IS MOSTLY BLANK AT NIGHT AND SOLID BY DAY, for the reason the wall one + * function down spends a paragraph on: 30 m of dim glyphs is 30 m of muddy band after dark, and + * 30 m of black is a hole cut in a bright sky at noon. A butte is the largest single object + * this world contains and it is the one that suffers most from being drawn as a rhythm. + * + * The swatch is the rock's own: stone for the shaded and grey beds, ember and timber for the + * red ones, sand where the sun is square on. That is a red-rock country in three swatches and + * it is the range the complaint asks for. */ + var rd = 0.20 + 0.12 * bh; + rd += (0.95 - rd) * dFill; + if (lod > 0 && hash2(Math.floor(u * 3.1), Math.floor(v * 2.7), sd ^ 0x9B) < rd) { + var rn = (10 + bh * 16) * shade * (0.5 + 0.5 * sun); + var rday = (30 + 150 * sun * sun + bh * 40) * shade; + var rcol = P.slate; + if (dFill > 0.002 && hash2(Math.floor(u * 1.9), Math.floor(v * 1.9), sd ^ 0x7D3) < dFill) + rcol = sun > 0.66 && bh > 0.55 ? (bh > 0.80 ? P.sand : P.ember) + : (bh < 0.30 ? P.timber : P.stone); + else if (sun > 0.6 && bh > 0.6) rcol = P.ember; + return fset(bh < 0.4 ? G_COLON : (bh < 0.75 ? G_PCT : G_AMP), rcol, + rn + (rday - rn) * dFill); } return fset(0, P.shadow, 0); } @@ -288,21 +442,71 @@ /* The sunlit swatch of THIS building. A frontier wall is bare wood going silver, painted * board, or mud — so the lit colour is the district's hue where that hue is a surface colour, * and amber where it is not. Amber is doing double duty as "sunlight on timber", which is what - * it is: the swatch is 216,232,74 and low sun on weathered pine is very close to it. */ - var litHue = (hue === P.warm || hue === P.white || hue === P.ember) ? hue : P.amber; - var sunHue = sun >= 0.62 ? P.amber : litHue; + * it is: the swatch is 216,232,74 and low sun on weathered pine is very close to it. + * + * ---- AND BY DAY IT IS THE MATERIAL, dithered across ------------------------------------------ + * Amber goes back to meaning LOW SUN ON A SURFACE, which is the only thing it was ever right + * for: 216,232,74 is close to weathered pine at four degrees of elevation and nothing like it + * at fifty. So the choice between the old answer and the material is made PER CELL against + * dFill, on a hash keyed to the wall the way every other hash in this function is. At dFill 0 + * every cell takes the old answer and the night frame is unchanged by construction; at dFill 1 + * every cell takes the material; in between the wall dissolves from one to the other. That is + * the only cross-fade available — this renderer cannot blend two palette indices, so the dither + * does the mixing, exactly as sky() below already does it between its two ladders. + * + * `ms` is the same hash renormalised over the cells that have crossed over, which makes it a + * free second uniform variate rather than a second hash: dividing by dFill maps [0,dFill) onto + * [0,1). It is what picks between the three material swatches below. */ + var mh = hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x1D5); + var dayMat = mh < dFill; + var ms = dFill > 0.002 ? mh / dFill : 0; + + /* WHERE THIS FACE SITS BETWEEN SHADE AND SUN, as a ramp and not a threshold. `sun >= 0.62` + * elsewhere in this file is a whole wall changing swatch at one instant of the clock — which is + * the large-area step the photosensitivity gate exists to catch, and it is tolerable only + * because at dusk the two sides of the street are nowhere near the threshold. The day branch + * must not add another one, so the three material swatches are dithered on `k` instead and the + * wall crosses over a few cells at a time as the sun climbs. + * + * The share of SUN cells is k*k rather than k: a wall at half illumination is not half covered + * in highlight, it is mostly its own colour with the sun catching the proud edges. MID never + * drops below a quarter, so even a fully shaded wall keeps some broken tone in it and does not + * read as one flat swatch. */ + var k = clamp((sun - 0.22) / 0.52, 0, 1); + var mat = ms < 0.72 * k * k ? MAT_SUN[hue] + : (ms < 0.72 * k * k + 0.24 + 0.20 * k ? MAT_MID[hue] : MAT_SHD[hue]); + + var litHue = dayMat ? mat + : ((hue === P.warm || hue === P.white || hue === P.ember) ? hue : P.amber); + var sunHue = dayMat ? mat : (sun >= 0.62 ? P.amber : litHue); + /* The swatch every "in shade" branch below reaches for. slate at night, because slate IS the + * night's shade swatch and the whole tuned frame is built on it; the material's own shade by + * day, because a shaded wall at noon is a dark BROWN wall and not a blue-grey one. */ + var shdHue = dayMat ? MAT_SHD[hue] : P.slate; /* ---- the coping --------------------------------------------------------------------------- * The top 30 cm of a false front is a capping board, and it is the single most valuable line * in the world: it is the roofline, and a roofline is what turns a black shape into a * building. It is drawn at every distance and every LOD for that reason. */ if (h - v < 0.34) { - return fset(G_EQ, sun >= 0.62 ? P.amber : (sun > 0.30 ? litHue : P.slate), + return fset(G_EQ, sun >= 0.62 ? sunHue : (sun > 0.30 ? litHue : shdHue), (sun >= 0.62 ? 214 : (sun > 0.30 ? 82 : 32)) * gr); } /* And the shadow it throws — one board's worth of dark immediately under it, which is what - * makes the coping read as PROUD of the wall rather than painted on it. */ - if (h - v < 0.62) return fset(0, P.shadow, 0); + * makes the coping read as PROUD of the wall rather than painted on it. + * + * BY DAY IT IS ALSO THE WEATHERING RUN. Everything that has ever come off that capping board + * has run down the two feet under it, so this is the dirtiest band on the building and it is + * STREAKED rather than flat: the hash is keyed on u alone, so a column is either running or it + * is not and the band comes out as vertical stains. It stays the darkest band on the wall, + * which is the whole job of the line it replaced. */ + if (h - v < 0.62) { + if (dFill <= 0.002) return fset(0, P.shadow, 0); + var wr = hash2(Math.floor(u * 4.3), 0, sd ^ 0x3E9); + if (wr > 0.86 * dFill) return fset(0, P.shadow, 0); + return fset(wr < 0.30 ? G_PIPE : G_COLON, wr < 0.50 ? P.timber : shdHue, + (12 + 54 * sun) * gr); + } var bay = Math.floor(u / st.bay), fu = u / st.bay - bay; var bh = hash2(bay, sd, 0x3F1); // this bay's identity, stable forever @@ -311,9 +515,18 @@ * Where the awning meets the wall. Above it the building; below it, shopfront in the shade of * its own porch. The dark band is the shadow line and it is what separates the two storeys * without drawing a cornice on a building that would never have had one. */ - if (v > st.gnd && v < st.gnd + 0.30) return fset(0, P.shadow, 0); + if (v > st.gnd && v < st.gnd + 0.30) { + if (dFill <= 0.002) return fset(0, P.shadow, 0); + /* By day the deepest shadow on the building is still not a hole — core.js lifts `shadow` + * from 0.80 to 0.46 by day for exactly this reason — so the porch line is drawn in indigo, + * the palette's own "shade with the sky in it", at a lum well under the wall either side of + * it. It has to stay the darkest thing at that height or the two storeys merge. */ + var pz = hash2(Math.floor(u * 3.3), Math.floor(v * 6), sd ^ 0x91); + if (pz > 0.82 * dFill) return fset(0, P.shadow, 0); + return fset(pz < 0.5 ? G_UNDER : G_DASH, P.indigo, (14 + 38 * dSky) * gr); + } if (v > st.gnd + 0.30 && v < st.gnd + 0.52) - return fset(G_DASH, sun >= 0.62 ? P.amber : P.slate, (sun >= 0.62 ? 74 : 22) * gr); + return fset(G_DASH, sun >= 0.62 ? sunHue : shdHue, (sun >= 0.62 ? 74 : 22) * gr); /* ---- ground floor: the shopfront ---------------------------------------------------------- */ if (v <= st.gnd) { @@ -333,8 +546,30 @@ /* The doorway. Open ones are a slot of lamplight with a dark head above; shut ones are * boards, and the frame is the only thing that reads. */ if (fu - d0 < 0.05 || d1 - fu < 0.05 || v > 2.02) - return fset(G_PIPE, P.slate, 20 * gr); - if (!open) return fset(0, P.shadow, 0); + return fset(G_PIPE, shdHue, (20 + 44 * dFill * sun) * gr); + if (open && dFill > 0.002 && + hash2(Math.floor(u * 3.9), Math.floor(v * 3.9), sd ^ 0x2E7) < dFill) { + /* AN OPEN DOOR AT NOON IS A HOLE, and that is the whole inversion. At dusk it is a slot + * of lamplight and the brightest thing at street level; at midday the room behind it is + * three or four stops under the street, so it is the DARKEST rectangle on the building. + * Getting this the wrong way round is what a lamp burning at noon looks like. A little of + * the floor just inside the threshold catches the light off the road, and that one bright + * line at the bottom is what stops the doorway reading as a painted black rectangle. */ + var dv2 = 1 - v / 2.15; + return fset(v < 0.30 ? G_EQ : (dv2 > 0.62 ? G_COLON : G_DOT), + v < 0.30 ? P.timber : P.indigo, + v < 0.30 ? 96 : (34 + 44 * dv2) * (0.5 + 0.5 * dSky)); + } + if (!open) { + /* A shut door by day is a panelled or ledged door in the porch's shade: vertical boards + * with a rail across them, and dark, because it is under the awning at every hour the + * sun is up. It was a hole, and a hole in the middle of a shopfront is the one place the + * eye goes. */ + if (dFill <= 0.002) return fset(0, P.shadow, 0); + var dz = (fu - d0) / dw * 5; + return fset(Math.abs(v - 1.18) < 0.09 ? G_EQ : (dz - Math.floor(dz) < 0.16 ? G_PIPE : G_UNDER), + P.timber, (16 + 66 * sun) * gr); + } var dk = 1 - v / 2.15; return fset(v < 0.35 ? G_UNDER : G_8, P.warm, (96 + 74 * dk) * (0.7 + 0.5 * gr)); } @@ -344,19 +579,62 @@ /* Glass. The frame first — a shopfront is a big pane in a heavy timber surround and the * surround is what carries the shape at distance. */ if (v - wv0 < 0.14 || wv1 - v < 0.14 || fu - w0 < 0.04 || w1 - fu < 0.04) - return fset(G_EQ, sun >= 0.62 ? P.white : P.slate, (sun >= 0.62 ? 66 : 26) * gr); + return fset(G_EQ, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate), + ((sun >= 0.62 ? 66 : 26) + 78 * dFill * sun) * gr); if (!open) { /* Shuttered: boards nailed across, which is a diagonal, and the one place a diagonal * belongs on this facade. */ var bd = Math.floor((v * 1.6 + fu * 2.2) * 2.4); - return (bd & 1) ? fset(G_SLASH, P.slate, 15 * gr) : fset(0, P.shadow, 0); + if (bd & 1) return fset(G_SLASH, dayMat ? P.timber : P.slate, + (15 + 74 * dFill * sun) * gr); + /* The dark between the nailed boards is the empty shop behind the glass, and by day that + * is a deep reflection of the street rather than nothing at all. */ + return dFill <= 0.002 ? fset(0, P.shadow, 0) + : fset(G_DOT, P.indigo, (10 + 44 * dSky) * gr); } /* Lit: a warm field with a mullion up the middle and the goods in the window reading as * broken dark. Held at lum 120-190 — warm's EXPOSURE weight is 0.32, so this lands in the * 130-165 print band that market.js measured as free on both the muddy and the hot count. */ var mull = Math.abs(fu - (w0 + w1) * 0.5) < 0.022; - if (mull) return fset(G_PIPE, P.slate, 30); + if (mull) return fset(G_PIPE, shdHue, 30 + 52 * dFill * sun); var gl = hash2(Math.floor(u * 2.6), Math.floor(v * 2.6), sd ^ 0x77); + /* ---- AND BY DAY THE PANE IS A MIRROR, NOT A LAMP ------------------------------------- + * What follows is a lit shopfront at dusk, and it is the best thing at street level in this + * world: warm at 120-216 with the flame drawn in amber over it. At NOON it is a kerosene + * lamp burning at midday. Measured at seed 42 frame 300 with the camera on a near + * shopfront, it was the brightest object in the frame in blocks eight cells wide, and a + * large share of a 22% hot tail. + * + * What a shop window at noon actually is: the top of the pane holds the SKY, which is the + * brightest thing there is, and the rest holds a dark interior with the street across it. + * So the pane splits at 0.58 of its height — sky above, room below — and the SPLIT is the + * read: a pale rectangle over a dark one is a window at any distance, in a way that a field + * of one tone is not. + * + * Dithered on the fill like everything else, so the lamps go out one cell at a time through + * the morning rather than all on one frame, and at dFill 0 not one cell of this exists. */ + if (dFill > 0.002 && + hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x6A3) < dFill) { + var rv = (v - wv0) / st.shopH; + if (rv > 0.58) { + var rk = (rv - 0.58) / 0.42; + return fset(ink(0.44 + 0.38 * rk + 0.14 * (gl - 0.5)), + gl < 0.62 ? P.white : P.ice, (108 + 84 * rk) * (0.5 + 0.5 * dSky)); + } + /* The room. Goods against the glass read as broken dark, and one cell in seven catches + * the road behind the viewer — which is what makes a dark pane read as glass rather than + * as a hole cut in the wall. */ + /* 52 + 78, not 18 + 44. The first cut put the room at a printed 18-62 in indigo, whose + * day ceiling is 104, and the lower half of every shopfront on the street came out as a + * solid black rectangle — a hole again, in the one place this pass had just finished + * removing one. What is actually in the bottom of a shop window at midday is the STREET, + * reflected: a bright road four metres away, laid over the dark of the room. It is still + * the darkest large area on the building, by about two stops from the wall beside it. */ + if (gl > 0.86) return fset(G_UNDER, P.sand, (86 + 54 * gl) * (0.4 + 0.6 * dSky)); + return fset(gl < 0.34 ? G_HASH : (gl < 0.66 ? G_COLON : G_DOT), + gl < 0.34 ? P.timber : P.indigo, + (52 + 78 * gl) * (0.5 + 0.5 * dSky)); + } if (gl < 0.17) return fset(G_0, P.shadow, 0); // stock, in silhouette /* THE LAMP. Every other lit cell in this world is a SURFACE catching a dying sun, and * core.js's ladder makes surfaces dim on purpose — warm is 0.32 and white is 0.30, so @@ -377,8 +655,17 @@ } /* The rest of the ground floor is board, in the porch's shade — so it is DARKER than the - * storey above it whichever way it faces, and that inversion is what makes a porch a porch. */ - return board(u, v, st, sd, lod, gr, sun * 0.42, sunHue, dist); + * storey above it whichever way it faces, and that inversion is what makes a porch a porch. + * + * 0.42 AT NIGHT AND 0.62 BY DAY, because what fills a porch is not the sun. At dusk the only + * light under an awning is the sky behind the viewer and 0.42 is generous. At noon there is a + * bone-white dirt road four metres in front of it throwing light straight back up under the + * boards, and that bounce is most of what a shaded shopfront is lit by — measured the other + * way round: at 0.42 the ground floors of the near buildings were the darkest band in a noon + * frame at a mean lum of 82, under both the wall above them and the road below. The porch has + * to stay the darker of the two or it stops being a porch, and at 0.62 it still is, by about + * a stop and a half. */ + return board(u, v, st, sd, lod, gr, sun * (0.42 + 0.20 * dFill), sunHue, shdHue, dayMat, dist); } /* ---- upper storey ------------------------------------------------------------------------- @@ -402,10 +689,22 @@ if (fu > c0 && fu < c1) { var wh = hash2(bay * 7 + storey, sd, 0x8D2); if (sv - 0.55 < 0.11 || 0.55 + st.winH - sv < 0.11 || fu - c0 < 0.05 || c1 - fu < 0.05) - return fset(G_DASH, sun >= 0.62 ? P.white : P.slate, - (sun >= 0.62 ? 58 : 22) * gr); + return fset(G_DASH, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate), + ((sun >= 0.62 ? 58 : 22) + 82 * dFill * sun) * gr); if (wh < lit) { var lg = hash2(Math.floor(u * 3.4), Math.floor(v * 3.4), sd ^ 0xA3); + /* The upstairs lamp goes out with the downstairs one and for the same reason — see the + * shopfront pane above. What replaces it is the dark-glass treatment two branches down, + * which is what an unlit sash at noon is, so a lit window and an unlit one converge as + * the day comes up. That is correct: at midday you cannot tell them apart. */ + if (dFill > 0.002 && + hash2(Math.floor(u * 3.1), Math.floor(v * 3.1), sd ^ 0x6A3) < dFill) { + if (Math.abs(sv - (0.55 + st.winH * 0.5)) < 0.06) + return fset(G_DASH, P.white, (30 + 96 * sun) * gr); + if (lg > 0.80) return fset(G_UNDER, P.white, (96 + 60 * lg) * (0.4 + 0.6 * dSky)); + return fset(lg < 0.40 ? G_COLON : G_DOT, P.indigo, + (34 + 62 * dSky + lg * 34) * gr); + } if (lg < 0.16) return fset(G_o, P.shadow, 0); // somebody at the glass if (lg > 0.66) return fset(lg > 0.92 ? G_o : G_8, P.amber, (204 + lg * 50) * gr); return fset(G_8, P.warm, (112 + lg * 84) * gr); @@ -414,17 +713,60 @@ * visible at all — a faint cool cell in a warm wall. It is ice rather than azure because * ice is a GLINT weight (0.36) and azure is a pillar (1.00): one dark pane in azure at * this lum would be the brightest thing on the building. */ - if (hash2(Math.floor(u * 2.2), Math.floor(v * 2.2), sd ^ 0xB5) < 0.30) - return fset(G_COLON, P.ice, 20 * gr); - return fset(0, P.shadow, 0); + var dg = hash2(Math.floor(u * 2.2), Math.floor(v * 2.2), sd ^ 0xB5); + if (dg < 0.30) return fset(G_COLON, P.ice, (20 + 46 * dFill) * gr); + /* AND BY DAY THE REST OF THE PANE IS NOT A HOLE EITHER. An unlit window at noon is the + * darkest rectangle on a bright wall — which is what makes a daylight building read — but + * it is glass with a sky in it, so it is indigo at a low lum and not black. A glazing bar + * across the middle of it, because a frontier sash is two lights over two. */ + if (dFill <= 0.002) return fset(0, P.shadow, 0); + if (Math.abs(sv - (0.55 + st.winH * 0.5)) < 0.06) + return fset(G_DASH, P.white, (30 + 96 * sun) * gr); + return fset(dg < 0.62 ? G_COLON : G_DOT, P.indigo, (18 + 50 * dSky + dg * 26) * gr); } /* The sill and the head run the full bay on a painted front — a line of white across the * facade at window height, which is a strong horizontal and very much of the period. */ if (st.rough === 0 && (sv - 0.55 < 0.10 || 0.55 + st.winH - sv < 0.10) && bh > 0.62) - return fset(G_DASH, sun >= 0.62 ? P.white : P.slate, (sun >= 0.62 ? 50 : 18) * gr); + return fset(G_DASH, sun >= 0.62 ? P.white : (dayMat ? P.white : P.slate), + ((sun >= 0.62 ? 50 : 18) + 76 * dFill * sun) * gr); } - return board(u, v, st, sd, lod, gr, sun, sunHue, dist); + /* ---- THE GHOST SIGN, one front in six and day only ------------------------------------------- + * A false front is a large blank board, and after the coping and the two storeys of windows it + * is the single biggest empty area in this world — which is most of what the complaint is + * about. What actually went on those boards was PAINT: a merchant's name in three-foot letters, + * half gone. + * + * It is drawn as a LATTICE and not as glyphs, and that is forced rather than chosen: the frame + * is 200 columns across a 17 m street, so a three-foot letter is one cell and any attempt to + * spell something reads as one speck. What the eye recognises a painted sign by at fifty metres + * is a BAND OF BLOCKY MARKS AT A REGULAR PITCH with the wear punched through it, and that is + * what this is: a 0.62 m letter pitch, three rows of stroke, and a third of it worn away. + * + * Day only, and the reason is not budget. At dusk this wall is either a hard amber rim or a + * silhouette, and a painted sign is neither — there is no light on it to be a different colour + * FROM. One front in six, because a street where every board carries lettering is a high street + * and not a frontier town; and only on fronts over 6.2 m, because that is where the blank board + * actually is. */ + var gs = hash2(sd, 0x51, 0x6C7); + if (dFill > 0.002 && gs < 0.17 && h > 6.2) { + var gy0 = st.gnd + 1.35, gy1 = gy0 + 1.60; + if (v > gy0 && v < gy1 && h - v > 1.10) { + var gu = u / 0.62, fgu = gu - Math.floor(gu); + var gvb = Math.floor((v - gy0) / 0.40); // four rows of stroke per letter + var gw = hash2(Math.floor(gu), gvb, sd ^ 0x5A3); + /* The stroke pattern: the outer rows are the tops and bottoms of the letters and are nearly + * continuous, the middle two are the uprights and are mostly gaps. That asymmetry is what + * stops the band reading as a chequer. */ + var inkP = (gvb === 0 || gvb === 3) ? 0.80 : 0.42; + if (fgu < 0.58 && gw < inkP && + hash2(Math.floor(u * 3.4), Math.floor(v * 3.4), sd ^ 0x9E1) < 0.74 * dFill) + return fset(gw < 0.34 ? G_HASH : G_8, + gs < 0.085 ? P.ember : P.white, (54 + 128 * sun + gw * 30) * gr); + } + } + + return board(u, v, st, sd, lod, gr, sun, sunHue, shdHue, dayMat, dist); } /* ---- bare wall ------------------------------------------------------------------------------- @@ -437,15 +779,35 @@ * The lap pitch coarsens with distance rather than being hashed finer, for the same reason * surfaces.js coarsens its bay lattice: at 40 m one cell spans half a metre of wall and a 34 cm * rhythm aliases into a crawling moire that is worse than no texture at all. */ - function board(u, v, st, sd, lod, gr, sun, sunHue, dist) { + function board(u, v, st, sd, lod, gr, sun, sunHue, shdHue, dayMat, dist) { if (st.rough) { /* Adobe and stone: no rhythm, a mottle. Rendered mud is nearly featureless in shade and * comes alive in raking light, which is exactly what `sun` does to the density below. */ var m = hash2(Math.floor(u * 2.4), Math.floor(v * 2.4), sd ^ 0x4C1); - var dens = 0.10 + 0.26 * sun; - if (m > dens) return fset(0, P.shadow, 0); - return fset(m < dens * 0.4 ? G_QUOTE : G_COLON, - sun >= 0.62 ? sunHue : P.slate, (10 + 62 * sun + m * 40) * gr); + /* DENSITY CARRIES THE TONE AT NIGHT AND BRIGHTNESS CARRIES IT BY DAY, which is the same + * lesson the road one function down learned and wrote out at length. A rendered wall at noon + * is a CONTINUOUS surface; drawn as a sparse field of specks it reads as dirt on glass, not + * as adobe. So the coverage goes to 0.94 as the day comes up and the lum ladder below takes + * over the job of saying how bright it is. 0.94 rather than 1.00 leaves the pitting and the + * blown render in it — mud that is perfectly covered stops being mud. */ + var mdens = 0.10 + 0.26 * sun; + mdens += (0.94 - mdens) * dFill; + if (m > mdens) return fset(0, P.shadow, 0); + var mn = 10 + 62 * sun + m * 40; + /* The day figure is fitted against the swatch and not against the night one: sand's day + * ceiling is 190 and the sun-facing wall of an adobe at noon is the brightest large surface + * in the frame, so it is written where it prints near that. The square on `sun` is what keeps + * three stops between the two walls of the street — see sunOf()'s ambient floor. */ + var md = 40 + 44 * dSky + 184 * sun * sun + 44 * m; + /* The thresholds carry dFill so that the third glyph only exists by day: at dFill 0 the + * second test is `m < mdens`, which the density test above has already guaranteed, so the + * cascade collapses to the two glyphs the night frame was tuned with. Written as a constant + * 0.28/0.62 it moved 41 cells of the night reference frame — glyph only, lum identical — and + * that is exactly the class of silent re-tune the day-ladder rule exists to forbid. */ + return fset(dayMat ? ink(0.32 + 0.76 * sun * sun + 0.26 * (m / mdens - 0.5)) + : (m < mdens * (0.40 - 0.12 * dFill) ? G_QUOTE + : (m < mdens * (1 - 0.38 * dFill) ? G_COLON : G_DOT)), + sun >= 0.62 ? sunHue : shdHue, (mn + (md - mn) * dFill) * gr); } var lap = st.lap * (lod === 2 ? 1 : (lod === 1 ? 2 : 4)); @@ -455,9 +817,15 @@ var bx = u / (lap * 1.4), fbx = bx - Math.floor(bx); if (fbx > 0.14) { return (sun >= 0.62 && hash2(Math.floor(u * 1.7), Math.floor(v * 1.7), sd ^ 0x2A) < 0.12) - ? fset(G_QUOTE, sunHue, 26 * gr) : fset(0, P.shadow, 0); + ? fset(G_QUOTE, sunHue, 26 * gr) + : fillCell(u, v, sd, gr, sun, sun >= 0.62 ? sunHue : shdHue, lod); } - return fset(G_PIPE, sun >= 0.62 ? sunHue : P.slate, (12 + 58 * sun) * gr); + /* The batten itself. By day it is the one thing on this wall that stands proud of it, so it + * keeps a shadow down one side — which is `dark` below, and is what makes a batten wall read + * as ribbed at noon instead of as striped. */ + var dark = fbx > 0.085 && dFill > 0.002 && lod === 2; + return fset(G_PIPE, sun >= 0.62 && !dark ? sunHue : shdHue, + ((12 + 58 * sun) + ((dark ? 30 : 128) + 110 * sun * sun - 12 - 58 * sun) * dFill) * gr); } var bv = v / lap, fbv = bv - Math.floor(bv); @@ -486,25 +854,108 @@ * sides, and the SHADOW wall keeps the sparse-lines treatment exactly as before, because slate * at any lum is inside the band and there is no way to spend cells there cheaply. One side of * the street is a surface, the other is a silhouette, and the print pays for both. */ + /* ---- THE JOINTS AND THE NAILS, and both are day-only ---------------------------------------- + * A frontier board is 12 to 16 feet long, so a wall wider than that has BUTT JOINTS in it — + * verticals every 4 m or so, staggered course by course, and they are the one thing that tells + * the eye the wall is made of boards rather than printed with stripes. Nails go in at the studs + * at 0.6 m centres and bleed rust down the board under them. + * + * Both are lod 2 only and both are gated on the fill: at distance they alias into the lap + * rhythm and at night there is nothing for them to be a variation OF. They are drawn DARK + * against the wall rather than bright, which is both what they look like and what keeps them + * off the photosensitivity gate — a one-cell-wide bright vertical that a walking camera steps + * across is the exact failure the gate is written for. */ + if (lod === 2 && dFill > 0.002) { + var course = Math.floor(v / lap); + /* The stagger: each course of boards starts at a different offset, so the joints do not line + * up into one continuous seam. Four metres is a sixteen-foot board with a bit off the end. */ + var ju = (u + hash2(course, sd, 0x4B7) * 3.7) / 4.1; + var fju = ju - Math.floor(ju); + if (fju < 0.045 && hash2(Math.floor(ju), course, sd ^ 0x7C1) < dFill) + return fset(G_PIPE, shdHue, (26 + 74 * sun * sun) * gr); + var stud = u / 0.61, fst = stud - Math.floor(stud); + if (fst < 0.10 && fbv > 0.30 && fbv < 0.52 && + hash2(Math.floor(stud), course, sd ^ 0x2B9) < 0.44 * dFill) + return fset(G_COLON, P.timber, (22 + 62 * sun) * gr); + } + if (sun >= 0.62) { var body = hash2(Math.floor(u * 2.4), Math.floor(v * 2.4), sd ^ 0x66); - if (fbv <= 0.30) - return fset(wob < 0.22 ? G_UNDER : G_DASH, sunHue, (176 + wob * 68) * gr); + /* THE LAP LINE INVERTS ACROSS THE DAY, and it has to. At a grazing sun the lower edge of each + * board is the part of the wall pointing most nearly at the light, so it is the BRIGHT line + * and the wall behind it is dark — which is what the 176-244 below draws and why a dusk + * clapboard reads. With the sun overhead the same edge is the part in its own shadow, so the + * line is DARK on a bright wall. Blended rather than switched, because a whole wall's rhythm + * inverting at one instant of the clock is a large-area step. */ + if (fbv <= 0.30) { + var lapN = 176 + wob * 68; + var lapD = 42 + 96 * sun * sun + wob * 30; + return fset(wob < 0.22 ? G_UNDER : G_DASH, + dFill > 0.5 ? shdHue : sunHue, (lapN + (lapD - lapN) * dFill) * gr); + } if (body < 0.62) - return fset(body < 0.20 ? G_DASH : (body < 0.44 ? G_UNDER : G_TICK), sunHue, - (124 + body * 74) * gr); - return fset(0, P.shadow, 0); + return fset(dayMat ? ink(0.34 + 0.72 * sun * sun + 0.28 * (body / 0.62 - 0.5)) + : (body < 0.20 ? G_DASH : (body < 0.44 ? G_UNDER : G_TICK)), sunHue, + ((124 + body * 74) + + ((58 + 46 * dSky + 168 * sun * sun + body * 40) - 124 - body * 74) * dFill) * gr); + return fillCell(u, v, sd, gr, sun, sunHue, lod); } if (fbv > 0.30) { /* Between the lines, on the shadow side. A very few specks — nail heads and knots — because * a perfectly empty field between two perfect lines reads as a stencil. */ if (lod === 2 && hash2(Math.floor(u * 2.8), Math.floor(v * 2.8), sd ^ 0x66) < 0.10) - return fset(G_DOT, P.slate, (10 + 46 * sun) * gr); - return fset(0, P.shadow, 0); + return fset(G_DOT, shdHue, (10 + 46 * sun) * gr); + return fillCell(u, v, sd, gr, sun, shdHue, lod); } /* The lap line, in shade. */ - return fset(wob < 0.22 ? G_UNDER : G_DASH, P.slate, (13 + 74 * sun + wob * 22) * gr); + return fset(wob < 0.22 ? G_UNDER : G_DASH, shdHue, + ((13 + 74 * sun + wob * 22) + + ((22 + 88 * sun * sun + wob * 24) - 13 - 74 * sun - wob * 22) * dFill) * gr); + } + + /* ---- THE BLANK BETWEEN THE STRUCTURE LINES, WHICH IS ONLY BLANK AT NIGHT ---------------------- + * board() paints a rhythm and leaves the wall between the lines black, and the two long comments + * around it say why: a full field of dim glyphs lands every one of its cells in the print's muddy + * band, and a two-storey town has a great deal of blank wall in it. That is a NIGHT argument, and + * the README already concedes as much — "by day the census that matters is the hot tail, not the + * muddy one". A wall at noon is a continuous surface with the whole sky on it; drawn as a rhythm + * of lines over black it is a hole with a ladder in it, which is exactly what the frontier + * printed at noon and exactly what the complaint describes. + * + * So every blank site on a WALL goes through here. At dFill 0 it returns the blank it replaced, + * byte for byte, and the night frame is unchanged by construction rather than by measurement. + * + * AND IT MAKES THE FLICKER GATE EASIER, not harder, which is worth writing down because the + * instinct is the other way. The worst per-cell step a walking camera can take is between a + * blank cell and a bright one, and every blank cell of a lit wall was the dark half of one of + * those pairs. Filling the wall replaces a 0-to-200 step with a 150-to-200 one. Measured with + * tools/west-flicker.cjs before and after; the worst step went DOWN. + * + * 0.93 and not 1.00: a wall with no holes in it has no grain, and the few per cent that stay + * black are the gaps, the knots and the boards that have dropped out. */ + function fillCell(u, v, sd, gr, sun, hue, lod) { + if (dFill <= 0.002) return fset(0, P.shadow, 0); + var h = hash2(Math.floor(u * 3.7), Math.floor(v * 3.7), sd ^ 0xC13); + var cov = 0.93 * dFill; + if (h > cov) return fset(0, P.shadow, 0); + var q = h / cov; // renormalised over the painted cells + /* THE SQUARE ON `sun` IS THE THREE STOPS. A wall in sun and the same wall in its own porch + * shade are about three stops apart at noon, and a linear ramp put them inside one of each + * other — the "one field of mid-tone" failure sunOf()'s ambient floor spends a paragraph on. + * Squared, the porch (sun*0.42) comes out at a fifth of the front, which is right. */ + /* Tone drives BOTH the ramp and the lum, and the spread is what keeps the wall from being one + * glyph repeated: +-0.15 of the ramp is about three steps, which reads as grain in the boards. + * + * THE 46*dSky IS THE HEMISPHERE AND IT IS NOT OPTIONAL. Everything else here is proportional to + * the SUN, and a wall that only has the sun in it is a wall in a vacuum: at noon the ground + * floors under the verandas came out at a mean printed lum of 93 in timber, whose day ceiling + * is 120, so the whole band under the awnings was 54 on a 255 scale — a black stripe across the + * middle of a midday street. What fills a porch is the sky, which is why this term keys on + * dSky and not on dSun, and why it is a FLOOR added rather than a factor: it is light that + * arrives whether or not this face can see the sun. */ + return fset(ink(0.34 + 0.72 * sun * sun + 0.30 * (q - 0.5)), + hue, (34 + 46 * dSky + 178 * sun * sun + 40 * q) * gr); } /* ---- ground ---------------------------------------------------------------------------------- @@ -592,6 +1043,14 @@ /* The deck itself. Planed board takes the low sun better than dirt does, so the walk on * the sunward side is one of the brightest surfaces in the frame and the one opposite is * nearly black — the two sides of a main street at dusk do not match and should not. */ + /* THE DECK BY DAY. A plank walk at noon is a continuous pale board surface with the joints + * dark in it, and it is the one large horizontal the eye uses to read the street's edge — + * so it takes the ramp and it takes `sand`, which is planed board with dust on it. At night + * this is `_` in white on the sunward side and mostly nothing opposite, unchanged. */ + if (dFill > 0.002 && hash2(Math.floor(wz * 4.1), (al * 3) | 0, 0x2F7) < 0.94 * dFill) + return rset(ink((sunSide ? 0.60 : 0.36) + 0.26 * (pw - 0.5)), + sunSide ? P.sand : P.timber, + (sunSide ? 150 : 78) + pw * 52); if (sunSide) return rset(G_UNDER, P.white, (62 + pw * 40)); return (pw < 0.30) ? rset(G_UNDER, P.slate, 12 + pw * 20) : rset(0, P.shadow, 0); } @@ -600,7 +1059,13 @@ if (al >= half + BOARDWALK) { if (lod === 0) return rset(0, P.shadow, 0); var og = hash2(Math.floor(wx * 1.6), Math.floor(wz * 1.6), 0x2D9); - if (og > 0.14) return rset(0, P.shadow, 0); + /* Dirt in the shade of the buildings. By day it fills — it is the same ground as the road, + * two stops down because it never sees the sun — and by night it stays the fourteen per cent + * scatter it was. */ + var od = 0.14 + (0.82 - 0.14) * dFill; + if (og > od) return rset(0, P.shadow, 0); + if (dFill > 0.002 && og < od * dFill) + return rset(ink(0.30 + 0.24 * (og / od - 0.5)), P.timber, 46 + og * 90); return rset(og < 0.05 ? G_COMMA : G_DOT, P.slate, 10 + og * 60); } @@ -649,10 +1114,22 @@ var rs = hash2(Math.floor(wx * (lod === 2 ? (dist < 9 ? 6.2 : 3.0) : 1.7)), Math.floor(wz * (lod === 2 ? (dist < 9 ? 6.2 : 3.0) : 1.7)), 0x18F); var rd = (0.34 + 0.42 * rut) * (lod === 2 ? 1 : 0.8); - if (rs < rd) - return rset(rs < 0.14 ? G_UNDER : (rs < 0.34 ? G_COMMA : G_DOT), - sunSide ? P.white : P.slate, - (26 + rs * 150) * rut * (sunSide ? 1.15 : 0.72)); + rd += (0.96 - rd) * dFill; // a wheel track at noon is churned dust, not grit + if (rs < rd) { + /* THE RUTS ARE THE ROAD'S ONLY LONG STRAIGHT LINES and by day they have to stay legible as + * lines while the ground either side of them fills in — which means they cannot simply get + * brighter with everything else. So they keep the paler-than-the-road relationship the + * comment above argues for, and take it in INK rather than in lum: two bands of churned + * dust at a heavier ramp step than the packed crown beside them. */ + var rk = rs / rd; + var rn = (26 + rs * 150) * rut * (sunSide ? 1.15 : 0.72); + var rdy = (108 + rk * 104) * (0.55 + 0.45 * rut) * (sunSide ? 1.10 : 0.80); + return rset(dFill > 0.002 && hash2(Math.floor(wx * 2.7), Math.floor(wz * 2.7), 0x3C8) < dFill + ? ink((sunSide ? 0.66 : 0.50) + 0.26 * (rk - 0.5)) + : (rs < 0.14 ? G_UNDER : (rs < 0.34 ? G_COMMA : G_DOT)), + sunSide ? (dFill > 0.5 ? P.sand : P.white) : (dFill > 0.5 ? P.timber : P.slate), + rn + (rdy - rn) * dFill); + } /* The stones the wheels turn up sit in the track, not beside it. */ if (lod === 2 && dist > 8 && rs > 0.988) return rset(G_o, P.slate, 30 + (1 - rs) * 3200); return rset(0, P.shadow, 0); @@ -679,10 +1156,32 @@ * lum term below keeps going. */ var lightK = clamp(0.18 + 0.62 * dSky + 0.26 * dSun, 0, 1.0); var sideBias = sunSide ? (1 + 0.25 * sideK) : (1 - 0.28 * sideK); - var dens = (0.42 - 0.20 * n * n) * sideBias * lightK * - (lod === 2 ? 1 : (lod === 1 ? 0.82 : 0.6)); - /* More dust in the air means more dust on the ground; a squall packs it down. */ - dens *= (0.82 + 0.5 * wDust) * (1 - 0.45 * clamp(wet - 0.3, 0, 1)); + var lodQ = lod === 2 ? 1 : (lod === 1 ? 0.82 : 0.6); + /* ---- AND BY DAY THE ROAD IS A SURFACE, not a scatter ----------------------------------------- + * The paragraph above is right about the CAP and wrong about what to do once the cap is + * reached. Measured at seed 42 frame 300 with a probe over the carriageway: at noon this road + * came out 35.7% covered. Sixty-four per cent of the brightest large surface in the world was + * the black the frame is cleared to — which is the complaint, in the one place it is easiest to + * check, because a dirt road at midday is not a dark thing with pale specks on it. + * + * So there are two densities and the day mixes between them. The night one is unchanged and is + * the tuned figure. The day one is 0.94 at the crown falling to 0.72 at the kerb: the road is + * still domed — the shoulders are where the loose stuff and the weeds are and they stay broken + * — but the middle of it is a surface. */ + var dnight = (0.42 - 0.20 * n * n) * sideBias * lightK * lodQ; + /* THE LOD TERM IS NOT THE SAME FACT BY DAY. Thinning the field with distance is a DETAIL + * decision — one lattice cell spans several screen columns out there and the grain stops being + * resolvable — and at night, where density carries the tone, thinning it also correctly makes + * the far road darker. By day it does not: the far half of a road at noon is exactly as + * continuous a surface as the near half and merely less detailed, so the day term only falls to + * 0.82 where the night one falls to 0.60. */ + var dday = (0.94 - 0.22 * n * n) * sideBias * (lod === 2 ? 1 : (lod === 1 ? 0.92 : 0.82)); + var dens = dnight + (dday - dnight) * dFill; + /* More dust in the air means more dust on the ground; a squall packs it down. The packing is + * worth 45% of the field at night and 18% of it by day, for the same reason as the LOD term + * above: wet ground at noon is a DARKER continuous surface, not a sparser one. Left at 45% the + * schedule's ordinary damp put 27% of the carriageway back to black in the middle of the day. */ + dens *= (0.82 + 0.5 * wDust) * (1 - (0.45 - 0.27 * dFill) * clamp(wet - 0.3, 0, 1)); /* THE LATTICE PITCH IS A FUNCTION OF THE DISTANCE BAND, and this is the same lesson the city's * floor learned one file over. A world hash at a fixed pitch is stable — which is the point — @@ -701,14 +1200,66 @@ * Dividing through by `dens` decouples them: the road still thins toward its edges and the * grains that remain keep the full tonal range. */ var k1 = d1 / dens; + /* THE DESERT'S OWN SWATCH BY DAY. `white` is 216,226,236, a cool render-grey: right for a + * plank walk catching a low sun, wrong for a dirt road at noon, which is 216,186,132 and is + * the exact thing `sand` was put in the palette to spell. Its day gain of 0.90 also makes it + * the only swatch that can carry a large bright ground plane without going to white — white's + * own 0.92 puts the road level with the render on the wall beside it, which is the fault + * core.js's sand entry documents from the other end. Dithered on its own hash so the road + * crosses over grain by grain rather than as one plane changing colour at an instant. */ + var sc = hash2(Math.floor(wx * q * 1.7), Math.floor(wz * q * 1.7), 0x1C5); /* WHITE ON BOTH SIDES ONCE THE SUN IS UP. The slate/white split is a dusk fact — one side of * the road in the light and one in the shade of the buildings — and at noon there is no shade * to be on the far side of. */ var dayGround = dSun > 0.55; - return rset(k1 < 0.3 ? G_DOT : (k1 < 0.62 ? G_COMMA : G_TICK), - hot ? P.amber : ((sunSide || dayGround) ? P.white : P.slate), - (hot ? 132 : 22 + k1 * 128) * (sunSide ? 1 : 0.78) * - (0.6 + 0.7 * lightK + 0.9 * dSun)); + /* THE LUM FLOOR HAS TO COME UP WITH THE COVERAGE OR THE EXTRA CELLS ARE ALL MUD. The cells + * the day density adds are the low-k1 ones — the faintest grains — and at the night ladder's + * 22 + k1*128 they arrive in the 40s, which is the middle of the muddy band and is precisely + * the "more cells at the same mid value" failure the cap above was defending against. Lifting + * the base to 88 puts the whole day field over the band's ceiling once the exposure + * multiplier is on it, so the extra coverage buys surface rather than mush. */ + var gn = (hot ? 132 : 22 + k1 * 128); + var gd = (hot ? 176 : 88 + k1 * 96); + /* The road takes the ink ramp on the same crossover as the swatch, and it needs it more than + * the walls do: '.' ',' and '`' are the three THINNEST entries in the table at 3.0, 6.2 and + * 2.6 per cent, which is exactly right for grit scattered on a dark road and is a third of a + * per cent of area for a bright one. A dirt road at noon is packed dust, not grit. Held under + * the walls' end of the ramp on purpose — ground that out-inks the buildings standing on it + * inverts the picture. */ + var gsc = sunSide ? 0.62 : 0.44; + /* ---- AND THE LIGHT TERM IS COUNTED ONCE, WHICH IT WAS NOT --------------------------------- + * `0.6 + 0.7 * lightK + 0.9 * dSun` is how much light there is, and it is the night ladder's: + * 0.73 at midnight, which is what `gn` was fitted under. At noon it is 2.20 — and `gd` above + * is already a DAYLIGHT level, written to print near sand's own ceiling. Multiplying the two + * put the carriageway at lum 194-405, i.e. clipped, and sand goes over the print's highlight + * line at lum 201. Measured at seed 42 frame 300, 200x60: 1390 of the frame's 1633 hot cells + * were the floor, the hot tail was 13.6% against the census's 3.5-5% target and the README's + * published 5.6% for this world and hour, and the consequence is the one the eye actually + * sees — the road, the sunlit walls and the sky all printing at the top of the ladder, so the + * street has no tonal hierarchy left. A road is DARKER than the sky above it at every hour + * there has ever been. + * + * So the light term blends to a day value of its own on the fill, exactly as every other + * scale in this file does, and is the identity at dFill 0. 1.40 is chosen off the ORDERING + * and confirmed by the census. Mean printed value by kind at seed 42 frame 300 noon: + * 2.20 sky 135.8 floor 153.4 facade 84.6 hot 13.61% + * 1.40 sky 135.5 floor 134.0 facade 84.5 hot 5.65% + * 1.15 sky 135.5 floor 121.1 facade 84.8 hot 3.04% + * At 2.20 the ground is brighter than the sky it is lit BY, which is the inversion. 1.40 is + * the value that puts the road just under the dome and leaves it the second-brightest plane + * in the frame, where a sunlit road belongs, and it lands on the 5.6% the README already + * publishes for this world and hour. 1.15 keeps the ordering but drops the tail under the + * census's own 3.5% floor and takes the road's whole highlight with it. Morning comes out at + * 5.54% and afternoon at 4.28% off the same number, both inside the band, because the fill + * carries them. */ + var lightMul = 0.6 + 0.7 * lightK + 0.9 * dSun; + lightMul += (1.40 - lightMul) * dFill; + return rset(sc < dFill * 0.86 + ? ink(gsc + 0.30 * (k1 - 0.5) + 0.16 * dSun) + : (k1 < 0.3 ? G_DOT : (k1 < 0.62 ? G_COMMA : G_TICK)), + hot ? P.amber + : (sc < dFill * 0.86 ? P.sand : ((sunSide || dayGround) ? P.white : P.slate)), + (gn + (gd - gn) * dFill) * (sunSide ? 1 : 0.78) * lightMul); } /* A stone, a dry weed, a hoofprint. Rare, and the only things on the road with an edge. */ if (lod === 2) { @@ -785,7 +1336,15 @@ /* Dust and cloud both eat the sky. Dust raises the floor of the whole dome (more scatter, so * more light everywhere and less contrast); cloud takes the top off. */ var lift = 0.90 + 0.50 * wDust; - var cap = 1 - 0.52 * wCloud; + /* CLOUD TAKES THE TOP OFF AT NIGHT AND DOES NOT BY DAY, and the two are the same physical fact + * read at two light levels. At night the deck is a lid: there is nothing above it, so covering + * the sky removes the sky. At noon the deck is LIT FROM ABOVE — an overcast midday sky is the + * brightest large surface in any frame that contains one, and it is the whole hemisphere rather + * than a hole in it. Measured: the schedule had wCloud at 1.00 at seed 42 frame 300, so `cap` + * was 0.48 and it was halving every term below at noon; the sky came out 47.9% covered with a + * mean lum of 112, i.e. half a sky. 0.80 of the cut removed leaves cloud still costing about a + * tenth by day, which is the difference between an overcast noon and a clear one. */ + var cap = 1 - 0.52 * wCloud * (1 - 0.80 * dFill); /* ---- THE HOUR, and it is the largest term in this function ---------------------------------- * Everything below was written at a fixed dusk and reads as one: an exponential falling away @@ -836,7 +1395,17 @@ /* Coverage climbs steeply with the field: the burn is a BAND, dense enough to be a mass, and * the upper dome is a scatter. A uniform dither over both gives a sky with a colour ramp and no * structure, which reads as a gradient rather than as weather. */ - if (hs < 0.05 + 1.18 * e) { + /* ---- AND THE DOME FILLS ---------------------------------------------------------------------- + * The dither is the sky's structure at dusk: the burn is a mass, the upper dome is a scatter, + * and the black between the cells is the night the frame is going into. At noon there is no + * black between the cells — a daylight sky is a continuous surface and the largest single + * object in a frontier frame — so the coverage goes to 0.96, and what carries the tone is the + * four-tier ladder below rather than how much of the dome got painted. 0.96 and not 1.00: the + * few per cent that stay open are what stop the dome reading as a flat card, and they are where + * stars.js and west_sky.js's own passes have somewhere to land. */ + var covr = 0.05 + 1.18 * e; + covr += (0.96 - covr) * dFill; + if (hs < covr) { /* Four swatches off one field. The thresholds are where they are because of core.js's * EXPOSURE ladder rather than because of the sky: amber (0.50) and ember (0.42) can carry a * bright band, slate (0.60) is the workhorse of the middle, and azure (1.00) is the highest @@ -877,8 +1446,27 @@ if (e > 0.13) return sset(G_TICK, P.slate, 138 * (0.52 + 0.78 * e) * (0.78 + 0.38 * hs2)); return sset(G_DOT, P.azure, (16 + 46 * e) * (0.7 + 0.6 * hs2)); } - if (e > 0.80) return sset(G_EQ, P.white, 214 * (0.80 + 0.24 * e) * (0.88 + 0.18 * hs2)); - if (e > 0.62) return sset(G_DASH, P.white, 176 * (0.72 + 0.32 * e) * (0.86 + 0.22 * hs2)); + /* ---- AND THE PALE BAND IS NOT PAPER --------------------------------------------------- + * The two white tiers were written at 214 and 176 and print at 186-236 and 139-185, and + * white's hot line is lum 184 — so nearly all of the first tier and the top of the second sit + * above the census's highlight line. On a frame with a lot of visible dome that is the other + * half of the hot tail the road was carrying: measured at seed 7 frame 900 noon, 684 of 1450 + * hot cells were sky, and under `dust` — where `lift` puts the horizon into the top tier + * outright — 885 of 1383. + * + * A midday sky IS the brightest thing in a frontier frame and it stays that way; what it + * must not be is CLIPPED, because a clipped band has no gradient in it and the dome stops + * receding upward. 0.80 measured across the day frames: seed 7 12.21% -> 7.45%, seed 42 under + * dust 13.18% -> 7.34%, seed 42 clear 5.66% -> 5.31%, with muddy moving less than half a + * point at any of them. Rejected 0.74, which is another point of tail for a horizon band that + * has started to read as overcast; rejected scaling the two ICE tiers with them, which is the + * blue dome and is nowhere near the line — that version put a point of muddy back on. + * + * On the fill, so night and both twilights are the identity: at dFill 0 this is exactly 1 and + * the sunset ladder above is the one being used anyway. */ + var dayHz = 1 - 0.20 * dFill; + if (e > 0.80) return sset(G_EQ, P.white, dayHz * 214 * (0.80 + 0.24 * e) * (0.88 + 0.18 * hs2)); + if (e > 0.62) return sset(G_DASH, P.white, dayHz * 176 * (0.72 + 0.32 * e) * (0.86 + 0.22 * hs2)); if (e > 0.38) return sset(G_TICK, P.ice, 168 * (0.62 + 0.50 * e) * (0.82 + 0.30 * hs2)); return sset(hs2 > 0.6 ? G_COLON : G_DOT, P.ice, (54 + 150 * e) * (0.78 + 0.36 * hs2)); } @@ -893,10 +1481,40 @@ * the range because the point of a long ramp is its far end. */ var FOG_START_W = 20.0, FOG_END_W = 210.0, FOG_POW_W = 1.25; + /* ---- AND THE RAMP OPENS UP BY DAY, because distance stops meaning darkness --------------------- + * surfaces.js's fog() is honest about what it is: "attenuation toward BLACK, never toward grey — + * there is no atmospheric scatter colour in the references, distant buildings simply stop + * emitting". That is a true statement about a city at night and a false one about a desert at + * noon, where the air between the eye and the far end of the street is the BRIGHTEST thing in the + * frame — a mesa fifteen kilometres out is pale blue-grey, not black. The renderer can only scale + * lum, so the nearest thing to aerial perspective available is to stop taking so much away, and + * that is these two numbers. + * + * `fogPow` 1.25 -> 0.72 is the whole of it. The ramp is k^p with k running 1 at fogStart to 0 at + * fogEnd, so a smaller exponent lifts the MIDDLE of the ramp and leaves both ends pinned: at the + * half-way mark k^1.25 keeps 42% of a cell's lum and k^0.72 keeps 61%, and at three quarters out + * it is 18% against 38%. That band — 60 to 150 m, the far half of a main street and every butte + * behind it — is where a frontier noon frame was still coming out black after the walls, the road + * and the sky had all been filled. + * + * `fogStart` 20 -> 40 m holds the near half of the street at full strength, which is what makes + * the ramp read as DEPTH rather than as an overall dimming. Rejected pushing fogEnd out with them + * (raycast.js marches to whatever this returns, so it is the one of the three that costs time) + * and rejected fogPow 0.5, which flattens the ramp far enough that the far end of the street + * stops receding at all — the depth cue that the slate entry in core.js spends a paragraph on. + * + * GETTERS, for the same reason SUN_AZ became one: surfaces.js re-reads all three in refog(), + * which weatherAt() calls once per frame, so a getter is picked up every frame and a copied value + * would freeze the ramp at whatever the sun was doing when this module loaded. At dFill 0 they + * return the shipped constants exactly. */ CC.SurfWest = { id: 'west', facade: facade, floorTex: floorTex, sky: sky, STYLE: STYLE_W, - fogStart: FOG_START_W, fogEnd: FOG_END_W, fogPow: FOG_POW_W, + fogEnd: FOG_END_W, sunOf: sunOf, BOARDWALK: BOARDWALK }; + Object.defineProperty(CC.SurfWest, 'fogStart', + { get: function () { return FOG_START_W + 20.0 * dFill; } }); + Object.defineProperty(CC.SurfWest, 'fogPow', + { get: function () { return FOG_POW_W - 0.53 * dFill; } }); /* GETTERS, because these three stopped being constants when the sun started moving and five * call sites in three element files read them by name. A getter kept every one of them correct * without an edit; a copied value would have frozen each reader at whatever the sun was doing @@ -905,6 +1523,15 @@ Object.defineProperty(CC.SurfWest, 'SUN_X', { get: function () { return SUN_X; } }); Object.defineProperty(CC.SurfWest, 'SUN_Z', { get: function () { return SUN_Z; } }); Object.defineProperty(CC.SurfWest, 'SUN_ALT', { get: function () { return SUN_ALT; } }); + /* THE DAY FILL, published for the same reason the three above are: this world's element files + * need the same "how much day is in the frame" number the painter uses, and two definitions of it + * is two clocks. west_sky.js and west_town.js read it through here. A GETTER, not a value — + * dayAt() refreshes it once per frame and a copied number freezes at load. */ + Object.defineProperty(CC.SurfWest, 'dayFill', { get: function () { return dFill; } }); + /* And the refresher itself, because an element draws BEFORE the world pass has run in exactly one + * case — an element at a layer under the caster — and a stale dFill there is a frame of the wrong + * hour. Cached on t, so calling it costs one compare. */ + CC.SurfWest.dayAt = dayAt; /* Self-registration: surfaces.js never learns this file's name. */ if (!CC.SURFACES) CC.SURFACES = {}; CC.SURFACES.west = CC.SurfWest; diff --git a/src/surfaces.js b/src/surfaces.js index c4e2fa3..6169b85 100644 --- a/src/surfaces.js +++ b/src/surfaces.js @@ -145,12 +145,46 @@ * dSun direct sun, 0 through the whole of twilight. Only things that need a SHADOW read this. */ var dT = 1 / 0, dSky = 0, dLamp = 1, dSun = 0, dWarm = 0; + /* The sun's bearing, as a unit vector in the project's convention (yaw 0 faces +z). The city + * never needed one — its light comes off the street and every face is the same — and by day + * that stopped being true: a canyon at noon has a lit wall and a shaded wall, and which is + * which is the only modelling a daylight facade gets. Refreshed on the same cache key as the + * rest of the hour, so it costs one sin and one cos per FRAME. */ + var SUNX = 0, SUNZ = 1, SUN_ALT = 0; function dayAt(t) { if (t === dT) return; dT = t; var D = CC.Daylight; if (!D) return; // standalone require: hold the tuned night dSky = D.P.sky; dLamp = D.P.lamp; dSun = D.P.sun; dWarm = D.P.warm; + SUNX = Math.sin(D.P.az); SUNZ = Math.cos(D.P.az); SUN_ALT = D.P.alt; + /* The depth ramp reads the HOUR as well as the weather, and refog() was only ever called from + * weatherAt(). Exactly ONE of refog's outputs is hour-dependent and it is hazeFloor, which + * multiplies D.P.sky; fogPow is a constant and fogStart/fogEnd are the weather's. So this call + * is worth one thing and one thing only: without it the haze floor lags the clock by a frame + * on the frames where the weather did not also change. That is invisible, and it is still + * worth the call, because both cache on `t` — one extra call per frame, never per cell — and + * whichever of the two runs second leaves the pair consistent. Do not delete it on the grounds + * that fogPow is constant: it is, and that is not why this is here. */ + refog(); + } + /* How square-on to the sun this wall is, 0 (facing away) .. 1 (facing it). The frontier's + * sunOf() is the model and this is the cheap half of it: no ambient floor, no sqrt, because + * this number only ever picks a SWATCH here — the lums are the day lift's own. + * + * The split collapses toward noon exactly as surf_west's does and for the same reason: at 54 + * degrees up the light arrives from above, so both walls of a street catch it and the + * difference between them is small. Without that term a noon canyon has one wall in full sun + * and one in near-shade, which is a low-sun picture drawn at the wrong hour. + * + * A cell with no face (the standalone harness, a probe) returns 0.5, i.e. neither — which is + * what the city looked like before there was a sun in it at all. */ + function sunFace(cell) { + if (!cell || cell.faceX === undefined) return 0.5; + /* The face crossed by a ray stepping +side has its outward normal pointing -side. */ + var d = cell.faceX ? -cell.side * SUNX : -cell.side * SUNZ; + var split = 1 - 0.62 * clamp(SUN_ALT / 0.95, 0, 1); + return clamp(0.5 + 0.70 * d * split, 0, 1); } var wT = 1 / 0, wWet = 1, wRain = 1, wWind = 1, wFogP = 0.30; @@ -249,6 +283,151 @@ * night look is the tuned baseline and a daylight cycle may not move it by a cell. */ var FOUT = { ch: 0, col: 0, lum: 0 }; var fU = 0, fV = 0, fSd = 0; + /* ---- WHAT THE DAY LIFT IS LIFTING, and it used to be one thing ------------------------------ + * The lift moved every unlit cell onto P.white as the sky came up, and it is why a noon city + * had no colour in it: measured at seed 42 frame 300, 200x60, noon, white took 73.0% of ALL the + * frame's energy and 82.2% of its LIT energy — one swatch, over three quarters of the picture. + * That is not a grey concrete canyon, it is a monochrome. + * + * Three facts about a daylight facade were being collapsed into one swatch, and each of them + * now carries its own: + * fGrain THE WALL ITSELF — the coverage dither that fills the blank cells between the + * painted detail. That is the concrete, and concrete is `stone`: the swatch slate + * refuses to be. It is also the one place stone can be spent for nothing, see below + * fMat 1 GLASS — the dead bays and the unlit panes. At noon a glazed wall is DARKER than the + * concrete round it and it is blue, which is `indigo` (day ceiling 104) and is the + * whole of the README's "a grey concrete canyon with dark glass in it" + * fSun WHICH WALL — as a GAIN and never as a swatch. A face square to the sun is a stop + * and a half brighter than one in shade; it is not made of a different material, and + * the version of this file that said it was is what finding 2 of the review is about + * All three are the identity at dSky 0, which is the rule the whole feature is built on. */ + var fMat = 0, fSun = 0.5, fUp = 0, fGrain = 0, dayG = 1; + /* ---- UP-FACING CELLS, AND THEY ARE WHERE A SHADED CANYON GETS ITS HIGHLIGHTS ---------------- + * fSun answers "how square to the sun is this WALL", which is the right question for the ninety + * per cent of a facade that is vertical and the wrong one for the coping on top of a parapet and + * the weathering of a belt course. Those are horizontal slabs, and a horizontal slab at local + * noon takes the sun whichever way the building faces. + * + * It matters because a roofline is the silhouette the whole picture is composed around, and a + * coping drawn at the wall's own bearing goes out at exactly the hour there is most light. + * Measured at seed 42 frame 300 noon — a canyon whose two walls both happen to face away from + * the sun — a coping on fSun prints v 96 against v 209 on upFace(), which is the difference + * between a roofline and a smudge. It is worth saying what this is NOT worth, because the + * version of this comment that shipped claimed it: sweeping the edge tier's gain 0.7 -> 1.3 + * over twelve noon seed/frame pairs moved the frame's hot tail 1.93% -> 2.14%, i.e. the copings + * and belt courses are too few to be a census term. They are a composition term. + * + * The blend is 35% of the wall's own bearing and 65% of the sun's ALTITUDE, so a coping is + * nearly fully lit at noon, tracks the walls at a low sun (when a horizontal surface really does + * get very little), and is 0 at night like everything else here. */ + function upFace() { + var alt = clamp(SUN_ALT / 0.95, 0, 1); + return fSun * 0.35 + 0.65 * (0.45 + 0.55 * alt); + } + /* Which swatch this cell takes at full daylight, and the gain that holds its PRINT where white's + * was. The gains are not decoration: stone's day ceiling is 145 and indigo's 104 against white's + * 209, so writing the same lum through them would hand the noon city a stop and a half of + * darkness that nobody asked for. Measured on the day ladder (mix 1, sun 1, near bucket): + * white lum 120 prints v 138; stone needs lum 186 for v 119 and CANNOT reach 138 at any lum, + * which is right — a concrete wall is not as bright as the sky above it, and that gap is the + * modelling the old single-swatch lift had none of. + * + * ---- WHICH SWATCHES ARE ALLOWED TO BE A HIGHLIGHT AT ALL, and this governs the whole file ---- + * tools/metrics.py classifies a cell by what it ACTUALLY prints, `max(r,g,b) * lum/255`. So a + * swatch's PIGMENT is a hard ceiling on the census that no exposure, gain or lum can lift: + * stone 170 timber 150 jade 148 indigo 142 slate 138 moss 126 shadow 66 + * against the hot line at 170. stone touches it exactly and only at printed lum 255, which the + * day ladder never reaches (it tops out at 217 in the near bucket), so a stone cell prints v 145 + * at best and is NEVER hot. The swatches that can carry a daylight highlight are white (236 → + * 209), sand (216 → 190), ice, pure and red — and that is the whole list. + * + * The consequence, and it is finding 2 of the review: the version of this function that shipped + * used stone as its SHADE tier, so a camera facing two shaded walls had no highlight anywhere in + * the frame by construction. Measured over twelve seed/frame pairs at noon, 200x60, against the + * pre-pass tree: hot 2.59% -> 2.11%, worse on nine of twelve, and on seed 99 frame 1800 — where + * the facade came out 4564 cells of stone and not one white cell — 3.18% -> 0.57%. + * + * What replaces it is the distinction the old code was missing. The SWATCH is the material and + * the SUN is the gain: stone moves onto the GRAIN, which is where a wall's concrete actually is, + * and the painted mass keeps a material that can be a highlight on BOTH sides of the street. + * Stone costs nothing there, and that is arithmetic rather than luck: a grain cell's lum tops + * out at 108 before the gain, so it could not reach the hot line on white either. Measured, same + * twelve pairs: hot 2.11% -> 3.97% (core.js's band is 3.5-5, and the pre-pass tree was 2.59%), + * muddy 65.5% -> 58.0% against the pre-pass 58.4%, and stone still takes 50-69% of the frame's + * lit energy against white's 14-31 — so the colour was not paid back to buy the census. */ + function dayMat(dK) { + /* ---- TWILIGHT, WHICH IS A THIRD MATERIAL AND NOT A HALF-LIT DAY ------------------------ + * Under the handover the cell used to stay on P.slate, and the consequence was measurable: at + * the dusk stop, seed 42 frame 1800, slate took 35.4% of ALL the frame's energy — one blue- + * grey swatch over a third of the picture at the one hour the file elsewhere calls the city's + * best. That is the far field being "uniformly slate", which is precisely what `indigo` was + * added to the palette to stop. + * + * The swap is free. core.js fits indigo's night ceiling at 115 against slate's 114 ON PURPOSE + * — "two readings of the same cold structure ... so a wall that changes from one to the other + * across a shadow edge changes HUE and not brightness" — so this moves no lums, no census + * band and no pillar. What it moves is that dusk shade now has a sky in it. + * + * dK > 0.06 is dSky > 0.245, i.e. the second half of civil twilight. Below that there is not + * enough sky for shade to have a colour and the swatch stays slate, which keeps the first + * minutes either side of night continuous with the night itself. */ + if (dK < 0.50) { dayG = 1; return dK > 0.06 ? P.indigo : P.slate; } + /* THE COSINE, AND IT IS NOW THE WHOLE OF THE SHADING. A wall square to the sun is a stop and a + * half brighter than one edge-on to it, and that is a difference in LIGHT, not in material — + * which is why the sunlit/shaded STEP that used to sit under this line is gone. The step was + * what made a frame's hot tail a coin toss: every wall in view lands on one side of one + * threshold, so seed 555 frame 1800 (all sunlit) printed 7.6% hot while seed 99 frame 1800 + * (all shaded) printed 0.57%, against a band of 3.5-5. A continuous ramp cannot do that. + * + * 0.85 + 1.10*sn, i.e. 1.10..1.70 across fSun's noon swing of 0.23..0.77 and 0.85..1.95 across + * a low sun's full swing — the same 1.55x between the two sides of a street the old + * 0.62 + 0.76*sn had, carrying the 1.4x that the retired tier multipliers (1.26 sunlit, 1.95 + * shaded) used to supply. Swept over twelve noon seed/frame pairs, hot / muddy: + * 0.78 + 1.05 3.43 / 60.3 0.80 + 1.10 3.72 / 59.3 + * 0.85 + 1.10 3.97 / 58.0 0.95 + 0.95 4.12 / 57.2 but the two sides converge + * 0.85 + 1.10 is the pair that is best on both numbers at once; past it the ramp flattens and + * the street stops having a lit side, which is the fault this term exists to prevent. */ + var sn = fUp ? upFace() : fSun; + var s = 0.85 + 1.10 * sn; + /* Glass. Darker than the concrete round it at every hour of the day, and blue, because what a + * dead pane is showing you is the sky. A sunlit pane is not brighter GLASS, it is the same + * glass with a sky reflection in it, which is why it rides `s` and never changes swatch. + * 0.90 and not the 1.25 it carried before, because `s` itself went up by 1.4x and indigo's day + * ceiling is 104: at 1.25 the whole glazed wall clipped to a flat 104 and the dead bays lost + * the modelling that makes them read as glass. 0.90 * 1.40 reproduces the old 1.25 at mid + * swing to within a printed unit. */ + if (fMat === 1) { dayG = 0.90 * s; return P.indigo; } + /* THE GRAIN — the coverage dither that fills a daylight wall between its painted detail, and + * the largest single population in the frame. This is the concrete itself, so it is `stone`, + * and stone is free HERE in a way it is not anywhere else: the dither writes lum 26-108 before + * the gain, and 108 cannot reach the hot line through white (which needs 176) let alone + * through stone. Putting the frame's grey mass where it cannot cost a highlight is the whole + * trick, and it is what lets the mass below stay on a swatch that can be one. + * + * 1.95, kept from the shaded tier it replaces but now riding the bigger `s`, so the grain runs + * 2.15..3.32 and about two cells in five clip at stone's 145. Swept, muddy over the twelve + * pairs: 1.30 -> 65.5, 1.60 -> 62.5, 1.95 -> 58.0, 2.30 -> 54.6. The hot tail does not move at + * any of them (3.94-4.04), which is the point above restated as a measurement. 2.30 reads + * better on the census and worse on the wall — it clips more than half the grain to one value + * and the concrete goes flat — so 1.95, which lands muddy on the pre-pass tree's own 58.4%. */ + if (fGrain) { dayG = 1.95 * s; return P.stone; } + /* THE PAINTED MASS — spandrel, mullion, parapet, coping, belt course. It takes the BUILDING'S + * material, one roll, both sides of the street, because a wall in shade is not made of + * something else. Two in eight take `sand`: warm render, stock brick, travertine, the things a + * real street is faced in that are not grey concrete. Its day ceiling is 190 against white's + * 209, so this is a HUE change and not much of a brightness one, and the roll is on the + * BUILDING SEED rather than on the cell, so a facade is one material from top to bottom. + * The bit test is deliberate rather than lazy: fSd is already the output of a hash, so its low + * bits are as uniform as another hash2 would be, and this runs once per painted cell. + * + * Two and not three. At three in eight the twelve-pair hot mean is 3.29% against 3.97%, + * because sand's ceiling is 19 printed units under white's and a frame that happens to face a + * sand building loses most of its highlight budget — seed 99 frame 1800 is exactly that frame + * and it went to 0.57% under the shipped roll. Two keeps the hue and stops it deciding the + * census. */ + dayG = s; + return (fSd & 7) < 2 ? P.sand : P.white; + } function fset(ch, col, lum) { if (dSky > 0.02) { /* SQUARED, and it is the same argument the print ladder makes one file over: a wall does @@ -261,14 +440,56 @@ var dK = dSky * dSky; if (ch === 0 || lum <= 0) { var hb = hash2(Math.floor(fU * 2.6), Math.floor(fV * 2.6), (fSd ^ 0x7D13) | 0); - if (hb < 0.14 + 0.50 * dK) { + /* HOW SOLID A DAYLIT WALL IS, and it is the only thing that decides how much continuous + * surface the frame gets. At 0.64 coverage the noon city was 32.7% pure black, which is a + * night budget being spent at midday, and the black was scattered through the wall as + * holes rather than massed as shadow. At 0.86 the wall is solid where it is lit and the + * frame's black goes back to being the dark blocks, the glazing and the sky slot, which + * are the things that are meant to carry it. + * + * WHAT IT COSTS, because the version that shipped stated only the half that it bought and + * finding 4 of the review is exactly that omission: coverage is a trade of black for the + * MUDDY band and nothing else. Measured over twelve noon seed/frame pairs, 200x60, gate + * 0.50 -> 0.72: black 27.8% -> 19.4% and muddy 55.5% -> 58.1%, with the hot tail unmoved + * (4.02 -> 4.15). Eight points of black for two and a half of muddy is the trade, it is + * taken deliberately, and by day the hot tail is the census core.js says to watch. + * + * AND DUSK DOES NOT PAY FOR IT. The shipped form was 0.14 + 0.72*dK, which is a linear + * ramp through a quadratic dK, so twilight got a coverage it was never tuned for: the dusk + * stop ran 58.0% muddy against 54.2% for the pre-pass tree, and nobody was tuning dusk. + * The cubic term is zero everywhere but the top of the day — 0.14 + 0.50*dK is the shipped + * curve exactly, and 0.22*dK^3 adds the solidity only where it was argued for. At noon + * dK is 1 and this is the same 0.86 as before, to the digit. Measured, muddy: dusk 58.0 + * -> 55.6, dawn 55.4 -> 53.1, morning 58.4 -> 57.6, noon 58.08 -> 58.08. + * The night is untouched: dK is 0 and the branch is not entered. */ + if (hb < 0.14 + 0.50 * dK + 0.22 * dK * dK * dK) { ch = hb < 0.34 ? G_DASH : (hb < 0.62 ? G_COLON : G_QUOTE); - col = dK > 0.55 ? P.white : P.slate; lum = (26 + hb * 96) * dK; + /* The gain rides in with the swatch and not before it: under the handover dayMat() + * returns the twilight tier at dayG 1, i.e. the shipped lum, which is what keeps the + * transition continuous. + * fGrain is the ONE flag dayMat cannot infer for itself — everything else it reads + * (fMat, fSun, fUp, fSd) is set by the painter, and which fset branch called it is not. + * Cleared on the way out rather than at the top of fset so that a painter which returns + * early through some other branch cannot leave it set for the next cell. */ + fGrain = 1; col = dayMat(dK); lum *= dayG; fGrain = 0; } } else if (col === P.shadow) { - col = dK > 0.48 ? P.white : P.slate; lum = lum * (1 + 2.6 * dK) + 62 * dK; + col = dayMat(dK); lum *= dayG; + } else if (col === P.slate) { + /* AND THE SLATE TIER, WHICH THE LIFT USED TO WALK STRAIGHT PAST. The coping, the corner + * rib, the belt course, the downpipe and the plant boxes are all written on P.slate at + * lum 9-46 — chosen against a NIGHT curve, where slate is the cold-structure swatch and + * that range prints v 10-63. At noon those are the only hard EDGES a facade has, and + * every one of them was still being drawn at its midnight value while the wall behind it + * lifted by a factor of four: measured at seed 42 noon, a parapet coping printed v 30 + * against v 138 for the spandrel two rows under it, so the roofline — the silhouette the + * whole picture is composed around — went out at exactly the hour there is most light. + * Same swatch rule as the mass beside it, and a slightly harder lift because these are + * proud edges catching more sky than the flat they stand on. */ + lum = lum * (1 + 3.4 * dK) + 66 * dK; + col = dayMat(dK); lum *= dayG; } else if (col === P.warm || col === P.amber || col === P.azure || col === P.ice) { /* KEYED ON THE SUN, NOT ON THE SKY, and the difference is the whole of dusk. A lamp behind * glass loses its advantage over the wall when there is DIRECT light on that wall — not @@ -311,6 +532,14 @@ * one without changing a signature that twenty-five call sites use. Three stores per cell on a * path that already does a dozen. */ fU = u; fV = v; fSd = sd; + /* Which material the day lift is about to be handed, and which way this wall faces. Both are + * per-CELL rather than per-call, so they are set once here and the two dozen fset() call sites + * below only have to move fMat when they are painting glass rather than concrete. Reset to + * structure on every entry: a stale 1 left by the previous cell would paint a parapet as a + * window. sunFace() costs two multiplies and a clamp and is skipped outright at night, where + * there is no sun to face. */ + fMat = 0; fUp = 0; + fSun = dSky > 0.02 ? sunFace(cell) : 0.5; var wu = Math.floor(u / st.pu), wv = Math.floor(v / st.pv); var fu = u / st.pu - wu, fv = v / st.pv - wv; @@ -350,9 +579,14 @@ var bh = cell && typeof cell.h === 'number' ? cell.h : 0; if (bh > 6 && v > bh - 2.35) { var pu2 = Math.floor(u / 1.9); - if (v > bh - 0.42) // coping, jointed every 1.9 m like real precast + if (v > bh - 0.42) { // coping, jointed every 1.9 m like real precast + /* THE ONE UP-FACING SURFACE IN THE WHOLE FACADE, and the one that makes a roofline read. + * A coping is a horizontal precast slab; at noon it takes the sun whatever the wall under + * it is doing. See upFace(). At night this is one store and no change. */ + fUp = 1; return fset((u - pu2 * 1.9) < 0.16 ? G_PIPE : G_EQ, P.slate, 24 + hash2(pu2, 0, sd ^ 0x2A1) * 22); + } if (v > bh - 1.85) { var pg = hash2(pu2, Math.floor(v * 2.2), sd ^ 0x2A2); return pg < 0.32 ? fset(DIMGL[(pg * DIMGL_N * 3.1) | 0], P.shadow, 14 + pg * 34) @@ -401,6 +635,11 @@ } /* Floor band every few storeys — a belt course, the only strong horizontal on the wall. */ if (fv < 0.11 && (wv % st.band) === 0 && hash2(wu, wv, sd ^ 0xB2) < 0.72) { + /* Up-facing too: a belt course oversails the wall, so what the street sees of it is its + * WEATHERING — the top slope that throws the rain clear — and that is a horizontal catching + * the sky. It is also the only strong horizontal a wall has between the ground band and the + * parapet, so it is where a shaded facade gets its second highlight. */ + fUp = 1; return fset(G_EQ, P.slate, 12 + hash2(wu, wv, sd ^ 0xB1) * 16); } @@ -591,6 +830,10 @@ } if (!lit) { + /* EVERYTHING BELOW THIS LINE IS GLAZING, so the day lift is told so once here rather than at + * each of the four returns. At night it changes nothing — fMat is only ever read inside + * fset's `dSky > 0.02` branch. */ + fMat = 1; /* Dead: the glass is gone. One unlit bay in twenty, and it is the state that costs nothing — * a broken window is mostly a hole, so this SUBTRACTS coverage rather than adding it, which * is how a facade pays for the parapet and the pipework above. */ @@ -691,6 +934,45 @@ * spring leans screen — with the quarter's own colour surviving as a minority tenant so the * district still reads as itself. Warm is two slots in every district: someone's counter lamp, * a garnish, never a third pillar. */ + /* ---- AND FOUR NEW QUARTERS, WHICH IS WHY THIS TABLE IS TWENTY ROWS AND NO LONGER MASKED ----- + * city.js's district table now leads on stone, jade, moss and indigo as well as the four this + * roll knew about, and `& 15` did not fail on them — it MISROUTED them, which is worse, because + * nothing throws. rose(16) folded onto row 0, gold(17) onto 1, moss(18) onto 2 and indigo(19) + * onto 3, so an indigo tower quarter was handed the SPRING shopfront parade and the district + * system quietly stopped meaning anything in four quarters out of nine. The mask is gone and + * the table is the palette's own length; a hue past the end still lands on `neutral`, which is + * the contract seedOf/styleOf/litOf keep. + * + * THE NEW ROWS ARE PILLARS ONLY, AND THAT IS NOT TIMIDITY — IT IS THE LADDER. This is the one + * table in the file that decides what COLOUR a light is, and a light that cannot print above the + * hot line is not a light, it is a stain. metrics.py scores a cell as `max(r,g,b) * lum/255`, so + * a swatch's pigment is a hard ceiling nothing downstream can lift: jade 148, moss 126, indigo + * 142, timber 150 — every one of them under the 170 the census calls a highlight, at any lum, on + * any ladder. gold reaches 240 as a pigment but core.js's night ladder caps it at a printed 157, + * which is the same answer. + * + * It was tried the other way, and finding 1 of the review is the bill. Two slots of jade in the + * stone and indigo parades and five plus two of gold in the jade one — 2/16 and 7/16 of the + * largest lit surface in the near frame — cost a district-heavy NIGHT frame this, measured + * against the pre-pass tree at seed 555 frame 600: muddy 30.2 -> 33.5%, hot 2.53 -> 1.08%, lit + * p90 161 -> 151, and azure 33.1 -> 15.5% of the frame's lit energy while jade took 17.2. Over + * twelve night frames the hot mean went 4.36 -> 3.25 and three frames fell out of the 3.5-5 + * band. This is exactly the fault the P.ice paragraph above records, committed again with a + * darker swatch: the band is v < 8 m, it fills most of the near frame, and anything holding a + * tenth of this roll is a PILLAR whether it can carry the job or not. + * + * So the new quarters lean, and do not tint. The lean is real district character and costs the + * census nothing: + * stone structure, and structure is not a light. It takes the neutral parade outright + * jade leans SCREEN — a teal quarter's tubes are cold sources, and azure is the cold source + * this print has. The teal itself survives where it belongs, on the tiled plinth + * course and the pharmacy cross, which are FITTINGS: a handful of cells each, written + * at L_LOW, and sized by the L_LOW table's own note on what jade can and cannot do + * moss leans SODIUM. A market quarter is lit by tungsten under canvas + * indigo leans SCREEN and hardest of the four: a finance tower's ground floor is a lit lobby + * behind dark glass, so this parade is ten slots of azure + * timber and sand are frontier swatches and never lead a city lot; they are listed so that a + * shared record cannot fall through, and both take neutral. */ var SHOP = (function () { var t = [], i; function fill(hue, list) { t[hue] = list; } @@ -700,12 +982,19 @@ fill(P.ember, [P.ember,P.ember,P.ember,P.ember,P.ember, A,A,A,A,A,A,A, Z,Z, W,W]); fill(P.spring, [P.spring,P.spring,P.spring,P.spring,P.spring, Z,Z,Z,Z,Z,Z,Z, A,A, W,W]); var neutral = [A,A,A,A,A,A,A, Z,Z,Z,Z,Z,Z,Z, W,W]; - /* Sixteen rows, not twelve, so the lookup can be indexed with `& 15` and is TOTAL: a cell - * record carrying a hue this file has never heard of gets the neutral parade instead of an - * exception, which is the same contract seedOf/styleOf/litOf keep. */ - for (i = 0; i < 16; i++) if (!t[i]) t[i] = neutral; + fill(P.stone, neutral); + fill(P.jade, [Z,Z,Z,Z,Z,Z,Z,Z,Z,Z, A,A,A,A, W,W]); + fill(P.moss, [A,A,A,A,A,A,A,A,A,A, Z,Z,Z,Z, W,W]); + fill(P.indigo, [Z,Z,Z,Z,Z,Z,Z,Z,Z,Z, A,A,A,A, W,W]); + for (i = 0; i < CC.PALETTE.length; i++) if (!t[i]) t[i] = neutral; return t; })(); + /* The roll is 16 slots wide and the table is the palette's length; a hue index past the end + * gets neutral rather than an exception. Written once here so the two call sites cannot drift. */ + function shopRoll(cell, sd) { + var h = hueOf(cell, sd); + return SHOP[h >= 0 && h < SHOP.length ? h : 0] || SHOP[0]; + } /* ---- STORE TYPES -------------------------------------------------------------------------- * Every open unit used to be the same shop — fascia, awning, sign band, plinth, mullioned @@ -765,9 +1054,35 @@ * slate and shadow are absent from every interior on purpose: their ceilings are v 114 and v 60, * so they CANNOT clear the muddy band at any lum, and the 255s in their slots are unreachable * placeholders that keep these three arrays indexable by palette index rather than sparse. */ - var L_LOW = [103, 52, 135, 133, 154, 165, 71, 255, 124, 110, 47, 255]; - var L_LIT = [157, 79, 206, 206, 239, 254, 109, 255, 190, 169, 72, 255]; - var L_HOT = [240, 120, 255, 255, 255, 255, 165, 255, 255, 255, 109, 255]; + /* ---- AND EIGHT MORE ROWS, IN THE SAME EDIT AS SHOP ABOVE, WHICH IS NOT A STYLE POINT --------- + * These three arrays are indexed by `lite`, and `lite` only ever comes out of SHOP. They were + * SAFE at twelve entries for exactly as long as SHOP could only ever return amber/azure/ember/ + * spring/warm; the moment the row above hands back jade or gold they read `undefined`, every + * lum in the shopfront band goes NaN, and CC.put writes `NaN | 0` — which is 0 — so the entire + * ground floor of the city silently goes black with no error anywhere. Widening SHOP without + * widening these is the one change in this file that fails invisibly. + * + * Re-measured on core.js's live NIGHT curve by the method the paragraph above describes (lum + * swept 0..255, v = max(r,g,b)*printed/255 in the near bucket, first lum reaching the target): + * L_LOW v~128 L_LIT v~150 L_HOT v~175 + * The eight new entries and what they mean for whoever paints with them: + * stone 122, timber 111, moss 94, indigo 115 — CEILINGS UNDER 128, so all three tiers are 255 + * and the swatch saturates at its own ceiling instead. That is not a placeholder, it is the + * honest answer: these four are the SURFACE half of the extension and they physically cannot + * clear the muddy band at night, which is why none of them appears in an interior below. + * They are here so the array is total, exactly as slate and shadow already were + * sand 138, jade 134, rose 131, gold 157 — these four CAN light an interior, and only jade, + * rose and gold are used as one. jade reaches v 128 at lum 215 and 134 at full scale, so a + * tile course or a pharmacy cross written at L_LOW is at the very top of what teal can do + * and cannot glare. rose reaches v 128 only at lum 238 and TOPS OUT AT 131 — it can never + * be hot at any lum, which is what makes "small signage cells only" arithmetic rather than + * a note. gold is the one of the three with real range: L_LOW 146, L_LIT 222 */ + var L_LOW = [103, 52, 135, 133, 154, 165, 71, 255, 124, 110, 47, 255, + 255, 255, 206, 215, 238, 146, 255, 255]; + var L_LIT = [157, 79, 206, 206, 239, 254, 109, 255, 190, 169, 72, 255, + 255, 255, 255, 255, 255, 222, 255, 255]; + var L_HOT = [240, 120, 255, 255, 255, 255, 165, 255, 255, 255, 109, 255, + 255, 255, 255, 255, 255, 255, 255, 255]; var T_NOODLE = 0, T_CONV = 1, T_LAUNDRY = 2, T_BAR = 3, T_ARCADE = 4, T_HARD = 5, T_PHARM = 6, T_BARBER = 7; @@ -945,6 +1260,29 @@ return fset(0, P.shadow, 0); } if (v > 1.06 && v < 1.20) return fset(G_DASH, lite, L_LOW[lite]); // the counter lip + /* ---- THE PINK TUBE, and it is the narrowest thing this file paints ------------------- + * A bent-glass tube in a bar window is the single most genre-defining object in the + * reference, and `rose` is the swatch that exists for it and for nothing else. The licence + * is deliberately tight, so the shape is taken from the licence rather than the other way + * round: + * ONE unit in four that is a bar, and a bar is 12% of the frontage, so this is 3% of the + * parade — about one tube in a frame, occasionally two, which is the rate that reads as + * "there is a bar down there" rather than as a colour scheme + * ONE COURSE tall, at 1.86-2.00 m, i.e. where a window tube actually hangs — above the + * bottles and below the head of the glazing + * CONTINUOUS along the unit, with only the glyph varying. A tube that switched on and off + * cell by cell as the camera walked past it is precisely the thin-bright-feature failure + * the photosensitivity gate exists for, and it is also not what a tube looks like + * THE BRIGHTNESS IS NOT NEGOTIABLE UPWARDS. core.js gives rose the lowest gain in either + * ladder (0.20) with a knee that crushes every rose cell under lum 96 to black, so the tube + * has to be written near full scale to exist at all — L_LOW[rose] is 238 — and it still + * cannot print above v 131. It is arithmetically impossible for it to reach the hot line or + * to take the bloom with it, which is the whole reason the swatch is licensed at all. */ + if (v > 1.86 && v < 2.00 && hash2(su, 71, sd ^ 0x9FB7) < 0.25) { + h = hash2((u * 5.4) | 0, 0, sd ^ 0x9FB9); + return fset(h < 0.34 ? G_UNDER : (h < 0.72 ? G_DASH : G_TILDE), P.rose, + L_LOW[P.rose] * (0.94 + h * 0.10)); + } return fset(0, P.shadow, 0); case T_ARCADE: @@ -1007,8 +1345,20 @@ * so the one white object on the street cannot glare. */ a = xm - 1.27; if (a < 0) a = -a; b = v - (gTop - 0.90); if (b < 0) b = -b; - if ((a < 0.15 && b < 0.52) || (b < 0.15 && a < 0.52)) - return fset(a < 0.15 && b < 0.15 ? G_8 : G_HASH, P.white, L_LIT[P.white]); + if ((a < 0.15 && b < 0.52) || (b < 0.15 && a < 0.52)) { + /* THE CROSS IS GREEN ON HALF OF THEM, and both readings are real: a white cross is the + * international one and a GREEN cross is the pharmacy sign over most of Europe and much + * of Asia, which is the reference this city is drawn from. Rolled per unit so a clinic + * keeps its colour as you walk past it, and split evenly so neither reads as the odd one. + * + * jade is the swatch's own listed job — "the green of a pharmacy cross" — and it is the + * cheapest place in the file to spend it: a cross is about forty cells, it is the only + * object in its own unit, and jade's ceiling of 134 sits under white's 151, so swapping + * one for the other cannot move the frame's highlight balance. L_LIT[jade] is 255 and + * saturates at 134, which is the honest reading of a lit sign in a small ceiling. */ + var pxc = hash2(su, 83, sd ^ 0x9FC7) < 0.50 ? P.jade : P.white; + return fset(a < 0.15 && b < 0.15 ? G_8 : G_HASH, pxc, L_LIT[pxc]); + } /* A QUIET ZONE round the cross, and it is the whole difference between a cross and a * coincidence: drawn straight onto the lit field the arms were the same brightness as the * blocks either side of them and the shape disappeared — looked at, on the flat probe, and @@ -1069,7 +1419,7 @@ * around two-fifths of all facade energy, so whatever colour it is, the FRAME is: a parade * of sodium shopfronts on its own turns a two-pillar city into a yellow one. */ var cr = hash2(su, 3, sd ^ 0x1D7); - var roll = SHOP[hueOf(cell, sd) & 15]; + var roll = shopRoll(cell, sd); var lite = roll[(cr * 16) | 0]; /* The unit's SECOND fitting, drawn from the same district roll on an unrelated hash. One unit * of frontage is 2.55 m, and the camera passes within two metres of a wall: at that range a @@ -1190,6 +1540,54 @@ * sign in the city was sitting a quarter of the way past the hot line while its amber * neighbour was under it. L_HOT lands both at v~175. */ if (v > st.gnd - 1.55) { + /* ---- THE BRASS FRAME, and it is what makes a lit sign look MADE rather than emitted ---- + * Every sign in this band was a floating rectangle of light with no edge and no fixings, + * which is what a sign looks like if you have never seen one switched off. A real fascia + * sign is a box: a channel along the bottom that the tubes sit in, and an upright at each + * end of the unit that carries it. Both are METAL catching the sign's own light, which is + * the entire brief for `gold` — it "peaks in the red and reads as metal being lit rather + * than as something emitting", against amber's sodium discharge peaking in the green. + * + * IT IS A THIN CONTINUOUS FEATURE, so it is drawn as one: the channel is one course of + * cells that is ALWAYS painted for the full width of an open unit, with the texture (the + * glyph and a 12% lum jitter) varying rather than the presence. A frame that appeared and + * disappeared bay by bay as the camera walked is the classic photosensitivity failure this + * project's gates exist to catch, and a bright one-cell horizontal is exactly the feature + * that produces it. Nothing here reads `t`. + * + * THE BUDGET. gold's night ceiling is 157 — twenty-two points under the lower pillar and + * well under the sign band's own L_HOT — so the frame can never out-print the sign it + * frames, which is the ladder the right way round. L_LOW[gold] is 146 and prints v 128, + * just clear of the muddy band's top. Two courses of one cell each per 2.55 m unit is + * about 4% of the band's cells, which is a frame and not a surface. */ + /* THREE UNITS IN FIVE, not all of them, and the rate is a census fix rather than taste. + * At every open unit the frame took 2.2% of the frame's LIT energy and pulled azure from + * 36.7% to 34.4% (seed 42, frame 300, night, 200x60) — outside the +-1.5 the pillar census + * allows, because a continuous course along every shopfront in the city is one of the + * longest lines in the picture and this one was eating sign cells to get there. At 0.62, + * with the uprights narrowed 0.115 -> 0.085, gold lands at 1.3% on that frame and both + * pillars are back inside their band. A frame on some of the signs and not others is also + * simply what a parade looks like: half the boxes are older than the other half. + * + * THE RANGE, and not one frame, because one frame is what the last pass reported and the + * review was right about it. Over twelve night seed/frame pairs gold takes 0.0-12.4% of + * lit energy, median 1.5: it is 1-2% on a street frame and it is 12.4% on seed 17 frame + * 900, which is a rooftop looking down a parade of forty lit shopfronts end-on. That frame + * costs the census almost nothing anyway — hot 2.61% against 2.68% for the pre-pass tree, + * muddy 24.7 against 24.2 — because gold at L_LOW prints v 128, one unit clear of the + * muddy band and nowhere near the hot line, so it displaces energy without moving a band. + * Dropping the rate to 0.40 was measured and NOT taken: it moves that frame's gold 12.4 -> + * 12.3% and its hot tail not at all — whatever that frame is looking at, the rate is not + * the handle on it — while it thins the gilding on an ordinary street frame from 1.3% to + * 0.3%, which is the feature not being there. */ + if (hash2(su, 91, sd ^ 0x519) < 0.62) { + if (v < st.gnd - 1.44) // the channel the tubes sit in + return fset(G_UNDER, P.gold, + L_LOW[P.gold] * (0.94 + hash2((u * 3.6) | 0, 1, sd ^ 0x51A) * 0.14)); + if (fs < 0.085 || fs > 0.915) // the uprights carrying it, one per end + return fset(G_PIPE, P.gold, + L_LOW[P.gold] * (0.90 + hash2(su, (v * 4.2) | 0, sd ^ 0x51B) * 0.16)); + } var sp = u / SIGN_PITCH[ty]; var sg = hash2(sp | 0, su, sd ^ 0x515); if (sg > SIGN_FILL[ty]) return fset(0, P.shadow, 0); @@ -1210,9 +1608,34 @@ * able to reach the top of the lit range or nothing in the picture is a highlight. */ return fset(FILL[((sg / SIGN_FILL[ty]) * FILL_N) | 0], sc, L_HOT[sc] * (1.00 + sg * 0.14)); } - if (v < 0.62) // plinth, in its own shadow + if (v < 0.62) { + /* ---- THE TILED PLINTH --------------------------------------------------------------- + * The stall-riser under a shopfront window — the 600 mm of wall between the pavement and + * the glass. Every one of them was black, and it is the strip nearest the camera in the + * whole picture: at a 1.8 m pavement the walk passes within two metres of it. + * + * A third of open units get a TILE COURSE in it, and the swatch is `jade` because that is + * the swatch's own brief — "tilework, oxidised copper" — and because a glazed tile is the + * one thing at street level that is neither a light nor concrete. It is lit by the shop + * above it, so it is written at L_LOW: jade's night ceiling is 134 and L_LOW[jade] is 215, + * which prints v 128 — the top of what teal can do and physically incapable of glare. + * + * ONE COURSE, NOT A FIELD. The tiles run 0.30-0.48 m, i.e. about a fifth of the plinth's + * height and a single cell at most working distances, with the rest left black in its own + * shadow exactly as before. That is a line of colour along the base of the parade rather + * than a green wall, and it is the same discipline the sign band's brass frame keeps two + * dozen lines up: thin, continuous, low. + * + * Continuous, again on purpose — the joint pattern varies along `u`, the PRESENCE does + * not, so a walking camera never switches it. */ + if (v > 0.30 && v < 0.48 && hash2(su, 59, sd ^ 0x3B7) < 0.34) { + var tl = u / 0.21; tl -= Math.floor(tl); + return fset(tl < 0.30 ? G_PIPE : G_EQ, P.jade, + L_LOW[P.jade] * (0.86 + hash2((u * 4.8) | 0, 0, sd ^ 0x3B8) * 0.20)); + } return hash2(su, Math.floor(v * 6), sd ^ 0x3) < 0.5 ? fset(G_UNDER, P.shadow, 14) : fset(0, P.shadow, 0); + } /* Glazing. Mullion every 0.85 m first, and it is BLACK: it used to be P.slate at lum 9, * which its own comment correctly said prints v 5 — and then called that "a division the eye * reads as an edge ... [that] costs the print nothing". Half of that is right. It costs the @@ -1377,8 +1800,55 @@ /* Set once at the top of floorTex and read back out by every rset() below, so the twenty-odd * early returns in the cascade do not each have to carry the water with them. */ var mirNow = 0, ripNow = 0, wchNow = 0, bounceNow = 0; + /* ---- THE STREET BY DAY, and it is the same repair the facade's fset() carries --------------- + * Everything below writes the carriageway, the kerb face, the pavement slabs, the joints and + * every piece of ironwork on P.slate at lum 6-40. Those numbers were fitted against a NIGHT + * curve where slate is the cold-structure swatch and that range prints v 7-56 — a dark road + * under a sodium lamp, which is correct and is most of what makes the night frame work. + * + * Nothing took them to daylight. Measured at seed 42 noon, 200x60: the floor was 14.6% of the + * frame and the tarmac in it printed v 10-56 at LOCAL NOON, i.e. the road was as dark at midday + * as at midnight while the walls above it lifted by a factor of four. The lower third of a + * daylight frame was a hole. + * + * TWO THINGS CHANGE AND BOTH ARE THE IDENTITY AT dSky 0: + * the SWATCH. slate is deliberately blue — core.js says so at length, and it is right at + * night, where the only thing lighting a road is a discharge lamp and a screen. By day the + * road is lit by the whole hemisphere and it is NEUTRAL, which is `stone`, the swatch slate + * refuses to be. P.shadow, the swatch for occluded structure in a world with no sky in it, + * becomes `indigo`, which is its counterpart for a world that has one + * the LEVEL. Squared on dSky for the same reason fset squares it: a road starts catching + * skylight at first light but does not become the subject of the frame until the sky is + * genuinely bright, and a linear ramp put the tarmac up level with the neon through the + * whole of dusk — the hour the signs are supposed to own + * The lift is DELIBERATELY MEANER THAN THE WALL'S (2.2 against 2.6, and stone's ceiling of 145 + * caps it anyway): asphalt has an albedo around 0.10 against concrete's 0.35, so a road that + * printed level with the wall over it would be the one surface in the picture lit wrongly. */ + function rday(col, lum) { + if (dSky <= 0.02) return lum; + var dK = dSky * dSky; + /* Three tiers, on the same two thresholds dayMat() uses and for the same reasons: slate while + * there is not yet enough sky for the ground to have a colour, INDIGO through twilight (a wet + * road at dusk is the sky lying on the tarmac, and indigo prints at slate's own height so this + * costs no lums), and stone once it is properly day. It does NOT follow dayMat onto the + * material roll, and the reason is albedo rather than tidiness: a wall may be pale render but + * asphalt is never anything but grey, so the road stays on stone and accepts that stone's + * ceiling of 145 keeps it out of the hot tail. Measured at seed 42 frame 300 noon, that costs + * the frame 92 hot floor cells against 74 — eighteen cells, and the alternative is a white + * road. */ + if (col === P.slate) { + RCOL = dK > 0.50 ? P.stone : (dK > 0.06 ? P.indigo : P.slate); + return lum * (1 + 2.2 * dK) + 26 * dK; + } + if (col === P.shadow) { RCOL = dK > 0.50 ? P.indigo : P.shadow; return lum * (1 + 1.8 * dK); } + RCOL = col; + return lum; + } + var RCOL = 0; function rset(ch, col, lum) { - ROUT.ch = ch; ROUT.col = col; + RCOL = col; + if (dSky > 0.02 && ch !== 0) lum = rday(col, lum); + ROUT.ch = ch; ROUT.col = RCOL; ROUT.lum = lum < 0 ? 0 : (lum > 255 ? 255 : lum | 0); ROUT.mir = mirNow > bounceNow ? mirNow : bounceNow; ROUT.rip = ripNow; ROUT.wch = wchNow; @@ -1676,9 +2146,28 @@ * sodium lamp and nothing else in the picture is lit so unambiguously; by day it is * concrete lit by the sky, which is white, and its rhythm comes from the sky rather than * from the lamp spacing that lampK carries. */ + /* SAND BY DAY, not white, and it is the single cheapest piece of colour in the lower + * third. This is the longest continuous line in the frame and by day it is a precast + * concrete kerb catching the sun square on — which is warm, not blue. white is render and + * cloud; `sand` is "the crown of a dirt road, adobe in sun", i.e. a pale surface with the + * sun's own colour on it, and its day gain (0.90) is one step under white's for exactly + * this kind of job. It also gives the noon road SOMETHING that is not grey: measured over + * the whole floor at seed 42 noon, sand takes about 3% of the frame's energy on its own + * and it is all in one converging line, which is where the eye reads perspective. */ return dSky > 0.45 - ? rset(G_UNDER, P.white, (96 + kw * 30 + mirNow * 26) * (0.7 + 0.7 * dSky)) + ? rset(G_UNDER, P.sand, (96 + kw * 30 + mirNow * 26) * (0.7 + 0.7 * dSky)) : rset(G_UNDER, P.amber, 124 + kw * 34 + lampK * 74 + mirNow * 30); + /* The kerb FACE, which is in its own shadow and never catches the sun — so it stays on the + * structure swatch and takes the ordinary day lift, and the contrast between it and the + * arris above is what makes the kerb read as a thickness rather than as a painted line. + * ALGAE. The bottom of a kerb face is permanently damp, and in a city that means a green- + * black stain along the gutter line — which is `moss` by name ("algae on concrete"). It is + * a DAY feature only: moss's night ceiling is 94, inside the muddy band's own top, so at + * night it could only ever be a grey veil on the longest line in the picture. By day its + * ceiling is 102 against the kerb face's stone at 145, so the stain reads as a stain. A + * third of the face, keyed on world z, so it is a patchy run and not a painted stripe. */ + if (dSky > 0.45 && hash2(Math.floor(wz * 1.7), 0, 0x3C1) < 0.34) + return rset(G_EQ, P.moss, (44 + kw * 30) * (0.6 + 0.8 * dSky)); return rset(G_EQ, P.slate, 10 + kw * 12); } @@ -1691,7 +2180,12 @@ * texture of its own rather than a grid of joints. */ if (CFG.xn > 0 && xd > xh - 0.2 && xd < xh + 2.4 && al < half + 2.2) { var tp = hash2(Math.floor(wx * 3.4), Math.floor(wz * 3.4), 0x2D3); - if (tp < 0.38) return rset(G_oo, P.slate, 15 + tp * 34); + /* Buff by day. Tactile paving is specified in a contrasting colour precisely so that it + * is visible, and the contrasting colour it is actually laid in is buff — which is `sand`. + * At night it stays slate: nothing at ankle height is colour-legible under a sodium lamp, + * and the shipped night frame is the tuned baseline. */ + if (tp < 0.38) return rset(G_oo, dSky > 0.45 ? P.sand : P.slate, + dSky > 0.45 ? (34 + tp * 44) * (0.6 + 0.8 * dSky) : 15 + tp * 34); return rset(0, P.shadow, 0); } /* Cable and service ducts run parallel to the kerb under every real pavement, and their @@ -2192,6 +2686,24 @@ fogStart = (alt && alt.fogStart !== undefined) ? alt.fogStart : FOG_START; fogEnd = ((alt && alt.fogEnd !== undefined) ? alt.fogEnd : FOG_END) * (1 - 0.26 * k); fogSpan = fogEnd - fogStart; + /* 1.5 is a NIGHT number — fog()'s own comment says "gentle near, hard crush past ~55 m", which + * buys the black the print wants out of a canyon lit only at its near end — and a daylight + * frame does pay for it. THE ARITHMETIC, because the version of this comment that shipped got + * it wrong and sent the next reader at a frozen file: at 40 m, k = 1 - 28/113 = 0.752 and + * k*sqrt(k) = 0.652, so a spandrel written at lum 205 arrives at the print at 134 (141 once + * the haze floor puts back what the ramp took). That crush is THIS file's, right here, on this + * line. It is not core.js's depth buckets: measured through the live day LUT, white prints + * v 209 at 3 m and v 207 at 40 m, and at lum 180 it is v 179 against v 175 — four units, not + * fifty. Rebuilding core.js with the bucket retirement removed altogether (gm = GM) moves the + * twelve-pair noon hot tail 4.15% -> 4.44%, i.e. three tenths of a point, and it is not worth + * unfreezing a file for. + * + * Flattening the exponent to 1.05 by day was tried and MEASURED, and it is not kept: it moved + * seed 42 frame 300's hot tail 0.78% -> 0.86% for a Math.pow on every one of twenty thousand + * cells a frame. Both of those are tenths. The lever that was actually worth something was + * local and one function away — see dayMat(), where taking the shaded tier off `stone` moved + * the same twelve pairs 2.11% -> 3.97%. Left at 1.5 with the arithmetic written down so the + * next person does not spend the same hour on it, or the wrong hour on core.js. */ fogPow = (alt && alt.fogPow !== undefined) ? alt.fogPow : 1.5; /* ---- AERIAL PERSPECTIVE, and it is the one place the house doctrine has an exception ------- * The doctrine, stated three times in this file, is that distance fades to BLACK and never to diff --git a/tools/flicker-rate.cjs b/tools/flicker-rate.cjs index 8b97cae..542c330 100644 --- a/tools/flicker-rate.cjs +++ b/tools/flicker-rate.cjs @@ -2,6 +2,12 @@ * src/elements/signage.js — the sibling of tools/lightning-rate.cjs, same rules, different unit. * * node tools/flicker-rate.cjs [signage.js path] [seconds] [phases] + * node tools/flicker-rate.cjs [seconds] [phases] — a bare number first IS the window + * + * RUN IT WITH NO ARGUMENTS to get a verdict. The default 60 s window is the one the 3-20 Hz limit + * was fitted at; below it that rule is printed but not judged and the process exits 3, because a + * short window inflates a broadband periodogram and the tool used to answer that with a FAIL that + * was about the estimator and not about the city. The arithmetic is beside BAND_CALIBRATION_SECS. * * lightning-rate.cjs measures the FRAME: it sums what the element adds over every cell, which is * the right unit for a stroke that lights the whole viewport at once. It is the wrong unit for a @@ -67,13 +73,50 @@ const root = path.join(__dirname, '..'); * before it measured anything. A safety tool that cannot be run the way its documentation says to * run it is a safety tool nobody runs, so the flag is filtered out here and again below. */ const ARGS = process.argv.slice(2).filter(function (a) { return a.indexOf('--') !== 0; }); -const SRC = path.resolve(ARGS[0] || path.join(root, 'src/elements/signage.js')); -const SECS = parseFloat(ARGS[1] || '60'); -const PHASES = parseInt(ARGS[2] || '24', 10); +/* And a BARE NUMBER first is seconds, not a path, which is the same bug one more time. Every other + * gate in tools/ takes its window length first — `west-flicker.cjs 4`, `lightning-rate.cjs 1 600` + * — so `flicker-rate.cjs 4` is what a person types and what a runbook writes down, and this file + * resolved it to /4 and died in readFileSync before it measured anything. The source path is + * still the first positional when it looks like one; only an argument that is entirely a number + * shifts along. */ +const NUM1 = ARGS.length && /^[0-9]+(\.[0-9]+)?$/.test(ARGS[0]); +const POS = NUM1 ? [null].concat(ARGS) : ARGS; +const SRC = path.resolve(POS[0] || path.join(root, 'src/elements/signage.js')); +const SECS = parseFloat(POS[1] || '60'); +const PHASES = parseInt(POS[2] || '24', 10); const MAX_FRAME_STEP = 0.34; // fraction of full scale const MAX_BAND_AMP = 0.02; // fraction of full scale, 3-20 Hz const MAX_DROPOUTS = 3; // per second +/* ---- AND THE BAND LIMIT IS ONLY A LIMIT AT THE WINDOW IT WAS FITTED AT ------------------------ + * `spectrum()` reports the largest single DFT bin between 3 and 20 Hz. For a COHERENT component — + * a tube alternating at 8 Hz — that number is the amplitude of the tube and does not care how long + * you watched. For a BROADBAND one it is a periodogram bin of a noise process, its value is + * sqrt(PSD * binwidth), the bin width is 1/T, and so the number falls as 1/sqrt(T) for ever while + * measuring exactly the same signal. + * + * kind 1, the failing starter, is broadband: vnoise at 2.8 control points a second through a + * smoothstep gate has no line in it at all. MEASURED, same source, same seed, one window length + * apart: + * 2 s 8.07% 3 s 5.41% 4 s 4.10% 8 s 3.58% 16 s 2.45% + * 30 s 1.58% 45 s 1.58% 60 s 1.46% 90 s 1.13% 120 s 0.94% + * and the reported peak wanders over 3.00-3.53 Hz, always against the bottom edge of the band, + * which is what a spectrum with no line in it looks like. Fit 8.07 * sqrt(2/T) against that column + * and it tracks to about a fifth over the whole 60x range. + * + * So the 2% limit means one thing at 60 s and something else at 4, and the tool used to answer a + * 4 s run with FAIL 3-20Hz — a hazard report generated by the estimator. The two wrong repairs are + * both available and both refused: normalising the number by sqrt(T/60) would make it flat for + * noise and would SHRINK a real 5 Hz tube by four times at a 4 s window, which is a safety + * regression dressed as a fix; and moving the limit is moving the limit. + * + * What is left is the truthful answer: four seconds of a broadband personality cannot resolve a 2% + * line, so the check is NOT RUN below the length it was fitted at, is reported as not run, and puts + * the process on exit code 3 — the code this file already has for "a rule verified nothing". The + * step, dropout and per-cell rules are unaffected and run at any window; they are per-frame and + * per-crossing statistics and have no bin width in them. */ +const BAND_CALIBRATION_SECS = 60; +const BAND_JUDGED = SECS >= BAND_CALIBRATION_SECS; global.CC = require(path.join(root, 'src/core.js')); global.window = undefined; @@ -170,7 +213,7 @@ function report(r, checks) { const flags = []; if (checks) { if (r.maxStep > MAX_FRAME_STEP) flags.push('FAIL step'); - if (r.band.amp > MAX_BAND_AMP) flags.push('FAIL 3-20Hz'); + if (BAND_JUDGED && r.band.amp > MAX_BAND_AMP) flags.push('FAIL 3-20Hz'); if (r.rate > MAX_DROPOUTS) flags.push('FAIL dropouts'); } console.log( @@ -179,6 +222,7 @@ function report(r, checks) { `${r.bigRate.toFixed(3)} over-${MAX_FRAME_STEP * 100 | 0}%/s)` + ` dropouts ${r.rate.toFixed(2)}/s @ ${(r.depth * 100).toFixed(0)}% deep` + ` 3-20Hz ${(r.band.amp * 100).toFixed(2)}% fs${r.band.amp > 1e-9 ? ' @ ' + r.band.hz.toFixed(2) + 'Hz' : ''}` + + (checks && !BAND_JUDGED ? ' [not judged]' : '') + (flags.length ? ' ' + flags.join(' ') : ' ok')); return !flags.length; } @@ -188,6 +232,14 @@ let ok = true; * 3 and the run verified less than its section headings claim — see the exit-code note at the top. */ const notApplicable = []; console.log('1. PERSONALITY — flick() multiplier, one sample per frame'); +if (!BAND_JUDGED) { + notApplicable.push(`1. personality 3-20 Hz: window ${SECS}s is under the ${BAND_CALIBRATION_SECS}s ` + + 'the ' + (MAX_BAND_AMP * 100) + '% limit was fitted at, so the band is measured ' + + 'and printed but not judged — see the note beside BAND_CALIBRATION_SECS'); + console.log(` (3-20 Hz printed but NOT JUDGED: a ${SECS}s window cannot resolve a ` + + `${MAX_BAND_AMP * 100}% line in a broadband personality — run with no arguments for ` + + `the ${BAND_CALIBRATION_SECS}s window the limit was fitted at)`); +} for (const K of KINDS) ok = report(run(K.label, K.kind, K.j, K.dead, false), true) && ok; console.log('\n reduced motion (every personality must be frozen):'); diff --git a/tools/metrics.py b/tools/metrics.py index ad6119e..f40cbf9 100644 --- a/tools/metrics.py +++ b/tools/metrics.py @@ -15,7 +15,13 @@ rather than fixing it; the fix is the two lines below and a kind breakdown for f """ import sys, json -NAMES = ['amber','azure','ember','spring','violet','white','red','slate','warm','ice','pure','shadow'] +# Must stay in step with core.js's PALETTE, in order and in length. The energy split indexes +# `ci % len(NAMES)` and the pigment lookup indexes `ci % len(pal)`, so a NAMES list shorter than +# the palette does not raise -- it wraps, and every stone cell in the frame is reported as amber. +# Eight swatches were appended to the palette (12..19) and this line is the whole of what that +# cost the census. +NAMES = ['amber','azure','ember','spring','violet','white','red','slate','warm','ice','pure','shadow', + 'stone','timber','sand','jade','rose','gold','moss','indigo'] KINDS = ['sky', 'facade', 'floor', 'element'] def load(src):