Merge branch 'master' of https://github.com/esengine/ecs-framework
# Conflicts: # extensions/ecs-tween/lib/framework.d.ts
This commit is contained in:
Vendored
+4
-3
@@ -5378,11 +5378,11 @@ declare module es {
|
||||
* 将缓存修剪为cacheCount项目
|
||||
* @param cacheCount
|
||||
*/
|
||||
static trimCache(cacheCount: number): void;
|
||||
static trimCache<T>(type: new (...args: any[]) => T, cacheCount: number): void;
|
||||
/**
|
||||
* 清除缓存
|
||||
*/
|
||||
static clearCache(): void;
|
||||
static clearCache<T>(type: new (...args: any[]) => T): void;
|
||||
/**
|
||||
* 如果可以的话,从堆栈中弹出一个项
|
||||
*/
|
||||
@@ -5391,7 +5391,8 @@ declare module es {
|
||||
* 将项推回堆栈
|
||||
* @param obj
|
||||
*/
|
||||
static free<T>(obj: T): void;
|
||||
static free<T>(type: new (...args: any[]) => T, obj: T): void;
|
||||
private static checkCreate;
|
||||
}
|
||||
interface IPoolable {
|
||||
/**
|
||||
|
||||
+30
-21
@@ -11261,7 +11261,7 @@ var es;
|
||||
};
|
||||
Tween.prototype.start = function () {
|
||||
if (!this._isFromValueOverridden)
|
||||
this._fromValue = this._target.getTargetObject();
|
||||
this._fromValue = this._target.getTweenedValue();
|
||||
if (this._tweenState == TweenState.complete) {
|
||||
this._tweenState = TweenState.running;
|
||||
es.TweenManager.addTween(this);
|
||||
@@ -11414,7 +11414,7 @@ var es;
|
||||
NumberTween.prototype.recycleSelf = function () {
|
||||
_super.prototype.recycleSelf.call(this);
|
||||
if (this._shouldRecycleTween && es.TweenManager.cacheNumberTweens)
|
||||
es.Pool.free(this);
|
||||
es.Pool.free(NumberTween, this);
|
||||
};
|
||||
return NumberTween;
|
||||
}(es.Tween));
|
||||
@@ -11440,7 +11440,7 @@ var es;
|
||||
Vector2Tween.prototype.recycleSelf = function () {
|
||||
_super.prototype.recycleSelf.call(this);
|
||||
if (this._shouldRecycleTween && es.TweenManager.cacheVector2Tweens)
|
||||
es.Pool.free(this);
|
||||
es.Pool.free(Vector2Tween, this);
|
||||
};
|
||||
return Vector2Tween;
|
||||
}(es.Tween));
|
||||
@@ -11466,7 +11466,7 @@ var es;
|
||||
RectangleTween.prototype.recycleSelf = function () {
|
||||
_super.prototype.recycleSelf.call(this);
|
||||
if (this._shouldRecycleTween && es.TweenManager.cacheRectTweens)
|
||||
es.Pool.free(this);
|
||||
es.Pool.free(RectangleTween, this);
|
||||
};
|
||||
return RectangleTween;
|
||||
}(es.Tween));
|
||||
@@ -11527,7 +11527,7 @@ var es;
|
||||
this._nextTween = null;
|
||||
}
|
||||
if (this._shouldRecycleTween && es.TweenManager.cacheColorTweens) {
|
||||
es.Pool.free(this);
|
||||
es.Pool.free(es.ColorTween, this);
|
||||
}
|
||||
};
|
||||
return RenderableColorTween;
|
||||
@@ -11711,7 +11711,7 @@ var es;
|
||||
this._target = null;
|
||||
this._nextTween = null;
|
||||
this._transform = null;
|
||||
es.Pool.free(this);
|
||||
es.Pool.free(es.Vector2Tween, this);
|
||||
}
|
||||
};
|
||||
return TransformVector2Tween;
|
||||
@@ -14094,10 +14094,11 @@ var es;
|
||||
* @param cacheCount
|
||||
*/
|
||||
Pool.warmCache = function (type, cacheCount) {
|
||||
cacheCount -= this._objectQueue.length;
|
||||
this.checkCreate(type);
|
||||
cacheCount -= this._objectQueue.get(type).length;
|
||||
if (cacheCount > 0) {
|
||||
for (var i = 0; i < cacheCount; i++) {
|
||||
this._objectQueue.unshift(new type());
|
||||
this._objectQueue.get(type).unshift(new type());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -14105,35 +14106,43 @@ var es;
|
||||
* 将缓存修剪为cacheCount项目
|
||||
* @param cacheCount
|
||||
*/
|
||||
Pool.trimCache = function (cacheCount) {
|
||||
while (cacheCount > this._objectQueue.length)
|
||||
this._objectQueue.shift();
|
||||
Pool.trimCache = function (type, cacheCount) {
|
||||
this.checkCreate(type);
|
||||
while (cacheCount > this._objectQueue.get(type).length)
|
||||
this._objectQueue.get(type).shift();
|
||||
};
|
||||
/**
|
||||
* 清除缓存
|
||||
*/
|
||||
Pool.clearCache = function () {
|
||||
this._objectQueue.length = 0;
|
||||
Pool.clearCache = function (type) {
|
||||
this.checkCreate(type);
|
||||
this._objectQueue.get(type).length = 0;
|
||||
};
|
||||
/**
|
||||
* 如果可以的话,从堆栈中弹出一个项
|
||||
*/
|
||||
Pool.obtain = function (type) {
|
||||
if (this._objectQueue.length > 0)
|
||||
return this._objectQueue.shift();
|
||||
this.checkCreate(type);
|
||||
if (this._objectQueue.get(type).length > 0)
|
||||
return this._objectQueue.get(type).shift();
|
||||
return new type();
|
||||
};
|
||||
/**
|
||||
* 将项推回堆栈
|
||||
* @param obj
|
||||
*/
|
||||
Pool.free = function (obj) {
|
||||
this._objectQueue.unshift(obj);
|
||||
Pool.free = function (type, obj) {
|
||||
this.checkCreate(type);
|
||||
this._objectQueue.get(type).unshift(obj);
|
||||
if (es.isIPoolable(obj)) {
|
||||
obj["reset"]();
|
||||
}
|
||||
};
|
||||
Pool._objectQueue = [];
|
||||
Pool.checkCreate = function (type) {
|
||||
if (!this._objectQueue.get(type))
|
||||
this._objectQueue.set(type, []);
|
||||
};
|
||||
Pool._objectQueue = new Map();
|
||||
return Pool;
|
||||
}());
|
||||
es.Pool = Pool;
|
||||
@@ -14414,7 +14423,7 @@ var es;
|
||||
for (var i = 0; i < this._unblockedCoroutines.length; i++) {
|
||||
var coroutine = this._unblockedCoroutines[i];
|
||||
if (coroutine.isDone) {
|
||||
es.Pool.free(coroutine);
|
||||
es.Pool.free(CoroutineImpl, coroutine);
|
||||
continue;
|
||||
}
|
||||
if (coroutine.waitForCoroutine != null) {
|
||||
@@ -14448,7 +14457,7 @@ var es;
|
||||
CoroutineManager.prototype.tickCoroutine = function (coroutine) {
|
||||
var chain = coroutine.enumerator.next();
|
||||
if (chain.done || coroutine.isDone) {
|
||||
es.Pool.free(coroutine);
|
||||
es.Pool.free(CoroutineImpl, coroutine);
|
||||
return false;
|
||||
}
|
||||
if (chain.value == null) {
|
||||
@@ -14465,7 +14474,7 @@ var es;
|
||||
}
|
||||
if (typeof chain.value == 'string') {
|
||||
if (chain.value == 'break') {
|
||||
es.Pool.free(coroutine);
|
||||
es.Pool.free(CoroutineImpl, coroutine);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -31,7 +31,7 @@ module es {
|
||||
}
|
||||
|
||||
if (this._shouldRecycleTween && TweenManager.cacheColorTweens) {
|
||||
Pool.free(this);
|
||||
Pool.free(ColorTween, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ module es {
|
||||
this._target = null;
|
||||
this._nextTween = null;
|
||||
this._transform = null;
|
||||
Pool.free(this);
|
||||
Pool.free(Vector2Tween, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ module es {
|
||||
|
||||
public start() {
|
||||
if (!this._isFromValueOverridden)
|
||||
this._fromValue = this._target.getTargetObject();
|
||||
this._fromValue = this._target.getTweenedValue();
|
||||
|
||||
if (this._tweenState == TweenState.complete) {
|
||||
this._tweenState = TweenState.running;
|
||||
|
||||
@@ -24,7 +24,7 @@ module es {
|
||||
super.recycleSelf();
|
||||
|
||||
if (this._shouldRecycleTween && TweenManager.cacheNumberTweens)
|
||||
Pool.free(this);
|
||||
Pool.free(NumberTween, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ module es {
|
||||
super.recycleSelf();
|
||||
|
||||
if (this._shouldRecycleTween && TweenManager.cacheVector2Tweens)
|
||||
Pool.free(this);
|
||||
Pool.free(Vector2Tween, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ module es {
|
||||
super.recycleSelf();
|
||||
|
||||
if (this._shouldRecycleTween && TweenManager.cacheRectTweens)
|
||||
Pool.free(this);
|
||||
Pool.free(RectangleTween, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ module es {
|
||||
* 用于池任何对象
|
||||
*/
|
||||
export class Pool {
|
||||
private static _objectQueue = [];
|
||||
private static _objectQueue: Map<any, any[]> = new Map();
|
||||
|
||||
/**
|
||||
* 预热缓存,使用最大的cacheCount对象填充缓存
|
||||
@@ -11,10 +11,11 @@ module es {
|
||||
* @param cacheCount
|
||||
*/
|
||||
public static warmCache<T>(type: new (...args) => T, cacheCount: number) {
|
||||
cacheCount -= this._objectQueue.length;
|
||||
this.checkCreate(type);
|
||||
cacheCount -= this._objectQueue.get(type).length;
|
||||
if (cacheCount > 0) {
|
||||
for (let i = 0; i < cacheCount; i++) {
|
||||
this._objectQueue.unshift(new type());
|
||||
this._objectQueue.get(type).unshift(new type());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,24 +24,27 @@ module es {
|
||||
* 将缓存修剪为cacheCount项目
|
||||
* @param cacheCount
|
||||
*/
|
||||
public static trimCache(cacheCount: number) {
|
||||
while (cacheCount > this._objectQueue.length)
|
||||
this._objectQueue.shift();
|
||||
public static trimCache<T>(type: new (...args) => T, cacheCount: number) {
|
||||
this.checkCreate(type);
|
||||
while (cacheCount > this._objectQueue.get(type).length)
|
||||
this._objectQueue.get(type).shift();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
*/
|
||||
public static clearCache() {
|
||||
this._objectQueue.length = 0;
|
||||
public static clearCache<T>(type: new (...args) => T) {
|
||||
this.checkCreate(type);
|
||||
this._objectQueue.get(type).length = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果可以的话,从堆栈中弹出一个项
|
||||
*/
|
||||
public static obtain<T>(type: new (...args) => T): T {
|
||||
if (this._objectQueue.length > 0)
|
||||
return this._objectQueue.shift();
|
||||
this.checkCreate(type);
|
||||
if (this._objectQueue.get(type).length > 0)
|
||||
return this._objectQueue.get(type).shift();
|
||||
|
||||
return new type() as T;
|
||||
}
|
||||
@@ -49,13 +53,19 @@ module es {
|
||||
* 将项推回堆栈
|
||||
* @param obj
|
||||
*/
|
||||
public static free<T>(obj: T) {
|
||||
this._objectQueue.unshift(obj);
|
||||
public static free<T>(type: new (...args) => T, obj: T) {
|
||||
this.checkCreate(type);
|
||||
this._objectQueue.get(type).unshift(obj);
|
||||
|
||||
if (isIPoolable(obj)) {
|
||||
obj["reset"]();
|
||||
}
|
||||
}
|
||||
|
||||
private static checkCreate<T>(type: new (...args) => T) {
|
||||
if (!this._objectQueue.get(type))
|
||||
this._objectQueue.set(type, []);
|
||||
}
|
||||
}
|
||||
|
||||
export interface IPoolable {
|
||||
|
||||
@@ -77,7 +77,7 @@ module es {
|
||||
let coroutine = this._unblockedCoroutines[i];
|
||||
|
||||
if (coroutine.isDone) {
|
||||
Pool.free(coroutine);
|
||||
Pool.free(CoroutineImpl, coroutine);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ module es {
|
||||
public tickCoroutine(coroutine: CoroutineImpl) {
|
||||
let chain = coroutine.enumerator.next();
|
||||
if (chain.done || coroutine.isDone) {
|
||||
Pool.free(coroutine);
|
||||
Pool.free(CoroutineImpl, coroutine);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ module es {
|
||||
|
||||
if (typeof chain.value == 'string') {
|
||||
if (chain.value == 'break') {
|
||||
Pool.free(coroutine);
|
||||
Pool.free(CoroutineImpl, coroutine);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user