新增被动系统与协调系统 完善matcher

This commit is contained in:
yhh
2020-07-01 14:54:35 +08:00
parent 549db2fcfe
commit 5e871bc501
10 changed files with 241 additions and 2 deletions

View File

@@ -485,6 +485,15 @@ declare abstract class EntityProcessingSystem extends EntitySystem {
protected process(entities: Entity[]): void; protected process(entities: Entity[]): void;
protected lateProcess(entities: Entity[]): void; protected lateProcess(entities: Entity[]): void;
} }
declare abstract class PassiveSystem extends EntitySystem {
onChanged(entity: Entity): void;
protected process(entities: Entity[]): void;
}
declare abstract class ProcessingSystem extends EntitySystem {
onChanged(entity: Entity): void;
protected process(entities: Entity[]): void;
abstract processSystem(): any;
}
declare class BitSet { declare class BitSet {
private static LONG_MASK; private static LONG_MASK;
private _bits; private _bits;
@@ -568,7 +577,13 @@ declare class Matcher {
protected exclusionSet: BitSet; protected exclusionSet: BitSet;
protected oneSet: BitSet; protected oneSet: BitSet;
static empty(): Matcher; static empty(): Matcher;
getAllSet(): BitSet;
getExclusionSet(): BitSet;
getOneSet(): BitSet;
IsIntersted(e: Entity): boolean; IsIntersted(e: Entity): boolean;
all(...types: any[]): Matcher;
exclude(...types: any[]): this;
one(...types: any[]): this;
} }
declare class RenderableComponentList { declare class RenderableComponentList {
private _components; private _components;

View File

@@ -2294,6 +2294,33 @@ var EntityProcessingSystem = (function (_super) {
}; };
return EntityProcessingSystem; return EntityProcessingSystem;
}(EntitySystem)); }(EntitySystem));
var PassiveSystem = (function (_super) {
__extends(PassiveSystem, _super);
function PassiveSystem() {
return _super !== null && _super.apply(this, arguments) || this;
}
PassiveSystem.prototype.onChanged = function (entity) {
};
PassiveSystem.prototype.process = function (entities) {
this.begin();
this.end();
};
return PassiveSystem;
}(EntitySystem));
var ProcessingSystem = (function (_super) {
__extends(ProcessingSystem, _super);
function ProcessingSystem() {
return _super !== null && _super.apply(this, arguments) || this;
}
ProcessingSystem.prototype.onChanged = function (entity) {
};
ProcessingSystem.prototype.process = function (entities) {
this.begin();
this.processSystem();
this.end();
};
return ProcessingSystem;
}(EntitySystem));
var BitSet = (function () { var BitSet = (function () {
function BitSet(nbits) { function BitSet(nbits) {
if (nbits === void 0) { nbits = 64; } if (nbits === void 0) { nbits = 64; }
@@ -2765,6 +2792,15 @@ var Matcher = (function () {
Matcher.empty = function () { Matcher.empty = function () {
return new Matcher(); return new Matcher();
}; };
Matcher.prototype.getAllSet = function () {
return this.allSet;
};
Matcher.prototype.getExclusionSet = function () {
return this.exclusionSet;
};
Matcher.prototype.getOneSet = function () {
return this.oneSet;
};
Matcher.prototype.IsIntersted = function (e) { Matcher.prototype.IsIntersted = function (e) {
if (!this.allSet.isEmpty()) { if (!this.allSet.isEmpty()) {
for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) { for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
@@ -2778,6 +2814,39 @@ var Matcher = (function () {
return false; return false;
return true; return true;
}; };
Matcher.prototype.all = function () {
var _this = this;
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
types.forEach(function (type) {
_this.allSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
};
Matcher.prototype.exclude = function () {
var _this = this;
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
types.forEach(function (type) {
_this.exclusionSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
};
Matcher.prototype.one = function () {
var _this = this;
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
types.forEach(function (type) {
_this.oneSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
};
return Matcher; return Matcher;
}()); }());
var RenderableComponentList = (function () { var RenderableComponentList = (function () {

File diff suppressed because one or more lines are too long

View File

@@ -485,6 +485,15 @@ declare abstract class EntityProcessingSystem extends EntitySystem {
protected process(entities: Entity[]): void; protected process(entities: Entity[]): void;
protected lateProcess(entities: Entity[]): void; protected lateProcess(entities: Entity[]): void;
} }
declare abstract class PassiveSystem extends EntitySystem {
onChanged(entity: Entity): void;
protected process(entities: Entity[]): void;
}
declare abstract class ProcessingSystem extends EntitySystem {
onChanged(entity: Entity): void;
protected process(entities: Entity[]): void;
abstract processSystem(): any;
}
declare class BitSet { declare class BitSet {
private static LONG_MASK; private static LONG_MASK;
private _bits; private _bits;
@@ -568,7 +577,13 @@ declare class Matcher {
protected exclusionSet: BitSet; protected exclusionSet: BitSet;
protected oneSet: BitSet; protected oneSet: BitSet;
static empty(): Matcher; static empty(): Matcher;
getAllSet(): BitSet;
getExclusionSet(): BitSet;
getOneSet(): BitSet;
IsIntersted(e: Entity): boolean; IsIntersted(e: Entity): boolean;
all(...types: any[]): Matcher;
exclude(...types: any[]): this;
one(...types: any[]): this;
} }
declare class RenderableComponentList { declare class RenderableComponentList {
private _components; private _components;

View File

@@ -2294,6 +2294,33 @@ var EntityProcessingSystem = (function (_super) {
}; };
return EntityProcessingSystem; return EntityProcessingSystem;
}(EntitySystem)); }(EntitySystem));
var PassiveSystem = (function (_super) {
__extends(PassiveSystem, _super);
function PassiveSystem() {
return _super !== null && _super.apply(this, arguments) || this;
}
PassiveSystem.prototype.onChanged = function (entity) {
};
PassiveSystem.prototype.process = function (entities) {
this.begin();
this.end();
};
return PassiveSystem;
}(EntitySystem));
var ProcessingSystem = (function (_super) {
__extends(ProcessingSystem, _super);
function ProcessingSystem() {
return _super !== null && _super.apply(this, arguments) || this;
}
ProcessingSystem.prototype.onChanged = function (entity) {
};
ProcessingSystem.prototype.process = function (entities) {
this.begin();
this.processSystem();
this.end();
};
return ProcessingSystem;
}(EntitySystem));
var BitSet = (function () { var BitSet = (function () {
function BitSet(nbits) { function BitSet(nbits) {
if (nbits === void 0) { nbits = 64; } if (nbits === void 0) { nbits = 64; }
@@ -2765,6 +2792,15 @@ var Matcher = (function () {
Matcher.empty = function () { Matcher.empty = function () {
return new Matcher(); return new Matcher();
}; };
Matcher.prototype.getAllSet = function () {
return this.allSet;
};
Matcher.prototype.getExclusionSet = function () {
return this.exclusionSet;
};
Matcher.prototype.getOneSet = function () {
return this.oneSet;
};
Matcher.prototype.IsIntersted = function (e) { Matcher.prototype.IsIntersted = function (e) {
if (!this.allSet.isEmpty()) { if (!this.allSet.isEmpty()) {
for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) { for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) {
@@ -2778,6 +2814,39 @@ var Matcher = (function () {
return false; return false;
return true; return true;
}; };
Matcher.prototype.all = function () {
var _this = this;
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
types.forEach(function (type) {
_this.allSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
};
Matcher.prototype.exclude = function () {
var _this = this;
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
types.forEach(function (type) {
_this.exclusionSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
};
Matcher.prototype.one = function () {
var _this = this;
var types = [];
for (var _i = 0; _i < arguments.length; _i++) {
types[_i] = arguments[_i];
}
types.forEach(function (type) {
_this.oneSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
};
return Matcher; return Matcher;
}()); }());
var RenderableComponentList = (function () { var RenderableComponentList = (function () {

File diff suppressed because one or more lines are too long

View File

@@ -7,12 +7,21 @@ abstract class EntityProcessingSystem extends EntitySystem {
super(matcher); super(matcher);
} }
/**
* 处理特定的实体
* @param entity
*/
public abstract processEntity(entity: Entity); public abstract processEntity(entity: Entity);
public lateProcessEntity(entity: Entity) { public lateProcessEntity(entity: Entity) {
} }
/**
* 遍历这个系统的所有实体并逐个处理它们
* @param entities
*/
protected process(entities: Entity[]) { protected process(entities: Entity[]) {
entities.forEach(entity => this.processEntity(entity)); entities.forEach(entity => this.processEntity(entity));
} }

View File

@@ -0,0 +1,11 @@
abstract class PassiveSystem extends EntitySystem {
public onChanged(entity: Entity){
}
protected process(entities: Entity[]){
// 我们用我们自己的不考虑实体的基本实体系统来代替
this.begin();
this.end();
}
}

View File

@@ -0,0 +1,15 @@
/** 用于协调其他系统的通用系统基类 */
abstract class ProcessingSystem extends EntitySystem {
public onChanged(entity: Entity){
}
protected process(entities: Entity[]){
this.begin();
this.processSystem();
this.end();
}
/** 处理我们的系统 每帧调用 */
public abstract processSystem();
}

View File

@@ -7,6 +7,18 @@ class Matcher{
return new Matcher(); return new Matcher();
} }
public getAllSet(){
return this.allSet;
}
public getExclusionSet(){
return this.exclusionSet;
}
public getOneSet(){
return this.oneSet;
}
public IsIntersted(e: Entity){ public IsIntersted(e: Entity){
if (!this.allSet.isEmpty()){ if (!this.allSet.isEmpty()){
for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)){ for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)){
@@ -23,4 +35,28 @@ class Matcher{
return true; return true;
} }
public all(...types: any[]): Matcher{
types.forEach(type => {
this.allSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
}
public exclude(...types: any[]){
types.forEach(type => {
this.exclusionSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
}
public one(...types: any[]){
types.forEach(type => {
this.oneSet.set(ComponentTypeManager.getIndexFor(type));
});
return this;
}
} }