From b7a15545031b6e5e70e74908cf9bf5e63786f525 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Tue, 13 Jun 2023 17:55:59 +0800 Subject: [PATCH 1/9] fix object --- cocos/core/data/object.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/core/data/object.ts b/cocos/core/data/object.ts index 0554698907e..d0efe305791 100644 --- a/cocos/core/data/object.ts +++ b/cocos/core/data/object.ts @@ -68,7 +68,7 @@ const PersistentMask = ~(ToDestroy | Dirty | Destroying | DontDestroy | Deactiva // all the hideFlags const AllHideMasks = DontSave | EditorOnly | LockedInEditor | HideInHierarchy; -const objectsToDestroy: any = []; +const objectsToDestroy: CCObject[] = []; let deferredDestroyTimer: number | null = null; function compileDestruct (obj, ctor): Function { From 05c9fc8142ee9b68842650e95733818f4f6963e6 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Tue, 13 Jun 2023 18:20:19 +0800 Subject: [PATCH 2/9] fix action --- cocos/tween/actions/action-manager.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/tween/actions/action-manager.ts b/cocos/tween/actions/action-manager.ts index ca82dd928c9..4efa5a4d945 100644 --- a/cocos/tween/actions/action-manager.ts +++ b/cocos/tween/actions/action-manager.ts @@ -39,10 +39,10 @@ let ID_COUNTER = 0; * @private */ class HashElement { - actions = []; + actions: Action[] = []; target: Record | null = null; // ccobject actionIndex = 0; - currentAction = null; // CCAction + currentAction: Action | null = null; // CCAction paused = false; lock = false; } @@ -451,7 +451,7 @@ export class ActionManager { */ update (dt: number): void { const locTargets = this._arrayTargets; - let locCurrTarget; + let locCurrTarget: HashElement; for (let elt = 0; elt < locTargets.length; elt++) { this._currentTarget = locTargets[elt]; locCurrTarget = this._currentTarget; From b18aef4c7678ae885a482ccb83425cc46667852d Mon Sep 17 00:00:00 2001 From: pp_pro Date: Wed, 14 Jun 2023 14:55:43 +0800 Subject: [PATCH 3/9] fix type in instantiate.ts --- cocos/serialization/instantiate.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/cocos/serialization/instantiate.ts b/cocos/serialization/instantiate.ts index e453eb2b6ef..38f38a0bf68 100644 --- a/cocos/serialization/instantiate.ts +++ b/cocos/serialization/instantiate.ts @@ -27,11 +27,12 @@ import { DEV, JSB } from 'internal:constants'; import { CCObject, isCCObject, js, ValueType, jsbUtils, isCCClassOrFastDefined, getError, warn, misc, cclegacy } from '../core'; import { Prefab } from '../scene-graph/prefab'; import { Node } from '../scene-graph/node'; +import { Component } from '../scene-graph/component'; const Destroyed = CCObject.Flags.Destroyed; const PersistentMask = CCObject.Flags.PersistentMask; -const objsToClearTmpVar: any = []; // used to reset _iN$t variable +const objsToClearTmpVar: any[] = []; // used to reset _iN$t variable /** * Invoke _instantiate method if supplied. @@ -87,7 +88,7 @@ export function instantiate (original: any, internalForce?: boolean): any { if (!cclegacy.isValid(original)) { throw new TypeError(getError(6901)); } - if (original instanceof cclegacy.Component) { + if (original instanceof Component) { warn('Should not instantiate a single cc.Component directly, you must instantiate the entire node.'); } } @@ -226,7 +227,7 @@ function enumerateObject (obj, clone, parent): void { * @param {Object|Array} obj - the original non-nil object, typeof must be 'object' * @return {Object|Array} - the original non-nil object, typeof must be 'object' */ -function instantiateObj (obj, parent): any { +function instantiateObj (obj: TypedArray | any[] | CCObject, parent: any): any { if (obj instanceof ValueType) { return obj.clone(); } @@ -235,10 +236,10 @@ function instantiateObj (obj, parent): any { // eslint-disable-next-line @typescript-eslint/no-unsafe-return return obj; } - let clone; + let clone: TypedArray | any[] | unknown; if (ArrayBuffer.isView(obj)) { - const len = (obj as any).length; - clone = new ((obj as any).constructor)(len); + const len = obj.length; + clone = new (obj.constructor as TypedArrayConstructor)(len); // NOTE: unknown injected property `_iN$t` (obj as any)._iN$t = clone; objsToClearTmpVar.push(obj); @@ -269,22 +270,22 @@ function instantiateObj (obj, parent): any { return null; } - const ctor = obj.constructor; + const ctor = obj.constructor as Constructor; if (isCCClassOrFastDefined(ctor)) { if (parent) { - if (parent instanceof cclegacy.Component) { - if (obj instanceof cclegacy.Node || obj instanceof cclegacy.Component) { + if (parent instanceof Component) { + if (obj instanceof Node || obj instanceof Component) { // eslint-disable-next-line @typescript-eslint/no-unsafe-return return obj; } - } else if (parent instanceof cclegacy.Node) { - if (obj instanceof cclegacy.Node) { + } else if (parent instanceof Node) { + if (obj instanceof Node) { if (!obj.isChildOf(parent)) { // should not clone other nodes if not descendant // eslint-disable-next-line @typescript-eslint/no-unsafe-return return obj; } - } else if (obj instanceof cclegacy.Component) { + } else if (obj instanceof Component) { if (obj.node && !obj.node.isChildOf(parent)) { // should not clone other component if not descendant // eslint-disable-next-line @typescript-eslint/no-unsafe-return @@ -301,11 +302,9 @@ function instantiateObj (obj, parent): any { clone = Object.create(null); } else { // unknown type - // eslint-disable-next-line @typescript-eslint/no-unsafe-return return obj; } enumerateObject(obj, clone, parent); - // eslint-disable-next-line @typescript-eslint/no-unsafe-return return clone; } From 26ff15e9a761f8db49965db7fcdd1c4c188f67a4 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Wed, 14 Jun 2023 15:43:32 +0800 Subject: [PATCH 4/9] fix type for NodeEventProcessor node_event_processor --- cocos/scene-graph/node-event-processor.ts | 3 +-- cocos/scene-graph/node.ts | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cocos/scene-graph/node-event-processor.ts b/cocos/scene-graph/node-event-processor.ts index d86e13a8048..b2f10963fdf 100644 --- a/cocos/scene-graph/node-event-processor.ts +++ b/cocos/scene-graph/node-event-processor.ts @@ -158,8 +158,7 @@ export class NodeEventProcessor { if (recursive && children.length > 0) { for (let i = 0; i < children.length; ++i) { const child = children[i]; - // NOTE: for circular reference reason, eventProcessor is typeof any, so it's OK to mark child as any - (child as any)._eventProcessor.setEnabled(value, true); + child.eventProcessor.setEnabled(value, true); } } // When a node is dispatching touch events and the node is set to disabled, diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 53feee0935c..983caeaeea0 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -40,6 +40,7 @@ import type { Scene } from './scene'; import { PrefabInfo, PrefabInstance } from './prefab/prefab-info'; import { NodeEventType } from './node-event'; import { Event } from '../input/types'; +import type { NodeEventProcessor } from './node-event-processor'; const Destroying = CCObject.Flags.Destroying; const DontDestroy = CCObject.Flags.DontDestroy; @@ -240,8 +241,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * * @deprecated since v3.4.0 */ - get eventProcessor (): any { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return + get eventProcessor (): NodeEventProcessor { return this._eventProcessor; } @@ -376,7 +376,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { protected _name: string; - protected _eventProcessor: any = new legacyCC.NodeEventProcessor(this); + protected _eventProcessor: NodeEventProcessor = new (legacyCC.NodeEventProcessor as typeof NodeEventProcessor)(this); protected _eventMask = 0; protected _siblingIndex = 0; From 4ff6a27c2c9b1654fee2f49c3d4f3f8c4337b1d6 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Wed, 14 Jun 2023 16:04:11 +0800 Subject: [PATCH 5/9] fix type in input.ts --- cocos/input/input.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/input/input.ts b/cocos/input/input.ts index 8729daaa838..4cf549caa09 100644 --- a/cocos/input/input.ts +++ b/cocos/input/input.ts @@ -62,7 +62,7 @@ class InputEventDispatcher implements IEventDispatcher { } } -const pointerEventTypeMap = { +const pointerEventTypeMap: Record = { [InputEventType.MOUSE_DOWN]: InputEventType.TOUCH_START, [InputEventType.MOUSE_MOVE]: InputEventType.TOUCH_MOVE, [InputEventType.MOUSE_UP]: InputEventType.TOUCH_END, From 3dc33f58ebfacf2efadc68c40146da4285ba3b50 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Sun, 25 Jun 2023 18:17:56 +0800 Subject: [PATCH 6/9] fix particle system --- cocos/particle/models/particle-batch-model.ts | 5 +-- cocos/particle/particle-system.ts | 2 +- .../renderer/particle-system-renderer-base.ts | 3 +- .../renderer/particle-system-renderer-cpu.ts | 32 +++++++++++-------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/cocos/particle/models/particle-batch-model.ts b/cocos/particle/models/particle-batch-model.ts index 6e79584eba7..33a611473d1 100644 --- a/cocos/particle/models/particle-batch-model.ts +++ b/cocos/particle/models/particle-batch-model.ts @@ -31,6 +31,7 @@ import { Color } from '../../core'; import { scene } from '../../render-scene'; import { Particle } from '../particle'; import { Material, RenderingSubMesh } from '../../asset/assets'; +import type { PVData } from '../renderer/particle-system-renderer-cpu'; const _uvs = [ 0, 0, // bottom-left @@ -325,7 +326,7 @@ export default class ParticleBatchModel extends scene.Model { this.setSubModelMaterial(0, mat); } - public addParticleVertexData (index: number, pvdata: any[]): void { + public addParticleVertexData (index: number, pvdata: PVData): void { if (!this._useInstance) { if (!this._mesh) { let offset: number = index * this._vertAttrsFloatCount; @@ -371,7 +372,7 @@ export default class ParticleBatchModel extends scene.Model { } } - private addParticleVertexDataIns (index: number, pvdata: any[]): void { + private addParticleVertexDataIns (index: number, pvdata: PVData): void { let offset: number = index * this._vertAttrsFloatCount; if (!this._mesh) { this._vdataF32![offset++] = pvdata[0].x; // position diff --git a/cocos/particle/particle-system.ts b/cocos/particle/particle-system.ts index c374a753227..a9ec7b73e96 100644 --- a/cocos/particle/particle-system.ts +++ b/cocos/particle/particle-system.ts @@ -1413,7 +1413,7 @@ export class ParticleSystem extends ModelRenderer { } // internal function - private _emit (dt): void { + private _emit (dt: number): void { // emit particles. const startDelay = this.startDelay.evaluate(0, 1)!; if (this._time > startDelay) { diff --git a/cocos/particle/renderer/particle-system-renderer-base.ts b/cocos/particle/renderer/particle-system-renderer-base.ts index d8e287843b4..33c598a33ba 100644 --- a/cocos/particle/renderer/particle-system-renderer-base.ts +++ b/cocos/particle/renderer/particle-system-renderer-base.ts @@ -31,9 +31,10 @@ import { Particle, IParticleModule } from '../particle'; import { RenderMode } from '../enum'; import { cclegacy } from '../../core'; import { Pass } from '../../render-scene'; +import type { ParticleSystem } from '../particle-system'; export abstract class ParticleSystemRendererBase { - protected _particleSystem: any = null; + protected _particleSystem: ParticleSystem | null = null; /** * @engineInternal */ diff --git a/cocos/particle/renderer/particle-system-renderer-cpu.ts b/cocos/particle/renderer/particle-system-renderer-cpu.ts index 677758a9c69..fc02bb74010 100644 --- a/cocos/particle/renderer/particle-system-renderer-cpu.ts +++ b/cocos/particle/renderer/particle-system-renderer-cpu.ts @@ -136,6 +136,10 @@ const _matInsInfo: IMaterialInstanceInfo = { subModelIdx: 0, }; +// TODO: we should not use this type, should use a uniform array type instead. +// Tracking issue: +export type PVData = [Vec3, Vec3, Vec3, Vec3, number, Vec3 | null, null]; + export default class ParticleSystemRendererCPU extends ParticleSystemRendererBase { private _defines: MacroRecord; private _trailDefines: MacroRecord; @@ -143,13 +147,13 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas private _tmp_velLenScale: Vec4; private _defaultMat: Material | null = null; private _node_scale: Vec4; - private _attrs: any[]; - private _particles: RecyclePool | null = null; + private _attrs: PVData; + private _particles: RecyclePool | null = null; private _defaultTrailMat: Material | null = null; private _updateList: Map = new Map(); private _animateList: Map = new Map(); private _runAnimateList: IParticleModule[] = new Array(); - private _fillDataFunc: any = null; + private _fillDataFunc: ((p: Particle, idx: number, fi: number) => void) | null = null; private _uScaleHandle = 0; private _uLenHandle = 0; private _uNodeRotHandle = 0; @@ -166,7 +170,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas this._frameTile_velLenScale = new Vec4(1, 1, 0, 0); this._tmp_velLenScale = this._frameTile_velLenScale.clone(); this._node_scale = new Vec4(); - this._attrs = new Array(7); + this._attrs = new Array(7) as PVData; this._defines = { CC_USE_WORLD_SPACE: true, CC_USE_BILLBOARD: true, @@ -293,25 +297,25 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas } } - private doUpdateRotation (pass): void { + private doUpdateRotation (pass: Pass): void { const mode = this._renderInfo!.renderMode; if (mode !== RenderMode.Mesh && this._alignSpace === AlignmentSpace.View) { return; } if (this._alignSpace === AlignmentSpace.Local) { - this._particleSystem.node.getRotation(_node_rot); + this._particleSystem?.node.getRotation(_node_rot); } else if (this._alignSpace === AlignmentSpace.World) { - this._particleSystem.node.getWorldRotation(_node_rot); + this._particleSystem?.node.getWorldRotation(_node_rot); } else if (this._alignSpace === AlignmentSpace.View) { // Quat.fromEuler(_node_rot, 0.0, 0.0, 0.0); _node_rot.set(0.0, 0.0, 0.0, 1.0); - const cameraLst: Camera[]|undefined = this._particleSystem.node.scene.renderScene?.cameras; + const cameraLst: Camera[] | undefined = this._particleSystem?.node.scene.renderScene?.cameras; if (cameraLst !== undefined) { for (let i = 0; i < cameraLst?.length; ++i) { const camera: Camera = cameraLst[i]; // eslint-disable-next-line max-len - const checkCamera: boolean = !EDITOR_NOT_IN_PREVIEW ? (camera.visibility & this._particleSystem.node.layer) === this._particleSystem.node.layer : camera.name === 'Editor Camera'; + const checkCamera: boolean = !EDITOR_NOT_IN_PREVIEW ? (camera.visibility & this._particleSystem!.node.layer) === this._particleSystem!.node.layer : camera.name === 'Editor Camera'; if (checkCamera) { Quat.fromViewUp(_node_rot, camera.forward); break; @@ -333,10 +337,10 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas private doUpdateScale (pass): void { switch (this._particleSystem.scaleSpace) { case Space.Local: - this._particleSystem.node.getScale(this._node_scale); + this._particleSystem?.node.getScale(this._node_scale); break; case Space.World: - this._particleSystem.node.getWorldScale(this._node_scale); + this._particleSystem?.node.getWorldScale(this._node_scale); break; default: break; @@ -358,7 +362,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas this.doUpdateRotation(pass); this._updateList.forEach((value: IParticleModule, key: string): void => { - value.update(ps._simulationSpace, _tempWorldTrans); + value.update(ps.simulationSpace, _tempWorldTrans); }); const trailModule = ps._trailModule; @@ -453,12 +457,12 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas for (let i = 0; i < this._particles!.length; ++i) { const p = this._particles!.data[i]; let fi = 0; - const textureModule = this._particleSystem._textureAnimationModule; + const textureModule = this._particleSystem!._textureAnimationModule; if (textureModule && textureModule.enable) { fi = p.frameIndex; } idx = i * 4; - this._fillDataFunc(p, idx, fi); + this._fillDataFunc!(p, idx, fi); } } From 033fa4be90b5a50d39a015674add30fcb8afe42e Mon Sep 17 00:00:00 2001 From: pp_pro Date: Sun, 25 Jun 2023 18:18:03 +0800 Subject: [PATCH 7/9] fix color type --- cocos/core/math/color.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/core/math/color.ts b/cocos/core/math/color.ts index 63d28b2335b..d5393128af5 100644 --- a/cocos/core/math/color.ts +++ b/cocos/core/math/color.ts @@ -704,7 +704,7 @@ export class Color extends ValueType { /** * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ - public _set_r_unsafe (red): Color { + public _set_r_unsafe (red: number): Color { this._val = ((this._val & 0xffffff00) | red) >>> 0; return this; } @@ -712,7 +712,7 @@ export class Color extends ValueType { /** * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ - public _set_g_unsafe (green): Color { + public _set_g_unsafe (green: number): Color { this._val = ((this._val & 0xffff00ff) | (green << 8)) >>> 0; return this; } @@ -720,7 +720,7 @@ export class Color extends ValueType { /** * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ - public _set_b_unsafe (blue): Color { + public _set_b_unsafe (blue: number): Color { this._val = ((this._val & 0xff00ffff) | (blue << 16)) >>> 0; return this; } @@ -728,7 +728,7 @@ export class Color extends ValueType { /** * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ - public _set_a_unsafe (alpha): Color { + public _set_a_unsafe (alpha: number): Color { this._val = ((this._val & 0x00ffffff) | (alpha << 24)) >>> 0; return this; } From 23402d49895e28887964c052cb047f9f54a9fd9f Mon Sep 17 00:00:00 2001 From: pp_pro Date: Tue, 27 Jun 2023 13:04:04 +0800 Subject: [PATCH 8/9] fix CI --- cocos/core/data/object.ts | 2 +- .../renderer/particle-system-renderer-base.ts | 6 +- .../renderer/particle-system-renderer-cpu.ts | 44 +++++----- .../renderer/particle-system-renderer-gpu.ts | 83 ++++++++++--------- cocos/scene-graph/node.ts | 6 +- cocos/serialization/instantiate.ts | 8 +- cocos/tween/actions/action-manager.ts | 9 +- 7 files changed, 90 insertions(+), 68 deletions(-) diff --git a/cocos/core/data/object.ts b/cocos/core/data/object.ts index d0efe305791..7d0bb9c22c2 100644 --- a/cocos/core/data/object.ts +++ b/cocos/core/data/object.ts @@ -620,7 +620,7 @@ declare namespace CCObject { * @return @en Whether it is a CCObject boolean value. @zh 是否为CCObject的布尔值。 * @engineInternal */ -export function isCCObject (object: any): boolean { +export function isCCObject (object: any): object is CCObject { return object instanceof CCObject; } diff --git a/cocos/particle/renderer/particle-system-renderer-base.ts b/cocos/particle/renderer/particle-system-renderer-base.ts index 33c598a33ba..64e76702973 100644 --- a/cocos/particle/renderer/particle-system-renderer-base.ts +++ b/cocos/particle/renderer/particle-system-renderer-base.ts @@ -63,7 +63,7 @@ export abstract class ParticleSystemRendererBase { return this._renderInfo!; } - public onInit (ps: Component): void { + public onInit (ps: ParticleSystem): void { this._particleSystem = ps; } @@ -94,7 +94,7 @@ export abstract class ParticleSystemRendererBase { if (this._model.scene) { this.detachFromScene(); } - this._particleSystem._getRenderScene().addModel(this._model); + this._particleSystem?._getRenderScene().addModel(this._model); } } @@ -120,7 +120,7 @@ export abstract class ParticleSystemRendererBase { } protected _initModel (): void { - if (!this._model) { + if (!this._model && this._particleSystem) { this._model = cclegacy.director.root.createModel(ParticleBatchModel); this._model!.setCapacity(this._particleSystem.capacity); this._model!.visFlags = this._particleSystem.visibility; diff --git a/cocos/particle/renderer/particle-system-renderer-cpu.ts b/cocos/particle/renderer/particle-system-renderer-cpu.ts index fc02bb74010..78cb25f37f0 100644 --- a/cocos/particle/renderer/particle-system-renderer-cpu.ts +++ b/cocos/particle/renderer/particle-system-renderer-cpu.ts @@ -24,7 +24,7 @@ import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; import { builtinResMgr } from '../../asset/asset-manager'; -import { Material } from '../../asset/assets'; +import { Material, Texture2D } from '../../asset/assets'; import { AttributeName, Format, Attribute, FormatInfos } from '../../gfx'; import { Mat4, Vec2, Vec3, Vec4, pseudoRandom, Quat, EPSILON, approx, RecyclePool } from '../../core'; import { MaterialInstance, IMaterialInstanceInfo } from '../../render-scene/core/material-instance'; @@ -38,6 +38,7 @@ import { Pass } from '../../render-scene'; import { ParticleNoise } from '../noise'; import { NoiseModule } from '../animator/noise-module'; import { isCurveTwoValues } from '../particle-general-function'; +import type { ParticleSystem } from '../particle-system'; const _tempAttribUV = new Vec3(); const _tempWorldTrans = new Mat4(); @@ -146,7 +147,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas private _frameTile_velLenScale: Vec4; private _tmp_velLenScale: Vec4; private _defaultMat: Material | null = null; - private _node_scale: Vec4; + private _node_scale: Vec3; private _attrs: PVData; private _particles: RecyclePool | null = null; private _defaultTrailMat: Material | null = null; @@ -169,7 +170,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas this._frameTile_velLenScale = new Vec4(1, 1, 0, 0); this._tmp_velLenScale = this._frameTile_velLenScale.clone(); - this._node_scale = new Vec4(); + this._node_scale = new Vec3(); this._attrs = new Array(7) as PVData; this._defines = { CC_USE_WORLD_SPACE: true, @@ -184,7 +185,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas }; } - public onInit (ps: Component): void { + public onInit (ps: ParticleSystem): void { super.onInit(ps); this._particles = new RecyclePool((): Particle => new Particle(this), 16); @@ -201,7 +202,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas public clear (): void { super.clear(); this._particles!.reset(); - if (this._particleSystem._trailModule) { + if (this._particleSystem && this._particleSystem._trailModule) { this._particleSystem._trailModule.clear(); } this.updateRenderData(); @@ -221,10 +222,10 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas } public getFreeParticle (): Particle | null { - if (this._particles!.length >= this._particleSystem.capacity) { + if (this._particleSystem && this._particles!.length >= this._particleSystem.capacity) { return null; } - return this._particles!.add() as Particle; + return this._particles!.add(); } public getDefaultTrailMaterial (): any { @@ -236,6 +237,9 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas private _initModuleList (): void { _anim_module.forEach((val): void => { + if (!this._particleSystem) { + return; + } const pm = this._particleSystem[val]; if (pm && pm.enable) { if (pm.needUpdate) { @@ -335,7 +339,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas } private doUpdateScale (pass): void { - switch (this._particleSystem.scaleSpace) { + switch (this._particleSystem?.scaleSpace) { case Space.Local: this._particleSystem?.node.getScale(this._node_scale); break; @@ -368,7 +372,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas const trailModule = ps._trailModule; const trailEnable = trailModule && trailModule.enable; if (trailEnable) { - trailModule.update(); + trailModule!.update(); } const useGravity = !ps.gravityModifier.isZero(); @@ -393,7 +397,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas if (p.remainingLifetime < 0.0) { if (trailEnable) { - trailModule.removeParticle(p); + trailModule!.removeParticle(p); } this._particles!.removeAt(i); --i; @@ -433,7 +437,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas Vec3.scaleAndAdd(p.position, p.position, p.ultimateVelocity, dt); // apply velocity. if (trailEnable) { - trailModule.animate(p, dt); + trailModule!.animate(p, dt); } } @@ -491,9 +495,10 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas if (this._model && index === 0) { this._model.setSubModelMaterial(0, material); } - const trailModule = this._particleSystem._trailModule; - if (trailModule && trailModule._trailModel && index === 1) { - trailModule._trailModel.setSubModelMaterial(0, material); + const trailModule = this._particleSystem!._trailModule; + const trailModel = trailModule?.getModel(); + if (trailModel && index === 1) { + trailModel.setSubModelMaterial(0, material); } } @@ -641,8 +646,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas const ps = this._particleSystem; const shareMaterial = ps.sharedMaterial; if (shareMaterial != null) { - const effectName = shareMaterial._effectAsset._name; - this._renderInfo!.mainTexture = shareMaterial.getProperty('mainTexture', 0); + this._renderInfo!.mainTexture = shareMaterial.getProperty('mainTexture', 0) as Texture2D; } if (ps.sharedMaterial == null && this._defaultMat == null) { @@ -657,8 +661,8 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas this._defaultMat.setProperty('mainTexture', this._renderInfo!.mainTexture); } } - const mat: Material = ps.getMaterialInstance(0) || this._defaultMat; - if (ps._simulationSpace === Space.World) { + const mat: Material = ps.getMaterialInstance(0) || this._defaultMat!; + if (ps.simulationSpace === Space.World) { this._defines[CC_USE_WORLD_SPACE] = true; } else { this._defines[CC_USE_WORLD_SPACE] = false; @@ -719,7 +723,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas } else { this._trailDefines[CC_USE_WORLD_SPACE] = false; } - let mat = ps.getMaterialInstance(1); + let mat: Material | null = ps.getMaterialInstance(1); if (mat === null && this._defaultTrailMat === null) { _matInsInfo.parent = builtinResMgr.get('default-trail-material'); _matInsInfo.owner = this._particleSystem; @@ -729,7 +733,7 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas _matInsInfo.owner = null!; _matInsInfo.subModelIdx = 0; } - mat = mat || this._defaultTrailMat; + mat = mat || this._defaultTrailMat!; mat.recompileShaders(this._trailDefines); trailModule.updateMaterial(); } diff --git a/cocos/particle/renderer/particle-system-renderer-gpu.ts b/cocos/particle/renderer/particle-system-renderer-gpu.ts index 894fc246ab8..10b06d9a1ba 100644 --- a/cocos/particle/renderer/particle-system-renderer-gpu.ts +++ b/cocos/particle/renderer/particle-system-renderer-gpu.ts @@ -37,6 +37,7 @@ import { Pass } from '../../render-scene/core/pass'; import { packCurveRangeXYZ, packCurveRangeZ, packCurveRangeXYZW, packCurveRangeN, packCurveRangeXY } from '../animator/curve-range'; import { ParticleSystemRendererBase } from './particle-system-renderer-base'; import { Camera } from '../../render-scene/scene/camera'; +import type { ParticleSystem } from '../particle-system'; const _tempWorldTrans = new Mat4(); const _tempVec4 = new Vec4(); @@ -133,7 +134,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas private _frameTile_velLenScale: Vec4; private _unifrom_velLenScale: Vec4; private _tmp_velLenScale: Vec4; - private _node_scale: Vec4; + private _node_scale: Vec3; protected _vertAttrs: Attribute[] = []; protected _defaultMat: Material | null = null; private _particleNum = 0; @@ -162,7 +163,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas this._frameTile_velLenScale = new Vec4(1, 1, 0, 0); this._unifrom_velLenScale = this._frameTile_velLenScale.clone(); this._tmp_velLenScale = this._frameTile_velLenScale.clone(); - this._node_scale = new Vec4(); + this._node_scale = new Vec3(); this._defines = { CC_USE_WORLD_SPACE: true, CC_USE_BILLBOARD: true, @@ -176,7 +177,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas this._particleNum = 0; } - public onInit (ps: Component): void { + public onInit (ps: ParticleSystem): void { super.onInit(ps); this._setVertexAttrib(); this._initModel(); @@ -219,7 +220,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } public enableModule (name: string, val: boolean, pm: IParticleModule): void { - const mat: Material | null = this._particleSystem.getMaterialInstance(0) || this._defaultMat; + const mat: Material | null = this._particleSystem?.getMaterialInstance(0) || this._defaultMat; if (!mat) { return; } @@ -231,7 +232,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } public getFreeParticle (): Particle | null { - if (this._particleNum >= this._particleSystem._capacity) { + if (this._particleSystem && this._particleNum >= this._particleSystem?.capacity) { return null; } @@ -239,7 +240,10 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } public setNewParticle (p: Particle): void { - this._model!.addGPUParticleVertexData(p, this._particleNum, this._particleSystem._time); + if (!this._particleSystem) { + return; + } + this._model!.addGPUParticleVertexData(p, this._particleNum, this._particleSystem.time); this._particleNum++; } @@ -260,14 +264,14 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } if (this._alignSpace === AlignmentSpace.Local) { - this._particleSystem.node.getRotation(_node_rot); + this._particleSystem?.node.getRotation(_node_rot); } else if (this._alignSpace === AlignmentSpace.World) { - this._particleSystem.node.getWorldRotation(_node_rot); + this._particleSystem?.node.getWorldRotation(_node_rot); } else if (this._alignSpace === AlignmentSpace.View) { // Quat.fromEuler(_node_rot, 0.0, 0.0, 0.0); _node_rot.set(0.0, 0.0, 0.0, 1.0); - const cameraLst: Camera[]|undefined = this._particleSystem.node.scene.renderScene?.cameras; - if (cameraLst !== undefined) { + const cameraLst: Camera[] | undefined = this._particleSystem?.node.scene.renderScene?.cameras; + if (cameraLst !== undefined && this._particleSystem) { for (let i = 0; i < cameraLst?.length; ++i) { const camera: Camera = cameraLst[i]; // eslint-disable-next-line max-len @@ -291,7 +295,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } private doUpdateScale (pass): void { - switch (this._particleSystem.scaleSpace) { + switch (this._particleSystem?.scaleSpace) { case Space.Local: this._particleSystem.node.getScale(this._node_scale); break; @@ -305,6 +309,9 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } public updateParticles (dt: number): number { + if (!this._particleSystem) { + return this._particleNum; + } if (EDITOR_NOT_IN_PREVIEW) { const mat: Material | null = this._particleSystem.getMaterialInstance(0) || this._defaultMat; @@ -322,7 +329,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas this.initShaderUniform(mat!); } - this._particleNum = this._model!.updateGPUParticles(this._particleNum, this._particleSystem._time, dt); + this._particleNum = this._model!.updateGPUParticles(this._particleNum, this._particleSystem.time, dt); this.updateShaderUniform(dt); this._model!.enabled = this._particleNum > 0; return this._particleNum; @@ -342,13 +349,16 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } public updateShaderUniform (dt: number): void { + if (!this._particleSystem) { + return; + } const mat: Material | null = this._particleSystem.getMaterialInstance(0) || this._defaultMat; if (!mat) { return; } const pass = mat.passes[0]; - _tempVec4.x = this._particleSystem._time; + _tempVec4.x = this._particleSystem.time; _tempVec4.y = dt; pass.setUniform(this._uTimeHandle, _tempVec4); @@ -373,11 +383,11 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas let enable = false; // force - const forceModule = this._particleSystem._forceOvertimeModule; + const forceModule = this._particleSystem?._forceOvertimeModule; enable = forceModule ? forceModule.enable : false; this._defines[FORCE_OVER_TIME_MODULE_ENABLE] = enable; if (enable) { - const packed = packCurveRangeXYZ(this._forceTexture, this._forceData, _sample_num, forceModule.x, forceModule.y, forceModule.z); + const packed = packCurveRangeXYZ(this._forceTexture, this._forceData, _sample_num, forceModule!.x, forceModule!.y, forceModule!.z); this._forceTexture = packed.texture; this._forceData = packed.texdata; const handle = pass.getHandle('force_over_time_tex0'); @@ -385,18 +395,18 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas pass.bindSampler(binding, this._forceTexture.getGFXSampler()!); pass.bindTexture(binding, this._forceTexture.getGFXTexture()!); const spaceHandle = pass.getHandle('u_force_space'); - pass.setUniform(spaceHandle, forceModule.space); + pass.setUniform(spaceHandle, forceModule!.space); const modeHandle = pass.getHandle('u_force_mode'); pass.setUniform(modeHandle, this._forceTexture.height); } // velocity - const velocityModule = this._particleSystem._velocityOvertimeModule; + const velocityModule = this._particleSystem?._velocityOvertimeModule; enable = velocityModule ? velocityModule.enable : false; this._defines[VELOCITY_OVER_TIME_MODULE_ENABLE] = enable; if (enable) { - const packed = packCurveRangeXYZW(this._velocityTexture, this._velocityData, _sample_num, velocityModule.x, velocityModule.y, - velocityModule.z, velocityModule.speedModifier); + const packed = packCurveRangeXYZW(this._velocityTexture, this._velocityData, _sample_num, velocityModule!.x, velocityModule!.y, + velocityModule!.z, velocityModule!.speedModifier); this._velocityTexture = packed.texture; this._velocityData = packed.texdata; const handle = pass.getHandle('velocity_over_time_tex0'); @@ -404,17 +414,17 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas pass.bindSampler(binding, this._velocityTexture.getGFXSampler()!); pass.bindTexture(binding, this._velocityTexture.getGFXTexture()!); const spaceHandle = pass.getHandle('u_velocity_space'); - pass.setUniform(spaceHandle, velocityModule.space); + pass.setUniform(spaceHandle, velocityModule!.space); const modeHandle = pass.getHandle('u_velocity_mode'); pass.setUniform(modeHandle, this._velocityTexture.height); } // color module - const colorModule = this._particleSystem._colorOverLifetimeModule; + const colorModule = this._particleSystem?._colorOverLifetimeModule; enable = colorModule ? colorModule.enable : false; this._defines[COLOR_OVER_TIME_MODULE_ENABLE] = enable; if (enable) { - const packed = packGradientRange(this._colorTexture, this._colorData, _sample_num, colorModule.color); + const packed = packGradientRange(this._colorTexture, this._colorData, _sample_num, colorModule!.color); this._colorTexture = packed.texture; this._colorData = packed.texdata; const handle = pass.getHandle('color_over_time_tex0'); @@ -426,16 +436,16 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } // rotation module - const roationModule = this._particleSystem._rotationOvertimeModule; + const roationModule = this._particleSystem?._rotationOvertimeModule; enable = roationModule ? roationModule.enable : false; this._defines[ROTATION_OVER_TIME_MODULE_ENABLE] = enable; if (enable) { let packed; - if (roationModule.separateAxes) { + if (roationModule!.separateAxes) { // eslint-disable-next-line max-len - packed = packCurveRangeXYZ(this._rotationTexture, this._rotationData, _sample_num, roationModule.x, roationModule.y, roationModule.z); + packed = packCurveRangeXYZ(this._rotationTexture, this._rotationData, _sample_num, roationModule!.x, roationModule!.y, roationModule!.z); } else { - packed = packCurveRangeZ(this._rotationTexture, this._rotationData, _sample_num, roationModule.z); + packed = packCurveRangeZ(this._rotationTexture, this._rotationData, _sample_num, roationModule!.z); } this._rotationTexture = packed.texture; this._rotationData = packed.texdata; @@ -450,15 +460,15 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } // size module - const sizeModule = this._particleSystem._sizeOvertimeModule; + const sizeModule = this._particleSystem?._sizeOvertimeModule; enable = sizeModule ? sizeModule.enable : false; this._defines[SIZE_OVER_TIME_MODULE_ENABLE] = enable; if (enable) { let packed; - if (sizeModule.separateAxes) { - packed = packCurveRangeXYZ(this._sizeTexture, this._sizeData, _sample_num, sizeModule.x, sizeModule.y, sizeModule.z, true); + if (sizeModule!.separateAxes) { + packed = packCurveRangeXYZ(this._sizeTexture, this._sizeData, _sample_num, sizeModule!.x, sizeModule!.y, sizeModule!.z, true); } else { - packed = packCurveRangeN(this._sizeTexture, this._sizeData, _sample_num, sizeModule.size, true); + packed = packCurveRangeN(this._sizeTexture, this._sizeData, _sample_num, sizeModule!.size, true); } this._sizeTexture = packed.texture; this._sizeData = packed.texdata; @@ -473,12 +483,12 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas } // texture module - const textureModule = this._particleSystem._textureAnimationModule; + const textureModule = this._particleSystem?._textureAnimationModule; enable = textureModule ? textureModule.enable : false; this._defines[TEXTURE_ANIMATION_MODULE_ENABLE] = enable; if (enable) { // eslint-disable-next-line max-len - const packed = packCurveRangeXY(this._animTexture, this._animData, _sample_num, textureModule.startFrame, textureModule.frameOverTime, true); + const packed = packCurveRangeXY(this._animTexture, this._animData, _sample_num, textureModule!.startFrame, textureModule!.frameOverTime, true); this._animTexture = packed.texture; this._animData = packed.texdata; const handle = pass.getHandle('texture_animation_tex0'); @@ -487,8 +497,8 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas pass.bindTexture(binding, this._animTexture.getGFXTexture()!); const infoHandle = pass.getHandle('u_anim_info'); _tempVec4.x = this._animTexture.height; - _tempVec4.y = textureModule.numTilesX * textureModule.numTilesY; - _tempVec4.z = textureModule.cycleCount; + _tempVec4.y = textureModule!.numTilesX * textureModule!.numTilesY; + _tempVec4.z = textureModule!.cycleCount; pass.setUniform(infoHandle, _tempVec4); } @@ -572,8 +582,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas const ps = this._particleSystem; const shareMaterial = ps.sharedMaterial; if (shareMaterial !== null) { - const effectName = shareMaterial._effectAsset._name; - this._renderInfo!.mainTexture = shareMaterial.getProperty('mainTexture', 0); + this._renderInfo!.mainTexture = shareMaterial.getProperty('mainTexture', 0) as Texture2D; } if (ps.sharedMaterial == null && this._defaultMat == null) { @@ -592,7 +601,7 @@ export default class ParticleSystemRendererGPU extends ParticleSystemRendererBas ps.node.getWorldMatrix(_tempWorldTrans); - if (ps._simulationSpace === Space.World) { + if (ps.simulationSpace === Space.World) { this._defines[CC_USE_WORLD_SPACE] = true; } else { this._defines[CC_USE_WORLD_SPACE] = false; diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 983caeaeea0..aa7607d4aa1 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -1140,7 +1140,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { default: break; } - this._eventProcessor.on(type, callback, target, useCapture); + this._eventProcessor.on(type as NodeEventType, callback, target, useCapture); } /** @@ -1160,7 +1160,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * ``` */ public off (type: string, callback?: AnyFunction, target?: unknown, useCapture: any = false): void { - this._eventProcessor.off(type, callback, target, useCapture); + this._eventProcessor.off(type as NodeEventType, callback, target, useCapture); const hasListeners = this._eventProcessor.hasEventListener(type); // All listener removed @@ -1188,7 +1188,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { * @param target - The target (this object) to invoke the callback, can be null */ public once (type: string, callback: AnyFunction, target?: unknown, useCapture?: any): void { - this._eventProcessor.once(type, callback, target, useCapture); + this._eventProcessor.once(type as NodeEventType, callback, target, useCapture); } /** diff --git a/cocos/serialization/instantiate.ts b/cocos/serialization/instantiate.ts index 38f38a0bf68..03c0afbff18 100644 --- a/cocos/serialization/instantiate.ts +++ b/cocos/serialization/instantiate.ts @@ -42,6 +42,10 @@ const objsToClearTmpVar: any[] = []; // used to reset _iN$t variable */ type CustomInstantiation = (this: T, instantiated?: T) => T; +function hasImplementedInstantiate (original: any): original is { _instantiate (...args: unknown[]): unknown } { + return typeof original._instantiate === 'function'; +} + /** * @zh 从 Prefab 实例化出新节点。 * @en Instantiate a node from the Prefab. @@ -97,7 +101,7 @@ export function instantiate (original: any, internalForce?: boolean): any { let clone; if (isCCObject(original)) { - if (original._instantiate) { + if (hasImplementedInstantiate(original)) { cclegacy.game._isCloning = true; clone = original._instantiate(null, true); cclegacy.game._isCloning = false; @@ -236,7 +240,7 @@ function instantiateObj (obj: TypedArray | any[] | CCObject, parent: any): any { // eslint-disable-next-line @typescript-eslint/no-unsafe-return return obj; } - let clone: TypedArray | any[] | unknown; + let clone: any; if (ArrayBuffer.isView(obj)) { const len = obj.length; clone = new (obj.constructor as TypedArrayConstructor)(len); diff --git a/cocos/tween/actions/action-manager.ts b/cocos/tween/actions/action-manager.ts index 4efa5a4d945..738a6416bbc 100644 --- a/cocos/tween/actions/action-manager.ts +++ b/cocos/tween/actions/action-manager.ts @@ -30,6 +30,7 @@ import { Action } from './action'; import { Node } from '../../scene-graph'; import { legacyCC } from '../../core/global-exports'; import { isCCObject } from '../../core/data/object'; +import type { ActionInterval } from './action-interval'; let ID_COUNTER = 0; @@ -458,7 +459,7 @@ export class ActionManager { const target = locCurrTarget.target; if (isCCObject(target) && !target.isValid) { - this.removeAllActionsFromTarget(target); + this.removeAllActionsFromTarget(target as unknown as Node); elt--; continue; } @@ -471,7 +472,7 @@ export class ActionManager { if (!locCurrTarget.currentAction) continue; // use for speed - locCurrTarget.currentAction.step(dt * (locCurrTarget.currentAction._speedMethod ? locCurrTarget.currentAction._speed : 1)); + locCurrTarget.currentAction.step(dt * (this._isActionInternal(locCurrTarget.currentAction) ? locCurrTarget.currentAction.getSpeed() : 1)); if (locCurrTarget.currentAction && locCurrTarget.currentAction.isDone()) { locCurrTarget.currentAction.stop(); @@ -493,4 +494,8 @@ export class ActionManager { } } } + + private _isActionInternal (action: any): action is ActionInterval { + return typeof action._speedMethod !== 'undefined'; + } } From 83a93c4bd55bcafe4345a8bf6a938a35e313d444 Mon Sep 17 00:00:00 2001 From: pp_pro Date: Tue, 27 Jun 2023 13:55:50 +0800 Subject: [PATCH 9/9] add tracking issue --- cocos/particle/renderer/particle-system-renderer-cpu.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/particle/renderer/particle-system-renderer-cpu.ts b/cocos/particle/renderer/particle-system-renderer-cpu.ts index 78cb25f37f0..1f80596eca1 100644 --- a/cocos/particle/renderer/particle-system-renderer-cpu.ts +++ b/cocos/particle/renderer/particle-system-renderer-cpu.ts @@ -138,7 +138,7 @@ const _matInsInfo: IMaterialInstanceInfo = { }; // TODO: we should not use this type, should use a uniform array type instead. -// Tracking issue: +// Tracking issue: https://github.com/cocos/cocos-engine/issues/15553 export type PVData = [Vec3, Vec3, Vec3, Vec3, number, Vec3 | null, null]; export default class ParticleSystemRendererCPU extends ParticleSystemRendererBase {