移除渲染模块,提供更纯净的ecs
This commit is contained in:
@@ -94,9 +94,6 @@ module es {
|
||||
for (let i = 0, s = this._components.length; i < s; ++ i) {
|
||||
let component = this._components[i];
|
||||
if (!component) continue;
|
||||
|
||||
if (component instanceof RenderableComponent)
|
||||
this._entity.scene.renderableComponents.remove(component);
|
||||
|
||||
// 处理IUpdatable
|
||||
if (isIUpdatable(component))
|
||||
@@ -112,9 +109,6 @@ module es {
|
||||
if (this._components.length > 0) {
|
||||
for (let i = 0, s = this._components.length; i < s; ++ i) {
|
||||
let component = this._components[i];
|
||||
if (component instanceof RenderableComponent)
|
||||
this._entity.scene.renderableComponents.add(component);
|
||||
|
||||
if (isIUpdatable(component))
|
||||
this._updatableComponents.push(component);
|
||||
|
||||
@@ -157,8 +151,6 @@ module es {
|
||||
if (this._componentsToAddList.length > 0) {
|
||||
for (let i = 0, l = this._componentsToAddList.length; i < l; ++ i) {
|
||||
let component = this._componentsToAddList[i];
|
||||
if (component instanceof RenderableComponent)
|
||||
this._entity.scene.renderableComponents.add(component);
|
||||
|
||||
if (isIUpdatable(component))
|
||||
this._updatableComponents.push(component);
|
||||
@@ -195,9 +187,6 @@ module es {
|
||||
}
|
||||
|
||||
public handleRemove(component: Component) {
|
||||
if (component instanceof RenderableComponent)
|
||||
this._entity.scene.renderableComponents.remove(component);
|
||||
|
||||
if (isIUpdatable(component) && this._updatableComponents.length > 0) {
|
||||
let index = this._updatableComponents.findIndex((c) => (<any>c as Component).id == component.id);
|
||||
if (index != -1)
|
||||
@@ -325,14 +314,5 @@ module es {
|
||||
this._components[i].onDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
public debugRender(batcher: IBatcher) {
|
||||
if (!batcher) return;
|
||||
for (let i = 0; i < this._components.length; i ++) {
|
||||
if (this._components[i].enabled) {
|
||||
this._components[i].debugRender(batcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
module es {
|
||||
export class RenderableComponentList {
|
||||
private _components: IRenderable[] = [];
|
||||
private _componentsByRenderLayer: Map<number, IRenderable[]> = new Map();
|
||||
private _unsortedRenderLayers: number[] = [];
|
||||
private _componentsNeedSort = true;
|
||||
|
||||
public get count() {
|
||||
return this._components.length;
|
||||
}
|
||||
|
||||
public get(index: number) {
|
||||
return this._components[index];
|
||||
}
|
||||
|
||||
public add(component: IRenderable) {
|
||||
this._components.push(component);
|
||||
this.addToRenderLayerList(component, component.renderLayer);
|
||||
}
|
||||
|
||||
public remove(component: IRenderable) {
|
||||
new List(this._components).remove(component);
|
||||
new List(this._componentsByRenderLayer.get(component.renderLayer)).remove(component);
|
||||
}
|
||||
|
||||
public updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number) {
|
||||
if (this._componentsByRenderLayer.has(oldRenderLayer) && new List(this._componentsByRenderLayer.get(oldRenderLayer)).contains(component)) {
|
||||
new List(this._componentsByRenderLayer.get(oldRenderLayer)).remove(component);
|
||||
this.addToRenderLayerList(component, newRenderLayer);
|
||||
}
|
||||
}
|
||||
|
||||
public setRenderLayerNeedsComponentSort(renderLayer: number) {
|
||||
const unsortedRenderLayersList = new List(this._unsortedRenderLayers);
|
||||
if (!unsortedRenderLayersList.contains(renderLayer))
|
||||
unsortedRenderLayersList.add(renderLayer);
|
||||
this._componentsNeedSort = true;
|
||||
}
|
||||
|
||||
public setNeedsComponentSort() {
|
||||
this._componentsNeedSort = true;
|
||||
}
|
||||
|
||||
private addToRenderLayerList(component: IRenderable, renderLayer: number) {
|
||||
let list = this.componentsWithRenderLayer(renderLayer);
|
||||
es.Insist.isFalse(!!list.find(c => c == component), "组件renderLayer列表已包含此组件");
|
||||
|
||||
list.push(component);
|
||||
const unsortedRenderLayersList = new List(this._unsortedRenderLayers);
|
||||
if (!unsortedRenderLayersList.contains(renderLayer))
|
||||
unsortedRenderLayersList.add(renderLayer);
|
||||
this._componentsNeedSort = true;
|
||||
}
|
||||
|
||||
public componentsWithRenderLayer(renderLayer: number) {
|
||||
if (!this._componentsByRenderLayer.get(renderLayer)) {
|
||||
this._componentsByRenderLayer.set(renderLayer, []);
|
||||
}
|
||||
|
||||
return this._componentsByRenderLayer.get(renderLayer);
|
||||
}
|
||||
|
||||
public updateLists() {
|
||||
if (this._componentsNeedSort) {
|
||||
this._components.sort((self, other) => other.renderLayer - self.renderLayer);
|
||||
this._componentsNeedSort = false;
|
||||
}
|
||||
|
||||
if (this._unsortedRenderLayers.length > 0) {
|
||||
for (let i = 0, count = this._unsortedRenderLayers.length; i < count; i ++) {
|
||||
const renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]);
|
||||
if (renderLayerComponents) {
|
||||
renderLayerComponents.sort((self, other) => other.renderLayer - self.renderLayer);
|
||||
}
|
||||
|
||||
this._unsortedRenderLayers.length = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user