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 all 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/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
19 changes: 10 additions & 9 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 (): Iterable<Readonly<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 (): Iterable<Readonly<ClipStatus>> {
const { _activatedTransitions: activatedTransitions } = this;
if (activatedTransitions.length === 0) {
return emptyClipStatusesIterable;
Expand Down Expand Up @@ -986,20 +986,21 @@ function createStateStatusCache (): MotionStateStatus {
};
}

const emptyClipStatusesIterator: Readonly<Iterator<ClipStatus>> = Object.freeze({
next (..._args: [] | [undefined]): IteratorResult<ClipStatus> {
type ReadonlyClipStatus = Readonly<ClipStatus>;
const emptyClipStatusesIterator: Iterator<ReadonlyClipStatus> = {
next (..._args: [] | [undefined]): IteratorResult<ReadonlyClipStatus> {
return {
done: true,
value: undefined,
};
},
});
};

const emptyClipStatusesIterable: Iterable<ClipStatus> = Object.freeze({
const emptyClipStatusesIterable: Iterable<ReadonlyClipStatus> = {
[Symbol.iterator] () {
return emptyClipStatusesIterator;
},
});
};

enum NodeKind {
entry, exit, any, animation,
Expand Down Expand Up @@ -1286,7 +1287,7 @@ class VMSMEval {
this._privateState.addTransition(transition);
}

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

public getClipStatuses (baseWeight: number): Iterable<ClipStatus> {
public getClipStatuses (baseWeight: number): Iterable<Readonly<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 @@ -85,12 +85,12 @@ type AttributeFormerlySerializedAs = `${AttributeName}${typeof POSTFIX_FORMERLY_
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 @@ -287,41 +287,41 @@ type TypedArrayViewConstructorName =
| '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 @@ -588,12 +588,10 @@ class _Deserializer {
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 @@ -767,26 +765,26 @@ class _Deserializer {
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 @@ export function deserializeDynamic (data: SerializedData | CCON, details: Detail
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