Skip to content

Render a rectangle of a map, pixel-identical to cropping the whole-map render. - #11

Open
2Pacalypse- wants to merge 1 commit into
mainfrom
region-render
Open

2Pacalypse- wants to merge 1 commit into
mainfrom
region-render

Conversation

@2Pacalypse-

Copy link
Copy Markdown
Member

Adds a region render: a rectangle of a map, rendered pixel-identical to cropping the same rectangle out of a whole-map render. Tiled viewers can then show a map at full detail without anything ever holding the whole full-resolution image (a 256x256 map at 32 px/tile is 8192x8192, 256 MB of RGBA, and the wasm bindings held about three copies of it). ShieldBattery uses it for the map compare page's zoom, rendering 512px tiles on request from the user's own install.

API

  • RenderOptions::region: Option<TileRect>, with TileRect { x, y, width, height } in map tiles. Every render entry point honours it: render_chk_preview, render_preview, render_terrain, plan_preview and execute_plan. RenderPlan gains a region field that's left out of serialized JSON when unset, so older plans still load. The CLI gets --region x,y,w,h.
  • The pixels per tile and the art tier are still resolved from the whole map, so every region of a map shares one pixel grid. A region outputs width*ppt x height*ppt pixels, clipped to the map; a region entirely off the map gives a 0x0 image. For a fixed density, set size to the map's longer side in tiles times the px/tile you want.
  • wasm: renderRgba/renderPng/planJson take "region": { "x", "y", "width", "height" }, plus "maxOutputPixels" for denser renders of big maps (Remastered at 64+ px/tile on a 256x256 map). New MapRenderOptions and MapRegion declarations, checked by test:types. The README gets an options table and a tiling recipe; docs/render-design.md gets a "Region renders" section.
  • requiredGraphics/loadAssets with a region list only that region's art. Without one they cover every region, so a tiling viewer loads once without a region and then renders many tiles.

Why it's exact

  • Terrain: the resampler computes each output pixel's filter weights from its position in the whole image, exactly as a whole-map render does, and sums them in the same order. It only composites the tile columns those weights reach: the region plus the filter's margin, at most one tile at 2 px/tile and above.
  • Units, sprites and shadows are placed in whole-image pixels and then shifted by the region's whole-pixel origin. Anything that can't reach the region is skipped, which can't change a pixel inside it. Image art is now decoded only once one of its frames lands on the output.
  • Start-location tokens are shaded only relative to their own corners, which is exact under the shift.

Cost

Per-tile cost is mostly compositing and filtering the terrain under the tile, so rendering every tile costs about 15% more than one whole-map render. Peak memory is the region's output plus one strip of its tile columns, a few filtered rows and the decoded art of images that land on it.

On (7)Continental Divide.scm (256x256), native release build, assets in memory:

Style, density Whole map One 512px tile
Original, 32 px/tile ~75 ms ~0.7 ms
Original, 16 px/tile ~410 ms ~7 ms
Original, 8 px/tile ~315 ms ~20 ms
Remastered, 32 px/tile ~1.7 s ~8 ms
Remastered, 16 px/tile ~1.2 s ~21 ms

Through wasm in Node: ~0.5 ms per tile against ~250 ms for the whole map at 32 px/tile, and ~12 ms against ~830 ms at 16 px/tile. Loading a 256x256 map's art for tiling from a real install added ~10-45 MB for Original and ~60 MB for Remastered at 128 px/tile.

Testing

  • A synthetic map in overlay.rs (random terrain, sprite art with transparent holes, units with shadows, doodads off every edge, tokens on region boundaries) checks a full tiling plus edge and off-map regions at native resolution and four downscales, down to 1 px/tile. Removing the filter margin makes it fail.
  • Region plans execute to the region render, plans and asset lists drop far-away sprites, an asset store holding only a region's prefetch renders that region exactly, and hostile plan regions are clipped. The fuzz targets generate regions too (compile-checked, not run).
  • real_assets.rs (needs BROODMAP_TEST_SCR_DIR): every 512px tile plus one unaligned region of lt.scm, Impossible_Scen._Future.scx, OcOc_Bound_2(p).scx and Sniper_Seed_vA.scx, at Original 32 and 16 px/tile and Remastered 16 px/tile, from assets loaded once for the whole map. All 9 real-asset tests pass against a local SC:R install.
  • A wasm test checks renderRgba the same way, and a Node smoke test through the built package matched 336 tiles across Lost Temple and Continental Divide.
  • cargo fmt --check, cargo clippy --workspace --all-targets --all-features -D warnings, cargo test --workspace, MSRV cargo +1.95 check, nightly check of the fuzz crate, and the wasm pipeline (pnpm test, build, test:package, test:types, build:demo).
  • Used from a packed build in ShieldBattery's app: tiles render on request and line up with no visible seams.

