Example #1
0
        public bool Remove(int x, int y, int z)
        {
            int key = PosToKey(Mathf.FloorToInt(x) & MASK, Mathf.FloorToInt(z) & MASK);

            if (mGrasses.ContainsKey(key))
            {
                RedGrassInstance rgi = mGrasses[key];
                if ((int)rgi.Position.y == y)
                {
                    if (mHGrass.ContainsKey(key))
                    {
                        List <RedGrassInstance> rgis = mHGrass[key];
                        mGrasses[key] = rgis[0];
                        rgis.RemoveAt(0);
                        if (rgis.Count == 0)
                        {
                            RGPoolSig.RecycleRGList(rgis);
                            mHGrass.Remove(key);
                        }

                        Dirty = true;
                        return(true);
                    }
                    else
                    {
                        Dirty = true;
                        mGrasses.Remove(key);
                        return(true);
                    }
                }
                else if (mHGrass.ContainsKey(key))
                {
                    int index = mHGrass[key].FindIndex(item0 => (int)item0.Position.y == y);
                    if (index != -1)
                    {
                        mHGrass[key].RemoveAt(index);
                        if (mHGrass[key].Count == 0)
                        {
                            mHGrass.Remove(key);
                        }

                        Dirty = true;
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #2
0
        public void Free()
        {
            lock (this)
            {
                mGrasses.Clear();

                if (mHGrass.Count > 0)
                {
                    foreach (KeyValuePair <int, List <RedGrassInstance> > pair in mHGrass)
                    {
                        pair.Value.Clear();
                        RGPoolSig.RecycleRGList(pair.Value);
                    }
                    mHGrass.Clear();
                }

                Dirty = true;
            }
        }