@holtjs/stage 0.6.0 → 0.8.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.
- package/CHANGELOG.md +24 -0
- package/dist/anims-ClNi6zZQ.d.ts +391 -0
- package/dist/anims.d.ts +2 -0
- package/dist/anims.js +436 -0
- package/dist/{game-Blm49zGH.d.ts → game-CEa0m4eX.d.ts} +154 -203
- package/dist/{game-Ds-cn2YI.js → game-D46nY-B2.js} +187 -5
- package/dist/headless.d.ts +5 -1
- package/dist/headless.js +18 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -3
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/lighting.d.ts +1 -1
- package/dist/projection.d.ts +1 -1
- package/dist/{renderer-webgpu-DJVQHR70.js → renderer-webgpu-BXU-ZDIp.js} +507 -32
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +2 -1
- package/dist/tilemap.d.ts +14 -3
- package/dist/tilemap.js +84 -10
- package/dist/trace.d.ts +1 -1
- package/dist/trace.js +7 -1
- package/package.json +5 -1
- package/skills/stage/SKILL.md +24 -7
- package/skills/stage/references/subpaths.md +11 -7
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as WebGpuBootstrapResult, Q as RequestWebGpuOptions, X as RendererWebGpu, Z as RendererWebGpuOptions, et as WebGpuCanvasContextLike, nt as requestWebGpuDevice, tt as WebGpuDeviceLike } from "./game-
|
|
1
|
+
import { $ as WebGpuBootstrapResult, Q as RequestWebGpuOptions, X as RendererWebGpu, Z as RendererWebGpuOptions, et as WebGpuCanvasContextLike, nt as requestWebGpuDevice, tt as WebGpuDeviceLike } from "./game-CEa0m4eX.js";
|
|
2
2
|
export { RendererWebGpu, RendererWebGpuOptions, RequestWebGpuOptions, WebGpuBootstrapResult, WebGpuCanvasContextLike, WebGpuDeviceLike, requestWebGpuDevice };
|
package/dist/renderer-webgpu.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-
|
|
1
|
+
export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-BXU-ZDIp.js";
|
package/dist/rig2d.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as BlendMode } from "./anims-ClNi6zZQ.js";
|
|
2
|
+
import { Ct as ImageObject, Pt as SceneHostLike, St as Graphics, ft as Container } from "./game-CEa0m4eX.js";
|
|
2
3
|
export type RigCurveKind = 'linear' | 'step' | 'smoothstep' | 'outBack';
|
|
3
4
|
export interface RigBoneDef {
|
|
4
5
|
name: string;
|
package/dist/tilemap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Pt as SceneHostLike, ft as Container, ut as BlitterObject } from "./game-CEa0m4eX.js";
|
|
2
2
|
/** Pack signed 16-bit chunk coordinates `[-32768..32767]` into a single 32-bit integer Map key (zero string allocation). */
|
|
3
3
|
export declare function packChunkKey(cx: number, cy: number): number;
|
|
4
4
|
export declare function unpackChunkX(key: number): number;
|
|
@@ -142,17 +142,28 @@ export interface MountedChunkedTilemap {
|
|
|
142
142
|
readonly blitters: ReadonlyArray<BlitterObject>;
|
|
143
143
|
/** Update visible chunks around `(viewLeft, viewTop, viewWidth, viewHeight)` in world pixels (O(visibleChunks)). */
|
|
144
144
|
syncViewport(viewLeft: number, viewTop: number, viewWidth: number, viewHeight: number): void;
|
|
145
|
+
/** Convenience alias accepting `Camera25D.getGroundViewportBounds()` (`{ left, top, width, height }`) directly. */
|
|
146
|
+
update(bounds: {
|
|
147
|
+
left: number;
|
|
148
|
+
top: number;
|
|
149
|
+
width: number;
|
|
150
|
+
height: number;
|
|
151
|
+
}): void;
|
|
145
152
|
readonly activeChunkCount: number;
|
|
146
153
|
readonly activeBobCount: number;
|
|
147
154
|
destroy(): void;
|
|
148
155
|
}
|
|
149
156
|
/**
|
|
150
|
-
* Mount a `ChunkedTilemap` + `BakedDualGridAtlas` onto a Stage `Scene
|
|
151
|
-
*
|
|
157
|
+
* Mount a `ChunkedTilemap` + `BakedDualGridAtlas` onto a Stage `Scene`.
|
|
158
|
+
* - On WebGL2 / WebGPU: batches into 1 GPU `BlitterObject` draw call per Dual-Grid layer.
|
|
159
|
+
* - On Canvas2D / pure-Node `createHeadlessStage`: automatically pre-composites all Dual-Grid layers of each
|
|
160
|
+
* `16×16` chunk onto a cached offscreen chunk canvas keyed by `chunk.version` (collapsing ~4,500 per-frame
|
|
161
|
+
* rotated tile `drawImage` calls down to ~12 chunk blits — >10× faster 60 FPS headless video rendering!).
|
|
152
162
|
*/
|
|
153
163
|
export declare function mountChunkedTilemap(scene: SceneHostLike, map: ChunkedTilemap, atlas: BakedDualGridAtlas, opts?: {
|
|
154
164
|
baseColor?: number;
|
|
155
165
|
depth?: number;
|
|
156
166
|
marginChunks?: number;
|
|
157
167
|
trackId?: string;
|
|
168
|
+
chunkCache?: boolean;
|
|
158
169
|
}): MountedChunkedTilemap;
|
package/dist/tilemap.js
CHANGED
|
@@ -471,11 +471,16 @@ function bakeDualGridTileset(textureKey, tileSize, layers, createCanvasFn) {
|
|
|
471
471
|
}
|
|
472
472
|
};
|
|
473
473
|
}
|
|
474
|
+
let nextTilemapMountSeq = 1;
|
|
474
475
|
/**
|
|
475
|
-
* Mount a `ChunkedTilemap` + `BakedDualGridAtlas` onto a Stage `Scene
|
|
476
|
-
*
|
|
476
|
+
* 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!).
|
|
477
481
|
*/
|
|
478
482
|
function mountChunkedTilemap(scene, map, atlas, opts = {}) {
|
|
483
|
+
const mountId = nextTilemapMountSeq++;
|
|
479
484
|
const root = scene.add.container(0, 0);
|
|
480
485
|
if (opts.depth !== void 0) root.setDepth(opts.depth);
|
|
481
486
|
if (opts.trackId) root.trackId = opts.trackId;
|
|
@@ -488,7 +493,9 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
|
|
|
488
493
|
for (let m = 0; m < 16; m++) arr[m] = resolvedTex.get(`${l.id}:${m}`);
|
|
489
494
|
return arr;
|
|
490
495
|
});
|
|
491
|
-
const
|
|
496
|
+
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);
|
|
498
|
+
const blitters = useChunkCache ? [] : layers.map((_, i) => {
|
|
492
499
|
const b = scene.make.blitter(0, 0, atlas.textureKey);
|
|
493
500
|
b.zIndex = i;
|
|
494
501
|
root.add(b);
|
|
@@ -498,12 +505,72 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
|
|
|
498
505
|
const margin = opts.marginChunks ?? 1;
|
|
499
506
|
const ts = map.tileSize;
|
|
500
507
|
const cs = map.chunkSize;
|
|
508
|
+
const chunkPx = cs * ts;
|
|
501
509
|
const halfTs = ts * .5;
|
|
502
510
|
let totalBobs = 0;
|
|
503
|
-
const
|
|
504
|
-
|
|
511
|
+
const evictChunkEntry = (entry) => {
|
|
512
|
+
if (entry.chunkImage) {
|
|
513
|
+
entry.chunkImage.destroy();
|
|
514
|
+
entry.chunkImage = void 0;
|
|
515
|
+
}
|
|
516
|
+
if (entry.chunkTexKey) {
|
|
517
|
+
scene.textures.remove(entry.chunkTexKey);
|
|
518
|
+
entry.chunkTexKey = void 0;
|
|
519
|
+
}
|
|
520
|
+
entry.chunkCanvas = void 0;
|
|
521
|
+
};
|
|
522
|
+
const buildChunkBobs = (cx, cy, version, prev) => {
|
|
505
523
|
const startVx = cx * cs;
|
|
506
524
|
const startVy = cy * cs;
|
|
525
|
+
if (useChunkCache && doc) {
|
|
526
|
+
const chunkCanvas = prev?.chunkCanvas ?? doc.createElement("canvas");
|
|
527
|
+
if (chunkCanvas.width !== chunkPx || chunkCanvas.height !== chunkPx) {
|
|
528
|
+
chunkCanvas.width = chunkPx;
|
|
529
|
+
chunkCanvas.height = chunkPx;
|
|
530
|
+
}
|
|
531
|
+
const cctx = chunkCanvas.getContext("2d");
|
|
532
|
+
let bobCount = 0;
|
|
533
|
+
if (cctx) {
|
|
534
|
+
cctx.clearRect(0, 0, chunkPx, chunkPx);
|
|
535
|
+
cctx.imageSmoothingEnabled = false;
|
|
536
|
+
const srcImg = atlas.canvas;
|
|
537
|
+
for (let ly = 0; ly < cs; ly++) {
|
|
538
|
+
const vy = startVy + ly;
|
|
539
|
+
const dy = ly * ts;
|
|
540
|
+
for (let lx = 0; lx < cs; lx++) {
|
|
541
|
+
const vx = startVx + lx;
|
|
542
|
+
const dx = lx * ts;
|
|
543
|
+
for (let li = 0; li < layers.length; li++) {
|
|
544
|
+
const mask = map.sampleDualGridMask(vx, vy, layers[li].matches);
|
|
545
|
+
if (mask === 0) continue;
|
|
546
|
+
const fr = frameTable[li][mask];
|
|
547
|
+
cctx.drawImage(srcImg, fr.cutX, fr.cutY, fr.cutWidth, fr.cutHeight, dx, dy, ts, ts);
|
|
548
|
+
bobCount++;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const texKey = prev?.chunkTexKey ?? `__stage_tchunk_${mountId}_${cx}_${cy}`;
|
|
554
|
+
let chunkImage = prev?.chunkImage;
|
|
555
|
+
if (!prev?.chunkTexKey || !scene.textures.exists(texKey)) scene.textures.addImage(texKey, chunkCanvas, { filterMode: FilterMode.NEAREST });
|
|
556
|
+
else scene.textures.get(texKey).source[0]?.update();
|
|
557
|
+
if (!chunkImage) {
|
|
558
|
+
chunkImage = scene.make.image(cx * chunkPx - halfTs, cy * chunkPx - halfTs, texKey);
|
|
559
|
+
chunkImage.setOrigin(0, 0);
|
|
560
|
+
root.add(chunkImage);
|
|
561
|
+
}
|
|
562
|
+
chunkImage.visible = bobCount > 0;
|
|
563
|
+
return {
|
|
564
|
+
version,
|
|
565
|
+
bobsByLayer: [],
|
|
566
|
+
bobCount,
|
|
567
|
+
chunkTexKey: texKey,
|
|
568
|
+
chunkCanvas,
|
|
569
|
+
chunkImage
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
const bobsByLayer = layers.map(() => []);
|
|
573
|
+
let bobCount = 0;
|
|
507
574
|
for (let ly = 0; ly < cs; ly++) {
|
|
508
575
|
const vy = startVy + ly;
|
|
509
576
|
const wy = vy * ts - halfTs;
|
|
@@ -520,12 +587,14 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
|
|
|
520
587
|
alpha: 1,
|
|
521
588
|
frame: frameTable[li][mask]
|
|
522
589
|
});
|
|
590
|
+
bobCount++;
|
|
523
591
|
}
|
|
524
592
|
}
|
|
525
593
|
}
|
|
526
594
|
return {
|
|
527
595
|
version,
|
|
528
|
-
bobsByLayer
|
|
596
|
+
bobsByLayer,
|
|
597
|
+
bobCount
|
|
529
598
|
};
|
|
530
599
|
};
|
|
531
600
|
return {
|
|
@@ -537,17 +606,20 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
|
|
|
537
606
|
get activeBobCount() {
|
|
538
607
|
return totalBobs;
|
|
539
608
|
},
|
|
609
|
+
update(bounds) {
|
|
610
|
+
this.syncViewport(bounds.left, bounds.top, bounds.width, bounds.height);
|
|
611
|
+
},
|
|
540
612
|
syncViewport(viewLeft, viewTop, viewWidth, viewHeight) {
|
|
541
|
-
const chunkPx = cs * ts;
|
|
542
613
|
const minCx = Math.floor(viewLeft / chunkPx) - margin;
|
|
543
614
|
const maxCx = Math.floor((viewLeft + viewWidth) / chunkPx) + margin;
|
|
544
615
|
const minCy = Math.floor(viewTop / chunkPx) - margin;
|
|
545
616
|
const maxCy = Math.floor((viewTop + viewHeight) / chunkPx) + margin;
|
|
546
617
|
let changed = false;
|
|
547
|
-
for (const key of mountedChunks.
|
|
618
|
+
for (const [key, entry] of mountedChunks.entries()) {
|
|
548
619
|
const cx = unpackChunkX(key);
|
|
549
620
|
const cy = unpackChunkY(key);
|
|
550
621
|
if (cx < minCx || cx > maxCx || cy < minCy || cy > maxCy) {
|
|
622
|
+
evictChunkEntry(entry);
|
|
551
623
|
mountedChunks.delete(key);
|
|
552
624
|
changed = true;
|
|
553
625
|
}
|
|
@@ -557,12 +629,13 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
|
|
|
557
629
|
const key = packChunkKey(cx, cy);
|
|
558
630
|
const prev = mountedChunks.get(key);
|
|
559
631
|
if (prev && prev.version === ch.version) continue;
|
|
560
|
-
mountedChunks.set(key, buildChunkBobs(cx, cy, ch.version));
|
|
632
|
+
mountedChunks.set(key, buildChunkBobs(cx, cy, ch.version, prev));
|
|
561
633
|
changed = true;
|
|
562
634
|
}
|
|
563
635
|
if (changed) {
|
|
564
636
|
totalBobs = 0;
|
|
565
|
-
for (
|
|
637
|
+
if (useChunkCache) for (const entry of mountedChunks.values()) totalBobs += entry.bobCount;
|
|
638
|
+
else for (let li = 0; li < layers.length; li++) {
|
|
566
639
|
const dst = blitters[li].children.list;
|
|
567
640
|
dst.length = 0;
|
|
568
641
|
for (const entry of mountedChunks.values()) {
|
|
@@ -574,6 +647,7 @@ function mountChunkedTilemap(scene, map, atlas, opts = {}) {
|
|
|
574
647
|
}
|
|
575
648
|
},
|
|
576
649
|
destroy() {
|
|
650
|
+
for (const entry of mountedChunks.values()) evictChunkEntry(entry);
|
|
577
651
|
mountedChunks.clear();
|
|
578
652
|
totalBobs = 0;
|
|
579
653
|
root.destroy();
|
package/dist/trace.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { B as SceneDigestSurfaceEntry, F as SceneDigestEngineSandbox, H as SceneDigestSurfaces, I as SceneDigestNode, L as SceneDigestOptions, N as SceneDigest, P as SceneDigestActiveFocus, R as SceneDigestOverlayStats, U as buildSceneDigest, V as SceneDigestSurfaceSource, W as sanitizeTrackToken, z as SceneDigestSandbox } from "./game-
|
|
1
|
+
import { B as SceneDigestSurfaceEntry, F as SceneDigestEngineSandbox, H as SceneDigestSurfaces, I as SceneDigestNode, L as SceneDigestOptions, N as SceneDigest, P as SceneDigestActiveFocus, R as SceneDigestOverlayStats, U as buildSceneDigest, V as SceneDigestSurfaceSource, W as sanitizeTrackToken, z as SceneDigestSandbox } from "./game-CEa0m4eX.js";
|
|
2
2
|
export { SceneDigest, SceneDigestActiveFocus, SceneDigestEngineSandbox, SceneDigestNode, SceneDigestOptions, SceneDigestOverlayStats, SceneDigestSandbox, SceneDigestSurfaceEntry, SceneDigestSurfaceSource, SceneDigestSurfaces, buildSceneDigest, sanitizeTrackToken };
|
package/dist/trace.js
CHANGED
|
@@ -185,6 +185,10 @@ function buildSceneDigest(scene, opts = {}) {
|
|
|
185
185
|
const trackId = sanitizeTrackToken(o.trackId);
|
|
186
186
|
if (!trackId || !seenTrackIds.has(trackId)) {
|
|
187
187
|
if (trackId) seenTrackIds.add(trackId);
|
|
188
|
+
const isSprite = o.type === "Sprite";
|
|
189
|
+
const isImageLike = isSprite || o.type === "Image";
|
|
190
|
+
const rawAnim = isSprite ? o.currentAnimKey : null;
|
|
191
|
+
const rawFrame = isImageLike ? String(o.frame?.name ?? "") : null;
|
|
188
192
|
pushNode({
|
|
189
193
|
trackId,
|
|
190
194
|
role: sanitizeTrackToken(o.role, 32),
|
|
@@ -196,7 +200,9 @@ function buildSceneDigest(scene, opts = {}) {
|
|
|
196
200
|
zIndex: o.zIndex || 0,
|
|
197
201
|
depth: o.depth || 0,
|
|
198
202
|
alpha: +alpha.toFixed(2),
|
|
199
|
-
bounds: roundBounds(wx - o.displayOriginX * Math.abs(o.scaleX), wy - o.displayOriginY * Math.abs(o.scaleY), o.displayWidth, o.displayHeight)
|
|
203
|
+
bounds: roundBounds(wx - o.displayOriginX * Math.abs(o.scaleX), wy - o.displayOriginY * Math.abs(o.scaleY), o.displayWidth, o.displayHeight),
|
|
204
|
+
...isSprite ? { anim: sanitizeTrackToken(rawAnim) } : {},
|
|
205
|
+
...isImageLike && rawFrame && rawFrame !== "__BASE" ? { frame: sanitizeTrackToken(rawFrame) } : {}
|
|
200
206
|
});
|
|
201
207
|
}
|
|
202
208
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holtjs/stage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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.",
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"types": "./dist/index.d.ts",
|
|
50
50
|
"default": "./dist/index.js"
|
|
51
51
|
},
|
|
52
|
+
"./anims": {
|
|
53
|
+
"types": "./dist/anims.d.ts",
|
|
54
|
+
"default": "./dist/anims.js"
|
|
55
|
+
},
|
|
52
56
|
"./flex": {
|
|
53
57
|
"types": "./dist/flex.d.ts",
|
|
54
58
|
"default": "./dist/flex.js"
|
package/skills/stage/SKILL.md
CHANGED
|
@@ -5,11 +5,11 @@ description: Build zero-dependency WebGPU/WebGL2/Canvas2D 2D & 2.5D games, GPU S
|
|
|
5
5
|
|
|
6
6
|
# Building 2D/2.5D Games, WebGPU UI & 60 FPS Video with `@holtjs/stage`
|
|
7
7
|
|
|
8
|
-
Use this skill whenever creating or modifying a browser 2D/2.5D game, WebGPU/WebGL2 canvas UI, survival sandbox, automated `InputTimeline` test, or pure-Node headless image/storyboard/60 FPS video pipeline built on `@holtjs/stage` (`v0.
|
|
8
|
+
Use this skill whenever creating or modifying a browser 2D/2.5D game, WebGPU/WebGL2 canvas UI, survival sandbox, automated `InputTimeline` test, or pure-Node headless image/storyboard/60 FPS video pipeline built on `@holtjs/stage` (`v0.8.0`, 21 subpaths).
|
|
9
9
|
|
|
10
|
-
For the exhaustive exported symbol list across all
|
|
10
|
+
For the exhaustive exported symbol list across all 21 subpaths, see [references/subpaths.md](references/subpaths.md).
|
|
11
11
|
|
|
12
|
-
## 1. Install & Choose from the
|
|
12
|
+
## 1. Install & Choose from the 21 Subpaths
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
pnpm add @holtjs/stage
|
|
@@ -19,7 +19,8 @@ pnpm add @holtjs/stage
|
|
|
19
19
|
|
|
20
20
|
| Need | Import path | Works in Node/Worker (no DOM)? |
|
|
21
21
|
|---|---|---|
|
|
22
|
-
| Core engine (`Game`, `Scene`, `
|
|
22
|
+
| Core engine (`Game`, `Scene`, `SpriteObject`, `AnimationManager`, `ShapeBatch`, `InstancedBatch`, `Panel`, `Graphics`, `Container`, `Text`) | `@holtjs/stage` | Browser (Headless via `./headless`) |
|
|
23
|
+
| Sprite-sheet & 4/8-directional atlas animation (`AnimationManager`, `createFromAtlas`) | `@holtjs/stage/anims` | Yes |
|
|
23
24
|
| Native WebGPU WGSL batch & analytical SDF renderer (`RendererWebGpu`, `requestWebGpuDevice`) | `@holtjs/stage/webgpu` | Browser WebGPU |
|
|
24
25
|
| `StageKernel` plugins, `ActionMap`, semantic `createInputTimeline`, recorder/replay | `@holtjs/stage/kernel` | Yes |
|
|
25
26
|
| Zero-browser 60 FPS Node PNG, storyboard & stereo video (`createHeadlessStage`) | `@holtjs/stage/headless` | Yes (`@napi-rs/canvas`) |
|
|
@@ -149,7 +150,24 @@ const mountedTerrain = mountChunkedTilemap(scene, tilemap, dgAtlas);
|
|
|
149
150
|
mountedTerrain.container.removeFromDisplayList();
|
|
150
151
|
stage25.groundWorld.add(mountedTerrain.container);
|
|
151
152
|
|
|
152
|
-
//
|
|
153
|
+
// 3A. Baked 3D->2D Atlas Sprite (`@holtjs/craft/three` / `textures.addAtlas` + `scene.anims.createFromAtlas`):
|
|
154
|
+
// Automatically aligns trimmed per-frame `ax/ay` pivots, transforms `hand` sockets, preserves walk phase across turns, & fires `footstep` events!
|
|
155
|
+
scene.textures.addAtlas('actors', bakedCanvas, bakedAtlasJson);
|
|
156
|
+
scene.anims.createFromAtlas('actors', {
|
|
157
|
+
clips: {
|
|
158
|
+
walk: { frameRate: 10, events: { 1: 'footstep', 4: 'footstep' } },
|
|
159
|
+
attack: { frameRate: 14, repeat: 0, events: { 2: 'hit' } },
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const survivor = scene.make.sprite(0, 0, 'actors', 'chars/survivor/idle/d0/f0');
|
|
163
|
+
survivor.trackId = 'actor.survivor';
|
|
164
|
+
survivor.onAnimEvent((ev) => { if (ev === 'footstep') playStepSfx(); });
|
|
165
|
+
stage25.registerBillboard(survivor, 0, 0);
|
|
166
|
+
// Inside update(): survivor.playDirectional('survivor/walk', Math.atan2(vy, vx), { cameraYaw: cam25.yaw });
|
|
167
|
+
// Attach held weapon with exact 3D->2D projected shaft angle, O(2) blade mirroring & front/back zIndex occlusion:
|
|
168
|
+
// survivor.syncAttachment(axeSprite, 'hand', { restAngle: -Math.PI / 2, mirrorBlade: true });
|
|
169
|
+
|
|
170
|
+
// 3B. Or 2D Cutout Skeletal Rig: O(1) equipment swap + 2-layer bone-masked overlay animation
|
|
153
171
|
const rig = new Rig2DInstance(heroSkeleton);
|
|
154
172
|
rig.play('walk');
|
|
155
173
|
rig.setAttachment('tool', 'axe_iron'); // swaps weapon slot in O(1) without resetting walk phase!
|
|
@@ -167,8 +185,7 @@ if (scene.game.kernel.actions.justPressed('rotateCW')) cam25.rotateSteps(1);
|
|
|
167
185
|
stage25.update(deltaMs);
|
|
168
186
|
mountedTerrain.update(cam25.getGroundViewportBounds());
|
|
169
187
|
heroView.update(deltaMs);
|
|
170
|
-
const
|
|
171
|
-
lighting.update(env, scene.clock.simTimeMs, (wx, wy, wz, out) => cam25.worldToScreen(wx, wy, wz, out));
|
|
188
|
+
lighting.update(deltaMs, (wx, wy, wz, out) => { const p = cam25.worldToScreen(wx, wy, wz); out.x = p.x; out.y = p.y; out.scale = p.scale; });
|
|
172
189
|
|
|
173
190
|
// 5. Compact Binary World Delta Save (only modified tiles + inventories + workstations)
|
|
174
191
|
const deltaBytes = encodeWorldDeltaBytes(captureWorldDelta({ seed: 1337, simTimeMs: 42_000, tilemap }));
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
# `@holtjs/stage` Subpath API Quick Reference
|
|
2
2
|
|
|
3
|
-
All symbols verified against `src/*.ts` (`@holtjs/stage@0.
|
|
3
|
+
All symbols verified against `src/*.ts` (`@holtjs/stage@0.8.0`, 21 subpaths).
|
|
4
4
|
|
|
5
|
-
## `@holtjs/stage` (~
|
|
6
|
-
- **Bootstrap & Lifecycle**: `Stage` / `Stage2D` (namespaces), `AUTO`, `WEBGPU`, `WEBGL`, `CANVAS`, `Scale` (`NONE`, `FIT`, `RESIZE`), `Scenes`, `Game` (`.stepSimOnly()`, `.kernel`), `Scene` (`.update()` simulation + `.preRender()` presentation), `SceneManager`, `ScaleManager` (`.fitToContainer()`), `GameLoop`, `EngineClock`, `LoaderPlugin
|
|
7
|
-
- **Display Graph**: `DisplayList`, `DisplayObject
|
|
8
|
-
- **Renderers & GPU Batchers**: `RendererWebGpu`, `requestWebGpuDevice`, `RendererGl` (`.createRenderTarget()`, `.renderToTarget(rt, content, cam?)`, `.restoreState()`), `StageRenderTarget` (`.camera`, `.readPixels()`), `Renderer2D
|
|
5
|
+
## `@holtjs/stage` (~68.0 kB gz · Core Engine Barrel)
|
|
6
|
+
- **Bootstrap & Lifecycle**: `Stage` / `Stage2D` (namespaces), `AUTO`, `WEBGPU`, `WEBGL`, `CANVAS`, `Scale` (`NONE`, `FIT`, `RESIZE`), `Scenes`, `Game` (`.stepSimOnly()`, `.kernel`, `.anims`), `Scene` (`.update()` simulation + `.preRender()` presentation, `.anims`), `SceneManager`, `ScaleManager` (`.fitToContainer()`), `GameLoop`, `EngineClock`, `LoaderPlugin` (`.atlas()`), `JsonCache`, `GameObjectFactory` (`scene.add.sprite`, `shapeBatch`, `instancedBatch`, `customPass`, `panel`, `blitter`, etc.), `AnimationManager` (`.create()`, `.createFromAtlas()`, `.generateFrameNames()`, `.generateFrameNumbers()`)
|
|
7
|
+
- **Display Graph**: `DisplayList`, `DisplayObject` (reactive `.zIndex`), `Container`, `ImageObject` (`.useFramePivot()`, `.getAnchor(name, space?)`, `.getAnchorPose(name, space?)`, `.syncAttachment(child, name, opts?)`), `SpriteObject` (`.play()`, `.playDirectional()`, `.onAnimEvent()`, `.pause()`, `.resume()`, `.stop()`), `NineSliceObject`, `TileSpriteObject`, `RectangleObject`, `PanelObject`, `MsdfIconObject`, `TextObject`, `Graphics` (GPU SDF fast-path + Canvas2D `Path2D` cache), `BlitterObject`, `InstancedBatchObject`, `ShapeBatchObject` (zero-texture SoA analytical SDF shapes), `CustomPassObject` (`restoreState: true` default)
|
|
8
|
+
- **Renderers & GPU Batchers**: `RendererWebGpu`, `requestWebGpuDevice`, `RendererGl` (`.createRenderTarget()`, `.renderToTarget(rt, content, cam?)`, `.restoreState()`), `StageRenderTarget` (`.camera`, `.readPixels()`), `Renderer2D` (4-corner frustum culling + sprite tint LRU cache), `SdfPanelBatcher`, `MsdfIconBatcher`, `PixelAaBatcher`, `Camera` (`.configureHiDpi()`, `.setBounds()`, `.clearBounds()`, `.startFollow()`, `.stopFollow()`, `.screenToWorld()`, `.worldToScreen()`, `.logicalToWorld()`, `.worldToLogical()`, `.clientToWorld()`), `Texture` (`.atlasYaw`), `CanvasTexture`, `TextureSource`, `Frame` (`.setPivot()`, `.setPixelPivot()`, `.setAnchor()`, `.getAnchor()`), `TextureManager` (`.exists()`, `.addAtlas()`, `.addCanvas()`, `.get()`)
|
|
9
9
|
- **Kernel & Input**: `StageKernel`, `ActionMap`, `createInputTimeline`, `createInputRecorder`, `createInputReplay`, `EventEmitter`, `Pointer`, `KeyboardPlugin` (`.isDown()`, `.justPressed()`, `.justReleased()`, `.injectKey()`), `InputPlugin`
|
|
10
10
|
- **Math & Color**: `BlendModes` (`NORMAL`, `ADD`, `MULTIPLY`, `SCREEN`), `TintModes`, `FilterMode`, `WHITE_RGB`, `BLACK_RGB`, `HEX_MASK`, `createMatrix2D`, `parseColor`, `rgbToCss`, `packColorAbgr`
|
|
11
11
|
- **Bundled UI/Observability Re-exports**: `computeFlexLayout`, `computeWrapLayout`, `resolvePadding`, `Easings`, `TweenManager`, `VirtualJoystick`, `clampJoystickOrigin`, `computeJoystickVector`, `isInJoystickZone`, `pullJoystickOrigin`, `quantizeJoystickDpad`, `SURFACE_BAND`, `createSurfaceTree`, `resolveSurfacePriority`, `surfacePriorityToDomZ`, `computeSurfaceDomZ`, `buildSceneDigest`, `sanitizeTrackToken`
|
|
12
12
|
|
|
13
|
-
## `@holtjs/stage/
|
|
13
|
+
## `@holtjs/stage/anims` (~2.6 kB gz · zero DOM)
|
|
14
|
+
- `AnimationManager`: `.create(cfg)`, `.createFromAtlas(textureKey, opts?)`, `.generateFrameNames(key, cfg?)`, `.generateFrameNumbers(key, cfg?)`, `.exists(key)`, `.get(key)`, `.getDirectionalGroup(baseKey)`, `.listKeys()`, `.listDirectionalGroups()`
|
|
15
|
+
- Types: `AnimationFrameInput`, `CompiledAnimationFrame`, `AnimationConfig`, `StageAnimation`, `GenerateFrameNamesConfig`, `GenerateFrameNumbersConfig`, `AtlasClipRule`, `AtlasAutoAnimOptions`, `DirectionalAnimGroup`
|
|
16
|
+
|
|
17
|
+
## `@holtjs/stage/webgpu` (~15.4 kB gz · Native WebGPU Renderer)
|
|
14
18
|
- `RendererWebGpu`: WGSL textured quad/polygon batcher + WGSL analytical 4-corner rounded/pixel-stepped SDF `PanelObject` pipelines across `NORMAL`, `ADD`, `MULTIPLY`, `SCREEN` blends
|
|
15
19
|
- `requestWebGpuDevice(canvas, opts?)` -> `Promise<WebGpuBootstrapResult | null>`
|
|
16
20
|
- Types: `WebGpuDeviceLike`, `WebGpuCanvasContextLike`, `RendererWebGpuOptions`, `RequestWebGpuOptions`, `WebGpuBootstrapResult`
|
|
@@ -23,7 +27,7 @@ All symbols verified against `src/*.ts` (`@holtjs/stage@0.6.0`, 20 subpaths).
|
|
|
23
27
|
- Types: `StagePlugin`, `InputProvider`, `StageInputEvent`, `InputTargetSpec`, `TimelineClickOptions`, `TimelineDragOptions`, `TimelineKeyOptions`, `InputTimelineOptions`, `InputTimelinePlugin`, `InputRecorderPlugin`, `RecordedInputEntry`
|
|
24
28
|
|
|
25
29
|
## `@holtjs/stage/headless` (~38.6 kB gz · pure Node with `@napi-rs/canvas`)
|
|
26
|
-
- `createHeadlessStage(opts)`: `.step()`, `.stepToMs()`, `.stepToFrame()`, `.fastForward(frames)`, `.pointerDown/Move/Up()`, `.keyDown/Up()`, `.toRgba()`, `.toPng()`, `.digest()`, `.recordFrames()`
|
|
30
|
+
- `createHeadlessStage(opts)`: `.step()`, `.stepToMs()`, `.stepToFrame()`, `.fastForward(frames)`, `.pointerDown/Move/Up()`, `.keyDown/Up()`, `.toRgba()`, `.toRgbaInto(out)`, `.toPng()`, `.digest()`, `.recordFrames({ ..., reuseFrameBuffer? })`
|
|
27
31
|
- `renderStoryboard(stage, opts)` -> `{ png, width, height, digests }`
|
|
28
32
|
- `createAudioTimeline(opts?)`: `.addAtMs()`, `.addAtFrame()`, `.toStereoPcm16()`, `.toWav()`
|
|
29
33
|
- Types: `HeadlessCanvasLike`, `CreateHeadlessCanvas`, `HeadlessStageOptions`, `HeadlessRecordedFrame`, `RecordFramesOptions`, `HeadlessStage`, `StoryboardOptions`, `StoryboardResult`, `AudioCueOptions`, `AudioTimelineOptions`, `AudioTimeline`
|