Skip to content

Commit

Permalink
useless code remove
Browse files Browse the repository at this point in the history
  • Loading branch information
LinYunMo committed Aug 7, 2023
1 parent 96f6be9 commit 65a644c
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 93 deletions.
2 changes: 0 additions & 2 deletions cocos/2d/assembler/label/bmfontUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export const bmfontUtils = {
style.color.set(comp.color); // render only
},

// 进行统一调用
updateLayoutData (comp: Label): void {
if (comp.layoutDirty) {
const trans = comp.node._uiProps.uiTransformComp!;
Expand Down Expand Up @@ -132,7 +131,6 @@ export const bmfontUtils = {
}

if (comp.renderData.vertDirty) {
// this.updateLayoutData(comp);// 需要注意的是要防止在两个函数中间被修改 // 但是这里的修改应该是不会影响到排版的
const renderData = comp.renderData;
const processing = TextProcessing.instance;
const style = comp.textStyle;
Expand Down
35 changes: 16 additions & 19 deletions cocos/2d/assembler/label/ttfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,36 @@ export const ttfUtils = {
trans: UITransform,
): void {
// font info // both
style.isSystemFontUsed = comp.useSystemFont; // 都会影响
style.fontSize = comp.fontSize; // 都会影响
style.isSystemFontUsed = comp.useSystemFont; // both
style.fontSize = comp.fontSize; // both

// layout info
layout.lineHeight = comp.lineHeight; // both // 都影响
layout.overFlow = comp.overflow; // layout only // but change render // 在 bmfont 里会和渲染相关,ttf 不会
layout.lineHeight = comp.lineHeight; // both
layout.overFlow = comp.overflow; // layout only
if (comp.overflow === Overflow.NONE) {
layout.wrapping = false;
} else if (comp.overflow === Overflow.RESIZE_HEIGHT) {
layout.wrapping = true;
} else {
layout.wrapping = comp.enableWrapText; // layout only // but change render // 在 bmfont 里会和渲染相关,ttf 不会
layout.wrapping = comp.enableWrapText; // layout only
}

// effect info // both
style.isBold = comp.isBold; // 可能会影响到 context 的测量,所以和排版相关 // 和渲染相关
style.isItalic = comp.isItalic; // 可能会影响到 context 的测量,所以和排版相关 // 和渲染相关
style.isBold = comp.isBold;
style.isItalic = comp.isItalic;

// outline// both
// outline // both
let outlineComp = LabelOutline && comp.getComponent(LabelOutline);
outlineComp = (outlineComp && outlineComp.enabled && outlineComp.width > 0) ? outlineComp : null;
if (outlineComp) {
style.isOutlined = true;
style.outlineColor.set(outlineComp.color);
style.outlineWidth = outlineComp.width;
} else {
style.isOutlined = false; // 由于影响到了canvas 的宽度,所以和排版相关 // 和渲染相关
style.isOutlined = false;
}

// shadow// both
// shadow // both
let shadowComp = LabelShadow && comp.getComponent(LabelShadow);
shadowComp = (shadowComp && shadowComp.enabled) ? shadowComp : null;
if (shadowComp) {
Expand All @@ -83,15 +83,15 @@ export const ttfUtils = {
style.shadowOffsetX = shadowComp.offset.x;
style.shadowOffsetY = shadowComp.offset.y;
} else {
style.hasShadow = false; // 由于影响到了canvas 的宽度,所以和排版相关 //和渲染相关
style.hasShadow = false;
}

layout.horizontalAlign = comp.horizontalAlign; // render Only // 由于影响起始位置的计算,所以和排版相关 // 和渲染相关
layout.verticalAlign = comp.verticalAlign; // render Only // 由于影响起始位置的计算,所以和排版相关 // 和渲染相关
layout.horizontalAlign = comp.horizontalAlign; // both
layout.verticalAlign = comp.verticalAlign; // both

// node info // both // 怎么触发 dirty
outputLayoutData.nodeContentSize.width = outputLayoutData.canvasSize.width = trans.width; // 这儿的更新一定都会影响的
outputLayoutData.nodeContentSize.height = outputLayoutData.canvasSize.height = trans.height; // 这儿的更新一定都会影响的
// node info // both
outputLayoutData.nodeContentSize.width = outputLayoutData.canvasSize.width = trans.width;
outputLayoutData.nodeContentSize.height = outputLayoutData.canvasSize.height = trans.height;
},

// render Only
Expand Down Expand Up @@ -123,7 +123,6 @@ export const ttfUtils = {
}
},

// 进行统一调用
updateLayoutData (comp: Label): void {
if (comp.layoutDirty) {
const trans = comp.node._uiProps.uiTransformComp!;
Expand All @@ -150,8 +149,6 @@ export const ttfUtils = {
if (!comp.renderData) { return; }

if (comp.renderData.vertDirty) {
// this.updateLayoutData(comp); // 需要注意的是要防止在两个函数中间被修改 // 但是这里的修改应该是不会影响到排版的

const processing = TextProcessing.instance;
const style = comp.textStyle;
const layout = comp.textLayout;
Expand Down
29 changes: 13 additions & 16 deletions cocos/2d/components/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class Label extends UIRenderer {
}

this._overflow = value;
this._markLayoutDirty(); // 其实只影响 bm
this._markLayoutDirty();
this.markForUpdateRenderData();
}

Expand All @@ -405,7 +405,7 @@ export class Label extends UIRenderer {
}

this._enableWrapText = value;
this._markLayoutDirty(); // 其实只影响 bm
this._markLayoutDirty();
this.markForUpdateRenderData();
}

Expand Down Expand Up @@ -504,7 +504,7 @@ export class Label extends UIRenderer {

this._fontAtlas = null;
this._markLayoutDirty();
this.updateRenderData(true);//为了 flushAssembler
this.updateRenderData(true);
}

/**
Expand Down Expand Up @@ -534,7 +534,7 @@ export class Label extends UIRenderer {

this._cacheMode = value;
this._markLayoutDirty();
this.updateRenderData(true); //为了 flushAssembler
this.updateRenderData(true);
}

/**
Expand Down Expand Up @@ -706,7 +706,7 @@ export class Label extends UIRenderer {
@serializable
protected _fontFamily = 'Arial';
@serializable
protected _lineHeight = 40;//实际上影响排版的位置,而不影响排版
protected _lineHeight = 40;
@serializable
protected _overflow: Overflow = Overflow.NONE;
@serializable
Expand All @@ -718,13 +718,13 @@ export class Label extends UIRenderer {
@serializable
protected _spacingX = 0;
@serializable
protected _isItalic = false;// 只会影响宽度
protected _isItalic = false;
@serializable
protected _isBold = false;// 只会影响宽度
protected _isBold = false;
@serializable
protected _isUnderline = false;// 不影响,但是要同步
protected _isUnderline = false;
@serializable
protected _underlineHeight = 2;// 不影响,但是要同步
protected _underlineHeight = 2;
@serializable
protected _cacheMode = CacheMode.NONE;

Expand All @@ -745,7 +745,7 @@ export class Label extends UIRenderer {
protected _textRenderData: TextOutputRenderData | null = null;
protected _textLayoutData: TextOutputLayoutData | null = null;

protected _layoutDirty = false; // 是否重新计算文本布局
protected _layoutDirty = false;

/**
* @engineInternal
Expand Down Expand Up @@ -827,7 +827,7 @@ export class Label extends UIRenderer {
* @zh 更新渲染相关数据。
* @param force @en Whether to force an immediate update. @zh 是否立马强制更新渲染数据。
*/
public updateRenderData (force = false): void { // 此接口应当有限使用,仅有几种情况才使用,且其他情况也该直接 markDirty 即可
public updateRenderData (force = false): void {
if (force) {
this._flushAssembler();
// Hack: Fixed the bug that richText wants to get the label length by _measureText,
Expand Down Expand Up @@ -982,12 +982,9 @@ export class Label extends UIRenderer {
* @engineInternal
*/
public _markLayoutDirty (): void {
if (this._layoutDirty) return;//同底层的markLayoutDirty中做的防护一样,防止重复加入队列
if (this._layoutDirty) return;
this._layoutDirty = true;
if (this.enabled) { //不一定需要
// 加入队列,统一进行更新
// 在排版时进行 renderDirty 的触发
// 还是在上层直接进行触发?
if (this.enabled) {
uiLayoutManager.markLayoutDirty(this);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/components/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ export class RichText extends Component {
label.useSystemFont = this._isSystemFontUsed;
label.lineHeight = this._lineHeight;

label.updateRenderData(true);// 此处的强制更新是为了这个步骤之后马上要使用的宽度
label.updateRenderData(true);
}

protected _applyLayer (): void {
Expand Down
10 changes: 2 additions & 8 deletions cocos/2d/framework/ui-layout-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,19 @@
THE SOFTWARE.
*/

import { DEBUG } from 'internal:constants';
import { assert } from '../../core';
import { UIRenderer } from './ui-renderer';

export class UILayoutManager { // 可能能够合并
private _dirtyUIs: (UIRenderer)[] = []; // 可能只要 uiTrans 就行
export class UILayoutManager {
private _dirtyUIs: (UIRenderer)[] = [];

public markLayoutDirty (uiRenderer: UIRenderer): void {
// 可由上层管理flag,否则就需要在 UIRenderer 中增加版本号
this._dirtyUIs.push(uiRenderer);
}

public updateAllDirtyLayout (): void {
const length = this._dirtyUIs.length;
const dirtyRenderers = this._dirtyUIs;
for (let i = 0; i < length; i++) {
if (DEBUG) {
assert(dirtyRenderers[i]._internalLayoutId !== -1);
}
dirtyRenderers[i]._updateLayout();
}
this._dirtyUIs.length = 0;
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/framework/ui-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class UIRenderer extends Renderer {
* @zh 后置渲染数据组装器
* @internal
*/
public static PostAssembler: IAssemblerManager | null = null; // Todo: remove it
public static PostAssembler: IAssemblerManager | null = null; // Todo: Remove it

constructor () {
super();
Expand Down Expand Up @@ -257,7 +257,7 @@ export class UIRenderer extends Renderer {
protected _stencilStage: Stage = Stage.DISABLED;

protected _assembler: IAssembler | null = null;
protected _postAssembler: IAssembler | null = null; // Todo: remove it
protected _postAssembler: IAssembler | null = null; // Todo: Remove it

// RenderEntity
//protected renderData: RenderData | null = null;
Expand Down Expand Up @@ -432,7 +432,7 @@ export class UIRenderer extends Renderer {
/**
* @engineInternal
*/
public _updateLayout (): void { } // 重载思路,或者也可以用回调思路,事件交由manger处理
public _updateLayout (): void { }

protected _render (render: IBatcher): void { }

Expand Down
11 changes: 3 additions & 8 deletions cocos/2d/framework/ui-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ export class UISystem extends System {
/**
* @en The draw batch manager for 2D UI, for engine internal usage, user do not need to use this.
* @zh 2D UI 渲染合批管理器,引擎内部使用,用户无需使用此接口
* @engineInternal
*/
public get batcher2D (): Batcher2D {
return this._batcher as Batcher2D;
}

public init (): void {
if (!this._batcher) {
// TODO
// 能否直接创建原生对象?然后管理 // 未能成功创建原生对象 // 存在循环引用
this._batcher = new Batcher2D(director.root!);
}
director.on(Director.EVENT_AFTER_SCENE_LAUNCH, this.afterSceneLaunch, this);
Expand Down Expand Up @@ -84,9 +83,8 @@ export class UISystem extends System {
}

public tick (): void {
uiLayoutManager.updateAllDirtyLayout(); // 更新所有 dirty 的 layout
// 可以分开更新了
uiRendererManager.updateAllDirtyRenderers(); // 更新所有 dirty 的 renderer
uiLayoutManager.updateAllDirtyLayout();
uiRendererManager.updateAllDirtyRenderers();
}

public render (): void {
Expand All @@ -102,9 +100,7 @@ export class UISystem extends System {
}
}

// 触发阶段
private beforeDraw (): void {
// 只支持了 once
for (let i = 0, length = this._extraPartBeforeUpdate.length; i < length; i++) {
const info = this._extraPartBeforeUpdate[i];
const callback = info.callback;
Expand All @@ -114,7 +110,6 @@ export class UISystem extends System {
this._extraPartBeforeUpdate.length = 0;
}

// only one time
public addCallbackToBeforeUpdate (callback: AnyFunction, target: any): void {
this._extraPartBeforeUpdate.push(new FunctionCallbackInfo(callback, target));
}
Expand Down
22 changes: 5 additions & 17 deletions cocos/2d/renderer/batcher-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ export class Batcher2D implements IBatcher {
}
this._batches.destroy();

// 应该在 manager destroy 的时候释放
const bufferAccessors = BufferAccessorManager.instance._bufferAccessors;
for (const accessor of bufferAccessors.values()) {
accessor.destroy();
}
bufferAccessors.clear();
BufferAccessorManager.instance.destroy();

if (this._drawBatchPool) {
this._drawBatchPool.destroy();
Expand Down Expand Up @@ -242,10 +237,7 @@ export class Batcher2D implements IBatcher {
this._meshDataArray[i].uploadBuffers();
}

for (const accessor of BufferAccessorManager.instance._bufferAccessors.values()) {
accessor.uploadBuffers();
accessor.reset();
}
BufferAccessorManager.instance.upload();

this._descriptorSetCache.update();
}
Expand All @@ -262,17 +254,13 @@ export class Batcher2D implements IBatcher {
this._drawBatchPool.free(batch);
}
// Reset buffer accessors
for (const accessor of BufferAccessorManager.instance._bufferAccessors.values()) {
accessor.reset();
}
BufferAccessorManager.instance.reset();
const length = this._meshDataArray.length;
for (let i = 0; i < length; i++) {
this._meshDataArray[i].freeIAPool();
}
this._meshDataArray.length = 0;
BufferAccessorManager.instance._staticVBBuffer = null;

BufferAccessorManager.instance._currBID = -1;
this._indexStart = 0;
this._currHash = 0;
this._currLayer = 0;
Expand Down Expand Up @@ -524,15 +512,15 @@ export class Batcher2D implements IBatcher {

public setupStaticBatch (staticComp: UIStaticBatch, bufferAccessor: StaticVBAccessor): void {
this.finishMergeBatches();
BufferAccessorManager.instance._staticVBBuffer = bufferAccessor;
BufferAccessorManager.instance.setVBBufferForce(bufferAccessor);
this.currStaticRoot = staticComp;
}

public endStaticBatch (): void {
this.finishMergeBatches();
this.currStaticRoot = null;
// Clear linear buffer to switch to the correct internal accessor
BufferAccessorManager.instance._staticVBBuffer = null;
BufferAccessorManager.instance.setVBBufferForce(null);
BufferAccessorManager.instance.switchBufferAccessor();
}

Expand Down
Loading

0 comments on commit 65a644c

Please sign in to comment.