Example #1
0
        //private ThreadSafeList<ChunkCoordinates> _loadedChunks = new ThreadSafeList<ChunkCoordinates>();
        private void UnloadChunks(ChunkCoordinates center, double maxViewDistance)
        {
            //var chunkPublisher = Client.LastChunkPublish;

            //Client.ChunkRadius
            foreach (var chunk in World.ChunkManager.GetAllChunks())
            {
                if (chunk.Key.DistanceTo(center) > maxViewDistance)
                {
                    //_chunkCache.TryRemove(chunkColumn.Key, out var waste);
                    UnloadChunk(chunk.Key);
                }
            }
            //Parallel.ForEach(_loadedChunks.ToArray(), (chunkColumn) =>
            //{

            /*if (chunkPublisher != null)
             * {
             *      if (chunkColumn.DistanceTo(new ChunkCoordinates(new Vector3(chunkPublisher.coordinates.X,
             *                  chunkPublisher.coordinates.Y, chunkPublisher.coordinates.Z))) < chunkPublisher.radius)
             *              return;
             * }*/


            //	});
        }
Example #2
0
        public void ChunkReceived(ChunkColumn chunkColumn)
        {
            _chunksReceived++;
            var coords = new ChunkCoordinates(chunkColumn.X, chunkColumn.Z);

            //if (!_loadedChunks.Contains(coords))
            _loadedChunks.TryAdd(coords);

            //sLog.Info($"Chunk received");
            base.LoadChunk(chunkColumn, chunkColumn.X, chunkColumn.Z, true);
        }
Example #3
0
 private void UnloadChunks(ChunkCoordinates center, double maxViewDistance)
 {
     Parallel.ForEach(_loadedChunks.ToArray(), (chunkColumn) =>
     {
         if (chunkColumn.DistanceTo(center) > maxViewDistance)
         {
             //_chunkCache.TryRemove(chunkColumn.Key, out var waste);
             UnloadChunk(chunkColumn);
         }
     });
 }
