动态合批

This commit is contained in:
yhh
2020-09-15 09:39:26 +08:00
parent 4ce810bdcd
commit 8e97dcda9c
8 changed files with 112 additions and 14 deletions

View File

@@ -1637,6 +1637,7 @@ var es;
_this._sceneComponents = [];
_this._renderers = [];
_this._postProcessors = [];
_this.dynamicBatch = false;
_this.entities = new es.EntityList(_this);
_this.renderableComponents = new es.RenderableComponentList();
_this.content = new es.ContentManager();
@@ -1736,6 +1737,30 @@ var es;
this._renderers[i].render(this);
}
};
Scene.prototype.dynamicInBatch = function () {
this.removeChildren();
var batching = false;
var displayContainer;
for (var _i = 0, _a = this.renderableComponents.buffer; _i < _a.length; _i++) {
var component = _a[_i];
if (component instanceof es.SpriteAnimator) {
this.addChild(component.displayObject);
this.addChild(component.debugDisplayObject);
batching = false;
displayContainer = null;
}
else if (component instanceof es.RenderableComponent) {
if (!batching) {
batching = true;
displayContainer = new egret.DisplayObjectContainer();
displayContainer.cacheAsBitmap = true;
this.addChild(displayContainer);
}
displayContainer.addChild(component.displayObject);
displayContainer.addChild(component.debugDisplayObject);
}
}
};
Scene.prototype.postRender = function () {
if (this.enablePostProcessing) {
for (var i = 0; i < this._postProcessors.length; i++) {
@@ -4514,13 +4539,16 @@ var es;
for (var i = 0; i < this._components.length; i++) {
var component = this._components[i];
if (component instanceof es.RenderableComponent) {
this._entity.scene.addChild(component.displayObject);
if (!this._entity.scene.dynamicBatch)
this._entity.scene.addChild(component.displayObject);
this._entity.scene.renderableComponents.add(component);
}
this._entity.scene.addChild(component.debugDisplayObject);
if (!this._entity.scene.dynamicBatch)
this._entity.scene.addChild(component.debugDisplayObject);
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
}
this._entity.scene.dynamicInBatch();
};
ComponentList.prototype.updateLists = function () {
if (this._componentsToRemove.length > 0) {
@@ -4534,15 +4562,18 @@ var es;
for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
var component = this._componentsToAdd[i];
if (component instanceof es.RenderableComponent) {
this._entity.scene.addChild(component.displayObject);
if (!this._entity.scene.dynamicBatch)
this._entity.scene.addChild(component.displayObject);
this._entity.scene.renderableComponents.add(component);
}
this._entity.scene.addChild(component.debugDisplayObject);
if (!this._entity.scene.dynamicBatch)
this._entity.scene.addChild(component.debugDisplayObject);
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
this._components.push(component);
this._tempBufferList.push(component);
}
this._entity.scene.dynamicInBatch();
this._componentsToAdd.length = 0;
this._isComponentListUnsorted = true;
for (var i = 0; i < this._tempBufferList.length; i++) {