@holtjs/stage 0.13.0 → 0.15.0

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.
@@ -1,2 +1,2 @@
1
- import { $t as OpenWgpuNativeFfiOptions, Gt as WebGpuBootstrapResult, Ht as RendererWebGpu, Jt as requestWebGpuDevice, Kt as WebGpuCanvasContextLike, Qt as OpenDawnWebGpuOptions, Ut as RendererWebGpuOptions, Wt as RequestWebGpuOptions, Xt as HeadlessWebGpuHandle, Yt as HeadlessWebGpuBackend, Zt as HeadlessWebGpuOptions, en as openDawnWebGpu, nn as requestHeadlessWebGpu, qt as WebGpuDeviceLike, tn as openWgpuNativeFfi } from "./game-C8bz7tay.js";
1
+ import { $t as HeadlessWebGpuOptions, Gt as RendererWebGpuOptions, Jt as WebGpuCanvasContextLike, Kt as RequestWebGpuOptions, Qt as HeadlessWebGpuHandle, Wt as RendererWebGpu, Xt as requestWebGpuDevice, Yt as WebGpuDeviceLike, Zt as HeadlessWebGpuBackend, en as OpenDawnWebGpuOptions, in as requestHeadlessWebGpu, nn as openDawnWebGpu, qt as WebGpuBootstrapResult, rn as openWgpuNativeFfi, tn as OpenWgpuNativeFfiOptions } from "./game-Ce35GTH4.js";
2
2
  export { type HeadlessWebGpuBackend, type HeadlessWebGpuHandle, type HeadlessWebGpuOptions, type OpenDawnWebGpuOptions, type OpenWgpuNativeFfiOptions, RendererWebGpu, RendererWebGpuOptions, RequestWebGpuOptions, WebGpuBootstrapResult, WebGpuCanvasContextLike, WebGpuDeviceLike, openDawnWebGpu, openWgpuNativeFfi, requestHeadlessWebGpu, requestWebGpuDevice };
