优化getComponent与getComponents性能

This commit is contained in:
yhh
2021-04-26 15:23:16 +08:00
parent d576a95548
commit bc6920f829
7 changed files with 215 additions and 127 deletions

View File

@@ -2,13 +2,13 @@
module es {
export class SystemIndexManager {
public static INDEX = 0;
private static indices: HashMap<Function, number> = new HashMap<Function, number>();
private static indices: Map<Function, number> = new Map<Function, number>();
public static getIndexFor(es: Class): number {
let index: number = SystemIndexManager.indices.get(es);
if (index === undefined) {
if (!index) {
index = SystemIndexManager.INDEX++;
SystemIndexManager.indices.put(es, index);
SystemIndexManager.indices.set(es, index);
}
return index;
}
@@ -60,7 +60,7 @@ module es {
}
public onChanged(entity: Entity) {
let contains = new es.List(this._entities).contains(entity);
let contains = entity.getSystemBits().get(this.systemIndex_);
let interest = this._matcher.isInterestedEntity(entity);
if (interest && !contains)
@@ -71,6 +71,7 @@ module es {
public add(entity: Entity) {
this._entities.push(entity);
entity.getSystemBits().set(this.systemIndex_);
this.onAdded(entity);
}
@@ -78,6 +79,7 @@ module es {
public remove(entity: Entity) {
new es.List(this._entities).remove(entity);
entity.getSystemBits().clear(this.systemIndex_);
this.onRemoved(entity);
}