protected override byte GetBiomeIndex(Chunk chunk)
        {
            // TODO: 仮想 BiomeBounds の判定

            //return (byte) random.Next(BiomeCatalog.Count);
            throw new NotImplementedException();
        }
        // I/F
        public void Generate(Chunk chunk)
        {
            var chunkSize = chunk.Size;

            for (int x = 0; x < chunkSize.X; x++)
            {
                for (int z = 0; z < chunkSize.Z; z++)
                {
                    for (int y = 0; y < chunkSize.Y; y++)
                    {
                        var blockIndex = Block.EmptyIndex;

                        if (y % 2 == 0)
                        {
                            if (x % 2 == 0 && z % 2 == 0)
                                blockIndex = Region.BlockCatalog.DirtIndex;
                        }
                        else
                        {
                            if (x % 2 == 1 && z % 2 == 1)
                                blockIndex = Region.BlockCatalog.DirtIndex;
                        }

                        chunk.SetBlockIndex(x, y, z, blockIndex);
                    }
                }
            }
        }
        // I/F
        public void Generate(Chunk chunk)
        {
            var chunkSize = chunk.Size;

            // バイオームを取得。
            // 選択されるブロックはバイオームに従う。
            var biome = Region.BiomeManager.GetBiome(chunk);

            for (int x = 0; x < chunkSize.X; x++)
            {
                // チャンク空間における相対ブロック位置をブロック空間の位置へ変換。
                var absoluteX = chunk.GetAbsoluteBlockPositionX(x);

                for (int z = 0; z < chunkSize.Z; z++)
                {
                    // チャンク空間における相対ブロック位置をブロック空間の位置へ変換。
                    var absoluteZ = chunk.GetAbsoluteBlockPositionZ(z);

                    // この XZ  におけるバイオーム要素を取得。
                    var biomeElement = biome.GetBiomeElement(absoluteX, absoluteZ);

                    bool topBlockExists = false;
                    for (int y = chunkSize.Y - 1; 0 <= y; y--)
                    {
                        // チャンク空間における相対ブロック位置をブロック空間の位置へ変換。
                        var absoluteY = chunk.GetAbsoluteBlockPositionY(y);

                        // 地形密度を取得。
                        var density = biome.TerrainNoise.Sample(absoluteX, absoluteY, absoluteZ);

                        byte blockIndex = Block.EmptyIndex;
                        if (0 < density)
                        {
                            // 密度 1 はブロック有り

                            if (!topBlockExists)
                            {
                                // トップ ブロックを検出。
                                blockIndex = GetBlockIndexAtTop(biomeElement);

                                topBlockExists = true;
                            }
                            else
                            {
                                blockIndex = GetBlockIndexBelowTop(biomeElement);
                            }
                        }
                        else
                        {
                            // 密度 0 はブロック無し

                            // トップ ブロックを見つけていた場合はそれを OFF とする。
                            topBlockExists = false;
                        }

                        chunk.SetBlockIndex(x, y, z, blockIndex);
                    }
                }
            }
        }
