新增scene.optimizeCost参数 用于优化cost过高情况
This commit is contained in:
Vendored
+2
@@ -365,6 +365,7 @@ declare module es {
|
|||||||
readonly _postProcessors: PostProcessor[];
|
readonly _postProcessors: PostProcessor[];
|
||||||
_didSceneBegin: any;
|
_didSceneBegin: any;
|
||||||
dynamicBatch: boolean;
|
dynamicBatch: boolean;
|
||||||
|
optimizeCost: boolean;
|
||||||
constructor();
|
constructor();
|
||||||
static createWithDefaultRenderer(): Scene;
|
static createWithDefaultRenderer(): Scene;
|
||||||
initialize(): void;
|
initialize(): void;
|
||||||
@@ -378,6 +379,7 @@ declare module es {
|
|||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
dynamicInBatch(): void;
|
dynamicInBatch(): void;
|
||||||
|
private optimizeCombine;
|
||||||
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;
|
||||||
|
|||||||
@@ -1629,6 +1629,7 @@ var es;
|
|||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
|
var Bitmap = egret.Bitmap;
|
||||||
var Scene = (function (_super) {
|
var Scene = (function (_super) {
|
||||||
__extends(Scene, _super);
|
__extends(Scene, _super);
|
||||||
function Scene() {
|
function Scene() {
|
||||||
@@ -1638,6 +1639,7 @@ var es;
|
|||||||
_this._renderers = [];
|
_this._renderers = [];
|
||||||
_this._postProcessors = [];
|
_this._postProcessors = [];
|
||||||
_this.dynamicBatch = false;
|
_this.dynamicBatch = false;
|
||||||
|
_this.optimizeCost = 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();
|
||||||
@@ -1747,6 +1749,8 @@ var es;
|
|||||||
this.addChild(component.displayObject);
|
this.addChild(component.displayObject);
|
||||||
this.addChild(component.debugDisplayObject);
|
this.addChild(component.debugDisplayObject);
|
||||||
batching = false;
|
batching = false;
|
||||||
|
if (this.optimizeCost && displayContainer)
|
||||||
|
this.optimizeCombine(displayContainer);
|
||||||
displayContainer = null;
|
displayContainer = null;
|
||||||
}
|
}
|
||||||
else if (component instanceof es.RenderableComponent) {
|
else if (component instanceof es.RenderableComponent) {
|
||||||
@@ -1754,12 +1758,25 @@ var es;
|
|||||||
batching = true;
|
batching = true;
|
||||||
displayContainer = new egret.DisplayObjectContainer();
|
displayContainer = new egret.DisplayObjectContainer();
|
||||||
displayContainer.cacheAsBitmap = true;
|
displayContainer.cacheAsBitmap = true;
|
||||||
|
displayContainer.touchEnabled = false;
|
||||||
|
displayContainer.touchChildren = false;
|
||||||
this.addChild(displayContainer);
|
this.addChild(displayContainer);
|
||||||
}
|
}
|
||||||
displayContainer.addChild(component.displayObject);
|
displayContainer.addChild(component.displayObject);
|
||||||
displayContainer.addChild(component.debugDisplayObject);
|
displayContainer.addChild(component.debugDisplayObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.optimizeCost && displayContainer)
|
||||||
|
this.optimizeCombine(displayContainer);
|
||||||
|
};
|
||||||
|
Scene.prototype.optimizeCombine = function (container) {
|
||||||
|
var renderTexture = new egret.RenderTexture();
|
||||||
|
renderTexture.drawToTexture(container, new es.Rectangle(0, 0, container.width, container.height));
|
||||||
|
var parent = container.parent;
|
||||||
|
var index = this.getChildIndex(container);
|
||||||
|
parent.addChildAt(new Bitmap(renderTexture), index);
|
||||||
|
parent.removeChild(container);
|
||||||
|
container.removeChildren();
|
||||||
};
|
};
|
||||||
Scene.prototype.postRender = function () {
|
Scene.prototype.postRender = function () {
|
||||||
if (this.enablePostProcessing) {
|
if (this.enablePostProcessing) {
|
||||||
@@ -3655,10 +3672,11 @@ var es;
|
|||||||
this.displayObject.anchorOffsetY = this._origin.y;
|
this.displayObject.anchorOffsetY = this._origin.y;
|
||||||
}
|
}
|
||||||
this.displayObject = new Bitmap(sprite.texture2D);
|
this.displayObject = new Bitmap(sprite.texture2D);
|
||||||
|
this.displayObject.touchEnabled = false;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
SpriteRenderer.prototype.setOrigin = function (origin) {
|
SpriteRenderer.prototype.setOrigin = function (origin) {
|
||||||
if (this._origin != origin) {
|
if (!this._origin.equals(origin)) {
|
||||||
this._origin = origin;
|
this._origin = origin;
|
||||||
this.displayObject.anchorOffsetX = this._origin.x;
|
this.displayObject.anchorOffsetX = this._origin.x;
|
||||||
this.displayObject.anchorOffsetY = this._origin.y;
|
this.displayObject.anchorOffsetY = this._origin.y;
|
||||||
@@ -3672,10 +3690,10 @@ var es;
|
|||||||
};
|
};
|
||||||
SpriteRenderer.prototype.render = function (camera) {
|
SpriteRenderer.prototype.render = function (camera) {
|
||||||
this.sync(camera);
|
this.sync(camera);
|
||||||
if (this.displayObject.x != this.bounds.x - camera.bounds.x)
|
if (this.displayObject.x != this.bounds.x - camera.bounds.x + this._origin.x)
|
||||||
this.displayObject.x = this.bounds.x - camera.bounds.x;
|
this.displayObject.x = this.bounds.x - camera.bounds.x + this._origin.x;
|
||||||
if (this.displayObject.y != this.bounds.y - camera.bounds.y)
|
if (this.displayObject.y != this.bounds.y - camera.bounds.y + this._origin.y)
|
||||||
this.displayObject.y = this.bounds.y - camera.bounds.y;
|
this.displayObject.y = this.bounds.y - camera.bounds.y + this._origin.y;
|
||||||
};
|
};
|
||||||
return SpriteRenderer;
|
return SpriteRenderer;
|
||||||
}(es.RenderableComponent));
|
}(es.RenderableComponent));
|
||||||
@@ -4548,7 +4566,8 @@ var es;
|
|||||||
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();
|
if (this._entity.scene.dynamicBatch)
|
||||||
|
this._entity.scene.dynamicInBatch();
|
||||||
};
|
};
|
||||||
ComponentList.prototype.updateLists = function () {
|
ComponentList.prototype.updateLists = function () {
|
||||||
if (this._componentsToRemove.length > 0) {
|
if (this._componentsToRemove.length > 0) {
|
||||||
@@ -4573,7 +4592,8 @@ var es;
|
|||||||
this._components.push(component);
|
this._components.push(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
}
|
}
|
||||||
this._entity.scene.dynamicInBatch();
|
if (this._entity.scene.dynamicBatch)
|
||||||
|
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
@@ -365,6 +365,7 @@ declare module es {
|
|||||||
readonly _postProcessors: PostProcessor[];
|
readonly _postProcessors: PostProcessor[];
|
||||||
_didSceneBegin: any;
|
_didSceneBegin: any;
|
||||||
dynamicBatch: boolean;
|
dynamicBatch: boolean;
|
||||||
|
optimizeCost: boolean;
|
||||||
constructor();
|
constructor();
|
||||||
static createWithDefaultRenderer(): Scene;
|
static createWithDefaultRenderer(): Scene;
|
||||||
initialize(): void;
|
initialize(): void;
|
||||||
@@ -378,6 +379,7 @@ declare module es {
|
|||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
dynamicInBatch(): void;
|
dynamicInBatch(): void;
|
||||||
|
private optimizeCombine;
|
||||||
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;
|
||||||
|
|||||||
+27
-7
@@ -1629,6 +1629,7 @@ var es;
|
|||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
|
var Bitmap = egret.Bitmap;
|
||||||
var Scene = (function (_super) {
|
var Scene = (function (_super) {
|
||||||
__extends(Scene, _super);
|
__extends(Scene, _super);
|
||||||
function Scene() {
|
function Scene() {
|
||||||
@@ -1638,6 +1639,7 @@ var es;
|
|||||||
_this._renderers = [];
|
_this._renderers = [];
|
||||||
_this._postProcessors = [];
|
_this._postProcessors = [];
|
||||||
_this.dynamicBatch = false;
|
_this.dynamicBatch = false;
|
||||||
|
_this.optimizeCost = 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();
|
||||||
@@ -1747,6 +1749,8 @@ var es;
|
|||||||
this.addChild(component.displayObject);
|
this.addChild(component.displayObject);
|
||||||
this.addChild(component.debugDisplayObject);
|
this.addChild(component.debugDisplayObject);
|
||||||
batching = false;
|
batching = false;
|
||||||
|
if (this.optimizeCost && displayContainer)
|
||||||
|
this.optimizeCombine(displayContainer);
|
||||||
displayContainer = null;
|
displayContainer = null;
|
||||||
}
|
}
|
||||||
else if (component instanceof es.RenderableComponent) {
|
else if (component instanceof es.RenderableComponent) {
|
||||||
@@ -1754,12 +1758,25 @@ var es;
|
|||||||
batching = true;
|
batching = true;
|
||||||
displayContainer = new egret.DisplayObjectContainer();
|
displayContainer = new egret.DisplayObjectContainer();
|
||||||
displayContainer.cacheAsBitmap = true;
|
displayContainer.cacheAsBitmap = true;
|
||||||
|
displayContainer.touchEnabled = false;
|
||||||
|
displayContainer.touchChildren = false;
|
||||||
this.addChild(displayContainer);
|
this.addChild(displayContainer);
|
||||||
}
|
}
|
||||||
displayContainer.addChild(component.displayObject);
|
displayContainer.addChild(component.displayObject);
|
||||||
displayContainer.addChild(component.debugDisplayObject);
|
displayContainer.addChild(component.debugDisplayObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.optimizeCost && displayContainer)
|
||||||
|
this.optimizeCombine(displayContainer);
|
||||||
|
};
|
||||||
|
Scene.prototype.optimizeCombine = function (container) {
|
||||||
|
var renderTexture = new egret.RenderTexture();
|
||||||
|
renderTexture.drawToTexture(container, new es.Rectangle(0, 0, container.width, container.height));
|
||||||
|
var parent = container.parent;
|
||||||
|
var index = this.getChildIndex(container);
|
||||||
|
parent.addChildAt(new Bitmap(renderTexture), index);
|
||||||
|
parent.removeChild(container);
|
||||||
|
container.removeChildren();
|
||||||
};
|
};
|
||||||
Scene.prototype.postRender = function () {
|
Scene.prototype.postRender = function () {
|
||||||
if (this.enablePostProcessing) {
|
if (this.enablePostProcessing) {
|
||||||
@@ -3655,10 +3672,11 @@ var es;
|
|||||||
this.displayObject.anchorOffsetY = this._origin.y;
|
this.displayObject.anchorOffsetY = this._origin.y;
|
||||||
}
|
}
|
||||||
this.displayObject = new Bitmap(sprite.texture2D);
|
this.displayObject = new Bitmap(sprite.texture2D);
|
||||||
|
this.displayObject.touchEnabled = false;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
SpriteRenderer.prototype.setOrigin = function (origin) {
|
SpriteRenderer.prototype.setOrigin = function (origin) {
|
||||||
if (this._origin != origin) {
|
if (!this._origin.equals(origin)) {
|
||||||
this._origin = origin;
|
this._origin = origin;
|
||||||
this.displayObject.anchorOffsetX = this._origin.x;
|
this.displayObject.anchorOffsetX = this._origin.x;
|
||||||
this.displayObject.anchorOffsetY = this._origin.y;
|
this.displayObject.anchorOffsetY = this._origin.y;
|
||||||
@@ -3672,10 +3690,10 @@ var es;
|
|||||||
};
|
};
|
||||||
SpriteRenderer.prototype.render = function (camera) {
|
SpriteRenderer.prototype.render = function (camera) {
|
||||||
this.sync(camera);
|
this.sync(camera);
|
||||||
if (this.displayObject.x != this.bounds.x - camera.bounds.x)
|
if (this.displayObject.x != this.bounds.x - camera.bounds.x + this._origin.x)
|
||||||
this.displayObject.x = this.bounds.x - camera.bounds.x;
|
this.displayObject.x = this.bounds.x - camera.bounds.x + this._origin.x;
|
||||||
if (this.displayObject.y != this.bounds.y - camera.bounds.y)
|
if (this.displayObject.y != this.bounds.y - camera.bounds.y + this._origin.y)
|
||||||
this.displayObject.y = this.bounds.y - camera.bounds.y;
|
this.displayObject.y = this.bounds.y - camera.bounds.y + this._origin.y;
|
||||||
};
|
};
|
||||||
return SpriteRenderer;
|
return SpriteRenderer;
|
||||||
}(es.RenderableComponent));
|
}(es.RenderableComponent));
|
||||||
@@ -4548,7 +4566,8 @@ var es;
|
|||||||
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();
|
if (this._entity.scene.dynamicBatch)
|
||||||
|
this._entity.scene.dynamicInBatch();
|
||||||
};
|
};
|
||||||
ComponentList.prototype.updateLists = function () {
|
ComponentList.prototype.updateLists = function () {
|
||||||
if (this._componentsToRemove.length > 0) {
|
if (this._componentsToRemove.length > 0) {
|
||||||
@@ -4573,7 +4592,8 @@ var es;
|
|||||||
this._components.push(component);
|
this._components.push(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
}
|
}
|
||||||
this._entity.scene.dynamicInBatch();
|
if (this._entity.scene.dynamicBatch)
|
||||||
|
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
@@ -90,6 +90,7 @@ module es {
|
|||||||
this.displayObject.anchorOffsetY = this._origin.y;
|
this.displayObject.anchorOffsetY = this._origin.y;
|
||||||
}
|
}
|
||||||
this.displayObject = new Bitmap(sprite.texture2D);
|
this.displayObject = new Bitmap(sprite.texture2D);
|
||||||
|
this.displayObject.touchEnabled = false;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -99,7 +100,7 @@ module es {
|
|||||||
* @param origin
|
* @param origin
|
||||||
*/
|
*/
|
||||||
public setOrigin(origin: Vector2): SpriteRenderer {
|
public setOrigin(origin: Vector2): SpriteRenderer {
|
||||||
if (this._origin != origin) {
|
if (!this._origin.equals(origin)) {
|
||||||
this._origin = origin;
|
this._origin = origin;
|
||||||
this.displayObject.anchorOffsetX = this._origin.x;
|
this.displayObject.anchorOffsetX = this._origin.x;
|
||||||
this.displayObject.anchorOffsetY = this._origin.y;
|
this.displayObject.anchorOffsetY = this._origin.y;
|
||||||
@@ -123,8 +124,8 @@ module es {
|
|||||||
public render(camera: Camera) {
|
public render(camera: Camera) {
|
||||||
this.sync(camera);
|
this.sync(camera);
|
||||||
|
|
||||||
if (this.displayObject.x != this.bounds.x - camera.bounds.x) this.displayObject.x = this.bounds.x - camera.bounds.x;
|
if (this.displayObject.x != this.bounds.x - camera.bounds.x + this._origin.x) this.displayObject.x = this.bounds.x - camera.bounds.x + this._origin.x;
|
||||||
if (this.displayObject.y != this.bounds.y - camera.bounds.y) this.displayObject.y = this.bounds.y - camera.bounds.y;
|
if (this.displayObject.y != this.bounds.y - camera.bounds.y + this._origin.y) this.displayObject.y = this.bounds.y - camera.bounds.y + this._origin.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
module es {
|
module es {
|
||||||
|
import Bitmap = egret.Bitmap;
|
||||||
|
|
||||||
/** 场景 */
|
/** 场景 */
|
||||||
export class Scene extends egret.DisplayObjectContainer {
|
export class Scene extends egret.DisplayObjectContainer {
|
||||||
/**
|
/**
|
||||||
@@ -33,7 +35,14 @@ module es {
|
|||||||
public _renderers: Renderer[] = [];
|
public _renderers: Renderer[] = [];
|
||||||
public readonly _postProcessors: PostProcessor[] = [];
|
public readonly _postProcessors: PostProcessor[] = [];
|
||||||
public _didSceneBegin;
|
public _didSceneBegin;
|
||||||
|
/**
|
||||||
|
* 动态合批
|
||||||
|
*/
|
||||||
public dynamicBatch: boolean = false;
|
public dynamicBatch: boolean = false;
|
||||||
|
/**
|
||||||
|
* 极致优化cost 会失去所有的事件(触摸、点击) 慎重开启
|
||||||
|
*/
|
||||||
|
public optimizeCost: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -203,6 +212,7 @@ module es {
|
|||||||
this.addChild(component.displayObject);
|
this.addChild(component.displayObject);
|
||||||
this.addChild(component.debugDisplayObject);
|
this.addChild(component.debugDisplayObject);
|
||||||
batching = false;
|
batching = false;
|
||||||
|
if (this.optimizeCost && displayContainer) this.optimizeCombine(displayContainer);
|
||||||
displayContainer = null;
|
displayContainer = null;
|
||||||
} else if (component instanceof RenderableComponent) {
|
} else if (component instanceof RenderableComponent) {
|
||||||
// 静态
|
// 静态
|
||||||
@@ -210,6 +220,8 @@ module es {
|
|||||||
batching = true;
|
batching = true;
|
||||||
displayContainer = new egret.DisplayObjectContainer();
|
displayContainer = new egret.DisplayObjectContainer();
|
||||||
displayContainer.cacheAsBitmap = true;
|
displayContainer.cacheAsBitmap = true;
|
||||||
|
displayContainer.touchEnabled = false;
|
||||||
|
displayContainer.touchChildren = false;
|
||||||
this.addChild(displayContainer);
|
this.addChild(displayContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,6 +229,18 @@ module es {
|
|||||||
displayContainer.addChild(component.debugDisplayObject);
|
displayContainer.addChild(component.debugDisplayObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.optimizeCost && displayContainer) this.optimizeCombine(displayContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private optimizeCombine(container: egret.DisplayObjectContainer){
|
||||||
|
let renderTexture = new egret.RenderTexture();
|
||||||
|
renderTexture.drawToTexture(container, new Rectangle(0, 0, container.width, container.height));
|
||||||
|
let parent = container.parent;
|
||||||
|
let index = this.getChildIndex(container);
|
||||||
|
parent.addChildAt(new Bitmap(renderTexture), index);
|
||||||
|
parent.removeChild(container);
|
||||||
|
container.removeChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ module es {
|
|||||||
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();
|
if (this._entity.scene.dynamicBatch) this._entity.scene.dynamicInBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,7 +134,7 @@ module es {
|
|||||||
this._components.push(component);
|
this._components.push(component);
|
||||||
this._tempBufferList.push(component);
|
this._tempBufferList.push(component);
|
||||||
}
|
}
|
||||||
this._entity.scene.dynamicInBatch();
|
if (this._entity.scene.dynamicBatch) this._entity.scene.dynamicInBatch();
|
||||||
|
|
||||||
// 在调用onAddedToEntity之前清除,以防添加更多组件
|
// 在调用onAddedToEntity之前清除,以防添加更多组件
|
||||||
this._componentsToAdd.length = 0;
|
this._componentsToAdd.length = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user