diff --git a/cocos/2d/components/rich-text.ts b/cocos/2d/components/rich-text.ts index 42ff5682d76..e10a6e57d22 100644 --- a/cocos/2d/components/rich-text.ts +++ b/cocos/2d/components/rich-text.ts @@ -27,7 +27,7 @@ import { ccclass, executeInEditMode, executionOrder, help, menu, multiline, type import { DEBUG, DEV, EDITOR } from 'internal:constants'; import { Font, SpriteAtlas, TTFFont, SpriteFrame } from '../assets'; import { EventTouch } from '../../input/types'; -import { assert, warnID, Color, Vec2, CCObject, cclegacy, js, Size } from '../../core'; +import { assert, warnID, Color, Vec2, CCObjectFlags, cclegacy, js, Size } from '../../core'; import { HtmlTextParser, IHtmlTextParserResultObj, IHtmlTextParserStack } from '../utils/html-text-parser'; import { Node } from '../../scene-graph'; import { CacheMode, HorizontalTextAlignment, Label, VerticalTextAlignment } from './label'; @@ -103,7 +103,7 @@ function getSegmentByPool (type: string, content: string | SpriteFrame): ISegmen if (!node) { node = new Node(type); } - node.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy; + node.hideFlags |= CCObjectFlags.DontSave | CCObjectFlags.HideInHierarchy; node.active = true; // Reset node state when use node if (type === RichTextChildImageName) { seg.comp = node.getComponent(Sprite) || node.addComponent(Sprite); diff --git a/cocos/3d/reflection-probe/reflection-probe-component.ts b/cocos/3d/reflection-probe/reflection-probe-component.ts index c94af42f17f..ce98ed5b214 100644 --- a/cocos/3d/reflection-probe/reflection-probe-component.ts +++ b/cocos/3d/reflection-probe/reflection-probe-component.ts @@ -23,7 +23,7 @@ */ import { ccclass, executeInEditMode, help, menu, playOnFocus, serializable, tooltip, type, visible } from 'cc.decorator'; import { EDITOR, EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; -import { CCBoolean, CCObject, Color, screen, Enum, Vec3, warn } from '../../core'; +import { CCBoolean, Color, screen, Enum, Vec3, warn, CCObjectFlags } from '../../core'; import { TextureCube } from '../../asset/assets'; import { scene } from '../../render-scene'; @@ -145,15 +145,15 @@ export class ReflectionProbe extends Component { } this.probe.switchProbeType(value, null); if (EDITOR) { - this._objFlags |= CCObject.Flags.IsRotationLocked; + this._objFlags |= CCObjectFlags.IsRotationLocked; } ReflectionProbeManager.probeManager.clearPlanarReflectionMap(this.probe); } else { if (lastSizeIsNoExist) { this._size.set(ReflectionProbe.DEFAULT_PLANER_SIZE); } - if (EDITOR && this._objFlags & CCObject.Flags.IsRotationLocked) { - this._objFlags ^= CCObject.Flags.IsRotationLocked; + if (EDITOR && this._objFlags & CCObjectFlags.IsRotationLocked) { + this._objFlags ^= CCObjectFlags.IsRotationLocked; } if (!this._sourceCamera) { warn('the reflection camera is invalid, please set the reflection camera'); @@ -426,7 +426,7 @@ export class ReflectionProbe extends Component { this._probe = new scene.ReflectionProbe(this._probeId); if (this._probe) { const cameraNode = new Node('ReflectionProbeCamera'); - cameraNode.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy; + cameraNode.hideFlags |= CCObjectFlags.DontSave | CCObjectFlags.HideInHierarchy; this.node.scene.addChild(cameraNode); this._probe.initialize(this.node, cameraNode); diff --git a/cocos/core/data/index.ts b/cocos/core/data/index.ts index 800783cf829..59c6b40f4e3 100644 --- a/cocos/core/data/index.ts +++ b/cocos/core/data/index.ts @@ -28,7 +28,7 @@ import { legacyCC } from '../global-exports'; legacyCC._decorator = _decorator; export { _decorator }; export { CCClass, isCCClassOrFastDefined } from './class'; -export { CCObject } from './object'; +export { CCObject, CCObjectFlags } from './object'; export { CCInteger, CCFloat, CCBoolean, CCString } from './utils/attribute'; export { CompactValueTypeArray } from './utils/compact-value-type-array'; export { editorExtrasTag } from './editor-extras-tag'; diff --git a/cocos/core/data/object.ts b/cocos/core/data/object.ts index 986aeebd457..d01c5effb64 100644 --- a/cocos/core/data/object.ts +++ b/cocos/core/data/object.ts @@ -30,43 +30,45 @@ import { legacyCC } from '../global-exports'; import { EditorExtendableObject, editorExtrasTag } from './editor-extras-tag'; import { copyAllProperties } from '../utils/js'; -// definitions for CCObject.Flags - -const Destroyed = 1 << 0; -const RealDestroyed = 1 << 1; -const ToDestroy = 1 << 2; -const DontSave = 1 << 3; -const EditorOnly = 1 << 4; -const Dirty = 1 << 5; -const DontDestroy = 1 << 6; -const Destroying = 1 << 7; -const Deactivating = 1 << 8; -const LockedInEditor = 1 << 9; -const HideInHierarchy = 1 << 10; - -const IsOnEnableCalled = 1 << 11; -const IsEditorOnEnableCalled = 1 << 12; -const IsPreloadStarted = 1 << 13; -const IsOnLoadCalled = 1 << 14; -const IsOnLoadStarted = 1 << 15; -const IsStartCalled = 1 << 16; - -const IsRotationLocked = 1 << 17; -const IsScaleLocked = 1 << 18; -const IsAnchorLocked = 1 << 19; -const IsSizeLocked = 1 << 20; -const IsPositionLocked = 1 << 21; - -// var Hide = HideInGame | HideInEditor; -// should not clone or serialize these flags -const PersistentMask = ~(ToDestroy | Dirty | Destroying | DontDestroy | Deactivating - | IsPreloadStarted | IsOnLoadStarted | IsOnLoadCalled | IsStartCalled - | IsOnEnableCalled | IsEditorOnEnableCalled - | IsRotationLocked | IsScaleLocked | IsAnchorLocked | IsSizeLocked | IsPositionLocked -/* RegisteredInEditor */); - -// all the hideFlags -const AllHideMasks = DontSave | EditorOnly | LockedInEditor | HideInHierarchy; +// definitions for CCObjectFlags + +export enum CCObjectFlags { + Destroyed = 1 << 0, + RealDestroyed = 1 << 1, + ToDestroy = 1 << 2, + DontSave = 1 << 3, + EditorOnly = 1 << 4, + Dirty = 1 << 5, + DontDestroy = 1 << 6, + Destroying = 1 << 7, + Deactivating = 1 << 8, + LockedInEditor = 1 << 9, + HideInHierarchy = 1 << 10, + + IsOnEnableCalled = 1 << 11, + IsEditorOnEnableCalled = 1 << 12, + IsPreloadStarted = 1 << 13, + IsOnLoadCalled = 1 << 14, + IsOnLoadStarted = 1 << 15, + IsStartCalled = 1 << 16, + + IsRotationLocked = 1 << 17, + IsScaleLocked = 1 << 18, + IsAnchorLocked = 1 << 19, + IsSizeLocked = 1 << 20, + IsPositionLocked = 1 << 21, + + // var Hide = HideInGame | HideInEditor, + // should not clone or serialize these flags + PersistentMask = ~(ToDestroy | Dirty | Destroying | DontDestroy | Deactivating + | IsPreloadStarted | IsOnLoadStarted | IsOnLoadCalled | IsStartCalled + | IsOnEnableCalled | IsEditorOnEnableCalled + | IsRotationLocked | IsScaleLocked | IsAnchorLocked | IsSizeLocked | IsPositionLocked + /* RegisteredInEditor */), + + // all the hideFlags + AllHideMasks = DontSave | EditorOnly | LockedInEditor | HideInHierarchy, +} const objectsToDestroy: CCObject[] = []; let deferredDestroyTimer: number | null = null; @@ -170,7 +172,7 @@ class CCObject implements EditorExtendableObject { const deleteCount = objectsToDestroy.length; for (let i = 0; i < deleteCount; ++i) { const obj = objectsToDestroy[i]; - if (!(obj._objFlags & Destroyed)) { + if (!(obj._objFlags & CCObjectFlags.Destroyed)) { obj._destroyImmediate(); } } @@ -234,11 +236,11 @@ class CCObject implements EditorExtendableObject { * @zh 在继承 CCObject 对象后,控制是否需要隐藏,锁定,序列化等功能。 */ public set hideFlags (hideFlags: CCObject.Flags) { - const flags = hideFlags & CCObject.Flags.AllHideMasks; - this._objFlags = (this._objFlags & ~CCObject.Flags.AllHideMasks) | flags; + const flags = hideFlags & CCObjectFlags.AllHideMasks; + this._objFlags = (this._objFlags & ~CCObjectFlags.AllHideMasks) | flags; } public get hideFlags (): CCObject.Flags { - return this._objFlags & CCObject.Flags.AllHideMasks; + return this._objFlags & CCObjectFlags.AllHideMasks; } /** @@ -268,7 +270,7 @@ class CCObject implements EditorExtendableObject { * ``` */ get isValid (): boolean { - return !(this._objFlags & Destroyed); + return !(this._objFlags & CCObjectFlags.Destroyed); } /** @@ -288,14 +290,14 @@ class CCObject implements EditorExtendableObject { * ``` */ public destroy (): boolean { - if (this._objFlags & Destroyed) { + if (this._objFlags & CCObjectFlags.Destroyed) { warnID(5000); return false; } - if (this._objFlags & ToDestroy) { + if (this._objFlags & CCObjectFlags.ToDestroy) { return false; } - this._objFlags |= ToDestroy; + this._objFlags |= CCObjectFlags.ToDestroy; objectsToDestroy.push(this); if (EDITOR_NOT_IN_PREVIEW && deferredDestroyTimer === null && legacyCC.engine && !legacyCC.engine._isUpdating) { @@ -358,7 +360,7 @@ class CCObject implements EditorExtendableObject { * @deprecated since v3.5.0, this is an engine private interface that will be removed in the future. */ public _destroyImmediate (): void { - if (this._objFlags & Destroyed) { + if (this._objFlags & CCObjectFlags.Destroyed) { errorID(5000); return; } @@ -378,14 +380,14 @@ class CCObject implements EditorExtendableObject { this._destruct(); } - this._objFlags |= Destroyed; + this._objFlags |= CCObjectFlags.Destroyed; } } const prototype = CCObject.prototype; if (EDITOR || TEST) { js.get(prototype, 'isRealValid', function (this: CCObject) { - return !(this._objFlags & RealDestroyed); + return !(this._objFlags & CCObjectFlags.RealDestroyed); }); /** @@ -399,7 +401,7 @@ if (EDITOR || TEST) { function (this: CCObject) { return this._objFlags; }, - function (this: CCObject, objFlags: CCObject.Flags) { + function (this: CCObject, objFlags: CCObjectFlags) { this._objFlags = objFlags; }, ); @@ -417,16 +419,16 @@ if (EDITOR || TEST) { * issue: https://github.com/cocos/cocos-engine/issues/14643 */ (prototype as any).realDestroyInEditor = function (): void { - if (!(this._objFlags & Destroyed)) { + if (!(this._objFlags & CCObjectFlags.Destroyed)) { warnID(5001); return; } - if (this._objFlags & RealDestroyed) { + if (this._objFlags & CCObjectFlags.RealDestroyed) { warnID(5000); return; } this._destruct(); - this._objFlags |= RealDestroyed; + this._objFlags |= CCObjectFlags.RealDestroyed; }; } @@ -468,35 +470,18 @@ if (EDITOR) { CCClass.fastDefine('cc.Object', CCObject, { _name: '', _objFlags: 0 }); } +const CCObjectFlagsEnum = {}; +for (const key in CCObjectFlags) { + if (typeof key === 'string' && typeof CCObjectFlags[key] === 'number') { + CCObjectFlagsEnum[key] = CCObjectFlags[key]; + } +} /** * Bit mask that controls object states. * @enum Object.Flags * @private */ -js.value(CCObject, 'Flags', { - Destroyed, - DontSave, - EditorOnly, - Dirty, - DontDestroy, - PersistentMask, - Destroying, - Deactivating, - LockedInEditor, - HideInHierarchy, - AllHideMasks, - IsPreloadStarted, - IsOnLoadStarted, - IsOnLoadCalled, - IsOnEnableCalled, - IsStartCalled, - IsEditorOnEnableCalled, - IsPositionLocked, - IsRotationLocked, - IsScaleLocked, - IsAnchorLocked, - IsSizeLocked, -}); +js.value(CCObject, 'Flags', CCObjectFlagsEnum); declare namespace CCObject { export enum Flags { @@ -657,7 +642,7 @@ export function isCCObject (object: any): object is CCObject { */ export function isValid (value: any, strictMode?: boolean): boolean { if (typeof value === 'object') { - return !!value && !(value._objFlags & (strictMode ? (Destroyed | ToDestroy) : Destroyed)); + return !!value && !(value._objFlags & (strictMode ? (CCObjectFlags.Destroyed | CCObjectFlags.ToDestroy) : CCObjectFlags.Destroyed)); } else { return typeof value !== 'undefined'; } @@ -665,9 +650,9 @@ export function isValid (value: any, strictMode?: boolean): boolean { legacyCC.isValid = isValid; if (EDITOR || TEST) { - js.value(CCObject, '_willDestroy', (obj) => !(obj._objFlags & Destroyed) && (obj._objFlags & ToDestroy) > 0); + js.value(CCObject, '_willDestroy', (obj) => !(obj._objFlags & CCObjectFlags.Destroyed) && (obj._objFlags & CCObjectFlags.ToDestroy) > 0); js.value(CCObject, '_cancelDestroy', (obj) => { - obj._objFlags &= ~ToDestroy; + obj._objFlags &= ~CCObjectFlags.ToDestroy; js.array.fastRemove(objectsToDestroy, obj); }); } diff --git a/cocos/dragon-bones/ArmatureDisplay.ts b/cocos/dragon-bones/ArmatureDisplay.ts index 83d67d923fa..40d8f3bf7fa 100644 --- a/cocos/dragon-bones/ArmatureDisplay.ts +++ b/cocos/dragon-bones/ArmatureDisplay.ts @@ -25,7 +25,7 @@ import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; import { Armature, Bone, EventObject, AnimationState } from '@cocos/dragonbones-js'; import { UIRenderer } from '../2d/framework/ui-renderer'; -import { Color, Enum, ccenum, errorID, RecyclePool, js, CCObject, EventTarget, cclegacy, _decorator, warn } from '../core'; +import { Color, Enum, ccenum, errorID, RecyclePool, js, EventTarget, cclegacy, _decorator, warn, CCObjectFlags } from '../core'; import { BlendFactor } from '../gfx'; import { AnimationCache, ArmatureCache, ArmatureFrame } from './ArmatureCache'; import { AttachUtil } from './AttachUtil'; @@ -759,8 +759,7 @@ export class ArmatureDisplay extends UIRenderer { */ _init (): void { if (EDITOR_NOT_IN_PREVIEW) { - const Flags = CCObject.Flags; - this._objFlags |= (Flags.IsAnchorLocked | Flags.IsSizeLocked); + this._objFlags |= (CCObjectFlags.IsAnchorLocked | CCObjectFlags.IsSizeLocked); // this._refreshInspector(); } @@ -998,7 +997,7 @@ export class ArmatureDisplay extends UIRenderer { if (this.debugBones) { if (!this._debugDraw) { const debugDrawNode = new Node('DEBUG_DRAW_NODE'); - debugDrawNode.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy; + debugDrawNode.hideFlags |= CCObjectFlags.DontSave | CCObjectFlags.HideInHierarchy; const debugDraw = debugDrawNode.addComponent(Graphics); debugDraw.lineWidth = 1; debugDraw.strokeColor = new Color(255, 0, 0, 255); diff --git a/cocos/game/director.ts b/cocos/game/director.ts index 30e304bdd36..6d6b2be97a7 100644 --- a/cocos/game/director.ts +++ b/cocos/game/director.ts @@ -29,7 +29,7 @@ import { DEBUG, EDITOR, BUILD, TEST, EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; import { SceneAsset } from '../asset/assets/scene-asset'; -import { System, EventTarget, Scheduler, js, errorID, error, assertID, warnID, macro, CCObject, cclegacy, isValid } from '../core'; +import { System, EventTarget, Scheduler, js, errorID, error, assertID, warnID, macro, CCObject, CCObjectFlags, cclegacy, isValid } from '../core'; import { input } from '../input'; import { Root } from '../root'; import { Node, NodeEventType, Scene } from '../scene-graph'; @@ -422,12 +422,12 @@ export class Director extends EventTarget { // scene also contains the persist node, select the old one const index = existNode.siblingIndex; // restore to the old saving flag - node.hideFlags &= ~CCObject.Flags.DontSave; - node.hideFlags |= CCObject.Flags.DontSave & existNode.hideFlags; + node.hideFlags &= ~CCObjectFlags.DontSave; + node.hideFlags |= CCObjectFlags.DontSave & existNode.hideFlags; existNode._destroyImmediate(); scene.insertChild(node, index); } else { - node.hideFlags |= CCObject.Flags.DontSave; + node.hideFlags |= CCObjectFlags.DontSave; node.parent = scene; } } diff --git a/cocos/particle/burst.ts b/cocos/particle/burst.ts index 4c05efff2dc..3148a9e1c25 100644 --- a/cocos/particle/burst.ts +++ b/cocos/particle/burst.ts @@ -86,12 +86,10 @@ export default class Burst { @range([0, Number.POSITIVE_INFINITY, 1]) public count: CurveRange = new CurveRange(); - private _remainingCount: number; - private _curTime: number; + private _remainingCount = 0; + private _curTime = 0.0; constructor () { - this._remainingCount = 0; - this._curTime = 0.0; } /** @@ -111,7 +109,7 @@ export default class Burst { preFrameTime = (preFrameTime > 0.0) ? preFrameTime : 0.0; const curFrameTime = repeat(psys.time - psys.startDelay.evaluate(0, 1), psys.duration); if (this._curTime >= preFrameTime && this._curTime < curFrameTime) { - (psys as any).emit(this.count.evaluate(this._curTime / psys.duration, 1), dt - (curFrameTime - this._curTime)); + psys.emit(this.count.evaluate(this._curTime / psys.duration, 1), dt - (curFrameTime - this._curTime)); this._curTime += this.repeatInterval; --this._remainingCount; } @@ -133,7 +131,7 @@ export default class Burst { * @param psys @en Particle system to burst. @zh 要触发的粒子系统。 * @returns @en burst max particle count. @zh 一次最多触发的粒子个数。 */ - public getMaxCount (psys): number { + public getMaxCount (psys: ParticleSystem): number { return this.count.getMax() * Math.min(Math.ceil(psys.duration / this.repeatInterval), this.repeatCount); } } diff --git a/cocos/particle/particle-system.ts b/cocos/particle/particle-system.ts index e9e11a8333b..491bb5b881a 100644 --- a/cocos/particle/particle-system.ts +++ b/cocos/particle/particle-system.ts @@ -1332,7 +1332,11 @@ export class ParticleSystem extends ModelRenderer { } } - private emit (count: number, dt: number): void { + /** + * @engineInternal + * emit is used in burst.ts, so it should be public and marked as engine internal. + */ + public emit (count: number, dt: number): void { const self = this; const node = self.node; const loopDelta = (self._time % self.duration) / self.duration; // loop delta value diff --git a/cocos/physics-2d/box2d-wasm/physics-world.ts b/cocos/physics-2d/box2d-wasm/physics-world.ts index b13bb0d35a5..db0e641906f 100644 --- a/cocos/physics-2d/box2d-wasm/physics-world.ts +++ b/cocos/physics-2d/box2d-wasm/physics-world.ts @@ -26,7 +26,7 @@ import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants'; import { B2, getImplPtr, addImplPtrReference, addImplPtrReferenceWASM, getTSObjectFromWASMObjectPtr, removeImplPtrReference, removeImplPtrReferenceWASM, B2ObjectType } from './instantiated'; import { IPhysicsWorld } from '../spec/i-physics-world'; -import { IVec2Like, Vec3, Quat, Vec2, toDegree, Rect, CCObject, js } from '../../core'; +import { IVec2Like, Vec3, Quat, Vec2, toDegree, Rect, CCObjectFlags, js } from '../../core'; import { PHYSICS_2D_PTM_RATIO, ERaycast2DType, ERigidBody2DType } from '../framework/physics-types'; import { Canvas } from '../../2d/framework'; import { Graphics } from '../../2d/components'; @@ -128,7 +128,7 @@ export class B2PhysicsWorld implements IPhysicsWorld { const node = new Node('PHYSICS_2D_DEBUG_DRAW'); // node.zIndex = cc.macro.MAX_ZINDEX; - node.hideFlags |= CCObject.Flags.DontSave; + node.hideFlags |= CCObjectFlags.DontSave; node.parent = canvas; node.worldPosition = Vec3.ZERO; node.layer = Layers.Enum.UI_2D; diff --git a/cocos/physics-2d/box2d/physics-world.ts b/cocos/physics-2d/box2d/physics-world.ts index 67bc585d24e..ef4ef45be66 100644 --- a/cocos/physics-2d/box2d/physics-world.ts +++ b/cocos/physics-2d/box2d/physics-world.ts @@ -26,7 +26,7 @@ import b2 from '@cocos/box2d'; import { EDITOR_NOT_IN_PREVIEW, TEST } from 'internal:constants'; import { IPhysicsWorld } from '../spec/i-physics-world'; -import { IVec2Like, Vec3, Quat, Vec2, toDegree, Rect, CCObject, js } from '../../core'; +import { IVec2Like, Vec3, Quat, Vec2, toDegree, Rect, CCObjectFlags, js } from '../../core'; import { PHYSICS_2D_PTM_RATIO, ERaycast2DType, ERigidBody2DType } from '../framework/physics-types'; import { b2RigidBody2D } from './rigid-body'; import { PhysicsContactListener } from './platform/physics-contact-listener'; @@ -122,7 +122,7 @@ export class b2PhysicsWorld implements IPhysicsWorld { const node = new Node('PHYSICS_2D_DEBUG_DRAW'); // node.zIndex = cc.macro.MAX_ZINDEX; - node.hideFlags |= CCObject.Flags.DontSave; + node.hideFlags |= CCObjectFlags.DontSave; node.parent = canvas; node.worldPosition = Vec3.ZERO; node.layer = Layers.Enum.UI_2D; diff --git a/cocos/physics-2d/builtin/builtin-world.ts b/cocos/physics-2d/builtin/builtin-world.ts index 75f78201615..1c3ac437afb 100644 --- a/cocos/physics-2d/builtin/builtin-world.ts +++ b/cocos/physics-2d/builtin/builtin-world.ts @@ -25,7 +25,7 @@ import { EDITOR_NOT_IN_PREVIEW, TEST } from 'internal:constants'; import { IPhysicsWorld } from '../spec/i-physics-world'; // import { Graphics } from '../../2d'; -import { CCObject, Vec3, Color, IVec2Like, Vec2, Rect, js } from '../../core'; +import { CCObjectFlags, Vec3, Color, IVec2Like, Vec2, Rect, js } from '../../core'; // import { Canvas } from '../../2d/framework'; import { BuiltinShape2D } from './shapes/shape-2d'; import { BuiltinBoxShape } from './shapes/box-shape-2d'; @@ -221,7 +221,7 @@ export class BuiltinPhysicsWorld implements IPhysicsWorld { const node = new Node('PHYSICS_2D_DEBUG_DRAW'); // node.zIndex = cc.macro.MAX_ZINDEX; - node.hideFlags |= CCObject.Flags.DontSave; + node.hideFlags |= CCObjectFlags.DontSave; node.parent = canvas; node.worldPosition = Vec3.ZERO; diff --git a/cocos/profiler/profiler.ts b/cocos/profiler/profiler.ts index fd1a831ce24..1359a908bf2 100644 --- a/cocos/profiler/profiler.ts +++ b/cocos/profiler/profiler.ts @@ -33,7 +33,7 @@ import { Node } from '../scene-graph/node'; import { ICounterOption } from './counter'; import { PerfCounter } from './perf-counter'; import { Pass } from '../render-scene'; -import { preTransforms, System, sys, cclegacy, settings, warnID, SettingsCategory } from '../core'; +import { preTransforms, System, sys, cclegacy, settings, warnID, SettingsCategory, CCObjectFlags } from '../core'; import { Root } from '../root'; import { director, DirectorEvent, game } from '../game'; import { ccwindow } from '../core/global-exports'; @@ -280,7 +280,7 @@ export class Profiler extends System { } this._rootNode = new Node('PROFILER_NODE'); - this._rootNode._objFlags = cclegacy.Object.Flags.DontSave | cclegacy.Object.Flags.HideInHierarchy; + this._rootNode._objFlags = CCObjectFlags.DontSave | CCObjectFlags.HideInHierarchy; game.addPersistRootNode(this._rootNode); const managerNode = new Node('Profiler_Root'); diff --git a/cocos/scene-graph/component-scheduler.ts b/cocos/scene-graph/component-scheduler.ts index 52add2eb662..654086409be 100644 --- a/cocos/scene-graph/component-scheduler.ts +++ b/cocos/scene-graph/component-scheduler.ts @@ -23,7 +23,7 @@ */ import { EDITOR, SUPPORT_JIT, DEV, TEST } from 'internal:constants'; -import { CCObject } from '../core/data/object'; +import { CCObjectFlags } from '../core/data/object'; import { js } from '../core'; import { tryCatchFunctor_EDITOR } from '../core/utils/misc'; import { legacyCC } from '../core/global-exports'; @@ -32,9 +32,9 @@ import type { Component } from './component'; const fastRemoveAt = js.array.fastRemoveAt; -const IsStartCalled = CCObject.Flags.IsStartCalled; -const IsOnEnableCalled = CCObject.Flags.IsOnEnableCalled; -const IsEditorOnEnableCalled = CCObject.Flags.IsEditorOnEnableCalled; +const IsStartCalled = CCObjectFlags.IsStartCalled; +const IsOnEnableCalled = CCObjectFlags.IsOnEnableCalled; +const IsEditorOnEnableCalled = CCObjectFlags.IsEditorOnEnableCalled; const callerFunctor: any = EDITOR && tryCatchFunctor_EDITOR; const callOnEnableInTryCatch: any = EDITOR && callerFunctor('onEnable'); diff --git a/cocos/scene-graph/component.ts b/cocos/scene-graph/component.ts index f48cf3c1eb8..fe964776061 100644 --- a/cocos/scene-graph/component.ts +++ b/cocos/scene-graph/component.ts @@ -26,7 +26,7 @@ import { ccclass, tooltip, displayName, type, serializable, disallowAnimation } from 'cc.decorator'; import { EDITOR, TEST } from 'internal:constants'; import { Script } from '../asset/assets/scripts'; -import { CCObject } from '../core/data/object'; +import { CCObject, CCObjectFlags } from '../core/data/object'; import { IDGenerator } from '../core/utils/id-generator'; import { getClassName, value } from '../core/utils/js'; import { RenderScene } from '../render-scene/core/render-scene'; @@ -39,7 +39,7 @@ import { CompPrefabInfo } from './prefab/prefab-info'; import { EventHandler } from './component-event-handler'; const idGenerator = new IDGenerator('Comp'); -const IsOnLoadCalled = CCObject.Flags.IsOnLoadCalled; +const IsOnLoadCalled = CCObjectFlags.IsOnLoadCalled; const NullNode = null as unknown as Node; diff --git a/cocos/scene-graph/deprecated.ts b/cocos/scene-graph/deprecated.ts index cc20fb0f056..67a382a3a10 100644 --- a/cocos/scene-graph/deprecated.ts +++ b/cocos/scene-graph/deprecated.ts @@ -30,7 +30,7 @@ import { Node } from './node'; import { Vec2 } from '../core/math/vec2'; import { Size } from '../core/math/size'; import { legacyCC } from '../core/global-exports'; -import { CCObject } from '../core/data/object'; +import { CCObjectFlags } from '../core/data/object'; import { warnID } from '../core/platform/debug'; import { SceneGlobals } from './scene-globals'; import { SystemEventType } from '../input/types'; @@ -298,8 +298,8 @@ removeProperty(Layers.BitMask, 'Layers.BitMask', [ }, ]); -const HideInHierarchy = CCObject.Flags.HideInHierarchy; -const DontSave = CCObject.Flags.DontSave; +const HideInHierarchy = CCObjectFlags.HideInHierarchy; +const DontSave = CCObjectFlags.DontSave; /** * @internal diff --git a/cocos/scene-graph/node-activator.ts b/cocos/scene-graph/node-activator.ts index 72d5e5950aa..294a41805ab 100644 --- a/cocos/scene-graph/node-activator.ts +++ b/cocos/scene-graph/node-activator.ts @@ -23,7 +23,7 @@ */ import { EDITOR, DEV, SUPPORT_JIT, DEBUG } from 'internal:constants'; -import { CCObject, isValid } from '../core/data/object'; +import { CCObjectFlags, isValid } from '../core/data/object'; import { array, Pool } from '../core/utils/js'; import { tryCatchFunctor_EDITOR } from '../core/utils/misc'; import { invokeOnEnable, createInvokeImpl, createInvokeImplJit, OneOffInvoker, LifeCycleInvoker, InvokeFunc } from './component-scheduler'; @@ -36,11 +36,11 @@ import type { Node } from './node'; const MAX_POOL_SIZE = 4; -const IsPreloadStarted = CCObject.Flags.IsPreloadStarted; -const IsOnLoadStarted = CCObject.Flags.IsOnLoadStarted; -const IsOnLoadCalled = CCObject.Flags.IsOnLoadCalled; -const IsOnEnableCalled = CCObject.Flags.IsOnEnableCalled; -const Deactivating = CCObject.Flags.Deactivating; +const IsPreloadStarted = CCObjectFlags.IsPreloadStarted; +const IsOnLoadStarted = CCObjectFlags.IsOnLoadStarted; +const IsOnLoadCalled = CCObjectFlags.IsOnLoadCalled; +const IsOnEnableCalled = CCObjectFlags.IsOnEnableCalled; +const Deactivating = CCObjectFlags.Deactivating; // for __preload: used internally, no sort class UnsortedInvoker extends LifeCycleInvoker { diff --git a/cocos/scene-graph/node-dev.ts b/cocos/scene-graph/node-dev.ts index cae8b7f732f..e4aa2a1941c 100644 --- a/cocos/scene-graph/node-dev.ts +++ b/cocos/scene-graph/node-dev.ts @@ -23,13 +23,13 @@ */ import { EDITOR, DEV, TEST } from 'internal:constants'; -import { CCObject } from '../core/data/object'; +import { CCObjectFlags } from '../core/data/object'; import * as js from '../core/utils/js'; import { legacyCC } from '../core/global-exports'; import { error, errorID, getError } from '../core/platform/debug'; import { Component } from './component'; -const Destroying = CCObject.Flags.Destroying; +const Destroying = CCObjectFlags.Destroying; const IS_PREVIEW = !!legacyCC.GAME_VIEW; export function nodePolyfill (Node): void { diff --git a/cocos/scene-graph/node.jsb.ts b/cocos/scene-graph/node.jsb.ts index e686de1ac1e..438b6c046c6 100644 --- a/cocos/scene-graph/node.jsb.ts +++ b/cocos/scene-graph/node.jsb.ts @@ -25,7 +25,7 @@ import { cclegacy } from '../core/global-exports'; import { errorID, getError } from '../core/platform/debug'; import { Component } from './component'; import { NodeEventType } from './node-event'; -import { CCObject } from '../core/data/object'; +import { CCObjectFlags } from '../core/data/object'; import { NodeUIProperties } from './node-ui-properties'; import { MobilityMode, NodeSpace, TransformBit } from './node-enum'; import { Mat4, Quat, Vec3 } from '../core/math'; @@ -84,7 +84,7 @@ const TRANSFORMBIT_TRS = TransformBit.TRS; const nodeProto: any = jsb.Node.prototype; export const TRANSFORM_ON = 1 << 0; const ACTIVE_ON = 1 << 1; -const Destroying = CCObject.Flags.Destroying; +const Destroying = CCObjectFlags.Destroying; // TODO: `_setTempFloatArray` is only implemented on Native platforms. @dumganhar // issue: https://github.com/cocos/cocos-engine/issues/14644 diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 99db8dd020f..34fc4ce0e50 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -35,7 +35,7 @@ import { CustomSerializable, editorExtrasTag, SerializationContext, Serializatio import { errorID, warnID, error, log, getError } from '../core/platform/debug'; import { Component } from './component'; import { property } from '../core/data/decorators/property'; -import { CCObject, js } from '../core'; +import { CCObject, CCObjectFlags, js } from '../core'; import { PrefabInfo, PrefabInstance } from './prefab/prefab-info'; import { NodeEventType } from './node-event'; import { Event } from '../input/types'; @@ -46,9 +46,9 @@ import type { Director } from '../game/director'; import type { Game } from '../game/game'; import type { UITransform } from '../2d/framework/ui-transform'; -const Destroying = CCObject.Flags.Destroying; -const DontDestroy = CCObject.Flags.DontDestroy; -const Deactivating = CCObject.Flags.Deactivating; +const Destroying = CCObjectFlags.Destroying; +const DontDestroy = CCObjectFlags.DontDestroy; +const Deactivating = CCObjectFlags.Deactivating; export const TRANSFORM_ON = 1 << 0; const ACTIVE_ON = 1 << 1; @@ -1917,11 +1917,10 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { } this.hasChangedFlags = TransformBit.TRS; - const len = this._children.length; - for (let i = 0; i < len; ++i) { - this._children[i]._siblingIndex = i; - this._children[i]._onBatchCreated(dontSyncChildPrefab); - } + this._children.forEach((child: Node, i: number) => { + child._siblingIndex = i; + child._onBatchCreated(dontSyncChildPrefab); + }); } /** @@ -2099,31 +2098,35 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { cur = cur._parent; } let child: Node; + let childMat: Mat4; + let childPos: Vec3; let dirtyBits = 0; while (i) { child = dirtyNodes[--i]; + childMat = child._mat; + childPos = child._pos; dirtyBits |= child._transformFlags; if (cur) { if (dirtyBits & TransformBit.POSITION) { - Vec3.transformMat4(child._pos, child._lpos, cur._mat); - child._mat.m12 = child._pos.x; - child._mat.m13 = child._pos.y; - child._mat.m14 = child._pos.z; + Vec3.transformMat4(childPos, child._lpos, cur._mat); + childMat.m12 = childPos.x; + childMat.m13 = childPos.y; + childMat.m14 = childPos.z; } if (dirtyBits & TransformBit.RS) { - Mat4.fromSRT(child._mat, child._lrot, child._lpos, child._lscale); - Mat4.multiply(child._mat, cur._mat, child._mat); + Mat4.fromSRT(childMat, child._lrot, child._lpos, child._lscale); + Mat4.multiply(childMat, cur._mat, childMat); const rotTmp = dirtyBits & TransformBit.ROTATION ? child._rot : null; - Mat4.toSRT(child._mat, rotTmp, null, child._scale); + Mat4.toSRT(childMat, rotTmp, null, child._scale); } } else { if (dirtyBits & TransformBit.POSITION) { - Vec3.copy(child._pos, child._lpos); - child._mat.m12 = child._pos.x; - child._mat.m13 = child._pos.y; - child._mat.m14 = child._pos.z; + Vec3.copy(childPos, child._lpos); + childMat.m12 = childPos.x; + childMat.m13 = childPos.y; + childMat.m14 = childPos.z; } if (dirtyBits & TransformBit.RS) { if (dirtyBits & TransformBit.ROTATION) { @@ -2132,7 +2135,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { if (dirtyBits & TransformBit.SCALE) { Vec3.copy(child._scale, child._lscale); } - Mat4.fromRTS(child._mat, child._rot, child._pos, child._scale); + Mat4.fromRTS(childMat, child._rot, child._pos, child._scale); } } diff --git a/cocos/serialization/instantiate-jit.ts b/cocos/serialization/instantiate-jit.ts index 98185f17ad3..9e1eb0c7b68 100644 --- a/cocos/serialization/instantiate-jit.ts +++ b/cocos/serialization/instantiate-jit.ts @@ -26,10 +26,10 @@ // Some helper methods for compile instantiation code import { TEST } from 'internal:constants'; -import { CCClass, isCCClassOrFastDefined, js, CCObject, isCCObject, cclegacy, flattenCodeArray } from '../core'; +import { CCClass, isCCClassOrFastDefined, js, CCObjectFlags, isCCObject, cclegacy, flattenCodeArray } from '../core'; -const Destroyed = CCObject.Flags.Destroyed; -const PersistentMask = CCObject.Flags.PersistentMask; +const Destroyed = CCObjectFlags.Destroyed; +const PersistentMask = CCObjectFlags.PersistentMask; const DEFAULT = `${CCClass.Attr.DELIMETER}default`; const IDENTIFIER_RE = CCClass.IDENTIFIER_RE; diff --git a/cocos/serialization/instantiate.ts b/cocos/serialization/instantiate.ts index f1d124c0cb3..aec26f16add 100644 --- a/cocos/serialization/instantiate.ts +++ b/cocos/serialization/instantiate.ts @@ -24,14 +24,14 @@ */ import { DEV, JSB } from 'internal:constants'; -import { CCObject, isCCObject, js, ValueType, isCCClassOrFastDefined, getError, warn, misc, cclegacy } from '../core'; +import { CCObject, CCObjectFlags, isCCObject, js, ValueType, 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'; import { updateChildrenForDeserialize } from '../core/utils/jsb-utils'; -const Destroyed = CCObject.Flags.Destroyed; -const PersistentMask = CCObject.Flags.PersistentMask; +const Destroyed = CCObjectFlags.Destroyed; +const PersistentMask = CCObjectFlags.PersistentMask; const objsToClearTmpVar: any[] = []; // used to reset _iN$t variable diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 95091b81696..f9b6034a3cd 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -27,7 +27,7 @@ import { Material, Texture2D } from '../asset/assets'; import { error, logID, warn } from '../core/platform/debug'; import { Enum, EnumType, ccenum } from '../core/value-types/enum'; import { Node, NodeEventType } from '../scene-graph'; -import { CCObject, Color, RecyclePool, js } from '../core'; +import { CCObjectFlags, Color, RecyclePool, js } from '../core'; import { SkeletonData } from './skeleton-data'; import { Graphics, UIRenderer } from '../2d'; import { Batcher2D } from '../2d/renderer/batcher-2d'; @@ -1614,7 +1614,7 @@ export class Skeleton extends UIRenderer { if (!this._debugRenderer) { const debugDrawNode = new Node('DEBUG_DRAW_NODE'); debugDrawNode.layer = this.node.layer; - debugDrawNode.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy; + debugDrawNode.hideFlags |= CCObjectFlags.DontSave | CCObjectFlags.HideInHierarchy; const debugDraw = debugDrawNode.addComponent(Graphics); debugDraw.lineWidth = 5; debugDraw.strokeColor = new Color(255, 0, 0, 255); diff --git a/cocos/terrain/terrain.ts b/cocos/terrain/terrain.ts index e59408f424a..c4abe8ff657 100644 --- a/cocos/terrain/terrain.ts +++ b/cocos/terrain/terrain.ts @@ -31,7 +31,7 @@ import { TextureFilter, PixelFormat, WrapMode } from '../asset/assets/asset-enum import { Material } from '../asset/assets/material'; import { RenderingSubMesh } from '../asset/assets/rendering-sub-mesh'; import { Component } from '../scene-graph/component'; -import { CCObject, isValid } from '../core/data/object'; +import { CCObjectFlags, isValid } from '../core/data/object'; import { director } from '../game/director'; import { AttributeName, BufferUsageBit, Format, MemoryUsageBit, PrimitiveMode, Attribute, Buffer, BufferInfo, deviceManager, Texture } from '../gfx'; import { clamp, Rect, Size, Vec2, Vec3, Vec4 } from '../core/math'; @@ -418,7 +418,7 @@ export class TerrainBlock { this._node = new Node('TerrainBlock'); this._node.setParent(this._terrain.node); - this._node.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy; + this._node.hideFlags |= CCObjectFlags.DontSave | CCObjectFlags.HideInHierarchy; this._node.layer = this._terrain.node.layer; this._renderable = this._node.addComponent(TerrainRenderable); diff --git a/cocos/tiledmap/tiled-object-group.ts b/cocos/tiledmap/tiled-object-group.ts index 79cf555a12c..0ffc066d6c0 100644 --- a/cocos/tiledmap/tiled-object-group.ts +++ b/cocos/tiledmap/tiled-object-group.ts @@ -32,7 +32,7 @@ import { BlendFactor } from '../gfx'; import { TMXMapInfo } from './tmx-xml-parser'; import { TiledTextureGrids, GID, TileFlag, Orientation, StaggerAxis, TMXObjectType, PropertiesInfo, TiledAnimationType, TMXObject, TMXObjectGroupInfo } from './tiled-types'; import { UITransform } from '../2d/framework/ui-transform'; -import { CCBoolean, Vec2, Color, CCObject } from '../core'; +import { CCBoolean, Vec2, Color, CCObjectFlags } from '../core'; import { SpriteFrame } from '../2d/assets'; import { Node } from '../scene-graph/node'; @@ -293,9 +293,9 @@ export class TiledObjectGroup extends Component { // Delete image nodes implemented as private nodes // Use cc.Node to implement node-level requirements - if (imgNode && (imgNode._objFlags & CCObject.Flags.HideInHierarchy)) { + if (imgNode && (imgNode._objFlags & CCObjectFlags.HideInHierarchy)) { imgNode.removeFromParent(); - imgNode.hideFlags |= CCObject.Flags.DontSave; + imgNode.hideFlags |= CCObjectFlags.DontSave; imgNode.destroy(); imgNode = null; } diff --git a/cocos/ui/sub-context-view.ts b/cocos/ui/sub-context-view.ts index e2cac9207f9..e20b9ce3b42 100644 --- a/cocos/ui/sub-context-view.ts +++ b/cocos/ui/sub-context-view.ts @@ -37,7 +37,7 @@ import { Size } from '../core/math'; import { legacyCC } from '../core/global-exports'; import { NodeEventType } from '../scene-graph/node-event'; -import { CCObject } from '../core'; +import { CCObjectFlags } from '../core'; import { Texture2D } from '../asset/assets'; /** @@ -118,7 +118,7 @@ export class SubContextView extends Component { constructor () { super(); - this._content.hideFlags |= CCObject.Flags.DontSave | CCObject.Flags.HideInHierarchy; + this._content.hideFlags |= CCObjectFlags.DontSave | CCObjectFlags.HideInHierarchy; this._updatedTime = performance.now(); } @@ -167,7 +167,7 @@ export class SubContextView extends Component { private _initContentNode (): void { if (this._openDataContext) { - const sharedCanvas = this._openDataContext.canvas; + const sharedCanvas: HTMLCanvasElement = this._openDataContext.canvas; const image = this._imageAsset; image.reset(sharedCanvas); @@ -240,7 +240,7 @@ export class SubContextView extends Component { return; } - const sharedCanvas = this._openDataContext.canvas; + const sharedCanvas: HTMLCanvasElement = this._openDataContext.canvas; img.reset(sharedCanvas); if (sharedCanvas.width > img.width || sharedCanvas.height > img.height) { this._texture.create(sharedCanvas.width, sharedCanvas.height);