动态合批
This commit is contained in:
Vendored
+2
@@ -364,6 +364,7 @@ declare module es {
|
|||||||
_renderers: Renderer[];
|
_renderers: Renderer[];
|
||||||
readonly _postProcessors: PostProcessor[];
|
readonly _postProcessors: PostProcessor[];
|
||||||
_didSceneBegin: any;
|
_didSceneBegin: any;
|
||||||
|
dynamicBatch: boolean;
|
||||||
constructor();
|
constructor();
|
||||||
static createWithDefaultRenderer(): Scene;
|
static createWithDefaultRenderer(): Scene;
|
||||||
initialize(): void;
|
initialize(): void;
|
||||||
@@ -376,6 +377,7 @@ declare module es {
|
|||||||
updateResolutionScaler(): void;
|
updateResolutionScaler(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
|
dynamicInBatch(): void;
|
||||||
postRender(): void;
|
postRender(): void;
|
||||||
requestScreenshot(callback: Function): void;
|
requestScreenshot(callback: Function): void;
|
||||||
addSceneComponent<T extends SceneComponent>(component: T): T;
|
addSceneComponent<T extends SceneComponent>(component: T): T;
|
||||||
|
|||||||
@@ -1637,6 +1637,7 @@ var es;
|
|||||||
_this._sceneComponents = [];
|
_this._sceneComponents = [];
|
||||||
_this._renderers = [];
|
_this._renderers = [];
|
||||||
_this._postProcessors = [];
|
_this._postProcessors = [];
|
||||||
|
_this.dynamicBatch = false;
|
||||||
_this.entities = new es.EntityList(_this);
|
_this.entities = new es.EntityList(_this);
|
||||||
_this.renderableComponents = new es.RenderableComponentList();
|
_this.renderableComponents = new es.RenderableComponentList();
|
||||||
_this.content = new es.ContentManager();
|
_this.content = new es.ContentManager();
|
||||||
@@ -1736,6 +1737,30 @@ var es;
|
|||||||
this._renderers[i].render(this);
|
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 () {
|
Scene.prototype.postRender = function () {
|
||||||
if (this.enablePostProcessing) {
|
if (this.enablePostProcessing) {
|
||||||
for (var i = 0; i < this._postProcessors.length; i++) {
|
for (var i = 0; i < this._postProcessors.length; i++) {
|
||||||
@@ -4514,13 +4539,16 @@ var es;
|
|||||||
for (var i = 0; i < this._components.length; i++) {
|
for (var i = 0; i < this._components.length; i++) {
|
||||||
var component = this._components[i];
|
var component = this._components[i];
|
||||||
if (component instanceof es.RenderableComponent) {
|
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.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.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.dynamicInBatch();
|
||||||
};
|
};
|
||||||
ComponentList.prototype.updateLists = function () {
|
ComponentList.prototype.updateLists = function () {
|
||||||
if (this._componentsToRemove.length > 0) {
|
if (this._componentsToRemove.length > 0) {
|
||||||
@@ -4534,15 +4562,18 @@ var es;
|
|||||||
for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
||||||
var component = this._componentsToAdd[i];
|
var component = this._componentsToAdd[i];
|
||||||
if (component instanceof es.RenderableComponent) {
|
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.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.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
this._components.push(component);
|
this._components.push(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.dynamicInBatch();
|
||||||
this._componentsToAdd.length = 0;
|
this._componentsToAdd.length = 0;
|
||||||
this._isComponentListUnsorted = true;
|
this._isComponentListUnsorted = true;
|
||||||
for (var i = 0; i < this._tempBufferList.length; i++) {
|
for (var i = 0; i < this._tempBufferList.length; i++) {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+2
@@ -364,6 +364,7 @@ declare module es {
|
|||||||
_renderers: Renderer[];
|
_renderers: Renderer[];
|
||||||
readonly _postProcessors: PostProcessor[];
|
readonly _postProcessors: PostProcessor[];
|
||||||
_didSceneBegin: any;
|
_didSceneBegin: any;
|
||||||
|
dynamicBatch: boolean;
|
||||||
constructor();
|
constructor();
|
||||||
static createWithDefaultRenderer(): Scene;
|
static createWithDefaultRenderer(): Scene;
|
||||||
initialize(): void;
|
initialize(): void;
|
||||||
@@ -376,6 +377,7 @@ declare module es {
|
|||||||
updateResolutionScaler(): void;
|
updateResolutionScaler(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
|
dynamicInBatch(): void;
|
||||||
postRender(): void;
|
postRender(): void;
|
||||||
requestScreenshot(callback: Function): void;
|
requestScreenshot(callback: Function): void;
|
||||||
addSceneComponent<T extends SceneComponent>(component: T): T;
|
addSceneComponent<T extends SceneComponent>(component: T): T;
|
||||||
|
|||||||
+35
-4
@@ -1637,6 +1637,7 @@ var es;
|
|||||||
_this._sceneComponents = [];
|
_this._sceneComponents = [];
|
||||||
_this._renderers = [];
|
_this._renderers = [];
|
||||||
_this._postProcessors = [];
|
_this._postProcessors = [];
|
||||||
|
_this.dynamicBatch = false;
|
||||||
_this.entities = new es.EntityList(_this);
|
_this.entities = new es.EntityList(_this);
|
||||||
_this.renderableComponents = new es.RenderableComponentList();
|
_this.renderableComponents = new es.RenderableComponentList();
|
||||||
_this.content = new es.ContentManager();
|
_this.content = new es.ContentManager();
|
||||||
@@ -1736,6 +1737,30 @@ var es;
|
|||||||
this._renderers[i].render(this);
|
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 () {
|
Scene.prototype.postRender = function () {
|
||||||
if (this.enablePostProcessing) {
|
if (this.enablePostProcessing) {
|
||||||
for (var i = 0; i < this._postProcessors.length; i++) {
|
for (var i = 0; i < this._postProcessors.length; i++) {
|
||||||
@@ -4514,13 +4539,16 @@ var es;
|
|||||||
for (var i = 0; i < this._components.length; i++) {
|
for (var i = 0; i < this._components.length; i++) {
|
||||||
var component = this._components[i];
|
var component = this._components[i];
|
||||||
if (component instanceof es.RenderableComponent) {
|
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.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.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.dynamicInBatch();
|
||||||
};
|
};
|
||||||
ComponentList.prototype.updateLists = function () {
|
ComponentList.prototype.updateLists = function () {
|
||||||
if (this._componentsToRemove.length > 0) {
|
if (this._componentsToRemove.length > 0) {
|
||||||
@@ -4534,15 +4562,18 @@ var es;
|
|||||||
for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
for (var i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
||||||
var component = this._componentsToAdd[i];
|
var component = this._componentsToAdd[i];
|
||||||
if (component instanceof es.RenderableComponent) {
|
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.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.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
this._components.push(component);
|
this._components.push(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.dynamicInBatch();
|
||||||
this._componentsToAdd.length = 0;
|
this._componentsToAdd.length = 0;
|
||||||
this._isComponentListUnsorted = true;
|
this._isComponentListUnsorted = true;
|
||||||
for (var i = 0; i < this._tempBufferList.length; i++) {
|
for (var i = 0; i < this._tempBufferList.length; i++) {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -33,6 +33,7 @@ module es {
|
|||||||
public _renderers: Renderer[] = [];
|
public _renderers: Renderer[] = [];
|
||||||
public readonly _postProcessors: PostProcessor[] = [];
|
public readonly _postProcessors: PostProcessor[] = [];
|
||||||
public _didSceneBegin;
|
public _didSceneBegin;
|
||||||
|
public dynamicBatch: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -189,6 +190,35 @@ module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态合批
|
||||||
|
*/
|
||||||
|
public dynamicInBatch(){
|
||||||
|
this.removeChildren();
|
||||||
|
let batching = false;
|
||||||
|
let displayContainer: egret.DisplayObjectContainer;
|
||||||
|
for (let component of this.renderableComponents.buffer){
|
||||||
|
if (component instanceof SpriteAnimator){
|
||||||
|
// 动态
|
||||||
|
this.addChild(component.displayObject);
|
||||||
|
this.addChild(component.debugDisplayObject);
|
||||||
|
batching = false;
|
||||||
|
displayContainer = null;
|
||||||
|
} else if (component instanceof RenderableComponent) {
|
||||||
|
// 静态
|
||||||
|
if (!batching){
|
||||||
|
batching = true;
|
||||||
|
displayContainer = new egret.DisplayObjectContainer();
|
||||||
|
displayContainer.cacheAsBitmap = true;
|
||||||
|
this.addChild(displayContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
displayContainer.addChild(component.displayObject);
|
||||||
|
displayContainer.addChild(component.debugDisplayObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 现在的任何后处理器都要完成它的处理
|
* 现在的任何后处理器都要完成它的处理
|
||||||
* 只有在SceneTransition请求渲染时,它才会有一个值。
|
* 只有在SceneTransition请求渲染时,它才会有一个值。
|
||||||
|
|||||||
@@ -95,14 +95,15 @@ module es {
|
|||||||
let component = this._components[i];
|
let component = this._components[i];
|
||||||
|
|
||||||
if (component instanceof RenderableComponent) {
|
if (component instanceof 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.renderableComponents.add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._entity.scene.addChild(component.debugDisplayObject);
|
if (!this._entity.scene.dynamicBatch) this._entity.scene.addChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.dynamicInBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,17 +123,18 @@ module es {
|
|||||||
for (let i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
for (let i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
||||||
let component = this._componentsToAdd[i];
|
let component = this._componentsToAdd[i];
|
||||||
if (component instanceof RenderableComponent) {
|
if (component instanceof 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.renderableComponents.add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._entity.scene.addChild(component.debugDisplayObject);
|
if (!this._entity.scene.dynamicBatch) this._entity.scene.addChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
|
|
||||||
this._components.push(component);
|
this._components.push(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.dynamicInBatch();
|
||||||
|
|
||||||
// 在调用onAddedToEntity之前清除,以防添加更多组件
|
// 在调用onAddedToEntity之前清除,以防添加更多组件
|
||||||
this._componentsToAdd.length = 0;
|
this._componentsToAdd.length = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user