Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AOT] fix type for AOT engine #15526

Merged
merged 7 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cocos/animation/marionette/animation-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class AnimationController extends Component {
* An empty iterable is returned if current state is not a motion state.
* @zh 到动画剪辑运作状态的迭代器。若当前状态不是动画状态,则返回一个空的迭代器。
*/
public getCurrentClipStatuses (layer: number): Iterable<Readonly<ClipStatus>> {
public getCurrentClipStatuses (layer: number): Readonly<Iterable<ClipStatus>> {
const { _graphEval: graphEval } = this;
assertIsNonNullable(graphEval);
return graphEval.getCurrentClipStatuses(layer);
Expand Down Expand Up @@ -266,7 +266,7 @@ export class AnimationController extends Component {
* An empty iterable is returned in case of no transition or next state is not a motion state.
* @zh 到下一状态上包含的动画剪辑运作状态的迭代器,若未在进行过渡或下一状态不是动画状态,则返回一个空的迭代器。
*/
public getNextClipStatuses (layer: number): Iterable<Readonly<ClipStatus>> {
public getNextClipStatuses (layer: number): Readonly<Iterable<ClipStatus>> {
const { _graphEval: graphEval } = this;
assertIsNonNullable(graphEval);
return graphEval.getNextClipStatuses(layer);
Expand Down
4 changes: 2 additions & 2 deletions cocos/animation/marionette/graph-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class AnimationGraphEval {
return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getCurrentStateStatus();
}

public getCurrentClipStatuses (layer: number): Iterable<Readonly<ClipStatus>> {
public getCurrentClipStatuses (layer: number): Readonly<Iterable<ClipStatus>> {
return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getCurrentClipStatuses();
}

Expand All @@ -185,7 +185,7 @@ export class AnimationGraphEval {
return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getNextStateStatus();
}

public getNextClipStatuses (layer: number): Iterable<Readonly<ClipStatus>> {
public getNextClipStatuses (layer: number): Readonly<Iterable<ClipStatus>> {
return this._rootPoseNode.getLayerTopLevelStateMachineEvaluation(layer).getNextClipStatuses();
}

Expand Down
4 changes: 2 additions & 2 deletions cocos/animation/marionette/pose-graph/instantiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ export interface PoseNodeDependencyEvaluation {
evaluate(): void;
}

function instantiateNode<TNode extends EvaluatableNode> (
function instantiateNode (
graph: PoseGraph,
node: TNode,
node: EvaluatableNode,
instantiationMap: Map<PoseGraphNode, RuntimeNodeEvaluation>,
linkContext: PureValueNodeLinkContext,
): RuntimeNodeEvaluation {
Expand Down
10 changes: 5 additions & 5 deletions cocos/animation/marionette/state-machine/state-machine-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class TopLevelStateMachineEvaluation {
}
}

public getCurrentClipStatuses (): Iterable<ClipStatus> {
public getCurrentClipStatuses (): Readonly<Iterable<ClipStatus>> {
const { _currentNode: currentNode } = this;
if (currentNode.kind === NodeKind.animation) {
return currentNode.getClipStatuses(currentNode.absoluteWeight);
Expand Down Expand Up @@ -237,7 +237,7 @@ class TopLevelStateMachineEvaluation {
return null;
}

public getNextClipStatuses (): Iterable<ClipStatus> {
public getNextClipStatuses (): Readonly<Iterable<ClipStatus>> {
const { _activatedTransitions: activatedTransitions } = this;
if (activatedTransitions.length === 0) {
return emptyClipStatusesIterable;
Expand Down Expand Up @@ -995,7 +995,7 @@ const emptyClipStatusesIterator: Readonly<Iterator<ClipStatus>> = Object.freeze(
},
});

const emptyClipStatusesIterable: Iterable<ClipStatus> = Object.freeze({
const emptyClipStatusesIterable: Readonly<Iterable<ClipStatus>> = Object.freeze({
[Symbol.iterator] () {
return emptyClipStatusesIterator;
},
Expand Down Expand Up @@ -1286,7 +1286,7 @@ class VMSMEval {
this._privateState.addTransition(transition);
}

public getClipStatuses (baseWeight: number): Iterable<ClipStatus> {
public getClipStatuses (baseWeight: number): Readonly<Iterable<ClipStatus>> {
const { _source: source } = this;
if (!source) {
return emptyClipStatusesIterable;
Expand Down Expand Up @@ -1357,7 +1357,7 @@ class VMSMInternalState extends EventifiedStateEval {
return stateStatus;
}

public getClipStatuses (baseWeight: number): Iterable<ClipStatus> {
public getClipStatuses (baseWeight: number): Readonly<Iterable<ClipStatus>> {
return this._container.getClipStatuses(baseWeight);
}

Expand Down
4 changes: 2 additions & 2 deletions cocos/animation/marionette/variable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import { VariableType, VariableTypeValueTypeMap, VarInstanceBase } from './basic';
import { PlainVariable } from './primitive-variable';
import { PlainVariable, PlainVariableType } from './primitive-variable';
import { TriggerVariable } from './trigger-variable';
import { Vec3Variable } from './vec3-variable';
import { QuatVariable } from './quat-variable';
Expand All @@ -50,7 +50,7 @@ export function createVariable<TVariableType extends VariableType> (
case VariableType.FLOAT:
case VariableType.INTEGER:
case VariableType.BOOLEAN:
variable = new PlainVariable(type);
variable = new PlainVariable(type as PlainVariableType);
break;
case VariableType.TRIGGER:
variable = new TriggerVariable();
Expand Down
2 changes: 1 addition & 1 deletion cocos/animation/marionette/variable/primitive-variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assertIsTrue } from '../../../core';
import { ccclass, serializable } from '../../../core/data/decorators';
import { BasicVariableDescription, VariableType, createInstanceTag, VarInstanceBase, Value } from './basic';

type PlainVariableType = VariableType.FLOAT | VariableType.INTEGER | VariableType.BOOLEAN;
export type PlainVariableType = VariableType.FLOAT | VariableType.INTEGER | VariableType.BOOLEAN;

@ccclass('cc.animation.PlainVariable')
export class PlainVariable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class CharacterController extends Eventify(Component) {
return this._center;
}

public set center (value: Vec3) {
public set center (value: Readonly<Vec3>) {
minggo marked this conversation as resolved.
Show resolved Hide resolved
if (Vec3.equals(this._center, value)) return;
Vec3.copy(this._center, value);
// if (this._cct) { //update cct position
Expand Down Expand Up @@ -312,7 +312,7 @@ export class CharacterController extends Eventify(Component) {
* @zh
* 设置中心的世界坐标。
*/
public set centerWorldPosition (value: Vec3) {
public set centerWorldPosition (value: Readonly<Vec3>) {
if (this._isInitialized) this._cct!.setPosition(value);
}

Expand Down
36 changes: 17 additions & 19 deletions cocos/serialization/deserialize-dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

import { EDITOR, TEST, DEV, DEBUG, JSB, PREVIEW, SUPPORT_JIT } from 'internal:constants';
import { cclegacy, js, misc, CCClass, ENUM_TAG, BITMASK_TAG, sys, error, assertIsTrue, CustomSerializable, DeserializationContext, deserializeTag, SerializationInput } from '../core';

Check warning on line 27 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 183. Maximum allowed is 150

Check warning on line 27 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 183. Maximum allowed is 150
import { MissingScript } from '../misc/missing-script';
import { Details } from './deserialize';
import { Platform } from '../../pal/system-info/enum-type';
Expand Down Expand Up @@ -85,12 +85,12 @@
type AttributeDefault = `${AttributeName}${typeof POSTFIX_DEFAULT}`;
type AttributeType = `${AttributeName}${typeof POSTFIX_TYPE}`;
type AttributeEditorOnly = `${AttributeName}${typeof POSTFIX_EDITOR_ONLY}`;
type AttrResult = {
interface AttrResult {
[K: string]: typeof K extends AttributeFormerlySerializedAs ? string :
typeof K extends AttributeDefault ? unknown :
typeof K extends AttributeType ? AnyFunction :
typeof K extends AttributeEditorOnly ? boolean : never;
};
}

function compileDeserializeJIT (self: _Deserializer, klass: CCClassConstructor<unknown>): CompiledDeserializeFn {
const attrs: AttrResult = CCClass.Attr.getClassAttrs(klass);
Expand Down Expand Up @@ -258,7 +258,7 @@
const valueTypeCtor = advancedPropsValueType[i];
if (valueTypeCtor) {
if (fastMode || prop) {
s._deserializeFastDefinedObject(o[propName] as Record<PropertyKey, unknown>, prop as SerializedGeneralTypedObject, valueTypeCtor);

Check warning on line 261 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 154. Maximum allowed is 150

Check warning on line 261 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 154. Maximum allowed is 150
} else {
o[propName] = null;
}
Expand Down Expand Up @@ -287,41 +287,41 @@
| 'Uint32Array' | 'Int32Array'
| 'Float32Array' | 'Float64Array';

type SerializedTypedArray = {
interface SerializedTypedArray {
__id__: never;
__uuid__: never;
__type__: 'TypedArray';
array: number[];
ctor: TypedArrayViewConstructorName;
};
}

type SerializedTypedArrayRef = {
interface SerializedTypedArrayRef {
__id__: never;
__uuid__: never;
__type__: 'TypedArrayRef';
ctor: TypedArrayViewConstructorName;
offset: number;
length: number;
};
}

type SerializedGeneralTypedObject = {
__id__: never;
__uuid__: never;
__type__?: NotKnownTypeTag;
} & Record<NotTypeTag, SerializedFieldValue>;

type SerializedObjectReference = {
interface SerializedObjectReference {
__type__: never;
__uuid__: never;
__id__: number;
}

type SerializedUUIDReference = {
interface SerializedUUIDReference {
__type__: never;
__id__: never;
__uuid__: string;
__expectedType__: string;
};
}

type SerializedObject = SerializedTypedArray | SerializedTypedArrayRef | SerializedGeneralTypedObject;

Expand Down Expand Up @@ -355,7 +355,7 @@

// TODO: this is should be a HACK, we've changed the method signature
// issue: https://github.com/cocos/cocos-engine/issues/14642
(DeserializerPool.prototype as any).get = function (

Check warning on line 358 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function

Check warning on line 358 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
this: DeserializerPool,
details: Details,
classFinder: ClassFinder,
Expand Down Expand Up @@ -404,7 +404,7 @@
}
}

public reset (result: Details, classFinder: ClassFinder, reportMissingClass: ReportMissingClass, customEnv: unknown, ignoreEditorOnly: unknown): void {

Check warning on line 407 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 155. Maximum allowed is 150

Check warning on line 407 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 155. Maximum allowed is 150
this.result = result;
this.customEnv = customEnv;
this._classFinder = classFinder;
Expand Down Expand Up @@ -489,11 +489,11 @@
}
}

private _deserializeTypedArrayView (value: SerializedTypedArray): Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array {

Check warning on line 492 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 178. Maximum allowed is 150

Check warning on line 492 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 178. Maximum allowed is 150
return globalThis[value.ctor].from(value.array);
}

private _deserializeTypedArrayViewRef (value: SerializedTypedArrayRef): Uint8Array | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array {

Check warning on line 496 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 184. Maximum allowed is 150

Check warning on line 496 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 184. Maximum allowed is 150
const { offset, length, ctor: constructorName } = value;
const obj = new globalThis[constructorName](
this._mainBinChunk.buffer,
Expand Down Expand Up @@ -588,12 +588,10 @@
return;
}

// cSpell:words Deserializable

type ClassicCustomizedDeserializable = { _deserialize: (content: unknown, deserializer: _Deserializer) => void; };
interface ClassicCustomizedDeserializable { _deserialize: (content: unknown, deserializer: _Deserializer) => void; }
if ((object as Partial<ClassicCustomizedDeserializable>)._deserialize) {
// TODO: content check?
(object as ClassicCustomizedDeserializable)._deserialize((value as unknown as { content: unknown }).content, this);
(object as Partial<ClassicCustomizedDeserializable>)._deserialize!((value as unknown as { content: unknown }).content, this);
return;
}

Expand Down Expand Up @@ -634,7 +632,7 @@
object[deserializeTag]!(serializationInput, this._context);
}

private _deserializeFireClass (obj: Record<PropertyKey, unknown>, serialized: SerializedGeneralTypedObject, klass: CCClassConstructor<unknown>): void {

Check warning on line 635 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 155. Maximum allowed is 150

Check warning on line 635 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 155. Maximum allowed is 150
let deserialize: CompiledDeserializeFn;
// eslint-disable-next-line no-prototype-builtins
if (klass.hasOwnProperty('__deserialize__')) {
Expand All @@ -648,12 +646,12 @@
const props: string[] = klass.__values__;
if (props.length === 0 || props[props.length - 1] !== '_$erialized') {
error(`The '_$erialized' prop of MissingScript is missing. Will force the raw data to be save.`);
error(` Error props: ['${props}']. Please contact jare.`);

Check warning on line 649 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "string[]" of template literal expression

Check warning on line 649 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "string[]" of template literal expression
// props.push('_$erialized');
}

const rawDeserialize: CompiledDeserializeFn = deserialize;
deserialize = function (deserializer: _Deserializer,

Check warning on line 654 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function

Check warning on line 654 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
object: Record<string, unknown>,
deserialized: Record<string, unknown>,
constructor: AnyFunction): void {
Expand All @@ -664,7 +662,7 @@
};
}
} catch (e) {
error(`Error when checking MissingScript 6, ${e}`);

Check warning on line 665 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "any" of template literal expression

Check warning on line 665 in cocos/serialization/deserialize-dynamic.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "any" of template literal expression
}

js.value(klass, '__deserialize__', deserialize, true);
Expand Down Expand Up @@ -767,26 +765,26 @@
klass: SerializableClassConstructor,
): void {
if (klass === cclegacy.Vec2) {
type SerializedVec2 = { x?: number; y?: number; };
interface SerializedVec2 { x?: number; y?: number; }
instance.x = (serialized as SerializedVec2).x || 0;
instance.y = (serialized as SerializedVec2).y || 0;
return;
} else if (klass === cclegacy.Vec3) {
type SerializedVec3 = { x?: number; y?: number; z?: number; };
interface SerializedVec3 { x?: number; y?: number; z?: number; }
instance.x = (serialized as SerializedVec3).x || 0;
instance.y = (serialized as SerializedVec3).y || 0;
instance.z = (serialized as SerializedVec3).z || 0;
return;
} else if (klass === cclegacy.Color) {
type SerializedColor = { r?: number; g?: number; b?: number; a?: number; };
interface SerializedColor { r?: number; g?: number; b?: number; a?: number; }
instance.r = (serialized as SerializedColor).r || 0;
instance.g = (serialized as SerializedColor).g || 0;
instance.b = (serialized as SerializedColor).b || 0;
const a = (serialized as SerializedColor).a;
instance.a = (a === undefined ? 255 : a);
return;
} else if (klass === cclegacy.Size) {
type SerializedSize = { width?: number; height?: number; };
interface SerializedSize { width?: number; height?: number; }
instance.width = (serialized as SerializedSize).width || 0;
instance.height = (serialized as SerializedSize).height || 0;
return;
Expand Down Expand Up @@ -865,8 +863,8 @@
return res;
}

export function parseUuidDependenciesDynamic (serialized: unknown): never[] {
const depends = [];
export function parseUuidDependenciesDynamic (serialized: unknown): string[] {
const depends: string[] = [];
const parseDependRecursively = (data: any, out: string[]): void => {
if (!data || typeof data !== 'object' || typeof data.__id__ === 'number') { return; }
const uuid = data.__uuid__;
Expand Down
Loading