取消Extension改为linq.List以避免forin污染
This commit is contained in:
@@ -63,6 +63,7 @@ module es {
|
||||
public _frameCounterElapsedTime: number = 0;
|
||||
public _frameCounter: number = 0;
|
||||
public _totalMemory: number = 0;
|
||||
public _titleMemory: (totalMemory: number, frameCounter: number) => void;
|
||||
public _scene: Scene;
|
||||
|
||||
/**
|
||||
@@ -188,6 +189,7 @@ module es {
|
||||
if (memoryInfo != null) {
|
||||
this._totalMemory = Number((memoryInfo.totalJSHeapSize / 1048576).toFixed(2));
|
||||
}
|
||||
if (this._titleMemory) this._titleMemory(this._totalMemory, this._frameCounter);
|
||||
this._frameCounter = 0;
|
||||
this._frameCounterElapsedTime -= 1;
|
||||
}
|
||||
|
||||
@@ -343,10 +343,10 @@ module es {
|
||||
* 获取类型T的第一个组件并返回它。如果没有找到组件,将创建组件。
|
||||
* @param type
|
||||
*/
|
||||
public getOrCreateComponent<T extends Component>(type: T) {
|
||||
let comp = this.components.getComponent<T>(TypeUtils.getType(type), true);
|
||||
public getOrCreateComponent<T extends Component>(type) {
|
||||
let comp = this.components.getComponent<T>(type, true);
|
||||
if (!comp) {
|
||||
comp = this.addComponent<T>(type);
|
||||
comp = this.addComponent<T>(new type());
|
||||
}
|
||||
|
||||
return comp;
|
||||
|
||||
@@ -147,7 +147,7 @@ module es {
|
||||
*/
|
||||
public getSceneComponent<T extends SceneComponent>(type) {
|
||||
for (let i = 0; i < this._sceneComponents.length; i++) {
|
||||
let component = this._sceneComponents[i];
|
||||
let component = this._sceneComponents.buffer[i];
|
||||
if (component instanceof type)
|
||||
return component as T;
|
||||
}
|
||||
@@ -212,9 +212,10 @@ module es {
|
||||
* @param renderer
|
||||
*/
|
||||
public removeRenderer(renderer: Renderer) {
|
||||
if (!this._renderers.contains(renderer))
|
||||
let rendererList = new linq.List(this._renderers);
|
||||
if (!rendererList.contains(renderer))
|
||||
return;
|
||||
this._renderers.remove(renderer);
|
||||
rendererList.remove(renderer);
|
||||
renderer.unload();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ module es {
|
||||
}
|
||||
|
||||
public onChanged(entity: Entity) {
|
||||
let contains = this._entities.contains(entity);
|
||||
let contains = new linq.List(this._entities).contains(entity);
|
||||
let interest = this._matcher.isInterestedEntity(entity);
|
||||
|
||||
if (interest && !contains)
|
||||
@@ -46,7 +46,7 @@ module es {
|
||||
}
|
||||
|
||||
public remove(entity: Entity) {
|
||||
this._entities.remove(entity);
|
||||
new linq.List(this._entities).remove(entity);
|
||||
this.onRemoved(entity);
|
||||
}
|
||||
|
||||
|
||||
@@ -268,8 +268,9 @@ module es {
|
||||
return this;
|
||||
|
||||
if (!this._parent) {
|
||||
this._parent._children.remove(this);
|
||||
this._parent._children.push(this);
|
||||
let children = new linq.List(this._parent._children);
|
||||
children.remove(this);
|
||||
children.add(this);
|
||||
}
|
||||
|
||||
this._parent = parent;
|
||||
|
||||
@@ -50,16 +50,18 @@ module es {
|
||||
}
|
||||
|
||||
public remove(component: Component) {
|
||||
if (this._componentsToRemove.contains(component))
|
||||
let componentToRemove = new linq.List(this._componentsToRemove);
|
||||
let componentToAdd = new linq.List(this._componentsToAdd);
|
||||
if (componentToRemove.contains(component))
|
||||
console.warn(`您正在尝试删除一个您已经删除的组件(${component})`);
|
||||
|
||||
// 这可能不是一个活动的组件,所以我们必须注意它是否还没有被处理,它可能正在同一帧中被删除
|
||||
if (this._componentsToAdd.contains(component)) {
|
||||
this._componentsToAdd.remove(component);
|
||||
if (componentToAdd.contains(component)) {
|
||||
componentToAdd.remove(component);
|
||||
return;
|
||||
}
|
||||
|
||||
this._componentsToRemove.push(component);
|
||||
componentToRemove.add(component);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,7 +122,7 @@ module es {
|
||||
public removeFromTagList(entity: Entity) {
|
||||
let list = this._entityDict.get(entity.tag);
|
||||
if (list) {
|
||||
list.remove(entity);
|
||||
new linq.List(list).remove(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ module es {
|
||||
}
|
||||
|
||||
public remove(processor: EntitySystem) {
|
||||
this._processors.remove(processor);
|
||||
new linq.List(this._processors).remove(processor);
|
||||
}
|
||||
|
||||
public onComponentAdded(entity: Entity) {
|
||||
|
||||
@@ -71,7 +71,7 @@ module es {
|
||||
throw new Error("index超出范围!");
|
||||
|
||||
this.length --;
|
||||
this.buffer.removeAt(index);
|
||||
new linq.List(this.buffer).removeAt(index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,14 +36,15 @@ module es {
|
||||
}
|
||||
|
||||
public remove(component: IRenderable) {
|
||||
this._components.remove(component);
|
||||
this._componentsByRenderLayer.get(component.renderLayer).remove(component);
|
||||
new linq.List(this._components).remove(component);
|
||||
new linq.List(this._componentsByRenderLayer.get(component.renderLayer)).remove(component);
|
||||
}
|
||||
|
||||
public updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number) {
|
||||
// 需要注意的是,如果渲染层在组件update之前发生了改变
|
||||
if (this._componentsByRenderLayer.has(oldRenderLayer) && this._componentsByRenderLayer.get(oldRenderLayer).contains(component)) {
|
||||
this._componentsByRenderLayer.get(oldRenderLayer).remove(component);
|
||||
let oldRenderLayers = new linq.List(this._componentsByRenderLayer.get(oldRenderLayer));
|
||||
if (this._componentsByRenderLayer.has(oldRenderLayer) && oldRenderLayers.contains(component)) {
|
||||
oldRenderLayers.remove(component);
|
||||
this.addToRenderLayerList(component, newRenderLayer);
|
||||
}
|
||||
}
|
||||
@@ -53,8 +54,9 @@ module es {
|
||||
* @param renderLayer
|
||||
*/
|
||||
public setRenderLayerNeedsComponentSort(renderLayer: number) {
|
||||
if (!this._unsortedRenderLayers.contains(renderLayer))
|
||||
this._unsortedRenderLayers.push(renderLayer);
|
||||
let unsortedRenderLayers = new linq.List(this._unsortedRenderLayers);
|
||||
if (!unsortedRenderLayers.contains(renderLayer))
|
||||
unsortedRenderLayers.add(renderLayer);
|
||||
this.componentsNeedSort = true;
|
||||
}
|
||||
|
||||
@@ -63,15 +65,16 @@ module es {
|
||||
}
|
||||
|
||||
public addToRenderLayerList(component: IRenderable, renderLayer: number) {
|
||||
let list = this.componentsWithRenderLayer(renderLayer);
|
||||
let list = new linq.List(this.componentsWithRenderLayer(renderLayer));
|
||||
if (list.contains(component)) {
|
||||
console.warn("组件呈现层列表已经包含此组件");
|
||||
return;
|
||||
}
|
||||
|
||||
list.push(component);
|
||||
if (!this._unsortedRenderLayers.contains(renderLayer))
|
||||
this._unsortedRenderLayers.push(renderLayer);
|
||||
list.add(component);
|
||||
let unsortedRenderLayers = new linq.List(this._unsortedRenderLayers);
|
||||
if (!unsortedRenderLayers.contains(renderLayer))
|
||||
unsortedRenderLayers.add(renderLayer);
|
||||
this.componentsNeedSort = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user