…p render.

RenderOptions::region (WASM `region`, CLI --region) composites only the
terrain under the region plus the resampling kernel's margin and draws only
the sprites that can reach it, so tiled viewers never hold a whole
full-resolution map.
2Pacalypse- added a commit to ShieldBattery/ShieldBattery that referenced this pull request Nov 4, 2026
…'s released.

Built from ShieldBattery/broodmap#11 at 2afeb5a. Swap the file: spec for a registry version once it's published.
2Pacalypse- added a commit to ShieldBattery/ShieldBattery that referenced this pull request Nov 4, 2026
…'s released.

Built from ShieldBattery/broodmap#11 at 2afeb5a. Swap the file: spec for a registry version once it's published.
2Pacalypse- added a commit to ShieldBattery/ShieldBattery that referenced this pull request Nov 5, 2026
…icker, highlight and subtract views. (#1885)

* Compare maps on their own linkable page, with split, slider, fade, flicker, highlight and subtract views.

* Mock the map compare page metadata resolver in the page metadata tests.

* Keep map family editor drafts when adding a file, and route compare page map links in the app.

* Add a copy link button to the map compare page.

* Show full-detail map tiles rendered by the app when zooming in on the map compare page.

* Install broodmap from a vendored package with region renders until it's released.

Built from ShieldBattery/broodmap#11 at 2afeb5a. Swap the file: spec for a registry version once it's published.

* Render map compare tiles one at a time with broodmap's region render.
2Pacalypse- added a commit to ShieldBattery/ShieldBattery that referenced this pull request Nov 10, 2026
…icker, highlight and subtract views. (#1885)

* Compare maps on their own linkable page, with split, slider, fade, flicker, highlight and subtract views.

* Mock the map compare page metadata resolver in the page metadata tests.

* Keep map family editor drafts when adding a file, and route compare page map links in the app.

* Add a copy link button to the map compare page.

* Show full-detail map tiles rendered by the app when zooming in on the map compare page.

* Install broodmap from a vendored package with region renders until it's released.

Built from ShieldBattery/broodmap#11 at 2afeb5a. Swap the file: spec for a registry version once it's published.

* Render map compare tiles one at a time with broodmap's region render.
2Pacalypse- added a commit to ShieldBattery/ShieldBattery that referenced this pull request Nov 15, 2026
…icker, highlight and subtract views. (#1885)

* Compare maps on their own linkable page, with split, slider, fade, flicker, highlight and subtract views.

* Mock the map compare page metadata resolver in the page metadata tests.

* Keep map family editor drafts when adding a file, and route compare page map links in the app.

* Add a copy link button to the map compare page.

* Show full-detail map tiles rendered by the app when zooming in on the map compare page.

* Install broodmap from a vendored package with region renders until it's released.

Built from ShieldBattery/broodmap#11 at 2afeb5a. Swap the file: spec for a registry version once it's published.

* Render map compare tiles one at a time with broodmap's region render.
2Pacalypse- added a commit to ShieldBattery/ShieldBattery that referenced this pull request Nov 17, 2026
…icker, highlight and subtract views. (#1885)

* Compare maps on their own linkable page, with split, slider, fade, flicker, highlight and subtract views.

* Mock the map compare page metadata resolver in the page metadata tests.

* Keep map family editor drafts when adding a file, and route compare page map links in the app.

* Add a copy link button to the map compare page.

* Show full-detail map tiles rendered by the app when zooming in on the map compare page.

* Install broodmap from a vendored package with region renders until it's released.

Built from ShieldBattery/broodmap#11 at 2afeb5a. Swap the file: spec for a registry version once it's published.

* Render map compare tiles one at a time with broodmap's region render.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant