mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Merge _flagChangeVersion and _hasChangedFlags, Use Single uint32_t to Save Memory and Avoid Inconsistencies (#14454)
* merge _flagChangeVersion & _hasChangedFlags into single uint32_t
This commit is contained in:
@@ -215,7 +215,7 @@ nodeProto.addComponent = function (typeOrClassName) {
|
||||
legacyCC.director._nodeActivator.activateComp(component);
|
||||
}
|
||||
if (EDITOR && !legacyCC.GAME_VIEW) {
|
||||
component.resetInEditor?.()
|
||||
component.resetInEditor?.();
|
||||
}
|
||||
|
||||
return component;
|
||||
|
||||
@@ -73,7 +73,10 @@ const m4_2 = new Mat4();
|
||||
const dirtyNodes: any[] = [];
|
||||
|
||||
const reserveContentsForAllSyncablePrefabTag = Symbol('ReserveContentsForAllSyncablePrefab');
|
||||
let globalFlagChangeVersion = 0;
|
||||
|
||||
// The default value of the global version should be higher than the default value of the node's changedVersion,
|
||||
// to ensure that the changeFlags of a node are initialized to 0.
|
||||
let globalFlagChangeVersion = 1;
|
||||
|
||||
/**
|
||||
* @zh
|
||||
@@ -997,7 +1000,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
|
||||
legacyCC.director._nodeActivator.activateComp(component);
|
||||
}
|
||||
if (EDITOR && !legacyCC.GAME_VIEW) {
|
||||
component.resetInEditor?.()
|
||||
component.resetInEditor?.();
|
||||
}
|
||||
|
||||
return component;
|
||||
@@ -1475,8 +1478,12 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
|
||||
protected _dirtyFlags = TransformBit.NONE; // does the world transform need to update?
|
||||
protected _eulerDirty = false;
|
||||
|
||||
protected _flagChangeVersion = 0;
|
||||
protected _hasChangedFlags = 0;
|
||||
/**
|
||||
* The high bits are used to store the version number of the changedFlag, and the low 3 bits represent its specific value
|
||||
*
|
||||
* | 31 - 29 reserved | 28 - 3 version number | 2 - 0 : Scale Rotation Translation|
|
||||
*/
|
||||
protected _changedVersionAndRTS = 0;
|
||||
|
||||
constructor (name?: string) {
|
||||
super(name);
|
||||
@@ -1707,12 +1714,11 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
|
||||
* @zh 这个节点的空间变换信息在当前帧内是否有变过?
|
||||
*/
|
||||
get hasChangedFlags () {
|
||||
return this._flagChangeVersion === globalFlagChangeVersion ? this._hasChangedFlags : 0;
|
||||
return (this._changedVersionAndRTS >>> 3) === globalFlagChangeVersion ? (this._changedVersionAndRTS & 7) : 0;
|
||||
}
|
||||
|
||||
set hasChangedFlags (val: number) {
|
||||
this._flagChangeVersion = globalFlagChangeVersion;
|
||||
this._hasChangedFlags = val;
|
||||
this._changedVersionAndRTS = (globalFlagChangeVersion << 3) | val;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2506,7 +2512,8 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
|
||||
* 清除所有节点的脏标记。
|
||||
*/
|
||||
public static resetHasChangedFlags () {
|
||||
globalFlagChangeVersion += 1;
|
||||
// Using 26 bits for the flags is sufficient.
|
||||
globalFlagChangeVersion = (globalFlagChangeVersion + 1) & 0x3FFFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace cc {
|
||||
uint32_t Node::clearFrame{0};
|
||||
uint32_t Node::clearRound{1000};
|
||||
const uint32_t Node::TRANSFORM_ON{1 << 0};
|
||||
uint32_t Node::globalFlagChangeVersion{0};
|
||||
uint32_t Node::globalFlagChangeVersion{1};
|
||||
|
||||
namespace {
|
||||
const ccstd::string EMPTY_NODE_NAME;
|
||||
@@ -775,10 +775,6 @@ void Node::setRTSInternal(Quaternion *rot, Vec3 *pos, Vec3 *scale, bool calledFr
|
||||
}
|
||||
}
|
||||
|
||||
void Node::resetChangedFlags() {
|
||||
globalFlagChangeVersion++;
|
||||
}
|
||||
|
||||
void Node::clearNodeArray() {
|
||||
if (clearFrame < clearRound) {
|
||||
clearFrame++;
|
||||
|
||||
@@ -127,7 +127,11 @@ public:
|
||||
template <typename T>
|
||||
static bool isNode(T *obj);
|
||||
|
||||
static void resetChangedFlags();
|
||||
inline static void resetChangedFlags() {
|
||||
// Using 26 bits for the flags is sufficient.
|
||||
globalFlagChangeVersion = (globalFlagChangeVersion + 1) & 0x3FFFFFF;
|
||||
}
|
||||
|
||||
static void clearNodeArray();
|
||||
|
||||
Node();
|
||||
@@ -463,11 +467,10 @@ public:
|
||||
* @zh 这个节点的空间变换信息在当前帧内是否有变过?
|
||||
*/
|
||||
inline uint32_t getChangedFlags() const {
|
||||
return _hasChangedFlagsVersion == globalFlagChangeVersion ? _hasChangedFlags : 0;
|
||||
return (_changedVersionAndRTS >> 3) == globalFlagChangeVersion ? (_changedVersionAndRTS & 0x7) : 0;
|
||||
}
|
||||
inline void setChangedFlags(uint32_t value) {
|
||||
_hasChangedFlagsVersion = globalFlagChangeVersion;
|
||||
_hasChangedFlags = value;
|
||||
_changedVersionAndRTS = (globalFlagChangeVersion << 3) | value;
|
||||
}
|
||||
|
||||
inline void setDirtyFlag(uint32_t value) { _dirtyFlag = value; }
|
||||
@@ -657,11 +660,12 @@ private:
|
||||
uint8_t _isStatic{0}; // Uint8: 2
|
||||
uint8_t _padding{0}; // Uint8: 3
|
||||
|
||||
/* set _hasChangedFlagsVersion to globalFlagChangeVersion when `_hasChangedFlags` updated.
|
||||
* `globalFlagChangeVersion == _hasChangedFlagsVersion` means that "_hasChangedFlags is dirty in current frametime".
|
||||
*/
|
||||
uint32_t _hasChangedFlagsVersion{0};
|
||||
uint32_t _hasChangedFlags{0};
|
||||
/**
|
||||
* The high bits are used to store the version number of the changeflag, and the low 3 bits represent its specific value
|
||||
*
|
||||
* | 31 - 29 reserved | 28 - 3 version number | 2 - 0 : Scale Rotation Translation|
|
||||
*/
|
||||
uint32_t _changedVersionAndRTS{0};
|
||||
|
||||
bool _eulerDirty{false};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user