@cyclonium/core 0.0.104 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/2d/transform-2d-component.d.ts +1 -1
- package/lib/2d/transform-2d-component.js +1 -2
- package/lib/decorator/legacy/editable/common.js +3 -1
- package/lib/decorator/legacy/editable/editable.d.ts +2 -2
- package/lib/decorator/legacy/editable/editable.js +1 -3
- package/lib/decorator/legacy/legacy-component-decorator.d.ts +2 -2
- package/lib/decorator/legacy/legacy-component-decorator.js +5 -7
- package/lib/decorator/legacy/legacy-general-decorator.d.ts +1 -1
- package/lib/decorator/legacy/legacy-general-decorator.js +1 -1
- package/lib/decorator/legacy/utils.d.ts +3 -3
- package/lib/decorator/legacy/utils.js +1 -1
- package/lib/export/internal.d.ts +1 -0
- package/lib/export/internal.js +1 -0
- package/lib/export/legacy-decorator.d.ts +1 -1
- package/lib/export/legacy-decorator.js +1 -1
- package/lib/framework/component.js +39 -27
- package/lib/framework/coroutine.d.ts +3 -3
- package/lib/framework/coroutine.js +10 -10
- package/lib/framework/tasking.d.ts +1 -1
- package/lib/framework/tasking.js +5 -2
- package/lib/framework/time-accumulator.d.ts +10 -0
- package/lib/framework/time-accumulator.js +29 -0
- package/lib/math/bounds-2d.js +4 -4
- package/lib/math/vec2.js +4 -4
- package/lib/utils/assert.js +0 -1
- package/lib/utils/raw.js +3 -1
- package/package.json +1 -1
|
@@ -12,7 +12,6 @@ import { Mat3 } from "../math/mat3.js";
|
|
|
12
12
|
import { mat3FromSRT } from "../math/transform-2d.js";
|
|
13
13
|
import { Vec2 } from "../math/vec2.js";
|
|
14
14
|
import { to0ToPI2 } from "../math/trigonometry.js";
|
|
15
|
-
import { logger } from "../utils/logger.js";
|
|
16
15
|
import { clamp } from "../math/number.js";
|
|
17
16
|
export var TransformFlag;
|
|
18
17
|
(function (TransformFlag) {
|
|
@@ -21,10 +20,10 @@ export var TransformFlag;
|
|
|
21
20
|
TransformFlag[TransformFlag["scale"] = 4] = "scale";
|
|
22
21
|
})(TransformFlag || (TransformFlag = {}));
|
|
23
22
|
class TransformChangeFlags {
|
|
23
|
+
frontValue = 0;
|
|
24
24
|
get token() {
|
|
25
25
|
return this._token;
|
|
26
26
|
}
|
|
27
|
-
frontValue = 0;
|
|
28
27
|
get backValue() {
|
|
29
28
|
return this._backValue;
|
|
30
29
|
}
|
|
@@ -3,6 +3,7 @@ export function createDecoratorForSetEditableMetadata(opts) {
|
|
|
3
3
|
return (target, propertyKey, descriptor) => {
|
|
4
4
|
const normalizedOptions = {
|
|
5
5
|
...opts,
|
|
6
|
+
serializable: false,
|
|
6
7
|
};
|
|
7
8
|
if (normalizedOptions.visible === undefined) {
|
|
8
9
|
if (typeof propertyKey === 'string' && propertyKey.startsWith('_')) {
|
|
@@ -10,7 +11,8 @@ export function createDecoratorForSetEditableMetadata(opts) {
|
|
|
10
11
|
normalizedOptions.displayName = propertyKey.slice(1);
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
_decorator.property(normalizedOptions)(target, propertyKey, descriptor);
|
|
15
|
+
_decorator.editable(target, propertyKey, descriptor);
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
//# sourceMappingURL=common.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CCInteger, type CCBoolean, type
|
|
1
|
+
import { CCInteger, type CCBoolean, type CCString } from 'cc';
|
|
2
2
|
export interface EditableDecoratorOptions {
|
|
3
3
|
type?: Function | typeof CCInteger;
|
|
4
4
|
min?: number;
|
|
@@ -17,7 +17,7 @@ export interface EditableDecoratorOptions {
|
|
|
17
17
|
}
|
|
18
18
|
declare function editable(options?: EditableDecoratorOptions): PropertyDecorator;
|
|
19
19
|
declare function editable(type?: Function): PropertyDecorator;
|
|
20
|
-
declare function editable(type?: typeof CCInteger | typeof CCBoolean | typeof
|
|
20
|
+
declare function editable(type?: typeof CCInteger | typeof CCBoolean | typeof CCString): PropertyDecorator;
|
|
21
21
|
declare function editable(target: object, propertyKey: string | symbol): void;
|
|
22
22
|
export { editable };
|
|
23
23
|
//# sourceMappingURL=editable.d.ts.map
|
|
@@ -50,9 +50,7 @@ function editableWithOptions(options) {
|
|
|
50
50
|
modifiedOptions.min = 0;
|
|
51
51
|
modifiedOptions.max = Math.PI * 2;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
modifiedOptions.step = 1;
|
|
55
|
-
}
|
|
53
|
+
modifiedOptions.step ??= 1;
|
|
56
54
|
}
|
|
57
55
|
createDecoratorForSetEditableMetadata(modifiedOptions)(...args);
|
|
58
56
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Component } from 'cc';
|
|
1
|
+
import { Component, type Constructor } from 'cc';
|
|
2
2
|
import { CycloComponent } from '../../framework/component.ts';
|
|
3
3
|
export declare function executionOrder(order: number): ClassDecorator;
|
|
4
4
|
export declare namespace executionOrder {
|
|
5
5
|
function lateThan(component: CycloComponentClass): ClassDecorator;
|
|
6
6
|
}
|
|
7
7
|
export declare const executeInEditMode: ((value?: boolean) => ClassDecorator) & ClassDecorator;
|
|
8
|
-
export declare function requiresComponent<T extends Component>(componentType:
|
|
8
|
+
export declare function requiresComponent<T extends Component>(componentType: Constructor<T>): MethodDecorator;
|
|
9
9
|
type CycloComponentClass = new (...args: never[]) => CycloComponent;
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=legacy-component-decorator.d.ts.map
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { _decorator, Component } from 'cc';
|
|
3
3
|
import { CycloComponent } from "../../framework/component.js";
|
|
4
4
|
import { getExecutionOrder, setExecutionOrder } from "../../framework/execution-order.js";
|
|
5
|
-
import { logger } from "../../utils/logger.js";
|
|
6
5
|
export function executionOrder(order) {
|
|
7
6
|
return defineComponentDecorator((target) => {
|
|
8
7
|
setExecutionOrder(target, order);
|
|
@@ -36,17 +35,16 @@ function addRequiredComponent(target, componentType) {
|
|
|
36
35
|
export function requiresComponent(componentType) {
|
|
37
36
|
return defineComponentMethodDecorator((target, propertyKey, descriptor) => {
|
|
38
37
|
addRequiredComponent(target, componentType);
|
|
39
|
-
|
|
40
|
-
if (set) {
|
|
38
|
+
if (descriptor.set !== undefined) {
|
|
41
39
|
throw new Error(`Property ${String(propertyKey)} of should not has set`);
|
|
42
40
|
}
|
|
43
|
-
if (value !== undefined) {
|
|
41
|
+
if (descriptor.value !== undefined) {
|
|
44
42
|
throw new Error(`Property ${String(propertyKey)} of should not has value`);
|
|
45
43
|
}
|
|
46
44
|
return {
|
|
47
|
-
|
|
45
|
+
configurable: descriptor.configurable,
|
|
46
|
+
enumerable: descriptor.enumerable,
|
|
48
47
|
get() {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
48
|
const component = this.getComponent(componentType);
|
|
51
49
|
if (!component) {
|
|
52
50
|
throw new Error(`Component ${componentType.name} is not found.`);
|
|
@@ -82,7 +80,7 @@ function defineComponentDecoratorWithOptionalBoolean(decorate) {
|
|
|
82
80
|
function defineComponentMethodDecorator(decorate) {
|
|
83
81
|
return (target, propertyKey, descriptor) => {
|
|
84
82
|
if (!(target instanceof CycloComponent)) {
|
|
85
|
-
throw new Error(`Class ${target} is not a subclass of CycloComponent.`);
|
|
83
|
+
throw new Error(`Class ${String(target)} is not a subclass of CycloComponent.`);
|
|
86
84
|
}
|
|
87
85
|
return decorate(target, propertyKey, descriptor);
|
|
88
86
|
};
|
|
@@ -16,7 +16,7 @@ export declare function createScopedCycloClassDecorator(opts: {
|
|
|
16
16
|
declare const cycloClass: CycloClassDecorator;
|
|
17
17
|
declare const cycloBuiltinClass: CycloClassDecorator;
|
|
18
18
|
export { cycloClass, cycloBuiltinClass };
|
|
19
|
-
export declare const
|
|
19
|
+
export declare const stored: PropertyDecorator;
|
|
20
20
|
/**
|
|
21
21
|
* Marks that the property's default value might vary between instances.
|
|
22
22
|
* @description
|
|
@@ -44,7 +44,7 @@ const cycloBuiltinClass = createScopedCycloClassDecorator({
|
|
|
44
44
|
scope: 'cyclo.',
|
|
45
45
|
});
|
|
46
46
|
export { cycloClass, cycloBuiltinClass };
|
|
47
|
-
export const
|
|
47
|
+
export const stored = _decorator.serializable;
|
|
48
48
|
/**
|
|
49
49
|
* Marks that the property's default value might vary between instances.
|
|
50
50
|
* @description
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export interface ShortenPropertyDecorator<TArgs extends
|
|
1
|
+
export interface ShortenPropertyDecorator<TArgs extends unknown[]> {
|
|
2
2
|
(...args: TArgs): PropertyDecorator;
|
|
3
|
-
(target:
|
|
3
|
+
(target: object, propertyKey: string | symbol): void;
|
|
4
4
|
}
|
|
5
|
-
export declare function defineShortenPropertyDecorator<TArgs extends
|
|
5
|
+
export declare function defineShortenPropertyDecorator<TArgs extends unknown[]>(decorator: (...args: TArgs) => PropertyDecorator, ...defaultArgs: TArgs): ShortenPropertyDecorator<TArgs>;
|
|
6
6
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -4,7 +4,7 @@ export function defineShortenPropertyDecorator(decorator, ...defaultArgs) {
|
|
|
4
4
|
// @x()
|
|
5
5
|
return decorator(...defaultArgs);
|
|
6
6
|
}
|
|
7
|
-
else if (!(typeof args[0] === 'object' && args[0] && typeof args[1] === 'string' || typeof args[1] === 'symbol')) {
|
|
7
|
+
else if (!((typeof args[0] === 'object' && args[0] && typeof args[1] === 'string') || typeof args[1] === 'symbol')) {
|
|
8
8
|
// @x(opts)
|
|
9
9
|
return decorator(...args);
|
|
10
10
|
}
|
package/lib/export/internal.d.ts
CHANGED
package/lib/export/internal.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy,
|
|
1
|
+
export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy, stored, type CycloClassOptions, type CycloClassDecorator, } from '../decorator/legacy/legacy-general-decorator.ts';
|
|
2
2
|
export { executionOrder, executeInEditMode, requiresComponent, } from '../decorator/legacy/legacy-component-decorator.ts';
|
|
3
3
|
export { applyLegacyDecorators } from '../decorator/legacy/apply-legacy-decorators.ts';
|
|
4
4
|
//# sourceMappingURL=legacy-decorator.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy,
|
|
1
|
+
export { designType, editable, editorOnly, cycloClass, createScopedCycloClassDecorator, dynamicDefault, idem, idemBy, stored, } from "../decorator/legacy/legacy-general-decorator.js";
|
|
2
2
|
export { executionOrder, executeInEditMode, requiresComponent, } from "../decorator/legacy/legacy-component-decorator.js";
|
|
3
3
|
export { applyLegacyDecorators } from "../decorator/legacy/apply-legacy-decorators.js";
|
|
4
4
|
//# sourceMappingURL=legacy-decorator.js.map
|
|
@@ -12,6 +12,7 @@ import { addFrameTask, TaskPriority } from "./tasking.js";
|
|
|
12
12
|
import { CoroutineRunner, stopCoroutine as stopCoroutineRecord } from "./coroutine.js";
|
|
13
13
|
import { retainIf } from '@cyclonium/algorithm/retain-if';
|
|
14
14
|
import { EDITOR_NOT_IN_PREVIEW } from 'cc/env';
|
|
15
|
+
import { TimeAccumulator } from './time-accumulator.js';
|
|
15
16
|
class ComponentScheduler {
|
|
16
17
|
enableComponent(component) {
|
|
17
18
|
const index = this._fixedUpdateRegistry.findIndex(({ component: c }) => c === component);
|
|
@@ -110,19 +111,35 @@ let CycloComponent = class CycloComponent extends Component {
|
|
|
110
111
|
get disablingSignal() {
|
|
111
112
|
return (this._disablingController ??= new AbortController()).signal;
|
|
112
113
|
}
|
|
113
|
-
onAwake() {
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
onAwake() {
|
|
115
|
+
// Optional lifecycle hook for subclasses.
|
|
116
|
+
}
|
|
117
|
+
onEnabled() {
|
|
118
|
+
// Optional lifecycle hook for subclasses.
|
|
119
|
+
}
|
|
120
|
+
onDisabled() {
|
|
121
|
+
// Optional lifecycle hook for subclasses.
|
|
122
|
+
}
|
|
116
123
|
onDestroy() {
|
|
117
124
|
this.stopAllCoroutines();
|
|
118
125
|
this._destroyingController?.abort();
|
|
119
126
|
this._destroyingController = undefined;
|
|
120
127
|
}
|
|
121
|
-
onStart() {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
onStart() {
|
|
129
|
+
// Optional lifecycle hook for subclasses.
|
|
130
|
+
}
|
|
131
|
+
onUpdate(_deltaTime) {
|
|
132
|
+
// Optional lifecycle hook for subclasses.
|
|
133
|
+
}
|
|
134
|
+
onFixedUpdate(_deltaTime) {
|
|
135
|
+
// Optional lifecycle hook for subclasses.
|
|
136
|
+
}
|
|
137
|
+
onLateUpdate(_deltaTime) {
|
|
138
|
+
// Optional lifecycle hook for subclasses.
|
|
139
|
+
}
|
|
140
|
+
onFrameEnd() {
|
|
141
|
+
// Optional lifecycle hook for subclasses.
|
|
142
|
+
}
|
|
126
143
|
/**
|
|
127
144
|
* Starts a coroutine owned by this component.
|
|
128
145
|
* @param coroutine - Coroutine iterator to start.
|
|
@@ -259,27 +276,22 @@ class FixedUpdateTask {
|
|
|
259
276
|
update(deltaTime) {
|
|
260
277
|
const scene = director.getScene();
|
|
261
278
|
if (!scene) {
|
|
262
|
-
this.
|
|
279
|
+
this._timeAccumulator.reset();
|
|
263
280
|
return;
|
|
264
281
|
}
|
|
265
|
-
const
|
|
282
|
+
const timeAccumulator = this._timeAccumulator;
|
|
283
|
+
const fixedTimeStep = timeAccumulator.timeStep;
|
|
266
284
|
const maxSteps = this.maxSteps;
|
|
267
|
-
const
|
|
268
|
-
const
|
|
269
|
-
const overloading = expectedSteps > maxSteps;
|
|
285
|
+
const actualSteps = timeAccumulator.advance(deltaTime, maxSteps);
|
|
286
|
+
const overloading = deltaTime > maxSteps * fixedTimeStep;
|
|
270
287
|
const previousOverloading = this._overloading;
|
|
271
288
|
this._overloading = overloading;
|
|
272
|
-
let actualSteps = 0;
|
|
273
289
|
if (overloading) {
|
|
274
|
-
actualSteps = maxSteps;
|
|
275
|
-
this._accumulatedTime = 0;
|
|
276
290
|
if (overloading !== previousOverloading) {
|
|
277
|
-
this._emitOverloadingBegin(
|
|
291
|
+
this._emitOverloadingBegin();
|
|
278
292
|
}
|
|
279
293
|
}
|
|
280
294
|
else {
|
|
281
|
-
actualSteps = expectedSteps;
|
|
282
|
-
this._accumulatedTime = accumulatedTime - actualSteps * fixedTimeStep;
|
|
283
295
|
if (overloading !== previousOverloading) {
|
|
284
296
|
this._emitOverloadingEnd();
|
|
285
297
|
}
|
|
@@ -288,12 +300,10 @@ class FixedUpdateTask {
|
|
|
288
300
|
globalComponentScheduler.invokeFixedUpdate(fixedTimeStep);
|
|
289
301
|
}
|
|
290
302
|
}
|
|
291
|
-
|
|
292
|
-
_accumulatedTime = 0;
|
|
303
|
+
_timeAccumulator = new TimeAccumulator(1 / 60);
|
|
293
304
|
_overloading = false;
|
|
294
|
-
_emitOverloadingBegin(
|
|
305
|
+
_emitOverloadingBegin() {
|
|
295
306
|
// todo
|
|
296
|
-
void expectedSteps;
|
|
297
307
|
}
|
|
298
308
|
_emitOverloadingEnd() {
|
|
299
309
|
// todo
|
|
@@ -301,15 +311,17 @@ class FixedUpdateTask {
|
|
|
301
311
|
}
|
|
302
312
|
if (!EDITOR_NOT_IN_PREVIEW) {
|
|
303
313
|
const fixedUpdatePriority = TaskPriority.before(TaskPriority.predefined.componentsLateUpdate);
|
|
314
|
+
const coroutineUpdateTask = new CoroutineUpdateTask();
|
|
315
|
+
const fixedUpdateTask = new FixedUpdateTask();
|
|
304
316
|
addFrameTask({
|
|
305
|
-
thisArg:
|
|
317
|
+
thisArg: coroutineUpdateTask,
|
|
306
318
|
priority: TaskPriority.between(fixedUpdatePriority, TaskPriority.predefined.componentsLateUpdate),
|
|
307
|
-
fn:
|
|
319
|
+
fn: coroutineUpdateTask.update.bind(coroutineUpdateTask),
|
|
308
320
|
});
|
|
309
321
|
addFrameTask({
|
|
310
|
-
thisArg:
|
|
322
|
+
thisArg: fixedUpdateTask,
|
|
311
323
|
priority: fixedUpdatePriority,
|
|
312
|
-
fn:
|
|
324
|
+
fn: fixedUpdateTask.update.bind(fixedUpdateTask),
|
|
313
325
|
});
|
|
314
326
|
addFrameTask({
|
|
315
327
|
thisArg: undefined,
|
|
@@ -84,13 +84,13 @@ export declare function waitUntil(predicate: CoroutinePredicate): CoroutineInstr
|
|
|
84
84
|
*/
|
|
85
85
|
export declare function waitWhile(predicate: CoroutinePredicate): CoroutineInstruction;
|
|
86
86
|
export declare class CoroutineRunner {
|
|
87
|
+
get frame(): number;
|
|
88
|
+
get deltaTime(): number;
|
|
89
|
+
get empty(): boolean;
|
|
87
90
|
start(coroutine: CoroutineIterator, opts?: StartCoroutineOptions): Coroutine;
|
|
88
91
|
update(deltaTime: number): void;
|
|
89
92
|
stop(handle: Coroutine): void;
|
|
90
93
|
stopAll(): void;
|
|
91
|
-
get frame(): number;
|
|
92
|
-
get deltaTime(): number;
|
|
93
|
-
get empty(): boolean;
|
|
94
94
|
private _records;
|
|
95
95
|
private _frame;
|
|
96
96
|
private _deltaTime;
|
|
@@ -52,6 +52,15 @@ export function waitWhile(predicate) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
export class CoroutineRunner {
|
|
55
|
+
get frame() {
|
|
56
|
+
return this._frame;
|
|
57
|
+
}
|
|
58
|
+
get deltaTime() {
|
|
59
|
+
return this._deltaTime;
|
|
60
|
+
}
|
|
61
|
+
get empty() {
|
|
62
|
+
return this._records.length === 0;
|
|
63
|
+
}
|
|
55
64
|
start(coroutine, opts) {
|
|
56
65
|
const record = new CoroutineRecord(this, coroutine, opts);
|
|
57
66
|
this._records.push(record);
|
|
@@ -89,15 +98,6 @@ export class CoroutineRunner {
|
|
|
89
98
|
this._endPruneDeferral();
|
|
90
99
|
}
|
|
91
100
|
}
|
|
92
|
-
get frame() {
|
|
93
|
-
return this._frame;
|
|
94
|
-
}
|
|
95
|
-
get deltaTime() {
|
|
96
|
-
return this._deltaTime;
|
|
97
|
-
}
|
|
98
|
-
get empty() {
|
|
99
|
-
return this._records.length === 0;
|
|
100
|
-
}
|
|
101
101
|
_records = [];
|
|
102
102
|
_frame = 0;
|
|
103
103
|
_deltaTime = 0;
|
|
@@ -191,6 +191,7 @@ class CoroutineRecord {
|
|
|
191
191
|
_done = false;
|
|
192
192
|
_executing = false;
|
|
193
193
|
_stopping = false;
|
|
194
|
+
_onAbort = undefined;
|
|
194
195
|
_advance(frame) {
|
|
195
196
|
let result;
|
|
196
197
|
this._executing = true;
|
|
@@ -273,6 +274,5 @@ class CoroutineRecord {
|
|
|
273
274
|
this._signal.removeEventListener('abort', this._onAbort);
|
|
274
275
|
this._onAbort = undefined;
|
|
275
276
|
}
|
|
276
|
-
_onAbort = undefined;
|
|
277
277
|
}
|
|
278
278
|
//# sourceMappingURL=coroutine.js.map
|
package/lib/framework/tasking.js
CHANGED
|
@@ -20,7 +20,10 @@ class TaskCluster {
|
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
this._tasks.push({
|
|
23
|
-
|
|
23
|
+
fn: task.fn,
|
|
24
|
+
thisArg: task.thisArg,
|
|
25
|
+
priority: task.priority,
|
|
26
|
+
execute: (deltaTime) => task.fn.call(task.thisArg, deltaTime),
|
|
24
27
|
});
|
|
25
28
|
this._tasks.sort((a, b) => b.priority - a.priority);
|
|
26
29
|
return true;
|
|
@@ -35,7 +38,7 @@ class TaskCluster {
|
|
|
35
38
|
}
|
|
36
39
|
execute(deltaTime) {
|
|
37
40
|
for (const task of this._tasks) {
|
|
38
|
-
task.
|
|
41
|
+
task.execute(deltaTime);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
_tasks = [];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class TimeAccumulator {
|
|
2
|
+
constructor(timeStep: number);
|
|
3
|
+
get timeStep(): number;
|
|
4
|
+
/** Adds at most `maxSteps` worth of elapsed time and consumes complete steps. */
|
|
5
|
+
advance(deltaTime: number, maxSteps: number): number;
|
|
6
|
+
reset(): void;
|
|
7
|
+
private readonly _timeStep;
|
|
8
|
+
private _accumulatedTime;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=time-accumulator.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class TimeAccumulator {
|
|
2
|
+
constructor(timeStep) {
|
|
3
|
+
this._timeStep = timeStep;
|
|
4
|
+
}
|
|
5
|
+
get timeStep() {
|
|
6
|
+
return this._timeStep;
|
|
7
|
+
}
|
|
8
|
+
/** Adds at most `maxSteps` worth of elapsed time and consumes complete steps. */
|
|
9
|
+
advance(deltaTime, maxSteps) {
|
|
10
|
+
const timeStep = this._timeStep;
|
|
11
|
+
const maximumDeltaTime = maxSteps * timeStep;
|
|
12
|
+
const acceptedDeltaTime = Math.min(deltaTime, maximumDeltaTime);
|
|
13
|
+
const accumulatedTime = this._accumulatedTime + acceptedDeltaTime;
|
|
14
|
+
const steps = Math.min(countCompleteSteps(accumulatedTime, timeStep), maxSteps);
|
|
15
|
+
this._accumulatedTime = Math.max(accumulatedTime - steps * timeStep, 0);
|
|
16
|
+
return steps;
|
|
17
|
+
}
|
|
18
|
+
reset() {
|
|
19
|
+
this._accumulatedTime = 0;
|
|
20
|
+
}
|
|
21
|
+
_timeStep;
|
|
22
|
+
_accumulatedTime = 0;
|
|
23
|
+
}
|
|
24
|
+
function countCompleteSteps(accumulatedTime, timeStep) {
|
|
25
|
+
const stepRatio = accumulatedTime / timeStep;
|
|
26
|
+
const tolerance = Number.EPSILON * Math.max(Math.abs(stepRatio), 1) * 4;
|
|
27
|
+
return Math.floor(stepRatio + tolerance);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=time-accumulator.js.map
|
package/lib/math/bounds-2d.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Bounds2D } from '@cyclonium/math/bounds-2d';
|
|
2
|
-
import { applyLegacyDecorators,
|
|
2
|
+
import { applyLegacyDecorators, stored, editable } from "../export/legacy-decorator.js";
|
|
3
3
|
import { cycloBuiltinClass } from "../decorator/legacy/legacy-decorator.js";
|
|
4
4
|
export * from '@cyclonium/math/bounds-2d';
|
|
5
5
|
applyLegacyDecorators(Bounds2D, {
|
|
6
6
|
classDecorators: [cycloBuiltinClass('Bounds2D')],
|
|
7
7
|
propertyDecorators: {
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
_min: [
|
|
10
|
-
_max: [
|
|
8
|
+
// @ts-expect-error -- Legacy decorators intentionally target Bounds2D's private serialized fields.
|
|
9
|
+
_min: [stored, editable],
|
|
10
|
+
_max: [stored, editable],
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
13
|
//# sourceMappingURL=bounds-2d.js.map
|
package/lib/math/vec2.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Vec2, v2 } from '@cyclonium/math/vec2';
|
|
2
2
|
import { applyLegacyDecorators } from "../decorator/legacy/apply-legacy-decorators.js";
|
|
3
|
-
import { editable, cycloBuiltinClass,
|
|
3
|
+
import { editable, cycloBuiltinClass, stored } from "../decorator/legacy/legacy-general-decorator.js";
|
|
4
4
|
import * as cc from 'cc';
|
|
5
5
|
applyLegacyDecorators(Vec2, {
|
|
6
6
|
classDecorators: [cycloBuiltinClass('Vec2')],
|
|
7
|
-
// @ts-expect-error
|
|
7
|
+
// @ts-expect-error -- Legacy decorators require metadata for Vec2 fields declared by another package.
|
|
8
8
|
propertyDecorators: {
|
|
9
|
-
x: [
|
|
10
|
-
y: [
|
|
9
|
+
x: [stored, editable],
|
|
10
|
+
y: [stored, editable],
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
13
|
export { Vec2, v2 };
|
package/lib/utils/assert.js
CHANGED
package/lib/utils/raw.js
CHANGED
|
@@ -15,7 +15,9 @@ Raw = __decorate([
|
|
|
15
15
|
cycloBuiltinClass('_Raw')
|
|
16
16
|
], Raw);
|
|
17
17
|
export { Raw };
|
|
18
|
-
export const dumpRaw = (
|
|
18
|
+
export const dumpRaw = (_target, _propertyKey, descriptor) => {
|
|
19
|
+
// The getter is deliberately invoked later with the decorated instance as its receiver.
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
19
21
|
const get = descriptor.get;
|
|
20
22
|
if (get) {
|
|
21
23
|
descriptor.get = function () {
|