2020-07-23 11:00:46 +08:00
|
|
|
module es {
|
|
|
|
|
export class Matcher{
|
|
|
|
|
protected allSet = new BitSet();
|
|
|
|
|
protected exclusionSet = new BitSet();
|
|
|
|
|
protected oneSet = new BitSet();
|
2020-06-08 20:11:58 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public static empty(){
|
|
|
|
|
return new Matcher();
|
|
|
|
|
}
|
2020-06-08 20:11:58 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public getAllSet(){
|
|
|
|
|
return this.allSet;
|
|
|
|
|
}
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public getExclusionSet(){
|
|
|
|
|
return this.exclusionSet;
|
|
|
|
|
}
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public getOneSet(){
|
|
|
|
|
return this.oneSet;
|
|
|
|
|
}
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public IsIntersted(e: Entity){
|
|
|
|
|
if (!this.allSet.isEmpty()){
|
|
|
|
|
for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)){
|
|
|
|
|
if (!e.componentBits.get(i))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-06-08 20:11:58 +08:00
|
|
|
}
|
|
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits))
|
|
|
|
|
return false;
|
2020-06-08 20:11:58 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits))
|
|
|
|
|
return false;
|
2020-06-08 20:11:58 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public all(...types: any[]): Matcher{
|
|
|
|
|
types.forEach(type => {
|
|
|
|
|
this.allSet.set(ComponentTypeManager.getIndexFor(type));
|
|
|
|
|
});
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
return this;
|
|
|
|
|
}
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public exclude(...types: any[]){
|
|
|
|
|
types.forEach(type => {
|
|
|
|
|
this.exclusionSet.set(ComponentTypeManager.getIndexFor(type));
|
|
|
|
|
});
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
return this;
|
|
|
|
|
}
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
public one(...types: any[]){
|
|
|
|
|
types.forEach(type => {
|
|
|
|
|
this.oneSet.set(ComponentTypeManager.getIndexFor(type));
|
|
|
|
|
});
|
2020-07-01 14:54:35 +08:00
|
|
|
|
2020-07-23 11:00:46 +08:00
|
|
|
return this;
|
|
|
|
|
}
|
2020-07-01 14:54:35 +08:00
|
|
|
}
|
2020-07-23 11:00:46 +08:00
|
|
|
}
|