Files
nothoughts/node_modules/pixi.js/lib/utils/pool/PoolGroup.mjs
2025-08-04 18:57:35 +02:00

71 lines
2.2 KiB
JavaScript

import { Pool } from './Pool.mjs';
"use strict";
class PoolGroupClass {
constructor() {
/**
* A map to store the pools by their class type.
* @private
*/
this._poolsByClass = /* @__PURE__ */ new Map();
}
/**
* Prepopulates a specific pool with a given number of items.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.
* @param {number} total - The number of items to add to the pool.
*/
prepopulate(Class, total) {
const classPool = this.getPool(Class);
classPool.prepopulate(total);
}
/**
* Gets an item from a specific pool.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} Class - The constructor of the items in the pool.
* @param {unknown} [data] - Optional data to pass to the item's constructor.
* @returns {T} The item from the pool.
*/
get(Class, data) {
const pool = this.getPool(Class);
return pool.get(data);
}
/**
* Returns an item to its respective pool.
* @param {PoolItem} item - The item to return to the pool.
*/
return(item) {
const pool = this.getPool(item.constructor);
pool.return(item);
}
/**
* Gets a specific pool based on the class type.
* @template T The type of items in the pool. Must extend PoolItem.
* @param {PoolItemConstructor<T>} ClassType - The constructor of the items in the pool.
* @returns {Pool<T>} The pool of the given class type.
*/
getPool(ClassType) {
if (!this._poolsByClass.has(ClassType)) {
this._poolsByClass.set(ClassType, new Pool(ClassType));
}
return this._poolsByClass.get(ClassType);
}
/** gets the usage stats of each pool in the system */
stats() {
const stats = {};
this._poolsByClass.forEach((pool) => {
const name = stats[pool._classType.name] ? pool._classType.name + pool._classType.ID : pool._classType.name;
stats[name] = {
free: pool.totalFree,
used: pool.totalUsed,
size: pool.totalSize
};
});
return stats;
}
}
const BigPool = new PoolGroupClass();
export { BigPool, PoolGroupClass };
//# sourceMappingURL=PoolGroup.mjs.map