新增entitySystemsEnabled用于控制是否开启系统

This commit is contained in:
yhh
2020-11-26 10:44:28 +08:00
parent 1bb1b8704b
commit 97dfcb4c04
6 changed files with 53 additions and 27 deletions

View File

@@ -538,6 +538,7 @@ var es;
this.transform = new es.Transform(this); this.transform = new es.Transform(this);
this.name = name; this.name = name;
this.id = Entity._idGenerator++; this.id = Entity._idGenerator++;
if (es.Core.entitySystemsEnabled)
this.componentBits = new es.BitSet(); this.componentBits = new es.BitSet();
} }
Object.defineProperty(Entity.prototype, "isDestroyed", { Object.defineProperty(Entity.prototype, "isDestroyed", {
@@ -820,6 +821,7 @@ var es;
this._renderers = []; this._renderers = [];
this.entities = new es.EntityList(this); this.entities = new es.EntityList(this);
this.renderableComponents = new es.RenderableComponentList(); this.renderableComponents = new es.RenderableComponentList();
if (es.Core.entitySystemsEnabled)
this.entityProcessors = new es.EntityProcessorList(); this.entityProcessors = new es.EntityProcessorList();
this.initialize(); this.initialize();
} }
@@ -2058,18 +2060,22 @@ var es;
continue; continue;
if (es.isIUpdatable(component)) if (es.isIUpdatable(component))
this._updatableComponents.remove(component); this._updatableComponents.remove(component);
if (es.Core.entitySystemsEnabled) {
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false); this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false);
this._entity.scene.entityProcessors.onComponentRemoved(this._entity); this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
} }
}
}; };
ComponentList.prototype.registerAllComponents = function () { ComponentList.prototype.registerAllComponents = function () {
for (var i = 0; i < this._components.length; i++) { for (var i = 0; i < this._components.length; i++) {
var component = this._components.buffer[i]; var component = this._components.buffer[i];
if (es.isIUpdatable(component)) if (es.isIUpdatable(component))
this._updatableComponents.add(component); this._updatableComponents.add(component);
if (es.Core.entitySystemsEnabled) {
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"])); this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]));
this._entity.scene.entityProcessors.onComponentAdded(this._entity); this._entity.scene.entityProcessors.onComponentAdded(this._entity);
} }
}
}; };
ComponentList.prototype.updateLists = function () { ComponentList.prototype.updateLists = function () {
if (this._componentsToRemove.length > 0) { if (this._componentsToRemove.length > 0) {
@@ -2084,8 +2090,10 @@ var es;
var component = this._componentsToAdd[i]; var component = this._componentsToAdd[i];
if (es.isIUpdatable(component)) if (es.isIUpdatable(component))
this._updatableComponents.add(component); this._updatableComponents.add(component);
if (es.Core.entitySystemsEnabled) {
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"])); this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]));
this._entity.scene.entityProcessors.onComponentAdded(this._entity); this._entity.scene.entityProcessors.onComponentAdded(this._entity);
}
this._components.add(component); this._components.add(component);
this._tempBufferList.push(component); this._tempBufferList.push(component);
} }
@@ -2110,8 +2118,10 @@ var es;
return; return;
if (es.isIUpdatable(component)) if (es.isIUpdatable(component))
this._updatableComponents.remove(component); this._updatableComponents.remove(component);
if (es.Core.entitySystemsEnabled) {
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false); this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false);
this._entity.scene.entityProcessors.onComponentRemoved(this._entity); this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
}
component.onRemovedFromEntity(); component.onRemovedFromEntity();
component.entity = null; component.entity = null;
}; };
@@ -2306,6 +2316,7 @@ var es;
this._entities.remove(entity); this._entities.remove(entity);
entity.onRemovedFromScene(); entity.onRemovedFromScene();
entity.scene = null; entity.scene = null;
if (es.Core.entitySystemsEnabled)
this.scene.entityProcessors.onEntityRemoved(entity); this.scene.entityProcessors.onEntityRemoved(entity);
} }
this._entitiesToRemove.length = 0; this._entitiesToRemove.length = 0;
@@ -2351,6 +2362,7 @@ var es;
this._entities.push(entity); this._entities.push(entity);
entity.scene = this.scene; entity.scene = this.scene;
this.addToTagList(entity); this.addToTagList(entity);
if (es.Core.entitySystemsEnabled)
this.scene.entityProcessors.onEntityAdded(entity); this.scene.entityProcessors.onEntityAdded(entity);
} }
}; };