Example #4
0
        public ChunkColumn GetChunk(ChunkCoordinates coordinates, bool cacheOnly = false)
        {
            if (coordinates == _coord)
            {
                return(_chunk);
            }

            if (_coord != ChunkCoordinates.None)
            {
                if (coordinates != _coord)
                {
                    if (coordinates != _coord + ChunkCoordinates.Backward)
                    {
                        if (coordinates != _coord + ChunkCoordinates.Forward)
                        {
                            if (coordinates != _coord + ChunkCoordinates.Left)
                            {
                                if (coordinates != _coord + ChunkCoordinates.Right)
                                {
                                    if (coordinates != _coord + ChunkCoordinates.Backward + ChunkCoordinates.Left)
                                    {
                                        if (coordinates != _coord + ChunkCoordinates.Backward + ChunkCoordinates.Right)
                                        {
                                            if (coordinates != _coord + ChunkCoordinates.Forward + ChunkCoordinates.Left)
                                            {
                                                if (coordinates != _coord + ChunkCoordinates.Forward + ChunkCoordinates.Right)
                                                {
                                                    return(null);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (_worldProvider.TryGetChunk(coordinates, out ChunkColumn column))
            {
                return((ChunkColumn)column);
            }

            return(null);
            //return _worldProvider.GenerateChunkColumn(coordinates, true);
        }
Example #5
0
        //private ThreadSafeList<ChunkCoordinates> _loadedChunks = new ThreadSafeList<ChunkCoordinates>();
        private void UnloadChunks(ChunkCoordinates center, double maxViewDistance)
        {
            var chunkPublisher = Client.LastChunkPublish;

            ChunkCoordinates publisherCenter = center;

            if (chunkPublisher != null)
            {
                publisherCenter = new ChunkCoordinates(
                    new Vector3(
                        chunkPublisher.coordinates.X, chunkPublisher.coordinates.Y, chunkPublisher.coordinates.Z));
            }

            //Client.ChunkRadius
            foreach (var chunk in World.ChunkManager.GetAllChunks())
            {
                var distance = chunk.Key.DistanceTo(center);

                if (chunkPublisher != null)
                {
                    if (chunk.Key.DistanceTo(publisherCenter) < (chunkPublisher.radius / 16f))
                    {
                        continue;
                    }
                }

                if (distance > Alex.Options.AlexOptions.VideoOptions.RenderDistance.Value)
                {
                    //_chunkCache.TryRemove(chunkColumn.Key, out var waste);
                    UnloadChunk(chunk.Key);
                }
            }
            //Parallel.ForEach(_loadedChunks.ToArray(), (chunkColumn) =>
            //{

            /*if (chunkPublisher != null)
             * {
             *      if (chunkColumn.DistanceTo(new ChunkCoordinates(new Vector3(chunkPublisher.coordinates.X,
             *                  chunkPublisher.coordinates.Y, chunkPublisher.coordinates.Z))) < chunkPublisher.radius)
             *              return;
             * }*/


            //	});
        }
Example #6
0
        public void Calculate(World level, BlockCoordinates coordinates)
        {
            int currentLight = level.GetSkyLight(coordinates);

            var         cc     = new ChunkCoordinates(coordinates);
            ChunkColumn chunk  = (ChunkColumn)level.GetChunkColumn(cc.X, cc.Z);
            var         height = chunk.GetRecalculatedHeight(coordinates.X & 0x0f, coordinates.Z & 0x0f);

            Queue <BlockCoordinates> sourceQueue = new Queue <BlockCoordinates>();

            sourceQueue.Enqueue(coordinates);
            if (currentLight != 0)
            {
                Queue <BlockCoordinates>   resetQueue = new Queue <BlockCoordinates>();
                HashSet <BlockCoordinates> visits     = new HashSet <BlockCoordinates>();

                // Reset all lights that potentially derive from this
                resetQueue.Enqueue(coordinates);

                Queue <BlockCoordinates> deleteQueue = new Queue <BlockCoordinates>();
                while (resetQueue.Count > 0)
                {
                    var coord = resetQueue.Dequeue();
                    if (visits.Contains(coord))
                    {
                        continue;
                    }

                    visits.Add(coord);

                    if (coord.DistanceTo(coordinates) > 16)
                    {
                        continue;
                    }

                    ResetLight(level, resetQueue, sourceQueue, coord);
                    if (!sourceQueue.Contains(coord))
                    {
                        deleteQueue.Enqueue(coord);
                    }
                }

                level.SetSkyLight(coordinates, 0);

                foreach (var delete in deleteQueue)
                {
                    level.SetSkyLight(delete, 0);
                }
            }
            else
            {
                sourceQueue.Enqueue(coordinates);
                sourceQueue.Enqueue(coordinates.BlockUp());
                sourceQueue.Enqueue(coordinates.BlockDown());
                sourceQueue.Enqueue(coordinates.BlockWest());
                sourceQueue.Enqueue(coordinates.BlockEast());
                sourceQueue.Enqueue(coordinates.BlockNorth());
                sourceQueue.Enqueue(coordinates.BlockSouth());
            }

            chunk.SetHeight(coordinates.X & 0x0f, coordinates.Z & 0x0f, (short)height);

            // Recalc
            Queue <BlockCoordinates>   lightBfQueue = new Queue <BlockCoordinates>(sourceQueue);
            HashSet <BlockCoordinates> lightBfSet   = new HashSet <BlockCoordinates>(sourceQueue);

            SkyLightBlockAccess blockAccess = new SkyLightBlockAccess(level.ChunkManager);

            Calculate(blockAccess, lightBfQueue, lightBfSet);
        }
Example #7
0
 public void UnloadChunk(ChunkCoordinates coordinates)
 {
     UnloadChunk(coordinates.X, coordinates.Z);
     _loadedChunks.Remove(coordinates);
 }
Example #8
0
 public void UnloadChunk(ChunkCoordinates coordinates)
 {
     World.UnloadChunk(coordinates);
 }
Example #9
0
 public SkyLightBlockAccess(ChunkManager worldProvider, ChunkColumn chunk) : this(worldProvider, -1)
 {
     _chunk = chunk;
     _coord = new ChunkCoordinates(chunk.X, chunk.Z);
 }