diff --git a/README.md b/README.md index 4af4473..866ab54 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,18 @@ The base map is the backdrop. It is 85 tiles / 0.3 MB, always resident, and Leaflet upscales it past its native z3 — so any gap while detail tiles load shows blurry terrain rather than the page background. +## Cache busting + +Tile paths are stable across rebuilds but their contents are not — move a map's +`place` and `tiles//6/17/33.webp` becomes different imagery. Tiles are +served `immutable` for a week, so a browser that saw the old build would blend +it with the new one and show duplicated, offset terrain. + +Each map therefore carries a `version` in `world.json` — a hash of its +geometry, zoom range and source file stamp — appended to every tile URL as +`?v=`. Re-tile a map and it simply gets fresh URLs. Identical rebuilds keep the +same version, so nothing is re-downloaded needlessly. + ## Stacking Placements are approximate, so map rectangles overlap where the real locations diff --git a/docs/adding-a-map.md b/docs/adding-a-map.md index cdf641d..d278910 100644 --- a/docs/adding-a-map.md +++ b/docs/adding-a-map.md @@ -30,16 +30,22 @@ you have to look each time: | Map | Base layers | | --- | --- | | Customs, Customs Dorms | `LOCATION` | -| Woods | `re3mr.com/Map&Art` (nested inside a wrapper group) | +| Woods | `re3mr.com/Map&Art/Map&OverlayArt/{RawMapLayer,WaterDetail}` | | Lighthouse | `Day` (there is also a hidden `Night`) | | Shoreline | `Baselayer` | | Shoreline Resort | `BGCOLOR PATTERN`, `BASEMAP+2DLAYERS` | -| Interchange | `Background`, `3DRENDER` | -| Reserve | `Day copy`, `Color Fill 1`, `Group 5` | -| Streets | `Layer 1`, `Map - 3D map portion…` | +| Interchange | `3DRENDER` | +| Reserve | `Day copy` | +| Streets | `Map - 3D map portion…` | -Note the two shapes this takes: several maps need **more than one** top-level -layer, and some bury the art **inside a wrapper group** (use a slash path). +Note the shapes this takes: several maps need **more than one** top-level +layer, and some bury the art **inside wrapper groups** (use a slash path — +Woods is three deep). + +Watch for layers that are really just plates. Interchange's `Background` and +Reserve's `Color Fill 1` are solid white; Woods' `MapBlackout` and Streets' +`Layer 1` are solid black. Including them hides the terrain underneath, so +leave them out. Also note any `shape` layers — psd-tools renders stroke-only vector shapes as solid fills, so they may need `excludeLayers`. @@ -53,10 +59,10 @@ solid fills, so they may need `excludeLayers`. "id": "woods", "name": "Woods", "psd": "sources/woods/woods.psd", - "baseLayers": ["re3mr.com/Map&Art"], + "baseLayers": ["re3mr.com/Map&Art/Map&OverlayArt/RawMapLayer"], "excludeLayers": [], "crop": null, - "place": { "cx": 818, "cy": 652, "w": 380 } + "place": { "cx": 814, "cy": 672, "w": 380 } } ``` @@ -92,7 +98,7 @@ A failed map no longer aborts the batch; check the summary at the end. ## 4. Position it on the world map The base of the canvas is `sources/overall/overall.jpeg`, rotated by -`world.rotate` (31°) so north is up. `place` is in **rotated overall-map +`world.rotate` (35°) so north is up. `place` is in **rotated overall-map pixels** — the north-up image you actually look at. ```bash @@ -156,6 +162,10 @@ python tools/build.py --force-export # re-render even if base.png is current `build.py` skips the PSD render when `base.png` is newer than the PSD, so iterating on `place` and `crop` is seconds, not minutes. +Retiling a map changes its `version` in `world.json`, which is appended to its +tile URLs as `?v=`. That is what stops a browser mixing a previous build's +tiles with the new ones — you do not need to hard-reload after a rebuild. + --- ## How placement works diff --git a/tools/tile.py b/tools/tile.py index 767ca69..664a311 100644 --- a/tools/tile.py +++ b/tools/tile.py @@ -18,6 +18,7 @@ identical to upscaling here but without storing the tiles. from __future__ import annotations +import hashlib import math import shutil import sys @@ -108,6 +109,19 @@ def tile_map(cfg: Config, m: dict) -> dict: f"@({round(x0)},{round(y0)}) z{min_zoom}-{native_level} " f"{written} tiles ({skipped} empty), {size_mb:.1f} MB") + # Tile URLs are stable across rebuilds but their *contents* are not: move a + # map's `place` and tiles//6/17/33.webp is suddenly different imagery. + # Since tiles are served immutable for a week, a browser that saw the old + # build would blend it with the new one. This version stamp goes into the + # URL so a rebuilt map simply gets fresh URLs. + stamp = f"{x0:.1f},{y0:.1f},{tw:.1f},{th:.1f},{min_zoom},{native_level},{written}" + if m["id"] != WORLD_ID: + st = (BUILD / m["id"] / "base.png").stat() + stamp += f",{int(st.st_mtime)},{st.st_size}" + else: + st = cfg.base_image_path().stat() + stamp += f",{int(st.st_mtime)},{st.st_size},{cfg.rotate},{cfg.overall_scale}" + return { "id": m["id"], "name": m["name"], @@ -117,6 +131,7 @@ def tile_map(cfg: Config, m: dict) -> dict: "minZoom": min_zoom, "maxNativeZoom": native_level, "base": m["id"] == WORLD_ID, + "version": hashlib.sha1(stamp.encode()).hexdigest()[:8], "pxPerMeter": m.get("pxPerMeter"), } diff --git a/web/app.js b/web/app.js index c3c39b2..9411a0b 100644 --- a/web/app.js +++ b/web/app.js @@ -23,11 +23,13 @@ const OffsetTileLayer = L.TileLayer.extend({ getTileUrl(coords) { const o = this.options; const perCell = (o.baseTileSize * 2 ** coords.z) / o.tileSize; + // ?v= busts the week-long immutable cache when a map is re-tiled; the same + // URL would otherwise serve a previous build's imagery. return L.Util.template(this._url, { z: coords.z + o.zoomOffset, x: coords.x - o.cell[0] * perCell, y: coords.y - o.cell[1] * perCell, - }); + }) + (o.version ? `?v=${o.version}` : ''); }, }); @@ -110,6 +112,7 @@ async function main() { const layer = new OffsetTileLayer(`tiles/${m.id}/{z}/{x}/{y}.webp`, { cell: m.cell, bounds: rectOf(m), + version: m.version, baseTileSize: world.tileSize, tileSize: world.tileSize / 2 ** boost, zoomOffset: boost,