@carbonenginejs/runtime-resource 0.11.1 → 0.12.1
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/CjsResMan.js +4 -4
- package/dist/CjsResMan.js.map +1 -1
- package/dist/_virtual/_rollupPluginBabelHelpers.js +1 -4
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/dist/format/CjsByteReader.js +310 -0
- package/dist/format/CjsByteReader.js.map +1 -0
- package/dist/format/CjsByteWriter.js +242 -0
- package/dist/format/CjsByteWriter.js.map +1 -0
- package/dist/format/CjsFormatError.js +41 -0
- package/dist/format/CjsFormatError.js.map +1 -0
- package/dist/format/CjsStringTable.js +268 -0
- package/dist/format/CjsStringTable.js.map +1 -0
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js +361 -0
- package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -0
- package/dist/format/carbonEffect/CjsCarbonEffectWriter.js +373 -0
- package/dist/format/carbonEffect/CjsCarbonEffectWriter.js.map +1 -0
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +372 -0
- package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +1 -0
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js +427 -0
- package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -0
- package/dist/format/carbonEffect/carbonEffectRecords.js +955 -0
- package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -0
- package/dist/format/compareUtf8.js +36 -0
- package/dist/format/compareUtf8.js.map +1 -0
- package/dist/format/index.js +11 -0
- package/dist/format/index.js.map +1 -0
- package/dist/formats/bnk/CjsBnkFormat.js +18 -2
- package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
- package/dist/formats/bnk/core/eventAction.js +305 -0
- package/dist/formats/bnk/core/eventAction.js.map +1 -0
- package/dist/formats/bnk/core/graph.js +3 -6
- package/dist/formats/bnk/core/graph.js.map +1 -1
- package/dist/formats/bnk/core/helpers.js +62 -11
- package/dist/formats/bnk/core/helpers.js.map +1 -1
- package/dist/formats/bnk/core/nodeBase.js +532 -0
- package/dist/formats/bnk/core/nodeBase.js.map +1 -0
- package/dist/formats/bnk/core/sfxNodes.js +632 -0
- package/dist/formats/bnk/core/sfxNodes.js.map +1 -0
- package/dist/formats/bnk/core/soundbanksInfo.js +59 -51
- package/dist/formats/bnk/core/soundbanksInfo.js.map +1 -1
- package/dist/formats/gr2/CjsGr2Format.js +256 -13
- package/dist/formats/gr2/CjsGr2Format.js.map +1 -1
- package/dist/formats/gr2/core/helpers.js +15 -15
- package/dist/formats/gr2/core/helpers.js.map +1 -1
- package/dist/formats/gr2/core/json.js +1 -1
- package/dist/formats/gr2/core/json.js.map +1 -1
- package/dist/formats/gr2/core/targets.js +1 -1
- package/dist/formats/gr2/core/targets.js.map +1 -1
- package/dist/formats/gr2/index.js +0 -1
- package/dist/formats/gr2/index.js.map +1 -1
- package/dist/formats/hlsl/core/HlslReader.js +7 -257
- package/dist/formats/hlsl/core/HlslReader.js.map +1 -1
- package/dist/formats/hlsl/core/analysis.js +1 -1
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +781 -0
- package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -0
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +21 -1
- package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
- package/dist/formats/hlsl/index.js +1 -0
- package/dist/formats/hlsl/index.js.map +1 -1
- package/dist/formats/index.js +3 -6
- package/dist/formats/index.js.map +1 -1
- package/dist/formats/webgl/core/cewg/CewgPackage.js +2 -1
- package/dist/formats/webgl/core/cewg/CewgPackage.js.map +1 -1
- package/dist/formats/webgl/core/cewg/binary.js +11 -93
- package/dist/formats/webgl/core/cewg/binary.js.map +1 -1
- package/dist/formats/webgl/core/effectPackage.js +4 -1
- package/dist/formats/webgl/core/effectPackage.js.map +1 -1
- package/dist/formats/webgl/core/errors.js +3 -3
- package/dist/formats/webgl/core/errors.js.map +1 -1
- package/dist/formats/webgpu/CjsWebgpuFormat.js +4 -23
- package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +197 -0
- package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js +368 -0
- package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/containerViews.js +355 -0
- package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +1 -0
- package/dist/formats/webgpu/core/cewgpu/validateContainer.js +90 -0
- package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +1 -0
- package/dist/formats/webgpu/core/effectBackendBodySet.js +21 -20
- package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
- package/dist/formats/webgpu/core/helpers.js +87 -92
- package/dist/formats/webgpu/core/helpers.js.map +1 -1
- package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +14 -13
- package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js.map +1 -1
- package/dist/formats/webgpu/core/ir/inferValueTypes.js +10 -8
- package/dist/formats/webgpu/core/ir/inferValueTypes.js.map +1 -1
- package/dist/formats/webgpu/core/packageEffect.js +94 -9
- package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
- package/dist/formats/webgpu/core/packageMetadata.js +10 -1
- package/dist/formats/webgpu/core/packageMetadata.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +17 -15
- package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +13 -12
- package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +9 -8
- package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +23 -22
- package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js.map +1 -1
- package/dist/formats/webgpu/core/wgsl/selectionPlans.js +46 -44
- package/dist/formats/webgpu/core/wgsl/selectionPlans.js.map +1 -1
- package/dist/resource/CjsResource.js +700 -684
- package/dist/resource/CjsResource.js.map +1 -1
- package/dist/resource/Tr2LightProfileRes.js +18 -27
- package/dist/resource/Tr2LightProfileRes.js.map +1 -1
- package/dist/resource/audio/CjsAudioBufferRes.js +2 -2
- package/dist/resource/audio/CjsAudioBufferRes.js.map +1 -1
- package/dist/resource/audio/CjsAudioRes.js +2 -2
- package/dist/resource/audio/CjsAudioRes.js.map +1 -1
- package/dist/resource/geometry/TriGeometryRes.js +605 -586
- package/dist/resource/geometry/TriGeometryRes.js.map +1 -1
- package/dist/resource/geometry/granny/Tr2GrannyStateRes.js +21 -30
- package/dist/resource/geometry/granny/Tr2GrannyStateRes.js.map +1 -1
- package/dist/resource/geometry/granny/TriGrannyRes.js +21 -30
- package/dist/resource/geometry/granny/TriGrannyRes.js.map +1 -1
- package/dist/resource/shader/Tr2EffectRes.js +9 -7
- package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialArea.js +5 -3
- package/dist/resource/shader/Tr2MaterialArea.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialMesh.js +4 -2
- package/dist/resource/shader/Tr2MaterialMesh.js.map +1 -1
- package/dist/resource/shader/Tr2MaterialRes.js +5 -3
- package/dist/resource/shader/Tr2MaterialRes.js.map +1 -1
- package/dist/resource/shader/Tr2Shader.js +26 -21
- package/dist/resource/shader/Tr2Shader.js.map +1 -1
- package/dist/resource/shader/Tr2ShaderPermutation.js +8 -6
- package/dist/resource/shader/Tr2ShaderPermutation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDefine.js +5 -3
- package/dist/resource/shader/reflection/Tr2EffectDefine.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectDescription.js +5 -3
- package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js +17 -15
- package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +11 -9
- package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectResource.js +8 -6
- package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js +15 -13
- package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js +7 -5
- package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
- package/dist/resource/shader/reflection/Tr2Pass.js +11 -9
- package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js +8 -6
- package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
- package/dist/resource/texture/CjsTextureArrayRes.js +400 -411
- package/dist/resource/texture/CjsTextureArrayRes.js.map +1 -1
- package/dist/resource/texture/Tr2ImageRes.js +99 -95
- package/dist/resource/texture/Tr2ImageRes.js.map +1 -1
- package/dist/resource/texture/TriTextureRes.js +312 -273
- package/dist/resource/texture/TriTextureRes.js.map +1 -1
- package/docs/README.md +13 -1
- package/docs/architecture.md +3 -3
- package/docs/concepts/resource-lifecycle.md +9 -2
- package/docs/concepts/shader-resource-model.md +114 -0
- package/docs/concepts/writing-an-engine-adapter.md +115 -0
- package/docs/formats/README.md +24 -1
- package/docs/formats/carbon-effect-container.md +452 -0
- package/docs/formats/dxbc/README.md +68 -0
- package/docs/formats/dxbc/architecture.md +80 -0
- package/docs/formats/dxbc/reference/api.md +77 -0
- package/docs/formats/dxbc/reference/classes/README.md +9 -0
- package/docs/formats/dxbc/reference/decoded-output.md +122 -0
- package/docs/formats/gr2.md +3 -4
- package/docs/formats/hlsl/README.md +54 -0
- package/docs/formats/hlsl/architecture.md +67 -0
- package/docs/formats/hlsl/guides/hydrating-json-output.md +62 -0
- package/docs/formats/hlsl/guides/reading-effects.md +64 -0
- package/docs/formats/hlsl/reference/advanced-analysis.md +66 -0
- package/docs/formats/hlsl/reference/api.md +98 -0
- package/docs/formats/hlsl/reference/classes/README.md +11 -0
- package/docs/formats/hlsl/reference/json-graph.md +100 -0
- package/docs/formats/hlsl/reference/portable-reflection.md +141 -0
- package/docs/formats/provenance.md +32 -17
- package/docs/formats/webgl/README.md +57 -0
- package/docs/formats/webgl/architecture.md +70 -0
- package/docs/formats/webgl/carbon-constant-layouts.md +326 -0
- package/docs/formats/webgl/decl-io.md +1234 -0
- package/docs/formats/webgl/effect-reflection.md +127 -0
- package/docs/formats/webgl/memory-structured.md +871 -0
- package/docs/formats/webgl/reference/classes/README.md +9 -0
- package/docs/formats/webgl/texture-sample.md +964 -0
- package/docs/formats/webgpu/README.md +84 -0
- package/docs/formats/webgpu/architecture.md +96 -0
- package/docs/formats/webgpu/formats/cewgpu.md +216 -0
- package/docs/formats/webgpu/guides/effect-packaging.md +191 -0
- package/docs/formats/webgpu/reference/api.md +197 -0
- package/docs/formats/webgpu/reference/classes/README.md +9 -0
- package/docs/formats/webgpu/reference/wgsl-compatibility.md +1543 -0
- package/docs/formats/wwise.md +45 -4
- package/docs/reference/classes/core.md +80 -0
- package/docs/reference/classes/formats.md +24 -34
- package/docs/reference/events.md +25 -0
- package/docs/reference/motherlode-cache.md +22 -8
- package/docs/reference/workers.md +5 -5
- package/docs/roadmap.md +61 -41
- package/format-notices/bnk/NOTICE +5 -4
- package/format-notices/webgl/NOTICE +1 -1
- package/package.json +2 -1
- package/dist/formats/gr2/core/CjsFormatGr2.js +0 -273
- package/dist/formats/gr2/core/CjsFormatGr2.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js +0 -415
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackage.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js +0 -100
- package/dist/formats/webgpu/core/cewgpu/CewgpuPackageBuilder.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/binary.js +0 -93
- package/dist/formats/webgpu/core/cewgpu/binary.js.map +0 -1
- package/dist/formats/webgpu/core/cewgpu/tags.js +0 -17
- package/dist/formats/webgpu/core/cewgpu/tags.js.map +0 -1
- package/dist/formats/webgpu/core/effectPackageValidation.js +0 -1078
- package/dist/formats/webgpu/core/effectPackageValidation.js.map +0 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { identity as _identity, applyDecs2311 as _applyDecs2311 } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
1
|
import { CjsEventEmitter } from '@carbonenginejs/runtime-utils/model';
|
|
3
2
|
import { normalizeResourcePath, normalizeResourceExtension, getResourceExtension } from '@carbonenginejs/runtime-utils/path';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
let _initProto, _initClass, _init_path, _init_extra_path, _init_ext, _init_extra_ext, _init_requirement, _init_extra_requirement, _init_state, _init_extra_state;
|
|
3
|
+
import { CjsSchema, carbon, impl, type } from '@carbonenginejs/runtime-utils/schema';
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
6
|
* Deterministic activity values accepted by resource-facing lease methods.
|
|
@@ -26,735 +23,715 @@ let _initProto, _initClass, _init_path, _init_extra_path, _init_ext, _init_extra
|
|
|
26
23
|
* @property {Function} [lock] Adds one inactivity-purge lock and returns its count.
|
|
27
24
|
* @property {Function} [unlock] Releases one inactivity-purge lock and returns its count.
|
|
28
25
|
*/
|
|
29
|
-
let _CjsResource;
|
|
30
|
-
new class extends _identity {
|
|
31
|
-
static [class CjsResource extends CjsEventEmitter {
|
|
32
|
-
static {
|
|
33
|
-
({
|
|
34
|
-
e: [_init_path, _init_extra_path, _init_ext, _init_extra_ext, _init_requirement, _init_extra_requirement, _init_state, _init_extra_state, _initProto],
|
|
35
|
-
c: [_CjsResource, _initClass]
|
|
36
|
-
} = _applyDecs2311(this, [type.define({
|
|
37
|
-
className: "CjsResource",
|
|
38
|
-
family: "resource"
|
|
39
|
-
})], [[[type, type.path], 16, "path"], [[type, type.string], 16, "ext"], [[type, type.string], 16, "requirement"], [[type, type.string], 16, "state"], [[carbon, carbon.method, impl, impl.adapted], 18, "Initialize"], [[carbon, carbon.method, impl, impl.adapted], 18, "GetPath"], [[carbon, carbon.method, impl, impl.adapted], 18, "GetExt"], [[carbon, carbon.method, impl, impl.adapted], 18, "IsLoading"], [[carbon, carbon.method, impl, impl.adapted], 18, "HasLoaded"], [[carbon, carbon.method, impl, impl.adapted], 18, "IsPrepared"], [[carbon, carbon.method, impl, impl.adapted], 18, "IsGood"], [[carbon, carbon.method, impl, impl.adapted], 18, "IsFailed"]], 0, void 0, CjsEventEmitter));
|
|
40
|
-
}
|
|
41
|
-
#payload = (_initProto(this), null);
|
|
42
|
-
|
|
43
|
-
/** Reloads attempted since the last successful load. */
|
|
44
|
-
#reloadAttempts = 0;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* How many times a purged or failed resource reloads itself before giving up.
|
|
48
|
-
*
|
|
49
|
-
* Per class so a subclass can be more or less patient. Counted per resource
|
|
50
|
-
* and reset on every successful load, so this bounds consecutive failures,
|
|
51
|
-
* not the lifetime total.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
path = _init_path(this, "");
|
|
55
|
-
ext = (_init_extra_path(this), _init_ext(this, ""));
|
|
56
|
-
requirement = (_init_extra_ext(this), _init_requirement(this, ""));
|
|
57
|
-
state = (_init_extra_requirement(this), _init_state(this, _CjsResource.State.EMPTY));
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Identifies this class as a runtime resource.
|
|
61
|
-
*
|
|
62
|
-
* Static, so a schema field declared as `@type.objectRef("TriGeometryRes")`
|
|
63
|
-
* can be known to hold a resource without an instance existing - the
|
|
64
|
-
* declaration alone is enough, resolved through `CjsSchema.GetConstructor`.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
/** Identifies this handle as a runtime resource. */
|
|
68
|
-
get isResource() {
|
|
69
|
-
return this.constructor.isResource === true;
|
|
70
|
-
}
|
|
71
26
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (values) {
|
|
112
|
-
this.SetValues(values);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
27
|
+
/**
|
|
28
|
+
* ResMan-owned runtime resource.
|
|
29
|
+
*
|
|
30
|
+
* Resources are not model graph objects: BLACK/RED graphs persist resource
|
|
31
|
+
* paths (including empty paths), while CjsResMan constructs, initializes,
|
|
32
|
+
* caches, and hydrates the corresponding runtime resource instances.
|
|
33
|
+
*/
|
|
34
|
+
class CjsResource extends CjsEventEmitter {
|
|
35
|
+
#payload = null;
|
|
36
|
+
|
|
37
|
+
/** Reloads attempted since the last successful load. */
|
|
38
|
+
#reloadAttempts = 0;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* How many times a purged or failed resource reloads itself before giving up.
|
|
42
|
+
*
|
|
43
|
+
* Per class so a subclass can be more or less patient. Counted per resource
|
|
44
|
+
* and reset on every successful load, so this bounds consecutive failures,
|
|
45
|
+
* not the lifetime total.
|
|
46
|
+
*/
|
|
47
|
+
static maxReloadAttempts = 3;
|
|
48
|
+
path = "";
|
|
49
|
+
ext = "";
|
|
50
|
+
requirement = "";
|
|
51
|
+
state = CjsResource.State.EMPTY;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Identifies this class as a runtime resource.
|
|
55
|
+
*
|
|
56
|
+
* Static, so a schema field declared as `@type.objectRef("TriGeometryRes")`
|
|
57
|
+
* can be known to hold a resource without an instance existing - the
|
|
58
|
+
* declaration alone is enough, resolved through `CjsSchema.GetConstructor`.
|
|
59
|
+
*/
|
|
60
|
+
static isResource = true;
|
|
61
|
+
|
|
62
|
+
/** Identifies this handle as a runtime resource. */
|
|
63
|
+
get isResource() {
|
|
64
|
+
return this.constructor.isResource === true;
|
|
65
|
+
}
|
|
115
66
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Create a detached runtime resource with empty identity and payload state.
|
|
69
|
+
* Schema values are applied without attaching manager lifecycle callbacks;
|
|
70
|
+
* CjsResMan supplies those callbacks after canonical insertion.
|
|
71
|
+
*
|
|
72
|
+
* @param {object|null} [values=null] Initial decorated schema-field values.
|
|
73
|
+
*/
|
|
74
|
+
constructor(values = null) {
|
|
75
|
+
super();
|
|
76
|
+
Object.defineProperty(this, "__adapterResources", {
|
|
77
|
+
value: Object.create(null),
|
|
78
|
+
enumerable: false,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(this, "__objectLoader", {
|
|
83
|
+
value: null,
|
|
84
|
+
enumerable: false,
|
|
85
|
+
configurable: true,
|
|
86
|
+
writable: true
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(this, "__objectRequest", {
|
|
89
|
+
value: null,
|
|
90
|
+
enumerable: false,
|
|
91
|
+
configurable: true,
|
|
92
|
+
writable: true
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(this, "__lifecycleController", {
|
|
95
|
+
value: null,
|
|
96
|
+
enumerable: false,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(this, "__reloadHook", {
|
|
101
|
+
value: null,
|
|
102
|
+
enumerable: false,
|
|
103
|
+
configurable: true,
|
|
104
|
+
writable: true
|
|
105
|
+
});
|
|
106
|
+
if (values) {
|
|
107
|
+
this.SetValues(values);
|
|
131
108
|
}
|
|
109
|
+
}
|
|
132
110
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Apply resource identity or metadata values without model graph semantics.
|
|
113
|
+
*
|
|
114
|
+
* @param {object|null} values
|
|
115
|
+
* @returns {CjsResource}
|
|
116
|
+
*/
|
|
117
|
+
SetValues(values = null) {
|
|
118
|
+
if (!values || typeof values !== "object") return this;
|
|
119
|
+
const fields = CjsSchema.getSchema(this.constructor).fields;
|
|
120
|
+
for (const field of fields) {
|
|
121
|
+
if (Object.prototype.hasOwnProperty.call(values, field.name)) {
|
|
122
|
+
this[field.name] = values[field.name];
|
|
143
123
|
}
|
|
144
|
-
return result;
|
|
145
124
|
}
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
146
127
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
this.error = null;
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
128
|
+
/**
|
|
129
|
+
* Export resource identity and schema metadata. Runtime state is not a model
|
|
130
|
+
* graph node; graph fields normally persist only their resource path.
|
|
131
|
+
*
|
|
132
|
+
* @returns {object}
|
|
133
|
+
*/
|
|
134
|
+
GetValues() {
|
|
135
|
+
const result = {};
|
|
136
|
+
for (const field of CjsSchema.getSchema(this.constructor).fields) {
|
|
137
|
+
result[field.name] = this[field.name];
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
163
141
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Initialize the resource identity from a path and optional extension.
|
|
144
|
+
*
|
|
145
|
+
* @param {string} path
|
|
146
|
+
* @param {string|null} ext
|
|
147
|
+
* @param {string|null} requirement
|
|
148
|
+
* @returns {CjsResource}
|
|
149
|
+
*/
|
|
150
|
+
Initialize(path, ext = null, requirement = "") {
|
|
151
|
+
this.path = normalizeResourcePath(path);
|
|
152
|
+
this.ext = ext ? normalizeResourceExtension(ext) : getResourceExtension(this.path);
|
|
153
|
+
this.requirement = requirement === null || requirement === undefined ? "" : String(requirement).trim().toLowerCase();
|
|
154
|
+
this.state = CjsResource.State.EMPTY;
|
|
155
|
+
this.error = null;
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
172
158
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Get the normalized resource path.
|
|
161
|
+
*
|
|
162
|
+
* @returns {string}
|
|
163
|
+
*/
|
|
164
|
+
GetPath() {
|
|
165
|
+
return this.path;
|
|
166
|
+
}
|
|
181
167
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
168
|
+
/**
|
|
169
|
+
* Get the normalized resource extension.
|
|
170
|
+
*
|
|
171
|
+
* @returns {string}
|
|
172
|
+
*/
|
|
173
|
+
GetExt() {
|
|
174
|
+
return this.ext;
|
|
175
|
+
}
|
|
191
176
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Return the normalized semantic outcome requested from this source path.
|
|
179
|
+
* This metadata query is pure and does not renew manager activity.
|
|
180
|
+
*
|
|
181
|
+
* @returns {string} Lowercase requirement name, or an empty string.
|
|
182
|
+
*/
|
|
183
|
+
GetRequirement() {
|
|
184
|
+
return this.requirement;
|
|
185
|
+
}
|
|
200
186
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Return true when the resource is currently loading.
|
|
189
|
+
*
|
|
190
|
+
* @returns {boolean}
|
|
191
|
+
*/
|
|
192
|
+
IsLoading() {
|
|
193
|
+
return this.state === CjsResource.State.REQUESTED || this.state === CjsResource.State.LOADING;
|
|
194
|
+
}
|
|
209
195
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Return true when CPU resource payload data has been loaded.
|
|
198
|
+
*
|
|
199
|
+
* @returns {boolean}
|
|
200
|
+
*/
|
|
201
|
+
HasLoaded() {
|
|
202
|
+
return this.state === CjsResource.State.LOADED || this.state === CjsResource.State.PREPARING || this.state === CjsResource.State.PREPARED;
|
|
203
|
+
}
|
|
218
204
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
* `PURGED` is not completion: nothing was tried and nothing concluded, the
|
|
228
|
-
* payload was simply taken away.
|
|
229
|
-
*
|
|
230
|
-
* @returns {boolean}
|
|
231
|
-
*/
|
|
232
|
-
HasCompleted() {
|
|
233
|
-
return this.state === _CjsResource.State.PREPARED || this.state === _CjsResource.State.FAILED;
|
|
234
|
-
}
|
|
205
|
+
/**
|
|
206
|
+
* Return true when preparation has completed or produced a good resource.
|
|
207
|
+
*
|
|
208
|
+
* @returns {boolean}
|
|
209
|
+
*/
|
|
210
|
+
IsPrepared() {
|
|
211
|
+
return this.state === CjsResource.State.PREPARED;
|
|
212
|
+
}
|
|
235
213
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Return true when this resource finished trying to load, either way.
|
|
216
|
+
*
|
|
217
|
+
* The pull form of the `completed` event. Carbon expresses this as a
|
|
218
|
+
* predicate because it has no events - `m_isPrepared` is set on the failure
|
|
219
|
+
* path too (`BlueAsyncRes.cpp:183`) - so `IsPrepared()` there means "finished
|
|
220
|
+
* trying" while ours keeps the narrower "succeeded".
|
|
221
|
+
*
|
|
222
|
+
* `PURGED` is not completion: nothing was tried and nothing concluded, the
|
|
223
|
+
* payload was simply taken away.
|
|
224
|
+
*
|
|
225
|
+
* @returns {boolean}
|
|
226
|
+
*/
|
|
227
|
+
HasCompleted() {
|
|
228
|
+
return this.state === CjsResource.State.PREPARED || this.state === CjsResource.State.FAILED;
|
|
229
|
+
}
|
|
251
230
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
231
|
+
/**
|
|
232
|
+
* Return true when preparation completed successfully, and renew this
|
|
233
|
+
* resource.
|
|
234
|
+
*
|
|
235
|
+
* Every caller of `IsGood()` is about to use the resource, so renewal always
|
|
236
|
+
* follows the query. Merging them - as ccpwgl does in `Tw2Resource.js:108` -
|
|
237
|
+
* closes that gap permanently instead of relying on call-site discipline, and
|
|
238
|
+
* means a purged resource reloads itself the moment anything asks for it.
|
|
239
|
+
*
|
|
240
|
+
* @returns {boolean}
|
|
241
|
+
*/
|
|
242
|
+
IsGood() {
|
|
243
|
+
this.KeepAlive();
|
|
244
|
+
return this.IsPrepared();
|
|
245
|
+
}
|
|
260
246
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
const previous = this.state;
|
|
270
|
-
if (previous === state) return this;
|
|
271
|
-
this.state = state;
|
|
272
|
-
// A successful load clears the budget, so the cap bounds consecutive
|
|
273
|
-
// failures rather than how many times a resource may ever be purged.
|
|
274
|
-
if (state === _CjsResource.State.PREPARED) this.#reloadAttempts = 0;
|
|
275
|
-
this.EmitEvent?.(state, this, ...details);
|
|
276
|
-
this.EmitEvent?.("statechange", this, state, previous);
|
|
277
|
-
// Fires again after a purge and reload, so subscribers rebuild whatever
|
|
278
|
-
// they derived from the payload that was deleted.
|
|
279
|
-
if (this.HasCompleted()) this.EmitEvent?.("completed", this, ...details);
|
|
280
|
-
return this;
|
|
281
|
-
}
|
|
247
|
+
/**
|
|
248
|
+
* Return true when preparation failed.
|
|
249
|
+
*
|
|
250
|
+
* @returns {boolean}
|
|
251
|
+
*/
|
|
252
|
+
IsFailed() {
|
|
253
|
+
return this.state === CjsResource.State.FAILED;
|
|
254
|
+
}
|
|
282
255
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
* @param {Function} listener Called with this resource once it has finished.
|
|
305
|
-
* @param {*} [source=null] Optional owner used for bulk removal.
|
|
306
|
-
* @returns {CjsResource} This resource.
|
|
307
|
-
*/
|
|
308
|
-
OnCompleted(listener, source = null) {
|
|
309
|
-
if (typeof listener !== "function") {
|
|
310
|
-
throw new TypeError("CjsResource.OnCompleted requires a function.");
|
|
311
|
-
}
|
|
312
|
-
if (this.HasCompleted()) {
|
|
313
|
-
listener(this);
|
|
314
|
-
return this;
|
|
315
|
-
}
|
|
316
|
-
return this.OnEvent("completed", listener, source);
|
|
317
|
-
}
|
|
256
|
+
/**
|
|
257
|
+
* Changes state and emits the state-specific, statechange, and - on reaching
|
|
258
|
+
* a load outcome - completed events.
|
|
259
|
+
*/
|
|
260
|
+
SetState(state, ...details) {
|
|
261
|
+
if (!CjsResource.isValidState(state)) {
|
|
262
|
+
throw new TypeError(`Invalid CjsResource state: ${state}`);
|
|
263
|
+
}
|
|
264
|
+
const previous = this.state;
|
|
265
|
+
if (previous === state) return this;
|
|
266
|
+
this.state = state;
|
|
267
|
+
// A successful load clears the budget, so the cap bounds consecutive
|
|
268
|
+
// failures rather than how many times a resource may ever be purged.
|
|
269
|
+
if (state === CjsResource.State.PREPARED) this.#reloadAttempts = 0;
|
|
270
|
+
this.EmitEvent?.(state, this, ...details);
|
|
271
|
+
this.EmitEvent?.("statechange", this, state, previous);
|
|
272
|
+
// Fires again after a purge and reload, so subscribers rebuild whatever
|
|
273
|
+
// they derived from the payload that was deleted.
|
|
274
|
+
if (this.HasCompleted()) this.EmitEvent?.("completed", this, ...details);
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
318
277
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Subscribe to this resource finishing, firing immediately when it already
|
|
280
|
+
* has.
|
|
281
|
+
*
|
|
282
|
+
* The immediate call is the point. A plain emitter drops late subscribers on
|
|
283
|
+
* the floor - subscribe after `PREPARED` and nothing ever arrives - which is
|
|
284
|
+
* why callers end up doing work synchronously "just in case" instead of
|
|
285
|
+
* subscribing. ccpwgl solves this by replaying current state at registration
|
|
286
|
+
* (`Tw2Resource.onNotification`), and a subscriber satisfied that way is
|
|
287
|
+
* never stored at all, so only subscriptions genuinely still waiting
|
|
288
|
+
* accumulate.
|
|
289
|
+
*
|
|
290
|
+
* The listener runs for both outcomes and branches itself:
|
|
291
|
+
*
|
|
292
|
+
* ```js
|
|
293
|
+
* res.OnCompleted(res => { if (res.IsPrepared()) something; else somethingElse; });
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* It may run more than once - a purge and reload completes again - so
|
|
297
|
+
* handlers must be written to be re-entered rather than assuming first load.
|
|
298
|
+
*
|
|
299
|
+
* @param {Function} listener Called with this resource once it has finished.
|
|
300
|
+
* @param {*} [source=null] Optional owner used for bulk removal.
|
|
301
|
+
* @returns {CjsResource} This resource.
|
|
302
|
+
*/
|
|
303
|
+
OnCompleted(listener, source = null) {
|
|
304
|
+
if (typeof listener !== "function") {
|
|
305
|
+
throw new TypeError("CjsResource.OnCompleted requires a function.");
|
|
306
|
+
}
|
|
307
|
+
if (this.HasCompleted()) {
|
|
308
|
+
listener(this);
|
|
309
|
+
return this;
|
|
322
310
|
}
|
|
311
|
+
return this.OnEvent("completed", listener, source);
|
|
312
|
+
}
|
|
323
313
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
314
|
+
/** Marks this resource as requested. */
|
|
315
|
+
MarkRequested() {
|
|
316
|
+
return this.SetState(CjsResource.State.REQUESTED);
|
|
317
|
+
}
|
|
328
318
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
319
|
+
/** Marks this resource as actively loading. */
|
|
320
|
+
MarkLoading() {
|
|
321
|
+
return this.SetState(CjsResource.State.LOADING);
|
|
322
|
+
}
|
|
333
323
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
324
|
+
/** Marks this resource's CPU payload as loaded. */
|
|
325
|
+
MarkLoaded() {
|
|
326
|
+
return this.SetState(CjsResource.State.LOADED);
|
|
327
|
+
}
|
|
338
328
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
329
|
+
/** Marks this resource as preparing its semantic result. */
|
|
330
|
+
MarkPreparing() {
|
|
331
|
+
return this.SetState(CjsResource.State.PREPARING);
|
|
332
|
+
}
|
|
343
333
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
334
|
+
/** Marks this resource as successfully prepared. */
|
|
335
|
+
MarkPrepared() {
|
|
336
|
+
return this.SetState(CjsResource.State.PREPARED);
|
|
337
|
+
}
|
|
348
338
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
*
|
|
354
|
-
* @returns {CjsResource} This purged resource.
|
|
355
|
-
*/
|
|
356
|
-
MarkPurged() {
|
|
357
|
-
return this.SetState(_CjsResource.State.PURGED);
|
|
358
|
-
}
|
|
339
|
+
/** Marks this resource as successfully prepared. */
|
|
340
|
+
MarkGood() {
|
|
341
|
+
return this.MarkPrepared();
|
|
342
|
+
}
|
|
359
343
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
344
|
+
/**
|
|
345
|
+
* Mark this detached resource handle as purged after a successful
|
|
346
|
+
* manager-owned policy eviction, such as inactivity or recorded-byte cache
|
|
347
|
+
* pressure, released its adapter allocations and payload.
|
|
348
|
+
*
|
|
349
|
+
* @returns {CjsResource} This purged resource.
|
|
350
|
+
*/
|
|
351
|
+
MarkPurged() {
|
|
352
|
+
return this.SetState(CjsResource.State.PURGED);
|
|
353
|
+
}
|
|
369
354
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
355
|
+
/**
|
|
356
|
+
* Return whether deterministic manager cleanup has purged this handle.
|
|
357
|
+
* This is a pure state query and never renews resource activity.
|
|
358
|
+
*
|
|
359
|
+
* @returns {boolean} `true` when the current state is `PURGED`.
|
|
360
|
+
*/
|
|
361
|
+
IsPurged() {
|
|
362
|
+
return this.state === CjsResource.State.PURGED;
|
|
363
|
+
}
|
|
375
364
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
* whose `object` points to the resource itself are unaffected. A non-null
|
|
382
|
-
* payload explicitly renews its manager-owned identity and payload leases;
|
|
383
|
-
* payload reads remain pure and do not renew either lease.
|
|
384
|
-
*
|
|
385
|
-
* @param {*} payload Plain reader/converter output, or `null` to clear it.
|
|
386
|
-
* @returns {CjsResource} This resource with the supplied payload reference.
|
|
387
|
-
*/
|
|
388
|
-
SetPayload(payload = null) {
|
|
389
|
-
const previous = this.#payload;
|
|
390
|
-
this.#payload = payload;
|
|
391
|
-
if (this.object === previous) this.object = payload;
|
|
392
|
-
if (this.HasPayload()) this.KeepPayloadAlive();
|
|
393
|
-
return this;
|
|
394
|
-
}
|
|
365
|
+
/** Stores a load failure and marks this resource as failed. */
|
|
366
|
+
SetError(error) {
|
|
367
|
+
this.error = error || null;
|
|
368
|
+
return this.SetState(CjsResource.State.FAILED, this.error);
|
|
369
|
+
}
|
|
395
370
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
371
|
+
/**
|
|
372
|
+
* Store the plain CPU payload associated with this resource.
|
|
373
|
+
* Concrete resource classes validate the fields they require before calling
|
|
374
|
+
* this method. If the compatibility `object` property still aliases the
|
|
375
|
+
* previous payload, it is updated to the replacement; semantic resources
|
|
376
|
+
* whose `object` points to the resource itself are unaffected. A non-null
|
|
377
|
+
* payload explicitly renews its manager-owned identity and payload leases;
|
|
378
|
+
* payload reads remain pure and do not renew either lease.
|
|
379
|
+
*
|
|
380
|
+
* @param {*} payload Plain reader/converter output, or `null` to clear it.
|
|
381
|
+
* @returns {CjsResource} This resource with the supplied payload reference.
|
|
382
|
+
*/
|
|
383
|
+
SetPayload(payload = null) {
|
|
384
|
+
const previous = this.#payload;
|
|
385
|
+
this.#payload = payload;
|
|
386
|
+
if (this.object === previous) this.object = payload;
|
|
387
|
+
if (this.HasPayload()) this.KeepPayloadAlive();
|
|
388
|
+
return this;
|
|
389
|
+
}
|
|
406
390
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Read the plain CPU payload associated with this resource.
|
|
393
|
+
*
|
|
394
|
+
* The query is pure and does not renew the payload lease.
|
|
395
|
+
*
|
|
396
|
+
* @returns {*} Current payload reference, or `null` after release.
|
|
397
|
+
*/
|
|
398
|
+
GetPayload() {
|
|
399
|
+
return this.#payload;
|
|
400
|
+
}
|
|
416
401
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
ReleasePayload() {
|
|
427
|
-
const payload = this.#payload;
|
|
428
|
-
this.#payload = null;
|
|
429
|
-
if (this.object === payload) this.object = null;
|
|
430
|
-
return this;
|
|
431
|
-
}
|
|
402
|
+
/**
|
|
403
|
+
* Return whether a payload has been explicitly assigned. This query is pure
|
|
404
|
+
* and does not renew the payload lease.
|
|
405
|
+
*
|
|
406
|
+
* @returns {boolean} Whether a non-null payload is attached.
|
|
407
|
+
*/
|
|
408
|
+
HasPayload() {
|
|
409
|
+
return this.#payload !== null && this.#payload !== undefined;
|
|
410
|
+
}
|
|
432
411
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
throw new TypeError(`CjsResource lifecycle controller ${name} must be a function.`);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
this.__lifecycleController = controller;
|
|
452
|
-
return this;
|
|
453
|
-
}
|
|
412
|
+
/**
|
|
413
|
+
* Release the complete payload reference after consumers have retained the
|
|
414
|
+
* scalars and typed-array views they require. When the compatibility
|
|
415
|
+
* `object` property still aliases that exact payload, it is cleared as part
|
|
416
|
+
* of the same ownership release. Semantic resources whose `object` property
|
|
417
|
+
* points to the resource itself are unaffected.
|
|
418
|
+
*
|
|
419
|
+
* @returns {CjsResource} This resource without its former payload reference.
|
|
420
|
+
*/
|
|
421
|
+
ReleasePayload() {
|
|
422
|
+
const payload = this.#payload;
|
|
423
|
+
this.#payload = null;
|
|
424
|
+
if (this.object === payload) this.object = null;
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
454
427
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
428
|
+
/**
|
|
429
|
+
* Bind or detach the manager callbacks used by explicit resource-facing
|
|
430
|
+
* liveness operations. Runtime resources remain usable when unbound; their
|
|
431
|
+
* liveness methods then become deterministic no-ops.
|
|
432
|
+
*
|
|
433
|
+
* @param {CjsResourceLifecycleController|null} controller Manager callbacks, or `null` after canonical ownership ends.
|
|
434
|
+
* @returns {CjsResource} This resource.
|
|
435
|
+
* @throws {TypeError} If the controller or any supplied callback is invalid.
|
|
436
|
+
*/
|
|
437
|
+
SetLifecycleController(controller = null) {
|
|
438
|
+
if (controller !== null && (typeof controller !== "object" || Array.isArray(controller))) {
|
|
439
|
+
throw new TypeError("CjsResource lifecycle controller must be an object or null.");
|
|
440
|
+
}
|
|
441
|
+
for (const name of ["isCurrent", "keepAlive", "keepPayloadAlive", "lock", "unlock"]) {
|
|
442
|
+
if (controller?.[name] !== undefined && typeof controller[name] !== "function") {
|
|
443
|
+
throw new TypeError(`CjsResource lifecycle controller ${name} must be a function.`);
|
|
444
|
+
}
|
|
466
445
|
}
|
|
446
|
+
this.__lifecycleController = controller;
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
467
449
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
* @returns {CjsResource} This resource, whether bound or detached.
|
|
481
|
-
* @throws {TypeError} If the bound manager rejects invalid activity values.
|
|
482
|
-
*/
|
|
483
|
-
KeepAlive(options = {}) {
|
|
484
|
-
this.__lifecycleController?.keepAlive?.(options);
|
|
485
|
-
if (this.IsPurged()) this.Reload(options);
|
|
486
|
-
return this;
|
|
487
|
-
}
|
|
450
|
+
/**
|
|
451
|
+
* Return whether this handle is still the manager's canonical resource.
|
|
452
|
+
*
|
|
453
|
+
* Engine adapters use this immediately before synchronously attaching a
|
|
454
|
+
* completed backend candidate. Detached resources return `false`; the query
|
|
455
|
+
* never renews activity, reloads data, or mutates lifecycle state.
|
|
456
|
+
*
|
|
457
|
+
* @returns {boolean} Whether the bound manager still owns this exact handle.
|
|
458
|
+
*/
|
|
459
|
+
IsCurrent() {
|
|
460
|
+
return Boolean(this.__lifecycleController?.isCurrent?.());
|
|
461
|
+
}
|
|
488
462
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
* Detached handles have no manager to re-register with and stay as they are.
|
|
510
|
-
*
|
|
511
|
-
* @param {CjsResourceActivityOptions} [options={}] Optional deterministic activity values.
|
|
512
|
-
* @returns {boolean} Whether a reload was started.
|
|
513
|
-
*/
|
|
514
|
-
Reload(options = {}) {
|
|
515
|
-
if (!this.IsPurged() && !this.IsFailed()) return false;
|
|
516
|
-
if (this.#reloadAttempts >= this.constructor.maxReloadAttempts) return false;
|
|
517
|
-
if (typeof this.__reloadHook !== "function") return false;
|
|
518
|
-
this.#reloadAttempts += 1;
|
|
519
|
-
return this.__reloadHook(options) !== false;
|
|
520
|
-
}
|
|
463
|
+
/**
|
|
464
|
+
* Renew this resource's canonical identity activity, and reload it when
|
|
465
|
+
* it has been purged.
|
|
466
|
+
*
|
|
467
|
+
* Purge is deletion - the payload is gone and nothing restores it - so
|
|
468
|
+
* revival is an ordinary reload along the first-load path. Consumers
|
|
469
|
+
* therefore never have to know a purge happened: they ask for what they need
|
|
470
|
+
* and this makes it be there.
|
|
471
|
+
*
|
|
472
|
+
* `IsGood()` calls this, so most callers never invoke it directly.
|
|
473
|
+
*
|
|
474
|
+
* @param {CjsResourceActivityOptions} [options={}] Optional deterministic activity values.
|
|
475
|
+
* @returns {CjsResource} This resource, whether bound or detached.
|
|
476
|
+
* @throws {TypeError} If the bound manager rejects invalid activity values.
|
|
477
|
+
*/
|
|
478
|
+
KeepAlive(options = {}) {
|
|
479
|
+
this.__lifecycleController?.keepAlive?.(options);
|
|
480
|
+
if (this.IsPurged()) this.Reload(options);
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
521
483
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
484
|
+
/**
|
|
485
|
+
* Re-register this handle with its manager and reload it into itself.
|
|
486
|
+
*
|
|
487
|
+
* Runs only from `PURGED` or `FAILED` - the two states where the payload is
|
|
488
|
+
* absent but recoverable. It does nothing to a resource that is loaded or
|
|
489
|
+
* still loading, so it is not a way to force a refetch of something already
|
|
490
|
+
* there.
|
|
491
|
+
*
|
|
492
|
+
* Bounded by `maxReloadAttempts`, because `KeepAlive()` calls this and the
|
|
493
|
+
* render path calls that every frame: without a cap, one missing texture
|
|
494
|
+
* becomes a permanent retry storm against the thing least likely to succeed.
|
|
495
|
+
* Attempts are spaced by real load round-trips rather than frames - starting
|
|
496
|
+
* one leaves `PURGED`/`FAILED`, so nothing re-enters until it settles - and
|
|
497
|
+
* the count resets on any successful load.
|
|
498
|
+
*
|
|
499
|
+
* The distinction that matters: the reload must fill THIS handle, not resolve
|
|
500
|
+
* whatever the manager currently caches for the same path. A consumer holding
|
|
501
|
+
* a purged handle has no way to discover a replacement, so handing it a fresh
|
|
502
|
+
* instance elsewhere leaves it dead forever.
|
|
503
|
+
*
|
|
504
|
+
* Detached handles have no manager to re-register with and stay as they are.
|
|
505
|
+
*
|
|
506
|
+
* @param {CjsResourceActivityOptions} [options={}] Optional deterministic activity values.
|
|
507
|
+
* @returns {boolean} Whether a reload was started.
|
|
508
|
+
*/
|
|
509
|
+
Reload(options = {}) {
|
|
510
|
+
if (!this.IsPurged() && !this.IsFailed()) return false;
|
|
511
|
+
if (this.#reloadAttempts >= this.constructor.maxReloadAttempts) return false;
|
|
512
|
+
if (typeof this.__reloadHook !== "function") return false;
|
|
513
|
+
this.#reloadAttempts += 1;
|
|
514
|
+
return this.__reloadHook(options) !== false;
|
|
515
|
+
}
|
|
542
516
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
517
|
+
/**
|
|
518
|
+
* Bind the manager callback that restores this handle after it loses its
|
|
519
|
+
* payload.
|
|
520
|
+
*
|
|
521
|
+
* Deliberately separate from the lifecycle controller, which is detached the
|
|
522
|
+
* moment canonical ownership ends. Recovery has to survive exactly that
|
|
523
|
+
* event: a purged handle with no route back to its manager is unrecoverable,
|
|
524
|
+
* which is the failure this whole contract exists to prevent.
|
|
525
|
+
*
|
|
526
|
+
* @param {Function|null} hook Manager callback, or `null` to detach it.
|
|
527
|
+
* @returns {CjsResource} This resource.
|
|
528
|
+
* @throws {TypeError} If the hook is neither a function nor null.
|
|
529
|
+
*/
|
|
530
|
+
SetReloadHook(hook = null) {
|
|
531
|
+
if (hook !== null && typeof hook !== "function") {
|
|
532
|
+
throw new TypeError("CjsResource.SetReloadHook requires a function or null.");
|
|
533
|
+
}
|
|
534
|
+
this.__reloadHook = hook;
|
|
535
|
+
return this;
|
|
536
|
+
}
|
|
551
537
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
*
|
|
561
|
-
* @returns {CjsResource} This resource.
|
|
562
|
-
*/
|
|
563
|
-
ResetReloadAttempts() {
|
|
564
|
-
this.#reloadAttempts = 0;
|
|
565
|
-
return this;
|
|
566
|
-
}
|
|
538
|
+
/**
|
|
539
|
+
* Return how many reloads have been attempted since the last successful load.
|
|
540
|
+
*
|
|
541
|
+
* @returns {number}
|
|
542
|
+
*/
|
|
543
|
+
GetReloadAttempts() {
|
|
544
|
+
return this.#reloadAttempts;
|
|
545
|
+
}
|
|
567
546
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
547
|
+
/**
|
|
548
|
+
* Clear the reload attempt count, so a resource that exhausted its attempts
|
|
549
|
+
* can be asked again.
|
|
550
|
+
*
|
|
551
|
+
* This is the deliberate "try it again" gesture - a user retrying a failed
|
|
552
|
+
* load, say. It is separate from `Reload()` because the cap exists precisely
|
|
553
|
+
* to stop the automatic path retrying forever, so lifting it has to be a
|
|
554
|
+
* decision someone made.
|
|
555
|
+
*
|
|
556
|
+
* @returns {CjsResource} This resource.
|
|
557
|
+
*/
|
|
558
|
+
ResetReloadAttempts() {
|
|
559
|
+
this.#reloadAttempts = 0;
|
|
560
|
+
return this;
|
|
561
|
+
}
|
|
581
562
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
563
|
+
/**
|
|
564
|
+
* Explicitly renew both canonical identity activity and the attached CPU
|
|
565
|
+
* payload lease. Reading the payload through `GetPayload()` or
|
|
566
|
+
* `HasPayload()` remains pure.
|
|
567
|
+
*
|
|
568
|
+
* @param {CjsResourceActivityOptions} [options={}] Optional deterministic activity values.
|
|
569
|
+
* @returns {CjsResource} This resource, whether a payload exists or not.
|
|
570
|
+
* @throws {TypeError} If the bound manager rejects invalid activity values.
|
|
571
|
+
*/
|
|
572
|
+
KeepPayloadAlive(options = {}) {
|
|
573
|
+
this.__lifecycleController?.keepPayloadAlive?.(options);
|
|
574
|
+
return this;
|
|
575
|
+
}
|
|
591
576
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
577
|
+
/**
|
|
578
|
+
* Add one explicit purge lock through the bound manager and renew identity
|
|
579
|
+
* activity. Locking never reloads or prepares a resource.
|
|
580
|
+
*
|
|
581
|
+
* @returns {number} New lock count, or `0` when this resource is detached.
|
|
582
|
+
*/
|
|
583
|
+
Lock() {
|
|
584
|
+
return this.__lifecycleController?.lock?.() || 0;
|
|
585
|
+
}
|
|
601
586
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
* @throws {TypeError} If the loader or reconstruction request is invalid.
|
|
612
|
-
*/
|
|
613
|
-
SetObjectLoader(loader = null, request = null) {
|
|
614
|
-
if (loader !== null && typeof loader !== "function") {
|
|
615
|
-
throw new TypeError("CjsResource.SetObjectLoader requires a function or null.");
|
|
616
|
-
}
|
|
617
|
-
if (request !== null && (!request || typeof request !== "object" || Array.isArray(request))) {
|
|
618
|
-
throw new TypeError("CjsResource.SetObjectLoader request must be an object or null.");
|
|
619
|
-
}
|
|
620
|
-
this.__objectLoader = loader;
|
|
621
|
-
this.__objectRequest = request === null ? null : Object.freeze({
|
|
622
|
-
...request
|
|
623
|
-
});
|
|
624
|
-
return this;
|
|
625
|
-
}
|
|
587
|
+
/**
|
|
588
|
+
* Release one explicit purge lock without allowing the count to underflow.
|
|
589
|
+
* Unlocking does not immediately purge or release a payload.
|
|
590
|
+
*
|
|
591
|
+
* @returns {number} Remaining lock count, or `0` when detached or unlocked.
|
|
592
|
+
*/
|
|
593
|
+
Unlock() {
|
|
594
|
+
return this.__lifecycleController?.unlock?.() || 0;
|
|
595
|
+
}
|
|
626
596
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
597
|
+
/**
|
|
598
|
+
* Bind the manager-owned object operation and compact reconstruction request
|
|
599
|
+
* for this shared resource handle. The request contains source provenance
|
|
600
|
+
* and requested-output defaults, not reader implementations or registry
|
|
601
|
+
* history.
|
|
602
|
+
*
|
|
603
|
+
* @param {Function|null} loader Manager callback, or `null` to detach it.
|
|
604
|
+
* @param {object|null} [request=null] Compact reconstruction defaults retained with the handle.
|
|
605
|
+
* @returns {CjsResource} This resource with the supplied loader binding.
|
|
606
|
+
* @throws {TypeError} If the loader or reconstruction request is invalid.
|
|
607
|
+
*/
|
|
608
|
+
SetObjectLoader(loader = null, request = null) {
|
|
609
|
+
if (loader !== null && typeof loader !== "function") {
|
|
610
|
+
throw new TypeError("CjsResource.SetObjectLoader requires a function or null.");
|
|
611
|
+
}
|
|
612
|
+
if (request !== null && (!request || typeof request !== "object" || Array.isArray(request))) {
|
|
613
|
+
throw new TypeError("CjsResource.SetObjectLoader request must be an object or null.");
|
|
614
|
+
}
|
|
615
|
+
this.__objectLoader = loader;
|
|
616
|
+
this.__objectRequest = request === null ? null : Object.freeze({
|
|
617
|
+
...request
|
|
618
|
+
});
|
|
619
|
+
return this;
|
|
620
|
+
}
|
|
637
621
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
* supplied here; operation policy such as cache/reload controls may still be
|
|
649
|
-
* overridden.
|
|
650
|
-
*
|
|
651
|
-
* @param {object} [options={}] Source, format, semantic outcome, and queue options forwarded to the manager.
|
|
652
|
-
* @returns {Promise<*>} In-flight, resident, or reconstructed object outcome.
|
|
653
|
-
*/
|
|
654
|
-
GetObject(options = {}) {
|
|
655
|
-
if (!this.__objectLoader) {
|
|
656
|
-
const error = new Error(`Resource has no object loader: ${this.path}`);
|
|
657
|
-
error.code = "CJS_RESOURCE_LOADER_UNBOUND";
|
|
658
|
-
return Promise.reject(error);
|
|
659
|
-
}
|
|
660
|
-
return this.__objectLoader(options);
|
|
661
|
-
}
|
|
622
|
+
/**
|
|
623
|
+
* Return the compact manager request retained for explicit reconstruction.
|
|
624
|
+
* This query is pure and exposes no reader, constructor, or implementation
|
|
625
|
+
* identity.
|
|
626
|
+
*
|
|
627
|
+
* @returns {Readonly<object>|null} Frozen reconstruction defaults, or `null` when unbound.
|
|
628
|
+
*/
|
|
629
|
+
GetObjectRequest() {
|
|
630
|
+
return this.__objectRequest;
|
|
631
|
+
}
|
|
662
632
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
633
|
+
/**
|
|
634
|
+
* Return the manager-owned object outcome for this resource identity.
|
|
635
|
+
* Concurrent callers share one in-flight operation. A resident payload is
|
|
636
|
+
* returned without source work; after explicit payload release, this call is
|
|
637
|
+
* an explicit reconstruction request and may load/prepare through the bound
|
|
638
|
+
* manager. This loader resolves the manager's current canonical identity, so
|
|
639
|
+
* on a purged handle it may answer with a different instance - use
|
|
640
|
+
* `KeepAlive()`/`Reload()` to revive this handle itself.
|
|
641
|
+
*
|
|
642
|
+
* Promised-output fields retained by the handle take precedence over fields
|
|
643
|
+
* supplied here; operation policy such as cache/reload controls may still be
|
|
644
|
+
* overridden.
|
|
645
|
+
*
|
|
646
|
+
* @param {object} [options={}] Source, format, semantic outcome, and queue options forwarded to the manager.
|
|
647
|
+
* @returns {Promise<*>} In-flight, resident, or reconstructed object outcome.
|
|
648
|
+
*/
|
|
649
|
+
GetObject(options = {}) {
|
|
650
|
+
if (!this.__objectLoader) {
|
|
651
|
+
const error = new Error(`Resource has no object loader: ${this.path}`);
|
|
652
|
+
error.code = "CJS_RESOURCE_LOADER_UNBOUND";
|
|
653
|
+
return Promise.reject(error);
|
|
654
|
+
}
|
|
655
|
+
return this.__objectLoader(options);
|
|
656
|
+
}
|
|
674
657
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
this.__adapterResources[String(key)] = value;
|
|
687
|
-
return this;
|
|
688
|
-
}
|
|
658
|
+
/**
|
|
659
|
+
* Promise-shaped alias for {@link CjsResource#GetObject}. Readiness shares an
|
|
660
|
+
* in-flight operation, returns resident payload without loading, and treats a
|
|
661
|
+
* call after payload release as an explicit reconstruction request.
|
|
662
|
+
*
|
|
663
|
+
* @param {object} [options={}] Source, format, semantic outcome, and queue options forwarded to the manager.
|
|
664
|
+
* @returns {Promise<*>} In-flight, resident, or reconstructed object outcome.
|
|
665
|
+
*/
|
|
666
|
+
Ready(options = {}) {
|
|
667
|
+
return this.GetObject(options);
|
|
668
|
+
}
|
|
689
669
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
670
|
+
/**
|
|
671
|
+
* Attach an opaque engine-owned resource object.
|
|
672
|
+
*
|
|
673
|
+
* Runtime-resource stores this value but does not inspect GPU APIs.
|
|
674
|
+
*
|
|
675
|
+
* @param {string} key
|
|
676
|
+
* @param {*} value
|
|
677
|
+
* @returns {CjsResource}
|
|
678
|
+
*/
|
|
679
|
+
SetAdapterResource(key, value) {
|
|
680
|
+
if (!key) throw new TypeError("CjsResource.SetAdapterResource requires a key.");
|
|
681
|
+
this.__adapterResources[String(key)] = value;
|
|
682
|
+
return this;
|
|
683
|
+
}
|
|
699
684
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
685
|
+
/**
|
|
686
|
+
* Get an opaque engine-owned resource object.
|
|
687
|
+
*
|
|
688
|
+
* @param {string} key
|
|
689
|
+
* @returns {*}
|
|
690
|
+
*/
|
|
691
|
+
GetAdapterResource(key) {
|
|
692
|
+
return this.__adapterResources[String(key)] ?? null;
|
|
693
|
+
}
|
|
709
694
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
const value = this.__adapterResources[name];
|
|
720
|
-
if (value && options.destroy !== false) {
|
|
721
|
-
destroyAdapterValue(value);
|
|
722
|
-
}
|
|
723
|
-
delete this.__adapterResources[name];
|
|
724
|
-
return this;
|
|
725
|
-
}
|
|
695
|
+
/**
|
|
696
|
+
* Returns true when an adapter resource exists for the given key.
|
|
697
|
+
*
|
|
698
|
+
* @param {string} key
|
|
699
|
+
* @returns {boolean}
|
|
700
|
+
*/
|
|
701
|
+
HasAdapterResource(key) {
|
|
702
|
+
return Object.prototype.hasOwnProperty.call(this.__adapterResources, String(key));
|
|
703
|
+
}
|
|
726
704
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
705
|
+
/**
|
|
706
|
+
* Remove an adapter resource and optionally call its destroy/dispose method.
|
|
707
|
+
*
|
|
708
|
+
* @param {string} key
|
|
709
|
+
* @param {object} options
|
|
710
|
+
* @returns {CjsResource}
|
|
711
|
+
*/
|
|
712
|
+
DestroyAdapterResource(key, options = {}) {
|
|
713
|
+
const name = String(key);
|
|
714
|
+
const value = this.__adapterResources[name];
|
|
715
|
+
if (value && options.destroy !== false) {
|
|
716
|
+
destroyAdapterValue(value);
|
|
717
|
+
}
|
|
718
|
+
delete this.__adapterResources[name];
|
|
719
|
+
return this;
|
|
720
|
+
}
|
|
743
721
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
State = Object.freeze({
|
|
722
|
+
/**
|
|
723
|
+
* Remove all adapter resources and optionally call their destroy/dispose methods.
|
|
724
|
+
*
|
|
725
|
+
* @param {object} options
|
|
726
|
+
* @returns {CjsResource}
|
|
727
|
+
*/
|
|
728
|
+
DestroyAdapterResources(options = {}) {
|
|
729
|
+
for (const key of Object.keys(this.__adapterResources)) {
|
|
730
|
+
this.DestroyAdapterResource(key, options);
|
|
731
|
+
}
|
|
732
|
+
return this;
|
|
733
|
+
}
|
|
734
|
+
static State = Object.freeze({
|
|
758
735
|
EMPTY: "empty",
|
|
759
736
|
REQUESTED: "requested",
|
|
760
737
|
LOADING: "loading",
|
|
@@ -765,10 +742,49 @@ new class extends _identity {
|
|
|
765
742
|
UNLOADED: "unloaded",
|
|
766
743
|
PURGED: "purged"
|
|
767
744
|
});
|
|
768
|
-
|
|
769
|
-
|
|
745
|
+
|
|
746
|
+
/** Returns true when a value belongs to the resource state vocabulary. */
|
|
747
|
+
static isValidState(state) {
|
|
748
|
+
return Object.values(CjsResource.State).includes(state);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Returns true when a resource state cannot continue its current operation.
|
|
753
|
+
*
|
|
754
|
+
* `PURGED` is deliberately absent: a purged resource reloads itself
|
|
755
|
+
* through `KeepAlive()`, so purge is a transition out of a settled state
|
|
756
|
+
* rather than a resting place.
|
|
757
|
+
*/
|
|
758
|
+
static isTerminalState(state) {
|
|
759
|
+
return state === CjsResource.State.PREPARED || state === CjsResource.State.FAILED || state === CjsResource.State.UNLOADED;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// Declared as data rather than with decorators, so the resource tree stays
|
|
764
|
+
// plain ESM that loads from source without a transform. Resources are not model
|
|
765
|
+
// graph nodes - there is no Copy or Clone here, and SetValues/GetValues are a
|
|
766
|
+
// flat schema-driven property copy - so nothing here needed the decorator form.
|
|
767
|
+
// Field order is key order, and GetValues() exports in that order.
|
|
768
|
+
CjsSchema.define(CjsResource, {
|
|
769
|
+
className: "CjsResource",
|
|
770
|
+
family: "resource",
|
|
771
|
+
fields: {
|
|
772
|
+
path: type.path,
|
|
773
|
+
ext: type.string,
|
|
774
|
+
requirement: type.string,
|
|
775
|
+
state: type.string
|
|
776
|
+
},
|
|
777
|
+
methods: {
|
|
778
|
+
Initialize: [carbon.method, impl.adapted],
|
|
779
|
+
GetPath: [carbon.method, impl.adapted],
|
|
780
|
+
GetExt: [carbon.method, impl.adapted],
|
|
781
|
+
IsLoading: [carbon.method, impl.adapted],
|
|
782
|
+
HasLoaded: [carbon.method, impl.adapted],
|
|
783
|
+
IsPrepared: [carbon.method, impl.adapted],
|
|
784
|
+
IsGood: [carbon.method, impl.adapted],
|
|
785
|
+
IsFailed: [carbon.method, impl.adapted]
|
|
770
786
|
}
|
|
771
|
-
}
|
|
787
|
+
});
|
|
772
788
|
function destroyAdapterValue(value) {
|
|
773
789
|
if (!value || typeof value !== "object") return;
|
|
774
790
|
const destroy = value.Destroy || value.Dispose || value.destroy || value.dispose;
|
|
@@ -777,5 +793,5 @@ function destroyAdapterValue(value) {
|
|
|
777
793
|
}
|
|
778
794
|
}
|
|
779
795
|
|
|
780
|
-
export {
|
|
796
|
+
export { CjsResource };
|
|
781
797
|
//# sourceMappingURL=CjsResource.js.map
|