Esempio n. 1
0
        private async Task UpdateTerrain()
        {
            if (!updatingTerrain)
            {
                var newPlayerChunk = config.GetChunkIndexAt(player.position);

                if (!newPlayerChunk.Equals(playerCurrentChunk))
                {
                    var newCurrentChunks = CalculateChunksAround(newPlayerChunk);

                    var chunksToDestroy = currentChunks.Except(newCurrentChunks);
                    var chunksToCreate  = newCurrentChunks.Except(currentChunks);

                    chunksPool.Deactivate(chunksToDestroy);

                    updatingTerrain = true;

                    await GenerateChunks(chunksToCreate)
                    .ContinueWith(_ =>
                    {
                        currentChunks.Clear();
                        currentChunks.UnionWith(newCurrentChunks);
                        playerCurrentChunk = newPlayerChunk;
                        updatingTerrain    = false;
                    });
                }
            }
        }
Esempio n. 2
0
        private TerrainBlock GetBlockAt(Vector3 pointInWorld, out TerrainChunk chunk)
        {
            var chunkIndex = config.GetChunkIndexAt(pointInWorld);

            chunk = chunkGenerator.GetOrGenerateEmpty(chunkIndex, chunksParent);
            var blockLocalIndex = chunk.GetBlockLocalIndexAt(pointInWorld);

            return(chunk.GetBlock(blockLocalIndex));
        }