@lightningjs/renderer 0.7.2 → 0.7.3
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/COPYING +1 -0
- package/LICENSE +202 -202
- package/NOTICE +3 -3
- package/README.md +221 -221
- package/dist/src/common/CommonTypes.d.ts +7 -0
- package/dist/src/core/Stage.d.ts +2 -1
- package/dist/src/core/Stage.js +4 -0
- package/dist/src/core/Stage.js.map +1 -1
- package/dist/src/core/animations/CoreAnimation.js +3 -0
- package/dist/src/core/animations/CoreAnimation.js.map +1 -1
- package/dist/src/core/animations/CoreAnimationController.d.ts +8 -0
- package/dist/src/core/animations/CoreAnimationController.js +26 -0
- package/dist/src/core/animations/CoreAnimationController.js.map +1 -1
- package/dist/src/core/lib/ImageWorker.js +21 -21
- package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +47 -47
- package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +61 -61
- package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +93 -93
- package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +63 -63
- package/dist/src/core/renderers/webgl/shaders/SdfShader.js +49 -49
- package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +5 -5
- package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +15 -15
- package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +42 -42
- package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +44 -44
- package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +3 -3
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +31 -31
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +13 -13
- package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +37 -37
- package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +19 -19
- package/dist/src/main-api/ICoreDriver.d.ts +2 -1
- package/dist/src/main-api/Inspector.d.ts +6 -0
- package/dist/src/main-api/Inspector.js +105 -19
- package/dist/src/main-api/Inspector.js.map +1 -1
- package/dist/src/main-api/RendererMain.d.ts +12 -0
- package/dist/src/main-api/RendererMain.js +19 -1
- package/dist/src/main-api/RendererMain.js.map +1 -1
- package/dist/src/render-drivers/main/MainCoreDriver.d.ts +2 -1
- package/dist/src/render-drivers/main/MainCoreDriver.js +7 -1
- package/dist/src/render-drivers/main/MainCoreDriver.js.map +1 -1
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.d.ts +2 -1
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js +7 -0
- package/dist/src/render-drivers/threadx/ThreadXCoreDriver.js.map +1 -1
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.d.ts +9 -1
- package/dist/src/render-drivers/threadx/ThreadXRendererMessage.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/exports/core-api.ts +102 -102
- package/exports/main-api.ts +60 -60
- package/exports/utils.ts +41 -41
- package/package.json +5 -3
- package/scripts/please-use-pnpm.js +13 -0
- package/src/common/CommonTypes.ts +113 -105
- package/src/common/EventEmitter.ts +77 -77
- package/src/common/IAnimationController.ts +29 -29
- package/src/core/CoreExtension.ts +32 -32
- package/src/core/CoreNode.ts +926 -926
- package/src/core/CoreShaderManager.ts +243 -243
- package/src/core/CoreTextNode.ts +391 -391
- package/src/core/CoreTextureManager.ts +326 -326
- package/src/core/Stage.ts +354 -342
- package/src/core/animations/AnimationManager.ts +38 -38
- package/src/core/animations/CoreAnimation.ts +181 -177
- package/src/core/animations/CoreAnimationController.ts +148 -117
- package/src/core/lib/ContextSpy.ts +41 -41
- package/src/core/lib/ImageWorker.ts +124 -124
- package/src/core/lib/Matrix3d.ts +290 -290
- package/src/core/lib/WebGlContextWrapper.ts +992 -992
- package/src/core/lib/textureCompression.ts +152 -152
- package/src/core/lib/utils.ts +241 -241
- package/src/core/platform.ts +46 -46
- package/src/core/renderers/CoreContextTexture.ts +30 -30
- package/src/core/renderers/CoreRenderOp.ts +22 -22
- package/src/core/renderers/CoreRenderer.ts +63 -63
- package/src/core/renderers/CoreShader.ts +41 -41
- package/src/core/renderers/webgl/WebGlCoreCtxSubTexture.ts +37 -37
- package/src/core/renderers/webgl/WebGlCoreCtxTexture.ts +231 -231
- package/src/core/renderers/webgl/WebGlCoreRenderOp.ts +107 -107
- package/src/core/renderers/webgl/WebGlCoreRenderer.ts +520 -520
- package/src/core/renderers/webgl/WebGlCoreShader.ts +337 -337
- package/src/core/renderers/webgl/internal/BufferCollection.ts +54 -54
- package/src/core/renderers/webgl/internal/RendererUtils.ts +131 -131
- package/src/core/renderers/webgl/internal/ShaderUtils.ts +136 -136
- package/src/core/renderers/webgl/internal/WebGlUtils.ts +35 -35
- package/src/core/renderers/webgl/shaders/DefaultShader.ts +95 -95
- package/src/core/renderers/webgl/shaders/DefaultShaderBatched.ts +132 -132
- package/src/core/renderers/webgl/shaders/DynamicShader.ts +474 -474
- package/src/core/renderers/webgl/shaders/RoundedRectangle.ts +161 -161
- package/src/core/renderers/webgl/shaders/SdfShader.ts +174 -174
- package/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.ts +101 -101
- package/src/core/renderers/webgl/shaders/effects/BorderEffect.ts +86 -86
- package/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.ts +101 -101
- package/src/core/renderers/webgl/shaders/effects/BorderRightEffect.ts +101 -101
- package/src/core/renderers/webgl/shaders/effects/BorderTopEffect.ts +101 -101
- package/src/core/renderers/webgl/shaders/effects/EffectUtils.ts +33 -33
- package/src/core/renderers/webgl/shaders/effects/FadeOutEffect.ts +135 -135
- package/src/core/renderers/webgl/shaders/effects/GlitchEffect.ts +145 -145
- package/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.ts +67 -67
- package/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.ts +176 -176
- package/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.ts +159 -159
- package/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.ts +186 -186
- package/src/core/renderers/webgl/shaders/effects/RadiusEffect.ts +121 -121
- package/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts +114 -114
- package/src/core/text-rendering/TextTextureRendererUtils.ts +189 -189
- package/src/core/text-rendering/TrFontManager.ts +96 -96
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +141 -141
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.ts +139 -139
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.test.ts +173 -173
- package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.ts +169 -169
- package/src/core/text-rendering/font-face-types/TrFontFace.ts +105 -105
- package/src/core/text-rendering/font-face-types/WebTrFontFace.ts +77 -77
- package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +751 -751
- package/src/core/text-rendering/renderers/LightningTextTextureRenderer.ts +741 -741
- package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +775 -775
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.test.ts +48 -48
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.ts +66 -66
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.ts +52 -52
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.ts +32 -32
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.ts +84 -84
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.test.ts +133 -133
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.ts +38 -38
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.ts +393 -393
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.test.ts +49 -49
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.ts +51 -51
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.test.ts +205 -205
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.ts +93 -93
- package/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.ts +40 -40
- package/src/core/text-rendering/renderers/TextRenderer.ts +504 -504
- package/src/core/textures/ColorTexture.ts +86 -86
- package/src/core/textures/ImageTexture.ts +133 -133
- package/src/core/textures/NoiseTexture.ts +96 -96
- package/src/core/textures/SubTexture.ts +143 -143
- package/src/core/textures/Texture.ts +218 -218
- package/src/core/utils.ts +224 -224
- package/src/env.d.ts +7 -7
- package/src/main-api/ICoreDriver.ts +66 -61
- package/src/main-api/INode.ts +470 -470
- package/src/main-api/Inspector.ts +432 -0
- package/src/main-api/RendererMain.ts +649 -610
- package/src/main-api/texture-usage-trackers/FinalizationRegistryTextureUsageTracker.ts +45 -45
- package/src/main-api/texture-usage-trackers/ManualCountTextureUsageTracker.ts +154 -154
- package/src/main-api/texture-usage-trackers/TextureUsageTracker.ts +54 -54
- package/src/render-drivers/main/MainCoreDriver.ts +148 -133
- package/src/render-drivers/main/MainOnlyNode.ts +453 -453
- package/src/render-drivers/main/MainOnlyTextNode.ts +261 -261
- package/src/render-drivers/threadx/NodeStruct.ts +300 -300
- package/src/render-drivers/threadx/SharedNode.ts +97 -97
- package/src/render-drivers/threadx/TextNodeStruct.ts +211 -211
- package/src/render-drivers/threadx/ThreadXCoreDriver.ts +285 -273
- package/src/render-drivers/threadx/ThreadXMainAnimationController.ts +99 -99
- package/src/render-drivers/threadx/ThreadXMainNode.ts +178 -178
- package/src/render-drivers/threadx/ThreadXMainTextNode.ts +85 -85
- package/src/render-drivers/threadx/ThreadXRendererMessage.ts +110 -97
- package/src/render-drivers/threadx/worker/ThreadXRendererNode.ts +238 -238
- package/src/render-drivers/threadx/worker/ThreadXRendererTextNode.ts +149 -149
- package/src/render-drivers/threadx/worker/renderer.ts +151 -151
- package/src/render-drivers/utils.ts +57 -57
- package/src/utils.ts +207 -207
- package/dist/src/core/lib/WebGlContext.d.ts +0 -414
- package/dist/src/core/lib/WebGlContext.js +0 -640
- package/dist/src/core/lib/WebGlContext.js.map +0 -1
- package/dist/src/core/scene/Scene.d.ts +0 -59
- package/dist/src/core/scene/Scene.js +0 -106
- package/dist/src/core/scene/Scene.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/findNearestMultiple.d.ts +0 -8
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/findNearestMultiple.js +0 -29
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/findNearestMultiple.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/SdfBufferHelper.d.ts +0 -19
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/SdfBufferHelper.js +0 -84
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/SdfBufferHelper.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutLine.d.ts +0 -8
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutLine.js +0 -40
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutLine.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutText2.d.ts +0 -2
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutText2.js +0 -41
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/layoutText2.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/utils.d.ts +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/utils.js +0 -4
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2/utils.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2.d.ts +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2.js +0 -2
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText2.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.d.ts +0 -20
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js +0 -55
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/makeRenderWindow.js.map +0 -1
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/roundUpToMultiple.d.ts +0 -9
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/roundUpToMultiple.js +0 -32
- package/dist/src/core/text-rendering/renderers/SdfTextRenderer/internal/roundUpToMultiple.js.map +0 -1
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
-
* following copyright and licenses apply:
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/* eslint-disable @typescript-eslint/unbound-method */
|
|
21
|
-
import type {
|
|
22
|
-
AnimationControllerState,
|
|
23
|
-
IAnimationController,
|
|
24
|
-
} from '../../common/IAnimationController.js';
|
|
25
|
-
import { assertTruthy } from '../../utils.js';
|
|
26
|
-
import type { ThreadXMainNode } from './ThreadXMainNode.js';
|
|
27
|
-
|
|
28
|
-
export class ThreadXMainAnimationController implements IAnimationController {
|
|
29
|
-
stoppedPromise: Promise<void> | null = null;
|
|
30
|
-
/**
|
|
31
|
-
* If this is null, then the animation is in a finished / stopped state.
|
|
32
|
-
*/
|
|
33
|
-
stoppedResolve: (() => void) | null = null;
|
|
34
|
-
|
|
35
|
-
constructor(private node: ThreadXMainNode, private id: number) {
|
|
36
|
-
this.onAnimationFinished = this.onAnimationFinished.bind(this);
|
|
37
|
-
this.state = 'stopped';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
state: AnimationControllerState;
|
|
41
|
-
|
|
42
|
-
start(): IAnimationController {
|
|
43
|
-
if (this.stoppedResolve === null) {
|
|
44
|
-
this.makeStoppedPromise();
|
|
45
|
-
this.node.on('animationFinished', this.onAnimationFinished);
|
|
46
|
-
}
|
|
47
|
-
this.state = 'running';
|
|
48
|
-
this.node.emit('startAnimation', { id: this.id });
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
stop(): IAnimationController {
|
|
53
|
-
this.node.emit('stopAnimation', { id: this.id });
|
|
54
|
-
this.node.off('animationFinished', this.onAnimationFinished);
|
|
55
|
-
if (this.stoppedResolve !== null) {
|
|
56
|
-
this.stoppedResolve();
|
|
57
|
-
this.stoppedResolve = null;
|
|
58
|
-
}
|
|
59
|
-
this.state = 'stopped';
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
pause(): IAnimationController {
|
|
64
|
-
this.node.emit('pauseAnimation', { id: this.id });
|
|
65
|
-
this.state = 'paused';
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
restore(): IAnimationController {
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
waitUntilStopped(): Promise<void> {
|
|
74
|
-
this.makeStoppedPromise();
|
|
75
|
-
const promise = this.stoppedPromise;
|
|
76
|
-
assertTruthy(promise);
|
|
77
|
-
return promise;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private onAnimationFinished(
|
|
81
|
-
target: ThreadXMainNode,
|
|
82
|
-
{ id, loop }: { id: number; loop: boolean },
|
|
83
|
-
) {
|
|
84
|
-
if (id === this.id) {
|
|
85
|
-
this.node.off('animationFinished', this.onAnimationFinished);
|
|
86
|
-
this.stoppedResolve?.();
|
|
87
|
-
this.stoppedResolve = null;
|
|
88
|
-
this.state = 'stopped';
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private makeStoppedPromise(): void {
|
|
93
|
-
if (this.stoppedResolve === null) {
|
|
94
|
-
this.stoppedPromise = new Promise((resolve) => {
|
|
95
|
-
this.stoppedResolve = resolve;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
21
|
+
import type {
|
|
22
|
+
AnimationControllerState,
|
|
23
|
+
IAnimationController,
|
|
24
|
+
} from '../../common/IAnimationController.js';
|
|
25
|
+
import { assertTruthy } from '../../utils.js';
|
|
26
|
+
import type { ThreadXMainNode } from './ThreadXMainNode.js';
|
|
27
|
+
|
|
28
|
+
export class ThreadXMainAnimationController implements IAnimationController {
|
|
29
|
+
stoppedPromise: Promise<void> | null = null;
|
|
30
|
+
/**
|
|
31
|
+
* If this is null, then the animation is in a finished / stopped state.
|
|
32
|
+
*/
|
|
33
|
+
stoppedResolve: (() => void) | null = null;
|
|
34
|
+
|
|
35
|
+
constructor(private node: ThreadXMainNode, private id: number) {
|
|
36
|
+
this.onAnimationFinished = this.onAnimationFinished.bind(this);
|
|
37
|
+
this.state = 'stopped';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
state: AnimationControllerState;
|
|
41
|
+
|
|
42
|
+
start(): IAnimationController {
|
|
43
|
+
if (this.stoppedResolve === null) {
|
|
44
|
+
this.makeStoppedPromise();
|
|
45
|
+
this.node.on('animationFinished', this.onAnimationFinished);
|
|
46
|
+
}
|
|
47
|
+
this.state = 'running';
|
|
48
|
+
this.node.emit('startAnimation', { id: this.id });
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
stop(): IAnimationController {
|
|
53
|
+
this.node.emit('stopAnimation', { id: this.id });
|
|
54
|
+
this.node.off('animationFinished', this.onAnimationFinished);
|
|
55
|
+
if (this.stoppedResolve !== null) {
|
|
56
|
+
this.stoppedResolve();
|
|
57
|
+
this.stoppedResolve = null;
|
|
58
|
+
}
|
|
59
|
+
this.state = 'stopped';
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
pause(): IAnimationController {
|
|
64
|
+
this.node.emit('pauseAnimation', { id: this.id });
|
|
65
|
+
this.state = 'paused';
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
restore(): IAnimationController {
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
waitUntilStopped(): Promise<void> {
|
|
74
|
+
this.makeStoppedPromise();
|
|
75
|
+
const promise = this.stoppedPromise;
|
|
76
|
+
assertTruthy(promise);
|
|
77
|
+
return promise;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private onAnimationFinished(
|
|
81
|
+
target: ThreadXMainNode,
|
|
82
|
+
{ id, loop }: { id: number; loop: boolean },
|
|
83
|
+
) {
|
|
84
|
+
if (id === this.id) {
|
|
85
|
+
this.node.off('animationFinished', this.onAnimationFinished);
|
|
86
|
+
this.stoppedResolve?.();
|
|
87
|
+
this.stoppedResolve = null;
|
|
88
|
+
this.state = 'stopped';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private makeStoppedPromise(): void {
|
|
93
|
+
if (this.stoppedResolve === null) {
|
|
94
|
+
this.stoppedPromise = new Promise((resolve) => {
|
|
95
|
+
this.stoppedResolve = resolve;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
-
* following copyright and licenses apply:
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
-
* you may not use this file except in compliance with the License.
|
|
9
|
-
* You may obtain a copy of the License at
|
|
10
|
-
*
|
|
11
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
*
|
|
13
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
* See the License for the specific language governing permissions and
|
|
17
|
-
* limitations under the License.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import type { IAnimationController } from '../../common/IAnimationController.js';
|
|
21
|
-
import type { INode, INodeAnimatableProps } from '../../main-api/INode.js';
|
|
22
|
-
import type {
|
|
23
|
-
RendererMain,
|
|
24
|
-
ShaderRef,
|
|
25
|
-
TextureRef,
|
|
26
|
-
} from '../../main-api/RendererMain.js';
|
|
27
|
-
import { assertTruthy } from '../../utils.js';
|
|
28
|
-
import type { NodeStruct } from './NodeStruct.js';
|
|
29
|
-
import { SharedNode } from './SharedNode.js';
|
|
30
|
-
import { ThreadXMainAnimationController } from './ThreadXMainAnimationController.js';
|
|
31
|
-
import type { AnimationSettings } from '../../core/animations/CoreAnimation.js';
|
|
32
|
-
|
|
33
|
-
export class ThreadXMainNode extends SharedNode implements INode {
|
|
34
|
-
private nextAnimationId = 1;
|
|
35
|
-
protected _parent: ThreadXMainNode | null = null;
|
|
36
|
-
protected _children: ThreadXMainNode[] = [];
|
|
37
|
-
protected _texture: TextureRef | null = null;
|
|
38
|
-
protected _shader: ShaderRef | null = null;
|
|
39
|
-
private _src = '';
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* FinalizationRegistry for animation controllers. When an animation
|
|
43
|
-
* controller is garbage collected, we let the render worker know so that
|
|
44
|
-
* it can remove it's corresponding animation controler from it's stored
|
|
45
|
-
* Set. This should ultimately allow the render worker to garbage collect
|
|
46
|
-
* it's animation controller. The animation itself independent from the animation
|
|
47
|
-
* controller, so it will continue to run until it's finished regardless of
|
|
48
|
-
* whether or not the animation controller is garbage collected.
|
|
49
|
-
*/
|
|
50
|
-
private animationRegistry = new FinalizationRegistry((id: number) => {
|
|
51
|
-
this.emit('destroyAnimation', { id });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
constructor(
|
|
55
|
-
private rendererMain: RendererMain,
|
|
56
|
-
sharedNodeStruct: NodeStruct,
|
|
57
|
-
extendedCurProps?: Record<string, unknown>,
|
|
58
|
-
) {
|
|
59
|
-
super(sharedNodeStruct, extendedCurProps);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get texture(): TextureRef | null {
|
|
63
|
-
return this._texture;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
set texture(texture: TextureRef | null) {
|
|
67
|
-
if (this._texture === texture) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (this._texture) {
|
|
71
|
-
this.rendererMain.textureTracker.decrementTextureRefCount(this._texture);
|
|
72
|
-
}
|
|
73
|
-
if (texture) {
|
|
74
|
-
this.rendererMain.textureTracker.incrementTextureRefCount(texture);
|
|
75
|
-
}
|
|
76
|
-
this._texture = texture;
|
|
77
|
-
if (texture) {
|
|
78
|
-
this.emit('loadTexture', texture as unknown as Record<string, unknown>);
|
|
79
|
-
} else {
|
|
80
|
-
this.emit('unloadTexture', {});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get shader(): ShaderRef | null {
|
|
85
|
-
return this._shader;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
set shader(shader: ShaderRef | null) {
|
|
89
|
-
if (this._shader === shader) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
this._shader = shader;
|
|
93
|
-
if (shader) {
|
|
94
|
-
this.emit('loadShader', shader as unknown as Record<string, unknown>);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get scale(): number | null {
|
|
99
|
-
if (this.scaleX !== this.scaleY) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
return this.scaleX;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
set scale(scale: number | null) {
|
|
106
|
-
// We ignore `null` when it's set.
|
|
107
|
-
if (scale === null) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.scaleX = scale;
|
|
111
|
-
this.scaleY = scale;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
animate(
|
|
115
|
-
props: Partial<INodeAnimatableProps>,
|
|
116
|
-
settings: Partial<AnimationSettings>,
|
|
117
|
-
): IAnimationController {
|
|
118
|
-
const id = this.nextAnimationId++;
|
|
119
|
-
this.emit('createAnimation', { id, props, settings });
|
|
120
|
-
const controller = new ThreadXMainAnimationController(this, id);
|
|
121
|
-
this.animationRegistry.register(controller, id);
|
|
122
|
-
return controller;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
get src(): string {
|
|
126
|
-
return this._src;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
set src(imageUrl: string) {
|
|
130
|
-
if (this._src === imageUrl) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
this._src = imageUrl;
|
|
134
|
-
if (!imageUrl) {
|
|
135
|
-
this.texture = null;
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
this.texture = this.rendererMain.createTexture('ImageTexture', {
|
|
139
|
-
src: imageUrl,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
//#region Parent/Child Props
|
|
144
|
-
get parent(): ThreadXMainNode | null {
|
|
145
|
-
return this._parent;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
set parent(newParent: ThreadXMainNode | null) {
|
|
149
|
-
const oldParent = this._parent;
|
|
150
|
-
this._parent = newParent;
|
|
151
|
-
this.parentId = newParent?.id ?? 0;
|
|
152
|
-
if (oldParent) {
|
|
153
|
-
const index = oldParent.children.indexOf(this);
|
|
154
|
-
assertTruthy(
|
|
155
|
-
index !== -1,
|
|
156
|
-
"ThreadXMainNode.parent: Node not found in old parent's children!",
|
|
157
|
-
);
|
|
158
|
-
oldParent.children.splice(index, 1);
|
|
159
|
-
}
|
|
160
|
-
if (newParent) {
|
|
161
|
-
newParent.children.push(this);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
get children(): ThreadXMainNode[] {
|
|
166
|
-
return this._children;
|
|
167
|
-
}
|
|
168
|
-
//#endregion Parent/Child Props
|
|
169
|
-
|
|
170
|
-
get props() {
|
|
171
|
-
return this.curProps;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
override destroy() {
|
|
175
|
-
super.destroy();
|
|
176
|
-
this.texture = null;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* If not stated otherwise in this file or this component's LICENSE file the
|
|
3
|
+
* following copyright and licenses apply:
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2023 Comcast Cable Communications Management, LLC.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the License);
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { IAnimationController } from '../../common/IAnimationController.js';
|
|
21
|
+
import type { INode, INodeAnimatableProps } from '../../main-api/INode.js';
|
|
22
|
+
import type {
|
|
23
|
+
RendererMain,
|
|
24
|
+
ShaderRef,
|
|
25
|
+
TextureRef,
|
|
26
|
+
} from '../../main-api/RendererMain.js';
|
|
27
|
+
import { assertTruthy } from '../../utils.js';
|
|
28
|
+
import type { NodeStruct } from './NodeStruct.js';
|
|
29
|
+
import { SharedNode } from './SharedNode.js';
|
|
30
|
+
import { ThreadXMainAnimationController } from './ThreadXMainAnimationController.js';
|
|
31
|
+
import type { AnimationSettings } from '../../core/animations/CoreAnimation.js';
|
|
32
|
+
|
|
33
|
+
export class ThreadXMainNode extends SharedNode implements INode {
|
|
34
|
+
private nextAnimationId = 1;
|
|
35
|
+
protected _parent: ThreadXMainNode | null = null;
|
|
36
|
+
protected _children: ThreadXMainNode[] = [];
|
|
37
|
+
protected _texture: TextureRef | null = null;
|
|
38
|
+
protected _shader: ShaderRef | null = null;
|
|
39
|
+
private _src = '';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* FinalizationRegistry for animation controllers. When an animation
|
|
43
|
+
* controller is garbage collected, we let the render worker know so that
|
|
44
|
+
* it can remove it's corresponding animation controler from it's stored
|
|
45
|
+
* Set. This should ultimately allow the render worker to garbage collect
|
|
46
|
+
* it's animation controller. The animation itself independent from the animation
|
|
47
|
+
* controller, so it will continue to run until it's finished regardless of
|
|
48
|
+
* whether or not the animation controller is garbage collected.
|
|
49
|
+
*/
|
|
50
|
+
private animationRegistry = new FinalizationRegistry((id: number) => {
|
|
51
|
+
this.emit('destroyAnimation', { id });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
private rendererMain: RendererMain,
|
|
56
|
+
sharedNodeStruct: NodeStruct,
|
|
57
|
+
extendedCurProps?: Record<string, unknown>,
|
|
58
|
+
) {
|
|
59
|
+
super(sharedNodeStruct, extendedCurProps);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get texture(): TextureRef | null {
|
|
63
|
+
return this._texture;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
set texture(texture: TextureRef | null) {
|
|
67
|
+
if (this._texture === texture) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (this._texture) {
|
|
71
|
+
this.rendererMain.textureTracker.decrementTextureRefCount(this._texture);
|
|
72
|
+
}
|
|
73
|
+
if (texture) {
|
|
74
|
+
this.rendererMain.textureTracker.incrementTextureRefCount(texture);
|
|
75
|
+
}
|
|
76
|
+
this._texture = texture;
|
|
77
|
+
if (texture) {
|
|
78
|
+
this.emit('loadTexture', texture as unknown as Record<string, unknown>);
|
|
79
|
+
} else {
|
|
80
|
+
this.emit('unloadTexture', {});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get shader(): ShaderRef | null {
|
|
85
|
+
return this._shader;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
set shader(shader: ShaderRef | null) {
|
|
89
|
+
if (this._shader === shader) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this._shader = shader;
|
|
93
|
+
if (shader) {
|
|
94
|
+
this.emit('loadShader', shader as unknown as Record<string, unknown>);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get scale(): number | null {
|
|
99
|
+
if (this.scaleX !== this.scaleY) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
return this.scaleX;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
set scale(scale: number | null) {
|
|
106
|
+
// We ignore `null` when it's set.
|
|
107
|
+
if (scale === null) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.scaleX = scale;
|
|
111
|
+
this.scaleY = scale;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
animate(
|
|
115
|
+
props: Partial<INodeAnimatableProps>,
|
|
116
|
+
settings: Partial<AnimationSettings>,
|
|
117
|
+
): IAnimationController {
|
|
118
|
+
const id = this.nextAnimationId++;
|
|
119
|
+
this.emit('createAnimation', { id, props, settings });
|
|
120
|
+
const controller = new ThreadXMainAnimationController(this, id);
|
|
121
|
+
this.animationRegistry.register(controller, id);
|
|
122
|
+
return controller;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get src(): string {
|
|
126
|
+
return this._src;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
set src(imageUrl: string) {
|
|
130
|
+
if (this._src === imageUrl) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this._src = imageUrl;
|
|
134
|
+
if (!imageUrl) {
|
|
135
|
+
this.texture = null;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.texture = this.rendererMain.createTexture('ImageTexture', {
|
|
139
|
+
src: imageUrl,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//#region Parent/Child Props
|
|
144
|
+
get parent(): ThreadXMainNode | null {
|
|
145
|
+
return this._parent;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
set parent(newParent: ThreadXMainNode | null) {
|
|
149
|
+
const oldParent = this._parent;
|
|
150
|
+
this._parent = newParent;
|
|
151
|
+
this.parentId = newParent?.id ?? 0;
|
|
152
|
+
if (oldParent) {
|
|
153
|
+
const index = oldParent.children.indexOf(this);
|
|
154
|
+
assertTruthy(
|
|
155
|
+
index !== -1,
|
|
156
|
+
"ThreadXMainNode.parent: Node not found in old parent's children!",
|
|
157
|
+
);
|
|
158
|
+
oldParent.children.splice(index, 1);
|
|
159
|
+
}
|
|
160
|
+
if (newParent) {
|
|
161
|
+
newParent.children.push(this);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
get children(): ThreadXMainNode[] {
|
|
166
|
+
return this._children;
|
|
167
|
+
}
|
|
168
|
+
//#endregion Parent/Child Props
|
|
169
|
+
|
|
170
|
+
get props() {
|
|
171
|
+
return this.curProps;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
override destroy() {
|
|
175
|
+
super.destroy();
|
|
176
|
+
this.texture = null;
|
|
177
|
+
}
|
|
178
|
+
}
|