@wildshard/sdk 0.0.0 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GUIDE.md +790 -0
- package/README.md +14 -4
- package/bin/wildshard.mjs +38 -0
- package/lint/declaration-config.d.mts +2 -0
- package/lint/declaration-config.mjs +19 -0
- package/lint/engine-plugin.d.mts +2 -0
- package/lint/engine-plugin.mjs +40 -0
- package/lint/host-callbacks.d.mts +6 -0
- package/lint/host-callbacks.mjs +123 -0
- package/lint/host-files.d.mts +1 -0
- package/lint/host-files.mjs +7 -0
- package/lint/layer-exports.d.mts +2 -0
- package/lint/layer-exports.mjs +21 -0
- package/lint/legacy-line-basis.json +995 -0
- package/lint/nine-tiling-baseline.json +35 -0
- package/lint/ratchet.json +11 -0
- package/lint/runtime-files.d.mts +12 -0
- package/lint/runtime-files.json +16 -0
- package/lint/runtime-files.mjs +69 -0
- package/lint/runtime-performance.d.mts +6 -0
- package/lint/runtime-performance.mjs +184 -0
- package/lint/sdk-plugin.d.mts +4 -0
- package/lint/sdk-plugin.mjs +134 -0
- package/lint/shardfile-boundaries.d.mts +10 -0
- package/lint/shardfile-boundaries.mjs +122 -0
- package/lint/tile-bake-debt.json +556 -0
- package/package.json +371 -4
- package/scripts/agent-parity.mjs +1524 -0
- package/scripts/agent-sync.mjs +518 -0
- package/scripts/apfs-clone.mjs +67 -0
- package/scripts/assert-store-layout.mjs +23 -0
- package/scripts/astc6-phone-cap.d.mts +3 -0
- package/scripts/astc6-phone-cap.mjs +137 -0
- package/scripts/audit-assets.d.mts +10 -0
- package/scripts/audit-assets.mjs +151 -0
- package/scripts/bake/coatFiles.d.mts +6 -0
- package/scripts/bake/coatFiles.mjs +37 -0
- package/scripts/bake/environment.d.mts +2 -0
- package/scripts/bake/environment.mjs +58 -0
- package/scripts/bake/far-proxies.mjs +45 -0
- package/scripts/bake/keyed-sky.d.mts +4 -0
- package/scripts/bake/keyed-sky.mjs +34 -0
- package/scripts/bake/movers.mjs +56 -0
- package/scripts/bake/nativeWorld.d.mts +6 -0
- package/scripts/bake/nativeWorld.mjs +43 -0
- package/scripts/bake/navmeshGround.ts +22 -0
- package/scripts/bake/near-placeholder.mjs +331 -0
- package/scripts/bake/placeholderShards.mjs +41 -0
- package/scripts/bake/skins.mjs +15 -0
- package/scripts/bake/template-skins.mjs +33 -0
- package/scripts/bake/viewmodelBytes.ts +26 -0
- package/scripts/bake/viewmodelPage.ts +11 -0
- package/scripts/bake/worldHost.d.mts +35 -0
- package/scripts/bake/worldHost.mjs +110 -0
- package/scripts/bake-astc6.cache.json +80 -0
- package/scripts/bake-astc6.far-reach.cache.json +23 -0
- package/scripts/bake-astc6.list.json +111 -0
- package/scripts/bake-astc6.mjs +279 -0
- package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
- package/scripts/bake-catalogue.mjs +44 -0
- package/scripts/bake-check.mjs +54 -0
- package/scripts/bake-chunk.mjs +124 -0
- package/scripts/bake-cloud-field.mjs +24 -0
- package/scripts/bake-coats.mjs +110 -0
- package/scripts/bake-data-maps.d.mts +24 -0
- package/scripts/bake-data-maps.mjs +72 -0
- package/scripts/bake-entry-programs.mjs +117 -0
- package/scripts/bake-geometry.mjs +106 -0
- package/scripts/bake-hybrid-tiles.mjs +28 -0
- package/scripts/bake-ktx2.cache.json +276 -0
- package/scripts/bake-ktx2.list.json +365 -0
- package/scripts/bake-ktx2.mjs +477 -0
- package/scripts/bake-map-glb.mjs +127 -0
- package/scripts/bake-map-rest.d.mts +7 -0
- package/scripts/bake-map-rest.mjs +50 -0
- package/scripts/bake-maps.mjs +200 -0
- package/scripts/bake-navmesh.mjs +259 -0
- package/scripts/bake-packs.mjs +129 -0
- package/scripts/bake-pickups.mjs +102 -0
- package/scripts/bake-query-terrain.mjs +64 -0
- package/scripts/bake-recurve-pool.mjs +16 -0
- package/scripts/bake-section-schemas.d.mts +3 -0
- package/scripts/bake-template-shardfile.mjs +32 -0
- package/scripts/bake-textures.mjs +80 -0
- package/scripts/bake-viewmodel-sets.json +45 -0
- package/scripts/bake-viewmodel-sets.mjs +137 -0
- package/scripts/bake-voxel-ao.mjs +119 -0
- package/scripts/bake-water-ripples.mjs +25 -0
- package/scripts/blender/README.md +129 -0
- package/scripts/blender/build.sh +166 -0
- package/scripts/blender/lib/export-scene.mjs +129 -0
- package/scripts/blender/lib/glb-digest.mjs +188 -0
- package/scripts/blender/lib/glb.py +68 -0
- package/scripts/blender/lib/save_blend.py +17 -0
- package/scripts/blender/lib/world_fixture.py +55 -0
- package/scripts/blender/targets.json +591 -0
- package/scripts/build-sdk.mjs +95 -0
- package/scripts/build-shardfiles.d.mts +7 -0
- package/scripts/build-shardfiles.mjs +206 -0
- package/scripts/capture-hero.mjs +137 -0
- package/scripts/check-lift-review.mjs +23 -0
- package/scripts/chromium-keychain-check.mjs +139 -0
- package/scripts/chromium-keychain.d.mts +1 -0
- package/scripts/chromium-keychain.mjs +5 -0
- package/scripts/compile-script.d.mts +3 -0
- package/scripts/compile-script.mjs +8 -0
- package/scripts/creature-color.mjs +255 -0
- package/scripts/decide/calibrate.py +127 -0
- package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
- package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
- package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
- package/scripts/decide/decide.py +262 -0
- package/scripts/decide/decide.sh +50 -0
- package/scripts/decide/layer-purity-pilot.mjs +41 -0
- package/scripts/decide/sets/capture-status.json +46 -0
- package/scripts/decide/sets/layer-purity.json +28 -0
- package/scripts/decide/sets/text-garbled.json +17 -0
- package/scripts/decide/test_decide.py +37 -0
- package/scripts/docs.mjs +15 -0
- package/scripts/entry-reads/crawl.ts +152 -0
- package/scripts/entry-reads/tsconfig.json +25 -0
- package/scripts/gen-format-schema.d.mts +2 -0
- package/scripts/gen-format-schema.mjs +21 -0
- package/scripts/gen-host-catalogue.d.mts +14 -0
- package/scripts/gen-host-catalogue.mjs +108 -0
- package/scripts/gen-shard-layout-doc.d.mts +4 -0
- package/scripts/gen-shard-layout-doc.mjs +55 -0
- package/scripts/gen-shards.d.mts +17 -0
- package/scripts/gen-shards.mjs +311 -0
- package/scripts/goldens/capture-inputs.d.mts +4 -0
- package/scripts/goldens/capture-inputs.mjs +34 -0
- package/scripts/goldens/colour_shift.py +27 -0
- package/scripts/goldens/native-residency.d.mts +10 -0
- package/scripts/goldens/native-residency.mjs +104 -0
- package/scripts/goldens/plot-inputs.d.mts +12 -0
- package/scripts/goldens/plot-inputs.mjs +46 -0
- package/scripts/gpu-texmem.mjs +98 -0
- package/scripts/horizon-matte/config.py +24 -0
- package/scripts/horizon-matte/encode.py +91 -0
- package/scripts/horizon-matte/key.py +141 -0
- package/scripts/horizon-matte/mkjobs.py +33 -0
- package/scripts/horizon-matte/mkjobs_day2.py +11 -0
- package/scripts/horizon-matte/overlap.py +80 -0
- package/scripts/horizon-matte/run_codex.py +57 -0
- package/scripts/horizon-matte/stitch.py +133 -0
- package/scripts/img2mesh/CC0.md +105 -0
- package/scripts/img2mesh/README.md +209 -0
- package/scripts/img2mesh/ab_board.py +102 -0
- package/scripts/img2mesh/birds/birds.json +255 -0
- package/scripts/img2mesh/birds/birds_atlas.py +150 -0
- package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
- package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
- package/scripts/img2mesh/birds/birds_pack.py +110 -0
- package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
- package/scripts/img2mesh/birds/birds_post.py +550 -0
- package/scripts/img2mesh/birds/birds_render.py +125 -0
- package/scripts/img2mesh/birds/birds_sheet.py +33 -0
- package/scripts/img2mesh/birds/birds_view.py +60 -0
- package/scripts/img2mesh/board.py +100 -0
- package/scripts/img2mesh/build_cc0.sh +52 -0
- package/scripts/img2mesh/build_driftwood.sh +12 -0
- package/scripts/img2mesh/build_faces.sh +53 -0
- package/scripts/img2mesh/build_props.py +81 -0
- package/scripts/img2mesh/cc0_export.py +186 -0
- package/scripts/img2mesh/driftwood_post.py +571 -0
- package/scripts/img2mesh/e304_faces.sh +67 -0
- package/scripts/img2mesh/face_remaster.py +911 -0
- package/scripts/img2mesh/face_views.py +95 -0
- package/scripts/img2mesh/faces-e304.json +9 -0
- package/scripts/img2mesh/faces.json +30 -0
- package/scripts/img2mesh/head_cut.py +100 -0
- package/scripts/img2mesh/hi3d_paint.py +94 -0
- package/scripts/img2mesh/hi3d_refine.py +161 -0
- package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
- package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
- package/scripts/img2mesh/props/coral-arch.json +32 -0
- package/scripts/img2mesh/props/ember-furnace.json +30 -0
- package/scripts/img2mesh/props/night-market-gate.json +10 -0
- package/scripts/img2mesh/render_still.py +86 -0
- package/scripts/img2mesh/rig_strip.mjs +46 -0
- package/scripts/img2mesh/rig_transfer.mjs +104 -0
- package/scripts/img2mesh/split_sheet.py +48 -0
- package/scripts/img2mesh/trellis_batch.py +110 -0
- package/scripts/img2mesh/versus_board.py +114 -0
- package/scripts/import-bundle.d.mts +2 -0
- package/scripts/import-bundle.mjs +20 -0
- package/scripts/ktx2-ab-board.py +133 -0
- package/scripts/ktx2-ab.mjs +111 -0
- package/scripts/ktx2-settings.mjs +18 -0
- package/scripts/land.d.mts +14 -0
- package/scripts/land.mjs +809 -0
- package/scripts/lint-dispatch.mjs +14 -0
- package/scripts/map-bake-frames.d.mts +4 -0
- package/scripts/map-bake-frames.mjs +23 -0
- package/scripts/map-geometry.d.mts +9 -0
- package/scripts/map-geometry.mjs +29 -0
- package/scripts/map-world.mjs +162 -0
- package/scripts/mockup-local.sh +46 -0
- package/scripts/music/export-midi.mjs +68 -0
- package/scripts/music/gen/analyze.py +308 -0
- package/scripts/music/gen/audio_jobs.py +46 -0
- package/scripts/music/gen/briefs.json +51 -0
- package/scripts/music/gen/build_page.py +334 -0
- package/scripts/music/gen/folk.json +3187 -0
- package/scripts/music/gen/gen_ace_step.py +156 -0
- package/scripts/music/gen/gen_heartmula.py +187 -0
- package/scripts/music/gen/gen_minimax.py +143 -0
- package/scripts/music/gen/gen_sao.py +122 -0
- package/scripts/music/gen/gen_sao_small.py +104 -0
- package/scripts/music/gen/gen_sfx.py +98 -0
- package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
- package/scripts/music/gen/gen_sfx_moss.py +112 -0
- package/scripts/music/gen/models.json +61 -0
- package/scripts/music/gen/nalati-jobs.json +104 -0
- package/scripts/music/gen/nalati-score-build.json +119 -0
- package/scripts/music/gen/nalati-score.json +3448 -0
- package/scripts/music/gen/ob7-fit-decisions.json +38 -0
- package/scripts/music/gen/ob7-score-jobs.json +152 -0
- package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
- package/scripts/music/gen/ob7_build.py +469 -0
- package/scripts/music/gen/ob7_generate.py +67 -0
- package/scripts/music/gen/ob7_run.sh +42 -0
- package/scripts/music/gen/orchestral.json +3187 -0
- package/scripts/music/gen/own_score.py +486 -0
- package/scripts/music/gen/ph-jobs.json +27 -0
- package/scripts/music/gen/ph_page.py +222 -0
- package/scripts/music/gen/piano.json +3175 -0
- package/scripts/music/gen/rank_v3.py +248 -0
- package/scripts/music/gen/sfx-best.json +2486 -0
- package/scripts/music/gen/sfx-ezaudio.json +4082 -0
- package/scripts/music/gen/sfx-jobs.json +57 -0
- package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
- package/scripts/music/gen/sfx-minimax.json +289 -0
- package/scripts/music/gen/sfx-moss.json +4082 -0
- package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
- package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
- package/scripts/music/gen/sfx-nalati.json +11202 -0
- package/scripts/music/gen/sfx-nd-jobs.json +57 -0
- package/scripts/music/gen/sfx-nd-moss.json +2097 -0
- package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
- package/scripts/music/gen/sfx-nd-summary.json +38 -0
- package/scripts/music/gen/sfx-peaks.json +7 -0
- package/scripts/music/gen/sfx-ph-jobs.json +169 -0
- package/scripts/music/gen/sfx-ph-moss.json +6564 -0
- package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
- package/scripts/music/gen/sfx-ph-summary.json +63 -0
- package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
- package/scripts/music/gen/sfx-sa3.json +4082 -0
- package/scripts/music/gen/sfx-summary.json +107 -0
- package/scripts/music/gen/sfx_build.py +332 -0
- package/scripts/music/gen/sfx_merge.py +255 -0
- package/scripts/music/gen/sfx_minimax.py +61 -0
- package/scripts/music/gen/sfx_nalati.py +331 -0
- package/scripts/music/gen/sfx_sprite.py +424 -0
- package/scripts/music/gen/stems.py +539 -0
- package/scripts/music/gen/test_loop_meter.py +29 -0
- package/scripts/music/gen/test_ob7_provenance.py +77 -0
- package/scripts/music/gen/v3-folk-build.json +148 -0
- package/scripts/music/gen/v3-folk.json +1818 -0
- package/scripts/music/gen/v3-jobs.json +145 -0
- package/scripts/music/gen/v3-orchestral-build.json +148 -0
- package/scripts/music/gen/v3-orchestral.json +1813 -0
- package/scripts/music/gen/v3-ph-folk-build.json +94 -0
- package/scripts/music/gen/v3-ph-folk.json +1806 -0
- package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
- package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
- package/scripts/music/gen/v3-ph-piano-build.json +94 -0
- package/scripts/music/gen/v3-ph-piano.json +1818 -0
- package/scripts/music/gen/v3-piano-build.json +148 -0
- package/scripts/music/gen/v3-piano.json +1813 -0
- package/scripts/music/wildshard-theme.mid +0 -0
- package/scripts/music/wildshard-trailer30.mid +0 -0
- package/scripts/named-blob-output.d.mts +8 -0
- package/scripts/named-blob-output.mjs +48 -0
- package/scripts/pack-all.mjs +15 -0
- package/scripts/pid-lock.d.mts +1 -0
- package/scripts/pid-lock.mjs +63 -0
- package/scripts/practice/bake_dummy.py +53 -0
- package/scripts/practice/build_dummies.sh +43 -0
- package/scripts/practice/dummy_parts.py +568 -0
- package/scripts/practice/dummy_rig_gate.py +139 -0
- package/scripts/practice/gate_sheet.py +36 -0
- package/scripts/practice/generate_dummy_unimate.py +132 -0
- package/scripts/practice/pack_dummy.mjs +59 -0
- package/scripts/practice/repair_dummy_weights.mjs +68 -0
- package/scripts/practice/rig_dummy.py +828 -0
- package/scripts/practice/verify_unimate_skin.mjs +356 -0
- package/scripts/preparation-seed.mjs +15 -0
- package/scripts/prepare-basis-tool.mjs +6 -0
- package/scripts/prepare-product.d.mts +14 -0
- package/scripts/prepare-product.mjs +101 -0
- package/scripts/product-build-tools.d.mts +3 -0
- package/scripts/product-build-tools.json +3 -0
- package/scripts/product-build-tools.mjs +31 -0
- package/scripts/publish-public.mjs +7 -0
- package/scripts/push-tables.d.mts +1 -0
- package/scripts/push-tables.mjs +28 -0
- package/scripts/record-shard-mounts.mjs +133 -0
- package/scripts/sdk-externals.d.mts +2 -0
- package/scripts/sdk-externals.mjs +2 -0
- package/scripts/section-inventory.ts +209 -0
- package/scripts/select-candidate.mjs +15 -0
- package/scripts/shard-build-pool.d.mts +4 -0
- package/scripts/shard-build-pool.mjs +53 -0
- package/scripts/shard-line-baseline.json +17 -0
- package/scripts/shard-milestones.d.mts +15 -0
- package/scripts/shard-milestones.mjs +105 -0
- package/scripts/shard-output-report.d.mts +9 -0
- package/scripts/shard-output-report.mjs +85 -0
- package/scripts/shard-platform-cli.mjs +93 -0
- package/scripts/shard-progress.mjs +212 -0
- package/scripts/shard-timelapse.py +102 -0
- package/scripts/shardfile-cold-boot.mjs +79 -0
- package/scripts/shardfile-vite.d.mts +4 -0
- package/scripts/shardfile-vite.mjs +20 -0
- package/scripts/simplify-models.mjs +24 -0
- package/scripts/site-facts.mjs +88 -0
- package/scripts/test-template-gate.mjs +44 -0
- package/scripts/test_golden_compare.py +68 -0
- package/scripts/tex-tiers.cache.json +181 -0
- package/scripts/tex-tiers.mjs +240 -0
- package/scripts/texmem-probe.mjs +184 -0
- package/scripts/unused-assets.mjs +173 -0
- package/scripts/vite-tmp.d.mts +23 -0
- package/scripts/vite-tmp.mjs +157 -0
- package/scripts/wave-line-baselines.json +32 -0
- package/scripts/wildshard.d.mts +4 -0
- package/scripts/wildshard.mjs +105 -0
- package/scripts/witness-checkpoints.d.mts +10 -0
- package/scripts/witness-checkpoints.mjs +84 -0
- package/scripts/witness-generation.d.mts +10 -0
- package/scripts/witness-generation.mjs +45 -0
- package/scripts/witness-manifests.d.mts +8 -0
- package/scripts/witness-manifests.mjs +157 -0
- package/scripts/worktree-ignore.d.mts +4 -0
- package/scripts/worktree-ignore.mjs +36 -0
- package/scripts/worktree-reap.mjs +214 -0
- package/scripts/worktree.mjs +396 -0
- package/scripts/worldclaw/capture-front.sh +28 -0
- package/scripts/worldclaw/design-template.md +62 -0
- package/scripts/worldclaw/spec-map.py +92 -0
- package/scripts/worldclaw/spec.ts +96 -0
- package/skills/wildshard/SKILL.md +50 -0
- package/skills/wildshard-goldens/SKILL.md +54 -0
- package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
- package/skills/wildshard-upgrade/SKILL.md +46 -0
- package/src/.oxfmtrc.json +50 -0
- package/src/.oxlintrc.json +173 -0
- package/src/cli/account/account.ts +199 -0
- package/src/cli/account/command.ts +193 -0
- package/src/cli/account/key.ts +154 -0
- package/src/cli/args.ts +97 -0
- package/src/cli/audio/audio.ts +24 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +196 -0
- package/src/cli/hero/adopt.ts +103 -0
- package/src/cli/hero/hero.ts +112 -0
- package/src/cli/hero/stamp.ts +298 -0
- package/src/cli/main.ts +292 -0
- package/src/cli/report.ts +16 -0
- package/src/cli/shardfile/command.ts +50 -0
- package/src/cli/shardfile/shardfile.ts +192 -0
- package/src/cli/upload/api.ts +246 -0
- package/src/cli/upload/compress.ts +55 -0
- package/src/cli/upload/hero.ts +62 -0
- package/src/cli/upload/placement.ts +115 -0
- package/src/cli/upload/provenance.ts +192 -0
- package/src/cli/upload/signature.ts +30 -0
- package/src/cli/upload/upload.ts +269 -0
- package/src/cli/upload/validate.ts +74 -0
- package/src/cli/upload/wire.ts +147 -0
- package/src/cli/version.ts +63 -0
- package/src/commons/bake/portableMath.ts +187 -0
- package/src/commons/catalogue.ts +10 -0
- package/src/commons/courseProgram.ts +32 -0
- package/src/commons/practiceCourse.ts +16 -0
- package/src/commons/scripts/abi.as +14 -0
- package/src/commons/scripts/bridge.as +14 -0
- package/src/commons/scripts/course.as +63 -0
- package/src/scripts/ask-new.sh +29 -0
- package/src/scripts/asks.mjs +141 -0
- package/src/scripts/herdr-prompt.sh +34 -0
- package/src/scripts/herdr-question-open.sh +67 -0
- package/src/scripts/md-wrap.mjs +229 -0
- package/src/server/app.ts +19 -0
- package/src/server/serve.ts +49 -0
- package/src/sharddev/admission.ts +7 -0
- package/src/sharddev/arenaView.ts +15 -0
- package/src/sharddev/as/groupBankV2.ts +36 -0
- package/src/sharddev/as/groupStepV2.ts +13 -0
- package/src/sharddev/as/ws.ts +30 -0
- package/src/sharddev/as/wsV2.ts +180 -0
- package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
- package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
- package/src/sharddev/assetHandle.ts +84 -0
- package/src/sharddev/assetOwner.ts +70 -0
- package/src/sharddev/assetScope.ts +30 -0
- package/src/sharddev/assets.ts +21 -0
- package/src/sharddev/audio.ts +9 -0
- package/src/sharddev/audioEncode.ts +211 -0
- package/src/sharddev/author.ts +3 -0
- package/src/sharddev/authorError.ts +28 -0
- package/src/sharddev/authorManifest.ts +39 -0
- package/src/sharddev/bake/annulus.ts +19 -0
- package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
- package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
- package/src/sharddev/bake/authoredWorld.ts +201 -0
- package/src/sharddev/bake/basisEncoder.ts +95 -0
- package/src/sharddev/bake/basisGlb.ts +85 -0
- package/src/sharddev/bake/basisTool.ts +74 -0
- package/src/sharddev/bake/basisToolInputs.ts +476 -0
- package/src/sharddev/bake/byteCodec.ts +33 -0
- package/src/sharddev/bake/canvasAtlas.ts +406 -0
- package/src/sharddev/bake/coarseCopy.ts +59 -0
- package/src/sharddev/bake/colliders.ts +87 -0
- package/src/sharddev/bake/compactGlb.ts +224 -0
- package/src/sharddev/bake/compileScript.ts +119 -0
- package/src/sharddev/bake/compileScriptV2.ts +75 -0
- package/src/sharddev/bake/contactRows.ts +84 -0
- package/src/sharddev/bake/creaturePlacement.ts +117 -0
- package/src/sharddev/bake/export.ts +67 -0
- package/src/sharddev/bake/facetedGeometry.ts +379 -0
- package/src/sharddev/bake/farImpostor.ts +120 -0
- package/src/sharddev/bake/forest.ts +100 -0
- package/src/sharddev/bake/format-hook.mjs +2 -0
- package/src/sharddev/bake/generatorGlb.ts +23 -0
- package/src/sharddev/bake/geometryBounds.ts +77 -0
- package/src/sharddev/bake/geometryError.ts +48 -0
- package/src/sharddev/bake/glb.ts +355 -0
- package/src/sharddev/bake/glbCompression.ts +143 -0
- package/src/sharddev/bake/gltfSource.ts +59 -0
- package/src/sharddev/bake/groundMap.ts +142 -0
- package/src/sharddev/bake/image.ts +20 -0
- package/src/sharddev/bake/isleMap.ts +64 -0
- package/src/sharddev/bake/json.mjs +84 -0
- package/src/sharddev/bake/keyedSky.ts +47 -0
- package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
- package/src/sharddev/bake/kinds.ts +137 -0
- package/src/sharddev/bake/lightSources.ts +31 -0
- package/src/sharddev/bake/mapAssembly.ts +84 -0
- package/src/sharddev/bake/mapRaster.ts +173 -0
- package/src/sharddev/bake/mapRest.ts +57 -0
- package/src/sharddev/bake/mapScenes.ts +234 -0
- package/src/sharddev/bake/materialGraph.ts +32 -0
- package/src/sharddev/bake/meadow.ts +27 -0
- package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
- package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
- package/src/sharddev/bake/nativeLattice.ts +178 -0
- package/src/sharddev/bake/nativeRaster.ts +106 -0
- package/src/sharddev/bake/nativeTerrainField.ts +11 -0
- package/src/sharddev/bake/navigation-json.mjs +38 -0
- package/src/sharddev/bake/navigation.ts +113 -0
- package/src/sharddev/bake/navigationAsset.ts +18 -0
- package/src/sharddev/bake/nearPlaceholder.ts +206 -0
- package/src/sharddev/bake/normalizeRig.ts +80 -0
- package/src/sharddev/bake/phoneAstc.ts +93 -0
- package/src/sharddev/bake/placeholders.ts +581 -0
- package/src/sharddev/bake/placement.ts +80 -0
- package/src/sharddev/bake/portableBytes.ts +18 -0
- package/src/sharddev/bake/portableBytesMemo.ts +50 -0
- package/src/sharddev/bake/practiceCourse.ts +49 -0
- package/src/sharddev/bake/primitives.ts +96 -0
- package/src/sharddev/bake/props.ts +443 -0
- package/src/sharddev/bake/questPlacement.ts +98 -0
- package/src/sharddev/bake/rawTexture.ts +26 -0
- package/src/sharddev/bake/riderArms.ts +97 -0
- package/src/sharddev/bake/rig.ts +95 -0
- package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
- package/src/sharddev/bake/signPlacements.ts +25 -0
- package/src/sharddev/bake/simplifier.ts +52 -0
- package/src/sharddev/bake/skinned.ts +312 -0
- package/src/sharddev/bake/slabChunks.ts +149 -0
- package/src/sharddev/bake/slabs.ts +263 -0
- package/src/sharddev/bake/source-loader.mjs +55 -0
- package/src/sharddev/bake/sourceMetadata.ts +54 -0
- package/src/sharddev/bake/species.ts +368 -0
- package/src/sharddev/bake/specimenCatalogue.ts +47 -0
- package/src/sharddev/bake/splatGround.ts +141 -0
- package/src/sharddev/bake/staticMaterials.ts +171 -0
- package/src/sharddev/bake/terrain.ts +195 -0
- package/src/sharddev/bake/texture.ts +33 -0
- package/src/sharddev/bake/textureWasm.ts +81 -0
- package/src/sharddev/bake/tileEncoder.ts +11 -0
- package/src/sharddev/bake/tileGrid.ts +62 -0
- package/src/sharddev/bake/v2Finite.ts +160 -0
- package/src/sharddev/bake/v2Fuel.ts +71 -0
- package/src/sharddev/bake/wholePartition.ts +74 -0
- package/src/sharddev/bake/wholePieceJoin.ts +147 -0
- package/src/sharddev/bake/world.ts +173 -0
- package/src/sharddev/bake/worldCollision.ts +128 -0
- package/src/sharddev/bake/worldGeometry.ts +237 -0
- package/src/sharddev/bake/worldGlb.ts +123 -0
- package/src/sharddev/bake/worldImage.ts +12 -0
- package/src/sharddev/bake/worldLod.ts +128 -0
- package/src/sharddev/bake/worldRows.ts +102 -0
- package/src/sharddev/bake/worldTextureMemo.ts +63 -0
- package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
- package/src/sharddev/bake.ts +193 -0
- package/src/sharddev/bakePublication.ts +31 -0
- package/src/sharddev/behaviourSource.ts +94 -0
- package/src/sharddev/bin/wildshard.mjs +7 -0
- package/src/sharddev/blobBytes.ts +65 -0
- package/src/sharddev/blobs.ts +138 -0
- package/src/sharddev/bootInventory.ts +129 -0
- package/src/sharddev/bossProfiles.ts +18 -0
- package/src/sharddev/buildBehaviour.ts +77 -0
- package/src/sharddev/buildCacheMetrics.ts +17 -0
- package/src/sharddev/buildDecisionScripts.ts +122 -0
- package/src/sharddev/check.ts +117 -0
- package/src/sharddev/checkProject.ts +126 -0
- package/src/sharddev/cli.ts +191 -0
- package/src/sharddev/clientChannels.ts +169 -0
- package/src/sharddev/clientScripts.ts +10 -0
- package/src/sharddev/commons.ts +77 -0
- package/src/sharddev/commonsCosts.ts +11 -0
- package/src/sharddev/compileMovers.ts +11 -0
- package/src/sharddev/configBoundary.ts +6 -0
- package/src/sharddev/cookInput.ts +40 -0
- package/src/sharddev/crowds.ts +6 -0
- package/src/sharddev/decisionBindingMap.ts +11 -0
- package/src/sharddev/decisionScriptBindings.ts +117 -0
- package/src/sharddev/decisionScripts.ts +28 -0
- package/src/sharddev/decisionSource.ts +51 -0
- package/src/sharddev/dev.ts +113 -0
- package/src/sharddev/director.ts +26 -0
- package/src/sharddev/directorAbi.ts +77 -0
- package/src/sharddev/discoveryDocument.ts +97 -0
- package/src/sharddev/draft.ts +11 -0
- package/src/sharddev/eliteEntryRows.ts +29 -0
- package/src/sharddev/entries.ts +76 -0
- package/src/sharddev/entryReads.ts +73 -0
- package/src/sharddev/executeBundle.ts +55 -0
- package/src/sharddev/finds.ts +5 -0
- package/src/sharddev/formatJsonSchema.ts +3 -0
- package/src/sharddev/generationCache.ts +257 -0
- package/src/sharddev/generationRecipe.ts +94 -0
- package/src/sharddev/handwritten.ts +110 -0
- package/src/sharddev/immutable.ts +14 -0
- package/src/sharddev/interactions.ts +38 -0
- package/src/sharddev/kit/bakedGeometry.ts +16 -0
- package/src/sharddev/kit/geometryPack.ts +110 -0
- package/src/sharddev/ledger.ts +13 -0
- package/src/sharddev/looks/tileField.ts +67 -0
- package/src/sharddev/materialGraphFiles.ts +57 -0
- package/src/sharddev/materials.ts +574 -0
- package/src/sharddev/measure.ts +18 -0
- package/src/sharddev/modes.ts +115 -0
- package/src/sharddev/moverPrograms.ts +213 -0
- package/src/sharddev/movers.ts +75 -0
- package/src/sharddev/nativePopulationRows.ts +46 -0
- package/src/sharddev/newProject.ts +247 -0
- package/src/sharddev/noise.ts +54 -0
- package/src/sharddev/outputProduct.ts +188 -0
- package/src/sharddev/outputRuntime.ts +66 -0
- package/src/sharddev/performancePolicy.ts +18 -0
- package/src/sharddev/phasedBoss.ts +34 -0
- package/src/sharddev/physics.ts +194 -0
- package/src/sharddev/platformSections.ts +42 -0
- package/src/sharddev/plumbing.ts +8 -0
- package/src/sharddev/productOutput.ts +128 -0
- package/src/sharddev/project.ts +337 -0
- package/src/sharddev/projectCompilerIdentity.ts +94 -0
- package/src/sharddev/projectDecisions.ts +66 -0
- package/src/sharddev/projectEntryProof.ts +32 -0
- package/src/sharddev/projectGeneration.ts +219 -0
- package/src/sharddev/projectInputFiles.ts +47 -0
- package/src/sharddev/projectManifest.ts +108 -0
- package/src/sharddev/projectMap.ts +35 -0
- package/src/sharddev/projectOutput.ts +242 -0
- package/src/sharddev/projectPolicy.ts +17 -0
- package/src/sharddev/projectSections.ts +27 -0
- package/src/sharddev/questGraph.ts +25 -0
- package/src/sharddev/quests.ts +65 -0
- package/src/sharddev/random.ts +61 -0
- package/src/sharddev/refusals.ts +234 -0
- package/src/sharddev/reportCard.ts +13 -0
- package/src/sharddev/returnProjectionV2.ts +81 -0
- package/src/sharddev/rows.ts +192 -0
- package/src/sharddev/runtimeImports.ts +38 -0
- package/src/sharddev/runtimeMirrors.ts +39 -0
- package/src/sharddev/runtimePerformance.ts +38 -0
- package/src/sharddev/scene.ts +321 -0
- package/src/sharddev/sceneAnimation.ts +54 -0
- package/src/sharddev/sceneAudio.ts +64 -0
- package/src/sharddev/sceneDeclarations.ts +100 -0
- package/src/sharddev/sceneGraph.ts +139 -0
- package/src/sharddev/sceneTransform.ts +12 -0
- package/src/sharddev/schemaValidation.ts +61 -0
- package/src/sharddev/sections.ts +47 -0
- package/src/sharddev/shardSource.ts +59 -0
- package/src/sharddev/sourceReader.ts +26 -0
- package/src/sharddev/spawns.ts +38 -0
- package/src/sharddev/species/clips.ts +24 -0
- package/src/sharddev/species.ts +29 -0
- package/src/sharddev/speciesBrains.ts +19 -0
- package/src/sharddev/synth.ts +66 -0
- package/src/sharddev/test/compileDualScriptV2.ts +71 -0
- package/src/sharddev/test/compileSimV2.ts +21 -0
- package/src/sharddev/test/diskScriptScenario.ts +86 -0
- package/src/sharddev/test/scriptScenario.ts +249 -0
- package/src/sharddev/test/scriptSource.ts +12 -0
- package/src/sharddev/version.ts +4 -0
- package/src/sharddev/weapons/bowProfile.ts +20 -0
- package/src/sharddev/weapons/firearmRows.ts +11 -0
- package/src/sharddev/weapons/meleeProfile.ts +71 -0
- package/src/sharddev/weapons/thrownProfile.ts +10 -0
- package/src/sharddev/worldScenes.ts +308 -0
- package/src/sharddev/worldSource.ts +82 -0
- package/src/shards/_template/README.md +78 -0
- package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
- package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
- package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
- package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
- package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
- package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
- package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
- package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
- package/src/shards/_template/behaviour/boss.as +39 -0
- package/src/shards/_template/behaviour/door.as +32 -0
- package/src/shards/_template/behaviour/hooks.json +129 -0
- package/src/shards/_template/behaviour/idle.as +75 -0
- package/src/shards/_template/behaviour/items.as +22 -0
- package/src/shards/_template/card/landscape.jpg +0 -0
- package/src/shards/_template/card/portrait.jpg +0 -0
- package/src/shards/_template/card/thumb.jpg +0 -0
- package/src/shards/_template/data/audio.json +45 -0
- package/src/shards/_template/data/bossDecision.json +83 -0
- package/src/shards/_template/data/budgets.json +70 -0
- package/src/shards/_template/data/card.json +281 -0
- package/src/shards/_template/data/clientScripts.json +987 -0
- package/src/shards/_template/data/creatures.json +65 -0
- package/src/shards/_template/data/director.json +39 -0
- package/src/shards/_template/data/encounters.json +96 -0
- package/src/shards/_template/data/items.json +172 -0
- package/src/shards/_template/data/layout.json +66 -0
- package/src/shards/_template/data/ledger.json +32 -0
- package/src/shards/_template/data/look.json +521 -0
- package/src/shards/_template/data/map.json +64 -0
- package/src/shards/_template/data/moves.json +16 -0
- package/src/shards/_template/data/placeholder.json +8 -0
- package/src/shards/_template/data/plumbing.json +32 -0
- package/src/shards/_template/data/quests.json +223 -0
- package/src/shards/_template/data/rows.json +423 -0
- package/src/shards/_template/data/skins.json +66 -0
- package/src/shards/_template/data/spawn.json +6 -0
- package/src/shards/_template/data/targets.json +150 -0
- package/src/shards/_template/data/text.json +12 -0
- package/src/shards/_template/data/ui.json +33 -0
- package/src/shards/_template/data/water.json +13 -0
- package/src/shards/_template/generators/behaviour.ts +34 -0
- package/src/shards/_template/generators/boss.ts +29 -0
- package/src/shards/_template/generators/buildOptions.ts +2 -0
- package/src/shards/_template/generators/cell.ts +224 -0
- package/src/shards/_template/generators/districts.ts +215 -0
- package/src/shards/_template/generators/farLook.ts +15 -0
- package/src/shards/_template/generators/generate.ts +27 -0
- package/src/shards/_template/generators/ground.ts +15 -0
- package/src/shards/_template/generators/kit.ts +69 -0
- package/src/shards/_template/generators/landscape.ts +59 -0
- package/src/shards/_template/generators/landscapeNoise.ts +62 -0
- package/src/shards/_template/generators/mapInputs.ts +10 -0
- package/src/shards/_template/generators/product.ts +100 -0
- package/src/shards/_template/generators/productOutput.ts +18 -0
- package/src/shards/_template/generators/props.ts +9 -0
- package/src/shards/_template/generators/templatePropsSource.ts +58 -0
- package/src/shards/_template/generators/terrain.ts +17 -0
- package/src/shards/_template/generators/world.ts +630 -0
- package/src/shards/_template/hero.json +10 -0
- package/src/shards/_template/look/entry-reads.json +20 -0
- package/src/shards/_template/manifest.json +281 -0
- package/src/shards/_template/shard.config.ts +10 -0
- package/src/shared/health.ts +10 -0
- package/src/tools/build-web.ts +59 -0
- package/src/tsconfig.json +30 -0
- package/src/web/app.tsx +53 -0
- package/src/web/index.html +12 -0
- package/src/web/main.tsx +10 -0
- package/src/web/tsconfig.json +13 -0
- package/tsconfig.author.json +23 -0
- package/tsconfig.commons.json +21 -0
- package/tsconfig.json +47 -0
- package/tsconfig.sharddev.json +20 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/** ABI v2 guest source. All reads and geometry stay inside Wasm; this does not
|
|
2
|
+
* install a host or change any ABI-v0/v1 authoring source. */
|
|
3
|
+
import { V2_REGION_STRIDES } from '@wildshard/format/scriptWireV2';
|
|
4
|
+
|
|
5
|
+
export function v2CoreSource(io: number): string {
|
|
6
|
+
if (!Number.isSafeInteger(io) || io < 0 || io%8 !== 0 || io > 4*65536-656) throw new Error('Invalid v2 SDK IO base');
|
|
7
|
+
const strides = V2_REGION_STRIDES.map((stride,index) => `case ${index+1}:return ${stride};`).join('');
|
|
8
|
+
return String.raw`
|
|
9
|
+
const IO:usize=${io};
|
|
10
|
+
let selected:i32=-1;
|
|
11
|
+
@external("env","__v2_fuel") declare function remainingFuel():i32;
|
|
12
|
+
let sliceStart:i32=-1;
|
|
13
|
+
@inline export function io():i32{return i32(IO);}
|
|
14
|
+
@inline function stride(kind:i32):u32{switch(kind){${strides}default:unreachable();}return 0;}
|
|
15
|
+
@inline function directory(kind:i32):usize{
|
|
16
|
+
assert(kind>=1&&kind<=22);const d=IO+128+usize(kind-1)*24;
|
|
17
|
+
assert(load<u32>(d)==u32(kind)&&load<u32>(d+8)==stride(kind));
|
|
18
|
+
const off=load<u32>(d+4),cap=load<u32>(d+12),count=load<u32>(d+16),limit=usize(memory.size())*65536-IO;
|
|
19
|
+
assert(off>=656&&usize(off)<=limit&&(IO+off)%16==0);
|
|
20
|
+
assert(cap<=u32((limit-off)/stride(kind))&&count<=cap);return d;
|
|
21
|
+
}
|
|
22
|
+
@inline export function count(kind:i32):i32{return i32(load<u32>(directory(kind)+16));}
|
|
23
|
+
@inline export function row(kind:i32,index:i32):usize{
|
|
24
|
+
const d=directory(kind);assert(index>=0&&u32(index)<load<u32>(d+16));
|
|
25
|
+
return IO+load<u32>(d+4)+usize(index)*stride(kind);
|
|
26
|
+
}
|
|
27
|
+
@inline export function select(index:i32):void{row(1,index);selected=index;}
|
|
28
|
+
@inline export function beginBinding(index:i32):bool{
|
|
29
|
+
select(index);const at=binding();if((load<u32>(at+12)&3)!=3)return false;
|
|
30
|
+
store<u32>(IO+64,load<u32>(at));sliceStart=remainingFuel();return true;
|
|
31
|
+
}
|
|
32
|
+
@inline export function endBinding():void{
|
|
33
|
+
const used=sliceStart-remainingFuel();assert(sliceStart>=0&&used>=0&&used<=load<i32>(binding()+56));sliceStart=-1;
|
|
34
|
+
}
|
|
35
|
+
@inline function binding():usize{assert(selected>=0);return row(1,selected);}
|
|
36
|
+
@inline export function handle():i32{return load<i32>(binding());}
|
|
37
|
+
@inline export function self():i32{return load<i32>(binding()+4);}
|
|
38
|
+
@inline export function player():i32{return load<i32>(binding()+8);}
|
|
39
|
+
@inline export function due():bool{return (load<u32>(binding()+12)&2)!=0;}
|
|
40
|
+
@inline export function previousTick():i32{return load<i32>(binding()+48);}
|
|
41
|
+
@inline export function currentTick():i32{return load<i32>(binding()+52);}
|
|
42
|
+
@inline export function absoluteTick(relative:i32):f64{return load<f64>(IO+104)+f64(relative);}
|
|
43
|
+
@inline export function beginState():void{
|
|
44
|
+
selected=-1;sliceStart=-1;store<u32>(IO+64,0);const n=count(2),d=directory(3);assert(u32(n)<=load<u32>(d+12));
|
|
45
|
+
store<u32>(d+16,u32(n));for(let i=0;i<n;i++)store<f64>(row(3,i),load<f64>(row(2,i)));
|
|
46
|
+
const r=count(21),out=directory(22);assert(u32(r)<=load<u32>(out+12));store<u32>(out+16,u32(r));
|
|
47
|
+
for(let i=0;i<r;i++){const a=row(21,i),b=row(22,i);for(let j:usize=0;j<64;j+=8)store<u64>(b+j,load<u64>(a+j));}
|
|
48
|
+
}
|
|
49
|
+
@inline function column(kind:i32,index:i32,base:usize):usize{
|
|
50
|
+
const b=binding();assert(index>=0&&u32(index)<load<u32>(b+base+4));
|
|
51
|
+
const start=load<u32>(b+base),n=u32(count(kind));assert(start<=n&&u32(index)<n-start);
|
|
52
|
+
return row(kind,i32(start)+index);
|
|
53
|
+
}
|
|
54
|
+
@inline export function state(index:i32):f64{return load<f64>(column(2,index,16));}
|
|
55
|
+
@inline export function setState(index:i32,value:f64):void{store<f64>(column(3,index,16),value);}
|
|
56
|
+
@inline export function parameter(index:i32):f64{return load<f64>(column(4,index,24));}
|
|
57
|
+
@inline export function fieldId(index:i32):i32{return load<i32>(column(6,index,36));}
|
|
58
|
+
@inline export function fieldPresent(index:i32):bool{
|
|
59
|
+
const present=load<u32>(column(6,index,36)+4);assert(present<=1);return present!=0;
|
|
60
|
+
}
|
|
61
|
+
@inline export function field(index:i32):f64{assert(fieldPresent(index));return load<f64>(column(6,index,36)+8);}
|
|
62
|
+
@inline function observation():usize{
|
|
63
|
+
const b=binding(),at=row(5,load<i32>(b+32));assert(load<i32>(at)==load<i32>(b)&&load<i32>(at+4)==load<i32>(b+4));return at;
|
|
64
|
+
}
|
|
65
|
+
@inline export function target():i32{return load<i32>(observation()+8);}
|
|
66
|
+
@inline export function sampleTick():i32{return load<i32>(observation()+16);}
|
|
67
|
+
@inline export function observed(component:i32):f64{
|
|
68
|
+
assert(component>=0&&component<9);const at=observation();
|
|
69
|
+
const bit=component<4?0:component==4?1:component==5?2:component<8?3:4;
|
|
70
|
+
assert((load<u32>(at+12)&(1<<bit))!=0);return load<f64>(at+24+usize(component)*8);
|
|
71
|
+
}
|
|
72
|
+
@inline export function playerHandle(index:i32):i32{return load<i32>(row(7,index));}
|
|
73
|
+
@inline export function playerSampleTick(index:i32):i32{return load<i32>(row(7,index)+8);}
|
|
74
|
+
@inline export function playerValue(index:i32,component:i32):f64{
|
|
75
|
+
assert(component>=0&&component<8);const at=row(7,index),bit=component<4?0:component==4?1:component<7?2:3;
|
|
76
|
+
assert((load<u32>(at+4)&(1<<bit))!=0);return load<f64>(at+16+usize(component)*8);
|
|
77
|
+
}
|
|
78
|
+
@inline export function edgeWord(index:i32,field:i32):i32{assert(field>=0&&field<4);return load<i32>(row(8,index)+usize(field)*4);}
|
|
79
|
+
@inline export function edgeValue(index:i32,axis:i32):f64{assert(axis>=0&&axis<2);return load<f64>(row(8,index)+16+usize(axis)*8);}
|
|
80
|
+
@inline export function eventWord(index:i32,field:i32):i32{assert(field>=0&&field<6);return load<i32>(row(9,index)+usize(field)*4);}
|
|
81
|
+
@inline export function eventValue(index:i32,field:i32):f64{assert(field>=0&&field<4);return load<f64>(row(9,index)+24+usize(field)*8);}
|
|
82
|
+
@inline export function actorCommand(op:i32,target:i32,a:f64=0,b:f64=0,c:f64=0):void{
|
|
83
|
+
assert((op>=1&&op<=7||op==12||op==13)&&target>=0);writeAction(op,target,a,b,c);
|
|
84
|
+
}
|
|
85
|
+
@inline function worldAction(op:i32,target:i32,a:f64,b:f64,c:f64):void{
|
|
86
|
+
assert(target>0);writeAction(op,target,a,b,c);
|
|
87
|
+
}
|
|
88
|
+
@inline function writeAction(op:i32,target:i32,a:f64,b:f64,c:f64,d:f64=0,e:f64=0,f:f64=0):void{const dir=directory(10),n=load<u32>(dir+16);assert(n<load<u32>(dir+12));
|
|
89
|
+
store<u32>(dir+16,n+1);const at=row(10,i32(n));
|
|
90
|
+
store<i32>(at,handle());store<i32>(at+4,op);store<i32>(at+8,target);store<u32>(at+12,0);
|
|
91
|
+
store<f64>(at+16,a);store<f64>(at+24,b);store<f64>(at+32,c);
|
|
92
|
+
store<f64>(at+40,d);store<f64>(at+48,e);store<f64>(at+56,f);store<u32>(IO+56,n+1);
|
|
93
|
+
}
|
|
94
|
+
@inline export function taming(op:i32,target:i32,a:f64=0,b:f64=0,c:f64=0,d:f64=0,e:f64=0,f:f64=0):void{assert((op==23||op>=26&&op<=39)&&target>0);writeAction(op,target,a,b,c,d,e,f);}
|
|
95
|
+
@inline export function dismount(target:i32,thrown:bool=false):void{worldAction(23,target,thrown?1:0,0,0);}
|
|
96
|
+
@inline export function ignite(target:i32,x:f64,z:f64):void{worldAction(24,target,x,z,0);}
|
|
97
|
+
@inline export function impulse(target:i32,x:f64,y:f64,z:f64):void{worldAction(14,target,x,y,z);}
|
|
98
|
+
|
|
99
|
+
/** Finite entered page action. Native capability rows define the operand width;
|
|
100
|
+
* unused words remain positive zero and no effect is applied inside Wasm. */
|
|
101
|
+
@inline export function pageOutput(action:i32,a:f64=0,b:f64=0,c:f64=0,d:f64=0):void{
|
|
102
|
+
assert(action>0&&action<=65535);writeAction(25,action,a,b,c,d);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@inline export function query(op:i32,id:u32,target:i32,a:f64=0,b:f64=0,c:f64=0,d:f64=0,e:f64=0,f:f64=0,g:f64=0):void{
|
|
106
|
+
assert((op==4||op==5||op==8||op==9||op==10||op==11)&&id>0&&target>=0);const dir=directory(11),n=load<u32>(dir+16);assert(n<load<u32>(dir+12));
|
|
107
|
+
store<u32>(dir+16,n+1);const at=row(11,i32(n));store<i32>(at,handle());store<u32>(at+4,id);store<i32>(at+8,op);store<u32>(at+12,0);store<i32>(at+16,load<i32>(IO+28));store<i32>(at+20,target);
|
|
108
|
+
store<f64>(at+24,a);store<f64>(at+32,b);store<f64>(at+40,c);store<f64>(at+48,d);store<f64>(at+56,e);store<f64>(at+64,f);store<f64>(at+72,g);store<u32>(IO+60,n+1);
|
|
109
|
+
}
|
|
110
|
+
@inline export function replyBinding(index:i32):i32{return load<i32>(row(12,index));}
|
|
111
|
+
@inline function reply(index:i32):usize{const at=row(12,index);assert(load<i32>(at)==handle());return at;}
|
|
112
|
+
@inline export function replyId(index:i32):u32{return load<u32>(reply(index)+4);}
|
|
113
|
+
@inline export function replyStatus(index:i32):u32{const status=load<u32>(reply(index)+8);assert(status>=1&&status<=3);return status;}
|
|
114
|
+
@inline export function replyTick(index:i32):i32{return load<i32>(reply(index)+16);}
|
|
115
|
+
@inline export function replyValue(index:i32,component:i32):f64{assert(replyStatus(index)==1&&component>=0&&component<5);return load<f64>(reply(index)+24+usize(component)*8);}
|
|
116
|
+
@inline export function replyData(index:i32,component:i32):f64{
|
|
117
|
+
const at=reply(index),n=load<u32>(at+12),base=load<u32>(at+20),total=u32(count(13));assert(replyStatus(index)==1&&base<=total&&n<=total-base&&component>=0&&u32(component)<n);return load<f64>(row(13,i32(base)+component));
|
|
118
|
+
}
|
|
119
|
+
@inline function mixRng(value:u32):u32{
|
|
120
|
+
value=(value^(value>>16))*0x7feb352d;value=(value^(value>>15))*0x846ca68b;return value^(value>>16);
|
|
121
|
+
}
|
|
122
|
+
@inline export function random(stream:u32):f64{
|
|
123
|
+
assert(stream>0);
|
|
124
|
+
for(let i=0;i<count(22);i++){
|
|
125
|
+
const at=row(22,i);if(load<i32>(at)!=handle()||load<u32>(at+4)!=stream)continue;
|
|
126
|
+
const draws=load<u32>(at+12);assert(draws<0xffffffff);store<u32>(at+12,draws+1);
|
|
127
|
+
const algorithm=load<u32>(at+8);
|
|
128
|
+
if(algorithm==1){
|
|
129
|
+
const state=u32(load<f64>(at+16))+0x6d2b79f5;store<f64>(at+16,f64(state));
|
|
130
|
+
let t=(state^(state>>15))*(state|1);t^=t+(t^(t>>7))*(t|61);return f64(t^(t>>14))/4294967296;
|
|
131
|
+
}
|
|
132
|
+
assert(algorithm==2);const counter=load<f64>(at+32),identity=load<f64>(at+40),instance=load<f64>(at+48);assert(counter<9007199254740991);
|
|
133
|
+
const value=mixRng(mixRng(u32(load<f64>(at+16))^u32(identity%4294967296))^mixRng(u32(load<f64>(at+24))^u32(instance%4294967296))
|
|
134
|
+
^mixRng(u32(Math.floor(identity/4294967296)))^mixRng(u32(Math.floor(instance/4294967296)))
|
|
135
|
+
^mixRng(u32(counter%4294967296))^mixRng(u32(Math.floor(counter/4294967296))));
|
|
136
|
+
store<f64>(at+32,counter+1);return f64(value)/4294967296;
|
|
137
|
+
}
|
|
138
|
+
unreachable();return 0;
|
|
139
|
+
}
|
|
140
|
+
@inline function grid():usize{
|
|
141
|
+
assert(count(14)>=64);const at=row(14,0);assert(load<u32>(at+56)==1&&load<u32>(at+44)==0&&load<u32>(at+60)==0);return at;
|
|
142
|
+
}
|
|
143
|
+
@inline export function gridWater():f64{return load<f64>(grid()+48);}
|
|
144
|
+
@inline export function gridHeight(x:f64,z:f64):f64{
|
|
145
|
+
const at=grid(),cols=load<u32>(at+32),rows=load<u32>(at+36),base=load<u32>(at+40),offset=load<u32>(directory(14)+4),n=u32(count(14));
|
|
146
|
+
assert(cols>=2&&rows>=2&&base>=offset+64&&base-offset<=n&&cols<=(n-(base-offset))/4/rows);
|
|
147
|
+
const ox=load<f64>(at),oz=load<f64>(at+8),cx=load<f64>(at+16),cz=load<f64>(at+24);assert(cx>0&&cz>0);
|
|
148
|
+
const ux=(x-ox)/cx,uz=(z-oz)/cz;assert(ux>=0&&uz>=0&&ux<=f64(cols-1)&&uz<=f64(rows-1));
|
|
149
|
+
const ix=min(cols-2,u32(Math.floor(ux))),iz=min(rows-2,u32(Math.floor(uz))),fx=ux-f64(ix),fz=uz-f64(iz);
|
|
150
|
+
const p=IO+base+usize(iz*cols+ix)*4;
|
|
151
|
+
const h00=f64(load<f32>(p)),h10=f64(load<f32>(p+4)),h01=f64(load<f32>(p+usize(cols)*4)),h11=f64(load<f32>(p+usize(cols+1)*4));
|
|
152
|
+
const a=h00+(h10-h00)*fx,b=h01+(h11-h01)*fx;return a+(b-a)*fz;
|
|
153
|
+
}
|
|
154
|
+
@inline export function distance(x:f64,z:f64,toX:f64,toZ:f64):f64{return Math.hypot(toX-x,toZ-z);}
|
|
155
|
+
@inline export function bearing(x:f64,z:f64,toX:f64,toZ:f64):f64{return Math.atan2(toX-x,toZ-z);}
|
|
156
|
+
@inline export function radialX(yaw:f64,radius:f64):f64{return Math.sin(yaw)*radius;}
|
|
157
|
+
@inline export function radialZ(yaw:f64,radius:f64):f64{return Math.cos(yaw)*radius;}
|
|
158
|
+
/** A bounded logical point-list request occupies its header plus up to six
|
|
159
|
+
* continuation records. Replies contain the corresponding ordered samples. */
|
|
160
|
+
export function queryPoints(op:i32,id:u32,points:usize,size:i32):void{
|
|
161
|
+
assert((op==12||op==13)&&id>0&&size>=1&&size<=16&&points%8==0);
|
|
162
|
+
const limit=usize(memory.size())*65536;
|
|
163
|
+
assert(points>=IO+load<u32>(IO+12)&&points<=limit&&usize(size)*16<=limit-points);
|
|
164
|
+
const blocks=(size+2)/3,dir=directory(11),start=load<u32>(dir+16),records=u32(1+blocks);
|
|
165
|
+
assert(start<=load<u32>(dir+12)&&records<=load<u32>(dir+12)-start);
|
|
166
|
+
store<u32>(dir+16,start+records);
|
|
167
|
+
for(let block:i32=-1;block<blocks;block++){
|
|
168
|
+
const at=row(11,i32(start)+block+1);store<i32>(at,handle());store<u32>(at+4,id);store<i32>(at+8,op);
|
|
169
|
+
store<u32>(at+12,block<0?0:1);store<i32>(at+16,load<i32>(IO+28));store<u32>(at+20,0);
|
|
170
|
+
for(let word:i32=0;word<7;word++){
|
|
171
|
+
let value:f64=0;const point=block*6+word;
|
|
172
|
+
if(block<0){if(word==0)value=f64(size);}
|
|
173
|
+
else if(word<6&&point<size*2)value=load<f64>(points+usize(point)*8);
|
|
174
|
+
assert(value<Infinity&&value>-Infinity);store<f64>(at+24+usize(word)*8,value);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
store<u32>(IO+60,start+records);
|
|
178
|
+
}
|
|
179
|
+
`;
|
|
180
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Resolve the pinned portable compiler without admitting its global declarations into host types. */
|
|
2
|
+
export function loadAssemblyScriptCompiler(): Promise<unknown>;
|
|
3
|
+
|
|
4
|
+
/** Resolve the pinned parser without its guest ambient declarations. */
|
|
5
|
+
export function loadAssemblyScriptParser(): Promise<unknown>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Load only the pinned external compiler; its guest globals must not enter host types.
|
|
2
|
+
* The static string expression is folded by the bundler and checked by the authoring audit.
|
|
3
|
+
* @returns {Promise<unknown>} */
|
|
4
|
+
export function loadAssemblyScriptCompiler() {
|
|
5
|
+
// oxlint-disable-next-line eslint/no-useless-concat -- A direct literal loads AssemblyScript's guest globals into the host type program; bundling and the audit fold these exact literals.
|
|
6
|
+
return import('assemblyscript/dist/' + 'asc.js');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Load the pinned parser without leaking guest globals into host declarations.
|
|
10
|
+
* @returns {Promise<unknown>} */
|
|
11
|
+
export function loadAssemblyScriptParser() {
|
|
12
|
+
// oxlint-disable-next-line eslint/no-useless-concat -- Keep guest declarations outside the host type program.
|
|
13
|
+
return import('assemblyscript/dist/' + 'assemblyscript.js');
|
|
14
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Author admission compares complete byte ranges with Node's native byte comparator.
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
import { hashImmutableBytes } from './immutable';
|
|
4
|
+
|
|
5
|
+
/** A private owned snapshot and its computed SHA-256. Only copies leave the handle. */
|
|
6
|
+
export interface ImmutableAsset {
|
|
7
|
+
readonly hash: string;
|
|
8
|
+
readonly byteLength: number;
|
|
9
|
+
readonly copy: () => Uint8Array<ArrayBuffer>;
|
|
10
|
+
}
|
|
11
|
+
interface Snapshot { readonly bytes: Uint8Array<ArrayBuffer>; readonly hash: string }
|
|
12
|
+
const snapshots = new WeakMap<ImmutableAsset, Snapshot>();
|
|
13
|
+
const aliases = new WeakMap<Uint8Array, ImmutableAsset>();
|
|
14
|
+
function arrayAccessor(name: 'byteLength' | 'buffer'): (input: Uint8Array) => unknown {
|
|
15
|
+
const prototype: object | null = Object.getPrototypeOf(Uint8Array.prototype);
|
|
16
|
+
if (prototype === null) throw new Error('Missing native typed array prototype');
|
|
17
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
18
|
+
const getter: unknown = descriptor === undefined ? undefined : Reflect.get(descriptor, 'get');
|
|
19
|
+
if (typeof getter !== 'function') throw new Error('Missing native typed array accessor');
|
|
20
|
+
return (input: Uint8Array): unknown => Reflect.apply(getter, input, []);
|
|
21
|
+
}
|
|
22
|
+
const byteLength = arrayAccessor('byteLength'), buffer = arrayAccessor('buffer');
|
|
23
|
+
function ownedBytes(input: Uint8Array): Uint8Array<ArrayBuffer> {
|
|
24
|
+
const length = byteLength(input);
|
|
25
|
+
if (typeof length !== 'number') throw new Error('Invalid native typed array length');
|
|
26
|
+
const bytes = new Uint8Array(length);
|
|
27
|
+
// Native TypedArray.set ignores an authored iterator and preserves view offsets.
|
|
28
|
+
bytes.set(input); return bytes;
|
|
29
|
+
}
|
|
30
|
+
function unshared(input: Uint8Array): boolean { return buffer(input) instanceof ArrayBuffer; }
|
|
31
|
+
|
|
32
|
+
function sameBytes(a: Uint8Array, b: Uint8Array): boolean {
|
|
33
|
+
return Buffer.compare(a, b) === 0;
|
|
34
|
+
}
|
|
35
|
+
function snapshotOf(bytes: Uint8Array): { readonly handle: ImmutableAsset; readonly snapshot: Snapshot } | undefined {
|
|
36
|
+
// A shared buffer can change concurrently after comparison. Never cache its mutable view.
|
|
37
|
+
if (!unshared(bytes)) return undefined;
|
|
38
|
+
const handle = aliases.get(bytes), snapshot = handle === undefined ? undefined : snapshots.get(handle);
|
|
39
|
+
return handle !== undefined && snapshot !== undefined && sameBytes(bytes, snapshot.bytes) ? { handle, snapshot } : undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Capture exact private bytes before computing their identity. Mutable aliases
|
|
43
|
+
* are checked in full on every reuse; changed bytes get a newly computed hash. */
|
|
44
|
+
export function immutableAsset(input: Uint8Array): ImmutableAsset {
|
|
45
|
+
if (!(input instanceof Uint8Array)) throw new Error('Asset ownership needs Uint8Array bytes');
|
|
46
|
+
const previous = snapshotOf(input);
|
|
47
|
+
if (previous !== undefined) return previous.handle;
|
|
48
|
+
const bytes = ownedBytes(input), snapshot = { bytes, hash: hashImmutableBytes(bytes) };
|
|
49
|
+
const handle: ImmutableAsset = Object.freeze({ hash: snapshot.hash, byteLength: bytes.byteLength,
|
|
50
|
+
copy: (): Uint8Array<ArrayBuffer> => {
|
|
51
|
+
const owned = ownedBytes(snapshot.bytes); aliases.set(owned, handle); return owned;
|
|
52
|
+
} });
|
|
53
|
+
snapshots.set(handle, snapshot);
|
|
54
|
+
if (unshared(input)) aliases.set(input, handle);
|
|
55
|
+
return handle;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Own a detached copy while carrying the snapshot's computed identity. */
|
|
59
|
+
export function copyAssetBytes(input: Uint8Array): Uint8Array<ArrayBuffer> { return immutableAsset(input).copy(); }
|
|
60
|
+
|
|
61
|
+
/** The author's format-admission hash port. Every call checks the complete
|
|
62
|
+
* mutable view; shared/unknown bytes retain actual cryptographic hashing. */
|
|
63
|
+
export function hashAssetBytes(input: Uint8Array): string {
|
|
64
|
+
if (!(input instanceof Uint8Array)) throw new Error('Asset ownership needs Uint8Array bytes');
|
|
65
|
+
return unshared(input) ? immutableAsset(input).hash : hashImmutableBytes(input);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Certify freshly read disk/pack bytes only after exact byte equality with a
|
|
69
|
+
* genuine private snapshot. Metadata, object shape and expected hash alone
|
|
70
|
+
* never authorize reuse; uncertified bytes take normal SHA-256 admission. */
|
|
71
|
+
export function verifyAssetBytes(input: Uint8Array, expected: string, known?: ImmutableAsset): boolean {
|
|
72
|
+
const snapshot = known === undefined ? undefined : snapshots.get(known);
|
|
73
|
+
if (known !== undefined && snapshot !== undefined && snapshot.hash === expected && unshared(input) && sameBytes(input, snapshot.bytes)) {
|
|
74
|
+
aliases.set(input, known); return true;
|
|
75
|
+
}
|
|
76
|
+
return hashAssetBytes(input) === expected;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** One writer's immutable handles, never a process-wide content lookup or an IO cache. */
|
|
80
|
+
export function assetHandles(values: Iterable<Uint8Array>): ReadonlyMap<string, ImmutableAsset> {
|
|
81
|
+
const handles = new Map<string, ImmutableAsset>();
|
|
82
|
+
for (const bytes of values) { const handle = immutableAsset(bytes); handles.set(handle.hash, handle); }
|
|
83
|
+
return handles;
|
|
84
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { hashImmutableBytes } from './immutable';
|
|
2
|
+
|
|
3
|
+
/** Data-only result of the explicit host factory, never an admission certificate. */
|
|
4
|
+
export interface OwnedAsset { readonly bytes: Uint8Array; readonly hash: string }
|
|
5
|
+
interface Snapshot { readonly bytes: Uint8Array<ArrayBuffer>; readonly hash: string }
|
|
6
|
+
const aliases = new WeakMap<Uint8Array, Snapshot>();
|
|
7
|
+
const slot = Symbol.for('wildshard.sdk.asset-owner.v1');
|
|
8
|
+
function accessor(name: 'byteLength' | 'buffer' | 'byteOffset'): (input: Uint8Array) => unknown {
|
|
9
|
+
const prototype: object | null = Object.getPrototypeOf(Uint8Array.prototype);
|
|
10
|
+
if (prototype === null) throw new Error('Missing native typed array prototype');
|
|
11
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
12
|
+
const getter: unknown = descriptor === undefined ? undefined : Reflect.get(descriptor, 'get');
|
|
13
|
+
if (typeof getter !== 'function') throw new Error('Missing native typed array accessor');
|
|
14
|
+
return (input: Uint8Array): unknown => Reflect.apply(getter, input, []);
|
|
15
|
+
}
|
|
16
|
+
const byteLength = accessor('byteLength'), buffer = accessor('buffer'), byteOffset = accessor('byteOffset');
|
|
17
|
+
const resizableDescriptor = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'resizable');
|
|
18
|
+
const resizableGetter: unknown = resizableDescriptor === undefined ? undefined : Reflect.get(resizableDescriptor, 'get');
|
|
19
|
+
function fixed(input: unknown): input is ArrayBuffer {
|
|
20
|
+
return input instanceof ArrayBuffer && Object.getPrototypeOf(input) === ArrayBuffer.prototype
|
|
21
|
+
&& (typeof resizableGetter !== 'function' || Reflect.apply(resizableGetter, input, []) === false);
|
|
22
|
+
}
|
|
23
|
+
function copy(input: Uint8Array): Uint8Array<ArrayBuffer> {
|
|
24
|
+
const length = byteLength(input);
|
|
25
|
+
if (typeof length !== 'number') throw new Error('Invalid native byte length');
|
|
26
|
+
const bytes = new Uint8Array(length); bytes.set(input); return bytes;
|
|
27
|
+
}
|
|
28
|
+
function equal(a: Uint8Array, b: Uint8Array): boolean {
|
|
29
|
+
const length = byteLength(a);
|
|
30
|
+
if (typeof length !== 'number' || length !== byteLength(b)) return false;
|
|
31
|
+
if (length >= 32 && Object.getPrototypeOf(a) === Uint8Array.prototype && Object.getPrototypeOf(b) === Uint8Array.prototype) {
|
|
32
|
+
const left = buffer(a), right = buffer(b);
|
|
33
|
+
if (fixed(left) && fixed(right)) {
|
|
34
|
+
const aOffset = byteOffset(a), bOffset = byteOffset(b);
|
|
35
|
+
if (typeof aOffset === 'number' && typeof bOffset === 'number' && aOffset % 4 === 0 && bOffset % 4 === 0) {
|
|
36
|
+
const count = Math.floor(length / 4), aWords = new Uint32Array(left, aOffset, count), bWords = new Uint32Array(right, bOffset, count);
|
|
37
|
+
for (let at = 0; at < count; at++) if (aWords[at] !== bWords[at]) return false;
|
|
38
|
+
for (let at = count * 4; at < length; at++) if (a[at] !== b[at]) return false;
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (let at = 0; at < length; at++) if (a[at] !== b[at]) return false;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function own(input: Uint8Array): OwnedAsset {
|
|
47
|
+
if (!(input instanceof Uint8Array)) throw new Error('Asset ownership needs Uint8Array bytes');
|
|
48
|
+
const unshared = buffer(input) instanceof ArrayBuffer, previous = unshared ? aliases.get(input) : undefined;
|
|
49
|
+
let snapshot: Snapshot;
|
|
50
|
+
if (previous !== undefined && equal(input, previous.bytes)) snapshot = previous;
|
|
51
|
+
else { const bytes = copy(input); snapshot = { bytes, hash: hashImmutableBytes(bytes) }; }
|
|
52
|
+
if (unshared) aliases.set(input, snapshot);
|
|
53
|
+
const bytes = copy(snapshot.bytes); aliases.set(bytes, snapshot); return { bytes, hash: snapshot.hash };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A config-safe producer consults an explicitly installed host factory or
|
|
57
|
+
* owns its own detached snapshot. It imports neither async scope machinery nor
|
|
58
|
+
* native comparison services. Every returned body still crosses full admission. */
|
|
59
|
+
export function ownAssetBytes(input: Uint8Array): OwnedAsset {
|
|
60
|
+
const activePort: unknown = Reflect.get(globalThis, slot);
|
|
61
|
+
if (typeof activePort !== 'object' || activePort === null || !('current' in activePort) || typeof activePort.current !== 'function') return own(input);
|
|
62
|
+
const current: unknown = Reflect.apply(activePort.current, activePort, []);
|
|
63
|
+
if (typeof current !== 'function') return own(input);
|
|
64
|
+
const result: unknown = Reflect.apply(current, undefined, [input]);
|
|
65
|
+
if (typeof result !== 'object' || result === null || !('bytes' in result) || !(result.bytes instanceof Uint8Array) ||
|
|
66
|
+
!('hash' in result) || typeof result.hash !== 'string' || !/^[a-f0-9]{64}$/u.test(result.hash) || !equal(input, result.bytes))
|
|
67
|
+
throw new Error('Author asset owner did not preserve its input bytes');
|
|
68
|
+
if (!(buffer(result.bytes) instanceof ArrayBuffer)) throw new Error('Author asset owner returned shared bytes');
|
|
69
|
+
return { bytes: result.bytes, hash: result.hash };
|
|
70
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Only the CLI owns async producer scope; config-reachable producers do not import this module.
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { immutableAsset } from './assetHandle';
|
|
4
|
+
|
|
5
|
+
import type { OwnedAsset } from './assetOwner';
|
|
6
|
+
|
|
7
|
+
type Factory = (input: Uint8Array) => OwnedAsset;
|
|
8
|
+
interface ScopePort { readonly current: () => Factory | undefined }
|
|
9
|
+
const slot = Symbol.for('wildshard.sdk.asset-owner.v1');
|
|
10
|
+
const scope = new AsyncLocalStorage<Factory>();
|
|
11
|
+
const port: ScopePort = Object.freeze({ current: (): Factory | undefined => scope.getStore() });
|
|
12
|
+
let active = 0;
|
|
13
|
+
|
|
14
|
+
function own(input: Uint8Array): OwnedAsset {
|
|
15
|
+
const asset = immutableAsset(input);
|
|
16
|
+
return { bytes: asset.copy(), hash: asset.hash };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Explicit author-only ownership scope; importing a module installs nothing.
|
|
20
|
+
* Its frozen port exposes the active factory, never the private snapshot table.
|
|
21
|
+
* Canonical format hash/verification functions do not consult this port. */
|
|
22
|
+
export async function withAssetOwner<T>(work: () => Promise<T>): Promise<T> {
|
|
23
|
+
const present: unknown = Reflect.get(globalThis, slot);
|
|
24
|
+
if (present !== undefined && present !== port) return work();
|
|
25
|
+
if (present === undefined) Object.defineProperty(globalThis, slot, { value: port, configurable: true });
|
|
26
|
+
active++;
|
|
27
|
+
try { return await scope.run(own, work); }
|
|
28
|
+
finally { if (--active === 0 && Reflect.get(globalThis, slot) === port) Reflect.deleteProperty(globalThis, slot); }
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ScriptContract } from '@wildshard/format/scriptContract';
|
|
2
|
+
import { assetCost as cost, assetOverdraw as raster, parseAudio as audio, parseGlb as glb, prepareAssetDecoders, type AssetCost as Cost } from '@wildshard/format/product';
|
|
3
|
+
import { parseKtx2 as ktx2 } from '@wildshard/format/ktx2Cost';
|
|
4
|
+
|
|
5
|
+
// Author-only facade: keep synchronous cost APIs ready without suspending app modules.
|
|
6
|
+
await prepareAssetDecoders();
|
|
7
|
+
|
|
8
|
+
/** Actual parsed residency and draw costs, independent of author declarations. */
|
|
9
|
+
export type AssetCost = Cost;
|
|
10
|
+
/** Admit a self-contained GLB and derive its geometry and instance costs. */
|
|
11
|
+
export function parseGlb(bytes: Uint8Array): Cost { return glb(bytes); }
|
|
12
|
+
/** Admit bounded KTX2 mip ranges and conservative transcode residency. */
|
|
13
|
+
export function parseKtx2(bytes: Uint8Array): Cost { return ktx2(bytes); }
|
|
14
|
+
/** Admit bounded PCM WAV or indexed 48 kHz stereo AAC-LC and derive decoded sample residency. */
|
|
15
|
+
export function parseAudio(bytes: Uint8Array): Cost { return audio(bytes); }
|
|
16
|
+
/** Select the game's shared asset parser for CLI and browser admission. */
|
|
17
|
+
export function assetCost(kind: string, bytes: Uint8Array, script?: ScriptContract): Cost { return cost(kind, bytes, script); }
|
|
18
|
+
/** Advisory raster layers from actual geometry and material alpha modes, before culling or occlusion. */
|
|
19
|
+
export type OverdrawEstimate = ReturnType<typeof raster>;
|
|
20
|
+
/** Derive the shared conservative raster estimate without accepting an author-supplied number. */
|
|
21
|
+
export function assetOverdraw(kind: string, bytes: Uint8Array, script?: ScriptContract): OverdrawEstimate { return raster(kind, bytes, script); }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { AudioDataSchema as schema, parseAudioData as parseData, type AudioData as Data } from '@wildshard/format/audio';
|
|
3
|
+
|
|
4
|
+
/** Compile cue mappings, wind ambience and silent/default score declarations. */
|
|
5
|
+
export const AudioDataSchema: v.SchemaWithPipe<readonly [typeof schema]> = v.pipe(schema);
|
|
6
|
+
/** A serialisable audio recipe whose voice ids the platform catalogue admits. */
|
|
7
|
+
export type AudioData = Data;
|
|
8
|
+
/** Validate the thin audio section before compiling a shardfile. */
|
|
9
|
+
export function parseAudioData(input: unknown): Data { return parseData(input); }
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The build runs the host's ffmpeg to encode recordings.
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The build host keys encoded recordings by exact content.
|
|
4
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The encode cache lives outside the authored product.
|
|
6
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The default cache is the existing build-cache root.
|
|
8
|
+
import { availableParallelism, homedir, release, tmpdir } from 'node:os';
|
|
9
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Cache paths use only trusted roots and hashes.
|
|
10
|
+
import { join, resolve } from 'node:path';
|
|
11
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- execFile's promise form.
|
|
12
|
+
import { promisify } from 'node:util';
|
|
13
|
+
import * as v from 'valibot';
|
|
14
|
+
import { measureRecording } from '@wildshard/format/audioMeasure';
|
|
15
|
+
import { AUDIO_RULES, audioReport } from '@wildshard/format/audioRules';
|
|
16
|
+
|
|
17
|
+
// AUDIO AU7 (meta docs/plans/AUDIO-PLAN.md, J299): the build re-encodes every source recording a shard mounts (wav,
|
|
18
|
+
// flac, aiff or m4a under /assets/music or /assets/sfx) to AU5's targets: AAC-LC 48 kHz in .m4a at the bitrate cap
|
|
19
|
+
// for its role and channels (format's AUDIO_RULES). AudioToolbox `aac_at` on macOS, ffmpeg's `aac` elsewhere. Sound
|
|
20
|
+
// effects go mono unless the shard source marks them stereo (`audio-stereo.json`); music keeps its channels. An AAC
|
|
21
|
+
// file that already passes AU5's per-file check at the right channel count ships as it is, so no file is encoded
|
|
22
|
+
// twice. Every recording keeps its URL (a `.wav` mount serves AAC bytes), because the shard's rows, fence list and
|
|
23
|
+
// code name that URL. Encoded bytes are cached by source hash, role, channel mark, AU5's rules, this encoder's code
|
|
24
|
+
// and the host encoder's identity (ffmpeg version, encoder, platform, and the macOS release for AudioToolbox), so a
|
|
25
|
+
// rebuild encodes nothing and a different encoder never reads another's bytes. AudioToolbox's stereo floor is 64
|
|
26
|
+
// kbps, so a stereo sound effect (48 kbps) takes ffmpeg's `aac` on every host. The 180 s rule is AU5's report's to
|
|
27
|
+
// judge (a waiver may cover it), so the encoder ignores it.
|
|
28
|
+
|
|
29
|
+
/** Which encoder the build found, and the identity its cache key carries. */
|
|
30
|
+
export interface AudioEncoder {
|
|
31
|
+
readonly ffmpeg: string;
|
|
32
|
+
readonly ffprobe: string;
|
|
33
|
+
readonly codec: 'aac_at' | 'aac';
|
|
34
|
+
readonly identity: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** What one encode pass did, for the build's log line. */
|
|
38
|
+
export interface AudioEncodeStats {
|
|
39
|
+
readonly files: number;
|
|
40
|
+
readonly encoded: number;
|
|
41
|
+
readonly cached: number;
|
|
42
|
+
readonly kept: number;
|
|
43
|
+
readonly unencoded: number;
|
|
44
|
+
readonly before: number;
|
|
45
|
+
readonly after: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AudioEncodeOptions {
|
|
49
|
+
/** Sound-effect URLs the source marks stereo (`audio-stereo.json`). */
|
|
50
|
+
readonly stereo?: ReadonlySet<string>;
|
|
51
|
+
readonly cacheRoot?: string;
|
|
52
|
+
/** `null` is no encoder on this host; undefined finds one. */
|
|
53
|
+
readonly encoder?: AudioEncoder | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface Mount { readonly url: string; readonly bytes: Uint8Array }
|
|
57
|
+
type Role = 'music' | 'sfx';
|
|
58
|
+
|
|
59
|
+
const SOURCE = /^\/assets\/(?<role>music|sfx)\/.+\.(?<ext>m4a|wav|flac|aiff?)$/u;
|
|
60
|
+
const SCHEMA = 'audio-encode/1';
|
|
61
|
+
const MAX_BYTES = 256_000_000;
|
|
62
|
+
const MB = 1_000_000;
|
|
63
|
+
const AAC_AT_STEREO_FLOOR = 64;
|
|
64
|
+
const RATE_STEP = 8;
|
|
65
|
+
const execFileAsync = promisify(execFile);
|
|
66
|
+
async function run(file: string, args: readonly string[]): Promise<string> {
|
|
67
|
+
try { return (await execFileAsync(file, [...args], { maxBuffer: 4_000_000 })).stdout; }
|
|
68
|
+
catch (error) {
|
|
69
|
+
const stderr = typeof error === 'object' && error !== null && 'stderr' in error ? String(error.stderr).trim().split('\n').slice(-2).join(' ') : '';
|
|
70
|
+
throw new Error(`${file} ${args.slice(0, 2).join(' ')}: ${stderr === '' ? String(error) : stderr}`, { cause: error });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const sha = (bytes: string | Uint8Array): string => createHash('sha256').update(bytes).digest('hex');
|
|
74
|
+
|
|
75
|
+
/** Whether a mount URL is a source recording the build encodes. */
|
|
76
|
+
export function isSourceRecordingUrl(url: string): boolean { return SOURCE.test(url); }
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
let found: Promise<AudioEncoder | null> | undefined;
|
|
80
|
+
/** The host's encoder: `aac_at` when ffmpeg on macOS has it, else ffmpeg's `aac`; null with no ffmpeg on PATH. */
|
|
81
|
+
export function findAudioEncoder(): Promise<AudioEncoder | null> {
|
|
82
|
+
found ??= (async () => {
|
|
83
|
+
const ffmpeg = process.env['WILDSHARD_FFMPEG'] ?? 'ffmpeg', ffprobe = process.env['WILDSHARD_FFPROBE'] ?? 'ffprobe';
|
|
84
|
+
try {
|
|
85
|
+
const version = (await run(ffmpeg, ['-hide_banner', '-version'])).split('\n')[0]?.trim() ?? '';
|
|
86
|
+
await run(ffprobe, ['-hide_banner', '-version']);
|
|
87
|
+
const toolbox = process.platform === 'darwin' && /\baac_at\b/u.test(await run(ffmpeg, ['-hide_banner', '-encoders']));
|
|
88
|
+
const codec = toolbox ? 'aac_at' : 'aac';
|
|
89
|
+
return { ffmpeg, ffprobe, codec, identity: `${version} ${codec} ${process.platform}-${process.arch}${toolbox ? ` ${release()}` : ''}` };
|
|
90
|
+
} catch { return null; }
|
|
91
|
+
})();
|
|
92
|
+
return found;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const StereoSchema = v.strictObject({ version: v.literal(1), stereo: v.array(v.pipe(v.string(), v.regex(/^\/assets\/sfx\/.+\.(?:m4a|wav|flac|aiff?)$/u, 'audio-stereo.json names sound effects under /assets/sfx/'))) });
|
|
96
|
+
/** The sound effects a shard source marks stereo: `audio-stereo.json` beside `mounts.json`, if any. */
|
|
97
|
+
export function readStereoMarks(project: string): ReadonlySet<string> {
|
|
98
|
+
const file = resolve(project, 'audio-stereo.json');
|
|
99
|
+
return existsSync(file) ? new Set(v.parse(StereoSchema, JSON.parse(readFileSync(file, 'utf8'))).stereo) : new Set();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** AU5's per-file findings the encoder answers for: format and bitrate, not the shard's budget or the 180 s rule. */
|
|
103
|
+
function missedTargets(row: Parameters<typeof audioReport>[0][number]): ReturnType<typeof audioReport>['findings'] {
|
|
104
|
+
return audioReport([row], { slug: '', waiver: undefined, today: '' }).findings.filter(finding => finding.rule === 'format' || finding.rule === 'bitrate');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Whether AAC bytes already meet AU5 at the channel count the build would pick, so encoding them again only loses. */
|
|
108
|
+
function alreadyAtTarget(url: string, bytes: Uint8Array, role: Role, stereo: boolean): boolean {
|
|
109
|
+
const row = measureRecording(url, sha(bytes), bytes);
|
|
110
|
+
if (row.codec !== 'aac' || row.reason !== undefined) return false;
|
|
111
|
+
if (role === 'sfx' && !stereo && row.channels !== 1) return false;
|
|
112
|
+
return missedTargets(row).length === 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function readCache(root: string, key: string): Uint8Array | undefined {
|
|
116
|
+
try {
|
|
117
|
+
const meta: unknown = JSON.parse(readFileSync(resolve(root, `${key}.json`), 'utf8'));
|
|
118
|
+
if (typeof meta !== 'object' || meta === null || !('key' in meta) || meta.key !== key || !('hash' in meta)) return undefined;
|
|
119
|
+
const bytes = readFileSync(resolve(root, `${key}.m4a`));
|
|
120
|
+
return sha(bytes) === meta.hash ? new Uint8Array(bytes) : undefined;
|
|
121
|
+
} catch { return undefined; }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function writeCache(root: string, key: string, bytes: Uint8Array): void {
|
|
125
|
+
const suffix = `.${process.pid}.${randomBytes(8).toString('hex')}.tmp`, body = resolve(root, `${key}.m4a`), meta = resolve(root, `${key}.json`);
|
|
126
|
+
try {
|
|
127
|
+
writeFileSync(body + suffix, bytes, { flag: 'wx' }); renameSync(body + suffix, body);
|
|
128
|
+
writeFileSync(meta + suffix, JSON.stringify({ key, hash: sha(bytes) }), { flag: 'wx' }); renameSync(meta + suffix, meta);
|
|
129
|
+
} catch { /* Storage availability does not change the build. */ }
|
|
130
|
+
finally { for (const file of [body + suffix, meta + suffix]) rmSync(file, { force: true }); }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A private work folder under the cache root, or under the system's temporary folder when the cache is not writable. */
|
|
134
|
+
function workFolder(root: string): string {
|
|
135
|
+
try { const work = resolve(root, `work-${process.pid}-${randomBytes(8).toString('hex')}`); mkdirSync(work, { recursive: true }); return work; }
|
|
136
|
+
catch { return mkdtempSync(join(tmpdir(), 'wildshard-audio-')); }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Encode one source with ffmpeg in a private work folder; the output must pass AU5's index, format and bitrate. */
|
|
140
|
+
async function encode(encoder: AudioEncoder, root: string, url: string, bytes: Uint8Array, role: Role, stereo: boolean): Promise<Uint8Array> {
|
|
141
|
+
const work = workFolder(root), ext = SOURCE.exec(url)?.groups?.['ext'] ?? 'bin';
|
|
142
|
+
try {
|
|
143
|
+
const input = resolve(work, `in.${ext}`), output = resolve(work, 'out.m4a');
|
|
144
|
+
writeFileSync(input, bytes);
|
|
145
|
+
const probed = Number((await run(encoder.ffprobe, ['-v', 'error', '-select_streams', 'a:0', '-show_entries', 'stream=channels', '-of', 'csv=p=0', input])).trim());
|
|
146
|
+
if (!Number.isInteger(probed) || probed < 1) throw new Error(`${url}: no audio stream to encode`);
|
|
147
|
+
const channels = probed === 1 || (role === 'sfx' && !stereo) ? 1 : 2;
|
|
148
|
+
const kbps = AUDIO_RULES.kbps[role][channels === 1 ? 'mono' : 'stereo'];
|
|
149
|
+
// AudioToolbox's CBR raises stereo under 64 kbps to 64 kbps, past a stereo sound effect's cap: ffmpeg's `aac` takes those.
|
|
150
|
+
const codec = encoder.codec === 'aac_at' && (channels === 1 || kbps >= AAC_AT_STEREO_FLOOR) ? 'aac_at' : 'aac';
|
|
151
|
+
const mode = codec === 'aac_at' ? ['-aac_at_mode', 'cbr', '-aac_at_quality', '0'] : [];
|
|
152
|
+
// A clip of a few frames overshoots its rate (priming and the last frame weigh more): step down 8 kbps, twice at most.
|
|
153
|
+
let missed = '';
|
|
154
|
+
for (const rate of [kbps, kbps - RATE_STEP, kbps - 2 * RATE_STEP]) {
|
|
155
|
+
await run(encoder.ffmpeg, ['-hide_banner', '-loglevel', 'error', '-nostdin', '-y', '-i', input, '-map', '0:a:0', '-map_metadata', '-1',
|
|
156
|
+
'-map_chapters', '-1', '-vn', '-c:a', codec, ...mode, '-b:a', `${rate}k`, '-ac', String(channels), '-ar', String(AUDIO_RULES.sampleRate),
|
|
157
|
+
'-fflags', '+bitexact', '-flags:a', '+bitexact', '-f', 'mp4', output]);
|
|
158
|
+
const encoded = new Uint8Array(readFileSync(output)), row = measureRecording(url.replace(/\.[a-z0-9]+$/u, '.m4a'), sha(encoded), encoded);
|
|
159
|
+
if (row.codec !== 'aac' || row.reason !== undefined) throw new Error(`${url}: ${codec} wrote AAC the playback index refuses (${row.reason ?? row.codec})`);
|
|
160
|
+
const findings = missedTargets(row);
|
|
161
|
+
if (findings.length === 0) return encoded;
|
|
162
|
+
missed = findings.map(finding => finding.message).join('; ');
|
|
163
|
+
if (findings.some(finding => finding.rule !== 'bitrate')) break;
|
|
164
|
+
}
|
|
165
|
+
throw new Error(`${url}: ${codec} missed AU5's target: ${missed}`);
|
|
166
|
+
} finally { rmSync(work, { recursive: true, force: true }); }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The encode steps' own code: a change to its arguments or rate ladder is a new cache key without a schema bump. */
|
|
170
|
+
const IMPLEMENTATION = sha(`${encode.toString()}\0${missedTargets.toString()}`);
|
|
171
|
+
|
|
172
|
+
/** Re-encode a shard's source recordings among its mounts, each at its own URL; every other mount passes through untouched. */
|
|
173
|
+
export async function encodeMountAudio(mounts: readonly Mount[], options: AudioEncodeOptions = {}): Promise<{ readonly mounts: Mount[]; readonly stats: AudioEncodeStats; readonly encoder: AudioEncoder | null }> {
|
|
174
|
+
const sources = mounts.filter(mount => isSourceRecordingUrl(mount.url));
|
|
175
|
+
const stats = { files: sources.length, encoded: 0, cached: 0, kept: 0, unencoded: 0, before: 0, after: 0 };
|
|
176
|
+
if (sources.length === 0) return { mounts: [...mounts], stats, encoder: null };
|
|
177
|
+
const encoder = options.encoder === undefined ? await findAudioEncoder() : options.encoder;
|
|
178
|
+
const root = options.cacheRoot ?? process.env['WILDSHARD_AUDIO_CACHE'] ?? resolve(homedir(), '.cache/wildshard/gen/audio-encode/1');
|
|
179
|
+
if (encoder !== null) try { mkdirSync(root, { recursive: true }); } catch { /* The cache is optional; encode still runs. */ }
|
|
180
|
+
const out = new Map<string, Uint8Array>();
|
|
181
|
+
const one = async ({ url, bytes }: Mount): Promise<void> => {
|
|
182
|
+
if (bytes.byteLength > MAX_BYTES) throw new Error(`audio: ${url} is over ${MAX_BYTES / MB} MB`);
|
|
183
|
+
const role: Role = SOURCE.exec(url)?.groups?.['role'] === 'music' ? 'music' : 'sfx', stereo = options.stereo?.has(url) === true;
|
|
184
|
+
stats.before += bytes.byteLength;
|
|
185
|
+
let result: Uint8Array;
|
|
186
|
+
if (url.endsWith('.m4a') && alreadyAtTarget(url, bytes, role, stereo)) { result = bytes; stats.kept++; }
|
|
187
|
+
else if (encoder === null) { result = bytes; stats.unencoded++; }
|
|
188
|
+
else {
|
|
189
|
+
const key = sha(JSON.stringify({ schema: SCHEMA, encoder: encoder.identity, rules: AUDIO_RULES, code: IMPLEMENTATION, role, stereo, source: sha(bytes) }));
|
|
190
|
+
const hit = readCache(root, key);
|
|
191
|
+
if (hit === undefined) { result = await encode(encoder, root, url, bytes, role, stereo); writeCache(root, key, result); stats.encoded++; }
|
|
192
|
+
else { result = hit; stats.cached++; }
|
|
193
|
+
}
|
|
194
|
+
stats.after += result.byteLength;
|
|
195
|
+
out.set(url, result);
|
|
196
|
+
};
|
|
197
|
+
// One failure stops the other workers taking new files.
|
|
198
|
+
const queue = [...sources], workers = Math.max(1, Math.min(4, availableParallelism()));
|
|
199
|
+
await Promise.all(Array.from({ length: workers }, async () => {
|
|
200
|
+
try { for (let next = queue.shift(); next !== undefined; next = queue.shift()) await one(next); }
|
|
201
|
+
catch (error) { queue.length = 0; throw error; }
|
|
202
|
+
}));
|
|
203
|
+
return { mounts: mounts.map(mount => { const bytes = out.get(mount.url); return bytes === undefined ? mount : { url: mount.url, bytes }; }), stats, encoder };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The build's audio line: before and after MB, and what each recording took. */
|
|
207
|
+
export function audioEncodeLine(slug: string, stats: AudioEncodeStats, encoder: AudioEncoder | null): string {
|
|
208
|
+
const mb = (bytes: number): string => `${(bytes / MB).toFixed(2)} MB`;
|
|
209
|
+
const how = [`${stats.encoded} encoded`, `${stats.cached} from cache`, `${stats.kept} already at target`, ...stats.unencoded > 0 ? [`${stats.unencoded} not encoded: no ffmpeg on PATH`] : []];
|
|
210
|
+
return `audio: ${slug} ${stats.files} recordings, ${mb(stats.before)} before, ${mb(stats.after)} after (${how.join(', ')}${encoder === null ? '' : `; ${encoder.codec}`})`;
|
|
211
|
+
}
|