移除Bitset更改为Bits
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
module es {
|
||||
export class Matcher {
|
||||
protected allSet = new BitSet();
|
||||
protected exclusionSet = new BitSet();
|
||||
protected oneSet = new BitSet();
|
||||
protected allSet: (new (...args: any[]) => Component)[] = [];
|
||||
protected exclusionSet: (new (...args: any[]) => Component)[] = [];
|
||||
protected oneSet: (new (...args: any[]) => Component)[] = [];
|
||||
|
||||
public static empty() {
|
||||
return new Matcher();
|
||||
@@ -24,46 +24,53 @@ module es {
|
||||
return this.isInterested(e.componentBits);
|
||||
}
|
||||
|
||||
public isInterested(componentBits: BitSet) {
|
||||
// 检查实体是否拥有该方面中定义的所有组件
|
||||
if (!this.allSet.isEmpty()) {
|
||||
for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
|
||||
if (!componentBits.get(i))
|
||||
public isInterested(components: Bits) {
|
||||
if (this.allSet.length != 0) {
|
||||
for (let s of this.allSet) {
|
||||
if (!components.get(ComponentTypeManager.getIndexFor(s)))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果我们仍然感兴趣,检查该实体是否拥有任何一个排除组件,如果有,那么系统就不感兴趣
|
||||
if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(componentBits))
|
||||
return false;
|
||||
if (this.exclusionSet.length != 0) {
|
||||
for (let s of this.exclusionSet) {
|
||||
if (components.get(ComponentTypeManager.getIndexFor(s)))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果我们仍然感兴趣,检查该实体是否拥有oneSet中的任何一个组件。如果是,系统就会感兴趣
|
||||
if (!this.oneSet.isEmpty() && !this.oneSet.intersects(componentBits))
|
||||
return false;
|
||||
if (this.oneSet.length != 0) {
|
||||
for (let s of this.oneSet) {
|
||||
if (components.get(ComponentTypeManager.getIndexFor(s)))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public all(...types: any[]): Matcher {
|
||||
types.forEach(type => {
|
||||
this.allSet.set(ComponentTypeManager.getIndexFor(type));
|
||||
});
|
||||
let t;
|
||||
for (t of types) {
|
||||
this.allSet.push(t);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public exclude(...types: any[]) {
|
||||
types.forEach(type => {
|
||||
this.exclusionSet.set(ComponentTypeManager.getIndexFor(type));
|
||||
});
|
||||
let t;
|
||||
for (t of types) {
|
||||
this.exclusionSet.push(t);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public one(...types: any[]) {
|
||||
types.forEach(type => {
|
||||
this.oneSet.set(ComponentTypeManager.getIndexFor(type));
|
||||
});
|
||||
for (const t of types) {
|
||||
this.oneSet.push(t);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user