@holtjs/stage 0.10.2 → 0.11.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 CHANGED
@@ -6,6 +6,35 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.11.0] - 2026-12-04
10
+
11
+ ### Added
12
+ - **Deterministic `EngineClock` Generator Coroutines (`ScriptScheduler`, `scene.script(function* (co) { ... })`, `./coroutine` & `./kernel`)**:
13
+ - Added heap-backed generator gameplay coroutines (`co.wait`, `co.waitMs` with sub-frame remainder carryover for zero quantization drift, `co.frames`, `co.until`, `co.tween`, `co.all`, `co.race`), scene-wide & per-coroutine `timeScale` hitstop pausing, `HeadlessStage.fastForward()` parity, and automatic `.return()` `finally`-block teardown on `cancel()` or `owner.onDispose()`.
14
+ - **Nested Declarative Flex Tree Flattener & Batched UI Mounter (`flattenFlexTree`, `mountFlexUi`, `./flex`)**:
15
+ - Solves arbitrarily nested `row`/`col` declarative UI trees (2-pass bottom-up intrinsic measurement + top-down stretch/grow propagation) and flattens all panel backgrounds/borders into a single GPU-instanced `ShapeBatchObject` alongside pooled labels, icons, `trackId` regions, `hitTest`, `dispatchClick`, and single-call `relayout()`.
16
+ - **Relational `SoaWorld` Queries, Zero-Byte Tags & Stateless Per-Frame Event Tables (`defineTag`, `defineEvent`, `world.select` / `world.query`, `world.events`, `world.clearEvents`, `./ecs`)**:
17
+ - Added zero-column-byte boolean tags (`defineTag`), strongly typed relational `world.select({ read, write, with, without })` / `world.query({...})` cursors (`each`, `collectSlots`, `count`), and dense SoA per-frame `EventTable`s (`emit`, `pushSlot`, `each`, `clearEvents`) for decoupled stateless system communication.
18
+ - **Stateless Immediate-Mode `DrawStream` (`DrawStreamObject`, `scene.drawStream`, `scene.add.drawStream`, `.`)**:
19
+ - Added auto-resetting, auto-growing immediate-mode sprite batch streams (`stream.sprite(...)`, `stream.writeBulk(...)`, optional Ciura `depthSort: true`, plus `Texture.frameIdOf` O(1) negative integer frame handles) rendering in 1 instanced pass across WebGPU, WebGL2, and frame-sliced Canvas2D with zero retained scene-graph nodes.
20
+ - **Pure-Data `WorldCatalog` & Zero-Reset Hot-Reload (`defineWorldCatalog`, `createWorldCatalogRuntime`, `StageKernel.bindCatalog` / `reloadCatalog`, `./world` & `./kernel`)**:
21
+ - Enforces pure acyclic JSON-compatible static rule catalogs decoupled from live runtime state, hot-swapping `ItemRegistry`, `RecipeRegistry`, and balance rules in-place with structured `CatalogReloadDiff` notifications while preserving active inventories, workstations, and world deltas.
22
+
23
+ ## [0.10.3] - 2026-12-04
24
+
25
+ ### Added & Optimized
26
+ - **Automatic Atlas Frame-Slice Cache in `Renderer2D` & `mountChunkedTilemap` (`src/renderer-2d.ts`, `src/tilemap.ts`)**:
27
+ - Added an O(1) `Frame`-keyed, `TextureSource.version`-coherent, `64 MB` LRU-bounded sub-canvas slice cache (`getFrameSlice`) in `Renderer2D` across `ImageObject` / `SpriteObject` (cropped, uncropped, and tinted), `BlitterObject`, `InstancedBatchObject`, `TileSpriteObject`, and `NineSliceObject`, plus tile-slice caching in `mountChunkedTilemap` (`chunkCache: true`) and early `Frame.empty` skipping before Canvas2D state saves.
28
+ - Eliminates the `@napi-rs/canvas` large-source `drawImage` cliff (`4096×2467` `Canvas` or `Image` taking ~`0.4 ms/draw`), accelerating `550`-sprite headless frames by **~20–70×** (`~240 ms` -> `~2–11 ms` in `game.step()`) out of the box with zero user-code wrappers.
29
+ - **Turnkey `rawvideo` RGBA8888 FFmpeg Pipe Encoder (`@holtjs/stage/headless`, `src/headless.ts`)**:
30
+ - Added `encodeVideoWithFfmpeg(stage, options)`, `stage.encodeVideo(options)`, and `buildFfmpegRawVideoArgs(options)` for Node.js and Bun, streaming `stage.toRgba()` directly into `ffmpeg -f rawvideo -pix_fmt rgba` with `drain` backpressure handling and optional `AudioTimeline` / `.wav` muxing (eliminating ~`33 ms/frame` per-frame JPEG/PNG `image2pipe` CPU encoding).
31
+
32
+ ## [0.10.2] - 2026-12-04
33
+
34
+ ### Fixed
35
+ - **2x/3x Retina HiDPI `scrollFactor !== 1` Camera Matrix Parity (`Camera.matrixForScrollFactor`, `src/camera.ts`, `src/renderer-gl.ts`, `src/renderer-webgpu.ts`, `src/renderer-2d.ts`, `src/lighting.ts`, `src/headless.ts`)**:
36
+ - Subtracted the `configureHiDpi` base offset `sx0 = ox / dpr - ox` before multiplying by `scrollFactorX/Y` across WebGL2, WebGPU, Canvas2D, and `Lighting2DSystem`, keeping `scrollFactor(0)` HUD / `mountStage25D` layers anchored at `(0, 0)` on Retina screens, and updated `HeadlessStage.toRgba` / `toRgbaInto` to read dynamic backing dimensions.
37
+
9
38
  ## [0.10.1] - 2026-12-04
