Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions build/notes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
// and once after an update ("What's new"). A PR adds its entry under the number it expects; the merge queue (tools/queue.mjs)
// gives it the number it really gets and writes this file.
export const NOTES = {
484: {
ru: ["📱 Телефоны получили помощника: мир теперь строит отдельный поток и на телефоне. Раньше поток считался как 400 МБ памяти, и телефону не доставалось ни одного; замер показал 30–45 МБ",
"⏱️ На iPhone с медленным в 4 раза процессором (эмуляция) земля вокруг после прыжка на 60 км готова за 11 с вместо 40, а вся земля за 53 с (раньше не успевала), памяти занято не больше",
"🧠 Поток живёт в классе памяти своей страницы: на телефоне он держит меньше планов городов, а картинка та же байт в байт. Если страница падала от нехватки памяти, потоков становится меньше",
"🏘️ Исправлено: города с жилыми посёлками (сборка 481) не строились, план такого города падал с ошибкой, и земля над ним не появлялась. Новый тест находит любое необъявленное имя во всём коде игры"],
en: ["📱 Phones got a helper: the world is now built by a thread of its own on a phone too. A thread used to be counted as 400 MB of memory, so a phone got none; measured, it takes 30–45 MB",
"⏱️ On an iPhone with a 4× slower processor (emulated) the land around after a 60 km jump is ready in 11 s instead of 40, and the whole land in 53 s (it did not finish before), with no more memory taken",
"🧠 The thread lives in its page's memory class: on a phone it keeps fewer town plans, and the picture is the same byte for byte. A page that ran out of memory gets fewer threads",
"🏘️ Fixed: towns with estates (build 481) were not built, the plan of such a town threw an error and the land over it never came. A new test finds any undeclared name in the whole code of the game"],
},
483: {
ru: ["🚤 Катер снова спускается с прицепа: кнопка 🚤 в машине пропала, когда лодки стали проверять воду под каждой клеткой корпуса. Теперь место за кормой спрашивают у самого катера, а не у коробки его длины"],
en: ["🚤 The motorboat launches from its trailer again: the 🚤 button in the car had gone when hulls began to check the water under every cell of the body. The place astern is now asked of the boat itself, not of a box of its length"],
Expand Down
14 changes: 14 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,14 @@ Design and migration: `docs/WORLDGEN.md`.
steep step fails), `tools/navi.test.mjs` (outside the towns that grew: no route off the net, no car on a walker's way; inside a grown
town, where a road is not always met by a street yet, the routes that cross the bare plan are counted by the one ratchet left,
`TOWNS`, until the towns' own rule closes it).
- **A thread is counted at what it measurably holds, and lives in its page's memory class.** How many workers a device gets follows
the cores and the memory a worker really costs (its heap, buffers and thread after the `cold` scenario, measured in Chromium), never a
guess: counted as 400 MB, a worker never reached a phone, which then made every column, far tile and town plan on its main thread. A
worker takes its page's budget with the land, so the caches of a small device are small there too and its tiles stay the same bytes;
a page that died for memory starts with a smaller budget and so with fewer workers. Before an optimisation is built, its gain is
measured: a generator-only worker script would have saved ~8 MB of a worker's 29–40 MB. Tests: `tools/wcount.test.mjs` (the table of
devices, more memory never means fewer workers, a small worker's caches and bytes), `tools/wcost.bench.mjs` (memory and the `cold`
times with an iPhone's profile).

## Robustness

Expand All @@ -701,6 +709,12 @@ Design and migration: `docs/WORLDGEN.md`.
- **No loop dies from one system's error.** `frame()` (`src/game/99_main.js`) asks for its next frame in `finally`; `Bg.step` runs its
parts (`Bg.parts`: world, own body, animations, network) each in its own `try`, so a throwing world never stops the network step that
heals the shared state. Each error goes to `Guard.fail` (below), logged once a second per kind. Test: `tools/netride.test.mjs` parts 2 and 3.
- **Every name the code uses is declared, checked over the whole source and not where it happens to run.** Two PRs that are each
right can land as a game that is wrong: the version floor dropped the constant `STR` (always true since), the estates, written before,
still read it in a new place; git merged them cleanly, the bundle built, and every town with an estate threw while it was planned
(build 481: its far tiles and columns never came). A name that is missing fails only when its line runs, so the test reads the whole
game as the build puts it together and fails on any free name that is not a global of the browser or the language. Test:
`tools/undef.test.mjs` (it found `STR`; the merge queue runs it on the combined state).
- **Every key the code reads from a constant table exists.** `LAMP.rev` had slipped into a comment (build 378) and the one branch that
reads it threw at night for every reversing car. Test: `tools/config.test.mjs` checks each `NAME.key` read in `src/game` against the
table on `window.G` (all-caps, data only), and draws every lamp state of a real car.
Expand Down
5 changes: 3 additions & 2 deletions docs/WORLDGEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ service-worker shim) would remove the copies; the copies are KBs, so it is not t
Today a phone gets no workers and plans everything on the main thread; parallelism alone cannot fix it. The design answers with:

- **A bounded cone** (section 3): the lever that works with 0 workers.
- **A planner worker that is not a copy of the game.** The levels M, R and D need only utilities and generator code (files 00–39 without
- **A planner worker that is not a copy of the game.** (Measured in phase 2: the code is only ~16 MB of a worker's 29–40 MB, so this was not built; phones got their worker by counting it at its measured cost.)
The plan was: the levels M, R and D need only utilities and generator code (files 00–39 without
items, meshes or renderer). Built as its own small worker script (about 5 to 10 MB in memory instead of about 50 MB), it fits a phone's
budget, so a phone gets one planner worker and the main thread never plans.
- **Time slices.** A chunk of any level must fit 8 ms on the reference desktop thread and 30 ms on the low-end profile. If a level's chunk
Expand Down Expand Up @@ -184,7 +185,7 @@ bytes.
|---|---|---|---|
| 0 | (perf thread, in progress) settlement planning shared by the workers and cached; bytes identical | no | `cold` with 1–6 workers |
| 1 | **Frame** (build 427+, done): `Lv` levels with sizes and declared reads (`src/game/30_lv.js`), the key hash RNG `lvHash`/`lvRnd`, the padding audit, the cone ratchet on today's generator (`tools/lv.test.mjs`, `tools/cone.test.mjs`). The store with single flight and the IndexedDB cache come from phase 0 under `Lv.key` | no | the cone ratchet |
| 2 | **Planner worker** script (levels M–D only) so phones get one; time slices | no | `cold` on the low-end profile, 0 vs 1 worker |
| 2 | **A worker for phones** (build 482, all worlds, bytes identical): measured first in headless Chromium after the `cold` scenario, a worker holds 29–40 MB (JS heap and buffers; the code ~16 MB of it, the rest the towns' plans, roads, railways and street lots it made). A script of the generator alone would save ~8 MB per worker and needs the game's top-level wiring split (`G`, registrations, the ship and fall jobs workers also run): not built. The lever was the count: a worker was counted as 400 MB, so a phone (budget 140–480 MB) got none; now `LodPool.count` counts 45 MB and lets the workers take a third of the budget, and a worker takes its page's budget with the land (`Mem.small` there too: the small caches). An iPhone emulated with the CPU 4× slower: the 3×3 around the camera 39.8 → 11.0 s, the whole land not within the scenario → 52.6 s, the page's memory no higher (`tools/wcost.bench.mjs`). Time slices: still open | no | `tools/wcount.test.mjs`, `cold` on the iPhone profile, 0 vs 1 worker |
| 3a | **Coarse decisions without the finer levels** (build 431, gw 57, done): town and airport sites, the ends and lines of roads and footpaths read `Terr.natC`, the land without the lava flows; no volcano traces its flows for them. Of 1489 towns and 2445 road lines in five worlds none moved and one line changed; `Terr.nat` of the first look −38…−52 %, the first look ~1.15 → ~0.83 s (node, 3 worlds). Measured against gw 56 (interchanges planned by nodes, build 430), which had grown the cone by 40–56 % (settlement cells 387–432 → 559–636, `Terr.nat` 135–183k → 165–280k, first look up to 1.9 s): gw 57 takes `Terr.nat` to 105–141k and the first look back to 0.85–1.1 s; the cells stay (phase 5). The ceilings of `tools/cone.known.json` were set again from gw 57 | gw 57 | the cone ratchet |
| 5a | **The roads of one settlement** (build after 433, all worlds, bytes identical): an edge is one object per pair of cells (`Roads.pair`), and the edges that end in a settlement (`Roads.ends`) read only the cells between it and its partners. `fork`, `greater` and `Roads.into` (the streets a town plan joins) used a scan of `own()` over 7×7 cells, which read 13×13 cells around each end. Cells of the first look 567/636/559 → 429/481/461; golden, xing, drive and rail unchanged. Anton's two scenes (a desert by home, the walls of a canyon 510 m out) join the cone ratchet as rings of far tiles | no | the cone ratchet |
| 5b | **Declared reach for the railways** (gw 61): a railway loop stays within its region's towns ±R ± `RL_REACH` (3000 cells; 1036 loops of 8 worlds measured at most 2482, none dropped) or is not built, `Rail.cand` skips regions whose box misses the query, and `make` asks `Air.site` only of the regions its box meets (an airport lies wholly in its region). Cells of the first look 429/481/461 → 379/181/345, rings of Anton's two scenes 611/591 → 482/467. Tried and dropped: a road reading the greater roads at its ends as their provisional lines (`line0`, no fork) cut 2–6 % more cells but gave 5 more clashes at two roundabouts of seed 5 (xing): the fork of a lesser road must see the finished greater road | gw 61 | the cone ratchet, `tools/rail.mjs test` |
Expand Down
Loading
Loading