/*
    const wallsPool = new DirtyPool(n, () => new Vector())
*/

export default class DirtyPool {
    constructor (n = 1, fnInit) {
        this.pool = Array(n).fill().map(fnInit)
        this.fnInit = fnInit
        this.size = n
        this.pointer = 0
    }

    reset () {
        this.pointer = 0
    }

    get () {
        if (this.size <= this.pointer) {
            this.pool.push(this.fnInit())
            this.size++
        }
        return this.pool[this.pointer++]
    }
}