10
39
 
11
40
  ### Added & Fixed
@@ -196,6 +196,8 @@ declare class Frame {
196
196
  readonly name: string | number;
197
197
  readonly sourceIndex: number;
198
198
  readonly source: TextureSource;
199
+ /** Dense 0-based registration index inside `texture.frameList` (enables O(1) numeric IDs via `texture.frameIdOf(name)`). */
200
+ index: number;
199
201
  cutX: number;
200
202
  cutY: number;
201
203
  cutWidth: number;
@@ -242,12 +244,18 @@ declare class Texture {
242
244
  readonly key: string;
243
245
  readonly source: TextureSource[];
244
246
  readonly frames: Record<string, Frame>;
247
+ readonly frameList: Frame[];
245
248
  /** Optional isometric camera azimuth (`yaw` in radians, e.g. `Math.PI / 4` from `@holtjs/craft/three`) used by `SpriteObject.playDirectional()`. */
246
249
  atlasYaw: number | null;
247
250
  atlasPitch: number | null;
248
251
  atlasScale: number | null;
249
252
  constructor(manager: TextureManager, key: string, image: TextureImageSource, filterMode: FilterModeValue, host: GlTextureHost | null, premultiplyAlpha?: boolean, isRenderTarget?: boolean);
250
253
  add(name: string | number, sourceIndex: number, x: number, y: number, width: number, height: number, meta?: FrameExtraMeta): Frame;
254
+ /**
255
+ * Resolve a stable negative integer frame handle (`-1 - frame.index`) usable directly in
256
+ * `InstancedColumns.frameIndex` and `DrawStreamObject` across WebGL2, WebGPU, and Canvas2D!
257
+ */
258
+ frameIdOf(name?: string | number): number;
251
259
  has(name: string | number): boolean;
252
260
  get(name?: string | number): Frame;
253
261
  remove(name: string | number): boolean;
package/dist/anims.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as AtlasClipRule, c as GenerateFrameNamesConfig, i as AtlasAutoAnimOptions, l as GenerateFrameNumbersConfig, n as AnimationFrameInput, o as CompiledAnimationFrame, r as AnimationManager, s as DirectionalAnimGroup, t as AnimationConfig, u as StageAnimation } from "./anims-D9N8w6IM.js";
1
+ import { a as AtlasClipRule, c as GenerateFrameNamesConfig, i as AtlasAutoAnimOptions, l as GenerateFrameNumbersConfig, n as AnimationFrameInput, o as CompiledAnimationFrame, r as AnimationManager, s as DirectionalAnimGroup, t as AnimationConfig, u as StageAnimation } from "./anims-BYBzSNXO.js";
2
2
  export { AnimationConfig, AnimationFrameInput, AnimationManager, AtlasAutoAnimOptions, AtlasClipRule, CompiledAnimationFrame, DirectionalAnimGroup, GenerateFrameNamesConfig, GenerateFrameNumbersConfig, StageAnimation };
@@ -0,0 +1,73 @@
1
+ import { c as TweenManager, n as EasingFn, r as EasingName, t as DisposableOwner } from "./tween-BiF1FUvc.js";
2
+ type CoroutineTweenProps<T extends object> = { readonly [K in keyof T]?: T[K] extends number ? number : never; };
3
+ type CoroutineGenerator<R = unknown> = Generator<void, R, number>;
4
+ interface ScriptContext {
5
+ /** Total simulation milliseconds accumulated by this coroutine since start. */
6
+ readonly elapsedMs: number;
7
+ /** Simulation milliseconds passed into the current step (`deltaMs * scheduler.timeScale * handle.timeScale`). */
8
+ readonly deltaMs: number;
9
+ /** Wait for `seconds` of simulation time (carries sub-frame remainder across sequential waits for zero drift!). */
10
+ wait(seconds: number): CoroutineGenerator<void>;
11
+ /** Wait for `durationMs` of simulation time (carries sub-frame remainder across sequential waits for zero drift!). */
12
+ waitMs(durationMs: number): CoroutineGenerator<void>;
13
+ /** Suspend for `count` simulation ticks (`default = 1`). */
14
+ frames(count?: number): CoroutineGenerator<void>;
15
+ /** Yield each tick until `predicate()` returns `true` (`true`), or optional `timeoutMs` elapses (`false`). */
16
+ until(predicate: () => boolean, timeoutMs?: number): CoroutineGenerator<boolean>;
17
+ /** Interpolate numeric properties on `target` over `durationSeconds` using the coroutine's exact clock & `timeScale`! */
18
+ tween<T extends object>(target: T, props: CoroutineTweenProps<T>, durationSeconds: number, ease?: EasingName | EasingFn): CoroutineGenerator<void>;
19
+ /** Step multiple child generators in parallel lockstep and resume once all complete. */
20
+ all<const G extends readonly CoroutineGenerator<any>[]>(...tasks: G): CoroutineGenerator<{ [K in keyof G]: G[K] extends CoroutineGenerator<infer V> ? V : unknown; }>;
21
+ /** Step multiple child generators in parallel and return the index of the first to complete (closing losers via `.return()`). */
22
+ race(...tasks: readonly CoroutineGenerator<unknown>[]): CoroutineGenerator<number>;
23
+ }
24
+ interface ScriptOptions {
25
+ /** Optional scene-graph node or owner whose `onDispose` automatically cancels this coroutine. */
26
+ owner?: DisposableOwner;
27
+ /** Optional group tag for bulk cancellation via `scheduler.cancelByTag(tag)`. */
28
+ tag?: string;
29
+ /** Per-coroutine time multiplier (`1` = normal, `0` = paused, `2` = double speed). */
30
+ timeScale?: number;
31
+ /** Optional callback fired when the coroutine finishes naturally (`!cancelled`). */
32
+ onComplete?: (result: unknown) => void;
33
+ }
34
+ interface ScriptHandle {
35
+ readonly id: number;
36
+ readonly tag: string | null;
37
+ readonly active: boolean;
38
+ readonly completed: boolean;
39
+ readonly cancelled: boolean;
40
+ timeScale: number;
41
+ cancel(): void;
42
+ }
43
+ interface ScriptStats {
44
+ active: number;
45
+ completed: number;
46
+ cancelled: number;
47
+ }
48
+ declare class ScriptScheduler {
49
+ /** Scene-wide coroutine speed multiplier (`0` pauses all coroutines during hitstop!). */
50
+ timeScale: number;
51
+ private readonly tweens;
52
+ private tasks;
53
+ private nextId;
54
+ private completedTotal;
55
+ private cancelledTotal;
56
+ constructor(tweens?: TweenManager | null);
57
+ get hasActive(): boolean;
58
+ get activeCount(): number;
59
+ stats(): ScriptStats;
60
+ /**
61
+ * Launch a deterministic generator coroutine stepped on every simulation tick.
62
+ * Note: advances up to the first `yield` immediately on `run()` so synchronous setup executes at frame-0!
63
+ */
64
+ run<R = unknown>(fn: (co: ScriptContext) => CoroutineGenerator<R>, options?: ScriptOptions): ScriptHandle;
65
+ /** Advance all active coroutines by `deltaMs` of simulation clock time. */
66
+ step(deltaMs: number): void;
67
+ /** Cancel all active coroutines matching `tag`; returns number of cancelled tasks. */
68
+ cancelByTag(tag: string): number;
69
+ /** Cancel and clear all active coroutines (executing `finally` blocks cleanly). */
70
+ clear(): void;
71
+ private compactInactive;
72
+ }
73
+ export { ScriptOptions as a, ScriptHandle as i, CoroutineTweenProps as n, ScriptScheduler as o, ScriptContext as r, ScriptStats as s, CoroutineGenerator as t };
@@ -0,0 +1,2 @@
1
+ import { a as ScriptOptions, i as ScriptHandle, n as CoroutineTweenProps, o as ScriptScheduler, r as ScriptContext, s as ScriptStats, t as CoroutineGenerator } from "./coroutine-DLgJumtD.js";
2
+ export { CoroutineGenerator, CoroutineTweenProps, ScriptContext, ScriptHandle, ScriptOptions, ScriptScheduler, ScriptStats };
@@ -0,0 +1,322 @@
1
+ import { Easings } from "./tween.js";
2
+ // src/coroutine.ts
3
+ function safeCloseGenerator(gen) {
4
+ try {
5
+ gen.return(void 0);
6
+ } catch {}
7
+ }
8
+ var ScriptScheduler = class {
9
+ /** Scene-wide coroutine speed multiplier (`0` pauses all coroutines during hitstop!). */
10
+ timeScale = 1;
11
+ tweens;
12
+ tasks = [];
13
+ nextId = 1;
14
+ completedTotal = 0;
15
+ cancelledTotal = 0;
16
+ constructor(tweens = null) {
17
+ this.tweens = tweens;
18
+ }
19
+ get hasActive() {
20
+ return this.tasks.length > 0;
21
+ }
22
+ get activeCount() {
23
+ return this.tasks.length;
24
+ }
25
+ stats() {
26
+ return {
27
+ active: this.tasks.length,
28
+ completed: this.completedTotal,
29
+ cancelled: this.cancelledTotal
30
+ };
31
+ }
32
+ /**
33
+ * Launch a deterministic generator coroutine stepped on every simulation tick.
34
+ * Note: advances up to the first `yield` immediately on `run()` so synchronous setup executes at frame-0!
35
+ */
36
+ run(fn, options = {}) {
37
+ const id = this.nextId++;
38
+ this.tweens;
39
+ const task = {
40
+ id,
41
+ gen: null,
42
+ tag: options.tag ?? null,
43
+ onComplete: options.onComplete,
44
+ detachDispose: null,
45
+ active: true,
46
+ completed: false,
47
+ cancelled: false,
48
+ timeScale: options.timeScale !== void 0 ? Math.max(0, options.timeScale) : 1,
49
+ elapsedMs: 0,
50
+ currentDt: 0,
51
+ carryMs: 0
52
+ };
53
+ const co = {
54
+ get elapsedMs() {
55
+ return task.elapsedMs;
56
+ },
57
+ get deltaMs() {
58
+ return task.currentDt;
59
+ },
60
+ *waitMs(durationMs) {
61
+ const target = Math.max(0, durationMs);
62
+ if (target <= 0) return;
63
+ let acc = task.carryMs;
64
+ task.carryMs = 0;
65
+ while (acc + 1e-6 < target) {
66
+ const dt = yield;
67
+ acc += dt;
68
+ }
69
+ task.carryMs = Math.max(0, acc - target);
70
+ },
71
+ *wait(seconds) {
72
+ yield* co.waitMs(Math.max(0, seconds) * 1e3);
73
+ },
74
+ *frames(count = 1) {
75
+ task.carryMs = 0;
76
+ const n = Math.max(0, Math.floor(count));
77
+ for (let i = 0; i < n; i++) yield;
78
+ },
79
+ *until(predicate, timeoutMs) {
80
+ task.carryMs = 0;
81
+ if (predicate()) return true;
82
+ const limit = timeoutMs !== void 0 && timeoutMs >= 0 ? timeoutMs : 1e400;
83
+ let waited = 0;
84
+ while (!predicate()) {
85
+ if (waited >= limit) return false;
86
+ const dt = yield;
87
+ waited += dt;
88
+ }
89
+ return true;
90
+ },
91
+ *tween(target, props, durationSeconds, easeInput = Easings.outQuad) {
92
+ const durMs = Math.max(0, durationSeconds * 1e3);
93
+ const easeFn = typeof easeInput === "function" ? easeInput : Easings[easeInput] ?? Easings.outQuad;
94
+ const keys = Object.keys(props);
95
+ const rec = target;
96
+ const starts = new Float64Array(keys.length);
97
+ const ends = new Float64Array(keys.length);
98
+ for (let i = 0; i < keys.length; i++) {
99
+ const k = keys[i];
100
+ starts[i] = Number(rec[k]) || 0;
101
+ ends[i] = Number(props[k]) || 0;
102
+ }
103
+ if (durMs <= 0) {
104
+ for (let i = 0; i < keys.length; i++) rec[keys[i]] = ends[i];
105
+ return;
106
+ }
107
+ let acc = task.carryMs;
108
+ task.carryMs = 0;
109
+ while (acc + 1e-6 < durMs) {
110
+ if (acc > 0) {
111
+ const t = easeFn(Math.min(1, acc / durMs));
112
+ for (let i = 0; i < keys.length; i++) rec[keys[i]] = starts[i] + (ends[i] - starts[i]) * t;
113
+ }
114
+ const dt = yield;
115
+ acc += dt;
116
+ }
117
+ for (let i = 0; i < keys.length; i++) rec[keys[i]] = ends[i];
118
+ task.carryMs = Math.max(0, acc - durMs);
119
+ },
120
+ *all(...children) {
121
+ task.carryMs = 0;
122
+ const n = children.length;
123
+ const results = new Array(n);
124
+ const finished = new Uint8Array(n);
125
+ let rem = n;
126
+ for (let i = 0; i < n; i++) {
127
+ const r = children[i].next(0);
128
+ if (r.done) {
129
+ finished[i] = 1;
130
+ results[i] = r.value;
131
+ rem--;
132
+ }
133
+ }
134
+ try {
135
+ while (rem > 0) {
136
+ const dt = yield;
137
+ for (let i = 0; i < n; i++) {
138
+ if (finished[i]) continue;
139
+ const r = children[i].next(dt);
140
+ if (r.done) {
141
+ finished[i] = 1;
142
+ results[i] = r.value;
143
+ rem--;
144
+ }
145
+ }
146
+ }
147
+ return results;
148
+ } finally {
149
+ for (let i = 0; i < n; i++) if (!finished[i]) safeCloseGenerator(children[i]);
150
+ }
151
+ },
152
+ *race(...children) {
153
+ task.carryMs = 0;
154
+ const n = children.length;
155
+ if (n === 0) return -1;
156
+ const finished = new Uint8Array(n);
157
+ let winner = -1;
158
+ for (let i = 0; i < n; i++) if (children[i].next(0).done) {
159
+ finished[i] = 1;
160
+ if (winner < 0) winner = i;
161
+ }
162
+ try {
163
+ while (winner < 0) {
164
+ const dt = yield;
165
+ for (let i = 0; i < n; i++) {
166
+ if (finished[i]) continue;
167
+ if (children[i].next(dt).done) {
168
+ finished[i] = 1;
169
+ if (winner < 0) winner = i;
170
+ }
171
+ }
172
+ }
173
+ return winner;
174
+ } finally {
175
+ for (let i = 0; i < n; i++) if (!finished[i]) safeCloseGenerator(children[i]);
176
+ }
177
+ }
178
+ };
179
+ const cancelTask = () => {
180
+ if (!task.active) return;
181
+ task.active = false;
182
+ task.cancelled = true;
183
+ this.cancelledTotal++;
184
+ if (task.detachDispose) {
185
+ const d = task.detachDispose;
186
+ task.detachDispose = null;
187
+ try {
188
+ d();
189
+ } catch {}
190
+ }
191
+ safeCloseGenerator(task.gen);
192
+ };
193
+ if (options.owner && typeof options.owner.onDispose === "function") {
194
+ const unsub = options.owner.onDispose(cancelTask);
195
+ if (typeof unsub === "function") task.detachDispose = unsub;
196
+ }
197
+ const gen = fn(co);
198
+ task.gen = gen;
199
+ const first = gen.next(0);
200
+ if (first.done) {
201
+ if (task.active) {
202
+ task.active = false;
203
+ task.completed = true;
204
+ this.completedTotal++;
205
+ if (task.detachDispose) {
206
+ const d = task.detachDispose;
207
+ task.detachDispose = null;
208
+ try {
209
+ d();
210
+ } catch {}
211
+ }
212
+ task.onComplete?.(first.value);
213
+ }
214
+ } else if (task.active) this.tasks.push(task);
215
+ return {
216
+ id,
217
+ tag: task.tag,
218
+ get active() {
219
+ return task.active;
220
+ },
221
+ get completed() {
222
+ return task.completed;
223
+ },
224
+ get cancelled() {
225
+ return task.cancelled;
226
+ },
227
+ get timeScale() {
228
+ return task.timeScale;
229
+ },
230
+ set timeScale(v) {
231
+ task.timeScale = Math.max(0, v);
232
+ },
233
+ cancel: cancelTask
234
+ };
235
+ }
236
+ /** Advance all active coroutines by `deltaMs` of simulation clock time. */
237
+ step(deltaMs) {
238
+ if (this.tasks.length === 0 || deltaMs <= 0 || this.timeScale <= 0) return;
239
+ const globalScale = this.timeScale;
240
+ let writeIdx = 0;
241
+ const initialLen = this.tasks.length;
242
+ for (let i = 0; i < initialLen; i++) {
243
+ const t = this.tasks[i];
244
+ if (!t.active) continue;
245
+ if (t.timeScale <= 0) {
246
+ this.tasks[writeIdx++] = t;
247
+ continue;
248
+ }
249
+ const dt = deltaMs * globalScale * t.timeScale;
250
+ t.currentDt = dt;
251
+ t.elapsedMs += dt;
252
+ const stepRes = t.gen.next(dt);
253
+ if (!t.active) continue;
254
+ if (stepRes.done) {
255
+ t.active = false;
256
+ t.completed = true;
257
+ this.completedTotal++;
258
+ if (t.detachDispose) {
259
+ const d = t.detachDispose;
260
+ t.detachDispose = null;
261
+ try {
262
+ d();
263
+ } catch {}
264
+ }
265
+ t.onComplete?.(stepRes.value);
266
+ } else this.tasks[writeIdx++] = t;
267
+ }
268
+ for (let i = initialLen; i < this.tasks.length; i++) {
269
+ const t = this.tasks[i];
270
+ if (t.active) this.tasks[writeIdx++] = t;
271
+ }
272
+ this.tasks.length = writeIdx;
273
+ }
274
+ /** Cancel all active coroutines matching `tag`; returns number of cancelled tasks. */
275
+ cancelByTag(tag) {
276
+ let count = 0;
277
+ for (let i = 0; i < this.tasks.length; i++) {
278
+ const t = this.tasks[i];
279
+ if (t.active && t.tag === tag) {
280
+ t.active = false;
281
+ t.cancelled = true;
282
+ this.cancelledTotal++;
283
+ if (t.detachDispose) {
284
+ const d = t.detachDispose;
285
+ t.detachDispose = null;
286
+ try {
287
+ d();
288
+ } catch {}
289
+ }
290
+ safeCloseGenerator(t.gen);
291
+ count++;
292
+ }
293
+ }
294
+ this.compactInactive();
295
+ return count;
296
+ }
297
+ /** Cancel and clear all active coroutines (executing `finally` blocks cleanly). */
298
+ clear() {
299
+ for (let i = 0; i < this.tasks.length; i++) {
300
+ const t = this.tasks[i];
301
+ if (!t.active) continue;
302
+ t.active = false;
303
+ t.cancelled = true;
304
+ this.cancelledTotal++;
305
+ if (t.detachDispose) {
306
+ const d = t.detachDispose;
307
+ t.detachDispose = null;
308
+ try {
309
+ d();
310
+ } catch {}
311
+ }
312
+ safeCloseGenerator(t.gen);
313
+ }
314
+ this.tasks.length = 0;
315
+ }
316
+ compactInactive() {
317
+ let w = 0;
318
+ for (let i = 0; i < this.tasks.length; i++) if (this.tasks[i].active) this.tasks[w++] = this.tasks[i];
319
+ this.tasks.length = w;
320
+ }
321
+ };
322
+ export { ScriptScheduler };
@@ -2159,4 +2159,226 @@ var ShapeBatchObject = class extends DisplayObject {
2159
2159
  super.destroy(fromScene);
2160
2160
  }
2161
2161
  };
