Skip to content

Commit

Permalink
change to static
Browse files Browse the repository at this point in the history
  • Loading branch information
LinYunMo committed Sep 26, 2023
1 parent 467b7bc commit cd377c6
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 36 deletions.
6 changes: 3 additions & 3 deletions cocos/2d/framework/ui-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { Director, director } from '../../game/director';
import { NodeEventType } from '../../scene-graph/node-event';
import { IMask } from '../../scene-graph/node-event-processor';
import { Mask } from '../components/mask';
import { uiSystem } from './ui-system';
import { Batcher2D } from '../renderer/batcher-2d';

const _vec2a = new Vec2();
const _vec2b = new Vec2();
Expand Down Expand Up @@ -238,7 +238,7 @@ export class UITransform extends Component {
* @deprecated since v3.0
*/
get visibility (): number {
const camera = uiSystem.batcher2D.getFirstRenderCamera(this.node);
const camera = Batcher2D.getFirstRenderCamera(this.node);
return camera ? camera.visibility : 0;
}

Expand All @@ -247,7 +247,7 @@ export class UITransform extends Component {
* @zh 查找被渲染相机的渲染优先级。
*/
get cameraPriority (): number {
const camera = uiSystem.batcher2D.getFirstRenderCamera(this.node);
const camera = Batcher2D.getFirstRenderCamera(this.node);
return camera ? camera.priority : 0;
}

Expand Down
34 changes: 17 additions & 17 deletions cocos/2d/renderer/batcher-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,28 @@ export class Batcher2D implements IBatcher {
}
private static instance: Batcher2D | null = null;

public static getFirstRenderCamera (node: Node): Camera | null {
if (node.scene && node.scene.renderScene) {
const cameras = node.scene.renderScene.cameras;
for (let i = 0; i < cameras.length; i++) {
const camera = cameras[i];
if (camera.visibility & node.layer) {
return camera;
}
}
}
return null;
}

get batches (): memop.CachedArray<DrawBatch2D> {
return this._batches;
}

public device: Device;
private _screens: Node[] = [];

private _drawBatchPool: Pool<DrawBatch2D>;
private _batches: CachedArray<DrawBatch2D>;
private _drawBatchPool: memop.Pool<DrawBatch2D>;
private _batches: memop.CachedArray<DrawBatch2D>;

private _indexStart = 0;

Expand Down Expand Up @@ -183,19 +196,6 @@ export class Batcher2D implements IBatcher {
this._screens.sort(this._screenSort);
}

public getFirstRenderCamera (node: Node): Camera | null {
if (node.scene && node.scene.renderScene) {
const cameras = node.scene.renderScene.cameras;
for (let i = 0; i < cameras.length; i++) {
const camera = cameras[i];
if (camera.visibility & node.layer) {
return camera;
}
}
}
return null;
}

public update (): void {
const screens = this._screens;
let offset = 0;
Expand Down Expand Up @@ -482,7 +482,7 @@ export class Batcher2D implements IBatcher {
dssHash = StencilManager.sharedManager!.getStencilHash(comp.stencilStage);
}

const stamp = cclegacy.director.getTotalFrames();
const stamp = cclegacy.director.getTotalFrames() as number;
if (model) {
model.updateTransform(stamp);
model.updateUBOs(stamp);
Expand Down Expand Up @@ -800,7 +800,7 @@ export class Batcher2D implements IBatcher {
}

const model = this._maskClearModel!;
const stamp = cclegacy.director.getTotalFrames();
const stamp = cclegacy.director.getTotalFrames() as number;
if (model) {
model.updateTransform(stamp);
model.updateUBOs(stamp);
Expand Down
6 changes: 2 additions & 4 deletions cocos/2d/renderer/i-batcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ import { Device, Attribute } from '../../gfx';
import { Camera } from '../../render-scene/scene/camera';
import { Model } from '../../render-scene/scene/model';
import { SpriteFrame } from '../assets/sprite-frame';
import { UIRenderer, RenderRoot2D } from '../framework';
import { StaticVBAccessor } from './static-vb-accessor';
import { UIRenderer } from '../framework';
import { DrawBatch2D } from './draw-batch';
import { BaseRenderData } from './render-data';
import { UIMeshRenderer } from '../components/ui-mesh-renderer';
import { Material } from '../../asset/assets';
import { Node } from '../../scene-graph';

export interface IBatcher {
readonly batches: CachedArray<DrawBatch2D>;
readonly batches: memop.CachedArray<DrawBatch2D>;
// registerCustomBuffer (attributes: MeshBuffer | Attribute[], callback: ((...args: number[]) => void) | null) : MeshBuffer;
// unRegisterCustomBuffer (buffer: MeshBuffer);

Expand All @@ -47,7 +46,6 @@ export interface IBatcher {
destroy();

addScreen (node: Node);
getFirstRenderCamera (node: Node): Camera | null;
removeScreen (node: Node);

sortScreens ();
Expand Down
2 changes: 0 additions & 2 deletions cocos/game/director.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import { Root } from '../root';
import { Node, Scene } from '../scene-graph';
import { ComponentScheduler } from '../scene-graph/component-scheduler';
import NodeActivator from '../scene-graph/node-activator';
import { scalableContainerManager } from '../core/memop/scalable-container';
import { uiRendererManager } from '../2d/framework/ui-renderer-manager';
import { assetManager } from '../asset/asset-manager';
import { deviceManager } from '../gfx';
import { releaseManager } from '../asset/asset-manager/release-manager';
Expand Down
4 changes: 2 additions & 2 deletions cocos/tiledmap/tiled-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { RenderEntity, RenderEntityType } from '../2d/renderer/render-entity';
import { RenderDrawInfo, RenderDrawInfoType } from '../2d/renderer/render-draw-info';
import { Texture2D } from '../asset/assets';
import { Camera } from '../render-scene/scene';
import { uiSystem } from '../2d/framework/ui-system';
import { Batcher2D } from '../2d/renderer/batcher-2d';

const _mat4_temp = new Mat4();
const _vec2_temp = new Vec2();
Expand Down Expand Up @@ -416,7 +416,7 @@ export class TiledLayer extends UIRenderer {
}

protected _reinstallCamera (): Camera | null {
const camera = uiSystem.batcher2D.getFirstRenderCamera(this.node);
const camera = Batcher2D.getFirstRenderCamera(this.node);
const cameraNode = camera?.node;
if (this._cameraNode !== cameraNode) {
this._uninstallCamera();
Expand Down
4 changes: 2 additions & 2 deletions cocos/ui/editbox/edit-box-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { tabIndexUtil } from './tabIndexUtil';
import { InputFlag, InputMode, KeyboardReturnType } from './types';
import { EditBoxImplBase } from './edit-box-impl-base';
import { BrowserType, OS } from '../../../pal/system-info/enum-type';
import { uiSystem } from '../../2d/framework/ui-system';
import { Batcher2D } from '../../2d/renderer/batcher-2d';

const ccdocument = ccwindow.document;

Expand Down Expand Up @@ -287,7 +287,7 @@ export class EditBoxImpl extends EditBoxImplBase {
return;
}

const camera = uiSystem.batcher2D.getFirstRenderCamera(node);
const camera = Batcher2D.getFirstRenderCamera(node);
if (!camera) return;

camera.node.getWorldRT(_matrix_temp);
Expand Down
4 changes: 2 additions & 2 deletions cocos/video/video-player-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { VideoPlayer } from './video-player';
import { EventType } from './video-player-enums';
import { Node } from '../scene-graph';
import type { Camera } from '../render-scene/scene';
import { uiSystem } from '../2d/framework/ui-system';
import { Batcher2D } from '../2d/renderer/batcher-2d';

export abstract class VideoPlayerImpl {
protected _componentEventList: Map<string, () => void> = new Map();
Expand Down Expand Up @@ -127,7 +127,7 @@ export abstract class VideoPlayerImpl {
public get state (): EventType { return this._state; }
public get isPlaying (): boolean { return this._playing; }
get UICamera (): Camera | null {
return uiSystem.batcher2D.getFirstRenderCamera(this._node!);
return Batcher2D.getFirstRenderCamera(this._node!);
}

// video player event
Expand Down
4 changes: 2 additions & 2 deletions cocos/web-view/web-view-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { EventType } from './web-view-enums';
import { UITransform } from '../2d/framework';
import { Node } from '../scene-graph';
import type { Camera } from '../render-scene/scene';
import { uiSystem } from '../2d/framework/ui-system';
import { Batcher2D } from '../2d/renderer/batcher-2d';

export abstract class WebViewImpl {
protected _componentEventList: Map<EventType, (...args: any[any]) => void> = new Map();
Expand Down Expand Up @@ -92,7 +92,7 @@ export abstract class WebViewImpl {
get webview (): HTMLIFrameElement | null { return this._webview; }
get state (): EventType { return this._state; }
get UICamera (): Camera | null {
return uiSystem.batcher2D.getFirstRenderCamera(this._node!);
return Batcher2D.getFirstRenderCamera(this._node!);
}

protected dispatchEvent (key: EventType, ...args: any[any]): void {
Expand Down
2 changes: 1 addition & 1 deletion native/cocos/2d/renderer/Batcher2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ scene::Camera* Batcher2d::getFirstRenderCamera(const Node* node) {
if (node->getScene()!= nullptr && node->getScene()->getRenderScene()!= nullptr) {
const auto cameras = node->getScene()->getRenderScene()->getCameras();
for (size_t i = 0; i < cameras.size(); i++) {
const auto camera = cameras[i];
const auto camera = cameras[i];
if (camera->getVisibility() & node->getLayer()) {
return camera;
}
Expand Down
2 changes: 1 addition & 1 deletion native/cocos/2d/renderer/Batcher2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static Batcher2d *getInstance();
void reset();
void destroy();

scene::Camera* getFirstRenderCamera(const Node* node);
static scene::Camera* getFirstRenderCamera(const Node* node);

void addScreen (Node* node);
void removeScreen (Node* node);
Expand Down

0 comments on commit cd377c6

Please sign in to comment.