laymur 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -4
- package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +14 -3
- package/dist/core/constraints/UIAspectConstraint/UIAspectConstraint.js +38 -5
- package/dist/core/constraints/UICustomConstraint.js +1 -1
- package/dist/core/constraints/UIHeightConstraint/UIHeightConstraint.js +1 -1
- package/dist/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.js +1 -1
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +1 -1
- package/dist/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.js +1 -1
- package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +6 -0
- package/dist/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.js +8 -0
- package/dist/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.js +1 -1
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +1 -1
- package/dist/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.js +1 -1
- package/dist/core/constraints/UIWidthConstraint/UIWidthConstraint.js +1 -1
- package/dist/core/elements/UICanvasElement/UICanvasElement.d.ts +54 -0
- package/dist/core/elements/UICanvasElement/UICanvasElement.js +70 -0
- package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +2 -0
- package/dist/core/elements/UIDummy/UIDummy.js +3 -1
- package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +42 -2
- package/dist/core/elements/UIGraphics/UIGraphics.Internal.js +2 -2
- package/dist/core/elements/UIGraphics/UIGraphics.d.ts +48 -34
- package/dist/core/elements/UIGraphics/UIGraphics.js +196 -93
- package/dist/core/elements/UIImage/UIImage.d.ts +11 -1
- package/dist/core/elements/UIImage/UIImage.js +14 -0
- package/dist/core/elements/UIScene/UIScene.Internal.d.ts +10 -1
- package/dist/core/elements/UIScene/UIScene.Internal.js +1 -0
- package/dist/core/elements/UIScene/UIScene.d.ts +11 -1
- package/dist/core/elements/UIScene/UIScene.js +29 -5
- package/dist/core/elements/UIText/UIText.Interfaces.d.ts +2 -2
- package/dist/core/elements/UIText/UIText.Internal.d.ts +14 -1
- package/dist/core/elements/UIText/UIText.Internal.js +12 -0
- package/dist/core/elements/UIText/UIText.Measuring.d.ts +9 -4
- package/dist/core/elements/UIText/UIText.Measuring.js +17 -6
- package/dist/core/elements/UIText/UIText.Rendering.d.ts +7 -16
- package/dist/core/elements/UIText/UIText.Rendering.js +212 -46
- package/dist/core/elements/UIText/UIText.d.ts +58 -28
- package/dist/core/elements/UIText/UIText.js +113 -138
- package/dist/core/index.d.ts +10 -4
- package/dist/core/index.js +5 -1
- package/dist/core/layers/UILayer/UILayer.d.ts +17 -3
- package/dist/core/layers/UILayer/UILayer.js +35 -4
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +2 -0
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +3 -0
- package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.d.ts +46 -0
- package/dist/core/miscellaneous/canvas-surface/UICanvasSurface.js +86 -0
- package/dist/core/miscellaneous/color/UIColor.d.ts +17 -0
- package/dist/core/miscellaneous/color/UIColor.js +22 -0
- package/dist/core/miscellaneous/color/canvasColor.d.ts +9 -0
- package/dist/core/miscellaneous/color/canvasColor.js +15 -0
- package/dist/core/miscellaneous/insets/UIInsets.d.ts +3 -0
- package/dist/core/miscellaneous/insets/UIInsets.js +15 -0
- package/dist/core/miscellaneous/paint/UIGradient.Internal.d.ts +37 -0
- package/dist/core/miscellaneous/paint/UIGradient.Internal.js +14 -0
- package/dist/core/miscellaneous/paint/UIGradient.d.ts +18 -0
- package/dist/core/miscellaneous/paint/UIGradient.js +35 -0
- package/dist/core/miscellaneous/paint/UILinearGradient.d.ts +14 -0
- package/dist/core/miscellaneous/paint/UILinearGradient.js +22 -0
- package/dist/core/miscellaneous/paint/UIPaint.Internal.d.ts +21 -0
- package/dist/core/miscellaneous/paint/UIPaint.Internal.js +1 -0
- package/dist/core/miscellaneous/paint/UIPaint.d.ts +17 -0
- package/dist/core/miscellaneous/paint/UIPaint.js +21 -0
- package/dist/core/miscellaneous/paint/UIRadialGradient.d.ts +18 -0
- package/dist/core/miscellaneous/paint/UIRadialGradient.js +33 -0
- package/dist/core/miscellaneous/shared.d.ts +14 -0
- package/dist/core/miscellaneous/shared.js +11 -0
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.d.ts +88 -30
- package/dist/core/miscellaneous/text-style/UITextStyle.Internal.js +12 -8
- package/dist/core/miscellaneous/text-style/UITextStyle.d.ts +41 -66
- package/dist/core/miscellaneous/text-style/UITextStyle.js +165 -294
- package/dist/core/miscellaneous/texture/UITextureView.Internal.d.ts +2 -1
- package/dist/core/miscellaneous/texture/UITextureView.Internal.js +12 -3
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +1 -1
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +1 -1
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +1 -1
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +6 -2
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +41 -9
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +97 -35
- package/dist/particles/elements/UIEmitter.Internal.d.ts +3 -0
- package/dist/particles/elements/UIEmitter.Internal.js +1 -0
- package/dist/particles/elements/UIEmitter.js +3 -2
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { UIConstraint } from "../../constraints/UIConstraint.js";
|
|
1
2
|
import { UIExpression } from "../../miscellaneous/UIExpression.js";
|
|
2
3
|
import { UIPriority } from "../../miscellaneous/UIPriority.js";
|
|
3
4
|
import { UIRelation } from "../../miscellaneous/UIRelation.js";
|
|
@@ -15,7 +16,7 @@ import type { UISolverWrapperView } from "./UISolverWrapper.Internal.js";
|
|
|
15
16
|
* - Index-based variable and constraint management
|
|
16
17
|
* - Required variables with P0 priority (always satisfied)
|
|
17
18
|
* - Dynamic constraint modification without full rebuilds
|
|
18
|
-
* - Automatic solver recovery on constraint conflicts
|
|
19
|
+
* - Automatic solver recovery on constraint conflicts, with rejected constraints reported
|
|
19
20
|
* - Lazy evaluation with recalculation flags
|
|
20
21
|
*
|
|
21
22
|
* @see {@link UIExpression} - Expression system for constraint definitions
|
|
@@ -23,6 +24,7 @@ import type { UISolverWrapperView } from "./UISolverWrapper.Internal.js";
|
|
|
23
24
|
* @see {@link UIRelation} - Relational operators for constraints
|
|
24
25
|
*/
|
|
25
26
|
export declare class UISolverWrapper implements UISolverWrapperView {
|
|
27
|
+
private readonly onConstraintsRejected;
|
|
26
28
|
private versionInternal;
|
|
27
29
|
/** The underlying Kiwi solver instance, undefined when solver needs rebuilding. */
|
|
28
30
|
private solver?;
|
|
@@ -36,7 +38,22 @@ export declare class UISolverWrapper implements UISolverWrapperView {
|
|
|
36
38
|
private readonly constraints;
|
|
37
39
|
/** Counter for generating unique constraint indices. */
|
|
38
40
|
private lastConstraintIndex;
|
|
39
|
-
/**
|
|
41
|
+
/** Enabled constraints the last rebuild could not add, see isConstraintApplied */
|
|
42
|
+
private readonly rejectedConstraints;
|
|
43
|
+
/**
|
|
44
|
+
* Bumped by the changes that can resolve a conflict of required constraints: any change of a
|
|
45
|
+
* constraint and of a required variable. Suggested values of other variables are not required
|
|
46
|
+
* and cannot.
|
|
47
|
+
*/
|
|
48
|
+
private structureVersion;
|
|
49
|
+
/** Structure version as of the last rebuild */
|
|
50
|
+
private rebuiltStructureVersion;
|
|
51
|
+
/**
|
|
52
|
+
* @param onConstraintsRejected - Called after a rebuild with the constraints it newly found in
|
|
53
|
+
* conflict with required constraints. The solver is complete by then, so it may throw.
|
|
54
|
+
*/
|
|
55
|
+
constructor(onConstraintsRejected: (constraints: readonly UIConstraint[]) => void);
|
|
56
|
+
/** Bumped by every change to the variables or constraints, to compare with a value seen before */
|
|
40
57
|
get version(): number;
|
|
41
58
|
/**
|
|
42
59
|
* Creates a new solver variable with the specified value and priority.
|
|
@@ -102,6 +119,16 @@ export declare class UISolverWrapper implements UISolverWrapperView {
|
|
|
102
119
|
* @throws Will throw an error if the variable doesn't exist
|
|
103
120
|
*/
|
|
104
121
|
readVariableValue(index: number): number;
|
|
122
|
+
/**
|
|
123
|
+
* Whether the solver applies a constraint, that is, it is enabled and not rejected. A required
|
|
124
|
+
* constraint that conflicts with other required ones is rejected, the later created of them.
|
|
125
|
+
* Rejected constraints are tried again after any change of a constraint or a required variable.
|
|
126
|
+
*
|
|
127
|
+
* @param index - Index of the constraint
|
|
128
|
+
* @returns True if the constraint takes part in solving
|
|
129
|
+
* @throws Will throw an error if the constraint doesn't exist
|
|
130
|
+
*/
|
|
131
|
+
isConstraintApplied(index: number): boolean;
|
|
105
132
|
/**
|
|
106
133
|
* Creates a new constraint between two expressions.
|
|
107
134
|
*
|
|
@@ -113,9 +140,10 @@ export declare class UISolverWrapper implements UISolverWrapperView {
|
|
|
113
140
|
* @param relation - Relational operator (equal, less than, greater than)
|
|
114
141
|
* @param priority - Priority level for constraint solving
|
|
115
142
|
* @param enabled - Whether the constraint is initially active
|
|
143
|
+
* @param owner - Constraint the solver constraint belongs to, named when it is rejected
|
|
116
144
|
* @returns Unique index identifier for the created constraint
|
|
117
145
|
*/
|
|
118
|
-
createConstraint(lhs: UIExpression, rhs: UIExpression, relation: UIRelation, priority: UIPriority, enabled: boolean): number;
|
|
146
|
+
createConstraint(lhs: UIExpression, rhs: UIExpression, relation: UIRelation, priority: UIPriority, enabled: boolean, owner: UIConstraint): number;
|
|
119
147
|
/**
|
|
120
148
|
* Removes a constraint from the solver system.
|
|
121
149
|
*
|
|
@@ -224,18 +252,22 @@ export declare class UISolverWrapper implements UISolverWrapperView {
|
|
|
224
252
|
* and preserves coefficients and constants.
|
|
225
253
|
*/
|
|
226
254
|
private convertExpression;
|
|
255
|
+
/**
|
|
256
|
+
* Brings the solver up to date. Rebuilds it when it was dropped, or when rejected constraints
|
|
257
|
+
* exist and the structure changed since the last rebuild, so that they are tried again. Then
|
|
258
|
+
* recalculates the variables.
|
|
259
|
+
*/
|
|
260
|
+
private ensureSolved;
|
|
227
261
|
/**
|
|
228
262
|
* Completely rebuilds the solver from scratch.
|
|
229
263
|
*
|
|
230
264
|
* Re-adds all variables and constraints to a fresh solver instance.
|
|
231
265
|
* Used for recovery when the solver enters an invalid state.
|
|
232
266
|
*
|
|
233
|
-
* The solver is normally dropped because
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
* already in. The fresh solver is only published once the replay is complete,
|
|
238
|
-
* so a rejection can never leave a half-built solver in place.
|
|
267
|
+
* The solver is normally dropped because kiwi rejected a constraint, and that constraint is
|
|
268
|
+
* still registered here. Each constraint kiwi refuses on replay is recorded as rejected and
|
|
269
|
+
* skipped, and the rest are added in order of creation. The fresh solver is published once the
|
|
270
|
+
* replay is complete, then the newly rejected constraints are reported.
|
|
239
271
|
*/
|
|
240
272
|
private rebuildSolver;
|
|
241
273
|
}
|
|
@@ -15,7 +15,7 @@ import { convertRelation, UIRelation } from "../../miscellaneous/UIRelation.js";
|
|
|
15
15
|
* - Index-based variable and constraint management
|
|
16
16
|
* - Required variables with P0 priority (always satisfied)
|
|
17
17
|
* - Dynamic constraint modification without full rebuilds
|
|
18
|
-
* - Automatic solver recovery on constraint conflicts
|
|
18
|
+
* - Automatic solver recovery on constraint conflicts, with rejected constraints reported
|
|
19
19
|
* - Lazy evaluation with recalculation flags
|
|
20
20
|
*
|
|
21
21
|
* @see {@link UIExpression} - Expression system for constraint definitions
|
|
@@ -23,7 +23,12 @@ import { convertRelation, UIRelation } from "../../miscellaneous/UIRelation.js";
|
|
|
23
23
|
* @see {@link UIRelation} - Relational operators for constraints
|
|
24
24
|
*/
|
|
25
25
|
export class UISolverWrapper {
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @param onConstraintsRejected - Called after a rebuild with the constraints it newly found in
|
|
28
|
+
* conflict with required constraints. The solver is complete by then, so it may throw.
|
|
29
|
+
*/
|
|
30
|
+
constructor(onConstraintsRejected) {
|
|
31
|
+
this.onConstraintsRejected = onConstraintsRejected;
|
|
27
32
|
this.versionInternal = 0;
|
|
28
33
|
/** The underlying Kiwi solver instance, undefined when solver needs rebuilding. */
|
|
29
34
|
this.solver = new Solver();
|
|
@@ -37,8 +42,18 @@ export class UISolverWrapper {
|
|
|
37
42
|
this.constraints = new Map();
|
|
38
43
|
/** Counter for generating unique constraint indices. */
|
|
39
44
|
this.lastConstraintIndex = 0;
|
|
45
|
+
/** Enabled constraints the last rebuild could not add, see isConstraintApplied */
|
|
46
|
+
this.rejectedConstraints = new Set();
|
|
47
|
+
/**
|
|
48
|
+
* Bumped by the changes that can resolve a conflict of required constraints: any change of a
|
|
49
|
+
* constraint and of a required variable. Suggested values of other variables are not required
|
|
50
|
+
* and cannot.
|
|
51
|
+
*/
|
|
52
|
+
this.structureVersion = 0;
|
|
53
|
+
/** Structure version as of the last rebuild */
|
|
54
|
+
this.rebuiltStructureVersion = -1;
|
|
40
55
|
}
|
|
41
|
-
/** Bumped by every change to the variables or constraints
|
|
56
|
+
/** Bumped by every change to the variables or constraints, to compare with a value seen before */
|
|
42
57
|
get version() {
|
|
43
58
|
return this.versionInternal;
|
|
44
59
|
}
|
|
@@ -78,6 +93,7 @@ export class UISolverWrapper {
|
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
this.recalculationRequired = true;
|
|
96
|
+
this.structureVersion++;
|
|
81
97
|
this.versionInternal++;
|
|
82
98
|
return index;
|
|
83
99
|
}
|
|
@@ -110,6 +126,7 @@ export class UISolverWrapper {
|
|
|
110
126
|
}
|
|
111
127
|
this.variables.delete(index);
|
|
112
128
|
this.recalculationRequired = true;
|
|
129
|
+
this.structureVersion++;
|
|
113
130
|
this.versionInternal++;
|
|
114
131
|
}
|
|
115
132
|
/**
|
|
@@ -146,6 +163,9 @@ export class UISolverWrapper {
|
|
|
146
163
|
this.solver?.suggestValue(description.variable, value);
|
|
147
164
|
}
|
|
148
165
|
this.recalculationRequired = true;
|
|
166
|
+
if (description.constraint) {
|
|
167
|
+
this.structureVersion++;
|
|
168
|
+
}
|
|
149
169
|
this.versionInternal++;
|
|
150
170
|
}
|
|
151
171
|
}
|
|
@@ -199,6 +219,7 @@ export class UISolverWrapper {
|
|
|
199
219
|
this.rebuildVariable(index, description);
|
|
200
220
|
}
|
|
201
221
|
this.recalculationRequired = true;
|
|
222
|
+
this.structureVersion++;
|
|
202
223
|
this.versionInternal++;
|
|
203
224
|
}
|
|
204
225
|
}
|
|
@@ -217,15 +238,26 @@ export class UISolverWrapper {
|
|
|
217
238
|
if (description === undefined) {
|
|
218
239
|
throw new Error(`UISolverWrapper.readVariableValue.index: variable ${index} does not exist; its element may be destroyed`);
|
|
219
240
|
}
|
|
220
|
-
|
|
221
|
-
this.rebuildSolver();
|
|
222
|
-
}
|
|
223
|
-
if (this.recalculationRequired) {
|
|
224
|
-
this.solver?.updateVariables();
|
|
225
|
-
this.recalculationRequired = false;
|
|
226
|
-
}
|
|
241
|
+
this.ensureSolved();
|
|
227
242
|
return description.variable.value();
|
|
228
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Whether the solver applies a constraint, that is, it is enabled and not rejected. A required
|
|
246
|
+
* constraint that conflicts with other required ones is rejected, the later created of them.
|
|
247
|
+
* Rejected constraints are tried again after any change of a constraint or a required variable.
|
|
248
|
+
*
|
|
249
|
+
* @param index - Index of the constraint
|
|
250
|
+
* @returns True if the constraint takes part in solving
|
|
251
|
+
* @throws Will throw an error if the constraint doesn't exist
|
|
252
|
+
*/
|
|
253
|
+
isConstraintApplied(index) {
|
|
254
|
+
const description = this.constraints.get(index);
|
|
255
|
+
if (description === undefined) {
|
|
256
|
+
throw new Error(`UISolverWrapper.isConstraintApplied.index: constraint ${index} does not exist; it may be destroyed`);
|
|
257
|
+
}
|
|
258
|
+
this.ensureSolved();
|
|
259
|
+
return description.enabled && !this.rejectedConstraints.has(index);
|
|
260
|
+
}
|
|
229
261
|
/**
|
|
230
262
|
* Creates a new constraint between two expressions.
|
|
231
263
|
*
|
|
@@ -237,9 +269,10 @@ export class UISolverWrapper {
|
|
|
237
269
|
* @param relation - Relational operator (equal, less than, greater than)
|
|
238
270
|
* @param priority - Priority level for constraint solving
|
|
239
271
|
* @param enabled - Whether the constraint is initially active
|
|
272
|
+
* @param owner - Constraint the solver constraint belongs to, named when it is rejected
|
|
240
273
|
* @returns Unique index identifier for the created constraint
|
|
241
274
|
*/
|
|
242
|
-
createConstraint(lhs, rhs, relation, priority, enabled) {
|
|
275
|
+
createConstraint(lhs, rhs, relation, priority, enabled, owner) {
|
|
243
276
|
const index = this.lastConstraintIndex++;
|
|
244
277
|
const constraint = this.buildConstraint(lhs, rhs, relation, priority);
|
|
245
278
|
this.constraints.set(index, {
|
|
@@ -249,6 +282,7 @@ export class UISolverWrapper {
|
|
|
249
282
|
priority,
|
|
250
283
|
relation,
|
|
251
284
|
enabled,
|
|
285
|
+
owner,
|
|
252
286
|
});
|
|
253
287
|
if (enabled) {
|
|
254
288
|
try {
|
|
@@ -258,6 +292,7 @@ export class UISolverWrapper {
|
|
|
258
292
|
this.solver = undefined;
|
|
259
293
|
}
|
|
260
294
|
this.recalculationRequired = true;
|
|
295
|
+
this.structureVersion++;
|
|
261
296
|
this.versionInternal++;
|
|
262
297
|
}
|
|
263
298
|
return index;
|
|
@@ -276,7 +311,7 @@ export class UISolverWrapper {
|
|
|
276
311
|
if (description === undefined) {
|
|
277
312
|
throw new Error(`UISolverWrapper.removeConstraint.index: constraint ${index} does not exist; it may be destroyed`);
|
|
278
313
|
}
|
|
279
|
-
if (description.enabled) {
|
|
314
|
+
if (description.enabled && !this.rejectedConstraints.has(index)) {
|
|
280
315
|
try {
|
|
281
316
|
this.solver?.removeConstraint(description.constraint);
|
|
282
317
|
}
|
|
@@ -285,7 +320,9 @@ export class UISolverWrapper {
|
|
|
285
320
|
}
|
|
286
321
|
}
|
|
287
322
|
this.constraints.delete(index);
|
|
323
|
+
this.rejectedConstraints.delete(index);
|
|
288
324
|
this.recalculationRequired = true;
|
|
325
|
+
this.structureVersion++;
|
|
289
326
|
this.versionInternal++;
|
|
290
327
|
}
|
|
291
328
|
/**
|
|
@@ -321,6 +358,7 @@ export class UISolverWrapper {
|
|
|
321
358
|
description.lhs.copy(lhs);
|
|
322
359
|
this.rebuildConstraintByDescription(description);
|
|
323
360
|
this.recalculationRequired = true;
|
|
361
|
+
this.structureVersion++;
|
|
324
362
|
this.versionInternal++;
|
|
325
363
|
}
|
|
326
364
|
/**
|
|
@@ -341,6 +379,7 @@ export class UISolverWrapper {
|
|
|
341
379
|
description.rhs.copy(rhs);
|
|
342
380
|
this.rebuildConstraintByDescription(description);
|
|
343
381
|
this.recalculationRequired = true;
|
|
382
|
+
this.structureVersion++;
|
|
344
383
|
this.versionInternal++;
|
|
345
384
|
}
|
|
346
385
|
/**
|
|
@@ -362,6 +401,7 @@ export class UISolverWrapper {
|
|
|
362
401
|
description.relation = relation;
|
|
363
402
|
this.rebuildConstraintByDescription(description);
|
|
364
403
|
this.recalculationRequired = true;
|
|
404
|
+
this.structureVersion++;
|
|
365
405
|
this.versionInternal++;
|
|
366
406
|
}
|
|
367
407
|
}
|
|
@@ -384,6 +424,7 @@ export class UISolverWrapper {
|
|
|
384
424
|
description.priority = priority;
|
|
385
425
|
this.rebuildConstraintByDescription(description);
|
|
386
426
|
this.recalculationRequired = true;
|
|
427
|
+
this.structureVersion++;
|
|
387
428
|
this.versionInternal++;
|
|
388
429
|
}
|
|
389
430
|
}
|
|
@@ -413,6 +454,7 @@ export class UISolverWrapper {
|
|
|
413
454
|
this.solver = undefined;
|
|
414
455
|
}
|
|
415
456
|
this.recalculationRequired = true;
|
|
457
|
+
this.structureVersion++;
|
|
416
458
|
this.versionInternal++;
|
|
417
459
|
}
|
|
418
460
|
}
|
|
@@ -515,18 +557,32 @@ export class UISolverWrapper {
|
|
|
515
557
|
return [coefficient, description.variable];
|
|
516
558
|
}), expression.constant);
|
|
517
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Brings the solver up to date. Rebuilds it when it was dropped, or when rejected constraints
|
|
562
|
+
* exist and the structure changed since the last rebuild, so that they are tried again. Then
|
|
563
|
+
* recalculates the variables.
|
|
564
|
+
*/
|
|
565
|
+
ensureSolved() {
|
|
566
|
+
if (this.solver === undefined ||
|
|
567
|
+
(this.rejectedConstraints.size > 0 && this.rebuiltStructureVersion !== this.structureVersion)) {
|
|
568
|
+
this.solver = undefined;
|
|
569
|
+
this.rebuildSolver();
|
|
570
|
+
}
|
|
571
|
+
if (this.recalculationRequired) {
|
|
572
|
+
this.solver?.updateVariables();
|
|
573
|
+
this.recalculationRequired = false;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
518
576
|
/**
|
|
519
577
|
* Completely rebuilds the solver from scratch.
|
|
520
578
|
*
|
|
521
579
|
* Re-adds all variables and constraints to a fresh solver instance.
|
|
522
580
|
* Used for recovery when the solver enters an invalid state.
|
|
523
581
|
*
|
|
524
|
-
* The solver is normally dropped because
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
* already in. The fresh solver is only published once the replay is complete,
|
|
529
|
-
* so a rejection can never leave a half-built solver in place.
|
|
582
|
+
* The solver is normally dropped because kiwi rejected a constraint, and that constraint is
|
|
583
|
+
* still registered here. Each constraint kiwi refuses on replay is recorded as rejected and
|
|
584
|
+
* skipped, and the rest are added in order of creation. The fresh solver is published once the
|
|
585
|
+
* replay is complete, then the newly rejected constraints are reported.
|
|
530
586
|
*/
|
|
531
587
|
rebuildSolver() {
|
|
532
588
|
if (this.solver) {
|
|
@@ -534,31 +590,37 @@ export class UISolverWrapper {
|
|
|
534
590
|
}
|
|
535
591
|
const solver = new Solver();
|
|
536
592
|
for (const description of this.variables.values()) {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
solver.addConstraint(description.constraint);
|
|
540
|
-
}
|
|
541
|
-
else {
|
|
542
|
-
solver.addEditVariable(description.variable, convertPriority(description.priority));
|
|
543
|
-
solver.suggestValue(description.variable, description.value);
|
|
544
|
-
}
|
|
593
|
+
if (description.constraint) {
|
|
594
|
+
solver.addConstraint(description.constraint);
|
|
545
595
|
}
|
|
546
|
-
|
|
547
|
-
|
|
596
|
+
else {
|
|
597
|
+
solver.addEditVariable(description.variable, convertPriority(description.priority));
|
|
598
|
+
solver.suggestValue(description.variable, description.value);
|
|
548
599
|
}
|
|
549
600
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
601
|
+
const newlyRejected = [];
|
|
602
|
+
for (const [index, description] of this.constraints) {
|
|
603
|
+
if (!description.enabled) {
|
|
604
|
+
this.rejectedConstraints.delete(index);
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
try {
|
|
608
|
+
solver.addConstraint(description.constraint);
|
|
609
|
+
this.rejectedConstraints.delete(index);
|
|
610
|
+
}
|
|
611
|
+
catch {
|
|
612
|
+
if (!this.rejectedConstraints.has(index)) {
|
|
613
|
+
this.rejectedConstraints.add(index);
|
|
614
|
+
newlyRejected.push(description.owner);
|
|
557
615
|
}
|
|
558
616
|
}
|
|
559
617
|
}
|
|
560
618
|
this.solver = solver;
|
|
561
619
|
this.recalculationRequired = true;
|
|
562
620
|
this.versionInternal++;
|
|
621
|
+
this.rebuiltStructureVersion = this.structureVersion;
|
|
622
|
+
if (newlyRejected.length > 0) {
|
|
623
|
+
this.onConstraintsRejected(newlyRejected);
|
|
624
|
+
}
|
|
563
625
|
}
|
|
564
626
|
}
|
|
@@ -13,6 +13,8 @@ export interface UIEmitterOptions extends UIAnchorOptions {
|
|
|
13
13
|
mode: UIEmitterMode;
|
|
14
14
|
/** Color blending of the particles with what is drawn under them */
|
|
15
15
|
blendMode: UIBlendMode;
|
|
16
|
+
/** Rendering order among the elements of the layer, see UIEmitter.zIndex */
|
|
17
|
+
zIndex: number;
|
|
16
18
|
/**
|
|
17
19
|
* Coordinate space of particle positions, and of the points behavior modules take, such as a
|
|
18
20
|
* gravity center. Spawn modules always write positions relative to the emitter.
|
|
@@ -58,6 +60,7 @@ export declare function ignoreInput(): boolean;
|
|
|
58
60
|
export type UIEmitterMode = UIMode.HIDDEN | UIMode.VISIBLE;
|
|
59
61
|
export declare const EMITTER_DEFAULT_MODE: UIEmitterMode;
|
|
60
62
|
export declare const EMITTER_DEFAULT_BLEND_MODE = UIBlendMode.NORMAL;
|
|
63
|
+
export declare const EMITTER_DEFAULT_Z_INDEX = 0;
|
|
61
64
|
export declare const EMITTER_DEFAULT_SPACE = UIEmitterSpace.LOCAL;
|
|
62
65
|
export declare const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
|
|
63
66
|
export declare const EMITTER_DEFAULT_CAPACITY_STEP = 32;
|
|
@@ -13,6 +13,7 @@ export function ignoreInput() {
|
|
|
13
13
|
}
|
|
14
14
|
export const EMITTER_DEFAULT_MODE = UIMode.VISIBLE;
|
|
15
15
|
export const EMITTER_DEFAULT_BLEND_MODE = UIBlendMode.NORMAL;
|
|
16
|
+
export const EMITTER_DEFAULT_Z_INDEX = 0;
|
|
16
17
|
export const EMITTER_DEFAULT_SPACE = UIEmitterSpace.LOCAL;
|
|
17
18
|
export const EMITTER_DEFAULT_EXPECTED_CAPACITY = 32;
|
|
18
19
|
export const EMITTER_DEFAULT_CAPACITY_STEP = 32;
|
|
@@ -8,7 +8,7 @@ import { isUIModeVisible } from "../../core/miscellaneous/UIMode.js";
|
|
|
8
8
|
import { assignRenderingRandomValues, collectProperties, collectRenderingUniforms, } from "../instancedParticle/UIInstancedParticle.Internal.js";
|
|
9
9
|
import { UIInstancedParticle } from "../instancedParticle/UIInstancedParticle.js";
|
|
10
10
|
import { assertValidNonNegativeInteger, BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME, BUILTIN_OFFSET_POSITION_X, BUILTIN_OFFSET_POSITION_Y, BUILTIN_OFFSET_RANDOM_A, BUILTIN_OFFSET_RANDOM_B, BUILTIN_OFFSET_RANDOM_C, BUILTIN_OFFSET_RANDOM_D, BUILTIN_OFFSET_RANDOM_E, BUILTIN_OFFSET_SCALE_X, BUILTIN_OFFSET_SCALE_Y, computeParticleSeed, particleRandom, particleRandomStream, writeParticleSeed, } from "../miscellaneous/miscellaneous.js";
|
|
11
|
-
import { advanceParticle, EMITTER_BEHAVIOR_SALT_BASE, EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES, EMITTER_DEFAULT_BLEND_MODE, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_LIFETIME, EMITTER_DEFAULT_MAX_DELTA_TIME, EMITTER_DEFAULT_MODE, EMITTER_DEFAULT_PREWARM_STEP, EMITTER_DEFAULT_SPACE, EMITTER_SHADER_SALT, EMITTER_SPAWN_SALT_BASE, ignoreInput, UIEmitterSpace, } from "./UIEmitter.Internal.js";
|
|
11
|
+
import { advanceParticle, EMITTER_BEHAVIOR_SALT_BASE, EMITTER_DEFAULT_AUTOMATICALLY_DESTROY_MODULES, EMITTER_DEFAULT_BLEND_MODE, EMITTER_DEFAULT_CAPACITY_STEP, EMITTER_DEFAULT_EXPECTED_CAPACITY, EMITTER_DEFAULT_LIFETIME, EMITTER_DEFAULT_MAX_DELTA_TIME, EMITTER_DEFAULT_MODE, EMITTER_DEFAULT_PREWARM_STEP, EMITTER_DEFAULT_SPACE, EMITTER_DEFAULT_Z_INDEX, EMITTER_SHADER_SALT, EMITTER_SPAWN_SALT_BASE, ignoreInput, UIEmitterSpace, } from "./UIEmitter.Internal.js";
|
|
12
12
|
import { UIEmissionSchedule } from "./UIEmitter.Schedule.js";
|
|
13
13
|
/** Builtin slots of the random values the shaders read, each with its stream */
|
|
14
14
|
const SHADER_RANDOM_SLOTS = [
|
|
@@ -93,7 +93,8 @@ export class UIEmitter extends UIAnchor {
|
|
|
93
93
|
},
|
|
94
94
|
};
|
|
95
95
|
const renderingSources = assignRenderingRandomValues(collectRenderingUniforms(collectedUniforms, renderingSequence, "UIEmitter.constructor.renderingSequence"), "UIEmitter.constructor.renderingSequence");
|
|
96
|
-
const zIndex =
|
|
96
|
+
const zIndex = options.zIndex ?? EMITTER_DEFAULT_Z_INDEX;
|
|
97
|
+
assertValidNumber(zIndex, "UIEmitter.constructor.options.zIndex");
|
|
97
98
|
this.catcherHandler = this.layer.inputWrapper.createInputCatcher({
|
|
98
99
|
catchPointerDown: ignoreInput,
|
|
99
100
|
catchPointerMove: ignoreInput,
|