移除Core,新增各接口用于sdk扩展
This commit is contained in:
@@ -86,10 +86,8 @@ module es {
|
||||
if (isIUpdatable(component))
|
||||
new linq.List(this._updatableComponents).remove(component);
|
||||
|
||||
if (Core.entitySystemsEnabled) {
|
||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)), false);
|
||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||
}
|
||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)), false);
|
||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,10 +96,8 @@ module es {
|
||||
if (isIUpdatable(component))
|
||||
this._updatableComponents.push(component);
|
||||
|
||||
if (Core.entitySystemsEnabled) {
|
||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)));
|
||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||
}
|
||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)));
|
||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,10 +121,8 @@ module es {
|
||||
if (isIUpdatable(component))
|
||||
this._updatableComponents.push(component);
|
||||
|
||||
if (Core.entitySystemsEnabled) {
|
||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)));
|
||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||
}
|
||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)));
|
||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||
|
||||
this._components.push(component);
|
||||
this._tempBufferList.push(component);
|
||||
@@ -164,10 +158,8 @@ module es {
|
||||
if (isIUpdatable(component))
|
||||
new linq.List(this._updatableComponents).remove(component);
|
||||
|
||||
if (Core.entitySystemsEnabled) {
|
||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)), false);
|
||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||
}
|
||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(TypeUtils.getType(component)), false);
|
||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||
|
||||
component.onRemovedFromEntity();
|
||||
component.entity = null;
|
||||
@@ -252,5 +244,12 @@ module es {
|
||||
for (let i = 0; i < this._components.length; i++)
|
||||
this._components[i].onDisabled();
|
||||
}
|
||||
|
||||
public debugRender(batcher: IBatcher) {
|
||||
for (let i = 0; i < this._components.length; i++) {
|
||||
if (this._components[i].enabled)
|
||||
this._components[i].debugRender(batcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,16 +136,15 @@ module es {
|
||||
public updateLists() {
|
||||
if (this._entitiesToRemove.getCount() > 0) {
|
||||
this._entitiesToRemove.toArray().forEach(entity => {
|
||||
// 处理标签列表
|
||||
this.removeFromTagList(entity);
|
||||
// 处理标签列表
|
||||
this.removeFromTagList(entity);
|
||||
|
||||
// 处理常规实体列表
|
||||
new linq.List(this._entities).remove(entity);
|
||||
entity.onRemovedFromScene();
|
||||
entity.scene = null;
|
||||
|
||||
if (Core.entitySystemsEnabled)
|
||||
this.scene.entityProcessors.onEntityRemoved(entity);
|
||||
// 处理常规实体列表
|
||||
new linq.List(this._entities).remove(entity);
|
||||
entity.onRemovedFromScene();
|
||||
entity.scene = null;
|
||||
|
||||
this.scene.entityProcessors.onEntityRemoved(entity);
|
||||
});
|
||||
this._entitiesToRemove.clear();
|
||||
}
|
||||
@@ -157,8 +156,7 @@ module es {
|
||||
|
||||
this.addToTagList(entity);
|
||||
|
||||
if (Core.entitySystemsEnabled)
|
||||
this.scene.entityProcessors.onEntityAdded(entity);
|
||||
this.scene.entityProcessors.onEntityAdded(entity);
|
||||
});
|
||||
|
||||
this._entitiesToAdded.toArray().forEach(entity => {
|
||||
@@ -177,7 +175,7 @@ module es {
|
||||
// 根据需要对标签列表进行排序
|
||||
if (this._unsortedTags.size > 0) {
|
||||
this._unsortedTags.forEach(value => this._entityDict.get(value).sort((a, b) => a.compareTo(b)));
|
||||
|
||||
|
||||
this._unsortedTags.clear();
|
||||
}
|
||||
}
|
||||
@@ -192,12 +190,12 @@ module es {
|
||||
return this._entities[i];
|
||||
}
|
||||
|
||||
for (let i = 0; i < this._entitiesToAdded.getCount(); i ++){
|
||||
for (let i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
||||
let entity = this._entitiesToAdded.toArray()[i];
|
||||
if (entity.name == name)
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -229,7 +227,7 @@ module es {
|
||||
list.push(this._entities[i] as T);
|
||||
}
|
||||
|
||||
for (let i = 0; i < this._entitiesToAdded.getCount(); i ++){
|
||||
for (let i = 0; i < this._entitiesToAdded.getCount(); i++) {
|
||||
let entity = this._entitiesToAdded.toArray()[i];
|
||||
if (TypeUtils.getType(entity) instanceof type) {
|
||||
list.push(entity as T);
|
||||
|
||||
90
source/src/ECS/Utils/RenderableComponentList.ts
Normal file
90
source/src/ECS/Utils/RenderableComponentList.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
module es {
|
||||
export class RenderableComponentList {
|
||||
// IRenderable列表的全局updateOrder排序
|
||||
public static compareUpdatableOrder: IComparer<IRenderable> = new RenderableComparer();
|
||||
|
||||
/**
|
||||
* 添加到实体的组件列表
|
||||
*/
|
||||
private _components: IRenderable[] = [];
|
||||
/**
|
||||
* 通过renderLayer跟踪组件,便于检索
|
||||
*/
|
||||
private _componentsByRenderLayer: Map<number, IRenderable[]> = new Map();
|
||||
|
||||
private _unsortedRenderLayers: number[] = [];
|
||||
private _componentsNeedSort: boolean = true;
|
||||
|
||||
public get count() {
|
||||
return this._components.length;
|
||||
}
|
||||
|
||||
public get(index: number): IRenderable {
|
||||
return this._components[index];
|
||||
}
|
||||
|
||||
public add(component: IRenderable) {
|
||||
this._components.push(component);
|
||||
this.addToRenderLayerList(component, component.renderLayer);
|
||||
}
|
||||
|
||||
public remove(component: IRenderable) {
|
||||
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) {
|
||||
// 需要注意的是,在组件 "上线 "之前,renderLayer可能会发生变化
|
||||
if (this._componentsByRenderLayer.has(oldRenderLayer) &&
|
||||
new linq.List(this._componentsByRenderLayer.get(oldRenderLayer)).contains(component)) {
|
||||
new linq.List(this._componentsByRenderLayer.get(oldRenderLayer)).remove(component);
|
||||
this.addToRenderLayerList(component, newRenderLayer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 弄脏RenderLayers排序标志,导致所有组件的重新排序
|
||||
* @param renderLayer
|
||||
*/
|
||||
public setRenderLayerNeedsComponentSort(renderLayer: number) {
|
||||
if (!new linq.List(this._unsortedRenderLayers).contains(renderLayer))
|
||||
this._unsortedRenderLayers.push(renderLayer);
|
||||
this._componentsNeedSort = true;
|
||||
}
|
||||
|
||||
private addToRenderLayerList(component: IRenderable, renderLayer: number) {
|
||||
let list = this.componentsWithRenderLayer(renderLayer);
|
||||
Insist.isFalse(new linq.List(list).contains(component), "组件renderLayer列表已经包含这个组件");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有给定renderLayer的组件。组件列表是预先排序的。
|
||||
* @param renderLayer
|
||||
*/
|
||||
public componentsWithRenderLayer(renderLayer: number) {
|
||||
if (!this._componentsByRenderLayer.has(renderLayer)) {
|
||||
this._componentsByRenderLayer.set(renderLayer, []);
|
||||
}
|
||||
|
||||
return this._componentsByRenderLayer.get(renderLayer);
|
||||
}
|
||||
|
||||
public updateList() {
|
||||
if (this._componentsNeedSort) {
|
||||
this._components.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
||||
this._componentsNeedSort = false;
|
||||
}
|
||||
|
||||
if (this._unsortedRenderLayers.length > 0) {
|
||||
for (let i = 0, count = this._unsortedRenderLayers.length; i < count; i++) {
|
||||
let renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]);
|
||||
if (renderLayerComponents) {
|
||||
renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
||||
}
|
||||
}
|
||||
|
||||
this._unsortedRenderLayers.length = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user