Example #4
0
        public ChunkBlock(Chunk chunk, IntVector3 position)
        {
            if (chunk == null) throw new ArgumentNullException("chunk");
            if (!chunk.Contains(position)) throw new ArgumentOutOfRangeException("position");

            this.chunk = chunk;
            this.position = position;
        }
        internal void Initialize(Chunk chunk, ChunkTaskType taskType, ChunkTaskPriority priority)
        {
            if (chunk == null) throw new ArgumentNullException("chunk");

            this.chunk = chunk;
            this.taskType = taskType;
            this.priority = priority;

            timestamp = TimeSpan.FromTicks(Environment.TickCount);
        }
        void Generate(Chunk chunk, ref IntVector3 chunkSize, ref IntVector3 chunkPosition, int x, int y, int z, BiomeElement biomeElement)
        {
            var h = chunkPosition.Y * chunkSize.Y + y;

            byte index = Block.EmptyIndex;

            if (Height == h)
            {
                // Horizon.
                switch (biomeElement)
                {
                    case BiomeElement.Desert:
                        index = Region.BlockCatalog.SandIndex;
                        break;
                    case BiomeElement.Forest:
                        index = Region.BlockCatalog.DirtIndex;
                        break;
                    case BiomeElement.Mountains:
                        index = Region.BlockCatalog.StoneIndex;
                        break;
                    case BiomeElement.Plains:
                        index = Region.BlockCatalog.GrassIndex;
                        break;
                    case BiomeElement.Snow:
                        index = Region.BlockCatalog.SnowIndex;
                        break;
                }
            }
            else if (h < Height)
            {
                // Below the horizon.
                switch (biomeElement)
                {
                    case BiomeElement.Desert:
                        index = Region.BlockCatalog.SandIndex;
                        break;
                    case BiomeElement.Forest:
                        index = Region.BlockCatalog.DirtIndex;
                        break;
                    case BiomeElement.Mountains:
                        index = Region.BlockCatalog.StoneIndex;
                        break;
                    case BiomeElement.Plains:
                        index = Region.BlockCatalog.DirtIndex;
                        break;
                    case BiomeElement.Snow:
                        index = Region.BlockCatalog.SnowIndex;
                        break;
                }
            }

            chunk.SetBlockIndex(x, y, z, index);
        }
        public void Clear()
        {
            Chunk = null;

            for (int z = 0; z < meshManager.MeshSegments.Z; z++)
            {
                for (int y = 0; y < meshManager.MeshSegments.Y; y++)
                {
                    for (int x = 0; x < meshManager.MeshSegments.X; x++)
                    {
                        opaques[x, y, z].Clear();
                        translucences[x, y, z].Clear();
                    }
                }
            }
        }
        // I/F
        public void Generate(Chunk chunk)
        {
            var chunkSize = chunk.Size;
            var chunkPosition = chunk.Position;
            var biome = Region.BiomeManager.GetBiome(chunk);

            for (int x = 0; x < chunkSize.X; x++)
            {
                for (int z = 0; z < chunkSize.Z; z++)
                {
                    var biomeElement = GetBiomeElement(chunk, biome, x, z);

                    for (int y = 0; y < chunkSize.Y; y++)
                        Generate(chunk, ref chunkSize, ref chunkPosition, x, y, z, biomeElement);
                }
            }
        }
 protected abstract byte GetBiomeIndex(Chunk chunk);
 // I/F
 public IBiome GetBiome(Chunk chunk)
 {
     return BiomeCatalog[GetBiomeIndex(chunk)];
 }
 internal void Clear()
 {
     chunk = null;
 }
        public void Initialize(Chunk chunk)
        {
            if (chunk == null) throw new ArgumentNullException("chunk");

            // メモ
            //
            // ここで隣接チャンクが揃っているか否かを検査していたが、
            // その検査は意味を成さない。
            // 非同期処理の最中に隣接チャンクが非アクティブ化される場合があるが、
            // 非同期処理では隣接チャンクがない場合に単に空チャンクを仮定して処理を進めている。

            Chunk = chunk;
        }
Example #13
0
 internal void Clear()
 {
     chunk = null;
 }
Example #14
0
 public void RequestUpdateMesh(Chunk chunk, ChunkMeshUpdatePriority priority)
 {
     meshManager.RequestUpdateMesh(chunk, priority);
 }
 // I/F
 public IBiome GetBiome(Chunk chunk)
 {
     return Biome;
 }
 protected override byte GetBiomeIndex(Chunk chunk)
 {
     throw new NotImplementedException();
 }
        void Generate(Chunk chunk, ref IntVector3 chunkSize, ref IntVector3 chunkPosition, int x, int y, int z, BiomeElement biomeElement)
        {
            var h = chunkPosition.Y * chunkSize.Y + y;

            byte index = Block.EmptyIndex;

            if (Height == h)
            {
                // Horizon.
                switch (biomeElement)
                {
                case BiomeElement.Desert:
                    index = Region.BlockCatalog.SandIndex;
                    break;

                case BiomeElement.Forest:
                    index = Region.BlockCatalog.DirtIndex;
                    break;

                case BiomeElement.Mountains:
                    index = Region.BlockCatalog.StoneIndex;
                    break;

                case BiomeElement.Plains:
                    index = Region.BlockCatalog.GrassIndex;
                    break;

                case BiomeElement.Snow:
                    index = Region.BlockCatalog.SnowIndex;
                    break;
                }
            }
            else if (h < Height)
            {
                // Below the horizon.
                switch (biomeElement)
                {
                case BiomeElement.Desert:
                    index = Region.BlockCatalog.SandIndex;
                    break;

                case BiomeElement.Forest:
                    index = Region.BlockCatalog.DirtIndex;
                    break;

                case BiomeElement.Mountains:
                    index = Region.BlockCatalog.StoneIndex;
                    break;

                case BiomeElement.Plains:
                    index = Region.BlockCatalog.DirtIndex;
                    break;

                case BiomeElement.Snow:
                    index = Region.BlockCatalog.SnowIndex;
                    break;
                }
            }

            chunk.SetBlockIndex(x, y, z, index);
        }
 BiomeElement GetBiomeElement(Chunk chunk, IBiome biome, int x, int z)
 {
     var absoluteX = chunk.GetAbsoluteBlockPositionX(x);
     var absoluteZ = chunk.GetAbsoluteBlockPositionZ(z);
     return biome.GetBiomeElement(absoluteX, absoluteZ);
 }