pool池优化性能
This commit is contained in:
4
source/bin/framework.d.ts
vendored
4
source/bin/framework.d.ts
vendored
@@ -94,7 +94,7 @@ declare module es {
|
||||
*/
|
||||
onSceneChanged(): void;
|
||||
protected initialize(): void;
|
||||
protected update(currentTime?: number): Promise<void>;
|
||||
protected update(currentTime?: number): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
@@ -4877,7 +4877,7 @@ declare module es {
|
||||
* 将项推回堆栈
|
||||
* @param obj
|
||||
*/
|
||||
static free<T>(type: new (...args: any[]) => T, obj: Array<T>): void;
|
||||
static free<T>(type: new (...args: any[]) => T, obj: T[]): void;
|
||||
private static checkCreate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,4 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __read = (this && this.__read) || function (o, n) {
|
||||
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
||||
if (!m) return o;
|
||||
@@ -74,6 +39,33 @@ var __values = (this && this.__values) || function (o) {
|
||||
}
|
||||
};
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var es;
|
||||
(function (es) {
|
||||
/**
|
||||
@@ -224,15 +216,12 @@ var es;
|
||||
};
|
||||
Core.prototype.update = function (currentTime) {
|
||||
if (currentTime === void 0) { currentTime = -1; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var i;
|
||||
return __generator(this, function (_a) {
|
||||
if (Core.paused) {
|
||||
return [2 /*return*/];
|
||||
return;
|
||||
}
|
||||
es.Time.update(currentTime, currentTime != -1);
|
||||
if (this._scene != null) {
|
||||
for (i = this._globalManagers.length - 1; i >= 0; i--) {
|
||||
for (var i = this._globalManagers.length - 1; i >= 0; i--) {
|
||||
if (this._globalManagers[i].enabled)
|
||||
this._globalManagers[i].update();
|
||||
}
|
||||
@@ -246,9 +235,6 @@ var es;
|
||||
}
|
||||
}
|
||||
this.startDebugDraw();
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
};
|
||||
Core.paused = false;
|
||||
/**
|
||||
@@ -8551,6 +8537,7 @@ var es;
|
||||
this._overlapTestCircle.position = circleCenter;
|
||||
var resultCounter = 0;
|
||||
var potentials = this.aabbBroadphase(bounds, null, layerMask);
|
||||
if (potentials.length > 0)
|
||||
for (var i = 0; i < potentials.length; i++) {
|
||||
var collider = potentials[i];
|
||||
if (collider instanceof es.BoxCollider) {
|
||||
@@ -12601,7 +12588,7 @@ var es;
|
||||
cacheCount -= this._objectQueue.get(type).length;
|
||||
if (cacheCount > 0) {
|
||||
for (var i = 0; i < cacheCount; i++) {
|
||||
this._objectQueue.get(type).unshift([]);
|
||||
this._objectQueue.get(type).push([]);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -12612,7 +12599,7 @@ var es;
|
||||
ListPool.trimCache = function (type, cacheCount) {
|
||||
this.checkCreate(type);
|
||||
while (cacheCount > this._objectQueue.get(type).length)
|
||||
this._objectQueue.get(type).shift();
|
||||
this._objectQueue.get(type).splice(0, 1);
|
||||
};
|
||||
/**
|
||||
* 清除缓存
|
||||
@@ -12636,11 +12623,11 @@ var es;
|
||||
*/
|
||||
ListPool.free = function (type, obj) {
|
||||
this.checkCreate(type);
|
||||
this._objectQueue.get(type).unshift(obj);
|
||||
this._objectQueue.get(type).push(obj);
|
||||
obj.length = 0;
|
||||
};
|
||||
ListPool.checkCreate = function (type) {
|
||||
if (!this._objectQueue.get(type))
|
||||
if (!this._objectQueue.has(type))
|
||||
this._objectQueue.set(type, []);
|
||||
};
|
||||
ListPool._objectQueue = new Map();
|
||||
@@ -12741,7 +12728,7 @@ var es;
|
||||
cacheCount -= this._objectQueue.get(type).length;
|
||||
if (cacheCount > 0) {
|
||||
for (var i = 0; i < cacheCount; i++) {
|
||||
this._objectQueue.get(type).unshift(new type());
|
||||
this._objectQueue.get(type).push(new type());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -12752,7 +12739,7 @@ var es;
|
||||
Pool.trimCache = function (type, cacheCount) {
|
||||
this.checkCreate(type);
|
||||
while (cacheCount > this._objectQueue.get(type).length)
|
||||
this._objectQueue.get(type).shift();
|
||||
this._objectQueue.get(type).splice(0, 1);
|
||||
};
|
||||
/**
|
||||
* 清除缓存
|
||||
@@ -12776,13 +12763,13 @@ var es;
|
||||
*/
|
||||
Pool.free = function (type, obj) {
|
||||
this.checkCreate(type);
|
||||
this._objectQueue.get(type).unshift(obj);
|
||||
this._objectQueue.get(type).push(obj);
|
||||
if (es.isIPoolable(obj)) {
|
||||
obj["reset"]();
|
||||
}
|
||||
};
|
||||
Pool.checkCreate = function (type) {
|
||||
if (!this._objectQueue.get(type))
|
||||
if (!this._objectQueue.has(type))
|
||||
this._objectQueue.set(type, []);
|
||||
};
|
||||
Pool._objectQueue = new Map();
|
||||
@@ -15179,7 +15166,7 @@ var es;
|
||||
this._timeInSeconds = timeInsSeconds;
|
||||
this._repeats = repeats;
|
||||
this.context = context;
|
||||
this._onTime = onTime;
|
||||
this._onTime = onTime.bind(context);
|
||||
};
|
||||
/**
|
||||
* 空出对象引用,以便在js需要时GC可以清理它们的引用
|
||||
@@ -15208,7 +15195,7 @@ var es;
|
||||
for (var 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -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,6 +259,7 @@ module es {
|
||||
|
||||
let resultCounter = 0;
|
||||
const potentials = this.aabbBroadphase(bounds, null, layerMask);
|
||||
if (potentials.length > 0)
|
||||
for (let i = 0; i < potentials.length; i ++) {
|
||||
const collider = potentials[i];
|
||||
if (collider instanceof BoxCollider) {
|
||||
|
||||
@@ -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