新增系统时序控制
This commit is contained in:
29
source/bin/framework.d.ts
vendored
29
source/bin/framework.d.ts
vendored
@@ -1573,6 +1573,16 @@ declare module es {
|
||||
*/
|
||||
abstract class EntitySystem {
|
||||
private _entities;
|
||||
private _updateOrder;
|
||||
private _startTime;
|
||||
private _endTime;
|
||||
private _useTime;
|
||||
/** 获取系统在当前帧所消耗的时间 仅在debug模式下生效 */
|
||||
readonly useTime: number;
|
||||
/**
|
||||
* 获取系统的更新时序
|
||||
*/
|
||||
updateOrder: number;
|
||||
constructor(matcher?: Matcher);
|
||||
private _scene;
|
||||
/**
|
||||
@@ -1581,11 +1591,11 @@ declare module es {
|
||||
scene: Scene;
|
||||
private _matcher;
|
||||
readonly matcher: Matcher;
|
||||
private _startTime;
|
||||
private _endTime;
|
||||
private _useTime;
|
||||
/** 获取系统在当前帧所消耗的时间 仅在debug模式下生效 */
|
||||
readonly useTime: number;
|
||||
/**
|
||||
* 设置更新时序
|
||||
* @param order
|
||||
*/
|
||||
setUpdateOrder(order: number): void;
|
||||
initialize(): void;
|
||||
onChanged(entity: Entity): void;
|
||||
add(entity: Entity): void;
|
||||
@@ -2006,7 +2016,12 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class EntityProcessorList {
|
||||
_processors: EntitySystem[];
|
||||
private _processors;
|
||||
private _orderDirty;
|
||||
/** 获取系统列表 */
|
||||
readonly processors: EntitySystem[];
|
||||
/** 系统数量 */
|
||||
readonly count: number;
|
||||
add(processor: EntitySystem): void;
|
||||
remove(processor: EntitySystem): void;
|
||||
onComponentAdded(entity: Entity): void;
|
||||
@@ -2017,6 +2032,8 @@ declare module es {
|
||||
update(): void;
|
||||
lateUpdate(): void;
|
||||
end(): void;
|
||||
setDirty(): void;
|
||||
clearDirty(): void;
|
||||
getProcessor<T extends EntitySystem>(type: new (...args: any[]) => T): T;
|
||||
protected notifyEntityChanged(entity: Entity): void;
|
||||
protected removeFromProcessors(entity: Entity): void;
|
||||
|
||||
@@ -1760,6 +1760,8 @@ var es;
|
||||
Scene.prototype.addEntityProcessor = function (processor) {
|
||||
processor.scene = this;
|
||||
this.entityProcessors.add(processor);
|
||||
processor.setUpdateOrder(this.entityProcessors.count - 1);
|
||||
this.entityProcessors.clearDirty();
|
||||
return processor;
|
||||
};
|
||||
/**
|
||||
@@ -3967,12 +3969,34 @@ var es;
|
||||
var EntitySystem = /** @class */ (function () {
|
||||
function EntitySystem(matcher) {
|
||||
this._entities = [];
|
||||
this._updateOrder = 0;
|
||||
this._startTime = 0;
|
||||
this._endTime = 0;
|
||||
this._useTime = 0;
|
||||
this._matcher = matcher ? matcher : es.Matcher.empty();
|
||||
this.initialize();
|
||||
}
|
||||
Object.defineProperty(EntitySystem.prototype, "useTime", {
|
||||
/** 获取系统在当前帧所消耗的时间 仅在debug模式下生效 */
|
||||
get: function () {
|
||||
return this._useTime;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(EntitySystem.prototype, "updateOrder", {
|
||||
/**
|
||||
* 获取系统的更新时序
|
||||
*/
|
||||
get: function () {
|
||||
return this._updateOrder;
|
||||
},
|
||||
set: function (value) {
|
||||
this.setUpdateOrder(value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(EntitySystem.prototype, "scene", {
|
||||
/**
|
||||
* 这个系统所属的场景
|
||||
@@ -3994,14 +4018,14 @@ var es;
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(EntitySystem.prototype, "useTime", {
|
||||
/** 获取系统在当前帧所消耗的时间 仅在debug模式下生效 */
|
||||
get: function () {
|
||||
return this._useTime;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
/**
|
||||
* 设置更新时序
|
||||
* @param order
|
||||
*/
|
||||
EntitySystem.prototype.setUpdateOrder = function (order) {
|
||||
this._updateOrder = order;
|
||||
this.scene.entityProcessors.setDirty();
|
||||
};
|
||||
EntitySystem.prototype.initialize = function () {
|
||||
};
|
||||
EntitySystem.prototype.onChanged = function (entity) {
|
||||
@@ -5135,7 +5159,24 @@ var es;
|
||||
var EntityProcessorList = /** @class */ (function () {
|
||||
function EntityProcessorList() {
|
||||
this._processors = [];
|
||||
this._orderDirty = false;
|
||||
}
|
||||
Object.defineProperty(EntityProcessorList.prototype, "processors", {
|
||||
/** 获取系统列表 */
|
||||
get: function () {
|
||||
return this._processors;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(EntityProcessorList.prototype, "count", {
|
||||
/** 系统数量 */
|
||||
get: function () {
|
||||
return this._processors.length;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
EntityProcessorList.prototype.add = function (processor) {
|
||||
this._processors.push(processor);
|
||||
};
|
||||
@@ -5159,6 +5200,15 @@ var es;
|
||||
EntityProcessorList.prototype.update = function () {
|
||||
if (this._processors.length == 0)
|
||||
return;
|
||||
if (this._orderDirty) {
|
||||
// 进行排序
|
||||
this._processors = this._processors.sort(function (a, b) { return a.updateOrder - b.updateOrder; });
|
||||
for (var i = 0, s = this._processors.length; i < s; ++i) {
|
||||
var processor = this._processors[i];
|
||||
processor.setUpdateOrder(i);
|
||||
}
|
||||
this.clearDirty();
|
||||
}
|
||||
for (var i = 0, s = this._processors.length; i < s; ++i) {
|
||||
this._processors[i].update();
|
||||
}
|
||||
@@ -5172,6 +5222,12 @@ var es;
|
||||
};
|
||||
EntityProcessorList.prototype.end = function () {
|
||||
};
|
||||
EntityProcessorList.prototype.setDirty = function () {
|
||||
this._orderDirty = true;
|
||||
};
|
||||
EntityProcessorList.prototype.clearDirty = function () {
|
||||
this._orderDirty = false;
|
||||
};
|
||||
EntityProcessorList.prototype.getProcessor = function (type) {
|
||||
if (this._processors.length == 0)
|
||||
return null;
|
||||
|
||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -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