Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Map: route paths from a runtime file and fewer unit spot candidates, the units' step 300 to 90 ms (refs #321) (#547)

Eyal Golan4875d0ee82b5
diff --git a/ASSETS.yaml b/ASSETS.yaml
index 3cbf29a96..c6254c4d8 100644
--- a/ASSETS.yaml
+++ b/ASSETS.yaml
@@ -192,6 +192,10 @@ rules:
source: "Railways and main roads of May 1948 (issue #35): traced by tools/routes_1948.py on the Survey of Palestine 1:250,000 map of 1946 (public domain; scans and georeferencing by Palestine Open Maps, https://palopenmaps.org/en/maps?basemap=pal250k1946) between waypoints at Wikipedia API (CC BY-SA) and Wikidata (CC0) coordinates; per-route sources and check dates in routes_1948.yaml"
status: verified
note: "Public domain checked 2026-10-11: PD-UKGov (expired Crown copyright: 50 years from publication for published works, which HMSO treats as worldwide) and PD-scan, as Wikimedia Commons files the 1946 Survey of Palestine sheets (e.g. https://commons.wikimedia.org/wiki/File:Gaza_sh._04,_1946.jpg). Palestine Open Maps' About page calls its maps public domain under the UK Copyright, Designs and Patents Act and publishes no terms of its own for its tiles or georeferencing; the traced lines are our own derivative and copy none of its layers. No OpenStreetMap (ODbL) geometry is copied: OSM and OpenHistoricalMap lines are only measured against (tools/routes_accuracy.py, docs/routes.md)."
+ - glob: "content/map/route_paths_1948.tsv"
+ licence: CC-BY-SA-4.0
+ source: "The baked runtime form of content/map/route_paths_1948.yaml (tools/route_paths_bake.py, issue #321): the same routes and points, with the YAML's check and the counts; no new facts. Sources as for the YAML above"
+ status: verified
- glob: "unity/Assets/Resources/Routes/RouteRibbons.bytes"
licence: CC-BY-SA-4.0
source: "The route ribbons' meshes (issue #321), baked by Editor RouteRibbonBake from content/map/route_paths_1948.yaml (the traced lines above) draped on the Copernicus DEM GLO-30-derived heightmap (unity/Assets/StreamingAssets/map/heightmap.*); no new facts; attribution in NOTICE"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bba3279cc..c886514e9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -260,6 +260,13 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
footprint) keep their mosques and water towers, at a quarter and three tenths of their size elsewhere, at the street
crossing nearest their hearts (refs #318, owner ruling 2026-10-12). The city's blocks keep their plots round them: core
cover 18.5% to 25.6%, the whole footprint 17.4% to 25.2%, 43 to 55 blocks.
+- The map reads its railways' and roads' traced lines from a baked runtime form at boot (`route_paths_1948.tsv`,
+ `tools/route_paths_bake.py`) instead of parsing the YAML, as the localities do (refs #321). A missing or stale file is
+ refused with a warning and the YAML is read as before. The unit placer no longer makes candidate spots for hexes its
+ one-hex limit rules out; every token stands where it stood. At `--cpu 4` the units' step takes about 90 ms instead of
+ 300, the map build at least 165 ms less (2379-2507 to 2196-2214 ms) and the start screen about 120 ms less (the
+ placer runs again there). `?bootlog` has four
+ more phases inside the units' step. Presentation only.
- CI checks the water and route-ribbon bakes against the code that makes them (#535), as it does the biome colours'
(#529): a pinned fingerprint of `MapBuilder.WaterMeshGrid` and of `RouteLayer.Plan` and `Derive`, and a numpy port of
the water mesh. Doc comments in `MapBuilder`, `RouteLayer` and `RouteRibbonFile` point to the checks. No change in the
diff --git a/LICENSING.md b/LICENSING.md
index d31d8c768..028707553 100644
--- a/LICENSING.md
+++ b/LICENSING.md
@@ -5,7 +5,7 @@ Different parts of this repository are under different licences. Where a file is
| What | Paths | Licence |
|---|---|---|
| Code | `sim/`, `tools/` (Python), `scripts/`, `.github/`, `.gitignore`, `unity/Assets/Scripts/`, `unity/Assets/Editor/`, `unity/Assets/Tests/`, `promo/*.py`, `spikes/` code, and everything else under `unity/Assets/` not listed below (scenes such as `Map.unity`, `WebGLTemplates/`, `link.xml`, `*.inputactions`, `.meta` files) | [MIT](LICENSE) |
-| Game content (text and data) | `content/` (events, people, offices, model, rules, map YAML/JSON), except the third-party map data below | [CC BY-SA 4.0](LICENSES/CC-BY-SA-4.0.txt), credit "Statecraft: Israel contributors". The text paraphrases its cited sources, many from Wikipedia (CC BY-SA), so share-alike applies; each entry lists its sources |
+| Game content (text and data) | `content/` (events, people, offices, model, rules, map YAML/JSON and their baked runtime forms `map/*.tsv`), except the third-party map data below | [CC BY-SA 4.0](LICENSES/CC-BY-SA-4.0.txt), credit "Statecraft: Israel contributors". The text paraphrases its cited sources, many from Wikipedia (CC BY-SA), so share-alike applies; each entry lists its sources |
| Original docs, art and UI assets | `docs/`, the root `*.md` files (except `LICENSE`), `ASSETS.yaml`, `ASSETS.portraits.yaml`, `promo/shots.json`, `promo/CREDITS.md`, `tools/README.md`, `reports/` (our own text), `research_notes/` (our own text), `unity/Assets/UI/*.uxml`, `*.uss`, `strings.en.yaml`, `unity/Assets/Materials/`, `unity/Assets/Resources/Units/` (materials), `unity/Assets/Shaders/`, `unity/Assets/UI/*.asset`, `unity/Assets/WebGLTemplates/Statecraft/favicon.ico`, `unity/Assets/Resources/EventImageCatalog.asset` (the event-photo catalog: alt texts, credits and flags; the pictures it points to are under their own licences below), `promo/ref/geo-reference.png` | [CC BY 4.0](LICENSES/CC-BY-4.0.txt), credit "Statecraft: Israel contributors" |
| Website | `site/` (the Astro source, `site/src/data/contributors.yaml`, the page text in both languages and the build scripts). Copied or derived files keep their own licences: the fonts in `site/public/fonts/` (SIL Open Font License 1.1, licence texts beside them), the in-engine video and poster (CC BY 4.0), the cinematic trailer's web encode `site/public/media/promo-trailer-720p.mp4` and its poster (AI-generated, CC0; its music is AI-generated, made with ElevenLabs Music) and the site's tab icon `site/public/favicon.svg` (an AI-assisted drawing, CC BY 4.0); per-file records in `ASSETS.yaml` | Code MIT; text CC BY 4.0, credit "Statecraft: Israel contributors". The History and Sources pages show `content/` text, which stays CC BY-SA 4.0 |
| Unity template-derived files | `unity/Assets/Settings/` (URP assets, renderers, volume profiles), `spikes/m0/unity/Assets/Settings/`, `spikes/m0/unity/Assets/UI Toolkit/UnityThemes/`, and any Shader Graph generated from a Unity template (for example `unity/Assets/Shaders/StatecraftTerrain.shadergraph`, from "Terrain Simple") | Created from Unity's project or graph templates and edited; under the [Unity Companion License](https://unity.com/legal/licenses/unity-companion-license) (use with Unity), not MIT |
diff --git a/content/map/route_paths_1948.tsv b/content/map/route_paths_1948.tsv
new file mode 100644
index 000000000..d950e8386
--- /dev/null
+++ b/content/map/route_paths_1948.tsv
@@ -0,0 +1,26 @@
+# Generated by tools/route_paths_bake.py from route_paths_1948.yaml. Do not edit: edit the YAML (tools/routes_1948.py)
+# and rerun the tool. The runtime form the map reads at boot (map-only, outside the content hash).
+#route id kind status from to length_km on_symbol max_gap_m point_count points
+meta version 2
+meta yaml_check 254700474
+meta routes 19
+route jaffa_jerusalem_railway rail draft 1920-10-05 79.4 1.0 65 113 34.76117 32.05894;34.76409 32.05996;34.76949 32.0605;34.77448 32.0603;34.77742 32.05924;34.78086 32.05571;34.78638 32.04568;34.79255 32.03932;34.81436 32.02349;34.83771 32.00775;34.84893 31.99572;34.8713 31.97509;34.88636 31.95755;34.88673 31.95516;34.88565 31.95368;34.87321 31.94354;34.87112 31.94135;34.86992 31.93914;34.8708 31.93573;34.87298 31.93191;34.87781 31.9283;34.88083 31.9234;34.88626 31.91762;34.88954 31.90869;34.88909 31.90734;34.88636 31.90467;34.87678 31.89781;34.87057 31.88903;34.87168 31.87982;34.87147 31.87482;34.86603 31.86169;34.86775 31.85101;34.87009 31.84463;34.87058 31.84073;34.86979 31.82851;34.86722 31.81997;34.86949 31.81555;34.87025 31.8114;34.87181 31.80857;34.87557 31.80583;34.88764 31.79956;34.89363 31.79506;34.90035 31.78828;34.92253 31.76821;34.92847 31.76507;34.93797 31.75898;34.94668 31.759;34.95347 31.75656;34.95884 31.756;34.97276 31.75634;34.98381 31.75799;35.00674 31.75687;35.01071 31.75768;35.01722 31.76211;35.03203 31.76215;35.03544 31.7646;35.03876 31.7659;35.0477 31.76358;35.05046 31.75846;35.05232 31.75727;35.0651 31.76556;35.0675 31.76593;35.06883 31.76475;35.06934 31.76031;35.06539 31.75626;35.06483 31.75461;35.06613 31.75284;35.06934 31.7512;35.0737 31.75011;35.07778 31.75009;35.08386 31.75723;35.08588 31.75852;35.08703 31.7586;35.08797 31.75729;35.08624 31.75413;35.08606 31.7517;35.08691 31.75108;35.09144 31.7511;35.09289 31.75045;35.09369 31.74963;35.09485 31.74558;35.0958 31.7445;35.10339 31.74279;35.11714 31.73811;35.11861 31.7385;35.12205 31.74277;35.12356 31.74337;35.12516 31.74331;35.12622 31.74156;35.1248 31.73751;35.12586 31.73527;35.12727 31.73454;35.12892 31.73445;35.13344 31.73692;35.13546 31.73692;35.13697 31.73577;35.13836 31.73204;35.13999 31.7312;35.14144 31.73175;35.15582 31.74346;35.16043 31.74566;35.16454 31.74553;35.1731 31.74401;35.17851 31.74412;35.18192 31.74515;35.1869 31.74832;35.19691 31.75147;35.19855 31.75147;35.20436 31.74975;35.20594 31.74999;35.21073 31.75343;35.21583 31.75941;35.22466 31.76678
+route kantara_main_line_south rail draft 1946 102.5 0.99 97 106 34.8755 31.94583;34.85647 31.94164;34.84493 31.94101;34.83788 31.93628;34.83139 31.93335;34.81811 31.93296;34.81475 31.92788;34.81331 31.91992;34.81009 31.91508;34.80842 31.9107;34.80337 31.90815;34.79081 31.89542;34.78637 31.89251;34.77953 31.88947;34.76356 31.87633;34.74713 31.86554;34.72107 31.8437;34.71295 31.83287;34.7051 31.82449;34.70018 31.81622;34.69304 31.80776;34.68667 31.79855;34.67908 31.79188;34.67078 31.78289;34.66478 31.77247;34.66476 31.77104;34.66776 31.76448;34.66696 31.76118;34.66343 31.75479;34.66284 31.75435;34.65236 31.75308;34.65118 31.75209;34.64526 31.74122;34.63381 31.72352;34.61521 31.69725;34.61254 31.69087;34.60678 31.68569;34.60549 31.68164;34.60529 31.67166;34.60389 31.67115;34.58877 31.67053;34.5874 31.66999;34.58724 31.66867;34.58805 31.66744;34.59896 31.66077;34.60022 31.65899;34.59968 31.65625;34.59564 31.64929;34.59557 31.64656;34.59706 31.63678;34.59465 31.63269;34.5905 31.62816;34.58473 31.6229;34.5791 31.61876;34.57812 31.61072;34.57035 31.59179;34.56867 31.58935;34.56352 31.58467;34.5611 31.58174;34.55798 31.58041;34.55715 31.58052;34.55643 31.57968;34.55603 31.57904;34.55627 31.57341;34.54561 31.55758;34.53515 31.54645;34.52255 31.53754;34.51649 31.53214;34.5101 31.5299;34.50219 31.52832;34.48311 31.51676;34.47609 31.51181;34.4657 31.50761;34.46364 31.50719;34.4628 31.50601;34.46266 31.50351;34.46458 31.49846;34.45976 31.49304;34.4537 31.48804;34.44529 31.48272;34.43482 31.47347;34.4278 31.46977;34.41818 31.46277;34.41574 31.46034;34.41146 31.45422;34.40586 31.44884;34.38021 31.42685;34.37118 31.41743;34.36077 31.40994;34.35722 31.4056;34.3496 31.39291;34.34069 31.38172;34.33788 31.37664;34.32567 31.36532;34.31324 31.34922;34.31124 31.34515;34.30399 31.34404;34.30001 31.33851;34.28154 31.3186;34.27795 31.31347;34.26673 31.30334;34.26553 31.29969;34.26534 31.28923;34.26436 31.2789;34.26318 31.27672;34.25855 31.27246
+route eastern_railway rail draft 1915 62.8 0.99 114 69 34.8755 31.94583;34.87938 31.94791;34.88741 31.9538;34.89447 31.96052;34.89701 31.9638;34.89951 31.9691;34.9021 31.98026;34.90296 31.98665;34.90556 31.99305;34.91548 32.01115;34.92223 32.01796;34.92509 32.02191;34.92851 32.03092;34.93275 32.03659;34.93409 32.03951;34.93514 32.04554;34.93522 32.05602;34.93344 32.06619;34.93323 32.09143;34.93553 32.11937;34.93319 32.12488;34.93243 32.13781;34.93403 32.14811;34.93762 32.15889;34.94349 32.16711;34.94779 32.17195;34.95517 32.1847;34.95618 32.1883;34.95543 32.19825;34.95811 32.20598;34.96048 32.20971;34.96819 32.21761;34.97086 32.22158;34.97969 32.24019;34.98528 32.25489;34.99084 32.26556;34.99322 32.27276;35.00063 32.28791;35.00307 32.29026;35.00837 32.29369;35.01296 32.30576;35.01461 32.30788;35.01882 32.30917;35.02419 32.30977;35.02548 32.31063;35.02613 32.3119;35.02535 32.31286;35.01651 32.31478;35.01369 32.31589;35.01196 32.31906;35.0108 32.3261;35.00841 32.33135;35.00484 32.34445;35.00266 32.35715;35.00008 32.36384;35.00082 32.36949;35.00256 32.37608;35.00245 32.37961;34.99682 32.39174;34.9936 32.39447;34.98082 32.40251;34.97732 32.4089;34.97446 32.4203;34.96666 32.43166;34.96297 32.43441;34.95436 32.43846;34.95042 32.44256;34.94959 32.44441;34.94966 32.44612
+route hadera_haifa_railway rail draft 1918 50.1 0.98 113 54 34.94966 32.44612;34.94705 32.44846;34.94267 32.45537;34.93971 32.46226;34.93994 32.4633;34.94935 32.47604;34.95226 32.48349;34.95255 32.48627;34.95128 32.49141;34.95113 32.4982;34.94961 32.50999;34.94557 32.52066;34.93745 32.53152;34.93152 32.53755;34.92904 32.54197;34.9283 32.55561;34.9303 32.5676;34.92822 32.5733;34.92481 32.58687;34.92225 32.60137;34.9226 32.60822;34.92466 32.62177;34.92708 32.63;34.92731 32.63449;34.93113 32.65522;34.93243 32.671;34.93673 32.6851;34.93717 32.69081;34.93933 32.69501;34.93893 32.69812;34.94117 32.70829;34.94462 32.71699;34.94492 32.72413;34.94612 32.7327;34.94884 32.74278;34.94999 32.75172;34.95147 32.75722;34.95174 32.76583;34.95396 32.78227;34.95585 32.78895;34.95376 32.81186;34.95075 32.82148;34.95619 32.82772;34.9608 32.83067;34.96596 32.83201;34.97343 32.83282;34.98097 32.83487;34.98425 32.83453;34.98591 32.83345;34.98772 32.82889;34.99523 32.82217;35.00216 32.81244;35.00376 32.81137;35.00493 32.81159
+route haifa_beirut_railway rail draft 1942 38.9 0.99 128 48 35.00493 32.81159;35.00565 32.80917;35.00775 32.80652;35.0134 32.80162;35.01704 32.79919;35.02914 32.79533;35.03329 32.79486;35.03617 32.79612;35.03964 32.79922;35.0464 32.80743;35.05302 32.81113;35.05477 32.81306;35.0617 32.82587;35.07154 32.83801;35.07335 32.84195;35.07872 32.8507;35.08379 32.85639;35.09184 32.86865;35.09246 32.8732;35.09205 32.88035;35.09123 32.88232;35.08812 32.88652;35.08614 32.89306;35.08309 32.89926;35.08257 32.9074;35.07982 32.9136;35.08095 32.92791;35.07849 32.94132;35.08077 32.9466;35.08267 32.95498;35.08351 32.96646;35.08301 32.97543;35.08377 32.98073;35.08492 32.9833;35.09139 32.9919;35.09384 33.00419;35.09671 33.01205;35.09695 33.01597;35.09605 33.02853;35.09685 33.03202;35.10021 33.03769;35.10074 33.04011;35.10101 33.04658;35.10211 33.05363;35.10095 33.06138;35.10098 33.07402;35.10338 33.09067;35.10449 33.09276
+route jezreel_valley_railway rail draft 1905-10-15 92.1 0.98 161 82 35.00493 32.81188;35.00739 32.80706;35.01036 32.80407;35.02104 32.79472;35.03193 32.7867;35.03871 32.78032;35.05094 32.77083;35.07756 32.74176;35.09548 32.72516;35.09776 32.72101;35.10394 32.69748;35.10869 32.69118;35.11121 32.68886;35.13988 32.67789;35.16098 32.66866;35.17078 32.66376;35.17972 32.66074;35.18654 32.65676;35.19593 32.65369;35.20696 32.64768;35.21337 32.64521;35.22874 32.63769;35.27292 32.6193;35.28716 32.61095;35.29396 32.60842;35.31072 32.59409;35.3267 32.57407;35.32986 32.57117;35.33326 32.5691;35.3504 32.56215;35.35688 32.56077;35.36423 32.55811;35.38138 32.55379;35.39527 32.54944;35.40237 32.54847;35.41424 32.54814;35.42758 32.54536;35.44802 32.5369;35.47577 32.52016;35.488 32.51605;35.49421 32.51331;35.50069 32.51387;35.50289 32.51475;35.50543 32.51661;35.51044 32.52146;35.51368 32.52876;35.51558 32.53062;35.51696 32.53033;35.52082 32.52651;35.5231 32.52564;35.52732 32.52825;35.5321 32.529;35.53339 32.53033;35.53212 32.53952;35.53436 32.55215;35.53813 32.55853;35.54511 32.56618;35.54746 32.57228;35.54804 32.58922;35.54755 32.60322;35.54868 32.60542;35.5539 32.61144;35.55776 32.62083;35.56635 32.62969;35.56747 32.63152;35.56851 32.63785;35.56997 32.65795;35.57618 32.67428;35.57763 32.68205;35.58173 32.69567;35.5843 32.70048;35.58682 32.70227;35.5891 32.70306;35.59647 32.70374;35.60504 32.69876;35.61936 32.69287;35.62748 32.68836;35.63065 32.68762;35.63946 32.68712;35.64648 32.68472;35.65255 32.68642;35.66583 32.68728
+route jaffa_jerusalem_road road draft 1946 60.1 0.94 599 65 34.75345 32.05224;34.75742 32.05487;34.76037 32.05571;34.76144 32.05376;34.76387 32.05121;34.77385 32.04355;34.77889 32.04034;34.79464 32.03293;34.80806 32.02196;34.83771 31.98114;34.84279 31.9738;34.84498 31.96965;34.85527 31.95517;34.86406 31.94408;34.86688 31.93781;34.87132 31.93069;34.88153 31.92166;34.88695 31.91839;34.89378 31.91308;34.91221 31.90185;34.91997 31.8939;34.93225 31.88586;34.93907 31.87898;34.94718 31.87218;34.95626 31.86201;34.95936 31.86118;34.96052 31.86134;34.96832 31.84617;34.97617 31.83644;34.97738 31.83315;34.97733 31.83165;34.97846 31.83027;34.9891 31.82818;35.00535 31.8272;35.01425 31.82514;35.0177 31.82325;35.02629 31.81547;35.03404 31.8098;35.03659 31.80869;35.04856 31.80587;35.05018 31.80582;35.05673 31.80782;35.05987 31.80816;35.07574 31.80217;35.08857 31.80234;35.09409 31.80497;35.10197 31.80655;35.10821 31.81111;35.11351 31.80841;35.12028 31.80365;35.12706 31.80094;35.13233 31.7999;35.14402 31.79977;35.14866 31.79659;35.15709 31.79407;35.16037 31.79389;35.16554 31.79404;35.1666 31.79447;35.1757 31.80119;35.18444 31.80201;35.19066 31.79692;35.19783 31.79256;35.21541 31.7861;35.22131 31.78263;35.22569 31.77933
+route burma_road track draft 1948-06-14 18.3 0.91 146 37 34.93489 31.82528;34.94746 31.81658;34.95295 31.81344;34.95679 31.8126;34.96494 31.81446;34.96761 31.81446;34.97296 31.81115;34.98001 31.80943;34.98267 31.80639;34.98371 31.80605;34.98463 31.80657;34.98564 31.80959;34.99268 31.81008;34.99565 31.81098;34.9968 31.812;34.99811 31.81489;34.99865 31.82419;34.9994 31.82542;35.00043 31.82601;35.00333 31.82628;35.00826 31.82582;35.01268 31.82476;35.01558 31.82347;35.02167 31.81757;35.02195 31.81561;35.01878 31.81181;35.01828 31.81017;35.02168 31.80841;35.02652 31.80309;35.03119 31.79917;35.03441 31.79526;35.04164 31.794;35.05581 31.79536;35.07023 31.7943;35.07422 31.79605;35.07462 31.79694;35.07394 31.79801
+route tel_aviv_haifa_road road draft 1937 103.5 0.94 534 105 34.7907 32.07785;34.79733 32.08163;34.80734 32.08401;34.81972 32.09023;34.82601 32.09211;34.8333 32.09337;34.85579 32.09353;34.86127 32.09309;34.86814 32.09161;34.87611 32.09145;34.88252 32.09003;34.88609 32.0907;34.89086 32.09356;34.89472 32.09733;34.89902 32.10549;34.90165 32.11253;34.90293 32.12035;34.90286 32.12502;34.90097 32.13011;34.89556 32.13695;34.89435 32.13951;34.89395 32.1597;34.89305 32.1701;34.89198 32.17268;34.88801 32.17675;34.88741 32.17838;34.88817 32.18908;34.88264 32.20438;34.88185 32.22637;34.88235 32.23171;34.89039 32.25737;34.90091 32.31693;34.90301 32.32459;34.90376 32.3321;34.90577 32.342;34.90621 32.35029;34.90576 32.36365;34.90685 32.37547;34.90526 32.38652;34.9013 32.39859;34.90125 32.4058;34.90259 32.41362;34.90757 32.43743;34.90832 32.43864;34.91025 32.43908;34.91473 32.43806;34.9202 32.43966;34.92639 32.43953;34.93342 32.4432;34.93743 32.44398;34.94626 32.44431;34.958 32.44935;34.96063 32.45287;34.96632 32.46639;34.96763 32.46822;34.97309 32.47142;34.97478 32.47417;34.97332 32.47859;34.96675 32.49142;34.96202 32.49858;34.9601 32.50438;34.958 32.50786;34.9551 32.51035;34.94898 32.51257;34.94633 32.51669;34.94485 32.51777;34.93095 32.51847;34.9295 32.51909;34.9289 32.52;34.92767 32.53222;34.92777 32.5376;34.92992 32.54437;34.9302 32.55626;34.93115 32.56124;34.93876 32.58448;34.94029 32.58739;34.94328 32.59078;34.94507 32.59429;34.94764 32.60189;34.95465 32.62861;34.95606 32.65276;34.95925 32.68294;34.9605 32.68785;34.96563 32.70047;34.96758 32.71222;34.96753 32.71643;34.96515 32.72135;34.96441 32.72449;34.96395 32.74506;34.96054 32.75508;34.95976 32.75933;34.9597 32.7651;34.96062 32.77481;34.96035 32.79396;34.95912 32.8011;34.95551 32.81181;34.9543 32.82144;34.95575 32.82424;34.95973 32.82741;34.96334 32.8291;34.9666 32.82932;34.97323 32.82728;34.97989 32.82295;34.9832 32.82144;34.99686 32.81952
+route coastal_road_south road draft 1946 114.8 0.87 632 105 34.75345 32.05224;34.75742 32.05486;34.76036 32.05572;34.76143 32.05377;34.76386 32.05122;34.77739 32.04105;34.79132 32.03478;34.79574 32.03205;34.80946 32.02035;34.82196 32.00262;34.82164 32.00109;34.81492 31.9933;34.81291 31.99016;34.80702 31.97288;34.80331 31.96615;34.80256 31.96013;34.80239 31.94896;34.79804 31.92549;34.79715 31.92486;34.78114 31.92173;34.77288 31.92062;34.77157 31.91988;34.77007 31.91295;34.76651 31.90779;34.7633 31.90007;34.75178 31.88062;34.74793 31.87073;34.74178 31.85955;34.72838 31.84875;34.72234 31.84322;34.71584 31.83357;34.70545 31.82128;34.6873 31.79655;34.6737 31.78428;34.66977 31.78282;34.66847 31.7828;34.66766 31.78201;34.66637 31.77355;34.66798 31.76353;34.66649 31.75844;34.66167 31.75317;34.66001 31.75244;34.65558 31.75257;34.6539 31.75162;34.63663 31.72398;34.61598 31.69461;34.61135 31.68496;34.60973 31.67472;34.60622 31.66711;34.6025 31.66115;34.59972 31.65404;34.59476 31.64612;34.59066 31.63518;34.58435 31.62377;34.57928 31.61676;34.57407 31.60575;34.5655 31.59086;34.55482 31.57756;34.54938 31.56518;34.54064 31.54131;34.52149 31.53412;34.51334 31.5297;34.50563 31.5269;34.50014 31.5243;34.49353 31.52048;34.4926 31.51931;34.49276 31.51798;34.49892 31.51207;34.49942 31.51043;34.49325 31.50413;34.48796 31.49721;34.48417 31.49387;34.48234 31.49403;34.4751 31.49941;34.46993 31.50413;34.46807 31.50423;34.4653 31.50123;34.45927 31.49747;34.45072 31.48774;34.44178 31.48013;34.43774 31.47475;34.43438 31.47155;34.41441 31.45546;34.40814 31.45154;34.39877 31.44435;34.38683 31.43413;34.37403 31.42211;34.35969 31.41049;34.34452 31.38816;34.33656 31.37844;34.33298 31.36747;34.32887 31.35813;34.31906 31.34882;34.31265 31.33982;34.31371 31.33161;34.31626 31.32417;34.31722 31.30326;34.31615 31.29432;34.31156 31.28505;34.30824 31.2809;34.3048 31.27838;34.28306 31.26989;34.27648 31.27143;34.26816 31.2719;34.26644 31.27246
+route haifa_acre_naqura_road road draft 1933 42.2 0.94 482 46 34.99686 32.81952;34.99613 32.81887;34.99631 32.81788;34.99984 32.81386;34.99876 32.81119;34.99784 32.81034;34.99878 32.80846;35.00199 32.80559;35.00777 32.80206;35.01343 32.79771;35.01971 32.79417;35.02478 32.79031;35.02729 32.78983;35.03565 32.79337;35.04522 32.79876;35.04893 32.80216;35.05179 32.80643;35.06297 32.80973;35.07042 32.81553;35.07585 32.82146;35.07938 32.83245;35.09077 32.85014;35.09194 32.85542;35.09413 32.87884;35.09386 32.88424;35.09195 32.89569;35.08975 32.90147;35.07554 32.92378;35.07789 32.93168;35.08928 32.9585;35.09043 32.96232;35.09097 32.97998;35.09437 32.99668;35.09983 33.01761;35.1016 33.03412;35.10313 33.04149;35.10277 33.04644;35.10058 33.05245;35.10082 33.05595;35.10847 33.06699;35.11147 33.07332;35.1124 33.07678;35.11195 33.07916;35.10777 33.08643;35.10643 33.09154;35.10484 33.09305
+route jerusalem_hebron_beersheba_road road draft 1946 81.6 0.97 341 111 35.22569 31.77933;35.22362 31.78044;35.22298 31.78031;35.22263 31.77942;35.22295 31.77264;35.22582 31.76641;35.22443 31.76239;35.21531 31.74305;35.20691 31.73027;35.20268 31.71896;35.19596 31.70701;35.19027 31.70084;35.1857 31.69773;35.18082 31.69584;35.17296 31.69505;35.16941 31.69422;35.16449 31.68954;35.15841 31.68522;35.15147 31.68204;35.14944 31.68184;35.149 31.68142;35.14982 31.67859;35.1492 31.67731;35.14145 31.67253;35.14124 31.67081;35.1465 31.65903;35.14529 31.65609;35.14313 31.65319;35.13974 31.65123;35.13409 31.64925;35.13257 31.64675;35.13171 31.6426;35.13258 31.6359;35.13223 31.62658;35.13151 31.62579;35.12486 31.623;35.11916 31.62114;35.11654 31.619;35.11417 31.61337;35.1131 31.60396;35.10955 31.60048;35.10764 31.59775;35.10475 31.59014;35.09917 31.57973;35.0985 31.57368;35.10031 31.55937;35.09815 31.54962;35.09897 31.53994;35.09837 31.5317;35.09886 31.52968;35.10013 31.52769;35.09843 31.5273;35.09159 31.52839;35.08767 31.52665;35.08499 31.52407;35.08177 31.51865;35.07749 31.51349;35.07845 31.50329;35.07795 31.49829;35.0769 31.49645;35.07559 31.49515;35.06409 31.48894;35.05386 31.48601;35.04816 31.48322;35.0439 31.48279;35.04367 31.48199;35.04487 31.47906;35.04446 31.47771;35.03451 31.4692;35.02437 31.45354;35.02069 31.44571;35.0165 31.44284;35.00691 31.43938;34.9999 31.43529;34.99578 31.42873;34.99248 31.42502;34.97679 31.41355;34.96801 31.40577;34.96599 31.40309;34.96299 31.39576;34.95698 31.38962;34.952 31.37499;34.94637 31.36942;34.94607 31.36838;34.94879 31.3652;34.94833 31.36315;34.9464 31.36131;34.93898 31.35948;34.93575 31.3574;34.93437 31.35379;34.93343 31.34418;34.92673 31.33234;34.91956 31.32393;34.90834 31.31365;34.90008 31.30825;34.89153 31.30034;34.8787 31.2911;34.87503 31.2895;34.86259 31.28628;34.85422 31.2815;34.84762 31.27594;34.83831 31.26576;34.82727 31.25859;34.81764 31.25104;34.80911 31.24576;34.7995 31.24132;34.79281 31.23954;34.79097 31.24023;34.78872 31.24233;34.78586 31.24538;34.78538 31.24664
+route jerusalem_nablus_nazareth_road road draft 1946 127.0 0.95 341 184 35.22569 31.77933;35.22586 31.78468;35.22918 31.79069;35.23397 31.80175;35.23497 31.80697;35.23386 31.8111;35.22965 31.81751;35.22846 31.82565;35.22941 31.83705;35.23038 31.84155;35.22992 31.84578;35.22869 31.84913;35.22583 31.85342;35.2224 31.86114;35.21883 31.87473;35.21886 31.87753;35.22026 31.88309;35.22025 31.88625;35.21559 31.89283;35.21118 31.90173;35.21224 31.9058;35.21602 31.91157;35.21739 31.91989;35.22234 31.92719;35.22104 31.93733;35.21668 31.94406;35.21646 31.95214;35.21729 31.95516;35.2191 31.95782;35.22347 31.95863;35.22466 31.95956;35.22793 31.96588;35.22824 31.97008;35.22888 31.97138;35.23023 31.97212;35.23436 31.97258;35.23523 31.97361;35.23587 31.98214;35.23465 31.98394;35.22916 31.9892;35.22858 31.99478;35.22649 31.99893;35.22695 32.00022;35.22955 32.00188;35.2372 32.00099;35.24608 31.99634;35.24811 31.99606;35.24991 31.99669;35.25235 31.99948;35.25552 32.00595;35.26347 32.01222;35.267 32.01895;35.27315 32.02427;35.27469 32.02672;35.27399 32.03014;35.27187 32.03439;35.2682 32.04006;35.26392 32.04535;35.2621 32.04954;35.25605 32.05388;35.25299 32.05483;35.24841 32.05529;35.24712 32.05606;35.24729 32.05868;35.2487 32.06049;35.24969 32.06032;35.2475 32.06438;35.24719 32.0679;35.24765 32.0707;35.24891 32.07286;35.25528 32.07618;35.25865 32.07886;35.26325 32.08353;35.26486 32.08749;35.26437 32.09201;35.26091 32.10033;35.25986 32.10104;35.2622 32.10477;35.25976 32.10888;35.25883 32.12032;35.25584 32.12506;35.25701 32.13544;35.25723 32.14953;35.25835 32.15521;35.26139 32.16303;35.26982 32.17329;35.27513 32.1815;35.28197 32.19061;35.28368 32.1954;35.28397 32.20039;35.28202 32.20866;35.26594 32.22029;35.26042 32.21941;35.25671 32.22105;35.25069 32.22492;35.24653 32.2292;35.23815 32.23179;35.23048 32.23838;35.227 32.24028;35.22095 32.24143;35.20667 32.24116;35.19755 32.24302;35.19455 32.24485;35.18881 32.24961;35.18687 32.2519;35.18548 32.25556;35.18636 32.26329;35.18606 32.26708;35.17925 32.27239;35.17699 32.27452;35.17637 32.27584;35.17706 32.27779;35.18079 32.28197;35.18413 32.29417;35.18259 32.29812;35.18225 32.30308;35.18095 32.30386;35.17731 32.30362;35.17667 32.30453;35.17912 32.30818;35.1841 32.31185;35.1861 32.31411;35.18897 32.31838;35.19032 32.322;35.19128 32.32266;35.19602 32.32348;35.20171 32.32847;35.20409 32.33702;35.20345 32.33972;35.20001 32.347;35.19997 32.34941;35.20161 32.3522;35.20836 32.36046;35.21177 32.36665;35.21269 32.36977;35.2134 32.37802;35.21458 32.38328;35.21404 32.38777;35.22286 32.40034;35.22799 32.41781;35.23093 32.42289;35.23622 32.4247;35.2493 32.42529;35.25496 32.42662;35.26415 32.43029;35.27403 32.43698;35.28483 32.43995;35.28774 32.44126;35.29223 32.44503;35.29579 32.44948;35.29806 32.45451;35.29986 32.46073;35.30279 32.4662;35.3025 32.47037;35.29779 32.48066;35.29735 32.48518;35.2993 32.49211;35.2998 32.50037;35.30062 32.50344;35.31421 32.52124;35.31624 32.52551;35.31666 32.53413;35.3159 32.5605;35.31472 32.56453;35.31001 32.57091;35.29459 32.58528;35.288 32.5942;35.28801 32.60741;35.28724 32.61442;35.28719 32.62237;35.29032 32.65697;35.29054 32.66492;35.28937 32.67314;35.28896 32.67375;35.28804 32.67378;35.28529 32.67539;35.28523 32.67992;35.28888 32.68938;35.28934 32.69641;35.29964 32.7042;35.30148 32.70504;35.30358 32.70517;35.30478 32.70467;35.30431 32.70404
+route tel_aviv_tulkarm_nablus_road road draft 1946 66.6 0.95 437 78 34.7907 32.07785;34.79731 32.08163;34.80693 32.08386;34.81851 32.08975;34.82713 32.09234;34.83613 32.09362;34.8548 32.09358;34.86111 32.09311;34.86797 32.09163;34.87592 32.09148;34.88355 32.08992;34.88661 32.09088;34.89477 32.09516;34.91013 32.09708;34.92573 32.10338;34.93194 32.10359;34.93448 32.10502;34.93644 32.10758;34.93705 32.11108;34.93744 32.11792;34.93687 32.12691;34.9379 32.13295;34.93993 32.13808;34.94474 32.1469;34.94842 32.15817;34.95885 32.17823;34.95993 32.1824;34.95926 32.18604;34.95858 32.18702;34.95887 32.18805;34.9598 32.18923;34.96541 32.1928;34.96869 32.19775;34.97223 32.21012;34.97834 32.22038;34.98303 32.23233;34.99166 32.2476;34.99385 32.25486;35.008 32.28689;35.01522 32.30685;35.0168 32.30889;35.01929 32.3107;35.02436 32.31195;35.02934 32.31525;35.03283 32.31646;35.04255 32.31889;35.05568 32.3191;35.06159 32.3187;35.08127 32.31597;35.08793 32.31557;35.09686 32.31157;35.12833 32.30435;35.12984 32.30271;35.13221 32.29553;35.13662 32.28785;35.14652 32.27971;35.1494 32.27434;35.15311 32.27208;35.16497 32.26729;35.16917 32.26494;35.17339 32.2605;35.17717 32.25343;35.17866 32.25326;35.18254 32.25534;35.18453 32.25512;35.18697 32.25126;35.18903 32.24947;35.19612 32.24388;35.1992 32.24287;35.20672 32.24115;35.22187 32.24135;35.22676 32.2406;35.22985 32.23885;35.23726 32.2325;35.23938 32.23143;35.24617 32.22981;35.25138 32.22459;35.26036 32.21955
+route haifa_nazareth_tiberias_road road draft 1946 63.9 0.97 225 83 34.99686 32.81952;34.99613 32.81887;34.99631 32.81788;34.99989 32.81353;34.99789 32.80968;35.00079 32.8066;35.0084 32.80162;35.02473 32.789;35.04026 32.77508;35.05961 32.75632;35.07525 32.74297;35.08071 32.73661;35.08808 32.73366;35.10007 32.72508;35.10676 32.7222;35.11328 32.72133;35.1219 32.71472;35.1343 32.71136;35.15538 32.70883;35.16314 32.70664;35.16885 32.70749;35.17217 32.70725;35.18712 32.70341;35.20065 32.70326;35.21269 32.69936;35.21951 32.69645;35.22567 32.69262;35.23042 32.68852;35.23183 32.68435;35.23756 32.68012;35.24533 32.67677;35.25019 32.67402;35.25413 32.67299;35.25863 32.67457;35.27116 32.68259;35.28034 32.6906;35.28632 32.69377;35.2989 32.7038;35.30664 32.70604;35.30668 32.70724;35.30419 32.70958;35.30438 32.71126;35.30738 32.71316;35.3118 32.71312;35.31285 32.71355;35.31323 32.71518;35.31138 32.71839;35.31133 32.72011;35.32156 32.72956;35.32298 32.73516;35.33237 32.74198;35.33471 32.74489;35.33723 32.74968;35.3423 32.7563;35.34634 32.75979;35.34992 32.76052;35.36051 32.76106;35.37168 32.76335;35.38266 32.76869;35.39849 32.77501;35.40208 32.77605;35.40946 32.77719;35.41562 32.78013;35.42281 32.7819;35.42827 32.78238;35.44567 32.7821;35.44751 32.78276;35.4526 32.7863;35.46315 32.78846;35.47807 32.78845;35.49227 32.7867;35.5 32.78806;35.50839 32.78872;35.51142 32.78986;35.51369 32.79139;35.51649 32.7952;35.51693 32.79666;35.51891 32.79783;35.52262 32.7964;35.52714 32.79747;35.52908 32.79731;35.53266 32.79581;35.5333 32.79442
+route jerusalem_jericho_road road draft 1946 32.1 0.96 439 58 35.22569 31.77933;35.22562 31.78292;35.22655 31.78395;35.23774 31.78424;35.23884 31.78325;35.24188 31.77528;35.2447 31.77387;35.24892 31.77278;35.25175 31.77087;35.2526 31.76965;35.25545 31.76952;35.26529 31.77587;35.26791 31.77613;35.26858 31.77574;35.27048 31.77679;35.27075 31.77646;35.27275 31.77703;35.27307 31.77671;35.27848 31.78054;35.28801 31.7826;35.29941 31.79562;35.30208 31.79789;35.30487 31.79942;35.30841 31.80034;35.31668 31.80109;35.32147 31.8023;35.3298 31.80698;35.33698 31.8087;35.34068 31.81025;35.34592 31.81465;35.35679 31.81668;35.36005 31.8165;35.3659 31.8149;35.36999 31.81486;35.37196 31.81534;35.38055 31.82007;35.38635 31.82523;35.3879 31.8257;35.38951 31.82555;35.39019 31.8248;35.39011 31.81983;35.39137 31.81457;35.39268 31.8112;35.39585 31.80715;35.40091 31.80592;35.403 31.8033;35.405 31.80224;35.4105 31.80087;35.41777 31.79769;35.42426 31.79664;35.43895 31.80764;35.44217 31.81087;35.443 31.81356;35.44427 31.82356;35.45146 31.84882;35.45332 31.85193;35.45479 31.85316;35.46 31.85576
+route tiberias_metula_road road draft 1946 58.1 0.91 418 68 35.5333 32.79442;35.5347 32.79877;35.53443 32.79938;35.5301 32.80216;35.52206 32.80947;35.51652 32.8195;35.51035 32.82659;35.50947 32.82961;35.5091 32.83631;35.5112 32.84125;35.52729 32.86386;35.53054 32.86931;35.53135 32.87008;35.53704 32.87211;35.54324 32.87688;35.5453 32.88023;35.54743 32.88644;35.54815 32.88771;35.54938 32.88827;35.54938 32.88926;35.54468 32.89726;35.54073 32.90223;35.54129 32.90344;35.54597 32.90579;35.54717 32.908;35.5443 32.91347;35.54335 32.91767;35.54277 32.93459;35.54487 32.94166;35.54313 32.94898;35.54158 32.95958;35.54332 32.96352;35.55158 32.97443;35.55511 32.98097;35.56398 33.00276;35.56361 33.00437;35.56096 33.00866;35.56213 33.0135;35.56791 33.01741;35.5697 33.02098;35.57069 33.02558;35.57107 33.03424;35.57067 33.04831;35.57396 33.0701;35.57266 33.0837;35.57341 33.09084;35.57343 33.09915;35.57092 33.12213;35.56822 33.13337;35.56943 33.14627;35.56953 33.15855;35.56847 33.16965;35.56558 33.17735;35.56508 33.18709;35.56536 33.19029;35.56739 33.19637;35.56935 33.21646;35.57048 33.21911;35.57522 33.22585;35.58054 33.24196;35.58022 33.24335;35.57778 33.24568;35.57213 33.2485;35.56961 33.25645;35.56981 33.26356;35.57424 33.27074;35.57577 33.27765;35.57536 33.27881
+route gaza_beersheba_road road draft 1946 45.7 0.96 358 55 34.46076 31.50912;34.47082 31.50312;34.47832 31.49745;34.48678 31.48862;34.49413 31.48278;34.50074 31.48077;34.51565 31.47893;34.52217 31.47653;34.53546 31.46778;34.55457 31.4573;34.56223 31.45227;34.57343 31.44743;34.58375 31.44173;34.59115 31.43592;34.59975 31.43088;34.60654 31.42227;34.61073 31.41522;34.61335 31.40248;34.61381 31.39021;34.61443 31.38667;34.61648 31.38162;34.61798 31.37574;34.62574 31.36641;34.64298 31.34962;34.64656 31.34717;34.65213 31.3447;34.65326 31.34334;34.65456 31.3398;34.65938 31.33669;34.67004 31.33302;34.67413 31.33319;34.68023 31.33475;34.68994 31.33366;34.69523 31.33394;34.69658 31.33321;34.70012 31.32881;34.7032 31.32372;34.70385 31.32133;34.70374 31.31355;34.70853 31.30754;34.70998 31.30094;34.71155 31.29774;34.71528 31.29493;34.72196 31.29137;34.72622 31.28793;34.73484 31.27907;34.73726 31.27572;34.73971 31.27084;34.74254 31.26831;34.75433 31.2616;34.76189 31.25557;34.77332 31.25226;34.78395 31.24652;34.78499 31.24626;34.78538 31.24664
+route beersheba_auja_road road draft 1946 69.9 0.97 261 77 34.78538 31.24664;34.78695 31.24386;34.79402 31.23727;34.79753 31.23201;34.80098 31.22072;34.80203 31.21544;34.80401 31.21001;34.80492 31.20399;34.80684 31.19738;34.80706 31.18043;34.80472 31.164;34.80613 31.15516;34.80491 31.14671;34.80542 31.13519;34.80651 31.1299;34.80798 31.1266;34.81171 31.12141;34.82035 31.11128;34.82177 31.108;34.82207 31.10204;34.82303 31.10092;34.82794 31.09776;34.82993 31.09167;34.83409 31.08549;34.83908 31.07546;34.83842 31.06632;34.83379 31.06149;34.83102 31.0565;34.80519 31.0366;34.79032 31.02098;34.78129 31.01459;34.77774 31.01282;34.77578 31.01246;34.76346 31.01561;34.76158 31.01531;34.7609 31.01406;34.75921 31.00408;34.76199 30.99334;34.76134 30.99179;34.75216 30.98452;34.72421 30.971;34.71105 30.96099;34.70396 30.9572;34.69683 30.95518;34.6775 30.95208;34.67385 30.9485;34.66057 30.94707;34.65502 30.9457;34.65323 30.94433;34.64789 30.93636;34.64092 30.93199;34.6349 30.92653;34.63194 30.92465;34.62888 30.92364;34.62487 30.9232;34.61728 30.92787;34.60679 30.93019;34.60518 30.92916;34.60133 30.92297;34.59443 30.91981;34.58566 30.91813;34.58336 30.91617;34.57899 30.91098;34.57525 30.90814;34.5551 30.90038;34.55032 30.8995;34.54487 30.90086;34.53995 30.90142;34.52619 30.90204;34.52124 30.90158;34.50057 30.89494;34.4856 30.8939;34.48196 30.89325;34.44598 30.88287;34.43721 30.88089;34.43465 30.87916;34.43364 30.8777
+meta body_check -352026697
diff --git a/docs/routes.md b/docs/routes.md
index b1efc57da..618b6f81a 100644
--- a/docs/routes.md
+++ b/docs/routes.md
@@ -12,6 +12,7 @@ The map draws the railways and main roads of 1948, each from its sourced date, a
| Tracer | `tools/routes_1948.py` (tests: `tools/tests/test_routes_1948.py`) |
| Map layer | `unity/Assets/Scripts/Map/Routes/` (`RoutePaths`, `RouteLayer`, `RouteTrain`, `TrainModels`) |
| Shader and materials | `unity/Assets/Shaders/Route.shader`; `Resources/Routes/Rail.mat`, `Road.mat` (`RouteMaterialAssets.Create`) |
+| Runtime form (generated) | `content/map/route_paths_1948.tsv` (`tools/route_paths_bake.py`; tests: `tools/tests/test_route_paths_bake.py`) |
| Baked ribbons (generated) | `unity/Assets/Resources/Routes/RouteRibbons.bytes` (`RouteRibbonBake.Bake`; tests: `tools/tests/test_route_ribbon_bake.py`) |
| Tests | `unity/Assets/Tests/EditMode/RouteTests.cs` |
@@ -263,6 +264,18 @@ measurement in `docs/units.md`:
**Toggles.** `routes` (the ribbons) and `train` (when there is one) are visual toggles, so `?vprofile` prices each one.
+**Runtime form** (issue #321). Boot reads the traced lines from `content/map/route_paths_1948.tsv` instead of parsing
+the YAML (about 125 ms at `--cpu 4`), as the localities do since #291.
+- `tools/route_paths_bake.py` writes it: one row per route, its points in one field, the layout's version, the YAML's
+ FNV-1a check (the same check the ribbon bake's header holds), the counts of routes and points, and a last
+ `body_check` row (FNV-1a over the route rows).
+- The YAML still ships. When the runtime file is missing, of another version, made from another YAML, cut short (even
+ inside a number) or edited by hand, the map reads the YAML with a warning (`...; reading the YAML`): the same routes,
+ only slower.
+- Rerun `uv run tools/route_paths_bake.py` after `tools/routes_1948.py` rewrites the YAML. `test_route_paths_bake.py`
+ fails a stale file and pins a fingerprint of the C# readers; Unity's `RoutePathsRuntimeTests` compares every route
+ and point with the YAML's.
+
**Baked ribbons** (issue #321). Boot places the ribbon meshes from a bake instead of deriving them, as the terrain water
does (#320, docs/visual-v1.md).
- `RouteRibbonFile` (format) and the editor's `RouteRibbonBake` write every mesh `RouteLayer.Build` draws, in its order
diff --git a/docs/visual-v1.md b/docs/visual-v1.md
index e94748eec..4da87b89f 100644
--- a/docs/visual-v1.md
+++ b/docs/visual-v1.md
@@ -2586,3 +2586,38 @@ The biome phase went from about 440 ms to 120 ms (82-88 terrain object, 38-41 th
population, routes, unit clearings, the `?kitscale` flags fall back). About 300-400 ms, medium risk (many inputs).
Without a bake, the hill scatter's per-cell checks could be reordered for 10-20 ms with the same trees.
- `heightmap decoded` (about 190 ms): smaller, untested.
+
+### #321 round 2: the units' step (T47)
+
+The `units placed` span #529 uncovered, split by four more `?bootlog` markers. Branch build with the markers only, one
+`--exclusive` run of 3 cold loads at `--cpu 4`, median ms: `route paths read` 127, `route corridors` 8, `footprints` 3,
+`unit data read` 51, `units placed` (now the unit spots alone: `UnitGround` and `UnitPlacer.PlaceAll`) 184.
+
+- **Route paths** (127 ms): YamlDotNet over route_paths_1948.yaml's 1,544 points. `tools/route_paths_bake.py` writes
+ `content/map/route_paths_1948.tsv` (29 KB: one row per route, its points in one field, the version, the YAML's FNV-1a
+ check, the counts of routes and points, and a last `body_check` row, FNV-1a over the route rows), and
+ `RoutePaths.ParseRuntime` reads it with the YAML reader's checks. The YAML still ships (WebGL now fetches both: 29 KB
+ more). A runtime file that is missing, of another version, made from another YAML, cut anywhere (even inside a
+ number: the review of #547 found that version 1's counts missed that case, so version 2 adds `body_check`) or edited
+ by hand is refused with a warning and the YAML is read. CI: `test_route_paths_bake.py` fails a stale file and pins a fingerprint
+ of the C# readers; Unity's `RoutePathsRuntimeTests` compares every route and point bit for bit.
+- **Unit spots** (184 ms): `UnitPlacer.PlaceAll` made every hex's candidate spots (19 a hex in the compact rounds, with
+ their trigonometry) for each anchor and round, then dropped all but the seven hexes within its one-hex limit. It now
+ lists those seven first and makes only their candidates, in the same order. `UnitPlacerSpeedTests` keeps the old
+ algorithm verbatim and gets exactly its spots and skips on four grounds, from all clear to none clear.
+- **Not changed:** `unit data read` (about 35-51 ms; the unit YAML is also read again by `GameRoot`), the corridors and
+ the footprints.
+
+Base `abe2263` against the branch, ABBA under one `--exclusive` hold (machine load 3.7-4.6), median of 3 each:
+
+| | base round 1 | branch round 1 | branch round 2 | base round 2 |
+|---|---|---|---|---|
+| `map_build_ms` | 2507 | 2214 | 2196 | 2379 |
+| units' span (base: `units placed`; branch: its five phases) | 315 | 90 | 91 | 291 |
+| `start screen shown` | 576 | 427 | 426 | 528 |
+| `first_frame_ms` | 9165 | 8249 | 8217 | 8351 |
+
+The units' span goes from about 300 to 90 ms. The map build is at least 165 ms shorter: the closest base and branch
+rounds differ by 165 ms, and the two base rounds spread by 128 ms, so the mean difference (about 240 ms) is not a firm
+figure.
+`start screen shown` falls by about 120 ms, since the units layer places the tokens again there.
diff --git a/sim/Statecraft.Sim.Tests/SaveGameTests.cs b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
index 6b60fdee7..1d8011b84 100644
--- a/sim/Statecraft.Sim.Tests/SaveGameTests.cs
+++ b/sim/Statecraft.Sim.Tests/SaveGameTests.cs
@@ -407,6 +407,34 @@ public class SaveGameTests
finally { if (Directory.Exists(copy)) Directory.Delete(copy, true); } // review M13: no temp copy left behind
}
+ /// <summary>content/map/route_paths_1948.tsv, the baked runtime form of route_paths_1948.yaml the map reads at boot
+ /// (issue #321), is map-only like the YAML: the sim never reads it, so it is outside the content hash and no save or
+ /// golden depends on it. Checked as the localities' file: on the fixture (added) and on the real content (removed).</summary>
+ [Fact]
+ public void TheRoutePathsRuntimeFileIsOutsideTheContentHash()
+ {
+ var dir = Fixture.Write();
+ var before = ContentLoader.Load(dir).Hash;
+ File.WriteAllText(Path.Combine(dir, "map", "route_paths_1948.tsv"), "meta\tversion\t2\n");
+ Assert.Equal(before, ContentLoader.Load(dir).Hash);
+
+ var real = RealContentTests.ContentRoot();
+ Assert.True(File.Exists(Path.Combine(real, "map", "route_paths_1948.tsv")));
+ var copy = Path.Combine(Path.GetTempPath(), "statecraft-noroutetsv-" + Guid.NewGuid().ToString("N"));
+ try
+ {
+ foreach (var f in Directory.GetFiles(real, "*", SearchOption.AllDirectories))
+ {
+ var rel = Path.GetRelativePath(real, f);
+ if (rel.Replace('\\', '/') == "map/route_paths_1948.tsv") continue;
+ Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(copy, rel))!);
+ File.Copy(f, Path.Combine(copy, rel));
+ }
+ Assert.Equal(ContentLoader.Load(real).Hash, ContentLoader.Load(copy).Hash);
+ }
+ finally { if (Directory.Exists(copy)) Directory.Delete(copy, true); }
+ }
+
[Fact]
public void TheContentHashChangesWithEventsAndSettlements()
{
diff --git a/tools/README.md b/tools/README.md
index 3c4778ecb..a7e9b943b 100644
--- a/tools/README.md
+++ b/tools/README.md
@@ -18,6 +18,9 @@ Offline data tools (uv inline-script Python). Run from the repo root.
into `tools/.cache/pal250k-1946/`, not committed): it reads the hand-written routes, sources and waypoints in
`content/map/routes_1948.yaml` and writes the traced lines to `content/map/route_paths_1948.yaml` (committed; the map
draws it, the sim never reads it). `--preview` writes each traced segment over the map for checking by eye.
+- `route_paths_bake.py [--check]` bakes `content/map/route_paths_1948.yaml` into `content/map/route_paths_1948.tsv`
+ (committed), the compact runtime form the map reads at boot (issue #321). Rerun it after `routes_1948.py`:
+ `test_route_paths_bake.py` fails a stale bake, and `--check` does the same.
- `localities_bake.py [--check]` bakes `content/map/localities_1948.yaml` (the sourced 1948 localities, edited by hand)
into `content/map/localities_1948.tsv` (committed), the compact runtime form the map reads at boot. Rerun it after
editing the YAML: `test_localities.py` fails a stale bake, and `--check` does the same.
diff --git a/tools/route_paths_bake.py b/tools/route_paths_bake.py
new file mode 100644
index 000000000..e39aac419
--- /dev/null
+++ b/tools/route_paths_bake.py
@@ -0,0 +1,111 @@
+# /// script
+# requires-python = ">=3.11"
+# dependencies = ["pyyaml==6.0.3"]
+# ///
+"""Bakes content/map/route_paths_1948.yaml (written by tools/routes_1948.py) into content/map/route_paths_1948.tsv, the
+compact runtime form the player reads at boot (RoutePaths.ParseRuntime in Unity).
+
+The boot budget is the reason (issue #321, docs/visual-v1.md): parsing the YAML's 1,500 points with YamlDotNet cost about
+125 ms of the map build at cpu 4, as the localities' YAML did before tools/localities_bake.py (#291). The YAML still
+ships and stays the file the tools and the route ribbons' bake read; the runtime file carries the YAML's check
+(RouteRibbonFile.Check: FNV-1a over its UTF-8 bytes) and this layout's version, and the player reads the YAML instead,
+with a warning, when either does not match. Rows, tab-separated:
+
+ meta version <VERSION>
+ meta yaml_check <signed int32>
+ meta routes <number of route rows>
+ route id kind status from to length_km on_symbol max_gap_m point_count points
+ ...
+ meta body_check <signed int32> (the last row)
+
+`to` is empty when the route has no end; `points` is "lon lat" pairs joined by ';', each number as Python's shortest
+round-trip form of the YAML's value. `body_check` is FNV-1a over the UTF-8 bytes of every route row, each with its
+'\n', in order. The reader requires it as the last row and recomputes it, so a file cut anywhere (even inside a
+number, review of #547) or edited by hand is refused; the counts give the clearer message for a lost row or point. Lines starting with '#' are comments. No field may hold a tab or a line break.
+
+Usage: uv run tools/route_paths_bake.py [--check]
+--check exits 1 when the committed runtime file differs from a fresh bake (pytest runs the same comparison:
+tools/tests/test_route_paths_bake.py).
+"""
+import argparse
+import struct
+import sys
+from pathlib import Path
+
+import yaml
+
+ROOT = Path(__file__).resolve().parents[1]
+SOURCE = ROOT / "content" / "map" / "route_paths_1948.yaml"
+RUNTIME = ROOT / "content" / "map" / "route_paths_1948.tsv"
+VERSION = 2 # RoutePaths.RuntimeVersion (2: the body_check row, review of #547)
+COLUMNS = ["route", "id", "kind", "status", "from", "to", "length_km", "on_symbol", "max_gap_m", "point_count", "points"]
+
+
+def yaml_check(data: bytes) -> int:
+ """RouteRibbonFile.Check: FNV-1a over the bytes, as a signed int32."""
+ h = 2166136261
+ for b in data:
+ h = ((h ^ b) * 16777619) & 0xFFFFFFFF
+ return struct.unpack("<i", struct.pack("<I", h))[0]
+
+
+def body_check(rows: list[str]) -> int:
+ """RoutePaths.BodyCheck: FNV-1a over the route rows' UTF-8 bytes, each followed by '\n', as a signed int32."""
+ return yaml_check("".join(r + "\n" for r in rows).encode("utf-8"))
+
+
+def _number(value, where: str) -> str:
+ if isinstance(value, bool) or not isinstance(value, (int, float)):
+ raise ValueError(f"{SOURCE.name}: {where}: {value!r} is not a number")
+ return repr(float(value)) if isinstance(value, float) else str(value)
+
+
+def _field(value, where: str) -> str:
+ text = "" if value is None else str(value)
+ if any(c in text for c in "\t\r\n;"):
+ raise ValueError(f"{SOURCE.name}: {where}: a field holds a tab, a ';' or a line break: {text!r}")
+ return text
+
+
+def bake(data: bytes) -> str:
+ """The runtime file for the YAML file's bytes: deterministic, so a fresh bake equals the committed file."""
+ doc = yaml.safe_load(data.decode("utf-8"))
+ out = [
+ "# Generated by tools/route_paths_bake.py from route_paths_1948.yaml. Do not edit: edit the YAML (tools/routes_1948.py)",
+ "# and rerun the tool. The runtime form the map reads at boot (map-only, outside the content hash).",
+ "#" + "\t".join(COLUMNS),
+ f"meta\tversion\t{VERSION}",
+ f"meta\tyaml_check\t{yaml_check(data)}",
+ f"meta\troutes\t{len(doc['routes'])}",
+ ]
+ rows = []
+ for r in doc["routes"]:
+ where = f"route '{r.get('id')}'"
+ points = ";".join(f"{_number(p[0], where)} {_number(p[1], where)}" for p in r["points"])
+ row = ["route", r["id"], r["kind"], r["status"], r["from"], r.get("to") or "", _number(r["length_km"], where),
+ _number(r["on_symbol"], where), _number(r["max_gap_m"], where), str(len(r["points"]))]
+ rows.append("\t".join(_field(v, where) for v in row) + "\t" + points)
+ out += rows
+ out.append(f"meta\tbody_check\t{body_check(rows)}")
+ return "\n".join(out) + "\n"
+
+
+def main() -> int:
+ ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
+ ap.add_argument("--check", action="store_true", help="fail when the committed runtime file is stale")
+ args = ap.parse_args()
+ fresh = bake(SOURCE.read_bytes())
+ if args.check:
+ current = RUNTIME.read_text(encoding="utf-8") if RUNTIME.exists() else ""
+ if current != fresh:
+ print(f"{RUNTIME.relative_to(ROOT)} is stale: run uv run tools/route_paths_bake.py", file=sys.stderr)
+ return 1
+ print(f"{RUNTIME.relative_to(ROOT)} is up to date")
+ return 0
+ RUNTIME.write_text(fresh, encoding="utf-8", newline="\n")
+ print(f"wrote {RUNTIME.relative_to(ROOT)} ({len(fresh)} characters)")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/tools/tests/test_route_paths_bake.py b/tools/tests/test_route_paths_bake.py
new file mode 100644
index 000000000..6f40bf9c9
--- /dev/null
+++ b/tools/tests/test_route_paths_bake.py
@@ -0,0 +1,93 @@
+"""The route paths' runtime form (content/map/route_paths_1948.tsv, issue #321) is the bake of the shipped YAML.
+
+The player reads the runtime file at boot instead of parsing route_paths_1948.yaml, and refuses it (reading the YAML, with
+a warning: slower, never wrong) when its version or its check of the YAML does not match (RoutePaths.ParseRuntime). CI
+runs no Unity, so this checks here:
+- the committed file is a fresh bake of the YAML (tools/route_paths_bake.py --check), so the YAML and the runtime file
+ never drift in a merged tree;
+- the bake's VERSION is RoutePaths.RuntimeVersion;
+- a fingerprint of the C# that reads the runtime file and the YAML (comments and whitespace left out), so a change to
+ either reader fails here until someone checks the two still agree (Unity's RoutePathsRuntimeTests compares every
+ route and point), bumps the version if the layout changed, re-bakes and re-pins. The bake checks the file's data; it
+ cannot check the C# that reads it (review of #529, S1).
+"""
+import hashlib
+import re
+import sys
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+sys.path.insert(0, str(ROOT / "tools"))
+import route_paths_bake as bake # noqa: E402
+
+SCRIPTS = ROOT / "unity/Assets/Scripts/Map/Routes"
+REBAKE = "run uv run tools/route_paths_bake.py"
+
+# The fingerprint of the readers (code_fingerprint). Re-pin only after RoutePathsRuntimeTests passes in Unity, with
+# RoutePaths.RuntimeVersion and route_paths_bake.VERSION bumped together if the runtime layout changed.
+PINNED_CODE = "a7cc9cf147bca7ec7bcf3a769fd86550bd4a92bbcfeea98ab0f74e60908fca00"
+
+
+def member(text: str, signature: str) -> str:
+ """The text of the member starting at signature, through its closing brace."""
+ i = text.index(signature)
+ depth = 0
+ for j in range(i, len(text)):
+ if text[j] == "{":
+ depth += 1
+ elif text[j] == "}":
+ depth -= 1
+ if depth == 0:
+ return text[i:j + 1]
+ raise AssertionError(f"{signature}: no end")
+
+
+def code_fingerprint() -> str:
+ paths = (SCRIPTS / "RoutePaths.cs").read_text()
+ ribbon = (SCRIPTS / "RouteRibbonFile.cs").read_text()
+ parts = [
+ member(paths, "public sealed class RoutePath\n"),
+ member(paths, "public static List<RoutePath> ReadRuntimeOrYaml("),
+ member(paths, "public static List<RoutePath> ParseRuntime("),
+ member(paths, "static RoutePathFile RuntimeDoc("),
+ member(paths, "public static int BodyCheck("),
+ member(paths, "static (int version, int check, List<RoutePath> routes) RuntimeRows("),
+ member(paths, "public static List<RoutePath> Parse("),
+ member(paths, "static List<RoutePath> Validate("),
+ member(ribbon, "public static int Check("),
+ ]
+ code = "\n".join(re.sub(r"\s+", " ", re.sub(r"//[^\n]*", "", p)).strip() for p in parts)
+ return hashlib.sha256(code.encode()).hexdigest()
+
+
+def test_the_runtime_file_is_the_bake_of_the_yaml():
+ assert bake.RUNTIME.read_text(encoding="utf-8") == bake.bake(bake.SOURCE.read_bytes()), f"stale: {REBAKE}"
+
+
+def test_the_bake_and_the_reader_share_a_version():
+ m = re.search(r"\bRuntimeVersion\s*=\s*(\d+)\b", (SCRIPTS / "RoutePaths.cs").read_text())
+ assert m and int(m.group(1)) == bake.VERSION, "RoutePaths.RuntimeVersion and route_paths_bake.VERSION differ"
+
+
+def test_the_readers_are_the_ones_the_runtime_file_was_checked_against():
+ assert code_fingerprint() == PINNED_CODE, (
+ f"the C# that reads route_paths_1948.yaml or its runtime form changed (fingerprint {code_fingerprint()}): run "
+ "RoutePathsRuntimeTests in Unity, bump the version on both sides if the layout changed, re-bake, then re-pin PINNED_CODE")
+
+
+def test_the_check_is_the_ribbon_bakes():
+ """The runtime file's yaml_check is the same FNV-1a the ribbon bake's header holds for the YAML."""
+ from test_route_ribbon_bake import text_check
+ assert bake.yaml_check(bake.SOURCE.read_bytes()) == text_check(bake.SOURCE)
+
+
+def test_the_file_ends_with_its_body_check():
+ """The last row is body_check over the route rows (review of #547, S1): a file cut anywhere, even inside a number,
+ loses it or no longer matches it, and RoutePaths.RuntimeRows refuses it."""
+ lines = bake.RUNTIME.read_text(encoding="utf-8").rstrip("\n").split("\n")
+ kind, name, value = lines[-1].split("\t")
+ assert (kind, name) == ("meta", "body_check")
+ rows = [line for line in lines if line.startswith("route\t")]
+ assert int(value) == bake.body_check(rows)
+ cut = rows[-1][:-1] # the last number a digit short
+ assert bake.body_check(rows[:-1] + [cut]) != int(value)
diff --git a/unity/Assets/Scripts/Boot/ContentManifest.cs b/unity/Assets/Scripts/Boot/ContentManifest.cs
index da75da411..7549415d5 100644
--- a/unity/Assets/Scripts/Boot/ContentManifest.cs
+++ b/unity/Assets/Scripts/Boot/ContentManifest.cs
@@ -22,8 +22,9 @@ namespace Statecraft.Game.Boot
/// localities_1948.yaml is the sourced input of tools/localities_bake.py; the map reads its baked runtime form.
public static readonly IReadOnlyCollection<string> ToolInputs = new HashSet<string> { "map/routes_1948.yaml", "map/localities_1948.yaml" };
- /// <summary>Baked map files that are not YAML, listed when present: the 1948 localities' runtime form (boot budget).</summary>
- public static readonly IReadOnlyList<string> RuntimeData = new[] { "map/localities_1948.tsv" };
+ /// <summary>Baked map files that are not YAML, listed when present: the runtime forms of the 1948 localities and of the
+ /// route paths (boot budget). The route paths' YAML still ships: the runtime file is checked against it.</summary>
+ public static readonly IReadOnlyList<string> RuntimeData = new[] { "map/localities_1948.tsv", "map/route_paths_1948.tsv" };
[Serializable] sealed class ManifestJson { public string[] files = new string[0]; }
diff --git a/unity/Assets/Scripts/Boot/GameInputs.cs b/unity/Assets/Scripts/Boot/GameInputs.cs
index 122b63c08..c03bfc87c 100644
--- a/unity/Assets/Scripts/Boot/GameInputs.cs
+++ b/unity/Assets/Scripts/Boot/GameInputs.cs
@@ -18,6 +18,9 @@ namespace Statecraft.Game.Boot
public string RegionsYaml = "";
/// <summary>content/map/route_paths_1948.yaml: the traced railways and roads the map draws (issue #35; map-only).</summary>
public string RoutesYaml = "";
+ /// <summary>content/map/route_paths_1948.tsv, the baked runtime form of RoutesYaml the map reads at boot (issue #321;
+ /// "" when absent: the YAML is read, with a warning).</summary>
+ public string RoutesTsv = "";
/// <summary>content/map/units_1948.yaml: the sourced units the map draws in play (docs/units.md; map-only, "" when
/// absent).</summary>
public string UnitsYaml = "";
@@ -50,6 +53,7 @@ namespace Statecraft.Game.Boot
SettlementsYaml = File.ReadAllText(Path.Combine(contentDir, "map", SettlementPlacer.DefaultFileName)),
RegionsYaml = File.ReadAllText(Path.Combine(contentDir, "map", Subdistricts1948.FileName)),
RoutesYaml = ReadIfExists(Path.Combine(contentDir, "map", Statecraft.Game.Map.Routes.RoutePaths.DefaultFileName)),
+ RoutesTsv = ReadIfExists(Path.Combine(contentDir, "map", Statecraft.Game.Map.Routes.RoutePaths.RuntimeFileName)),
UnitsYaml = ReadIfExists(Path.Combine(contentDir, "map", Statecraft.Game.Map.Units.UnitData.DefaultFileName)),
PopulationYaml = File.Exists(Path.Combine(contentDir, "map", Statecraft.Game.Map.Kits.KitPopulation.FileName))
? File.ReadAllText(Path.Combine(contentDir, "map", Statecraft.Game.Map.Kits.KitPopulation.FileName)) : "",
@@ -77,6 +81,7 @@ namespace Statecraft.Game.Boot
HexesJson = texts["map/hexes.json"], SettlementsYaml = texts["map/" + SettlementPlacer.DefaultFileName],
RegionsYaml = texts["map/" + Subdistricts1948.FileName],
RoutesYaml = texts.TryGetValue("map/" + Statecraft.Game.Map.Routes.RoutePaths.DefaultFileName, out var routes) ? routes : "",
+ RoutesTsv = texts.TryGetValue("map/" + Statecraft.Game.Map.Routes.RoutePaths.RuntimeFileName, out var routesTsv) ? routesTsv : "",
UnitsYaml = texts.TryGetValue("map/" + Statecraft.Game.Map.Units.UnitData.DefaultFileName, out var unitsYaml) ? unitsYaml : "",
PopulationYaml = texts.TryGetValue("map/" + Statecraft.Game.Map.Kits.KitPopulation.FileName, out var pop) ? pop : "",
LocalitiesTsv = texts.TryGetValue("map/" + Statecraft.Game.Map.Kits.Localities.RuntimeFileName, out var loc) ? loc : "",
diff --git a/unity/Assets/Scripts/Map/MapScene.cs b/unity/Assets/Scripts/Map/MapScene.cs
index d2f829cda..413f4a4f5 100644
--- a/unity/Assets/Scripts/Map/MapScene.cs
+++ b/unity/Assets/Scripts/Map/MapScene.cs
@@ -245,14 +245,19 @@ namespace Statecraft.Game.Map
DiagLog.BootPhase("settlements placed");
KitStats = null;
// The 1948 railways and roads (issue #35), read before the kits so buildings and trees keep off them.
- var routes = Routes.RoutePaths.ReadOrNone(inputs.RoutesYaml, (meta.lon0, meta.lon1, meta.lat0, meta.lat1), Debug.LogWarning);
+ // From the baked runtime form when it matches the YAML (issue #321: boot time), else from the YAML with a warning.
+ var routes = Routes.RoutePaths.ReadRuntimeOrYaml(inputs.RoutesTsv, inputs.RoutesYaml, (meta.lon0, meta.lon1, meta.lat0, meta.lat1), Debug.LogWarning);
+ DiagLog.BootPhase("route paths read"); // issue #321: the splits of the units' phase
RouteCorridors = Routes.RouteLayer.Corridors(Frame, routes);
+ DiagLog.BootPhase("route corridors");
// The game settlements' and the 1948 localities' discs, as the kits will claim them (review I5: a token placed "off
// the towns" keeps off the villages too). The camps are placed after the units and keep off them instead.
SettlementFootprints = painted.Select(s => { var w = Frame.ToWorld(s.Lon, s.Lat, 0); return (new Vector2(w.x, w.z), Kits.SettlementKits.FootprintRadiusM(s, hexSizeM)); }).ToList();
// The units' spots depend only on the footprints, the routes and the land, so they are known before the kits:
// a unit placed in a town gets a clearing the kits keep free (UnitLayer places it the same way).
+ DiagLog.BootPhase("footprints");
var unitData = Units.UnitData.ReadOrNone(inputs.UnitsYaml, Debug.LogWarning);
+ DiagLog.BootPhase("unit data read");
var unitHexes = Hexes.hexes.Select(h => new Statecraft.Sim.MapHex { Q = h.q, R = h.r, Lon = h.lon, Lat = h.lat, ElevM = h.elev_m, Land = h.land, Biome = h.biome }).ToList();
var unitGround = new Units.UnitGround(SettlementFootprints, RouteCorridors, unitHexes,
(lon, lat) => { var w = Frame.ToWorld(lon, lat, 0); return new Vector2(w.x, w.z); }, hexSizeM);
diff --git a/unity/Assets/Scripts/Map/Routes/RoutePaths.cs b/unity/Assets/Scripts/Map/Routes/RoutePaths.cs
index 2553c63bc..4d6102497 100644
--- a/unity/Assets/Scripts/Map/Routes/RoutePaths.cs
+++ b/unity/Assets/Scripts/Map/Routes/RoutePaths.cs
@@ -49,6 +49,12 @@ namespace Statecraft.Game.Map.Routes
public static class RoutePaths
{
public const string DefaultFileName = "route_paths_1948.yaml";
+ /// <summary>The baked runtime form the player reads at boot (tools/route_paths_bake.py; issue #321, as #291's
+ /// localities_1948.tsv): one row per route, its points in one field.</summary>
+ public const string RuntimeFileName = "route_paths_1948.tsv";
+ /// <summary>Bump it, with tools/route_paths_bake.py's VERSION, when the runtime file's layout or its reading
+ /// (ParseRuntime, RuntimeRows) changes; tools/tests/test_route_paths_bake.py pins a fingerprint of that code.</summary>
+ public const int RuntimeVersion = 2; // 2: the body_check row (review of #547)
public const string Rail = "rail", Road = "road", Track = "track";
static readonly HashSet<string> Kinds = new HashSet<string> { Rail, Road, Track };
static readonly Regex IdRule = new Regex(@"^[a-z][a-z0-9_]*\z");
@@ -80,6 +86,108 @@ namespace Statecraft.Game.Map.Routes
catch (InvalidDataException e) { warn($"{e.Message}; the map draws no railways or roads"); return new List<RoutePath>(); }
}
+ /// <summary>The boot read (issue #321): the routes from the runtime file when it was baked from this YAML by this
+ /// version (ParseRuntime), else, with one warning through <paramref name="warn"/>, from the YAML (ReadOrNone).</summary>
+ public static List<RoutePath> ReadRuntimeOrYaml(string? tsv, string? yaml, (double lon0, double lon1, double lat0, double lat1)? bounds,
+ Action<string> warn)
+ {
+ // One cause, one warning (review of #547, N1): with no YAML, only its own warning.
+ if (string.IsNullOrWhiteSpace(yaml)) return ReadOrNone(yaml, bounds, warn);
+ if (string.IsNullOrWhiteSpace(tsv)) { warn($"{RuntimeFileName}: missing; reading the YAML"); return ReadOrNone(yaml, bounds, warn); }
+ RoutePathFile doc;
+ try { doc = RuntimeDoc(tsv!, yaml!, RuntimeFileName); }
+ catch (InvalidDataException e) { warn($"{e.Message}; reading the YAML"); return ReadOrNone(yaml, bounds, warn); }
+ // The file is this YAML's bake, so the YAML would fail the checks the same way: no second parse.
+ try { return Validate(doc, bounds, RuntimeFileName, warn); }
+ catch (InvalidDataException e) { warn($"{e.Message}; the map draws no railways or roads"); return new List<RoutePath>(); }
+ }
+
+ /// <summary>Parses the runtime file with the same checks as <see cref="Parse"/>. Throws InvalidDataException naming
+ /// <paramref name="file"/> (and the line, for a malformed row) when it is of another version, was baked from another
+ /// YAML than <paramref name="yaml"/> (RouteRibbonFile.Check of its text), or does not parse.</summary>
+ public static List<RoutePath> ParseRuntime(string tsv, string yaml, (double lon0, double lon1, double lat0, double lat1)? bounds = null,
+ Action<string>? skipBadWindow = null, string file = RuntimeFileName)
+ {
+ return Validate(RuntimeDoc(tsv, yaml, file), bounds, file, skipBadWindow);
+ }
+
+ /// <summary>The runtime file's routes before the reader's checks; throws when it is of another version, made from
+ /// another YAML, cut short or malformed.</summary>
+ static RoutePathFile RuntimeDoc(string tsv, string yaml, string file)
+ {
+ var (version, check, routes) = RuntimeRows(tsv, file);
+ if (version != RuntimeVersion) throw new InvalidDataException($"{file}: version {version}, this build reads {RuntimeVersion} (re-bake: tools/route_paths_bake.py)");
+ if (check != RouteRibbonFile.Check(yaml)) throw new InvalidDataException($"{file}: made from another {DefaultFileName} (re-bake: tools/route_paths_bake.py)");
+ return new RoutePathFile { Routes = routes };
+ }
+
+ /// <summary>The runtime file's body_check: FNV-1a over the UTF-8 bytes of its route rows, each followed by '\n', in
+ /// order (tools/route_paths_bake.py's body_check).</summary>
+ public static int BodyCheck(IEnumerable<string> routeRows)
+ {
+ uint h = 2166136261;
+ foreach (var row in routeRows)
+ {
+ foreach (var b in System.Text.Encoding.UTF8.GetBytes(row)) { h ^= b; h *= 16777619; }
+ h ^= (byte)'\n'; h *= 16777619;
+ }
+ return (int)h;
+ }
+
+ static (int version, int check, List<RoutePath> routes) RuntimeRows(string tsv, string file)
+ {
+ int? version = null, check = null, count = null, body = null;
+ var routes = new List<RoutePath>();
+ var rows = new List<string>();
+ var lines = tsv.Split('\n');
+ double Num(string text, string what, int line) =>
+ double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var v)
+ ? v : throw new InvalidDataException($"{file}:{line}: {what} '{text}' is not a number");
+ int Int(string text, string what, int line) =>
+ int.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out var v)
+ ? v : throw new InvalidDataException($"{file}:{line}: {what} '{text}' is not an integer");
+ for (int i = 0; i < lines.Length; i++)
+ {
+ var text = lines[i].TrimEnd('\r');
+ if (text.Length == 0 || text[0] == '#') continue;
+ int line = i + 1;
+ if (body != null) throw new InvalidDataException($"{file}:{line}: a row after body_check, which must be the last");
+ var c = text.Split('\t');
+ if (c[0] == "meta" && c.Length == 3 && c[1] == "body_check") body = Int(c[2], "body_check", line);
+ else if (c[0] == "meta" && c.Length == 3 && c[1] == "version") version = Int(c[2], "version", line);
+ else if (c[0] == "meta" && c.Length == 3 && c[1] == "yaml_check") check = Int(c[2], "yaml_check", line);
+ else if (c[0] == "meta" && c.Length == 3 && c[1] == "routes") count = Int(c[2], "routes", line);
+ else if (c[0] == "route")
+ {
+ if (c.Length != 11) throw new InvalidDataException($"{file}:{line}: a route row has {c.Length} fields, not 11");
+ rows.Add(text);
+ var pairs = c[10].Split(';');
+ if (pairs.Length != Int(c[9], "point_count", line))
+ throw new InvalidDataException($"{file}:{line}: {pairs.Length} points, the row says {c[9]}");
+ var points = new List<List<double>>(pairs.Length);
+ foreach (var pair in pairs)
+ {
+ int sp = pair.IndexOf(' ');
+ if (sp < 0 || pair.IndexOf(' ', sp + 1) >= 0) throw new InvalidDataException($"{file}:{line}: point '{pair}' is not 'lon lat'");
+ points.Add(new List<double> { Num(pair.Substring(0, sp), "lon", line), Num(pair.Substring(sp + 1), "lat", line) });
+ }
+ routes.Add(new RoutePath
+ {
+ Id = c[1], Kind = c[2], Status = c[3], From = c[4], To = c[5].Length == 0 ? null : c[5],
+ LengthKm = Num(c[6], "length_km", line), OnSymbol = Num(c[7], "on_symbol", line), MaxGapM = Num(c[8], "max_gap_m", line),
+ Points = points,
+ });
+ }
+ else throw new InvalidDataException($"{file}:{line}: unknown row '{c[0]}'");
+ }
+ if (version == null || check == null || count == null) throw new InvalidDataException($"{file}: no version, yaml_check or routes row");
+ // A file cut anywhere, even inside a number, loses the last row or no longer matches it (review of #547, S1).
+ if (body == null) throw new InvalidDataException($"{file}: no body_check row at the end (cut short?)");
+ if (body != BodyCheck(rows)) throw new InvalidDataException($"{file}: the route rows do not match body_check (cut short or edited?)");
+ if (routes.Count != count) throw new InvalidDataException($"{file}: {routes.Count} routes, the file says {count}");
+ return (version.Value, check.Value, routes);
+ }
+
/// <summary>Parses the file. Every problem throws InvalidDataException naming <paramref name="file"/> and, for
/// content errors, the route id: YAML syntax, duplicate or unknown keys, no routes, a bad or duplicate id, an unknown
/// kind, fewer than two points, a point that is not a [lon, lat] pair of finite numbers or lies outside
@@ -95,6 +203,12 @@ namespace Statecraft.Game.Map.Routes
.Build().Deserialize<RoutePathFile>(yaml);
}
catch (YamlException e) { throw new InvalidDataException($"{file}: {e.Message}", e); }
+ return Validate(doc, bounds, file, skipBadWindow);
+ }
+
+ static List<RoutePath> Validate(RoutePathFile? doc, (double lon0, double lon1, double lat0, double lat1)? bounds, string file,
+ Action<string>? skipBadWindow)
+ {
if (doc?.Routes == null || doc.Routes.Count == 0) throw new InvalidDataException($"{file}: no routes");
var ids = new HashSet<string>();
var skipped = new List<RoutePath>();
diff --git a/unity/Assets/Scripts/Map/Units/UnitPlacer.cs b/unity/Assets/Scripts/Map/Units/UnitPlacer.cs
index 16f34dda2..94e27fa4d 100644
--- a/unity/Assets/Scripts/Map/Units/UnitPlacer.cs
+++ b/unity/Assets/Scripts/Map/Units/UnitPlacer.cs
@@ -82,12 +82,16 @@ namespace Statecraft.Game.Map.Units
DateTime from = UnitData.Day(a.From), to = UnitData.Day(a.To);
int home = Nearest(centres, p);
var (hq, hr) = (hexes[home].Q, hexes[home].R);
+ // The hexes within the one-hex limit, in list order: the only ones whose points can pass the test below,
+ // so the others' candidate points are never made (issue #321: boot time; UnitPlacerSpeedTests).
+ var near = new List<int>();
+ for (int i = 0; i < hexes.Count; i++) if (MapActions.Distance(hexes[i].Q, hexes[i].R, hq, hr) <= MaxShift) near.Add(i);
AnchorSpot? best = null;
foreach (var round in new[] { 1, 2, 3 })
{
bool compact = round > 1, inTown = round == 3;
double bestD = double.MaxValue, bestDepth = double.MaxValue;
- foreach (var (i, x, z) in Candidates(hexes, centres, hexSizeM, compact, a.Toward != null ? target : ((double, double)?)null))
+ foreach (var (i, x, z) in Candidates(near, centres, hexSizeM, compact, a.Toward != null ? target : ((double, double)?)null))
{
var h = hexes[i];
if (h.Land == sea || MapActions.Distance(h.Q, h.R, hq, hr) > MaxShift) continue;
@@ -121,12 +125,13 @@ namespace Statecraft.Game.Map.Units
/// town's roads near the sourced place, not only on the hex grid's points.</summary>
public const double TowardStepM = 500.0, TowardReachM = 2500.0;
- /// <summary>The round's candidate spots, each with the index of the hex it lies in: every hex centre, and for a
- /// compact round the points inside each hex; and in every round the rings round the `toward` point.</summary>
- static IEnumerable<(int i, double x, double z)> Candidates(IReadOnlyList<MapHex> hexes, (double x, double z)[] centres, double hexSizeM,
+ /// <summary>The round's candidate spots, each with the index of the hex it lies in: the centre of every hex in
+ /// <paramref name="hexIndices"/> (in that order), and for a compact round the points inside each; and in every round
+ /// the rings round the `toward` point (each with its nearest hex, whichever it is).</summary>
+ static IEnumerable<(int i, double x, double z)> Candidates(IReadOnlyList<int> hexIndices, (double x, double z)[] centres, double hexSizeM,
bool compact, (double x, double z)? toward)
{
- for (int i = 0; i < hexes.Count; i++)
+ foreach (var i in hexIndices)
{
yield return (i, centres[i].x, centres[i].z);
if (!compact) continue;
diff --git a/unity/Assets/Tests/EditMode/RoutePathsRuntimeTests.cs b/unity/Assets/Tests/EditMode/RoutePathsRuntimeTests.cs
new file mode 100644
index 000000000..d12542278
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/RoutePathsRuntimeTests.cs
@@ -0,0 +1,168 @@
+#nullable enable
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Boot;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Routes;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+
+/// <summary>Issue #321: the map reads route_paths_1948.yaml's baked runtime form (route_paths_1948.tsv, tools/route_paths_bake.py)
+/// at boot instead of parsing the YAML (about 125 ms of the map build at cpu 4), as #291 did for the localities. The
+/// runtime file must give exactly the routes the YAML gives; one that does not match the YAML it ships with (its check or
+/// its version) is refused with a warning and the YAML is read instead.</summary>
+public class RoutePathsRuntimeTests
+{
+ [TearDown]
+ public void Reset() { EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); VisualToggles.Clear(); }
+
+ static MapInputs Inputs() => GameInputs.MapFromDisk(Paths.Content, Paths.StreamingMap);
+
+ static (double, double, double, double) Bounds()
+ {
+ var b = HeightmapLoader.Load(Paths.StreamingMap).meta;
+ return (b.lon0, b.lon1, b.lat0, b.lat1);
+ }
+
+ [Test]
+ public void TheRuntimeFileYieldsTheSameRoutesAsTheYaml()
+ {
+ var inputs = Inputs();
+ Assert.IsNotEmpty(inputs.RoutesTsv, "content/map/" + RoutePaths.RuntimeFileName + " (tools/route_paths_bake.py)");
+ var yaml = RoutePaths.Parse(inputs.RoutesYaml, Bounds());
+ var tsv = RoutePaths.ParseRuntime(inputs.RoutesTsv, inputs.RoutesYaml, Bounds());
+ Assert.AreEqual(yaml.Count, tsv.Count);
+ for (int i = 0; i < yaml.Count; i++)
+ {
+ var (y, t) = (yaml[i], tsv[i]);
+ Assert.AreEqual((y.Id, y.Kind, y.Status, y.LengthKm, y.From, y.To, y.OnSymbol, y.MaxGapM, y.Points.Count),
+ (t.Id, t.Kind, t.Status, t.LengthKm, t.From, t.To, t.OnSymbol, t.MaxGapM, t.Points.Count), y.Id);
+ for (int k = 0; k < y.Points.Count; k++)
+ {
+ Assert.AreEqual(2, t.Points[k].Count, $"{y.Id} point {k}");
+ Assert.AreEqual(System.BitConverter.DoubleToInt64Bits(y.Points[k][0]), System.BitConverter.DoubleToInt64Bits(t.Points[k][0]), $"{y.Id} point {k} lon");
+ Assert.AreEqual(System.BitConverter.DoubleToInt64Bits(y.Points[k][1]), System.BitConverter.DoubleToInt64Bits(t.Points[k][1]), $"{y.Id} point {k} lat");
+ }
+ }
+ }
+
+ /// <summary>The boot read: the runtime file when it is for this YAML, without a warning.</summary>
+ [Test]
+ public void TheMapReadsTheRuntimeFile()
+ {
+ var inputs = Inputs();
+ var warnings = new List<string>();
+ var routes = RoutePaths.ReadRuntimeOrYaml(inputs.RoutesTsv, inputs.RoutesYaml, Bounds(), warnings.Add);
+ CollectionAssert.IsEmpty(warnings);
+ Assert.AreEqual(RoutePaths.Parse(inputs.RoutesYaml, Bounds()).Count, routes.Count);
+ }
+
+ /// <summary>Review of #547, S2: the map scene itself reads the runtime file, not only ReadRuntimeOrYaml. The first route's
+ /// first point is moved 0.01 degrees east in the runtime file alone (its body_check re-made, its yaml_check still the
+ /// YAML's), so the routes the map builds show which file it read: a MapScene that went back to the YAML would put the
+ /// corridor's first point where the YAML has it. No fallback warning is logged.</summary>
+ [Test]
+ public void TheMapSceneBuildsItsRoutesFromTheRuntimeFile()
+ {
+ var inputs = Inputs();
+ var lines = inputs.RoutesTsv.Split('\n').ToList();
+ int at = lines.FindIndex(l => l.StartsWith("route\t"));
+ var c = lines[at].Split('\t'); var points = c[10].Split(';'); var first = points[0].Split(' ');
+ double lon = double.Parse(first[0], CultureInfo.InvariantCulture) + 0.01, lat = double.Parse(first[1], CultureInfo.InvariantCulture);
+ points[0] = lon.ToString("R", CultureInfo.InvariantCulture) + " " + first[1];
+ c[10] = string.Join(";", points); lines[at] = string.Join("\t", c);
+ int end = lines.FindIndex(l => l.StartsWith("meta\tbody_check\t"));
+ lines[end] = "meta\tbody_check\t" + RoutePaths.BodyCheck(lines.Where(l => l.StartsWith("route\t"))).ToString(CultureInfo.InvariantCulture);
+ inputs.RoutesTsv = string.Join("\n", lines);
+
+ var fallbacks = new List<string>();
+ void Watch(string message, string stack, LogType type) { if (message.Contains("reading the YAML")) fallbacks.Add(message); }
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var map = Object.FindFirstObjectByType<MapScene>();
+ Application.logMessageReceived += Watch;
+ try { map.Build(inputs); }
+ finally { Application.logMessageReceived -= Watch; }
+ CollectionAssert.IsEmpty(fallbacks);
+ var moved = map.Frame.ToWorld(lon, lat, 0);
+ var drawn = map.RouteCorridors[0].line[0];
+ Assert.AreEqual(moved.x, drawn.x, 0.01f, "the corridor starts where the runtime file puts the route, not the YAML");
+ Assert.AreEqual(moved.z, drawn.y, 0.01f);
+ }
+
+ /// <summary>A runtime file for another YAML, of another version, malformed or missing: a warning, and the YAML's routes.</summary>
+ [Test]
+ public void AStaleOrBrokenRuntimeFileFallsBackToTheYaml()
+ {
+ var inputs = Inputs();
+ int expected = RoutePaths.Parse(inputs.RoutesYaml, Bounds()).Count;
+ string otherYaml = inputs.RoutesYaml + "\n# an edit after the bake\n";
+ string otherVersion = inputs.RoutesTsv.Replace($"meta\tversion\t{RoutePaths.RuntimeVersion}\n", $"meta\tversion\t{RoutePaths.RuntimeVersion + 1}\n");
+ Assert.AreNotEqual(inputs.RoutesTsv, otherVersion, "the file carries its version");
+ string badRow = inputs.RoutesTsv.Replace("\trail\t", "\tcanal\t");
+ string cutRow = inputs.RoutesTsv.Substring(0, inputs.RoutesTsv.LastIndexOf(';'));
+ string lastRowGone = inputs.RoutesTsv.Substring(0, inputs.RoutesTsv.TrimEnd('\n').LastIndexOf('\n') + 1);
+ // Review of #547, S1: a file cut inside a number. The last route row's last number loses its last digit, with the
+ // file ending there (a cut download) or with the rows after it intact; and the file loses its last two bytes.
+ int lastRoute = inputs.RoutesTsv.LastIndexOf("\nroute\t") + 1;
+ int lastRouteEnd = inputs.RoutesTsv.IndexOf('\n', lastRoute);
+ string cutMidNumber = inputs.RoutesTsv.Substring(0, lastRouteEnd - 1);
+ string shortNumber = inputs.RoutesTsv.Remove(lastRouteEnd - 1, 1);
+ string twoBytesOff = inputs.RoutesTsv.Substring(0, inputs.RoutesTsv.Length - 2);
+ foreach (var (tsv, yaml, why) in new[]
+ {
+ (inputs.RoutesTsv, otherYaml, "made from another YAML"), (otherVersion, inputs.RoutesYaml, "version"),
+ (badRow, inputs.RoutesYaml, "unknown kind"), (cutRow, inputs.RoutesYaml, "a point cut short"), (lastRowGone, inputs.RoutesYaml, "a route row cut off"),
+ (cutMidNumber, inputs.RoutesYaml, "cut inside the last number"), (shortNumber, inputs.RoutesYaml, "one number a digit short"),
+ (twoBytesOff, inputs.RoutesYaml, "two bytes off the end"), ("", inputs.RoutesYaml, "missing"),
+ })
+ {
+ var warnings = new List<string>();
+ var routes = RoutePaths.ReadRuntimeOrYaml(tsv, yaml, Bounds(), warnings.Add);
+ Assert.AreEqual(1, warnings.Count, why);
+ StringAssert.Contains("reading the YAML", warnings[0], why);
+ Assert.AreEqual(expected, routes.Count, why);
+ }
+ }
+
+ /// <summary>Review of #547, N1: one cause, one warning. With both files missing, only the YAML's own warning; with a
+ /// runtime file that matches the YAML but fails the reader's checks (here every point is outside the bounds), one
+ /// warning and no routes, without parsing the YAML only to fail the same way.</summary>
+ [Test]
+ public void OneCauseGivesOneWarning()
+ {
+ var inputs = Inputs();
+ var warnings = new List<string>();
+ CollectionAssert.IsEmpty(RoutePaths.ReadRuntimeOrYaml("", "", Bounds(), warnings.Add));
+ Assert.AreEqual(1, warnings.Count, string.Join(" | ", warnings));
+ warnings.Clear();
+ CollectionAssert.IsEmpty(RoutePaths.ReadRuntimeOrYaml(inputs.RoutesTsv, inputs.RoutesYaml, (0.0, 1.0, 0.0, 1.0), warnings.Add));
+ Assert.AreEqual(1, warnings.Count, string.Join(" | ", warnings));
+ StringAssert.Contains("outside the map", warnings[0]);
+ }
+
+ /// <summary>A malformed row is an error naming the file and its line, as the localities' runtime file.</summary>
+ [Test]
+ public void TheRuntimeFileRejectsBadRowsByLine()
+ {
+ var inputs = Inputs();
+ var lines = inputs.RoutesTsv.Split('\n');
+ int at = System.Array.FindIndex(lines, l => l.StartsWith("route\t"));
+ lines[at] = lines[at].Replace("\t", "\t\t");
+ var e = Assert.Throws<InvalidDataException>(() => RoutePaths.ParseRuntime(string.Join("\n", lines), inputs.RoutesYaml, Bounds()));
+ StringAssert.Contains($"{RoutePaths.RuntimeFileName}:{at + 1}:", e!.Message);
+ }
+
+ /// <summary>The manifest ships the runtime file to the player, beside the YAML (the ribbon bake and this check read it).</summary>
+ [Test]
+ public void TheManifestShipsTheRuntimeFile()
+ {
+ var files = ContentManifest.Collect(Paths.Content);
+ CollectionAssert.Contains(files, "map/" + RoutePaths.RuntimeFileName);
+ CollectionAssert.Contains(files, "map/" + RoutePaths.DefaultFileName);
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/RoutePathsRuntimeTests.cs.meta b/unity/Assets/Tests/EditMode/RoutePathsRuntimeTests.cs.meta
new file mode 100644
index 000000000..2a80eeff6
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/RoutePathsRuntimeTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: c4eb03c33deb44bea867a00aeb6f2776
diff --git a/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs b/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs
new file mode 100644
index 000000000..fb18f9e86
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs
@@ -0,0 +1,190 @@
+#nullable enable
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Boot;
+using Statecraft.Game.Map;
+using Statecraft.Game.Map.Units;
+using Statecraft.Sim;
+using UnityEngine;
+using static Statecraft.Game.Map.Units.UnitPlacer;
+
+/// <summary>Issue #321: UnitPlacer.PlaceAll was about 185 ms of the map build at cpu 4, most of it the candidate spots of
+/// hexes the one-hex limit throws away. Its result must stay exactly the original algorithm's (kept here verbatim as the
+/// reference), for any ground: the spots decide where every unit token stands.</summary>
+public class UnitPlacerSpeedTests
+{
+ /// <summary>UnitPlacer.PlaceAll, Candidates, Inside and Nearest as they were before issue #321's change, verbatim.</summary>
+ static class Reference
+ {
+ public static Dictionary<UnitAnchor, AnchorSpot> PlaceAll(IReadOnlyList<UnitEntry> units, IReadOnlyList<MapHex> hexes, double hexSizeM,
+ Func<double, double, (double x, double z)> toXZ, Func<string, double, double, bool, bool, double, double, bool> clear,
+ Func<double, double, double> townOverlap, Action<string>? skipped = null)
+ {
+ if (units == null) throw new ArgumentNullException(nameof(units));
+ if (hexes == null || hexes.Count == 0) throw new ArgumentException("no hexes", nameof(hexes));
+ var centres = new (double x, double z)[hexes.Count];
+ for (int i = 0; i < hexes.Count; i++) centres[i] = toXZ(hexes[i].Lon, hexes[i].Lat);
+ double maxOffset = Math.Sqrt(3.0) * hexSizeM + 1.0; // one hex step (plus a metre of rounding)
+ var held = new List<(int q, int r, DateTime from, DateTime to)>();
+ var result = new Dictionary<UnitAnchor, AnchorSpot>();
+ foreach (var u in units)
+ {
+ if (u.Hidden != null) continue;
+ bool sea = u.Service == UnitData.Navy;
+ foreach (var a in u.Anchors)
+ {
+ var p = toXZ(a.Lon, a.Lat);
+ // A sourced point on the unit's own side, when the anchor has one: spots are ranked by distance to it.
+ var target = a.Toward != null ? toXZ(a.Toward.Lon, a.Toward.Lat) : p;
+ DateTime from = UnitData.Day(a.From), to = UnitData.Day(a.To);
+ int home = Nearest(centres, p);
+ var (hq, hr) = (hexes[home].Q, hexes[home].R);
+ AnchorSpot? best = null;
+ foreach (var round in new[] { 1, 2, 3 })
+ {
+ bool compact = round > 1, inTown = round == 3;
+ double bestD = double.MaxValue, bestDepth = double.MaxValue;
+ foreach (var (i, x, z) in Candidates(hexes, centres, hexSizeM, compact, a.Toward != null ? target : ((double, double)?)null))
+ {
+ var h = hexes[i];
+ if (h.Land == sea || MapActions.Distance(h.Q, h.R, hq, hr) > MaxShift) continue;
+ if (a.PlaceHex != null && (h.Q != a.PlaceHex[0] || h.R != a.PlaceHex[1])) continue;
+ if (held.Exists(c => c.q == h.Q && c.r == h.R && c.from < to && from < c.to)) continue;
+ if (Math.Sqrt((x - p.x) * (x - p.x) + (z - p.z) * (z - p.z)) > maxOffset) continue;
+ double d = Math.Sqrt((x - target.x) * (x - target.x) + (z - target.z) * (z - target.z));
+ // Round 3 ranks by depth into the town first (rounded to a metre), then by distance; with a
+ // sourced own-side point it ranks by distance to that alone (the town edge may be the other side's).
+ double overlap = inTown ? Math.Max(0.0, townOverlap(x, z)) : 0.0;
+ double depth = a.Toward == null ? Math.Round(overlap) : 0.0;
+ if (depth > bestDepth || (depth == bestDepth && d > bestD)) continue;
+ // Ties go to the lower (q, r): the result never depends on the hex list's order.
+ if (depth == bestDepth && d == bestD && best != null && (h.Q, h.R).CompareTo((best.Value.Q, best.Value.R)) > 0) continue;
+ if (!clear(u.Service, x, z, compact, inTown, p.x, p.z)) continue;
+ best = new AnchorSpot(h.Q, h.R, x, z, compact, inTown && overlap > 0); bestD = d; bestDepth = depth;
+ }
+ if (best != null) break;
+ if (sea) break; // a ship's sea hex is all its test; rounds 2 and 3 add nothing
+ }
+ if (best == null) { skipped?.Invoke($"UNITS no clear spot within one hex of {a.Place} for {u.Id}; not drawn"); continue; }
+ held.Add((best.Value.Q, best.Value.R, from, to));
+ result[a] = best.Value;
+ }
+ }
+ return result;
+ }
+
+ /// <summary>Within the one-hex limit around a `toward` point (every round): rings every
+ /// <see cref="TowardStepM"/> out to <see cref="TowardReachM"/>, twelve points each, so a spot can sit between a
+ /// town's roads near the sourced place, not only on the hex grid's points.</summary>
+ public const double TowardStepM = 500.0, TowardReachM = 2500.0;
+
+ /// <summary>The round's candidate spots, each with the index of the hex it lies in: every hex centre, and for a
+ /// compact round the points inside each hex; and in every round the rings round the `toward` point.</summary>
+ static IEnumerable<(int i, double x, double z)> Candidates(IReadOnlyList<MapHex> hexes, (double x, double z)[] centres, double hexSizeM,
+ bool compact, (double x, double z)? toward)
+ {
+ for (int i = 0; i < hexes.Count; i++)
+ {
+ yield return (i, centres[i].x, centres[i].z);
+ if (!compact) continue;
+ for (int k = 0; k < 6 * InsideOffsets.Length; k++) { var (x, z) = Inside(centres[i], k, hexSizeM); yield return (i, x, z); }
+ }
+ if (toward == null) yield break; // the rings round a `toward` point are tried in every round
+ var t = toward.Value;
+ for (double rad = 0; rad <= TowardReachM; rad += TowardStepM)
+ for (int k = 0; k < (rad == 0 ? 1 : 12); k++)
+ {
+ double x = t.x + Math.Cos(Math.PI / 6.0 * k) * rad, z = t.z + Math.Sin(Math.PI / 6.0 * k) * rad;
+ yield return (Nearest(centres, (x, z)), x, z);
+ }
+ }
+
+ static (double x, double z) Inside((double x, double z) c, int k, double hexSizeM)
+ {
+ double ang = Math.PI / 3.0 * (k % 6), off = InsideOffsets[k / 6] * hexSizeM;
+ return (c.x + Math.Cos(ang) * off, c.z + Math.Sin(ang) * off);
+ }
+
+ static int Nearest((double x, double z)[] centres, (double x, double z) p)
+ {
+ int best = 0; double bestD = double.MaxValue;
+ for (int i = 0; i < centres.Length; i++)
+ {
+ double d = (centres[i].x - p.x) * (centres[i].x - p.x) + (centres[i].z - p.z) * (centres[i].z - p.z);
+ if (d < bestD) { bestD = d; best = i; }
+ }
+ return best;
+ }
+ }
+
+ static (List<UnitEntry> units, List<MapHex> hexes, Func<double, double, (double, double)> toXZ, double hexSizeM) Inputs()
+ {
+ var inputs = GameInputs.MapFromDisk(Paths.Content, Paths.StreamingMap);
+ var hexFile = MapBuilder.LoadHexes(inputs.HexesJson, "hexes.json");
+ var meta = HeightmapLoader.Load(Paths.StreamingMap).meta;
+ var size = MapBuilder.TerrainSize(meta);
+ var frame = new GeoFrame(meta.lon0, meta.lon1, meta.lat0, meta.lat1, size.x, size.z);
+ var hexes = hexFile.hexes.Select(h => new MapHex { Q = h.q, R = h.r, Lon = h.lon, Lat = h.lat, ElevM = h.elev_m, Land = h.land, Biome = h.biome }).ToList();
+ var units = UnitData.Parse(inputs.UnitsYaml);
+ return (units, hexes, (lon, lat) => { var w = frame.ToWorld(lon, lat, 0); return (w.x, w.z); }, hexFile.hex_size_km * 1000.0);
+ }
+
+ static ulong Mix(double a, double b, ulong salt)
+ {
+ ulong h = 1469598103934665603UL ^ salt;
+ foreach (var v in new[] { BitConverter.DoubleToInt64Bits(a), BitConverter.DoubleToInt64Bits(b) }) { h ^= (ulong)v; h *= 1099511628211UL; h ^= h >> 29; }
+ return h;
+ }
+
+ [Test]
+ public void TheFastPlacerGivesExactlyTheOriginalSpots()
+ {
+ var (units, hexes, toXZ, hexSizeM) = Inputs();
+ Assert.Greater(units.Sum(u => u.Anchors.Count), 10);
+ // Grounds from open to harsh: everything clear; a seeded share of spots clear; nothing clear in the first round (so
+ // rounds 2 and 3 and the town ranking run); and nothing clear at all (every anchor skipped).
+ var grounds = new (string name, Func<string, double, double, bool, bool, double, double, bool> clear, Func<double, double, double> overlap)[]
+ {
+ ("open", (s, x, z, c, t, ax, az) => true, (x, z) => 0.0),
+ ("seeded", (s, x, z, c, t, ax, az) => Mix(x, z, c ? 3UL : 1UL) % 3 != 0, (x, z) => (Mix(x, z, 7) % 900) - 300.0),
+ ("compact only", (s, x, z, c, t, ax, az) => c && Mix(x, z, t ? 5UL : 9UL) % 4 == 0, (x, z) => (Mix(x, z, 11) % 2000) / 3.0),
+ ("closed", (s, x, z, c, t, ax, az) => false, (x, z) => 0.0),
+ };
+ // Which neighbours of the anchors' home hexes the reference picks (review of #547, N2): the offsets (dq, dr) the
+ // test checks the fast placer against, by ground.
+ var centres = hexes.Select(h => toXZ(h.Lon, h.Lat)).ToArray();
+ (int, int) Home(UnitAnchor a)
+ {
+ var (px, pz) = toXZ(a.Lon, a.Lat);
+ int best = 0; double bestD = double.MaxValue;
+ for (int i = 0; i < centres.Length; i++) { double d = (centres[i].Item1 - px) * (centres[i].Item1 - px) + (centres[i].Item2 - pz) * (centres[i].Item2 - pz); if (d < bestD) { bestD = d; best = i; } }
+ return (hexes[best].Q, hexes[best].R);
+ }
+ var offsets = new SortedSet<(int, int)>();
+ foreach (var (name, clear, overlap) in grounds)
+ {
+ var skippedA = new List<string>(); var skippedB = new List<string>();
+ var fast = UnitPlacer.PlaceAll(units, hexes, hexSizeM, toXZ, clear, overlap, skippedA.Add);
+ var reference = Reference.PlaceAll(units, hexes, hexSizeM, toXZ, clear, overlap, skippedB.Add);
+ CollectionAssert.AreEqual(skippedB, skippedA, name);
+ Assert.AreEqual(reference.Count, fast.Count, name);
+ var here = new SortedSet<(int, int)>();
+ foreach (var kv in reference) { var (hq, hr) = Home(kv.Key); here.Add((kv.Value.Q - hq, kv.Value.R - hr)); }
+ TestContext.WriteLine($"{name}: {reference.Count} spots, offsets from the home hex {string.Join(" ", here)}");
+ offsets.UnionWith(here);
+ foreach (var kv in reference)
+ {
+ Assert.IsTrue(fast.TryGetValue(kv.Key, out var spot), $"{name}: {kv.Key.Place}");
+ Assert.AreEqual(kv.Value, spot, $"{name}: {kv.Key.Place}");
+ }
+ }
+ // Measured on the units of 2026-10-14: the home hex and five of its six neighbours, (-1, 0) (0, -1) (0, 1) (1, -1)
+ // (1, 0); no reference spot lies at (-1, 1). A change to the units may move the set; it must keep at least four.
+ TestContext.WriteLine($"all grounds: offsets {string.Join(" ", offsets)}");
+ CollectionAssert.Contains(offsets, (0, 0));
+ Assert.GreaterOrEqual(offsets.Count(o => o != (0, 0)), 4, $"too few neighbour offsets exercised: {string.Join(" ", offsets)}");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs.meta b/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs.meta
new file mode 100644
index 000000000..3123514d9
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/UnitPlacerSpeedTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 0a41ea8ebefd4167b0c32c963b53825d