Exemple #1
0
        public ChunkRegionRender(ChunkRegion chunkRegion)
        {
            _chunkRegion = chunkRegion;

            _renders = new ConcurrentDictionary <string, BlockRender>();


            _deleted = false;
        }
Exemple #2
0
 public Chunk(ChunkRegion region, Vector3i position)
 {
     _region      = region;
     _position    = position;
     _blocks      = new Block[ChunkLength, ChunkLength, ChunkLength];
     _taskManager = new WorldTaskManager();
     _modified    = true;
     _natural     = false;
 }
Exemple #3
0
        public Chunk CreateChunk(Vector3i position)
        {
            var regionPosition = position >> 2;

            var region = GetChunkRegion(regionPosition);

            if (region == null)
            {
                region = new ChunkRegion(this, regionPosition);
                region.LoadIfDeleted();
                _chunkRegions[regionPosition] = region;
            }
            else
            {
                region.LoadIfDeleted();
            }

            var chunk = region.GetChunkFromChunkPosition(position);

            if (chunk != null)
            {
                return(chunk);
            }

            var chunkPositionInRegion = position - (regionPosition << 2);

            if (region.TryLoadSavedChunk(chunkPositionInRegion, out chunk))
            {
                _unloadedChunkGenerationManager.OnChunkLoad(chunk);
                return(chunk);
            }

            chunk = new Chunk(region, position)
            {
                Natural = true
            };
            region.SetChunk(chunk, chunkPositionInRegion);
            _worldGenerator.GenerateChunkData(chunk);
            _unloadedChunkGenerationManager.FlushToAllChunks();

            return(chunk);
        }
Exemple #4
0
        public Block SetBlock(BlockSnapshot snapshot, Vector3i position, Func <Block, bool> canBeReplaced)
        {
            var regionPosition = position >> 6;
            var chunkPosition  = position >> 4;

            var region = GetChunkRegion(regionPosition);

            if (region == null)
            {
                region = new ChunkRegion(this, regionPosition);
                region.LoadIfDeleted();
                _chunkRegions[regionPosition] = region;
            }

            var chunk = region.GetChunkFromChunkPosition(chunkPosition);

            if (chunk != null)
            {
                return(chunk.SetBlockFromWorldPosition(snapshot, position, canBeReplaced));
            }
            _unloadedChunkGenerationManager.AddBlock(position, snapshot, true);
            return(null);
        }