pool池优化性能
This commit is contained in:
@@ -177,7 +177,7 @@ module es {
|
||||
|
||||
}
|
||||
|
||||
protected async update(currentTime: number = -1) {
|
||||
protected update(currentTime: number = -1) {
|
||||
if (Core.paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ module es {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (colliders.length > 0) {
|
||||
for (let i = 0; i < colliders.length; i++) {
|
||||
let collider = colliders[i];
|
||||
|
||||
@@ -259,31 +259,32 @@ module es {
|
||||
|
||||
let resultCounter = 0;
|
||||
const potentials = this.aabbBroadphase(bounds, null, layerMask);
|
||||
for (let i = 0; i < potentials.length; i ++) {
|
||||
const collider = potentials[i];
|
||||
if (collider instanceof BoxCollider) {
|
||||
if (collider.shape.overlaps(this._overlapTestCircle)) {
|
||||
results[resultCounter] = collider;
|
||||
resultCounter++;
|
||||
if (potentials.length > 0)
|
||||
for (let i = 0; i < potentials.length; i ++) {
|
||||
const collider = potentials[i];
|
||||
if (collider instanceof BoxCollider) {
|
||||
if (collider.shape.overlaps(this._overlapTestCircle)) {
|
||||
results[resultCounter] = collider;
|
||||
resultCounter++;
|
||||
}
|
||||
} else if (collider instanceof CircleCollider) {
|
||||
if (collider.shape.overlaps(this._overlapTestCircle)) {
|
||||
results[resultCounter] = collider;
|
||||
resultCounter++;
|
||||
}
|
||||
} else if (collider instanceof PolygonCollider) {
|
||||
if (collider.shape.overlaps(this._overlapTestCircle)) {
|
||||
results[resultCounter] = collider;
|
||||
resultCounter++;
|
||||
}
|
||||
} else {
|
||||
throw new Error("对这个对撞机类型的overlapCircle没有实现!");
|
||||
}
|
||||
} else if (collider instanceof CircleCollider) {
|
||||
if (collider.shape.overlaps(this._overlapTestCircle)) {
|
||||
results[resultCounter] = collider;
|
||||
resultCounter++;
|
||||
}
|
||||
} else if (collider instanceof PolygonCollider) {
|
||||
if (collider.shape.overlaps(this._overlapTestCircle)) {
|
||||
results[resultCounter] = collider;
|
||||
resultCounter++;
|
||||
}
|
||||
} else {
|
||||
throw new Error("对这个对撞机类型的overlapCircle没有实现!");
|
||||
}
|
||||
|
||||
// 如果我们所有的结果数据有了则返回
|
||||
if (resultCounter === results.length)
|
||||
return resultCounter;
|
||||
}
|
||||
// 如果我们所有的结果数据有了则返回
|
||||
if (resultCounter === results.length)
|
||||
return resultCounter;
|
||||
}
|
||||
|
||||
return resultCounter;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ module es {
|
||||
cacheCount -= this._objectQueue.get(type).length;
|
||||
if (cacheCount > 0) {
|
||||
for (let i = 0; i < cacheCount; i++) {
|
||||
this._objectQueue.get(type).unshift([]);
|
||||
this._objectQueue.get(type).push([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ module es {
|
||||
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();
|
||||
this._objectQueue.get(type).splice(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,14 +52,14 @@ module es {
|
||||
* 将项推回堆栈
|
||||
* @param obj
|
||||
*/
|
||||
public static free<T>(type: new (...args) => T, obj: Array<T>) {
|
||||
public static free<T>(type: new (...args) => T, obj: T[]) {
|
||||
this.checkCreate(type);
|
||||
this._objectQueue.get(type).unshift(obj);
|
||||
this._objectQueue.get(type).push(obj);
|
||||
obj.length = 0;
|
||||
}
|
||||
|
||||
private static checkCreate<T>(type: new (...args) => T) {
|
||||
if (!this._objectQueue.get(type))
|
||||
if (!this._objectQueue.has(type))
|
||||
this._objectQueue.set(type, []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ module es {
|
||||
cacheCount -= this._objectQueue.get(type).length;
|
||||
if (cacheCount > 0) {
|
||||
for (let i = 0; i < cacheCount; i++) {
|
||||
this._objectQueue.get(type).unshift(new type());
|
||||
this._objectQueue.get(type).push(new type());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ module es {
|
||||
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();
|
||||
this._objectQueue.get(type).splice(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ module es {
|
||||
*/
|
||||
public static free<T>(type: new (...args) => T, obj: T) {
|
||||
this.checkCreate(type);
|
||||
this._objectQueue.get(type).unshift(obj);
|
||||
this._objectQueue.get(type).push(obj);
|
||||
|
||||
if (isIPoolable(obj)) {
|
||||
obj["reset"]();
|
||||
@@ -63,7 +63,7 @@ module es {
|
||||
}
|
||||
|
||||
private static checkCreate<T>(type: new (...args) => T) {
|
||||
if (!this._objectQueue.get(type))
|
||||
if (!this._objectQueue.has(type))
|
||||
this._objectQueue.set(type, []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ module es {
|
||||
this._timeInSeconds = timeInsSeconds;
|
||||
this._repeats = repeats;
|
||||
this.context = context;
|
||||
this._onTime = onTime;
|
||||
this._onTime = onTime.bind(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,7 @@ module es {
|
||||
for (let i = this._timers.length - 1; i >= 0; i --){
|
||||
if (this._timers[i].tick()){
|
||||
this._timers[i].unload();
|
||||
new es.List(this._timers).removeAt(i);
|
||||
this._timers.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user