Files
esengine/source/src/ECS/Systems/IntervalSystem.ts

63 lines
2.0 KiB
TypeScript
Raw Normal View History

module es {
/**
* EntitySystem
* process
*/
export abstract class IntervalSystem extends EntitySystem {
/**
*
*/
private acc: number = 0;
/**
*
*/
private readonly interval: number;
/**
*
*/
private intervalRemainder: number = 0;
/**
*
* @param matcher
* @param interval
*/
constructor(matcher: Matcher, interval: number) {
super(matcher);
this.interval = interval;
}
/**
*
* true
* false
*/
protected checkProcessing(): boolean {
// 更新累积增量
this.acc += Time.deltaTime;
// 如果累积增量超过时间间隔,则进行处理
if (this.acc >= this.interval) {
// 更新时间间隔余数
this.intervalRemainder = this.acc - this.interval;
// 重置累积增量
this.acc = 0;
// 返回 true表示需要进行处理
return true;
}
// 返回 false表示不需要进行处理
return false;
}
/**
* delta
* delta
*/
protected getIntervalDelta(): number {
return this.interval + this.intervalRemainder;
}
}
}