1.新增类型识别

2.EntitySystem新增initialize生命周期,构造函数后执行
This commit is contained in:
yhh
2021-03-31 16:59:21 +08:00
parent 7e94f42b10
commit 781bad9573
6 changed files with 11 additions and 9 deletions

View File

@@ -76,7 +76,7 @@ declare module es {
* 获取类型为T的全局管理器
* @param type
*/
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
static getGlobalManager<T extends es.GlobalManager>(type: new (...args: any[]) => T): T;
/**
* 启动一个coroutine。Coroutine可以将number延时几秒或延时到其他startCoroutine.Yielding
* null将使coroutine在下一帧被执行。
@@ -3792,14 +3792,14 @@ declare module es {
/**
* 用于池任何对象
*/
class Pool<T> {
class Pool {
private static _objectQueue;
/**
* 预热缓存使用最大的cacheCount对象填充缓存
* @param type
* @param cacheCount
*/
static warmCache(type: any, cacheCount: number): void;
static warmCache<T>(type: new (...args: any[]) => T, cacheCount: number): void;
/**
* 将缓存修剪为cacheCount项目
* @param cacheCount
@@ -3812,7 +3812,7 @@ declare module es {
/**
* 如果可以的话,从堆栈中弹出一个项
*/
static obtain<T>(type: any): T;
static obtain<T>(type: new (...args: any[]) => T): T;
/**
* 将项推回堆栈
* @param obj

View File

@@ -2906,6 +2906,7 @@ var es;
function EntitySystem(matcher) {
this._entities = [];
this._matcher = matcher ? matcher : es.Matcher.empty();
this.initialize();
}
Object.defineProperty(EntitySystem.prototype, "scene", {
/**

File diff suppressed because one or more lines are too long

View File

@@ -124,7 +124,7 @@ module es {
* 获取类型为T的全局管理器
* @param type
*/
public static getGlobalManager<T extends es.GlobalManager>(type): T {
public static getGlobalManager<T extends es.GlobalManager>(type: new (...args) => T): T {
for (let i = 0; i < this._instance._globalManagers.length; i++) {
if (this._instance._globalManagers[i] instanceof type)
return this._instance._globalManagers[i] as T;

View File

@@ -7,6 +7,7 @@ module es {
constructor(matcher?: Matcher) {
this._matcher = matcher ? matcher : Matcher.empty();
this.initialize();
}
private _scene: Scene;

View File

@@ -2,7 +2,7 @@ module es {
/**
* 用于池任何对象
*/
export class Pool<T> {
export class Pool {
private static _objectQueue = [];
/**
@@ -10,7 +10,7 @@ module es {
* @param type
* @param cacheCount
*/
public static warmCache(type: any, cacheCount: number) {
public static warmCache<T>(type: new (...args) => T, cacheCount: number) {
cacheCount -= this._objectQueue.length;
if (cacheCount > 0) {
for (let i = 0; i < cacheCount; i++) {
@@ -38,7 +38,7 @@ module es {
/**
* 如果可以的话,从堆栈中弹出一个项
*/
public static obtain<T>(type: any): T {
public static obtain<T>(type: new (...args) => T): T {
if (this._objectQueue.length > 0)
return this._objectQueue.shift();