@moku-labs/game 0.15.161 → 0.15.163
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/page.mjs +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-CLhKYlot.d.mts → commands-CAvCuLaL.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-3zxu6rIq.d.mts → define-DSOTwTUY.d.mts} +2 -2
- package/dist/{headless-DFkrIVO4.d.mts → headless-PANjNy6-.d.mts} +1 -1
- package/dist/{index-CVmEBBm5.d.mts → index-oS9wiCoO.d.mts} +12 -12
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/inspect.d.mts +6 -6
- package/dist/inspect.mjs +1 -1
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-CI8p6sVn.d.mts → runtime-Bb5sNTGb.d.mts} +1 -1
- package/dist/{sources-D9Fk3Z4d.mjs → sources-DRP-bS6e.mjs} +2 -1
- package/dist/{src-qeTzNTZA.mjs → src-DBhsppmi.mjs} +1075 -308
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-CM7Ng3EN.d.mts → types-BuN6rLDs.d.mts} +2 -2
- package/dist/{types-Bl9jyah_.d.mts → types-C4d1Ptfc.d.mts} +1881 -39
- package/dist/{types-D1xdKk_t.d.mts → types-DTkhpupa.d.mts} +91 -22
- package/dist/{types-DHWjH6p9.d.mts → types-SUCTOeQZ.d.mts} +4 -4
- package/dist/types-dSup2_q9.d.mts +1841 -0
- package/dist/{visual-D_4mmn1u.d.mts → visual-BZrQT1r1.d.mts} +5 -6
- package/dist/visual.d.mts +1 -1
- package/dist/visual.mjs +1 -1
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/dist/types-D-vnlN3n.d.mts +0 -3632
|
@@ -0,0 +1,1841 @@
|
|
|
1
|
+
import { A as FilterSlotInputs, Ar as Api$1, Q as Api$2, Ur as Events$2, Vr as Api$4, Wn as Descriptor, Wr as Json, at as PixiSprite, b as Events$3, bi as Require, br as Entity, bt as FilterCache, gr as ComponentHandle, it as PixiModule, j as FilterSlotQuad, k as FilterSlot, mn as Api, nt as PixiFilter, oi as Events$4, ot as PixiTexture, rt as PixiGpuProgram, s as Events, st as PixiUniformGroup, t as Api$3, ui as Api$5, vr as ComponentType, vt as Point, yi as Events$1 } from "./types-DTkhpupa.mjs";
|
|
2
|
+
import { nt as AnimApi } from "./types-C4d1Ptfc.mjs";
|
|
3
|
+
import { Log } from "@moku-labs/common/browser";
|
|
4
|
+
import { PluginCtx } from "@moku-labs/core";
|
|
5
|
+
|
|
6
|
+
//#region src/plugins/effects/filters/types.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* One uniform of a custom filter, as declared: a number is an `f32` (`float` in GLSL), `{ color }`
|
|
9
|
+
* a `0xrrggbb` hex sent as a `vec3<f32>` (`vec3`), a tuple of 2 to 4 numbers a `vecN<f32>`
|
|
10
|
+
* (`vecN`).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const uniforms: Record<string, UniformDeclaration> = { amount: 0.5, color: { color: 0xffd700 }, offset: [2, 2] };
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
type UniformDeclaration = number | {
|
|
18
|
+
readonly color: number;
|
|
19
|
+
} | readonly [number, number] | readonly [number, number, number] | readonly [number, number, number, number];
|
|
20
|
+
/**
|
|
21
|
+
* The component field a uniform declaration becomes: a number for a number and for a colour, a
|
|
22
|
+
* list of numbers for a tuple.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* type Amount = UniformValue<0.5>; // number
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
type UniformValue<Declaration> = Declaration extends number ? number : Declaration extends {
|
|
30
|
+
readonly color: number;
|
|
31
|
+
} ? number : readonly number[];
|
|
32
|
+
/**
|
|
33
|
+
* The value of a filter component made by `defineFilter`: one field per uniform, then `enabled`
|
|
34
|
+
* and `order`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* type TintValue = FilterValueOf<{ amount: number; color: { color: number } }>;
|
|
39
|
+
* // { amount: number; color: number; enabled: boolean; order: number }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
type FilterValueOf<Uniforms extends Record<string, UniformDeclaration>> = { -readonly [Name in keyof Uniforms]: UniformValue<Uniforms[Name]> } & {
|
|
43
|
+
enabled: boolean;
|
|
44
|
+
order: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A rectangle in the filtered entity's own units — the space its box, its hit box and its children's positions are in
|
|
48
|
+
* (reference units for a view at the root without scale): x, y, width, height.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // A lens disc of reach 88 around (195, 189): the 176 × 176 box it can draw in.
|
|
53
|
+
* const area: FilterArea = [107, 101, 176, 176];
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
type FilterArea = readonly [x: number, y: number, width: number, height: number];
|
|
57
|
+
/**
|
|
58
|
+
* What `defineFilter` takes besides the id. Both bodies are required, so the filter draws on
|
|
59
|
+
* WebGPU and on the WebGL fallback: `wgsl` is the WGSL fragment body only, the engine prepends the
|
|
60
|
+
* vertex stage, the input bindings and the `FilterUniforms` struct; `glsl` is its GLSL ES 3.0 twin
|
|
61
|
+
* over the same uniform names, the engine prepends the version, the inputs, `finalColor` and one
|
|
62
|
+
* `uniform` per declared uniform.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* // A Memory Missing's frost on the layer of its panels: the body reads a blurred copy of the scene drawn under them.
|
|
67
|
+
* const Frost = defineFilter("Frost", {
|
|
68
|
+
* wgsl: FROST_WGSL,
|
|
69
|
+
* glsl: FROST_GLSL,
|
|
70
|
+
* uniforms: { view: [0, 0, 1], rectA: [0, 0, 0, 0], strength: 16, vivid: 1.2 },
|
|
71
|
+
* backdrop: true,
|
|
72
|
+
* inputs: { blur: { from: "back", stages: [FrostBox4, FrostHalf, FrostGauss], chain: frostChain } },
|
|
73
|
+
* area: value => [value.rectA[0] ?? 0, value.rectA[1] ?? 0, value.rectA[2] ?? 0, value.rectA[3] ?? 0],
|
|
74
|
+
* fallback: FrostVeil
|
|
75
|
+
* });
|
|
76
|
+
* [Frost.filter.backdrop, Frost.filter.cache, Frost.filter.inputs[0]?.from]; // [true, "screen", "back"]
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
type FilterSpec<Uniforms extends Record<string, UniformDeclaration>> = {
|
|
80
|
+
/** The WGSL fragment body: `fn mainFragment` and its helpers, without the engine's header. */readonly wgsl: string;
|
|
81
|
+
/**
|
|
82
|
+
* The GLSL ES 3.0 fragment body: `void main()`, which sets `finalColor`, and its helpers, without
|
|
83
|
+
* the engine's header. It reads each uniform under its bare name: `amount`, not `fu.amount`.
|
|
84
|
+
*/
|
|
85
|
+
readonly glsl: string; /** The uniforms in struct order. Default `{}`. */
|
|
86
|
+
readonly uniforms?: Uniforms; /** Render passes one apply of the filter costs, an integer of at least 1. Default `1`. */
|
|
87
|
+
readonly passes?: number; /** Pixels around the view's bounds, or the name of a number uniform whose live value they are. Default `0`. */
|
|
88
|
+
readonly padding?: number | string;
|
|
89
|
+
/**
|
|
90
|
+
* Second textures the body reads, by name: `blur` declares `sampleBlur(uv)` in the WGSL and the GLSL, with the
|
|
91
|
+
* texture, its sampler and two uniforms the engine fills. Leave `passes` out: the engine counts them. Default none.
|
|
92
|
+
*/
|
|
93
|
+
readonly inputs?: Readonly<Record<string, FilterInput<FilterValueOf<Uniforms>>>>;
|
|
94
|
+
/**
|
|
95
|
+
* What draws instead when the filter is broken (its shader or a stage does not compile on the device, its apply
|
|
96
|
+
* throws, its chain fails): another filter over a subset of its uniforms, with the same value. Default none: a broken
|
|
97
|
+
* filter leaves its view unfiltered.
|
|
98
|
+
*/
|
|
99
|
+
readonly fallback?: FilterStage;
|
|
100
|
+
/**
|
|
101
|
+
* What the renderer may do with a view this filter draws on, while nothing it depends on changes: `"local"` (the
|
|
102
|
+
* default) keeps it as a picture, also while the view moves; `"placed"` keeps it with its canvas origin, for a body
|
|
103
|
+
* that reads where it is drawn through `canvasPixel(uv)` (a body that calls the helper is placed by itself); set
|
|
104
|
+
* `false` for a body whose look depends on where the view is drawn in a way the engine cannot see (a time read from
|
|
105
|
+
* a texture, a hash of the screen position): no output of it is kept. On WebGPU the view's subtree picture is kept
|
|
106
|
+
* and the body runs on its quad in every frame, the canvas place in `uOutputFrame.xy`; on WebGL, or when it does not
|
|
107
|
+
* fit the quad, it is drawn live in every frame. A body that reads `uGlobalFrame`, `@builtin(position)`,
|
|
108
|
+
* `gl_FragCoord`, `uOutputTexture` or the origin of `uOutputFrame` and declares nothing is treated as `false`, and a
|
|
109
|
+
* dev build warns once: declare `cache: false`.
|
|
110
|
+
*/
|
|
111
|
+
readonly cache?: "local" | "placed" | false;
|
|
112
|
+
/**
|
|
113
|
+
* The rectangle outside of which this filter draws nothing, in the filtered entity's own units, from the component's
|
|
114
|
+
* value; `undefined` for "the view's bounds" (the default). Outside it Pixi draws nothing of the view at all — neither
|
|
115
|
+
* the filter nor the view's own content — so declare it only for a filter whose output is transparent there. A view
|
|
116
|
+
* with several enabled filters gets the union; a view with an enabled filter that declares no area gets none. Called
|
|
117
|
+
* only when the value changed.
|
|
118
|
+
*/
|
|
119
|
+
readonly area?: (value: Readonly<FilterValueOf<Uniforms>>) => FilterArea | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* The texels per CSS px the view and its filters are drawn at under this filter, from 0 to 4; `0` (the default) for
|
|
122
|
+
* the resolution of the canvas. Pixi draws all the filters of a view at the smallest resolution among them, so a
|
|
123
|
+
* resolution below the canvas's lowers the others on the same view too. A stage of an input ignores it: its step's
|
|
124
|
+
* `scale` sizes it.
|
|
125
|
+
*/
|
|
126
|
+
readonly resolution?: number;
|
|
127
|
+
/**
|
|
128
|
+
* `true` for a filter that reads what was drawn under its view, inside its box (the view's bounds, or its `area`):
|
|
129
|
+
* Pixi copies that part of the canvas before the view draws, the body reads it through `sampleBack(uv)`, and an input
|
|
130
|
+
* may start from it (`from: "back"`). Its output is laid over the canvas like the view's own pixels: where the body
|
|
131
|
+
* answers transparent the canvas stays as it is. A backdrop is drawn live in every frame, never kept (`cache` may only
|
|
132
|
+
* be left out or `false`), has no padding, and is no stage; its fallback may be one. On WebGL the renderer then draws
|
|
133
|
+
* every frame into Pixi's back buffer. Default `false`.
|
|
134
|
+
*/
|
|
135
|
+
readonly backdrop?: boolean;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* How one uniform travels to the GPU: its name, its WGSL type and the form it was declared in.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* const spec: UniformSpec = { name: "color", type: "vec3<f32>", form: "color", size: 3 };
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
type UniformSpec = {
|
|
146
|
+
readonly name: string;
|
|
147
|
+
readonly type: "f32" | "vec2<f32>" | "vec3<f32>" | "vec4<f32>";
|
|
148
|
+
readonly form: "number" | "color" | "vector";
|
|
149
|
+
readonly size: number;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* The filter a component made by `defineFilter` carries: the assembled WGSL in `source`, the
|
|
153
|
+
* assembled GLSL in `glsl`, the uniforms in struct order, the passes one apply costs, the
|
|
154
|
+
* padding, the second textures the body reads and the filter drawn in its place when it is broken.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* Tint.filter.source.includes("fn mainFragment"); // true: the WGSL, drawn on WebGPU
|
|
159
|
+
* Tint.filter.glsl.startsWith("#version 300 es"); // true: the GLSL, drawn on WebGL
|
|
160
|
+
* Tint.filter.uniforms.map(uniform => uniform.name); // ["amount", "color"]
|
|
161
|
+
* Tint.filter.inputs.length; // 0: it reads no second texture
|
|
162
|
+
* Tint.filter.cache; // "local": a still view under it is drawn from a picture
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
type FilterDefinition = {
|
|
166
|
+
readonly id: string; /** The assembled WGSL: the engine's header, the uniform struct, the input bindings, the body. */
|
|
167
|
+
readonly source: string; /** The assembled GLSL ES 3.0: the engine's header, one `uniform` per uniform, the inputs, the body. */
|
|
168
|
+
readonly glsl: string;
|
|
169
|
+
/**
|
|
170
|
+
* The quad program: the same body on a mesh, in the pass that draws the canvas (renderer README, "Kept pictures").
|
|
171
|
+
* A definition with inputs has one too: each input starts from the view's own input, and the mesh binds its held
|
|
172
|
+
* chain result (`Bloom` rides it while its `strength` moves). `undefined` for a backdrop, an input from `"back"`, or
|
|
173
|
+
* a body the rewrite does not fit.
|
|
174
|
+
*/
|
|
175
|
+
readonly quadSource: string | undefined;
|
|
176
|
+
readonly uniforms: readonly UniformSpec[];
|
|
177
|
+
readonly passes: number;
|
|
178
|
+
readonly padding: number | string; /** The second textures the body reads, in declaration order; empty for a filter with none. */
|
|
179
|
+
readonly inputs: readonly FilterInputDefinition[]; /** What draws in its place when it is broken: another definition over a subset of its uniforms. */
|
|
180
|
+
readonly fallback: FilterDefinition | undefined; /** What the kept-picture cache may do with it: the worst of its declaration, its body and its stages' bodies. */
|
|
181
|
+
readonly cache: FilterCache;
|
|
182
|
+
/**
|
|
183
|
+
* The engine's `keptOrigin` uniform (`vec2<f32>`) of a body that calls `canvasPixel(uv)`, kept out of `uniforms`;
|
|
184
|
+
* `undefined` for any other body.
|
|
185
|
+
*/
|
|
186
|
+
readonly origin: UniformSpec | undefined; /** The rectangle outside of which the filter draws nothing, from the value; present only when the spec gave one. */
|
|
187
|
+
readonly area?: (value: Readonly<FilterFields>) => FilterArea | undefined; /** The texels per CSS px it draws at; 0 for the resolution of the canvas. */
|
|
188
|
+
readonly resolution: number; /** True for a filter that reads what was drawn under its view: Pixi's `blendRequired`, and `sampleBack` in its body. */
|
|
189
|
+
readonly backdrop: boolean;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* A filter a chain may draw: any component `defineFilter` made. Listed in an input's `stages` and named by its steps.
|
|
193
|
+
* A built-in Pixi-core kind (`Blur`, `ColorMatrix`, …) has no `filter` and cannot be a stage.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* const FrostGauss = defineFilter("FrostGauss", { wgsl: gaussWgsl, glsl: gaussGlsl, uniforms: { dir: [0, 0], sigma: 0 } });
|
|
198
|
+
* const stages: readonly FilterStage[] = [FrostBox4, FrostHalf, FrostGauss];
|
|
199
|
+
* stages.map(stage => stage.filter.id); // ["FrostBox4", "FrostHalf", "FrostGauss"]
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
type FilterStage = {
|
|
203
|
+
readonly componentName: string;
|
|
204
|
+
readonly defaults: object;
|
|
205
|
+
readonly filter: FilterDefinition;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* One step of a chain: the stage that draws, the share of the input's resolution it draws at, and the stage uniforms
|
|
209
|
+
* of this step. A uniform the step leaves out takes the stage's default. A colour is a `0xrrggbb` number.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* // A Gaussian along x at an eighth of the resolution of the view's input.
|
|
214
|
+
* const step: FilterStep = { stage: FrostGauss, scale: 1 / 8, uniforms: { dir: [1, 0], sigma: 4.66 } };
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
type FilterStep = {
|
|
218
|
+
readonly stage: FilterStage; /** Above 0 and at most 1: the target of this step has `scale` × the resolution of the view's input. */
|
|
219
|
+
readonly scale: number;
|
|
220
|
+
readonly uniforms?: Readonly<Record<string, number | readonly number[]>>;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* What a chain is told besides the value: the real pixels per CSS pixel of the texture the view is drawn into (the
|
|
224
|
+
* canvas resolution for a view at the top, less under a filter of lower resolution).
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* // The owner's phone at maxResolution 3: 16 units of blur are 37 real pixels, an eighth is enough.
|
|
229
|
+
* frostChain({ ...Frost().value, strength: 16, view: [0, 0, 384 / 390] }, { resolution: 2.8125 }).map(step => step.scale);
|
|
230
|
+
* // [0.25, 0.125, 0.125, 0.125]
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
type FilterChainContext = {
|
|
234
|
+
readonly resolution: number;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* A second texture the body of a filter reads, named by its key in `inputs`: `blur` gives the body
|
|
238
|
+
* `sampleBlur(uv)`. `chain` returns the steps that draw it from the view's own input, each from the one before;
|
|
239
|
+
* the body reads the last one. `stages` lists every filter the chain may name: they are checked on the device and
|
|
240
|
+
* warmed up before the first draw, and a step naming another one is refused. The chain runs again only when a uniform
|
|
241
|
+
* of the value or the resolution changed, never per frame; it may return `[]`, and the body then reads the view's own
|
|
242
|
+
* input.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* const input: FilterInput<{ strength: number; enabled: boolean; order: number }> = {
|
|
247
|
+
* stages: [FrostHalf, FrostGauss],
|
|
248
|
+
* chain: (value, { resolution }) => [
|
|
249
|
+
* { stage: FrostHalf, scale: 1 / 2 },
|
|
250
|
+
* { stage: FrostGauss, scale: 1 / 2, uniforms: { dir: [1, 0], sigma: (value.strength * resolution) / 2 } },
|
|
251
|
+
* { stage: FrostGauss, scale: 1 / 2, uniforms: { dir: [0, 1], sigma: (value.strength * resolution) / 2 } }
|
|
252
|
+
* ]
|
|
253
|
+
* };
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
type FilterInput<Value> = {
|
|
257
|
+
/**
|
|
258
|
+
* Where the first step reads: `"input"` (the default), the view's own input; `"back"`, what was drawn under the
|
|
259
|
+
* view inside its box, for a backdrop filter only. A chain from back runs at the resolution of the surface under the
|
|
260
|
+
* view, which `context.resolution` then holds.
|
|
261
|
+
*/
|
|
262
|
+
readonly from?: "input" | "back";
|
|
263
|
+
readonly stages: readonly FilterStage[];
|
|
264
|
+
/**
|
|
265
|
+
* The steps of the second texture for this value and resolution. Pure: no state, no randomness; the context object
|
|
266
|
+
* is the engine's and valid during the call only. The engine reads the steps during the call and copies the uniform
|
|
267
|
+
* values it needs, so a chain may answer the same array on every call, its uniform objects written in place (what
|
|
268
|
+
* `Bloom` does, so a tween allocates nothing in the chain).
|
|
269
|
+
*
|
|
270
|
+
* @param value - The stored value of the filter component.
|
|
271
|
+
* @param context - The resolution of the texture the view is drawn into.
|
|
272
|
+
* @returns The steps in draw order, at most 16.
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* // A quarter is enough at one real pixel per CSS pixel: the box, then the Gaussian along x and along y.
|
|
276
|
+
* Frost.filter.inputs[0]?.chain({ ...Frost().value, strength: 16, view: [0, 0, 1] }, { resolution: 1 }).length; // 3
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
chain(value: Readonly<Value>, context: FilterChainContext): readonly FilterStep[];
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* An input as `defineFilter` stored it: the names the engine declared for it in both shader languages, its two
|
|
283
|
+
* uniforms, its stages and its chain.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* const [blur] = Frost.filter.inputs;
|
|
288
|
+
* [blur?.texture, blur?.sampler, blur?.scale.name, blur?.clamp.name, blur?.sample, blur?.from];
|
|
289
|
+
* // ["blurTexture", "blurSampler", "blurScale", "blurClamp", "sampleBlur", "back"]
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
type FilterInputDefinition = {
|
|
293
|
+
readonly name: string; /** Where its first step reads: the view's own input, or what was drawn under the view. */
|
|
294
|
+
readonly from: "input" | "back";
|
|
295
|
+
readonly texture: string;
|
|
296
|
+
readonly sampler: string;
|
|
297
|
+
readonly scale: UniformSpec;
|
|
298
|
+
readonly clamp: UniformSpec;
|
|
299
|
+
readonly sample: string;
|
|
300
|
+
readonly stages: readonly FilterStage[];
|
|
301
|
+
readonly chain: FilterInput<FilterFields>["chain"];
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* A filter component type: the `component()` of its id, with the filter definition attached. Its
|
|
305
|
+
* numeric fields are tweenable like any component.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* const Tint: FilterComponent<{ amount: number; enabled: boolean; order: number }> =
|
|
310
|
+
* defineFilter("fx.tint", { wgsl: tintWgsl, glsl: tintGlsl, uniforms: { amount: 0 } });
|
|
311
|
+
* Tint.componentName; // "fx.tint"
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
type FilterComponent<Value extends object> = ComponentType<Value> & {
|
|
315
|
+
readonly filter: FilterDefinition;
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* One field of a stored filter value: a number, a switch, an asset key or a vector.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* const field: FilterField = 0.5;
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
type FilterField = number | boolean | string | readonly number[];
|
|
326
|
+
/**
|
|
327
|
+
* The stored value of any filter component, with the kind erased: the filter sync reads every
|
|
328
|
+
* kind through it.
|
|
329
|
+
*/
|
|
330
|
+
type FilterFields = {
|
|
331
|
+
readonly enabled: boolean;
|
|
332
|
+
readonly order: number;
|
|
333
|
+
readonly [field: string]: FilterField;
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* `Glow`: a soft halo of `color` around the opaque pixels of the view.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```ts
|
|
340
|
+
* const value: GlowValue = { strength: 2, distance: 10, color: 0xffffff, alpha: 1, enabled: true, order: 0 };
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
type GlowValue = {
|
|
344
|
+
strength: number;
|
|
345
|
+
distance: number;
|
|
346
|
+
color: number;
|
|
347
|
+
alpha: number;
|
|
348
|
+
enabled: boolean;
|
|
349
|
+
order: number;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* `Outline`: a ring of `thickness` pixels in `color` around the opaque pixels of the view.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* const value: OutlineValue = { thickness: 2, color: 0x000000, alpha: 1, enabled: true, order: 0 };
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
type OutlineValue = {
|
|
360
|
+
thickness: number;
|
|
361
|
+
color: number;
|
|
362
|
+
alpha: number;
|
|
363
|
+
enabled: boolean;
|
|
364
|
+
order: number;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* `Blur`: Pixi's blur. `quality: 0` means `config.blur.quality`; `resolution: 0` means
|
|
368
|
+
* `config.blur.phoneResolution` on a phone, otherwise 1.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```ts
|
|
372
|
+
* const value: BlurValue = { strength: 8, quality: 0, resolution: 0, repeatEdgePixels: true, enabled: true, order: 0 };
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
type BlurValue = {
|
|
376
|
+
strength: number;
|
|
377
|
+
quality: number;
|
|
378
|
+
resolution: number;
|
|
379
|
+
repeatEdgePixels: boolean;
|
|
380
|
+
enabled: boolean;
|
|
381
|
+
order: number;
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* `ColorMatrix`: brightness, saturation, contrast, hue and grayscale composed in that order.
|
|
385
|
+
* Every default is the identity.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* const value: ColorMatrixValue = { brightness: 1, saturation: 0, contrast: 0, hue: 0, grayscale: 1, enabled: true, order: 0 };
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
type ColorMatrixValue = {
|
|
393
|
+
brightness: number;
|
|
394
|
+
saturation: number;
|
|
395
|
+
contrast: number;
|
|
396
|
+
hue: number;
|
|
397
|
+
grayscale: number;
|
|
398
|
+
enabled: boolean;
|
|
399
|
+
order: number;
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* `Noise`: Pixi's noise with its seed always given, so two runs draw the same grain.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* const value: NoiseValue = { amount: 0.5, seed: 7, enabled: true, order: 0 };
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
type NoiseValue = {
|
|
410
|
+
amount: number;
|
|
411
|
+
seed: number;
|
|
412
|
+
enabled: boolean;
|
|
413
|
+
order: number;
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* `Displacement`: Pixi's displacement over the texture of an asset key.
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```ts
|
|
420
|
+
* const value: DisplacementValue = { map: "fx.ripple", scaleX: 20, scaleY: 20, enabled: true, order: 0 };
|
|
421
|
+
* ```
|
|
422
|
+
*/
|
|
423
|
+
type DisplacementValue = {
|
|
424
|
+
map: string;
|
|
425
|
+
scaleX: number;
|
|
426
|
+
scaleY: number;
|
|
427
|
+
enabled: boolean;
|
|
428
|
+
order: number;
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* `Alpha`: Pixi's alpha over the whole subtree, as one layer. `resolution` is the texels per CSS px the subtree is drawn
|
|
432
|
+
* at, at most 4, `0` for the resolution of the canvas; Pixi draws all the filters of a view at the smallest resolution
|
|
433
|
+
* among them, so `Alpha({ resolution: 0.5 })` beside a `Glow` draws the glow at 0.5 too. At `alpha: 1` and
|
|
434
|
+
* `resolution: 0` the filter would copy the subtree unchanged through a pass of its own: it is switched off, at once
|
|
435
|
+
* when it is built so, otherwise after 8 frames at rest there (a keyframe that touches 1 switches nothing), and the
|
|
436
|
+
* subtree draws as if the Alpha were not there.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* // The fog of a memory screen, opaque, drawn at half a texel per CSS px through the Alpha's one pass.
|
|
441
|
+
* const value: AlphaValue = { alpha: 1, resolution: 0.5, enabled: true, order: 0 };
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
type AlphaValue = {
|
|
445
|
+
alpha: number;
|
|
446
|
+
resolution: number;
|
|
447
|
+
enabled: boolean;
|
|
448
|
+
order: number;
|
|
449
|
+
};
|
|
450
|
+
/**
|
|
451
|
+
* The five built-in kinds drawn by a Pixi core filter.
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* const kind: CoreKind = "blur";
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
type CoreKind = "blur" | "colorMatrix" | "noise" | "displacement" | "alpha";
|
|
459
|
+
/**
|
|
460
|
+
* Where a filter kind comes from: our or a game's shaders (`"wgsl"`, with the GLSL twin beside
|
|
461
|
+
* it), or a Pixi core filter.
|
|
462
|
+
*/
|
|
463
|
+
type KindSource = {
|
|
464
|
+
readonly source: "wgsl";
|
|
465
|
+
readonly definition: FilterDefinition;
|
|
466
|
+
} | {
|
|
467
|
+
readonly source: "core";
|
|
468
|
+
readonly core: CoreKind;
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* A filter kind before it is registered: its id, its component and its source.
|
|
472
|
+
*/
|
|
473
|
+
type KindEntry = KindSource & {
|
|
474
|
+
readonly id: string;
|
|
475
|
+
readonly component: ComponentHandle<FilterFields>;
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* One registered filter kind. `index` is the registration order: the built-ins first, then the
|
|
479
|
+
* filters of every feature in feature order.
|
|
480
|
+
*/
|
|
481
|
+
type FilterKind = KindEntry & {
|
|
482
|
+
readonly index: number;
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* The values of the uniform group of one of our filter instances: a number per `f32`, a vector
|
|
486
|
+
* per colour and tuple. Written where they differ from the stored value.
|
|
487
|
+
*/
|
|
488
|
+
type UniformValues = Record<string, number | Float32Array>;
|
|
489
|
+
/**
|
|
490
|
+
* The uniform group of one of our filter instances, as the instance writes it.
|
|
491
|
+
*/
|
|
492
|
+
type FilterUniforms = PixiUniformGroup & {
|
|
493
|
+
readonly uniforms: UniformValues;
|
|
494
|
+
};
|
|
495
|
+
/**
|
|
496
|
+
* The Pixi object of one kind on one view, with the passes one apply of it costs now: what the
|
|
497
|
+
* builders of `instance.ts` make before the instance gets its sort keys. A Pixi-core kind keeps
|
|
498
|
+
* the fields its setters were last given, `applied`, so an equal value calls no setter.
|
|
499
|
+
*/
|
|
500
|
+
type FilterBody = {
|
|
501
|
+
readonly kind: "wgsl";
|
|
502
|
+
readonly filter: PixiFilter;
|
|
503
|
+
readonly group: FilterUniforms | undefined;
|
|
504
|
+
readonly definition: FilterDefinition;
|
|
505
|
+
passes: number; /** The chains and their places; `undefined` for a definition without inputs. Set once, by `createFilter`. */
|
|
506
|
+
inputs: InputsState | undefined; /** The dev mark drawn after the fallback by a stand-in (E5.4); `undefined` otherwise. */
|
|
507
|
+
readonly mark: OursBody | undefined; /** The definition's last area answer, filled in place; `some: false` for `undefined` (B4). */
|
|
508
|
+
readonly area: AreaBox; /** The value changed since the area was last asked: the next sync asks the definition again. */
|
|
509
|
+
areaStale: boolean; /** What the slot hands over for the quad, made once: the renderer compares it by identity. */
|
|
510
|
+
quad: FilterSlotQuad | undefined;
|
|
511
|
+
} | {
|
|
512
|
+
readonly kind: "blur";
|
|
513
|
+
readonly filter: InstanceType<PixiModule["BlurFilter"]>; /** The fields the setters were last given; compared before a write. */
|
|
514
|
+
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
515
|
+
readonly fields: readonly string[];
|
|
516
|
+
passes: number;
|
|
517
|
+
} | {
|
|
518
|
+
readonly kind: "colorMatrix";
|
|
519
|
+
readonly filter: InstanceType<PixiModule["ColorMatrixFilter"]>; /** The fields the setters were last given; compared before a write. */
|
|
520
|
+
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
521
|
+
readonly fields: readonly string[];
|
|
522
|
+
passes: number;
|
|
523
|
+
} | {
|
|
524
|
+
readonly kind: "noise";
|
|
525
|
+
readonly filter: InstanceType<PixiModule["NoiseFilter"]>; /** The fields the setters were last given; compared before a write. */
|
|
526
|
+
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
527
|
+
readonly fields: readonly string[];
|
|
528
|
+
passes: number;
|
|
529
|
+
} | {
|
|
530
|
+
readonly kind: "displacement";
|
|
531
|
+
readonly filter: InstanceType<PixiModule["DisplacementFilter"]>;
|
|
532
|
+
readonly sprite: PixiSprite; /** The fields the setters were last given; compared before a write. */
|
|
533
|
+
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
534
|
+
readonly fields: readonly string[]; /** The asset key the map sprite shows now. */
|
|
535
|
+
map: string;
|
|
536
|
+
passes: number;
|
|
537
|
+
} | {
|
|
538
|
+
readonly kind: "alpha";
|
|
539
|
+
readonly filter: InstanceType<PixiModule["AlphaFilter"]>; /** The fields the setters were last given; compared before a write. */
|
|
540
|
+
readonly applied: Record<string, FilterField>; /** The keys of `applied`, listed once: a compare walks them by index, with no `Object.keys` per frame. */
|
|
541
|
+
readonly fields: readonly string[];
|
|
542
|
+
passes: number;
|
|
543
|
+
/**
|
|
544
|
+
* Syncs in a row its value drew the view unchanged (at 1, at the canvas's resolution) while its filter was on;
|
|
545
|
+
* the filter is switched off at `CALM_AFTER` and the count starts over.
|
|
546
|
+
*/
|
|
547
|
+
calm: number;
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* A probe of the warm-up (spec 27 F4): the Pixi filter handed to `renderer.sync.filters.warm`, the quad of a kind whose
|
|
551
|
+
* body can run on one, and its teardown.
|
|
552
|
+
*/
|
|
553
|
+
type WarmProbe = {
|
|
554
|
+
readonly filter: PixiFilter;
|
|
555
|
+
readonly quad: FilterSlotQuad | undefined;
|
|
556
|
+
destroy(): void;
|
|
557
|
+
};
|
|
558
|
+
/**
|
|
559
|
+
* A filter area as the filter sync keeps it, written in place: the four numbers, and whether there is one.
|
|
560
|
+
*/
|
|
561
|
+
type AreaBox = {
|
|
562
|
+
x: number;
|
|
563
|
+
y: number;
|
|
564
|
+
width: number;
|
|
565
|
+
height: number;
|
|
566
|
+
some: boolean;
|
|
567
|
+
};
|
|
568
|
+
/**
|
|
569
|
+
* The instance of one kind on one view: its Pixi object, and what it sorts by on the view, the
|
|
570
|
+
* `order` of its component (written every frame) and the `index` of its kind. The instance is
|
|
571
|
+
* the object the builder made, never a copy: a closure made while building (the apply guard)
|
|
572
|
+
* reads and writes the same fields the filter sync does.
|
|
573
|
+
*/
|
|
574
|
+
type FilterInstance = FilterBody & {
|
|
575
|
+
order: number;
|
|
576
|
+
readonly index: number; /** True once the instance broke (its apply threw, its chain failed): it stays broken until it is retired. */
|
|
577
|
+
broken: boolean; /** The value the filter sync handed over last: the chain and a stand-in are built from it. */
|
|
578
|
+
value: Readonly<FilterFields>; /** The kind this instance draws for; a stand-in carries the id of the kind it stands in for. */
|
|
579
|
+
readonly kindId: string; /** True for an instance that draws in place of a broken kind or instance (E5). */
|
|
580
|
+
readonly standIn: boolean; /** A stand-in built while this broken instance was drawing; the next sync puts it in its place. */
|
|
581
|
+
replacement: FilterInstance | undefined;
|
|
582
|
+
/**
|
|
583
|
+
* The entity of the view it draws on, set when the filter sync takes it in; 0 for a warm-up probe. A break inside a
|
|
584
|
+
* render tells the renderer about this view (`renderer.invalidate`) before it switches the filter off.
|
|
585
|
+
*/
|
|
586
|
+
entity: Entity;
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* One of our bodies: a `Filter` over the assembled programs, the kind of every place of a chain and of a mark.
|
|
590
|
+
*/
|
|
591
|
+
type OursBody = Extract<FilterBody, {
|
|
592
|
+
kind: "wgsl";
|
|
593
|
+
}>;
|
|
594
|
+
/** One place of a chain: the Pixi filter that draws the stage there, and the share of the resolution it draws at. */
|
|
595
|
+
type Place = {
|
|
596
|
+
readonly definition: FilterDefinition;
|
|
597
|
+
readonly body: OursBody;
|
|
598
|
+
scale: number;
|
|
599
|
+
};
|
|
600
|
+
/**
|
|
601
|
+
* The chains of one instance of a filter with inputs: what draws each second texture, and the seam spec 23 keeps
|
|
602
|
+
* pictures through.
|
|
603
|
+
*/
|
|
604
|
+
type InputsState = {
|
|
605
|
+
/** A uniform of the value changed since the last evaluation (set by `writeFilter`). */stale: boolean; /** The resolution of the view's input at the last evaluation. */
|
|
606
|
+
resolution: number; /** The resolution of what was drawn under the view at the last evaluation; the input's for a filter that reads none. */
|
|
607
|
+
backResolution: number; /** An input starts from the view's own input: a new resolution of the input runs the chains again. */
|
|
608
|
+
readonly fromInput: boolean; /** An input starts from what was drawn under the view: a new resolution of the back runs the chains again. */
|
|
609
|
+
readonly fromBack: boolean; /** Changes whenever what the stages draw changes; 1 after the first evaluation. */
|
|
610
|
+
version: number; /** The object `chain` receives, reused: its `resolution` is written before each call. */
|
|
611
|
+
readonly context: {
|
|
612
|
+
resolution: number;
|
|
613
|
+
}; /** Per input, its places in draw order (each with the scale of its step). */
|
|
614
|
+
readonly places: Place[][]; /** Bodies of places that left the chain, destroyed by the next sync. */
|
|
615
|
+
readonly retired: OursBody[]; /** Pooled textures taken by the running apply; emptied in its `finally`. One array, reused. */
|
|
616
|
+
readonly taken: PixiTexture[]; /** The options object handed to `TexturePool.getOptimalTexture`, reused. */
|
|
617
|
+
readonly request: {
|
|
618
|
+
width: number;
|
|
619
|
+
height: number;
|
|
620
|
+
resolution: number;
|
|
621
|
+
}; /** Results lent by spec 23: while set, the apply draws the main body only, over them. */
|
|
622
|
+
held: readonly PixiTexture[] | undefined; /** The slot seam, a frozen object replaced when a place is built or dropped. */
|
|
623
|
+
slot: FilterSlotInputs;
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* Where the shader check of every definition a kind can draw stands, in every build: one run per start of the
|
|
627
|
+
* plugin.
|
|
628
|
+
*/
|
|
629
|
+
type CheckState = {
|
|
630
|
+
/** Bumped by `stopEffects`: an answer of an earlier run is ignored. */run: number; /** The checks were started on the running backend. */
|
|
631
|
+
started: boolean; /** Where each definition stands. */
|
|
632
|
+
status: WeakMap<FilterDefinition, "pending" | "ok" | "broken">; /** The definitions whose quad text compiled clean on this run's device: only they hand a quad over. */
|
|
633
|
+
quads: WeakSet<FilterDefinition>; /** The program of each of them, built at the first ask: `GpuProgram.from` keys the whole source on every call. */
|
|
634
|
+
programs: WeakMap<FilterDefinition, PixiGpuProgram>; /** Definitions still pending. */
|
|
635
|
+
waiting: number; /** Definitions started, for the `effects:checks` line. */
|
|
636
|
+
checked: number; /** Definitions that failed, for the `effects:checks` line. */
|
|
637
|
+
failed: number; /** GLSL compiles in flight under `KHR_parallel_shader_compile`. */
|
|
638
|
+
gl: Array<{
|
|
639
|
+
definition: FilterDefinition;
|
|
640
|
+
shader: WebGLShader;
|
|
641
|
+
}>; /** `performance.now()` when the checks started, for the `effects:checks` line. */
|
|
642
|
+
startedAt: number; /** Resolves when `started` and `waiting === 0`. */
|
|
643
|
+
settled: Promise<void>; /** Resolves `settled`. */
|
|
644
|
+
resolve: () => void;
|
|
645
|
+
};
|
|
646
|
+
/**
|
|
647
|
+
* What the filter sync keeps for one entity: the kinds it carries, one instance per kind, the
|
|
648
|
+
* instances waiting to be destroyed after the next assignment, the slots last handed to
|
|
649
|
+
* `renderer.sync.filters.set`, the run in which each core kind's component last changed, the
|
|
650
|
+
* instances of this frame in their sorted order (one array, reused every frame), the one
|
|
651
|
+
* `renderer.invalidate` call a visible filter write of the frame makes, and whether the next run
|
|
652
|
+
* syncs it.
|
|
653
|
+
*/
|
|
654
|
+
type FilteredView = {
|
|
655
|
+
/** The entity the record is kept for. */readonly entity: Entity;
|
|
656
|
+
readonly kinds: Set<string>;
|
|
657
|
+
readonly instances: Map<string, FilterInstance>;
|
|
658
|
+
readonly retired: FilterInstance[];
|
|
659
|
+
assigned: readonly FilterSlot[];
|
|
660
|
+
/**
|
|
661
|
+
* Per kind `index`, the run of the filter sync in which its component was last seen changed; read only for a
|
|
662
|
+
* Pixi-core kind, which is written only in such a run. A number per kind, so marking allocates nothing.
|
|
663
|
+
*/
|
|
664
|
+
readonly marks: number[];
|
|
665
|
+
readonly placed: FilterInstance[]; /** True once `renderer.invalidate` was called for this view in the current frame. */
|
|
666
|
+
signalled: boolean; /** Calls `renderer.invalidate(entity)` once per frame for this view, before the write; made once with the record. */
|
|
667
|
+
readonly signal: () => void; /** The area last handed to `renderer.sync.filters.area`, written in place (B4). */
|
|
668
|
+
readonly areaSent: AreaBox; /** The `enabled` switches of the placed instances when the area was last judged, one bit each in placed order. */
|
|
669
|
+
areaMask: number;
|
|
670
|
+
/**
|
|
671
|
+
* The next run of the filter sync brings the view up to date: a filter component of it changed, came or left, its
|
|
672
|
+
* map was retired, a kind of it still waits for its instance, or a chain left places to destroy.
|
|
673
|
+
*/
|
|
674
|
+
dirty: boolean; /** Forgotten: out of `State.views`; the next run drops it from `State.viewList`. */
|
|
675
|
+
gone: boolean;
|
|
676
|
+
};
|
|
677
|
+
/**
|
|
678
|
+
* Where the filter sync stands between two runs. It syncs only the views marked dirty, and judges the full-screen
|
|
679
|
+
* budget only when something it depends on moved.
|
|
680
|
+
*/
|
|
681
|
+
type FilterSyncState = {
|
|
682
|
+
/** The current run, counted from 1: a core kind's change mark holds the run it was made in. */round: number;
|
|
683
|
+
/**
|
|
684
|
+
* Every view syncs at the next run: a debug switch turned a kind off or on, or a filter broke or ran its chains at a
|
|
685
|
+
* new resolution inside a render, where the view it belongs to is not known.
|
|
686
|
+
*/
|
|
687
|
+
all: boolean; /** A view was marked dirty or forgotten since the last walk: the next run walks the dense list, otherwise it skips it. */
|
|
688
|
+
pending: boolean; /** The viewport width the full-screen budget was last judged at; -1 before the first judgement. */
|
|
689
|
+
width: number; /** The viewport height the full-screen budget was last judged at; -1 before the first judgement. */
|
|
690
|
+
height: number;
|
|
691
|
+
};
|
|
692
|
+
//#endregion
|
|
693
|
+
//#region src/plugins/effects/particles/types.d.ts
|
|
694
|
+
/**
|
|
695
|
+
* An inclusive `[min, max]` range; every particle draws its own value from it.
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* ```ts
|
|
699
|
+
* const lifeMs: Range = [500, 900];
|
|
700
|
+
* ```
|
|
701
|
+
*/
|
|
702
|
+
type Range = readonly [min: number, max: number];
|
|
703
|
+
/**
|
|
704
|
+
* A value over the life of a particle, linear from its birth (`from`) to its death (`to`).
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```ts
|
|
708
|
+
* const shrink: Curve = { from: 1, to: 0.2 };
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
type Curve = {
|
|
712
|
+
readonly from: number;
|
|
713
|
+
readonly to: number;
|
|
714
|
+
};
|
|
715
|
+
/**
|
|
716
|
+
* Where a particle is born, around the origin of its emitter, in reference units. `circle` is
|
|
717
|
+
* uniform over the disc, `ring` uniform between `radius − width / 2` and `radius + width / 2`,
|
|
718
|
+
* `rect` uniform over the centred box.
|
|
719
|
+
*
|
|
720
|
+
* @example
|
|
721
|
+
* ```ts
|
|
722
|
+
* const burstRing: Shape = { kind: "ring", radius: 48, width: 16 };
|
|
723
|
+
* ```
|
|
724
|
+
*/
|
|
725
|
+
type Shape = {
|
|
726
|
+
readonly kind: "point";
|
|
727
|
+
} | {
|
|
728
|
+
readonly kind: "circle";
|
|
729
|
+
readonly radius: number;
|
|
730
|
+
} | {
|
|
731
|
+
readonly kind: "rect";
|
|
732
|
+
readonly w: number;
|
|
733
|
+
readonly h: number;
|
|
734
|
+
} | {
|
|
735
|
+
readonly kind: "ring";
|
|
736
|
+
readonly radius: number;
|
|
737
|
+
readonly width: number;
|
|
738
|
+
};
|
|
739
|
+
/**
|
|
740
|
+
* A particle effect as data, what `defineEmitter` takes. Every field is optional except
|
|
741
|
+
* `textures` and exactly one of `burst` and `rate`. Speeds are reference units per second, angles
|
|
742
|
+
* degrees with 0 to the right and 90 down, spins radians per second.
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* ```ts
|
|
746
|
+
* const stars: EmitterConfig = {
|
|
747
|
+
* textures: ["fx.star", "fx.sparkle"], burst: 40, lifeMs: [500, 900], speed: [300, 700],
|
|
748
|
+
* gravity: 900, drag: 0.2, shape: { kind: "circle", radius: 24 }, alpha: { from: 1, to: 0 }
|
|
749
|
+
* };
|
|
750
|
+
* ```
|
|
751
|
+
*/
|
|
752
|
+
type EmitterConfig = {
|
|
753
|
+
/** 1 to 16 asset keys of one atlas page; a particle picks one at random. */readonly textures: readonly string[]; /** Particles emitted once, when the component appears or its `effect` changes. */
|
|
754
|
+
readonly burst?: number; /** Particles per second while `active` is true and the entity lives. */
|
|
755
|
+
readonly rate?: number; /** Life of a particle in milliseconds. Default `[600, 1000]`. */
|
|
756
|
+
readonly lifeMs?: Range; /** Start speed in reference units per second. Default `[0, 0]`. */
|
|
757
|
+
readonly speed?: Range; /** Start direction in degrees, 0 right, 90 down. Default `[0, 360]`. */
|
|
758
|
+
readonly angle?: Range; /** Downward acceleration in reference units per second². Default `0`. */
|
|
759
|
+
readonly gravity?: number; /** Velocity lost per second, 0..1: `v *= (1 − drag) ^ seconds`. Default `0`. */
|
|
760
|
+
readonly drag?: number; /** Spin in radians per second. Default `[0, 0]`. */
|
|
761
|
+
readonly spin?: Range; /** Where particles are born around the origin. Default `{ kind: "point" }`. */
|
|
762
|
+
readonly shape?: Shape; /** Scale over life. Default `{ from: 1, to: 1 }`. */
|
|
763
|
+
readonly scale?: Curve; /** Alpha over life, 0..1. Default `{ from: 1, to: 1 }`. */
|
|
764
|
+
readonly alpha?: Curve; /** Tint over life, `0xrrggbb`, linear per channel. Default white to white. */
|
|
765
|
+
readonly tint?: Curve; /** `"world"`: particles outlive the entity. `"local"`: they move and die with it. Default `"world"`. */
|
|
766
|
+
readonly space?: "world" | "local"; /** Milliseconds simulated before the first frame, for streams, 0..5000. Default `0`. */
|
|
767
|
+
readonly prewarmMs?: number; /** Hard ceiling of live particles of one instance, 1..5000. Default `256`. */
|
|
768
|
+
readonly maxParticles?: number; /** Blend mode of the particle container. Default `"normal"`. */
|
|
769
|
+
readonly blend?: "normal" | "add";
|
|
770
|
+
};
|
|
771
|
+
/**
|
|
772
|
+
* An `EmitterConfig` with every default filled in. `burst` and `rate` stay as given: exactly one
|
|
773
|
+
* of them is present.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```ts
|
|
777
|
+
* defineEmitter("fx.steam", { textures: ["fx.puff"], rate: 12 }).config.lifeMs; // [600, 1000]
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
type ResolvedEmitterConfig = Required<Omit<EmitterConfig, "burst" | "rate">> & Pick<EmitterConfig, "burst" | "rate">;
|
|
781
|
+
/**
|
|
782
|
+
* A particle effect as `defineEmitter` returns it: frozen, registered through the `emitters` key
|
|
783
|
+
* of a feature and started by an `Emitter` component that names its id.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```ts
|
|
787
|
+
* const steam: EmitterDefinition = defineEmitter("fx.steam", { textures: ["fx.puff"], rate: 12 });
|
|
788
|
+
* steam.config.rate; // 12
|
|
789
|
+
* ```
|
|
790
|
+
*/
|
|
791
|
+
type EmitterDefinition = {
|
|
792
|
+
readonly id: string;
|
|
793
|
+
readonly config: ResolvedEmitterConfig;
|
|
794
|
+
};
|
|
795
|
+
/**
|
|
796
|
+
* The value of the `Emitter` component: which effect runs on the entity and whether a stream
|
|
797
|
+
* emits. `""` draws nothing.
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```ts
|
|
801
|
+
* const value: EmitterValue = { effect: "fx.steam", active: true };
|
|
802
|
+
* ```
|
|
803
|
+
*/
|
|
804
|
+
type EmitterValue = {
|
|
805
|
+
effect: string;
|
|
806
|
+
active: boolean;
|
|
807
|
+
};
|
|
808
|
+
/**
|
|
809
|
+
* The cosmetic random source of one instance: xorshift32 over its own seed, never `Math.random`
|
|
810
|
+
* and never the model's rng.
|
|
811
|
+
*/
|
|
812
|
+
type Rng = {
|
|
813
|
+
/** The next number in `[0, 1)`. */next(): number; /** An integer in `[0, count)`. */
|
|
814
|
+
int(count: number): number; /** A number in `[min, max]`. */
|
|
815
|
+
between(min: number, max: number): number;
|
|
816
|
+
};
|
|
817
|
+
/**
|
|
818
|
+
* A Pixi particle container: what one emitter instance draws in.
|
|
819
|
+
*/
|
|
820
|
+
type PixiParticleContainer = InstanceType<PixiModule["ParticleContainer"]>;
|
|
821
|
+
/**
|
|
822
|
+
* One particle of a container, as the container keeps it.
|
|
823
|
+
*/
|
|
824
|
+
type PixiParticle = PixiParticleContainer["particleChildren"][number];
|
|
825
|
+
/**
|
|
826
|
+
* What one effect id bakes to on first use: the 64-entry curve tables, the reach rectangle's half
|
|
827
|
+
* side and the resolved textures. Dropped when a bundle with one of its textures leaves.
|
|
828
|
+
*/
|
|
829
|
+
type BakedEmitter = {
|
|
830
|
+
readonly id: string;
|
|
831
|
+
readonly config: ResolvedEmitterConfig; /** Scale per 1/64 of the life. */
|
|
832
|
+
readonly scaleTable: Float32Array; /** Alpha per 1/64 of the life, 0..1. */
|
|
833
|
+
readonly alphaTable: Float32Array; /** Tint per 1/64 of the life, packed as Pixi's `0xbbggrr`. */
|
|
834
|
+
readonly tintTable: Uint32Array;
|
|
835
|
+
/**
|
|
836
|
+
* The colour a particle is drawn with per 1/64 of the life, packed as Pixi's `0xaabbggrr`: the tint under the alpha
|
|
837
|
+
* byte. Read straight from the table every frame: a number above the small integers handed back by a call is boxed.
|
|
838
|
+
*/
|
|
839
|
+
readonly colorTable: Uint32Array; /** Half side of the box no particle leaves, in reference units. */
|
|
840
|
+
readonly reach: number;
|
|
841
|
+
readonly textures: readonly PixiTexture[]; /** The texture source of the first texture: every texture of the effect samples it. */
|
|
842
|
+
readonly source: PixiTexture["source"] | undefined; /** The largest side of the textures, in pixels. */
|
|
843
|
+
readonly maxSide: number;
|
|
844
|
+
};
|
|
845
|
+
/**
|
|
846
|
+
* The per-particle numbers a Pixi particle has no field for, one entry per live particle, in the
|
|
847
|
+
* order of `particleChildren`.
|
|
848
|
+
*/
|
|
849
|
+
type BornFields = {
|
|
850
|
+
readonly age: Float32Array;
|
|
851
|
+
readonly life: Float32Array;
|
|
852
|
+
readonly vx: Float32Array;
|
|
853
|
+
readonly vy: Float32Array;
|
|
854
|
+
readonly spin: Float32Array;
|
|
855
|
+
readonly variant: Float32Array;
|
|
856
|
+
};
|
|
857
|
+
/**
|
|
858
|
+
* One running effect: its container, the plugin-owned entity that carries it, the particle pool
|
|
859
|
+
* and the numbers the step needs.
|
|
860
|
+
*/
|
|
861
|
+
type EmitterInstance = {
|
|
862
|
+
readonly id: string;
|
|
863
|
+
readonly baked: BakedEmitter; /** The entity whose `Emitter` started it. */
|
|
864
|
+
readonly host: Entity; /** The plugin-owned entity whose `Display` is the container. */
|
|
865
|
+
readonly entity: Entity;
|
|
866
|
+
readonly container: PixiParticleContainer; /** Retired particles, reused before a new one is made. */
|
|
867
|
+
readonly pool: PixiParticle[];
|
|
868
|
+
readonly born: BornFields; /** Fraction of a particle owed to the next frame of a stream. */
|
|
869
|
+
carry: number;
|
|
870
|
+
readonly rng: Rng; /** The point the container was placed at, in root space (world space only). */
|
|
871
|
+
readonly origin: Readonly<Point>;
|
|
872
|
+
readonly space: "world" | "local"; /** Pixi's particle class, from the module the renderer loaded. */
|
|
873
|
+
readonly particleClass: PixiModule["Particle"];
|
|
874
|
+
};
|
|
875
|
+
//#endregion
|
|
876
|
+
//#region src/plugins/effects/set/types.d.ts
|
|
877
|
+
/**
|
|
878
|
+
* @file effects/set — the values of the members of the engine's effect set: one field per uniform, then `enabled` and
|
|
879
|
+
* `order`, which every filter component carries. A number field is tweenable; a colour is a `0xrrggbb` number, set,
|
|
880
|
+
* not tweened.
|
|
881
|
+
*/
|
|
882
|
+
/**
|
|
883
|
+
* `Flash`: the view washed with `color` by `amount`, 0 none, 1 all of it.
|
|
884
|
+
*
|
|
885
|
+
* @example
|
|
886
|
+
* ```ts
|
|
887
|
+
* const value: FlashValue = { amount: 1, color: 0xffd700, enabled: true, order: 0 };
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
type FlashValue = {
|
|
891
|
+
amount: number;
|
|
892
|
+
color: number;
|
|
893
|
+
enabled: boolean;
|
|
894
|
+
order: number;
|
|
895
|
+
};
|
|
896
|
+
/**
|
|
897
|
+
* `Grade`: contrast, brightness and saturation of the view, each 1 for none (0..2), then a multiply by `tint`.
|
|
898
|
+
*
|
|
899
|
+
* @example
|
|
900
|
+
* ```ts
|
|
901
|
+
* const value: GradeValue = { brightness: 1, contrast: 1, saturation: 0, tint: 0xffffff, enabled: true, order: 0 };
|
|
902
|
+
* ```
|
|
903
|
+
*/
|
|
904
|
+
type GradeValue = {
|
|
905
|
+
brightness: number;
|
|
906
|
+
contrast: number;
|
|
907
|
+
saturation: number;
|
|
908
|
+
tint: number;
|
|
909
|
+
enabled: boolean;
|
|
910
|
+
order: number;
|
|
911
|
+
};
|
|
912
|
+
/**
|
|
913
|
+
* `Vignette`: the view darkened, or coloured, outside a disc around `x`, `y` (0..1 of the view) of `radius`, over a soft
|
|
914
|
+
* edge `soft` wide, by `amount`.
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```ts
|
|
918
|
+
* const value: VignetteValue = { x: 0.5, y: 0.5, radius: 0.3, soft: 0.4, color: 0x000000, amount: 1, enabled: true, order: 0 };
|
|
919
|
+
* ```
|
|
920
|
+
*/
|
|
921
|
+
type VignetteValue = {
|
|
922
|
+
x: number;
|
|
923
|
+
y: number;
|
|
924
|
+
radius: number;
|
|
925
|
+
soft: number;
|
|
926
|
+
color: number;
|
|
927
|
+
amount: number;
|
|
928
|
+
enabled: boolean;
|
|
929
|
+
order: number;
|
|
930
|
+
};
|
|
931
|
+
/**
|
|
932
|
+
* `RevealLine`: the view shown up to a straight line that sweeps across it, `progress` 0 none of it, 1 all of it, the
|
|
933
|
+
* line at `angle` (radians, in the view's own 0..1 frame), its edge `soft` wide.
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```ts
|
|
937
|
+
* const value: RevealLineValue = { progress: 0.5, angle: Math.PI / 4, soft: 0.1, enabled: true, order: 0 };
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
940
|
+
type RevealLineValue = {
|
|
941
|
+
progress: number;
|
|
942
|
+
angle: number;
|
|
943
|
+
soft: number;
|
|
944
|
+
enabled: boolean;
|
|
945
|
+
order: number;
|
|
946
|
+
};
|
|
947
|
+
/**
|
|
948
|
+
* `RevealRound`: the view shown inside a disc around `x`, `y` (0..1 of the view) of `radius`, its edge `soft` wide and
|
|
949
|
+
* wavy by `wobble`.
|
|
950
|
+
*
|
|
951
|
+
* @example
|
|
952
|
+
* ```ts
|
|
953
|
+
* const value: RevealRoundValue = { x: 0.5, y: 0.5, radius: 1.2, soft: 0.05, wobble: 0.04, enabled: true, order: 0 };
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
type RevealRoundValue = {
|
|
957
|
+
x: number;
|
|
958
|
+
y: number;
|
|
959
|
+
radius: number;
|
|
960
|
+
soft: number;
|
|
961
|
+
wobble: number;
|
|
962
|
+
enabled: boolean;
|
|
963
|
+
order: number;
|
|
964
|
+
};
|
|
965
|
+
/**
|
|
966
|
+
* `Dissolve`: the view eaten by a noise of `scale` cells across, `progress` 0 none of it, 1 all of it, the rim `edge`
|
|
967
|
+
* wide in `edgeColor`.
|
|
968
|
+
*
|
|
969
|
+
* @example
|
|
970
|
+
* ```ts
|
|
971
|
+
* const value: DissolveValue = { progress: 0.5, scale: 8, edge: 0.08, edgeColor: 0xffffff, enabled: true, order: 0 };
|
|
972
|
+
* ```
|
|
973
|
+
*/
|
|
974
|
+
type DissolveValue = {
|
|
975
|
+
progress: number;
|
|
976
|
+
scale: number;
|
|
977
|
+
edge: number;
|
|
978
|
+
edgeColor: number;
|
|
979
|
+
enabled: boolean;
|
|
980
|
+
order: number;
|
|
981
|
+
};
|
|
982
|
+
/**
|
|
983
|
+
* `Shine`: a band of light `width` wide at `position` of its sweep (-0.5..1.5), across the view at `angle`, by
|
|
984
|
+
* `strength`.
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```ts
|
|
988
|
+
* const value: ShineValue = { position: 0.5, width: 0.2, angle: 0.6, strength: 0.6, enabled: true, order: 0 };
|
|
989
|
+
* ```
|
|
990
|
+
*/
|
|
991
|
+
type ShineValue = {
|
|
992
|
+
position: number;
|
|
993
|
+
width: number;
|
|
994
|
+
angle: number;
|
|
995
|
+
strength: number;
|
|
996
|
+
enabled: boolean;
|
|
997
|
+
order: number;
|
|
998
|
+
};
|
|
999
|
+
/**
|
|
1000
|
+
* `Aura`: a halo of `color` by `strength` (0..2) around the shape of the view, `spread` CSS px wide, which is also the
|
|
1001
|
+
* view's padding.
|
|
1002
|
+
*
|
|
1003
|
+
* @example
|
|
1004
|
+
* ```ts
|
|
1005
|
+
* const value: AuraValue = { color: 0xffd700, strength: 1, spread: 12, enabled: true, order: 0 };
|
|
1006
|
+
* ```
|
|
1007
|
+
*/
|
|
1008
|
+
type AuraValue = {
|
|
1009
|
+
color: number;
|
|
1010
|
+
strength: number;
|
|
1011
|
+
spread: number;
|
|
1012
|
+
enabled: boolean;
|
|
1013
|
+
order: number;
|
|
1014
|
+
};
|
|
1015
|
+
/**
|
|
1016
|
+
* `Fold`: the view turned by `angle` (radians) about its vertical axis (`axis: 0`) or its horizontal one (`axis: 1`),
|
|
1017
|
+
* leaning by `perspective` (0..1), its back darkened by `shade` (0..1).
|
|
1018
|
+
*
|
|
1019
|
+
* @example
|
|
1020
|
+
* ```ts
|
|
1021
|
+
* const value: FoldValue = { angle: Math.PI / 2, axis: 1, perspective: 0.5, shade: 0.4, enabled: true, order: 0 };
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
type FoldValue = {
|
|
1025
|
+
angle: number;
|
|
1026
|
+
axis: number;
|
|
1027
|
+
perspective: number;
|
|
1028
|
+
shade: number;
|
|
1029
|
+
enabled: boolean;
|
|
1030
|
+
order: number;
|
|
1031
|
+
};
|
|
1032
|
+
/**
|
|
1033
|
+
* `Bloom`: light around the bright parts of the view: what is above `threshold` (0..1) of its light, blurred `radius`
|
|
1034
|
+
* CSS px wide and added back by `strength` (0..2).
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
* ```ts
|
|
1038
|
+
* const value: BloomValue = { strength: 0.6, threshold: 0.7, radius: 16, enabled: true, order: 0 };
|
|
1039
|
+
* ```
|
|
1040
|
+
*/
|
|
1041
|
+
type BloomValue = {
|
|
1042
|
+
strength: number;
|
|
1043
|
+
threshold: number;
|
|
1044
|
+
radius: number;
|
|
1045
|
+
enabled: boolean;
|
|
1046
|
+
order: number;
|
|
1047
|
+
};
|
|
1048
|
+
/**
|
|
1049
|
+
* `Pixelate`: the view drawn in square blocks `size` CSS px wide, from its top-left; 1 or less draws it as it is.
|
|
1050
|
+
*
|
|
1051
|
+
* @example
|
|
1052
|
+
* ```ts
|
|
1053
|
+
* const value: PixelateValue = { size: 8, enabled: true, order: 0 };
|
|
1054
|
+
* ```
|
|
1055
|
+
*/
|
|
1056
|
+
type PixelateValue = {
|
|
1057
|
+
size: number;
|
|
1058
|
+
enabled: boolean;
|
|
1059
|
+
order: number;
|
|
1060
|
+
};
|
|
1061
|
+
/**
|
|
1062
|
+
* `GradientMap`: the view's light mapped from `dark` through `middle` to `light`, mixed in by `amount` (0..1).
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```ts
|
|
1066
|
+
* const value: GradientMapValue = { dark: 0x2b1a0e, middle: 0x9c6b3c, light: 0xf5e6c8, amount: 1, enabled: true, order: 0 };
|
|
1067
|
+
* ```
|
|
1068
|
+
*/
|
|
1069
|
+
type GradientMapValue = {
|
|
1070
|
+
dark: number;
|
|
1071
|
+
middle: number;
|
|
1072
|
+
light: number;
|
|
1073
|
+
amount: number;
|
|
1074
|
+
enabled: boolean;
|
|
1075
|
+
order: number;
|
|
1076
|
+
};
|
|
1077
|
+
/**
|
|
1078
|
+
* `Wave`: the view swaying by `amplitude` CSS px, one wave every `wavelength` CSS px, shifted by `phase` (radians);
|
|
1079
|
+
* at `angle` 0 its rows sway left and right, at `π / 2` its columns up and down.
|
|
1080
|
+
*
|
|
1081
|
+
* @example
|
|
1082
|
+
* ```ts
|
|
1083
|
+
* const value: WaveValue = { amplitude: 4, wavelength: 48, phase: Math.PI, angle: 0, enabled: true, order: 0 };
|
|
1084
|
+
* ```
|
|
1085
|
+
*/
|
|
1086
|
+
type WaveValue = {
|
|
1087
|
+
amplitude: number;
|
|
1088
|
+
wavelength: number;
|
|
1089
|
+
phase: number;
|
|
1090
|
+
angle: number;
|
|
1091
|
+
enabled: boolean;
|
|
1092
|
+
order: number;
|
|
1093
|
+
};
|
|
1094
|
+
/**
|
|
1095
|
+
* `Mirror`: the view flipped top to bottom (`axis: 1`) or left to right (`axis: 0`), at `alpha` (0..1), fading out to
|
|
1096
|
+
* nothing at `fade` of its size from the mirror line; `fade: 0` keeps it whole.
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```ts
|
|
1100
|
+
* const value: MirrorValue = { axis: 1, alpha: 0.4, fade: 0.5, enabled: true, order: 0 };
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
1103
|
+
type MirrorValue = {
|
|
1104
|
+
axis: number;
|
|
1105
|
+
alpha: number;
|
|
1106
|
+
fade: number;
|
|
1107
|
+
enabled: boolean;
|
|
1108
|
+
order: number;
|
|
1109
|
+
};
|
|
1110
|
+
/**
|
|
1111
|
+
* `Shadow`: a shadow of `color` at `alpha` (0..1) under the view, moved by `x`, `y` CSS px and `soft` CSS px wide;
|
|
1112
|
+
* `|x| + soft` and `|y| + soft` are held within the padding of 8.
|
|
1113
|
+
*
|
|
1114
|
+
* @example
|
|
1115
|
+
* ```ts
|
|
1116
|
+
* const value: ShadowValue = { x: 0, y: 4, soft: 4, color: 0x000000, alpha: 0.5, enabled: true, order: 0 };
|
|
1117
|
+
* ```
|
|
1118
|
+
*/
|
|
1119
|
+
type ShadowValue = {
|
|
1120
|
+
x: number;
|
|
1121
|
+
y: number;
|
|
1122
|
+
soft: number;
|
|
1123
|
+
color: number;
|
|
1124
|
+
alpha: number;
|
|
1125
|
+
enabled: boolean;
|
|
1126
|
+
order: number;
|
|
1127
|
+
};
|
|
1128
|
+
declare namespace types_d_exports$1 {
|
|
1129
|
+
export { AlphaValue, AssetsReplaced$1 as AssetsReplaced, AuraValue, BloomValue, BlurValue, BundleUnloaded$1 as BundleUnloaded, ColorMatrixValue, Config$1 as Config, CoreKind, Curve, Deps$1 as Deps, DisplacementValue, DissolveValue, EffectsApi, EffectsCtx, EffectsDiagnostics, EffectsStats, EmitterConfig, EmitterDefinition, EmitterValue, FilterArea, FilterCache, FilterChainContext, FilterComponent, FilterDefinition, FilterInput, FilterInputDefinition, FilterSpec, FilterStage, FilterStep, FilterValueOf, FlashValue, FoldValue, GlowValue, GradeValue, GradientMapValue, HotSwap, KernelSlice$1 as KernelSlice, MirrorValue, NoiseValue, OutlineValue, PixelateValue, Range, ResolvedEmitterConfig, RevealLineValue, RevealRoundValue, ShadowValue, Shape, ShineValue, State$1 as State, UniformDeclaration, UniformSpec, UniformValue, VignetteValue, WaveValue };
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* effects plugin config. `maxParticles` here is the global warning line; the `maxParticles` of an
|
|
1133
|
+
* emitter config caps one instance.
|
|
1134
|
+
*
|
|
1135
|
+
* @example
|
|
1136
|
+
* ```ts
|
|
1137
|
+
* createApp({
|
|
1138
|
+
* plugins: [...screen, effectsPlugin],
|
|
1139
|
+
* pluginConfigs: { effects: { maxPasses: 16, phone: false } }
|
|
1140
|
+
* });
|
|
1141
|
+
* ```
|
|
1142
|
+
*/
|
|
1143
|
+
type Config$1 = {
|
|
1144
|
+
/** Live particles over all instances above which one dev warning fires per crossing. */maxParticles: number; /** Render passes per frame above which one dev warning fires once they stay over it 60 frames in a row. */
|
|
1145
|
+
maxPasses: number; /** Whether this device is a phone. `"auto"`: a coarse pointer and a short side of at most 820 CSS px, read once in `onStart`. */
|
|
1146
|
+
phone: boolean | "auto";
|
|
1147
|
+
/**
|
|
1148
|
+
* What a `Blur` with `quality: 0` and `resolution: 0` resolves to. Shallow merge: a game that
|
|
1149
|
+
* sets `blur` gives both fields.
|
|
1150
|
+
*/
|
|
1151
|
+
blur: {
|
|
1152
|
+
quality: number;
|
|
1153
|
+
phoneResolution: number;
|
|
1154
|
+
};
|
|
1155
|
+
};
|
|
1156
|
+
/**
|
|
1157
|
+
* effects plugin state: the particle half, the filter half, and what both share.
|
|
1158
|
+
*/
|
|
1159
|
+
type State$1 = {
|
|
1160
|
+
/** Resolved in `onStart`. */phone: boolean; /** The `emitters` of every feature, read in `onStart`. */
|
|
1161
|
+
emitters: Map<string, EmitterDefinition>; /** Per effect id, built on first use. */
|
|
1162
|
+
baked: Map<string, BakedEmitter>; /** Host entity to its running instance. */
|
|
1163
|
+
instances: Map<Entity, EmitterInstance>; /** World-space instances whose host left, stepped until empty. */
|
|
1164
|
+
orphans: Set<EmitterInstance>; /** Ordinal of the next instance: the cosmetic seed. */
|
|
1165
|
+
seedCounter: number; /** Live particles after the last step. */
|
|
1166
|
+
particles: number; /** Filter kinds whose shader or one of whose stages failed the check on the running backend, in every build. */
|
|
1167
|
+
broken: Set<string>; /** Filter kinds whose main definition and every stage answered ok: a kind's status is a set lookup once settled. */
|
|
1168
|
+
ready: Set<string>; /** The filter kinds, built-ins first, then the filters of every feature. */
|
|
1169
|
+
kinds: Map<string, FilterKind>; /** The shader check of every definition a kind can draw, in every build. */
|
|
1170
|
+
checks: CheckState; /** Entity to the filters the sync keeps for it. */
|
|
1171
|
+
views: Map<Entity, FilteredView>;
|
|
1172
|
+
/**
|
|
1173
|
+
* The records of `views` in the order they were first seen: the dense list the filter sync walks by index. A
|
|
1174
|
+
* forgotten record stays, `gone`, until the next run drops it.
|
|
1175
|
+
*/
|
|
1176
|
+
viewList: FilteredView[]; /** The filter kinds in registration order, one per `index`: the change sets the filter sync reads, by index. */
|
|
1177
|
+
kindList: FilterKind[]; /** Where the filter sync stands between two runs. */
|
|
1178
|
+
filterSync: FilterSyncState; /** Keys of the one-shot warnings: `"emitter:fx.x"`, `"texture:board.cell"`, `"atlas:fx.x"`. */
|
|
1179
|
+
warned: Set<string>;
|
|
1180
|
+
/**
|
|
1181
|
+
* Whether each budget warning is in force, so a crossing warns once; for the passes, the frames in a row over the
|
|
1182
|
+
* budget, so only a steady crossing warns.
|
|
1183
|
+
*/
|
|
1184
|
+
over: {
|
|
1185
|
+
particles: boolean;
|
|
1186
|
+
passes: number;
|
|
1187
|
+
fullScreen: boolean;
|
|
1188
|
+
}; /** The teardown closure, the two systems and the world hooks. */
|
|
1189
|
+
removers: Array<() => void>;
|
|
1190
|
+
/**
|
|
1191
|
+
* The switches of a debug build: the kind ids in registration order (frozen, filled in `onStart`), the kinds
|
|
1192
|
+
* turned off, and those as a frozen list in the order of `kinds`.
|
|
1193
|
+
*/
|
|
1194
|
+
diagnostics: {
|
|
1195
|
+
kinds: readonly string[];
|
|
1196
|
+
off: Set<string>;
|
|
1197
|
+
offList: readonly string[];
|
|
1198
|
+
};
|
|
1199
|
+
/**
|
|
1200
|
+
* The warm-up hand-over (spec 27 F4): started at the first frame with a ready host, the Pixi-core kinds noted then,
|
|
1201
|
+
* and the probes handed to `renderer.sync.filters.warm`, kept until the app stops.
|
|
1202
|
+
*/
|
|
1203
|
+
warm: {
|
|
1204
|
+
started: boolean;
|
|
1205
|
+
core: string[];
|
|
1206
|
+
probes: WarmProbe[];
|
|
1207
|
+
};
|
|
1208
|
+
};
|
|
1209
|
+
/**
|
|
1210
|
+
* What `app.effects.stats()` answers: live particles, running emitter instances, filter instances
|
|
1211
|
+
* on views, and the render passes of the frame as the renderer counts them.
|
|
1212
|
+
*
|
|
1213
|
+
* @example
|
|
1214
|
+
* ```ts
|
|
1215
|
+
* const stats: EffectsStats = { particles: 120, emitters: 3, filters: 25, renderPasses: 49 };
|
|
1216
|
+
* ```
|
|
1217
|
+
*/
|
|
1218
|
+
type EffectsStats = {
|
|
1219
|
+
/** Live particles over every instance and orphan after the last step. */particles: number; /** Running instances plus the orphans still flying. */
|
|
1220
|
+
emitters: number; /** Filter instances over every view; the stages of a filter's inputs are counted in `renderPasses`, not here. */
|
|
1221
|
+
filters: number; /** `renderer.sync.renderPasses()`, read at call time. */
|
|
1222
|
+
renderPasses: number;
|
|
1223
|
+
};
|
|
1224
|
+
/**
|
|
1225
|
+
* effects plugin API, `app.effects`. Everything a game does with effects is data on entities;
|
|
1226
|
+
* the API only counts.
|
|
1227
|
+
*
|
|
1228
|
+
* @example
|
|
1229
|
+
* ```ts
|
|
1230
|
+
* // A test waits for a merge burst to land before it compares the board.
|
|
1231
|
+
* while (app.effects.stats().particles > 0) app.time.step(16);
|
|
1232
|
+
* app.effects.stats().particles; // 0
|
|
1233
|
+
* ```
|
|
1234
|
+
*/
|
|
1235
|
+
type EffectsApi = {
|
|
1236
|
+
/**
|
|
1237
|
+
* Counts what runs now. `renderPasses` is the renderer's own number, read at call time; the
|
|
1238
|
+
* others are the plugin's. Headless every number is 0.
|
|
1239
|
+
*
|
|
1240
|
+
* @returns A fresh object: live particles, emitter instances with orphans, filter instances
|
|
1241
|
+
* and render passes.
|
|
1242
|
+
* @example
|
|
1243
|
+
* ```ts
|
|
1244
|
+
* // After the board rests: one steam stream, 24 enabled glows on 24 views, one disabled blur.
|
|
1245
|
+
* app.effects.stats();
|
|
1246
|
+
* // { particles: 18, emitters: 1, filters: 25, renderPasses: 49 }: 1 + 24 × (1 + 1), the disabled blur costs 0
|
|
1247
|
+
* ```
|
|
1248
|
+
*/
|
|
1249
|
+
stats(): EffectsStats;
|
|
1250
|
+
/**
|
|
1251
|
+
* Switches of a debug build: filter kinds turned off by hand, to measure what a kind costs on the device. Acts on
|
|
1252
|
+
* a page with the agent flag (a debug build, the dev page); elsewhere `disable` and `enable` change nothing. An off
|
|
1253
|
+
* kind keeps its instances: `stats().filters` still counts them, `renderPasses` drops.
|
|
1254
|
+
*
|
|
1255
|
+
* @example
|
|
1256
|
+
* ```ts
|
|
1257
|
+
* // A game's overlay toggle "Glow": the frame without any glow, then with it again.
|
|
1258
|
+
* app.effects.diagnostics.disable("effects.glow"); // true
|
|
1259
|
+
* app.effects.diagnostics.enable("effects.glow"); // true
|
|
1260
|
+
* ```
|
|
1261
|
+
*/
|
|
1262
|
+
diagnostics: EffectsDiagnostics;
|
|
1263
|
+
};
|
|
1264
|
+
/**
|
|
1265
|
+
* Switches of a debug build: filter kinds turned off by hand, to measure what a kind costs on the device. Acts on
|
|
1266
|
+
* a page with the agent flag (a debug build, the dev page); elsewhere `disable` and `enable` change nothing.
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```ts
|
|
1270
|
+
* // A game's overlay toggle "Glow" (H4.4): the frame without any glow, then with it again.
|
|
1271
|
+
* app.effects.diagnostics.disable("effects.glow"); // true
|
|
1272
|
+
* app.effects.diagnostics.enable("effects.glow"); // true
|
|
1273
|
+
* ```
|
|
1274
|
+
*/
|
|
1275
|
+
type EffectsDiagnostics = {
|
|
1276
|
+
/**
|
|
1277
|
+
* The filter kinds this app knows, in registration order: the seven built-ins, then the `filters` of every
|
|
1278
|
+
* feature. The same frozen array on every call; empty before start. Every build.
|
|
1279
|
+
*
|
|
1280
|
+
* @returns The kind ids.
|
|
1281
|
+
* @example
|
|
1282
|
+
* ```ts
|
|
1283
|
+
* // A game with the frost filter of its casefile feature, after start.
|
|
1284
|
+
* app.effects.diagnostics.kinds();
|
|
1285
|
+
* // ["effects.glow", "effects.outline", "effects.blur", "effects.colorMatrix", "effects.noise",
|
|
1286
|
+
* // "effects.displacement", "effects.alpha", "casefile.frost"]
|
|
1287
|
+
* ```
|
|
1288
|
+
*/
|
|
1289
|
+
kinds(): readonly string[];
|
|
1290
|
+
/**
|
|
1291
|
+
* Turns a filter kind off: from the next frame no view draws it (no apply, no render pass), while its instances
|
|
1292
|
+
* stay and are still written, so `enable` shows the current look at once. Agent pages only.
|
|
1293
|
+
*
|
|
1294
|
+
* @param kind - A kind id of `kinds()`.
|
|
1295
|
+
* @returns True when the kind is known and now off; false for an unknown kind, and on a page without the agent
|
|
1296
|
+
* flag, where nothing changes.
|
|
1297
|
+
* @example
|
|
1298
|
+
* ```ts
|
|
1299
|
+
* // The owner measures the board without the glow of its four cards (one glow pass each).
|
|
1300
|
+
* app.effects.diagnostics.disable("effects.glow"); // true
|
|
1301
|
+
* app.time.step(16);
|
|
1302
|
+
* app.effects.stats().renderPasses; // 9, down from 13
|
|
1303
|
+
* app.effects.diagnostics.disable("fx.nope"); // false, and one warning effects:diagnostics-unknown
|
|
1304
|
+
* ```
|
|
1305
|
+
*/
|
|
1306
|
+
disable(kind: string): boolean;
|
|
1307
|
+
/**
|
|
1308
|
+
* Turns a filter kind on again: from the next frame its views draw it with their current values.
|
|
1309
|
+
*
|
|
1310
|
+
* @param kind - A kind id of `kinds()`.
|
|
1311
|
+
* @returns True when the kind is known and now on; false for an unknown kind and without the agent flag.
|
|
1312
|
+
* @example
|
|
1313
|
+
* ```ts
|
|
1314
|
+
* app.effects.diagnostics.enable("effects.glow"); // true
|
|
1315
|
+
* app.time.step(16);
|
|
1316
|
+
* app.effects.stats().renderPasses; // 13
|
|
1317
|
+
* ```
|
|
1318
|
+
*/
|
|
1319
|
+
enable(kind: string): boolean;
|
|
1320
|
+
/**
|
|
1321
|
+
* The kinds turned off now, in registration order. The same frozen array until the next change; empty without
|
|
1322
|
+
* the agent flag.
|
|
1323
|
+
*
|
|
1324
|
+
* @returns The kind ids.
|
|
1325
|
+
* @example
|
|
1326
|
+
* ```ts
|
|
1327
|
+
* app.effects.diagnostics.disable("casefile.frost");
|
|
1328
|
+
* app.effects.diagnostics.disable("effects.glow");
|
|
1329
|
+
* app.effects.diagnostics.disabled(); // ["effects.glow", "casefile.frost"]
|
|
1330
|
+
* ```
|
|
1331
|
+
*/
|
|
1332
|
+
disabled(): readonly string[];
|
|
1333
|
+
};
|
|
1334
|
+
/**
|
|
1335
|
+
* Resolved dependency APIs.
|
|
1336
|
+
*/
|
|
1337
|
+
type Deps$1 = {
|
|
1338
|
+
flow: Api;
|
|
1339
|
+
world: Api$1;
|
|
1340
|
+
renderer: Api$2;
|
|
1341
|
+
assets: Api$3;
|
|
1342
|
+
anim: AnimApi;
|
|
1343
|
+
};
|
|
1344
|
+
/**
|
|
1345
|
+
* What the kernel context offers before the deps are attached. `effects` owns no event, so
|
|
1346
|
+
* `emit` is the kernel's and never called here.
|
|
1347
|
+
*/
|
|
1348
|
+
type KernelSlice$1 = PluginCtx<Config$1, State$1> & {
|
|
1349
|
+
readonly global: object;
|
|
1350
|
+
readonly log: Log.LogApi;
|
|
1351
|
+
readonly require: Require;
|
|
1352
|
+
};
|
|
1353
|
+
/**
|
|
1354
|
+
* Domain context shared by both modules: the kernel slice plus the resolved deps.
|
|
1355
|
+
*/
|
|
1356
|
+
type EffectsCtx = KernelSlice$1 & {
|
|
1357
|
+
readonly deps: Deps$1;
|
|
1358
|
+
};
|
|
1359
|
+
/**
|
|
1360
|
+
* Payload of the `assets:bundle-unloaded` hook: `keys` names every texture that is gone.
|
|
1361
|
+
*/
|
|
1362
|
+
type BundleUnloaded$1 = Events["assets:bundle-unloaded"];
|
|
1363
|
+
/**
|
|
1364
|
+
* Payload of the `assets:replaced` hook: `keys` names every asset a dev hot swap gave new bytes.
|
|
1365
|
+
*/
|
|
1366
|
+
type AssetsReplaced$1 = Events["assets:replaced"];
|
|
1367
|
+
/**
|
|
1368
|
+
* Payload of the global `ui:hot-swap` hook: the saved file and its new exports.
|
|
1369
|
+
*/
|
|
1370
|
+
type HotSwap = Events$1["ui:hot-swap"];
|
|
1371
|
+
declare namespace types_d_exports {
|
|
1372
|
+
export { AssetsReplaced, AudioApi, AudioContextLike, AudioCtx, AudioSessionLike, AudioSessionType, BundleUnloaded, Bus, BusState, Config, Deps, KernelSlice, LifecycleChanged, ModelCommitted, MusicDescriptor, MusicMode, MusicOptions, MusicRequest, MusicSwitch, MusicTrack, NamedSound, RetiringTrack, SceneChanged, SfxRequest, SoundEntry, State, StreamTrack, Volumes, VolumesFor };
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* The three volume buses. `master` carries the whole game, `music` the scene track, `sfx` every
|
|
1376
|
+
* sound a node or a timeline fires.
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1379
|
+
* ```ts
|
|
1380
|
+
* const bus: Bus = "music";
|
|
1381
|
+
* ```
|
|
1382
|
+
*/
|
|
1383
|
+
type Bus = "master" | "music" | "sfx";
|
|
1384
|
+
/**
|
|
1385
|
+
* The part of `AudioContext` the plugin uses. A test passes its own through `config.context`, so
|
|
1386
|
+
* nothing in the unit tests touches a sound card. `state` adds Safari's `"interrupted"`, which a
|
|
1387
|
+
* phone call or the lock screen puts a context into.
|
|
1388
|
+
*
|
|
1389
|
+
* @example
|
|
1390
|
+
* ```ts
|
|
1391
|
+
* // A dev tool builds the engine's context itself and hands it to the plugin.
|
|
1392
|
+
* const context: AudioContextLike = new AudioContext();
|
|
1393
|
+
* createApp({ plugins: [...screen, audioPlugin], pluginConfigs: { audio: { context: () => context } } });
|
|
1394
|
+
* ```
|
|
1395
|
+
*/
|
|
1396
|
+
type AudioContextLike = Pick<AudioContext, "destination" | "currentTime" | "createGain" | "createBufferSource" | "decodeAudioData" | "createMediaElementSource" | "resume" | "close"> & {
|
|
1397
|
+
readonly state: AudioContext["state"] | "interrupted";
|
|
1398
|
+
};
|
|
1399
|
+
/**
|
|
1400
|
+
* What `music` accepts besides the key. An absent `fadeMs` means `config.musicFadeMs` at play time.
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* ```ts
|
|
1404
|
+
* const options: MusicOptions = { fadeMs: 200 };
|
|
1405
|
+
* ```
|
|
1406
|
+
*/
|
|
1407
|
+
type MusicOptions = {
|
|
1408
|
+
fadeMs?: number;
|
|
1409
|
+
};
|
|
1410
|
+
/**
|
|
1411
|
+
* `music` bound to the audio asset keys of one game. `defineGame` returns it through `audioFor`;
|
|
1412
|
+
* the loose export accepts any string. The descriptor resolves nothing.
|
|
1413
|
+
*
|
|
1414
|
+
* @example
|
|
1415
|
+
* ```ts
|
|
1416
|
+
* const gameMusic: MusicDescriptor<"board.theme"> = music;
|
|
1417
|
+
* ```
|
|
1418
|
+
*/
|
|
1419
|
+
type MusicDescriptor<Asset extends string> = (key: Asset | null, options?: MusicOptions) => Descriptor<void>;
|
|
1420
|
+
/**
|
|
1421
|
+
* Reads the player's volume choice out of the committed player state. Every bus it names is
|
|
1422
|
+
* applied; the ones it leaves out keep the value they had.
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* ```ts
|
|
1426
|
+
* const volumes: Volumes = player => (player as { settings: { audio: { music: number } } }).settings.audio;
|
|
1427
|
+
* ```
|
|
1428
|
+
*/
|
|
1429
|
+
type Volumes = (player: Json) => Partial<Record<Bus, number>>;
|
|
1430
|
+
/**
|
|
1431
|
+
* `Volumes`, written against the player type of one game: `defineGame` hands it as `volumes`, so
|
|
1432
|
+
* the callback reads the game's player with no cast. The same function at run time.
|
|
1433
|
+
*
|
|
1434
|
+
* @example
|
|
1435
|
+
* ```ts
|
|
1436
|
+
* // index.ts of a game: `volumes` comes from the kit, so `player` is the game's Player.
|
|
1437
|
+
* pluginConfigs: { audio: { volumes: volumes(player => ({ music: player.settings.music })) } }
|
|
1438
|
+
* ```
|
|
1439
|
+
*/
|
|
1440
|
+
type VolumesFor<Player> = (read: (player: Player) => Partial<Record<Bus, number>>) => Volumes;
|
|
1441
|
+
/**
|
|
1442
|
+
* How a music track is played. `"decode"`: one AudioBuffer per track, gapless, about 58 MB per
|
|
1443
|
+
* 150 s at 48 kHz. `"stream"`: an `<audio>` element on a `blob:` URL of the bytes `assets` holds,
|
|
1444
|
+
* about 12 MB, and a gap at every loop: 5 to 49 ms in Chromium, about 0.4 s in WebKit. A tight
|
|
1445
|
+
* loop keeps `"decode"`; a long track that tolerates a seam takes `"stream"`.
|
|
1446
|
+
*
|
|
1447
|
+
* @example
|
|
1448
|
+
* ```ts
|
|
1449
|
+
* const mode: MusicMode = "stream";
|
|
1450
|
+
* ```
|
|
1451
|
+
*/
|
|
1452
|
+
type MusicMode = "decode" | "stream";
|
|
1453
|
+
/**
|
|
1454
|
+
* What the page asks iOS for. `"ambient"`: mixes with other apps, the silent switch mutes it.
|
|
1455
|
+
* `"playback"`: stops other apps, plays through the switch. `"auto"`: WebKit picks.
|
|
1456
|
+
*
|
|
1457
|
+
* @example
|
|
1458
|
+
* ```ts
|
|
1459
|
+
* const session: AudioSessionType = "playback";
|
|
1460
|
+
* ```
|
|
1461
|
+
*/
|
|
1462
|
+
type AudioSessionType = "ambient" | "playback" | "auto";
|
|
1463
|
+
/**
|
|
1464
|
+
* The part of `navigator.audioSession` the plugin writes. `lib.dom` has no type for it, and only
|
|
1465
|
+
* WebKit has the object at all.
|
|
1466
|
+
*
|
|
1467
|
+
* @example
|
|
1468
|
+
* ```ts
|
|
1469
|
+
* // What Safari answers before the plugin started: no override.
|
|
1470
|
+
* const session: AudioSessionLike = { type: "auto" };
|
|
1471
|
+
* ```
|
|
1472
|
+
*/
|
|
1473
|
+
type AudioSessionLike = {
|
|
1474
|
+
type: string;
|
|
1475
|
+
};
|
|
1476
|
+
/**
|
|
1477
|
+
* One music track played by an element at `music: "stream"`: the element, its source node in the
|
|
1478
|
+
* graph, the track gain every level goes through, and the `blob:` URL the element reads.
|
|
1479
|
+
*
|
|
1480
|
+
* @example
|
|
1481
|
+
* ```ts
|
|
1482
|
+
* // `state.music.stream` once "board.theme" plays at `music: "stream"`.
|
|
1483
|
+
* const { element, url }: StreamTrack = track;
|
|
1484
|
+
* element.loop; // true
|
|
1485
|
+
* url.startsWith("blob:"); // true
|
|
1486
|
+
* ```
|
|
1487
|
+
*/
|
|
1488
|
+
type StreamTrack = {
|
|
1489
|
+
element: HTMLAudioElement;
|
|
1490
|
+
node: MediaElementAudioSourceNode;
|
|
1491
|
+
gain: GainNode;
|
|
1492
|
+
url: string;
|
|
1493
|
+
};
|
|
1494
|
+
/**
|
|
1495
|
+
* A streamed track that fades out. Its timer frees the element when the fade ends: an element has
|
|
1496
|
+
* no `stop(when)` on the context clock.
|
|
1497
|
+
*
|
|
1498
|
+
* @example
|
|
1499
|
+
* ```ts
|
|
1500
|
+
* // A switch at `musicFadeMs: 600` keeps the old track here for 600 ms.
|
|
1501
|
+
* const entry: RetiringTrack = { stream: oldTrack, timer: setTimeout(free, 600) };
|
|
1502
|
+
* ```
|
|
1503
|
+
*/
|
|
1504
|
+
type RetiringTrack = {
|
|
1505
|
+
stream: StreamTrack;
|
|
1506
|
+
timer: ReturnType<typeof setTimeout>;
|
|
1507
|
+
};
|
|
1508
|
+
/**
|
|
1509
|
+
* audio plugin config.
|
|
1510
|
+
*
|
|
1511
|
+
* @example
|
|
1512
|
+
* ```ts
|
|
1513
|
+
* // `volumes` comes from the game's `defineGame` kit, so `player` is the game's Player.
|
|
1514
|
+
* createApp({
|
|
1515
|
+
* plugins: [...screen, audioPlugin],
|
|
1516
|
+
* pluginConfigs: {
|
|
1517
|
+
* audio: { musicFadeMs: 400, music: "stream", session: "playback", volumes: volumes(player => player.settings.audio) }
|
|
1518
|
+
* }
|
|
1519
|
+
* });
|
|
1520
|
+
* ```
|
|
1521
|
+
*/
|
|
1522
|
+
type Config = {
|
|
1523
|
+
/** Start gain of each bus, 0..1. Overridden per commit when `volumes` is set. */buses: {
|
|
1524
|
+
master: number;
|
|
1525
|
+
music: number;
|
|
1526
|
+
sfx: number;
|
|
1527
|
+
}; /** Cross-fade of a music switch, in real milliseconds of the context clock. */
|
|
1528
|
+
musicFadeMs: number;
|
|
1529
|
+
/**
|
|
1530
|
+
* Fade of a named sound, an `sfx` with `id`, in real milliseconds of the context clock: when a
|
|
1531
|
+
* new sound with its id replaces it and names no `fadeMs`, or a stop names none.
|
|
1532
|
+
*/
|
|
1533
|
+
sfxFadeMs: number; /** Reads the player's choice from the committed player. `undefined`: the buses stay at `buses`. */
|
|
1534
|
+
volumes: Volumes | undefined;
|
|
1535
|
+
/**
|
|
1536
|
+
* Context factory, the test seam. `undefined`: `new AudioContext()` when the global exists, otherwise headless.
|
|
1537
|
+
* On iOS the plugin calls it again after a return from the background, so each call returns a new context.
|
|
1538
|
+
*/
|
|
1539
|
+
context: (() => AudioContextLike) | undefined; /** How many started sounds `journal()` keeps, newest last. `0` turns the journal off. */
|
|
1540
|
+
journal: number; /** How music plays. `"stream"` needs MP3 or AAC: WebM Opus is silent through a media element in WebKit (bug 276813). Sounds always decode. */
|
|
1541
|
+
music: MusicMode; /** Set on `navigator.audioSession.type` in `onStart`, before the context exists. No-op where the API is missing (every Chromium, Firefox). */
|
|
1542
|
+
session: AudioSessionType;
|
|
1543
|
+
};
|
|
1544
|
+
/**
|
|
1545
|
+
* One sound that started: a play of an `sfx` or a music track that began. `at` is the elapsed
|
|
1546
|
+
* game time in milliseconds, `app.time.snapshot().elapsed` at the start. `id` is there only for
|
|
1547
|
+
* an `sfx` started with one.
|
|
1548
|
+
*
|
|
1549
|
+
* @example
|
|
1550
|
+
* ```ts
|
|
1551
|
+
* const entry: SoundEntry = { key: "ui.click", bus: "sfx", kind: "sfx", at: 1600 };
|
|
1552
|
+
* const line: SoundEntry = { key: "story.line1", bus: "sfx", kind: "sfx", id: "voice", at: 2400 };
|
|
1553
|
+
* ```
|
|
1554
|
+
*/
|
|
1555
|
+
type SoundEntry = {
|
|
1556
|
+
readonly key: string;
|
|
1557
|
+
readonly bus: Bus;
|
|
1558
|
+
readonly kind: "sfx" | "music";
|
|
1559
|
+
readonly id?: string;
|
|
1560
|
+
readonly at: number;
|
|
1561
|
+
};
|
|
1562
|
+
/**
|
|
1563
|
+
* What the plugin keeps for one bus: its gain node while a context exists, the volume a game or
|
|
1564
|
+
* the player chose, and whether it is muted.
|
|
1565
|
+
*
|
|
1566
|
+
* @example
|
|
1567
|
+
* ```ts
|
|
1568
|
+
* const entry: BusState = { gain: undefined, volume: 0.6, muted: false };
|
|
1569
|
+
* ```
|
|
1570
|
+
*/
|
|
1571
|
+
type BusState = {
|
|
1572
|
+
gain: GainNode | undefined;
|
|
1573
|
+
volume: number;
|
|
1574
|
+
muted: boolean;
|
|
1575
|
+
};
|
|
1576
|
+
/**
|
|
1577
|
+
* The music that is playing, or the key remembered until the context is unlocked.
|
|
1578
|
+
* `source` plays a decoded track, `stream` a streamed one; they are never both set. Both
|
|
1579
|
+
* `undefined`: the key is only remembered (a locked context, or a refused `play()`).
|
|
1580
|
+
*
|
|
1581
|
+
* @example
|
|
1582
|
+
* ```ts
|
|
1583
|
+
* const track: MusicTrack = { key: "board.theme", gain: undefined, source: undefined, stream: undefined };
|
|
1584
|
+
* ```
|
|
1585
|
+
*/
|
|
1586
|
+
type MusicTrack = {
|
|
1587
|
+
key: string;
|
|
1588
|
+
gain: GainNode | undefined;
|
|
1589
|
+
source: AudioBufferSourceNode | undefined;
|
|
1590
|
+
stream: StreamTrack | undefined;
|
|
1591
|
+
};
|
|
1592
|
+
/**
|
|
1593
|
+
* A music switch that waits for its buffer to decode. Its identity is the token: a later request
|
|
1594
|
+
* replaces it, and the replaced switch neither starts nor fades anything when its buffer arrives.
|
|
1595
|
+
*
|
|
1596
|
+
* @example
|
|
1597
|
+
* ```ts
|
|
1598
|
+
* const waiting: MusicSwitch = { key: "ui.theme" };
|
|
1599
|
+
* ```
|
|
1600
|
+
*/
|
|
1601
|
+
type MusicSwitch = {
|
|
1602
|
+
key: string;
|
|
1603
|
+
};
|
|
1604
|
+
/**
|
|
1605
|
+
* The sound that plays, or still decodes, under one id. The entry object is the token, as a
|
|
1606
|
+
* `MusicSwitch` is: a sound whose entry is no longer the one `named` holds when its buffer arrives
|
|
1607
|
+
* starts nothing. `gain` and `source` stay `undefined` until the sound started.
|
|
1608
|
+
*/
|
|
1609
|
+
type NamedSound = {
|
|
1610
|
+
gain: GainNode | undefined;
|
|
1611
|
+
source: AudioBufferSourceNode | undefined;
|
|
1612
|
+
};
|
|
1613
|
+
/**
|
|
1614
|
+
* audio plugin state.
|
|
1615
|
+
*/
|
|
1616
|
+
type State = {
|
|
1617
|
+
/** `undefined` means headless: no graph, no sound, every member still keeps its value. */context: AudioContextLike | undefined;
|
|
1618
|
+
buses: Record<Bus, BusState>; /** A lifecycle push is in force: every bus is held at zero. */
|
|
1619
|
+
paused: boolean;
|
|
1620
|
+
unlocked: boolean; /** A gesture called `resume()` and it has not settled yet. The start attempt never sets it. */
|
|
1621
|
+
resuming: boolean;
|
|
1622
|
+
/**
|
|
1623
|
+
* Sounds fired while `resuming`: one per id, under `"#" + id`, and one per key for a sound
|
|
1624
|
+
* without an id. Played when the context runs, dropped when it does not.
|
|
1625
|
+
*/
|
|
1626
|
+
pendingSfx: Map<string, SfxRequest>; /** The sound that plays, or decodes, under each id; an entry leaves when its sound ends or stops. */
|
|
1627
|
+
named: Map<string, NamedSound>; /** Per key, evicted per key on `assets:bundle-unloaded` and `assets:replaced`, and when a music track stops being the one that plays. */
|
|
1628
|
+
decoded: Map<string, Promise<AudioBuffer>>; /** Asset keys that already got their one warning. */
|
|
1629
|
+
warned: Set<string>; /** `config.volumes` threw once and was reported; it is not reported again this run. */
|
|
1630
|
+
warnedVolumes: boolean;
|
|
1631
|
+
music: MusicTrack | undefined; /** The latest switch still decoding; `undefined` once it started or a later request replaced it. */
|
|
1632
|
+
musicPending: MusicSwitch | undefined; /** Removes the two window listeners of the unlock. */
|
|
1633
|
+
unlock: (() => void) | undefined; /** Cancels the renewal that waits after a return from the background: its timer and its two listeners. */
|
|
1634
|
+
renewal: (() => void) | undefined; /** The token of the renewal that runs; a stop or a newer renewal replaces it, and the old one makes nothing. */
|
|
1635
|
+
renewing: object | undefined; /** The removers of the three fx handlers. */
|
|
1636
|
+
removers: Array<() => void>; /** The `navigator.audioSession` that took `config.session`; `stop` writes `"auto"` back to it. */
|
|
1637
|
+
session: AudioSessionLike | undefined; /** Streamed tracks that fade out, each freed by its timer. */
|
|
1638
|
+
retiring: Set<RetiringTrack>;
|
|
1639
|
+
/**
|
|
1640
|
+
* The sounds that started, oldest first, at most `config.journal` of them. Frozen: a write
|
|
1641
|
+
* replaces the whole list, so `journal()` hands it out without a copy.
|
|
1642
|
+
*/
|
|
1643
|
+
journal: readonly SoundEntry[];
|
|
1644
|
+
};
|
|
1645
|
+
/**
|
|
1646
|
+
* audio plugin API, `app.audio`. Three buses, the unlock flag, the journal and the stop of a named
|
|
1647
|
+
* sound: what a game changes about sound it commits to the player state, which this plugin applies
|
|
1648
|
+
* on the next commit.
|
|
1649
|
+
*
|
|
1650
|
+
* @example
|
|
1651
|
+
* ```ts
|
|
1652
|
+
* // A dev overlay pulls the music down and reads the value back.
|
|
1653
|
+
* app.audio.setVolume("music", 0.2);
|
|
1654
|
+
* app.audio.volume("music"); // 0.2
|
|
1655
|
+
* ```
|
|
1656
|
+
*/
|
|
1657
|
+
type AudioApi = {
|
|
1658
|
+
/**
|
|
1659
|
+
* Sets the volume of one bus and schedules the new gain at once. The value is clamped to 0..1
|
|
1660
|
+
* and `NaN` becomes 0. Nothing is persisted: a game stores the choice in the player state and
|
|
1661
|
+
* lets `config.volumes` apply it, so the next commit overwrites what this call set.
|
|
1662
|
+
*
|
|
1663
|
+
* @param bus - The bus to change.
|
|
1664
|
+
* @param value - The new volume, 0..1.
|
|
1665
|
+
* @throws {Error} When the bus does not exist.
|
|
1666
|
+
* @example
|
|
1667
|
+
* ```ts
|
|
1668
|
+
* // A test turns the music off before it walks the graph, so nothing rings.
|
|
1669
|
+
* app.audio.setVolume("music", 0);
|
|
1670
|
+
* app.audio.volume("music"); // 0
|
|
1671
|
+
* ```
|
|
1672
|
+
*/
|
|
1673
|
+
setVolume(bus: Bus, value: number): void;
|
|
1674
|
+
/**
|
|
1675
|
+
* The stored volume of a bus, never the live gain: a muted or paused bus still answers the
|
|
1676
|
+
* value the player chose.
|
|
1677
|
+
*
|
|
1678
|
+
* @param bus - The bus to read.
|
|
1679
|
+
* @returns The stored volume, 0..1.
|
|
1680
|
+
* @throws {Error} When the bus does not exist.
|
|
1681
|
+
* @example
|
|
1682
|
+
* ```ts
|
|
1683
|
+
* // The settings screen draws the slider of the sfx bus at its stored place.
|
|
1684
|
+
* app.audio.mute("sfx", true);
|
|
1685
|
+
* app.audio.volume("sfx"); // 1: muting does not move the slider
|
|
1686
|
+
* ```
|
|
1687
|
+
*/
|
|
1688
|
+
volume(bus: Bus): number;
|
|
1689
|
+
/**
|
|
1690
|
+
* Mutes or unmutes one bus. The flag is independent of the pause: a bus muted here stays muted
|
|
1691
|
+
* when the game comes back from the background.
|
|
1692
|
+
*
|
|
1693
|
+
* @param bus - The bus to change.
|
|
1694
|
+
* @param on - `true` mutes it, `false` lets it play again.
|
|
1695
|
+
* @throws {Error} When the bus does not exist.
|
|
1696
|
+
* @example
|
|
1697
|
+
* ```ts
|
|
1698
|
+
* // A dev overlay silences the whole game while a profiler trace runs.
|
|
1699
|
+
* app.audio.mute("master", true);
|
|
1700
|
+
* app.audio.volume("master"); // 1, and nothing is heard
|
|
1701
|
+
* ```
|
|
1702
|
+
*/
|
|
1703
|
+
mute(bus: Bus, on: boolean): void;
|
|
1704
|
+
/**
|
|
1705
|
+
* Tells whether one bus is muted: the stored flag `mute` wrote. A pause does not change it, and
|
|
1706
|
+
* a headless run answers it too.
|
|
1707
|
+
*
|
|
1708
|
+
* @param bus - The bus to read.
|
|
1709
|
+
* @returns True while the bus is muted.
|
|
1710
|
+
* @throws {Error} When the bus does not exist.
|
|
1711
|
+
* @example
|
|
1712
|
+
* ```ts
|
|
1713
|
+
* // The settings screen draws the Sound switch off after the player muted the game.
|
|
1714
|
+
* app.audio.mute("master", true);
|
|
1715
|
+
* app.audio.muted("master"); // true
|
|
1716
|
+
* ```
|
|
1717
|
+
*/
|
|
1718
|
+
muted(bus: Bus): boolean;
|
|
1719
|
+
/**
|
|
1720
|
+
* Tells whether the audio context runs. A shell that lets audio play with no gesture, such as a
|
|
1721
|
+
* native webview with the requirement switched off, makes it true at start: at once when the
|
|
1722
|
+
* context is created running, otherwise when the `resume()` of `onStart` fulfils. A browser
|
|
1723
|
+
* that wants a gesture keeps it false until the first touch or click on the page resumed the
|
|
1724
|
+
* context and it runs; on iOS that resume may stay pending until iOS gives the sound back. It is
|
|
1725
|
+
* false for the whole of a headless run, and for the moment an iOS renewal closes the old context.
|
|
1726
|
+
*
|
|
1727
|
+
* @returns True once the context is running.
|
|
1728
|
+
* @example
|
|
1729
|
+
* ```ts
|
|
1730
|
+
* // A "tap for sound" hint stays on screen only while the shell holds the sound back.
|
|
1731
|
+
* await app.start();
|
|
1732
|
+
* app.audio.unlocked(); // true where the context was created running, false in a browser tab
|
|
1733
|
+
* // The player touches the page of that tab.
|
|
1734
|
+
* app.audio.unlocked(); // true
|
|
1735
|
+
* ```
|
|
1736
|
+
*/
|
|
1737
|
+
unlocked(): boolean;
|
|
1738
|
+
/**
|
|
1739
|
+
* The sounds that started, oldest first: every play of an `sfx` and every music track that
|
|
1740
|
+
* began, at most `config.journal` of them. A sound dropped before the unlock, a missing file
|
|
1741
|
+
* and a music switch to the track that already plays are not in it. Empty while
|
|
1742
|
+
* `config.journal` is 0, the default, and after the app stopped.
|
|
1743
|
+
*
|
|
1744
|
+
* No copy and no live view: the list and its entries are never written. Every new sound replaces the plugin's list
|
|
1745
|
+
* with a new frozen one, so a list read earlier keeps what it held, and a caller cannot change the journal through it.
|
|
1746
|
+
*
|
|
1747
|
+
* @returns The journal, frozen; a later sound replaces the list and leaves this one as it was.
|
|
1748
|
+
* @example
|
|
1749
|
+
* ```ts
|
|
1750
|
+
* // A test composed with `pluginConfigs.audio = { journal: 200 }` taps "deliver" after the
|
|
1751
|
+
* // first touch and checks the chime was heard.
|
|
1752
|
+
* app.audio.journal();
|
|
1753
|
+
* // [{ key: "board.theme", bus: "music", kind: "music", at: 0 },
|
|
1754
|
+
* // { key: "orders.complete", bus: "sfx", kind: "sfx", at: 1600 }]
|
|
1755
|
+
* ```
|
|
1756
|
+
*/
|
|
1757
|
+
journal(): readonly SoundEntry[];
|
|
1758
|
+
/**
|
|
1759
|
+
* Fades out and ends the sound that plays under one id, an `sfx` started with `{ id }`. The
|
|
1760
|
+
* same stop as the effect kind `stopSfx`: a sound with that id still decoding never starts, one
|
|
1761
|
+
* waiting for the unlock is dropped, and an id nothing plays under changes nothing. Headless it
|
|
1762
|
+
* does nothing.
|
|
1763
|
+
*
|
|
1764
|
+
* @param id - The id the sound was started with, `"voice"` for `sfx(key, { id: "voice" })`.
|
|
1765
|
+
* @param options - How the sound ends.
|
|
1766
|
+
* @param options.fadeMs - Length of the fade in real milliseconds; `config.sfxFadeMs` when absent, `0` cuts it at once.
|
|
1767
|
+
* @example
|
|
1768
|
+
* ```ts
|
|
1769
|
+
* // A test composed with `journal: 200` cuts the narrator's line before it checks the next screen.
|
|
1770
|
+
* app.audio.journal().at(-1); // { key: "story.line1", bus: "sfx", kind: "sfx", id: "voice", at: 0 }
|
|
1771
|
+
* app.audio.stop("voice", { fadeMs: 0 }); // the line ends now and stays in the journal
|
|
1772
|
+
* ```
|
|
1773
|
+
*/
|
|
1774
|
+
stop(id: string, options?: {
|
|
1775
|
+
fadeMs?: number;
|
|
1776
|
+
}): void;
|
|
1777
|
+
};
|
|
1778
|
+
/**
|
|
1779
|
+
* Resolved dependency APIs.
|
|
1780
|
+
*/
|
|
1781
|
+
type Deps = {
|
|
1782
|
+
flow: Api;
|
|
1783
|
+
assets: Api$3;
|
|
1784
|
+
model: Api$4;
|
|
1785
|
+
time: Api$5;
|
|
1786
|
+
};
|
|
1787
|
+
/**
|
|
1788
|
+
* What the kernel context offers before the deps are attached.
|
|
1789
|
+
*
|
|
1790
|
+
* `audio` owns no event, so `emit` is the kernel's and never called here.
|
|
1791
|
+
*/
|
|
1792
|
+
type KernelSlice = PluginCtx<Config, State> & {
|
|
1793
|
+
readonly global: object;
|
|
1794
|
+
readonly log: Log.LogApi;
|
|
1795
|
+
readonly require: Require;
|
|
1796
|
+
};
|
|
1797
|
+
/**
|
|
1798
|
+
* Domain context shared by the files of the plugin: the kernel slice plus the resolved deps.
|
|
1799
|
+
*/
|
|
1800
|
+
type AudioCtx = KernelSlice & {
|
|
1801
|
+
readonly deps: Deps;
|
|
1802
|
+
};
|
|
1803
|
+
/**
|
|
1804
|
+
* Payload of the `model:committed` hook: the source of every volume a game sets.
|
|
1805
|
+
*/
|
|
1806
|
+
type ModelCommitted = Events$2["model:committed"];
|
|
1807
|
+
/**
|
|
1808
|
+
* Payload of the `scenes:changed` hook: `music` is the track the next scene declared.
|
|
1809
|
+
*/
|
|
1810
|
+
type SceneChanged = Events$3["scenes:changed"];
|
|
1811
|
+
/**
|
|
1812
|
+
* Payload of the `lifecycle:changed` hook: the pause that holds every bus at zero.
|
|
1813
|
+
*/
|
|
1814
|
+
type LifecycleChanged = Events$4["lifecycle:changed"];
|
|
1815
|
+
/**
|
|
1816
|
+
* Payload of the `assets:bundle-unloaded` hook: `keys` names every decoded sound that is gone.
|
|
1817
|
+
*/
|
|
1818
|
+
type BundleUnloaded = Events["assets:bundle-unloaded"];
|
|
1819
|
+
/**
|
|
1820
|
+
* Payload of the `assets:replaced` hook: `keys` names every asset a dev hot swap gave new bytes.
|
|
1821
|
+
*/
|
|
1822
|
+
type AssetsReplaced = Events["assets:replaced"];
|
|
1823
|
+
/**
|
|
1824
|
+
* What one play of a sound asks for: the key, the bus the sound goes to, the id it plays under
|
|
1825
|
+
* (`undefined`: none), and the fade in milliseconds of the sound with that id it replaces.
|
|
1826
|
+
*/
|
|
1827
|
+
type SfxRequest = {
|
|
1828
|
+
key: string;
|
|
1829
|
+
bus: string;
|
|
1830
|
+
id: string | undefined;
|
|
1831
|
+
fadeMs: number;
|
|
1832
|
+
};
|
|
1833
|
+
/**
|
|
1834
|
+
* What one music switch asks for: the key, or `null` to fade the current track out.
|
|
1835
|
+
*/
|
|
1836
|
+
type MusicRequest = {
|
|
1837
|
+
key: string | null;
|
|
1838
|
+
fadeMs: number;
|
|
1839
|
+
};
|
|
1840
|
+
//#endregion
|
|
1841
|
+
export { EmitterConfig as A, FilterValueOf as B, PixelateValue as C, ShineValue as D, ShadowValue as E, ColorMatrixValue as F, NoiseValue as H, DisplacementValue as I, FilterArea as L, EmitterValue as M, AlphaValue as N, VignetteValue as O, BlurValue as P, FilterComponent as R, MirrorValue as S, RevealRoundValue as T, OutlineValue as U, GlowValue as V, UniformDeclaration as W, DissolveValue as _, MusicOptions as a, GradeValue as b, VolumesFor as c, EffectsApi as d, EffectsStats as f, BloomValue as g, AuraValue as h, MusicDescriptor as i, EmitterDefinition as j, WaveValue as k, types_d_exports as l, types_d_exports$1 as m, AudioContextLike as n, SoundEntry as o, State$1 as p, Config as r, State as s, AudioApi as t, Config$1 as u, FlashValue as v, RevealLineValue as w, GradientMapValue as x, FoldValue as y, FilterSpec as z };
|