新增DelayedIteratingSystem/IntervalSystem/IntervalIteratingSystem
This commit is contained in:
+134
-15
@@ -351,6 +351,11 @@ declare module es {
|
|||||||
* 每帧进行调用进行更新组件
|
* 每帧进行调用进行更新组件
|
||||||
*/
|
*/
|
||||||
update(): void;
|
update(): void;
|
||||||
|
/**
|
||||||
|
* 创建组件的新实例。返回实例组件
|
||||||
|
* @param componentType
|
||||||
|
*/
|
||||||
|
createComponent<T extends Component>(componentType: new () => T): T;
|
||||||
/**
|
/**
|
||||||
* 将组件添加到组件列表中。返回组件。
|
* 将组件添加到组件列表中。返回组件。
|
||||||
* @param component
|
* @param component
|
||||||
@@ -857,15 +862,6 @@ declare module es {
|
|||||||
toString(): string;
|
toString(): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
class ComponentPool<T extends PooledComponent> {
|
|
||||||
private _cache;
|
|
||||||
private _type;
|
|
||||||
constructor(typeClass: any);
|
|
||||||
obtain(): T;
|
|
||||||
free(component: T): void;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
/**
|
/**
|
||||||
* 接口,当添加到一个Component时,只要Component和实体被启用,它就会在每个框架中调用更新方法。
|
* 接口,当添加到一个Component时,只要Component和实体被启用,它就会在每个框架中调用更新方法。
|
||||||
@@ -883,12 +879,6 @@ declare module es {
|
|||||||
}
|
}
|
||||||
var isIUpdatable: (props: any) => props is IUpdatable;
|
var isIUpdatable: (props: any) => props is IUpdatable;
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
/** 回收实例的组件类型。 */
|
|
||||||
abstract class PooledComponent extends Component {
|
|
||||||
abstract reset(): any;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
class SceneComponent implements IComparer<SceneComponent> {
|
class SceneComponent implements IComparer<SceneComponent> {
|
||||||
/**
|
/**
|
||||||
@@ -1272,6 +1262,9 @@ declare module es {
|
|||||||
private _entities;
|
private _entities;
|
||||||
constructor(matcher?: Matcher);
|
constructor(matcher?: Matcher);
|
||||||
private _scene;
|
private _scene;
|
||||||
|
/**
|
||||||
|
* 这个系统所属的场景
|
||||||
|
*/
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
private _matcher;
|
private _matcher;
|
||||||
readonly matcher: Matcher;
|
readonly matcher: Matcher;
|
||||||
@@ -1283,10 +1276,96 @@ declare module es {
|
|||||||
onRemoved(entity: Entity): void;
|
onRemoved(entity: Entity): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
lateUpdate(): void;
|
lateUpdate(): void;
|
||||||
|
/**
|
||||||
|
* 在系统处理开始前调用
|
||||||
|
* 在下一个系统开始处理或新的处理回合开始之前(以先到者为准),使用此方法创建的任何实体都不会激活
|
||||||
|
*/
|
||||||
protected begin(): void;
|
protected begin(): void;
|
||||||
protected process(entities: Entity[]): void;
|
protected process(entities: Entity[]): void;
|
||||||
protected lateProcess(entities: Entity[]): void;
|
protected lateProcess(entities: Entity[]): void;
|
||||||
|
/**
|
||||||
|
* 系统处理完毕后调用
|
||||||
|
*/
|
||||||
protected end(): void;
|
protected end(): void;
|
||||||
|
/**
|
||||||
|
* 系统是否需要处理
|
||||||
|
*
|
||||||
|
* 在启用系统时有用,但仅偶尔需要处理
|
||||||
|
* 这只影响处理,不影响事件或订阅列表
|
||||||
|
* @returns 如果系统应该处理,则为true,如果不处理则为false。
|
||||||
|
*/
|
||||||
|
protected checkProcessing(): boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
/**
|
||||||
|
* 追踪每个实体的冷却时间,当实体的计时器耗尽时进行处理
|
||||||
|
*
|
||||||
|
* 一个示例系统将是ExpirationSystem,该系统将在特定生存期后删除实体。
|
||||||
|
* 你不必运行会为每个实体递减timeLeft值的系统
|
||||||
|
* 而只需使用此系统在寿命最短的实体时在将来执行
|
||||||
|
* 然后重置系统在未来的某一个最短命实体的时间运行
|
||||||
|
*
|
||||||
|
* 另一个例子是一个动画系统
|
||||||
|
* 你知道什么时候你必须对某个实体进行动画制作,比如300毫秒内。
|
||||||
|
* 所以你可以设置系统以300毫秒为单位运行来执行动画
|
||||||
|
*
|
||||||
|
* 这将在某些情况下节省CPU周期
|
||||||
|
*/
|
||||||
|
abstract class DelayedIteratingSystem extends EntitySystem {
|
||||||
|
/**
|
||||||
|
* 一个实体应被处理的时间
|
||||||
|
*/
|
||||||
|
private delay;
|
||||||
|
/**
|
||||||
|
* 如果系统正在运行,并倒计时延迟
|
||||||
|
*/
|
||||||
|
private running;
|
||||||
|
/**
|
||||||
|
* 倒计时
|
||||||
|
*/
|
||||||
|
private acc;
|
||||||
|
constructor(matcher: Matcher);
|
||||||
|
protected process(entities: Entity[]): void;
|
||||||
|
protected checkProcessing(): boolean;
|
||||||
|
/**
|
||||||
|
* 只有当提供的延迟比系统当前计划执行的时间短时,才会重新启动系统。
|
||||||
|
* 如果系统已经停止(不运行),那么提供的延迟将被用来重新启动系统,无论其值如何
|
||||||
|
* 如果系统已经在倒计时,并且提供的延迟大于剩余时间,系统将忽略它。
|
||||||
|
* 如果提供的延迟时间短于剩余时间,系统将重新启动,以提供的延迟时间运行。
|
||||||
|
* @param offeredDelay
|
||||||
|
*/
|
||||||
|
offerDelay(offeredDelay: number): void;
|
||||||
|
/**
|
||||||
|
* 处理本系统感兴趣的实体
|
||||||
|
* 从实体定义的延迟中抽象出accumulativeDelta
|
||||||
|
* @param entity
|
||||||
|
* @param accumulatedDelta 本系统最后一次执行后的delta时间
|
||||||
|
*/
|
||||||
|
protected abstract processDelta(entity: Entity, accumulatedDelta: number): any;
|
||||||
|
protected abstract processExpired(entity: Entity): any;
|
||||||
|
/**
|
||||||
|
* 返回该实体处理前的延迟时间
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
protected abstract getRemainingDelay(entity: Entity): number;
|
||||||
|
/**
|
||||||
|
* 获取系统被命令处理实体后的初始延迟
|
||||||
|
*/
|
||||||
|
getInitialTimeDelay(): number;
|
||||||
|
/**
|
||||||
|
* 获取系统计划运行前的时间
|
||||||
|
* 如果系统没有运行,则返回零
|
||||||
|
*/
|
||||||
|
getRemainingTimeUntilProcessing(): number;
|
||||||
|
/**
|
||||||
|
* 检查系统是否正在倒计时处理
|
||||||
|
*/
|
||||||
|
isRunning(): boolean;
|
||||||
|
/**
|
||||||
|
* 停止系统运行,中止当前倒计时
|
||||||
|
*/
|
||||||
|
stop(): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1312,6 +1391,46 @@ declare module es {
|
|||||||
protected lateProcess(entities: Entity[]): void;
|
protected lateProcess(entities: Entity[]): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
/**
|
||||||
|
* 实体系统以一定的时间间隔进行处理
|
||||||
|
*/
|
||||||
|
abstract class IntervalSystem extends EntitySystem {
|
||||||
|
/**
|
||||||
|
* 累积增量以跟踪间隔
|
||||||
|
*/
|
||||||
|
protected acc: number;
|
||||||
|
/**
|
||||||
|
* 更新之间需要等待多长时间
|
||||||
|
*/
|
||||||
|
private readonly interval;
|
||||||
|
private intervalDelta;
|
||||||
|
constructor(matcher: Matcher, interval: number);
|
||||||
|
protected checkProcessing(): boolean;
|
||||||
|
/**
|
||||||
|
* 获取本系统上次处理后的实际delta值
|
||||||
|
*/
|
||||||
|
protected getIntervalDelta(): number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
/**
|
||||||
|
* 每x个ticks处理一个实体的子集
|
||||||
|
*
|
||||||
|
* 典型的用法是每隔一定的时间间隔重新生成弹药或生命值
|
||||||
|
* 而无需在每个游戏循环中都进行
|
||||||
|
* 而是每100毫秒一次或每秒
|
||||||
|
*/
|
||||||
|
abstract class IntervalIteratingSystem extends IntervalSystem {
|
||||||
|
constructor(matcher: Matcher, interval: number);
|
||||||
|
/**
|
||||||
|
* 处理本系统感兴趣的实体
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
abstract processEntity(entity: Entity): any;
|
||||||
|
protected process(entities: Entity[]): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
abstract class PassiveSystem extends EntitySystem {
|
abstract class PassiveSystem extends EntitySystem {
|
||||||
onChanged(entity: Entity): void;
|
onChanged(entity: Entity): void;
|
||||||
|
|||||||
+1
-1
Submodule extensions/ecs-tween updated: 1613c1d2a8...2154498b2f
Vendored
+134
-15
@@ -351,6 +351,11 @@ declare module es {
|
|||||||
* 每帧进行调用进行更新组件
|
* 每帧进行调用进行更新组件
|
||||||
*/
|
*/
|
||||||
update(): void;
|
update(): void;
|
||||||
|
/**
|
||||||
|
* 创建组件的新实例。返回实例组件
|
||||||
|
* @param componentType
|
||||||
|
*/
|
||||||
|
createComponent<T extends Component>(componentType: new () => T): T;
|
||||||
/**
|
/**
|
||||||
* 将组件添加到组件列表中。返回组件。
|
* 将组件添加到组件列表中。返回组件。
|
||||||
* @param component
|
* @param component
|
||||||
@@ -857,15 +862,6 @@ declare module es {
|
|||||||
toString(): string;
|
toString(): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
class ComponentPool<T extends PooledComponent> {
|
|
||||||
private _cache;
|
|
||||||
private _type;
|
|
||||||
constructor(typeClass: any);
|
|
||||||
obtain(): T;
|
|
||||||
free(component: T): void;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
/**
|
/**
|
||||||
* 接口,当添加到一个Component时,只要Component和实体被启用,它就会在每个框架中调用更新方法。
|
* 接口,当添加到一个Component时,只要Component和实体被启用,它就会在每个框架中调用更新方法。
|
||||||
@@ -883,12 +879,6 @@ declare module es {
|
|||||||
}
|
}
|
||||||
var isIUpdatable: (props: any) => props is IUpdatable;
|
var isIUpdatable: (props: any) => props is IUpdatable;
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
/** 回收实例的组件类型。 */
|
|
||||||
abstract class PooledComponent extends Component {
|
|
||||||
abstract reset(): any;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
class SceneComponent implements IComparer<SceneComponent> {
|
class SceneComponent implements IComparer<SceneComponent> {
|
||||||
/**
|
/**
|
||||||
@@ -1272,6 +1262,9 @@ declare module es {
|
|||||||
private _entities;
|
private _entities;
|
||||||
constructor(matcher?: Matcher);
|
constructor(matcher?: Matcher);
|
||||||
private _scene;
|
private _scene;
|
||||||
|
/**
|
||||||
|
* 这个系统所属的场景
|
||||||
|
*/
|
||||||
scene: Scene;
|
scene: Scene;
|
||||||
private _matcher;
|
private _matcher;
|
||||||
readonly matcher: Matcher;
|
readonly matcher: Matcher;
|
||||||
@@ -1283,10 +1276,96 @@ declare module es {
|
|||||||
onRemoved(entity: Entity): void;
|
onRemoved(entity: Entity): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
lateUpdate(): void;
|
lateUpdate(): void;
|
||||||
|
/**
|
||||||
|
* 在系统处理开始前调用
|
||||||
|
* 在下一个系统开始处理或新的处理回合开始之前(以先到者为准),使用此方法创建的任何实体都不会激活
|
||||||
|
*/
|
||||||
protected begin(): void;
|
protected begin(): void;
|
||||||
protected process(entities: Entity[]): void;
|
protected process(entities: Entity[]): void;
|
||||||
protected lateProcess(entities: Entity[]): void;
|
protected lateProcess(entities: Entity[]): void;
|
||||||
|
/**
|
||||||
|
* 系统处理完毕后调用
|
||||||
|
*/
|
||||||
protected end(): void;
|
protected end(): void;
|
||||||
|
/**
|
||||||
|
* 系统是否需要处理
|
||||||
|
*
|
||||||
|
* 在启用系统时有用,但仅偶尔需要处理
|
||||||
|
* 这只影响处理,不影响事件或订阅列表
|
||||||
|
* @returns 如果系统应该处理,则为true,如果不处理则为false。
|
||||||
|
*/
|
||||||
|
protected checkProcessing(): boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
/**
|
||||||
|
* 追踪每个实体的冷却时间,当实体的计时器耗尽时进行处理
|
||||||
|
*
|
||||||
|
* 一个示例系统将是ExpirationSystem,该系统将在特定生存期后删除实体。
|
||||||
|
* 你不必运行会为每个实体递减timeLeft值的系统
|
||||||
|
* 而只需使用此系统在寿命最短的实体时在将来执行
|
||||||
|
* 然后重置系统在未来的某一个最短命实体的时间运行
|
||||||
|
*
|
||||||
|
* 另一个例子是一个动画系统
|
||||||
|
* 你知道什么时候你必须对某个实体进行动画制作,比如300毫秒内。
|
||||||
|
* 所以你可以设置系统以300毫秒为单位运行来执行动画
|
||||||
|
*
|
||||||
|
* 这将在某些情况下节省CPU周期
|
||||||
|
*/
|
||||||
|
abstract class DelayedIteratingSystem extends EntitySystem {
|
||||||
|
/**
|
||||||
|
* 一个实体应被处理的时间
|
||||||
|
*/
|
||||||
|
private delay;
|
||||||
|
/**
|
||||||
|
* 如果系统正在运行,并倒计时延迟
|
||||||
|
*/
|
||||||
|
private running;
|
||||||
|
/**
|
||||||
|
* 倒计时
|
||||||
|
*/
|
||||||
|
private acc;
|
||||||
|
constructor(matcher: Matcher);
|
||||||
|
protected process(entities: Entity[]): void;
|
||||||
|
protected checkProcessing(): boolean;
|
||||||
|
/**
|
||||||
|
* 只有当提供的延迟比系统当前计划执行的时间短时,才会重新启动系统。
|
||||||
|
* 如果系统已经停止(不运行),那么提供的延迟将被用来重新启动系统,无论其值如何
|
||||||
|
* 如果系统已经在倒计时,并且提供的延迟大于剩余时间,系统将忽略它。
|
||||||
|
* 如果提供的延迟时间短于剩余时间,系统将重新启动,以提供的延迟时间运行。
|
||||||
|
* @param offeredDelay
|
||||||
|
*/
|
||||||
|
offerDelay(offeredDelay: number): void;
|
||||||
|
/**
|
||||||
|
* 处理本系统感兴趣的实体
|
||||||
|
* 从实体定义的延迟中抽象出accumulativeDelta
|
||||||
|
* @param entity
|
||||||
|
* @param accumulatedDelta 本系统最后一次执行后的delta时间
|
||||||
|
*/
|
||||||
|
protected abstract processDelta(entity: Entity, accumulatedDelta: number): any;
|
||||||
|
protected abstract processExpired(entity: Entity): any;
|
||||||
|
/**
|
||||||
|
* 返回该实体处理前的延迟时间
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
protected abstract getRemainingDelay(entity: Entity): number;
|
||||||
|
/**
|
||||||
|
* 获取系统被命令处理实体后的初始延迟
|
||||||
|
*/
|
||||||
|
getInitialTimeDelay(): number;
|
||||||
|
/**
|
||||||
|
* 获取系统计划运行前的时间
|
||||||
|
* 如果系统没有运行,则返回零
|
||||||
|
*/
|
||||||
|
getRemainingTimeUntilProcessing(): number;
|
||||||
|
/**
|
||||||
|
* 检查系统是否正在倒计时处理
|
||||||
|
*/
|
||||||
|
isRunning(): boolean;
|
||||||
|
/**
|
||||||
|
* 停止系统运行,中止当前倒计时
|
||||||
|
*/
|
||||||
|
stop(): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1312,6 +1391,46 @@ declare module es {
|
|||||||
protected lateProcess(entities: Entity[]): void;
|
protected lateProcess(entities: Entity[]): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
/**
|
||||||
|
* 实体系统以一定的时间间隔进行处理
|
||||||
|
*/
|
||||||
|
abstract class IntervalSystem extends EntitySystem {
|
||||||
|
/**
|
||||||
|
* 累积增量以跟踪间隔
|
||||||
|
*/
|
||||||
|
protected acc: number;
|
||||||
|
/**
|
||||||
|
* 更新之间需要等待多长时间
|
||||||
|
*/
|
||||||
|
private readonly interval;
|
||||||
|
private intervalDelta;
|
||||||
|
constructor(matcher: Matcher, interval: number);
|
||||||
|
protected checkProcessing(): boolean;
|
||||||
|
/**
|
||||||
|
* 获取本系统上次处理后的实际delta值
|
||||||
|
*/
|
||||||
|
protected getIntervalDelta(): number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
/**
|
||||||
|
* 每x个ticks处理一个实体的子集
|
||||||
|
*
|
||||||
|
* 典型的用法是每隔一定的时间间隔重新生成弹药或生命值
|
||||||
|
* 而无需在每个游戏循环中都进行
|
||||||
|
* 而是每100毫秒一次或每秒
|
||||||
|
*/
|
||||||
|
abstract class IntervalIteratingSystem extends IntervalSystem {
|
||||||
|
constructor(matcher: Matcher, interval: number);
|
||||||
|
/**
|
||||||
|
* 处理本系统感兴趣的实体
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
abstract processEntity(entity: Entity): any;
|
||||||
|
protected process(entities: Entity[]): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
abstract class PassiveSystem extends EntitySystem {
|
abstract class PassiveSystem extends EntitySystem {
|
||||||
onChanged(entity: Entity): void;
|
onChanged(entity: Entity): void;
|
||||||
|
|||||||
+214
-46
@@ -928,6 +928,15 @@ var es;
|
|||||||
Entity.prototype.update = function () {
|
Entity.prototype.update = function () {
|
||||||
this.components.update();
|
this.components.update();
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* 创建组件的新实例。返回实例组件
|
||||||
|
* @param componentType
|
||||||
|
*/
|
||||||
|
Entity.prototype.createComponent = function (componentType) {
|
||||||
|
var component = new componentType();
|
||||||
|
this.addComponent(component);
|
||||||
|
return component;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* 将组件添加到组件列表中。返回组件。
|
* 将组件添加到组件列表中。返回组件。
|
||||||
* @param component
|
* @param component
|
||||||
@@ -1953,29 +1962,6 @@ var es;
|
|||||||
es.Transform = Transform;
|
es.Transform = Transform;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
|
||||||
var ComponentPool = /** @class */ (function () {
|
|
||||||
function ComponentPool(typeClass) {
|
|
||||||
this._type = typeClass;
|
|
||||||
this._cache = [];
|
|
||||||
}
|
|
||||||
ComponentPool.prototype.obtain = function () {
|
|
||||||
try {
|
|
||||||
return this._cache.length > 0 ? this._cache.shift() : new this._type();
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
throw new Error(this._type + err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ComponentPool.prototype.free = function (component) {
|
|
||||||
component.reset();
|
|
||||||
this._cache.push(component);
|
|
||||||
};
|
|
||||||
return ComponentPool;
|
|
||||||
}());
|
|
||||||
es.ComponentPool = ComponentPool;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
(function (es) {
|
||||||
/**
|
/**
|
||||||
* 用于比较组件更新排序
|
* 用于比较组件更新排序
|
||||||
@@ -1992,18 +1978,6 @@ var es;
|
|||||||
es.isIUpdatable = function (props) { return typeof props['update'] !== 'undefined'; };
|
es.isIUpdatable = function (props) { return typeof props['update'] !== 'undefined'; };
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
|
||||||
/** 回收实例的组件类型。 */
|
|
||||||
var PooledComponent = /** @class */ (function (_super) {
|
|
||||||
__extends(PooledComponent, _super);
|
|
||||||
function PooledComponent() {
|
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
|
||||||
}
|
|
||||||
return PooledComponent;
|
|
||||||
}(es.Component));
|
|
||||||
es.PooledComponent = PooledComponent;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var SceneComponent = /** @class */ (function () {
|
var SceneComponent = /** @class */ (function () {
|
||||||
function SceneComponent() {
|
function SceneComponent() {
|
||||||
@@ -2913,6 +2887,9 @@ var es;
|
|||||||
this._matcher = matcher ? matcher : es.Matcher.empty();
|
this._matcher = matcher ? matcher : es.Matcher.empty();
|
||||||
}
|
}
|
||||||
Object.defineProperty(EntitySystem.prototype, "scene", {
|
Object.defineProperty(EntitySystem.prototype, "scene", {
|
||||||
|
/**
|
||||||
|
* 这个系统所属的场景
|
||||||
|
*/
|
||||||
get: function () {
|
get: function () {
|
||||||
return this._scene;
|
return this._scene;
|
||||||
},
|
},
|
||||||
@@ -2944,29 +2921,44 @@ var es;
|
|||||||
this._entities.push(entity);
|
this._entities.push(entity);
|
||||||
this.onAdded(entity);
|
this.onAdded(entity);
|
||||||
};
|
};
|
||||||
EntitySystem.prototype.onAdded = function (entity) {
|
EntitySystem.prototype.onAdded = function (entity) { };
|
||||||
};
|
|
||||||
EntitySystem.prototype.remove = function (entity) {
|
EntitySystem.prototype.remove = function (entity) {
|
||||||
new linq.List(this._entities).remove(entity);
|
new linq.List(this._entities).remove(entity);
|
||||||
this.onRemoved(entity);
|
this.onRemoved(entity);
|
||||||
};
|
};
|
||||||
EntitySystem.prototype.onRemoved = function (entity) {
|
EntitySystem.prototype.onRemoved = function (entity) { };
|
||||||
};
|
|
||||||
EntitySystem.prototype.update = function () {
|
EntitySystem.prototype.update = function () {
|
||||||
|
if (this.checkProcessing()) {
|
||||||
this.begin();
|
this.begin();
|
||||||
this.process(this._entities);
|
this.process(this._entities);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
EntitySystem.prototype.lateUpdate = function () {
|
EntitySystem.prototype.lateUpdate = function () {
|
||||||
|
if (this.checkProcessing()) {
|
||||||
this.lateProcess(this._entities);
|
this.lateProcess(this._entities);
|
||||||
this.end();
|
this.end();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
EntitySystem.prototype.begin = function () {
|
/**
|
||||||
};
|
* 在系统处理开始前调用
|
||||||
EntitySystem.prototype.process = function (entities) {
|
* 在下一个系统开始处理或新的处理回合开始之前(以先到者为准),使用此方法创建的任何实体都不会激活
|
||||||
};
|
*/
|
||||||
EntitySystem.prototype.lateProcess = function (entities) {
|
EntitySystem.prototype.begin = function () { };
|
||||||
};
|
EntitySystem.prototype.process = function (entities) { };
|
||||||
EntitySystem.prototype.end = function () {
|
EntitySystem.prototype.lateProcess = function (entities) { };
|
||||||
|
/**
|
||||||
|
* 系统处理完毕后调用
|
||||||
|
*/
|
||||||
|
EntitySystem.prototype.end = function () { };
|
||||||
|
/**
|
||||||
|
* 系统是否需要处理
|
||||||
|
*
|
||||||
|
* 在启用系统时有用,但仅偶尔需要处理
|
||||||
|
* 这只影响处理,不影响事件或订阅列表
|
||||||
|
* @returns 如果系统应该处理,则为true,如果不处理则为false。
|
||||||
|
*/
|
||||||
|
EntitySystem.prototype.checkProcessing = function () {
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
return EntitySystem;
|
return EntitySystem;
|
||||||
}());
|
}());
|
||||||
@@ -2975,6 +2967,118 @@ var es;
|
|||||||
///<reference path="./EntitySystem.ts"/>
|
///<reference path="./EntitySystem.ts"/>
|
||||||
var es;
|
var es;
|
||||||
///<reference path="./EntitySystem.ts"/>
|
///<reference path="./EntitySystem.ts"/>
|
||||||
|
(function (es) {
|
||||||
|
/**
|
||||||
|
* 追踪每个实体的冷却时间,当实体的计时器耗尽时进行处理
|
||||||
|
*
|
||||||
|
* 一个示例系统将是ExpirationSystem,该系统将在特定生存期后删除实体。
|
||||||
|
* 你不必运行会为每个实体递减timeLeft值的系统
|
||||||
|
* 而只需使用此系统在寿命最短的实体时在将来执行
|
||||||
|
* 然后重置系统在未来的某一个最短命实体的时间运行
|
||||||
|
*
|
||||||
|
* 另一个例子是一个动画系统
|
||||||
|
* 你知道什么时候你必须对某个实体进行动画制作,比如300毫秒内。
|
||||||
|
* 所以你可以设置系统以300毫秒为单位运行来执行动画
|
||||||
|
*
|
||||||
|
* 这将在某些情况下节省CPU周期
|
||||||
|
*/
|
||||||
|
var DelayedIteratingSystem = /** @class */ (function (_super) {
|
||||||
|
__extends(DelayedIteratingSystem, _super);
|
||||||
|
function DelayedIteratingSystem(matcher) {
|
||||||
|
var _this = _super.call(this, matcher) || this;
|
||||||
|
/**
|
||||||
|
* 一个实体应被处理的时间
|
||||||
|
*/
|
||||||
|
_this.delay = 0;
|
||||||
|
/**
|
||||||
|
* 如果系统正在运行,并倒计时延迟
|
||||||
|
*/
|
||||||
|
_this.running = false;
|
||||||
|
/**
|
||||||
|
* 倒计时
|
||||||
|
*/
|
||||||
|
_this.acc = 0;
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
DelayedIteratingSystem.prototype.process = function (entities) {
|
||||||
|
var processed = entities.length;
|
||||||
|
if (processed == 0) {
|
||||||
|
this.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.delay = Number.MAX_VALUE;
|
||||||
|
for (var i = 0; processed > i; i++) {
|
||||||
|
var e = entities[i];
|
||||||
|
this.processDelta(e, this.acc);
|
||||||
|
var remaining = this.getRemainingDelay(e);
|
||||||
|
if (remaining <= 0) {
|
||||||
|
this.processExpired(e);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.offerDelay(remaining);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.acc = 0;
|
||||||
|
};
|
||||||
|
DelayedIteratingSystem.prototype.checkProcessing = function () {
|
||||||
|
if (this.running) {
|
||||||
|
this.acc += es.Time.deltaTime;
|
||||||
|
return this.acc >= this.delay;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 只有当提供的延迟比系统当前计划执行的时间短时,才会重新启动系统。
|
||||||
|
* 如果系统已经停止(不运行),那么提供的延迟将被用来重新启动系统,无论其值如何
|
||||||
|
* 如果系统已经在倒计时,并且提供的延迟大于剩余时间,系统将忽略它。
|
||||||
|
* 如果提供的延迟时间短于剩余时间,系统将重新启动,以提供的延迟时间运行。
|
||||||
|
* @param offeredDelay
|
||||||
|
*/
|
||||||
|
DelayedIteratingSystem.prototype.offerDelay = function (offeredDelay) {
|
||||||
|
if (!this.running) {
|
||||||
|
this.running = true;
|
||||||
|
this.delay = offeredDelay;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.delay = Math.min(this.delay, offeredDelay);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 获取系统被命令处理实体后的初始延迟
|
||||||
|
*/
|
||||||
|
DelayedIteratingSystem.prototype.getInitialTimeDelay = function () {
|
||||||
|
return this.delay;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 获取系统计划运行前的时间
|
||||||
|
* 如果系统没有运行,则返回零
|
||||||
|
*/
|
||||||
|
DelayedIteratingSystem.prototype.getRemainingTimeUntilProcessing = function () {
|
||||||
|
if (this.running) {
|
||||||
|
return this.delay - this.acc;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 检查系统是否正在倒计时处理
|
||||||
|
*/
|
||||||
|
DelayedIteratingSystem.prototype.isRunning = function () {
|
||||||
|
return this.running;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 停止系统运行,中止当前倒计时
|
||||||
|
*/
|
||||||
|
DelayedIteratingSystem.prototype.stop = function () {
|
||||||
|
this.running = false;
|
||||||
|
this.acc = 0;
|
||||||
|
};
|
||||||
|
return DelayedIteratingSystem;
|
||||||
|
}(es.EntitySystem));
|
||||||
|
es.DelayedIteratingSystem = DelayedIteratingSystem;
|
||||||
|
})(es || (es = {}));
|
||||||
|
///<reference path="./EntitySystem.ts" />
|
||||||
|
var es;
|
||||||
|
///<reference path="./EntitySystem.ts" />
|
||||||
(function (es) {
|
(function (es) {
|
||||||
/**
|
/**
|
||||||
* 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础
|
* 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础
|
||||||
@@ -3006,6 +3110,70 @@ var es;
|
|||||||
es.EntityProcessingSystem = EntityProcessingSystem;
|
es.EntityProcessingSystem = EntityProcessingSystem;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
/**
|
||||||
|
* 实体系统以一定的时间间隔进行处理
|
||||||
|
*/
|
||||||
|
var IntervalSystem = /** @class */ (function (_super) {
|
||||||
|
__extends(IntervalSystem, _super);
|
||||||
|
function IntervalSystem(matcher, interval) {
|
||||||
|
var _this = _super.call(this, matcher) || this;
|
||||||
|
/**
|
||||||
|
* 累积增量以跟踪间隔
|
||||||
|
*/
|
||||||
|
_this.acc = 0;
|
||||||
|
/**
|
||||||
|
* 更新之间需要等待多长时间
|
||||||
|
*/
|
||||||
|
_this.interval = 0;
|
||||||
|
_this.intervalDelta = 0;
|
||||||
|
_this.interval = interval;
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
IntervalSystem.prototype.checkProcessing = function () {
|
||||||
|
this.acc += es.Time.deltaTime;
|
||||||
|
if (this.acc >= this.interval) {
|
||||||
|
this.acc -= this.interval;
|
||||||
|
this.intervalDelta = (this.acc - this.intervalDelta);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 获取本系统上次处理后的实际delta值
|
||||||
|
*/
|
||||||
|
IntervalSystem.prototype.getIntervalDelta = function () {
|
||||||
|
return this.interval + this.intervalDelta;
|
||||||
|
};
|
||||||
|
return IntervalSystem;
|
||||||
|
}(es.EntitySystem));
|
||||||
|
es.IntervalSystem = IntervalSystem;
|
||||||
|
})(es || (es = {}));
|
||||||
|
///<reference path="./IntervalSystem.ts"/>
|
||||||
|
var es;
|
||||||
|
///<reference path="./IntervalSystem.ts"/>
|
||||||
|
(function (es) {
|
||||||
|
/**
|
||||||
|
* 每x个ticks处理一个实体的子集
|
||||||
|
*
|
||||||
|
* 典型的用法是每隔一定的时间间隔重新生成弹药或生命值
|
||||||
|
* 而无需在每个游戏循环中都进行
|
||||||
|
* 而是每100毫秒一次或每秒
|
||||||
|
*/
|
||||||
|
var IntervalIteratingSystem = /** @class */ (function (_super) {
|
||||||
|
__extends(IntervalIteratingSystem, _super);
|
||||||
|
function IntervalIteratingSystem(matcher, interval) {
|
||||||
|
return _super.call(this, matcher, interval) || this;
|
||||||
|
}
|
||||||
|
IntervalIteratingSystem.prototype.process = function (entities) {
|
||||||
|
var _this = this;
|
||||||
|
entities.forEach(function (entity) { return _this.processEntity(entity); });
|
||||||
|
};
|
||||||
|
return IntervalIteratingSystem;
|
||||||
|
}(es.IntervalSystem));
|
||||||
|
es.IntervalIteratingSystem = IntervalIteratingSystem;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var PassiveSystem = /** @class */ (function (_super) {
|
var PassiveSystem = /** @class */ (function (_super) {
|
||||||
__extends(PassiveSystem, _super);
|
__extends(PassiveSystem, _super);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,24 +0,0 @@
|
|||||||
module es {
|
|
||||||
export class ComponentPool<T extends PooledComponent> {
|
|
||||||
private _cache: T[];
|
|
||||||
private _type: any;
|
|
||||||
|
|
||||||
constructor(typeClass: any) {
|
|
||||||
this._type = typeClass;
|
|
||||||
this._cache = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public obtain(): T {
|
|
||||||
try {
|
|
||||||
return this._cache.length > 0 ? this._cache.shift() : new this._type();
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(this._type + err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public free(component: T) {
|
|
||||||
component.reset();
|
|
||||||
this._cache.push(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
module es {
|
|
||||||
/** 回收实例的组件类型。 */
|
|
||||||
export abstract class PooledComponent extends Component {
|
|
||||||
public abstract reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -380,6 +380,16 @@ module es {
|
|||||||
this.components.update();
|
this.components.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建组件的新实例。返回实例组件
|
||||||
|
* @param componentType
|
||||||
|
*/
|
||||||
|
public createComponent<T extends Component>(componentType: new () => T): T {
|
||||||
|
let component = new componentType();
|
||||||
|
this.addComponent(component);
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将组件添加到组件列表中。返回组件。
|
* 将组件添加到组件列表中。返回组件。
|
||||||
* @param component
|
* @param component
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
///<reference path="./EntitySystem.ts"/>
|
||||||
|
module es {
|
||||||
|
/**
|
||||||
|
* 追踪每个实体的冷却时间,当实体的计时器耗尽时进行处理
|
||||||
|
*
|
||||||
|
* 一个示例系统将是ExpirationSystem,该系统将在特定生存期后删除实体。
|
||||||
|
* 你不必运行会为每个实体递减timeLeft值的系统
|
||||||
|
* 而只需使用此系统在寿命最短的实体时在将来执行
|
||||||
|
* 然后重置系统在未来的某一个最短命实体的时间运行
|
||||||
|
*
|
||||||
|
* 另一个例子是一个动画系统
|
||||||
|
* 你知道什么时候你必须对某个实体进行动画制作,比如300毫秒内。
|
||||||
|
* 所以你可以设置系统以300毫秒为单位运行来执行动画
|
||||||
|
*
|
||||||
|
* 这将在某些情况下节省CPU周期
|
||||||
|
*/
|
||||||
|
export abstract class DelayedIteratingSystem extends EntitySystem {
|
||||||
|
/**
|
||||||
|
* 一个实体应被处理的时间
|
||||||
|
*/
|
||||||
|
private delay: number = 0;
|
||||||
|
/**
|
||||||
|
* 如果系统正在运行,并倒计时延迟
|
||||||
|
*/
|
||||||
|
private running: boolean = false;
|
||||||
|
/**
|
||||||
|
* 倒计时
|
||||||
|
*/
|
||||||
|
private acc: number = 0;
|
||||||
|
|
||||||
|
constructor(matcher: Matcher) {
|
||||||
|
super(matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected process(entities: Entity[]) {
|
||||||
|
let processed = entities.length;
|
||||||
|
if (processed == 0) {
|
||||||
|
this.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.delay = Number.MAX_VALUE;
|
||||||
|
for (let i = 0; processed > i; i++) {
|
||||||
|
let e = entities[i];
|
||||||
|
this.processDelta(e, this.acc);
|
||||||
|
let remaining = this.getRemainingDelay(e);
|
||||||
|
if (remaining <= 0) {
|
||||||
|
this.processExpired(e);
|
||||||
|
} else {
|
||||||
|
this.offerDelay(remaining);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.acc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected checkProcessing() {
|
||||||
|
if (this.running) {
|
||||||
|
this.acc += Time.deltaTime;
|
||||||
|
return this.acc >= this.delay;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只有当提供的延迟比系统当前计划执行的时间短时,才会重新启动系统。
|
||||||
|
* 如果系统已经停止(不运行),那么提供的延迟将被用来重新启动系统,无论其值如何
|
||||||
|
* 如果系统已经在倒计时,并且提供的延迟大于剩余时间,系统将忽略它。
|
||||||
|
* 如果提供的延迟时间短于剩余时间,系统将重新启动,以提供的延迟时间运行。
|
||||||
|
* @param offeredDelay
|
||||||
|
*/
|
||||||
|
public offerDelay(offeredDelay: number) {
|
||||||
|
if (!this.running) {
|
||||||
|
this.running = true;
|
||||||
|
this.delay = offeredDelay;
|
||||||
|
} else {
|
||||||
|
this.delay = Math.min(this.delay, offeredDelay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理本系统感兴趣的实体
|
||||||
|
* 从实体定义的延迟中抽象出accumulativeDelta
|
||||||
|
* @param entity
|
||||||
|
* @param accumulatedDelta 本系统最后一次执行后的delta时间
|
||||||
|
*/
|
||||||
|
protected abstract processDelta(entity: Entity, accumulatedDelta: number);
|
||||||
|
|
||||||
|
protected abstract processExpired(entity: Entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回该实体处理前的延迟时间
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
protected abstract getRemainingDelay(entity: Entity): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统被命令处理实体后的初始延迟
|
||||||
|
*/
|
||||||
|
public getInitialTimeDelay() {
|
||||||
|
return this.delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统计划运行前的时间
|
||||||
|
* 如果系统没有运行,则返回零
|
||||||
|
*/
|
||||||
|
public getRemainingTimeUntilProcessing(): number {
|
||||||
|
if (this.running) {
|
||||||
|
return this.delay - this.acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查系统是否正在倒计时处理
|
||||||
|
*/
|
||||||
|
public isRunning(): boolean {
|
||||||
|
return this.running;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止系统运行,中止当前倒计时
|
||||||
|
*/
|
||||||
|
public stop() {
|
||||||
|
this.running = false;
|
||||||
|
this.acc = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,9 @@ module es {
|
|||||||
|
|
||||||
private _scene: Scene;
|
private _scene: Scene;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个系统所属的场景
|
||||||
|
*/
|
||||||
public get scene() {
|
public get scene() {
|
||||||
return this._scene;
|
return this._scene;
|
||||||
}
|
}
|
||||||
@@ -45,42 +48,53 @@ module es {
|
|||||||
this.onAdded(entity);
|
this.onAdded(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public onAdded(entity: Entity) {
|
public onAdded(entity: Entity) { }
|
||||||
}
|
|
||||||
|
|
||||||
public remove(entity: Entity) {
|
public remove(entity: Entity) {
|
||||||
new linq.List(this._entities).remove(entity);
|
new linq.List(this._entities).remove(entity);
|
||||||
this.onRemoved(entity);
|
this.onRemoved(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public onRemoved(entity: Entity) {
|
public onRemoved(entity: Entity) { }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public update() {
|
public update() {
|
||||||
|
if (this.checkProcessing()) {
|
||||||
this.begin();
|
this.begin();
|
||||||
this.process(this._entities);
|
this.process(this._entities);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public lateUpdate() {
|
public lateUpdate() {
|
||||||
|
if (this.checkProcessing()) {
|
||||||
this.lateProcess(this._entities);
|
this.lateProcess(this._entities);
|
||||||
this.end();
|
this.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected begin() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected process(entities: Entity[]) {
|
/**
|
||||||
|
* 在系统处理开始前调用
|
||||||
|
* 在下一个系统开始处理或新的处理回合开始之前(以先到者为准),使用此方法创建的任何实体都不会激活
|
||||||
|
*/
|
||||||
|
protected begin() { }
|
||||||
|
|
||||||
}
|
protected process(entities: Entity[]) { }
|
||||||
|
|
||||||
protected lateProcess(entities: Entity[]) {
|
protected lateProcess(entities: Entity[]) { }
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* 系统处理完毕后调用
|
||||||
protected end() {
|
*/
|
||||||
|
protected end() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统是否需要处理
|
||||||
|
*
|
||||||
|
* 在启用系统时有用,但仅偶尔需要处理
|
||||||
|
* 这只影响处理,不影响事件或订阅列表
|
||||||
|
* @returns 如果系统应该处理,则为true,如果不处理则为false。
|
||||||
|
*/
|
||||||
|
protected checkProcessing() {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
///<reference path="./IntervalSystem.ts"/>
|
||||||
|
module es {
|
||||||
|
/**
|
||||||
|
* 每x个ticks处理一个实体的子集
|
||||||
|
*
|
||||||
|
* 典型的用法是每隔一定的时间间隔重新生成弹药或生命值
|
||||||
|
* 而无需在每个游戏循环中都进行
|
||||||
|
* 而是每100毫秒一次或每秒
|
||||||
|
*/
|
||||||
|
export abstract class IntervalIteratingSystem extends IntervalSystem {
|
||||||
|
constructor(matcher: Matcher, interval: number) {
|
||||||
|
super(matcher, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理本系统感兴趣的实体
|
||||||
|
* @param entity
|
||||||
|
*/
|
||||||
|
public abstract processEntity(entity: Entity);
|
||||||
|
|
||||||
|
protected process(entities: Entity[]) {
|
||||||
|
entities.forEach(entity => this.processEntity(entity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
module es {
|
||||||
|
/**
|
||||||
|
* 实体系统以一定的时间间隔进行处理
|
||||||
|
*/
|
||||||
|
export abstract class IntervalSystem extends EntitySystem {
|
||||||
|
/**
|
||||||
|
* 累积增量以跟踪间隔
|
||||||
|
*/
|
||||||
|
protected acc: number = 0;
|
||||||
|
/**
|
||||||
|
* 更新之间需要等待多长时间
|
||||||
|
*/
|
||||||
|
private readonly interval: number = 0;
|
||||||
|
private intervalDelta: number = 0;
|
||||||
|
|
||||||
|
constructor(matcher: Matcher, interval: number) {
|
||||||
|
super(matcher);
|
||||||
|
this.interval = interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected checkProcessing() {
|
||||||
|
this.acc += Time.deltaTime;
|
||||||
|
if (this.acc >= this.interval) {
|
||||||
|
this.acc -= this.interval;
|
||||||
|
this.intervalDelta = (this.acc - this.intervalDelta);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取本系统上次处理后的实际delta值
|
||||||
|
*/
|
||||||
|
protected getIntervalDelta() {
|
||||||
|
return this.interval + this.intervalDelta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user