新增系统时序控制
This commit is contained in:
@@ -276,6 +276,9 @@ module es {
|
||||
public addEntityProcessor(processor: EntitySystem) {
|
||||
processor.scene = this;
|
||||
this.entityProcessors.add(processor);
|
||||
|
||||
processor.setUpdateOrder(this.entityProcessors.count - 1);
|
||||
this.entityProcessors.clearDirty();
|
||||
return processor;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,26 @@ module es {
|
||||
*/
|
||||
export abstract class EntitySystem {
|
||||
private _entities: Entity[] = [];
|
||||
private _updateOrder: number = 0;
|
||||
private _startTime = 0;
|
||||
private _endTime = 0;
|
||||
private _useTime = 0;
|
||||
|
||||
/** 获取系统在当前帧所消耗的时间 仅在debug模式下生效 */
|
||||
public get useTime() {
|
||||
return this._useTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统的更新时序
|
||||
*/
|
||||
public get updateOrder() {
|
||||
return this._updateOrder;
|
||||
}
|
||||
|
||||
public set updateOrder(value: number) {
|
||||
this.setUpdateOrder(value);
|
||||
}
|
||||
|
||||
constructor(matcher?: Matcher) {
|
||||
this._matcher = matcher ? matcher : Matcher.empty();
|
||||
@@ -31,12 +51,13 @@ module es {
|
||||
return this._matcher;
|
||||
}
|
||||
|
||||
private _startTime = 0;
|
||||
private _endTime = 0;
|
||||
private _useTime = 0;
|
||||
/** 获取系统在当前帧所消耗的时间 仅在debug模式下生效 */
|
||||
public get useTime() {
|
||||
return this._useTime;
|
||||
/**
|
||||
* 设置更新时序
|
||||
* @param order
|
||||
*/
|
||||
public setUpdateOrder(order: number) {
|
||||
this._updateOrder = order;
|
||||
this.scene.entityProcessors.setDirty();
|
||||
}
|
||||
|
||||
public initialize() {
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
module es {
|
||||
export class EntityProcessorList {
|
||||
public _processors: EntitySystem[] = [];
|
||||
private _processors: EntitySystem[] = [];
|
||||
private _orderDirty: boolean = false;
|
||||
/** 获取系统列表 */
|
||||
public get processors() {
|
||||
return this._processors;
|
||||
}
|
||||
|
||||
/** 系统数量 */
|
||||
public get count() {
|
||||
return this._processors.length;
|
||||
}
|
||||
|
||||
public add(processor: EntitySystem) {
|
||||
this._processors.push(processor);
|
||||
@@ -34,6 +44,16 @@ module es {
|
||||
if (this._processors.length == 0)
|
||||
return;
|
||||
|
||||
if (this._orderDirty) {
|
||||
// 进行排序
|
||||
this._processors = this._processors.sort((a, b) => a.updateOrder - b.updateOrder);
|
||||
for (let i = 0, s = this._processors.length; i < s; ++ i) {
|
||||
const processor = this._processors[i];
|
||||
processor.setUpdateOrder(i);
|
||||
}
|
||||
this.clearDirty();
|
||||
}
|
||||
|
||||
for (let i = 0, s = this._processors.length; i < s; ++ i) {
|
||||
this._processors[i].update();
|
||||
}
|
||||
@@ -52,6 +72,14 @@ module es {
|
||||
|
||||
}
|
||||
|
||||
public setDirty() {
|
||||
this._orderDirty = true;
|
||||
}
|
||||
|
||||
public clearDirty() {
|
||||
this._orderDirty = false;
|
||||
}
|
||||
|
||||
public getProcessor<T extends EntitySystem>(type: new (...args: any[]) => T): T {
|
||||
if (this._processors.length == 0)
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user