tiny-ecs icon indicating copy to clipboard operation
tiny-ecs copied to clipboard

Automatic pool typing

Open killroy42 opened this issue 9 years ago • 0 comments

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);
    }
}

killroy42 avatar Sep 30 '16 09:09 killroy42