@@ -1 +1 @@
1
- export { t as RendererWebGpu, r as openDawnWebGpu, i as openWgpuNativeFfi, a as requestHeadlessWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-LDnrpYa0.js";
1
+ export { t as RendererWebGpu, r as openDawnWebGpu, i as openWgpuNativeFfi, a as requestHeadlessWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-q4vdE3kA.js";
package/dist/rig2d.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as BlendMode } from "./anims-n8aqhzxu.js";
2
- import { Bn as SceneHostLike, On as Graphics, kn as ImageObject, pn as Container } from "./game-C8bz7tay.js";
1
+ import { T as BlendMode } from "./anims-BOvaKn6w.js";
2
+ import { An as Graphics, Hn as SceneHostLike, hn as Container, jn as ImageObject } from "./game-Ce35GTH4.js";
3
3
  export type RigCurveKind = 'linear' | 'step' | 'smoothstep' | 'outBack';
4
4
  export interface RigBoneDef {
5
5
  name: string;
package/dist/tilemap.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { Ct as unpackChunkY, St as unpackChunkX, _t as floorDiv, at as ChunkedTilemapOptions, bt as packChunkKey, ct as MountedChunkedTilemap, dt as TileChunk, ft as bakeDualGridTileset, gt as fbm2D, ht as createIslandBiomeGenerator, it as ChunkedTilemap, lt as SurvivalBiomes, mt as computeDualGridMask, nt as BakedDualGridAtlas, ot as DualGridLayerSpec, pt as computeBlob47Index, rt as ChunkGeneratorFn, st as IslandBiomeConfig, ut as TileCellFlags, vt as hash2D, wt as valueNoise2D, xt as positiveMod, yt as mountChunkedTilemap } from "./game-C8bz7tay.js";
2
- export { BakedDualGridAtlas, ChunkGeneratorFn, ChunkedTilemap, ChunkedTilemapOptions, DualGridLayerSpec, IslandBiomeConfig, MountedChunkedTilemap, SurvivalBiomes, TileCellFlags, TileChunk, bakeDualGridTileset, computeBlob47Index, computeDualGridMask, createIslandBiomeGenerator, fbm2D, floorDiv, hash2D, mountChunkedTilemap, packChunkKey, positiveMod, unpackChunkX, unpackChunkY, valueNoise2D };
1
+ import { Ct as positiveMod, Et as valueNoise2D, St as packChunkKey, Tt as unpackChunkY, _t as createIslandBiomeGenerator, at as ChunkedTilemap, bt as hash2D, ct as IslandBiomeConfig, dt as SurvivalBiomes, ft as TileCellFlags, gt as computeDualGridMask, ht as computeBlob47Index, it as ChunkGeneratorFn, lt as MountChunkedTilemapOptions, mt as bakeDualGridTileset, nt as BakeDualGridTilesetOptions, ot as ChunkedTilemapOptions, pt as TileChunk, rt as BakedDualGridAtlas, st as DualGridLayerSpec, ut as MountedChunkedTilemap, vt as fbm2D, wt as unpackChunkX, xt as mountChunkedTilemap, yt as floorDiv } from "./game-Ce35GTH4.js";
2
+ export { BakeDualGridTilesetOptions, BakedDualGridAtlas, ChunkGeneratorFn, ChunkedTilemap, ChunkedTilemapOptions, DualGridLayerSpec, IslandBiomeConfig, MountChunkedTilemapOptions, MountedChunkedTilemap, SurvivalBiomes, TileCellFlags, TileChunk, bakeDualGridTileset, computeBlob47Index, computeDualGridMask, createIslandBiomeGenerator, fbm2D, floorDiv, hash2D, mountChunkedTilemap, packChunkKey, positiveMod, unpackChunkX, unpackChunkY, valueNoise2D };
package/dist/tilemap.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as FilterMode } from "./types-CXsCvp1p.js";
1
+ import { _ as rgbToCss, o as FilterMode } from "./types-CXsCvp1p.js";
2
2
  // src/tilemap.ts
3
3
  /** Pack signed 16-bit chunk coordinates `[-32768..32767]` into a single 32-bit integer Map key (zero string allocation). */
4
4
  function packChunkKey(cx, cy) {
@@ -18,7 +18,7 @@ function positiveMod(a, b) {
18
18
  return r < 0 ? r + b : r;
19
19
  }
20
20
  /**
21
- * Compute Oskar Stålberg's 4-bit **Dual-Grid** mask (`0..15`) for visual vertex `(vx, vy)`,
21
+ * Compute the 4-bit **Dual-Grid** mask (`0..15`) for half-offset visual vertex `(vx, vy)`,
22
22
  * which sits at world `(vx * tileSize - tileSize * 0.5, vy * tileSize - tileSize * 0.5)` and samples
23
23
  * the 4 surrounding logical cells `(vx-1, vy-1)`, `(vx, vy-1)`, `(vx-1, vy)`, `(vx, vy)`.
24
24
  *
@@ -282,8 +282,8 @@ var ChunkedTilemap = class {
282
282
  const rev = ++this.globalRevision;
283
283
  ch.version = rev;
284
284
  const last = this.chunkSize - 1;
285
- const dx = lx === 0 ? -1 : lx === last ? 1 : 0;
286
- const dy = ly === 0 ? -1 : ly === last ? 1 : 0;
285
+ const dx = lx <= 1 ? -1 : lx >= last - 1 ? 1 : 0;
286
+ const dy = ly <= 1 ? -1 : ly >= last - 1 ? 1 : 0;
287
287
  if (dx !== 0) {
288
288
  const n = this.peekChunk(ch.cx + dx, ch.cy);
289
289
  if (n) n.version = rev;
@@ -381,27 +381,36 @@ function createIslandBiomeGenerator(cfg) {
381
381
  }
382
382
  /**
383
383
  * Bake one or more 16-tile (`0..15`) organic Dual-Grid terrain layers onto a single crisp texture atlas!
384
- * Uses smooth analytical quarter-circle / saddle SDF distance fields per pixel so beaches, grass, dark forest,
385
- * and cobblestone roads interlock with hand-crafted *Don't Starve* turf borders.
384
+ * Uses smooth analytical quarter-circle / saddle SDF distance fields per pixel with edge-pixel extrusion
385
+ * (`extrude = 2` by default) so rotated 2.5D ground never bleeds neighbor cells under `FilterMode.LINEAR`.
386
386
  */
387
- function bakeDualGridTileset(textureKey, tileSize, layers, createCanvasFn) {
387
+ function bakeDualGridTileset(textureKey, tileSize, layers, createCanvasOrOpts, maybeOpts) {
388
+ const createCanvasFn = typeof createCanvasOrOpts === "function" ? createCanvasOrOpts : maybeOpts?.createCanvas ?? createCanvasOrOpts?.createCanvas;
389
+ const resolvedOpts = (typeof createCanvasOrOpts === "object" && createCanvasOrOpts !== null ? createCanvasOrOpts : maybeOpts) ?? {};
388
390
  const ts = Math.max(8, Math.round(tileSize));
391
+ const extrude = Math.max(0, Math.round(resolvedOpts.extrude ?? 2));
392
+ const filterMode = resolvedOpts.filterMode ?? FilterMode.NEAREST;
393
+ const stride = ts + extrude * 2;
389
394
  const cols = 16;
390
395
  const rows = Math.max(1, layers.length);
391
- const w = cols * ts;
392
- const h = rows * ts;
393
- const canvas = (createCanvasFn ?? ((cw, ch) => {
394
- if (typeof document === "undefined") throw new Error("bakeDualGridTileset: pass createCanvasFn in headless Node environments");
396
+ const w = cols * stride;
397
+ const h = rows * stride;
398
+ let canvas = null;
399
+ let ctx = null;
400
+ if (createCanvasFn) {
401
+ canvas = createCanvasFn(w, h);
402
+ ctx = canvas.getContext("2d");
403
+ } else if (typeof document !== "undefined" && typeof document.createElement === "function") {
395
404
  const c = document.createElement("canvas");
396
- c.width = cw;
397
- c.height = ch;
398
- return c;
399
- }))(w, h);
400
- const ctx = canvas.getContext("2d");
401
- if (!ctx) throw new Error("bakeDualGridTileset: 2D context unavailable");
402
- ctx.clearRect(0, 0, w, h);
403
- const img = ctx.createImageData(w, h);
404
- const data = img.data;
405
+ c.width = w;
406
+ c.height = h;
407
+ const c2d = c.getContext("2d");
408
+ if (c2d) {
409
+ canvas = c;
410
+ ctx = c2d;
411
+ }
412
+ }
413
+ const rgba = new Uint8ClampedArray(w * h * 4);
405
414
  for (let li = 0; li < layers.length; li++) {
406
415
  const layer = layers[li];
407
416
  const fr = layer.fillColor >> 16 & 255;
@@ -419,8 +428,8 @@ function bakeDualGridTileset(textureKey, tileSize, layers, createCanvasFn) {
419
428
  const tr = mask & 4 ? 1 : 0;
420
429
  const bl = mask & 2 ? 1 : 0;
421
430
  const br = mask & 1 ? 1 : 0;
422
- const ox = mask * ts;
423
- const oy = li * ts;
431
+ const ox = mask * stride + extrude;
432
+ const oy = li * stride + extrude;
424
433
  for (let py = 0; py < ts; py++) {
425
434
  const v = (py + .5) / ts;
426
435
  for (let px = 0; px < ts; px++) {
@@ -435,38 +444,96 @@ function bakeDualGridTileset(textureKey, tileSize, layers, createCanvasFn) {
435
444
  const isEdge = mask !== 15 && field < .56;
436
445
  const grain = hash2D(px, py, li * 97 + mask * 13);
437
446
  if (isEdge) {
438
- data[pIdx] = er;
439
- data[pIdx + 1] = eg;
440
- data[pIdx + 2] = eb;
441
- data[pIdx + 3] = field < .5 ? 200 : 255;
447
+ rgba[pIdx] = er;
448
+ rgba[pIdx + 1] = eg;
449
+ rgba[pIdx + 2] = eb;
450
+ rgba[pIdx + 3] = field < .5 ? 200 : 255;
442
451
  } else if (grain > .89) {
443
- data[pIdx] = sr;
444
- data[pIdx + 1] = sg;
445
- data[pIdx + 2] = sb;
446
- data[pIdx + 3] = 255;
452
+ rgba[pIdx] = sr;
453
+ rgba[pIdx + 1] = sg;
454
+ rgba[pIdx + 2] = sb;
455
+ rgba[pIdx + 3] = 255;
447
456
  } else {
448
- data[pIdx] = fr;
449
- data[pIdx + 1] = fg;
450
- data[pIdx + 2] = fb;
451
- data[pIdx + 3] = 255;
457
+ rgba[pIdx] = fr;
458
+ rgba[pIdx + 1] = fg;
459
+ rgba[pIdx + 2] = fb;
460
+ rgba[pIdx + 3] = 255;
461
+ }
462
+ }
463
+ }
464
+ if (extrude > 0) {
465
+ const rowBytes = ts * 4;
466
+ const topSrc = (oy * w + ox) * 4;
467
+ const botSrc = ((oy + ts - 1) * w + ox) * 4;
468
+ for (let e = 1; e <= extrude; e++) {
469
+ rgba.set(rgba.subarray(topSrc, topSrc + rowBytes), ((oy - e) * w + ox) * 4);
470
+ rgba.set(rgba.subarray(botSrc, botSrc + rowBytes), ((oy + ts - 1 + e) * w + ox) * 4);
471
+ }
472
+ for (let ry = oy - extrude; ry < oy + ts + extrude; ry++) {
473
+ const leftSrc = (ry * w + ox) * 4;
474
+ const rightSrc = (ry * w + ox + ts - 1) * 4;
475
+ for (let e = 1; e <= extrude; e++) {
476
+ const lDst = leftSrc - e * 4;
477
+ rgba[lDst] = rgba[leftSrc];
478
+ rgba[lDst + 1] = rgba[leftSrc + 1];
479
+ rgba[lDst + 2] = rgba[leftSrc + 2];
480
+ rgba[lDst + 3] = rgba[leftSrc + 3];
481
+ const rDst = rightSrc + e * 4;
482
+ rgba[rDst] = rgba[rightSrc];
483
+ rgba[rDst + 1] = rgba[rightSrc + 1];
484
+ rgba[rDst + 2] = rgba[rightSrc + 2];
485
+ rgba[rDst + 3] = rgba[rightSrc + 3];
452
486
  }
453
487
  }
454
488
  }
455
489
  }
456
490
  }
457
- ctx.putImageData(img, 0, 0);
491
+ const has2dCanvas = Boolean(canvas && ctx);
492
+ if (canvas && ctx) {
493
+ ctx.clearRect(0, 0, w, h);
494
+ const img = ctx.createImageData(w, h);
495
+ img.data.set(rgba);
496
+ ctx.putImageData(img, 0, 0);
497
+ }
498
+ const fallbackCanvas = canvas ?? {
499
+ width: w,
500
+ height: h,
501
+ data: rgba,
502
+ getContext: () => null
503
+ };
504
+ const frameRect = (layerIndex, mask) => ({
505
+ x: (mask & 15) * stride + extrude,
506
+ y: layerIndex * stride + extrude,
507
+ width: ts,
508
+ height: ts
509
+ });
458
510
  return {
459
511
  textureKey,
460
512
  tileSize: ts,
461
- canvas,
513
+ extrude,
514
+ cellStride: stride,
515
+ filterMode,
516
+ width: w,
517
+ height: h,
518
+ rgba,
519
+ canvas: fallbackCanvas,
462
520
  layers,
463
521
  frameName: (layerId, mask) => `${layerId}:${mask & 15}`,
464
- registerOnScene(scene) {
465
- const tex = scene.textures.addImage(textureKey, canvas, { filterMode: FilterMode.NEAREST });
522
+ frameRect,
523
+ registerOnScene(scene, opts) {
524
+ const source = has2dCanvas ? fallbackCanvas : {
525
+ width: w,
526
+ height: h,
527
+ data: rgba
528
+ };
529
+ const tex = scene.textures.addImage(textureKey, source, { filterMode: opts?.filterMode ?? filterMode });
466
530
  if (!tex) return;
467
531
  for (let li = 0; li < layers.length; li++) {
468
532
  const lid = layers[li].id;
469
- for (let mask = 0; mask < 16; mask++) tex.add(`${lid}:${mask}`, 0, mask * ts, li * ts, ts, ts);
533
+ for (let mask = 0; mask < 16; mask++) {
534
+ const r = frameRect(li, mask);
535
+ tex.add(`${lid}:${mask}`, 0, r.x, r.y, r.width, r.height);
536
+ }
470
537
  }
471
538
  }
472
539
  };
@@ -474,17 +541,17 @@ function bakeDualGridTileset(textureKey, tileSize, layers, createCanvasFn) {
474
541
  let nextTilemapMountSeq = 1;
475
542
  /**
476
543
  * Mount a `ChunkedTilemap` + `BakedDualGridAtlas` onto a Stage `Scene`.
477
- * - On WebGL2 / WebGPU: batches into 1 GPU `BlitterObject` draw call per Dual-Grid layer.
478
- * - On Canvas2D / pure-Node `createHeadlessStage`: automatically pre-composites all Dual-Grid layers of each
479
- * `16×16` chunk onto a cached offscreen chunk canvas keyed by `chunk.version` (collapsing ~4,500 per-frame
480
- * rotated tile `drawImage` calls down to ~12 chunk blits — >10× faster 60 FPS headless video rendering!).
544
+ * - By default (`chunkCache: true`) across WebGPU, WebGL2, and Canvas2D: pre-composites all Dual-Grid layers of each
545
+ * chunk onto a cached chunk texture with a `2px` cross-chunk world-neighbor apron (`chunkApron: 2`), inheriting
546
+ * `FilterMode.LINEAR` / `FilterMode.NEAREST` so rotated 2.5D ground has zero tile or chunk seams at ~12 quads/frame.
547
+ * - Pass `{ chunkCache: false }` to emit individual per-layer `BlitterObject` quads instead.
481
548
  */
482
549
  function mountChunkedTilemap(scene, map, atlas, opts = {}) {
483
550
  const mountId = nextTilemapMountSeq++;
484
551
  const root = scene.add.container(0, 0);
485
552
  if (opts.depth !== void 0) root.setDepth(opts.depth);
486
553
  if (opts.trackId) root.trackId = opts.trackId;
487
- if (!scene.textures.exists(atlas.textureKey)) atlas.registerOnScene(scene);
554
+ if (!scene.textures.exists(atlas.textureKey)) atlas.registerOnScene(scene, opts.filterMode !== void 0 ? { filterMode: opts.filterMode } : void 0);
488
555
  const resolvedTex = scene.textures.get(atlas.textureKey);
489
556
  if (!resolvedTex) throw new Error(`mountChunkedTilemap: missing atlas texture "${atlas.textureKey}"`);
490
557
  const layers = atlas.layers;
@@ -494,7 +561,15 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
494
561
  return arr;
495
562
  });
496
563
  const doc = scene.doc ?? (typeof document !== "undefined" ? document : null);
497
- const useChunkCache = opts.chunkCache !== void 0 ? Boolean(opts.chunkCache && doc) : Boolean(scene.renderer?.type === 1 && doc);
564
+ let canUseCanvas2d = false;
565
+ if (doc && typeof doc.createElement === "function") {
566
+ const probe = doc.createElement("canvas");
567
+ canUseCanvas2d = Boolean(probe && typeof probe.getContext === "function" && probe.getContext("2d"));
568
+ }
569
+ const isCanvasRenderer = scene.renderer?.type === 1;
570
+ const canCompositeRawRgba = !isCanvasRenderer && Boolean(atlas.rgba && atlas.width > 0 && atlas.height > 0);
571
+ const useChunkCache = opts.chunkCache !== void 0 ? Boolean(opts.chunkCache && (canUseCanvas2d || canCompositeRawRgba)) : Boolean(canUseCanvas2d || canCompositeRawRgba);
572
+ const chunkFilterMode = opts.filterMode ?? resolvedTex.source[0]?.filterMode ?? atlas.filterMode ?? FilterMode.NEAREST;
498
573
  const blitters = useChunkCache ? [] : layers.map((_, i) => {
499
574
  const b = scene.make.blitter(0, 0, atlas.textureKey);
500
575
  b.zIndex = i;
@@ -507,8 +582,11 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
507
582
  const cs = map.chunkSize;
508
583
  const chunkPx = cs * ts;
509
584
  const halfTs = ts * .5;
585
+ const apronPx = useChunkCache ? Math.max(0, Math.min(ts, Math.round(opts.chunkApron ?? 2))) : 0;
586
+ const surfSize = chunkPx + apronPx * 2;
587
+ const cutSize = isCanvasRenderer && apronPx >= 1 ? chunkPx + 1 : chunkPx;
510
588
  let totalBobs = 0;
511
- const tileSlices = useChunkCache ? layers.map(() => new Array(16)) : [];
589
+ const tileSlices = useChunkCache && canUseCanvas2d ? layers.map(() => new Array(16)) : [];
512
590
  const getTileSlice = (li, mask, fr) => {
513
591
  const row = tileSlices[li];
514
592
  if (!row || !doc) return null;
@@ -544,56 +622,137 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
544
622
  entry.chunkTexKey = void 0;
545
623
  }
546
624
  entry.chunkCanvas = void 0;
625
+ entry.chunkRawSource = void 0;
547
626
  };
548
627
  const buildChunkBobs = (cx, cy, version, prev) => {
549
628
  const startVx = cx * cs;
550
629
  const startVy = cy * cs;
551
- if (useChunkCache && doc) {
552
- const chunkCanvas = prev?.chunkCanvas ?? doc.createElement("canvas");
553
- if (chunkCanvas.width !== chunkPx || chunkCanvas.height !== chunkPx) {
554
- chunkCanvas.width = chunkPx;
555
- chunkCanvas.height = chunkPx;
556
- }
557
- const cctx = chunkCanvas.getContext("2d");
630
+ if (useChunkCache) {
631
+ const lyMin = apronPx > 0 ? -1 : 0;
632
+ const lyMax = apronPx > 0 ? cs : cs - 1;
633
+ const lxMin = apronPx > 0 ? -1 : 0;
634
+ const lxMax = apronPx > 0 ? cs : cs - 1;
558
635
  let bobCount = 0;
559
- if (cctx) {
560
- cctx.clearRect(0, 0, chunkPx, chunkPx);
561
- cctx.imageSmoothingEnabled = false;
562
- const srcImg = atlas.canvas;
563
- for (let ly = 0; ly < cs; ly++) {
636
+ let chunkCanvas = prev?.chunkCanvas;
637
+ let chunkRawSource = prev?.chunkRawSource;
638
+ if (canUseCanvas2d && doc) {
639
+ chunkCanvas = chunkCanvas ?? doc.createElement("canvas");
640
+ if (chunkCanvas.width !== surfSize || chunkCanvas.height !== surfSize) {
641
+ chunkCanvas.width = surfSize;
642
+ chunkCanvas.height = surfSize;
643
+ }
644
+ const cctx = chunkCanvas.getContext("2d");
645
+ if (cctx) {
646
+ cctx.clearRect(0, 0, surfSize, surfSize);
647
+ if (opts.baseColor !== void 0) {
648
+ cctx.fillStyle = rgbToCss(opts.baseColor);
649
+ cctx.fillRect(0, 0, surfSize, surfSize);
650
+ }
651
+ cctx.imageSmoothingEnabled = false;
652
+ const fallbackSrcImg = resolvedTex.source[0]?.image ?? atlas.canvas;
653
+ for (let ly = lyMin; ly <= lyMax; ly++) {
654
+ const vy = startVy + ly;
655
+ const dy = ly * ts + apronPx;
656
+ for (let lx = lxMin; lx <= lxMax; lx++) {
657
+ const vx = startVx + lx;
658
+ const dx = lx * ts + apronPx;
659
+ const isInterior = lx >= 0 && lx < cs && ly >= 0 && ly < cs;
660
+ for (let li = 0; li < layers.length; li++) {
661
+ const mask = map.sampleDualGridMask(vx, vy, layers[li].matches);
662
+ if (mask === 0) continue;
663
+ const fr = frameTable[li][mask];
664
+ const tileSlice = getTileSlice(li, mask, fr);
665
+ if (tileSlice) cctx.drawImage(tileSlice, 0, 0, fr.cutWidth, fr.cutHeight, dx, dy, ts, ts);
666
+ else cctx.drawImage(fallbackSrcImg, fr.cutX, fr.cutY, fr.cutWidth, fr.cutHeight, dx, dy, ts, ts);
667
+ if (isInterior) bobCount++;
668
+ }
669
+ }
670
+ }
671
+ }
672
+ } else if (canCompositeRawRgba) {
673
+ if (!chunkRawSource || chunkRawSource.width !== surfSize || chunkRawSource.height !== surfSize) chunkRawSource = {
674
+ width: surfSize,
675
+ height: surfSize,
676
+ data: new Uint8Array(surfSize * surfSize * 4)
677
+ };
678
+ const dst = chunkRawSource.data;
679
+ if (opts.baseColor !== void 0) {
680
+ const br = opts.baseColor >> 16 & 255;
681
+ const bg = opts.baseColor >> 8 & 255;
682
+ const bb = opts.baseColor & 255;
683
+ for (let p = 0; p < dst.length; p += 4) {
684
+ dst[p] = br;
685
+ dst[p + 1] = bg;
686
+ dst[p + 2] = bb;
687
+ dst[p + 3] = 255;
688
+ }
689
+ } else dst.fill(0);
690
+ const srcData = atlas.rgba;
691
+ const srcW = atlas.width;
692
+ for (let ly = lyMin; ly <= lyMax; ly++) {
564
693
  const vy = startVy + ly;
565
- const dy = ly * ts;
566
- for (let lx = 0; lx < cs; lx++) {
694
+ const dy = ly * ts + apronPx;
695
+ const pyStart = dy < 0 ? -dy : 0;
696
+ const pyEnd = dy + ts > surfSize ? surfSize - dy : ts;
697
+ if (pyStart >= pyEnd) continue;
698
+ for (let lx = lxMin; lx <= lxMax; lx++) {
567
699
  const vx = startVx + lx;
568
- const dx = lx * ts;
700
+ const dx = lx * ts + apronPx;
701
+ const pxStart = dx < 0 ? -dx : 0;
702
+ const pxEnd = dx + ts > surfSize ? surfSize - dx : ts;
703
+ if (pxStart >= pxEnd) continue;
704
+ const isInterior = lx >= 0 && lx < cs && ly >= 0 && ly < cs;
569
705
  for (let li = 0; li < layers.length; li++) {
570
706
  const mask = map.sampleDualGridMask(vx, vy, layers[li].matches);
571
707
  if (mask === 0) continue;
572
708
  const fr = frameTable[li][mask];
573
- const tileSlice = getTileSlice(li, mask, fr);
574
- if (tileSlice) cctx.drawImage(tileSlice, 0, 0, fr.cutWidth, fr.cutHeight, dx, dy, ts, ts);
575
- else cctx.drawImage(srcImg, fr.cutX, fr.cutY, fr.cutWidth, fr.cutHeight, dx, dy, ts, ts);
576
- bobCount++;
709
+ const cutX = fr.cutX | 0;
710
+ const cutY = fr.cutY | 0;
711
+ for (let py = pyStart; py < pyEnd; py++) {
712
+ let sOff = ((cutY + py) * srcW + cutX + pxStart) * 4;
713
+ let dOff = ((dy + py) * surfSize + dx + pxStart) * 4;
714
+ for (let px = pxStart; px < pxEnd; px++, sOff += 4, dOff += 4) {
715
+ const sa = srcData[sOff + 3];
716
+ if (sa === 0) continue;
717
+ if (sa === 255 || dst[dOff + 3] === 0) {
718
+ dst[dOff] = srcData[sOff];
719
+ dst[dOff + 1] = srcData[sOff + 1];
720
+ dst[dOff + 2] = srcData[sOff + 2];
721
+ dst[dOff + 3] = sa;
722
+ } else {
723
+ const inv = 255 - sa;
724
+ dst[dOff] = (srcData[sOff] * sa + dst[dOff] * inv + 127) / 255;
725
+ dst[dOff + 1] = (srcData[sOff + 1] * sa + dst[dOff + 1] * inv + 127) / 255;
726
+ dst[dOff + 2] = (srcData[sOff + 2] * sa + dst[dOff + 2] * inv + 127) / 255;
727
+ dst[dOff + 3] = sa + (dst[dOff + 3] * inv + 127) / 255;
728
+ }
729
+ }
730
+ }
731
+ if (isInterior) bobCount++;
577
732
  }
578
733
  }
579
734
  }
580
735
  }
581
736
  const texKey = prev?.chunkTexKey ?? `__stage_tchunk_${mountId}_${cx}_${cy}`;
737
+ const texSource = chunkCanvas ?? chunkRawSource;
582
738
  let chunkImage = prev?.chunkImage;
583
- if (!prev?.chunkTexKey || !scene.textures.exists(texKey)) scene.textures.addImage(texKey, chunkCanvas, { filterMode: FilterMode.NEAREST });
584
- else scene.textures.get(texKey).source[0]?.update();
739
+ if (!prev?.chunkTexKey || !scene.textures.exists(texKey)) {
740
+ const ctex = scene.textures.addImage(texKey, texSource, { filterMode: chunkFilterMode });
741
+ if (ctex && apronPx > 0) ctex.add("interior", 0, apronPx, apronPx, cutSize, cutSize);
742
+ } else scene.textures.get(texKey).source[0]?.update();
585
743
  if (!chunkImage) {
586
- chunkImage = scene.make.image(cx * chunkPx - halfTs, cy * chunkPx - halfTs, texKey);
744
+ chunkImage = scene.make.image(cx * chunkPx - halfTs, cy * chunkPx - halfTs, texKey, apronPx > 0 ? "interior" : void 0);
587
745
  chunkImage.setOrigin(0, 0);
588
746
  root.add(chunkImage);
589
747
  }
590
- chunkImage.visible = bobCount > 0;
748
+ chunkImage.visible = bobCount > 0 || opts.baseColor !== void 0;
591
749
  return {
592
750
  version,
593
751
  bobsByLayer: [],
594
752
  bobCount,
595
753
  chunkTexKey: texKey,
596
754
  chunkCanvas,
755
+ chunkRawSource,
597
756
  chunkImage
598
757
  };
599
758
  }
package/dist/trace.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { At as SceneDigestOverlayStats, Dt as SceneDigestEngineSandbox, Et as SceneDigestActiveFocus, Ft as buildSceneDigest, It as sanitizeTrackToken, Mt as SceneDigestSurfaceEntry, Nt as SceneDigestSurfaceSource, Ot as SceneDigestNode, Pt as SceneDigestSurfaces, Tt as SceneDigest, jt as SceneDigestSandbox, kt as SceneDigestOptions } from "./game-C8bz7tay.js";
1
+ import { At as SceneDigestNode, Dt as SceneDigest, Ft as SceneDigestSurfaceSource, It as SceneDigestSurfaces, Lt as buildSceneDigest, Mt as SceneDigestOverlayStats, Nt as SceneDigestSandbox, Ot as SceneDigestActiveFocus, Pt as SceneDigestSurfaceEntry, Rt as sanitizeTrackToken, jt as SceneDigestOptions, kt as SceneDigestEngineSandbox } from "./game-Ce35GTH4.js";
2
2
  export { SceneDigest, SceneDigestActiveFocus, SceneDigestEngineSandbox, SceneDigestNode, SceneDigestOptions, SceneDigestOverlayStats, SceneDigestSandbox, SceneDigestSurfaceEntry, SceneDigestSurfaceSource, SceneDigestSurfaces, buildSceneDigest, sanitizeTrackToken };
package/dist/world.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as decodeWorldDeltaBytes, B as RecipeRegistry, F as InventoryContainer, G as WorkstationSnapshot, H as WorkstationInstance, I as ItemDef, J as WorldDeltaSnapshot, K as WorldCatalogRuntime, L as ItemRegistry, N as CatalogReloadDiff, P as FrozenWorldCatalog, Q as createWorldCatalogRuntime, R as ItemStack, U as WorkstationJob, V as TileCellDelta, W as WorkstationScheduler, X as applyWorldDelta, Y as WorldEntityRecord, Z as captureWorldDelta, et as defineWorldCatalog, q as WorldCatalogSpec, tt as encodeWorldDeltaBytes, z as RecipeDef } from "./game-C8bz7tay.js";
1
+ import { $ as decodeWorldDeltaBytes, B as RecipeRegistry, F as InventoryContainer, G as WorkstationSnapshot, H as WorkstationInstance, I as ItemDef, J as WorldDeltaSnapshot, K as WorldCatalogRuntime, L as ItemRegistry, N as CatalogReloadDiff, P as FrozenWorldCatalog, Q as createWorldCatalogRuntime, R as ItemStack, U as WorkstationJob, V as TileCellDelta, W as WorkstationScheduler, X as applyWorldDelta, Y as WorldEntityRecord, Z as captureWorldDelta, et as defineWorldCatalog, q as WorldCatalogSpec, tt as encodeWorldDeltaBytes, z as RecipeDef } from "./game-Ce35GTH4.js";
2
2
  export { CatalogReloadDiff, FrozenWorldCatalog, InventoryContainer, ItemDef, ItemRegistry, ItemStack, RecipeDef, RecipeRegistry, TileCellDelta, WorkstationInstance, WorkstationJob, WorkstationScheduler, WorkstationSnapshot, WorldCatalogRuntime, WorldCatalogSpec, WorldDeltaSnapshot, WorldEntityRecord, applyWorldDelta, captureWorldDelta, createWorldCatalogRuntime, decodeWorldDeltaBytes, defineWorldCatalog, encodeWorldDeltaBytes };
package/llms.txt CHANGED
@@ -25,7 +25,7 @@
25
25
  - `@holtjs/stage/kernel` (~4.9 kB gz, no DOM): `StageKernel` (`game.kernel`), `StagePlugin` lifecycle, `ActionMap`, `InputProvider` bus, `createInputTimeline` (`trackId` semantic clicks + virtual cursor), `createInputRecorder`, `createInputReplay`.
26
26
  - `@holtjs/stage/headless` (~50.4 kB gz, pure Node with `@napi-rs/canvas`): `createHeadlessStage` (`.step()`, `.fastForward()`, `.toRgbaInto()`, `.recordFrames()`), `renderStoryboard`, `createAudioTimeline` stereo WAV mixer.
27
27
  - `@holtjs/stage/rig2d` (~5.7 kB gz, no DOM): 2D cutout/slot skeletal rig (`defineRig2DSkeleton`, `Rig2DInstance`, `mountRig2D`, `bakeCutoutAtlas`), O(1) equipment/skin swapping, 2-layer base + bone-masked overlay mixer.
28
- - `@holtjs/stage/tilemap` (~4.0 kB gz, no DOM): Sparse `ChunkedTilemap`, Oskar Stålberg 16-tile Dual-Grid autotiler (`computeDualGridMask`, `bakeDualGridTileset`), 47-tile Blob autotiler (`computeBlob47Index`), `createIslandBiomeGenerator`, chunk-cached `mountChunkedTilemap`.
28
+ - `@holtjs/stage/tilemap` (~4.0 kB gz, no DOM): Sparse `ChunkedTilemap`, 16-tile Dual-Grid autotiler (`computeDualGridMask`, edge-extruded `bakeDualGridTileset`), 47-tile Blob autotiler (`computeBlob47Index`), `createIslandBiomeGenerator`, seamless neighbor-apron `mountChunkedTilemap`.
29
29
  - `@holtjs/stage/projection` (~2.8 kB gz, no DOM): Rotatable oblique `Camera25D` (`worldToScreen` ↔ `screenToGround`, smooth `Q/E` yaw spin) and `mountStage25D` (tilted ground plane + oblique sun `shadowLayer` + upright cylindrical depth-sorted billboards).
30
30
  - `@holtjs/stage/lighting` (~9.2 kB gz, no DOM): `DayNightCycle`, Sobel 3×3 `computeNormalMapPixels` / `bakeNormalMapCanvas`, `Lighting2DSystem` (zero-band radial `MULTIPLY` lightmap + `bindEmissive` self-lit glow), batched `createSceneNormalLitPass`.
31
31
  - `@holtjs/stage/world` (~2.8 kB gz, no DOM): `ItemRegistry`, `InventoryContainer` (with spoilage), `RecipeRegistry`, `WorkstationInstance` / `WorkstationScheduler` (offline tick catch-up), `WorldDeltaSave` (`HWLD` binary codec).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holtjs/stage",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Zero-dependency TypeScript stage engine for 2D WebGPU/WebGL2/Canvas2D games, GPU SDF UI, procedural audio, StageKernel plugins, tracing-native observability, and deterministic 60 FPS headless image & video rendering.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Botiverse, Inc.",
@@ -132,7 +132,7 @@ import {
132
132
  captureWorldDelta, encodeWorldDeltaBytes,
133
133
  } from '@holtjs/stage/world';
134
134
 
135
- // 1. Infinite/Island Chunked Tilemap + 16-tile Oskar Stålberg Dual-Grid Autotiler
135
+ // 1. Infinite/Island Chunked Tilemap + 16-tile Dual-Grid Autotiler
136
136
  const tilemap = new ChunkedTilemap({
137
137
  chunkSize: 16,
138
138
  tileSize: 36,
@@ -39,9 +39,9 @@ All symbols verified against `src/*.ts` (`@holtjs/stage@0.10.1`, 21 subpaths).
39
39
 
40
40
  ## `@holtjs/stage/tilemap` (~3.5 kB gz · zero DOM)
41
41
  - Sparse Chunk Storage: `ChunkedTilemap` (`.getGround(tx, ty)`, `.setGround(tx, ty, turfId)`, `.getOverlay(tx, ty)`, `.setOverlay(tx, ty, id, solid?)`, `.isWalkable(tx, ty)`, `.sampleDualGridMask()`, `.sampleOverlayBlob47()`, `.extractWalkGrid(...)`, `.exportModifiedCells()`), `TileCellFlags`, `packChunkKey`, `unpackChunkX`, `unpackChunkY`, `floorDiv`, `positiveMod`
42
- - Autotilers & Procedural Biomes: `computeDualGridMask(...)` (16-tile Oskar Stålberg Dual-Grid), `computeBlob47Index(...)` (47-tile Blob), `bakeDualGridTileset(textureKey, tileSize, layers, createCanvas?)`, `SurvivalBiomes`, `createIslandBiomeGenerator(cfg)`, `hash2D`, `valueNoise2D`, `fbm2D`
43
- - Scene Streaming Adapter: `mountChunkedTilemap(scene, tilemap, atlas, opts?)` -> `MountedChunkedTilemap` (`.container`, `.update(viewBounds)`, `.destroy()`)
44
- - Types: `TileChunk`, `ChunkGeneratorFn`, `ChunkedTilemapOptions`, `IslandBiomeConfig`, `DualGridLayerSpec`, `BakedDualGridAtlas`, `MountedChunkedTilemap`
42
+ - Autotilers & Procedural Biomes: `computeDualGridMask(...)` (16-tile half-offset Dual-Grid), `computeBlob47Index(...)` (47-tile Blob), `bakeDualGridTileset(textureKey, tileSize, layers, opts?)` (`extrude: 2`, `filterMode`), `SurvivalBiomes`, `createIslandBiomeGenerator(cfg)`, `hash2D`, `valueNoise2D`, `fbm2D`
43
+ - Scene Streaming Adapter: `mountChunkedTilemap(scene, tilemap, atlas, opts?)` -> `MountedChunkedTilemap` (`.container`, `.update(viewBounds)`, `.destroy()`, default `chunkCache: true` + `chunkApron: 2`)
44
+ - Types: `TileChunk`, `ChunkGeneratorFn`, `ChunkedTilemapOptions`, `IslandBiomeConfig`, `DualGridLayerSpec`, `BakeDualGridTilesetOptions`, `BakedDualGridAtlas`, `MountChunkedTilemapOptions`, `MountedChunkedTilemap`
45
45
 
46
46
  ## `@holtjs/stage/projection` (~2.8 kB gz · zero DOM)
47
47
  - `Camera25D`: `.worldToScreen(wx, wy, wz?, out?)`, `.screenToGround(sx, sy, planeZ?, out?)` (exact inverse across any 360° `yaw`), `.rotateSteps(steps, stepAngleRad?)`, `.setYawImmediate(yawRad)`, `.step(deltaMs)`, `.getGroundViewportBounds()`, `.computeSunShadowVector(...)`