Skip to content

Commit

Permalink
[v3.8.6] Inline enums for CCObjectFlags.
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Jan 14, 2025
1 parent b4c572b commit 040fdd1
Show file tree
Hide file tree
Showing 25 changed files with 168 additions and 162 deletions.
4 changes: 2 additions & 2 deletions cocos/2d/components/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions cocos/3d/reflection-probe/reflection-probe-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion cocos/core/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
150 changes: 76 additions & 74 deletions cocos/core/data/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,43 @@ 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;
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;
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -268,7 +270,7 @@ class CCObject implements EditorExtendableObject {
* ```
*/
get isValid (): boolean {
return !(this._objFlags & Destroyed);
return !(this._objFlags & CCObjectFlags.Destroyed);
}

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
});

/**
Expand Down Expand Up @@ -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;
};
}

Expand Down Expand Up @@ -474,28 +476,28 @@ if (EDITOR) {
* @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,
Destroyed: CCObjectFlags.Destroyed,
DontSave: CCObjectFlags.DontSave,
EditorOnly: CCObjectFlags.EditorOnly,
Dirty: CCObjectFlags.Dirty,
DontDestroy: CCObjectFlags.DontDestroy,
PersistentMask: CCObjectFlags.PersistentMask,
Destroying: CCObjectFlags.Destroying,
Deactivating: CCObjectFlags.Deactivating,
LockedInEditor: CCObjectFlags.LockedInEditor,
HideInHierarchy: CCObjectFlags.HideInHierarchy,
AllHideMasks: CCObjectFlags.AllHideMasks,
IsPreloadStarted: CCObjectFlags.IsPreloadStarted,
IsOnLoadStarted: CCObjectFlags.IsOnLoadStarted,
IsOnLoadCalled: CCObjectFlags.IsOnLoadCalled,
IsOnEnableCalled: CCObjectFlags.IsOnEnableCalled,
IsStartCalled: CCObjectFlags.IsStartCalled,
IsEditorOnEnableCalled: CCObjectFlags.IsEditorOnEnableCalled,
IsPositionLocked: CCObjectFlags.IsPositionLocked,
IsRotationLocked: CCObjectFlags.IsRotationLocked,
IsScaleLocked: CCObjectFlags.IsScaleLocked,
IsAnchorLocked: CCObjectFlags.IsAnchorLocked,
IsSizeLocked: CCObjectFlags.IsSizeLocked,
});

declare namespace CCObject {
Expand Down Expand Up @@ -657,17 +659,17 @@ 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';
}
}
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);
});
}
Expand Down
7 changes: 3 additions & 4 deletions cocos/dragon-bones/ArmatureDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions cocos/game/director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
}
Expand Down
10 changes: 4 additions & 6 deletions cocos/particle/burst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}
Expand All @@ -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);
}
}
Loading

0 comments on commit 040fdd1

Please sign in to comment.