@holtjs/stage 0.5.2 → 0.7.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 +30 -0
- package/dist/anims-CS0rfUIz.d.ts +389 -0
- package/dist/anims.d.ts +2 -0
- package/dist/anims.js +436 -0
- package/dist/{game-DWELKTnB.d.ts → game-3L9wS-Bv.d.ts} +279 -205
- package/dist/{game-B8UlnEB_.js → game-BnSWR44q.js} +642 -285
- package/dist/headless.d.ts +5 -1
- package/dist/headless.js +19 -3
- package/dist/index.d.ts +22 -2
- package/dist/index.js +7 -4
- package/dist/joystick.d.ts +1 -1
- package/dist/joystick.js +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/kernel.js +4 -0
- package/dist/lighting.d.ts +1 -1
- package/dist/lighting.js +4 -9
- package/dist/projection.d.ts +1 -1
- package/dist/{renderer-webgpu-Djk7FayG.js → renderer-webgpu-alSDj9RR.js} +1298 -96
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +2 -1
- package/dist/rig2d.js +1 -1
- package/dist/tilemap.d.ts +14 -3
- package/dist/tilemap.js +85 -11
- package/dist/trace.d.ts +1 -1
- package/dist/trace.js +8 -2
- package/dist/{types-DRFB0Klc.js → types-CXsCvp1p.js} +5 -1
- package/llms.txt +1 -1
- package/package.json +5 -1
- package/skills/stage/SKILL.md +38 -12
- package/skills/stage/references/subpaths.md +11 -7
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { _ as rgbToCss, a as EventEmitter,
|
|
2
|
-
import {
|
|
1
|
+
import { _ as rgbToCss, a as EventEmitter, c as Scale, h as packColorAbgr, l as Scenes, m as createMatrix2D, o as FilterMode, p as WHITE_RGB, r as BlendModes, u as TintModes } from "./types-CXsCvp1p.js";
|
|
2
|
+
import { AnimationManager } from "./anims.js";
|
|
3
|
+
import { _ as SpriteObject, a as Container, b as Camera, d as InstancedBatchObject, f as MsdfIconObject, g as ShapeBatchObject, h as RectangleObject, i as BlitterObject, l as Graphics, m as PanelObject, o as CustomPassObject, p as NineSliceObject, r as Renderer2D, s as DisplayList, t as RendererWebGpu, u as ImageObject, v as TextObject, y as TileSpriteObject } from "./renderer-webgpu-alSDj9RR.js";
|
|
3
4
|
import { TweenManager } from "./tween.js";
|
|
4
5
|
import { StageKernel } from "./kernel.js";
|
|
5
6
|
// src/texture.ts
|
|
6
|
-
var TextureSource = class {
|
|
7
|
+
var TextureSource = class TextureSource {
|
|
8
|
+
static nextId = 1;
|
|
9
|
+
id = TextureSource.nextId++;
|
|
10
|
+
version = 0;
|
|
7
11
|
texture;
|
|
8
12
|
image;
|
|
9
13
|
width;
|
|
@@ -47,6 +51,7 @@ var TextureSource = class {
|
|
|
47
51
|
update() {
|
|
48
52
|
this.width = sourceWidth(this.image);
|
|
49
53
|
this.height = sourceHeight(this.image);
|
|
54
|
+
this.version++;
|
|
50
55
|
this.dirty = true;
|
|
51
56
|
if (this.host?.gl && !this.host.contextLost && this.width > 0 && this.height > 0) this.host.uploadTextureSource(this);
|
|
52
57
|
}
|
|
@@ -81,12 +86,28 @@ var Frame = class {
|
|
|
81
86
|
v0 = 0;
|
|
82
87
|
u1 = 1;
|
|
83
88
|
v1 = 1;
|
|
84
|
-
|
|
89
|
+
/** True when the atlas/baker specified an explicit per-frame pivot (`ax/ay` or `pivotX/pivotY`). */
|
|
90
|
+
customPivot = false;
|
|
91
|
+
pivotX = .5;
|
|
92
|
+
pivotY = .5;
|
|
93
|
+
pixelPivotX = 0;
|
|
94
|
+
pixelPivotY = 0;
|
|
95
|
+
/** Named frame-space pixel sockets relative to trimmed `(0, 0)`, e.g. `{ hand: [28, 34] }`. */
|
|
96
|
+
anchors = null;
|
|
97
|
+
emissiveCenter = null;
|
|
98
|
+
emissivePower = 0;
|
|
99
|
+
actor = null;
|
|
100
|
+
clip = null;
|
|
101
|
+
dir = null;
|
|
102
|
+
animFrameIndex = null;
|
|
103
|
+
animLoop = void 0;
|
|
104
|
+
constructor(texture, name, sourceIndex, x, y, w, h, meta) {
|
|
85
105
|
this.texture = texture;
|
|
86
106
|
this.name = name;
|
|
87
107
|
this.sourceIndex = sourceIndex;
|
|
88
108
|
this.source = texture.source[sourceIndex];
|
|
89
109
|
this.setSize(w, h, x, y);
|
|
110
|
+
if (meta) this.applyMeta(meta);
|
|
90
111
|
}
|
|
91
112
|
setSize(width, height, x = this.cutX, y = this.cutY) {
|
|
92
113
|
this.cutX = x;
|
|
@@ -95,9 +116,59 @@ var Frame = class {
|
|
|
95
116
|
this.cutHeight = height;
|
|
96
117
|
this.width = width;
|
|
97
118
|
this.height = height;
|
|
119
|
+
if (!this.customPivot) {
|
|
120
|
+
this.pixelPivotX = width * this.pivotX;
|
|
121
|
+
this.pixelPivotY = height * this.pivotY;
|
|
122
|
+
}
|
|
98
123
|
this.updateUVs();
|
|
99
124
|
return this;
|
|
100
125
|
}
|
|
126
|
+
/** Set normalized `[0..1]` per-frame pivot (marks `customPivot = true`). */
|
|
127
|
+
setPivot(pivotX, pivotY) {
|
|
128
|
+
this.customPivot = true;
|
|
129
|
+
this.pivotX = pivotX;
|
|
130
|
+
this.pivotY = pivotY;
|
|
131
|
+
this.pixelPivotX = this.width * pivotX;
|
|
132
|
+
this.pixelPivotY = this.height * pivotY;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
/** Set exact pixel pivot `(ax, ay)` from trimmed frame top-left `(0, 0)` (avoids float rounding drift). */
|
|
136
|
+
setPixelPivot(ax, ay) {
|
|
137
|
+
this.customPivot = true;
|
|
138
|
+
this.pixelPivotX = ax;
|
|
139
|
+
this.pixelPivotY = ay;
|
|
140
|
+
this.pivotX = this.width > 0 ? ax / this.width : .5;
|
|
141
|
+
this.pivotY = this.height > 0 ? ay / this.height : .5;
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
/** Attach or update a named pixel socket `(x, y)` relative to trimmed frame top-left `(0, 0)`. */
|
|
145
|
+
setAnchor(name, x, y) {
|
|
146
|
+
if (!this.anchors) this.anchors = Object.create(null);
|
|
147
|
+
this.anchors[name] = [x, y];
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
/** Read a named pixel socket `[x, y]` (falls back to `emissiveCenter` when `name === 'emissive'`). */
|
|
151
|
+
getAnchor(name) {
|
|
152
|
+
if (this.anchors && Object.prototype.hasOwnProperty.call(this.anchors, name)) return this.anchors[name];
|
|
153
|
+
if (name === "emissive" && this.emissiveCenter) return this.emissiveCenter;
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
applyMeta(meta) {
|
|
157
|
+
if (typeof meta.ax === "number" && typeof meta.ay === "number") this.setPixelPivot(meta.ax, meta.ay);
|
|
158
|
+
else if (typeof meta.pivotX === "number" || typeof meta.pivotY === "number") this.setPivot(meta.pivotX ?? .5, meta.pivotY ?? .5);
|
|
159
|
+
if (meta.anchors) {
|
|
160
|
+
for (const [k, pt] of Object.entries(meta.anchors)) if (Array.isArray(pt) && pt.length >= 2) this.setAnchor(k, Number(pt[0]) || 0, Number(pt[1]) || 0);
|
|
161
|
+
}
|
|
162
|
+
if (Array.isArray(meta.emissiveCenter) && meta.emissiveCenter.length >= 2) this.emissiveCenter = [Number(meta.emissiveCenter[0]) || 0, Number(meta.emissiveCenter[1]) || 0];
|
|
163
|
+
if (typeof meta.emissivePower === "number") this.emissivePower = meta.emissivePower;
|
|
164
|
+
const actor = meta.actor ?? meta.char;
|
|
165
|
+
if (typeof actor === "string" && actor.length > 0) this.actor = actor;
|
|
166
|
+
if (typeof meta.clip === "string" && meta.clip.length > 0) this.clip = meta.clip;
|
|
167
|
+
if (typeof meta.dir === "number" || typeof meta.dir === "string") this.dir = meta.dir;
|
|
168
|
+
if (typeof meta.frame === "number" && Number.isFinite(meta.frame)) this.animFrameIndex = meta.frame;
|
|
169
|
+
if (typeof meta.loop === "boolean") this.animLoop = meta.loop;
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
101
172
|
updateUVs() {
|
|
102
173
|
const sw = this.source.width || 1;
|
|
103
174
|
const sh = this.source.height || 1;
|
|
@@ -112,6 +183,10 @@ var Texture = class {
|
|
|
112
183
|
key;
|
|
113
184
|
source;
|
|
114
185
|
frames = Object.create(null);
|
|
186
|
+
/** Optional isometric camera azimuth (`yaw` in radians, e.g. `Math.PI / 4` from `@holtjs/craft/three`) used by `SpriteObject.playDirectional()`. */
|
|
187
|
+
atlasYaw = null;
|
|
188
|
+
atlasPitch = null;
|
|
189
|
+
atlasScale = null;
|
|
115
190
|
constructor(manager, key, image, filterMode, host, premultiplyAlpha = true, isRenderTarget = false) {
|
|
116
191
|
this.manager = manager;
|
|
117
192
|
this.key = key;
|
|
@@ -119,8 +194,8 @@ var Texture = class {
|
|
|
119
194
|
this.source = [src];
|
|
120
195
|
this.add("__BASE", 0, 0, 0, src.width, src.height);
|
|
121
196
|
}
|
|
122
|
-
add(name, sourceIndex, x, y, width, height) {
|
|
123
|
-
const frame = new Frame(this, name, sourceIndex, x, y, width, height);
|
|
197
|
+
add(name, sourceIndex, x, y, width, height, meta) {
|
|
198
|
+
const frame = new Frame(this, name, sourceIndex, x, y, width, height, meta);
|
|
124
199
|
this.frames[String(name)] = frame;
|
|
125
200
|
return frame;
|
|
126
201
|
}
|
|
@@ -250,6 +325,71 @@ var TextureManager = class {
|
|
|
250
325
|
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) tex.add(idx++, 0, margin + c * strideX, margin + r * strideY, fw, fh);
|
|
251
326
|
return tex;
|
|
252
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Register a packed sprite atlas (`@holtjs/craft/three`, `@holtjs/craft/atlas`, or TexturePacker / Aseprite JSON Hash & Array)
|
|
330
|
+
* preserving per-frame trimmed pivots (`ax/ay` or `pivot`), named sockets (`anchors`), `emissiveCenter`, and `atlasYaw`!
|
|
331
|
+
*/
|
|
332
|
+
addAtlas(key, source, atlasData, options) {
|
|
333
|
+
const tex = this.addImage(key, source, options);
|
|
334
|
+
if (!tex || !atlasData) return tex;
|
|
335
|
+
const root = atlasData.json && typeof atlasData.json === "object" ? atlasData.json : atlasData;
|
|
336
|
+
if (typeof root.yaw === "number" && Number.isFinite(root.yaw)) tex.atlasYaw = root.yaw;
|
|
337
|
+
if (typeof root.pitch === "number" && Number.isFinite(root.pitch)) tex.atlasPitch = root.pitch;
|
|
338
|
+
if (typeof root.scale === "number" && Number.isFinite(root.scale)) tex.atlasScale = root.scale;
|
|
339
|
+
const rawFrames = root.frames ?? atlasData.frames;
|
|
340
|
+
if (!rawFrames) return tex;
|
|
341
|
+
const addEntry = (frameName, entry) => {
|
|
342
|
+
if (!entry || typeof entry !== "object") return;
|
|
343
|
+
if (entry.frame && typeof entry.frame === "object" && typeof entry.frame.w === "number") {
|
|
344
|
+
const fr = entry.frame;
|
|
345
|
+
const fx = Number(fr.x) || 0;
|
|
346
|
+
const fy = Number(fr.y) || 0;
|
|
347
|
+
const fw = Number(fr.w) || 0;
|
|
348
|
+
const fh = Number(fr.h) || 0;
|
|
349
|
+
const meta = {};
|
|
350
|
+
if (entry.pivot && typeof entry.pivot.x === "number" && typeof entry.pivot.y === "number") {
|
|
351
|
+
const px = Number(entry.pivot.x);
|
|
352
|
+
const py = Number(entry.pivot.y);
|
|
353
|
+
if (entry.trimmed && entry.sourceSize && entry.spriteSourceSize && typeof entry.sourceSize.w === "number" && typeof entry.spriteSourceSize.x === "number") {
|
|
354
|
+
meta.ax = entry.sourceSize.w * px - entry.spriteSourceSize.x;
|
|
355
|
+
meta.ay = entry.sourceSize.h * py - entry.spriteSourceSize.y;
|
|
356
|
+
} else {
|
|
357
|
+
meta.pivotX = px;
|
|
358
|
+
meta.pivotY = py;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (entry.anchors) meta.anchors = entry.anchors;
|
|
362
|
+
tex.add(frameName, 0, fx, fy, fw, fh, meta);
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
const fx = Number(entry.x) || 0;
|
|
366
|
+
const fy = Number(entry.y) || 0;
|
|
367
|
+
const fw = Number(entry.w ?? entry.width) || 0;
|
|
368
|
+
const fh = Number(entry.h ?? entry.height) || 0;
|
|
369
|
+
tex.add(frameName, 0, fx, fy, fw, fh, {
|
|
370
|
+
ax: typeof entry.ax === "number" ? entry.ax : void 0,
|
|
371
|
+
ay: typeof entry.ay === "number" ? entry.ay : void 0,
|
|
372
|
+
pivotX: typeof entry.pivotX === "number" ? entry.pivotX : void 0,
|
|
373
|
+
pivotY: typeof entry.pivotY === "number" ? entry.pivotY : void 0,
|
|
374
|
+
anchors: entry.anchors,
|
|
375
|
+
emissiveCenter: entry.emissiveCenter,
|
|
376
|
+
emissivePower: entry.emissivePower,
|
|
377
|
+
char: entry.char,
|
|
378
|
+
actor: entry.actor,
|
|
379
|
+
clip: entry.clip,
|
|
380
|
+
dir: entry.dir,
|
|
381
|
+
frame: typeof entry.frame === "number" ? entry.frame : void 0,
|
|
382
|
+
frames: entry.frames,
|
|
383
|
+
loop: entry.loop
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
if (Array.isArray(rawFrames)) for (let i = 0; i < rawFrames.length; i++) {
|
|
387
|
+
const item = rawFrames[i];
|
|
388
|
+
addEntry(String(item?.filename ?? item?.name ?? item?.key ?? i), item);
|
|
389
|
+
}
|
|
390
|
+
else if (typeof rawFrames === "object") for (const [name, item] of Object.entries(rawFrames)) addEntry(name, item);
|
|
391
|
+
return tex;
|
|
392
|
+
}
|
|
253
393
|
remove(key) {
|
|
254
394
|
if (!this.exists(key)) return false;
|
|
255
395
|
const tex = this.list[key];
|
|
@@ -280,264 +420,7 @@ var TextureManager = class {
|
|
|
280
420
|
this.host = null;
|
|
281
421
|
}
|
|
282
422
|
};
|
|
283
|
-
|
|
284
|
-
var Camera = class {
|
|
285
|
-
x = 0;
|
|
286
|
-
y = 0;
|
|
287
|
-
width;
|
|
288
|
-
height;
|
|
289
|
-
scrollX = 0;
|
|
290
|
-
scrollY = 0;
|
|
291
|
-
zoom = 1;
|
|
292
|
-
alpha = 1;
|
|
293
|
-
originX = .5;
|
|
294
|
-
originY = .5;
|
|
295
|
-
roundPixels = false;
|
|
296
|
-
useBounds = false;
|
|
297
|
-
boundsX = 0;
|
|
298
|
-
boundsY = 0;
|
|
299
|
-
boundsWidth = 0;
|
|
300
|
-
boundsHeight = 0;
|
|
301
|
-
backgroundColor;
|
|
302
|
-
transparent;
|
|
303
|
-
worldView = {
|
|
304
|
-
x: 0,
|
|
305
|
-
y: 0,
|
|
306
|
-
width: 0,
|
|
307
|
-
height: 0,
|
|
308
|
-
right: 0,
|
|
309
|
-
bottom: 0
|
|
310
|
-
};
|
|
311
|
-
matrixCombined = createMatrix2D();
|
|
312
|
-
followTarget = null;
|
|
313
|
-
followLerpX = 1;
|
|
314
|
-
followLerpY = 1;
|
|
315
|
-
followOffsetX = 0;
|
|
316
|
-
followOffsetY = 0;
|
|
317
|
-
deadzoneW = 0;
|
|
318
|
-
deadzoneH = 0;
|
|
319
|
-
constructor(width, height, transparent = false, backgroundColor) {
|
|
320
|
-
this.width = Math.max(1, width);
|
|
321
|
-
this.height = Math.max(1, height);
|
|
322
|
-
this.transparent = transparent;
|
|
323
|
-
this.backgroundColor = backgroundColor !== void 0 ? parseColor(backgroundColor, transparent ? 0 : 1) : {
|
|
324
|
-
r: 0,
|
|
325
|
-
g: 0,
|
|
326
|
-
b: 0,
|
|
327
|
-
a: transparent ? 0 : 1
|
|
328
|
-
};
|
|
329
|
-
this.syncMetrics();
|
|
330
|
-
}
|
|
331
|
-
get displayWidth() {
|
|
332
|
-
return this.width / (this.zoom || 1);
|
|
333
|
-
}
|
|
334
|
-
get displayHeight() {
|
|
335
|
-
return this.height / (this.zoom || 1);
|
|
336
|
-
}
|
|
337
|
-
setBackgroundColor(color) {
|
|
338
|
-
this.backgroundColor = parseColor(color, 1);
|
|
339
|
-
this.transparent = this.backgroundColor.a <= 0;
|
|
340
|
-
return this;
|
|
341
|
-
}
|
|
342
|
-
setRoundPixels(v) {
|
|
343
|
-
this.roundPixels = !!v;
|
|
344
|
-
return this;
|
|
345
|
-
}
|
|
346
|
-
setOrigin(x = .5, y = x) {
|
|
347
|
-
this.originX = x;
|
|
348
|
-
this.originY = y;
|
|
349
|
-
this.syncMetrics();
|
|
350
|
-
return this;
|
|
351
|
-
}
|
|
352
|
-
setZoom(z) {
|
|
353
|
-
this.zoom = z > 0 ? z : 1;
|
|
354
|
-
if (this.useBounds) {
|
|
355
|
-
this.scrollX = this.clampX(this.scrollX);
|
|
356
|
-
this.scrollY = this.clampY(this.scrollY);
|
|
357
|
-
}
|
|
358
|
-
this.syncMetrics();
|
|
359
|
-
return this;
|
|
360
|
-
}
|
|
361
|
-
setScroll(x, y) {
|
|
362
|
-
this.scrollX = this.useBounds ? this.clampX(x) : x;
|
|
363
|
-
this.scrollY = this.useBounds ? this.clampY(y) : y;
|
|
364
|
-
this.syncMetrics();
|
|
365
|
-
return this;
|
|
366
|
-
}
|
|
367
|
-
setViewport(x, y, width, height) {
|
|
368
|
-
this.x = x;
|
|
369
|
-
this.y = y;
|
|
370
|
-
this.width = Math.max(1, width);
|
|
371
|
-
this.height = Math.max(1, height);
|
|
372
|
-
if (this.useBounds) {
|
|
373
|
-
this.scrollX = this.clampX(this.scrollX);
|
|
374
|
-
this.scrollY = this.clampY(this.scrollY);
|
|
375
|
-
}
|
|
376
|
-
this.syncMetrics();
|
|
377
|
-
return this;
|
|
378
|
-
}
|
|
379
|
-
setSize(width, height) {
|
|
380
|
-
this.width = Math.max(1, width);
|
|
381
|
-
this.height = Math.max(1, height);
|
|
382
|
-
if (this.useBounds) {
|
|
383
|
-
this.scrollX = this.clampX(this.scrollX);
|
|
384
|
-
this.scrollY = this.clampY(this.scrollY);
|
|
385
|
-
}
|
|
386
|
-
this.syncMetrics();
|
|
387
|
-
return this;
|
|
388
|
-
}
|
|
389
|
-
setAlpha(a) {
|
|
390
|
-
this.alpha = Math.max(0, Math.min(1, a));
|
|
391
|
-
return this;
|
|
392
|
-
}
|
|
393
|
-
setBounds(x, y, width, height) {
|
|
394
|
-
this.useBounds = true;
|
|
395
|
-
this.boundsX = x;
|
|
396
|
-
this.boundsY = y;
|
|
397
|
-
this.boundsWidth = width;
|
|
398
|
-
this.boundsHeight = height;
|
|
399
|
-
this.scrollX = this.clampX(this.scrollX);
|
|
400
|
-
this.scrollY = this.clampY(this.scrollY);
|
|
401
|
-
this.syncMetrics();
|
|
402
|
-
return this;
|
|
403
|
-
}
|
|
404
|
-
clampX(sx) {
|
|
405
|
-
if (!this.useBounds) return sx;
|
|
406
|
-
const ox = this.width * this.originX;
|
|
407
|
-
const dw = this.displayWidth;
|
|
408
|
-
if (dw >= this.boundsWidth) return this.boundsX + this.boundsWidth * .5 - ox;
|
|
409
|
-
const minSx = this.boundsX - ox + ox / this.zoom;
|
|
410
|
-
const maxSx = this.boundsX + this.boundsWidth - dw - ox + ox / this.zoom;
|
|
411
|
-
return sx < minSx ? minSx : sx > maxSx ? maxSx : sx;
|
|
412
|
-
}
|
|
413
|
-
clampY(sy) {
|
|
414
|
-
if (!this.useBounds) return sy;
|
|
415
|
-
const oy = this.height * this.originY;
|
|
416
|
-
const dh = this.displayHeight;
|
|
417
|
-
if (dh >= this.boundsHeight) return this.boundsY + this.boundsHeight * .5 - oy;
|
|
418
|
-
const minSy = this.boundsY - oy + oy / this.zoom;
|
|
419
|
-
const maxSy = this.boundsY + this.boundsHeight - dh - oy + oy / this.zoom;
|
|
420
|
-
return sy < minSy ? minSy : sy > maxSy ? maxSy : sy;
|
|
421
|
-
}
|
|
422
|
-
centerOn(x, y) {
|
|
423
|
-
const ox = this.width * this.originX;
|
|
424
|
-
const oy = this.height * this.originY;
|
|
425
|
-
return this.setScroll(x - ox, y - oy);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* One-line HiDPI camera + backing-buffer configurator: maps logical `(0, 0)..(viewportW, viewportH)`
|
|
429
|
-
* 1:1 onto crisp physical `viewportW * dpr` pixels without copy-pasting origin/scroll math.
|
|
430
|
-
* Returns the clamped `dpr` applied.
|
|
431
|
-
*/
|
|
432
|
-
configureHiDpi(scale, viewportWidth, viewportHeight, dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1, maxDpr = 2) {
|
|
433
|
-
const safeDpr = Math.min(Math.max(1, maxDpr), Math.max(1, Number.isFinite(dpr) ? dpr : 1));
|
|
434
|
-
const vw = Math.max(1, Math.round(viewportWidth));
|
|
435
|
-
const vh = Math.max(1, Math.round(viewportHeight));
|
|
436
|
-
scale.zoom = 1 / safeDpr;
|
|
437
|
-
scale.resize(Math.round(vw * safeDpr), Math.round(vh * safeDpr));
|
|
438
|
-
if (scale.canvas?.style) {
|
|
439
|
-
scale.canvas.style.width = `${vw}px`;
|
|
440
|
-
scale.canvas.style.height = `${vh}px`;
|
|
441
|
-
}
|
|
442
|
-
const ox = this.width * this.originX;
|
|
443
|
-
const oy = this.height * this.originY;
|
|
444
|
-
this.setZoom(safeDpr);
|
|
445
|
-
this.setScroll(ox / safeDpr - ox, oy / safeDpr - oy);
|
|
446
|
-
return safeDpr;
|
|
447
|
-
}
|
|
448
|
-
/** Convert canvas/backing-buffer coordinates `(screenX, screenY)` into world coordinates. */
|
|
449
|
-
screenToWorld(screenX, screenY, out = {
|
|
450
|
-
x: 0,
|
|
451
|
-
y: 0
|
|
452
|
-
}) {
|
|
453
|
-
const m = this.matrixCombined;
|
|
454
|
-
out.x = (screenX - m.tx) / (m.a || 1);
|
|
455
|
-
out.y = (screenY - m.ty) / (m.d || 1);
|
|
456
|
-
return out;
|
|
457
|
-
}
|
|
458
|
-
/** Convert world coordinates `(worldX, worldY)` into canvas/backing-buffer coordinates. */
|
|
459
|
-
worldToScreen(worldX, worldY, out = {
|
|
460
|
-
x: 0,
|
|
461
|
-
y: 0
|
|
462
|
-
}) {
|
|
463
|
-
const m = this.matrixCombined;
|
|
464
|
-
out.x = worldX * m.a + m.tx;
|
|
465
|
-
out.y = worldY * m.d + m.ty;
|
|
466
|
-
return out;
|
|
467
|
-
}
|
|
468
|
-
/** Lock or smoothly follow any `{ x, y }` actor/point (frame-rate independent lerp + optional deadzone). */
|
|
469
|
-
startFollow(target, options = {}) {
|
|
470
|
-
this.followTarget = target;
|
|
471
|
-
this.followLerpX = Math.max(.001, Math.min(1, options.lerpX ?? 1));
|
|
472
|
-
this.followLerpY = Math.max(.001, Math.min(1, options.lerpY ?? this.followLerpX));
|
|
473
|
-
this.followOffsetX = options.offsetX ?? 0;
|
|
474
|
-
this.followOffsetY = options.offsetY ?? 0;
|
|
475
|
-
this.deadzoneW = Math.max(0, options.deadzoneWidth ?? 0);
|
|
476
|
-
this.deadzoneH = Math.max(0, options.deadzoneHeight ?? 0);
|
|
477
|
-
return this;
|
|
478
|
-
}
|
|
479
|
-
stopFollow() {
|
|
480
|
-
this.followTarget = null;
|
|
481
|
-
return this;
|
|
482
|
-
}
|
|
483
|
-
/** Internal per-step follow update invoked automatically by `Game.step()` before rendering. */
|
|
484
|
-
stepFollow(deltaMs) {
|
|
485
|
-
const target = this.followTarget;
|
|
486
|
-
if (!target) return;
|
|
487
|
-
const tx = target.x + this.followOffsetX;
|
|
488
|
-
const ty = target.y + this.followOffsetY;
|
|
489
|
-
const curCx = this.worldView.x + this.worldView.width * .5;
|
|
490
|
-
const curCy = this.worldView.y + this.worldView.height * .5;
|
|
491
|
-
let wantCx = curCx;
|
|
492
|
-
let wantCy = curCy;
|
|
493
|
-
const halfDzW = this.deadzoneW * .5;
|
|
494
|
-
const halfDzH = this.deadzoneH * .5;
|
|
495
|
-
if (tx < curCx - halfDzW) wantCx = tx + halfDzW;
|
|
496
|
-
else if (tx > curCx + halfDzW) wantCx = tx - halfDzW;
|
|
497
|
-
if (ty < curCy - halfDzH) wantCy = ty + halfDzH;
|
|
498
|
-
else if (ty > curCy + halfDzH) wantCy = ty - halfDzH;
|
|
499
|
-
const frames = Math.max(.1, deltaMs / (1e3 / 60));
|
|
500
|
-
const ax = this.followLerpX >= 1 ? 1 : 1 - Math.pow(1 - this.followLerpX, frames);
|
|
501
|
-
const ay = this.followLerpY >= 1 ? 1 : 1 - Math.pow(1 - this.followLerpY, frames);
|
|
502
|
-
const nextCx = curCx + (wantCx - curCx) * ax;
|
|
503
|
-
const nextCy = curCy + (wantCy - curCy) * ay;
|
|
504
|
-
const ox = this.width * this.originX;
|
|
505
|
-
const oy = this.height * this.originY;
|
|
506
|
-
const z = this.zoom || 1;
|
|
507
|
-
const nextSx = nextCx - this.worldView.width * .5 - ox + ox / z;
|
|
508
|
-
const nextSy = nextCy - this.worldView.height * .5 - oy + oy / z;
|
|
509
|
-
this.setScroll(nextSx, nextSy);
|
|
510
|
-
}
|
|
511
|
-
/** Recompute `worldView` and world->canvas `matrixCombined`. */
|
|
512
|
-
syncMetrics() {
|
|
513
|
-
const z = this.zoom || 1;
|
|
514
|
-
const ox = this.width * this.originX;
|
|
515
|
-
const oy = this.height * this.originY;
|
|
516
|
-
const sx = this.roundPixels ? Math.round(this.scrollX) : this.scrollX;
|
|
517
|
-
const sy = this.roundPixels ? Math.round(this.scrollY) : this.scrollY;
|
|
518
|
-
const dw = this.width / z;
|
|
519
|
-
const dh = this.height / z;
|
|
520
|
-
const vx = sx + ox - ox / z;
|
|
521
|
-
const vy = sy + oy - oy / z;
|
|
522
|
-
this.worldView.x = vx;
|
|
523
|
-
this.worldView.y = vy;
|
|
524
|
-
this.worldView.width = dw;
|
|
525
|
-
this.worldView.height = dh;
|
|
526
|
-
this.worldView.right = vx + dw;
|
|
527
|
-
this.worldView.bottom = vy + dh;
|
|
528
|
-
const m = this.matrixCombined;
|
|
529
|
-
m.a = z;
|
|
530
|
-
m.b = 0;
|
|
531
|
-
m.c = 0;
|
|
532
|
-
m.d = z;
|
|
533
|
-
m.tx = (-sx - ox) * z + ox + this.x;
|
|
534
|
-
m.ty = (-sy - oy) * z + oy + this.y;
|
|
535
|
-
m.scaleX = z;
|
|
536
|
-
m.scaleY = z;
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
// src/sdf-panel.ts
|
|
540
|
-
const MAX_PANELS = 1024;
|
|
423
|
+
const MAX_PANELS = 4096;
|
|
541
424
|
const MAX_VERTS$3 = MAX_PANELS * 4;
|
|
542
425
|
const VERT_FLOATS$3 = 18;
|
|
543
426
|
const VERT_STRIDE$3 = 72;
|
|
@@ -838,6 +721,100 @@ var SdfPanelBatcher = class {
|
|
|
838
721
|
u32[off + 17] = glintAbgr;
|
|
839
722
|
this.panelCount++;
|
|
840
723
|
}
|
|
724
|
+
/**
|
|
725
|
+
* Fast-path SDF quad emitter for symmetric-radius shapes (`Graphics` circles/rounded-rects & `ShapeBatchObject`)
|
|
726
|
+
* with `pxScale` precomputed once per node/matrix. Caller ensures `pending < MAX_SDF_BATCH_QUADS` before calling.
|
|
727
|
+
*/
|
|
728
|
+
pushSimple(m, pxScale, rx, ry, w, h, radius, fillAbgr, borderAbgr, borderWidth, pixelStep = 0) {
|
|
729
|
+
const maxR = Math.min(w, h) * .5;
|
|
730
|
+
const rad = radius <= 0 ? 0 : radius >= maxR ? maxR : radius;
|
|
731
|
+
const bw = borderWidth <= 0 ? 0 : borderWidth >= maxR ? maxR : borderWidth;
|
|
732
|
+
const step = pixelStep > 0 ? pixelStep : 0;
|
|
733
|
+
const pad = step > 0 ? 0 : 1 / pxScale;
|
|
734
|
+
const lx0 = rx - pad, ly0 = ry - pad;
|
|
735
|
+
const lx1 = rx + w + pad, ly1 = ry + h + pad;
|
|
736
|
+
const u0 = -pad, v0 = -pad, u1 = w + pad, v1 = h + pad;
|
|
737
|
+
const a = m.a, b = m.b, c = m.c, d = m.d, tx = m.tx, ty = m.ty;
|
|
738
|
+
const f32 = this.vertF32;
|
|
739
|
+
const u32 = this.vertU32;
|
|
740
|
+
let off = this.panelCount * 4 * VERT_FLOATS$3;
|
|
741
|
+
f32[off] = a * lx0 + c * ly0 + tx;
|
|
742
|
+
f32[off + 1] = b * lx0 + d * ly0 + ty;
|
|
743
|
+
f32[off + 2] = u0;
|
|
744
|
+
f32[off + 3] = v0;
|
|
745
|
+
f32[off + 4] = w;
|
|
746
|
+
f32[off + 5] = h;
|
|
747
|
+
f32[off + 6] = 0;
|
|
748
|
+
f32[off + 7] = rad;
|
|
749
|
+
f32[off + 8] = rad;
|
|
750
|
+
f32[off + 9] = rad;
|
|
751
|
+
f32[off + 10] = rad;
|
|
752
|
+
f32[off + 11] = bw;
|
|
753
|
+
f32[off + 12] = step;
|
|
754
|
+
f32[off + 13] = pxScale;
|
|
755
|
+
f32[off + 14] = 0;
|
|
756
|
+
u32[off + 15] = fillAbgr;
|
|
757
|
+
u32[off + 16] = borderAbgr;
|
|
758
|
+
u32[off + 17] = 0;
|
|
759
|
+
off += VERT_FLOATS$3;
|
|
760
|
+
f32[off] = a * lx1 + c * ly0 + tx;
|
|
761
|
+
f32[off + 1] = b * lx1 + d * ly0 + ty;
|
|
762
|
+
f32[off + 2] = u1;
|
|
763
|
+
f32[off + 3] = v0;
|
|
764
|
+
f32[off + 4] = w;
|
|
765
|
+
f32[off + 5] = h;
|
|
766
|
+
f32[off + 6] = 0;
|
|
767
|
+
f32[off + 7] = rad;
|
|
768
|
+
f32[off + 8] = rad;
|
|
769
|
+
f32[off + 9] = rad;
|
|
770
|
+
f32[off + 10] = rad;
|
|
771
|
+
f32[off + 11] = bw;
|
|
772
|
+
f32[off + 12] = step;
|
|
773
|
+
f32[off + 13] = pxScale;
|
|
774
|
+
f32[off + 14] = 0;
|
|
775
|
+
u32[off + 15] = fillAbgr;
|
|
776
|
+
u32[off + 16] = borderAbgr;
|
|
777
|
+
u32[off + 17] = 0;
|
|
778
|
+
off += VERT_FLOATS$3;
|
|
779
|
+
f32[off] = a * lx1 + c * ly1 + tx;
|
|
780
|
+
f32[off + 1] = b * lx1 + d * ly1 + ty;
|
|
781
|
+
f32[off + 2] = u1;
|
|
782
|
+
f32[off + 3] = v1;
|
|
783
|
+
f32[off + 4] = w;
|
|
784
|
+
f32[off + 5] = h;
|
|
785
|
+
f32[off + 6] = 0;
|
|
786
|
+
f32[off + 7] = rad;
|
|
787
|
+
f32[off + 8] = rad;
|
|
788
|
+
f32[off + 9] = rad;
|
|
789
|
+
f32[off + 10] = rad;
|
|
790
|
+
f32[off + 11] = bw;
|
|
791
|
+
f32[off + 12] = step;
|
|
792
|
+
f32[off + 13] = pxScale;
|
|
793
|
+
f32[off + 14] = 0;
|
|
794
|
+
u32[off + 15] = fillAbgr;
|
|
795
|
+
u32[off + 16] = borderAbgr;
|
|
796
|
+
u32[off + 17] = 0;
|
|
797
|
+
off += VERT_FLOATS$3;
|
|
798
|
+
f32[off] = a * lx0 + c * ly1 + tx;
|
|
799
|
+
f32[off + 1] = b * lx0 + d * ly1 + ty;
|
|
800
|
+
f32[off + 2] = u0;
|
|
801
|
+
f32[off + 3] = v1;
|
|
802
|
+
f32[off + 4] = w;
|
|
803
|
+
f32[off + 5] = h;
|
|
804
|
+
f32[off + 6] = 0;
|
|
805
|
+
f32[off + 7] = rad;
|
|
806
|
+
f32[off + 8] = rad;
|
|
807
|
+
f32[off + 9] = rad;
|
|
808
|
+
f32[off + 10] = rad;
|
|
809
|
+
f32[off + 11] = bw;
|
|
810
|
+
f32[off + 12] = step;
|
|
811
|
+
f32[off + 13] = pxScale;
|
|
812
|
+
f32[off + 14] = 0;
|
|
813
|
+
u32[off + 15] = fillAbgr;
|
|
814
|
+
u32[off + 16] = borderAbgr;
|
|
815
|
+
u32[off + 17] = 0;
|
|
816
|
+
this.panelCount++;
|
|
817
|
+
}
|
|
841
818
|
flush(resW, resH) {
|
|
842
819
|
const count = this.panelCount;
|
|
843
820
|
if (count === 0 || !this.program || !this.vbo || !this.quadIbo) return false;
|
|
@@ -1791,6 +1768,19 @@ function buildLineSeg(x0, y0, x1, y1, halfW, rgb, alpha) {
|
|
|
1791
1768
|
const ny = dx / len * halfW;
|
|
1792
1769
|
buildQuadPts(x0 + nx, y0 + ny, x1 + nx, y1 + ny, x1 - nx, y1 - ny, x0 - nx, y0 - ny, rgb, alpha);
|
|
1793
1770
|
}
|
|
1771
|
+
const UNIT_COS = [];
|
|
1772
|
+
const UNIT_SIN = [];
|
|
1773
|
+
for (let segs = 6; segs <= 64; segs++) {
|
|
1774
|
+
const cs = new Float32Array(segs);
|
|
1775
|
+
const sn = new Float32Array(segs);
|
|
1776
|
+
const step = Math.PI * 2 / segs;
|
|
1777
|
+
for (let i = 0; i < segs; i++) {
|
|
1778
|
+
cs[i] = Math.cos(i * step);
|
|
1779
|
+
sn[i] = Math.sin(i * step);
|
|
1780
|
+
}
|
|
1781
|
+
UNIT_COS[segs] = cs;
|
|
1782
|
+
UNIT_SIN[segs] = sn;
|
|
1783
|
+
}
|
|
1794
1784
|
function buildEllipseFill(cx, cy, rx, ry, scale, rgb, alpha) {
|
|
1795
1785
|
if (rx <= 0 || ry <= 0) return;
|
|
1796
1786
|
buildHasScaleCurves = true;
|
|
@@ -1807,13 +1797,11 @@ function buildEllipseFill(cx, cy, rx, ry, scale, rgb, alpha) {
|
|
|
1807
1797
|
buildRgb[baseV] = rgb;
|
|
1808
1798
|
buildAlphas[baseV] = alpha;
|
|
1809
1799
|
buildAbgr1[baseV] = abgr;
|
|
1810
|
-
const
|
|
1800
|
+
const csLut = UNIT_COS[segs];
|
|
1801
|
+
const snLut = UNIT_SIN[segs];
|
|
1811
1802
|
for (let i = 0; i < segs; i++) {
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
const py = cy + Math.sin(ang) * ry;
|
|
1815
|
-
buildXy[xyI++] = px;
|
|
1816
|
-
buildXy[xyI++] = py;
|
|
1803
|
+
buildXy[xyI++] = cx + csLut[i] * rx;
|
|
1804
|
+
buildXy[xyI++] = cy + snLut[i] * ry;
|
|
1817
1805
|
buildRgb[baseV + 1 + i] = rgb;
|
|
1818
1806
|
buildAlphas[baseV + 1 + i] = alpha;
|
|
1819
1807
|
buildAbgr1[baseV + 1 + i] = abgr;
|
|
@@ -1841,10 +1829,10 @@ function buildEllipseStroke(cx, cy, rx, ry, lw, scale, rgb, alpha) {
|
|
|
1841
1829
|
const baseV = buildV;
|
|
1842
1830
|
const abgr = packColorAbgr(rgb, alpha);
|
|
1843
1831
|
let xyI = baseV * 2;
|
|
1844
|
-
const
|
|
1832
|
+
const csLut = UNIT_COS[segs];
|
|
1833
|
+
const snLut = UNIT_SIN[segs];
|
|
1845
1834
|
for (let i = 0; i < segs; i++) {
|
|
1846
|
-
const
|
|
1847
|
-
const cs = Math.cos(ang), sn = Math.sin(ang);
|
|
1835
|
+
const cs = csLut[i], sn = snLut[i];
|
|
1848
1836
|
const vi = baseV + i * 2;
|
|
1849
1837
|
buildXy[xyI++] = cx + cs * orx;
|
|
1850
1838
|
buildXy[xyI++] = cy + sn * ory;
|
|
@@ -2785,11 +2773,7 @@ var RendererGl = class extends EventEmitter {
|
|
|
2785
2773
|
const sdf = this.sdfBatcher;
|
|
2786
2774
|
if (!sdf || sdf.pending === 0 || this.contextLost) return;
|
|
2787
2775
|
const count = sdf.pending;
|
|
2788
|
-
if (!this.batchStateBound)
|
|
2789
|
-
const gl = this.gl;
|
|
2790
|
-
if (this.curBlend === BlendModes.ADD) gl.blendFunc(gl.ONE, gl.ONE);
|
|
2791
|
-
else gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
|
|
2792
|
-
}
|
|
2776
|
+
if (!this.batchStateBound) applyGlBlendMode(this.gl, this.curBlend);
|
|
2793
2777
|
if (sdf.flush(this.width, this.height)) {
|
|
2794
2778
|
this.curDrawCalls++;
|
|
2795
2779
|
this.curFlushes++;
|
|
@@ -3053,7 +3037,11 @@ var RendererGl = class extends EventEmitter {
|
|
|
3053
3037
|
if (!frame || frame.width <= 0 || frame.height <= 0) return;
|
|
3054
3038
|
const ox = img.displayOriginX;
|
|
3055
3039
|
const oy = img.displayOriginY;
|
|
3056
|
-
|
|
3040
|
+
const pivotMirrored = frame.customPivot && !img.customOrigin && !img.isCropped;
|
|
3041
|
+
let x0 = pivotMirrored && img.flipX ? ox - img.width : -ox;
|
|
3042
|
+
let y0 = pivotMirrored && img.flipY ? oy - img.height : -oy;
|
|
3043
|
+
let x1 = pivotMirrored && img.flipX ? ox : img.width - ox;
|
|
3044
|
+
let y1 = pivotMirrored && img.flipY ? oy : img.height - oy;
|
|
3057
3045
|
let u0 = frame.u0, v0 = frame.v0, u1 = frame.u1, v1 = frame.v1;
|
|
3058
3046
|
if (img.isCropped) {
|
|
3059
3047
|
const fw = frame.width || 1, fh = frame.height || 1;
|
|
@@ -3292,6 +3280,10 @@ var RendererGl = class extends EventEmitter {
|
|
|
3292
3280
|
}
|
|
3293
3281
|
renderGraphics(g, m, alpha) {
|
|
3294
3282
|
if (g.opLen === 0) return;
|
|
3283
|
+
if (g._hasSdfShapes && !g._hasNonSdfOps && this.sdfBatcher) {
|
|
3284
|
+
this.renderGraphicsSdf(g, m, alpha);
|
|
3285
|
+
return;
|
|
3286
|
+
}
|
|
3295
3287
|
let cache = g._glCache;
|
|
3296
3288
|
let scaleBucket = 2;
|
|
3297
3289
|
if (!cache || cache.version !== g.version || cache.hasScaleCurves) {
|
|
@@ -3433,8 +3425,253 @@ var RendererGl = class extends EventEmitter {
|
|
|
3433
3425
|
if (this.pixelAaBatcher?.pending) this.flushPixelAa();
|
|
3434
3426
|
if (this.indexCount > 0) this.flush();
|
|
3435
3427
|
this.setBlend(panel.blendMode);
|
|
3428
|
+
if (this.sdfBatcher && this.sdfBatcher.pending >= 4096) this.flushSdf();
|
|
3436
3429
|
this.sdfBatcher?.push(m, ox, oy, w, h, panel.radiusTL, panel.radiusTR, panel.radiusBR, panel.radiusBL, panel.fillColor, fillAlpha, panel.borderColor, borderAlpha, borderW, panel.pixelStep, panel.openSide, panel.topGlintColor, panel.topGlintAlpha, panel.topGlintHeight, this.width, this.height);
|
|
3437
3430
|
}
|
|
3431
|
+
renderGraphicsSdf(g, m, alpha) {
|
|
3432
|
+
const sdf = this.sdfBatcher;
|
|
3433
|
+
if (!sdf) return;
|
|
3434
|
+
if (this.activeCustomHandler) this.flushCustomHandler();
|
|
3435
|
+
if (this.msdfBatcher?.pending) this.flushMsdf();
|
|
3436
|
+
if (this.pixelAaBatcher?.pending) this.flushPixelAa();
|
|
3437
|
+
if (this.indexCount > 0) this.flush();
|
|
3438
|
+
this.setBlend(g.blendMode);
|
|
3439
|
+
const sx = Math.hypot(m.a, m.b);
|
|
3440
|
+
const sy = Math.hypot(m.c, m.d);
|
|
3441
|
+
const pxScale = Math.max(.001, Math.min(sx, sy));
|
|
3442
|
+
gfxStateStack.length = 0;
|
|
3443
|
+
let fillRgb = WHITE_RGB, fillA = 1;
|
|
3444
|
+
let lineW = 1, lineRgb = WHITE_RGB, lineA = 1;
|
|
3445
|
+
let cachedFillRgb = -1, cachedFillA = -1, fillAbgr = 0;
|
|
3446
|
+
let cachedLineRgb = -1, cachedLineA = -1, lineAbgr = 0;
|
|
3447
|
+
const getFillAbgr = () => {
|
|
3448
|
+
const eff = fillA * alpha;
|
|
3449
|
+
if (fillRgb !== cachedFillRgb || eff !== cachedFillA) {
|
|
3450
|
+
cachedFillRgb = fillRgb;
|
|
3451
|
+
cachedFillA = eff;
|
|
3452
|
+
fillAbgr = packColorAbgr(fillRgb, eff);
|
|
3453
|
+
}
|
|
3454
|
+
return fillAbgr;
|
|
3455
|
+
};
|
|
3456
|
+
const getLineAbgr = () => {
|
|
3457
|
+
const eff = lineA * alpha;
|
|
3458
|
+
if (lineRgb !== cachedLineRgb || eff !== cachedLineA) {
|
|
3459
|
+
cachedLineRgb = lineRgb;
|
|
3460
|
+
cachedLineA = eff;
|
|
3461
|
+
lineAbgr = packColorAbgr(lineRgb, eff);
|
|
3462
|
+
}
|
|
3463
|
+
return lineAbgr;
|
|
3464
|
+
};
|
|
3465
|
+
const ops = g.ops;
|
|
3466
|
+
const nums = g.nums;
|
|
3467
|
+
let ni = 0;
|
|
3468
|
+
for (let oi = 0; oi < g.opLen; oi++) switch (ops[oi]) {
|
|
3469
|
+
case 22:
|
|
3470
|
+
gfxStateStack.push(fillRgb, fillA, lineW, lineRgb, lineA);
|
|
3471
|
+
break;
|
|
3472
|
+
case 23:
|
|
3473
|
+
if (gfxStateStack.length >= 5) {
|
|
3474
|
+
lineA = gfxStateStack.pop();
|
|
3475
|
+
lineRgb = gfxStateStack.pop();
|
|
3476
|
+
lineW = gfxStateStack.pop();
|
|
3477
|
+
fillA = gfxStateStack.pop();
|
|
3478
|
+
fillRgb = gfxStateStack.pop();
|
|
3479
|
+
}
|
|
3480
|
+
break;
|
|
3481
|
+
case 1:
|
|
3482
|
+
fillRgb = nums[ni++];
|
|
3483
|
+
fillA = nums[ni++];
|
|
3484
|
+
break;
|
|
3485
|
+
case 2:
|
|
3486
|
+
lineW = nums[ni++];
|
|
3487
|
+
lineRgb = nums[ni++];
|
|
3488
|
+
lineA = nums[ni++];
|
|
3489
|
+
break;
|
|
3490
|
+
case 3: {
|
|
3491
|
+
const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
|
|
3492
|
+
if (fillA * alpha > 0 && w !== 0 && h !== 0) {
|
|
3493
|
+
const rx = w < 0 ? x + w : x, ry = h < 0 ? y + h : y;
|
|
3494
|
+
const rw = Math.abs(w), rh = Math.abs(h);
|
|
3495
|
+
if (!this.isOffscreen(m, rx, ry, rx + rw, ry + rh)) {
|
|
3496
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3497
|
+
sdf.pushSimple(m, pxScale, rx, ry, rw, rh, 0, getFillAbgr(), 0, 0);
|
|
3498
|
+
} else this.curCulled++;
|
|
3499
|
+
}
|
|
3500
|
+
break;
|
|
3501
|
+
}
|
|
3502
|
+
case 4: {
|
|
3503
|
+
const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++];
|
|
3504
|
+
if (lineA * alpha > 0 && lineW > 0 && w !== 0 && h !== 0) {
|
|
3505
|
+
const hw = lineW * .5;
|
|
3506
|
+
const rx = (w < 0 ? x + w : x) - hw, ry = (h < 0 ? y + h : y) - hw;
|
|
3507
|
+
const rw = Math.abs(w) + lineW, rh = Math.abs(h) + lineW;
|
|
3508
|
+
if (!this.isOffscreen(m, rx, ry, rx + rw, ry + rh)) {
|
|
3509
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3510
|
+
sdf.pushSimple(m, pxScale, rx, ry, rw, rh, 0, 0, getLineAbgr(), lineW);
|
|
3511
|
+
} else this.curCulled++;
|
|
3512
|
+
}
|
|
3513
|
+
break;
|
|
3514
|
+
}
|
|
3515
|
+
case 5: {
|
|
3516
|
+
const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
|
|
3517
|
+
if (fillA * alpha > 0 && w > 0 && h > 0) {
|
|
3518
|
+
if (!this.isOffscreen(m, x, y, x + w, y + h)) {
|
|
3519
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3520
|
+
sdf.pushSimple(m, pxScale, x, y, w, h, r, getFillAbgr(), 0, 0);
|
|
3521
|
+
} else this.curCulled++;
|
|
3522
|
+
}
|
|
3523
|
+
break;
|
|
3524
|
+
}
|
|
3525
|
+
case 6: {
|
|
3526
|
+
const x = nums[ni++], y = nums[ni++], w = nums[ni++], h = nums[ni++], r = nums[ni++];
|
|
3527
|
+
if (lineA * alpha > 0 && lineW > 0 && w > 0 && h > 0) {
|
|
3528
|
+
const hw = lineW * .5;
|
|
3529
|
+
const rx = x - hw, ry = y - hw, rw = w + lineW, rh = h + lineW;
|
|
3530
|
+
if (!this.isOffscreen(m, rx, ry, rx + rw, ry + rh)) {
|
|
3531
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3532
|
+
sdf.pushSimple(m, pxScale, rx, ry, rw, rh, Math.max(0, r) + hw, 0, getLineAbgr(), lineW);
|
|
3533
|
+
} else this.curCulled++;
|
|
3534
|
+
}
|
|
3535
|
+
break;
|
|
3536
|
+
}
|
|
3537
|
+
case 7: {
|
|
3538
|
+
const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
|
|
3539
|
+
if (fillA * alpha > 0 && r > 0) {
|
|
3540
|
+
const d = r * 2, rx = cx - r, ry = cy - r;
|
|
3541
|
+
if (!this.isOffscreen(m, rx, ry, rx + d, ry + d)) {
|
|
3542
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3543
|
+
sdf.pushSimple(m, pxScale, rx, ry, d, d, r, getFillAbgr(), 0, 0);
|
|
3544
|
+
} else this.curCulled++;
|
|
3545
|
+
}
|
|
3546
|
+
break;
|
|
3547
|
+
}
|
|
3548
|
+
case 8: {
|
|
3549
|
+
const cx = nums[ni++], cy = nums[ni++], r = nums[ni++];
|
|
3550
|
+
if (lineA * alpha > 0 && lineW > 0 && r > 0) {
|
|
3551
|
+
const ro = r + lineW * .5, d = ro * 2, rx = cx - ro, ry = cy - ro;
|
|
3552
|
+
if (!this.isOffscreen(m, rx, ry, rx + d, ry + d)) {
|
|
3553
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3554
|
+
sdf.pushSimple(m, pxScale, rx, ry, d, d, ro, 0, getLineAbgr(), lineW);
|
|
3555
|
+
} else this.curCulled++;
|
|
3556
|
+
}
|
|
3557
|
+
break;
|
|
3558
|
+
}
|
|
3559
|
+
case 9: {
|
|
3560
|
+
const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
|
|
3561
|
+
if (fillA * alpha > 0 && w > 0 && h > 0) {
|
|
3562
|
+
const rx = cx - w * .5, ry = cy - h * .5;
|
|
3563
|
+
if (!this.isOffscreen(m, rx, ry, rx + w, ry + h)) {
|
|
3564
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3565
|
+
sdf.pushSimple(m, pxScale, rx, ry, w, h, w * .5, getFillAbgr(), 0, 0);
|
|
3566
|
+
} else this.curCulled++;
|
|
3567
|
+
}
|
|
3568
|
+
break;
|
|
3569
|
+
}
|
|
3570
|
+
case 10: {
|
|
3571
|
+
const cx = nums[ni++], cy = nums[ni++], w = nums[ni++], h = nums[ni++];
|
|
3572
|
+
if (lineA * alpha > 0 && lineW > 0 && w > 0 && h > 0) {
|
|
3573
|
+
const rw = w + lineW, rh = h + lineW, rx = cx - rw * .5, ry = cy - rh * .5;
|
|
3574
|
+
if (!this.isOffscreen(m, rx, ry, rx + rw, ry + rh)) {
|
|
3575
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3576
|
+
sdf.pushSimple(m, pxScale, rx, ry, rw, rh, rw * .5, 0, getLineAbgr(), lineW);
|
|
3577
|
+
} else this.curCulled++;
|
|
3578
|
+
}
|
|
3579
|
+
break;
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
renderShapeBatch(batch, m, alpha) {
|
|
3584
|
+
const sdf = this.sdfBatcher;
|
|
3585
|
+
const cols = batch.columns;
|
|
3586
|
+
if (!sdf || !cols || cols.count <= 0) return;
|
|
3587
|
+
const n = Math.min(cols.count, batch.maxCount, cols.x.length, cols.y.length);
|
|
3588
|
+
if (n <= 0) return;
|
|
3589
|
+
if (this.activeCustomHandler) this.flushCustomHandler();
|
|
3590
|
+
if (this.msdfBatcher?.pending) this.flushMsdf();
|
|
3591
|
+
if (this.pixelAaBatcher?.pending) this.flushPixelAa();
|
|
3592
|
+
if (this.indexCount > 0) this.flush();
|
|
3593
|
+
this.setBlend(batch.blendMode);
|
|
3594
|
+
const sx = Math.hypot(m.a, m.b);
|
|
3595
|
+
const sy = Math.hypot(m.c, m.d);
|
|
3596
|
+
const basePxScale = Math.max(.001, Math.min(sx, sy));
|
|
3597
|
+
const oxRatio = batch.originX;
|
|
3598
|
+
const oyRatio = batch.originY;
|
|
3599
|
+
const step = batch.pixelStep;
|
|
3600
|
+
const wCol = typeof cols.width === "object" && cols.width ? cols.width : null;
|
|
3601
|
+
const wDef = typeof cols.width === "number" ? cols.width : batch.defaultWidth;
|
|
3602
|
+
const hCol = typeof cols.height === "object" && cols.height ? cols.height : null;
|
|
3603
|
+
const hDef = typeof cols.height === "number" ? cols.height : typeof cols.width === "number" ? cols.width : batch.defaultHeight;
|
|
3604
|
+
const rCol = typeof cols.radius === "object" && cols.radius ? cols.radius : null;
|
|
3605
|
+
const rDef = typeof cols.radius === "number" ? cols.radius : batch.defaultRadius;
|
|
3606
|
+
const fcCol = typeof cols.fillColor === "object" && cols.fillColor ? cols.fillColor : null;
|
|
3607
|
+
const fcDef = typeof cols.fillColor === "number" ? cols.fillColor : batch.defaultFillColor;
|
|
3608
|
+
const faCol = typeof cols.fillAlpha === "object" && cols.fillAlpha ? cols.fillAlpha : null;
|
|
3609
|
+
const faDef = typeof cols.fillAlpha === "number" ? cols.fillAlpha : batch.defaultFillAlpha;
|
|
3610
|
+
const bcCol = typeof cols.borderColor === "object" && cols.borderColor ? cols.borderColor : null;
|
|
3611
|
+
const bcDef = typeof cols.borderColor === "number" ? cols.borderColor : batch.defaultBorderColor;
|
|
3612
|
+
const baCol = typeof cols.borderAlpha === "object" && cols.borderAlpha ? cols.borderAlpha : null;
|
|
3613
|
+
const baDef = typeof cols.borderAlpha === "number" ? cols.borderAlpha : batch.defaultBorderAlpha;
|
|
3614
|
+
const bwCol = typeof cols.borderWidth === "object" && cols.borderWidth ? cols.borderWidth : null;
|
|
3615
|
+
const bwDef = typeof cols.borderWidth === "number" ? cols.borderWidth : batch.defaultBorderWidth;
|
|
3616
|
+
const rotCol = cols.rotation ?? null;
|
|
3617
|
+
const ordCol = cols.order ?? null;
|
|
3618
|
+
let lastFc = -1, lastFa = -1, fillAbgr = 0;
|
|
3619
|
+
let lastBc = -1, lastBa = -1, borderAbgr = 0;
|
|
3620
|
+
const rotMat = this.sfMat;
|
|
3621
|
+
for (let i = 0; i < n; i++) {
|
|
3622
|
+
const s = ordCol ? ordCol[i] : i;
|
|
3623
|
+
const w = wCol ? wCol[s] : wDef;
|
|
3624
|
+
const h = hCol ? hCol[s] : wCol ? w : hDef;
|
|
3625
|
+
if (w <= 0 || h <= 0) continue;
|
|
3626
|
+
const fa = (faCol ? faCol[s] : faDef) * alpha;
|
|
3627
|
+
const bw = bwCol ? bwCol[s] : bwDef;
|
|
3628
|
+
const ba = bw > 0 ? (baCol ? baCol[s] : baDef) * alpha : 0;
|
|
3629
|
+
if (fa <= 0 && ba <= 0) continue;
|
|
3630
|
+
const fc = fcCol ? fcCol[s] : fcDef;
|
|
3631
|
+
if (fc !== lastFc || fa !== lastFa) {
|
|
3632
|
+
lastFc = fc;
|
|
3633
|
+
lastFa = fa;
|
|
3634
|
+
fillAbgr = packColorAbgr(fc, fa);
|
|
3635
|
+
}
|
|
3636
|
+
if (bw > 0) {
|
|
3637
|
+
const bc = bcCol ? bcCol[s] : bcDef;
|
|
3638
|
+
if (bc !== lastBc || ba !== lastBa) {
|
|
3639
|
+
lastBc = bc;
|
|
3640
|
+
lastBa = ba;
|
|
3641
|
+
borderAbgr = packColorAbgr(bc, ba);
|
|
3642
|
+
}
|
|
3643
|
+
} else borderAbgr = 0;
|
|
3644
|
+
const rad = rCol ? rCol[s] : rDef;
|
|
3645
|
+
const px = cols.x[s];
|
|
3646
|
+
const py = cols.y[s];
|
|
3647
|
+
const rot = rotCol ? rotCol[s] : 0;
|
|
3648
|
+
if (rot === 0) {
|
|
3649
|
+
const rx = px - w * oxRatio;
|
|
3650
|
+
const ry = py - h * oyRatio;
|
|
3651
|
+
if (this.isOffscreen(m, rx, ry, rx + w, ry + h)) {
|
|
3652
|
+
this.curCulled++;
|
|
3653
|
+
continue;
|
|
3654
|
+
}
|
|
3655
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3656
|
+
sdf.pushSimple(m, basePxScale, rx, ry, w, h, rad, fillAbgr, borderAbgr, bw, step);
|
|
3657
|
+
} else {
|
|
3658
|
+
const cs = Math.cos(rot), sn = Math.sin(rot);
|
|
3659
|
+
rotMat.a = m.a * cs + m.c * sn;
|
|
3660
|
+
rotMat.b = m.b * cs + m.d * sn;
|
|
3661
|
+
rotMat.c = m.a * -sn + m.c * cs;
|
|
3662
|
+
rotMat.d = m.b * -sn + m.d * cs;
|
|
3663
|
+
rotMat.tx = m.a * px + m.c * py + m.tx;
|
|
3664
|
+
rotMat.ty = m.b * px + m.d * py + m.ty;
|
|
3665
|
+
const rx = -w * oxRatio, ry = -h * oyRatio;
|
|
3666
|
+
if (this.isOffscreen(rotMat, rx, ry, rx + w, ry + h)) {
|
|
3667
|
+
this.curCulled++;
|
|
3668
|
+
continue;
|
|
3669
|
+
}
|
|
3670
|
+
if (sdf.pending >= 4096) this.flushSdf();
|
|
3671
|
+
sdf.pushSimple(rotMat, basePxScale, rx, ry, w, h, rad, fillAbgr, borderAbgr, bw, step);
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3438
3675
|
renderMsdfIcon(icon, m, alpha) {
|
|
3439
3676
|
const w = icon.width;
|
|
3440
3677
|
const h = icon.height;
|
|
@@ -3679,7 +3916,25 @@ var RendererGl = class extends EventEmitter {
|
|
|
3679
3916
|
width: w,
|
|
3680
3917
|
height: h,
|
|
3681
3918
|
texture: tex,
|
|
3919
|
+
camera: new Camera(w, h, true),
|
|
3682
3920
|
_fbo: fbo,
|
|
3921
|
+
readPixels: (out) => {
|
|
3922
|
+
const byteLen = w * h * 4;
|
|
3923
|
+
const dst = out && out.length >= byteLen ? out : new Uint8Array(byteLen);
|
|
3924
|
+
if (this.contextLost) return dst;
|
|
3925
|
+
this.flushAll();
|
|
3926
|
+
const raw = new Uint8Array(byteLen);
|
|
3927
|
+
const prev = this.activeFbo;
|
|
3928
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
|
3929
|
+
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, raw);
|
|
3930
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, prev);
|
|
3931
|
+
const rowStride = w * 4;
|
|
3932
|
+
for (let y = 0; y < h; y++) {
|
|
3933
|
+
const srcOff = (h - 1 - y) * rowStride;
|
|
3934
|
+
dst.set(raw.subarray(srcOff, srcOff + rowStride), y * rowStride);
|
|
3935
|
+
}
|
|
3936
|
+
return dst;
|
|
3937
|
+
},
|
|
3683
3938
|
destroy: () => {
|
|
3684
3939
|
try {
|
|
3685
3940
|
if (!this.contextLost) {
|
|
@@ -3692,8 +3947,8 @@ var RendererGl = class extends EventEmitter {
|
|
|
3692
3947
|
}
|
|
3693
3948
|
};
|
|
3694
3949
|
}
|
|
3695
|
-
/** Render a `DisplayList` (or custom pass callback) into an offscreen `StageRenderTarget` FBO. */
|
|
3696
|
-
renderToTarget(target, content, camera) {
|
|
3950
|
+
/** Render a `DisplayList` (or custom pass callback) into an offscreen `StageRenderTarget` FBO (`camera` defaults to `target.camera`). */
|
|
3951
|
+
renderToTarget(target, content, camera = target.camera) {
|
|
3697
3952
|
if (this.contextLost) return;
|
|
3698
3953
|
this.flushAll();
|
|
3699
3954
|
const gl = this.gl;
|
|
@@ -3797,6 +4052,7 @@ var RendererGl = class extends EventEmitter {
|
|
|
3797
4052
|
}
|
|
3798
4053
|
switch (obj.type) {
|
|
3799
4054
|
case "Image":
|
|
4055
|
+
case "Sprite":
|
|
3800
4056
|
this.renderImage(obj, camera, m, effAlpha);
|
|
3801
4057
|
break;
|
|
3802
4058
|
case "NineSlice":
|
|
@@ -3826,6 +4082,9 @@ var RendererGl = class extends EventEmitter {
|
|
|
3826
4082
|
case "InstancedBatch":
|
|
3827
4083
|
this.renderInstancedBatch(obj, m, effAlpha);
|
|
3828
4084
|
break;
|
|
4085
|
+
case "ShapeBatch":
|
|
4086
|
+
this.renderShapeBatch(obj, m, effAlpha);
|
|
4087
|
+
break;
|
|
3829
4088
|
case "Container": {
|
|
3830
4089
|
const cont = obj;
|
|
3831
4090
|
const mask = cont.clipMask;
|
|
@@ -4629,6 +4888,16 @@ var LoaderPlugin = class extends EventEmitter {
|
|
|
4629
4888
|
});
|
|
4630
4889
|
return this;
|
|
4631
4890
|
}
|
|
4891
|
+
atlas(key, imageUrl, atlasData, options) {
|
|
4892
|
+
this.queue.push({
|
|
4893
|
+
kind: "atlas",
|
|
4894
|
+
key,
|
|
4895
|
+
url: imageUrl,
|
|
4896
|
+
atlas: atlasData,
|
|
4897
|
+
imageOpts: options
|
|
4898
|
+
});
|
|
4899
|
+
return this;
|
|
4900
|
+
}
|
|
4632
4901
|
get hasQueued() {
|
|
4633
4902
|
return this.queue.length > 0;
|
|
4634
4903
|
}
|
|
@@ -4747,6 +5016,7 @@ var LoaderPlugin = class extends EventEmitter {
|
|
|
4747
5016
|
if (settled || isAborted() || activeImg !== img) return;
|
|
4748
5017
|
try {
|
|
4749
5018
|
if (item.kind === "spritesheet" && item.sheet) this.textures.addSpriteSheet(item.key, img, item.sheet);
|
|
5019
|
+
else if (item.kind === "atlas" && item.atlas) this.textures.addAtlas(item.key, img, item.atlas, item.imageOpts);
|
|
4750
5020
|
else this.textures.addImage(item.key, img, item.imageOpts);
|
|
4751
5021
|
settle(true);
|
|
4752
5022
|
} catch {
|
|
@@ -4801,6 +5071,9 @@ var GameObjectFactory = class {
|
|
|
4801
5071
|
image(x, y, key, frame) {
|
|
4802
5072
|
return this.register(new ImageObject(this.scene, x, y, key, frame));
|
|
4803
5073
|
}
|
|
5074
|
+
sprite(x, y, key, frame) {
|
|
5075
|
+
return this.register(new SpriteObject(this.scene, x, y, key, frame));
|
|
5076
|
+
}
|
|
4804
5077
|
nineslice(x, y, key, frame, width, height, left, right, top, bottom) {
|
|
4805
5078
|
return this.register(new NineSliceObject(this.scene, x, y, key, frame, width, height, left, right, top, bottom));
|
|
4806
5079
|
}
|
|
@@ -4831,6 +5104,10 @@ var GameObjectFactory = class {
|
|
|
4831
5104
|
instancedBatch(key, maxCount = 1024, frame) {
|
|
4832
5105
|
return this.register(new InstancedBatchObject(this.scene, key, maxCount, frame));
|
|
4833
5106
|
}
|
|
5107
|
+
/** Create a zero-texture GPU analytical SDF shape batch (`circles`, `rings`, `pills`, `rounded rects`). */
|
|
5108
|
+
shapeBatch(maxCount = 1024, defaults) {
|
|
5109
|
+
return this.register(new ShapeBatchObject(this.scene, maxCount, defaults));
|
|
5110
|
+
}
|
|
4834
5111
|
container(x = 0, y = 0, children) {
|
|
4835
5112
|
return this.register(new Container(this.scene, x, y, children));
|
|
4836
5113
|
}
|
|
@@ -4843,15 +5120,21 @@ var ScaleManager = class extends EventEmitter {
|
|
|
4843
5120
|
renderer;
|
|
4844
5121
|
width;
|
|
4845
5122
|
height;
|
|
5123
|
+
logicalWidth;
|
|
5124
|
+
logicalHeight;
|
|
4846
5125
|
zoom;
|
|
5126
|
+
mode;
|
|
4847
5127
|
displayScale;
|
|
4848
|
-
constructor(canvas, renderer, width, height, zoom = 1) {
|
|
5128
|
+
constructor(canvas, renderer, width, height, zoom = 1, mode = Scale.NONE) {
|
|
4849
5129
|
super();
|
|
4850
5130
|
this.canvas = canvas;
|
|
4851
5131
|
this.renderer = renderer;
|
|
4852
5132
|
this.width = Math.max(1, Math.round(width));
|
|
4853
5133
|
this.height = Math.max(1, Math.round(height));
|
|
5134
|
+
this.logicalWidth = this.width;
|
|
5135
|
+
this.logicalHeight = this.height;
|
|
4854
5136
|
this.zoom = zoom > 0 ? zoom : 1;
|
|
5137
|
+
this.mode = mode;
|
|
4855
5138
|
this.displayScale = {
|
|
4856
5139
|
x: 1 / this.zoom,
|
|
4857
5140
|
y: 1 / this.zoom
|
|
@@ -4877,7 +5160,41 @@ var ScaleManager = class extends EventEmitter {
|
|
|
4877
5160
|
});
|
|
4878
5161
|
return this;
|
|
4879
5162
|
}
|
|
5163
|
+
/**
|
|
5164
|
+
* Proportionally fit `canvas.style.width/height` inside `availWidth × availHeight` (or `canvas.parentElement` / `window`)
|
|
5165
|
+
* preserving `logicalWidth : logicalHeight` aspect ratio (zero CSS matrix distortion; `InputPlugin` & `clientToWorld` stay exact).
|
|
5166
|
+
*/
|
|
5167
|
+
fitToContainer(availWidth, availHeight) {
|
|
5168
|
+
const parent = this.canvas?.parentElement;
|
|
5169
|
+
const win = this.canvas?.ownerDocument?.defaultView;
|
|
5170
|
+
const aw = Math.max(1, availWidth ?? parent?.clientWidth ?? win?.innerWidth ?? this.logicalWidth);
|
|
5171
|
+
const ah = Math.max(1, availHeight ?? parent?.clientHeight ?? win?.innerHeight ?? this.logicalHeight);
|
|
5172
|
+
const lw = Math.max(1, this.logicalWidth);
|
|
5173
|
+
const lh = Math.max(1, this.logicalHeight);
|
|
5174
|
+
const scale = Math.min(aw / lw, ah / lh);
|
|
5175
|
+
const cssWidth = Math.max(1, Math.round(lw * scale));
|
|
5176
|
+
const cssHeight = Math.max(1, Math.round(lh * scale));
|
|
5177
|
+
const offsetX = Math.floor((aw - cssWidth) * .5);
|
|
5178
|
+
const offsetY = Math.floor((ah - cssHeight) * .5);
|
|
5179
|
+
if (this.canvas?.style) {
|
|
5180
|
+
this.canvas.style.width = `${cssWidth}px`;
|
|
5181
|
+
this.canvas.style.height = `${cssHeight}px`;
|
|
5182
|
+
}
|
|
5183
|
+
this.displayScale.x = this.width / cssWidth;
|
|
5184
|
+
this.displayScale.y = this.height / cssHeight;
|
|
5185
|
+
return {
|
|
5186
|
+
scale,
|
|
5187
|
+
cssWidth,
|
|
5188
|
+
cssHeight,
|
|
5189
|
+
offsetX,
|
|
5190
|
+
offsetY
|
|
5191
|
+
};
|
|
5192
|
+
}
|
|
4880
5193
|
refresh() {
|
|
5194
|
+
if (this.mode === Scale.FIT) {
|
|
5195
|
+
this.fitToContainer();
|
|
5196
|
+
return this;
|
|
5197
|
+
}
|
|
4881
5198
|
this.displayScale.x = 1 / (this.zoom || 1);
|
|
4882
5199
|
this.displayScale.y = 1 / (this.zoom || 1);
|
|
4883
5200
|
return this;
|
|
@@ -4889,6 +5206,7 @@ var Scene = class {
|
|
|
4889
5206
|
events = new EventEmitter();
|
|
4890
5207
|
/** Deterministic EngineClock-driven tween & spring manager (auto-stepped in `Game.step()`). */
|
|
4891
5208
|
tweens = new TweenManager();
|
|
5209
|
+
_animatedSprites = /* @__PURE__ */ new Set();
|
|
4892
5210
|
_nodesCreated = 0;
|
|
4893
5211
|
_nodesDestroyed = 0;
|
|
4894
5212
|
_disposersRan = 0;
|
|
@@ -4898,6 +5216,7 @@ var Scene = class {
|
|
|
4898
5216
|
clock;
|
|
4899
5217
|
renderer;
|
|
4900
5218
|
textures;
|
|
5219
|
+
anims;
|
|
4901
5220
|
scale;
|
|
4902
5221
|
input;
|
|
4903
5222
|
load;
|
|
@@ -4929,6 +5248,7 @@ var Scene = class {
|
|
|
4929
5248
|
this.clock = game.clock;
|
|
4930
5249
|
this.renderer = game.renderer;
|
|
4931
5250
|
this.textures = game.textures;
|
|
5251
|
+
this.anims = game.anims;
|
|
4932
5252
|
this.scale = game.scale;
|
|
4933
5253
|
this.input = game.input;
|
|
4934
5254
|
this.load = new LoaderPlugin(game.textures);
|
|
@@ -4969,6 +5289,17 @@ var Scene = class {
|
|
|
4969
5289
|
tweenStats() {
|
|
4970
5290
|
return this.tweens.stats();
|
|
4971
5291
|
}
|
|
5292
|
+
_registerAnimatedSprite(sprite) {
|
|
5293
|
+
this._animatedSprites.add(sprite);
|
|
5294
|
+
}
|
|
5295
|
+
_unregisterAnimatedSprite(sprite) {
|
|
5296
|
+
this._animatedSprites.delete(sprite);
|
|
5297
|
+
}
|
|
5298
|
+
_stepAnimations(deltaMs) {
|
|
5299
|
+
if (this._animatedSprites.size === 0 || deltaMs <= 0) return;
|
|
5300
|
+
for (const s of this._animatedSprites) if (s.active) s._stepAnim(deltaMs);
|
|
5301
|
+
else this._animatedSprites.delete(s);
|
|
5302
|
+
}
|
|
4972
5303
|
_invalidateTextGl() {
|
|
4973
5304
|
const walk = (list) => {
|
|
4974
5305
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -4993,6 +5324,7 @@ var Scene = class {
|
|
|
4993
5324
|
for (let i = 0; i < snap.length; i++) try {
|
|
4994
5325
|
snap[i].destroy(true);
|
|
4995
5326
|
} catch {}
|
|
5327
|
+
this._animatedSprites.clear();
|
|
4996
5328
|
this.tweens.clear();
|
|
4997
5329
|
}
|
|
4998
5330
|
};
|
|
@@ -5132,6 +5464,7 @@ var Game = class {
|
|
|
5132
5464
|
canvas;
|
|
5133
5465
|
renderer;
|
|
5134
5466
|
textures;
|
|
5467
|
+
anims;
|
|
5135
5468
|
scale;
|
|
5136
5469
|
input;
|
|
5137
5470
|
cache;
|
|
@@ -5147,6 +5480,7 @@ var Game = class {
|
|
|
5147
5480
|
destroyed = false;
|
|
5148
5481
|
ownedCanvas = false;
|
|
5149
5482
|
inStep = false;
|
|
5483
|
+
onWindowResize = null;
|
|
5150
5484
|
constructor(config = {}) {
|
|
5151
5485
|
this.config = config;
|
|
5152
5486
|
const fallbackDoc = typeof document !== "undefined" ? document : void 0;
|
|
@@ -5199,11 +5533,22 @@ var Game = class {
|
|
|
5199
5533
|
}
|
|
5200
5534
|
const glHost = this.renderer.type === 2 ? this.renderer : null;
|
|
5201
5535
|
this.textures = new TextureManager(Boolean(config.pixelArt), glHost, this.doc);
|
|
5536
|
+
this.anims = new AnimationManager(this.textures);
|
|
5202
5537
|
if (glHost) glHost.onContextLost = () => {
|
|
5203
5538
|
this.textures.invalidateAllGl();
|
|
5204
5539
|
for (let i = 0; i < this.scene.scenes.length; i++) this.scene.scenes[i]._invalidateTextGl();
|
|
5205
5540
|
};
|
|
5206
|
-
|
|
5541
|
+
const scaleMode = config.scale?.mode ?? Scale.NONE;
|
|
5542
|
+
this.scale = new ScaleManager(this.canvas, this.renderer, width, height, zoom, scaleMode);
|
|
5543
|
+
if (scaleMode === Scale.FIT) {
|
|
5544
|
+
this.scale.fitToContainer();
|
|
5545
|
+
if (this.win && typeof this.win.addEventListener === "function") {
|
|
5546
|
+
this.onWindowResize = () => {
|
|
5547
|
+
if (!this.destroyed) this.scale.fitToContainer();
|
|
5548
|
+
};
|
|
5549
|
+
this.win.addEventListener("resize", this.onWindowResize);
|
|
5550
|
+
}
|
|
5551
|
+
}
|
|
5207
5552
|
this.cache = { json: new JsonCache() };
|
|
5208
5553
|
this.scene = new SceneManager(this);
|
|
5209
5554
|
this.input = new InputPlugin(this.canvas, this.win, () => this.scene.getPrimaryCamera(), config.input, () => this.clock.frameSeq, () => this.inStep ? this.clock.frameSeq : this.clock.frameSeq + 1);
|
|
@@ -5238,6 +5583,7 @@ var Game = class {
|
|
|
5238
5583
|
if (sc.sys.settings.status === Scenes.RUNNING) {
|
|
5239
5584
|
sc.events.emit("preupdate", time, delta);
|
|
5240
5585
|
if (sc.tweens.hasActive) sc.tweens.step(this.clock.lastDeltaMs);
|
|
5586
|
+
sc._stepAnimations(this.clock.lastDeltaMs);
|
|
5241
5587
|
sc.update?.(time, delta);
|
|
5242
5588
|
this.kernel._updateScene(sc, time, delta);
|
|
5243
5589
|
sc.cameras.main.stepFollow(this.clock.lastDeltaMs);
|
|
@@ -5256,10 +5602,16 @@ var Game = class {
|
|
|
5256
5602
|
try {
|
|
5257
5603
|
if (!this.stepSimOnly(time, delta)) return;
|
|
5258
5604
|
const scenes = this.scene.scenes;
|
|
5605
|
+
const lastDt = this.clock.lastDeltaMs;
|
|
5259
5606
|
this.events.emit("prerender", this.renderer);
|
|
5260
5607
|
for (let i = 0; i < scenes.length; i++) {
|
|
5261
5608
|
const sc = scenes[i];
|
|
5262
|
-
if (sc.sys.settings.status === Scenes.RUNNING)
|
|
5609
|
+
if (sc.sys.settings.status === Scenes.RUNNING) {
|
|
5610
|
+
sc.preRender?.(time, lastDt);
|
|
5611
|
+
this.kernel._prerenderScene(sc, this.renderer, time, lastDt);
|
|
5612
|
+
sc.events.emit("prerender", this.renderer, time, lastDt);
|
|
5613
|
+
this.renderer.render(sc._displayList, sc.cameras.main);
|
|
5614
|
+
}
|
|
5263
5615
|
}
|
|
5264
5616
|
this.kernel._postrender(this.renderer);
|
|
5265
5617
|
this.events.emit("postrender", this.renderer);
|
|
@@ -5272,10 +5624,15 @@ var Game = class {
|
|
|
5272
5624
|
this.pendingDestroy = true;
|
|
5273
5625
|
this.destroyed = true;
|
|
5274
5626
|
this.loop.destroy();
|
|
5627
|
+
if (this.onWindowResize && this.win && typeof this.win.removeEventListener === "function") {
|
|
5628
|
+
this.win.removeEventListener("resize", this.onWindowResize);
|
|
5629
|
+
this.onWindowResize = null;
|
|
5630
|
+
}
|
|
5275
5631
|
this.events.emit("destroy", this);
|
|
5276
5632
|
this.kernel.dispose();
|
|
5277
5633
|
this.scene.destroy();
|
|
5278
5634
|
this.input.destroy();
|
|
5635
|
+
this.anims.clear();
|
|
5279
5636
|
this.textures.destroy();
|
|
5280
5637
|
this.cache.json.clear();
|
|
5281
5638
|
this.renderer.destroy();
|
|
@@ -5285,4 +5642,4 @@ var Game = class {
|
|
|
5285
5642
|
else if (removeCanvas) this.canvas.remove();
|
|
5286
5643
|
}
|
|
5287
5644
|
};
|
|
5288
|
-
export {
|
|
5645
|
+
export { CanvasTexture as _, JsonCache as a, TextureManager as b, Scene as c, KeyboardPlugin as d, Pointer as f, SdfPanelBatcher as g, MsdfIconBatcher as h, GameObjectFactory as i, SceneManager as l, PixelAaBatcher as m, Game as n, LoaderPlugin as o, RendererGl as p, GameLoop as r, ScaleManager as s, EngineClock as t, InputPlugin as u, Frame as v, TextureSource as x, Texture as y };
|