Repository navigation
Read render assets from a SC:R install in the wasm bindings - #7
Merged
Merged
Conversation
2Pacalypse-
added a commit
to ShieldBattery/ShieldBattery
that referenced
this pull request
Oct 23, 2026
…StarCraft install. The app renders them with broodmap from the install's own assets, in the server's style, and caches them as JPEGs by file hash and game build. The vendored broodmap package is repacked from ShieldBattery/broodmap#7 for CascStorage.
2Pacalypse-
added a commit
to ShieldBattery/ShieldBattery
that referenced
this pull request
Oct 23, 2026
…StarCraft install. (#1788) * Show map files the server doesn't have with images rendered from the StarCraft install. The app renders them with broodmap from the install's own assets, in the server's style, and caches them as JPEGs by file hash and game build. The vendored broodmap package is repacked from ShieldBattery/broodmap#7 for CascStorage. * List maps on this PC from the files alone, asking the server about a file only when it's chosen. With images rendered locally, the per-page mapsByHash lookup only added server stats and badges to the tab. A chosen file now checks its own hash: a known map is opened or picked without uploading, an unknown one is uploaded first. * Render a batch of local map images in list order, newest batch first. * Load local map images only for tiles on screen, a couple at a time in layout order. Lazy-loaded images were requested well below the screen, so the renderer's queue couldn't tell which maps were visible. The client now decides, and the app renders requests in the order they arrive. * Say that maps from this PC upload when first used, and show when the server is processing one. * Remove mapFileIdToHash, which nothing uses anymore.
2Pacalypse-
added a commit
to ShieldBattery/ShieldBattery
that referenced
this pull request
Oct 24, 2026
…StarCraft install. (#1788) * Show map files the server doesn't have with images rendered from the StarCraft install. The app renders them with broodmap from the install's own assets, in the server's style, and caches them as JPEGs by file hash and game build. The vendored broodmap package is repacked from ShieldBattery/broodmap#7 for CascStorage. * List maps on this PC from the files alone, asking the server about a file only when it's chosen. With images rendered locally, the per-page mapsByHash lookup only added server stats and badges to the tab. A chosen file now checks its own hash: a known map is opened or picked without uploading, an unknown one is uploaded first. * Render a batch of local map images in list order, newest batch first. * Load local map images only for tiles on screen, a couple at a time in layout order. Lazy-loaded images were requested well below the screen, so the renderer's queue couldn't tell which maps were visible. The client now decides, and the app renders requests in the order they arrive. * Say that maps from this PC upload when first used, and show when the server is processing one. * Remove mapFileIdToHash, which nothing uses anymore.
CascStorage runs broodcasc over host-provided sync file callbacks, and MapRenderer.loadAssets fills both prefetch rounds from it. Decoded assets are shared across maps in a size-bounded cache, since every render needs the ~38 MB mainSD.anim.
broodcasc reserves at most 8 MiB for a decoded asset and doubles past that, so the ~38 MB mainSD.anim went through 16, 32 and 64 MiB buffers and left WASM memory at 163 MB after the first render. Reserving up to 64 MiB brings that to 116 MB; most of the rest is the Vec to Arc copy, which needs a decode-into-buffer API in broodcasc to avoid. read() now fills a view of WASM memory instead of a JS buffer that was then copied in, and CascFiles/CascStorageOptions are declared for TypeScript callers.
tec27
force-pushed
the
wasm-casc-source
branch
from
October 24, 2026 22:58
56b5875 to
bc6dada
Compare
broodcasc's read_file now reserves the exact decoded size, so the initial reserve workaround is gone, and read_file_into lets both CascStorage and CascSource decode into the Arc they return instead of copying a Vec into one. WASM memory after the first render drops from 116 MB to 61 MB, and after opening the install from 22 MB to 14 MB. fast-inflate is enabled explicitly: broodmap-render's broodcasc dependency only reaches the wasm build in dev-dependencies, so the package wasn't getting it.
The wasm package comes out ~8% smaller (1.86 to 1.71 MB) at the same speed.
2Pacalypse-
added a commit
to ShieldBattery/ShieldBattery
that referenced
this pull request
Oct 27, 2026
…StarCraft install. (#1788) * Show map files the server doesn't have with images rendered from the StarCraft install. The app renders them with broodmap from the install's own assets, in the server's style, and caches them as JPEGs by file hash and game build. The vendored broodmap package is repacked from ShieldBattery/broodmap#7 for CascStorage. * List maps on this PC from the files alone, asking the server about a file only when it's chosen. With images rendered locally, the per-page mapsByHash lookup only added server stats and badges to the tab. A chosen file now checks its own hash: a known map is opened or picked without uploading, an unknown one is uploaded first. * Render a batch of local map images in list order, newest batch first. * Load local map images only for tiles on screen, a couple at a time in layout order. Lazy-loaded images were requested well below the screen, so the renderer's queue couldn't tell which maps were visible. The client now decides, and the app renders requests in the order they arrive. * Say that maps from this PC upload when first used, and show when the server is processing one. * Remove mapFileIdToHash, which nothing uses anymore.
2Pacalypse-
added a commit
to ShieldBattery/ShieldBattery
that referenced
this pull request
Nov 10, 2026
…StarCraft install. (#1788) * Show map files the server doesn't have with images rendered from the StarCraft install. The app renders them with broodmap from the install's own assets, in the server's style, and caches them as JPEGs by file hash and game build. The vendored broodmap package is repacked from ShieldBattery/broodmap#7 for CascStorage. * List maps on this PC from the files alone, asking the server about a file only when it's chosen. With images rendered locally, the per-page mapsByHash lookup only added server stats and badges to the tab. A chosen file now checks its own hash: a known map is opened or picked without uploading, an unknown one is uploaded first. * Render a batch of local map images in list order, newest batch first. * Load local map images only for tiles on screen, a couple at a time in layout order. Lazy-loaded images were requested well below the screen, so the renderer's queue couldn't tell which maps were visible. The client now decides, and the app renders requests in the order they arrive. * Say that maps from this PC upload when first used, and show when the server is processing one. * Remove mapFileIdToHash, which nothing uses anymore.
2Pacalypse-
added a commit
to ShieldBattery/ShieldBattery
that referenced
this pull request
Nov 15, 2026
…StarCraft install. (#1788) * Show map files the server doesn't have with images rendered from the StarCraft install. The app renders them with broodmap from the install's own assets, in the server's style, and caches them as JPEGs by file hash and game build. The vendored broodmap package is repacked from ShieldBattery/broodmap#7 for CascStorage. * List maps on this PC from the files alone, asking the server about a file only when it's chosen. With images rendered locally, the per-page mapsByHash lookup only added server stats and badges to the tab. A chosen file now checks its own hash: a known map is opened or picked without uploading, an unknown one is uploaded first. * Render a batch of local map images in list order, newest batch first. * Load local map images only for tiles on screen, a couple at a time in layout order. Lazy-loaded images were requested well below the screen, so the renderer's queue couldn't tell which maps were visible. The client now decides, and the app renders requests in the order they arrive. * Say that maps from this PC upload when first used, and show when the server is processing one. * Remove mapFileIdToHash, which nothing uses anymore.
2Pacalypse-
added a commit
to ShieldBattery/ShieldBattery
that referenced
this pull request
Nov 17, 2026
…StarCraft install. (#1788) * Show map files the server doesn't have with images rendered from the StarCraft install. The app renders them with broodmap from the install's own assets, in the server's style, and caches them as JPEGs by file hash and game build. The vendored broodmap package is repacked from ShieldBattery/broodmap#7 for CascStorage. * List maps on this PC from the files alone, asking the server about a file only when it's chosen. With images rendered locally, the per-page mapsByHash lookup only added server stats and badges to the tab. A chosen file now checks its own hash: a known map is opened or picked without uploading, an unknown one is uploaded first. * Render a batch of local map images in list order, newest batch first. * Load local map images only for tiles on screen, a couple at a time in layout order. Lazy-loaded images were requested well below the screen, so the renderer's queue couldn't tell which maps were visible. The client now decides, and the app renders requests in the order they arrive. * Say that maps from this PC upload when first used, and show when the server is processing one. * Remove mapFileIdToHash, which nothing uses anymore.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets the wasm bindings read render assets straight from a SC:R install's CASC storage. Hosts that can read files synchronously (Node, Electron) then need no prefetch and no extracted asset directory. ShieldBattery uses it to render previews of map files in a user's map folders that its server has never seen, using the user's own install, in the same style as server renders. This is B4 from the map render plan.
CascStorage(src/casc.rs)new CascStorage(files, options?)runs broodcasc in wasm over five host callbacks:open(path),size(handle),read(handle, buffer, position),close(handle)andlistDir(path). Paths are relative to the install directory. In Node they map one to one ontofs.openSync/fstatSync/readSync/closeSync/readdirSync;examples/casc-files.mjsis that adapter. TypeScript sees the callbacks asCascFilesand the options asCascStorageOptions.read'sbufferis a view of wasm memory, so reads land there directly instead of going through a JS buffer and a copy. As a result, the callbacks must not call back into the module.ea3556d, with default features off (fsdoesn't build for wasm32) andfast-inflateon. broodmap-render's own broodcasc dependency only reaches the wasm build through dev-dependencies, so it doesn't supply that feature.Send + Sync, so the JS handles getunsafe impls. That's sound because a wasm32 target without atomics has one thread; acompile_error!guards theatomicscase. On native targets, wasm-bindgen imports panic, so no handle can be created.Arc<[u8]>that's shared from then on, via broodcasc'sread_file_into: one allocation of exactly the decoded size, checked against broodcasc's decoded-size limit before allocating. broodmap-render's nativeCascSourcedoes the same.MapRendererloading from the same storage. It evicts the least recently used entries first,cacheBytesdefaults to 128 MiB, and entries are shared without copies. Every render needs the ~38 MBSD/mainSD.anim, so without the cache each map would decode it again.storage.versionis the install's game version, for keying image caches;cachedBytesreports the cache's size.MapRenderer.loadAssets(storage, options).dattable) or on any read error, so callers don't cache a degraded image because of a transient I/O failure.Build
lto = trueandcodegen-units = 1. That makes the.wasmabout 8% smaller (1.86 → 1.71 MB) at the same speed; incremental rebuilds are about as fast as before.js-sysbringswasm-bindgenfrom 0.2.126 to 0.2.129 in the lockfile.Testing
New native tests: cache eviction and budget, missing vs failed reads, and base-asset failures.
load_assets_matches_the_prefetch_flowchecks thatloadAssetsand the prefetch flow give byte-identical PNGs from a real install. Like broodmap-render's real-asset tests, it needsBROODMAP_TEST_SCR_DIR. Those tests and this one pass against SC:R 1.23.10.13515.pnpm run test:package: in CI, it checks that incomplete callbacks and a directory that isn't an install both throw. WithBROODMAP_TEST_SCR_DIRset, it also renders from a real install and checks that a second render reads only from the cache.pnpm run test:typescovers the new declarations.pnpm test(111/111),cargo test --workspace,cargo fmt, andcargo clippyboth native (--workspace --all-targets --all-features) and forwasm32-unknown-unknown.Output is byte-identical to a render from an extracted
fetch-assetsdirectory.Measured in Node on a desktop with 512 px
original-style renders:lt.scm, first render:loadAssetslt.scm, first render: totallt.scm, later renderTo try it:
pnpm run build, thennode examples/node-casc.mjs "C:/Program Files (x86)/StarCraft" ../broodmap/assets/lt.scm.