From 87775ff2b490f941a2814ef06a6a2e27cbb11cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leslie=20Leigh=20=28=E6=9D=8E=E7=9A=84=E5=BA=8F=29?= Date: Fri, 3 Sep 2021 18:57:02 +0800 Subject: [PATCH] Fast define curve (#9276) * Fast define curve * Use fastDefine --- cocos/core/curves/curve.ts | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/cocos/core/curves/curve.ts b/cocos/core/curves/curve.ts index a294783c6a..a1d5ca38ca 100644 --- a/cocos/core/curves/curve.ts +++ b/cocos/core/curves/curve.ts @@ -6,9 +6,10 @@ import { RealInterpolationMode, ExtrapolationMode, TangentWeightMode } from './r import { binarySearchEpsilon } from '../algorithm/binary-search'; import { solveCubic } from './solve-cubic'; import { EditorExtendable, EditorExtendableMixin } from '../data/editor-extendable'; -import { deserializeTag, editorExtrasTag, SerializationContext, SerializationInput, SerializationOutput, serializeTag } from '../data'; +import { CCClass, deserializeTag, editorExtrasTag, SerializationContext, SerializationInput, SerializationOutput, serializeTag } from '../data'; import { DeserializationContext } from '../data/custom-serializable'; import { EasingMethod, getEasingFn } from './easing-method'; +import { getOrCreateSerializationMetadata } from '../data/serialization-metadata'; export { RealInterpolationMode, ExtrapolationMode, TangentWeightMode, EasingMethod }; @@ -16,25 +17,20 @@ export { RealInterpolationMode, ExtrapolationMode, TangentWeightMode, EasingMeth * View to a real frame value. * Note, the view may be invalidated due to keyframe change/add/remove. */ -@ccclass('cc.RealKeyframeValue') -@uniquelyReferenced class RealKeyframeValue extends EditorExtendable { /** * Interpolation method used for this keyframe. */ - @serializable public interpolationMode = RealInterpolationMode.LINEAR; /** * Tangent weight mode. */ - @serializable public tangentWeightMode = TangentWeightMode.NONE; /** * Value of the keyframe. */ - @serializable public value = 0.0; /** @@ -42,7 +38,6 @@ class RealKeyframeValue extends EditorExtendable { * when it's used as starting point during cubic interpolation. * Meaningless otherwise. */ - @serializable public rightTangent = 0.0; /** @@ -50,7 +45,6 @@ class RealKeyframeValue extends EditorExtendable { * when it's used as starting point during cubic interpolation. * Meaningless otherwise. */ - @serializable public rightTangentWeight = 0.0; /** @@ -58,7 +52,6 @@ class RealKeyframeValue extends EditorExtendable { * when it's used as ending point during cubic interpolation. * Meaningless otherwise. */ - @serializable public leftTangent = 0.0; /** @@ -66,16 +59,36 @@ class RealKeyframeValue extends EditorExtendable { * when it's used as starting point during cubic interpolation. * Meaningless otherwise. */ - @serializable public leftTangentWeight = 0.0; /** * @deprecated Reserved for backward compatibility. Will be removed in future. */ - @serializable public easingMethod = EasingMethod.LINEAR; } +CCClass.fastDefine( + 'cc.RealKeyframeValue', + RealKeyframeValue, { + interpolationMode: RealInterpolationMode.LINEAR, + tangentWeightMode: TangentWeightMode.NONE, + value: 0.0, + rightTangent: 0.0, + rightTangentWeight: 0.0, + leftTangent: 0.0, + leftTangentWeight: 0.0, + }, +); + +CCClass.Attr.setClassAttr( + RealKeyframeValue, + editorExtrasTag, + 'editorOnly', + true, +); + +getOrCreateSerializationMetadata(RealKeyframeValue).uniquelyReferenced = true; + export type { RealKeyframeValue }; /**