新增entityprocessor管理实体解析器

This commit is contained in:
YHH
2020-06-08 21:53:09 +08:00
parent a048a8ac29
commit 11af0a31a7
17 changed files with 386 additions and 66 deletions

View File

@@ -94,7 +94,7 @@ class BitSet{
public isEmpty(): boolean{
for (let i = this._bits.length - 1; i >= 0; i --){
if (this._bits[i] != 0)
if (this._bits[i])
return false;
}
@@ -121,9 +121,13 @@ class BitSet{
return -1;
}
public set(pos: number){
let offset = pos >> 6;
this.ensure(offset);
this._bits[offset] |= 1 << pos;
public set(pos: number, value: boolean = true){
if (value){
let offset = pos >> 6;
this.ensure(offset);
this._bits[offset] |= 1 << pos;
}else{
this.clear(pos);
}
}
}

View File

@@ -69,7 +69,7 @@ class EntityList{
this._entities.remove(entity);
entity.scene = null;
this.scene.entityProcessors.forEach(processor => processor.remove(entity));
this.scene.entityProcessors.onEntityRemoved(entity);
});
this._tempEntityList.length = 0;
@@ -83,7 +83,7 @@ class EntityList{
this._entities.push(entity);
entity.scene = this.scene;
this.scene.entityProcessors.forEach(processor => processor.onChanged(entity));
this.scene.entityProcessors.onEntityAdded(entity)
});
this._tempEntityList.length = 0;

View File

@@ -0,0 +1,69 @@
class EntityProcessorList {
private _processors: EntitySystem[] = [];
public add(processor: EntitySystem){
this._processors.push(processor);
}
public remove(processor: EntitySystem){
this._processors.remove(processor);
}
public onComponentAdded(entity: Entity){
this.notifyEntityChanged(entity);
}
public onComponentRemoved(entity: Entity){
this.notifyEntityChanged(entity);
}
public onEntityAdded(entity: Entity){
this.notifyEntityChanged(entity);
}
public onEntityRemoved(entity: Entity){
this.removeFromProcessors(entity);
}
protected notifyEntityChanged(entity: Entity){
for (let i = 0; i < this._processors.length; i ++){
this._processors[i].onChanged(entity);
}
}
protected removeFromProcessors(entity: Entity){
for (let i = 0; i < this._processors.length; i ++){
this._processors[i].remove(entity);
}
}
public begin(){
}
public update(){
for (let i = 0; i < this._processors.length; i++){
this._processors[i].update();
}
}
public lateUpdate(){
for (let i = 0; i < this._processors.length; i ++){
this._processors[i].lateUpdate();
}
}
public end(){
}
public getProcessor<T extends EntitySystem>(): T{
for (let i = 0; i < this._processors.length; i ++){
let processor = this._processors[i];
if (processor instanceof EntitySystem)
return processor as T;
}
return null;
}
}

View File

@@ -0,0 +1,15 @@
class Time {
public static unscaledDeltaTime;
public static deltaTime: number;
public static timeScale = 1;
private static _lastTime = 0;
public static update(currentTime: number){
let dt = (currentTime - this._lastTime) / 1000;
this.deltaTime = dt * this.timeScale;
this.unscaledDeltaTime = dt;
this._lastTime = currentTime;
}
}