package net.minecraft.src;

import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Vec3Pool {

    private static final Logger L = Logger.getLogger(Vec3Pool.class.getName());
    private Vec3[] pool = new Vec3[16000];
    private int poolIndex = -1;

    public Vec3Pool(int par1, int par2) {
    }

    /**
     * extends the pool if all vecs are currently "out"
     */
    public Vec3 getVecFromPool(double x, double y, double z) {
        // create new instances when free or overflowed, otherwise re-use
        // instances saved in the pool
        if (++poolIndex > pool.length - 1) {
            return new Vec3(this, x, y, z);
        } else if (pool[poolIndex] == null) {
            return pool[poolIndex] = new Vec3(this, x, y, z);
        } else {
            return pool[poolIndex].setComponents(x, y, z);
        }
    }

    /**
     * Will truncate the array everyN clears to the maximum size observed since
     * the last truncation.
     */
    public void clear() {
        if (poolIndex > pool.length - 1) {
            L.log(Level.WARNING, "Vector pool overflow, created {0} unpooled instances", (poolIndex - pool.length));
        }

        poolIndex = -1;
    }

    public void clearAndFreeCache() {
        Arrays.fill(pool, null);
        poolIndex = -1;
    }

    public int func_82591_c() {
        return pool.length;
    }

    public int func_82590_d() {
        return poolIndex % pool.length;
    }
}