Merge branch 'master' of https://github.com/esengine/ecs-framework
# Conflicts: # extensions/ecs-tween/lib/framework.d.ts
This commit is contained in:
@@ -1,319 +0,0 @@
|
||||
declare module es {
|
||||
abstract class AbstractTweenable implements ITweenable {
|
||||
protected _isPaused: boolean;
|
||||
protected _isCurrentlyManagedByTweenManager: boolean;
|
||||
abstract tick(): boolean;
|
||||
recycleSelf(): void;
|
||||
isRunning(): boolean;
|
||||
start(): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
stop(bringToCompletion?: boolean): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class PropertyTweens {
|
||||
static NumberPropertyTo(self: any, memberName: string, to: number, duration: number): ITween<number>;
|
||||
static Vector2PropertyTo(self: any, memeberName: string, to: Vector2, duration: number): ITween<Vector2>;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class TransformSpringTween extends AbstractTweenable {
|
||||
readonly targetType: TransformTargetType;
|
||||
private _transform;
|
||||
private _targetType;
|
||||
private _targetValue;
|
||||
private _velocity;
|
||||
dampingRatio: number;
|
||||
angularFrequency: number;
|
||||
constructor(transform: Transform, targetType: TransformTargetType, targetValue: Vector2);
|
||||
setTargetValue(targetValue: Vector2): void;
|
||||
updateDampingRatioWithHalfLife(lambda: number): void;
|
||||
tick(): boolean;
|
||||
private setTweenedValue;
|
||||
private getCurrentValueOfTweenedTargetType;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
enum LoopType {
|
||||
none = 0,
|
||||
restartFromBeginning = 1,
|
||||
pingpong = 2
|
||||
}
|
||||
enum TweenState {
|
||||
running = 0,
|
||||
paused = 1,
|
||||
complete = 2
|
||||
}
|
||||
abstract class Tween<T> implements ITweenable, ITween<T> {
|
||||
protected _target: ITweenTarget<T>;
|
||||
protected _isFromValueOverridden: boolean;
|
||||
protected _fromValue: T;
|
||||
protected _toValue: T;
|
||||
protected _easeType: EaseType;
|
||||
protected _shouldRecycleTween: boolean;
|
||||
protected _isRelative: boolean;
|
||||
protected _completionHandler: (tween: ITween<T>) => void;
|
||||
protected _loopCompleteHandler: (tween: ITween<T>) => void;
|
||||
protected _nextTween: ITweenable;
|
||||
protected _tweenState: TweenState;
|
||||
private _isTimeScaleIndependent;
|
||||
protected _delay: number;
|
||||
protected _duration: number;
|
||||
protected _timeScale: number;
|
||||
protected _elapsedTime: number;
|
||||
protected _loopType: LoopType;
|
||||
protected _loops: number;
|
||||
protected _delayBetweenLoops: number;
|
||||
private _isRunningInReverse;
|
||||
context: any;
|
||||
setEaseType(easeType: EaseType): ITween<T>;
|
||||
setDelay(delay: number): ITween<T>;
|
||||
setDuration(duration: number): ITween<T>;
|
||||
setTimeScale(timeSclae: number): ITween<T>;
|
||||
setIsTimeScaleIndependent(): ITween<T>;
|
||||
setCompletionHandler(completeHandler: (tween: ITween<T>) => void): ITween<T>;
|
||||
setLoops(loopType: LoopType, loops?: number, delayBetweenLoops?: number): ITween<T>;
|
||||
setLoopCompletionHanlder(loopCompleteHandler: (tween: ITween<T>) => void): ITween<T>;
|
||||
setFrom(from: T): ITween<T>;
|
||||
prepareForReuse(from: T, to: T, duration: number): ITween<T>;
|
||||
setRecycleTween(shouldRecycleTween: boolean): ITween<T>;
|
||||
abstract setIsRelative(): ITween<T>;
|
||||
setContext(context: any): ITween<T>;
|
||||
setNextTween(nextTween: ITweenable): ITween<T>;
|
||||
tick(): boolean;
|
||||
recycleSelf(): void;
|
||||
isRunning(): boolean;
|
||||
start(): void;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
stop(bringToCompletion?: boolean): void;
|
||||
jumpToElapsedTime(elapsedTime: any): void;
|
||||
reverseTween(): void;
|
||||
waitForCompletion(): IterableIterator<any>;
|
||||
getTargetObject(): any;
|
||||
private resetState;
|
||||
initialize(target: ITweenTarget<T>, to: T, duration: number): void;
|
||||
private handleLooping;
|
||||
protected abstract updateValue(): any;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class NumberTween extends Tween<number> {
|
||||
static create(): NumberTween;
|
||||
constructor(target?: ITweenTarget<number>, to?: number, duration?: number);
|
||||
setIsRelative(): ITween<number>;
|
||||
protected updateValue(): void;
|
||||
recycleSelf(): void;
|
||||
}
|
||||
class Vector2Tween extends Tween<Vector2> {
|
||||
static create(): Vector2Tween;
|
||||
constructor(target?: ITweenTarget<Vector2>, to?: Vector2, duration?: number);
|
||||
setIsRelative(): ITween<Vector2>;
|
||||
protected updateValue(): void;
|
||||
recycleSelf(): void;
|
||||
}
|
||||
class RectangleTween extends Tween<Rectangle> {
|
||||
static create(): RectangleTween;
|
||||
constructor(target?: ITweenTarget<Rectangle>, to?: Rectangle, duration?: number);
|
||||
setIsRelative(): ITween<Rectangle>;
|
||||
protected updateValue(): void;
|
||||
recycleSelf(): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
enum TransformTargetType {
|
||||
position = 0,
|
||||
localPosition = 1,
|
||||
scale = 2,
|
||||
localScale = 3,
|
||||
rotationDegrees = 4,
|
||||
localRotationDegrees = 5
|
||||
}
|
||||
class TransformVector2Tween extends Vector2Tween implements ITweenTarget<Vector2> {
|
||||
private _transform;
|
||||
private _targetType;
|
||||
setTweenedValue(value: Vector2): void;
|
||||
getTweenedValue(): Vector2;
|
||||
getTargetObject(): Transform;
|
||||
setTargetAndType(transform: Transform, targetType: TransformTargetType): void;
|
||||
protected updateValue(): void;
|
||||
recycleSelf(): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
enum EaseType {
|
||||
linear = 0,
|
||||
sineIn = 1,
|
||||
sineOut = 2,
|
||||
sineInOut = 3,
|
||||
quadIn = 4,
|
||||
quadOut = 5,
|
||||
quadInOut = 6,
|
||||
quintIn = 7,
|
||||
quintOut = 8,
|
||||
quintInOut = 9,
|
||||
cubicIn = 10,
|
||||
cubicOut = 11,
|
||||
cubicInOut = 12,
|
||||
quartIn = 13,
|
||||
quartOut = 14,
|
||||
quartInOut = 15,
|
||||
expoIn = 16,
|
||||
expoOut = 17,
|
||||
expoInOut = 18,
|
||||
circleIn = 19,
|
||||
circleOut = 20,
|
||||
circleInOut = 21,
|
||||
elasticIn = 22,
|
||||
elasticOut = 23,
|
||||
elasticInOut = 24,
|
||||
punch = 25,
|
||||
backIn = 26,
|
||||
backOut = 27,
|
||||
backInOut = 28,
|
||||
bounceIn = 29,
|
||||
bounceOut = 30,
|
||||
bounceInOut = 31
|
||||
}
|
||||
class EaseHelper {
|
||||
static oppositeEaseType(easeType: EaseType): EaseType.linear | EaseType.sineIn | EaseType.sineOut | EaseType.sineInOut | EaseType.quadIn | EaseType.quadOut | EaseType.quadInOut | EaseType.quintIn | EaseType.quintOut | EaseType.quintInOut | EaseType.cubicIn | EaseType.cubicOut | EaseType.cubicInOut | EaseType.quartIn | EaseType.quartInOut | EaseType.expoIn | EaseType.expoOut | EaseType.expoInOut | EaseType.circleIn | EaseType.circleOut | EaseType.circleInOut | EaseType.elasticIn | EaseType.elasticOut | EaseType.elasticInOut | EaseType.punch | EaseType.backIn | EaseType.backOut | EaseType.backInOut | EaseType.bounceIn | EaseType.bounceOut | EaseType.bounceInOut;
|
||||
static ease(easeType: EaseType, t: number, duration: number): number;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class TweenManager extends GlobalManager {
|
||||
static defaultEaseType: EaseType;
|
||||
static removeAllTweensOnLevelLoad: boolean;
|
||||
static cacheNumberTweens: boolean;
|
||||
static cacheVector2Tweens: boolean;
|
||||
static cacheRectTweens: boolean;
|
||||
private _activeTweens;
|
||||
private _tempTweens;
|
||||
private _isUpdating;
|
||||
private static _instance;
|
||||
constructor();
|
||||
update(): void;
|
||||
static addTween(tween: ITweenable): void;
|
||||
static removeTween(tween: ITweenable): void;
|
||||
static stopAllTweens(bringToCompletion?: boolean): void;
|
||||
static allTweensWithContext(context: any): ITweenable[];
|
||||
static stopAllTweensWithContext(context: any, bringToCompletion?: boolean): void;
|
||||
static allTweenWithTarget(target: any): ITweenable[];
|
||||
static stopAllTweensWithTarget(target: any, bringToCompletion?: boolean): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
module Easing {
|
||||
class Linear {
|
||||
static easeNone(t: number, d: number): number;
|
||||
}
|
||||
class Quadratic {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
class Back {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
class Bounce {
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
class Circular {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
class Cubic {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
class Elastic {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
static punch(t: number, d: number): number;
|
||||
}
|
||||
class Exponential {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
class Quartic {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
class Quintic {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
class Sinusoidal {
|
||||
static easeIn(t: number, d: number): number;
|
||||
static easeOut(t: number, d: number): number;
|
||||
static easeInOut(t: number, d: number): number;
|
||||
}
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class Lerps {
|
||||
static lerp(from: number, to: number, t: number): number;
|
||||
static lerpVector2(from: Vector2, to: Vector2, t: number): Vector2;
|
||||
static lerpRectangle(from: Rectangle, to: Rectangle, t: number): Rectangle;
|
||||
static angleLerp(from: Vector2, to: Vector2, t: number): Vector2;
|
||||
static ease(easeType: EaseType, from: number, to: number, t: number, duration: number): number;
|
||||
static easeVector2(easeType: EaseType, from: Vector2, to: Vector2, t: number, duration: number): Vector2;
|
||||
static easeRectangle(easeType: EaseType, from: Rectangle, to: Rectangle, t: number, duration: number): Rectangle;
|
||||
static easeAngle(easeType: EaseType, from: Vector2, to: Vector2, t: number, duration: number): Vector2;
|
||||
static fastSpring(currentValue: Vector2, targetValue: Vector2, velocity: Vector2, dampingRatio: number, angularFrequency: number): Vector2;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
interface ITween<T> extends ITweenControl {
|
||||
setEaseType(easeType: EaseType): ITween<T>;
|
||||
setDelay(delay: number): ITween<T>;
|
||||
setDuration(duration: number): ITween<T>;
|
||||
setTimeScale(timeScale: number): ITween<T>;
|
||||
setIsTimeScaleIndependent(): ITween<T>;
|
||||
setCompletionHandler(completionHandler: (tween: ITween<T>) => void): ITween<T>;
|
||||
setLoops(loopType: LoopType, loops: number, delayBetweenLoops: number): ITween<T>;
|
||||
setFrom(from: T): ITween<T>;
|
||||
prepareForReuse(from: T, to: T, duration: number): ITween<T>;
|
||||
setRecycleTween(shouldRecycleTween: boolean): ITween<T>;
|
||||
setIsRelative(): ITween<T>;
|
||||
setContext(context: any): ITween<T>;
|
||||
setNextTween(nextTween: ITweenable): ITween<T>;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
interface ITweenControl extends ITweenable {
|
||||
context: any;
|
||||
jumpToElapsedTime(elapsedTime: number): any;
|
||||
waitForCompletion(): any;
|
||||
getTargetObject(): any;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
interface ITweenTarget<T> {
|
||||
setTweenedValue(value: T): any;
|
||||
getTweenedValue(): T;
|
||||
getTargetObject(): any;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
interface ITweenable {
|
||||
tick(): boolean;
|
||||
recycleSelf(): any;
|
||||
isRunning(): boolean;
|
||||
start(): any;
|
||||
pause(): any;
|
||||
resume(): any;
|
||||
stop(bringToCompletion: boolean): any;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
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