From 2a97bc3a57220fea9ecf148333910e41162fe74b Mon Sep 17 00:00:00 2001 From: SmallMain Date: Wed, 4 Sep 2024 17:10:08 +0800 Subject: [PATCH] =?UTF-8?q?[engine]=20=E4=B8=BA=E5=8A=A8=E6=80=81=E5=9B=BE?= =?UTF-8?q?=E9=9B=86=E7=AE=A1=E7=90=86=E5=99=A8=E5=A2=9E=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=AE=9E=E7=94=A8=E6=8E=A5=E5=8F=A3=EF=BC=88getUnused?= =?UTF-8?q?Atlas,=20deleteAtlas,=20destroyUnusedAtlases=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../renderer/utils/dynamic-atlas/manager.js | 30 +++++++++++++++++++ .../utils/dynamic-atlas/reusable-atlas.ts | 2 ++ engine/cocos2d/core/sp/multi-batcher.ts | 3 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/engine/cocos2d/core/renderer/utils/dynamic-atlas/manager.js b/engine/cocos2d/core/renderer/utils/dynamic-atlas/manager.js index 801337a6..5e0a578b 100644 --- a/engine/cocos2d/core/renderer/utils/dynamic-atlas/manager.js +++ b/engine/cocos2d/core/renderer/utils/dynamic-atlas/manager.js @@ -366,6 +366,36 @@ let dynamicAtlasManager = { _atlases[i].update(); } }, + + getUnusedAtlas() { + if (!this.enabled) return null; + + for (let i = 0; i <= _atlasIndex; i++) { + if (_atlases[i].isEmpty()) { + return _atlases[i]; + } + } + + return null; + }, + + deleteAtlas(index) { + if (!this.enabled) return; + + _atlases[index].destroy(); + _atlases.splice(index, 1); + _atlasIndex--; + }, + + destroyUnusedAtlases() { + if (!this.enabled) return; + + for (let i = 0; i <= _atlasIndex; i++) { + if (_atlases[i].isEmpty()) { + _atlases[i].destroy(); + } + } + }, }; /** diff --git a/engine/cocos2d/core/renderer/utils/dynamic-atlas/reusable-atlas.ts b/engine/cocos2d/core/renderer/utils/dynamic-atlas/reusable-atlas.ts index 76900799..a4e77902 100644 --- a/engine/cocos2d/core/renderer/utils/dynamic-atlas/reusable-atlas.ts +++ b/engine/cocos2d/core/renderer/utils/dynamic-atlas/reusable-atlas.ts @@ -623,6 +623,8 @@ export class Atlas { /** * 销毁 + * + * 请勿直接调用 */ destroy() { this.reset(); diff --git a/engine/cocos2d/core/sp/multi-batcher.ts b/engine/cocos2d/core/sp/multi-batcher.ts index dd18ab2f..ef85280c 100644 --- a/engine/cocos2d/core/sp/multi-batcher.ts +++ b/engine/cocos2d/core/sp/multi-batcher.ts @@ -61,10 +61,11 @@ export class MultiBatcher { /** - * 重置多纹理材质数组,再次使用请先初始化 + * 重置 */ reset() { this.handlers.length = 0; + this.nextHandler = null!; } }