2162
- export { DisplayObject as a, InstancedBatchObject as c, PanelObject as d, RectangleObject as f, TileSpriteObject as g, TextObject as h, DisplayList as i, MsdfIconObject as l, SpriteObject as m, Container as n, Graphics as o, ShapeBatchObject as p, CustomPassObject as r, ImageObject as s, BlitterObject as t, NineSliceObject as u };
2162
+ const STREAM_CIURA_GAPS = [
2163
+ 701,
2164
+ 301,
2165
+ 132,
2166
+ 57,
2167
+ 23,
2168
+ 10,
2169
+ 4,
2170
+ 1
2171
+ ];
2172
+ /**
2173
+ * Stateless per-frame immediate-mode sprite batch (`scene.drawStream(textureKey)` or `scene.add.drawStream(...)`).
2174
+ * Submits thousands of transient drops, projectiles, grass tufts, or minimap markers in 1 GPU instanced draw call
2175
+ * across WebGPU, WebGL2, and Canvas2D with zero retained `DisplayObject` allocations!
2176
+ */
2177
+ var DrawStreamObject = class extends InstancedBatchObject {
2178
+ autoReset;
2179
+ depthSort;
2180
+ cap;
2181
+ curCount = 0;
2182
+ depthDirty = false;
2183
+ colX;
2184
+ colY;
2185
+ colSx;
2186
+ colSy;
2187
+ colRot;
2188
+ colAlpha;
2189
+ colTint;
2190
+ colFrame;
2191
+ colDepth;
2192
+ colOrder;
2193
+ liveColumns;
2194
+ detachEvents;
2195
+ constructor(scene, key, options = {}) {
2196
+ const initCap = Math.max(16, Math.floor(options.initialCapacity ?? 256));
2197
+ super(scene, key, initCap, options.defaultFrame);
2198
+ this.cap = initCap;
2199
+ this.autoReset = options.autoReset !== false;
2200
+ this.depthSort = Boolean(options.depthSort);
2201
+ if (options.depth !== void 0) this.setDepth(options.depth);
2202
+ if (options.blendMode !== void 0) this.setBlendMode(options.blendMode);
2203
+ if (options.scrollFactor !== void 0) this.setScrollFactor(options.scrollFactor, options.scrollFactor);
2204
+ this.colX = new Float32Array(initCap);
2205
+ this.colY = new Float32Array(initCap);
2206
+ this.colSx = new Float32Array(initCap);
2207
+ this.colSy = new Float32Array(initCap);
2208
+ this.colRot = new Float32Array(initCap);
2209
+ this.colAlpha = new Float32Array(initCap);
2210
+ this.colTint = new Uint32Array(initCap);
2211
+ this.colFrame = new Int32Array(initCap);
2212
+ this.colDepth = new Float32Array(initCap);
2213
+ this.colOrder = new Int32Array(initCap);
2214
+ this.liveColumns = {
2215
+ count: 0,
2216
+ x: this.colX,
2217
+ y: this.colY,
2218
+ scaleX: this.colSx,
2219
+ scaleY: this.colSy,
2220
+ rotation: this.colRot,
2221
+ alpha: this.colAlpha,
2222
+ tint: this.colTint,
2223
+ frameIndex: this.colFrame,
2224
+ order: null
2225
+ };
2226
+ this.setColumns(this.liveColumns);
2227
+ const ev = scene.events;
2228
+ if (ev) {
2229
+ const onPreUpdate = () => {
2230
+ if (this.autoReset) this.begin();
2231
+ };
2232
+ const onPreRender = () => {
2233
+ this.flushOrder();
2234
+ };
2235
+ ev.on("preupdate", onPreUpdate);
2236
+ ev.on("prerender", onPreRender);
2237
+ this.detachEvents = () => {
2238
+ ev.off("preupdate", onPreUpdate);
2239
+ ev.off("prerender", onPreRender);
2240
+ };
2241
+ } else this.detachEvents = null;
2242
+ }
2243
+ get count() {
2244
+ return this.curCount;
2245
+ }
2246
+ /** Reset write cursor to `0` for a fresh frame (zero memory freed or allocated). */
2247
+ begin() {
2248
+ this.curCount = 0;
2249
+ this.depthDirty = false;
2250
+ this.liveColumns.count = 0;
2251
+ this.liveColumns.order = null;
2252
+ return this;
2253
+ }
2254
+ ensureStreamCapacity(needed) {
2255
+ if (needed <= this.cap) return;
2256
+ let next = this.cap;
2257
+ while (next < needed) next *= 2;
2258
+ const growF32 = (src) => {
2259
+ const dst = new Float32Array(next);
2260
+ dst.set(src);
2261
+ return dst;
2262
+ };
2263
+ const growU32 = (src) => {
2264
+ const dst = new Uint32Array(next);
2265
+ dst.set(src);
2266
+ return dst;
2267
+ };
2268
+ const growI32 = (src) => {
2269
+ const dst = new Int32Array(next);
2270
+ dst.set(src);
2271
+ return dst;
2272
+ };
2273
+ this.colX = growF32(this.colX);
2274
+ this.colY = growF32(this.colY);
2275
+ this.colSx = growF32(this.colSx);
2276
+ this.colSy = growF32(this.colSy);
2277
+ this.colRot = growF32(this.colRot);
2278
+ this.colAlpha = growF32(this.colAlpha);
2279
+ this.colTint = growU32(this.colTint);
2280
+ this.colFrame = growI32(this.colFrame);
2281
+ this.colDepth = growF32(this.colDepth);
2282
+ this.colOrder = growI32(this.colOrder);
2283
+ this.cap = next;
2284
+ this.maxCount = next;
2285
+ this.liveColumns.x = this.colX;
2286
+ this.liveColumns.y = this.colY;
2287
+ this.liveColumns.scaleX = this.colSx;
2288
+ this.liveColumns.scaleY = this.colSy;
2289
+ this.liveColumns.rotation = this.colRot;
2290
+ this.liveColumns.alpha = this.colAlpha;
2291
+ this.liveColumns.tint = this.colTint;
2292
+ this.liveColumns.frameIndex = this.colFrame;
2293
+ if (this.liveColumns.order) this.liveColumns.order = this.colOrder;
2294
+ }
2295
+ /** Append a single sprite command in O(1) zero-GC typed-array writes; returns emitted instance index. */
2296
+ sprite(frame, x, y, opts) {
2297
+ const idx = this.curCount;
2298
+ this.ensureStreamCapacity(idx + 1);
2299
+ const sUniform = opts?.scale ?? 1;
2300
+ this.colX[idx] = x;
2301
+ this.colY[idx] = y;
2302
+ this.colSx[idx] = opts?.scaleX ?? sUniform;
2303
+ this.colSy[idx] = opts?.scaleY ?? sUniform;
2304
+ this.colRot[idx] = opts?.rotation ?? 0;
2305
+ this.colAlpha[idx] = opts?.alpha ?? 1;
2306
+ this.colTint[idx] = opts?.tint ?? 0xffffff;
2307
+ this.colFrame[idx] = this.texture.frameIdOf(frame);
2308
+ this.colDepth[idx] = opts?.depth ?? y;
2309
+ this.curCount = idx + 1;
2310
+ this.liveColumns.count = this.curCount;
2311
+ if (this.depthSort) this.depthDirty = true;
2312
+ return idx;
2313
+ }
2314
+ /** Reserve `count` contiguous instance slots for bulk SIMD / Worker `TypedArray.set()` fills! */
2315
+ writeBulk(count, writer) {
2316
+ const n = Math.max(0, Math.floor(count));
2317
+ if (n <= 0) return this.curCount;
2318
+ const offset = this.curCount;
2319
+ this.ensureStreamCapacity(offset + n);
2320
+ const defaultFid = this.texture.frameIdOf(this.defaultFrame.name);
2321
+ this.colSx.fill(1, offset, offset + n);
2322
+ this.colSy.fill(1, offset, offset + n);
2323
+ this.colRot.fill(0, offset, offset + n);
2324
+ this.colAlpha.fill(1, offset, offset + n);
2325
+ this.colTint.fill(WHITE_RGB, offset, offset + n);
2326
+ this.colFrame.fill(defaultFid, offset, offset + n);
2327
+ writer({
2328
+ x: this.colX,
2329
+ y: this.colY,
2330
+ scaleX: this.colSx,
2331
+ scaleY: this.colSy,
2332
+ rotation: this.colRot,
2333
+ alpha: this.colAlpha,
2334
+ tint: this.colTint,
2335
+ frameIndex: this.colFrame,
2336
+ depth: this.colDepth
2337
+ }, offset);
2338
+ this.curCount = offset + n;
2339
+ this.liveColumns.count = this.curCount;
2340
+ if (this.depthSort) this.depthDirty = true;
2341
+ return offset;
2342
+ }
2343
+ /** Materialize ascending `depth` painter's order in `columns.order` when `depthSort: true`. */
2344
+ flushOrder() {
2345
+ if (!this.depthSort) {
2346
+ this.liveColumns.order = null;
2347
+ return;
2348
+ }
2349
+ const n = this.curCount;
2350
+ if (n <= 1) {
2351
+ this.liveColumns.order = null;
2352
+ this.depthDirty = false;
2353
+ return;
2354
+ }
2355
+ if (!this.depthDirty && this.liveColumns.order === this.colOrder) return;
2356
+ const ord = this.colOrder;
2357
+ const dep = this.colDepth;
2358
+ for (let i = 0; i < n; i++) ord[i] = i;
2359
+ for (let gi = 0; gi < STREAM_CIURA_GAPS.length; gi++) {
2360
+ const gap = STREAM_CIURA_GAPS[gi];
2361
+ if (gap >= n) continue;
2362
+ for (let i = gap; i < n; i++) {
2363
+ const cur = ord[i];
2364
+ const curD = dep[cur];
2365
+ let j = i;
2366
+ while (j >= gap) {
2367
+ const prev = ord[j - gap];
2368
+ const prevD = dep[prev];
2369
+ if (prevD < curD || prevD === curD && prev < cur) break;
2370
+ ord[j] = prev;
2371
+ j -= gap;
2372
+ }
2373
+ ord[j] = cur;
2374
+ }
2375
+ }
2376
+ this.liveColumns.order = ord;
2377
+ this.depthDirty = false;
2378
+ }
2379
+ destroy(fromScene) {
2380
+ this.detachEvents?.();
2381
+ super.destroy(fromScene);
2382
+ }
2383
+ };
2384
+ export { TileSpriteObject as _, DisplayObject as a, ImageObject as c, NineSliceObject as d, PanelObject as f, TextObject as g, SpriteObject as h, DisplayList as i, InstancedBatchObject as l, ShapeBatchObject as m, Container as n, DrawStreamObject as o, RectangleObject as p, CustomPassObject as r, Graphics as s, BlitterObject as t, MsdfIconObject as u };