    001    package net.minecraft.util;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import java.util.ArrayList;
    006    import java.util.List;
    007
    008    public class AABBPool
    009    {
    010        /**
    011         * Maximum number of times the pool can be "cleaned" before the list is shrunk
    012         */
    013        private final int maxNumCleans;
    014
    015        /**
    016         * Number of Pool entries to remove when cleanPool is called maxNumCleans times.
    017         */
    018        private final int numEntriesToRemove;
    019
    020        /** List of AABB stored in this Pool */
    021        private final List listAABB = new ArrayList();
    022
    023        /** Next index to use when adding a Pool Entry. */
    024        private int nextPoolIndex = 0;
    025
    026        /**
    027         * Largest index reached by this Pool (can be reset to 0 upon calling cleanPool)
    028         */
    029        private int maxPoolIndex = 0;
    030
    031        /** Number of times this Pool has been cleaned */
    032        private int numCleans = 0;
    033
    034        public AABBPool(int par1, int par2)
    035        {
    036            this.maxNumCleans = par1;
    037            this.numEntriesToRemove = par2;
    038        }
    039
    040        /**
    041         * Adds a AABB to the pool, or if there is an available AABB, updates an existing AABB entry to specified
    042         * coordinates
    043         */
    044        public AxisAlignedBB addOrModifyAABBInPool(double par1, double par3, double par5, double par7, double par9, double par11)
    045        {
    046            AxisAlignedBB var13;
    047
    048            if (this.nextPoolIndex >= this.listAABB.size())
    049            {
    050                var13 = new AxisAlignedBB(par1, par3, par5, par7, par9, par11);
    051                this.listAABB.add(var13);
    052            }
    053            else
    054            {
    055                var13 = (AxisAlignedBB)this.listAABB.get(this.nextPoolIndex);
    056                var13.setBounds(par1, par3, par5, par7, par9, par11);
    057            }
    058
    059            ++this.nextPoolIndex;
    060            return var13;
    061        }
    062
    063        /**
    064         * Marks the pool as "empty", starting over when adding new entries. If this is called maxNumCleans times, the list
    065         * size is reduced
    066         */
    067        public void cleanPool()
    068        {
    069            if (this.nextPoolIndex > this.maxPoolIndex)
    070            {
    071                this.maxPoolIndex = this.nextPoolIndex;
    072            }
    073
    074            if (this.numCleans++ == this.maxNumCleans)
    075            {
    076                int var1 = Math.max(this.maxPoolIndex, this.listAABB.size() - this.numEntriesToRemove);
    077
    078                while (this.listAABB.size() > var1)
    079                {
    080                    this.listAABB.remove(var1);
    081                }
    082
    083                this.maxPoolIndex = 0;
    084                this.numCleans = 0;
    085            }
    086
    087            this.nextPoolIndex = 0;
    088        }
    089
    090        @SideOnly(Side.CLIENT)
    091
    092        /**
    093         * Clears the AABBPool
    094         */
    095        public void clearPool()
    096        {
    097            this.nextPoolIndex = 0;
    098            this.listAABB.clear();
    099        }
    100
    101        public int getlistAABBsize()
    102        {
    103            return this.listAABB.size();
    104        }
    105
    106        public int getnextPoolIndex()
    107        {
    108            return this.nextPoolIndex;
    109        }
    110    }