tiny-ecs
tiny-ecs copied to clipboard
Automatic pool typing
I've been using tiny-ecs as a helpful guide for designing my own ECS. Just wanted to give back this little idea for managing multiple types of object pools more easily:
class PoolManager {
constructor() {
this._pools = {};
}
getPool(T) {
if(this._pools[T] === undefined) {
this._pools[T] = new ObjectPool(T);
}
return this._pools[T];
}
aquire(T) {
const pool = this.getPool(T);
return pool.aquire();
}
release(item) {
const pool = this.getPool(item.constructor);
pool.release(item);
}
}