UNPKG

@awayjs/graphics

Version:
83 lines (82 loc) 2.43 kB
var ManagedPool = /** @class */ (function () { function ManagedPool(baseClass, _limit, enabled) { if (_limit === void 0) { _limit = 10; } if (enabled === void 0) { enabled = true; } this.baseClass = baseClass; this._limit = _limit; this.enabled = enabled; this._store = []; } ManagedPool.prototype.resize = function (target) { if (target >= this._store.length) { return; } var diff = this._store.splice(0, this._store.length - target); for (var _i = 0, diff_1 = diff; _i < diff_1.length; _i++) { var s = diff_1[_i]; s.dispose(); } }; Object.defineProperty(ManagedPool.prototype, "size", { get: function () { return this._store.length; }, set: function (v) { this.resize(v); }, enumerable: false, configurable: true }); Object.defineProperty(ManagedPool.prototype, "limit", { get: function () { return this._limit; }, set: function (v) { this.resize(v); this._limit = v; }, enumerable: false, configurable: true }); ManagedPool.prototype.pop = function () { return this._store.length && this.enabled ? this._store.shift() : null; }; ManagedPool.prototype.store = function (entry) { if (!this.enabled) { return false; } if (entry.assetType !== this.baseClass.assetType) { return false; } if (this._store.length >= this._limit) { return false; } this._store.push(entry); return true; }; ManagedPool.prototype.release = function (entry) { var index = this._store.indexOf(entry); if (index === -1) { return false; } this._store.splice(index, 1); return true; }; ManagedPool.prototype.clear = function () { this.resize(0); }; ManagedPool.prototype.dispose = function () { for (var _i = 0, _a = this._store; _i < _a.length; _i++) { var s = _a[_i]; s.dispose(); } this._store = null; this._limit = 0; }; /** * @description Reduce a size every n-sec */ ManagedPool.REDUCE_TIMEOUT = 5000; return ManagedPool; }()); export { ManagedPool };