# Conflicts:
#	extensions/ecs-tween/lib/framework.d.ts
This commit is contained in:
yhh
2021-08-04 12:54:18 +08:00
13 changed files with 67 additions and 1477 deletions

View File

@@ -31,7 +31,7 @@ module es {
}
if (this._shouldRecycleTween && TweenManager.cacheColorTweens) {
Pool.free(this);
Pool.free(ColorTween, this);
}
}
}

View File

@@ -83,7 +83,7 @@ module es {
this._target = null;
this._nextTween = null;
this._transform = null;
Pool.free(this);
Pool.free(Vector2Tween, this);
}
}
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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 {

View File

@@ -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;
}