Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3.8.6] Optimize code size: Add an internal method ( Node.getUITransformComp ) which could be mangled to avoid invoking the code ._uiProps.uiTransformComp that could not be mangled. #18165

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cocos/2d/assembler/label/bmfontUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const bmfontUtils = {

if (comp.renderData.vertDirty) {
_comp = comp;
_uiTrans = _comp.node._uiProps.uiTransformComp!;
_uiTrans = _comp.node._getUITransformComp()!;
const renderData = comp.renderData;

const processing = TextProcessing.instance;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/label/ttf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const ttf: IAssembler = {
if (!renderData) {
return;
}
const uiTrans = comp.node._uiProps.uiTransformComp!;
const uiTrans = comp.node._getUITransformComp()!;
const width = uiTrans.width;
const height = uiTrans.height;
const appX = uiTrans.anchorX * width;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/label/ttfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const ttfUtils = {
if (!comp.renderData) { return; }

if (comp.renderData.vertDirty) {
const trans = comp.node._uiProps.uiTransformComp!;
const trans = comp.node._getUITransformComp()!;
const processing = TextProcessing.instance;
const style = comp.textStyle;
const layout = comp.textLayout;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/bar-filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const barFilled: IAssembler = {
updateVertexData (sprite: Sprite, fillStart: number, fillEnd: number) {
const renderData: RenderData | null = sprite.renderData;
const dataList: IRenderData[] = renderData!.data;
const uiTrans = sprite.node._uiProps.uiTransformComp!;
const uiTrans = sprite.node._getUITransformComp()!;
const width = uiTrans.width;
const height = uiTrans.height;
const appX = uiTrans.anchorX * width;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/radial-filled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function _calcIntersectedPoints (
}

function _calculateVertices (sprite: Sprite): void {
const uiTrans = sprite.node._uiProps.uiTransformComp!;
const uiTrans = sprite.node._getUITransformComp()!;
const width = uiTrans.width;
const height = uiTrans.height;
const appX = uiTrans.anchorX * width;
Expand Down
10 changes: 5 additions & 5 deletions cocos/2d/assembler/sprite/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ const QUAD_INDICES = Uint16Array.from([0, 1, 2, 1, 3, 2]);
* 可通过 `UI.simple` 获取该组装器。
*/
export const simple: IAssembler = {
createData(sprite: Sprite) {
createData (sprite: Sprite) {
const renderData = sprite.requestRenderData();
renderData.dataLength = 4;
renderData.resize(4, 6);
renderData.chunk.setIndexBuffer(QUAD_INDICES);
return renderData;
},

updateRenderData(sprite: Sprite) {
updateRenderData (sprite: Sprite) {
const frame = sprite.spriteFrame;

dynamicAtlasManager.packToDynamicAtlas(sprite, frame);
Expand Down Expand Up @@ -95,7 +95,7 @@ export const simple: IAssembler = {
}
},

fillBuffers(sprite: Sprite, renderer: IBatcher) {
fillBuffers (sprite: Sprite, renderer: IBatcher) {
if (sprite === null) {
return;
}
Expand Down Expand Up @@ -138,13 +138,13 @@ export const simple: IAssembler = {
// renderer.switchBufferAccessor().appendIndices(chunk);
},

updateVertexData(sprite: Sprite) {
updateVertexData (sprite: Sprite) {
const renderData: RenderData | null = sprite.renderData;
if (!renderData) {
return;
}

const uiTrans = sprite.node._uiProps.uiTransformComp!;
const uiTrans = sprite.node._getUITransformComp()!;
const dataList: IRenderData[] = renderData.data;
const cw = uiTrans.width;
const ch = uiTrans.height;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/assembler/sprite/sliced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const sliced: IAssembler = {
const renderData = sprite.renderData;
if (!renderData) return;
const dataList: IRenderData[] = renderData.data;
const uiTrans = sprite.node._uiProps.uiTransformComp!;
const uiTrans = sprite.node._getUITransformComp()!;
const width = uiTrans.width;
const height = uiTrans.height;
const appX = uiTrans.anchorX * width;
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/assembler/sprite/tiled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const tiled: IAssembler = {
return;
}

const uiTrans = sprite.node._uiProps.uiTransformComp!;
const uiTrans = sprite.node._getUITransformComp()!;
const contentWidth = Math.abs(uiTrans.width);
const contentHeight = Math.abs(uiTrans.height);

Expand Down Expand Up @@ -226,7 +226,7 @@ export const tiled: IAssembler = {
},

updateVerts (sprite: Sprite, sizableWidth: number, sizableHeight: number, row: number, col: number) {
const uiTrans = sprite.node._uiProps.uiTransformComp!;
const uiTrans = sprite.node._getUITransformComp()!;
const renderData = sprite.renderData;
if (!renderData) return;
const dataList: IRenderData[] = renderData.data;
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/components/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
* @zh
* 椭圆遮罩的曲线细分数。
*/
@visible(function (this: Mask) {

Check warning on line 202 in cocos/2d/components/mask.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return this.type === MaskType.GRAPHICS_ELLIPSE;
})
get segments (): number {
Expand Down Expand Up @@ -251,7 +251,7 @@
* 该数值 0 ~ 1 之间的浮点数,默认值为 0.1
* 当被设置为 1 时,会丢弃所有蒙版像素,所以不会显示任何内容
*/
@visible(function (this: Mask): boolean {

Check warning on line 254 in cocos/2d/components/mask.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return this.type === MaskType.SPRITE_STENCIL;
})
@range([0, 1, 0.1])
Expand Down Expand Up @@ -336,7 +336,7 @@
* @param worldPt @en point in World Space. @zh 世界空间中的点击点。
*/
public isHit (worldPt: Vec2): boolean {
const uiTrans = this.node._uiProps.uiTransformComp!;
const uiTrans = this.node._getUITransformComp()!;
const size = uiTrans.contentSize;
const w = size.width;
const h = size.height;
Expand Down Expand Up @@ -412,7 +412,7 @@
return;
}

const uiTrans = this.node._uiProps.uiTransformComp!;
const uiTrans = this.node._getUITransformComp()!;
const graphics = this._graphics;
// Share render data with graphics content
graphics.clear();
Expand Down
26 changes: 13 additions & 13 deletions cocos/2d/components/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function getSegmentByPool (type: string, content: string | SpriteFrame): ISegmen
seg.comp.underlineHeight = 2;
}
node.setPosition(0, 0, 0);
const trans = node._uiProps.uiTransformComp!;
const trans = node._getUITransformComp()!;
trans.setAnchorPoint(0.5, 0.5);

seg.node = node;
Expand Down Expand Up @@ -758,7 +758,7 @@ export class RichText extends Component {
}
label.styleIndex = styleIndex;
this._applyTextAttribute(label);
const size = label.node._uiProps.uiTransformComp!.contentSize;
const size = label.node._getUITransformComp()!.contentSize;
Vec2.set(out, size.x, size.y);
return out;
}
Expand Down Expand Up @@ -855,7 +855,7 @@ export class RichText extends Component {

labelSegment.styleIndex = styleIndex;
labelSegment.lineCount = this._lineCount;
labelSegment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 0);
labelSegment.node._getUITransformComp()!.setAnchorPoint(0, 0);
labelSegment.node.layer = this.node.layer;
this.node.insertChild(labelSegment.node, this._labelChildrenNum++);
this._applyTextAttribute(labelSegment);
Expand Down Expand Up @@ -901,7 +901,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
for (let k = 0; k < fragments.length; ++k) {
const splitString = fragments[k];
labelSegment = this._addLabelSegment(splitString, styleIndex);
const labelSize = labelSegment.node._uiProps.uiTransformComp!.contentSize;
const labelSize = labelSegment.node._getUITransformComp()!.contentSize;
this._lineOffsetX += labelSize.width;
if (fragments.length > 1 && k < fragments.length - 1) {
this._updateLineInfo();
Expand Down Expand Up @@ -984,13 +984,13 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
const sprite = segment.comp;
switch (style.imageAlign) {
case 'top':
segment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 1);
segment.node._getUITransformComp()!.setAnchorPoint(0, 1);
break;
case 'center':
segment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 0.5);
segment.node._getUITransformComp()!.setAnchorPoint(0, 0.5);
break;
default:
segment.node._uiProps.uiTransformComp!.setAnchorPoint(0, 0);
segment.node._getUITransformComp()!.setAnchorPoint(0, 0);
break;
}

Expand Down Expand Up @@ -1033,7 +1033,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
this._labelWidth = this._lineOffsetX;
}
}
segment.node._uiProps.uiTransformComp!.setContentSize(spriteWidth, spriteHeight);
segment.node._getUITransformComp()!.setContentSize(spriteWidth, spriteHeight);
segment.lineCount = this._lineCount;

segment.clickHandler = '';
Expand Down Expand Up @@ -1126,7 +1126,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
} else {
label = this._addLabelSegment(labelString, i);

this._lineOffsetX += label.node._uiProps.uiTransformComp!.width;
this._lineOffsetX += label.node._getUITransformComp()!.width;
if (this._lineOffsetX > this._labelWidth) {
this._labelWidth = this._lineOffsetX;
}
Expand All @@ -1147,7 +1147,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
this._labelHeight = (this._lineCount + BASELINE_RATIO) * this._lineHeight;

// trigger "size-changed" event
this.node._uiProps.uiTransformComp!.setContentSize(this._labelWidth, this._labelHeight);
this.node._getUITransformComp()!.setContentSize(this._labelWidth, this._labelHeight);

this._updateRichTextPosition();
this._layoutDirty = false;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
let nextTokenX = 0;
let nextLineIndex = 1;
const totalLineCount = this._lineCount;
const trans = this.node._uiProps.uiTransformComp!;
const trans = this.node._getUITransformComp()!;
const anchorX = trans.anchorX;
const anchorY = trans.anchorY;
for (let i = 0; i < this._segments.length; ++i) {
Expand Down Expand Up @@ -1209,7 +1209,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
);

if (lineCount === nextLineIndex) {
nextTokenX += segment.node._uiProps.uiTransformComp!.width;
nextTokenX += segment.node._getUITransformComp()!.width;
}

const sprite = segment.node.getComponent(Sprite);
Expand All @@ -1218,7 +1218,7 @@ this._measureText(styleIndex) as unknown as (s: string) => number,
// adjust img align (from <img align=top|center|bottom>)
const lineHeightSet = this._lineHeight;
const lineHeightReal = this._lineHeight * (1 + BASELINE_RATIO); // single line node height
switch (segment.node._uiProps.uiTransformComp!.anchorY) {
switch (segment.node._getUITransformComp()!.anchorY) {
case 1:
position.y += (lineHeightSet + ((lineHeightReal - lineHeightSet) / 2));
break;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/components/sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
* sprite.trim = true;
* ```
*/
@visible(function (this: Sprite) {

Check warning on line 372 in cocos/2d/components/sprite.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
return this._type === SpriteType.SIMPLE;
})
@displayOrder(8)
Expand Down Expand Up @@ -648,7 +648,7 @@
}

if (this._spriteFrame) {
const actualSize = this.node._uiProps.uiTransformComp!.contentSize;
const actualSize = this.node._getUITransformComp()!.contentSize;
let expectedW = actualSize.width;
let expectedH = actualSize.height;
if (this._sizeMode === SizeMode.RAW) {
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/components/ui-mesh-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class UIMeshRenderer extends Component {
}

public onLoad (): void {
if (!this.node._uiProps.uiTransformComp) {
if (!this.node._getUITransformComp()) {
this.node.addComponent('cc.UITransform');
}

Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/event/pointer-event-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class PointerEventDispatcher implements IEventDispatcher {
const pointerEventProcessor = pointerEventProcessorList[i];
const node = pointerEventProcessor.node;
if (node._uiProps) {
const trans = node._uiProps.uiTransformComp;
const trans = node._getUITransformComp();
pointerEventProcessor.cachedCameraPriority = trans!.cameraPriority;
}
}
Expand All @@ -227,9 +227,9 @@ class PointerEventDispatcher implements IEventDispatcher {
private _sortByPriority (p1: NodeEventProcessor, p2: NodeEventProcessor): number {
const node1: Node = p1.node;
const node2: Node = p2.node;
if (!p2 || !node2 || !node2.activeInHierarchy || !node2._uiProps.uiTransformComp) {
if (!p2 || !node2 || !node2.activeInHierarchy || !node2._getUITransformComp()) {
return -1;
} else if (!p1 || !node1 || !node1.activeInHierarchy || !node1._uiProps.uiTransformComp) {
} else if (!p1 || !node1 || !node1.activeInHierarchy || !node1._getUITransformComp()) {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/framework/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class Canvas extends RenderRoot2D {
// TODO: support paddings of locked widget
this.node.getPosition(this._pos);
const nodeSize = view.getDesignResolutionSize();
const trans = this.node._uiProps.uiTransformComp!;
const trans = this.node._getUITransformComp()!;

let scaleX = this.node.scale.x;
let anchorX = trans.anchorX;
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/framework/ui-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,12 @@ export class UITransform extends Component {
}
}

private static _sortChildrenSibling (node): void {
private static _sortChildrenSibling (node: Node): void {
const siblings = node.children;
if (siblings) {
siblings.sort((a: Node, b: Node): number => {
const aComp = a._uiProps.uiTransformComp;
const bComp = b._uiProps.uiTransformComp;
const aComp = a._getUITransformComp();
const bComp = b._getUITransformComp();
const ca = aComp ? aComp._priority : 0;
const cb = bComp ? bComp._priority : 0;
const diff = ca - cb;
Expand Down
2 changes: 1 addition & 1 deletion cocos/dragon-bones/ArmatureDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@

const animName = animsEnum[this._animationIndex];
if (animName !== undefined) {
this.playAnimation(animName, this.playTimes);

Check failure on line 339 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`
} else {
errorID(7402, this.name);
}
Expand Down Expand Up @@ -613,8 +613,8 @@
this._inited = false;
this.attachUtil = new AttachUtil();
this.initFactory();
setPropertyEnumType(this, '_animationIndex', this._enumAnimations);

Check failure on line 616 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `EnumType`
setPropertyEnumType(this, '_defaultArmatureIndex', this._enumArmatures);

Check failure on line 617 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `EnumType`
this._useVertexOpacity = true;
}
/**
Expand Down Expand Up @@ -1089,7 +1089,7 @@
if (this._armature) {
const armatureData = this._armature.armatureData;
const aabb = armatureData.aabb;
this.node._uiProps.uiTransformComp!.setContentSize(aabb.width, aabb.height);
this.node._getUITransformComp()!.setContentSize(aabb.width, aabb.height);
}
this.attachUtil.init(this);

Expand Down Expand Up @@ -1160,7 +1160,7 @@
} else {
Object.assign(this._cacheModeEnum, DefaultCacheMode);
}
setPropertyEnumType(this, '_defaultCacheMode', this._cacheModeEnum);

Check failure on line 1163 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `EnumType`
}

// update animation list for editor
Expand All @@ -1179,7 +1179,7 @@
Object.assign(this._enumAnimations, animEnum || DefaultAnimsEnum);
Enum.update(this._enumAnimations);
// change enum
setPropertyEnumType(this, '_animationIndex', this._enumAnimations);

Check failure on line 1182 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `EnumType`
}

// update armature list for editor
Expand All @@ -1198,7 +1198,7 @@
Object.assign(this._enumArmatures, armatureEnum || DefaultArmaturesEnum);
Enum.update(this._enumArmatures);
// change enum
setPropertyEnumType(this, '_defaultArmatureIndex', this._enumArmatures);

Check failure on line 1201 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `EnumType`
}
/**
* @engineInternal Since v3.7.2 this is an engine private function.
Expand All @@ -1217,7 +1217,7 @@
(bone as any).path = bone.name;
return bone.name;
}
const name = `${cacheBoneName((bone.parent as any)._boneIndex, bones, cache)}/${bone.name}`;

Check failure on line 1220 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `BoneIndex`
cache.set(bi, name);
(bone as any).path = name;
return name;
Expand Down Expand Up @@ -1420,7 +1420,7 @@
* @zh 调用回调函数的对象,可以为 null。
*/
addEventListener (eventType, listener, target): void {
this._eventTarget.on(eventType, listener, target);

Check failure on line 1423 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `EventType`
}

/**
Expand All @@ -1435,7 +1435,7 @@
* @zh 调用回调函数的对象,可以为 null。
*/
removeEventListener (eventType, listener, target): void {
this._eventTarget.off(eventType, listener, target);

Check failure on line 1438 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `EventType`
}

/**
Expand Down Expand Up @@ -1488,7 +1488,7 @@
if (socket.path && socket.target) {
const bone = this._cachedSockets.get(socket.path);
if (!bone) {
console.error(`Skeleton data does not contain path ${socket.path}`);

Check failure on line 1491 in cocos/dragon-bones/ArmatureDisplay.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected console statement
continue;
}
socket.boneIndex = bone as unknown as number;
Expand Down
4 changes: 2 additions & 2 deletions cocos/dragon-bones/CCArmatureDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class CCArmatureDisplay extends DisplayData implements IEventDispatcher {
convertToWorldSpace (point: Vec3): Vec3 | undefined {
const newPos = this.convertToRootSpace(point);
const ccNode = this.getRootNode();
return ccNode?._uiProps.uiTransformComp?.convertToWorldSpaceAR(newPos);
return ccNode?._getUITransformComp()?.convertToWorldSpaceAR(newPos);
}
/**
* @en Get the node of root ArmatureDisplay component in.
Expand Down Expand Up @@ -185,7 +185,7 @@ export class CCArmatureDisplay extends DisplayData implements IEventDispatcher {
this.shouldAdvanced = !!on;
}

hasDBEventListener (type): boolean {
hasDBEventListener (type: string): boolean {
return this._eventTarget.hasEventListener(type);
}

Expand Down
Loading
Loading