Exemplo n.º 1
0
        public void Evict()
        {
            if (_chunks == null)
            {
                return;
            }
            Save();
            State = ColumnState.Evicting;
            for (var y = 0; y < _chunks.Count; ++y)
            {
                if (!_chunks[y].Equals(default(IChunk)))
                {
                    var chunk = _chunks[y];
                    chunk.Evict();
                }
                _chunks[y] = default(IChunk);
            }

            if (_lightData != null)
            {
                _lightData.Evict();
                PoolManager.GetObjectPool <CompressableArray <uint> >().Push(_lightData);
            }
            if (_neighbors != null)
            {
                _neighbors.Clear();
                PoolManager.GetObjectPool <Dictionary <FaceDirection, Column> >().Push(_neighbors);
            }
            PoolManager.GetObjectPool <List <IChunk> >().Push(_chunks);
            _lightData = null;
            _chunks    = null;
            State      = ColumnState.Uninitialized;
        }
Exemplo n.º 2
0
 public override void Evict()
 {
     base.Evict();
     _compressableArray.Evict();
     PoolManager.GetObjectPool <CompressableArray <IBlock> >().Push(_compressableArray);
     _compressableArray = null;
     for (var x = 0; x < PatchesWide; x++)
     {
         for (var y = 0; y < PatchesWide; y++)
         {
             for (var z = 0; z < PatchesWide; z++)
             {
                 _patches[x, y, z]?.Evict();
             }
         }
     }
 }
Exemplo n.º 3
0
 public void Initiailize(Vector3Int position, long chunkId)
 {
     Offset             = position;
     _compressableArray = PoolManager.GetObjectPool <CompressableArray <IBlock> >().Pop();
     _compressableArray.Initialize(Size.x);
     ChunkId   = chunkId;
     Neighbors = PoolManager.GetObjectPool <Dictionary <FaceDirection, IChunk> >().Pop();
     _patches  = PoolManager.GetArrayPool <Patch[, , ]>(PatchesWide).Pop();
     for (var x = 0; x < PatchesWide; x++)
     {
         for (var y = 0; y < PatchesWide; y++)
         {
             for (var z = 0; z < PatchesWide; z++)
             {
                 if (_patches[x, y, z] == null)
                 {
                     _patches[x, y, z] = new Patch();
                 }
                 _patches[x, y, z].Initialize(this, new Vector3Int(x, y, z) * ConfigManager.Properties.PatchSize);
             }
         }
     }
 }
Exemplo n.º 4
0
        public void BuildColumn(IEnumerable <BatchUpdateItem <LightBlockItem> > fill)
        {
            var lightProcessor = new LightProcessor(ChunkSize, ChunkSize, ChunkSize);
            var chunkPool      = PoolManager.GetObjectPool <Chunk>();

            foreach (var batchUpdateItem in fill)
            {
                var    pos        = batchUpdateItem.Position;
                var    chunkIndex = pos.y / ChunkSize;
                IChunk chunk;
                if (chunkIndex < _chunks.Count)
                {
                    chunk = _chunks[chunkIndex];
                }
                else
                {
                    if (batchUpdateItem.Item.Block.Equals(BlockFactory.Empty) || batchUpdateItem.Item.Block.Equals(BlockFactory.BottomOfWorld))
                    {
                        continue;
                    }
                    var newChunk = chunkPool.Pop();
                    newChunk.Initiailize(new Vector3Int(Offset.x, chunkIndex * ChunkSize, Offset.y), ColumnId + chunkIndex);
                    _chunks.Add(newChunk);
                    chunk    = newChunk;
                    _height += ChunkSize;
                    lightProcessor.GrowArray(_height);
                }
                lightProcessor.SetupBufferStep(batchUpdateItem);
                chunk.UpdateBlock(pos.x, pos.y % ChunkSize, pos.z, batchUpdateItem.Item.Block);
            }
            var buffer = lightProcessor.Light(GetLight);

            _lightData = PoolManager.GetObjectPool <CompressableArray <uint> >().Pop();
            _lightData.Initialize(buffer, ChunkSize, _height);
            lightProcessor.Dispose();

            var missingChunks = MaxHeight / ChunkSize - _chunks.Count;

            for (var y = 0; y < missingChunks; ++y)
            {
                var fake = PoolManager.GetObjectPool <FakeChunk>().Pop();
                fake.Initiailize(new Vector3Int(Offset.x, _chunks.Count * ChunkSize, Offset.y), ColumnId + _chunks.Count, BlockFactory.Empty);
                _chunks.Add(fake);
            }

            for (var y = 0; y < _chunks.Count; y++)
            {
                var chunk = _chunks[y];
                chunk.PhysicsState    = LoadingState.Empty;
                chunk.BlockDataLoaded = true;
                foreach (var neighbor in _neighbors)
                {
                    chunk.SetNeighbor(neighbor.Key, neighbor.Value[y * ChunkSize]);
                }

                IChunk bottomNeighbor;
                if (y > 0)
                {
                    bottomNeighbor = _chunks[y - 1];
                }
                else
                {
                    var bottomOfWorld = new FakeChunk();
                    bottomOfWorld.Initiailize(Vector3Int.zero, long.MinValue, BlockFactory.BottomOfWorld);
                    bottomOfWorld.SetNeighbor(FaceDirection.XIncreasing, bottomOfWorld);
                    bottomOfWorld.SetNeighbor(FaceDirection.ZIncreasing, bottomOfWorld);
                    bottomNeighbor = bottomOfWorld;
                }
                chunk.SetNeighbor(FaceDirection.YDecreasing, bottomNeighbor);

                if (y < _chunks.Count - 1)
                {
                    chunk.SetNeighbor(FaceDirection.YIncreasing, _chunks[y + 1]);
                }
            }
        }