@moku-labs/game 0.15.88 → 0.15.90
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/dist/app/page.d.mts +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/assets.d.mts +1 -1
- package/dist/{commands-C6RMqrY8.d.mts → commands-DUco80gt.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-DE1XcBwC.d.mts → define-C-EbeoLA.d.mts} +2 -2
- package/dist/{headless-CtRq6Uij.d.mts → headless-Dasz6dgy.d.mts} +1 -1
- package/dist/{index-nK7iVsWx.d.mts → index-vPc22SoP.d.mts} +3 -3
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +1 -1
- package/dist/inspect.d.mts +6 -6
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-CmRqaHmz.d.mts → runtime-CW4HJWqC.d.mts} +1 -1
- package/dist/{src-BTPWdbHH.mjs → src-D2-mFvog.mjs} +874 -63
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-BlXL-VC3.d.mts → types-B2Dh7oWu.d.mts} +4 -4
- package/dist/{types-BbLjYfGR.d.mts → types-BMUuyOcm.d.mts} +1 -1
- package/dist/{types-ehmvA6yu.d.mts → types-Btqe51cJ.d.mts} +2 -2
- package/dist/{types-CJYudpme.d.mts → types-Cc7uKiHX.d.mts} +2 -2
- package/dist/{types-w5_A5TPL.d.mts → types-D1lRinVJ.d.mts} +187 -9
- package/dist/{visual-DvhjRhgP.d.mts → visual-BMyWTUgm.d.mts} +6 -6
- package/dist/visual.d.mts +1 -1
- package/llms.txt +1 -0
- package/package.json +1 -1
|
@@ -13418,7 +13418,7 @@ function emptyRest() {
|
|
|
13418
13418
|
*
|
|
13419
13419
|
* @returns An empty table of key to entity.
|
|
13420
13420
|
*/
|
|
13421
|
-
function emptyKeys$
|
|
13421
|
+
function emptyKeys$2() {
|
|
13422
13422
|
return /* @__PURE__ */ new Map();
|
|
13423
13423
|
}
|
|
13424
13424
|
/**
|
|
@@ -13614,7 +13614,7 @@ function createProjectionApi(ctx, deps) {
|
|
|
13614
13614
|
},
|
|
13615
13615
|
registerKey: (projection, key, entity) => {
|
|
13616
13616
|
if (state.mounted.get(projection)?.live.has(key) === true) throw new Error(`[game] Key "${key}" of projection "${projection}" is already a live view.\n Register the element under another key.`);
|
|
13617
|
-
const byKey = state.keys.get(projection) ?? emptyKeys$
|
|
13617
|
+
const byKey = state.keys.get(projection) ?? emptyKeys$2();
|
|
13618
13618
|
byKey.set(key, entity);
|
|
13619
13619
|
state.keys.set(projection, byKey);
|
|
13620
13620
|
state.keysByEntity.set(entity, {
|
|
@@ -17169,6 +17169,11 @@ function createHostApi(ctx, deps) {
|
|
|
17169
17169
|
if (!state.ready || app === void 0) return;
|
|
17170
17170
|
app.renderer.texture.initSource(source);
|
|
17171
17171
|
},
|
|
17172
|
+
canvasTexture: () => liveDevice(state) === void 0 ? void 0 : state.canvas?.getContext("webgpu")?.getCurrentTexture(),
|
|
17173
|
+
gpuTexture: (source) => {
|
|
17174
|
+
const textures = state.ready ? state.app?.renderer.texture : void 0;
|
|
17175
|
+
return textures !== void 0 && "getGpuSource" in textures ? textures.getGpuSource(source) : void 0;
|
|
17176
|
+
},
|
|
17172
17177
|
clearsCanvas: () => state.ready && state.app?.renderer.background.clearBeforeRender === true,
|
|
17173
17178
|
setResolution: (value, reason) => askResolution(state, value, reason),
|
|
17174
17179
|
overrideResolution: (value) => {
|
|
@@ -19198,7 +19203,8 @@ const NOW = {
|
|
|
19198
19203
|
c: 0,
|
|
19199
19204
|
d: 1,
|
|
19200
19205
|
tx: 0,
|
|
19201
|
-
ty: 0
|
|
19206
|
+
ty: 0,
|
|
19207
|
+
under: false
|
|
19202
19208
|
};
|
|
19203
19209
|
/** What a kept record owes `refresh`: nothing, the filter output, or the pre-pass results and the filter output. */
|
|
19204
19210
|
const OWED = {
|
|
@@ -19269,15 +19275,16 @@ function drawsDirect(stack) {
|
|
|
19269
19275
|
* filter with a quad, no inputs, on `"inherit"`, at the canvas resolution, and not drawn direct. An `Alpha` beside it does
|
|
19270
19276
|
* not fit: stage 3 draws `F(A·x)` in stack order, the mesh would draw `A·F(x)`, and for a body that is not alpha-linear
|
|
19271
19277
|
* the picture would pop at every entry. A top that blends otherwise never gets here: `pictureWhy` refuses it. A mesh
|
|
19272
|
-
* destroyed with a parent around it has nothing left to draw on.
|
|
19278
|
+
* destroyed with a parent around it has nothing left to draw on. Allocates nothing.
|
|
19273
19279
|
*
|
|
19274
19280
|
* @param kctx - The kept context.
|
|
19275
19281
|
* @param record - The record.
|
|
19282
|
+
* @param stack - The stack of this frame.
|
|
19276
19283
|
* @returns True when it fits.
|
|
19277
19284
|
*/
|
|
19278
|
-
function shadeFits(kctx, record) {
|
|
19279
|
-
if (kctx.host.kind() !== "webgpu" ||
|
|
19280
|
-
if (
|
|
19285
|
+
function shadeFits(kctx, record, stack) {
|
|
19286
|
+
if (kctx.host.kind() !== "webgpu" || stack.enabled !== 1) return false;
|
|
19287
|
+
if (stack.rs !== NOW.r || drawsDirect(stack)) return false;
|
|
19281
19288
|
const slot = enabledSlot(record.slots);
|
|
19282
19289
|
const bodyOnQuad = slot?.quad !== void 0 && slot.inputs === void 0;
|
|
19283
19290
|
const followsCanvas = slot?.filter.resolution === "inherit";
|
|
@@ -19393,8 +19400,8 @@ function drawnAnyway(kctx, node) {
|
|
|
19393
19400
|
return node.renderable || kctx.sync.hiddenOnlyAmong(kctx.hidden, node, DRAWN_ANYWAY);
|
|
19394
19401
|
}
|
|
19395
19402
|
/**
|
|
19396
|
-
* Tells whether an ancestor filters a placed record's view: a filter of its own or its kept picture.
|
|
19397
|
-
*
|
|
19403
|
+
* Tells whether an ancestor filters a placed record's view: a filter of its own or its kept picture. Live, the canvas
|
|
19404
|
+
* position of a placed filter is then relative to that filter's texture.
|
|
19398
19405
|
*
|
|
19399
19406
|
* @param kctx - The kept context.
|
|
19400
19407
|
* @param record - The record.
|
|
@@ -19406,23 +19413,27 @@ function filtersPlaced(kctx, record, node) {
|
|
|
19406
19413
|
}
|
|
19407
19414
|
/**
|
|
19408
19415
|
* Tells whether an ancestor draws what is under it as a picture would: visible, untinted, blending normally, drawn (an
|
|
19409
|
-
* overlay's range and a kept ancestor's picture count)
|
|
19410
|
-
*
|
|
19411
|
-
*
|
|
19412
|
-
*
|
|
19413
|
-
*
|
|
19416
|
+
* overlay's range and a kept ancestor's picture count). For a placed filter it may also hold a filter, noted in
|
|
19417
|
+
* `NOW.under`, while the record fits the mode: a stage 3 picture would hold the wrong place, the record's own body on its
|
|
19418
|
+
* quad reads the canvas place from the world transform, whatever target the ancestor renders into. Its alpha is not read
|
|
19419
|
+
* (F113): the quad hangs in the top's parent and Pixi multiplies it by the ancestors' alpha, while stage 1 renders the
|
|
19420
|
+
* top as a root without them. A fading ancestor so draws the picture at `A·F(x)`, live draws `F(A·x)`: the same for an
|
|
19421
|
+
* alpha-linear filter, the whole picture faded for one that is not.
|
|
19414
19422
|
*
|
|
19415
19423
|
* @param kctx - The kept context.
|
|
19416
19424
|
* @param record - The record.
|
|
19417
19425
|
* @param node - The ancestor.
|
|
19426
|
+
* @param stack - The stack of this frame.
|
|
19418
19427
|
* @returns 0 when it does, else the `WHY` it does not.
|
|
19419
19428
|
*/
|
|
19420
|
-
function ancestorWhy(kctx, record, node) {
|
|
19429
|
+
function ancestorWhy(kctx, record, node, stack) {
|
|
19421
19430
|
if (!node.visible) return WHY.ancestorHidden;
|
|
19422
19431
|
if (node.tint !== WHITE$2) return WHY.ancestorTint;
|
|
19423
19432
|
if (!plainBlend(node.blendMode)) return WHY.ancestorBlend;
|
|
19424
19433
|
if (!drawnAnyway(kctx, node)) return WHY.ancestorHidden;
|
|
19425
|
-
|
|
19434
|
+
if (!filtersPlaced(kctx, record, node)) return 0;
|
|
19435
|
+
NOW.under = true;
|
|
19436
|
+
return shadeFits(kctx, record, stack) ? 0 : WHY.placedUnderFilter;
|
|
19426
19437
|
}
|
|
19427
19438
|
/**
|
|
19428
19439
|
* Tells whether every ancestor up to the stage draws the view as a picture would (`ancestorWhy`).
|
|
@@ -19430,12 +19441,13 @@ function ancestorWhy(kctx, record, node) {
|
|
|
19430
19441
|
* @param kctx - The kept context.
|
|
19431
19442
|
* @param record - The record.
|
|
19432
19443
|
* @param stage - The stage of the application.
|
|
19444
|
+
* @param stack - The stack of this frame.
|
|
19433
19445
|
* @returns 0 when they do, else the `WHY` of the first that does not.
|
|
19434
19446
|
*/
|
|
19435
|
-
function ancestorsWhy(kctx, record, stage) {
|
|
19447
|
+
function ancestorsWhy(kctx, record, stage, stack) {
|
|
19436
19448
|
for (let node = record.top.parent; node !== stage; node = node.parent) {
|
|
19437
19449
|
if (node === null) return WHY.ancestorHidden;
|
|
19438
|
-
const why = ancestorWhy(kctx, record, node);
|
|
19450
|
+
const why = ancestorWhy(kctx, record, node, stack);
|
|
19439
19451
|
if (why !== 0) return why;
|
|
19440
19452
|
}
|
|
19441
19453
|
return 0;
|
|
@@ -19459,7 +19471,7 @@ function eligible(kctx, record, view, stack) {
|
|
|
19459
19471
|
const picture = pictureWhy(record.top, view);
|
|
19460
19472
|
if (picture !== 0) return picture;
|
|
19461
19473
|
if (!topDrawn(kctx.sync, view)) return WHY.hidden;
|
|
19462
|
-
return ancestorsWhy(kctx, record, stage);
|
|
19474
|
+
return ancestorsWhy(kctx, record, stage, stack);
|
|
19463
19475
|
}
|
|
19464
19476
|
/**
|
|
19465
19477
|
* Tells whether the kept cache may keep anything this frame: switched on and not bypassed.
|
|
@@ -19950,7 +19962,7 @@ function renderStages(kctx, pixi, matrices, record, view, now) {
|
|
|
19950
19962
|
return ok;
|
|
19951
19963
|
}
|
|
19952
19964
|
record.direct = false;
|
|
19953
|
-
|
|
19965
|
+
meshForTake(kctx, pixi, record, ok);
|
|
19954
19966
|
if (ok && first !== void 0) renderStage2(kctx, pixi, matrices, record, {
|
|
19955
19967
|
inputs: first.inputs,
|
|
19956
19968
|
resolution: now.r,
|
|
@@ -19964,6 +19976,23 @@ function renderStages(kctx, pixi, matrices, record, view, now) {
|
|
|
19964
19976
|
return ok;
|
|
19965
19977
|
}
|
|
19966
19978
|
/**
|
|
19979
|
+
* Settles what a take draws through, before its output: a stack that stopped fitting leaves before anything is drawn
|
|
19980
|
+
* for it, and the frame draws a sprite of stage 3. Under a filter there is no sprite to draw, so a picture that rendered
|
|
19981
|
+
* goes on the mesh; the sprite a mesh takes the place of may not exist yet.
|
|
19982
|
+
*
|
|
19983
|
+
* @param kctx - The kept context.
|
|
19984
|
+
* @param pixi - The module that draws.
|
|
19985
|
+
* @param record - The record, its take keys written.
|
|
19986
|
+
* @param ok - Stage 1 rendered.
|
|
19987
|
+
*/
|
|
19988
|
+
function meshForTake(kctx, pixi, record, ok) {
|
|
19989
|
+
if (record.shaded && !shadeFits(kctx, record, NOW)) leaveShade(record);
|
|
19990
|
+
const quad = enabledSlot(record.slots)?.quad;
|
|
19991
|
+
if (!ok || !NOW.under || record.shaded || quad === void 0) return;
|
|
19992
|
+
quadDrawing(pixi, record, record.s3 ?? pixi.Texture.EMPTY);
|
|
19993
|
+
enterShade(kctx, pixi, record, quad, NOW);
|
|
19994
|
+
}
|
|
19995
|
+
/**
|
|
19967
19996
|
* Puts the filters of a live record whose take failed back on its top: it draws live again.
|
|
19968
19997
|
*
|
|
19969
19998
|
* @param kctx - The kept context.
|
|
@@ -20339,7 +20368,8 @@ function retakeOrGoLive(kctx, pixi, matrices, record, view, why) {
|
|
|
20339
20368
|
}
|
|
20340
20369
|
/**
|
|
20341
20370
|
* A stage-1 change of a kept record (P4.3): retaken, or after three in a row drawn live and calm, so it stands still
|
|
20342
|
-
* for eight frames before the next take.
|
|
20371
|
+
* for eight frames before the next take. Under a filter it is always retaken: live, a body that reads its place reads
|
|
20372
|
+
* another one, and a glow would jump; only a refused take or an eviction goes live there.
|
|
20343
20373
|
*
|
|
20344
20374
|
* @param kctx - The kept context.
|
|
20345
20375
|
* @param pixi - The module that draws.
|
|
@@ -20350,7 +20380,7 @@ function retakeOrGoLive(kctx, pixi, matrices, record, view, why) {
|
|
|
20350
20380
|
*/
|
|
20351
20381
|
function churn(kctx, pixi, matrices, record, view, why) {
|
|
20352
20382
|
record.churn += 1;
|
|
20353
|
-
if (record.churn < 3) {
|
|
20383
|
+
if (record.churn < 3 || NOW.under) {
|
|
20354
20384
|
retakeOrGoLive(kctx, pixi, matrices, record, view, why);
|
|
20355
20385
|
return;
|
|
20356
20386
|
}
|
|
@@ -20631,10 +20661,11 @@ function refresh$1(kctx, pixi, matrices, record, view, hold) {
|
|
|
20631
20661
|
* @returns True when the record was taken whole.
|
|
20632
20662
|
*/
|
|
20633
20663
|
function refreshOutput(kctx, pixi, matrices, record, view, hold) {
|
|
20634
|
-
const fits = shadeFits(kctx, record);
|
|
20664
|
+
const fits = shadeFits(kctx, record, NOW);
|
|
20635
20665
|
const unfit = record.shaded && !fits;
|
|
20636
20666
|
if (unfit) leaveShade(record);
|
|
20637
|
-
const
|
|
20667
|
+
const unplaced = unfit || NOW.under && !record.shaded;
|
|
20668
|
+
const owed = Math.max(stagesOwed(record, hold), unplaced ? OWED.output : OWED.none);
|
|
20638
20669
|
if (owed === OWED.none) return leaveAtRest(kctx, pixi, matrices, record, view, hold);
|
|
20639
20670
|
const chain = owed === OWED.chain;
|
|
20640
20671
|
const why = refreshWhy(record, chain, hold);
|
|
@@ -20644,6 +20675,7 @@ function refreshOutput(kctx, pixi, matrices, record, view, hold) {
|
|
|
20644
20675
|
}
|
|
20645
20676
|
const inputs = firstInputs(record.slots)?.inputs;
|
|
20646
20677
|
if (inputs === void 0 && record.s2Of !== void 0) releaseInputs(kctx, record);
|
|
20678
|
+
record.direct = false;
|
|
20647
20679
|
if (!unfit && enterShadeWhenDue(kctx, pixi, record, owed, fits)) {
|
|
20648
20680
|
redrawShade(kctx, pixi, matrices, record);
|
|
20649
20681
|
return false;
|
|
@@ -20654,7 +20686,6 @@ function refreshOutput(kctx, pixi, matrices, record, view, hold) {
|
|
|
20654
20686
|
padding: NOW.P
|
|
20655
20687
|
});
|
|
20656
20688
|
noteTake(kctx, record, why);
|
|
20657
|
-
record.direct = false;
|
|
20658
20689
|
renderStage3(kctx, pixi, matrices, record, NOW);
|
|
20659
20690
|
account(kctx, record);
|
|
20660
20691
|
if (!chain) kctx.state.refreshesOpen += 1;
|
|
@@ -20691,7 +20722,8 @@ function redrawShade(kctx, pixi, matrices, record) {
|
|
|
20691
20722
|
/**
|
|
20692
20723
|
* Counts an output owed by a record on its sprite, and puts the record on its mesh when it is due: stage 3 alone was owed
|
|
20693
20724
|
* more than `QUAD_AFTER` times without a gap of `CALM_AFTER` frames, and it fits. The gap rule, not a reset on a quiet
|
|
20694
|
-
* frame: a tween that writes every second frame reaches the mode.
|
|
20725
|
+
* frame: a tween that writes every second frame reaches the mode. Under a filter nothing is counted: it may draw no other
|
|
20726
|
+
* way. A shaded record counts nothing.
|
|
20695
20727
|
*
|
|
20696
20728
|
* @param kctx - The kept context.
|
|
20697
20729
|
* @param pixi - The module that draws.
|
|
@@ -20706,9 +20738,7 @@ function enterShadeWhenDue(kctx, pixi, record, owed, fits) {
|
|
|
20706
20738
|
record.outputRuns = frame - record.outputAt > 8 ? 1 : record.outputRuns + 1;
|
|
20707
20739
|
record.outputAt = frame;
|
|
20708
20740
|
const quad = enabledSlot(record.slots)?.quad;
|
|
20709
|
-
|
|
20710
|
-
const ranLong = record.outputRuns > 2;
|
|
20711
|
-
if (!outputAlone || !fits || !ranLong || quad === void 0) return false;
|
|
20741
|
+
if (!(NOW.under || owed === OWED.output && record.outputRuns > 2) || !fits || quad === void 0) return false;
|
|
20712
20742
|
return enterShade(kctx, pixi, record, quad, NOW);
|
|
20713
20743
|
}
|
|
20714
20744
|
/**
|
|
@@ -20725,7 +20755,8 @@ function shadedCalm(state, record) {
|
|
|
20725
20755
|
* A shaded record that owes nothing and stood `QUAD_CALM` frames goes back to its sprite (F126 stage 2): a resting mesh
|
|
20726
20756
|
* runs the whole body every frame. Under `limitLeft`, shared with the refining and the settle, it stays shaded in a frame
|
|
20727
20757
|
* the limit is spent. It counts as a refresh. The pixels do not change, so the pass marks nothing above; a stack whose
|
|
20728
|
-
* resolution moved under a held step is taken whole, as `refresh` takes it, and that does change them.
|
|
20758
|
+
* resolution moved under a held step is taken whole, as `refresh` takes it, and that does change them. Under a filter
|
|
20759
|
+
* it stays: its clock starts over, so a calm frame leaves it alone until it comes round again.
|
|
20729
20760
|
*
|
|
20730
20761
|
* @param kctx - The kept context.
|
|
20731
20762
|
* @param pixi - The module that draws.
|
|
@@ -20737,6 +20768,7 @@ function shadedCalm(state, record) {
|
|
|
20737
20768
|
*/
|
|
20738
20769
|
function leaveAtRest(kctx, pixi, matrices, record, view, hold) {
|
|
20739
20770
|
const { state } = kctx;
|
|
20771
|
+
if (shadedCalm(state, record) && NOW.under) record.shadedAt = state.frame;
|
|
20740
20772
|
if (!shadedCalm(state, record) || !limitLeft(kctx)) return false;
|
|
20741
20773
|
leaveShade(record);
|
|
20742
20774
|
if (hold && record.key[KEY.rs] !== NOW.rs) {
|
|
@@ -20870,6 +20902,7 @@ function stepRecord(kctx, pixi, matrices, record, view) {
|
|
|
20870
20902
|
record.idleSeen = false;
|
|
20871
20903
|
}
|
|
20872
20904
|
readStack(record.slots, pixi.AlphaFilter, NOW);
|
|
20905
|
+
NOW.under = false;
|
|
20873
20906
|
const why = eligible(kctx, record, view, NOW);
|
|
20874
20907
|
if (why === 0) stepEligible(kctx, pixi, matrices, record, view);
|
|
20875
20908
|
else stepIneligible(kctx, record, view, why);
|
|
@@ -21007,6 +21040,8 @@ function bypassRecord(kctx, record, view, live) {
|
|
|
21007
21040
|
* logged, every record goes live and every range is owed a render (the policy takes them again). The call site guards
|
|
21008
21041
|
* it inline, so a production bundle drops this module.
|
|
21009
21042
|
*/
|
|
21043
|
+
/** What the read of the live frame answers when the frame is not compared. */
|
|
21044
|
+
const PLACE_DIFFERS = "place";
|
|
21010
21045
|
/**
|
|
21011
21046
|
* Tells whether a kept record's quad stands off its picture's grid: it is moving, drawn scaled to another linear part
|
|
21012
21047
|
* than at the take (F67), or drawn at another resolution than the canvas after a step (F126), and sampled linearly
|
|
@@ -21036,6 +21071,81 @@ function faded(record) {
|
|
|
21036
21071
|
return false;
|
|
21037
21072
|
}
|
|
21038
21073
|
/**
|
|
21074
|
+
* Where a filter pass starts on one axis, as Pixi works it out (`FilterSystem._calculateFilterBounds`): the bounds cut to
|
|
21075
|
+
* the canvas while the stack clips to it, floored to the pass's grid, then padded. Pure.
|
|
21076
|
+
*
|
|
21077
|
+
* @param start - The bounds' start on the canvas, CSS px.
|
|
21078
|
+
* @param resolution - The pass's resolution.
|
|
21079
|
+
* @param padding - The pass's padding, whole px.
|
|
21080
|
+
* @param clipped - Every enabled filter of the stack has `clipToViewport` on.
|
|
21081
|
+
* @returns The pass's start, CSS px.
|
|
21082
|
+
* @example
|
|
21083
|
+
* ```ts
|
|
21084
|
+
* passStart(-5, 1, 8, true); // -8
|
|
21085
|
+
* ```
|
|
21086
|
+
*/
|
|
21087
|
+
function passStart(start, resolution, padding, clipped) {
|
|
21088
|
+
return Math.floor((clipped ? Math.max(start, 0) : start) * resolution) / resolution - padding;
|
|
21089
|
+
}
|
|
21090
|
+
/**
|
|
21091
|
+
* The box a filter pass over a node measures, on the node's own axes: its filter area when it holds one, which replaces
|
|
21092
|
+
* the bounds, else what its subtree draws. Read with every picture live: the tree then holds the views, not their quads,
|
|
21093
|
+
* which stand padded.
|
|
21094
|
+
*
|
|
21095
|
+
* @param pixi - The module that draws.
|
|
21096
|
+
* @param node - The node.
|
|
21097
|
+
* @returns The box.
|
|
21098
|
+
*/
|
|
21099
|
+
function passBox(pixi, node) {
|
|
21100
|
+
const area = node.filterArea;
|
|
21101
|
+
if (area === null || area === void 0) return drawnBounds(pixi, node);
|
|
21102
|
+
const { x, y, width, height } = area;
|
|
21103
|
+
return {
|
|
21104
|
+
minX: x,
|
|
21105
|
+
minY: y,
|
|
21106
|
+
maxX: x + width,
|
|
21107
|
+
maxY: y + height
|
|
21108
|
+
};
|
|
21109
|
+
}
|
|
21110
|
+
/**
|
|
21111
|
+
* Tells whether a filter pass over a node starts off the canvas origin.
|
|
21112
|
+
*
|
|
21113
|
+
* @param kctx - The kept context.
|
|
21114
|
+
* @param pixi - The module that draws.
|
|
21115
|
+
* @param node - The node.
|
|
21116
|
+
* @param filters - Its enabled filters.
|
|
21117
|
+
* @returns True when it does.
|
|
21118
|
+
*/
|
|
21119
|
+
function passOffOrigin(kctx, pixi, node, filters) {
|
|
21120
|
+
const canvasResolution = kctx.host.resolution();
|
|
21121
|
+
const resolutions = filters.map(({ resolution }) => resolution === "inherit" ? canvasResolution : resolution);
|
|
21122
|
+
const resolution = Math.min(...resolutions);
|
|
21123
|
+
const clipped = filters.every((filter) => filter.clipToViewport);
|
|
21124
|
+
const padding = Math.trunc(filters.reduce((sum, filter) => sum + filter.padding, 0));
|
|
21125
|
+
const { a, b, c, d, tx, ty } = node.getGlobalTransform(new pixi.Matrix(), false);
|
|
21126
|
+
const box = linearBounds(a, b, c, d, passBox(pixi, node));
|
|
21127
|
+
return passStart(tx + box.x0, resolution, padding, clipped) !== 0 || passStart(ty + box.y0, resolution, padding, clipped) !== 0;
|
|
21128
|
+
}
|
|
21129
|
+
/**
|
|
21130
|
+
* Tells whether a shaded placed record hangs under a filter whose pass starts off the canvas origin. Live, its body
|
|
21131
|
+
* reads a place relative to that pass's texture; on the mesh it reads the canvas (spec 23 P8.3). The two differ by that
|
|
21132
|
+
* origin by design, not by a stale picture. Only the closest filter counts: Pixi offsets by that one alone. Read with
|
|
21133
|
+
* every picture live: a kept ancestor's filters are back on its top, and the views are back in the tree.
|
|
21134
|
+
*
|
|
21135
|
+
* @param kctx - The kept context.
|
|
21136
|
+
* @param record - The record, kept.
|
|
21137
|
+
* @returns True when the frame is not compared.
|
|
21138
|
+
*/
|
|
21139
|
+
function placeDiffers(kctx, record) {
|
|
21140
|
+
const pixi = kctx.host.pixi();
|
|
21141
|
+
if (!record.shaded || record.category !== "placed" || pixi === void 0) return false;
|
|
21142
|
+
for (let node = record.top.parent; node !== null; node = node.parent) {
|
|
21143
|
+
const filters = node.filters?.filter((filter) => filter.enabled) ?? [];
|
|
21144
|
+
if (filters.length > 0) return passOffOrigin(kctx, pixi, node, filters);
|
|
21145
|
+
}
|
|
21146
|
+
return false;
|
|
21147
|
+
}
|
|
21148
|
+
/**
|
|
21039
21149
|
* Tells whether the padded picture of a kept record reaches past the canvas edge, where Pixi clips the live filter.
|
|
21040
21150
|
*
|
|
21041
21151
|
* @param record - The record, kept.
|
|
@@ -21124,9 +21234,9 @@ function logStale(kctx, pixels, records, ranges) {
|
|
|
21124
21234
|
}
|
|
21125
21235
|
/**
|
|
21126
21236
|
* The pixel leg after a drawn frame: the picture as drawn against the same frame with every picture live. Frames in
|
|
21127
|
-
* which a picture moves off its grid, was drawn at another resolution (F126), is translucent itself (F120)
|
|
21128
|
-
* under a translucent ancestor (F113)
|
|
21129
|
-
* compared.
|
|
21237
|
+
* which a picture moves off its grid, was drawn at another resolution (F126), is translucent itself (F120), hangs
|
|
21238
|
+
* under a translucent ancestor (F113) or reads its place under a filter off the canvas origin are skipped and counted;
|
|
21239
|
+
* at rest, opaque, under opaque ancestors every picture is compared.
|
|
21130
21240
|
*
|
|
21131
21241
|
* @param kctx - The kept context.
|
|
21132
21242
|
* @param bypass - Draws every kept record live (true) or as its picture again (false).
|
|
@@ -21144,7 +21254,11 @@ function verifyPictures(kctx, bypass, recover) {
|
|
|
21144
21254
|
const resolution = host.resolution();
|
|
21145
21255
|
const drawn = host.pixels(resolution);
|
|
21146
21256
|
if (drawn === void 0) return;
|
|
21147
|
-
const live = drawLive(kctx, bypass, () => host.pixels(resolution));
|
|
21257
|
+
const live = drawLive(kctx, bypass, () => records.some((record) => placeDiffers(kctx, record)) ? PLACE_DIFFERS : host.pixels(resolution));
|
|
21258
|
+
if (live === PLACE_DIFFERS) {
|
|
21259
|
+
state.verifySkipped += 1;
|
|
21260
|
+
return;
|
|
21261
|
+
}
|
|
21148
21262
|
if (live === void 0 || live.length !== drawn.length) return;
|
|
21149
21263
|
const screen = host.screen();
|
|
21150
21264
|
const width = screen === void 0 ? 0 : Math.round(screen.width * resolution);
|
|
@@ -26856,6 +26970,359 @@ function stopMonitor(state) {
|
|
|
26856
26970
|
if (typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__ && state.perf !== void 0) stopPerf(state.perf, state.sinks);
|
|
26857
26971
|
}
|
|
26858
26972
|
//#endregion
|
|
26973
|
+
//#region src/plugins/renderer/shots/chain.ts
|
|
26974
|
+
/** The factor of a hop: its output texel centre falls on a corner of source pixels, so 2 x 2 taps are an exact box. */
|
|
26975
|
+
const HOP_FACTOR = 4;
|
|
26976
|
+
/** The widest radius of a kernel: the centre, and 15 pairs. */
|
|
26977
|
+
const MAX_RADIUS = 30;
|
|
26978
|
+
/** The radius of a kernel, in sigmas. */
|
|
26979
|
+
const RADIUS_SIGMAS = 3;
|
|
26980
|
+
/** The widest blur, in texels of the shot: its radius is the widest the uniform holds. */
|
|
26981
|
+
const MAX_SIGMA = MAX_RADIUS / RADIUS_SIGMAS;
|
|
26982
|
+
/** Taps a side of an exact box: each averages two source pixels, at 2 texels from the next. */
|
|
26983
|
+
const BOX_TAPS = 2;
|
|
26984
|
+
/** Taps a side of any other hop, spread evenly over it. */
|
|
26985
|
+
const SPREAD_TAPS = 3;
|
|
26986
|
+
/** Floats of the box uniform: `texel`, `step`, `size`, `count` and its padding. */
|
|
26987
|
+
const BOX_FLOATS = 8;
|
|
26988
|
+
/** Where the taps start in the blur uniform: an array of `vec4f` is aligned to 16 bytes, past `count`. */
|
|
26989
|
+
const KERNEL_HEAD = 8;
|
|
26990
|
+
/** Floats of one tap in the blur uniform: a `vec4f`. */
|
|
26991
|
+
const TAP_FLOATS = 4;
|
|
26992
|
+
/**
|
|
26993
|
+
* The sizes a chain draws into, the shot last: the canvas divided by 4, rounding up, while that stays at least twice
|
|
26994
|
+
* the shot's size, then the shot. A last hop of a ratio near 1 would sample without averaging anything, so a canvas
|
|
26995
|
+
* smaller than 8 x the shot goes straight to it.
|
|
26996
|
+
*
|
|
26997
|
+
* @param canvasWidth - The canvas in device pixels, across.
|
|
26998
|
+
* @param canvasHeight - The canvas in device pixels, down.
|
|
26999
|
+
* @param width - The shot, across.
|
|
27000
|
+
* @param height - The shot, down.
|
|
27001
|
+
* @returns The hops, in order.
|
|
27002
|
+
* @example
|
|
27003
|
+
* ```ts
|
|
27004
|
+
* hopsOf(1080, 2340, 96, 208); // [{ width: 270, height: 585 }, { width: 96, height: 208 }]
|
|
27005
|
+
* ```
|
|
27006
|
+
*/
|
|
27007
|
+
function hopsOf(canvasWidth, canvasHeight, width, height) {
|
|
27008
|
+
const hops = [];
|
|
27009
|
+
let hopWidth = Math.ceil(canvasWidth / HOP_FACTOR);
|
|
27010
|
+
let hopHeight = Math.ceil(canvasHeight / HOP_FACTOR);
|
|
27011
|
+
while (hopWidth >= 2 * width && hopHeight >= 2 * height) {
|
|
27012
|
+
hops.push({
|
|
27013
|
+
width: hopWidth,
|
|
27014
|
+
height: hopHeight
|
|
27015
|
+
});
|
|
27016
|
+
hopWidth = Math.ceil(hopWidth / HOP_FACTOR);
|
|
27017
|
+
hopHeight = Math.ceil(hopHeight / HOP_FACTOR);
|
|
27018
|
+
}
|
|
27019
|
+
hops.push({
|
|
27020
|
+
width,
|
|
27021
|
+
height
|
|
27022
|
+
});
|
|
27023
|
+
return hops;
|
|
27024
|
+
}
|
|
27025
|
+
/**
|
|
27026
|
+
* One side of a Gaussian of radius `ceil(3 * sigma)`, normalised so the centre and twice the rest make 1, its
|
|
27027
|
+
* neighbouring texels paired into one bilinear tap at their weights' centre. At most `MAX_TAPS` taps.
|
|
27028
|
+
*
|
|
27029
|
+
* @param sigma - The sigma in texels; 0 or less is no blur.
|
|
27030
|
+
* @returns The taps, the centre first; none for no blur.
|
|
27031
|
+
* @example
|
|
27032
|
+
* ```ts
|
|
27033
|
+
* gaussianTaps(0); // []
|
|
27034
|
+
* ```
|
|
27035
|
+
*/
|
|
27036
|
+
function gaussianTaps(sigma) {
|
|
27037
|
+
if (sigma <= 0) return [];
|
|
27038
|
+
const radius = Math.min(Math.ceil(RADIUS_SIGMAS * sigma), MAX_RADIUS);
|
|
27039
|
+
const spread = 2 * sigma * sigma;
|
|
27040
|
+
const weightAt = (texel) => Math.exp(-(texel * texel) / spread);
|
|
27041
|
+
let total = 1;
|
|
27042
|
+
for (let texel = 1; texel <= radius; texel += 1) total += 2 * weightAt(texel);
|
|
27043
|
+
const taps = [{
|
|
27044
|
+
offset: 0,
|
|
27045
|
+
weight: 1 / total
|
|
27046
|
+
}];
|
|
27047
|
+
for (let texel = 1; texel <= radius; texel += 2) {
|
|
27048
|
+
const near = weightAt(texel);
|
|
27049
|
+
const far = texel < radius ? weightAt(texel + 1) : 0;
|
|
27050
|
+
const pair = near + far;
|
|
27051
|
+
if (pair > 0) taps.push({
|
|
27052
|
+
offset: (texel * near + (texel + 1) * far) / pair,
|
|
27053
|
+
weight: pair / total
|
|
27054
|
+
});
|
|
27055
|
+
}
|
|
27056
|
+
return taps;
|
|
27057
|
+
}
|
|
27058
|
+
/**
|
|
27059
|
+
* The sigma of a take in texels of the shot, from the reference units of the config, capped.
|
|
27060
|
+
*
|
|
27061
|
+
* @param blur - `shots.blur`.
|
|
27062
|
+
* @param width - `shots.width`.
|
|
27063
|
+
* @param frameWidth - The frame's width in reference units now; 0 while there is no frame.
|
|
27064
|
+
* @returns The sigma; 0 for no blur.
|
|
27065
|
+
* @example
|
|
27066
|
+
* ```ts
|
|
27067
|
+
* sigmaOf(54, 96, 1080); // 4.8
|
|
27068
|
+
* ```
|
|
27069
|
+
*/
|
|
27070
|
+
function sigmaOf(blur, width, frameWidth) {
|
|
27071
|
+
return frameWidth > 0 ? Math.min(blur * width / frameWidth, MAX_SIGMA) : 0;
|
|
27072
|
+
}
|
|
27073
|
+
/**
|
|
27074
|
+
* The uniform of a hop. A hop of a factor of 4 takes two taps a side at +-1 source pixel: an exact box of 4 x 4. The
|
|
27075
|
+
* last hop, of any other factor, takes three a side, a third of the ratio apart.
|
|
27076
|
+
*
|
|
27077
|
+
* @param source - What it reads.
|
|
27078
|
+
* @param target - What it draws.
|
|
27079
|
+
* @param last - True for the hop that ends at the shot.
|
|
27080
|
+
* @returns `texel`, `step`, `size`, `count` of the box shader.
|
|
27081
|
+
* @example
|
|
27082
|
+
* ```ts
|
|
27083
|
+
* boxData({ width: 8, height: 4 }, { width: 2, height: 1 }, false); // [0.125, 0.25, 2, 2, 2, 1, 2, 0]
|
|
27084
|
+
* ```
|
|
27085
|
+
*/
|
|
27086
|
+
function boxData(source, target, last) {
|
|
27087
|
+
const ratioX = source.width / target.width;
|
|
27088
|
+
const ratioY = source.height / target.height;
|
|
27089
|
+
const exactBox = !last || ratioX === HOP_FACTOR && ratioY === HOP_FACTOR;
|
|
27090
|
+
const data = new Float32Array(BOX_FLOATS);
|
|
27091
|
+
data.set([
|
|
27092
|
+
1 / source.width,
|
|
27093
|
+
1 / source.height,
|
|
27094
|
+
exactBox ? BOX_TAPS : ratioX / SPREAD_TAPS,
|
|
27095
|
+
exactBox ? BOX_TAPS : ratioY / SPREAD_TAPS,
|
|
27096
|
+
target.width,
|
|
27097
|
+
target.height,
|
|
27098
|
+
exactBox ? BOX_TAPS : SPREAD_TAPS
|
|
27099
|
+
]);
|
|
27100
|
+
return data;
|
|
27101
|
+
}
|
|
27102
|
+
/**
|
|
27103
|
+
* The uniform of one axis of the Gaussian: one texel along that axis, the size, the tap count, and each tap as the `x`
|
|
27104
|
+
* and `y` of a `vec4f`.
|
|
27105
|
+
*
|
|
27106
|
+
* @param size - The shot.
|
|
27107
|
+
* @param axis - The axis of the pass.
|
|
27108
|
+
* @param taps - The kernel, at most `MAX_TAPS`.
|
|
27109
|
+
* @returns `axis`, `size`, `count`, `taps` of the blur shader.
|
|
27110
|
+
* @example
|
|
27111
|
+
* ```ts
|
|
27112
|
+
* blurData({ width: 4, height: 2 }, "y", [{ offset: 0, weight: 1 }]).slice(0, 5); // [0, 0.5, 4, 2, 1]
|
|
27113
|
+
* ```
|
|
27114
|
+
*/
|
|
27115
|
+
function blurData(size, axis, taps) {
|
|
27116
|
+
const data = /* @__PURE__ */ new Float32Array(72);
|
|
27117
|
+
data.set([
|
|
27118
|
+
axis === "x" ? 1 / size.width : 0,
|
|
27119
|
+
axis === "y" ? 1 / size.height : 0,
|
|
27120
|
+
size.width,
|
|
27121
|
+
size.height,
|
|
27122
|
+
taps.length
|
|
27123
|
+
]);
|
|
27124
|
+
for (const [index, tap] of taps.entries()) data.set([tap.offset, tap.weight], KERNEL_HEAD + index * TAP_FLOATS);
|
|
27125
|
+
return data;
|
|
27126
|
+
}
|
|
27127
|
+
//#endregion
|
|
27128
|
+
//#region src/plugins/renderer/shots/shader.ts
|
|
27129
|
+
/**
|
|
27130
|
+
* @file renderer/shots — the two filters of a chain and their pipelines: a box filter of bilinear taps and one axis of a
|
|
27131
|
+
* Gaussian. One fullscreen triangle each, reading a texture through a sampler. Their weights and sizes live in uniforms
|
|
27132
|
+
* (`chain.ts` writes them), so a kernel that follows the frame's width needs no new pipeline.
|
|
27133
|
+
*/
|
|
27134
|
+
/** The format of a shot, of the hops between the canvas and it, and so of both pipelines' target. */
|
|
27135
|
+
const SHOT_FORMAT = "bgra8unorm";
|
|
27136
|
+
/** The vertex stage and the two bindings every filter reads: a triangle over the whole target. */
|
|
27137
|
+
const SHARED_WGSL = `
|
|
27138
|
+
@group(0) @binding(0) var picture: texture_2d<f32>;
|
|
27139
|
+
@group(0) @binding(1) var smooth_sampler: sampler;
|
|
27140
|
+
|
|
27141
|
+
@vertex fn vertex_main(@builtin(vertex_index) index: u32) -> @builtin(position) vec4f {
|
|
27142
|
+
let corner = vec2f(f32((index << 1u) & 2u), f32(index & 2u));
|
|
27143
|
+
|
|
27144
|
+
return vec4f(corner * 2.0 - 1.0, 0.0, 1.0);
|
|
27145
|
+
}
|
|
27146
|
+
`;
|
|
27147
|
+
/** The box filter: `count` x `count` taps round the centre of a target pixel, `step` source pixels apart. */
|
|
27148
|
+
const BOX_WGSL = `${SHARED_WGSL}
|
|
27149
|
+
struct Box {
|
|
27150
|
+
texel: vec2f,
|
|
27151
|
+
spacing: vec2f,
|
|
27152
|
+
size: vec2f,
|
|
27153
|
+
count: f32,
|
|
27154
|
+
};
|
|
27155
|
+
|
|
27156
|
+
@group(0) @binding(2) var<uniform> box: Box;
|
|
27157
|
+
|
|
27158
|
+
@fragment fn fragment_main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
|
27159
|
+
let uv = position.xy / box.size;
|
|
27160
|
+
let count = i32(box.count);
|
|
27161
|
+
let centre = (box.count - 1.0) / 2.0;
|
|
27162
|
+
var sum = vec4f(0.0);
|
|
27163
|
+
|
|
27164
|
+
for (var y = 0; y < count; y++) {
|
|
27165
|
+
for (var x = 0; x < count; x++) {
|
|
27166
|
+
let place = (vec2f(f32(x), f32(y)) - centre) * box.spacing * box.texel;
|
|
27167
|
+
|
|
27168
|
+
sum += textureSampleLevel(picture, smooth_sampler, uv + place, 0.0);
|
|
27169
|
+
}
|
|
27170
|
+
}
|
|
27171
|
+
|
|
27172
|
+
return vec4f(sum.rgb / (box.count * box.count), 1.0);
|
|
27173
|
+
}
|
|
27174
|
+
`;
|
|
27175
|
+
/** One axis of the Gaussian: the centre, then each tap on both sides. A tap's `x` is its offset, its `y` its weight. */
|
|
27176
|
+
const BLUR_WGSL = `${SHARED_WGSL}
|
|
27177
|
+
struct Kernel {
|
|
27178
|
+
axis: vec2f,
|
|
27179
|
+
size: vec2f,
|
|
27180
|
+
count: f32,
|
|
27181
|
+
taps: array<vec4f, 16>,
|
|
27182
|
+
};
|
|
27183
|
+
|
|
27184
|
+
@group(0) @binding(2) var<uniform> kernel: Kernel;
|
|
27185
|
+
|
|
27186
|
+
@fragment fn fragment_main(@builtin(position) position: vec4f) -> @location(0) vec4f {
|
|
27187
|
+
let uv = position.xy / kernel.size;
|
|
27188
|
+
var sum = textureSampleLevel(picture, smooth_sampler, uv, 0.0) * kernel.taps[0].y;
|
|
27189
|
+
|
|
27190
|
+
for (var index = 1; index < i32(kernel.count); index++) {
|
|
27191
|
+
let tap = kernel.taps[index];
|
|
27192
|
+
let place = tap.x * kernel.axis;
|
|
27193
|
+
|
|
27194
|
+
sum += textureSampleLevel(picture, smooth_sampler, uv + place, 0.0) * tap.y;
|
|
27195
|
+
sum += textureSampleLevel(picture, smooth_sampler, uv - place, 0.0) * tap.y;
|
|
27196
|
+
}
|
|
27197
|
+
|
|
27198
|
+
return vec4f(sum.rgb, 1.0);
|
|
27199
|
+
}
|
|
27200
|
+
`;
|
|
27201
|
+
/**
|
|
27202
|
+
* Compiles one filter off the main thread.
|
|
27203
|
+
*
|
|
27204
|
+
* @param device - The device.
|
|
27205
|
+
* @param code - Its WGSL.
|
|
27206
|
+
* @returns The pipeline.
|
|
27207
|
+
*/
|
|
27208
|
+
function pipelineOf(device, code) {
|
|
27209
|
+
const module = device.createShaderModule({ code });
|
|
27210
|
+
return device.createRenderPipelineAsync({
|
|
27211
|
+
layout: "auto",
|
|
27212
|
+
vertex: {
|
|
27213
|
+
module,
|
|
27214
|
+
entryPoint: "vertex_main"
|
|
27215
|
+
},
|
|
27216
|
+
fragment: {
|
|
27217
|
+
module,
|
|
27218
|
+
entryPoint: "fragment_main",
|
|
27219
|
+
targets: [{ format: SHOT_FORMAT }]
|
|
27220
|
+
},
|
|
27221
|
+
primitive: { topology: "triangle-list" }
|
|
27222
|
+
});
|
|
27223
|
+
}
|
|
27224
|
+
/**
|
|
27225
|
+
* Compiles the pipelines of a device, off the main thread: a take never compiles in the tap frame.
|
|
27226
|
+
*
|
|
27227
|
+
* @param device - The device.
|
|
27228
|
+
* @returns The pipelines and their sampler.
|
|
27229
|
+
*/
|
|
27230
|
+
async function createShotPipes(device) {
|
|
27231
|
+
const [box, blur] = await Promise.all([pipelineOf(device, BOX_WGSL), pipelineOf(device, BLUR_WGSL)]);
|
|
27232
|
+
return {
|
|
27233
|
+
box,
|
|
27234
|
+
blur,
|
|
27235
|
+
sampler: device.createSampler({
|
|
27236
|
+
magFilter: "linear",
|
|
27237
|
+
minFilter: "linear",
|
|
27238
|
+
addressModeU: "clamp-to-edge",
|
|
27239
|
+
addressModeV: "clamp-to-edge"
|
|
27240
|
+
})
|
|
27241
|
+
};
|
|
27242
|
+
}
|
|
27243
|
+
//#endregion
|
|
27244
|
+
//#region src/plugins/renderer/shots/state.ts
|
|
27245
|
+
/**
|
|
27246
|
+
* @file renderer/shots — the state of the shots, the texture of a shot, and what a loss and a stop leave.
|
|
27247
|
+
*/
|
|
27248
|
+
/**
|
|
27249
|
+
* Creates an empty key list. It lives in its own non-exported function because lint rule L5 refuses a collection built
|
|
27250
|
+
* inside an exported declaration.
|
|
27251
|
+
*
|
|
27252
|
+
* @returns An empty list.
|
|
27253
|
+
*/
|
|
27254
|
+
function emptyKeys$1() {
|
|
27255
|
+
return [];
|
|
27256
|
+
}
|
|
27257
|
+
/**
|
|
27258
|
+
* Creates an empty map. Same reason as `emptyKeys`.
|
|
27259
|
+
*
|
|
27260
|
+
* @returns An empty map.
|
|
27261
|
+
*/
|
|
27262
|
+
function emptyShots() {
|
|
27263
|
+
return /* @__PURE__ */ new Map();
|
|
27264
|
+
}
|
|
27265
|
+
/**
|
|
27266
|
+
* Makes the empty state of the shots.
|
|
27267
|
+
*
|
|
27268
|
+
* @returns The shots branch of the plugin state.
|
|
27269
|
+
*/
|
|
27270
|
+
function createShotsState() {
|
|
27271
|
+
return {
|
|
27272
|
+
wanted: emptyKeys$1(),
|
|
27273
|
+
taken: emptyShots(),
|
|
27274
|
+
pipes: void 0,
|
|
27275
|
+
off: void 0,
|
|
27276
|
+
warned: false
|
|
27277
|
+
};
|
|
27278
|
+
}
|
|
27279
|
+
/**
|
|
27280
|
+
* Makes the texture of a shot, on the GPU at once: linear and clamped, so a stretched shot stays soft to its edges, of
|
|
27281
|
+
* the format the pipelines draw, and Pixi's collector leaves it alone. Its own texture, no atlas, no mipmaps.
|
|
27282
|
+
*
|
|
27283
|
+
* @param pixi - The module that draws.
|
|
27284
|
+
* @param host - What registers and uploads it.
|
|
27285
|
+
* @param shots - The config.
|
|
27286
|
+
* @returns The texture.
|
|
27287
|
+
*/
|
|
27288
|
+
function createShotTexture(pixi, host, shots) {
|
|
27289
|
+
const texture = pixi.RenderTexture.create({
|
|
27290
|
+
width: shots.width,
|
|
27291
|
+
height: shots.height,
|
|
27292
|
+
resolution: 1,
|
|
27293
|
+
scaleMode: "linear",
|
|
27294
|
+
addressMode: "clamp-to-edge",
|
|
27295
|
+
autoGarbageCollect: false,
|
|
27296
|
+
format: SHOT_FORMAT,
|
|
27297
|
+
label: "renderer.shot"
|
|
27298
|
+
});
|
|
27299
|
+
host.keep(texture.source, true);
|
|
27300
|
+
host.initSource(texture.source);
|
|
27301
|
+
return texture;
|
|
27302
|
+
}
|
|
27303
|
+
/**
|
|
27304
|
+
* Forgets what a device held: the takes, the shots and the pipelines. The textures went with the device.
|
|
27305
|
+
*
|
|
27306
|
+
* @param state - The shots branch of the plugin state.
|
|
27307
|
+
*/
|
|
27308
|
+
function forgetShots(state) {
|
|
27309
|
+
state.wanted.length = 0;
|
|
27310
|
+
state.taken.clear();
|
|
27311
|
+
state.pipes = void 0;
|
|
27312
|
+
}
|
|
27313
|
+
/**
|
|
27314
|
+
* Removes the texture provider and destroys every shot while the application exists (`stopRenderer` runs it before
|
|
27315
|
+
* `stopHost`).
|
|
27316
|
+
*
|
|
27317
|
+
* @param state - The shots branch of the plugin state.
|
|
27318
|
+
*/
|
|
27319
|
+
function stopShots(state) {
|
|
27320
|
+
state.off?.();
|
|
27321
|
+
state.off = void 0;
|
|
27322
|
+
for (const texture of state.taken.values()) destroyWhole(texture);
|
|
27323
|
+
forgetShots(state);
|
|
27324
|
+
}
|
|
27325
|
+
//#endregion
|
|
26859
27326
|
//#region src/plugins/renderer/sync/hidden.ts
|
|
26860
27327
|
/** The bit of each reason in a mask. */
|
|
26861
27328
|
const BITS = {
|
|
@@ -27767,8 +28234,11 @@ function renderPassesOf(state, kept) {
|
|
|
27767
28234
|
* ends the warm-up of the application: a throw inside Pixi's render leaves its filter stack unbalanced, which no public
|
|
27768
28235
|
* API rebalances, so another probe would only throw again. A filter handed over with its quad draws a mesh of that
|
|
27769
28236
|
* program after it, on WebGPU, inside an error scope: a quad program that does not fit its pipeline fails asynchronously,
|
|
27770
|
-
* as a blank view with nothing in the logs, and this is the one place such a fault can be seen.
|
|
27771
|
-
*
|
|
28237
|
+
* as a blank view with nothing in the logs, and this is the one place such a fault can be seen. A mesh draws onto the
|
|
28238
|
+
* canvas, or inside an outer filter pass or picture, whose target holds no stencil: another pipeline. The texture of the
|
|
28239
|
+
* texture variants cannot make it (a clip gave it a stencil for good), so that draw goes into a second texture no clip
|
|
28240
|
+
* ever draws into, in the frame of the first. The end of a run reaches the monitor through `onWarm`; this file never
|
|
28241
|
+
* imports the monitor (LEAD-FIXES-3 O24).
|
|
27772
28242
|
*/
|
|
27773
28243
|
/** The side of every probe, in CSS pixels: the smallest thing that still draws a triangle. */
|
|
27774
28244
|
const PROBE_SIZE = 4;
|
|
@@ -27803,6 +28273,8 @@ const TEXTURE_VARIANTS = Object.freeze(["texture", "texture+clip"]);
|
|
|
27803
28273
|
const CANVAS_VARIANT = Object.freeze(["canvas"]);
|
|
27804
28274
|
/** WebGL on a canvas that is not cleared: the one variant that leaves no pixel. */
|
|
27805
28275
|
const TEXTURE_VARIANT = Object.freeze(["texture"]);
|
|
28276
|
+
/** The second draw of a quad: a target with no stencil, as an outer filter pass or a picture is. */
|
|
28277
|
+
const PLAIN_VARIANT = Object.freeze(["plain"]);
|
|
27806
28278
|
/**
|
|
27807
28279
|
* The per-particle properties `effects` uploads every frame: the vertex layout its particle pipeline is keyed by.
|
|
27808
28280
|
*
|
|
@@ -27874,6 +28346,13 @@ function buildObjects(pixi) {
|
|
|
27874
28346
|
autoGarbageCollect: false,
|
|
27875
28347
|
label: "renderer.warm.texture"
|
|
27876
28348
|
});
|
|
28349
|
+
const plain = pixi.RenderTexture.create({
|
|
28350
|
+
width: PROBE_SIZE,
|
|
28351
|
+
height: PROBE_SIZE,
|
|
28352
|
+
antialias: false,
|
|
28353
|
+
autoGarbageCollect: false,
|
|
28354
|
+
label: "renderer.warm.plain"
|
|
28355
|
+
});
|
|
27877
28356
|
const holder = new pixi.Container();
|
|
27878
28357
|
const graphics = new pixi.Graphics().rect(0, 0, PROBE_SIZE, PROBE_SIZE).fill(16777215);
|
|
27879
28358
|
root.label = "renderer.warm";
|
|
@@ -27890,6 +28369,7 @@ function buildObjects(pixi) {
|
|
|
27890
28369
|
clip,
|
|
27891
28370
|
mask,
|
|
27892
28371
|
target,
|
|
28372
|
+
plain,
|
|
27893
28373
|
holder,
|
|
27894
28374
|
list: [],
|
|
27895
28375
|
sprite: whiteSprite(pixi),
|
|
@@ -27959,6 +28439,7 @@ function dropObjects(warm) {
|
|
|
27959
28439
|
];
|
|
27960
28440
|
for (const node of nodes) node?.destroy({ children: true });
|
|
27961
28441
|
destroyWhole(objects.target);
|
|
28442
|
+
destroyWhole(objects.plain);
|
|
27962
28443
|
}
|
|
27963
28444
|
/**
|
|
27964
28445
|
* Logs one warning once per key: a probe tree Pixi could not build, or the canvas variants left out.
|
|
@@ -28002,8 +28483,8 @@ function enqueue$1(warm, subject, variants) {
|
|
|
28002
28483
|
});
|
|
28003
28484
|
}
|
|
28004
28485
|
/**
|
|
28005
|
-
* Queues the draws of a filter, then the
|
|
28006
|
-
* filter alone.
|
|
28486
|
+
* Queues the draws of a filter, then the two of its quad: one for the canvas, one for a target with no stencil. A quad
|
|
28487
|
+
* program is a WebGPU program: WebGL draws the filter alone.
|
|
28007
28488
|
*
|
|
28008
28489
|
* @param sctx - Domain context of the sync module.
|
|
28009
28490
|
* @param filter - The filter.
|
|
@@ -28020,7 +28501,11 @@ function enqueueFilter(sctx, filter, variants) {
|
|
|
28020
28501
|
filter,
|
|
28021
28502
|
quad
|
|
28022
28503
|
}, once);
|
|
28023
|
-
|
|
28504
|
+
enqueue$1(warm, {
|
|
28505
|
+
filter,
|
|
28506
|
+
quad
|
|
28507
|
+
}, PLAIN_VARIANT);
|
|
28508
|
+
return variants.length + once.length + PLAIN_VARIANT.length;
|
|
28024
28509
|
}
|
|
28025
28510
|
/**
|
|
28026
28511
|
* Tells whether the renderer can warm anything now: the config asks for draws, a device draws, and no probe threw on
|
|
@@ -28317,14 +28802,14 @@ function drawProbe(sctx, pixi, objects, draw) {
|
|
|
28317
28802
|
const node = nodeOf$1(pixi, warm, objects, draw.subject);
|
|
28318
28803
|
if (node === void 0) return true;
|
|
28319
28804
|
const clipped = draw.variant === "canvas+clip" || draw.variant === "texture+clip";
|
|
28320
|
-
const
|
|
28805
|
+
const target = draw.variant === "texture" || draw.variant === "texture+clip" ? objects.target : void 0;
|
|
28321
28806
|
if (clipped) {
|
|
28322
28807
|
objects.clip.addChild(node);
|
|
28323
28808
|
objects.root.addChild(objects.clipFrame);
|
|
28324
28809
|
} else objects.root.addChild(node);
|
|
28325
28810
|
const scope = openScope(sctx, draw.subject);
|
|
28326
28811
|
try {
|
|
28327
|
-
sctx.deps.host.renderProbe(objects.root,
|
|
28812
|
+
sctx.deps.host.renderProbe(objects.root, draw.variant === "plain" ? objects.plain : target);
|
|
28328
28813
|
return true;
|
|
28329
28814
|
} catch (error) {
|
|
28330
28815
|
failWarm(sctx, draw, error);
|
|
@@ -28385,10 +28870,31 @@ function objectsOf$1(sctx, pixi) {
|
|
|
28385
28870
|
}
|
|
28386
28871
|
}
|
|
28387
28872
|
/**
|
|
28388
|
-
*
|
|
28389
|
-
*
|
|
28390
|
-
*
|
|
28391
|
-
*
|
|
28873
|
+
* Tells whether the next draw of the queue goes with the one before it: a quad's draw into the plain texture.
|
|
28874
|
+
*
|
|
28875
|
+
* @param warm - The warm branch of the sync state.
|
|
28876
|
+
* @returns True when it asks for no frame of its own.
|
|
28877
|
+
*/
|
|
28878
|
+
function ridesAlong(warm) {
|
|
28879
|
+
return warm.queue[warm.head]?.variant === "plain";
|
|
28880
|
+
}
|
|
28881
|
+
/**
|
|
28882
|
+
* Tells whether a warm frame draws one more probe: one is queued, and the budget has room or it asks for none.
|
|
28883
|
+
*
|
|
28884
|
+
* @param warm - The warm branch of the sync state.
|
|
28885
|
+
* @param drawn - The draws of this frame so far.
|
|
28886
|
+
* @param budget - `renderer.warm`.
|
|
28887
|
+
* @returns True when it does.
|
|
28888
|
+
*/
|
|
28889
|
+
function wantsDraw(warm, drawn, budget) {
|
|
28890
|
+
return warm.head < warm.queue.length && (drawn < budget || ridesAlong(warm));
|
|
28891
|
+
}
|
|
28892
|
+
/**
|
|
28893
|
+
* Draws up to `renderer.warm` probes before the stage pass of a drawn frame, and the plain draw of a quad with the draw
|
|
28894
|
+
* before it; answers whether it drew any, so the frame is told to `time` as a probed one. A draw is counted only after
|
|
28895
|
+
* its own render call ran; a queue that still holds draws asks for the next frame; a probe that threw ends the warm-up
|
|
28896
|
+
* there. Allocates nothing while the queue is empty, and nothing but Pixi's own work on a warm frame: the probe tree is
|
|
28897
|
+
* made once per device.
|
|
28392
28898
|
*
|
|
28393
28899
|
* @param sctx - Domain context of the sync module.
|
|
28394
28900
|
* @returns True when a probe was drawn in this frame.
|
|
@@ -28401,7 +28907,7 @@ function warmStep(sctx) {
|
|
|
28401
28907
|
if (pixi === void 0 || objects === void 0) return false;
|
|
28402
28908
|
const budget = sctx.ctx.config.warm;
|
|
28403
28909
|
let drawn = 0;
|
|
28404
|
-
while (drawn
|
|
28910
|
+
while (wantsDraw(warm, drawn, budget)) {
|
|
28405
28911
|
const draw = warm.queue[warm.head];
|
|
28406
28912
|
warm.head += 1;
|
|
28407
28913
|
if (draw === void 0) continue;
|
|
@@ -30338,6 +30844,7 @@ function advance(run, now) {
|
|
|
30338
30844
|
*/
|
|
30339
30845
|
function hang$1(sctx, objects, stage, screen) {
|
|
30340
30846
|
if (stage.children.at(-1) !== objects.top) stage.addChild(objects.top);
|
|
30847
|
+
objects.top.visible = sctx.ctx.state.shots.wanted.length === 0;
|
|
30341
30848
|
objects.veil.position.set(screen.x, screen.y);
|
|
30342
30849
|
objects.veil.scale.set(screen.width, screen.height);
|
|
30343
30850
|
sctx.deps.viewport.apply(objects.frame);
|
|
@@ -32933,8 +33440,9 @@ function withDeps$8(ctx) {
|
|
|
32933
33440
|
* overlay step (spec 22), then `kept` reads the marks before `demand` decides whether the frame is
|
|
32934
33441
|
* drawn and clears them; a drawn frame draws the probes of the warm-up onto the canvas first (F4: the
|
|
32935
33442
|
* stage pass clears them, in the same task, so they never show), then uploads the queued texture sources (F60), then
|
|
32936
|
-
* the kept pictures (`kept.flush`, so the canvas stays one pass, E7), then the stage, then
|
|
32937
|
-
*
|
|
33443
|
+
* the kept pictures (`kept.flush`, so the canvas stays one pass, E7), then the stage, then a shot of the frame just drawn
|
|
33444
|
+
* while the canvas texture holds it (`shots.after`, never of the heat map), then the pixel leg of the kept oracle;
|
|
33445
|
+
* `demand` settles the
|
|
32938
33446
|
* frame (the dev check, the pixel oracle), and `monitor` closes it and hands a drawn one to a
|
|
32939
33447
|
* waiting capture; last, `host` trims Pixi's texture pool when a rest or a scene change is due. The display objects
|
|
32940
33448
|
* are written by the `sync` system. While the overdraw heat map of a dev or debug build is on, every frame asks to be
|
|
@@ -32948,7 +33456,7 @@ function withDeps$8(ctx) {
|
|
|
32948
33456
|
* never a sample of the rate.
|
|
32949
33457
|
*
|
|
32950
33458
|
* @param ctx - Domain context of the renderer plugin.
|
|
32951
|
-
* @param modules - The
|
|
33459
|
+
* @param modules - The seven modules.
|
|
32952
33460
|
*/
|
|
32953
33461
|
function renderFrame(ctx, modules) {
|
|
32954
33462
|
if (modules.host.resolutionPending()) ctx.state.viewport.resizePending = true;
|
|
@@ -32972,7 +33480,9 @@ function renderFrame(ctx, modules) {
|
|
|
32972
33480
|
const uploaded = modules.sync.uploadStep();
|
|
32973
33481
|
const built = modules.sync.takeBuildWork();
|
|
32974
33482
|
modules.kept.flush();
|
|
32975
|
-
|
|
33483
|
+
const rendered = overdraw ? modules.sync.drawOverdraw(modules.host.render) : modules.host.render();
|
|
33484
|
+
modules.shots.after(rendered && !overdraw);
|
|
33485
|
+
if (rendered) {
|
|
32976
33486
|
ctx.deps.time.frameDrawn();
|
|
32977
33487
|
if (probed || uploaded || built) ctx.deps.time.frameProbed();
|
|
32978
33488
|
}
|
|
@@ -33001,16 +33511,21 @@ async function startRenderer(ctx) {
|
|
|
33001
33511
|
modules.host.onReady(() => {
|
|
33002
33512
|
modules.viewport.start();
|
|
33003
33513
|
modules.sync.start();
|
|
33514
|
+
modules.shots.start();
|
|
33004
33515
|
rendererCtx.state.host.cleanups.push(rendererCtx.deps.time.onFrame("input", () => modules.monitor.begin()), rendererCtx.deps.time.onFrame("render", () => renderFrame(rendererCtx, modules)));
|
|
33005
33516
|
modules.monitor.attach();
|
|
33006
33517
|
modules.monitor.attachPasses();
|
|
33007
33518
|
});
|
|
33008
|
-
modules.host.onLoss(() =>
|
|
33519
|
+
modules.host.onLoss(() => {
|
|
33520
|
+
modules.sync.forget();
|
|
33521
|
+
modules.shots.forget();
|
|
33522
|
+
});
|
|
33009
33523
|
modules.host.onRestore((rebuilt) => {
|
|
33010
33524
|
modules.demand.whole("restore");
|
|
33011
33525
|
if (!rebuilt) return;
|
|
33012
33526
|
rendererCtx.state.viewport.resizePending = true;
|
|
33013
33527
|
modules.sync.rebuildAll();
|
|
33528
|
+
modules.shots.start();
|
|
33014
33529
|
modules.monitor.attach();
|
|
33015
33530
|
modules.monitor.attachPasses();
|
|
33016
33531
|
});
|
|
@@ -33018,7 +33533,7 @@ async function startRenderer(ctx) {
|
|
|
33018
33533
|
}
|
|
33019
33534
|
/**
|
|
33020
33535
|
* Stops the renderer in the reverse order of the start: `monitor` answers the waiting captures
|
|
33021
|
-
* and stops its performance monitor, `demand` forgets its marks and pictures, `kept`
|
|
33536
|
+
* and stops its performance monitor, `demand` forgets its marks and pictures, `kept` and `shots` destroy their
|
|
33022
33537
|
* textures, `sync` lets its views go while `world` is still alive, `viewport` drops its observer and its
|
|
33023
33538
|
* probe, and `host` destroys the application. Textures are left to `assets`; a `Display` object
|
|
33024
33539
|
* is left to the game.
|
|
@@ -33029,6 +33544,7 @@ function stopRenderer(scope) {
|
|
|
33029
33544
|
stopMonitor(scope.state.monitor);
|
|
33030
33545
|
stopDemand(scope.state.demand);
|
|
33031
33546
|
stopKept(scope.state.kept);
|
|
33547
|
+
stopShots(scope.state.shots);
|
|
33032
33548
|
stopSync(scope.state.sync);
|
|
33033
33549
|
stopViewport(scope.state.viewport);
|
|
33034
33550
|
stopHost(scope.state.host);
|
|
@@ -33453,6 +33969,252 @@ function installPassCounting(pixi, sinks) {
|
|
|
33453
33969
|
};
|
|
33454
33970
|
}
|
|
33455
33971
|
//#endregion
|
|
33972
|
+
//#region src/plugins/renderer/shots/passes.ts
|
|
33973
|
+
/**
|
|
33974
|
+
* @file renderer/shots — the passes of one take, in one command encoder, submitted once: the canvas down through the
|
|
33975
|
+
* hops to the shot, then a horizontal and a vertical Gaussian through one extra texture of the shot's size. What only
|
|
33976
|
+
* the take needs is made here and destroyed after the submit. A take may allocate: it runs once per switch.
|
|
33977
|
+
*/
|
|
33978
|
+
/** `GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT`. */
|
|
33979
|
+
const HOP_USAGE = 20;
|
|
33980
|
+
/** `GPUBufferUsage.COPY_DST | GPUBufferUsage.UNIFORM`. */
|
|
33981
|
+
const UNIFORM_USAGE = 72;
|
|
33982
|
+
/**
|
|
33983
|
+
* Makes a texture for this take alone.
|
|
33984
|
+
*
|
|
33985
|
+
* @param run - The take.
|
|
33986
|
+
* @param size - Its size.
|
|
33987
|
+
* @returns The texture.
|
|
33988
|
+
*/
|
|
33989
|
+
function hopTexture(run, size) {
|
|
33990
|
+
const texture = run.device.createTexture({
|
|
33991
|
+
size,
|
|
33992
|
+
format: SHOT_FORMAT,
|
|
33993
|
+
usage: HOP_USAGE
|
|
33994
|
+
});
|
|
33995
|
+
run.spent.push(texture);
|
|
33996
|
+
return texture;
|
|
33997
|
+
}
|
|
33998
|
+
/**
|
|
33999
|
+
* Draws one pass: a fullscreen triangle of a filter, from a texture onto another.
|
|
34000
|
+
*
|
|
34001
|
+
* @param run - The take.
|
|
34002
|
+
* @param pipeline - The filter.
|
|
34003
|
+
* @param source - What it reads.
|
|
34004
|
+
* @param target - What it draws.
|
|
34005
|
+
* @param data - Its uniform.
|
|
34006
|
+
*/
|
|
34007
|
+
function drawPass(run, pipeline, source, target, data) {
|
|
34008
|
+
const { device, encoder, pipes, spent } = run;
|
|
34009
|
+
const uniform = device.createBuffer({
|
|
34010
|
+
size: data.byteLength,
|
|
34011
|
+
usage: UNIFORM_USAGE
|
|
34012
|
+
});
|
|
34013
|
+
spent.push(uniform);
|
|
34014
|
+
device.queue.writeBuffer(uniform, 0, data);
|
|
34015
|
+
const group = device.createBindGroup({
|
|
34016
|
+
layout: pipeline.getBindGroupLayout(0),
|
|
34017
|
+
entries: [
|
|
34018
|
+
{
|
|
34019
|
+
binding: 0,
|
|
34020
|
+
resource: source.createView()
|
|
34021
|
+
},
|
|
34022
|
+
{
|
|
34023
|
+
binding: 1,
|
|
34024
|
+
resource: pipes.sampler
|
|
34025
|
+
},
|
|
34026
|
+
{
|
|
34027
|
+
binding: 2,
|
|
34028
|
+
resource: { buffer: uniform }
|
|
34029
|
+
}
|
|
34030
|
+
]
|
|
34031
|
+
});
|
|
34032
|
+
const pass = encoder.beginRenderPass({ colorAttachments: [{
|
|
34033
|
+
view: target.createView(),
|
|
34034
|
+
loadOp: "clear",
|
|
34035
|
+
storeOp: "store"
|
|
34036
|
+
}] });
|
|
34037
|
+
pass.setPipeline(pipeline);
|
|
34038
|
+
pass.setBindGroup(0, group);
|
|
34039
|
+
pass.draw(3);
|
|
34040
|
+
pass.end();
|
|
34041
|
+
}
|
|
34042
|
+
/**
|
|
34043
|
+
* Draws the hops from the canvas down to the shot.
|
|
34044
|
+
*
|
|
34045
|
+
* @param run - The take.
|
|
34046
|
+
* @param canvas - The canvas texture of this frame.
|
|
34047
|
+
* @param shot - The texture of the shot.
|
|
34048
|
+
*/
|
|
34049
|
+
function drawHops(run, canvas, shot) {
|
|
34050
|
+
const hops = hopsOf(canvas.width, canvas.height, shot.width, shot.height);
|
|
34051
|
+
let source = canvas;
|
|
34052
|
+
for (const [index, hop] of hops.entries()) {
|
|
34053
|
+
const last = index === hops.length - 1;
|
|
34054
|
+
const target = last ? shot : hopTexture(run, hop);
|
|
34055
|
+
drawPass(run, run.pipes.box, source, target, boxData(source, hop, last));
|
|
34056
|
+
source = target;
|
|
34057
|
+
}
|
|
34058
|
+
}
|
|
34059
|
+
/**
|
|
34060
|
+
* Blurs the shot in place: across into a texture of its size, and back down.
|
|
34061
|
+
*
|
|
34062
|
+
* @param run - The take.
|
|
34063
|
+
* @param shot - The texture of the shot.
|
|
34064
|
+
* @param taps - The kernel.
|
|
34065
|
+
*/
|
|
34066
|
+
function drawBlur(run, shot, taps) {
|
|
34067
|
+
const across = hopTexture(run, shot);
|
|
34068
|
+
drawPass(run, run.pipes.blur, shot, across, blurData(shot, "x", taps));
|
|
34069
|
+
drawPass(run, run.pipes.blur, across, shot, blurData(shot, "y", taps));
|
|
34070
|
+
}
|
|
34071
|
+
/**
|
|
34072
|
+
* Takes one picture of the canvas into every target: the chain draws the first, and the others are copies of it, so
|
|
34073
|
+
* two keys of one frame cost one chain.
|
|
34074
|
+
*
|
|
34075
|
+
* @param device - The device.
|
|
34076
|
+
* @param pipes - The pipelines of that device.
|
|
34077
|
+
* @param canvas - The canvas texture of this frame.
|
|
34078
|
+
* @param targets - The textures of the shots, each once, all of one size.
|
|
34079
|
+
* @param sigma - The Gaussian in texels of the shot; 0 for none.
|
|
34080
|
+
*/
|
|
34081
|
+
function drawShot(device, pipes, canvas, targets, sigma) {
|
|
34082
|
+
const [shot, ...copies] = targets;
|
|
34083
|
+
if (shot === void 0) return;
|
|
34084
|
+
const encoder = device.createCommandEncoder();
|
|
34085
|
+
const run = {
|
|
34086
|
+
device,
|
|
34087
|
+
pipes,
|
|
34088
|
+
encoder,
|
|
34089
|
+
spent: []
|
|
34090
|
+
};
|
|
34091
|
+
const taps = gaussianTaps(sigma);
|
|
34092
|
+
drawHops(run, canvas, shot);
|
|
34093
|
+
if (taps.length > 0) drawBlur(run, shot, taps);
|
|
34094
|
+
for (const copy of copies) encoder.copyTextureToTexture({ texture: shot }, { texture: copy }, shot);
|
|
34095
|
+
device.queue.submit([encoder.finish()]);
|
|
34096
|
+
for (const resource of run.spent) resource.destroy();
|
|
34097
|
+
}
|
|
34098
|
+
//#endregion
|
|
34099
|
+
//#region src/plugins/renderer/shots/api.ts
|
|
34100
|
+
/** Shots kept when `shots.keep` is left out. */
|
|
34101
|
+
const DEFAULT_KEEP = 8;
|
|
34102
|
+
/**
|
|
34103
|
+
* Compiles the pipelines of a device, off the main thread. What ends on a device that is no longer the live one is
|
|
34104
|
+
* dropped, a failure too: the restore compiles again. A failure on the live device leaves `take` a no-op, and warns
|
|
34105
|
+
* once.
|
|
34106
|
+
*
|
|
34107
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
34108
|
+
* @param deps - The modules it reads.
|
|
34109
|
+
* @param device - The device.
|
|
34110
|
+
*/
|
|
34111
|
+
async function compilePipes(ctx, deps, device) {
|
|
34112
|
+
const state = ctx.state.shots;
|
|
34113
|
+
try {
|
|
34114
|
+
const pipes = await createShotPipes(device);
|
|
34115
|
+
if (deps.host.device() === device) state.pipes = pipes;
|
|
34116
|
+
} catch (error) {
|
|
34117
|
+
if (deps.host.device() !== device || state.warned) return;
|
|
34118
|
+
state.warned = true;
|
|
34119
|
+
ctx.log.warn("renderer:shots-unavailable", { error });
|
|
34120
|
+
}
|
|
34121
|
+
}
|
|
34122
|
+
/**
|
|
34123
|
+
* The texture of the oldest shot, which leaves its key to a new one, once `keep` shots stand.
|
|
34124
|
+
*
|
|
34125
|
+
* @param state - The shots branch of the plugin state.
|
|
34126
|
+
* @param keep - The limit.
|
|
34127
|
+
* @param stale - The keys whose views look again: the key that went joins them.
|
|
34128
|
+
* @returns Its texture, or `undefined` while there is room.
|
|
34129
|
+
*/
|
|
34130
|
+
function recycled(state, keep, stale) {
|
|
34131
|
+
const [oldest] = state.taken;
|
|
34132
|
+
if (oldest === void 0 || state.taken.size < keep) return void 0;
|
|
34133
|
+
state.taken.delete(oldest[0]);
|
|
34134
|
+
stale.push(oldest[0]);
|
|
34135
|
+
return oldest[1];
|
|
34136
|
+
}
|
|
34137
|
+
/**
|
|
34138
|
+
* Seats every wanted key on a texture: its own for a retake, as the newest; the oldest's at the limit; a new one
|
|
34139
|
+
* otherwise. Keys may end on one texture when a frame wants more than `keep`.
|
|
34140
|
+
*
|
|
34141
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
34142
|
+
* @param deps - The modules it reads.
|
|
34143
|
+
* @param pixi - The module that draws.
|
|
34144
|
+
* @param shots - The config.
|
|
34145
|
+
* @param stale - The keys whose views look again: the keys that went join them.
|
|
34146
|
+
* @returns The textures to draw, each once.
|
|
34147
|
+
*/
|
|
34148
|
+
function seatWanted(ctx, deps, pixi, shots, stale) {
|
|
34149
|
+
const state = ctx.state.shots;
|
|
34150
|
+
const keep = shots.keep ?? DEFAULT_KEEP;
|
|
34151
|
+
const seats = /* @__PURE__ */ new Set();
|
|
34152
|
+
for (const key of state.wanted) {
|
|
34153
|
+
const held = state.taken.get(key);
|
|
34154
|
+
state.taken.delete(key);
|
|
34155
|
+
const texture = held ?? recycled(state, keep, stale) ?? createShotTexture(pixi, deps.host, shots);
|
|
34156
|
+
state.taken.set(key, texture);
|
|
34157
|
+
seats.add(texture);
|
|
34158
|
+
}
|
|
34159
|
+
return seats;
|
|
34160
|
+
}
|
|
34161
|
+
/**
|
|
34162
|
+
* Reads this frame's canvas into the wanted keys, once, and asks for one more frame: the look shows from it, and the
|
|
34163
|
+
* views of the keys, which look again, draw from it. Nothing that can be read: nothing is taken.
|
|
34164
|
+
*
|
|
34165
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
34166
|
+
* @param deps - The modules it reads.
|
|
34167
|
+
*/
|
|
34168
|
+
function shoot(ctx, deps) {
|
|
34169
|
+
const { shots } = ctx.config;
|
|
34170
|
+
const { pipes, wanted } = ctx.state.shots;
|
|
34171
|
+
const device = deps.host.device();
|
|
34172
|
+
const pixi = deps.host.pixi();
|
|
34173
|
+
const canvas = deps.host.canvasTexture();
|
|
34174
|
+
if (shots === void 0 || pipes === void 0) return;
|
|
34175
|
+
if (device === void 0 || pixi === void 0 || canvas === void 0) return;
|
|
34176
|
+
const stale = [...wanted];
|
|
34177
|
+
const targets = [];
|
|
34178
|
+
for (const texture of seatWanted(ctx, deps, pixi, shots, stale)) {
|
|
34179
|
+
const target = deps.host.gpuTexture(texture.source);
|
|
34180
|
+
if (target !== void 0) targets.push(target);
|
|
34181
|
+
}
|
|
34182
|
+
drawShot(device, pipes, canvas, targets, sigmaOf(shots.blur, shots.width, deps.viewport.size().width));
|
|
34183
|
+
deps.sync.textures.invalidate(stale);
|
|
34184
|
+
deps.demand.request();
|
|
34185
|
+
}
|
|
34186
|
+
/**
|
|
34187
|
+
* Creates the shots module. It keeps nothing of its own: the plugin builds its modules more than once over one state.
|
|
34188
|
+
*
|
|
34189
|
+
* @param ctx - Domain context of the renderer plugin.
|
|
34190
|
+
* @param deps - The modules it reads.
|
|
34191
|
+
* @returns The shots API and its internal half.
|
|
34192
|
+
*/
|
|
34193
|
+
function createShotsApi(ctx, deps) {
|
|
34194
|
+
const state = ctx.state.shots;
|
|
34195
|
+
return {
|
|
34196
|
+
take: (key) => {
|
|
34197
|
+
if (state.pipes === void 0 || !deps.host.ready()) return;
|
|
34198
|
+
if (ctx.deps.world.ecs.mode() !== "live") return;
|
|
34199
|
+
if (!state.wanted.includes(key)) state.wanted.push(key);
|
|
34200
|
+
deps.demand.request();
|
|
34201
|
+
},
|
|
34202
|
+
has: (key) => state.taken.has(key),
|
|
34203
|
+
start: () => {
|
|
34204
|
+
if (ctx.config.shots === void 0) return;
|
|
34205
|
+
state.off ??= deps.sync.textures.provide((key) => state.taken.get(key));
|
|
34206
|
+
const device = deps.host.device();
|
|
34207
|
+
if (device !== void 0) compilePipes(ctx, deps, device);
|
|
34208
|
+
},
|
|
34209
|
+
after: (drawn) => {
|
|
34210
|
+
if (state.wanted.length === 0) return;
|
|
34211
|
+
if (drawn) shoot(ctx, deps);
|
|
34212
|
+
state.wanted.length = 0;
|
|
34213
|
+
},
|
|
34214
|
+
forget: () => forgetShots(state)
|
|
34215
|
+
};
|
|
34216
|
+
}
|
|
34217
|
+
//#endregion
|
|
33456
34218
|
//#region src/plugins/renderer/sync/hit-test.ts
|
|
33457
34219
|
/** How deep a parent chain or a container tree is followed. */
|
|
33458
34220
|
const MAX_DEPTH$6 = 32;
|
|
@@ -36244,8 +37006,8 @@ function createViewportApi(ctx, deps) {
|
|
|
36244
37006
|
//#region src/plugins/renderer/api.ts
|
|
36245
37007
|
/**
|
|
36246
37008
|
* @file renderer plugin — API factory. The one place that builds `host`, `viewport`, `demand`,
|
|
36247
|
-
* `kept`, `sync` and `monitor` in the accepted injection order, and the one place that
|
|
36248
|
-
* them to their public half.
|
|
37009
|
+
* `kept`, `sync`, `shots` and `monitor` in the accepted injection order, and the one place that
|
|
37010
|
+
* reduces them to their public half.
|
|
36249
37011
|
*/
|
|
36250
37012
|
/**
|
|
36251
37013
|
* The counting `host` installs before `new Application()`: the seven counting classes (BatcherPipe among them) of
|
|
@@ -36274,7 +37036,7 @@ const syncWriters = {
|
|
|
36274
37036
|
renderPassesOf
|
|
36275
37037
|
};
|
|
36276
37038
|
/**
|
|
36277
|
-
* Builds the
|
|
37039
|
+
* Builds the seven modules in the accepted order `host → viewport → demand → kept → sync → shots → monitor`.
|
|
36278
37040
|
* Each keeps its data in its branch of `ctx.state`, so these objects are views on the plugin
|
|
36279
37041
|
* state, not owners of it. `host` gets the counting of `monitor` up front, because it installs
|
|
36280
37042
|
* the classes before `monitor` exists (the six of a dev or debug build, the pass counter of the
|
|
@@ -36282,11 +37044,12 @@ const syncWriters = {
|
|
|
36282
37044
|
* keep their identity; `kept` reads the views of `sync` the same way, and gives a bare view its
|
|
36283
37045
|
* wrapper through `sync.wrapForPicture` (spec 23 D4), reached through a holder filled once `sync`
|
|
36284
37046
|
* exists; `sync` marks every write in
|
|
36285
|
-
* `demand` and asks `kept` where a view's filters hang; `
|
|
37047
|
+
* `demand` and asks `kept` where a view's filters hang; `shots` provides its textures through `sync`,
|
|
37048
|
+
* which reads its waiting keys through the state alone; `monitor` gets the others, since a legend
|
|
36286
37049
|
* places views on the picture and the performance log reads all of them.
|
|
36287
37050
|
*
|
|
36288
37051
|
* @param ctx - Domain context of the renderer plugin.
|
|
36289
|
-
* @returns The
|
|
37052
|
+
* @returns The seven modules with their public and internal methods.
|
|
36290
37053
|
*/
|
|
36291
37054
|
function createModules$1(ctx) {
|
|
36292
37055
|
const host = createHostApi(ctx, {
|
|
@@ -36320,6 +37083,12 @@ function createModules$1(ctx) {
|
|
|
36320
37083
|
demand,
|
|
36321
37084
|
kept,
|
|
36322
37085
|
sync,
|
|
37086
|
+
shots: createShotsApi(ctx, {
|
|
37087
|
+
host,
|
|
37088
|
+
viewport,
|
|
37089
|
+
demand,
|
|
37090
|
+
sync
|
|
37091
|
+
}),
|
|
36323
37092
|
monitor: createMonitorApi(ctx, {
|
|
36324
37093
|
host,
|
|
36325
37094
|
viewport,
|
|
@@ -36372,14 +37141,14 @@ function exposeSync(sync) {
|
|
|
36372
37141
|
};
|
|
36373
37142
|
}
|
|
36374
37143
|
/**
|
|
36375
|
-
* Creates the renderer API: `app.renderer.host`, `.viewport`, `.sync` and `.monitor`, and
|
|
37144
|
+
* Creates the renderer API: `app.renderer.host`, `.viewport`, `.sync`, `.shots` and `.monitor`, and
|
|
36376
37145
|
* `stats()` and `capture()` of `monitor` on the plugin itself.
|
|
36377
37146
|
*
|
|
36378
37147
|
* @param ctx - Kernel context of the renderer plugin.
|
|
36379
37148
|
* @returns The plugin API.
|
|
36380
37149
|
*/
|
|
36381
37150
|
function createRendererApi(ctx) {
|
|
36382
|
-
const { host, viewport, demand, sync, monitor } = createModules$1({
|
|
37151
|
+
const { host, viewport, demand, sync, shots, monitor } = createModules$1({
|
|
36383
37152
|
...ctx,
|
|
36384
37153
|
deps: resolveDeps$6(ctx)
|
|
36385
37154
|
});
|
|
@@ -36403,6 +37172,10 @@ function createRendererApi(ctx) {
|
|
|
36403
37172
|
sections: monitor.sections,
|
|
36404
37173
|
counts: monitor.counts
|
|
36405
37174
|
},
|
|
37175
|
+
shots: {
|
|
37176
|
+
take: shots.take,
|
|
37177
|
+
has: shots.has
|
|
37178
|
+
},
|
|
36406
37179
|
invalidate: demand.invalidate,
|
|
36407
37180
|
stats: monitor.stats,
|
|
36408
37181
|
capture: monitor.capture
|
|
@@ -36733,6 +37506,8 @@ const RING_FRAMES = {
|
|
|
36733
37506
|
const MAX_WARM = 16;
|
|
36734
37507
|
/** The most textures the upload queue may put on the GPU in one drawn frame: about 9 ms each on a Galaxy A26. */
|
|
36735
37508
|
const MAX_UPLOADS = 8;
|
|
37509
|
+
/** The most texels a side of a shot may have. */
|
|
37510
|
+
const MAX_SHOT_SIDE = 512;
|
|
36736
37511
|
/**
|
|
36737
37512
|
* Tells a finite number of at least 0 from anything else a config can hold.
|
|
36738
37513
|
*
|
|
@@ -36778,12 +37553,44 @@ function checkAdaptiveScale(adaptiveScale) {
|
|
|
36778
37553
|
if (devices !== "phone" && devices !== "all") throw new Error(`[game] renderer.adaptiveScale.devices is ${String(devices)}.\n Give "phone" or "all".`);
|
|
36779
37554
|
}
|
|
36780
37555
|
/**
|
|
37556
|
+
* Tells a side of a shot from anything else a config can hold.
|
|
37557
|
+
*
|
|
37558
|
+
* @param value - The config value.
|
|
37559
|
+
* @returns True for a whole number from 1 to 512.
|
|
37560
|
+
* @example
|
|
37561
|
+
* ```ts
|
|
37562
|
+
* isShotSide(512); // true
|
|
37563
|
+
* ```
|
|
37564
|
+
*/
|
|
37565
|
+
function isShotSide(value) {
|
|
37566
|
+
return Number.isInteger(value) && Number(value) >= 1 && Number(value) <= MAX_SHOT_SIDE;
|
|
37567
|
+
}
|
|
37568
|
+
/**
|
|
37569
|
+
* Checks the shots of the config: left out, or an object of a size, a blur and, when given, a limit.
|
|
37570
|
+
*
|
|
37571
|
+
* @param shots - What the config holds.
|
|
37572
|
+
* @throws {Error} When it is no object, `width` or `height` is not a whole number from 1 to 512, `blur` is not a finite
|
|
37573
|
+
* number of at least 0, or `keep` is given and not a whole number of at least 1.
|
|
37574
|
+
*/
|
|
37575
|
+
function checkShots(shots) {
|
|
37576
|
+
if (shots === void 0) return;
|
|
37577
|
+
if (typeof shots !== "object" || shots === null) throw new Error(`[game] renderer.shots is ${String(shots)}.\n Give { width, height, blur } or leave it out.`);
|
|
37578
|
+
const width = "width" in shots ? shots.width : void 0;
|
|
37579
|
+
const height = "height" in shots ? shots.height : void 0;
|
|
37580
|
+
const blur = "blur" in shots ? shots.blur : void 0;
|
|
37581
|
+
const keep = "keep" in shots ? shots.keep : void 0;
|
|
37582
|
+
if (!isShotSide(width)) throw new Error(`[game] renderer.shots.width is ${String(width)}.\n Give the texels across, a whole number from 1 to 512.`);
|
|
37583
|
+
if (!isShotSide(height)) throw new Error(`[game] renderer.shots.height is ${String(height)}.\n Give the texels down, a whole number from 1 to 512.`);
|
|
37584
|
+
if (!isCount(blur)) throw new Error(`[game] renderer.shots.blur is ${String(blur)}.\n Give the sigma in reference units, 0 or more.`);
|
|
37585
|
+
if (keep !== void 0 && !(Number.isInteger(keep) && Number(keep) >= 1)) throw new Error(`[game] renderer.shots.keep is ${String(keep)}.\n Give the shots kept, a whole number of at least 1.`);
|
|
37586
|
+
}
|
|
37587
|
+
/**
|
|
36781
37588
|
* Checks the numbers of the config a game can get wrong, at `createApp`, in every build: the
|
|
36782
37589
|
* resolution cap, the pool trim, the adaptive render scale, the performance monitor, the budget of the kept pictures,
|
|
36783
|
-
* the probe draws of the warm-up
|
|
37590
|
+
* the probe draws of the warm-up, the textures uploaded per drawn frame and the shots.
|
|
36784
37591
|
*
|
|
36785
37592
|
* @param config - The resolved plugin config.
|
|
36786
|
-
* @throws {Error} When `maxResolution` is not a number above 0, `poolTrim` or `
|
|
37593
|
+
* @throws {Error} When `maxResolution` is not a number above 0, `poolTrim`, `adaptiveScale` or `shots` fails its check,
|
|
36787
37594
|
* `monitor.budgetMs` is neither `"rate"` nor a number above 0, `monitor.frames` is not a whole
|
|
36788
37595
|
* number from 64 to 16384, `keptMb` is not a finite number of at least 0, `warm` is not a
|
|
36789
37596
|
* whole number from 0 to 16, or `uploads` is not a whole number from 0 to 8.
|
|
@@ -36794,6 +37601,7 @@ function checkConfig$1(config) {
|
|
|
36794
37601
|
if (!Number.isFinite(maxResolution) || maxResolution <= 0) throw new Error(`[game] renderer.maxResolution is ${maxResolution}.\n Give a number above 0.`);
|
|
36795
37602
|
checkPoolTrim(config.poolTrim);
|
|
36796
37603
|
checkAdaptiveScale(config.adaptiveScale);
|
|
37604
|
+
checkShots(config.shots);
|
|
36797
37605
|
if (budgetMs !== "rate" && !(Number.isFinite(budgetMs) && budgetMs > 0)) throw new Error(`[game] renderer.monitor.budgetMs is ${String(budgetMs)}.\n Give the frame budget in milliseconds, or "rate" for one frame of the current rate.`);
|
|
36798
37606
|
if (!Number.isInteger(frames) || frames < RING_FRAMES.min || frames > RING_FRAMES.max) throw new Error(`[game] renderer.monitor.frames is ${frames}.\n Give a whole number from 64 to 16384.`);
|
|
36799
37607
|
if (typeof keptMb !== "number" || !Number.isFinite(keptMb) || keptMb < 0) throw new Error(`[game] renderer.keptMb is ${String(keptMb)}.\n Give the MiB kept pictures may hold, or 0 to keep none.`);
|
|
@@ -36820,7 +37628,8 @@ function createRendererState(ctx) {
|
|
|
36820
37628
|
sync: createSyncState(ctx.config.debug),
|
|
36821
37629
|
monitor: createMonitorState(ctx.config.monitor),
|
|
36822
37630
|
demand: createDemandState(ctx.config.debug.verifyFrames === true),
|
|
36823
|
-
kept: createKeptState(ctx.config)
|
|
37631
|
+
kept: createKeptState(ctx.config),
|
|
37632
|
+
shots: createShotsState()
|
|
36824
37633
|
};
|
|
36825
37634
|
}
|
|
36826
37635
|
/**
|
|
@@ -36886,7 +37695,8 @@ const rendererPlugin = /*#__PURE__*/ createPlugin$1("renderer", {
|
|
|
36886
37695
|
adaptiveScale: {
|
|
36887
37696
|
floor: .75,
|
|
36888
37697
|
devices: "phone"
|
|
36889
|
-
}
|
|
37698
|
+
},
|
|
37699
|
+
shots: void 0
|
|
36890
37700
|
},
|
|
36891
37701
|
events: (register) => register.map({ "renderer:device-lost": "The GPU device or context was lost; the game is paused" }),
|
|
36892
37702
|
createState: createRendererState,
|
|
@@ -72765,6 +73575,7 @@ function cubicBezier(x1, y1, x2, y2) {
|
|
|
72765
73575
|
* | renderer | keptMb | 64, MiB the kept pictures may hold: a filtered view that did not change is drawn from its picture, the least recently drawn goes first; 0 keeps none |
|
|
72766
73576
|
* | renderer | warm | 1, probe draws a drawn frame that create the GPU pipelines while the game loads; 0 creates each in the first frame that needs it |
|
|
72767
73577
|
* | renderer | uploads | 1, texture sources `sync.textures.upload` puts on the GPU a drawn frame (~9 ms each on the A26); 0 turns the queue off |
|
|
73578
|
+
* | renderer | shots | undefined, no shot is taken; { width, height, blur, keep? }: texels 1–512 a side, sigma in reference units, pictures kept (8); shallow merge: a game that sets `shots` gives width, height and blur |
|
|
72768
73579
|
* | input | tapSlopPx | 12 |
|
|
72769
73580
|
* | input | longPressMs | 450 |
|
|
72770
73581
|
* | input | dragStartPx | 8 |
|