@cyclonium/core 0.0.100

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.
Files changed (79) hide show
  1. package/lib/2d/transform-2d-component.d.ts +67 -0
  2. package/lib/2d/transform-2d-component.js +206 -0
  3. package/lib/decorator/legacy/apply-legacy-decorators.d.ts +5 -0
  4. package/lib/decorator/legacy/apply-legacy-decorators.js +12 -0
  5. package/lib/decorator/legacy/editable/common.d.ts +3 -0
  6. package/lib/decorator/legacy/editable/common.js +16 -0
  7. package/lib/decorator/legacy/editable/editable.d.ts +23 -0
  8. package/lib/decorator/legacy/editable/editable.js +61 -0
  9. package/lib/decorator/legacy/legacy-component-decorator.d.ts +11 -0
  10. package/lib/decorator/legacy/legacy-component-decorator.js +91 -0
  11. package/lib/decorator/legacy/legacy-decorator.d.ts +3 -0
  12. package/lib/decorator/legacy/legacy-decorator.js +3 -0
  13. package/lib/decorator/legacy/legacy-general-decorator.d.ts +32 -0
  14. package/lib/decorator/legacy/legacy-general-decorator.js +94 -0
  15. package/lib/decorator/legacy/utils.d.ts +6 -0
  16. package/lib/decorator/legacy/utils.js +17 -0
  17. package/lib/export/2d.d.ts +2 -0
  18. package/lib/export/2d.js +2 -0
  19. package/lib/export/framework.d.ts +4 -0
  20. package/lib/export/framework.js +4 -0
  21. package/lib/export/internal.d.ts +2 -0
  22. package/lib/export/internal.js +2 -0
  23. package/lib/export/legacy-decorator.d.ts +4 -0
  24. package/lib/export/legacy-decorator.js +4 -0
  25. package/lib/export/log.d.ts +2 -0
  26. package/lib/export/log.js +2 -0
  27. package/lib/export/math/bounds-2d.d.ts +2 -0
  28. package/lib/export/math/bounds-2d.js +2 -0
  29. package/lib/export/math/geometry.d.ts +2 -0
  30. package/lib/export/math/geometry.js +2 -0
  31. package/lib/export/math/mat3.d.ts +2 -0
  32. package/lib/export/math/mat3.js +2 -0
  33. package/lib/export/math/number.d.ts +2 -0
  34. package/lib/export/math/number.js +2 -0
  35. package/lib/export/math/ray.d.ts +2 -0
  36. package/lib/export/math/ray.js +2 -0
  37. package/lib/export/math/transform-2d.d.ts +2 -0
  38. package/lib/export/math/transform-2d.js +2 -0
  39. package/lib/export/math/trigonometry.d.ts +2 -0
  40. package/lib/export/math/trigonometry.js +2 -0
  41. package/lib/export/math/vec2.d.ts +2 -0
  42. package/lib/export/math/vec2.js +2 -0
  43. package/lib/export/utils.d.ts +5 -0
  44. package/lib/export/utils.js +5 -0
  45. package/lib/framework/component.d.ts +90 -0
  46. package/lib/framework/component.js +322 -0
  47. package/lib/framework/coroutine.d.ts +105 -0
  48. package/lib/framework/coroutine.js +278 -0
  49. package/lib/framework/execution-order.d.ts +12 -0
  50. package/lib/framework/execution-order.js +17 -0
  51. package/lib/framework/tasking.d.ts +17 -0
  52. package/lib/framework/tasking.js +82 -0
  53. package/lib/math/bounds-2d.d.ts +2 -0
  54. package/lib/math/bounds-2d.js +13 -0
  55. package/lib/math/geometry.d.ts +4 -0
  56. package/lib/math/geometry.js +19 -0
  57. package/lib/math/mat3.d.ts +2 -0
  58. package/lib/math/mat3.js +2 -0
  59. package/lib/math/number.d.ts +2 -0
  60. package/lib/math/number.js +2 -0
  61. package/lib/math/ray.d.ts +12 -0
  62. package/lib/math/ray.js +26 -0
  63. package/lib/math/transform-2d.d.ts +2 -0
  64. package/lib/math/transform-2d.js +2 -0
  65. package/lib/math/trigonometry.d.ts +2 -0
  66. package/lib/math/trigonometry.js +2 -0
  67. package/lib/math/vec2.d.ts +5 -0
  68. package/lib/math/vec2.js +17 -0
  69. package/lib/utils/assert.d.ts +5 -0
  70. package/lib/utils/assert.js +14 -0
  71. package/lib/utils/enum.d.ts +3 -0
  72. package/lib/utils/enum.js +15 -0
  73. package/lib/utils/inheritance.d.ts +2 -0
  74. package/lib/utils/inheritance.js +5 -0
  75. package/lib/utils/logger.d.ts +7 -0
  76. package/lib/utils/logger.js +19 -0
  77. package/lib/utils/raw.d.ts +6 -0
  78. package/lib/utils/raw.js +26 -0
  79. package/package.json +44 -0
