public bool TryGetValue(int x, int z, out HeightMapInfo[] Heights, out int heightIndex)
        {
            int fx = x >> 7;
            int fz = z >> 7;

            heightIndex = ((z - (fz << 7)) << 7) + (x - (fx << 7));
            int Key = ((fz + 1024) << 16) + (fx + 1024);

            if (Key != mLastKey || mLastSector < 0)
            {
                if (!mSectors.TryGetValue(Key, out int poolIndex) || Key != mSectorsPool[poolIndex].Key)
                {
                    int leastUsed = int.MaxValue;
                    for (int k = 0; k < mSectorsPool.Length; k++)
                    {
                        if (mSectorsPool[k].Uses < leastUsed)
                        {
                            leastUsed = mSectorsPool[k].Uses;
                            poolIndex = k;
                        }
                    }

                    HeightMapInfoPoolEntry sector = mSectorsPool[poolIndex];
                    if (sector.Key > 0)
                    {
                        mSectors.Remove(sector.Key);
                    }

                    sector.Key    = Key;
                    sector.Uses   = 0;
                    mSectors[Key] = poolIndex;

                    if (sector.Heights == null)
                    {
                        sector.Heights = new HeightMapInfo[16384];
                    }
                    else
                    {
                        for (int k = 0; k < sector.Heights.Length; k++)
                        {
                            sector.Heights[k].Biome       = null;
                            sector.Heights[k].Moisture    = 0;
                            sector.Heights[k].GroundLevel = 0;
                        }
                    }
                }
                mLastKey    = Key;
                mLastSector = poolIndex;
            }

            HeightMapInfoPoolEntry theSector = mSectorsPool[mLastSector];

            theSector.Uses++;
            Heights = theSector.Heights;
            return(Heights[heightIndex].GroundLevel != 0);
        }
Пример #2
0
        public bool Remove()
        {
            var res   = false;
            var found = _found;
            var copy  = new FastHashSet <T>(_hashSet);

            for (var i = 0; i < found.Length; i++)
            {
                res ^= copy.Remove(found[i]);
            }

            return(res);
        }
Пример #3
0
        public void ContainsIn()
        {
            FastHashSet <int> set = new FastHashSet <int>();
            int x   = 1;
            int x2  = 2;
            int x3  = 3;
            int x4  = 4;
            int x5  = 5;
            int x6  = 6;
            int x7  = 7;
            int x8  = 8;
            int x9  = 9;
            int x10 = 10;
            int x11 = 11;
            int x12 = 12;

            set.Add(in x);
            set.Add(in x2);
            set.Add(in x3);
            set.Add(in x4);
            set.Add(in x5);
            set.Add(in x6);
            set.Add(in x7);
            set.Add(in x8);
            set.Add(in x9);
            set.Add(in x10);
            set.Add(in x11);
            set.Add(in x12);
            set.Remove(x12);

            Assert.True(set.Contains(in x));
            Assert.True(set.Contains(in x2));
            Assert.True(set.Contains(in x3));
            Assert.True(set.Contains(in x4));
            Assert.True(set.Contains(in x5));
            Assert.True(set.Contains(in x6));
            Assert.True(set.Contains(in x7));
            Assert.True(set.Contains(in x8));
            Assert.True(set.Contains(in x9));
            Assert.True(set.Contains(in x10));
            Assert.True(set.Contains(in x11));
            Assert.False(set.Contains(in x12));
        }