优化updatelist增快addEntity速度

This commit is contained in:
yhh
2020-10-09 15:39:06 +08:00
parent c9c745c730
commit 74fcfd7778
8 changed files with 137 additions and 114 deletions

View File

@@ -1,61 +0,0 @@
module es {
export class PrototypeSpriteRenderer extends SpriteRenderer {
public get width(): number {
return this._width;
}
public get height(): number {
return this._height;
}
public get bounds(): Rectangle {
if (this._areBoundsDirty){
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale,
this.entity.transform.rotation, this._width, this._height);
this._areBoundsDirty = false;
}
return this._bounds;
}
public skewTopX: number = 0;
public skewBottomX: number = 0;
public skewLeftY: number = 0;
public skewRightY: number = 0;
public _width: number = 0;
public _height: number = 0;
constructor(width: number = 50, height: number = 50){
super(Graphics.Instance.pixelTexture);
this._width = width;
this._height = height;
}
public setWidth(width: number): PrototypeSpriteRenderer {
this._width = width;
return this;
}
public setHeight(height: number): PrototypeSpriteRenderer {
this._height = height;
return this;
}
public setSkew(skewTopX: number, skewBottomX: number, skewLeftY: number, skewRightY: number): PrototypeSpriteRenderer{
this.skewTopX = skewTopX;
this.skewBottomX = skewBottomX;
this.skewLeftY = skewLeftY;
this.skewRightY = skewRightY;
return this;
}
public onAddedToEntity() {
this.originNormalized = Vector2Ext.halfVector();
}
public render(camera: es.Camera) {
}
}
}

View File

@@ -144,7 +144,7 @@ module es {
let temp = this._entitiesToRemove;
this._entitiesToRemove = this._tempEntityList;
this._tempEntityList = temp;
this._tempEntityList.forEach(entity => {
for (const entity of this._tempEntityList) {
this.removeFromTagList(entity);
this._entities.remove(entity);
@@ -152,7 +152,7 @@ module es {
entity.scene = null;
this.scene.entityProcessors.onEntityRemoved(entity);
});
}
this._tempEntityList.length = 0;
}
@@ -161,7 +161,7 @@ module es {
let temp = this._entitiesToAdded;
this._entitiesToAdded = this._tempEntityList;
this._tempEntityList = temp;
this._tempEntityList.forEach(entity => {
for (const entity of this._tempEntityList) {
if (!this._entities.contains(entity)) {
this._entities.push(entity);
entity.scene = this.scene;
@@ -170,23 +170,29 @@ module es {
this.scene.entityProcessors.onEntityAdded(entity)
}
});
}
// 现在所有实体都被添加到场景中我们再次循环并调用onAddedToScene
this._tempEntityList.forEach(entity => entity.onAddedToScene());
for (const entity of this._tempEntityList) {
entity.onAddedToScene();
}
this._tempEntityList.length = 0;
this._isEntityListUnsorted = true;
}
if (this._isEntityListUnsorted) {
this._entities.sort();
this._entities.sort((a, b)=>{
return a.compareTo(b);
});
this._isEntityListUnsorted = false;
}
if (this._unsortedTags.length > 0) {
this._unsortedTags.forEach(tag => {
this._entityDict.get(tag).sort();
});
for (const tag of this._unsortedTags) {
this._entityDict.get(tag).sort((a, b) => {
return a.compareTo(b);
});
}
this._unsortedTags.length = 0;
}
@@ -229,10 +235,10 @@ module es {
if (this._entities[i] instanceof type)
list.push(this._entities[i] as T);
}
this._entitiesToAdded.forEach(entity => {
for (const entity of this._entitiesToAdded) {
if (entity instanceof type)
list.push(entity as T);
});
}
return list;
}