@holtjs/stage 0.14.0 → 0.16.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 +25 -0
- package/README.md +1 -1
- package/dist/ecs.d.ts +18 -0
- package/dist/ecs.js +174 -0
- package/dist/{game-BF1ZbJRC.js → game-CFxS641c.js} +56 -8
- package/dist/{game-rKghsNlA.d.ts → game-Dxh9e0Hv.d.ts} +151 -18
- package/dist/headless.d.ts +86 -19
- package/dist/headless.js +1183 -34
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -4
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +166 -1
- package/dist/lighting.d.ts +4 -2
- package/dist/lighting.js +17 -11
- package/dist/particles.d.ts +75 -0
- package/dist/particles.js +127 -1
- package/dist/projection.d.ts +3 -1
- package/dist/projection.js +7 -0
- package/dist/{renderer-webgpu-CnIevdNP.js → renderer-webgpu-q4vdE3kA.js} +73 -1
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +1 -1
- package/dist/tilemap.d.ts +2 -2
- package/dist/tilemap.js +228 -69
- package/dist/trace.d.ts +1 -1
- package/dist/world.d.ts +1 -1
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/skills/stage/SKILL.md +1 -1
- package/skills/stage/references/subpaths.md +14 -13
package/dist/headless.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Lt as SceneDigestOptions, Nt as SceneDigest, an as HeadlessWebGpuOptions, cn as openDawnWebGpu, f as SceneInput, in as HeadlessWebGpuHandle, j as StagePlugin, ln as openWgpuNativeFfi, n as EngineClockSnapshot, on as OpenDawnWebGpuOptions, r as Game, rn as HeadlessWebGpuBackend, sn as OpenWgpuNativeFfiOptions, tn as WebGpuDeviceLike, u as Scene, un as requestHeadlessWebGpu } from "./game-Dxh9e0Hv.js";
|
|
2
2
|
/** Minimal Canvas2D surface compatible with `@napi-rs/canvas`, `node-canvas`, and browser `<canvas>`. */
|
|
3
3
|
export interface HeadlessCanvasLike {
|
|
4
4
|
width: number;
|
|
5
5
|
height: number;
|
|
6
6
|
getContext(contextId: '2d', options?: unknown): CanvasRenderingContext2D | null;
|
|
7
|
-
toBuffer?(mimeType:
|
|
7
|
+
toBuffer?(mimeType: string, quality?: number): Uint8Array;
|
|
8
8
|
}
|
|
9
9
|
export type CreateHeadlessCanvas = (width: number, height: number) => HeadlessCanvasLike;
|
|
10
10
|
export type HeadlessStageBackend = HeadlessWebGpuBackend | 'webgpu' | 'webgl' | 'canvas2d';
|
|
@@ -198,30 +198,33 @@ export interface AudioTimeline {
|
|
|
198
198
|
* chiptune cues with 60 FPS headless video renders. Exports ready-to-mux stereo 16-bit `.wav` bytes.
|
|
199
199
|
*/
|
|
200
200
|
export declare function createAudioTimeline(options?: AudioTimelineOptions): AudioTimeline;
|
|
201
|
+
export type FfmpegInputFormat = 'auto' | 'rawvideo' | 'mjpeg' | 'png';
|
|
201
202
|
export interface FfmpegRawVideoArgsOptions {
|
|
202
203
|
readonly width: number;
|
|
203
204
|
readonly height: number;
|
|
204
205
|
readonly fps: number;
|
|
205
206
|
readonly outputPath: string;
|
|
207
|
+
/** Input pipe format (`'rawvideo'` default for `buildFfmpegRawVideoArgs`, `'mjpeg'` or `'png'` for `image2pipe`). */
|
|
208
|
+
readonly inputFormat?: Exclude<FfmpegInputFormat, 'auto'>;
|
|
206
209
|
/** Optional path to a `.wav` audio file (e.g. written from `AudioTimeline.toWav()`). */
|
|
207
210
|
readonly audioWavPath?: string;
|
|
208
|
-
/** Video codec (default `'libx264'`). */
|
|
211
|
+
/** Video codec (default `'libx264'`, or `'libvpx-vp9'` when `outputPath` ends with `.webm`). */
|
|
209
212
|
readonly videoCodec?: string;
|
|
210
|
-
/** Encoder preset (default `'veryfast'`). */
|
|
213
|
+
/** Encoder preset (default `'veryfast'` for x264/x265). */
|
|
211
214
|
readonly preset?: string;
|
|
212
|
-
/** Constant Rate Factor quality `0..51` (default `19`). */
|
|
215
|
+
/** Constant Rate Factor quality `0..51` (default `19`, or `28` for VP9). */
|
|
213
216
|
readonly crf?: number;
|
|
214
217
|
/** Output pixel format for universal player compatibility (default `'yuv420p'`). */
|
|
215
218
|
readonly outputPixelFormat?: string;
|
|
216
|
-
/** Audio codec when `audioWavPath` is supplied (default `'aac'`). */
|
|
219
|
+
/** Audio codec when `audioWavPath` is supplied (default `'aac'`, or `'libopus'` for `.webm`). */
|
|
217
220
|
readonly audioCodec?: string;
|
|
218
221
|
/** Audio bitrate when `audioWavPath` is supplied (default `'160k'`). */
|
|
219
222
|
readonly audioBitrate?: string;
|
|
220
|
-
/** Extra CLI flags appended before
|
|
223
|
+
/** Extra CLI flags appended before `<outputPath>`. */
|
|
221
224
|
readonly extraArgs?: readonly string[];
|
|
222
225
|
}
|
|
223
226
|
export interface EncodeVideoWithFfmpegOptions {
|
|
224
|
-
/** Destination video file path (e.g. `'out.mp4'`). */
|
|
227
|
+
/** Destination video file path (e.g. `'out.mp4'` or `'out.webm'`). */
|
|
225
228
|
readonly outputPath: string;
|
|
226
229
|
/** Total frames to render (`frames` or `durationMs` required). */
|
|
227
230
|
readonly frames?: number;
|
|
@@ -229,26 +232,36 @@ export interface EncodeVideoWithFfmpegOptions {
|
|
|
229
232
|
readonly durationMs?: number;
|
|
230
233
|
/** Optional `AudioTimeline`, stereo `.wav` `Uint8Array`, or `.wav` file path muxed into the output video. */
|
|
231
234
|
readonly audio?: AudioTimeline | Uint8Array | string;
|
|
232
|
-
/** Custom `ffmpeg` executable path (
|
|
235
|
+
/** Custom `ffmpeg` executable path (auto-discovers system `ffmpeg` or Playwright's cached `ffmpeg` when omitted). */
|
|
233
236
|
readonly ffmpegPath?: string;
|
|
234
|
-
/**
|
|
237
|
+
/**
|
|
238
|
+
* Frame pipe format (`default = 'auto'`):
|
|
239
|
+
* - `'auto'`: uses zero-copy `'rawvideo'` when supported by `ffmpeg`, falling back automatically to `'mjpeg'` on trimmed Playwright `ffmpeg` builds.
|
|
240
|
+
* - `'rawvideo'`: streams uncompressed `RGBA8888` (`-f rawvideo -pix_fmt rgba`).
|
|
241
|
+
* - `'mjpeg'`: encodes each frame as JPEG (`-f image2pipe -vcodec mjpeg`) for stripped `ffmpeg` builds.
|
|
242
|
+
* - `'png'`: encodes each frame as PNG (`-f image2pipe -vcodec png`).
|
|
243
|
+
*/
|
|
244
|
+
readonly inputFormat?: FfmpegInputFormat;
|
|
245
|
+
/** JPEG quality `1..100` when `inputFormat` resolves to `'mjpeg'` (`default = 90`). */
|
|
246
|
+
readonly jpegQuality?: number;
|
|
247
|
+
/** Video codec (auto-selects `'libx264'` or `'libvpx-vp9'` based on container and `ffmpeg` capabilities when omitted). */
|
|
235
248
|
readonly videoCodec?: string;
|
|
236
|
-
/** Encoder preset (default `'veryfast'`). */
|
|
249
|
+
/** Encoder preset (default `'veryfast'` on x264/x265). */
|
|
237
250
|
readonly preset?: string;
|
|
238
|
-
/** Constant Rate Factor quality `0..51` (default `19`). */
|
|
251
|
+
/** Constant Rate Factor quality `0..51` (default `19` for H.264, `28` for VP9). */
|
|
239
252
|
readonly crf?: number;
|
|
240
253
|
/** Output pixel format (default `'yuv420p'`). */
|
|
241
254
|
readonly outputPixelFormat?: string;
|
|
242
|
-
/** Audio codec when `audio` is provided (default `'aac'`). */
|
|
255
|
+
/** Audio codec when `audio` is provided (default `'aac'` for MP4, `'libopus'` for WebM). */
|
|
243
256
|
readonly audioCodec?: string;
|
|
244
257
|
/** Audio bitrate when `audio` is provided (default `'160k'`). */
|
|
245
258
|
readonly audioBitrate?: string;
|
|
246
|
-
/** Extra CLI flags appended before
|
|
259
|
+
/** Extra CLI flags appended before `<outputPath>`. */
|
|
247
260
|
readonly extraArgs?: readonly string[];
|
|
248
261
|
/** Capture a zero-PII `SceneDigest` every N frames (`0` = disabled; default `0`). */
|
|
249
262
|
readonly digestEvery?: number;
|
|
250
263
|
readonly digestOptions?: SceneDigestOptions;
|
|
251
|
-
/** Optional per-frame hook invoked after stepping each frame before piping
|
|
264
|
+
/** Optional per-frame hook invoked after stepping each frame before piping to `ffmpeg`. */
|
|
252
265
|
readonly onFrame?: (frame: HeadlessRecordedFrame) => void | Promise<void>;
|
|
253
266
|
}
|
|
254
267
|
export interface EncodeVideoResult {
|
|
@@ -260,15 +273,69 @@ export interface EncodeVideoResult {
|
|
|
260
273
|
readonly durationMs: number;
|
|
261
274
|
readonly clock: EngineClockSnapshot;
|
|
262
275
|
readonly digests: SceneDigest[];
|
|
276
|
+
readonly inputFormat: Exclude<FfmpegInputFormat, 'auto'>;
|
|
277
|
+
readonly videoCodec: string;
|
|
263
278
|
}
|
|
264
279
|
/**
|
|
265
|
-
* Build deterministic `ffmpeg` CLI arguments that consume
|
|
266
|
-
*
|
|
280
|
+
* Build deterministic `ffmpeg` CLI arguments that consume `rawvideo` (`RGBA8888`), `mjpeg`, or `png` frames from `stdin` (`pipe:0`),
|
|
281
|
+
* adapting container flags automatically for MP4 (`libx264` + `+faststart`) and WebM (`libvpx-vp9`).
|
|
267
282
|
*/
|
|
268
283
|
export declare function buildFfmpegRawVideoArgs(options: FfmpegRawVideoArgsOptions): string[];
|
|
269
284
|
/**
|
|
270
|
-
* Step a `HeadlessStage` in Node.js or Bun and stream
|
|
271
|
-
*
|
|
285
|
+
* Step a `HeadlessStage` in Node.js or Bun and stream frames into `ffmpeg` stdin with backpressure handling.
|
|
286
|
+
* Automatically uses zero-copy `rawvideo` (`RGBA8888`) on full `ffmpeg` builds and falls back seamlessly to
|
|
287
|
+
* `image2pipe` (`mjpeg` + `libvpx-vp9` WebM) when only Playwright's trimmed `ffmpeg` binary is available.
|
|
272
288
|
*/
|
|
273
289
|
export declare function encodeVideoWithFfmpeg(stage: HeadlessStage, options: EncodeVideoWithFfmpegOptions): Promise<EncodeVideoResult>;
|
|
290
|
+
export interface MetricSummaryStats {
|
|
291
|
+
readonly min: number;
|
|
292
|
+
readonly max: number;
|
|
293
|
+
readonly mean: number;
|
|
294
|
+
readonly p50: number;
|
|
295
|
+
readonly p95: number;
|
|
296
|
+
readonly sum: number;
|
|
297
|
+
}
|
|
298
|
+
export interface HeadlessRolloutRunResult<TMetrics extends Record<string, number>> {
|
|
299
|
+
readonly runIndex: number;
|
|
300
|
+
readonly seed: number;
|
|
301
|
+
readonly ticks: number;
|
|
302
|
+
readonly simTimeMs: number;
|
|
303
|
+
readonly metrics: TMetrics;
|
|
304
|
+
}
|
|
305
|
+
export interface HeadlessRolloutOptions<TMetrics extends Record<string, number>, TScene extends Scene = Scene> {
|
|
306
|
+
/** Number of independent simulation rollouts (`default = seeds?.length ?? 16`). */
|
|
307
|
+
readonly runs?: number;
|
|
308
|
+
/** Optional explicit seed list; defaults to `baseSeed + runIndex`. */
|
|
309
|
+
readonly seeds?: readonly number[];
|
|
310
|
+
/** Starting integer seed when `seeds` is omitted (`default = 1`). */
|
|
311
|
+
readonly baseSeed?: number;
|
|
312
|
+
/** Total deterministic simulation ticks executed per run (`default = 1800` = 30s @ 60 Hz). */
|
|
313
|
+
readonly ticksPerRun?: number;
|
|
314
|
+
/** Simulation tick frequency in Hz (`default = 60`). */
|
|
315
|
+
readonly fps?: number;
|
|
316
|
+
/** Logical viewport width (`default = 1280`). */
|
|
317
|
+
readonly width?: number;
|
|
318
|
+
/** Logical viewport height (`default = 720`). */
|
|
319
|
+
readonly height?: number;
|
|
320
|
+
/** Construct a fresh `Scene` instance for `(runIndex, seed)`. */
|
|
321
|
+
readonly createScene: (runIndex: number, seed: number) => TScene;
|
|
322
|
+
/** Optional per-tick bot/policy hook `(stage, tick, runIndex, seed) => boolean | void` (return `false` for early stop). */
|
|
323
|
+
readonly onTick?: (stage: HeadlessStage, tick: number, runIndex: number, seed: number) => boolean | void;
|
|
324
|
+
/** Extract numeric telemetry metrics `{ survived: 1, kills: 14, ... }` at the end of each rollout. */
|
|
325
|
+
readonly extractMetrics: (scene: TScene, clock: EngineClockSnapshot, runIndex: number, seed: number) => TMetrics;
|
|
326
|
+
}
|
|
327
|
+
export interface HeadlessRolloutReport<TMetrics extends Record<string, number>> {
|
|
328
|
+
readonly runsCompleted: number;
|
|
329
|
+
readonly totalTicks: number;
|
|
330
|
+
readonly elapsedMs: number;
|
|
331
|
+
readonly ticksPerSecond: number;
|
|
332
|
+
readonly summary: { readonly [K in keyof TMetrics]: MetricSummaryStats; };
|
|
333
|
+
readonly results: ReadonlyArray<HeadlessRolloutRunResult<TMetrics>>;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Execute `N` deterministic zero-rasterization headless game rollouts in a single Node.js, Bun, or Deno process
|
|
337
|
+
* (`stepSimOnly` / `fastForward` with a zero-overhead stub canvas — zero pixel rasterization or GPU driver required!),
|
|
338
|
+
* returning per-run results and aggregated `min / max / mean / p50 / p95 / sum` balance statistics.
|
|
339
|
+
*/
|
|
340
|
+
export declare function runHeadlessRollouts<TMetrics extends Record<string, number>, TScene extends Scene = Scene>(options: HeadlessRolloutOptions<TMetrics, TScene>): HeadlessRolloutReport<TMetrics>;
|
|
274
341
|
export { type HeadlessWebGpuBackend, type HeadlessWebGpuHandle, type HeadlessWebGpuOptions, type OpenDawnWebGpuOptions, type OpenWgpuNativeFfiOptions, openDawnWebGpu, openWgpuNativeFfi, requestHeadlessWebGpu };
|