@@ -0,0 +1,4 @@
1
+ export { CycloComponent } from '../framework/component.ts';
2
+ export { nextFrame, waitFor, waitUntil, waitWhile, type Coroutine, type CoroutineFrame, type CoroutineInstruction, type CoroutineIterator, type CoroutinePredicate, type StartCoroutineOptions, } from '../framework/coroutine.ts';
3
+ export { PredefinedExecutionOrder } from '../framework/execution-order.ts';
4
+ //# sourceMappingURL=framework.d.ts.map
@@ -0,0 +1,4 @@
1
+ export { CycloComponent } from "../framework/component.js";
2
+ export { nextFrame, waitFor, waitUntil, waitWhile, } from "../framework/coroutine.js";
3
+ export { PredefinedExecutionOrder } from "../framework/execution-order.js";
4
+ //# sourceMappingURL=framework.js.map
@@ -0,0 +1,2 @@
1
+ export { cycloBuiltinClass } from '../decorator/legacy/legacy-decorator.ts';
2
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { cycloBuiltinClass } from "../decorator/legacy/legacy-decorator.js";
2
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1,4 @@
1
+ export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy, serializable, type CycloClassOptions, type CycloClassDecorator, } from '../decorator/legacy/legacy-general-decorator.ts';
2
+ export { executionOrder, executeInEditMode, requiresComponent, } from '../decorator/legacy/legacy-component-decorator.ts';
3
+ export { applyLegacyDecorators } from '../decorator/legacy/apply-legacy-decorators.ts';
4
+ //# sourceMappingURL=legacy-decorator.d.ts.map
@@ -0,0 +1,4 @@
1
+ export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy, serializable, } from "../decorator/legacy/legacy-general-decorator.js";
2
+ export { executionOrder, executeInEditMode, requiresComponent, } from "../decorator/legacy/legacy-component-decorator.js";
3
+ export { applyLegacyDecorators } from "../decorator/legacy/apply-legacy-decorators.js";
4
+ //# sourceMappingURL=legacy-decorator.js.map
@@ -0,0 +1,2 @@
1
+ export { logger } from '../utils/logger.ts';
2
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { logger } from "../utils/logger.js";
2
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/bounds-2d.js';
2
+ //# sourceMappingURL=bounds-2d.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/bounds-2d.js';
2
+ //# sourceMappingURL=bounds-2d.js.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/geometry.ts';
2
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../math/geometry.js";
2
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/mat3.ts';
2
+ //# sourceMappingURL=mat3.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../math/mat3.js";
2
+ //# sourceMappingURL=mat3.js.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/number.ts';
2
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../math/number.js";
2
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/ray.ts';
2
+ //# sourceMappingURL=ray.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../math/ray.js";
2
+ //# sourceMappingURL=ray.js.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/transform-2d.ts';
2
+ //# sourceMappingURL=transform-2d.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../math/transform-2d.js";
2
+ //# sourceMappingURL=transform-2d.js.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/trigonometry.ts';
2
+ //# sourceMappingURL=trigonometry.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../math/trigonometry.js";
2
+ //# sourceMappingURL=trigonometry.js.map
@@ -0,0 +1,2 @@
1
+ export * from '../../math/vec2.ts';
2
+ //# sourceMappingURL=vec2.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../math/vec2.js";
2
+ //# sourceMappingURL=vec2.js.map
@@ -0,0 +1,5 @@
1
+ export { assert } from '../utils/assert.ts';
2
+ export { markEnum, DynamicEnum } from '../utils/enum.ts';
3
+ export { isSubClassOfInclusive } from '../utils/inheritance.ts';
4
+ export { dumpRaw } from '../utils/raw.ts';
5
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,5 @@
1
+ export { assert } from "../utils/assert.js";
2
+ export { markEnum, DynamicEnum } from "../utils/enum.js";
3
+ export { isSubClassOfInclusive } from "../utils/inheritance.js";
4
+ export { dumpRaw } from "../utils/raw.js";
5
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,90 @@
1
+ import { Component, Node } from 'cc';
2
+ import { AbortSignal } from '@cyclonium/abort-controller';
3
+ import { type Coroutine, type CoroutineIterator, type StartCoroutineOptions } from './coroutine.ts';
4
+ export declare class CycloComponent extends Component {
5
+ static of<TThis extends abstract new (...args: never[]) => CycloComponent>(this: TThis, componentOrNode: CycloComponent | Node): InstanceType<TThis>;
6
+ static ofOrNull<TThis extends abstract new (...args: never[]) => CycloComponent>(this: TThis, componentOrNode: CycloComponent | Node): InstanceType<TThis> | null;
7
+ static existsOn<TThis extends abstract new (...args: never[]) => CycloComponent>(this: TThis, componentOrNode: CycloComponent | Node): boolean;
8
+ /**
9
+ * @internal
10
+ */
11
+ _invokeFixedUpdate(deltaTime: number): void;
12
+ /**
13
+ * @internal
14
+ */
15
+ _invokeCoroutineUpdate(deltaTime: number): void;
16
+ protected get destroyingSignal(): AbortSignal;
17
+ protected get disablingSignal(): AbortSignal;
18
+ protected onAwake(): void;
19
+ protected onEnabled(): void;
20
+ protected onDisabled(): void;
21
+ protected onDestroy(): void;
22
+ protected onStart(): void;
23
+ protected onUpdate(_deltaTime: number): void;
24
+ protected onFixedUpdate(_deltaTime: number): void;
25
+ protected onLateUpdate(_deltaTime: number): void;
26
+ protected onFrameEnd(): void;
27
+ /**
28
+ * Starts a coroutine owned by this component.
29
+ * @param coroutine - Coroutine iterator to start.
30
+ * @param opts - Optional start options, including an abort signal that can stop the coroutine.
31
+ * @returns An opaque coroutine handle that can be passed to `stopCoroutine`.
32
+ * @description
33
+ * The coroutine starts immediately and runs until its first yield before this
34
+ * method returns. Component `enabled = false` does not pause it; it is stopped
35
+ * when the owning node becomes inactive in hierarchy or when the component is destroyed.
36
+ * Coroutines resume after all component `onUpdate` calls and before fixed updates.
37
+ * @example
38
+ * ```ts
39
+ * protected override onStart(): void {
40
+ * this.startCoroutine(this.destroyLater());
41
+ * }
42
+ *
43
+ * private *destroyLater(): CoroutineIterator {
44
+ * yield waitFor(1);
45
+ * this.node.destroy();
46
+ * }
47
+ * ```
48
+ */
49
+ protected startCoroutine(coroutine: CoroutineIterator, opts?: StartCoroutineOptions): Coroutine;
50
+ /**
51
+ * Stops a coroutine handle.
52
+ * @param coroutine - Coroutine handle returned by `startCoroutine`.
53
+ * @description
54
+ * Stopping marks the coroutine so it will not resume on later frames. If this
55
+ * is called while that same coroutine is currently executing, it does not abort
56
+ * the current call stack; code after the stop call keeps running until the
57
+ * coroutine yields or returns.
58
+ */
59
+ protected stopCoroutine(coroutine: Coroutine): void;
60
+ /**
61
+ * Stops all coroutines owned by this component.
62
+ * @description
63
+ * Existing coroutines are marked as stopped and will not resume on later frames.
64
+ * Calling this from inside a coroutine does not abort the current call stack;
65
+ * the currently executing body keeps running until it yields or returns.
66
+ * Coroutines started during stop cleanup are treated as new coroutines and are
67
+ * not included in the batch being stopped.
68
+ */
69
+ protected stopAllCoroutines(): void;
70
+ protected onLoad(): void;
71
+ /**
72
+ * @internal
73
+ */
74
+ protected onEnable(): void;
75
+ /**
76
+ * @internal
77
+ */
78
+ protected onDisable(): void;
79
+ protected start(): void;
80
+ protected lateUpdate(deltaTime: number): void;
81
+ /**
82
+ * @deprecated
83
+ */
84
+ protected update(deltaTime: number): void;
85
+ private _coroutines;
86
+ private _disablingController;
87
+ private _destroyingController;
88
+ private _clearCoroutinesIfEmpty;
89
+ }
90
+ //# sourceMappingURL=component.d.ts.map
@@ -0,0 +1,322 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var CycloComponent_1;
8
+ import { Component, director, Node } from 'cc';
9
+ import { cycloBuiltinClass } from "../decorator/legacy/legacy-general-decorator.js";
10
+ import { AbortController, AbortSignal } from '@cyclonium/abort-controller';
11
+ import { addFrameTask, TaskPriority } from "./tasking.js";
12
+ import { CoroutineRunner, stopCoroutine as stopCoroutineRecord } from "./coroutine.js";
13
+ import { prune } from '@cyclonium/algorithm/prune';
14
+ import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
15
+ class ComponentScheduler {
16
+ enableComponent(component) {
17
+ const index = this._fixedUpdateRegistry.findIndex(({ component: c }) => c === component);
18
+ if (index < 0) {
19
+ this._fixedUpdateRegistry.push({ component, enabled: true });
20
+ }
21
+ else {
22
+ this._fixedUpdateRegistry[index].enabled = true;
23
+ }
24
+ }
25
+ disableComponent(component) {
26
+ const index = this._fixedUpdateRegistry.findIndex(({ component: c }) => c === component);
27
+ if (index >= 0) {
28
+ this._fixedUpdateRegistry[index].enabled = false;
29
+ }
30
+ }
31
+ prune() {
32
+ prune(this._fixedUpdateRegistry, ({ enabled }) => enabled);
33
+ prune(this._coroutineUpdateRegistry, ({ enabled }) => enabled);
34
+ }
35
+ invokeFixedUpdate(deltaTime) {
36
+ for (const { component, enabled } of this._fixedUpdateRegistry) {
37
+ if (enabled) {
38
+ invokeComponentFixedUpdate(component, deltaTime);
39
+ }
40
+ }
41
+ }
42
+ enableCoroutineUpdate(component) {
43
+ const index = this._coroutineUpdateRegistry.findIndex(({ component: c }) => c === component);
44
+ if (index < 0) {
45
+ this._coroutineUpdateRegistry.push({ component, enabled: true });
46
+ }
47
+ else {
48
+ this._coroutineUpdateRegistry[index].enabled = true;
49
+ }
50
+ }
51
+ disableCoroutineUpdate(component) {
52
+ const index = this._coroutineUpdateRegistry.findIndex(({ component: c }) => c === component);
53
+ if (index >= 0) {
54
+ this._coroutineUpdateRegistry[index].enabled = false;
55
+ }
56
+ }
57
+ invokeCoroutineUpdate(deltaTime) {
58
+ const count = this._coroutineUpdateRegistry.length;
59
+ for (let i = 0; i < count; i++) {
60
+ const { component, enabled } = this._coroutineUpdateRegistry[i];
61
+ if (enabled) {
62
+ invokeComponentCoroutineUpdate(component, deltaTime);
63
+ }
64
+ }
65
+ }
66
+ _fixedUpdateRegistry = [];
67
+ _coroutineUpdateRegistry = [];
68
+ }
69
+ const globalComponentScheduler = new ComponentScheduler();
70
+ let invokeComponentFixedUpdate;
71
+ let invokeComponentCoroutineUpdate;
72
+ let CycloComponent = class CycloComponent extends Component {
73
+ static { CycloComponent_1 = this; }
74
+ static of(componentOrNode) {
75
+ const instance = (componentOrNode instanceof Component ? componentOrNode.node : componentOrNode).getComponent(this);
76
+ if (!instance) {
77
+ throw new Error(`Component ${this.name} is not attached to entity ${componentOrNode.name}.`);
78
+ }
79
+ return instance;
80
+ }
81
+ static ofOrNull(componentOrNode) {
82
+ return (componentOrNode instanceof Component ? componentOrNode.node : componentOrNode).getComponent(this) ?? null;
83
+ }
84
+ static existsOn(componentOrNode) {
85
+ return !!((componentOrNode instanceof Component ? componentOrNode.node : componentOrNode).getComponent(this));
86
+ }
87
+ /**
88
+ * @internal
89
+ */
90
+ _invokeFixedUpdate(deltaTime) {
91
+ this.onFixedUpdate(deltaTime);
92
+ }
93
+ /**
94
+ * @internal
95
+ */
96
+ _invokeCoroutineUpdate(deltaTime) {
97
+ if (!this._coroutines) {
98
+ return;
99
+ }
100
+ if (!this.node.activeInHierarchy) {
101
+ this.stopAllCoroutines();
102
+ return;
103
+ }
104
+ this._coroutines.update(deltaTime);
105
+ this._clearCoroutinesIfEmpty();
106
+ }
107
+ get destroyingSignal() {
108
+ return (this._destroyingController ??= new AbortController()).signal;
109
+ }
110
+ get disablingSignal() {
111
+ return (this._disablingController ??= new AbortController()).signal;
112
+ }
113
+ onAwake() { }
114
+ onEnabled() { }
115
+ onDisabled() { }
116
+ onDestroy() {
117
+ this.stopAllCoroutines();
118
+ this._destroyingController?.abort();
119
+ this._destroyingController = undefined;
120
+ }
121
+ onStart() { }
122
+ onUpdate(_deltaTime) { }
123
+ onFixedUpdate(_deltaTime) { }
124
+ onLateUpdate(_deltaTime) { }
125
+ onFrameEnd() { }
126
+ /**
127
+ * Starts a coroutine owned by this component.
128
+ * @param coroutine - Coroutine iterator to start.
129
+ * @param opts - Optional start options, including an abort signal that can stop the coroutine.
130
+ * @returns An opaque coroutine handle that can be passed to `stopCoroutine`.
131
+ * @description
132
+ * The coroutine starts immediately and runs until its first yield before this
133
+ * method returns. Component `enabled = false` does not pause it; it is stopped
134
+ * when the owning node becomes inactive in hierarchy or when the component is destroyed.
135
+ * Coroutines resume after all component `onUpdate` calls and before fixed updates.
136
+ * @example
137
+ * ```ts
138
+ * protected override onStart(): void {
139
+ * this.startCoroutine(this.destroyLater());
140
+ * }
141
+ *
142
+ * private *destroyLater(): CoroutineIterator {
143
+ * yield waitFor(1);
144
+ * this.node.destroy();
145
+ * }
146
+ * ```
147
+ */
148
+ startCoroutine(coroutine, opts) {
149
+ const coroutines = this._coroutines ??= new CoroutineRunner();
150
+ const handle = coroutines.start(coroutine, opts);
151
+ if (!coroutines.empty) {
152
+ globalComponentScheduler.enableCoroutineUpdate(this);
153
+ }
154
+ this._clearCoroutinesIfEmpty();
155
+ return handle;
156
+ }
157
+ /**
158
+ * Stops a coroutine handle.
159
+ * @param coroutine - Coroutine handle returned by `startCoroutine`.
160
+ * @description
161
+ * Stopping marks the coroutine so it will not resume on later frames. If this
162
+ * is called while that same coroutine is currently executing, it does not abort
163
+ * the current call stack; code after the stop call keeps running until the
164
+ * coroutine yields or returns.
165
+ */
166
+ stopCoroutine(coroutine) {
167
+ if (this._coroutines) {
168
+ this._coroutines.stop(coroutine);
169
+ }
170
+ else {
171
+ stopCoroutineRecord(coroutine);
172
+ }
173
+ this._clearCoroutinesIfEmpty();
174
+ }
175
+ /**
176
+ * Stops all coroutines owned by this component.
177
+ * @description
178
+ * Existing coroutines are marked as stopped and will not resume on later frames.
179
+ * Calling this from inside a coroutine does not abort the current call stack;
180
+ * the currently executing body keeps running until it yields or returns.
181
+ * Coroutines started during stop cleanup are treated as new coroutines and are
182
+ * not included in the batch being stopped.
183
+ */
184
+ stopAllCoroutines() {
185
+ const coroutines = this._coroutines;
186
+ if (!coroutines) {
187
+ return;
188
+ }
189
+ this._coroutines = undefined;
190
+ globalComponentScheduler.disableCoroutineUpdate(this);
191
+ coroutines.stopAll();
192
+ }
193
+ onLoad() {
194
+ this.onAwake();
195
+ }
196
+ /**
197
+ * @internal
198
+ */
199
+ onEnable() {
200
+ globalComponentScheduler.enableComponent(this);
201
+ this.onEnabled();
202
+ }
203
+ /**
204
+ * @internal
205
+ */
206
+ onDisable() {
207
+ globalComponentScheduler.disableComponent(this);
208
+ if (!this.node.activeInHierarchy) {
209
+ this.stopAllCoroutines();
210
+ }
211
+ this.onDisabled();
212
+ this._disablingController?.abort();
213
+ this._disablingController = undefined;
214
+ }
215
+ start() {
216
+ this.onStart();
217
+ }
218
+ lateUpdate(deltaTime) {
219
+ this.onLateUpdate(deltaTime);
220
+ this.onFrameEnd();
221
+ }
222
+ /**
223
+ * @deprecated
224
+ */
225
+ update(deltaTime) {
226
+ this.onUpdate(deltaTime);
227
+ }
228
+ _coroutines = undefined;
229
+ _disablingController = undefined;
230
+ _destroyingController = undefined;
231
+ _clearCoroutinesIfEmpty() {
232
+ if (this._coroutines?.empty) {
233
+ this._coroutines = undefined;
234
+ globalComponentScheduler.disableCoroutineUpdate(this);
235
+ }
236
+ }
237
+ static {
238
+ invokeComponentFixedUpdate = (component, deltaTime) => {
239
+ if (component.onFixedUpdate !== CycloComponent_1.prototype.onFixedUpdate) {
240
+ component.onFixedUpdate(deltaTime);
241
+ }
242
+ };
243
+ invokeComponentCoroutineUpdate = (component, deltaTime) => {
244
+ component._invokeCoroutineUpdate(deltaTime);
245
+ };
246
+ }
247
+ };
248
+ CycloComponent = CycloComponent_1 = __decorate([
249
+ cycloBuiltinClass({ abstract: true })
250
+ ], CycloComponent);
251
+ export { CycloComponent };
252
+ class CoroutineUpdateTask {
253
+ update(deltaTime) {
254
+ globalComponentScheduler.invokeCoroutineUpdate(deltaTime);
255
+ }
256
+ }
257
+ class FixedUpdateTask {
258
+ maxSteps = 2;
259
+ update(deltaTime) {
260
+ const scene = director.getScene();
261
+ if (!scene) {
262
+ this._accumulatedTime = 0;
263
+ return;
264
+ }
265
+ const fixedTimeStep = this._fixedTimeStep;
266
+ const maxSteps = this.maxSteps;
267
+ const accumulatedTime = this._accumulatedTime + deltaTime;
268
+ const expectedSteps = Math.floor(accumulatedTime / fixedTimeStep);
269
+ const overloading = expectedSteps > maxSteps;
270
+ const previousOverloading = this._overloading;
271
+ this._overloading = overloading;
272
+ let actualSteps = 0;
273
+ if (overloading) {
274
+ actualSteps = maxSteps;
275
+ this._accumulatedTime = 0;
276
+ if (overloading !== previousOverloading) {
277
+ this._emitOverloadingBegin(expectedSteps);
278
+ }
279
+ }
280
+ else {
281
+ actualSteps = expectedSteps;
282
+ this._accumulatedTime = accumulatedTime - actualSteps * fixedTimeStep;
283
+ if (overloading !== previousOverloading) {
284
+ this._emitOverloadingEnd();
285
+ }
286
+ }
287
+ for (let i = 0; i < actualSteps; i++) {
288
+ globalComponentScheduler.invokeFixedUpdate(fixedTimeStep);
289
+ }
290
+ }
291
+ _fixedTimeStep = 1 / 60;
292
+ _accumulatedTime = 0;
293
+ _overloading = false;
294
+ _emitOverloadingBegin(expectedSteps) {
295
+ // todo
296
+ void expectedSteps;
297
+ }
298
+ _emitOverloadingEnd() {
299
+ // todo
300
+ }
301
+ }
302
+ if (!EDITOR_NOT_IN_PREVIEW) {
303
+ const fixedUpdatePriority = TaskPriority.before(TaskPriority.predefined.componentsLateUpdate);
304
+ addFrameTask({
305
+ thisArg: new CoroutineUpdateTask(),
306
+ priority: TaskPriority.between(fixedUpdatePriority, TaskPriority.predefined.componentsLateUpdate),
307
+ fn: CoroutineUpdateTask.prototype.update,
308
+ });
309
+ addFrameTask({
310
+ thisArg: new FixedUpdateTask(),
311
+ priority: fixedUpdatePriority,
312
+ fn: FixedUpdateTask.prototype.update,
313
+ });
314
+ addFrameTask({
315
+ thisArg: undefined,
316
+ priority: TaskPriority.after(TaskPriority.predefined.componentsLateUpdate),
317
+ fn: () => {
318
+ globalComponentScheduler.prune();
319
+ },
320
+ });
321
+ }
322
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1,105 @@
1
+ import type { AbortSignal } from '@cyclonium/abort-controller';
2
+ /**
3
+ * Frame data passed back when a coroutine resumes.
4
+ */
5
+ export interface CoroutineFrame {
6
+ /**
7
+ * Time elapsed since the previous coroutine update, in seconds.
8
+ */
9
+ readonly deltaTime: number;
10
+ /**
11
+ * Time elapsed since this coroutine started, in seconds.
12
+ */
13
+ readonly elapsedTime: number;
14
+ /**
15
+ * Number of coroutine update frames since the owner component started running coroutines.
16
+ */
17
+ readonly frame: number;
18
+ }
19
+ declare const CoroutineBrand: unique symbol;
20
+ /**
21
+ * Handle returned by `startCoroutine`.
22
+ * @description
23
+ * This is an opaque handle. Store it if you need to stop the coroutine later,
24
+ * and pass it back to `stopCoroutine`; do not inspect or construct it yourself.
25
+ */
26
+ export interface Coroutine {
27
+ readonly [CoroutineBrand]: never;
28
+ }
29
+ /**
30
+ * Yield instruction returned by coroutine wait helpers.
31
+ * @description
32
+ * This is an opaque token produced by helpers such as `nextFrame` and `waitFor`.
33
+ * Yield it from a coroutine to tell the scheduler when the coroutine should resume.
34
+ */
35
+ export interface CoroutineInstruction {
36
+ readonly __brand: unique symbol;
37
+ }
38
+ /**
39
+ * Iterator shape accepted by `startCoroutine`.
40
+ * @description
41
+ * A coroutine yields `CoroutineInstruction`, `null`, or `undefined`. When it resumes,
42
+ * the yielded expression receives a `CoroutineFrame` describing the current frame.
43
+ */
44
+ export type CoroutineIterator = IterableIterator<CoroutineYield, void, CoroutineFrame>;
45
+ /**
46
+ * Predicate evaluated with the current coroutine frame.
47
+ * @param frame - The frame data for the coroutine update being evaluated.
48
+ */
49
+ export type CoroutinePredicate = (frame: CoroutineFrame) => boolean;
50
+ type CoroutineYield = CoroutineInstruction | null | undefined;
51
+ /**
52
+ * Options used when starting a coroutine.
53
+ */
54
+ export interface StartCoroutineOptions {
55
+ /**
56
+ * Abort signal that stops the coroutine when aborted.
57
+ * @description
58
+ * If the signal is already aborted, the coroutine is stopped immediately after creation.
59
+ * Aborting the signal later has the same effect as stopping this coroutine handle.
60
+ */
61
+ readonly signal?: AbortSignal;
62
+ }
63
+ /**
64
+ * Resume the coroutine on the next coroutine update.
65
+ * @returns An opaque instruction to yield from a coroutine.
66
+ */
67
+ export declare function nextFrame(): CoroutineInstruction;
68
+ /**
69
+ * Resume the coroutine after at least the given duration.
70
+ * @param seconds - Duration to wait, in seconds. Must be a non-negative finite number.
71
+ * @returns An opaque instruction to yield from a coroutine.
72
+ */
73
+ export declare function waitFor(seconds: number): CoroutineInstruction;
74
+ /**
75
+ * Resume the coroutine when the predicate becomes true.
76
+ * @param predicate - Function evaluated each coroutine update with the current frame.
77
+ * @returns An opaque instruction to yield from a coroutine.
78
+ */
79
+ export declare function waitUntil(predicate: CoroutinePredicate): CoroutineInstruction;
80
+ /**
81
+ * Resume the coroutine when the predicate becomes false.
82
+ * @param predicate - Function evaluated each coroutine update with the current frame.
83
+ * @returns An opaque instruction to yield from a coroutine.
84
+ */
85
+ export declare function waitWhile(predicate: CoroutinePredicate): CoroutineInstruction;
86
+ export declare class CoroutineRunner {
87
+ start(coroutine: CoroutineIterator, opts?: StartCoroutineOptions): Coroutine;
88
+ update(deltaTime: number): void;
89
+ stop(handle: Coroutine): void;
90
+ stopAll(): void;
91
+ get frame(): number;
92
+ get deltaTime(): number;
93
+ get empty(): boolean;
94
+ private _records;
95
+ private _frame;
96
+ private _deltaTime;
97
+ private _pruneDeferralDepth;
98
+ private _beginPruneDeferral;
99
+ private _endPruneDeferral;
100
+ private _pruneIfNotDeferred;
101
+ private _prune;
102
+ }
103
+ export declare function stopCoroutine(coroutine: Coroutine): void;
104
+ export {};
105
+ //# sourceMappingURL=coroutine.d.ts.map