File diff suppressed because one or more lines are too long

View File

@@ -34,6 +34,7 @@ module es {
this.name = name; this.name = name;
this.id = Entity._idGenerator++; this.id = Entity._idGenerator++;
if (Core.entitySystemsEnabled)
this.componentBits = new BitSet(); this.componentBits = new BitSet();
} }

View File

@@ -22,6 +22,7 @@ module es {
this.entities = new EntityList(this); this.entities = new EntityList(this);
this.renderableComponents = new RenderableComponentList(); this.renderableComponents = new RenderableComponentList();
if (Core.entitySystemsEnabled)
this.entityProcessors = new EntityProcessorList(); this.entityProcessors = new EntityProcessorList();
this.initialize(); this.initialize();

View File

@@ -86,10 +86,12 @@ module es {
if (isIUpdatable(component)) if (isIUpdatable(component))
this._updatableComponents.remove(component); this._updatableComponents.remove(component);
if (Core.entitySystemsEnabled) {
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false); this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false);
this._entity.scene.entityProcessors.onComponentRemoved(this._entity); this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
} }
} }
}
public registerAllComponents() { public registerAllComponents() {
for (let i = 0; i < this._components.length; i++) { for (let i = 0; i < this._components.length; i++) {
@@ -98,10 +100,12 @@ module es {
if (isIUpdatable(component)) if (isIUpdatable(component))
this._updatableComponents.add(component); this._updatableComponents.add(component);
if (Core.entitySystemsEnabled) {
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"])); this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]));
this._entity.scene.entityProcessors.onComponentAdded(this._entity); this._entity.scene.entityProcessors.onComponentAdded(this._entity);
} }
} }
}
/** /**
* 处理任何需要删除或添加的组件 * 处理任何需要删除或添加的组件
@@ -123,8 +127,10 @@ module es {
if (isIUpdatable(component)) if (isIUpdatable(component))
this._updatableComponents.add(component); this._updatableComponents.add(component);
if (Core.entitySystemsEnabled) {
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"])); this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]));
this._entity.scene.entityProcessors.onComponentAdded(this._entity); this._entity.scene.entityProcessors.onComponentAdded(this._entity);
}
this._components.add(component); this._components.add(component);
this._tempBufferList.push(component); this._tempBufferList.push(component);
@@ -160,8 +166,10 @@ module es {
if (isIUpdatable(component)) if (isIUpdatable(component))
this._updatableComponents.remove(component); this._updatableComponents.remove(component);
if (Core.entitySystemsEnabled) {
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false); this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component["__proto__"]["constructor"]), false);
this._entity.scene.entityProcessors.onComponentRemoved(this._entity); this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
}
component.onRemovedFromEntity(); component.onRemovedFromEntity();
component.entity = null; component.entity = null;

View File

@@ -144,12 +144,15 @@ module es {
public updateLists() { public updateLists() {
if (this._entitiesToRemove.length > 0) { if (this._entitiesToRemove.length > 0) {
for (const entity of this._entitiesToRemove) { for (const entity of this._entitiesToRemove) {
// 处理标签列表
this.removeFromTagList(entity); this.removeFromTagList(entity);
// 处理常规实体列表
this._entities.remove(entity); this._entities.remove(entity);
entity.onRemovedFromScene(); entity.onRemovedFromScene();
entity.scene = null; entity.scene = null;
if (Core.entitySystemsEnabled)
this.scene.entityProcessors.onEntityRemoved(entity); this.scene.entityProcessors.onEntityRemoved(entity);
} }
@@ -209,6 +212,7 @@ module es {
this.addToTagList(entity); this.addToTagList(entity);
if (Core.entitySystemsEnabled)
this.scene.entityProcessors.onEntityAdded(entity); this.scene.entityProcessors.onEntityAdded(entity);
} }
} }